Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / inc / unx / gtk / gtkgdi.hxx
blob0d04de19e918ab5296644781f1653de1d19eec57
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_INC_UNX_GTK_GTKGDI_HXX
21 #define INCLUDED_VCL_INC_UNX_GTK_GTKGDI_HXX
23 #include <config_cairo_canvas.h>
25 #include <gtk/gtk.h>
26 #include <gdk/gdkx.h>
27 #include <gdk/gdkkeysyms.h>
29 #include <unx/gtk/gtkframe.hxx>
30 #include "ControlCacheKey.hxx"
32 #if GTK_CHECK_VERSION(3,0,0)
34 #include <headless/svpgdi.hxx>
35 #include "textrender.hxx"
37 enum class GtkControlPart
39 ToplevelWindow,
40 Button,
41 LinkButton,
42 CheckButton,
43 CheckButtonCheck,
44 RadioButton,
45 RadioButtonRadio,
46 Entry,
47 Combobox,
48 ComboboxBox,
49 ComboboxBoxEntry,
50 ComboboxBoxButton,
51 ComboboxBoxButtonBox,
52 ComboboxBoxButtonBoxArrow,
53 Listbox,
54 ListboxBox,
55 ListboxBoxButton,
56 ListboxBoxButtonBox,
57 ListboxBoxButtonBoxArrow,
58 SpinButton,
59 SpinButtonEntry,
60 SpinButtonUpButton,
61 SpinButtonDownButton,
62 ScrollbarVertical,
63 ScrollbarVerticalContents,
64 ScrollbarVerticalTrough,
65 ScrollbarVerticalSlider,
66 ScrollbarVerticalButton,
67 ScrollbarHorizontal,
68 ScrollbarHorizontalContents,
69 ScrollbarHorizontalTrough,
70 ScrollbarHorizontalSlider,
71 ScrollbarHorizontalButton,
72 ProgressBar,
73 ProgressBarTrough,
74 ProgressBarProgress,
75 Notebook,
76 NotebookHeader,
77 NotebookStack,
78 NotebookHeaderTabs,
79 NotebookHeaderTabsTab,
80 NotebookHeaderTabsTabLabel,
81 NotebookHeaderTabsTabActiveLabel,
82 NotebookHeaderTabsTabHoverLabel,
83 FrameBorder,
84 MenuBar,
85 MenuBarItem,
86 MenuWindow,
87 Menu,
88 MenuItem,
89 MenuItemLabel,
90 MenuItemArrow,
91 CheckMenuItem,
92 CheckMenuItemCheck,
93 RadioMenuItem,
94 RadioMenuItemRadio,
95 SeparatorMenuItem,
96 SeparatorMenuItemSeparator,
99 typedef void (*gtk_widget_path_iter_set_object_nameFunc)(GtkWidgetPath *, guint, const char*);
101 class GtkSalGraphics : public SvpSalGraphics
103 GtkSalFrame *mpFrame;
104 public:
105 GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow );
106 virtual bool drawNativeControl( ControlType nType, ControlPart nPart,
107 const tools::Rectangle& rControlRegion,
108 ControlState nState, const ImplControlValue& aValue,
109 const OUString& rCaption ) override;
110 virtual bool IsNativeControlSupported( ControlType nType, ControlPart nPart ) override;
111 virtual bool getNativeControlRegion( ControlType nType, ControlPart nPart,
112 const tools::Rectangle& rControlRegion,
113 ControlState nState,
114 const ImplControlValue& aValue,
115 const OUString& rCaption,
116 tools::Rectangle &rNativeBoundingRegion,
117 tools::Rectangle &rNativeContentRegion ) override;
118 #if ENABLE_CAIRO_CANVAS
120 virtual bool SupportsCairo() const override;
121 virtual cairo::SurfaceSharedPtr CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
122 virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y, int width, int height) const override;
124 #endif
126 void WidgetQueueDraw() const;
128 void updateSettings( AllSettings& rSettings );
129 static void refreshFontconfig( GtkSettings *pSettings );
130 static void signalSettingsNotify( GObject*, GParamSpec *pSpec, gpointer );
132 virtual void GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY) override;
134 GtkStyleContext* createStyleContext(gtk_widget_path_iter_set_object_nameFunc set_object_name, GtkControlPart ePart);
135 GtkStyleContext* createNewContext(GtkControlPart ePart, gtk_widget_path_iter_set_object_nameFunc set_object_name);
136 GtkStyleContext* createOldContext(GtkControlPart ePart);
137 GtkStyleContext* makeContext(GtkWidgetPath *pPath, GtkStyleContext *pParent);
138 private:
139 GtkWidget *mpWindow;
140 static GtkStyleContext *mpWindowStyle;
141 static GtkStyleContext *mpButtonStyle;
142 static GtkStyleContext *mpLinkButtonStyle;
143 static GtkStyleContext *mpEntryStyle;
144 static GtkStyleContext *mpTextViewStyle;
145 static GtkStyleContext *mpVScrollbarStyle;
146 static GtkStyleContext *mpVScrollbarContentsStyle;
147 static GtkStyleContext *mpVScrollbarTroughStyle;
148 static GtkStyleContext *mpVScrollbarSliderStyle;
149 static GtkStyleContext *mpVScrollbarButtonStyle;
150 static GtkStyleContext *mpHScrollbarStyle;
151 static GtkStyleContext *mpHScrollbarContentsStyle;
152 static GtkStyleContext *mpHScrollbarTroughStyle;
153 static GtkStyleContext *mpHScrollbarSliderStyle;
154 static GtkStyleContext *mpHScrollbarButtonStyle;
155 static GtkStyleContext *mpToolbarStyle;
156 static GtkStyleContext *mpToolButtonStyle;
157 static GtkStyleContext *mpToolbarSeperatorStyle;
158 static GtkStyleContext *mpCheckButtonStyle;
159 static GtkStyleContext *mpCheckButtonCheckStyle;
160 static GtkStyleContext *mpRadioButtonStyle;
161 static GtkStyleContext *mpRadioButtonRadioStyle;
162 static GtkStyleContext *mpSpinStyle;
163 static GtkStyleContext *mpSpinEntryStyle;
164 static GtkStyleContext *mpSpinUpStyle;
165 static GtkStyleContext *mpSpinDownStyle;
166 static GtkStyleContext *mpComboboxStyle;
167 static GtkStyleContext *mpComboboxBoxStyle;
168 static GtkStyleContext *mpComboboxEntryStyle;
169 static GtkStyleContext *mpComboboxButtonStyle;
170 static GtkStyleContext *mpComboboxButtonBoxStyle;
171 static GtkStyleContext *mpComboboxButtonArrowStyle;
172 static GtkStyleContext *mpListboxStyle;
173 static GtkStyleContext *mpListboxBoxStyle;
174 static GtkStyleContext *mpListboxButtonStyle;
175 static GtkStyleContext *mpListboxButtonBoxStyle;
176 static GtkStyleContext *mpListboxButtonArrowStyle;
177 static GtkStyleContext *mpFrameInStyle;
178 static GtkStyleContext *mpFrameOutStyle;
179 static GtkStyleContext *mpFixedHoriLineStyle;
180 static GtkStyleContext *mpFixedVertLineStyle;
181 static GtkStyleContext *mpTreeHeaderButtonStyle;
182 static GtkStyleContext *mpProgressBarStyle;
183 static GtkStyleContext *mpProgressBarTroughStyle;
184 static GtkStyleContext *mpProgressBarProgressStyle;
185 static GtkStyleContext *mpNotebookStyle;
186 static GtkStyleContext *mpNotebookStackStyle;
187 static GtkStyleContext *mpNotebookHeaderStyle;
188 static GtkStyleContext *mpNotebookHeaderTabsStyle;
189 static GtkStyleContext *mpNotebookHeaderTabsTabStyle;
190 static GtkStyleContext *mpNotebookHeaderTabsTabLabelStyle;
191 static GtkStyleContext *mpNotebookHeaderTabsTabActiveLabelStyle;
192 static GtkStyleContext *mpNotebookHeaderTabsTabHoverLabelStyle;
193 static GtkStyleContext *mpMenuBarStyle;
194 static GtkStyleContext *mpMenuBarItemStyle;
195 static GtkStyleContext *mpMenuWindowStyle;
196 static GtkStyleContext *mpMenuStyle;
197 static GtkStyleContext *mpMenuItemStyle;
198 static GtkStyleContext *mpMenuItemLabelStyle;
199 static GtkStyleContext *mpMenuItemArrowStyle;
200 static GtkStyleContext *mpCheckMenuItemStyle;
201 static GtkStyleContext *mpCheckMenuItemCheckStyle;
202 static GtkStyleContext *mpRadioMenuItemStyle;
203 static GtkStyleContext *mpRadioMenuItemRadioStyle;
204 static GtkStyleContext *mpSeparatorMenuItemStyle;
205 static GtkStyleContext *mpSeparatorMenuItemSeparatorStyle;
207 static tools::Rectangle NWGetScrollButtonRect( ControlPart nPart, tools::Rectangle aAreaRect );
208 static tools::Rectangle NWGetSpinButtonRect( ControlPart nPart, tools::Rectangle aAreaRect);
209 static tools::Rectangle NWGetComboBoxButtonRect( ControlType nType, ControlPart nPart, tools::Rectangle aAreaRect );
211 static void PaintScrollbar(GtkStyleContext *context,
212 cairo_t *cr,
213 const tools::Rectangle& rControlRectangle,
214 ControlType nType,
215 ControlPart nPart,
216 const ImplControlValue& aValue );
217 void PaintOneSpinButton( GtkStyleContext *context,
218 cairo_t *cr,
219 ControlType nType,
220 ControlPart nPart,
221 tools::Rectangle aAreaRect,
222 ControlState nState );
223 void PaintSpinButton(GtkStateFlags flags,
224 cairo_t *cr,
225 const tools::Rectangle& rControlRectangle,
226 ControlType nType,
227 ControlPart nPart,
228 const ImplControlValue& aValue);
229 static void PaintCombobox(GtkStateFlags flags,
230 cairo_t *cr,
231 const tools::Rectangle& rControlRectangle,
232 ControlType nType,
233 ControlPart nPart,
234 const ImplControlValue& aValue);
235 static void PaintCheckOrRadio(cairo_t *cr, GtkStyleContext *context,
236 const tools::Rectangle& rControlRectangle,
237 bool bIsCheck, bool bInMenu);
239 static void PaintCheck(cairo_t *cr, GtkStyleContext *context,
240 const tools::Rectangle& rControlRectangle, bool bInMenu);
242 static void PaintRadio(cairo_t *cr, GtkStyleContext *context,
243 const tools::Rectangle& rControlRectangle, bool bInMenu);
246 static bool style_loaded;
249 #else
250 #include <unx/salgdi.h>
252 class GdkX11Pixmap;
253 class GtkSalGraphics : public X11SalGraphics
255 GtkWidget *m_pWindow;
256 vcl::Region m_aClipRegion;
258 public:
259 GtkSalGraphics(GtkSalFrame *, GtkWidget *window, SalX11Screen nXScreen);
260 virtual ~GtkSalGraphics() override;
262 GtkWidget* GetGtkWidget() const { return m_pWindow; }
263 GdkWindow* GetGdkWindow() const { return m_pWindow->window; }
264 GtkSalFrame* GetGtkFrame() const { return static_cast<GtkSalFrame*>(m_pFrame); }
265 void SetWindow( GtkWidget* window ) { m_pWindow = window; }
267 // will be set when UI theme was changed
268 static bool bThemeChanged;
269 static bool bNeedPixmapPaint;
270 static bool bNeedTwoPasses;
272 // native widget methods
273 virtual bool IsNativeControlSupported( ControlType nType, ControlPart nPart ) override;
274 virtual bool hitTestNativeControl( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion,
275 const Point& aPos, bool& rIsInside ) override;
276 virtual bool drawNativeControl( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion,
277 ControlState nState, const ImplControlValue& aValue,
278 const OUString& rCaption ) override;
279 virtual bool getNativeControlRegion( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion, ControlState nState,
280 const ImplControlValue& aValue, const OUString& rCaption,
281 tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion ) override;
283 //helper methods for frame's UpdateSettings
284 void updateSettings( AllSettings& rSettings );
285 static void refreshFontconfig( GtkSettings *pSettings );
286 static void signalSettingsNotify( GObject*, GParamSpec *pSpec, gpointer );
288 virtual bool setClipRegion( const vcl::Region& ) override;
289 virtual void ResetClipRegion() override;
291 // some themes set the background pixmap of our window EVERY time
292 // a control is painted; but presentation effects need
293 // the background set to None; workaround: set the background
294 // before copyBits
295 virtual void copyBits( const SalTwoRect& rPosAry,
296 SalGraphics* pSrcGraphics ) override;
298 protected:
300 GdkX11Pixmap* NWGetPixmapFromScreen( tools::Rectangle srcRect, int nBgColor = 0 );
301 bool NWRenderPixmapToScreen( GdkX11Pixmap* pPixmap, GdkX11Pixmap* pMask, tools::Rectangle dstRect );
303 bool DoDrawNativeControl( GdkDrawable* pDrawable,
304 ControlType nType,
305 ControlPart nPart,
306 const tools::Rectangle& aCtrlRect,
307 const std::list< tools::Rectangle >& aClip,
308 ControlState nState,
309 const ImplControlValue& aValue,
310 const OUString& rCaption,
311 ControlCacheKey& rControlCacheKey);
313 bool NWPaintGTKArrow( GdkDrawable* gdkDrawable,
314 const tools::Rectangle& rControlRectangle,
315 const std::list< tools::Rectangle >& rClipList,
316 ControlState nState, const ImplControlValue& aValue );
317 bool NWPaintGTKListHeader( GdkDrawable* gdkDrawable,
318 const tools::Rectangle& rControlRectangle,
319 const std::list< tools::Rectangle >& rClipList,
320 ControlState nState );
321 bool NWPaintGTKFixedLine( GdkDrawable* gdkDrawable, ControlPart nPart,
322 const tools::Rectangle& rControlRectangle );
323 bool NWPaintGTKFrame( GdkDrawable* gdkDrawable,
324 const tools::Rectangle& rControlRectangle,
325 const std::list< tools::Rectangle >& rClipList,
326 const ImplControlValue& aValue );
327 bool NWPaintGTKWindowBackground( GdkDrawable* gdkDrawable,
328 const tools::Rectangle& rControlRectangle,
329 const std::list< tools::Rectangle >& rClipList );
330 bool NWPaintGTKButtonReal( GtkWidget* button, GdkDrawable* gdkDrawable,
331 const tools::Rectangle& rControlRectangle,
332 const std::list< tools::Rectangle >& rClipList,
333 ControlState nState );
334 bool NWPaintGTKButton( GdkDrawable* gdkDrawable,
335 const tools::Rectangle& rControlRectangle,
336 const std::list< tools::Rectangle >& rClipList,
337 ControlState nState );
338 bool NWPaintGTKRadio( GdkDrawable* gdkDrawable,
339 const tools::Rectangle& rControlRectangle,
340 const std::list< tools::Rectangle >& rClipList,
341 ControlState nState, const ImplControlValue& aValue );
342 bool NWPaintGTKCheck( GdkDrawable* gdkDrawable,
343 const tools::Rectangle& rControlRectangle,
344 const std::list< tools::Rectangle >& rClipList,
345 ControlState nState, const ImplControlValue& aValue );
346 bool NWPaintGTKScrollbar( ControlPart nPart,
347 const tools::Rectangle& rControlRectangle,
348 const std::list< tools::Rectangle >& rClipList,
349 ControlState nState, const ImplControlValue& aValue );
350 bool NWPaintGTKEditBox( GdkDrawable* gdkDrawable, ControlType nType, ControlPart nPart,
351 const tools::Rectangle& rControlRectangle,
352 const std::list< tools::Rectangle >& rClipList,
353 ControlState nState, const ImplControlValue& aValue,
354 const OUString& rCaption );
355 bool NWPaintGTKSpinBox(ControlType nType, ControlPart nPart,
356 const tools::Rectangle& rControlRectangle,
357 const std::list< tools::Rectangle >& rClipList,
358 ControlState nState, const ImplControlValue& aValue,
359 const OUString& rCaption,
360 ControlCacheKey& rControlCacheKey);
361 bool NWPaintGTKComboBox( GdkDrawable* gdkDrawable, ControlType nType, ControlPart nPart,
362 const tools::Rectangle& rControlRectangle,
363 const std::list< tools::Rectangle >& rClipList,
364 ControlState nState, const ImplControlValue& aValue,
365 const OUString& rCaption );
366 bool NWPaintGTKTabItem( ControlType nType,
367 const tools::Rectangle& rControlRectangle,
368 const std::list< tools::Rectangle >& rClipList,
369 ControlState nState, const ImplControlValue& aValue );
370 bool NWPaintGTKListBox( GdkDrawable* gdkDrawable, ControlPart nPart,
371 const tools::Rectangle& rControlRectangle,
372 const std::list< tools::Rectangle >& rClipList,
373 ControlState nState );
375 bool NWPaintGTKToolbar( GdkDrawable* gdkDrawable, ControlPart nPart,
376 const tools::Rectangle& rControlRectangle,
377 const std::list< tools::Rectangle >& rClipList,
378 ControlState nState, const ImplControlValue& aValue );
379 bool NWPaintGTKMenubar( GdkDrawable* gdkDrawable, ControlPart nPart,
380 const tools::Rectangle& rControlRectangle,
381 const std::list< tools::Rectangle >& rClipList,
382 ControlState nState );
383 bool NWPaintGTKPopupMenu( GdkDrawable* gdkDrawable, ControlPart nPart,
384 const tools::Rectangle& rControlRectangle,
385 const std::list< tools::Rectangle >& rClipList,
386 ControlState nState );
387 bool NWPaintGTKTooltip( GdkDrawable* gdkDrawable,
388 const tools::Rectangle& rControlRectangle,
389 const std::list< tools::Rectangle >& rClipList );
390 bool NWPaintGTKProgress(
391 const tools::Rectangle& rControlRectangle,
392 const ImplControlValue& aValue );
393 bool NWPaintGTKSlider( ControlPart nPart,
394 const tools::Rectangle& rControlRectangle,
395 const std::list< tools::Rectangle >& rClipList,
396 ControlState nState, const ImplControlValue& aValue );
397 bool NWPaintGTKListNode(
398 const tools::Rectangle& rControlRectangle,
399 const std::list< tools::Rectangle >& rClipList,
400 ControlState nState, const ImplControlValue& aValue );
403 #endif // !gtk3
405 #endif // INCLUDED_VCL_INC_UNX_GTK_GTKGDI_HXX
407 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */