The Gnome Chemistry Utils  0.14.0
gcp/view.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * GChemPaint library
5  * view.h
6  *
7  * Copyright (C) 2001-2011 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 3 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 gcugtk {
45  class UIManager;
46 }
47 
48 namespace gcp {
49 
50 class Atom;
51 class Bond;
52 class Document;
53 class WidgetData;
54 
55 #define GCHEMPAINT_ATOM_NAME "application/x-gchempaint"
56 extern GtkTargetEntry const targets[];
57 
61 class View: public gccv::Client
62 {
63 public:
64  //Constructor and destructor
72  View (Document *pDoc, bool Embedded);
76  virtual ~View ();
77 
78  //Interface
79 public:
83  GtkWidget* GetWidget () {return m_pWidget;}
87  Document* GetDoc () {return m_pDoc;}
93  void AddObject (gcu::Object *pObject);
99  void Update (gcu::Object *pObject);
105  GtkWidget* CreateNewWidget ();
111  void OnDestroy (GtkWidget* widget);
115  double GetZoomFactor ();
119  void UpdateFont ();
125  void Remove (gcu::Object* pObject);
129  double GetFontHeight () {return m_dFontHeight;}
133  gchar* GetFontName () {return m_sFontName;}
137  gchar* GetSmallFontName () {return m_sSmallFontName;}
141  PangoFontDescription* GetPangoFontDesc () {return m_PangoFontDesc;}
145  PangoFontDescription* GetPangoSmallFontDesc () {return m_PangoSmallFontDesc;}
151  void OnDeleteSelection (GtkWidget* w);
158  void OnCopySelection (GtkWidget* w, GtkClipboard* clipboard);
165  void OnPasteSelection (GtkWidget* w, GtkClipboard* clipboard);
172  void OnCutSelection (GtkWidget* w, GtkClipboard* clipboard);
180  bool OnKeyPress (GtkWidget* w, GdkEventKey* event);
188  bool OnKeyRelease (GtkWidget* w, GdkEventKey* event);
195  void SetTextActive (gccv::Text* item);
202  bool PrepareUnselect ();
209  void OnReceive (GtkClipboard* clipboard, GtkSelectionData* selection_data);
213  void OnSelectAll ();
217  bool IsEmbedded () {return m_bEmbedded;}
221  int GetNbWidgets () {return m_Widgets.size ();}
232  void ExportImage (std::string const &filename, const char* type, int resolution = -1);
236  char *BuildSVG ();
240  char *BuildEPS ();
248  GdkPixbuf *BuildPixbuf (int resolution);
253  void EnsureSize ();
259  void Zoom (double zoom);
265  void ShowCursor (bool show);
269  void UpdateTheme ();
275  void Render (cairo_t *cr);
282  void SetSelectionState (gcu::Object *object, int state);
283  // Signals
284  // there is no needd to document these since the documentation in gccv/client.h is appropriate.
285  bool OnButtonPressed (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
286  bool OnButtonReleased (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
287  bool OnDrag (gccv::ItemClient *client, double x, double y, unsigned state);
288  bool OnMotion (gccv::ItemClient *client, double x, double y, unsigned state);
289  bool OnLeaveNotify (unsigned state);
290 
294  WidgetData *GetData () {return m_pData;}
295 
304  void GetVisibleArea (double &x0, double &y0, double &x1, double &y1);
305 
306  //Implementation
307 private:
308  WidgetData* m_pData;
309  Document* m_pDoc;
310  GtkWidget* m_pWidget;
311  std::list<GtkWidget*> m_Widgets;
312  PangoFontDescription* m_PangoFontDesc, *m_PangoSmallFontDesc;
313  double m_dFontHeight;
314  gchar* m_sFontName, *m_sSmallFontName;
315  int m_width, m_height;
316  double m_lastx, m_lasty;
317  bool m_bEmbedded;
318  gcugtk::UIManager *m_UIManager;
319  bool m_Dragging;
320  gcu::Object *m_CurObject;
321  Atom *m_CurAtom;
322 
323 
327 GCU_RO_PROP (double, BaseLineOffset)
331 GCU_RO_PROP (gccv::Text *, ActiveRichText)
335 GCU_RO_PROP (double, CHeight)
339 GCU_RO_PROP (double, HWidth)
340 };
341 
349 void on_receive (GtkClipboard *clipboard, GtkSelectionData *selection_data, View * pView);
350 
351 } // namespace gcp
352 
353 #endif // GCHEMPAINT_VIEW_H