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 
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         // virtual menus actions:
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         void UpdateAllTargets ();
00434 
00435 protected:
00439         gcp::Document *m_pActiveDoc;
00443         Target *m_pActiveTarget;
00447         unsigned m_NumWindow; //used for new files (Untitled%d)
00448 
00449 private:
00450         int m_CurZ;
00451         std::map <std::string, GtkWidget*> ToolItems;
00452         std::map <std::string, GtkWidget*> Toolbars;
00453         std::map <std::string, Tool*> m_Tools;
00454         Tool* m_pActiveTool;
00455         static bool m_bInit;
00456         static bool m_Have_Ghemical;
00457         static bool m_Have_InChI;
00458         xmlDocPtr XmlDoc;
00459         GtkIconFactory *IconFactory;
00460         std::list<char const*> UiDescs;
00461         GtkRadioActionEntry* RadioActions;
00462         int m_entries;
00463         std::map<int, std::string> ToolbarNames;
00464         unsigned m_NumDoc; //used to build the name of the action associated with the menu
00465         std::set<Target*> m_Targets;
00466         int visible_windows;
00467         std::list<std::string> m_SupportedMimeTypes;
00468         std::list<std::string> m_WriteableMimeTypes;
00469         GOConfNode *m_ConfNode;
00470         guint m_NotificationId;
00471         gcu::Object *m_Dummy;
00472         std::list<BuildMenuCb> m_MenuCbs;
00473         GdkCursor *m_Cursors[CursorMax];
00474 
00475 GCU_RO_POINTER_PROP     (GtkStyle, Style)
00476 };
00477 
00478 }       // namespace gcp
00479 
00480 #endif //GCHEMPAINT_APPLICATION_H

Generated on Thu Dec 31 11:27:58 2009 for The Gnome Chemistry Utils by  doxygen 1.6.1