1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_SALNATIVEWIDGETS_HXX
21 #define INCLUDED_VCL_SALNATIVEWIDGETS_HXX
23 #include <rtl/ustring.hxx>
24 #include <vcl/dllapi.h>
25 #include <tools/gen.hxx>
26 #include <o3tl/typed_flags_set.hxx>
28 #include <boost/functional/hash.hpp>
32 * Specify the overall, whole control
33 * type (as opposed to parts of the
34 * control if it were composite).
37 typedef sal_uInt32 ControlType
;
39 // for use in general purpose ImplControlValue
40 #define CTRL_GENERIC 0
42 // Normal PushButton/Command Button
43 #define CTRL_PUSHBUTTON 1
45 // Normal single radio button
46 #define CTRL_RADIOBUTTON 2
48 // Normal single checkbox
49 #define CTRL_CHECKBOX 10
51 // Combobox, i.e. a ListBox
52 // that allows data entry by user
53 #define CTRL_COMBOBOX 20
55 // Control that allows text entry
56 #define CTRL_EDITBOX 30
58 // Control that allows text entry, but without the usual border
59 // Has to be handled separately, because this one cannot handle
60 // HAS_BACKGROUND_TEXTURE, which is drawn in the edit box'es
62 #define CTRL_EDITBOX_NOBORDER 31
64 // Control that allows text entry
65 // ( some systems distinguish between single and multi line edit boxes )
66 #define CTRL_MULTILINE_EDITBOX 32
68 // Control that pops up a menu,
69 // but does NOT allow data entry
70 #define CTRL_LISTBOX 35
72 // An edit field together with two little
73 // buttons on the side (aka spin field)
74 #define CTRL_SPINBOX 40
76 // Two standalone spin buttons
77 // without an edit field
78 #define CTRL_SPINBUTTONS 45
81 #define CTRL_TAB_ITEM 50
83 // The border around a tab area,
84 // but without the tabs themselves.
85 // May have a gap at the top for
87 #define CTRL_TAB_PANE 55
89 // The background to the tab area
90 #define CTRL_TAB_HEADER 56
92 // Background of a Tab Pane
93 #define CTRL_TAB_BODY 57
95 // Normal scrollbar, including
96 // all parts like slider, buttons
97 #define CTRL_SCROLLBAR 60
99 #define CTRL_SLIDER 65
101 // Border around a group of related
102 // items, perhaps also displaying
103 // a label of identification
104 #define CTRL_GROUPBOX 70
107 #define CTRL_FIXEDLINE 80
109 // A toolbar control with buttons and a grip
110 #define CTRL_TOOLBAR 100
113 #define CTRL_MENUBAR 120
115 #define CTRL_MENU_POPUP 121
117 #define CTRL_PROGRESS 131
118 // Progress bar for the intro window
119 // (aka splash screen), in case some
120 // wants native progress bar in the
121 // application but not for the splash
122 // screen (used in desktop/)
123 #define CTRL_INTROPROGRESS 132
126 #define CTRL_TOOLTIP 140
128 // to draw the implemented theme
129 #define CTRL_WINDOW_BACKGROUND 150
131 //to draw border of frames natively
132 #define CTRL_FRAME 160
134 // for nodes in listviews
135 // used in svtools/source/contnr/svtreebx.cxx
136 #define CTRL_LISTNODE 170
137 // nets between elements of listviews
139 #define CTRL_LISTNET 171
141 #define CTRL_LISTHEADER 172
146 * Uniquely identify a part of a control,
147 * for example the slider of a scroll bar.
150 typedef sal_uInt32 ControlPart
;
152 #define PART_ENTIRE_CONTROL 1
153 #define PART_WINDOW 5 // the static listbox window containing the list
154 #define PART_BUTTON 100
155 #define PART_BUTTON_UP 101
156 #define PART_BUTTON_DOWN 102 // Also for ComboBoxes/ListBoxes
157 #define PART_BUTTON_LEFT 103
158 #define PART_BUTTON_RIGHT 104
159 #define PART_ALL_BUTTONS 105
160 #define PART_SEPARATOR_HORZ 106
161 #define PART_SEPARATOR_VERT 107
162 #define PART_TRACK_HORZ_LEFT 200
163 #define PART_TRACK_VERT_UPPER 201
164 #define PART_TRACK_HORZ_RIGHT 202
165 #define PART_TRACK_VERT_LOWER 203
166 #define PART_TRACK_HORZ_AREA 204
167 #define PART_TRACK_VERT_AREA 205
168 #define PART_THUMB_HORZ 210 // Also used as toolbar grip
169 #define PART_THUMB_VERT 211 // Also used as toolbar grip
170 #define PART_ARROW 220
171 #define PART_MENU_ITEM 250
172 #define PART_MENU_ITEM_CHECK_MARK 251
173 #define PART_MENU_ITEM_RADIO_MARK 252
174 #define PART_MENU_SEPARATOR 253
175 #define PART_MENU_SUBMENU_ARROW 254
178 HACK: for scrollbars in case of thumb rect, page up and page down rect we
179 abuse the HitTestNativeControl interface. All theming engines but aqua
180 are actually able to draw the thumb according to our internal representation.
181 However aqua draws a little outside. The canonical way would be to enhance the
182 HitTestNativeControl passing a ScrollbarValue additionally so all necessary
183 information is available in the call.
185 However since there is only this one small exception we will deviate a little and
186 instead pass the respective rect as control region to allow for a small correction.
188 So all places using HitTestNativeControl on PART_THUMB_HORZ, PART_THUMB_VERT,
189 PART_TRACK_HORZ_LEFT, PART_TRACK_HORZ_RIGHT, PART_TRACK_VERT_UPPER, PART_TRACK_VERT_LOWER
190 do not use the control rectangle as region but the actuall part rectangle, making
191 only small deviations feasible.
194 /** The edit field part of a control, e.g. of the combo box.
196 Currently used just for combo boxes and just for GetNativeControlRegion().
197 It is valid only if GetNativeControlRegion() supports PART_BUTTON_DOWN as
200 #define PART_SUB_EDIT 300
202 // For controls that require the entire background
203 // to be drawn first, and then other pieces over top.
204 // (GTK+ scrollbars for example). Control region passed
205 // in to draw this part is expected to be the entire
206 // area of the control.
207 // A control may respond to one or both.
208 #define PART_DRAW_BACKGROUND_HORZ 1000
209 #define PART_DRAW_BACKGROUND_VERT 1001
211 // GTK+ also draws tabs right->left since there is a
212 // hardcoded 2 pixel overlap between adjacent tabs
213 #define PART_TABS_DRAW_RTL 3000
215 // For themes that do not want to have the focus
216 // rectangle part drawn by VCL but take care of the
217 // whole inner control part by themselves
218 // eg, listboxes or comboboxes or spinbuttons
219 #define HAS_BACKGROUND_TEXTURE 4000
221 // For scrollbars that have 3 buttons (most KDE themes)
222 #define HAS_THREE_BUTTONS 5000
224 #define PART_BACKGROUND_WINDOW 6000
225 #define PART_BACKGROUND_DIALOG 6001
227 //to draw natively the border of frames
228 #define PART_BORDER 7000
230 //to draw natively the focus rects
231 #define PART_FOCUS 8000
235 * Specify how a particular part of the control
236 * is to be drawn. Constants are bitwise OR-ed
237 * together to compose a final drawing state.
238 * A _disabled_ state is assumed by the drawing
239 * functions until an ENABLED or HIDDEN is passed
240 * in the ControlState.
242 enum class ControlState
{
251 DOUBLEBUFFERING
= 0x4000, ///< Set when the control is painted using double-buffering via VirtualDevice.
252 CACHING_ALLOWED
= 0x8000, ///< Set when the control is completely visible (i.e. not clipped).
256 template<> struct typed_flags
<ControlState
> : is_typed_flags
<ControlState
, 0xc007f> {};
259 class ControlCacheKey
264 ControlState mnState
;
267 ControlCacheKey(ControlType nType
, ControlPart nPart
, ControlState nState
, const Size
& rSize
)
274 bool operator==(ControlCacheKey
const& aOther
) const
276 return mnType
== aOther
.mnType
277 && mnPart
== aOther
.mnPart
278 && mnState
== aOther
.mnState
279 && maSize
.Width() == aOther
.maSize
.Width()
280 && maSize
.Height() == aOther
.maSize
.Height();
283 bool canCacheControl()
288 case CTRL_RADIOBUTTON
:
292 if (mnPart
== PART_ENTIRE_CONTROL
)
303 struct ControlCacheHashFunction
305 std::size_t operator()(ControlCacheKey
const& aCache
) const
307 std::size_t seed
= 0;
308 boost::hash_combine(seed
, aCache
.mnType
);
309 boost::hash_combine(seed
, aCache
.mnPart
);
310 boost::hash_combine(seed
, aCache
.mnState
);
311 boost::hash_combine(seed
, aCache
.maSize
.Width());
312 boost::hash_combine(seed
, aCache
.maSize
.Height());
320 * Identifies the tri-state value options
325 BUTTONVALUE_DONTKNOW
,
333 * Generic value container for all control parts.
336 class VCL_DLLPUBLIC ImplControlValue
338 friend class SalFrame
;
342 ButtonValue mTristate
; // Tristate value: on, off, mixed
343 long mNumber
; // numeric value
345 ImplControlValue( ControlType i_eType
, ButtonValue i_eTriState
, long i_nNumber
)
347 , mTristate( i_eTriState
)
348 , mNumber( i_nNumber
)
352 explicit ImplControlValue( ButtonValue nTristate
)
353 : mType( CTRL_GENERIC
), mTristate(nTristate
), mNumber(0) {}
354 explicit ImplControlValue( long nNumeric
)
355 : mType( CTRL_GENERIC
), mTristate(BUTTONVALUE_DONTKNOW
), mNumber( nNumeric
) {}
356 inline ImplControlValue()
357 : mType( CTRL_GENERIC
), mTristate(BUTTONVALUE_DONTKNOW
), mNumber(0) {}
359 virtual ~ImplControlValue();
361 virtual ImplControlValue
* clone() const;
363 ControlType
getType() const { return mType
; }
365 inline ButtonValue
getTristateVal() const { return mTristate
; }
366 inline void setTristateVal( ButtonValue nTristate
) { mTristate
= nTristate
; }
368 inline long getNumericVal() const { return mNumber
; }
369 inline void setNumericVal( long nNumeric
) { mNumber
= nNumeric
; }
374 * Value container for scrollbars.
376 class VCL_DLLPUBLIC ScrollbarValue
: public ImplControlValue
383 Rectangle maThumbRect
;
384 Rectangle maButton1Rect
;
385 Rectangle maButton2Rect
;
386 ControlState mnButton1State
;
387 ControlState mnButton2State
;
388 ControlState mnThumbState
;
389 ControlState mnPage1State
;
390 ControlState mnPage2State
;
392 inline ScrollbarValue()
393 : ImplControlValue( CTRL_SCROLLBAR
, BUTTONVALUE_DONTKNOW
, 0 )
395 mnMin
= 0; mnMax
= 0; mnCur
= 0; mnVisibleSize
= 0;
396 mnButton1State
= ControlState::NONE
; mnButton2State
= ControlState::NONE
;
397 mnThumbState
= ControlState::NONE
; mnPage1State
= ControlState::NONE
; mnPage2State
= ControlState::NONE
;
399 virtual ~ScrollbarValue();
400 virtual ScrollbarValue
* clone() const SAL_OVERRIDE
;
403 class VCL_DLLPUBLIC SliderValue
: public ImplControlValue
409 Rectangle maThumbRect
;
410 ControlState mnThumbState
;
413 : ImplControlValue( CTRL_SLIDER
, BUTTONVALUE_DONTKNOW
, 0 )
414 , mnMin( 0 ), mnMax( 0 ), mnCur( 0 ), mnThumbState( ControlState::NONE
)
416 virtual ~SliderValue();
417 virtual SliderValue
* clone() const SAL_OVERRIDE
;
422 * Value container for tabitems.
425 /* TABITEM constants are OR-ed together */
426 #define TABITEM_LEFTALIGNED 0x001 // the tabitem is aligned with the left border of the TabControl
427 #define TABITEM_RIGHTALIGNED 0x002 // the tabitem is aligned with the right border of the TabControl
428 #define TABITEM_FIRST_IN_GROUP 0x004 // the tabitem is the first in group of tabitems
429 #define TABITEM_LAST_IN_GROUP 0x008 // the tabitem is the last in group of tabitems
431 class VCL_DLLPUBLIC TabitemValue
: public ImplControlValue
434 unsigned int mnAlignment
;
435 Rectangle maContentRect
;
437 TabitemValue(const Rectangle
&rContentRect
)
438 : ImplControlValue( CTRL_TAB_ITEM
, BUTTONVALUE_DONTKNOW
, 0 )
440 , maContentRect(rContentRect
)
443 virtual ~TabitemValue();
444 virtual TabitemValue
* clone() const SAL_OVERRIDE
;
446 bool isLeftAligned() const { return (mnAlignment
& TABITEM_LEFTALIGNED
) != 0; }
447 bool isRightAligned() const { return (mnAlignment
& TABITEM_RIGHTALIGNED
) != 0; }
448 bool isBothAligned() const { return isLeftAligned() && isRightAligned(); }
449 bool isNotAligned() const { return (mnAlignment
& (TABITEM_LEFTALIGNED
| TABITEM_RIGHTALIGNED
)) == 0; }
450 bool isFirst() const { return (mnAlignment
& TABITEM_FIRST_IN_GROUP
) != 0; }
451 bool isLast() const { return (mnAlignment
& TABITEM_LAST_IN_GROUP
) != 0; }
452 const Rectangle
& getContentRect() const { return maContentRect
; }
457 * Value container for spinbuttons to paint both buttons at once.
458 * Note: the other parameters of DrawNativeControl will have no meaning
459 * all parameters for spinbuttons are carried here
461 class VCL_DLLPUBLIC SpinbuttonValue
: public ImplControlValue
464 Rectangle maUpperRect
;
465 Rectangle maLowerRect
;
466 ControlState mnUpperState
;
467 ControlState mnLowerState
;
472 : ImplControlValue( CTRL_SPINBUTTONS
, BUTTONVALUE_DONTKNOW
, 0 )
473 , mnUpperState(ControlState::NONE
)
474 , mnLowerState(ControlState::NONE
)
480 virtual ~SpinbuttonValue();
481 virtual SpinbuttonValue
* clone() const SAL_OVERRIDE
;
486 * Value container for toolbars detailing the grip position
488 class VCL_DLLPUBLIC ToolbarValue
: public ImplControlValue
491 ToolbarValue() : ImplControlValue( CTRL_TOOLBAR
, BUTTONVALUE_DONTKNOW
, 0 )
492 { mbIsTopDockingArea
= false; }
493 virtual ~ToolbarValue();
494 virtual ToolbarValue
* clone() const SAL_OVERRIDE
;
495 Rectangle maGripRect
;
496 bool mbIsTopDockingArea
; // indicates that this is the top aligned dockingarea
497 // adjacent to the menubar
502 * Value container for menubars specifying height of adjacent docking area
504 class VCL_DLLPUBLIC MenubarValue
: public ImplControlValue
507 MenubarValue() : ImplControlValue( CTRL_MENUBAR
, BUTTONVALUE_DONTKNOW
, 0 )
508 { maTopDockingAreaHeight
=0; }
509 virtual ~MenubarValue();
510 virtual MenubarValue
* clone() const SAL_OVERRIDE
;
511 int maTopDockingAreaHeight
;
516 * Value container for menu items; specifies the rectangle for the whole item which
517 * may be useful when drawing parts with a smaller rectangle.
519 class VCL_DLLPUBLIC MenupopupValue
: public ImplControlValue
522 MenupopupValue() : ImplControlValue( CTRL_MENU_POPUP
, BUTTONVALUE_DONTKNOW
, 0 )
524 MenupopupValue( long i_nGutterWidth
, const Rectangle
& i_rItemRect
)
525 : ImplControlValue( CTRL_MENU_POPUP
, BUTTONVALUE_DONTKNOW
, i_nGutterWidth
)
526 , maItemRect( i_rItemRect
)
528 virtual ~MenupopupValue();
529 virtual MenupopupValue
* clone() const SAL_OVERRIDE
;
530 Rectangle maItemRect
;
535 * Value container for pushbuttons specifying additional drawing hints
537 class VCL_DLLPUBLIC PushButtonValue
: public ImplControlValue
541 : ImplControlValue( CTRL_PUSHBUTTON
, BUTTONVALUE_DONTKNOW
, 0 )
542 , mbBevelButton( false ), mbSingleLine( true ) {}
543 virtual ~PushButtonValue();
544 virtual PushButtonValue
* clone() const SAL_OVERRIDE
;
546 bool mbBevelButton
:1;
553 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */