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 Window;
00048 class NewFileDlg;
00049 class Tool;
00050 class Document;
00051 typedef void (*BuildMenuCb) (GtkUIManager *UIManager);
00052 
00053 class Application: public gcu::Application
00054 {
00055 public:
00056         Application ();
00057         virtual ~Application ();
00058 
00059         void ActivateTool (const string& toolname, bool activate);
00060         void ActivateWindowsActionWidget (const char *path, bool activate);
00061         virtual void ClearStatus ();
00062         virtual void SetStatusText (const char* text);
00063         virtual GtkWindow* GetWindow () = 0;
00064         void SetMenu (const string& menuname, GtkWidget* menu) {Menus[menuname] = menu;}
00065         GtkWidget* GetMenu (const string& name) {return Menus[name];}
00066         Tool* GetActiveTool () {return m_pActiveTool;}
00067         gcp::Document* GetActiveDocument () {return m_pActiveDoc;}
00068         void SetActiveDocument (gcp::Document* pDoc) {m_pActiveDoc = pDoc;}
00069         Tool* GetTool (const string& name) {return m_Tools[name];}
00070         void SetTool (const string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
00071         GtkWidget* GetToolItem(const string& name) {return ToolItems[name];}
00072         void SetToolItem (const string& name, GtkWidget* w) {ToolItems[name] = w;}
00073         void SetCurZ (int Z) {m_CurZ = Z;}
00074         int GetCurZ () {return m_CurZ;}
00075         void OnSaveAs ();
00076         bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
00077         void SaveWithBabel (string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00078         void OpenWithBabel (string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00079         void SaveGcp (string const &filename, gcp::Document* pDoc);
00080         void OpenGcp (string const &filename, gcp::Document* pDoc);
00081         xmlDocPtr GetXmlDoc () {return XmlDoc;}
00082         void SetCallback (const string& name, GCallback cb) {Callbacks[name] = cb;}
00083         GCallback GetCallback (const string& name) {return Callbacks[name];}
00084         void OnSaveAsImage ();
00085         bool HaveGhemical () {return m_Have_Ghemical;}
00086         bool HaveInChI () {return m_Have_InChI;}
00087         int GetDocsNumber () {return m_Docs.size ();}
00088         void Zoom (double zoom);
00089         void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
00090         void RegisterToolbar (char const *name, int index);
00091         void OnToolChanged (GtkAction *current);
00092         void AddWindow (Window *window);
00093         void DeleteWindow (Window *window);
00094         void NotifyIconification (bool iconified);
00095         void NotifyFocus (bool has_focus, Window *window = NULL);
00096         void CheckFocus ();
00097         void CloseAll ();
00098         list<string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
00099         void OnConfigChanged (GConfClient *client,  guint cnxn_id, GConfEntry *entry);
00100         list<string> &GetExtensions(string &mime_type);
00101         void OnThemeNamesChanged ();
00102 
00108         void AddMenuCallback (BuildMenuCb cb);
00109 
00116         void BuildMenu (GtkUIManager *manager);
00117 
00118         // virtual menus actions:
00119         virtual void OnFileNew (char const *Theme = NULL) = 0;
00120 
00121 protected:
00122         void InitTools();
00123         void BuildTools ();
00124         void ShowTools (bool visible);
00125 
00126 private:
00127         void TestSupportedType (char const *mime_type);
00128 
00129 protected:
00130         int m_CurZ;
00131         gcp::Document *m_pActiveDoc;
00132         Window *m_pActiveWin;
00133         map <string, GtkWidget*> Menus;
00134         map <string, GtkWidget*> ToolItems;
00135         map <string, GtkWidget*> Toolbars;
00136         map <string, Tool*> m_Tools;
00137         map <string, GCallback> Callbacks;
00138         Tool* m_pActiveTool;
00139         static bool m_bInit, m_Have_Ghemical, m_Have_InChI;
00140         xmlDocPtr XmlDoc;
00141         unsigned m_NumWindow; //used for new files (Untitled%d)
00142 
00143 private:
00144         GtkIconFactory *IconFactory;
00145         list<char const*> UiDescs;
00146         GtkRadioActionEntry* RadioActions;
00147         int m_entries;
00148         map<int, string> ToolbarNames;
00149         unsigned m_NumDoc; //used to build the name of the action associated with the menu
00150         std::set<Window*> m_Windows;
00151         int visible_windows;
00152         list<string> m_SupportedMimeTypes;
00153         list<string> m_WriteableMimeTypes;
00154         GConfClient *m_ConfClient;
00155         guint m_NotificationId;
00156         Object *m_Dummy;
00157         list<BuildMenuCb> m_MenuCbs;
00158 };
00159 
00160 }       // namespace gcp
00161 
00162 #endif //GCHEMPAINT_APPLICATION_H

Generated on Thu Jun 28 09:02:00 2007 for The Gnome Chemistry Utils by  doxygen 1.5.2