The Gnome Chemistry Utils  0.12.11
view.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * GChemPaint library
5  * view.h
6  *
7  * Copyright (C) 2001-2008 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCHEMPAINT_VIEW_H
26 #define GCHEMPAINT_VIEW_H
27 
30 #include <gcu/macros.h>
31 #include <gccv/client.h>
32 #include <list>
33 #include <map>
34 
35 namespace gccv {
36  class Canvas;
37  class Text;
38 }
39 
40 namespace gcu {
41  class Object;
42 };
43 
44 namespace gcp {
45 
46 class Atom;
47 class Bond;
48 class Document;
49 class WidgetData;
50 
51 #define GCHEMPAINT_ATOM_NAME "application/x-gchempaint"
52 extern GtkTargetEntry const targets[];
53 
57 class View: public gccv::Client
58 {
59 public:
60  //Constructor and destructor
68  View (Document *pDoc, bool Embedded);
72  virtual ~View ();
73 
74  //Interface
75 public:
79  GtkWidget* GetWidget () {return m_pWidget;}
83  Document* GetDoc () {return m_pDoc;}
89  void AddObject (gcu::Object *pObject);
95  void Update (gcu::Object *pObject);
101  GtkWidget* CreateNewWidget ();
107  void OnDestroy (GtkWidget* widget);
111  double GetZoomFactor ();
115  void UpdateFont ();
121  void Remove (gcu::Object* pObject);
125  double GetFontHeight () {return m_dFontHeight;}
129  gchar* GetFontName () {return m_sFontName;}
133  gchar* GetSmallFontName () {return m_sSmallFontName;}
137  PangoFontDescription* GetPangoFontDesc () {return m_PangoFontDesc;}
141  PangoFontDescription* GetPangoSmallFontDesc () {return m_PangoSmallFontDesc;}
147  void OnDeleteSelection (GtkWidget* w);
154  void OnCopySelection (GtkWidget* w, GtkClipboard* clipboard);
161  void OnPasteSelection (GtkWidget* w, GtkClipboard* clipboard);
168  void OnCutSelection (GtkWidget* w, GtkClipboard* clipboard);
176  bool OnKeyPress (GtkWidget* w, GdkEventKey* event);
184  bool OnKeyRelease (GtkWidget* w, GdkEventKey* event);
191  void SetTextActive (gccv::Text* item);
198  bool PrepareUnselect ();
205  void OnReceive (GtkClipboard* clipboard, GtkSelectionData* selection_data);
209  void OnSelectAll ();
213  bool IsEmbedded () {return m_bEmbedded;}
217  int GetNbWidgets () {return m_Widgets.size ();}
228  void ExportImage (std::string const &filename, const char* type, int resolution = -1);
232  char *BuildSVG ();
236  char *BuildEPS ();
244  GdkPixbuf *BuildPixbuf (int resolution);
249  void EnsureSize ();
255  void Zoom (double zoom);
261  void ShowCursor (bool show);
265  void UpdateTheme ();
271  void Render (cairo_t *cr);
278  void SetSelectionState (gcu::Object *object, int state);
279  // Signals
280  // there is no needd to document these since the documentation in gccv/client.h is appropriate.
281  bool OnButtonPressed (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
282  bool OnButtonReleased (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
283  bool OnDrag (gccv::ItemClient *client, double x, double y, unsigned state);
284  bool OnMotion (gccv::ItemClient *client, double x, double y, unsigned state);
285  bool OnLeaveNotify (unsigned state);
286 
290  WidgetData *GetData () {return m_pData;}
291  //Implementation
292 private:
293  WidgetData* m_pData;
294  Document* m_pDoc;
295  GtkWidget* m_pWidget;
296  std::list<GtkWidget*> m_Widgets;
297  PangoFontDescription* m_PangoFontDesc, *m_PangoSmallFontDesc;
298  double m_dFontHeight;
299  gchar* m_sFontName, *m_sSmallFontName;
300  int m_width, m_height;
301  double m_lastx, m_lasty;
302  bool m_bEmbedded;
303  GtkUIManager *m_UIManager;
304  bool m_Dragging;
305  gcu::Object *m_CurObject;
306  Atom *m_CurAtom;
307 
308 
312 GCU_RO_PROP (double, BaseLineOffset)
316 GCU_RO_PROP (gccv::Text *, ActiveRichText)
320 GCU_RO_PROP (double, CHeight)
324 GCU_RO_PROP (double, HWidth)
325 };
326 
334 void on_receive (GtkClipboard *clipboard, GtkSelectionData *selection_data, View * pView);
335 
336 } // namespace gcp
337 
338 #endif // GCHEMPAINT_VIEW_H