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
00044 class View
00045 {
00046 public:
00047
00048 View (Document *pDoc, bool Embedded);
00049 virtual ~View ();
00050
00051
00052 public:
00053 GtkWidget* GetWidget () {return m_pWidget;}
00054 Document* GetDoc () {return m_pDoc;}
00055 bool OnEvent (GnomeCanvasItem *item, GdkEvent *event, GtkWidget* widget);
00056 void AddObject (gcu::Object* pObject);
00057 void Update (gcu::Object* pObject);
00058 GtkWidget* CreateNewWidget ();
00059 void OnDestroy (GtkWidget* widget);
00060 GnomeCanvasItem* GetCanvasItem (GtkWidget* widget, gcu::Object* Object);
00061 GnomeCanvasItem* GetBackground ();
00062 double GetZoomFactor ();
00063 void UpdateFont ();
00064 void Remove (gcu::Object* pObject);
00065 PangoContext* GetPangoContext () {return m_PangoContext;}
00066 double GetFontHeight () {return m_dFontHeight;}
00067 gchar* GetFontName () {return m_sFontName;}
00068 gchar* GetSmallFontName () {return m_sSmallFontName;}
00069 PangoFontDescription* GetPangoFontDesc () {return m_PangoFontDesc;}
00070 PangoFontDescription* GetPangoSmallFontDesc () {return m_PangoSmallFontDesc;}
00071 void OnDeleteSelection (GtkWidget* w);
00072 void OnCopySelection (GtkWidget* w, GtkClipboard* clipboard);
00073 void OnPasteSelection (GtkWidget* w, GtkClipboard* clipboard);
00074 void OnCutSelection (GtkWidget* w, GtkClipboard* clipboard);
00075 bool OnKeyPress (GtkWidget* w, GdkEventKey* event);
00076 bool OnKeyRelease (GtkWidget* w, GdkEventKey* event);
00077 bool OnSize (GtkWidget *w, int width, int height);
00078 void UpdateSize (double x1, double y1, double x2, double y2);
00079 void SetGnomeCanvasPangoActive (GnomeCanvasPango* item);
00080 bool PrepareUnselect ();
00081 void OnReceive (GtkClipboard* clipboard, GtkSelectionData* selection_data);
00082 void OnSelectAll ();
00083 bool IsEmbedded () {return m_bEmbedded;}
00084 int GetNbWidgets () {return m_Widgets.size ();}
00085 void ExportImage (std::string const &filename, const char* type, int resolution = -1);
00086 xmlDocPtr BuildSVG ();
00087 GdkPixbuf *BuildPixbuf (int resolution);
00088 void EnsureSize ();
00089 void Zoom (double zoom);
00090 void ShowCursor (bool show);
00091 void UpdateTheme ();
00092 void Render (cairo_t *cr);
00093
00094
00095 private:
00096 WidgetData* m_pData;
00097 Document* m_pDoc;
00098 GtkWidget* m_pWidget;
00099 std::list<GtkWidget*> m_Widgets;
00100 PangoContext* m_PangoContext;
00101 PangoFontDescription* m_PangoFontDesc, *m_PangoSmallFontDesc;
00102 double m_dFontHeight;
00103 gchar* m_sFontName, *m_sSmallFontName;
00104 int m_width, m_height;
00105 double m_lastx, m_lasty;
00106 bool m_bEmbedded;
00107 GtkUIManager *m_UIManager;
00108 bool m_Dragging;
00109 gcu::Object *m_CurObject;
00110
00111 GCU_RO_PROP (double, BaseLineOffset)
00112 GCU_RO_PROP (GnomeCanvasPango*, ActiveRichText)
00113 };
00114
00115 bool on_event (GnomeCanvasItem *item, GdkEvent *event, GtkWidget* widget);
00116 void on_receive (GtkClipboard *clipboard, GtkSelectionData *selection_data, View * pView);
00117
00118 }
00119
00120 #endif // GCHEMPAINT_VIEW_H