The Gnome Chemistry Utils 0.13.3
gcp/view.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * view.h 
00006  *
00007  * Copyright (C) 2001-2011 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_VIEW_H
00026 #define GCHEMPAINT_VIEW_H
00027 
00030 #include <gcu/macros.h>
00031 #include <gccv/client.h>
00032 #include <list>
00033 #include <map>
00034 
00035 namespace gccv {
00036         class Canvas;
00037         class Text;
00038 }
00039 
00040 namespace gcu {
00041         class Object;
00042 };
00043 
00044 namespace gcugtk {
00045         class UIManager;
00046 }
00047 
00048 namespace gcp {
00049 
00050 class Atom;
00051 class Bond;
00052 class Document;
00053 class WidgetData;
00054 
00055 #define GCHEMPAINT_ATOM_NAME "application/x-gchempaint"
00056 extern GtkTargetEntry const targets[];
00057 
00061 class View: public gccv::Client
00062 {
00063 public:
00064         //Constructor and destructor
00072         View (Document *pDoc, bool Embedded);
00076         virtual ~View ();
00077 
00078         //Interface     
00079 public:
00083         GtkWidget* GetWidget () {return m_pWidget;}
00087         Document* GetDoc () {return m_pDoc;}
00093         void AddObject (gcu::Object *pObject);
00099         void Update (gcu::Object *pObject);
00105         GtkWidget* CreateNewWidget ();
00111         void OnDestroy (GtkWidget* widget);
00115         double GetZoomFactor ();
00119         void UpdateFont ();
00125         void Remove (gcu::Object* pObject);
00129         double GetFontHeight () {return m_dFontHeight;}
00133         gchar* GetFontName () {return m_sFontName;}
00137         gchar* GetSmallFontName () {return m_sSmallFontName;}
00141         PangoFontDescription* GetPangoFontDesc () {return m_PangoFontDesc;}
00145         PangoFontDescription* GetPangoSmallFontDesc () {return m_PangoSmallFontDesc;}
00151         void OnDeleteSelection (GtkWidget* w);
00158         void OnCopySelection (GtkWidget* w, GtkClipboard* clipboard);
00165         void OnPasteSelection (GtkWidget* w, GtkClipboard* clipboard);
00172         void OnCutSelection (GtkWidget* w, GtkClipboard* clipboard);
00180         bool OnKeyPress (GtkWidget* w, GdkEventKey* event);
00188         bool OnKeyRelease (GtkWidget* w, GdkEventKey* event);
00195         void SetTextActive (gccv::Text* item);
00202         bool PrepareUnselect ();
00209         void OnReceive (GtkClipboard* clipboard, GtkSelectionData* selection_data);
00213         void OnSelectAll ();
00217         bool IsEmbedded () {return m_bEmbedded;}
00221         int GetNbWidgets () {return m_Widgets.size ();}
00232         void ExportImage (std::string const &filename, const char* type, int resolution = -1);
00236         char *BuildSVG ();
00240         char *BuildEPS ();
00248         GdkPixbuf *BuildPixbuf (int resolution);
00253         void EnsureSize ();
00259         void Zoom (double zoom);
00265         void ShowCursor (bool show);
00269         void UpdateTheme ();
00275         void Render (cairo_t *cr);
00282         void SetSelectionState (gcu::Object *object, int state);
00283         // Signals
00284         // there is no needd to document these since the documentation in gccv/client.h is appropriate.
00285         bool OnButtonPressed (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
00286         bool OnButtonReleased (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
00287         bool OnDrag (gccv::ItemClient *client, double x, double y, unsigned state);
00288         bool OnMotion (gccv::ItemClient *client, double x, double y, unsigned state);
00289         bool OnLeaveNotify (unsigned state);
00290 
00294         WidgetData *GetData () {return m_pData;}
00295 
00296         void GetVisibleArea (double &x0, double &y0, double &x1, double &y1);
00297 
00298         //Implementation
00299 private:
00300         WidgetData* m_pData;
00301         Document* m_pDoc;
00302         GtkWidget* m_pWidget;
00303         std::list<GtkWidget*> m_Widgets;
00304         PangoFontDescription* m_PangoFontDesc, *m_PangoSmallFontDesc;
00305         double m_dFontHeight;
00306         gchar* m_sFontName, *m_sSmallFontName;
00307         int m_width, m_height;
00308         double m_lastx, m_lasty;
00309         bool m_bEmbedded;
00310         gcugtk::UIManager *m_UIManager;
00311         bool m_Dragging;
00312         gcu::Object *m_CurObject;
00313         Atom *m_CurAtom;
00314         
00315 
00319 GCU_RO_PROP (double, BaseLineOffset)
00323 GCU_RO_PROP (gccv::Text *, ActiveRichText)
00327 GCU_RO_PROP (double, CHeight)
00331 GCU_RO_PROP (double, HWidth)
00332 };
00333 
00341 void on_receive (GtkClipboard *clipboard, GtkSelectionData *selection_data, View * pView);
00342 
00343 }       //      namespace gcp
00344 
00345 #endif // GCHEMPAINT_VIEW_H