gcp/application.h

00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * application.h 
00006  *
00007  * Copyright (C) 2004-2007 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
00023  */
00024 
00025 #ifndef GCHEMPAINT_APPLICATION_H
00026 #define GCHEMPAINT_APPLICATION_H
00027 
00028 #include <gcu/application.h>
00029 #include <gcu/dialog.h>
00030 #include <gcu/object.h>
00031 #include <gconf/gconf-client.h>
00032 #include <set>
00033 #include <string>
00034 #include <map>
00035 #include <list>
00036 
00037 using namespace gcu;
00038 
00039 namespace gcp {
00040 
00041 typedef struct
00042 {
00043         char const *name;
00044         unsigned char const *data_24;
00045 } IconDesc;
00046 
00047 class Target;
00048 class NewFileDlg;
00049 class Tool;
00050 class Document;
00051 struct option_data;
00052 typedef void (*BuildMenuCb) (GtkUIManager *UIManager);
00053 
00054 class Application: public gcu::Application
00055 {
00056 public:
00057         Application ();
00058         virtual ~Application ();
00059 
00060         void ActivateTool (const string& toolname, bool activate);
00061         void ActivateWindowsActionWidget (const char *path, bool activate);
00062         virtual void ClearStatus ();
00063         virtual void SetStatusText (const char* text);
00064         virtual GtkWindow* GetWindow () = 0;
00065         void SetMenu (const string& menuname, GtkWidget* menu) {Menus[menuname] = menu;}
00066         GtkWidget* GetMenu (const string& name) {return Menus[name];}
00067         Tool* GetActiveTool () {return m_pActiveTool;}
00068         gcp::Document* GetActiveDocument () {return m_pActiveDoc;}
00069         void SetActiveDocument (gcp::Document* pDoc) {m_pActiveDoc = pDoc;}
00070         Tool* GetTool (const string& name) {return m_Tools[name];}
00071         void SetTool (const string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
00072         GtkWidget* GetToolItem(const string& name) {return ToolItems[name];}
00073         void SetToolItem (const string& name, GtkWidget* w) {ToolItems[name] = w;}
00074         void SetCurZ (int Z) {m_CurZ = Z;}
00075         int GetCurZ () {return m_CurZ;}
00076         void OnSaveAs ();
00077         bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
00078         void SaveWithBabel (string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00079         void OpenWithBabel (string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00080         void SaveGcp (string const &filename, gcp::Document* pDoc);
00081         void OpenGcp (string const &filename, gcp::Document* pDoc);
00082         xmlDocPtr GetXmlDoc () {return XmlDoc;}
00083         void SetCallback (const string& name, GCallback cb) {Callbacks[name] = cb;}
00084         GCallback GetCallback (const string& name) {return Callbacks[name];}
00085         void OnSaveAsImage ();
00086         bool HaveGhemical () {return m_Have_Ghemical;}
00087         bool HaveInChI () {return m_Have_InChI;}
00088         int GetDocsNumber () {return m_Docs.size ();}
00089         void Zoom (double zoom);
00090         void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
00091         void RegisterToolbar (char const *name, int index);
00092         void OnToolChanged (GtkAction *current);
00093         void AddTarget (Target *target);
00094         void DeleteTarget (Target *target);
00095         void NotifyIconification (bool iconified);
00096         void NotifyFocus (bool has_focus, Target *target = NULL);
00097         void CheckFocus ();
00098         void CloseAll ();
00099         list<string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
00100         void OnConfigChanged (GConfClient *client,  guint cnxn_id, GConfEntry *entry);
00101         list<string> &GetExtensions(string &mime_type);
00102         void OnThemeNamesChanged ();
00103 
00109         void AddMenuCallback (BuildMenuCb cb);
00110 
00117         void BuildMenu (GtkUIManager *manager);
00118 
00126         void RegisterOptions (GOptionEntry const *entries, char const *translation_domain = GETTEXT_PACKAGE);
00127 
00134         void AddOptions (GOptionContext *context);
00135 
00136         // virtual menus actions:
00137         virtual void OnFileNew (char const *Theme = NULL) = 0;
00138 
00139 protected:
00140         void InitTools();
00141         void BuildTools ();
00142         void ShowTools (bool visible);
00143 
00144 private:
00145         void TestSupportedType (char const *mime_type);
00146 
00147 protected:
00148         int m_CurZ;
00149         gcp::Document *m_pActiveDoc;
00150         Target *m_pActiveTarget;
00151         map <string, GtkWidget*> Menus;
00152         map <string, GtkWidget*> ToolItems;
00153         map <string, GtkWidget*> Toolbars;
00154         map <string, Tool*> m_Tools;
00155         map <string, GCallback> Callbacks;
00156         Tool* m_pActiveTool;
00157         static bool m_bInit, m_Have_Ghemical, m_Have_InChI;
00158         xmlDocPtr XmlDoc;
00159         unsigned m_NumWindow; //used for new files (Untitled%d)
00160 
00161 private:
00162         GtkIconFactory *IconFactory;
00163         list<char const*> UiDescs;
00164         GtkRadioActionEntry* RadioActions;
00165         int m_entries;
00166         map<int, string> ToolbarNames;
00167         unsigned m_NumDoc; //used to build the name of the action associated with the menu
00168         std::set<Target*> m_Targets;
00169         int visible_windows;
00170         list<string> m_SupportedMimeTypes;
00171         list<string> m_WriteableMimeTypes;
00172         GConfClient *m_ConfClient;
00173         guint m_NotificationId;
00174         Object *m_Dummy;
00175         list<BuildMenuCb> m_MenuCbs;
00176         list<option_data> m_Options;
00177 };
00178 
00179 }       // namespace gcp
00180 
00181 #endif //GCHEMPAINT_APPLICATION_H

Generated on Sun Sep 16 14:21:55 2007 for The Gnome Chemistry Utils by  doxygen 1.5.3