gcp/view.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef GCHEMPAINT_VIEW_H
00026 #define GCHEMPAINT_VIEW_H
00027
00028 #include <map>
00029 #include <list>
00030 #include <libgnomecanvas/libgnomecanvas.h>
00031 #include <canvas/gcp-canvas-pango.h>
00032 #include <gcu/macros.h>
00033 #include "atom.h"
00034 #include "bond.h"
00035
00036 namespace gcp {
00037
00038 class Document;
00039 class WidgetData;
00040
00041 #define GCHEMPAINT_ATOM_NAME "application/x-gchempaint"
00042 extern GtkTargetEntry const targets[];
00043
00047 class View
00048 {
00049 public:
00050
00058 View (Document *pDoc, bool Embedded);
00062 virtual ~View ();
00063
00064
00065 public:
00069 GtkWidget* GetWidget () {return m_pWidget;}
00073 Document* GetDoc () {return m_pDoc;}
00082 bool OnEvent (GnomeCanvasItem *item, GdkEvent *event, GtkWidget* widget);
00086 void AddObject (gcu::Object const *pObject);
00089 void Update (gcu::Object const *pObject);
00092 GtkWidget* CreateNewWidget ();
00095 void OnDestroy (GtkWidget* widget);
00098 GnomeCanvasItem* GetCanvasItem (GtkWidget* widget, gcu::Object* Object);
00101 GnomeCanvasItem* GetBackground ();
00104 double GetZoomFactor ();
00107 void UpdateFont ();
00110 void Remove (gcu::Object* pObject);
00113 PangoContext* GetPangoContext () {return m_PangoContext;}
00116 double GetFontHeight () {return m_dFontHeight;}
00119 gchar* GetFontName () {return m_sFontName;}
00122 gchar* GetSmallFontName () {return m_sSmallFontName;}
00125 PangoFontDescription* GetPangoFontDesc () {return m_PangoFontDesc;}
00128 PangoFontDescription* GetPangoSmallFontDesc () {return m_PangoSmallFontDesc;}
00134 void OnDeleteSelection (GtkWidget* w);
00141 void OnCopySelection (GtkWidget* w, GtkClipboard* clipboard);
00148 void OnPasteSelection (GtkWidget* w, GtkClipboard* clipboard);
00155 void OnCutSelection (GtkWidget* w, GtkClipboard* clipboard);
00159 bool OnKeyPress (GtkWidget* w, GdkEventKey* event);
00163 bool OnKeyRelease (GtkWidget* w, GdkEventKey* event);
00167 bool OnSize (GtkWidget *w, int width, int height);
00171 void UpdateSize (double x1, double y1, double x2, double y2);
00175 void SetGnomeCanvasPangoActive (GnomeCanvasPango* item);
00179 bool PrepareUnselect ();
00183 void OnReceive (GtkClipboard* clipboard, GtkSelectionData* selection_data);
00187 void OnSelectAll ();
00191 bool IsEmbedded () {return m_bEmbedded;}
00195 int GetNbWidgets () {return m_Widgets.size ();}
00199 void ExportImage (std::string const &filename, const char* type, int resolution = -1);
00203 xmlDocPtr BuildSVG ();
00211 GdkPixbuf *BuildPixbuf (int resolution);
00216 void EnsureSize ();
00222 void Zoom (double zoom);
00228 void ShowCursor (bool show);
00232 void UpdateTheme ();
00238 void Render (cairo_t *cr);
00239
00240
00241 private:
00242 WidgetData* m_pData;
00243 Document* m_pDoc;
00244 GtkWidget* m_pWidget;
00245 std::list<GtkWidget*> m_Widgets;
00246 PangoContext* m_PangoContext;
00247 PangoFontDescription* m_PangoFontDesc, *m_PangoSmallFontDesc;
00248 double m_dFontHeight;
00249 gchar* m_sFontName, *m_sSmallFontName;
00250 int m_width, m_height;
00251 double m_lastx, m_lasty;
00252 bool m_bEmbedded;
00253 GtkUIManager *m_UIManager;
00254 bool m_Dragging;
00255 gcu::Object *m_CurObject;
00256
00260 GCU_RO_PROP (double, BaseLineOffset)
00264 GCU_RO_PROP (GnomeCanvasPango*, ActiveRichText)
00265 };
00266
00267 bool on_event (GnomeCanvasItem *item, GdkEvent *event, GtkWidget* widget);
00268 void on_receive (GtkClipboard *clipboard, GtkSelectionData *selection_data, View * pView);
00269
00270 }
00271
00272 #endif // GCHEMPAINT_VIEW_H