home *** CD-ROM | disk | FTP | other *** search
-
- // gadgets.h.writablefield
-
- // 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_writablefield_H
- #define dreamscape_writablefield_H
-
- #include "gadget.h"
- #include "window.h"
-
- class WritableFieldTemplate: public GadgetTemplate {
- public:
- WritableFieldTemplate(): justify(centre), inform(0), secret(0),
- text_size(0), allow_size(0), previous(0), next(0)
- { bbox = WinBBox(0, -52, 100, 0); }
-
- enum { left, centre, right };
- unsigned justify: 2;
- unsigned inform: 1;
- unsigned secret: 1;
- String text;
- int text_size;
- String allow;
- int allow_size;
- const Gadget *previous, *next;
- };
-
- class WritableFieldFileInfo {
- public:
- WritableFieldFileInfo(): size(0), shift(0), control(0), alt(0) {}
-
- Filetype type;
- int size;
- unsigned shift: 1;
- unsigned control: 1;
- unsigned alt: 1;
- };
-
- class WritableField: public Gadget {
- 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 Gadget *create(Window *window, int component);
- static void changed(const toolbox_action *event, const toolbox_block *ids);
-
- Command *changed_handler;
-
- WritableField(Window *window, int component);
- public:
- WritableField(Window *window, const WritableFieldTemplate &t);
- virtual ~WritableField();
-
- WritableField &operator=(const char *text)
- { set_text(text); return *this; }
- WritableField &operator+=(const char *text)
- { set_text(get_text() + text); return *this; }
- String operator+(const char *text) const { return get_text() + text; }
- operator String() const { return get_text(); }
-
- typedef Loader<const char *, WritableFieldFileInfo> FileLoader;
- typedef Loader<istream &, WritableFieldFileInfo> DataLoader;
- typedef LoaderOneType<const char *, WritableFieldFileInfo>
- FileLoaderOneType;
- typedef LoaderOneType<istream &, WritableFieldFileInfo> DataLoaderOneType;
-
- private:
- struct FLNode { FileLoader *l; FLNode *next; } *file_loaders;
- struct DLNode { DataLoader *l; DLNode *next; } *data_loaders;
- struct FLTempData { WritableFieldFileInfo i; FileLoader *l; };
- struct DLTempData { WritableFieldFileInfo i; DataLoader *l; };
- static WritableField *get_load_object(const DataLoadProtocol::Info &info);
- static void fill_in_loader_info(WritableFieldFileInfo &i,
- const DataLoadProtocol::Info &info);
-
- public:
- void add_file_loader(FileLoader *loader);
- void remove_file_loader(FileLoader *loader);
- void add_data_loader(DataLoader *loader);
- void remove_data_loader(DataLoader *loader);
-
- void set_changed_handler(Command *handler) { changed_handler = handler; }
-
- void set_text(const char *text);
- String get_text() const;
-
- void set_allowable(const char *allow = 0);
-
- void set_font(const char *font = 0, float width = 12, float height = 0);
- };
-
- class VirtualWritableField: public WindowRedrawable {
- public:
- VirtualWritableField(): justify(centre), bbox(0, -52, 100, 0) {}
- VirtualWritableField(const WritableFieldTemplate &t): text(t.text),
- bbox(t.bbox), justify(t.justify) {}
-
- VirtualWritableField &operator=(const WritableFieldTemplate &t)
- { text = t.text; bbox = t.bbox; justify = t.justify; return *this; }
-
- String text;
- WinBBox bbox;
- enum { left, centre, right };
- unsigned justify: 2;
-
- void redraw(const RedrawInfo &info) const;
- };
-
- class WritableFieldFilenameInserter:
- public WritableField::FileLoaderOneType {
- WritableField *gadget;
- public:
- WritableFieldFilenameInserter(WritableField *g, Filetype type):
- WritableField::FileLoaderOneType(type), gadget(g)
- { gadget->add_file_loader(this); }
-
- void load(const WritableFieldFileInfo &info, const char *filename);
- };
-
- #endif
-