The Gnome Chemistry Utils  0.14.0
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  unsigned char const *data_24;
72 } IconDesc;
73 
74 class Target;
75 class NewFileDlg;
76 class Tool;
77 class Document;
78 typedef void (*BuildMenuCb) (gcu::UIManager *UIManager);
79 
85 typedef enum {
92 } CursorId;
93 
101 {
102 friend class ApplicationPrivate;
103 public:
107  Application (gcugtk::CmdContextGtk *cc = NULL);
111  virtual ~Application ();
112 
124  void ActivateTool (const std::string& toolname, bool activate);
125 
140  void ActivateWindowsActionWidget (const char *path, bool activate);
144  virtual void ClearStatus ();
150  virtual void SetStatusText (const char* text);
155  virtual GtkWindow* GetWindow () = 0;
159  Tool* GetActiveTool () {return m_pActiveTool;}
174  Tool* GetTool (const std::string& name) {return m_Tools[name];}
182  void SetTool (const std::string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
187  GtkWidget* GetToolItem(const std::string& name) {return ToolItems[name];}
195  void SetToolItem (const std::string& name, GtkWidget* w) {ToolItems[name] = w;}
201  void SetCurZ (int Z) {m_CurZ = Z;}
205  int GetCurZ () {return m_CurZ;}
209  void OnSaveAs ();
221  bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
228  void SaveGcp (std::string const &filename, gcp::Document* pDoc);
235  void OpenGcp (std::string const &filename, gcp::Document* pDoc);
240  xmlDocPtr GetXmlDoc () {return XmlDoc;}
244  void OnSaveAsImage ();
248  bool HaveInChI () {return m_Have_InChI;}
252  int GetDocsNumber () {return m_Docs.size ();}
258  void Zoom (double zoom);
304  void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
312  void RegisterToolbar (char const *name, int index);
318  void OnToolChanged (GtkAction *current);
325  void AddTarget (Target *target);
332  void DeleteTarget (Target *target);
339  void NotifyIconification (bool iconified);
347  void NotifyFocus (bool has_focus, Target *target = NULL);
351  void CloseAll ();
355  std::list<std::string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
363  void OnConfigChanged (GOConfNode *node, gchar const *name);
368  std::list<std::string> &GetExtensions(std::string &mime_type);
369 
374  void OnThemeNamesChanged ();
375 
381  void AddMenuCallback (BuildMenuCb cb);
382 
389  void BuildMenu (gcu::UIManager *manager);
390 
396 
397  // virtual menus actions:
405  virtual void OnFileNew (char const *Theme = NULL) = 0;
406 
412  GdkCursor *GetCursor (CursorId id) {return m_Cursors[id];}
413 
417  bool Have3DSupport () {return m_HaveGhemical | m_HaveGChem3D | m_HaveAvogadro;}
425  void AddCanvas (char const *path, gccv::Canvas *canvas) {m_ToolCanvases[path] = canvas;}
432  void ReceiveTargets (GtkClipboard *clipboard, GtkSelectionData *selection_data);
433 
434 protected:
439  void InitTools();
444  void BuildTools () throw (std::runtime_error);
450  void ShowTools (bool visible);
451 
452 private:
453  void TestSupportedType (char const *mime_type, char const* babel_type = NULL, bool writeable = false);
454  void AddMimeType (std::list<std::string> &l, std::string const& mime_type);
455  void UpdateAllTargets ();
456 
457 protected:
469  unsigned m_NumWindow; //used for new files (Untitled%d)
470 
471 private:
472  int m_CurZ;
473  std::map <std::string, GtkWidget*> ToolItems;
474  std::map <std::string, GtkWidget*> Toolbars;
475  std::map <std::string, Tool*> m_Tools;
476  Tool* m_pActiveTool;
477  static bool m_bInit;
478  static bool m_Have_InChI;
479  xmlDocPtr XmlDoc;
480  GtkIconFactory *IconFactory;
481  std::list<char const*> UiDescs;
482  GtkRadioActionEntry* RadioActions;
483  int m_entries;
484  std::map<int, std::string> ToolbarNames;
485  unsigned m_NumDoc; //used to build the name of the action associated with the menu
486  std::set<Target*> m_Targets;
487  int visible_windows;
488  std::list<std::string> m_SupportedMimeTypes;
489  std::list<std::string> m_WriteableMimeTypes;
490  GOConfNode *m_ConfNode;
491  guint m_NotificationId;
492  gcu::Object *m_Dummy;
493  std::list<BuildMenuCb> m_MenuCbs;
494  GdkCursor *m_Cursors[CursorMax];
495  std::map < std::string, gccv::Canvas * >m_ToolCanvases;
496 
500  GCU_RO_STATIC_PROP (bool, HaveGhemical)
504  GCU_RO_STATIC_PROP (bool, HaveGChem3D)
508  GCU_RO_STATIC_PROP (bool, HaveAvogadro)
512  GCU_RO_PROP (bool, UseAtomColors)
513 };
514 
515 } // namespace gcp
516 
517 #endif //GCHEMPAINT_APPLICATION_H