gcp/application.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef GCHEMPAINT_APPLICATION_H
00026 #define GCHEMPAINT_APPLICATION_H
00027
00028 #include <gcu/application.h>
00029 #include <gcu/macros.h>
00030 #include <libxml/parser.h>
00031 #include <set>
00032 #include <string>
00033 #include <map>
00034 #include <list>
00035 #include <stdexcept>
00036
00037 namespace gcu {
00038 class Dialog;
00039 class Object;
00040 }
00041
00049 namespace gcp {
00050
00055 typedef struct
00056 {
00060 char const *name;
00064 unsigned char const *data_24;
00065 } IconDesc;
00066
00067 class Target;
00068 class NewFileDlg;
00069 class Tool;
00070 class Document;
00071 struct option_data;
00072 typedef void (*BuildMenuCb) (GtkUIManager *UIManager);
00073
00074 typedef enum {
00075 CursorUnallowed,
00076 CursorPencil,
00077 CursorMax
00078 } CursorId;
00079
00086 class Application: public gcu::Application
00087 {
00088 public:
00092 Application ();
00096 virtual ~Application ();
00097
00109 void ActivateTool (const std::string& toolname, bool activate);
00110
00125 void ActivateWindowsActionWidget (const char *path, bool activate);
00129 virtual void ClearStatus ();
00135 virtual void SetStatusText (const char* text);
00140 virtual GtkWindow* GetWindow () = 0;
00144 Tool* GetActiveTool () {return m_pActiveTool;}
00148 gcp::Document* GetActiveDocument () {return m_pActiveDoc;}
00154 void SetActiveDocument (gcp::Document* pDoc) {m_pActiveDoc = pDoc;}
00159 Tool* GetTool (const std::string& name) {return m_Tools[name];}
00167 void SetTool (const std::string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
00172 GtkWidget* GetToolItem(const std::string& name) {return ToolItems[name];}
00180 void SetToolItem (const std::string& name, GtkWidget* w) {ToolItems[name] = w;}
00186 void SetCurZ (int Z) {m_CurZ = Z;}
00190 int GetCurZ () {return m_CurZ;}
00194 void OnSaveAs ();
00206 bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
00214 void SaveWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00222 void OpenWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00229 void SaveGcp (std::string const &filename, gcp::Document* pDoc);
00236 void OpenGcp (std::string const &filename, gcp::Document* pDoc);
00241 xmlDocPtr GetXmlDoc () {return XmlDoc;}
00245 void OnSaveAsImage ();
00249 bool HaveGhemical () {return m_Have_Ghemical;}
00253 bool HaveInChI () {return m_Have_InChI;}
00257 int GetDocsNumber () {return m_Docs.size ();}
00263 void Zoom (double zoom);
00309 void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
00317 void RegisterToolbar (char const *name, int index);
00323 void OnToolChanged (GtkAction *current);
00330 void AddTarget (Target *target);
00337 void DeleteTarget (Target *target);
00344 void NotifyIconification (bool iconified);
00352 void NotifyFocus (bool has_focus, Target *target = NULL);
00356 void CloseAll ();
00360 std::list<std::string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
00368 void OnConfigChanged (GOConfNode *node, gchar const *name);
00373 std::list<std::string> &GetExtensions(std::string &mime_type);
00374
00379 void OnThemeNamesChanged ();
00380
00386 void AddMenuCallback (BuildMenuCb cb);
00387
00394 void BuildMenu (GtkUIManager *manager);
00395
00403 void RegisterOptions (GOptionEntry const *entries, char const *translation_domain = GETTEXT_PACKAGE);
00404
00411 void AddOptions (GOptionContext *context);
00412
00417 gcu::Document *CreateNewDocument ();
00418
00419
00427 virtual void OnFileNew (char const *Theme = NULL) = 0;
00428
00429 GdkCursor *GetCursor (CursorId id) {return m_Cursors[id];}
00430
00431 protected:
00436 void InitTools();
00441 void BuildTools () throw (std::runtime_error);
00447 void ShowTools (bool visible);
00448
00449 private:
00450 void TestSupportedType (char const *mime_type);
00451 void AddMimeType (std::list<std::string> &l, std::string const& mime_type);
00452
00453 protected:
00457 gcp::Document *m_pActiveDoc;
00461 Target *m_pActiveTarget;
00465 unsigned m_NumWindow;
00466
00467 private:
00468 int m_CurZ;
00469 std::map <std::string, GtkWidget*> ToolItems;
00470 std::map <std::string, GtkWidget*> Toolbars;
00471 std::map <std::string, Tool*> m_Tools;
00472 Tool* m_pActiveTool;
00473 static bool m_bInit;
00474 static bool m_Have_Ghemical;
00475 static bool m_Have_InChI;
00476 xmlDocPtr XmlDoc;
00477 GtkIconFactory *IconFactory;
00478 std::list<char const*> UiDescs;
00479 GtkRadioActionEntry* RadioActions;
00480 int m_entries;
00481 std::map<int, std::string> ToolbarNames;
00482 unsigned m_NumDoc;
00483 std::set<Target*> m_Targets;
00484 int visible_windows;
00485 std::list<std::string> m_SupportedMimeTypes;
00486 std::list<std::string> m_WriteableMimeTypes;
00487 GOConfNode *m_ConfNode;
00488 guint m_NotificationId;
00489 gcu::Object *m_Dummy;
00490 std::list<BuildMenuCb> m_MenuCbs;
00491 std::list<option_data> m_Options;
00492 GdkCursor *m_Cursors[CursorMax];
00493
00494 GCU_RO_POINTER_PROP (GtkStyle, Style)
00495 };
00496
00497 }
00498
00499 #endif //GCHEMPAINT_APPLICATION_H