home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / dreamscape / source / Dreamscape / Headers / objects / h / clipboard < prev    next >
Encoding:
Text File  |  1996-09-06  |  3.6 KB  |  149 lines

  1.  
  2. // objects.h.clipboard
  3.  
  4. // Dreamscape - C++ class library for RISC OS
  5. // Copyright (c) 1996 Mark Seaborn <mseaborn@argonet.co.uk>
  6. //
  7. // This library is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU Library General Public
  9. // License as published by the Free Software Foundation; either
  10. // version 2 of the License, or (at your option) any later version.
  11. // See the Dreamscape documentation for more information.
  12.  
  13. #ifndef dreamscape_clipboard_H
  14. #define dreamscape_clipboard_H
  15.  
  16. #include "bool.h"
  17.  
  18. #include "command.h"
  19. #include "loader.h"
  20. #include "saver.h"
  21. #include "dataload.h"
  22. #include "datasave.h"
  23.  
  24. struct wimp_message;
  25.  
  26. class SelectionDeleter {
  27. public:
  28.   virtual void delete_selection() = 0;
  29. };
  30.  
  31. class ClipboardInfo {
  32. public:
  33.   ClipboardInfo(): size(0) {}
  34.  
  35.   Filetype type;
  36.   int size;
  37. };
  38.  
  39. class ClipboardPaster {
  40.   static class Initialise: public DataLoadProtocol::Client {
  41.   public:
  42.     Initialise();
  43.  
  44.     void *accept_data(const DataLoadProtocol::Info &info);
  45.     void *accept_file(const DataLoadProtocol::Info &info);
  46.     void load_data(const DataLoadProtocol::Info &info, istream &stream,
  47.         void *handle);
  48.     void load_file(const DataLoadProtocol::Info &info, const char *filename,
  49.         void *handle);
  50.   } init;
  51.   friend Initialise;
  52.  
  53.   static ClipboardPaster *pasting;
  54.  
  55. public:
  56.   ClipboardPaster();
  57.   virtual ~ClipboardPaster();
  58.  
  59.   typedef Loader<istream &, ClipboardInfo> DataLoader;
  60.   typedef LoaderOneType<istream &, ClipboardInfo> DataLoaderOneType;
  61.  
  62. private:
  63.   struct DLNode { DataLoader *l; DLNode *next; } *data_loaders;
  64.   struct DLTempData { ClipboardInfo i; DataLoader *l; };
  65.  
  66. public:
  67.   void add_paster(DataLoader *loader);
  68.   void remove_paster(DataLoader *loader);
  69.  
  70.   bool paste_possible() const;
  71.   void paste();
  72. };
  73.  
  74. class ClipboardCopier {
  75.   static class Initialise: public DataSaveProtocol::Client {
  76.   public:
  77.     Initialise();
  78.  
  79.     void save_to_stream(ostream &stream, void *handle);
  80.     void save_finished(void *handle);
  81.     void save_unsuccessful(void *handle);
  82.   } init;
  83.   friend Initialise;
  84.  
  85.   static void find_clipboard_filetype();
  86.   static bool message_data_save(const wimp_message *message);
  87.   static bool message_claim_entity(const wimp_message *message,
  88.         void *handle);
  89.   static bool message_data_request(const wimp_message *message,
  90.         void *handle);
  91.   static char *clipboard;
  92.   static int clipboard_size;
  93.   static Filetype clipboard_type;
  94.   friend ClipboardPaster;
  95.  
  96.   Filetype type;
  97.   const SelectionSaver *copier;
  98.   SelectionDeleter *deleter;
  99.  
  100. public:
  101.   ClipboardCopier();
  102.   virtual ~ClipboardCopier();
  103.  
  104.   void set_copier(const SelectionSaver *copier,
  105.         SelectionDeleter *deleter = 0);
  106.   void set_deleter(SelectionDeleter *deleter);
  107.  
  108.   void set_filetype(Filetype type) { this->type = type; }
  109.   Filetype get_filetype() const { return type; }
  110.  
  111.   bool cut_possible() const { return copier && deleter; }
  112.   bool copy_possible() const { return copier ? 1:0; }
  113.   bool delete_possible() const { return deleter ? 1:0; }
  114.  
  115.   void cut() { copy(); sdelete(); }
  116.   void copy();
  117.   void sdelete() { if(deleter) deleter->delete_selection(); }
  118. };
  119.  
  120. class CutCommand: public Command {
  121.   ClipboardCopier *copier;
  122. public:
  123.   CutCommand(ClipboardCopier *c): copier(c) {}
  124.   void execute();
  125. };
  126.  
  127. class CopyCommand: public Command {
  128.   ClipboardCopier *copier;
  129. public:
  130.   CopyCommand(ClipboardCopier *c): copier(c) {}
  131.   void execute();
  132. };
  133.  
  134. class PasteCommand: public Command {
  135.   ClipboardPaster *paster;
  136. public:
  137.   PasteCommand(ClipboardPaster *p): paster(p) {}
  138.   void execute();
  139. };
  140.  
  141. class DeleteCommand: public Command {
  142.   ClipboardCopier *copier;
  143. public:
  144.   DeleteCommand(ClipboardCopier *c): copier(c) {}
  145.   void execute();
  146. };
  147.  
  148. #endif
  149.