home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef testprog_wotsit_H
- #define testprog_wotsit_H
-
- #include "window.h"
- #include "winhandlers.h"
- #include "menu.h"
- #include "saveas.h"
- #include "clipboard.h"
-
- class WotsitGadget: public WindowRedrawable, public ClickHandler,
- public Saver, public SelectionSaver, public SelectionDeleter,
- public KeyPressedHandler, public Window::DataLoaderOneType,
- public ClipboardPaster::DataLoaderOneType {
- Window *window;
- WinBBox bbox;
-
- ClipboardPaster *paster;
- ClipboardCopier *copier;
-
- enum { left_margin = 20, top_margin = 20 };
- String text;
- int position, selection;
- void set_state(int p, int s);
- void insert_char(char i);
- void redraw_chars(int p, int s);
- int get_pos(const WinCoords &pos);
-
- class DragSelection: public DragHandler {
- WotsitGadget *gadget;
- int pos;
- public:
- DragSelection(WotsitGadget *g, int p): gadget(g), pos(p) {}
- void drag_in_progress(const DragInfo &info);
- void drag_finished(const DragInfo &info);
- void drag_aborted();
- };
- friend DragSelection;
-
- class DragWordsSelection: public DragHandler {
- WotsitGadget *gadget;
- int pos;
- public:
- DragWordsSelection(WotsitGadget *g, int p): gadget(g), pos(p) {}
- void drag_in_progress(const DragInfo &info);
- void drag_finished(const DragInfo &info);
- void drag_aborted();
- };
- friend DragWordsSelection;
-
- public:
- WotsitGadget(Window *w, ClipboardPaster *p, ClipboardCopier *c,
- const WinBBox &b);
- ~WotsitGadget();
-
- void redraw(const RedrawInfo &info) const;
- bool single_click(const ClickInfo &info);
- bool double_click(const ClickInfo &info);
- bool multi_click(const ClickInfo &info, int clicks);
- bool drag(const ClickInfo &info);
- bool multi_drag(const ClickInfo &info, int clicks);
- bool key_pressed(Key key);
-
- void save(ostream &stream) const;
- void save_selection(ostream &stream) const;
- void delete_selection();
-
- void load(istream &stream);
- void load(const WindowFileInfo &info, istream &stream);
- void load(const ClipboardInfo &info, istream &stream);
-
- bool is_selection() const { return selection ? 1:0; }
- void select_all() { set_state(0, text.length()); }
- void clear_selection() { set_state(position, 0); }
- };
-
- class Thingy {
- public:
- Thingy();
-
- Window window;
- Menu &menu;
- SaveAs &save_as;
- WotsitGadget gadget;
-
- ClipboardPaster paster;
- ClipboardCopier copier;
-
- MenuEntry &cut_entry, ©_entry, &paste_entry, &delete_entry,
- &select_all_entry, &clear_entry;
-
- DeleteObjectCommand<Thingy> hide;
-
- class SaveAsShowing: public Command {
- Thingy *thingy;
- public:
- SaveAsShowing(Thingy *t): thingy(t) {}
- void execute();
- } save_as_showing;
-
- class MenuShowing: public Command {
- Thingy *thingy;
- public:
- MenuShowing(Thingy *t): thingy(t) {}
- void execute();
- } menu_showing;
-
- CutCommand cut_command;
- CopyCommand copy_command;
- PasteCommand paste_command;
- DeleteCommand delete_command;
-
- class SelectAllCommand: public Command {
- WotsitGadget *gadget;
- public:
- SelectAllCommand(WotsitGadget *g): gadget(g) {}
- void execute() { gadget->select_all(); }
- } select_all_command;
-
- class ClearSelectionCommand: public Command {
- WotsitGadget *gadget;
- public:
- ClearSelectionCommand(WotsitGadget *g): gadget(g) {}
- void execute() { gadget->clear_selection(); }
- } clear_selection_command;
- };
-
- #endif
-