home *** CD-ROM | disk | FTP | other *** search
-
- // objects.h.clipboard
-
- // Dreamscape - C++ class library for RISC OS
- // Copyright (c) 1996 Mark Seaborn <mseaborn@argonet.co.uk>
- //
- // This library is free software; you can redistribute it and/or
- // modify it under the terms of the GNU Library General Public
- // License as published by the Free Software Foundation; either
- // version 2 of the License, or (at your option) any later version.
- // See the Dreamscape documentation for more information.
-
- #ifndef dreamscape_clipboard_H
- #define dreamscape_clipboard_H
-
- #include "bool.h"
-
- #include "command.h"
- #include "loader.h"
- #include "saver.h"
- #include "dataload.h"
- #include "datasave.h"
-
- struct wimp_message;
-
- class SelectionDeleter {
- public:
- virtual void delete_selection() = 0;
- };
-
- class ClipboardInfo {
- public:
- ClipboardInfo(): size(0) {}
-
- Filetype type;
- int size;
- };
-
- class ClipboardPaster {
- static class Initialise: public DataLoadProtocol::Client {
- public:
- Initialise();
-
- void *accept_data(const DataLoadProtocol::Info &info);
- void *accept_file(const DataLoadProtocol::Info &info);
- void load_data(const DataLoadProtocol::Info &info, istream &stream,
- void *handle);
- void load_file(const DataLoadProtocol::Info &info, const char *filename,
- void *handle);
- } init;
- friend Initialise;
-
- static ClipboardPaster *pasting;
-
- public:
- ClipboardPaster();
- virtual ~ClipboardPaster();
-
- typedef Loader<istream &, ClipboardInfo> DataLoader;
- typedef LoaderOneType<istream &, ClipboardInfo> DataLoaderOneType;
-
- private:
- struct DLNode { DataLoader *l; DLNode *next; } *data_loaders;
- struct DLTempData { ClipboardInfo i; DataLoader *l; };
-
- public:
- void add_paster(DataLoader *loader);
- void remove_paster(DataLoader *loader);
-
- bool paste_possible() const;
- void paste();
- };
-
- class ClipboardCopier {
- static class Initialise: public DataSaveProtocol::Client {
- public:
- Initialise();
-
- void save_to_stream(ostream &stream, void *handle);
- void save_finished(void *handle);
- void save_unsuccessful(void *handle);
- } init;
- friend Initialise;
-
- static void find_clipboard_filetype();
- static bool message_data_save(const wimp_message *message);
- static bool message_claim_entity(const wimp_message *message,
- void *handle);
- static bool message_data_request(const wimp_message *message,
- void *handle);
- static char *clipboard;
- static int clipboard_size;
- static Filetype clipboard_type;
- friend ClipboardPaster;
-
- Filetype type;
- const SelectionSaver *copier;
- SelectionDeleter *deleter;
-
- public:
- ClipboardCopier();
- virtual ~ClipboardCopier();
-
- void set_copier(const SelectionSaver *copier,
- SelectionDeleter *deleter = 0);
- void set_deleter(SelectionDeleter *deleter);
-
- void set_filetype(Filetype type) { this->type = type; }
- Filetype get_filetype() const { return type; }
-
- bool cut_possible() const { return copier && deleter; }
- bool copy_possible() const { return copier ? 1:0; }
- bool delete_possible() const { return deleter ? 1:0; }
-
- void cut() { copy(); sdelete(); }
- void copy();
- void sdelete() { if(deleter) deleter->delete_selection(); }
- };
-
- class CutCommand: public Command {
- ClipboardCopier *copier;
- public:
- CutCommand(ClipboardCopier *c): copier(c) {}
- void execute();
- };
-
- class CopyCommand: public Command {
- ClipboardCopier *copier;
- public:
- CopyCommand(ClipboardCopier *c): copier(c) {}
- void execute();
- };
-
- class PasteCommand: public Command {
- ClipboardPaster *paster;
- public:
- PasteCommand(ClipboardPaster *p): paster(p) {}
- void execute();
- };
-
- class DeleteCommand: public Command {
- ClipboardCopier *copier;
- public:
- DeleteCommand(ClipboardCopier *c): copier(c) {}
- void execute();
- };
-
- #endif
-