ubit
udoc.hpp
1 /************************************************************************
2  *
3  * udoc.hpp: Document Element
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _udoc_hpp_
18 #define _udoc_hpp_ 1
19 #include <list>
20 #include <map>
21 #include <ubit/udefs.hpp>
22 #include <ubit/ustr.hpp>
23 #include <ubit/uboxes.hpp>
24 namespace ubit {
25 
26  class UDocCreator;
27  class UDocAttachment;
28 
31  typedef std::list<UDocAttachment*> UDocAttachments;
32 
33  /* ==================================================== ====== ======= */
37  class UDocFactory {
38  public:
39  UDocFactory();
40  virtual ~UDocFactory();
41 
46  virtual UDoc* create(const UStr& name);
52  virtual UDoc* load(const UStr& name, const UStr& buffer);
58  virtual UDoc* read(const UStr& filename);
64  virtual int getStatus() const;
72  virtual void saveErrors(bool);
73  virtual UStr* getErrors() const;
78  virtual UDocCreator* getCreator(const UStr& type);
88  virtual UDocCreator* getDefaultCreator();
90 
91  virtual void addCreator(const UStr& type, UDocCreator&);
93 
94  virtual void setDefaultCreator(UDocCreator&);
96 
97  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98  protected:
99  struct Comp {
100  bool operator()(const UStr* s1, const UStr* s2) const;
101  };
102  typedef std::map<const UStr*, UDocCreator*, Comp> Map;
103  Map rmap;
104  UDocCreator* default_creator;
105  int stat;
106  uptr<UStr> errors;
107  };
108 
109 
110  /* ==================================================== ====== ======= */
122  class UDoc : public UBox {
123  public:
124  UCLASS(UDoc)
125 
126  static UDocFactory& getDefaultFactory();
128 
129  virtual ~UDoc();
130 
131  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
132 
133  virtual bool isEditable() const;
134  virtual void setEditable(bool state = true);
135 
136  virtual const UStr& getPath() const {return *ppath;}
138 
139  virtual void setPath(const UStr& path);
140  virtual void makePath(UStr& fullpath, const UStr& url);
146  virtual const UDocAttachments* getAttachments() const {return null;}
148 
149  virtual int loadAttachments(bool reload = false) {return 0;}
156  virtual bool loadAttachment(UDocAttachment*, bool reload = false) {return false;}
158 
159  virtual void addLinkCallback(const UChild& cond_slash_callback);
168  // - - - Impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
169 
170  virtual void linkEventCB(UInputEvent&, const UStr* path);
171 
172  protected:
173  UDoc();
174  UDoc(const UStr& path);
176 
177  private:
178  uptr<UStr> ppath;
179  uptr<UElem> call_list;
180  UDoc(const UDoc&); // these operators are forbidden
181  UDoc& operator=(const UDoc&);
182  };
183 
184  /* ==================================================== ======== ======= */
188  public:
189  virtual ~UDocAttachment() {}
190  virtual const UStr& getUrl() const = 0;
191  virtual const UStr& getType() const = 0;
192  virtual bool isLoaded() const = 0;
193  virtual int load(UDoc*) = 0;
194  };
195 
196  /* ==================================================== ======== ======= */
199  struct UDocSource {
200  enum From {PATHNAME, BUFFER, SCRATCH};
201 
202  UDocSource(int from, const UStr* path, UStr* errors, const UStr* buffer = null);
204 
205  int from;
206  int stat;
207  uptr<const UStr> path, fullpath;
208  const UStr* buffer;
209  UStr* errors;
210  };
211 
212 
213  /* ==================================================== ======== ======= */
216  class UDocCreator {
217  public:
218  virtual ~UDocCreator() {}
219  virtual UDoc* create(UDocSource&) = 0;
221  };
222 
223 
224  /* ==================================================== ======== ======= */
228  class UFlatDoc : public UDoc {
229  public:
230  UFlatDoc(const UStr& _pathname);
231  virtual bool isEditable() const;
232  virtual void setEditable(bool state = true);
233  uptr<class UEdit> edit;
234  };
235 
236 
237  /* ==================================================== ======== ======= */
240  class UPluginDoc : public UDoc {
241  public:
242  UPluginDoc(const UStr& _pathname);
243  //virtual void setEditable(bool state = true) {}
244  };
245 
246 }
247 #endif
virtual bool loadAttachment(UDocAttachment *, bool reload=false)
loads this attachment.
Definition: udoc.hpp:156
virtual UStr * getErrors() const
return last errors messages if saveErrors() was set to true.
Definition: udoc.cpp:387
virtual UDocCreator * getCreator(const UStr &type)
returns the creator for this type (if any, null otherwise).
Definition: udoc.cpp:469
Box container.
Definition: ubox.hpp:64
virtual void setDefaultCreator(UDocCreator &)
changes the creator that is used when the document type is unknown.
Definition: udoc.cpp:465
virtual const UStr & getPath() const
returns the pathname of the document.
Definition: udoc.hpp:136
virtual void addCreator(const UStr &type, UDocCreator &)
adds a document creator.
Definition: udoc.cpp:460
virtual int loadAttachments(bool reload=false)
loads the attachments.
Definition: udoc.hpp:149
virtual UDoc * load(const UStr &name, const UStr &buffer)
loads a document from a buffer in memory.
Definition: udoc.cpp:424
virtual UDoc * read(const UStr &filename)
reads a document from a file.
Definition: udoc.cpp:409
< Base of flat documents that just contains flat text or an image see also: UXmlDocument for XML "hie...
Definition: udoc.hpp:228
virtual const UDocAttachments * getAttachments() const
returns the objects (images, stylesheets, etc) that are attached to this document.
Definition: udoc.hpp:146
virtual int getStatus() const
status of the last (read/load/create) operation.
Definition: udoc.cpp:383
Document source (file, buffer, etc.).
Definition: udoc.hpp:199
static UDocFactory & getDefaultFactory()
returns the default factory for reading/creating documents.
Definition: udoc.cpp:27
Generic Document.
Definition: udoc.hpp:122
Document attachment (image, stylesheet, etc.)
Definition: udoc.hpp:187
Document Factory: use this class to read documents.
Definition: udoc.hpp:37
Definition: udoc.hpp:99
Definition: uhardfont.hpp:31
Base class for UMouseEvent and UKeyEvent Note that this class inherits from class UModifier that defi...
Definition: uevent.hpp:75
Document creator interface (intended to be subclassed).
Definition: udoc.hpp:216
virtual UDocCreator * getDefaultCreator()
returns the default document creator.
Definition: udoc.cpp:478
virtual UDoc * create(const UStr &name)
creates an empty document.
Definition: udoc.cpp:439
Ubit String.
Definition: ustr.hpp:72
< Documents that needs a plugin to be displayed.
Definition: udoc.hpp:240
[impl] Internal implementation of a child node.
Definition: uchild.hpp:23