home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / dreamscape / source / Dreamscape / Headers / gadgets / h / writablefi < prev   
Encoding:
Text File  |  1996-09-06  |  4.2 KB  |  138 lines

  1.  
  2. // gadgets.h.writablefield
  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_writablefield_H
  14. #define dreamscape_writablefield_H
  15.  
  16. #include "gadget.h"
  17. #include "window.h"
  18.  
  19. class WritableFieldTemplate: public GadgetTemplate {
  20. public:
  21.   WritableFieldTemplate(): justify(centre), inform(0), secret(0),
  22.     text_size(0), allow_size(0), previous(0), next(0)
  23.       { bbox = WinBBox(0, -52, 100, 0); }
  24.  
  25.   enum { left, centre, right };
  26.   unsigned justify: 2;
  27.   unsigned inform: 1;
  28.   unsigned secret: 1;
  29.   String text;
  30.   int text_size;
  31.   String allow;
  32.   int allow_size;
  33.   const Gadget *previous, *next;
  34. };
  35.  
  36. class WritableFieldFileInfo {
  37. public:
  38.   WritableFieldFileInfo(): size(0), shift(0), control(0), alt(0) {}
  39.  
  40.   Filetype type;
  41.   int size;
  42.   unsigned shift: 1;
  43.   unsigned control: 1;
  44.   unsigned alt: 1;
  45. };
  46.  
  47. class WritableField: public Gadget {
  48.   static class Initialise: public DataLoadProtocol::Client {
  49.   public:
  50.     Initialise();
  51.  
  52.     void *accept_data(const DataLoadProtocol::Info &info);
  53.     void *accept_file(const DataLoadProtocol::Info &info);
  54.     void load_data(const DataLoadProtocol::Info &info, istream &stream,
  55.         void *handle);
  56.     void load_file(const DataLoadProtocol::Info &info, const char *filename,
  57.         void *handle);
  58.   } init;
  59.   friend Initialise;
  60.  
  61.   static Gadget *create(Window *window, int component);
  62.   static void changed(const toolbox_action *event, const toolbox_block *ids);
  63.  
  64.   Command *changed_handler;
  65.  
  66.   WritableField(Window *window, int component);
  67. public:
  68.   WritableField(Window *window, const WritableFieldTemplate &t);
  69.   virtual ~WritableField();
  70.  
  71.   WritableField &operator=(const char *text)
  72.     { set_text(text); return *this; }
  73.   WritableField &operator+=(const char *text)
  74.     { set_text(get_text() + text); return *this; }
  75.   String operator+(const char *text) const { return get_text() + text; }
  76.   operator String() const { return get_text(); }
  77.  
  78.   typedef Loader<const char *, WritableFieldFileInfo> FileLoader;
  79.   typedef Loader<istream &, WritableFieldFileInfo> DataLoader;
  80.   typedef LoaderOneType<const char *, WritableFieldFileInfo>
  81.         FileLoaderOneType;
  82.   typedef LoaderOneType<istream &, WritableFieldFileInfo> DataLoaderOneType;
  83.  
  84. private:
  85.   struct FLNode { FileLoader *l; FLNode *next; } *file_loaders;
  86.   struct DLNode { DataLoader *l; DLNode *next; } *data_loaders;
  87.   struct FLTempData { WritableFieldFileInfo i; FileLoader *l; };
  88.   struct DLTempData { WritableFieldFileInfo i; DataLoader *l; };
  89.   static WritableField *get_load_object(const DataLoadProtocol::Info &info);
  90.   static void fill_in_loader_info(WritableFieldFileInfo &i,
  91.         const DataLoadProtocol::Info &info);
  92.  
  93. public:
  94.   void add_file_loader(FileLoader *loader);
  95.   void remove_file_loader(FileLoader *loader);
  96.   void add_data_loader(DataLoader *loader);
  97.   void remove_data_loader(DataLoader *loader);
  98.  
  99.   void set_changed_handler(Command *handler) { changed_handler = handler; }
  100.  
  101.   void set_text(const char *text);
  102.   String get_text() const;
  103.  
  104.   void set_allowable(const char *allow = 0);
  105.  
  106.   void set_font(const char *font = 0, float width = 12, float height = 0);
  107. };
  108.  
  109. class VirtualWritableField: public WindowRedrawable {
  110. public:
  111.   VirtualWritableField(): justify(centre), bbox(0, -52, 100, 0) {}
  112.   VirtualWritableField(const WritableFieldTemplate &t): text(t.text),
  113.     bbox(t.bbox), justify(t.justify) {}
  114.  
  115.   VirtualWritableField &operator=(const WritableFieldTemplate &t)
  116.     { text = t.text; bbox = t.bbox; justify = t.justify; return *this; }
  117.  
  118.   String text;
  119.   WinBBox bbox;
  120.   enum { left, centre, right };
  121.   unsigned justify: 2;
  122.  
  123.   void redraw(const RedrawInfo &info) const;
  124. };
  125.  
  126. class WritableFieldFilenameInserter:
  127. public WritableField::FileLoaderOneType {
  128.   WritableField *gadget;
  129. public:
  130.   WritableFieldFilenameInserter(WritableField *g, Filetype type):
  131.     WritableField::FileLoaderOneType(type), gadget(g)
  132.       { gadget->add_file_loader(this); }
  133.  
  134.   void load(const WritableFieldFileInfo &info, const char *filename);
  135. };
  136.  
  137. #endif
  138.