gcu/application.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef GCU_APPLICATION_H
00026 #define GCU_APPLICATION_H
00027
00028 #include "dialog-owner.h"
00029 #include "structs.h"
00030 #include "object.h"
00031 #include <list>
00032 #include <map>
00033 #include <set>
00034 #include <string>
00035 #include <gcu/macros.h>
00036
00038 namespace gcu {
00039
00040 class Document;
00041 class Dialog;
00042 struct option_data;
00043 class TypeDesc;
00044 class CmdContext;
00045
00049 typedef enum {
00053 NormalWindowState,
00057 MaximizedWindowState,
00061 MinimizedWindowState,
00065 FullScreenWindowState
00066 } WindowState;
00067
00068 #define GCU_CONF_DIR "gchemutils"
00069
00073 class Application: virtual public DialogOwner
00074 {
00075 friend class Document;
00076 friend class Dialog;
00077 friend class ApplicationPrivate;
00078 public:
00090 Application (std::string name, std::string datadir = DATADIR, char const *help_name = NULL, char const *icon_name = NULL, CmdContext *cc = NULL);
00094 virtual ~Application ();
00095
00104 void OnHelp (std::string s = "");
00108 bool HasHelp ();
00112 std::string &GetName () {return Name;}
00113
00117 virtual GtkWindow * GetWindow () {return NULL;}
00118
00132 virtual bool FileProcess (G_GNUC_UNUSED const gchar* filename, G_GNUC_UNUSED const gchar* mime_type, G_GNUC_UNUSED bool bSave, G_GNUC_UNUSED GtkWindow *window, G_GNUC_UNUSED Document *pDoc = NULL)
00133 {return false;}
00134
00138 char const* GetCurDir () {return CurDir.c_str ();}
00139
00143 void SetCurDir (char const* dir);
00144
00148 void SetCurDir (std::string const &dir);
00149
00155 void ShowURI (std::string& uri);
00156
00162 void OnBug (char const *uri = PACKAGE_BUGREPORT)
00163 {std::string s (uri); ShowURI (s);}
00164
00169 void OnWeb (char const *uri = "http://gchemutils.nongnu.org/")
00170 {std::string s (uri); ShowURI (s);}
00171
00178 void OnMail (char const *MailAddress = "mailto:gchemutils-main@nongnu.org");
00179
00183 void OnLiveAssistance ();
00184
00189 GtkWidget *GetImageResolutionWidget ();
00190
00195 GtkWidget *GetImageSizeWidget ();
00196
00200 std::map<std::string, GdkPixbufFormat*> &GetSupportedPixbufFormats () {return m_SupportedPixbufFormats;}
00201
00211 char const *GetPixbufTypeName (std::string& filename, char const *mime_type);
00212
00222 ContentType Load (std::string const &uri, const gchar *mime_type, Document* Doc);
00223
00234 bool Save (std::string const &uri, const gchar *mime_type, Document const *Doc, ContentType type);
00235
00240 virtual Document *CreateNewDocument () {return NULL;}
00241
00246 static GOConfNode *GetConfDir ();
00247
00252 std::string const &GetIconName () {return IconName;}
00253
00261 void RegisterOptions (GOptionEntry const *entries, char const *translation_domain = GETTEXT_PACKAGE);
00262
00269 void AddOptions (GOptionContext *context);
00273 static WindowState GetDefaultWindowState () {return DefaultWindowState;}
00278 static Application *GetDefaultApplication ();
00279 static Application *GetApplication (char const *name);
00280 static Application *GetApplication (std::string &name);
00281
00282
00292 TypeId AddType (std::string TypeName, Object* (*CreateFunc) (), TypeId id = OtherType);
00293
00304 Object* CreateObject (const std::string& TypeName, Object* parent = NULL);
00305
00316 bool BuildObjectContextualMenu (Object *target, GtkUIManager *UIManager, Object *object, double x, double y);
00324 void AddRule (TypeId type1, RuleId rule, TypeId type2);
00332 void AddRule (const std::string& type1, RuleId rule, const std::string& type2);
00339 const std::set<TypeId>& GetRules (TypeId type, RuleId rule);
00340
00347 const std::set<TypeId>& GetRules (const std::string& type, RuleId rule);
00348
00356 void SetCreationLabel (TypeId Id, std::string Label);
00357
00363 const std::string& GetCreationLabel (TypeId Id);
00364
00370 const std::string& GetCreationLabel (const std::string& TypeName);
00371
00378 void AddMenuCallback (TypeId Id, BuildMenuCb cb);
00379
00380 TypeDesc const *GetTypeDescription (TypeId Id);
00381 CmdContext *GetCmdContext ();
00382
00383 protected:
00384
00390 virtual void NoMoreDocsEvent () {gtk_main_quit ();}
00391
00392 private:
00393 void AddDocument (Document *Doc) {m_Docs.insert (Doc);}
00394 void RemoveDocument (Document *Doc);
00395
00396 private:
00397 std::string Name;
00398 std::string HelpName;
00399 std::string HelpBrowser;
00400 std::string HelpFilename;
00401 std::string CurDir;
00402 std::string IconName;
00403 static GOConfNode *m_ConfDir;
00404 std::list<option_data> m_Options;
00405 static WindowState DefaultWindowState;
00406 std::map<TypeId, TypeDesc> m_Types;
00407
00408 protected:
00412 std::map<std::string, GdkPixbufFormat*> m_SupportedPixbufFormats;
00413
00414 CmdContext *m_CmdContext;
00415
00422 GCU_PROT_PROP (std::set <Document*>, Docs)
00426 GCU_RO_PROP (unsigned, ScreenResolution)
00440 GCU_PROP (unsigned, ImageResolution)
00454 GCU_PROP (unsigned, ImageWidth)
00468 GCU_PROP (unsigned, ImageHeight)
00480 GCU_PROP (bool, TransparentBackground)
00484 GCU_RO_PROP (GtkRecentManager*, RecentManager)
00485 };
00486
00487 }
00488
00489 #endif // GCU_APPLICATION_H