The Gnome Chemistry Utils
0.13.7
|
00001 // -*- C++ -*- 00002 00003 /* 00004 * GChemPaint library 00005 * application.h 00006 * 00007 * Copyright (C) 2004-2012 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 3 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 00417 bool Have3DSupport () {return m_HaveGhemical | m_HaveGChem3D | m_HaveAvogadro;} 00425 void AddCanvas (char const *path, gccv::Canvas *canvas) {m_ToolCanvases[path] = canvas;} 00432 void ReceiveTargets (GtkClipboard *clipboard, GtkSelectionData *selection_data); 00433 00434 protected: 00439 void InitTools(); 00444 void BuildTools () throw (std::runtime_error); 00450 void ShowTools (bool visible); 00451 00452 private: 00453 void TestSupportedType (char const *mime_type, char const* babel_type = NULL, bool writeable = false); 00454 void AddMimeType (std::list<std::string> &l, std::string const& mime_type); 00455 void UpdateAllTargets (); 00456 00457 protected: 00461 gcp::Document *m_pActiveDoc; 00465 Target *m_pActiveTarget; 00469 unsigned m_NumWindow; //used for new files (Untitled%d) 00470 00471 private: 00472 int m_CurZ; 00473 std::map <std::string, GtkWidget*> ToolItems; 00474 std::map <std::string, GtkWidget*> Toolbars; 00475 std::map <std::string, Tool*> m_Tools; 00476 Tool* m_pActiveTool; 00477 static bool m_bInit; 00478 static bool m_Have_InChI; 00479 xmlDocPtr XmlDoc; 00480 GtkIconFactory *IconFactory; 00481 std::list<char const*> UiDescs; 00482 GtkRadioActionEntry* RadioActions; 00483 int m_entries; 00484 std::map<int, std::string> ToolbarNames; 00485 unsigned m_NumDoc; //used to build the name of the action associated with the menu 00486 std::set<Target*> m_Targets; 00487 int visible_windows; 00488 std::list<std::string> m_SupportedMimeTypes; 00489 std::list<std::string> m_WriteableMimeTypes; 00490 GOConfNode *m_ConfNode; 00491 guint m_NotificationId; 00492 gcu::Object *m_Dummy; 00493 std::list<BuildMenuCb> m_MenuCbs; 00494 GdkCursor *m_Cursors[CursorMax]; 00495 std::map < std::string, gccv::Canvas * >m_ToolCanvases; 00496 00500 GCU_RO_STATIC_PROP (bool, HaveGhemical) 00504 GCU_RO_STATIC_PROP (bool, HaveGChem3D) 00508 GCU_RO_STATIC_PROP (bool, HaveAvogadro) 00512 GCU_RO_PROP (bool, UseAtomColors) 00513 }; 00514 00515 } // namespace gcp 00516 00517 #endif //GCHEMPAINT_APPLICATION_H