The Gnome Chemistry Utils  0.14.16
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* GetPangoTextFontDesc () {return m_PangoTextFontDesc;}
149  PangoFontDescription* GetPangoSmallFontDesc () {return m_PangoSmallFontDesc;}
155  void OnDeleteSelection (GtkWidget* w);
162  void OnCopySelection (GtkWidget* w, GtkClipboard* clipboard);
169  void OnPasteSelection (GtkWidget* w, GtkClipboard* clipboard);
176  void OnCutSelection (GtkWidget* w, GtkClipboard* clipboard);
184  bool OnKeyPress (GtkWidget* w, GdkEventKey* event);
192  bool OnKeyRelease (GtkWidget* w, GdkEventKey* event);
199  void SetTextActive (gccv::Text* item);
206  bool PrepareUnselect ();
213  void OnReceive (GtkClipboard* clipboard, GtkSelectionData* selection_data);
217  void OnSelectAll ();
221  bool IsEmbedded () {return m_bEmbedded;}
225  int GetNbWidgets () {return m_Widgets.size ();}
236  void ExportImage (std::string const &filename, const char* type, int resolution = -1);
240  char *BuildSVG ();
244  char *BuildEPS ();
253  GdkPixbuf *BuildPixbuf (int resolution, bool transparent = true);
258  void EnsureSize ();
264  void Zoom (double zoom);
270  void ShowCursor (bool show);
274  void UpdateTheme ();
280  void Render (cairo_t *cr);
287  void SetSelectionState (gcu::Object *object, int state);
288  // Signals
289  // there is no needd to document these since the documentation in gccv/client.h is appropriate.
290  bool OnButtonPressed (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
291  bool OnButtonReleased (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
292  bool OnDrag (gccv::ItemClient *client, double x, double y, unsigned state);
293  bool OnMotion (gccv::ItemClient *client, double x, double y, unsigned state);
294  bool OnLeaveNotify (unsigned state);
295 
299  WidgetData *GetData () {return m_pData;}
300 
309  void GetVisibleArea (double &x0, double &y0, double &x1, double &y1);
310 
311  //Implementation
312 private:
313  WidgetData* m_pData;
314  Document* m_pDoc;
315  GtkWidget* m_pWidget;
316  std::list<GtkWidget*> m_Widgets;
317  PangoFontDescription* m_PangoFontDesc, *m_PangoSmallFontDesc, *m_PangoTextFontDesc;
318  double m_dFontHeight;
319  gchar* m_sFontName, *m_sSmallFontName;
320  int m_width, m_height;
321  double m_lastx, m_lasty;
322  bool m_bEmbedded;
323  gcugtk::UIManager *m_UIManager;
324  bool m_Dragging;
325  gcu::Object *m_CurObject;
326  Atom *m_CurAtom;
327 
328 
332 GCU_RO_PROP (double, BaseLineOffset)
336 GCU_RO_PROP (gccv::Text *, ActiveRichText)
340 GCU_RO_PROP (double, CHeight)
344 GCU_RO_PROP (double, HWidth)
345 };
346 
354 void on_receive (GtkClipboard *clipboard, GtkSelectionData *selection_data, View * pView);
355 
356 } // namespace gcp
357 
358 #endif // GCHEMPAINT_VIEW_H
the base class for objects associated with a canvas item.
Definition: item-client.h:44
The document associated with the canvas.
Definition: client.h:43
The Gtk using base classes.
GChemPaint specific C++ classes.
gchar * GetFontName()
Definition: gcp/view.h:133
gchar * GetSmallFontName()
Definition: gcp/view.h:137
Text.
Definition: gccv/text.h:79
#define GCU_RO_PROP(type, member)
Definition: macros.h:117
WidgetData * GetData()
Definition: gcp/view.h:299
PangoFontDescription * GetPangoFontDesc()
Definition: gcp/view.h:141
bool IsEmbedded()
Definition: gcp/view.h:221
double GetFontHeight()
Definition: gcp/view.h:129
Gnome Chemistry Canvas library namespace.
The Gnome Chemistry Utils C++ classes.
Document * GetDoc()
Definition: gcp/view.h:87
void on_receive(GtkClipboard *clipboard, GtkSelectionData *selection_data, View *pView)
int GetNbWidgets()
Definition: gcp/view.h:225
A GtkUIManager wrapper.
Definition: tk/ui-manager.h:40
PangoFontDescription * GetPangoTextFontDesc()
Definition: gcp/view.h:145
PangoFontDescription * GetPangoSmallFontDesc()
Definition: gcp/view.h:149
GtkWidget * GetWidget()
Definition: gcp/view.h:83