The Gnome Chemistry Utils 0.13.4
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 gccv {
00037         class Canvas;
00038 }
00039 
00040 namespace gcu {
00041         class Dialog;
00042         class Object;
00043 }
00044 
00052 namespace gcp {
00053 
00058 typedef struct
00059 {
00063         char const *name;
00067         unsigned char const *data_24;
00071         gccv::Canvas *canvas;
00072 } IconDesc;
00073 
00074 class Target;
00075 class NewFileDlg;
00076 class Tool;
00077 class Document;
00078 typedef void (*BuildMenuCb) (gcu::UIManager *UIManager);
00079 
00085 typedef enum {
00087         CursorUnallowed,
00089         CursorPencil,
00091         CursorMax
00092 } CursorId;
00093 
00100 class Application: public gcugtk::Application
00101 {
00102 friend class ApplicationPrivate;
00103 public:
00107         Application (gcugtk::CmdContextGtk *cc = NULL);
00111         virtual ~Application ();
00112 
00124         void ActivateTool (const std::string& toolname, bool activate);
00125 
00140         void ActivateWindowsActionWidget (const char *path, bool activate);
00144         virtual void ClearStatus ();
00150         virtual void SetStatusText (const char* text);
00155         virtual GtkWindow* GetWindow () = 0;
00159         Tool* GetActiveTool () {return m_pActiveTool;}
00163         gcp::Document* GetActiveDocument () {return m_pActiveDoc;}
00169         void SetActiveDocument (gcp::Document* pDoc) {m_pActiveDoc = pDoc;}
00174         Tool* GetTool (const std::string& name) {return m_Tools[name];}
00182         void SetTool (const std::string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
00187         GtkWidget* GetToolItem(const std::string& name) {return ToolItems[name];}
00195         void SetToolItem (const std::string& name, GtkWidget* w) {ToolItems[name] = w;}
00201         void SetCurZ (int Z) {m_CurZ = Z;}
00205         int GetCurZ () {return m_CurZ;}
00209         void OnSaveAs ();
00221         bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
00228         void SaveGcp (std::string const &filename, gcp::Document* pDoc);
00235         void OpenGcp (std::string const &filename, gcp::Document* pDoc);
00240         xmlDocPtr GetXmlDoc () {return XmlDoc;}
00244         void OnSaveAsImage ();
00248         bool HaveInChI () {return m_Have_InChI;}
00252         int GetDocsNumber () {return m_Docs.size ();}
00258         void Zoom (double zoom);
00304         void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
00312         void RegisterToolbar (char const *name, int index);
00318         void OnToolChanged (GtkAction *current);
00325         void AddTarget (Target *target);
00332         void DeleteTarget (Target *target);
00339         void NotifyIconification (bool iconified);
00347         void NotifyFocus (bool has_focus, Target *target = NULL);
00351         void CloseAll ();
00355         std::list<std::string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
00363         void OnConfigChanged (GOConfNode *node, gchar const *name);
00368         std::list<std::string> &GetExtensions(std::string &mime_type);
00369 
00374         void OnThemeNamesChanged ();
00375 
00381         void AddMenuCallback (BuildMenuCb cb);
00382 
00389         void BuildMenu (gcu::UIManager *manager);
00390 
00395         gcu::Document *CreateNewDocument ();
00396 
00397         // virtual menus actions:
00405         virtual void OnFileNew (char const *Theme = NULL) = 0;
00406 
00412         GdkCursor *GetCursor (CursorId id)  {return m_Cursors[id];}
00413 
00414         bool Have3DSupport () {return m_HaveGhemical | m_HaveGChem3D | m_HaveAvogadro;}
00415         void AddCanvas (char const *path, gccv::Canvas *canvas) {m_ToolCanvases[path] = canvas;}
00416 
00417 protected:
00422         void InitTools();
00427         void BuildTools () throw (std::runtime_error);
00433         void ShowTools (bool visible);
00434 
00435 private:
00436         void TestSupportedType (char const *mime_type, char const* babel_type = NULL, bool writeable = false);
00437         void AddMimeType (std::list<std::string> &l, std::string const& mime_type);
00438         void UpdateAllTargets ();
00439 
00440 protected:
00444         gcp::Document *m_pActiveDoc;
00448         Target *m_pActiveTarget;
00452         unsigned m_NumWindow; //used for new files (Untitled%d)
00453 
00454 private:
00455         int m_CurZ;
00456         std::map <std::string, GtkWidget*> ToolItems;
00457         std::map <std::string, GtkWidget*> Toolbars;
00458         std::map <std::string, Tool*> m_Tools;
00459         Tool* m_pActiveTool;
00460         static bool m_bInit;
00461         static bool m_Have_InChI;
00462         xmlDocPtr XmlDoc;
00463         GtkIconFactory *IconFactory;
00464         std::list<char const*> UiDescs;
00465         GtkRadioActionEntry* RadioActions;
00466         int m_entries;
00467         std::map<int, std::string> ToolbarNames;
00468         unsigned m_NumDoc; //used to build the name of the action associated with the menu
00469         std::set<Target*> m_Targets;
00470         int visible_windows;
00471         std::list<std::string> m_SupportedMimeTypes;
00472         std::list<std::string> m_WriteableMimeTypes;
00473         GOConfNode *m_ConfNode;
00474         guint m_NotificationId;
00475         gcu::Object *m_Dummy;
00476         std::list<BuildMenuCb> m_MenuCbs;
00477         GdkCursor *m_Cursors[CursorMax];
00478         std::map < std::string, gccv::Canvas * >m_ToolCanvases;
00479 
00480 #if 0
00481 
00484         GCU_RO_POINTER_PROP     (GtkStyle, Style)
00485 #endif
00486 
00489         GCU_RO_STATIC_PROP (bool, HaveGhemical)
00490         GCU_RO_STATIC_PROP (bool, HaveGChem3D)
00491         GCU_RO_STATIC_PROP (bool, HaveAvogadro)
00492         GCU_RO_PROP (bool, UseAtomColors)
00493 };
00494 
00495 }       // namespace gcp
00496 
00497 #endif //GCHEMPAINT_APPLICATION_H