The Gnome Chemistry Utils  0.14.16
gcp/application.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * GChemPaint library
5  * application.h
6  *
7  * Copyright (C) 2004-2012 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCHEMPAINT_APPLICATION_H
26 #define GCHEMPAINT_APPLICATION_H
27 
28 #include <gcugtk/application.h>
29 #include <gcu/macros.h>
30 #include <libxml/parser.h>
31 #include <set>
32 #include <string>
33 #include <map>
34 #include <stdexcept>
35 
36 namespace gccv {
37  class Canvas;
38 }
39 
40 namespace gcu {
41  class Dialog;
42  class Object;
43 }
44 
52 namespace gcp {
53 
58 typedef struct
59 {
63  char const *name;
67  char const *tip;
71  unsigned bar;
76  unsigned group;
80  char const *icon_name;
85  GtkWidget *widget;
86 } ToolDesc;
87 
88 // standard toolbars
89 enum {
90  SelectionToolbar,
91  AtomToolbar,
92  BondToolbar,
93  RingToolbar,
94  ArrowToolbar,
95  MaxToolbar
96 };
97 
98 class Target;
99 class NewFileDlg;
100 class Tool;
101 class Document;
102 typedef void (*BuildMenuCb) (gcu::UIManager *UIManager);
103 
109 typedef enum {
116 } CursorId;
117 
125 {
126 friend class ApplicationPrivate;
127 public:
131  Application (gcugtk::CmdContextGtk *cc = NULL);
135  virtual ~Application ();
136 
148  void ActivateTool (const std::string& toolname, bool activate);
149 
164  void ActivateWindowsActionWidget (const char *path, bool activate);
168  virtual void ClearStatus ();
174  virtual void SetStatusText (const char* text);
179  virtual GtkWindow* GetWindow () = 0;
183  Tool* GetActiveTool () {return m_pActiveTool;}
187  gcp::Document* GetActiveDocument () {return m_pActiveDoc;}
193  void SetActiveDocument (gcp::Document* pDoc) {m_pActiveDoc = pDoc;}
198  Tool* GetTool (const std::string& name) {return m_Tools[name];}
206  void SetTool (const std::string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
211  GtkWidget* GetToolItem(const std::string& name) {return ToolItems[name];}
219  void SetToolItem (const std::string& name, GtkWidget* w) {ToolItems[name] = w;}
225  void SetCurZ (int Z) {m_CurZ = Z;}
229  int GetCurZ () {return m_CurZ;}
233  void OnSaveAs ();
245  bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
252  void SaveGcp (std::string const &filename, gcp::Document* pDoc);
259  void OpenGcp (std::string const &filename, gcp::Document* pDoc);
264  xmlDocPtr GetXmlDoc () {return XmlDoc;}
268  void OnSaveAsImage ();
272  bool HaveInChI () {return m_Have_InChI;}
276  int GetDocsNumber () {return m_Docs.size ();}
282  void Zoom (double zoom);
288  void AddTools (ToolDesc const *tools);
296  void RegisterToolbar (char const *name, int index);
302  void OnToolChanged (char const *new_tool_name);
309  void AddTarget (Target *target);
316  void DeleteTarget (Target *target);
323  void NotifyIconification (bool iconified);
331  void NotifyFocus (bool has_focus, Target *target = NULL);
335  void CloseAll ();
339  std::list<std::string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
347  void OnConfigChanged (GOConfNode *node, gchar const *name);
352  std::list<std::string> &GetExtensions(std::string &mime_type);
353 
358  void OnThemeNamesChanged ();
359 
365  void AddMenuCallback (BuildMenuCb cb);
366 
373  void BuildMenu (gcu::UIManager *manager);
374 
379  gcu::Document *CreateNewDocument ();
380 
381  // virtual menus actions:
389  virtual void OnFileNew (char const *Theme = NULL) = 0;
390 
396  GdkCursor *GetCursor (CursorId id) {return m_Cursors[id];}
397 
401  bool Have3DSupport () {return m_HaveGhemical | m_HaveGChem3D | m_HaveAvogadro;}
408  void ReceiveTargets (GtkClipboard *clipboard, GtkSelectionData *selection_data);
412  std::list < ToolDesc const * > const &GetToolDescriptions () const {return m_ToolDescriptions;}
413 
414 protected:
419  void InitTools();
424  void BuildTools () throw (std::runtime_error);
430  void ShowTools (bool visible);
431 
432 private:
433  void TestSupportedType (char const *mime_type, char const* babel_type = NULL, bool writeable = false);
434  void AddMimeType (std::list<std::string> &l, std::string const& mime_type);
435  void UpdateAllTargets ();
436 
437 protected:
449  unsigned m_NumWindow; //used for new files (Untitled%d)
450 
451 private:
452  int m_CurZ;
453  std::map <std::string, GtkWidget*> ToolItems;
454  std::map <std::string, GtkWidget*> Toolbars;
455  std::map <std::string, Tool*> m_Tools;
456  Tool* m_pActiveTool;
457  static bool m_bInit;
458  static bool m_Have_InChI;
459  xmlDocPtr XmlDoc;
460  GtkIconFactory *IconFactory;
461  std::list<char const*> UiDescs;
462  GtkRadioActionEntry* RadioActions;
463  int m_entries;
464  std::map<int, std::string> ToolbarNames;
465  unsigned m_NumDoc; //used to build the name of the action associated with the menu
466  std::set<Target*> m_Targets;
467  int visible_windows;
468  std::list<std::string> m_SupportedMimeTypes;
469  std::list<std::string> m_WriteableMimeTypes;
470  GOConfNode *m_ConfNode;
471  guint m_NotificationId;
472  gcu::Object *m_Dummy;
473  std::list<BuildMenuCb> m_MenuCbs;
474  GdkCursor *m_Cursors[CursorMax];
475  std::list < ToolDesc const * > m_ToolDescriptions;
476 
480  GCU_RO_STATIC_PROP (bool, HaveGhemical)
484  GCU_RO_STATIC_PROP (bool, HaveGChem3D)
488  GCU_RO_STATIC_PROP (bool, HaveAvogadro)
492  GCU_RO_PROP (bool, UseAtomColors)
493 };
494 
495 } // namespace gcp
496 
497 #endif //GCHEMPAINT_APPLICATION_H
xmlDocPtr GetXmlDoc()
themes class.
Definition: theme.h:67
GChemPaint specific C++ classes.
A Gtk+ using gcu::CmdContext implementation.
GdkCursor * GetCursor(CursorId id)
char const * icon_name
#define GCU_RO_PROP(type, member)
Definition: macros.h:117
GtkWidget * widget
void SetActiveDocument(gcp::Document *pDoc)
the Canvas class
Definition: canvas.h:53
gcp::Document * m_pActiveDoc
char const * tip
std::list< ToolDesc const *> const & GetToolDescriptions() const
std::list< std::string > & GetSupportedMimeTypes()
base class for a user interface manager
Definition: ui-manager.h:33
char const * name
Gnome Chemistry Canvas library namespace.
The Gnome Chemistry Utils C++ classes.
void SetCurZ(int Z)
gcp::Document * GetActiveDocument()
#define GCU_RO_STATIC_PROP(type, member)
Definition: macros.h:136
void SetToolItem(const std::string &name, GtkWidget *w)
void SetTool(const std::string &toolname, Tool *tool)
Definition: tool.h:56
CursorId
Cursors.
GChemPaint application base class.
GtkWidget * GetToolItem(const std::string &name)
Target * m_pActiveTarget
Tool * GetTool(const std::string &name)