gcp/application.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * application.h 
00006  *
00007  * Copyright (C) 2004-2009 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
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 
00077 typedef enum {
00079         CursorUnallowed,
00081         CursorPencil,
00083         CursorMax
00084 } CursorId;
00085 
00092 class Application: public gcu::Application
00093 {
00094 public:
00098         Application ();
00102         virtual ~Application ();
00103 
00115         void ActivateTool (const std::string& toolname, bool activate);
00116 
00131         void ActivateWindowsActionWidget (const char *path, bool activate);
00135         virtual void ClearStatus ();
00141         virtual void SetStatusText (const char* text);
00146         virtual GtkWindow* GetWindow () = 0;
00150         Tool* GetActiveTool () {return m_pActiveTool;}
00154         gcp::Document* GetActiveDocument () {return m_pActiveDoc;}
00160         void SetActiveDocument (gcp::Document* pDoc) {m_pActiveDoc = pDoc;}
00165         Tool* GetTool (const std::string& name) {return m_Tools[name];}
00173         void SetTool (const std::string& toolname, Tool* tool) {m_Tools[toolname] = tool;}
00178         GtkWidget* GetToolItem(const std::string& name) {return ToolItems[name];}
00186         void SetToolItem (const std::string& name, GtkWidget* w) {ToolItems[name] = w;}
00192         void SetCurZ (int Z) {m_CurZ = Z;}
00196         int GetCurZ () {return m_CurZ;}
00200         void OnSaveAs ();
00212         bool FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, GtkWindow *window, gcu::Document *pDoc = NULL);
00220         void SaveWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00228         void OpenWithBabel (std::string const &filename, const gchar *mime_type, gcp::Document* pDoc);
00235         void SaveGcp (std::string const &filename, gcp::Document* pDoc);
00242         void OpenGcp (std::string const &filename, gcp::Document* pDoc);
00247         xmlDocPtr GetXmlDoc () {return XmlDoc;}
00251         void OnSaveAsImage ();
00255         bool HaveGhemical () {return m_Have_Ghemical;}
00259         bool HaveInChI () {return m_Have_InChI;}
00263         int GetDocsNumber () {return m_Docs.size ();}
00269         void Zoom (double zoom);
00315         void AddActions (GtkRadioActionEntry const *entries, int nb, char const *ui_description, IconDesc const *icons);
00323         void RegisterToolbar (char const *name, int index);
00329         void OnToolChanged (GtkAction *current);
00336         void AddTarget (Target *target);
00343         void DeleteTarget (Target *target);
00350         void NotifyIconification (bool iconified);
00358         void NotifyFocus (bool has_focus, Target *target = NULL);
00362         void CloseAll ();
00366         std::list<std::string> &GetSupportedMimeTypes () {return m_SupportedMimeTypes;}
00374         void OnConfigChanged (GOConfNode *node, gchar const *name);
00379         std::list<std::string> &GetExtensions(std::string &mime_type);
00380 
00385         void OnThemeNamesChanged ();
00386 
00392         void AddMenuCallback (BuildMenuCb cb);
00393 
00400         void BuildMenu (GtkUIManager *manager);
00401 
00406         gcu::Document *CreateNewDocument ();
00407 
00408         // virtual menus actions:
00416         virtual void OnFileNew (char const *Theme = NULL) = 0;
00417 
00423         GdkCursor *GetCursor (CursorId id)  {return m_Cursors[id];}
00424 
00425 protected:
00430         void InitTools();
00435         void BuildTools () throw (std::runtime_error);
00441         void ShowTools (bool visible);
00442 
00443 private:
00444         void TestSupportedType (char const *mime_type);
00445         void AddMimeType (std::list<std::string> &l, std::string const& mime_type);
00446         void UpdateAllTargets ();
00447 
00448 protected:
00452         gcp::Document *m_pActiveDoc;
00456         Target *m_pActiveTarget;
00460         unsigned m_NumWindow; //used for new files (Untitled%d)
00461 
00462 private:
00463         int m_CurZ;
00464         std::map <std::string, GtkWidget*> ToolItems;
00465         std::map <std::string, GtkWidget*> Toolbars;
00466         std::map <std::string, Tool*> m_Tools;
00467         Tool* m_pActiveTool;
00468         static bool m_bInit;
00469         static bool m_Have_Ghemical;
00470         static bool m_Have_InChI;
00471         xmlDocPtr XmlDoc;
00472         GtkIconFactory *IconFactory;
00473         std::list<char const*> UiDescs;
00474         GtkRadioActionEntry* RadioActions;
00475         int m_entries;
00476         std::map<int, std::string> ToolbarNames;
00477         unsigned m_NumDoc; //used to build the name of the action associated with the menu
00478         std::set<Target*> m_Targets;
00479         int visible_windows;
00480         std::list<std::string> m_SupportedMimeTypes;
00481         std::list<std::string> m_WriteableMimeTypes;
00482         GOConfNode *m_ConfNode;
00483         guint m_NotificationId;
00484         gcu::Object *m_Dummy;
00485         std::list<BuildMenuCb> m_MenuCbs;
00486         GdkCursor *m_Cursors[CursorMax];
00487 
00491         GCU_RO_POINTER_PROP     (GtkStyle, Style)
00492 };
00493 
00494 }       // namespace gcp
00495 
00496 #endif //GCHEMPAINT_APPLICATION_H

Generated on Fri Sep 24 15:58:41 2010 for The Gnome Chemistry Utils by  doxygen 1.5.9