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 <libgnomeprint/gnome-print.h>
00031 #include <libgnomecanvas/libgnomecanvas.h>
00032 #include <canvas/gcp-canvas-pango.h>
00033 #include <gcu/macros.h>
00034 #include "atom.h"
00035 #include "bond.h"
00036
00037 namespace gcp {
00038
00039 class Document;
00040 class WidgetData;
00041
00042 #define GCHEMPAINT_ATOM_NAME "application/x-gchempaint"
00043 extern GtkTargetEntry const targets[];
00044
00045 class View
00046 {
00047 public:
00048
00049 View (Document *pDoc, bool Embedded);
00050 virtual ~View ();
00051
00052
00053 public:
00054 GtkWidget* GetWidget () {return m_pWidget;}
00055 Document* GetDoc () {return m_pDoc;}
00056 bool OnEvent (GnomeCanvasItem *item, GdkEvent *event, GtkWidget* widget);
00057 void AddObject (Object* pObject);
00058 void Update (Object* pObject);
00059 GtkWidget* CreateNewWidget ();
00060 void OnDestroy (GtkWidget* widget);
00061 GnomeCanvasItem* GetCanvasItem (GtkWidget* widget, Object* Object);
00062 void Print (GnomePrintContext *pc, gdouble width, gdouble height);
00063 GnomeCanvasItem* GetBackground ();
00064 double GetZoomFactor ();
00065 void UpdateFont ();
00066 void Remove (Object* pObject);
00067 PangoContext* GetPangoContext () {return m_PangoContext;}
00068 double GetFontHeight () {return m_dFontHeight;}
00069 gchar* GetFontName () {return m_sFontName;}
00070 gchar* GetSmallFontName () {return m_sSmallFontName;}
00071 PangoFontDescription* GetPangoFontDesc () {return m_PangoFontDesc;}
00072 PangoFontDescription* GetPangoSmallFontDesc () {return m_PangoSmallFontDesc;}
00073 void OnDeleteSelection (GtkWidget* w);
00074 void OnCopySelection (GtkWidget* w, GtkClipboard* clipboard);
00075 void OnPasteSelection (GtkWidget* w, GtkClipboard* clipboard);
00076 void OnCutSelection (GtkWidget* w, GtkClipboard* clipboard);
00077 bool OnKeyPress (GtkWidget* w, GdkEventKey* event);
00078 bool OnKeyRelease (GtkWidget* w, GdkEventKey* event);
00079 bool OnSize (GtkWidget *w, int width, int height);
00080 void UpdateSize (double x1, double y1, double x2, double y2);
00081 void SetGnomeCanvasPangoActive (GnomeCanvasPango* item);
00082 bool PrepareUnselect ();
00083 void OnReceive (GtkClipboard* clipboard, GtkSelectionData* selection_data);
00084 void OnSelectAll ();
00085 bool IsEmbedded () {return m_bEmbedded;}
00086 int GetNbWidgets () {return m_Widgets.size ();}
00087 void ExportImage (string const &filename, const char* type, int resolution = -1);
00088 xmlDocPtr BuildSVG ();
00089 GdkPixbuf *BuildPixbuf (int resolution);
00090 void EnsureSize ();
00091 void Zoom (double zoom);
00092 void ShowCursor (bool show);
00093 void UpdateTheme ();
00094
00095
00096 private:
00097 WidgetData* m_pData;
00098 Document* m_pDoc;
00099 GtkWidget* m_pWidget;
00100 std::list<GtkWidget*> m_Widgets;
00101 PangoContext* m_PangoContext;
00102 PangoFontDescription* m_PangoFontDesc, *m_PangoSmallFontDesc;
00103 double m_dFontHeight;
00104 gchar* m_sFontName, *m_sSmallFontName;
00105 int m_width, m_height;
00106 double m_lastx, m_lasty;
00107 bool m_bEmbedded;
00108 GtkUIManager *m_UIManager;
00109 bool m_Dragging;
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