LibreOffice Module vcl (master)  1
salnativewidgets.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_VCL_SALNATIVEWIDGETS_HXX
21 #define INCLUDED_VCL_SALNATIVEWIDGETS_HXX
22 
23 #include <vcl/dllapi.h>
24 #include <tools/gen.hxx>
25 #include <o3tl/typed_flags_set.hxx>
26 
27 /* Control Types:
28  *
29  * Specify the overall, whole control
30  * type (as opposed to parts of the
31  * control if it were composite).
32  */
33 
34 enum class ControlType {
35 // for use in general purpose ImplControlValue
36  Generic = 0,
37 // Normal PushButton/Command Button
38  Pushbutton = 1,
39 // Normal single radio button
40  Radiobutton = 2,
41 // Normal single checkbox
42  Checkbox = 10,
43 // Combobox, i.e. a ListBox
44 // that allows data entry by user
45  Combobox = 20,
46 // Control that allows text entry
47  Editbox = 30,
48 // Control that allows text entry, but without the usual border
49 // Has to be handled separately, because this one cannot handle
50 // ControlPart::HasBackgroundTexture, which is drawn in the edit box'es
51 // border window.
52  EditboxNoBorder = 31,
53 // Control that allows text entry
54 // ( some systems distinguish between single and multi line edit boxes )
55  MultilineEditbox = 32,
56 // Control that pops up a menu,
57 // but does NOT allow data entry
58  Listbox = 35,
59 // An edit field together with two little
60 // buttons on the side (aka spin field)
61  Spinbox = 40,
62 // Two standalone spin buttons
63 // without an edit field
64  SpinButtons = 45,
65 // A single tab
66  TabItem = 50,
67 // The border around a tab area,
68 // but without the tabs themselves.
69 // May have a gap at the top for
70 // the active tab
71  TabPane = 55,
72 // The background to the tab area
73  TabHeader = 56,
74 // Background of a Tab Pane
75  TabBody = 57,
76 // Normal scrollbar, including
77 // all parts like slider, buttons
78  Scrollbar = 60,
79  Slider = 65,
80 // A separator line
81  Fixedline = 80,
82 // A toolbar control with buttons and a grip
83  Toolbar = 100,
84 // The menubar
85  Menubar = 120,
86 // popup menu
87  MenuPopup = 121,
88  Progress = 131,
89 // Progress bar for the intro window
90 // (aka splash screen), in case some
91 // wants native progress bar in the
92 // application but not for the splash
93 // screen (used in desktop/)
94  IntroProgress = 132,
95 // tool tips
96  Tooltip = 140,
97 // to draw the implemented theme
98  WindowBackground = 150,
99 //to draw border of frames natively
100  Frame = 160,
101 // for nodes in listviews
102 // used in svtools/source/contnr/svtreebx.cxx
103  ListNode = 170,
104 // nets between elements of listviews
105 // with nodes
106  ListNet = 171,
107 // for list headers
108  ListHeader = 172,
109 };
110 
111 
112 /* Control Parts:
113  *
114  * Uniquely identify a part of a control,
115  * for example the slider of a scroll bar.
116  */
117 
118 enum class ControlPart
119 {
120  NONE = 0,
121  Entire = 1,
122  ListboxWindow = 5, // the static listbox window containing the list
123  Button = 100,
124  ButtonUp = 101,
125  ButtonDown = 102, // Also for ComboBoxes/ListBoxes
126  ButtonLeft = 103,
127  ButtonRight = 104,
128  AllButtons = 105,
129  SeparatorHorz = 106,
130  SeparatorVert = 107,
131  TrackHorzLeft = 200,
132  TrackVertUpper = 201,
133  TrackHorzRight = 202,
134  TrackVertLower = 203,
135  TrackHorzArea = 204,
136  TrackVertArea = 205,
137  Arrow = 220,
138  ThumbHorz = 210, // Also used as toolbar grip
139  ThumbVert = 211, // Also used as toolbar grip
140  MenuItem = 250,
141  MenuItemCheckMark = 251,
142  MenuItemRadioMark = 252,
143  Separator = 253,
144  SubmenuArrow = 254,
145 
146 /* #i77549#
147  HACK: for scrollbars in case of thumb rect, page up and page down rect we
148  abuse the HitTestNativeScrollbar interface. All theming engines but aqua
149  are actually able to draw the thumb according to our internal representation.
150  However aqua draws a little outside. The canonical way would be to enhance the
151  HitTestNativeScrollbar passing a ScrollbarValue additionally so all necessary
152  information is available in the call.
153  .
154  However since there is only this one small exception we will deviate a little and
155  instead pass the respective rect as control region to allow for a small correction.
156 
157  So all places using HitTestNativeScrollbar on ControlPart::ThumbHorz, ControlPart::ThumbVert,
158  ControlPart::TrackHorzLeft, ControlPart::TrackHorzRight, ControlPart::TrackVertUpper, ControlPart::TrackVertLower
159  do not use the control rectangle as region but the actual part rectangle, making
160  only small deviations feasible.
161 */
162 
169  SubEdit = 300,
170 
171 // For controls that require the entire background
172 // to be drawn first, and then other pieces over top.
173 // (GTK+ scrollbars for example). Control region passed
174 // in to draw this part is expected to be the entire
175 // area of the control.
176 // A control may respond to one or both.
177  DrawBackgroundHorz = 1000,
178  DrawBackgroundVert = 1001,
179 
180 // GTK+ also draws tabs right->left since there is a
181 // hardcoded 2 pixel overlap between adjacent tabs
182  TabsDrawRtl = 3000,
183 
184 // Qt doesn't have a separate header to draw
185  TabPaneWithHeader = 3001,
186 
187 // For themes that do not want to have the focus
188 // rectangle part drawn by VCL but take care of the
189 // whole inner control part by themselves
190 // eg, listboxes or comboboxes or spinbuttons
191  HasBackgroundTexture = 4000,
192 
193 // For scrollbars that have 3 buttons (most KDE themes)
194  HasThreeButtons = 5000,
195 
196  BackgroundWindow = 6000,
197  BackgroundDialog = 6001,
198 
199 //to draw natively the border of frames
200  Border = 7000,
201 
202 //to draw natively the focus rects
203  Focus = 8000
204 };
205 
206 /* Control State:
207  *
208  * Specify how a particular part of the control
209  * is to be drawn. Constants are bitwise OR-ed
210  * together to compose a final drawing state.
211  * A _disabled_ state is assumed by the drawing
212  * functions until an ENABLED or HIDDEN is passed
213  * in the ControlState.
214  */
215 enum class ControlState {
216  NONE = 0,
217  ENABLED = 0x0001,
218  FOCUSED = 0x0002,
219  PRESSED = 0x0004,
220  ROLLOVER = 0x0008,
221  DEFAULT = 0x0020,
222  SELECTED = 0x0040
223 };
224 namespace o3tl
225 {
226  template<> struct typed_flags<ControlState> : is_typed_flags<ControlState, 0x006f> {};
227 }
228 
229 /* ButtonValue:
230  *
231  * Identifies the tri-state value options
232  * that buttons allow
233  */
234 
235 enum class ButtonValue {
236  DontKnow,
237  On,
238  Off,
239  Mixed
240 };
241 
242 /* ImplControlValue:
243  *
244  * Generic value container for all control parts.
245  */
246 
248 {
249  friend class SalFrame;
250 
251  private:
253  ButtonValue mTristate; // Tristate value: on, off, mixed
254  long mNumber; // numeric value
255  protected:
256  ImplControlValue( ControlType i_eType, long i_nNumber )
257  : mType( i_eType )
258  , mTristate( ButtonValue::DontKnow )
259  , mNumber( i_nNumber )
260  {}
261 
262  public:
263  explicit ImplControlValue( ButtonValue nTristate )
264  : mType( ControlType::Generic ), mTristate(nTristate), mNumber(0) {}
265  explicit ImplControlValue( long nNumeric )
266  : mType( ControlType::Generic ), mTristate(ButtonValue::DontKnow), mNumber( nNumeric) {}
268  : mType( ControlType::Generic ), mTristate(ButtonValue::DontKnow), mNumber(0) {}
269 
270  virtual ~ImplControlValue();
271 
272  ImplControlValue(ImplControlValue const &) = default;
273  ImplControlValue(ImplControlValue &&) = default;
274  ImplControlValue & operator =(ImplControlValue const &) = delete; // due to const mType
275  ImplControlValue & operator =(ImplControlValue &&) = delete; // due to const mType
276 
277  virtual ImplControlValue* clone() const;
278 
279  ControlType getType() const { return mType; }
280 
281  ButtonValue getTristateVal() const { return mTristate; }
282  void setTristateVal( ButtonValue nTristate ) { mTristate = nTristate; }
283 
284  long getNumericVal() const { return mNumber; }
285  void setNumericVal( long nNumeric ) { mNumber = nNumeric; }
286 };
287 
288 /* ScrollbarValue:
289  *
290  * Value container for scrollbars.
291  */
292 class SAL_DLLPUBLIC_RTTI ScrollbarValue final : public ImplControlValue
293 {
294  public:
295  long mnMin;
296  long mnMax;
297  long mnCur;
305 
308  {
309  mnMin = 0; mnMax = 0; mnCur = 0; mnVisibleSize = 0;
310  mnButton1State = ControlState::NONE; mnButton2State = ControlState::NONE;
311  mnThumbState = ControlState::NONE;
312  };
313  virtual ~ScrollbarValue() override;
314  virtual ScrollbarValue* clone() const override;
315 
316  ScrollbarValue(ScrollbarValue const &) = default;
317  ScrollbarValue(ScrollbarValue &&) = default;
318  ScrollbarValue & operator =(ScrollbarValue const &) = delete; // due to ImplControlValue
319  ScrollbarValue & operator =(ScrollbarValue &&) = delete; // due to ImplControlValue
320 };
321 
322 class SAL_DLLPUBLIC_RTTI SliderValue final : public ImplControlValue
323 {
324  public:
325  long mnMin;
326  long mnMax;
327  long mnCur;
330 
333  , mnMin( 0 ), mnMax( 0 ), mnCur( 0 ), mnThumbState( ControlState::NONE )
334  {}
335  virtual ~SliderValue() override;
336  virtual SliderValue* clone() const override;
337 
338  SliderValue(SliderValue const &) = default;
339  SliderValue(SliderValue &&) = default;
340  SliderValue & operator =(SliderValue const &) = delete; // due to ImplControlValue
341  SliderValue & operator =(SliderValue &&) = delete; // due to ImplControlValue
342 };
343 
345 {
346 public:
349  // increased tab size, so it'll overlab the frame rect when drawing
350  // static value, as there is currently no sane way to return additional data
351  static int m_nOverlap;
352 
353  TabPaneValue(const tools::Rectangle &rTabHeaderRect, const tools::Rectangle &rSelectedTabRect)
355  , m_aTabHeaderRect(rTabHeaderRect)
356  , m_aSelectedTabRect(rSelectedTabRect)
357  {
358  }
359  TabPaneValue* clone() const override;
360 
361  TabPaneValue(TabPaneValue const &) = default;
362  TabPaneValue(TabPaneValue &&) = default;
363  TabPaneValue & operator =(TabPaneValue const &) = delete;
364  TabPaneValue & operator =(TabPaneValue &&) = delete;
365 };
366 
367 /* TabitemValue:
368  *
369  * Value container for tabitems.
370  */
371 
372 /* TABITEM constants are OR-ed together */
373 enum class TabitemFlags
374 {
375  NONE = 0x00,
376  LeftAligned = 0x01, // the tabitem is aligned with the left border of the TabControl
377  RightAligned = 0x02, // the tabitem is aligned with the right border of the TabControl
378  FirstInGroup = 0x04, // the tabitem is the first in group of tabitems
379  LastInGroup = 0x08, // the tabitem is the last in group of tabitems
380 };
381 namespace o3tl
382 {
383  template<> struct typed_flags<TabitemFlags> : is_typed_flags<TabitemFlags, 0x0f> {};
384 }
385 
386 class SAL_DLLPUBLIC_RTTI TabitemValue final : public ImplControlValue
387 {
388  public:
391 
392  TabitemValue(const tools::Rectangle &rContentRect)
394  , mnAlignment(TabitemFlags::NONE)
395  , maContentRect(rContentRect)
396  {
397  }
398  virtual ~TabitemValue() override;
399  virtual TabitemValue* clone() const override;
400 
401  TabitemValue(TabitemValue const &) = default;
402  TabitemValue(TabitemValue &&) = default;
403  TabitemValue & operator =(TabitemValue const &) = delete; // due to ImplControlValue
404  TabitemValue & operator =(TabitemValue &&) = delete; // due to ImplControlValue
405 
406  bool isLeftAligned() const { return bool(mnAlignment & TabitemFlags::LeftAligned); }
407  bool isRightAligned() const { return bool(mnAlignment & TabitemFlags::RightAligned); }
408  bool isBothAligned() const { return isLeftAligned() && isRightAligned(); }
409  bool isNotAligned() const { return !(mnAlignment & (TabitemFlags::LeftAligned | TabitemFlags::RightAligned)); }
410  bool isFirst() const { return bool(mnAlignment & TabitemFlags::FirstInGroup); }
411  bool isLast() const { return bool(mnAlignment & TabitemFlags::LastInGroup); }
412  const tools::Rectangle& getContentRect() const { return maContentRect; }
413 };
414 
415 /* SpinbuttonValue:
416  *
417  * Value container for spinbuttons to paint both buttons at once.
418  * Note: the other parameters of DrawNativeControl will have no meaning
419  * all parameters for spinbuttons are carried here
420  */
421 class SAL_DLLPUBLIC_RTTI SpinbuttonValue final : public ImplControlValue
422 {
423  public:
430 
433  , mnUpperState(ControlState::NONE)
434  , mnLowerState(ControlState::NONE)
435  , mnUpperPart(ControlPart::NONE)
436  , mnLowerPart(ControlPart::NONE)
437  {
438  }
439 
440  virtual ~SpinbuttonValue() override;
441  virtual SpinbuttonValue* clone() const override;
442 
443  SpinbuttonValue(SpinbuttonValue const &) = default;
444  SpinbuttonValue(SpinbuttonValue &&) = default;
445  SpinbuttonValue & operator =(SpinbuttonValue const &) = delete; // due to ImplControlValue
446  SpinbuttonValue & operator =(SpinbuttonValue &&) = delete; // due to ImplControlValue
447 };
448 
449 /* Toolbarvalue:
450  *
451  * Value container for toolbars detailing the grip position
452  */
453 class ToolbarValue final : public ImplControlValue
454 {
455 public:
457  { mbIsTopDockingArea = false; }
458  virtual ~ToolbarValue() override;
459  virtual ToolbarValue* clone() const override;
460 
461  ToolbarValue(ToolbarValue const &) = default;
462  ToolbarValue(ToolbarValue &&) = default;
463  ToolbarValue & operator =(ToolbarValue const &) = delete; // due to ImplControlValue
464  ToolbarValue & operator =(ToolbarValue &&) = delete; // due to ImplControlValue
465 
467  bool mbIsTopDockingArea; // indicates that this is the top aligned dockingarea
468  // adjacent to the menubar, only used on Windows
469 };
470 
471 /* MenubarValue:
472  *
473  * Value container for menubars specifying height of adjacent docking area
474  */
475 class MenubarValue final : public ImplControlValue
476 {
477 public:
480  virtual ~MenubarValue() override;
481  virtual MenubarValue* clone() const override;
482  MenubarValue(MenubarValue const &) = default;
483  MenubarValue(MenubarValue &&) = default;
484  MenubarValue & operator =(MenubarValue const &) = delete; // due to ImplControlValue
485  MenubarValue & operator =(MenubarValue &&) = delete; // due to ImplControlValue
487 };
488 
489 /* MenupopupValue:
490  *
491  * Value container for menu items; specifies the rectangle for the whole item which
492  * may be useful when drawing parts with a smaller rectangle.
493  */
494 class SAL_DLLPUBLIC_RTTI MenupopupValue final : public ImplControlValue
495 {
496 public:
497  MenupopupValue( long i_nGutterWidth, const tools::Rectangle& i_rItemRect )
498  : ImplControlValue( ControlType::MenuPopup, i_nGutterWidth )
499  , maItemRect( i_rItemRect )
500  {}
501  virtual ~MenupopupValue() override;
502  virtual MenupopupValue* clone() const override;
503  MenupopupValue(MenupopupValue const &) = default;
504  MenupopupValue(MenupopupValue &&) = default;
505  MenupopupValue & operator =(MenupopupValue const &) = delete; // due to ImplControlValue
506  MenupopupValue & operator =(MenupopupValue &&) = delete; // due to ImplControlValue
508 };
509 
510 /* PushButtonValue:
511  *
512  * Value container for pushbuttons specifying additional drawing hints
513  */
515 {
516 public:
519  , mbBevelButton(false)
520  , mbSingleLine(true)
521  , mbIsAction(false)
522  {}
523 
524  virtual ~PushButtonValue() override;
525  virtual PushButtonValue* clone() const override;
526 
527  PushButtonValue(PushButtonValue const &) = default;
528  PushButtonValue(PushButtonValue &&) = default;
529  PushButtonValue & operator =(PushButtonValue const &) = delete; // due to ImplControlValue
530  PushButtonValue & operator =(PushButtonValue &&) = delete; // due to ImplControlValue
531 
532  bool mbBevelButton:1; // only used on OSX
533  bool mbSingleLine:1; // only used on OSX
534  bool mbIsAction:1;
535 };
536 
537 
538 #endif
539 
540 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const tools::Rectangle & getContentRect() const
tools::Rectangle m_aTabHeaderRect
virtual MenubarValue * clone() const override
MenubarValue & operator=(MenubarValue const &)=delete
TabitemFlags
ControlType getType() const
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
tools::Rectangle maButton2Rect
void setTristateVal(ButtonValue nTristate)
ControlPart mnLowerPart
ToolbarValue & operator=(ToolbarValue const &)=delete
tools::Rectangle maLowerRect
NONE
tools::Rectangle maUpperRect
ControlState mnButton2State
TabitemFlags mnAlignment
bool isFirst() const
bool isLeftAligned() const
ControlType const mType
bool isLast() const
ControlPart mnUpperPart
tools::Rectangle maItemRect
ControlState mnUpperState
tools::Rectangle maContentRect
virtual ImplControlValue * clone() const
bool isRightAligned() const
The edit field part of a control, e.g.
tools::Rectangle maButton1Rect
ControlState mnLowerState
ImplControlValue(ButtonValue nTristate)
bool isBothAligned() const
ControlState mnButton1State
tools::Rectangle m_aSelectedTabRect
tools::Rectangle maThumbRect
TabitemValue(const tools::Rectangle &rContentRect)
ControlState mnThumbState
ControlType
These types are all based on the supported variants vcl/salnativewidgets.hxx and must be kept in-sync...
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
TabPaneValue(const tools::Rectangle &rTabHeaderRect, const tools::Rectangle &rSelectedTabRect)
ControlState mnThumbState
virtual ToolbarValue * clone() const override
ImplControlValue(long nNumeric)
void setNumericVal(long nNumeric)
ButtonValue getTristateVal() const
virtual ~MenubarValue() override
static int m_nOverlap
T * clone(T *const other)
tools::Rectangle maGripRect
long getNumericVal() const
MenupopupValue(long i_nGutterWidth, const tools::Rectangle &i_rItemRect)
tools::Rectangle maThumbRect
bool isNotAligned() const
ImplControlValue(ControlType i_eType, long i_nNumber)
ImplControlValue & operator=(ImplControlValue const &)=delete
virtual ~ToolbarValue() override