The Gnome Chemistry Utils  0.14.8
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 ();
249  GdkPixbuf *BuildPixbuf (int resolution, bool transparent = true);
254  void EnsureSize ();
260  void Zoom (double zoom);
266  void ShowCursor (bool show);
270  void UpdateTheme ();
276  void Render (cairo_t *cr);
283  void SetSelectionState (gcu::Object *object, int state);
284  // Signals
285  // there is no needd to document these since the documentation in gccv/client.h is appropriate.
286  bool OnButtonPressed (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
287  bool OnButtonReleased (gccv::ItemClient *client, unsigned button, double x, double y, unsigned state);
288  bool OnDrag (gccv::ItemClient *client, double x, double y, unsigned state);
289  bool OnMotion (gccv::ItemClient *client, double x, double y, unsigned state);
290  bool OnLeaveNotify (unsigned state);
291 
295  WidgetData *GetData () {return m_pData;}
296 
305  void GetVisibleArea (double &x0, double &y0, double &x1, double &y1);
306 
307  //Implementation
308 private:
309  WidgetData* m_pData;
310  Document* m_pDoc;
311  GtkWidget* m_pWidget;
312  std::list<GtkWidget*> m_Widgets;
313  PangoFontDescription* m_PangoFontDesc, *m_PangoSmallFontDesc;
314  double m_dFontHeight;
315  gchar* m_sFontName, *m_sSmallFontName;
316  int m_width, m_height;
317  double m_lastx, m_lasty;
318  bool m_bEmbedded;
319  gcugtk::UIManager *m_UIManager;
320  bool m_Dragging;
321  gcu::Object *m_CurObject;
322  Atom *m_CurAtom;
323 
324 
328 GCU_RO_PROP (double, BaseLineOffset)
332 GCU_RO_PROP (gccv::Text *, ActiveRichText)
336 GCU_RO_PROP (double, CHeight)
340 GCU_RO_PROP (double, HWidth)
341 };
342 
350 void on_receive (GtkClipboard *clipboard, GtkSelectionData *selection_data, View * pView);
351 
352 } // namespace gcp
353 
354 #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
gchar * GetFontName()
Definition: gcp/view.h:133
bool OnLeaveNotify(unsigned state)
gchar * GetSmallFontName()
Definition: gcp/view.h:137
Text.
Definition: gccv/text.h:79
void Render(cairo_t *cr)
#define GCU_RO_PROP(type, member)
Definition: macros.h:117
bool PrepareUnselect()
double GetZoomFactor()
virtual ~View()
void SetTextActive(gccv::Text *item)
void GetVisibleArea(double &x0, double &y0, double &x1, double &y1)
WidgetData * GetData()
Definition: gcp/view.h:295
PangoFontDescription * GetPangoFontDesc()
Definition: gcp/view.h:141
bool OnKeyRelease(GtkWidget *w, GdkEventKey *event)
void SetSelectionState(gcu::Object *object, int state)
bool IsEmbedded()
Definition: gcp/view.h:217
bool OnButtonReleased(gccv::ItemClient *client, unsigned button, double x, double y, unsigned state)
double GetFontHeight()
Definition: gcp/view.h:129
void Remove(gcu::Object *pObject)
void OnReceive(GtkClipboard *clipboard, GtkSelectionData *selection_data)
bool OnMotion(gccv::ItemClient *client, double x, double y, unsigned state)
void OnCutSelection(GtkWidget *w, GtkClipboard *clipboard)
void OnDeleteSelection(GtkWidget *w)
bool OnKeyPress(GtkWidget *w, GdkEventKey *event)
void EnsureSize()
void Update(gcu::Object *pObject)
Document * GetDoc()
Definition: gcp/view.h:87
char * BuildEPS()
void on_receive(GtkClipboard *clipboard, GtkSelectionData *selection_data, View *pView)
void OnCopySelection(GtkWidget *w, GtkClipboard *clipboard)
void ShowCursor(bool show)
int GetNbWidgets()
Definition: gcp/view.h:221
char * BuildSVG()
void UpdateTheme()
A GtkUIManager wrapper.
Definition: tk/ui-manager.h:40
void Zoom(double zoom)
void ExportImage(std::string const &filename, const char *type, int resolution=-1)
GtkWidget * CreateNewWidget()
View(Document *pDoc, bool Embedded)
bool OnDrag(gccv::ItemClient *client, double x, double y, unsigned state)
PangoFontDescription * GetPangoSmallFontDesc()
Definition: gcp/view.h:145
GdkPixbuf * BuildPixbuf(int resolution, bool transparent=true)
void AddObject(gcu::Object *pObject)
bool OnButtonPressed(gccv::ItemClient *client, unsigned button, double x, double y, unsigned state)
GtkWidget * GetWidget()
Definition: gcp/view.h:83
void OnDestroy(GtkWidget *widget)
void UpdateFont()
void OnSelectAll()
void OnPasteSelection(GtkWidget *w, GtkClipboard *clipboard)