home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / dreamscape / examples / Dreamscape / Examples / TestProg / h / wotsit < prev   
Encoding:
Text File  |  1996-07-29  |  3.3 KB  |  129 lines

  1.  
  2. #ifndef testprog_wotsit_H
  3. #define testprog_wotsit_H
  4.  
  5. #include "window.h"
  6. #include "winhandlers.h"
  7. #include "menu.h"
  8. #include "saveas.h"
  9. #include "clipboard.h"
  10.  
  11. class WotsitGadget: public WindowRedrawable, public ClickHandler,
  12. public Saver, public SelectionSaver, public SelectionDeleter,
  13. public KeyPressedHandler, public Window::DataLoaderOneType,
  14. public ClipboardPaster::DataLoaderOneType {
  15.   Window *window;
  16.   WinBBox bbox;
  17.  
  18.   ClipboardPaster *paster;
  19.   ClipboardCopier *copier;
  20.  
  21.   enum { left_margin = 20, top_margin = 20 };
  22.   String text;
  23.   int position, selection;
  24.   void set_state(int p, int s);
  25.   void insert_char(char i);
  26.   void redraw_chars(int p, int s);
  27.   int get_pos(const WinCoords &pos);
  28.  
  29.   class DragSelection: public DragHandler {
  30.     WotsitGadget *gadget;
  31.     int pos;
  32.   public:
  33.     DragSelection(WotsitGadget *g, int p): gadget(g), pos(p) {}
  34.     void drag_in_progress(const DragInfo &info);
  35.     void drag_finished(const DragInfo &info);
  36.     void drag_aborted();
  37.   };
  38.   friend DragSelection;
  39.  
  40.   class DragWordsSelection: public DragHandler {
  41.     WotsitGadget *gadget;
  42.     int pos;
  43.   public:
  44.     DragWordsSelection(WotsitGadget *g, int p): gadget(g), pos(p) {}
  45.     void drag_in_progress(const DragInfo &info);
  46.     void drag_finished(const DragInfo &info);
  47.     void drag_aborted();
  48.   };
  49.   friend DragWordsSelection;
  50.  
  51. public:
  52.   WotsitGadget(Window *w, ClipboardPaster *p, ClipboardCopier *c,
  53.     const WinBBox &b);
  54.   ~WotsitGadget();
  55.  
  56.   void redraw(const RedrawInfo &info) const;
  57.   bool single_click(const ClickInfo &info);
  58.   bool double_click(const ClickInfo &info);
  59.   bool multi_click(const ClickInfo &info, int clicks);
  60.   bool drag(const ClickInfo &info);
  61.   bool multi_drag(const ClickInfo &info, int clicks);
  62.   bool key_pressed(Key key);
  63.  
  64.   void save(ostream &stream) const;
  65.   void save_selection(ostream &stream) const;
  66.   void delete_selection();
  67.  
  68.   void load(istream &stream);
  69.   void load(const WindowFileInfo &info, istream &stream);
  70.   void load(const ClipboardInfo &info, istream &stream);
  71.  
  72.   bool is_selection() const { return selection ? 1:0; }
  73.   void select_all() { set_state(0, text.length()); }
  74.   void clear_selection() { set_state(position, 0); }
  75. };
  76.  
  77. class Thingy {
  78. public:
  79.   Thingy();
  80.  
  81.   Window window;
  82.   Menu &menu;
  83.   SaveAs &save_as;
  84.   WotsitGadget gadget;
  85.  
  86.   ClipboardPaster paster;
  87.   ClipboardCopier copier;
  88.  
  89.   MenuEntry &cut_entry, ©_entry, &paste_entry, &delete_entry,
  90.           &select_all_entry, &clear_entry;
  91.  
  92.   DeleteObjectCommand<Thingy> hide;
  93.  
  94.   class SaveAsShowing: public Command {
  95.     Thingy *thingy;
  96.   public:
  97.     SaveAsShowing(Thingy *t): thingy(t) {}
  98.     void execute();
  99.   } save_as_showing;
  100.  
  101.   class MenuShowing: public Command {
  102.     Thingy *thingy;
  103.   public:
  104.     MenuShowing(Thingy *t): thingy(t) {}
  105.     void execute();
  106.   } menu_showing;
  107.  
  108.   CutCommand cut_command;
  109.   CopyCommand copy_command;
  110.   PasteCommand paste_command;
  111.   DeleteCommand delete_command;
  112.  
  113.   class SelectAllCommand: public Command {
  114.     WotsitGadget *gadget;
  115.   public:
  116.     SelectAllCommand(WotsitGadget *g): gadget(g) {}
  117.     void execute() { gadget->select_all(); }
  118.   } select_all_command;
  119.  
  120.   class ClearSelectionCommand: public Command {
  121.     WotsitGadget *gadget;
  122.   public:
  123.     ClearSelectionCommand(WotsitGadget *g): gadget(g) {}
  124.     void execute() { gadget->clear_selection(); }
  125.   } clear_selection_command;
  126. };
  127.  
  128. #endif
  129.