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 <stdexcept>
00035
00036 namespace gcu {
00037 class Dialog;
00038 class Object;
00039 }
00040
00048 namespace gcp {
00049
00054 typedef struct
00055 {
00059 char const *name;
00063 unsigned char const *data_24;
00064 } IconDesc;
00065
00066 class Target;
00067 class NewFileDlg;
00068 class Tool;
00069 class Document;
00070 typedef void (*BuildMenuCb) (GtkUIManager *UIManager);
00071
00072 typedef enum {
00073 CursorUnallowed,
00074 CursorPencil,
00075 CursorMax
00076 } CursorId;
00077
00084 class Application: public gcu::Application
00085 {
00086 public:
00090 Application ();
00094 virtual ~Application ();
00095
00107 void ActivateTool (const std::string& toolname, bool activate);
00108
00123 void ActivateWindowsActionWidget (const char *path, bool activate);
00127 virtual void ClearStatus ();
00133 virtual void SetStatusText (const char* text);
00138 virtual GtkWindow* GetWindow () = 0;
00142 Tool* GetActiveTool () {return m_pActiveTool;}
00146 gcp::Document* GetActiveDocument () {return m_pActiveDoc;}
00152 void SetActiveDocument (gcp::Document* pDoc) {m_pActiveDoc = pDoc;}
00157 Tool* GetTool (const std::string& name) {return m_Tools[name];}
00165 void SetTool (const std::string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
00170 GtkWidget* GetToolItem(const std::string& name) {return ToolItems[name];}
00178 void SetToolItem (const std::string& name, GtkWidget* w) {ToolItems[name] = w;}
00184 void SetCurZ (int Z) {m_CurZ = Z;}
00188 int GetCurZ () {return m_CurZ;}
00192 void OnSaveAs ();
00204 bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
00212 void SaveWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00220 void OpenWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00227 void SaveGcp (std::string const &filename, gcp::Document* pDoc);
00234 void OpenGcp (std::string const &filename, gcp::Document* pDoc);
00239 xmlDocPtr GetXmlDoc () {return XmlDoc;}
00243 void OnSaveAsImage ();
00247 bool HaveGhemical () {return m_Have_Ghemical;}
00251 bool HaveInChI () {return m_Have_InChI;}
00255 int GetDocsNumber () {return m_Docs.size ();}
00261 void Zoom (double zoom);
00307 void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
00315 void RegisterToolbar (char const *name, int index);
00321 void OnToolChanged (GtkAction *current);
00328 void AddTarget (Target *target);
00335 void DeleteTarget (Target *target);
00342 void NotifyIconification (bool iconified);
00350 void NotifyFocus (bool has_focus, Target *target = NULL);
00354 void CloseAll ();
00358 std::list<std::string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
00366 void OnConfigChanged (GOConfNode *node, gchar const *name);
00371 std::list<std::string> &GetExtensions(std::string &mime_type);
00372
00377 void OnThemeNamesChanged ();
00378
00384 void AddMenuCallback (BuildMenuCb cb);
00385
00392 void BuildMenu (GtkUIManager *manager);
00393
00398 gcu::Document *CreateNewDocument ();
00399
00400
00408 virtual void OnFileNew (char const *Theme = NULL) = 0;
00409
00410 GdkCursor *GetCursor (CursorId id) {return m_Cursors[id];}
00411
00412 protected:
00417 void InitTools();
00422 void BuildTools () throw (std::runtime_error);
00428 void ShowTools (bool visible);
00429
00430 private:
00431 void TestSupportedType (char const *mime_type);
00432 void AddMimeType (std::list<std::string> &l, std::string const& mime_type);
00433
00434 protected:
00438 gcp::Document *m_pActiveDoc;
00442 Target *m_pActiveTarget;
00446 unsigned m_NumWindow;
00447
00448 private:
00449 int m_CurZ;
00450 std::map <std::string, GtkWidget*> ToolItems;
00451 std::map <std::string, GtkWidget*> Toolbars;
00452 std::map <std::string, Tool*> m_Tools;
00453 Tool* m_pActiveTool;
00454 static bool m_bInit;
00455 static bool m_Have_Ghemical;
00456 static bool m_Have_InChI;
00457 xmlDocPtr XmlDoc;
00458 GtkIconFactory *IconFactory;
00459 std::list<char const*> UiDescs;
00460 GtkRadioActionEntry* RadioActions;
00461 int m_entries;
00462 std::map<int, std::string> ToolbarNames;
00463 unsigned m_NumDoc;
00464 std::set<Target*> m_Targets;
00465 int visible_windows;
00466 std::list<std::string> m_SupportedMimeTypes;
00467 std::list<std::string> m_WriteableMimeTypes;
00468 GOConfNode *m_ConfNode;
00469 guint m_NotificationId;
00470 gcu::Object *m_Dummy;
00471 std::list<BuildMenuCb> m_MenuCbs;
00472 GdkCursor *m_Cursors[CursorMax];
00473
00474 GCU_RO_POINTER_PROP (GtkStyle, Style)
00475 };
00476
00477 }
00478
00479 #endif //GCHEMPAINT_APPLICATION_H