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

Generated on Thu Dec 20 11:20:45 2007 for The Gnome Chemistry Utils by  doxygen 1.5.4