The Gnome Chemistry Utils 0.13.3
gcp/application.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * application.h 
00006  *
00007  * Copyright (C) 2004-2011 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 <gcugtk/application.h>
00029 #include <gcu/macros.h>
00030 #include <libxml/parser.h>
00031 #include <set>
00032 #include <string>
00033 #include <map>
00034 #include <stdexcept>
00035 
00036 namespace gcu {
00037         class Dialog;
00038         class Object;
00039 }
00040 
00048 namespace gcp {
00049 
00054 typedef struct
00055 {
00059         char const *name;
00063         unsigned char const *data_24;
00064 } IconDesc;
00065 
00066 class Target;
00067 class NewFileDlg;
00068 class Tool;
00069 class Document;
00070 typedef void (*BuildMenuCb) (gcu::UIManager *UIManager);
00071 
00077 typedef enum {
00079         CursorUnallowed,
00081         CursorPencil,
00083         CursorMax
00084 } CursorId;
00085 
00092 class Application: public gcugtk::Application
00093 {
00094 friend class ApplicationPrivate;
00095 public:
00099         Application (gcugtk::CmdContextGtk *cc = NULL);
00103         virtual ~Application ();
00104 
00116         void ActivateTool (const std::string& toolname, bool activate);
00117 
00132         void ActivateWindowsActionWidget (const char *path, bool activate);
00136         virtual void ClearStatus ();
00142         virtual void SetStatusText (const char* text);
00147         virtual GtkWindow* GetWindow () = 0;
00151         Tool* GetActiveTool () {return m_pActiveTool;}
00155         gcp::Document* GetActiveDocument () {return m_pActiveDoc;}
00161         void SetActiveDocument (gcp::Document* pDoc) {m_pActiveDoc = pDoc;}
00166         Tool* GetTool (const std::string& name) {return m_Tools[name];}
00174         void SetTool (const std::string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
00179         GtkWidget* GetToolItem(const std::string& name) {return ToolItems[name];}
00187         void SetToolItem (const std::string& name, GtkWidget* w) {ToolItems[name] = w;}
00193         void SetCurZ (int Z) {m_CurZ = Z;}
00197         int GetCurZ () {return m_CurZ;}
00201         void OnSaveAs ();
00213         bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
00220         void SaveGcp (std::string const &filename, gcp::Document* pDoc);
00227         void OpenGcp (std::string const &filename, gcp::Document* pDoc);
00232         xmlDocPtr GetXmlDoc () {return XmlDoc;}
00236         void OnSaveAsImage ();
00240         bool HaveInChI () {return m_Have_InChI;}
00244         int GetDocsNumber () {return m_Docs.size ();}
00250         void Zoom (double zoom);
00296         void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
00304         void RegisterToolbar (char const *name, int index);
00310         void OnToolChanged (GtkAction *current);
00317         void AddTarget (Target *target);
00324         void DeleteTarget (Target *target);
00331         void NotifyIconification (bool iconified);
00339         void NotifyFocus (bool has_focus, Target *target = NULL);
00343         void CloseAll ();
00347         std::list<std::string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
00355         void OnConfigChanged (GOConfNode *node, gchar const *name);
00360         std::list<std::string> &GetExtensions(std::string &mime_type);
00361 
00366         void OnThemeNamesChanged ();
00367 
00373         void AddMenuCallback (BuildMenuCb cb);
00374 
00381         void BuildMenu (gcu::UIManager *manager);
00382 
00387         gcu::Document *CreateNewDocument ();
00388 
00389         // virtual menus actions:
00397         virtual void OnFileNew (char const *Theme = NULL) = 0;
00398 
00404         GdkCursor *GetCursor (CursorId id)  {return m_Cursors[id];}
00405 
00406         bool Have3DSupport () {return m_HaveGhemical | m_HaveGChem3D | m_HaveAvogadro;}
00407 
00408 protected:
00413         void InitTools();
00418         void BuildTools () throw (std::runtime_error);
00424         void ShowTools (bool visible);
00425 
00426 private:
00427         void TestSupportedType (char const *mime_type, char const* babel_type = NULL, bool writeable = false);
00428         void AddMimeType (std::list<std::string> &l, std::string const& mime_type);
00429         void UpdateAllTargets ();
00430 
00431 protected:
00435         gcp::Document *m_pActiveDoc;
00439         Target *m_pActiveTarget;
00443         unsigned m_NumWindow; //used for new files (Untitled%d)
00444 
00445 private:
00446         int m_CurZ;
00447         std::map <std::string, GtkWidget*> ToolItems;
00448         std::map <std::string, GtkWidget*> Toolbars;
00449         std::map <std::string, Tool*> m_Tools;
00450         Tool* m_pActiveTool;
00451         static bool m_bInit;
00452         static bool m_Have_InChI;
00453         xmlDocPtr XmlDoc;
00454         GtkIconFactory *IconFactory;
00455         std::list<char const*> UiDescs;
00456         GtkRadioActionEntry* RadioActions;
00457         int m_entries;
00458         std::map<int, std::string> ToolbarNames;
00459         unsigned m_NumDoc; //used to build the name of the action associated with the menu
00460         std::set<Target*> m_Targets;
00461         int visible_windows;
00462         std::list<std::string> m_SupportedMimeTypes;
00463         std::list<std::string> m_WriteableMimeTypes;
00464         GOConfNode *m_ConfNode;
00465         guint m_NotificationId;
00466         gcu::Object *m_Dummy;
00467         std::list<BuildMenuCb> m_MenuCbs;
00468         GdkCursor *m_Cursors[CursorMax];
00469 
00473         GCU_RO_POINTER_PROP     (GtkStyle, Style)
00477         GCU_RO_STATIC_PROP (bool, HaveGhemical)
00478         GCU_RO_STATIC_PROP (bool, HaveGChem3D)
00479         GCU_RO_STATIC_PROP (bool, HaveAvogadro)
00480         GCU_RO_PROP (bool, UseAtomColors)
00481 };
00482 
00483 }       // namespace gcp
00484 
00485 #endif //GCHEMPAINT_APPLICATION_H