The Gnome Chemistry Utils  0.12.13
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-2009 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 2 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 <gcu/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 gcu {
37  class Dialog;
38  class Object;
39 }
40 
48 namespace gcp {
49 
54 typedef struct
55 {
59  char const *name;
63  unsigned char const *data_24;
64 } IconDesc;
65 
66 class Target;
67 class NewFileDlg;
68 class Tool;
69 class Document;
70 typedef void (*BuildMenuCb) (GtkUIManager *UIManager);
71 
77 typedef enum {
84 } CursorId;
85 
93 {
94 public:
98  Application ();
102  virtual ~Application ();
103 
115  void ActivateTool (const std::string& toolname, bool activate);
116 
131  void ActivateWindowsActionWidget (const char *path, bool activate);
135  virtual void ClearStatus ();
141  virtual void SetStatusText (const char* text);
146  virtual GtkWindow* GetWindow () = 0;
150  Tool* GetActiveTool () {return m_pActiveTool;}
165  Tool* GetTool (const std::string& name) {return m_Tools[name];}
173  void SetTool (const std::string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
178  GtkWidget* GetToolItem(const std::string& name) {return ToolItems[name];}
186  void SetToolItem (const std::string& name, GtkWidget* w) {ToolItems[name] = w;}
192  void SetCurZ (int Z) {m_CurZ = Z;}
196  int GetCurZ () {return m_CurZ;}
200  void OnSaveAs ();
212  bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
220  void SaveWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
228  void OpenWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
235  void SaveGcp (std::string const &filename, gcp::Document* pDoc);
242  void OpenGcp (std::string const &filename, gcp::Document* pDoc);
247  xmlDocPtr GetXmlDoc () {return XmlDoc;}
251  void OnSaveAsImage ();
255  bool HaveGhemical () {return m_Have_Ghemical;}
259  bool HaveInChI () {return m_Have_InChI;}
263  int GetDocsNumber () {return m_Docs.size ();}
269  void Zoom (double zoom);
315  void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
323  void RegisterToolbar (char const *name, int index);
329  void OnToolChanged (GtkAction *current);
336  void AddTarget (Target *target);
343  void DeleteTarget (Target *target);
350  void NotifyIconification (bool iconified);
358  void NotifyFocus (bool has_focus, Target *target = NULL);
362  void CloseAll ();
366  std::list<std::string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
374  void OnConfigChanged (GOConfNode *node, gchar const *name);
379  std::list<std::string> &GetExtensions(std::string &mime_type);
380 
385  void OnThemeNamesChanged ();
386 
392  void AddMenuCallback (BuildMenuCb cb);
393 
400  void BuildMenu (GtkUIManager *manager);
401 
407 
408  // virtual menus actions:
416  virtual void OnFileNew (char const *Theme = NULL) = 0;
417 
423  GdkCursor *GetCursor (CursorId id) {return m_Cursors[id];}
424 
425 protected:
430  void InitTools();
435  void BuildTools () throw (std::runtime_error);
441  void ShowTools (bool visible);
442 
443 private:
444  void TestSupportedType (char const *mime_type);
445  void AddMimeType (std::list<std::string> &l, std::string const& mime_type);
446  void UpdateAllTargets ();
447 
448 protected:
460  unsigned m_NumWindow; //used for new files (Untitled%d)
461 
462 private:
463  int m_CurZ;
464  std::map <std::string, GtkWidget*> ToolItems;
465  std::map <std::string, GtkWidget*> Toolbars;
466  std::map <std::string, Tool*> m_Tools;
467  Tool* m_pActiveTool;
468  static bool m_bInit;
469  static bool m_Have_Ghemical;
470  static bool m_Have_InChI;
471  xmlDocPtr XmlDoc;
472  GtkIconFactory *IconFactory;
473  std::list<char const*> UiDescs;
474  GtkRadioActionEntry* RadioActions;
475  int m_entries;
476  std::map<int, std::string> ToolbarNames;
477  unsigned m_NumDoc; //used to build the name of the action associated with the menu
478  std::set<Target*> m_Targets;
479  int visible_windows;
480  std::list<std::string> m_SupportedMimeTypes;
481  std::list<std::string> m_WriteableMimeTypes;
482  GOConfNode *m_ConfNode;
483  guint m_NotificationId;
484  gcu::Object *m_Dummy;
485  std::list<BuildMenuCb> m_MenuCbs;
486  GdkCursor *m_Cursors[CursorMax];
487 
492 };
493 
494 } // namespace gcp
495 
496 #endif //GCHEMPAINT_APPLICATION_H