1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: t -*- */
2 /* AbiWord
3  * Copyright (C) 2004-2006 Tomas Frydrych <dr.tomas@yahoo.co.uk>
4  * Copyright (C) 2009-2016 Hubert Figuiere
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA.
20  */
21 
22 
23 #ifndef __GR_UNIXCAIROGRAPHICS_H__
24 #define __GR_UNIXCAIROGRAPHICS_H__
25 
26 #include <gdk/gdk.h>
27 #include "xap_Gtk2Compat.h"
28 #include "gr_CairoGraphics.h"
29 
30 class ABI_EXPORT GR_UnixCairoAllocInfo : public GR_CairoAllocInfo
31 {
32 public:
33 	GR_UnixCairoAllocInfo(GdkWindow * win, bool double_buffered=false)
GR_CairoAllocInfo(false,false,double_buffered)34 		: GR_CairoAllocInfo(false, false, double_buffered),
35 		m_win(win)
36 		{}
GR_UnixCairoAllocInfo(GtkWidget * widget)37 	GR_UnixCairoAllocInfo(GtkWidget *widget)
38 		: GR_CairoAllocInfo(false, false, gtk_widget_get_double_buffered(widget)),
39 		  m_win(gtk_widget_get_window(GTK_WIDGET(widget)))
40 	{}
41 
GR_UnixCairoAllocInfo(bool bPreview)42 	GR_UnixCairoAllocInfo(bool bPreview)
43 		: GR_CairoAllocInfo(bPreview, true, false),
44 		  m_win(NULL){}
45 
createCairo()46 	cairo_t *createCairo() {return NULL;} // we need this since otherwise the class would be abstract
47 	GdkWindow     * m_win;
48 };
49 
50 class ABI_EXPORT GR_UnixCairoGraphicsBase
51 	: public GR_CairoGraphics
52 {
53  public:
54 	~GR_UnixCairoGraphicsBase();
55 
56 	virtual GR_Image*	createNewImage(const char* pszName,
57 									   const UT_ByteBuf* pBB,
58 		                               const std::string& mimetype,
59 									   UT_sint32 iDisplayWidth,
60 									   UT_sint32 iDisplayHeight,
61 									   GR_Image::GRType =GR_Image::GRT_Raster);
62  protected:
63 	GR_UnixCairoGraphicsBase();
64 	GR_UnixCairoGraphicsBase(cairo_t *cr, UT_uint32 iDeviceResolution);
65 
66 };
67 
68 
69 class ABI_EXPORT GR_UnixCairoGraphics
70 	: public GR_UnixCairoGraphicsBase
71 {
72 public:
73 	~GR_UnixCairoGraphics();
s_getClassId()74 	static UT_uint32       s_getClassId() {return GRID_UNIX_PANGO;}
getClassId()75 	virtual UT_uint32      getClassId() {return s_getClassId();}
76 
graphicsDescriptor()77 	static const char *    graphicsDescriptor(){return "Unix Cairo Pango";}
78 	static GR_Graphics *   graphicsAllocator(GR_AllocInfo&);
getWindow()79 	GdkWindow *  getWindow () {return m_pWin;}
80 
81 	virtual GR_Font * getGUIFont(void);
82 
83 	virtual void		setCursor(GR_Graphics::Cursor c);
84 	virtual void		scroll(UT_sint32, UT_sint32);
85 	virtual void		scroll(UT_sint32 x_dest, UT_sint32 y_dest,
86 						   UT_sint32 x_src, UT_sint32 y_src,
87 						   UT_sint32 width, UT_sint32 height);
88 	virtual GR_Image *  genImageFromRectangle(const UT_Rect & r);
89 
90 	void				init3dColors(GtkWidget* w);
91 #if !GTK_CHECK_VERSION(3,0,0)
92 	void                init3dColors(GtkStyle* pStyle);
93 #endif
94 	void				initWidget(GtkWidget *widget);
95 	virtual bool		queryProperties(GR_Graphics::Properties gp) const;
96 
97 #if GTK_CHECK_VERSION(3,0,0)
98 	/** In the UnixCairoGraphics, color3D are mostly invalid. */
99 	virtual bool        getColor3D(GR_Color3D name, UT_RGBColor &color);
100 
101 	virtual void		fillRect(GR_Color3D c,
102 								 UT_sint32 x, UT_sint32 y,
103 								 UT_sint32 w, UT_sint32 h);
104 #endif
105 	virtual void      flush(void);
106 
107 protected:
108 	virtual void		_resetClip(void);
109 	static void		widget_size_allocate (GtkWidget        *widget,
110 									  GtkAllocation    *allocation,
111 									  GR_UnixCairoGraphics *me);
112 	static void		widget_destroy (GtkWidget        *widget,
113 									  GR_UnixCairoGraphics *me);
114 	GR_UnixCairoGraphics(GdkWindow * win = NULL, bool double_buffered=false);
_getWindow(void)115 	virtual GdkWindow * _getWindow(void)
116 	{  return m_pWin;}
117 
118 	virtual void _beginPaint();
119 	virtual void _endPaint();
120 
121 private:
122 	GdkWindow *m_pWin;
123 	bool m_double_buffered;
124 	bool m_CairoCreated;
125 	bool m_Painting;
126 	gulong m_Signal, m_DestroySignal;
127 	GtkWidget *m_Widget;
128 #if GTK_CHECK_VERSION(3,0,0)
129 	GtkStyleContext* m_styleBg;
130 	GtkStyleContext* m_styleHighlight;
131 #endif
132 };
133 
134 
135 #endif
136 
137