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 #ifdef HAVE_GO_CONF_SYNC
00032 #include <goffice/app/go-conf.h>
00033 #else
00034 #include <gconf/gconf-client.h>
00035 #endif
00036 #include <set>
00037 #include <string>
00038 #include <map>
00039 #include <list>
00040 
00041 namespace gcp {
00042 
00043 typedef struct
00044 {
00045         char const *name;
00046         unsigned char const *data_24;
00047 } IconDesc;
00048 
00049 class Target;
00050 class NewFileDlg;
00051 class Tool;
00052 class Document;
00053 struct option_data;
00054 typedef void (*BuildMenuCb) (GtkUIManager *UIManager);
00055 
00056 class Application: public gcu::Application
00057 {
00058 public:
00059         Application ();
00060         virtual ~Application ();
00061 
00062         void ActivateTool (const std::string& toolname, bool activate);
00063         void ActivateWindowsActionWidget (const char *path, bool activate);
00064         virtual void ClearStatus ();
00065         virtual void SetStatusText (const char* text);
00066         virtual GtkWindow* GetWindow () = 0;
00067         void SetMenu (const std::string& menuname, GtkWidget* menu) {Menus[menuname] = menu;}
00068         GtkWidget* GetMenu (const std::string& name) {return Menus[name];}
00069         Tool* GetActiveTool () {return m_pActiveTool;}
00070         gcp::Document* GetActiveDocument () {return m_pActiveDoc;}
00071         void SetActiveDocument (gcp::Document* pDoc) {m_pActiveDoc = pDoc;}
00072         Tool* GetTool (const std::string& name) {return m_Tools[name];}
00073         void SetTool (const std::string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
00074         GtkWidget* GetToolItem(const std::string& name) {return ToolItems[name];}
00075         void SetToolItem (const std::string& name, GtkWidget* w) {ToolItems[name] = w;}
00076         void SetCurZ (int Z) {m_CurZ = Z;}
00077         int GetCurZ () {return m_CurZ;}
00078         void OnSaveAs ();
00079         bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
00080         void SaveWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00081         void OpenWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00082         void SaveGcp (std::string const &filename, gcp::Document* pDoc);
00083         void OpenGcp (std::string const &filename, gcp::Document* pDoc);
00084         xmlDocPtr GetXmlDoc () {return XmlDoc;}
00085         void SetCallback (const std::string& name, GCallback cb) {Callbacks[name] = cb;}
00086         GCallback GetCallback (const std::string& name) {return Callbacks[name];}
00087         void OnSaveAsImage ();
00088         bool HaveGhemical () {return m_Have_Ghemical;}
00089         bool HaveInChI () {return m_Have_InChI;}
00090         int GetDocsNumber () {return m_Docs.size ();}
00091         void Zoom (double zoom);
00092         void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
00093         void RegisterToolbar (char const *name, int index);
00094         void OnToolChanged (GtkAction *current);
00095         void AddTarget (Target *target);
00096         void DeleteTarget (Target *target);
00097         void NotifyIconification (bool iconified);
00098         void NotifyFocus (bool has_focus, Target *target = NULL);
00099         void CheckFocus ();
00100         void CloseAll ();
00101         std::list<std::string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
00102 #ifdef HAVE_GO_CONF_SYNC
00103         void OnConfigChanged (GOConfNode *node, gchar const *name);
00104 #else
00105         void OnConfigChanged (GConfClient *client,  guint cnxn_id, GConfEntry *entry);
00106 #endif
00107         std::list<std::string> &GetExtensions(std::string &mime_type);
00108         void OnThemeNamesChanged ();
00109         void AddMimeType (std::list<std::string> &l, std::string const& mime_type);
00110 
00116         void AddMenuCallback (BuildMenuCb cb);
00117 
00124         void BuildMenu (GtkUIManager *manager);
00125 
00133         void RegisterOptions (GOptionEntry const *entries, char const *translation_domain = GETTEXT_PACKAGE);
00134 
00141         void AddOptions (GOptionContext *context);
00142 
00143         // virtual menus actions:
00144         virtual void OnFileNew (char const *Theme = NULL) = 0;
00145         gcu::Document *CreateNewDocument ();
00146 
00147 protected:
00148         void InitTools();
00149         void BuildTools ();
00150         void ShowTools (bool visible);
00151 
00152 private:
00153         void TestSupportedType (char const *mime_type);
00154 
00155 protected:
00156         int m_CurZ;
00157         gcp::Document *m_pActiveDoc;
00158         Target *m_pActiveTarget;
00159         std::map <std::string, GtkWidget*> Menus;
00160         std::map <std::string, GtkWidget*> ToolItems;
00161         std::map <std::string, GtkWidget*> Toolbars;
00162         std::map <std::string, Tool*> m_Tools;
00163         std::map <std::string, GCallback> Callbacks;
00164         Tool* m_pActiveTool;
00165         static bool m_bInit, m_Have_Ghemical, m_Have_InChI;
00166         xmlDocPtr XmlDoc;
00167         unsigned m_NumWindow; //used for new files (Untitled%d)
00168 
00169 private:
00170         GtkIconFactory *IconFactory;
00171         std::list<char const*> UiDescs;
00172         GtkRadioActionEntry* RadioActions;
00173         int m_entries;
00174         std::map<int, std::string> ToolbarNames;
00175         unsigned m_NumDoc; //used to build the name of the action associated with the menu
00176         std::set<Target*> m_Targets;
00177         int visible_windows;
00178         std::list<std::string> m_SupportedMimeTypes;
00179         std::list<std::string> m_WriteableMimeTypes;
00180 #ifdef HAVE_GO_CONF_SYNC
00181         GOConfNode *m_ConfNode;
00182 #else
00183         GConfClient *m_ConfClient;
00184 #endif
00185         guint m_NotificationId;
00186         gcu::Object *m_Dummy;
00187         std::list<BuildMenuCb> m_MenuCbs;
00188         std::list<option_data> m_Options;
00189 };
00190 
00191 }       // namespace gcp
00192 
00193 #endif //GCHEMPAINT_APPLICATION_H

Generated on Sun Jun 22 13:26:05 2008 for The Gnome Chemistry Utils by  doxygen 1.5.6