00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _udoc_hpp_
00021 #define _udoc_hpp_
00022
00023 #include <list>
00024 #include <map>
00025 #include <ubit/uprop.hpp>
00026 #include <ubit/ustr.hpp>
00027 #include <ubit/uboxes.hpp>
00028 namespace ubit {
00029
00030 class UDocCreator;
00031 class UDocAttachment;
00032
00035 typedef std::list<UDocAttachment*> UDocAttachments;
00036
00037
00041 class UDocFactory {
00042 public:
00043 UDocFactory();
00044 virtual ~UDocFactory();
00045
00046 static UDocFactory& getDefaultFactory();
00050 virtual UDoc* create(const UStr& name);
00056 virtual UDoc* load(const UStr& name, const UStr& buffer);
00062 virtual UDoc* read(const UStr& filename);
00068 virtual int getStatus() const;
00076 virtual void saveErrors(bool);
00077 virtual UStr* getErrors() const;
00082 virtual UDocCreator* getCreator(const UStr& type);
00092 virtual UDocCreator* getDefaultCreator();
00094
00095 virtual void addCreator(const UStr& type, UDocCreator&);
00097
00098 virtual void setDefaultCreator(UDocCreator&);
00100
00101
00102 protected:
00103 struct Comp {
00104 bool operator()(const UStr* s1, const UStr* s2) const;
00105 };
00106 typedef std::map<const UStr*, UDocCreator*, Comp> Map;
00107 Map rmap;
00108 UDocCreator* default_creator;
00109 int stat;
00110 uptr<UStr> errors;
00111 };
00112
00113
00114
00126 class UDoc : public UVbox {
00127 public:
00128 UBIT_ELEMENT_CLASS(UDoc, UVbox)
00129
00130 static UDocFactory& getDefaultFactory();
00132
00133 virtual ~UDoc();
00134
00135
00136
00137 virtual bool isEditable() const;
00138 virtual void setEditable(bool state = true);
00139
00140 virtual const UStr& getPath() const {return *ppath;}
00142
00143 virtual void setPath(const UStr& path);
00144 virtual void makePath(UStr& fullpath, const UStr& url);
00150 virtual const UDocAttachments* getAttachments() const {return null;}
00152
00153 virtual int loadAttachments(bool reload = false) {return 0;}
00160 virtual bool loadAttachment(UDocAttachment*, bool reload = false) {return false;}
00162
00163 virtual void onElementEvent(const UArgs&);
00174
00175
00176
00177 virtual void dispatchEvent(UEvent&, const UStr* path);
00178
00179 protected:
00180 friend class UDoc::Class;
00181 UDoc();
00182 UDoc(const UStr& path);
00184
00185 private:
00186 uptr<UStr> ppath;
00187 uptr<UGroup> call_list;
00188 UDoc(const UDoc&);
00189 UDoc& operator=(const UDoc&);
00190 };
00191
00192
00195 class UDocAttachment {
00196 public:
00197 virtual ~UDocAttachment() {}
00198 virtual const UStr* getUrl() const = 0;
00199 virtual const UStr* getType() const = 0;
00200 virtual bool isLoaded() const = 0;
00201 virtual int load(UDoc*) = 0;
00202 };
00203
00204
00207 struct UDocSource {
00208 enum From {PATHNAME, BUFFER, SCRATCH};
00209
00210 UDocSource(int from, const UStr* path, UStr* errors,
00211 const UStr* buffer = null);
00212 int from;
00213 int stat;
00214 uptr<const UStr> path, fullpath;
00215 const UStr* buffer;
00216 UStr* errors;
00217 };
00218
00219
00222 class UDocCreator {
00223 public:
00224 virtual ~UDocCreator() {}
00225 virtual UDoc* create(UDocSource&) = 0;
00227 };
00228
00229
00233 class UFlatDoc : public UDoc {
00234 public:
00235 UFlatDoc(const UStr& _pathname);
00236 virtual bool isEditable() const;
00237 virtual void setEditable(bool state = true);
00238 uptr<class UEdit> edit;
00239 };
00240
00241
00244 class UPluginDoc : public UDoc {
00245 public:
00246 UPluginDoc(const UStr& _pathname);
00247
00248 };
00249
00250 }
00251 #endif
00252