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 #include <vcl/toolbox.hxx>
21 #include <vcl/commandinfoprovider.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/decoview.hxx>
24 #include <vcl/accel.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/help.hxx>
27 #include <vcl/mnemonic.hxx>
28 #include <vcl/gradient.hxx>
29 #include <vcl/layout.hxx>
30 #include <vcl/menu.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/vclstatuslistener.hxx>
33 #include <vcl/ptrstyle.hxx>
34 #include <bitmaps.hlst>
36 #include <tools/poly.hxx>
37 #include <svl/imageitm.hxx>
38 #include <sal/log.hxx>
39 #include <osl/diagnose.h>
54 #define SMALLBUTTON_HSIZE 7
55 #define SMALLBUTTON_VSIZE 7
57 #define SMALLBUTTON_OFF_NORMAL_X 3
58 #define SMALLBUTTON_OFF_NORMAL_Y 3
60 #define TB_TEXTOFFSET 2
61 #define TB_IMAGETEXTOFFSET 3
62 #define TB_LINESPACING 3
63 #define TB_SPIN_SIZE 14
64 #define TB_SPIN_OFFSET 2
65 #define TB_BORDER_OFFSET1 4
66 #define TB_BORDER_OFFSET2 2
68 #define TB_MAXNOSCROLL 32765
70 #define TB_DRAGWIDTH 8 // the default width of the drag grip
72 #define TB_CALCMODE_HORZ 1
73 #define TB_CALCMODE_VERT 2
74 #define TB_CALCMODE_FLOAT 3
76 #define TB_WBLINESIZING (WB_SIZEABLE | WB_DOCKABLE | WB_SCROLL)
78 #define DOCK_LINEHSIZE (sal_uInt16(0x0001))
79 #define DOCK_LINEVSIZE (sal_uInt16(0x0002))
80 #define DOCK_LINERIGHT (sal_uInt16(0x1000))
81 #define DOCK_LINEBOTTOM (sal_uInt16(0x2000))
82 #define DOCK_LINELEFT (sal_uInt16(0x4000))
83 #define DOCK_LINETOP (sal_uInt16(0x8000))
84 #define DOCK_LINEOFFSET 3
89 VclPtr
<ToolBox
> mpDragBox
;
91 tools::Rectangle maRect
;
92 tools::Rectangle maStartRect
;
94 sal_uInt16 mnLineMode
;
95 ToolBox::ImplToolItems::size_type mnStartLines
;
97 ImplTBDragMgr(const ImplTBDragMgr
&) = delete;
98 ImplTBDragMgr
& operator=(const ImplTBDragMgr
&) = delete;
103 void StartDragging( ToolBox
* pDragBox
, const Point
& rPos
, const tools::Rectangle
& rRect
, sal_uInt16 nLineMode
);
104 void Dragging( const Point
& rPos
);
105 void EndDragging( bool bOK
= true );
106 DECL_LINK( SelectHdl
, Accelerator
&, void );
110 static ImplTBDragMgr
* ImplGetTBDragMgr()
112 ImplSVData
* pSVData
= ImplGetSVData();
113 if ( !pSVData
->maCtrlData
.mpTBDragMgr
)
114 pSVData
->maCtrlData
.mpTBDragMgr
= new ImplTBDragMgr
;
115 return pSVData
->maCtrlData
.mpTBDragMgr
;
118 int ToolBox::ImplGetDragWidth( const vcl::RenderContext
& rRenderContext
, bool bHorz
)
120 int nWidth
= TB_DRAGWIDTH
;
121 if( rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Entire
) )
124 ImplControlValue aControlValue
;
125 tools::Rectangle aContent
, aBound
;
126 tools::Rectangle
aArea( Point(), rRenderContext
.GetOutputSizePixel() );
128 if ( rRenderContext
.GetNativeControlRegion(ControlType::Toolbar
,
129 bHorz
? ControlPart::ThumbVert
: ControlPart::ThumbHorz
,
130 aArea
, ControlState::NONE
, aControlValue
, aBound
, aContent
) )
132 nWidth
= bHorz
? aContent
.GetWidth() : aContent
.GetHeight();
136 // increase the hit area of the drag handle according to DPI scale factor
137 nWidth
*= rRenderContext
.GetDPIScaleFactor();
142 int ToolBox::ImplGetDragWidth() const
144 return ToolBox::ImplGetDragWidth( *this, mbHorz
);
147 static ButtonType
determineButtonType( ImplToolItem
const * pItem
, ButtonType defaultType
)
149 ButtonType tmpButtonType
= defaultType
;
150 ToolBoxItemBits nBits
= pItem
->mnBits
& ( ToolBoxItemBits::TEXT_ONLY
| ToolBoxItemBits::ICON_ONLY
);
151 if ( nBits
!= ToolBoxItemBits::NONE
) // item has custom setting
153 tmpButtonType
= ButtonType::SYMBOLTEXT
;
154 if ( nBits
== ToolBoxItemBits::TEXT_ONLY
)
155 tmpButtonType
= ButtonType::TEXT
;
156 else if ( nBits
== ToolBoxItemBits::ICON_ONLY
)
157 tmpButtonType
= ButtonType::SYMBOLONLY
;
159 return tmpButtonType
;
162 void ToolBox::ImplUpdateDragArea() const
164 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
167 if ( ImplIsFloatingMode() || pWrapper
->IsLocked() )
168 pWrapper
->SetDragArea( tools::Rectangle() );
171 if( meAlign
== WindowAlign::Top
|| meAlign
== WindowAlign::Bottom
)
172 pWrapper
->SetDragArea( tools::Rectangle( 0, 0, ImplGetDragWidth(), GetOutputSizePixel().Height() ) );
174 pWrapper
->SetDragArea( tools::Rectangle( 0, 0, GetOutputSizePixel().Width(), ImplGetDragWidth() ) );
179 void ToolBox::ImplCalcBorder( WindowAlign eAlign
, long& rLeft
, long& rTop
,
180 long& rRight
, long& rBottom
) const
182 if( ImplIsFloatingMode() || !(mnWinStyle
& WB_BORDER
) )
184 // no border in floating mode
185 rLeft
= rTop
= rRight
= rBottom
= 0;
189 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
191 // reserve DragArea only for dockable toolbars
192 int dragwidth
= ( pWrapper
&& !pWrapper
->IsLocked() ) ? ImplGetDragWidth() : 0;
194 // no shadow border for dockable toolbars
195 int borderwidth
= pWrapper
? 0: 2;
197 if ( eAlign
== WindowAlign::Top
)
199 rLeft
= borderwidth
+dragwidth
;
201 rRight
= borderwidth
;
204 else if ( eAlign
== WindowAlign::Left
)
207 rTop
= borderwidth
+dragwidth
;
209 rBottom
= borderwidth
;
211 else if ( eAlign
== WindowAlign::Bottom
)
213 rLeft
= borderwidth
+dragwidth
;
215 rRight
= borderwidth
;
216 rBottom
= borderwidth
;
221 rTop
= borderwidth
+dragwidth
;
222 rRight
= borderwidth
;
223 rBottom
= borderwidth
;
227 void ToolBox::ImplCheckUpdate()
229 // remove any pending invalidates to avoid
230 // have them triggered when paint is locked (see mpData->mbIsPaintLocked)
231 // which would result in erasing the background only and not painting any items
232 // this must not be done when we're already in Paint()
234 // this is only required for transparent toolbars (see ImplDrawTransparentBackground() )
235 if( !IsBackground() && HasPaintEvent() && !IsInPaint() )
239 void ToolBox::ImplDrawGrip(vcl::RenderContext
& rRenderContext
,
240 const tools::Rectangle
&aDragArea
, int nDragWidth
, WindowAlign eAlign
, bool bHorz
)
242 bool bNativeOk
= false;
243 const ControlPart ePart
= bHorz
? ControlPart::ThumbVert
: ControlPart::ThumbHorz
;
244 const Size
aSz( rRenderContext
.GetOutputSizePixel() );
245 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ePart
))
247 ToolbarValue aToolbarValue
;
248 aToolbarValue
.maGripRect
= aDragArea
;
250 tools::Rectangle
aCtrlRegion(Point(), aSz
);
252 bNativeOk
= rRenderContext
.DrawNativeControl( ControlType::Toolbar
, ePart
,
253 aCtrlRegion
, ControlState::ENABLED
, aToolbarValue
, OUString() );
259 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
260 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
261 rRenderContext
.SetFillColor(rStyleSettings
.GetShadowColor());
263 float fScaleFactor
= rRenderContext
.GetDPIScaleFactor();
265 if (eAlign
== WindowAlign::Top
|| eAlign
== WindowAlign::Bottom
)
267 int height
= static_cast<int>(0.6 * aSz
.Height() + 0.5);
268 int i
= (aSz
.Height() - height
) / 2;
272 int x
= nDragWidth
/ 2;
273 rRenderContext
.DrawEllipse(tools::Rectangle(Point(x
, i
), Size(2 * fScaleFactor
, 2 * fScaleFactor
)));
274 i
+= 4 * fScaleFactor
;
279 int width
= static_cast<int>(0.6 * aSz
.Width() + 0.5);
280 int i
= (aSz
.Width() - width
) / 2;
284 int y
= nDragWidth
/ 2;
285 rRenderContext
.DrawEllipse(tools::Rectangle(Point(i
, y
), Size(2 * fScaleFactor
, 2 * fScaleFactor
)));
286 i
+= 4 * fScaleFactor
;
291 void ToolBox::ImplDrawGrip(vcl::RenderContext
& rRenderContext
)
293 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
294 if( pWrapper
&& !pWrapper
->GetDragArea().IsEmpty() )
296 // execute pending paint requests
298 ImplDrawGrip( rRenderContext
, pWrapper
->GetDragArea(),
299 ImplGetDragWidth(), meAlign
, mbHorz
);
303 void ToolBox::ImplDrawGradientBackground(vcl::RenderContext
& rRenderContext
)
305 // draw a nice gradient
307 Color startCol
, endCol
;
308 const StyleSettings rSettings
= rRenderContext
.GetSettings().GetStyleSettings();
310 startCol
= rSettings
.GetFaceGradientColor();
311 endCol
= rSettings
.GetFaceColor();
312 if (rSettings
.GetHighContrastMode())
313 // no 'extreme' gradient when high contrast
317 g
.SetAngle(mbHorz
? 0 : 900);
318 g
.SetStyle(GradientStyle::Linear
);
320 g
.SetStartColor(startCol
);
321 g
.SetEndColor(endCol
);
323 bool bLineColor
= rRenderContext
.IsLineColor();
324 Color aOldCol
= rRenderContext
.GetLineColor();
325 rRenderContext
.SetLineColor(rRenderContext
.GetSettings().GetStyleSettings().GetShadowColor());
327 Size
aFullSz(GetOutputSizePixel());
328 Size
aLineSz(aFullSz
);
330 // use the linesize only when floating
331 // full window height is used when docked (single line)
332 if (ImplIsFloatingMode())
337 nLineSize
= mnMaxItemHeight
;
338 if (mnWinHeight
> mnMaxItemHeight
)
339 nLineSize
= mnWinHeight
;
341 aLineSz
.setHeight( nLineSize
);
345 nLineSize
= mnMaxItemWidth
;
346 aLineSz
.setWidth( nLineSize
);
350 long nLeft
, nTop
, nRight
, nBottom
;
351 ImplCalcBorder(meAlign
, nLeft
, nTop
, nRight
, nBottom
);
353 Size
aTopLineSz(aLineSz
);
354 Size
aBottomLineSz(aLineSz
);
356 if (mnWinStyle
& WB_BORDER
)
360 aTopLineSz
.AdjustHeight(TB_BORDER_OFFSET2
+ nTop
);
361 aBottomLineSz
.AdjustHeight(TB_BORDER_OFFSET2
+ nBottom
);
364 aTopLineSz
.AdjustHeight(TB_BORDER_OFFSET2
+ nBottom
);
368 aTopLineSz
.AdjustWidth(TB_BORDER_OFFSET1
+ nLeft
);
369 aBottomLineSz
.AdjustWidth(TB_BORDER_OFFSET1
+ nRight
);
372 aTopLineSz
.AdjustWidth(TB_BORDER_OFFSET1
+ nLeft
);
380 aLineSz
.AdjustHeight(TB_LINESPACING
);
382 aTopLineSz
.AdjustHeight(TB_LINESPACING
);
386 aLineSz
.AdjustWidth(TB_LINESPACING
);
388 aTopLineSz
.AdjustWidth(TB_LINESPACING
);
396 rRenderContext
.DrawGradient(tools::Rectangle(0, y
, aTopLineSz
.Width(), y
+ aTopLineSz
.Height()), g
);
397 y
+= aTopLineSz
.Height();
399 while (y
< (mnDY
- aBottomLineSz
.Height()))
401 rRenderContext
.DrawGradient(tools::Rectangle(0, y
, aLineSz
.Width(), y
+ aLineSz
.Height()), g
);
402 y
+= aLineSz
.Height();
405 rRenderContext
.DrawGradient(tools::Rectangle(0, y
, aBottomLineSz
.Width(), y
+ aBottomLineSz
.Height()), g
);
411 rRenderContext
.DrawGradient(tools::Rectangle(x
, 0, x
+ aTopLineSz
.Width(), aTopLineSz
.Height()), g
);
412 x
+= aTopLineSz
.Width();
414 while (x
< (mnDX
- aBottomLineSz
.Width()))
416 rRenderContext
.DrawGradient(tools::Rectangle(x
, 0, x
+ aLineSz
.Width(), aLineSz
.Height()), g
);
417 x
+= aLineSz
.Width();
420 rRenderContext
.DrawGradient(tools::Rectangle( x
, 0, x
+ aBottomLineSz
.Width(), aBottomLineSz
.Height()), g
);
424 rRenderContext
.SetLineColor( aOldCol
);
428 bool ToolBox::ImplDrawNativeBackground(vcl::RenderContext
& rRenderContext
)
431 tools::Rectangle
aCtrlRegion(Point(), GetOutputSizePixel());
433 return rRenderContext
.DrawNativeControl( ControlType::Toolbar
, mbHorz
? ControlPart::DrawBackgroundHorz
: ControlPart::DrawBackgroundVert
,
434 aCtrlRegion
, ControlState::ENABLED
, ImplControlValue(), OUString() );
437 void ToolBox::ImplDrawTransparentBackground(const vcl::Region
&rRegion
)
439 // just invalidate to trigger paint of the parent
440 const bool bOldPaintLock
= mpData
->mbIsPaintLocked
;
441 mpData
->mbIsPaintLocked
= true;
443 // send an invalidate to the first opaque parent and invalidate the whole hierarchy from there (noclipchildren)
444 Invalidate(rRegion
, InvalidateFlags::Update
| InvalidateFlags::NoClipChildren
);
446 mpData
->mbIsPaintLocked
= bOldPaintLock
;
449 void ToolBox::ImplDrawConstantBackground(vcl::RenderContext
& rRenderContext
, const vcl::Region
&rRegion
, bool bIsInPopupMode
)
451 // draw a constant color
454 // default background
455 rRenderContext
.Erase(rRegion
.GetBoundRect());
459 // use different color in popupmode
460 const StyleSettings rSettings
= rRenderContext
.GetSettings().GetStyleSettings();
461 Wallpaper
aWallpaper(rSettings
.GetFaceGradientColor());
462 rRenderContext
.DrawWallpaper(rRegion
.GetBoundRect(), aWallpaper
);
466 void ToolBox::ImplDrawBackground(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
468 // execute pending paint requests
471 ImplDockingWindowWrapper
* pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
472 bool bIsInPopupMode
= ImplIsInPopupMode();
474 vcl::Region
aPaintRegion(rRect
);
476 // make sure we do not invalidate/erase too much
478 aPaintRegion
.Intersect(GetActiveClipRegion());
480 rRenderContext
.Push(PushFlags::CLIPREGION
);
481 rRenderContext
.IntersectClipRegion( aPaintRegion
);
485 // no gradient for ordinary toolbars (not dockable)
486 if( !IsBackground() && !IsInPaint() )
487 ImplDrawTransparentBackground(aPaintRegion
);
489 ImplDrawConstantBackground(rRenderContext
, aPaintRegion
, bIsInPopupMode
);
493 // toolbars known to the dockingmanager will be drawn using NWF or a gradient
494 // docked toolbars are transparent and NWF is already used in the docking area which is their common background
495 // so NWF is used here for floating toolbars only
496 bool bNativeOk
= false;
497 if( ImplIsFloatingMode() && rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Entire
) )
498 bNativeOk
= ImplDrawNativeBackground(rRenderContext
);
501 const StyleSettings rSetting
= Application::GetSettings().GetStyleSettings();
502 const bool isHeader
= GetAlign() == WindowAlign::Top
&& !rSetting
.GetPersonaHeader().IsEmpty();
503 const bool isFooter
= GetAlign() == WindowAlign::Bottom
&& !rSetting
.GetPersonaFooter().IsEmpty();
504 if (!IsBackground() || isHeader
|| isFooter
)
507 ImplDrawTransparentBackground(aPaintRegion
);
510 ImplDrawGradientBackground(rRenderContext
);
514 // restore clip region
515 rRenderContext
.Pop();
518 void ToolBox::ImplErase(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&rRect
, bool bHighlight
, bool bHasOpenPopup
)
520 // the background of non NWF buttons is painted in a constant color
521 // to have the same highlight color (transparency in DrawSelectionBackground())
522 // items with open popups will also painted using a constant color
523 if (!mpData
->mbNativeButtons
&&
524 (bHighlight
|| !(GetStyle() & WB_3DLOOK
)))
526 if (GetStyle() & WB_3DLOOK
)
528 rRenderContext
.Push(PushFlags::LINECOLOR
| PushFlags::FILLCOLOR
);
529 rRenderContext
.SetLineColor();
531 // choose the same color as the popup will use
532 rRenderContext
.SetFillColor(rRenderContext
.GetSettings().GetStyleSettings().GetFaceGradientColor());
534 rRenderContext
.SetFillColor(COL_WHITE
);
536 rRenderContext
.DrawRect(rRect
);
537 rRenderContext
.Pop();
540 ImplDrawBackground(rRenderContext
, rRect
);
543 ImplDrawBackground(rRenderContext
, rRect
);
546 void ToolBox::ImplDrawBorder(vcl::RenderContext
& rRenderContext
)
548 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
552 ImplDockingWindowWrapper
* pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
554 // draw borders for ordinary toolbars only (not dockable)
558 if (meAlign
== WindowAlign::Bottom
)
560 // draw bottom border
561 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
562 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-1, nDY
-2 ) );
563 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
564 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
569 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
570 rRenderContext
.DrawLine( Point( 0, 0 ), Point( nDX
-1, 0 ) );
571 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
572 rRenderContext
.DrawLine( Point( 0, 1 ), Point( nDX
-1, 1 ) );
574 if (meAlign
== WindowAlign::Left
|| meAlign
== WindowAlign::Right
)
576 if (meAlign
== WindowAlign::Left
)
578 // draw left-bottom border
579 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
580 rRenderContext
.DrawLine( Point( 0, 0 ), Point( 0, nDY
-1 ) );
581 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-1, nDY
-2 ) );
582 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
583 rRenderContext
.DrawLine( Point( 1, 1 ), Point( 1, nDY
-3 ) );
584 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
588 // draw right-bottom border
589 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
590 rRenderContext
.DrawLine( Point( nDX
-2, 0 ), Point( nDX
-2, nDY
-3 ) );
591 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-2, nDY
-2 ) );
592 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
593 rRenderContext
.DrawLine( Point( nDX
-1, 0 ), Point( nDX
-1, nDY
-1 ) );
594 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
599 if ( meAlign
== WindowAlign::Bottom
|| meAlign
== WindowAlign::Top
)
602 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
603 rRenderContext
.DrawLine( Point( nDX
-2, 0 ), Point( nDX
-2, nDY
-1 ) );
604 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
605 rRenderContext
.DrawLine( Point( nDX
-1, 0 ), Point( nDX
-1, nDY
-1 ) );
609 static bool ImplIsFixedControl( const ImplToolItem
*pItem
)
611 return ( pItem
->mpWindow
&&
612 (pItem
->mpWindow
->GetType() == WindowType::FIXEDTEXT
||
613 pItem
->mpWindow
->GetType() == WindowType::FIXEDLINE
||
614 pItem
->mpWindow
->GetType() == WindowType::GROUPBOX
) );
617 const ImplToolItem
*ToolBox::ImplGetFirstClippedItem() const
619 for (auto & item
: mpData
->m_aItems
)
621 if( item
.IsClipped() )
627 Size
ToolBox::ImplCalcSize( ImplToolItems::size_type nCalcLines
, sal_uInt16 nCalcMode
)
635 WindowAlign eOldAlign
= meAlign
;
636 bool bOldHorz
= mbHorz
;
637 bool bOldAssumeDocked
= mpData
->mbAssumeDocked
;
638 bool bOldAssumeFloating
= mpData
->mbAssumeFloating
;
642 bool bOldFloatingMode
= ImplIsFloatingMode();
644 mpData
->mbAssumeDocked
= false;
645 mpData
->mbAssumeFloating
= false;
647 if ( nCalcMode
== TB_CALCMODE_HORZ
)
649 mpData
->mbAssumeDocked
= true; // force non-floating mode during calculation
650 ImplCalcBorder( WindowAlign::Top
, nLeft
, nTop
, nRight
, nBottom
);
652 if ( mbHorz
!= bOldHorz
)
653 meAlign
= WindowAlign::Top
;
655 else if ( nCalcMode
== TB_CALCMODE_VERT
)
657 mpData
->mbAssumeDocked
= true; // force non-floating mode during calculation
658 ImplCalcBorder( WindowAlign::Left
, nLeft
, nTop
, nRight
, nBottom
);
660 if ( mbHorz
!= bOldHorz
)
661 meAlign
= WindowAlign::Left
;
663 else if ( nCalcMode
== TB_CALCMODE_FLOAT
)
665 mpData
->mbAssumeFloating
= true; // force non-floating mode during calculation
666 nLeft
= nTop
= nRight
= nBottom
= 0;
668 if ( mbHorz
!= bOldHorz
)
669 meAlign
= WindowAlign::Top
;
672 if ( (meAlign
!= eOldAlign
) || (mbHorz
!= bOldHorz
) ||
673 (ImplIsFloatingMode() != bOldFloatingMode
) )
677 ImplCalcBorder( meAlign
, nLeft
, nTop
, nRight
, nBottom
);
681 if( !nCalcMode
&& ImplIsFloatingMode() )
683 aSize
= ImplCalcFloatSize( nCalcLines
);
689 if ( mnWinHeight
> mnMaxItemHeight
)
690 aSize
.setHeight( nCalcLines
* mnWinHeight
);
692 aSize
.setHeight( nCalcLines
* mnMaxItemHeight
);
695 aSize
.AdjustHeight((nCalcLines
-1)*TB_LINESPACING
);
697 if ( mnWinStyle
& WB_BORDER
)
698 aSize
.AdjustHeight((TB_BORDER_OFFSET2
*2) + nTop
+ nBottom
);
701 ImplCalcBreaks( TB_MAXNOSCROLL
, &nMax
, mbHorz
);
703 aSize
.AdjustWidth(nMax
);
705 if ( mnWinStyle
& WB_BORDER
)
706 aSize
.AdjustWidth((TB_BORDER_OFFSET1
*2) + nLeft
+ nRight
);
710 aSize
.setWidth( nCalcLines
* mnMaxItemWidth
);
713 aSize
.AdjustWidth((nCalcLines
-1)*TB_LINESPACING
);
715 if ( mnWinStyle
& WB_BORDER
)
716 aSize
.AdjustWidth((TB_BORDER_OFFSET2
*2) + nLeft
+ nRight
);
719 ImplCalcBreaks( TB_MAXNOSCROLL
, &nMax
, mbHorz
);
721 aSize
.AdjustHeight(nMax
);
723 if ( mnWinStyle
& WB_BORDER
)
724 aSize
.AdjustHeight((TB_BORDER_OFFSET1
*2) + nTop
+ nBottom
);
727 // restore previous values
730 mpData
->mbAssumeDocked
= bOldAssumeDocked
;
731 mpData
->mbAssumeFloating
= bOldAssumeFloating
;
732 if ( (meAlign
!= eOldAlign
) || (mbHorz
!= bOldHorz
) )
743 void ToolBox::ImplCalcFloatSizes()
745 if ( !maFloatSizes
.empty() )
748 // calculate the minimal size, i.e. where the biggest item just fits
751 for (auto const& item
: mpData
->m_aItems
)
753 if ( item
.mbVisible
)
757 long nTempSize
= item
.mpWindow
->GetSizePixel().Width();
758 if ( nTempSize
> nCalcSize
)
759 nCalcSize
= nTempSize
;
763 if( item
.maItemSize
.Width() > nCalcSize
)
764 nCalcSize
= item
.maItemSize
.Width();
769 // calc an upper bound for ImplCalcBreaks below
770 long upperBoundWidth
= nCalcSize
* mpData
->m_aItems
.size();
772 ImplToolItems::size_type nLines
;
773 ImplToolItems::size_type nCalcLines
;
774 ImplToolItems::size_type nTempLines
;
776 nCalcLines
= ImplCalcBreaks( nCalcSize
, &nMaxLineWidth
, true );
778 maFloatSizes
.reserve( nCalcLines
);
780 nTempLines
= nLines
= nCalcLines
;
783 long nHeight
= ImplCalcSize( nTempLines
, TB_CALCMODE_FLOAT
).Height();
786 aSize
.mnWidth
= nMaxLineWidth
+(TB_BORDER_OFFSET1
*2);
787 aSize
.mnHeight
= nHeight
;
788 aSize
.mnLines
= nTempLines
;
789 maFloatSizes
.push_back( aSize
);
795 nCalcSize
+= mnMaxItemWidth
;
796 nTempLines
= ImplCalcBreaks( nCalcSize
, &nMaxLineWidth
, true );
798 while ((nCalcSize
< upperBoundWidth
) && (nLines
< nTempLines
)); // implies nTempLines>1
799 if ( nTempLines
< nLines
)
805 Size
ToolBox::ImplCalcFloatSize( ImplToolItems::size_type
& rLines
)
807 ImplCalcFloatSizes();
811 rLines
= mnFloatLines
;
817 while ( i
+ 1u < maFloatSizes
.size() && rLines
< maFloatSizes
[i
].mnLines
)
822 Size
aSize( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
823 rLines
= maFloatSizes
[i
].mnLines
;
828 void ToolBox::ImplCalcMinMaxFloatSize( Size
& rMinSize
, Size
& rMaxSize
)
830 ImplCalcFloatSizes();
833 rMinSize
= Size( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
834 rMaxSize
= Size( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
835 while ( ++i
< maFloatSizes
.size() )
837 if( maFloatSizes
[i
].mnWidth
< rMinSize
.Width() )
838 rMinSize
.setWidth( maFloatSizes
[i
].mnWidth
);
839 if( maFloatSizes
[i
].mnHeight
< rMinSize
.Height() )
840 rMinSize
.setHeight( maFloatSizes
[i
].mnHeight
);
842 if( maFloatSizes
[i
].mnWidth
> rMaxSize
.Width() )
843 rMaxSize
.setWidth( maFloatSizes
[i
].mnWidth
);
844 if( maFloatSizes
[i
].mnHeight
> rMaxSize
.Height() )
845 rMaxSize
.setHeight( maFloatSizes
[i
].mnHeight
);
849 void ToolBox::ImplSetMinMaxFloatSize()
851 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
852 Size aMinSize
, aMaxSize
;
853 ImplCalcMinMaxFloatSize( aMinSize
, aMaxSize
);
856 pWrapper
->SetMinOutputSizePixel( aMinSize
);
857 pWrapper
->SetMaxOutputSizePixel( aMaxSize
);
858 pWrapper
->ShowTitleButton( TitleButton::Menu
, bool( GetMenuType() & ToolBoxMenuType::Customize
) );
862 // TODO: change SetMinOutputSizePixel to be not inline
863 SetMinOutputSizePixel( aMinSize
);
864 SetMaxOutputSizePixel( aMaxSize
);
868 ToolBox::ImplToolItems::size_type
ToolBox::ImplCalcLines( long nToolSize
) const
874 if ( mnWinHeight
> mnMaxItemHeight
)
875 nLineHeight
= mnWinHeight
;
877 nLineHeight
= mnMaxItemHeight
;
880 nLineHeight
= mnMaxItemWidth
;
882 if ( mnWinStyle
& WB_BORDER
)
883 nToolSize
-= TB_BORDER_OFFSET2
*2;
887 nLineHeight
+= TB_LINESPACING
;
888 nToolSize
+= TB_LINESPACING
;
891 // #i91917# always report at least one line
892 long nLines
= nToolSize
/nLineHeight
;
899 sal_uInt16
ToolBox::ImplTestLineSize( const Point
& rPos
) const
901 if ( !ImplIsFloatingMode() &&
902 (!mbScroll
|| (mnLines
> 1) || (mnCurLines
> mnVisLines
)) )
904 WindowAlign eAlign
= GetAlign();
906 if ( eAlign
== WindowAlign::Left
)
908 if ( rPos
.X() > mnDX
-DOCK_LINEOFFSET
)
909 return DOCK_LINEHSIZE
| DOCK_LINERIGHT
;
911 else if ( eAlign
== WindowAlign::Top
)
913 if ( rPos
.Y() > mnDY
-DOCK_LINEOFFSET
)
914 return DOCK_LINEVSIZE
| DOCK_LINEBOTTOM
;
916 else if ( eAlign
== WindowAlign::Right
)
918 if ( rPos
.X() < DOCK_LINEOFFSET
)
919 return DOCK_LINEHSIZE
| DOCK_LINELEFT
;
921 else if ( eAlign
== WindowAlign::Bottom
)
923 if ( rPos
.Y() < DOCK_LINEOFFSET
)
924 return DOCK_LINEVSIZE
| DOCK_LINETOP
;
931 void ToolBox::ImplLineSizing( const Point
& rPos
, tools::Rectangle
& rRect
, sal_uInt16 nLineMode
)
940 if ( nLineMode
& DOCK_LINERIGHT
)
942 nCurSize
= rPos
.X() - rRect
.Left();
945 else if ( nLineMode
& DOCK_LINEBOTTOM
)
947 nCurSize
= rPos
.Y() - rRect
.Top();
950 else if ( nLineMode
& DOCK_LINELEFT
)
952 nCurSize
= rRect
.Right() - rPos
.X();
955 else if ( nLineMode
& DOCK_LINETOP
)
957 nCurSize
= rRect
.Bottom() - rPos
.Y();
961 OSL_FAIL( "ImplLineSizing: Trailing else" );
966 Size aWinSize
= GetSizePixel();
967 ImplToolItems::size_type nMaxLines
= std::max(mnLines
, mnCurLines
);
968 if ( nMaxLines
> TB_MAXLINES
)
969 nMaxLines
= TB_MAXLINES
;
972 nOneLineSize
= ImplCalcSize( 1 ).Height();
974 if ( nMaxSize
< aWinSize
.Height() )
975 nMaxSize
= aWinSize
.Height();
979 nOneLineSize
= ImplCalcSize( 1 ).Width();
981 if ( nMaxSize
< aWinSize
.Width() )
982 nMaxSize
= aWinSize
.Width();
985 ImplToolItems::size_type i
= 1;
986 if ( nCurSize
<= nOneLineSize
)
987 nSize
= nOneLineSize
;
991 while ( (nSize
< nCurSize
) && (i
< nMaxLines
) )
994 aSize
= ImplCalcSize( i
);
996 nSize
= aSize
.Height();
998 nSize
= aSize
.Width();
999 if ( nSize
> nMaxSize
)
1002 aSize
= ImplCalcSize( i
);
1004 nSize
= aSize
.Height();
1006 nSize
= aSize
.Width();
1012 if ( nLineMode
& DOCK_LINERIGHT
)
1013 rRect
.SetRight( rRect
.Left()+nSize
-1 );
1014 else if ( nLineMode
& DOCK_LINEBOTTOM
)
1015 rRect
.SetBottom( rRect
.Top()+nSize
-1 );
1016 else if ( nLineMode
& DOCK_LINELEFT
)
1017 rRect
.SetLeft( rRect
.Right()-nSize
);
1019 rRect
.SetTop( rRect
.Bottom()-nSize
);
1024 ImplTBDragMgr::ImplTBDragMgr()
1025 : mpDragBox(nullptr)
1029 maAccel
.InsertItem( KEY_RETURN
, vcl::KeyCode( KEY_RETURN
) );
1030 maAccel
.InsertItem( KEY_ESCAPE
, vcl::KeyCode( KEY_ESCAPE
) );
1031 maAccel
.SetSelectHdl( LINK( this, ImplTBDragMgr
, SelectHdl
) );
1034 void ImplTBDragMgr::StartDragging( ToolBox
* pToolBox
,
1035 const Point
& rPos
, const tools::Rectangle
& rRect
,
1036 sal_uInt16 nDragLineMode
)
1038 mpDragBox
= pToolBox
;
1039 pToolBox
->CaptureMouse();
1040 pToolBox
->mbDragging
= true;
1041 Application::InsertAccel( &maAccel
);
1043 mnLineMode
= nDragLineMode
;
1044 mnStartLines
= pToolBox
->mnDockLines
;
1046 // calculate MouseOffset
1047 maMouseOff
.setX( rRect
.Left() - rPos
.X() );
1048 maMouseOff
.setY( rRect
.Top() - rPos
.Y() );
1050 maStartRect
= rRect
;
1051 pToolBox
->ShowTracking( maRect
);
1054 void ImplTBDragMgr::Dragging( const Point
& rPos
)
1056 mpDragBox
->ImplLineSizing( rPos
, maRect
, mnLineMode
);
1057 Point aOff
= mpDragBox
->OutputToScreenPixel( Point() );
1058 maRect
.Move( aOff
.X(), aOff
.Y() );
1059 mpDragBox
->Docking( rPos
, maRect
);
1060 maRect
.Move( -aOff
.X(), -aOff
.Y() );
1061 mpDragBox
->ShowTracking( maRect
);
1064 void ImplTBDragMgr::EndDragging( bool bOK
)
1066 mpDragBox
->HideTracking();
1067 if (mpDragBox
->IsMouseCaptured())
1068 mpDragBox
->ReleaseMouse();
1069 mpDragBox
->mbDragging
= false;
1070 Application::RemoveAccel( &maAccel
);
1074 mpDragBox
->mnDockLines
= mnStartLines
;
1075 mpDragBox
->EndDocking( maStartRect
, false );
1078 mpDragBox
->EndDocking( maRect
, false );
1081 mpDragBox
= nullptr;
1084 IMPL_LINK( ImplTBDragMgr
, SelectHdl
, Accelerator
&, rAccel
, void )
1086 if ( rAccel
.GetCurItemId() == KEY_ESCAPE
)
1087 EndDragging( false );
1092 void ToolBox::ImplInitToolBoxData()
1094 // initialize variables
1095 ImplGetWindowImpl()->mbToolBox
= true;
1096 mpData
.reset(new ImplToolBoxPrivateData
);
1098 mpFloatWin
= nullptr;
1102 mnMaxItemHeight
= 0;
1109 mnOutStyle
= TOOLBOX_STYLE_FLAT
; // force flat buttons since NWF
1113 mnCurPos
= ITEM_NOTFOUND
;
1120 mnMouseModifier
= 0;
1122 mbSelection
= false;
1128 mbFullPaint
= false;
1131 mbLastFloatMode
= false;
1132 mbCustomize
= false;
1134 mbIsKeyEvent
= false;
1135 mbChangingHighlight
= false;
1136 mbImagesMirrored
= false;
1137 mbLineSpacing
= false;
1138 mbIsArranged
= false;
1139 meButtonType
= ButtonType::SYMBOLONLY
;
1140 meAlign
= WindowAlign::Top
;
1141 meDockAlign
= WindowAlign::Top
;
1142 meLastStyle
= PointerStyle::Arrow
;
1144 meLayoutMode
= ToolBoxLayoutMode::Normal
;
1145 meTextPosition
= ToolBoxTextPosition::Right
;
1146 mnLastFocusItemId
= 0;
1147 mnActivateCount
= 0;
1148 mnImagesRotationAngle
= 0;
1150 mpStatusListener
= new VclStatusListener
<ToolBox
>(this, ".uno:ImageOrientation");
1151 mpStatusListener
->startListening();
1153 mpIdle
.reset(new Idle("vcl::ToolBox maIdle update"));
1154 mpIdle
->SetPriority( TaskPriority::RESIZE
);
1155 mpIdle
->SetInvokeHandler( LINK( this, ToolBox
, ImplUpdateHdl
) );
1157 // set timeout and handler for dropdown items
1158 mpData
->maDropdownTimer
.SetTimeout( 250 );
1159 mpData
->maDropdownTimer
.SetInvokeHandler( LINK( this, ToolBox
, ImplDropdownLongClickHdl
) );
1160 mpData
->maDropdownTimer
.SetDebugName( "vcl::ToolBox mpData->maDropdownTimer" );
1163 void ToolBox::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
1165 // initialize variables
1166 mbScroll
= (nStyle
& WB_SCROLL
) != 0;
1167 mnWinStyle
= nStyle
;
1169 DockingWindow::ImplInit( pParent
, nStyle
& ~WB_BORDER
);
1171 // dockingwindow's ImplInit removes some bits, so restore them here to allow keyboard handling for toolbars
1172 ImplGetWindowImpl()->mnStyle
|= WB_TABSTOP
|WB_NODIALOGCONTROL
; // always set WB_TABSTOP for ToolBars
1173 ImplGetWindowImpl()->mnStyle
&= ~WB_DIALOGCONTROL
;
1175 ImplInitSettings(true, true, true);
1178 void ToolBox::ApplyForegroundSettings(vcl::RenderContext
& rRenderContext
, const StyleSettings
& rStyleSettings
)
1181 if (IsControlForeground())
1182 aColor
= GetControlForeground();
1183 else if (Window::GetStyle() & WB_3DLOOK
)
1184 aColor
= rStyleSettings
.GetButtonTextColor();
1186 aColor
= rStyleSettings
.GetWindowTextColor();
1187 rRenderContext
.SetTextColor(aColor
);
1188 rRenderContext
.SetTextFillColor();
1191 void ToolBox::ApplyBackgroundSettings(vcl::RenderContext
& rRenderContext
, const StyleSettings
& rStyleSettings
)
1193 if (IsControlBackground())
1195 rRenderContext
.SetBackground(GetControlBackground());
1196 SetPaintTransparent(false);
1197 SetParentClipMode();
1201 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ControlPart::Entire
)
1202 || (GetAlign() == WindowAlign::Top
&& !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty())
1203 || (GetAlign() == WindowAlign::Bottom
&& !Application::GetSettings().GetStyleSettings().GetPersonaFooter().IsEmpty()))
1205 rRenderContext
.SetBackground();
1206 rRenderContext
.SetTextColor(rStyleSettings
.GetToolTextColor());
1207 SetPaintTransparent(true);
1208 SetParentClipMode(ParentClipMode::NoClip
);
1209 mpData
->maDisplayBackground
= Wallpaper(rStyleSettings
.GetFaceColor());
1214 if (Window::GetStyle() & WB_3DLOOK
)
1215 aColor
= rStyleSettings
.GetFaceColor();
1217 aColor
= rStyleSettings
.GetWindowColor();
1218 rRenderContext
.SetBackground(aColor
);
1219 SetPaintTransparent(false);
1220 SetParentClipMode();
1225 void ToolBox::ApplySettings(vcl::RenderContext
& rRenderContext
)
1227 mpData
->mbNativeButtons
= rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ControlPart::Button
);
1229 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
1231 ApplyControlFont(rRenderContext
, rStyleSettings
.GetToolFont());
1232 ApplyForegroundSettings(rRenderContext
, rStyleSettings
);
1233 ApplyBackgroundSettings(rRenderContext
, rStyleSettings
);
1236 void ToolBox::ImplInitSettings(bool bFont
, bool bForeground
, bool bBackground
)
1238 mpData
->mbNativeButtons
= IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
);
1240 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
1243 ApplyControlFont(*this, rStyleSettings
.GetToolFont());
1244 if (bForeground
|| bFont
)
1245 ApplyForegroundSettings(*this, rStyleSettings
);
1248 ApplyBackgroundSettings(*this, rStyleSettings
);
1249 EnableChildTransparentMode(IsPaintTransparent());
1253 void ToolBox::doDeferredInit(WinBits nBits
)
1255 VclPtr
<vcl::Window
> pParent
= mpDialogParent
;
1256 mpDialogParent
= nullptr;
1257 ImplInit(pParent
, nBits
);
1258 mbIsDeferredInit
= false;
1261 void ToolBox::queue_resize(StateChangedType eReason
)
1263 Window::queue_resize(eReason
);
1266 ToolBox::ToolBox( vcl::Window
* pParent
, WinBits nStyle
) :
1267 DockingWindow( WindowType::TOOLBOX
)
1269 ImplInitToolBoxData();
1270 ImplInit( pParent
, nStyle
);
1273 ToolBox::ToolBox(vcl::Window
* pParent
, const OString
& rID
,
1274 const OUString
& rUIXMLDescription
, const css::uno::Reference
<css::frame::XFrame
> &rFrame
)
1275 : DockingWindow(WindowType::TOOLBOX
)
1277 ImplInitToolBoxData();
1279 loadUI(pParent
, rID
, rUIXMLDescription
, rFrame
);
1281 // calculate size of floating windows and switch if the
1282 // toolbox is initially in floating mode
1283 if ( ImplIsFloatingMode() )
1288 if (!(GetStyle() & WB_HIDE
))
1297 void ToolBox::dispose()
1299 // #103005# make sure our activate/deactivate balance is right
1300 while( mnActivateCount
> 0 )
1303 // terminate popupmode if the floating window is
1306 mpFloatWin
->EndPopupMode( FloatWinPopupEndFlags::Cancel
);
1307 mpFloatWin
= nullptr;
1309 // delete private data
1312 ImplSVData
* pSVData
= ImplGetSVData();
1313 delete pSVData
->maCtrlData
.mpTBDragMgr
;
1314 pSVData
->maCtrlData
.mpTBDragMgr
= nullptr;
1316 if (mpStatusListener
.is())
1317 mpStatusListener
->dispose();
1323 DockingWindow::dispose();
1326 ImplToolItem
* ToolBox::ImplGetItem( sal_uInt16 nItemId
) const
1331 for (auto & item
: mpData
->m_aItems
)
1333 if ( item
.mnId
== nItemId
)
1340 static void ImplAddButtonBorder( long &rWidth
, long& rHeight
, bool bNativeButtons
)
1342 rWidth
+= SMALLBUTTON_HSIZE
;
1343 rHeight
+= SMALLBUTTON_VSIZE
;
1345 if( bNativeButtons
)
1347 // give more border space for rounded buttons
1353 bool ToolBox::ImplCalcItem()
1356 // recalc required ?
1360 ImplDisableFlatButtons();
1365 long nMaxHeight
= 0;
1367 long nMinHeight
= 6;
1368 long nDropDownArrowWidth
= TB_DROPDOWNARROWWIDTH
;
1370 nDropDownArrowWidth
*= 3;
1373 // set defaults if image or text is needed but empty
1374 nDefWidth
= GetDefaultImageSize().Width();
1375 nDefHeight
= GetDefaultImageSize().Height();
1378 // determine minimum size necessary in NWF
1380 tools::Rectangle
aRect( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1381 tools::Rectangle
aReg( aRect
);
1382 ImplControlValue aVal
;
1383 tools::Rectangle aNativeBounds
, aNativeContent
;
1384 if( IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
) )
1386 if( GetNativeControlRegion( ControlType::Toolbar
, ControlPart::Button
,
1388 ControlState::ENABLED
| ControlState::ROLLOVER
,
1390 aNativeBounds
, aNativeContent
) )
1392 aRect
= aNativeBounds
;
1393 if( aRect
.GetWidth() > nMinWidth
)
1394 nMinWidth
= aRect
.GetWidth();
1395 if( aRect
.GetHeight() > nMinHeight
)
1396 nMinHeight
= aRect
.GetHeight();
1397 if( nDropDownArrowWidth
< nMinWidth
)
1398 nDropDownArrowWidth
= nMinWidth
;
1399 if( nMinWidth
> mpData
->mnMenuButtonWidth
)
1400 mpData
->mnMenuButtonWidth
= nMinWidth
;
1401 else if( nMinWidth
< TB_MENUBUTTON_SIZE
)
1402 mpData
->mnMenuButtonWidth
= TB_MENUBUTTON_SIZE
;
1406 // also calculate the area for comboboxes, drop down list boxes and spinfields
1407 // as these are often inserted into toolboxes; set mnWinHeight to the
1408 // greater of those values to prevent toolbar flickering (#i103385#)
1409 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1411 if( GetNativeControlRegion( ControlType::Combobox
, ControlPart::Entire
,
1413 ControlState::ENABLED
| ControlState::ROLLOVER
,
1415 aNativeBounds
, aNativeContent
) )
1417 aRect
= aNativeBounds
;
1418 if( aRect
.GetHeight() > mnWinHeight
)
1419 mnWinHeight
= aRect
.GetHeight();
1421 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1423 if( GetNativeControlRegion( ControlType::Listbox
, ControlPart::Entire
,
1425 ControlState::ENABLED
| ControlState::ROLLOVER
,
1427 aNativeBounds
, aNativeContent
) )
1429 aRect
= aNativeBounds
;
1430 if( aRect
.GetHeight() > mnWinHeight
)
1431 mnWinHeight
= aRect
.GetHeight();
1433 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1435 if( GetNativeControlRegion( ControlType::Spinbox
, ControlPart::Entire
,
1437 ControlState::ENABLED
| ControlState::ROLLOVER
,
1439 aNativeBounds
, aNativeContent
) )
1441 aRect
= aNativeBounds
;
1442 if( aRect
.GetHeight() > mnWinHeight
)
1443 mnWinHeight
= aRect
.GetHeight();
1447 if ( ! mpData
->m_aItems
.empty() )
1449 for (auto & item
: mpData
->m_aItems
)
1451 item
.mbVisibleText
= false; // indicates if text will definitely be drawn, influences dropdown pos
1453 if ( item
.meType
== ToolBoxItemType::BUTTON
)
1458 // check if image and/or text exists
1459 bImage
= !!item
.maImage
;
1460 bText
= !item
.maText
.isEmpty();
1461 ButtonType tmpButtonType
= determineButtonType( &item
, meButtonType
); // default to toolbox setting
1462 if ( bImage
|| bText
)
1465 item
.mbEmptyBtn
= false;
1467 if ( tmpButtonType
== ButtonType::SYMBOLONLY
)
1469 // we're drawing images only
1470 if ( bImage
|| !bText
)
1472 item
.maItemSize
= item
.maImage
.GetSizePixel();
1476 item
.maItemSize
= Size( GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
,
1478 item
.mbVisibleText
= true;
1481 else if ( tmpButtonType
== ButtonType::TEXT
)
1483 // we're drawing text only
1484 if ( bText
|| !bImage
)
1486 item
.maItemSize
= Size( GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
,
1488 item
.mbVisibleText
= true;
1492 item
.maItemSize
= item
.maImage
.GetSizePixel();
1497 // we're drawing images and text
1498 item
.maItemSize
.setWidth( bText
? GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
: 0 );
1499 item
.maItemSize
.setHeight( bText
? GetTextHeight() : 0 );
1501 if ( meTextPosition
== ToolBoxTextPosition::Right
)
1503 // leave space between image and text
1505 item
.maItemSize
.AdjustWidth(TB_IMAGETEXTOFFSET
);
1507 // image and text side by side
1508 item
.maItemSize
.AdjustWidth(item
.maImage
.GetSizePixel().Width() );
1509 if ( item
.maImage
.GetSizePixel().Height() > item
.maItemSize
.Height() )
1510 item
.maItemSize
.setHeight( item
.maImage
.GetSizePixel().Height() );
1514 // leave space between image and text
1516 item
.maItemSize
.AdjustHeight(TB_IMAGETEXTOFFSET
);
1519 item
.maItemSize
.AdjustHeight(item
.maImage
.GetSizePixel().Height() );
1520 if ( item
.maImage
.GetSizePixel().Width() > item
.maItemSize
.Width() )
1521 item
.maItemSize
.setWidth( item
.maImage
.GetSizePixel().Width() );
1524 item
.mbVisibleText
= bText
;
1528 { // no image and no text
1529 item
.maItemSize
= Size( nDefWidth
, nDefHeight
);
1530 item
.mbEmptyBtn
= true;
1533 // save the content size
1534 item
.maContentSize
= item
.maItemSize
;
1536 // if required, take window height into consideration
1537 if ( item
.mpWindow
)
1539 long nHeight
= item
.mpWindow
->GetSizePixel().Height();
1540 if ( nHeight
> mnWinHeight
)
1541 mnWinHeight
= nHeight
;
1544 // add in drop down arrow
1545 if( item
.mnBits
& ToolBoxItemBits::DROPDOWN
)
1547 item
.maItemSize
.AdjustWidth(nDropDownArrowWidth
);
1548 item
.mnDropDownArrowWidth
= nDropDownArrowWidth
;
1551 // text items will be rotated in vertical mode
1552 // -> swap width and height
1553 if( item
.mbVisibleText
&& !mbHorz
)
1555 long tmp
= item
.maItemSize
.Width();
1556 item
.maItemSize
.setWidth( item
.maItemSize
.Height() );
1557 item
.maItemSize
.setHeight( tmp
);
1559 tmp
= item
.maContentSize
.Width();
1560 item
.maContentSize
.setWidth( item
.maContentSize
.Height() );
1561 item
.maContentSize
.setHeight( tmp
);
1564 else if ( item
.meType
== ToolBoxItemType::SPACE
)
1566 item
.maItemSize
= Size( nDefWidth
, nDefHeight
);
1567 item
.maContentSize
= item
.maItemSize
;
1570 if ( item
.meType
== ToolBoxItemType::BUTTON
|| item
.meType
== ToolBoxItemType::SPACE
)
1573 long w
= item
.maItemSize
.Width();
1574 long h
= item
.maItemSize
.Height();
1575 ImplAddButtonBorder( w
, h
, mpData
->mbNativeButtons
);
1576 item
.maItemSize
.setWidth(w
);
1577 item
.maItemSize
.setHeight(h
);
1579 if( item
.meType
== ToolBoxItemType::BUTTON
)
1581 long nMinW
= std::max(nMinWidth
, item
.maMinimalItemSize
.Width());
1582 long nMinH
= std::max(nMinHeight
, item
.maMinimalItemSize
.Height());
1584 long nGrowContentWidth
= 0;
1585 long nGrowContentHeight
= 0;
1587 if( item
.maItemSize
.Width() < nMinW
)
1589 nGrowContentWidth
= nMinW
- item
.maItemSize
.Width();
1590 item
.maItemSize
.setWidth( nMinW
);
1592 if( item
.maItemSize
.Height() < nMinH
)
1594 nGrowContentHeight
= nMinH
- item
.maItemSize
.Height();
1595 item
.maItemSize
.setHeight( nMinH
);
1598 // grow the content size by the additional available space
1599 item
.maContentSize
.AdjustWidth(nGrowContentWidth
);
1600 item
.maContentSize
.AdjustHeight(nGrowContentHeight
);
1603 // keep track of max item size
1604 if ( item
.maItemSize
.Width() > nMaxWidth
)
1605 nMaxWidth
= item
.maItemSize
.Width();
1606 if ( item
.maItemSize
.Height() > nMaxHeight
)
1607 nMaxHeight
= item
.maItemSize
.Height();
1613 nMaxWidth
= nDefWidth
;
1614 nMaxHeight
= nDefHeight
;
1616 ImplAddButtonBorder( nMaxWidth
, nMaxHeight
, mpData
->mbNativeButtons
);
1619 if( !ImplIsFloatingMode() && GetToolboxButtonSize() != ToolBoxButtonSize::DontCare
1620 && ( meTextPosition
== ToolBoxTextPosition::Right
) )
1622 // make sure all vertical toolbars have the same width and horizontal have the same height
1623 // this depends on the used button sizes
1624 // as this is used for alignment of multiple toolbars
1625 // it is only required for docked toolbars
1627 long nFixedWidth
= nDefWidth
+nDropDownArrowWidth
;
1628 long nFixedHeight
= nDefHeight
;
1629 ImplAddButtonBorder( nFixedWidth
, nFixedHeight
, mpData
->mbNativeButtons
);
1632 nMaxHeight
= nFixedHeight
;
1634 nMaxWidth
= nFixedWidth
;
1640 // do we have to recalc the sizes ?
1641 if ( (nMaxWidth
!= mnMaxItemWidth
) || (nMaxHeight
!= mnMaxItemHeight
) )
1643 mnMaxItemWidth
= nMaxWidth
;
1644 mnMaxItemHeight
= nMaxHeight
;
1652 ToolBox::ImplToolItems::size_type
ToolBox::ImplCalcBreaks( long nWidth
, long* pMaxLineWidth
, bool bCalcHorz
) const
1654 sal_uLong nLineStart
= 0;
1655 sal_uLong nGroupStart
= 0;
1656 long nLineWidth
= 0;
1658 long nLastGroupLineWidth
= 0;
1659 long nMaxLineWidth
= 0;
1660 ImplToolItems::size_type nLines
= 1;
1662 bool bBreak
= false;
1663 long nWidthTotal
= nWidth
;
1664 long nMenuWidth
= 0;
1666 // when docked the menubutton will be in the first line
1667 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1668 nMenuWidth
= mpData
->maMenubuttonItem
.maItemSize
.Width();
1670 // we need to know which item is the last visible one to be able to add
1671 // the menu width in case we are unable to show all the items
1672 ImplToolItems::iterator it
, lastVisible
;
1673 for ( it
= mpData
->m_aItems
.begin(); it
!= mpData
->m_aItems
.end(); ++it
)
1675 if ( it
->mbVisible
)
1679 it
= mpData
->m_aItems
.begin();
1680 while ( it
!= mpData
->m_aItems
.end() )
1682 it
->mbBreak
= bBreak
;
1685 if ( it
->mbVisible
)
1691 if ( it
->meType
== ToolBoxItemType::BUTTON
|| it
->meType
== ToolBoxItemType::SPACE
)
1694 nCurWidth
= it
->maItemSize
.Width();
1696 nCurWidth
= it
->maItemSize
.Height();
1698 if ( it
->mpWindow
&& bCalcHorz
)
1700 long nWinItemWidth
= it
->mpWindow
->GetSizePixel().Width();
1701 if ( !mbScroll
|| (nWinItemWidth
<= nWidthTotal
) )
1703 nCurWidth
= nWinItemWidth
;
1708 if ( it
->mbEmptyBtn
)
1715 // in case we are able to show all the items, we do not want
1716 // to show the toolbar's menu; otherwise yes
1717 if ( ( ( it
== lastVisible
) && (nLineWidth
+nCurWidth
> nWidthTotal
) && mbScroll
) ||
1718 ( ( it
!= lastVisible
) && (nLineWidth
+nCurWidth
+nMenuWidth
> nWidthTotal
) && mbScroll
) )
1721 else if ( it
->meType
== ToolBoxItemType::SEPARATOR
)
1723 nCurWidth
= it
->mnSepSize
;
1724 if ( !ImplIsFloatingMode() && ( it
!= lastVisible
) && (nLineWidth
+nCurWidth
+nMenuWidth
> nWidthTotal
) )
1727 // treat breaks as separators, except when using old style toolbars (ie. no menu button)
1728 else if ( (it
->meType
== ToolBoxItemType::BREAK
) && !IsMenuEnabled() )
1735 // Add break before the entire group or take group apart?
1736 if ( (it
->meType
== ToolBoxItemType::BREAK
) ||
1737 (nLineStart
== nGroupStart
) )
1739 if ( nLineWidth
> nMaxLineWidth
)
1740 nMaxLineWidth
= nLineWidth
;
1743 nLineStart
= it
- mpData
->m_aItems
.begin();
1744 nGroupStart
= nLineStart
;
1750 if ( nLastGroupLineWidth
> nMaxLineWidth
)
1751 nMaxLineWidth
= nLastGroupLineWidth
;
1753 // if the break is added before the group, set it to
1754 // beginning of line and re-calculate
1756 nLineStart
= nGroupStart
;
1757 it
= mpData
->m_aItems
.begin() + nGroupStart
;
1763 if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
1765 if ( (it
->meType
!= ToolBoxItemType::BUTTON
) || bWindow
)
1767 // found separator or break
1768 nLastGroupLineWidth
= nLineWidth
;
1769 nGroupStart
= it
- mpData
->m_aItems
.begin();
1776 nLineWidth
+= nCurWidth
;
1782 if ( pMaxLineWidth
)
1784 if ( nLineWidth
> nMaxLineWidth
)
1785 nMaxLineWidth
= nLineWidth
;
1787 if( ImplIsFloatingMode() && !ImplIsInPopupMode() )
1789 // leave enough space to display buttons in the decoration
1790 long aMinWidth
= 2 * GetSettings().GetStyleSettings().GetFloatTitleHeight();
1791 if( nMaxLineWidth
< aMinWidth
)
1792 nMaxLineWidth
= aMinWidth
;
1794 *pMaxLineWidth
= nMaxLineWidth
;
1800 Size
ToolBox::ImplGetOptimalFloatingSize()
1802 if( !ImplIsFloatingMode() )
1805 Size
aCurrentSize( mnDX
, mnDY
);
1806 Size
aSize1( aCurrentSize
);
1807 Size
aSize2( aCurrentSize
);
1809 // try to preserve current height
1811 // calc number of floating lines for current window height
1812 ImplToolItems::size_type nFloatLinesHeight
= ImplCalcLines( mnDY
);
1813 // calc window size according to this number
1814 aSize1
= ImplCalcFloatSize( nFloatLinesHeight
);
1816 if( aCurrentSize
== aSize1
)
1819 // try to preserve current width
1821 long nLineHeight
= std::max( mnWinHeight
, mnMaxItemHeight
);
1822 int nBorderX
= 2*TB_BORDER_OFFSET1
+ mnLeftBorder
+ mnRightBorder
;
1823 int nBorderY
= 2*TB_BORDER_OFFSET2
+ mnTopBorder
+ mnBottomBorder
;
1824 Size
aSz( aCurrentSize
);
1826 ImplToolItems::size_type nLines
= ImplCalcBreaks( aSz
.Width()-nBorderX
, &maxX
, mbHorz
);
1828 ImplToolItems::size_type manyLines
= 1000;
1829 Size aMinimalFloatSize
= ImplCalcFloatSize( manyLines
);
1831 aSz
.setHeight( nBorderY
+ nLineHeight
* nLines
);
1832 // line space when more than one line
1833 if ( mbLineSpacing
)
1834 aSz
.AdjustHeight((nLines
-1)*TB_LINESPACING
);
1836 aSz
.setWidth( nBorderX
+ maxX
);
1838 // avoid clipping of any items
1839 if( aSz
.Width() < aMinimalFloatSize
.Width() )
1840 aSize2
= ImplCalcFloatSize( nLines
);
1844 if( aCurrentSize
== aSize2
)
1847 // set the size with the smallest delta as the current size
1848 long dx1
= std::abs( mnDX
- aSize1
.Width() );
1849 long dy1
= std::abs( mnDY
- aSize1
.Height() );
1851 long dx2
= std::abs( mnDX
- aSize2
.Width() );
1852 long dy2
= std::abs( mnDY
- aSize2
.Height() );
1854 if( dx1
*dy1
< dx2
*dy2
)
1855 aCurrentSize
= aSize1
;
1857 aCurrentSize
= aSize2
;
1859 return aCurrentSize
;
1864 void lcl_hideDoubleSeparators( ToolBox::ImplToolItems
& rItems
)
1866 bool bLastSep( true );
1867 ToolBox::ImplToolItems::iterator it
;
1868 for ( it
= rItems
.begin(); it
!= rItems
.end(); ++it
)
1870 if ( it
->meType
== ToolBoxItemType::SEPARATOR
)
1872 it
->mbVisible
= false;
1875 // check if any visible items have to appear behind it
1876 if (std::any_of(it
+ 1, rItems
.end(), [](const ImplToolItem
& rItem
) {
1877 return (rItem
.meType
== ToolBoxItemType::BUTTON
) && rItem
.mbVisible
; }))
1878 it
->mbVisible
= true;
1882 else if ( it
->mbVisible
)
1888 void ToolBox::ImplFormat( bool bResize
)
1890 // Has to re-formatted
1894 mpData
->ImplClearLayoutData();
1896 // recalculate positions and sizes
1897 tools::Rectangle aEmptyRect
;
1901 long nMax
; // width of layoutarea in pixels
1902 ImplToolItems::size_type nFormatLine
;
1903 bool bMustFullPaint
;
1905 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
1906 bool bIsInPopupMode
= ImplIsInPopupMode();
1908 maFloatSizes
.clear();
1910 // compute border sizes
1911 ImplCalcBorder( meAlign
, mnLeftBorder
, mnTopBorder
, mnRightBorder
, mnBottomBorder
);
1913 // update drag area (where the 'grip' will be placed)
1914 tools::Rectangle aOldDragRect
;
1916 aOldDragRect
= pWrapper
->GetDragArea();
1917 ImplUpdateDragArea();
1919 bMustFullPaint
= ImplCalcItem();
1921 // calculate new size during interactive resize or
1922 // set computed size when formatting only
1923 if ( ImplIsFloatingMode() )
1926 mnFloatLines
= ImplCalcLines( mnDY
);
1928 SetOutputSizePixel( ImplGetOptimalFloatingSize() );
1935 // nLineSize: height of a single line, will fit highest item
1936 nLineSize
= mnMaxItemHeight
;
1938 if ( mnWinHeight
> mnMaxItemHeight
)
1939 nLineSize
= mnWinHeight
;
1944 mnVisLines
= ImplCalcLines( mnDY
);
1948 // layout over all lines
1949 mnVisLines
= mnLines
;
1950 nMax
= TB_MAXNOSCROLL
;
1953 // add in all border offsets
1954 if ( mnWinStyle
& WB_BORDER
)
1956 nLeft
= TB_BORDER_OFFSET1
+ mnLeftBorder
;
1957 nTop
= TB_BORDER_OFFSET2
+ mnTopBorder
;
1958 nBottom
= TB_BORDER_OFFSET1
+ mnBottomBorder
;
1959 nMax
-= nLeft
+ TB_BORDER_OFFSET1
+ mnRightBorder
;
1968 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
1969 // we have to center all items in the window height
1970 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1972 long nWinHeight
= mnDY
- nTop
- nBottom
;
1973 if( nWinHeight
> nLineSize
)
1974 nLineSize
= nWinHeight
;
1980 nLineSize
= mnMaxItemWidth
;
1984 mnVisLines
= ImplCalcLines( mnDX
);
1989 mnVisLines
= mnLines
;
1990 nMax
= TB_MAXNOSCROLL
;
1993 if ( mnWinStyle
& WB_BORDER
)
1995 nTop
= TB_BORDER_OFFSET1
+ mnTopBorder
;
1996 nLeft
= TB_BORDER_OFFSET2
+ mnLeftBorder
;
1997 nRight
= TB_BORDER_OFFSET2
+ mnRightBorder
;
1998 nMax
-= nTop
+ TB_BORDER_OFFSET1
+ mnBottomBorder
;
2007 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
2008 // we have to center all items in the window height
2009 if( !ImplIsFloatingMode() && IsMenuEnabled() )
2011 long nWinWidth
= mnDX
- nLeft
- nRight
;
2012 if( nWinWidth
> nLineSize
)
2013 nLineSize
= nWinWidth
;
2017 // no calculation if the window has no size (nMax=0)
2018 // non scrolling toolboxes must be computed though
2019 if ( (nMax
<= 0) && mbScroll
)
2025 for (auto & item
: mpData
->m_aItems
)
2027 item
.maRect
= aEmptyRect
;
2030 maLowerRect
= aEmptyRect
;
2031 maUpperRect
= aEmptyRect
;
2035 // init start values
2036 long nX
= nLeft
; // top-left offset
2040 // save old scroll rectangles and reset them
2041 tools::Rectangle aOldLowerRect
= maLowerRect
;
2042 tools::Rectangle aOldUpperRect
= maUpperRect
;
2043 tools::Rectangle aOldMenubuttonRect
= mpData
->maMenubuttonItem
.maRect
;
2044 maUpperRect
= aEmptyRect
;
2045 maLowerRect
= aEmptyRect
;
2046 mpData
->maMenubuttonItem
.maRect
= aEmptyRect
;
2048 // do we have any toolbox items at all ?
2049 if ( !mpData
->m_aItems
.empty() || IsMenuEnabled() )
2051 lcl_hideDoubleSeparators( mpData
->m_aItems
);
2053 // compute line breaks and visible lines give the current window width (nMax)
2054 // the break indicators will be stored within each item (it->mbBreak)
2055 mnCurLines
= ImplCalcBreaks( nMax
, nullptr, mbHorz
);
2057 // check for scrollbar buttons or dropdown menu
2058 // (if a menu is enabled, this will be used to store clipped
2059 // items and no scroll buttons will appear)
2060 if ( (!ImplIsFloatingMode() && (mnCurLines
> mnVisLines
) && mbScroll
) ||
2063 // compute linebreaks again, incorporating scrollbar buttons
2064 if( !IsMenuEnabled() )
2066 nMax
-= TB_SPIN_SIZE
+TB_SPIN_OFFSET
;
2067 mnCurLines
= ImplCalcBreaks( nMax
, nullptr, mbHorz
);
2070 // compute scroll rectangles or menu button
2073 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2075 if( !ImplIsFloatingMode() )
2077 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
- 2 );
2078 mpData
->maMenubuttonItem
.maRect
.SetTop( nTop
);
2079 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2083 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
- mnRightBorder
-TB_BORDER_OFFSET1
-1 );
2084 mpData
->maMenubuttonItem
.maRect
.SetTop( nTop
);
2085 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2087 mpData
->maMenubuttonItem
.maRect
.SetLeft( mpData
->maMenubuttonItem
.maRect
.Right() - mpData
->mnMenuButtonWidth
);
2091 maUpperRect
.SetLeft( nLeft
+nMax
+TB_SPIN_OFFSET
);
2092 maUpperRect
.SetRight( maUpperRect
.Left()+TB_SPIN_SIZE
-1 );
2093 maUpperRect
.SetTop( nTop
);
2094 maLowerRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2095 maLowerRect
.SetLeft( maUpperRect
.Left() );
2096 maLowerRect
.SetRight( maUpperRect
.Right() );
2097 maUpperRect
.SetBottom( maUpperRect
.Top() +
2098 (maLowerRect
.Bottom()-maUpperRect
.Top())/2 );
2099 maLowerRect
.SetTop( maUpperRect
.Bottom() );
2104 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2106 if( !ImplIsFloatingMode() )
2108 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
- 2 );
2109 mpData
->maMenubuttonItem
.maRect
.SetLeft( nLeft
);
2110 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2114 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
- mnBottomBorder
-TB_BORDER_OFFSET1
-1 );
2115 mpData
->maMenubuttonItem
.maRect
.SetLeft( nLeft
);
2116 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2118 mpData
->maMenubuttonItem
.maRect
.SetTop( mpData
->maMenubuttonItem
.maRect
.Bottom() - mpData
->mnMenuButtonWidth
);
2122 maUpperRect
.SetTop( nTop
+nMax
+TB_SPIN_OFFSET
);
2123 maUpperRect
.SetBottom( maUpperRect
.Top()+TB_SPIN_SIZE
-1 );
2124 maUpperRect
.SetLeft( nLeft
);
2125 maLowerRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2126 maLowerRect
.SetTop( maUpperRect
.Top() );
2127 maLowerRect
.SetBottom( maUpperRect
.Bottom() );
2128 maUpperRect
.SetRight( maUpperRect
.Left() +
2129 (maLowerRect
.Right()-maUpperRect
.Left())/2 );
2130 maLowerRect
.SetLeft( maUpperRect
.Right() );
2135 // no scrolling when there is a "more"-menu
2136 // anything will "fit" in a single line then
2137 if( IsMenuEnabled() )
2140 // determine the currently visible line
2141 if ( mnVisLines
>= mnCurLines
)
2143 else if ( mnCurLine
+mnVisLines
-1 > mnCurLines
)
2144 mnCurLine
= mnCurLines
- (mnVisLines
-1);
2146 long firstItemCenter
= 0;
2147 for (auto & item
: mpData
->m_aItems
)
2149 item
.mbShowWindow
= false;
2151 // check for line break and advance nX/nY accordingly
2156 // increment starting with the second line
2157 if ( nFormatLine
> mnCurLine
)
2162 if ( mbLineSpacing
)
2163 nY
+= nLineSize
+TB_LINESPACING
;
2170 if ( mbLineSpacing
)
2171 nX
+= nLineSize
+TB_LINESPACING
;
2178 if ( !item
.mbVisible
|| (nFormatLine
< mnCurLine
) ||
2179 (nFormatLine
> mnCurLine
+mnVisLines
-1) )
2180 // item is not visible
2181 item
.maCalcRect
= aEmptyRect
;
2184 // 1. determine current item width/height
2185 // take window size and orientation into account, because this affects the size of item windows
2187 Size
aCurrentItemSize( item
.GetSize( mbHorz
, mbScroll
, nMax
, Size(mnMaxItemWidth
, mnMaxItemHeight
) ) );
2189 // 2. position item rect and use size from step 1
2190 // items will be centered horizontally (if mbHorz) or vertically
2191 // advance nX and nY accordingly
2195 // In special mode Locked horizontal positions of all items remain unchanged.
2197 if ( mbIsArranged
&& meLayoutMode
== ToolBoxLayoutMode::Locked
&& mnLines
== 1 && item
.maRect
.Left() > 0 )
2198 nX
= item
.maRect
.Left();
2199 item
.maCalcRect
.SetLeft( nX
);
2201 // In special mode Locked first item's vertical position remains unchanged. Consecutive items vertical
2202 // positions are centered around first item's vertical position. If an item's height exceeds available
2203 // space, item's vertical position remains unchanged too.
2205 if ( mbIsArranged
&& meLayoutMode
== ToolBoxLayoutMode::Locked
&& mnLines
== 1 )
2206 if ( firstItemCenter
> 0 )
2207 if ( firstItemCenter
-aCurrentItemSize
.Height()/2 > nY
)
2208 item
.maCalcRect
.SetTop( firstItemCenter
-aCurrentItemSize
.Height()/2 );
2210 item
.maCalcRect
.SetTop( item
.maRect
.Top() );
2213 item
.maCalcRect
.SetTop( item
.maRect
.Top() );
2214 firstItemCenter
= item
.maRect
.Top()+aCurrentItemSize
.Height()/2;
2217 item
.maCalcRect
.SetTop( nY
+(nLineSize
-aCurrentItemSize
.Height())/2 );
2218 item
.maCalcRect
.SetRight( nX
+aCurrentItemSize
.Width()-1 );
2219 item
.maCalcRect
.SetBottom( item
.maCalcRect
.Top()+aCurrentItemSize
.Height()-1 );
2220 nX
+= aCurrentItemSize
.Width();
2224 item
.maCalcRect
.SetLeft( nX
+(nLineSize
-aCurrentItemSize
.Width())/2 );
2225 item
.maCalcRect
.SetTop( nY
);
2226 item
.maCalcRect
.SetRight( item
.maCalcRect
.Left()+aCurrentItemSize
.Width()-1 );
2227 item
.maCalcRect
.SetBottom( nY
+aCurrentItemSize
.Height()-1 );
2228 nY
+= aCurrentItemSize
.Height();
2232 // position window items into calculated item rect
2233 if ( item
.mpWindow
)
2235 if ( item
.mbShowWindow
)
2237 Point
aPos( item
.maCalcRect
.Left(), item
.maCalcRect
.Top() );
2239 assert( item
.maCalcRect
.Top() >= 0 );
2241 item
.mpWindow
->SetPosPixel( aPos
);
2242 item
.mpWindow
->Show();
2245 item
.mpWindow
->Hide();
2247 } // end of loop over all items
2248 mbIsArranged
= true;
2251 // we have no toolbox items
2254 if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2256 // custom menu will be the last button in floating mode
2257 ImplToolItem
&rIt
= mpData
->maMenubuttonItem
;
2261 rIt
.maRect
.SetLeft( nX
+TB_MENUBUTTON_OFFSET
);
2262 rIt
.maRect
.SetTop( nY
);
2263 rIt
.maRect
.SetRight( rIt
.maRect
.Left() + mpData
->mnMenuButtonWidth
);
2264 rIt
.maRect
.SetBottom( nY
+nLineSize
-1 );
2265 nX
+= rIt
.maItemSize
.Width();
2269 rIt
.maRect
.SetLeft( nX
);
2270 rIt
.maRect
.SetTop( nY
+TB_MENUBUTTON_OFFSET
);
2271 rIt
.maRect
.SetRight( nX
+nLineSize
-1 );
2272 rIt
.maRect
.SetBottom( rIt
.maRect
.Top() + mpData
->mnMenuButtonWidth
);
2273 nY
+= rIt
.maItemSize
.Height();
2277 // if toolbox visible trigger paint for changed regions
2278 if ( IsVisible() && !mbFullPaint
)
2280 if ( bMustFullPaint
)
2282 maPaintRect
= tools::Rectangle( mnLeftBorder
, mnTopBorder
,
2283 mnDX
-mnRightBorder
, mnDY
-mnBottomBorder
);
2287 if ( aOldLowerRect
!= maLowerRect
)
2289 maPaintRect
.Union( maLowerRect
);
2290 maPaintRect
.Union( aOldLowerRect
);
2292 if ( aOldUpperRect
!= maUpperRect
)
2294 maPaintRect
.Union( maUpperRect
);
2295 maPaintRect
.Union( aOldUpperRect
);
2297 if ( aOldMenubuttonRect
!= mpData
->maMenubuttonItem
.maRect
)
2299 maPaintRect
.Union( mpData
->maMenubuttonItem
.maRect
);
2300 maPaintRect
.Union( aOldMenubuttonRect
);
2302 if ( pWrapper
&& aOldDragRect
!= pWrapper
->GetDragArea() )
2304 maPaintRect
.Union( pWrapper
->GetDragArea() );
2305 maPaintRect
.Union( aOldDragRect
);
2308 for (auto const& item
: mpData
->m_aItems
)
2310 if ( item
.maRect
!= item
.maCalcRect
)
2312 maPaintRect
.Union( item
.maRect
);
2313 maPaintRect
.Union( item
.maCalcRect
);
2318 Invalidate( maPaintRect
);
2321 // store the new calculated item rects
2322 maPaintRect
= aEmptyRect
;
2323 for (auto & item
: mpData
->m_aItems
)
2324 item
.maRect
= item
.maCalcRect
;
2327 // indicate formatting is done
2331 IMPL_LINK_NOARG(ToolBox
, ImplDropdownLongClickHdl
, Timer
*, void)
2333 if (mnCurPos
!= ITEM_NOTFOUND
&&
2334 (mpData
->m_aItems
[ mnCurPos
].mnBits
& ToolBoxItemBits::DROPDOWN
))
2336 mpData
->mbDropDownByKeyboard
= false;
2337 mpData
->maDropdownClickHdl
.Call( this );
2339 // do not reset data if the dropdown handler opened a floating window
2340 // see ImplFloatControl()
2343 // no floater was opened
2345 InvalidateItem(mnCurPos
);
2347 mnCurPos
= ITEM_NOTFOUND
;
2350 mnMouseModifier
= 0;
2356 IMPL_LINK_NOARG(ToolBox
, ImplUpdateHdl
, Timer
*, void)
2359 if( mbFormat
&& mpData
)
2363 static void ImplDrawMoreIndicator(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
2365 const Image
pImage(StockImage::Yes
, CHEVRON
);
2366 Size aImageSize
= pImage
.GetSizePixel();
2367 long x
= rRect
.Left() + (rRect
.getWidth() - aImageSize
.Width())/2;
2368 long y
= rRect
.Top() + (rRect
.getHeight() - aImageSize
.Height())/2;
2369 DrawImageFlags nImageStyle
= DrawImageFlags::NONE
;
2371 rRenderContext
.DrawImage(Point(x
,y
), pImage
, nImageStyle
);
2374 static void ImplDrawDropdownArrow(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rDropDownRect
, bool bSetColor
, bool bRotate
)
2376 bool bLineColor
= rRenderContext
.IsLineColor();
2377 bool bFillColor
= rRenderContext
.IsFillColor();
2378 Color aOldFillColor
= rRenderContext
.GetFillColor();
2379 Color aOldLineColor
= rRenderContext
.GetLineColor();
2380 rRenderContext
.SetLineColor();
2384 if (rRenderContext
.GetSettings().GetStyleSettings().GetFaceColor().IsDark())
2385 rRenderContext
.SetFillColor(COL_WHITE
);
2387 rRenderContext
.SetFillColor(COL_BLACK
);
2390 float fScaleFactor
= rRenderContext
.GetDPIScaleFactor();
2392 tools::Polygon
aPoly(4);
2394 long width
= round(rDropDownRect
.getHeight()/5.5) * fScaleFactor
; // scale triangle depending on theme/toolbar height with 7 for gtk, 5 for gen
2395 long height
= round(rDropDownRect
.getHeight()/9.5) * fScaleFactor
; // 4 for gtk, 3 for gen
2396 if (width
< 4) width
= 4;
2397 if (height
< 3) height
= 3;
2399 long x
= rDropDownRect
.Left() + (rDropDownRect
.getWidth() - width
)/2;
2400 long y
= rDropDownRect
.Top() + (rDropDownRect
.getHeight() - height
)/2;
2402 long halfwidth
= (width
+1)>>1;
2403 aPoly
.SetPoint(Point(x
, y
), 0);
2404 aPoly
.SetPoint(Point(x
+ halfwidth
, y
+ height
), 1);
2405 aPoly
.SetPoint(Point(x
+ halfwidth
*2, y
), 2);
2406 aPoly
.SetPoint(Point(x
, y
), 3);
2408 if (bRotate
) // TESTME: harder ...
2409 aPoly
.Rotate(Point(x
,y
+height
/2),2700);
2411 auto aaflags
= rRenderContext
.GetAntialiasing();
2412 rRenderContext
.SetAntialiasing(AntialiasingFlags::EnableB2dDraw
);
2413 rRenderContext
.DrawPolygon( aPoly
);
2414 rRenderContext
.SetAntialiasing(aaflags
);
2417 rRenderContext
.SetFillColor(aOldFillColor
);
2419 rRenderContext
.SetFillColor();
2421 rRenderContext
.SetLineColor(aOldLineColor
);
2423 rRenderContext
.SetLineColor();
2426 void ToolBox::ImplDrawMenuButton(vcl::RenderContext
& rRenderContext
, bool bHighlight
)
2428 if (!mpData
->maMenubuttonItem
.maRect
.IsEmpty())
2430 // #i53937# paint menu button only if necessary
2431 if (!ImplHasClippedItems())
2434 // execute pending paint requests
2437 rRenderContext
.Push(PushFlags::FILLCOLOR
| PushFlags::LINECOLOR
);
2439 // draw the 'more' indicator / button (>>)
2440 ImplErase(rRenderContext
, mpData
->maMenubuttonItem
.maRect
, bHighlight
);
2443 ImplDrawButton(rRenderContext
, mpData
->maMenubuttonItem
.maRect
, 2, false, true, false );
2445 if (ImplHasClippedItems())
2446 ImplDrawMoreIndicator(rRenderContext
, mpData
->maMenubuttonItem
.maRect
);
2448 // store highlight state
2449 mpData
->mbMenubuttonSelected
= bHighlight
;
2452 rRenderContext
.Pop();
2456 void ToolBox::ImplDrawSpin(vcl::RenderContext
& rRenderContext
)
2461 if ( maUpperRect
.IsEmpty() || maLowerRect
.IsEmpty() )
2464 bTmpUpper
= mnCurLine
> 1;
2466 bTmpLower
= mnCurLine
+mnVisLines
-1 < mnCurLines
;
2474 ImplDrawUpDownButtons(rRenderContext
, maUpperRect
, maLowerRect
,
2475 false/*bUpperIn*/, false/*bLowerIn*/, bTmpUpper
, bTmpLower
, !mbHorz
);
2478 void ToolBox::ImplDrawSeparator(vcl::RenderContext
& rRenderContext
, ImplToolItems::size_type nPos
, const tools::Rectangle
& rRect
)
2480 if ( nPos
>= mpData
->m_aItems
.size() - 1 )
2481 // no separator if it's the last item
2484 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPos
];
2485 ImplToolItem
* pPreviousItem
= &mpData
->m_aItems
[nPos
-1];
2486 ImplToolItem
* pNextItem
= &mpData
->m_aItems
[nPos
+1];
2488 if ( ( pPreviousItem
->mbShowWindow
&& pNextItem
->mbShowWindow
) || pNextItem
->mbBreak
)
2489 // no separator between two windows or before a break
2492 bool bNativeOk
= false;
2493 ControlPart nPart
= IsHorizontal() ? ControlPart::SeparatorVert
: ControlPart::SeparatorHorz
;
2494 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, nPart
))
2496 ImplControlValue aControlValue
;
2497 bNativeOk
= rRenderContext
.DrawNativeControl(ControlType::Toolbar
, nPart
, rRect
, ControlState::NONE
, aControlValue
, OUString());
2500 /* Draw the widget only if it can't be drawn natively. */
2503 long nCenterPos
, nSlim
;
2504 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
2505 rRenderContext
.SetLineColor(rStyleSettings
.GetSeparatorColor());
2508 nSlim
= (pItem
->maRect
.Bottom() - pItem
->maRect
.Top ()) / 4;
2509 nCenterPos
= pItem
->maRect
.Center().X();
2510 rRenderContext
.DrawLine(Point(nCenterPos
, pItem
->maRect
.Top() + nSlim
),
2511 Point(nCenterPos
, pItem
->maRect
.Bottom() - nSlim
));
2515 nSlim
= (pItem
->maRect
.Right() - pItem
->maRect
.Left ()) / 4;
2516 nCenterPos
= pItem
->maRect
.Center().Y();
2517 rRenderContext
.DrawLine(Point(pItem
->maRect
.Left() + nSlim
, nCenterPos
),
2518 Point(pItem
->maRect
.Right() - nSlim
, nCenterPos
));
2523 void ToolBox::ImplDrawButton(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&rRect
, sal_uInt16 highlight
,
2524 bool bChecked
, bool bEnabled
, bool bIsWindow
)
2526 // draws toolbar button background either native or using a coloured selection
2527 // if bIsWindow is true, the corresponding item is a control and only a selection border will be drawn
2529 bool bNativeOk
= false;
2530 if( !bIsWindow
&& rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
) )
2532 ImplControlValue aControlValue
;
2533 ControlState nState
= ControlState::NONE
;
2535 if ( highlight
== 1 ) nState
|= ControlState::PRESSED
;
2536 if ( highlight
== 2 ) nState
|= ControlState::ROLLOVER
;
2537 if ( bEnabled
) nState
|= ControlState::ENABLED
;
2539 aControlValue
.setTristateVal( bChecked
? ButtonValue::On
: ButtonValue::Off
);
2541 bNativeOk
= rRenderContext
.DrawNativeControl( ControlType::Toolbar
, ControlPart::Button
,
2542 rRect
, nState
, aControlValue
, OUString() );
2546 vcl::RenderTools::DrawSelectionBackground(rRenderContext
, *this, rRect
, bIsWindow
? 3 : highlight
,
2547 bChecked
, true, bIsWindow
, nullptr, 2);
2550 void ToolBox::ImplDrawItem(vcl::RenderContext
& rRenderContext
, ImplToolItems::size_type nPos
, sal_uInt16 nHighlight
)
2552 if (nPos
>= mpData
->m_aItems
.size())
2555 // execute pending paint requests
2558 ImplDisableFlatButtons();
2560 rRenderContext
.SetFillColor();
2562 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPos
];
2564 if (!pItem
->mbEnabled
)
2567 // if the rectangle is outside visible area
2568 if (pItem
->maRect
.IsEmpty())
2571 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
2573 // no gradient background for items that have a popup open
2574 bool bHasOpenPopup
= mpFloatWin
&& (mnDownItemId
==pItem
->mnId
);
2576 bool bHighContrastWhite
= false;
2577 // check the face color as highcontrast indicator
2578 // because the toolbox itself might have a gradient
2579 if (rStyleSettings
.GetFaceColor() == COL_WHITE
)
2580 bHighContrastWhite
= true;
2582 // Compute buttons area.
2583 Size aBtnSize
= pItem
->maRect
.GetSize();
2585 /* Compute the button/separator rectangle here, we'll need it for
2586 * both the buttons and the separators. */
2587 tools::Rectangle
aButtonRect( pItem
->maRect
.TopLeft(), aBtnSize
);
2588 long nOffX
= SMALLBUTTON_OFF_NORMAL_X
;
2589 long nOffY
= SMALLBUTTON_OFF_NORMAL_Y
;
2590 long nImageOffX
= 0;
2591 long nImageOffY
= 0;
2592 DrawButtonFlags nStyle
= DrawButtonFlags::NONE
;
2594 // draw separators in flat style only
2595 if ( (mnOutStyle
& TOOLBOX_STYLE_FLAT
) &&
2596 (pItem
->meType
== ToolBoxItemType::SEPARATOR
) &&
2600 ImplDrawSeparator(rRenderContext
, nPos
, aButtonRect
);
2603 // do nothing if item is no button or will be displayed as window
2604 if ( (pItem
->meType
!= ToolBoxItemType::BUTTON
) || pItem
->mbShowWindow
)
2607 if ( pItem
->meState
== TRISTATE_TRUE
)
2609 nStyle
|= DrawButtonFlags::Checked
;
2611 else if ( pItem
->meState
== TRISTATE_INDET
)
2613 nStyle
|= DrawButtonFlags::DontKnow
;
2615 if ( nHighlight
== 1 )
2617 nStyle
|= DrawButtonFlags::Pressed
;
2620 if ( mnOutStyle
& TOOLBOX_STYLE_FLAT
)
2622 ImplErase(rRenderContext
, pItem
->maRect
, nHighlight
!= 0, bHasOpenPopup
);
2626 DecorationView
aDecoView(&rRenderContext
);
2627 aDecoView
.DrawButton(aButtonRect
, nStyle
);
2630 nOffX
+= pItem
->maRect
.Left();
2631 nOffY
+= pItem
->maRect
.Top();
2633 // determine what has to be drawn on the button: image, text or both
2636 ButtonType tmpButtonType
= determineButtonType( pItem
, meButtonType
); // default to toolbox setting
2637 pItem
->DetermineButtonDrawStyle( tmpButtonType
, bImage
, bText
);
2639 // compute output values
2640 long nBtnWidth
= aBtnSize
.Width()-SMALLBUTTON_HSIZE
;
2641 long nBtnHeight
= aBtnSize
.Height()-SMALLBUTTON_VSIZE
;
2647 aTxtSize
.setWidth( GetCtrlTextWidth( pItem
->maText
) );
2648 aTxtSize
.setHeight( GetTextHeight() );
2653 const Image
* pImage
= &(pItem
->maImage
);
2654 const Image
& rOverlayImage
= pItem
->maOverlayImage
;
2655 aImageSize
= pImage
->GetSizePixel();
2657 // determine drawing flags
2658 DrawImageFlags nImageStyle
= DrawImageFlags::NONE
;
2660 if ( !pItem
->mbEnabled
|| !IsEnabled() )
2661 nImageStyle
|= DrawImageFlags::Disable
;
2663 // #i35563# the dontknow state indicates different states at the same time
2664 // which should not be rendered disabled but normal
2669 if ( ( (pItem
->mnBits
& (ToolBoxItemBits::LEFT
|ToolBoxItemBits::DROPDOWN
)) || bText
)
2670 && ( meTextPosition
== ToolBoxTextPosition::Right
) )
2672 // left align also to leave space for drop down arrow
2673 // and when drawing text+image
2674 // just center in y, except for vertical (ie rotated text)
2675 if( mbHorz
|| !bText
)
2676 nImageOffY
+= (nBtnHeight
-aImageSize
.Height())/2;
2680 nImageOffX
+= (nBtnWidth
-aImageSize
.Width())/2;
2681 if ( meTextPosition
== ToolBoxTextPosition::Right
)
2682 nImageOffY
+= (nBtnHeight
-aImageSize
.Height())/2;
2684 if ( nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) )
2687 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2689 ImplDrawButton(rRenderContext
, aButtonRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2690 pItem
->mbEnabled
&& IsEnabled(), pItem
->mbShowWindow
);
2692 if( nHighlight
!= 0 )
2694 if( bHighContrastWhite
)
2695 nImageStyle
|= DrawImageFlags::ColorTransform
;
2698 rRenderContext
.DrawImage(Point( nImageOffX
, nImageOffY
), *pImage
, nImageStyle
);
2699 if (!!rOverlayImage
)
2700 rRenderContext
.DrawImage(Point( nImageOffX
, nImageOffY
), rOverlayImage
, nImageStyle
);
2704 bool bRotate
= false;
2707 long nTextOffX
= nOffX
;
2708 long nTextOffY
= nOffY
;
2710 // rotate text when vertically docked
2711 vcl::Font aOldFont
= rRenderContext
.GetFont();
2712 if( pItem
->mbVisibleText
&& !ImplIsFloatingMode() &&
2713 ((meAlign
== WindowAlign::Left
) || (meAlign
== WindowAlign::Right
)) )
2717 vcl::Font aRotateFont
= aOldFont
;
2718 aRotateFont
.SetOrientation( 2700 );
2720 // center horizontally
2721 nTextOffX
+= aTxtSize
.Height();
2722 nTextOffX
+= (nBtnWidth
-aTxtSize
.Height())/2;
2724 // add in image offset
2726 nTextOffY
= nImageOffY
+ aImageSize
.Height() + TB_IMAGETEXTOFFSET
;
2728 rRenderContext
.SetFont(aRotateFont
);
2732 if ( meTextPosition
== ToolBoxTextPosition::Right
)
2734 // center vertically
2735 nTextOffY
+= (nBtnHeight
-aTxtSize
.Height())/2;
2737 // add in image offset
2739 nTextOffX
= nImageOffX
+ aImageSize
.Width() + TB_IMAGETEXTOFFSET
;
2743 // center horizontally
2744 nTextOffX
+= (nBtnWidth
-aTxtSize
.Width() - TB_IMAGETEXTOFFSET
)/2;
2745 // set vertical position
2746 nTextOffY
+= nBtnHeight
- aTxtSize
.Height();
2750 // draw selection only if not already drawn during image output (see above)
2751 if ( !bImage
&& (nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) ) )
2754 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2756 ImplDrawButton(rRenderContext
, pItem
->maRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2757 pItem
->mbEnabled
&& IsEnabled(), pItem
->mbShowWindow
);
2760 DrawTextFlags nTextStyle
= DrawTextFlags::NONE
;
2761 if ( !pItem
->mbEnabled
)
2762 nTextStyle
|= DrawTextFlags::Disable
;
2763 rRenderContext
.DrawCtrlText( Point( nTextOffX
, nTextOffY
), pItem
->maText
,
2764 0, pItem
->maText
.getLength(), nTextStyle
);
2766 SetFont( aOldFont
);
2769 // paint optional drop down arrow
2770 if ( pItem
->mnBits
& ToolBoxItemBits::DROPDOWN
)
2772 tools::Rectangle
aDropDownRect( pItem
->GetDropDownRect( mbHorz
) );
2773 bool bSetColor
= true;
2774 if ( !pItem
->mbEnabled
|| !IsEnabled() )
2777 rRenderContext
.SetFillColor(rStyleSettings
.GetShadowColor());
2780 // dropdown only will be painted without inner border
2781 if( (pItem
->mnBits
& ToolBoxItemBits::DROPDOWNONLY
) != ToolBoxItemBits::DROPDOWNONLY
)
2783 ImplErase(rRenderContext
, aDropDownRect
, nHighlight
!= 0, bHasOpenPopup
);
2785 if( nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) )
2788 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2790 ImplDrawButton(rRenderContext
, aDropDownRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2791 pItem
->mbEnabled
&& IsEnabled(), false);
2794 ImplDrawDropdownArrow(rRenderContext
, aDropDownRect
, bSetColor
, bRotate
);
2798 void ToolBox::ImplDrawFloatwinBorder(vcl::RenderContext
& rRenderContext
, ImplToolItem
const * pItem
)
2800 if ( pItem
->maRect
.IsEmpty() )
2803 tools::Rectangle
aRect( mpFloatWin
->ImplGetItemEdgeClipRect() );
2804 aRect
.SetPos( AbsoluteScreenToOutputPixel( aRect
.TopLeft() ) );
2805 rRenderContext
.SetLineColor(rRenderContext
.GetSettings().GetStyleSettings().GetShadowColor());
2808 p1
= pItem
->maRect
.TopLeft();
2810 p2
= pItem
->maRect
.TopRight();
2812 rRenderContext
.DrawLine( p1
, p2
);
2813 p1
= pItem
->maRect
.BottomLeft();
2815 p2
= pItem
->maRect
.BottomRight();
2817 rRenderContext
.DrawLine( p1
, p2
);
2819 p1
= pItem
->maRect
.TopLeft();
2821 p2
= pItem
->maRect
.BottomLeft();
2823 rRenderContext
.DrawLine( p1
, p2
);
2824 p1
= pItem
->maRect
.TopRight();
2826 p2
= pItem
->maRect
.BottomRight();
2828 rRenderContext
.DrawLine( p1
, p2
);
2832 void ToolBox::ImplFloatControl( bool bStart
, FloatingWindow
* pFloatWindow
)
2837 mpFloatWin
= pFloatWindow
;
2839 // redraw item, to trigger drawing of a special border
2840 InvalidateItem(mnCurPos
);
2844 if (IsMouseCaptured())
2849 mpFloatWin
= nullptr;
2851 // if focus is still in this toolbox, then the floater was opened by keyboard
2852 // draw current item with highlight and keep old state
2853 bool bWasKeyboardActivate
= mpData
->mbDropDownByKeyboard
;
2855 if ( mnCurPos
!= ITEM_NOTFOUND
)
2856 InvalidateItem(mnCurPos
);
2859 if( !bWasKeyboardActivate
)
2861 mnCurPos
= ITEM_NOTFOUND
;
2870 void ToolBox::ShowLine( bool bNext
)
2882 bool ToolBox::ImplHandleMouseMove( const MouseEvent
& rMEvt
, bool bRepeat
)
2884 Point aMousePos
= rMEvt
.GetPosPixel();
2890 if ( mbDrag
&& mnCurPos
!= ITEM_NOTFOUND
)
2892 // is the cursor over the item?
2893 ImplToolItem
* pItem
= &mpData
->m_aItems
[mnCurPos
];
2894 if ( pItem
->maRect
.IsInside( aMousePos
) )
2898 InvalidateItem(mnCurPos
);
2899 mnCurItemId
= pItem
->mnId
;
2903 if ( (pItem
->mnBits
& ToolBoxItemBits::REPEAT
) && bRepeat
)
2910 InvalidateItem(mnCurPos
);
2912 InvalidateItem(mnCurPos
);
2922 bool bNewIn
= maUpperRect
.IsInside( aMousePos
);
2923 if ( bNewIn
!= mbIn
)
2926 InvalidateSpin(true, false);
2933 bool bNewIn
= maLowerRect
.IsInside( aMousePos
);
2934 if ( bNewIn
!= mbIn
)
2937 InvalidateSpin(false);
2945 bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent
& rMEvt
, bool bCancel
)
2947 ImplDisableFlatButtons();
2952 // stop eventual running dropdown timer
2953 if( mnCurPos
< mpData
->m_aItems
.size() &&
2954 (mpData
->m_aItems
[mnCurPos
].mnBits
& ToolBoxItemBits::DROPDOWN
) )
2956 mpData
->maDropdownTimer
.Stop();
2959 if ( mbDrag
|| mbSelection
)
2961 // set mouse data if in selection mode, as then
2962 // the MouseButtonDown handler cannot be called
2964 mnMouseModifier
= rMEvt
.GetModifier();
2972 mbSelection
= false;
2973 if ( mnCurPos
== ITEM_NOTFOUND
)
2977 // has mouse been released on top of item?
2978 if( mnCurPos
< mpData
->m_aItems
.size() )
2980 ImplToolItem
* pItem
= &mpData
->m_aItems
[mnCurPos
];
2981 if ( pItem
->maRect
.IsInside( rMEvt
.GetPosPixel() ) )
2983 mnCurItemId
= pItem
->mnId
;
2986 // execute AutoCheck if required
2987 if ( pItem
->mnBits
& ToolBoxItemBits::AUTOCHECK
)
2989 if ( pItem
->mnBits
& ToolBoxItemBits::RADIOCHECK
)
2991 if ( pItem
->meState
!= TRISTATE_TRUE
)
2992 SetItemState( pItem
->mnId
, TRISTATE_TRUE
);
2996 if ( pItem
->meState
!= TRISTATE_TRUE
)
2997 pItem
->meState
= TRISTATE_TRUE
;
2999 pItem
->meState
= TRISTATE_FALSE
;
3003 // do not call Select when Repeat is active, as in this
3004 // case that was triggered already in MouseButtonDown
3005 if ( !(pItem
->mnBits
& ToolBoxItemBits::REPEAT
) )
3007 // prevent from being destroyed in the select handler
3008 VclPtr
<vcl::Window
> xWindow
= this;
3010 if ( xWindow
->IsDisposed() )
3018 // Items not destroyed, in Select handler
3021 // Get current pos for the case that items are inserted/removed
3023 mnCurPos
= GetItemPos( mnCurItemId
);
3024 if ( mnCurPos
!= ITEM_NOTFOUND
)
3026 InvalidateItem(mnCurPos
);
3033 mnCurPos
= ITEM_NOTFOUND
;
3036 mnMouseModifier
= 0;
3039 else if ( mbUpper
|| mbLower
)
3042 ShowLine( !mbUpper
);
3053 void ToolBox::MouseMove( const MouseEvent
& rMEvt
)
3055 // pressing a modifier generates synthetic mouse moves
3056 // ignore it if keyboard selection is active
3057 if( HasFocus() && ( rMEvt
.GetMode() & MouseEventModifiers::MODIFIERCHANGED
) )
3060 if ( ImplHandleMouseMove( rMEvt
) )
3063 ImplDisableFlatButtons();
3065 Point aMousePos
= rMEvt
.GetPosPixel();
3067 // only highlight when the focus is not inside a child window of a toolbox
3068 // eg, in an edit control
3069 // and do not highlight when focus is in a different toolbox
3070 bool bDrawHotSpot
= true;
3071 vcl::Window
*pFocusWin
= Application::GetFocusWindow();
3073 bool bFocusWindowIsAToolBoxChild
= false;
3076 vcl::Window
*pWin
= pFocusWin
->GetParent();
3079 if(pWin
->ImplGetWindowImpl()->mbToolBox
)
3081 bFocusWindowIsAToolBoxChild
= true;
3084 pWin
= pWin
->GetParent();
3088 if( bFocusWindowIsAToolBoxChild
|| (pFocusWin
&& pFocusWin
->ImplGetWindowImpl()->mbToolBox
&& pFocusWin
!= this) )
3089 bDrawHotSpot
= false;
3091 if ( mbSelection
&& bDrawHotSpot
)
3093 ImplToolItems::size_type i
= 0;
3094 ImplToolItems::size_type nNewPos
= ITEM_NOTFOUND
;
3096 // search the item that has been clicked
3097 for (auto const& item
: mpData
->m_aItems
)
3099 // if the mouse position is in this item,
3100 // we can stop the search
3101 if ( item
.maRect
.IsInside( aMousePos
) )
3103 // select it if it is a button
3104 if ( item
.meType
== ToolBoxItemType::BUTTON
)
3106 // if button is disabled, do not
3108 if ( !item
.mbEnabled
|| item
.mbShowWindow
)
3118 // was a new entry selected?
3119 // don't change selection if keyboard selection is active and
3120 // mouse leaves the toolbox
3121 if ( nNewPos
!= mnCurPos
&& !( HasFocus() && nNewPos
== ITEM_NOTFOUND
) )
3123 if ( mnCurPos
!= ITEM_NOTFOUND
)
3125 InvalidateItem(mnCurPos
);
3126 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( mnCurPos
) );
3130 if ( mnCurPos
!= ITEM_NOTFOUND
)
3132 mnCurItemId
= mnHighItemId
= mpData
->m_aItems
[mnCurPos
].mnId
;
3133 InvalidateItem(mnCurPos
);
3136 mnCurItemId
= mnHighItemId
= 0;
3145 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3146 pMgr
->Dragging( aMousePos
);
3150 PointerStyle eStyle
= PointerStyle::Arrow
;
3152 // change mouse cursor over drag area
3153 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
3154 if( pWrapper
&& pWrapper
->GetDragArea().IsInside( rMEvt
.GetPosPixel() ) )
3155 eStyle
= PointerStyle::Move
;
3157 if ( (mnWinStyle
& TB_WBLINESIZING
) == TB_WBLINESIZING
)
3159 if ( rMEvt
.GetMode() & MouseEventModifiers::SIMPLEMOVE
)
3161 sal_uInt16 nLinePtr
= ImplTestLineSize( rMEvt
.GetPosPixel() );
3162 if ( nLinePtr
& DOCK_LINEHSIZE
)
3164 if ( meAlign
== WindowAlign::Left
)
3165 eStyle
= PointerStyle::WindowESize
;
3167 eStyle
= PointerStyle::WindowWSize
;
3169 else if ( nLinePtr
& DOCK_LINEVSIZE
)
3171 if ( meAlign
== WindowAlign::Top
)
3172 eStyle
= PointerStyle::WindowSSize
;
3174 eStyle
= PointerStyle::WindowNSize
;
3179 if ( bDrawHotSpot
&& ( (mnOutStyle
& TOOLBOX_STYLE_FLAT
) || !mnOutStyle
) )
3181 bool bClearHigh
= true;
3182 if ( !rMEvt
.IsLeaveWindow() && (mnCurPos
== ITEM_NOTFOUND
) )
3184 ImplToolItems::size_type nTempPos
= 0;
3185 for (auto const& item
: mpData
->m_aItems
)
3187 if ( item
.maRect
.IsInside( aMousePos
) )
3189 if ( (item
.meType
== ToolBoxItemType::BUTTON
) && item
.mbEnabled
)
3191 if ( !mnOutStyle
|| (mnOutStyle
& TOOLBOX_STYLE_FLAT
) )
3194 if ( mnHighItemId
!= item
.mnId
)
3199 ImplToolItems::size_type nPos
= GetItemPos( mnHighItemId
);
3200 InvalidateItem(nPos
);
3201 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nPos
) );
3203 if ( mpData
->mbMenubuttonSelected
)
3205 // remove highlight from menubutton
3206 InvalidateMenuButton();
3208 mnHighItemId
= item
.mnId
;
3209 InvalidateItem(nTempPos
);
3211 CallEventListeners( VclEventId::ToolboxHighlight
);
3221 // only clear highlight when focus is not in toolbar
3222 bool bMenuButtonHit
= mpData
->maMenubuttonItem
.maRect
.IsInside( aMousePos
) && ImplHasClippedItems();
3223 if ( !HasFocus() && (bClearHigh
|| bMenuButtonHit
) )
3225 if ( !bMenuButtonHit
&& mpData
->mbMenubuttonSelected
)
3227 // remove highlight from menubutton
3228 InvalidateMenuButton();
3233 ImplToolItems::size_type nClearPos
= GetItemPos( mnHighItemId
);
3234 if ( nClearPos
!= ITEM_NOTFOUND
)
3236 InvalidateItem(nClearPos
);
3237 if( nClearPos
!= mnCurPos
)
3238 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nClearPos
) );
3244 if( bMenuButtonHit
)
3246 InvalidateMenuButton();
3251 if ( meLastStyle
!= eStyle
)
3253 meLastStyle
= eStyle
;
3254 SetPointer( eStyle
);
3257 DockingWindow::MouseMove( rMEvt
);
3260 void ToolBox::MouseButtonDown( const MouseEvent
& rMEvt
)
3262 // only trigger toolbox for left mouse button and when
3263 // we're not in normal operation
3264 if ( rMEvt
.IsLeft() && !mbDrag
&& (mnCurPos
== ITEM_NOTFOUND
) )
3266 // call activate already here, as items could
3270 // update ToolBox here, such that user knows it
3277 Point aMousePos
= rMEvt
.GetPosPixel();
3278 ImplToolItems::size_type i
= 0;
3279 ImplToolItems::size_type nNewPos
= ITEM_NOTFOUND
;
3281 // search for item that was clicked
3282 for (auto const& item
: mpData
->m_aItems
)
3284 // is this the item?
3285 if ( item
.maRect
.IsInside( aMousePos
) )
3287 // do nothing if it is a separator or
3288 // if the item has been disabled
3289 if ( (item
.meType
== ToolBoxItemType::BUTTON
) &&
3290 !item
.mbShowWindow
)
3300 if ( nNewPos
!= ITEM_NOTFOUND
)
3302 if ( !mpData
->m_aItems
[nNewPos
].mbEnabled
)
3308 // update actual data
3309 StartTrackingFlags nTrackFlags
= StartTrackingFlags::NONE
;
3311 mnCurItemId
= mpData
->m_aItems
[nNewPos
].mnId
;
3312 mnDownItemId
= mnCurItemId
;
3313 mnMouseModifier
= rMEvt
.GetModifier();
3314 if ( mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::REPEAT
)
3315 nTrackFlags
|= StartTrackingFlags::ButtonRepeat
;
3319 InvalidateItem(mnCurPos
);
3324 // update bDrag here, as it is evaluated in the EndSelection
3327 // on double-click: only call the handler, but do so before the button
3328 // is hit, as in the handler dragging
3329 // can be terminated
3330 if ( rMEvt
.GetClicks() == 2 )
3335 InvalidateItem(mnCurPos
);
3339 // was dropdown arrow pressed
3340 if( mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::DROPDOWN
)
3342 if( ( (mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::DROPDOWNONLY
) == ToolBoxItemBits::DROPDOWNONLY
)
3343 || mpData
->m_aItems
[nNewPos
].GetDropDownRect( mbHorz
).IsInside( aMousePos
))
3345 // dropdownonly always triggers the dropdown handler, over the whole button area
3347 // the drop down arrow should not trigger the item action
3348 mpData
->mbDropDownByKeyboard
= false;
3349 mpData
->maDropdownClickHdl
.Call( this );
3351 // do not reset data if the dropdown handler opened a floating window
3352 // see ImplFloatControl()
3355 // no floater was opened
3357 InvalidateItem(mnCurPos
);
3359 mnCurPos
= ITEM_NOTFOUND
;
3362 mnMouseModifier
= 0;
3367 else // activate long click timer
3368 mpData
->maDropdownTimer
.Start();
3371 // call Click handler
3372 if ( rMEvt
.GetClicks() != 2 )
3375 // also call Select handler at repeat
3376 if ( nTrackFlags
& StartTrackingFlags::ButtonRepeat
)
3379 // if the actions was not aborted in Click handler
3381 StartTracking( nTrackFlags
);
3384 // if mouse was clicked over an item we
3391 // menu button hit ?
3392 if( mpData
->maMenubuttonItem
.maRect
.IsInside( aMousePos
) && ImplHasClippedItems() )
3394 if ( maMenuButtonHdl
.IsSet() )
3395 maMenuButtonHdl
.Call( this );
3397 ExecuteCustomMenu( mpData
->maMenubuttonItem
.maRect
);
3401 // check scroll- and next-buttons here
3402 if ( maUpperRect
.IsInside( aMousePos
) )
3404 if ( mnCurLine
> 1 )
3409 InvalidateSpin(true, false);
3413 if ( maLowerRect
.IsInside( aMousePos
) )
3415 if ( mnCurLine
+mnVisLines
-1 < mnCurLines
)
3420 InvalidateSpin(false);
3425 // Linesizing testen
3426 if ( (mnWinStyle
& TB_WBLINESIZING
) == TB_WBLINESIZING
)
3428 sal_uInt16 nLineMode
= ImplTestLineSize( aMousePos
);
3431 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3433 // call handler, such that we can set the
3437 Point aPos
= GetParent()->OutputToScreenPixel( GetPosPixel() );
3438 Size aSize
= GetSizePixel();
3439 aPos
= ScreenToOutputPixel( aPos
);
3442 pMgr
->StartDragging( this, aMousePos
, tools::Rectangle( aPos
, aSize
),
3448 // no item, then only click or double click
3449 if ( rMEvt
.GetClicks() == 2 )
3455 if ( !mbDrag
&& !mbSelection
&& (mnCurPos
== ITEM_NOTFOUND
) )
3456 DockingWindow::MouseButtonDown( rMEvt
);
3459 void ToolBox::MouseButtonUp( const MouseEvent
& rMEvt
)
3461 if ( ImplHandleMouseButtonUp( rMEvt
) )
3464 if ( mbDragging
&& rMEvt
.IsLeft() )
3466 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3467 pMgr
->EndDragging();
3471 DockingWindow::MouseButtonUp( rMEvt
);
3474 void ToolBox::Tracking( const TrackingEvent
& rTEvt
)
3476 VclPtr
<vcl::Window
> xWindow
= this;
3478 if ( rTEvt
.IsTrackingEnded() )
3479 ImplHandleMouseButtonUp( rTEvt
.GetMouseEvent(), rTEvt
.IsTrackingCanceled() );
3481 ImplHandleMouseMove( rTEvt
.GetMouseEvent(), rTEvt
.IsTrackingRepeat() );
3483 if ( xWindow
->IsDisposed() )
3484 // toolbox was deleted
3486 DockingWindow::Tracking( rTEvt
);
3489 void ToolBox::InvalidateItem(ImplToolItems::size_type nPosition
)
3491 if (mpData
&& nPosition
< mpData
->m_aItems
.size())
3493 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPosition
];
3494 Invalidate(pItem
->maRect
);
3498 void ToolBox::InvalidateMenuButton()
3500 if (!mpData
->maMenubuttonItem
.maRect
.IsEmpty())
3501 Invalidate(mpData
->maMenubuttonItem
.maRect
);
3504 void ToolBox::InvalidateSpin(bool bUpperIn
, bool bLowerIn
)
3506 if (bUpperIn
&& !maUpperRect
.IsEmpty())
3507 Invalidate(maUpperRect
);
3509 if (bLowerIn
&& !maLowerRect
.IsEmpty())
3510 Invalidate(maLowerRect
);
3513 void ToolBox::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rPaintRect
)
3515 if( mpData
->mbIsPaintLocked
)
3518 if (rPaintRect
== tools::Rectangle(0, 0, mnDX
-1, mnDY
-1))
3521 mbFullPaint
= false;
3523 ImplDrawBackground(rRenderContext
, rPaintRect
);
3525 if ( (mnWinStyle
& WB_BORDER
) && !ImplIsFloatingMode() )
3526 ImplDrawBorder(rRenderContext
);
3528 if( !ImplIsFloatingMode() )
3529 ImplDrawGrip(rRenderContext
);
3531 ImplDrawMenuButton(rRenderContext
, mpData
->mbMenubuttonSelected
);
3534 if (mnWinStyle
& WB_SCROLL
)
3536 if (mnCurLines
> mnLines
)
3537 ImplDrawSpin(rRenderContext
);
3541 ImplToolItems::size_type nHighPos
;
3543 nHighPos
= GetItemPos( mnHighItemId
);
3545 nHighPos
= ITEM_NOTFOUND
;
3547 ImplToolItems::size_type nCount
= mpData
->m_aItems
.size();
3548 for( ImplToolItems::size_type i
= 0; i
< nCount
; i
++ )
3550 ImplToolItem
* pItem
= &mpData
->m_aItems
[i
];
3552 // only draw when the rectangle is in the draw rectangle
3553 if ( !pItem
->maRect
.IsEmpty() && rPaintRect
.IsOver( pItem
->maRect
) )
3555 sal_uInt16 nHighlight
= 0;
3556 if ( i
== mnCurPos
)
3558 else if ( i
== nHighPos
)
3560 ImplDrawItem(rRenderContext
, i
, nHighlight
);
3566 void ToolBox::Resize()
3568 Size aSize
= GetOutputSizePixel();
3569 // #i31422# some WindowManagers send (0,0) sizes when
3570 // switching virtual desktops - ignore this and avoid reformatting
3571 if( !aSize
.Width() && !aSize
.Height() )
3576 mnDX
= aSize
.Width();
3577 mnDY
= aSize
.Height();
3581 // invalidate everything to have gradient backgrounds properly drawn
3584 // If we have any expandable entries, then force a reformat first using
3585 // their optimal sizes, then share out the excess space evenly across those
3586 // expandables and reformat again
3587 std::vector
<size_t> aExpandables
;
3588 for (size_t i
= 0; i
< mpData
->m_aItems
.size(); ++i
)
3590 if (mpData
->m_aItems
[i
].mbExpand
)
3592 vcl::Window
*pWindow
= mpData
->m_aItems
[i
].mpWindow
;
3593 SAL_INFO_IF(!pWindow
, "vcl.layout", "only tabitems with window supported at the moment");
3596 Size
aWinSize(pWindow
->GetSizePixel());
3597 Size
aPrefSize(pWindow
->get_preferred_size());
3598 aWinSize
.setWidth( aPrefSize
.Width() );
3599 pWindow
->SetSizePixel(aWinSize
);
3600 aExpandables
.push_back(i
);
3604 // re-format or re-draw
3605 if ( mbScroll
|| !aExpandables
.empty() )
3607 if ( !mbFormat
|| !aExpandables
.empty() )
3610 if( IsReallyVisible() || !aExpandables
.empty() )
3614 if (!aExpandables
.empty())
3616 //Get how big the optimal size is
3617 tools::Rectangle aBounds
;
3618 for (const ImplToolItem
& rItem
: mpData
->m_aItems
)
3620 aBounds
.Union( rItem
.maRect
);
3623 long nOptimalWidth
= aBounds
.GetWidth();
3624 long nDiff
= aSize
.Width() - nOptimalWidth
;
3625 nDiff
/= aExpandables
.size();
3627 //share out the diff from optimal to real across
3628 //expandable entries
3629 for (size_t nIndex
: aExpandables
)
3631 vcl::Window
*pWindow
= mpData
->m_aItems
[nIndex
].mpWindow
;
3632 Size
aWinSize(pWindow
->GetSizePixel());
3633 Size
aPrefSize(pWindow
->get_preferred_size());
3634 aWinSize
.setWidth( aPrefSize
.Width() + nDiff
);
3635 pWindow
->SetSizePixel(aWinSize
);
3638 //now reformat with final sizes
3647 if ( mnWinStyle
& WB_BORDER
)
3649 // as otherwise, when painting we might think we have to re-draw everything
3650 if ( mbFormat
&& IsReallyVisible() )
3654 if ( mnRightBorder
)
3656 if ( nOldDX
> mnDX
)
3657 Invalidate( tools::Rectangle( mnDX
-mnRightBorder
-1, 0, mnDX
, mnDY
) );
3659 Invalidate( tools::Rectangle( nOldDX
-mnRightBorder
-1, 0, nOldDX
, nOldDY
) );
3662 if ( mnBottomBorder
)
3664 if ( nOldDY
> mnDY
)
3665 Invalidate( tools::Rectangle( 0, mnDY
-mnBottomBorder
-1, mnDX
, mnDY
) );
3667 Invalidate( tools::Rectangle( 0, nOldDY
-mnBottomBorder
-1, nOldDX
, nOldDY
) );
3675 bool DispatchableCommand(const OUString
& rName
)
3677 return rName
.startsWith(".uno") ||
3678 rName
.startsWith("slot:") ||
3679 rName
.startsWith("macro:") ||
3680 rName
.startsWith("vnd.sun.star.script");
3684 const OUString
& ToolBox::ImplGetHelpText( sal_uInt16 nItemId
) const
3686 ImplToolItem
* pItem
= ImplGetItem( nItemId
);
3690 if ( pItem
->maHelpText
.isEmpty() && ( !pItem
->maHelpId
.isEmpty() || pItem
->maCommandStr
.getLength() ))
3692 Help
* pHelp
= Application::GetHelp();
3695 if (DispatchableCommand(pItem
->maCommandStr
))
3696 pItem
->maHelpText
= pHelp
->GetHelpText( pItem
->maCommandStr
, this );
3697 if ( pItem
->maHelpText
.isEmpty() && !pItem
->maHelpId
.isEmpty() )
3698 pItem
->maHelpText
= pHelp
->GetHelpText( OStringToOUString( pItem
->maHelpId
, RTL_TEXTENCODING_UTF8
), this );
3702 return pItem
->maHelpText
;
3705 void ToolBox::RequestHelp( const HelpEvent
& rHEvt
)
3710 if( !rHEvt
.KeyboardActivated() )
3712 nItemId
= GetItemId( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ) );
3713 aHelpPos
= rHEvt
.GetMousePosPixel();
3720 nItemId
= mnHighItemId
;
3721 tools::Rectangle
aRect( GetItemRect( nItemId
) );
3722 if( aRect
.IsEmpty() )
3725 aHelpPos
= OutputToScreenPixel( aRect
.Center() );
3730 if ( rHEvt
.GetMode() & (HelpEventMode::BALLOON
| HelpEventMode::QUICK
) )
3733 tools::Rectangle aTempRect
= GetItemRect( nItemId
);
3734 Point aPt
= OutputToScreenPixel( aTempRect
.TopLeft() );
3735 aTempRect
.SetLeft( aPt
.X() );
3736 aTempRect
.SetTop( aPt
.Y() );
3737 aPt
= OutputToScreenPixel( aTempRect
.BottomRight() );
3738 aTempRect
.SetRight( aPt
.X() );
3739 aTempRect
.SetBottom( aPt
.Y() );
3741 // get text and display it
3742 OUString aStr
= GetQuickHelpText( nItemId
);
3744 aStr
= MnemonicGenerator::EraseAllMnemonicChars( GetItemText( nItemId
) );
3745 if ( rHEvt
.GetMode() & HelpEventMode::BALLOON
)
3747 const OUString
& rHelpStr
= GetHelpText( nItemId
);
3748 if (!rHelpStr
.isEmpty())
3750 Help::ShowBalloon( this, aHelpPos
, aTempRect
, aStr
);
3753 Help::ShowQuickHelp( this, aTempRect
, aStr
, QuickHelpFlags::CtrlText
);
3758 DockingWindow::RequestHelp( rHEvt
);
3761 bool ToolBox::EventNotify( NotifyEvent
& rNEvt
)
3763 if ( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
3765 KeyEvent aKEvt
= *rNEvt
.GetKeyEvent();
3766 vcl::KeyCode aKeyCode
= aKEvt
.GetKeyCode();
3767 sal_uInt16 nKeyCode
= aKeyCode
.GetCode();
3772 // internal TAB cycling only if parent is not a dialog or if we are the only child
3773 // otherwise the dialog control will take over
3774 vcl::Window
*pParent
= ImplGetParent();
3775 bool bOldSchoolContainer
=
3776 ((pParent
->GetStyle() & (WB_DIALOGCONTROL
| WB_NODIALOGCONTROL
)) == WB_DIALOGCONTROL
&&
3777 pParent
->GetChildCount() != 1);
3778 bool bNoTabCycling
= bOldSchoolContainer
|| isContainerWindow(pParent
);
3781 return DockingWindow::EventNotify( rNEvt
);
3782 else if( ImplChangeHighlightUpDn( aKeyCode
.IsShift() , bNoTabCycling
) )
3785 return DockingWindow::EventNotify( rNEvt
);
3791 else if( rNEvt
.GetType() == MouseNotifyEvent::GETFOCUS
)
3793 if( rNEvt
.GetWindow() == this )
3795 // the toolbar itself got the focus
3796 if( mnLastFocusItemId
!= 0 || mpData
->mbMenubuttonWasLastSelected
)
3798 // restore last item
3799 if( mpData
->mbMenubuttonWasLastSelected
)
3801 ImplChangeHighlight( nullptr );
3802 mpData
->mbMenubuttonSelected
= true;
3803 InvalidateMenuButton();
3807 ImplChangeHighlight( ImplGetItem( mnLastFocusItemId
) );
3808 mnLastFocusItemId
= 0;
3811 else if( (GetGetFocusFlags() & (GetFocusFlags::Backward
|GetFocusFlags::Tab
) ) == (GetFocusFlags::Backward
|GetFocusFlags::Tab
))
3812 // Shift-TAB was pressed in the parent
3813 ImplChangeHighlightUpDn( false );
3815 ImplChangeHighlightUpDn( true );
3817 mnLastFocusItemId
= 0;
3823 // a child window got the focus so update current item to
3824 // allow for proper lose focus handling in keyboard navigation
3825 for (auto const& item
: mpData
->m_aItems
)
3827 if ( item
.mbVisible
)
3829 if ( item
.mpWindow
&& item
.mpWindow
->ImplIsWindowOrChild( rNEvt
.GetWindow() ) )
3831 mnHighItemId
= item
.mnId
;
3836 return DockingWindow::EventNotify( rNEvt
);
3839 else if( rNEvt
.GetType() == MouseNotifyEvent::LOSEFOCUS
)
3843 mpData
->mbMenubuttonWasLastSelected
= false;
3845 mnCurPos
= ITEM_NOTFOUND
;
3848 return DockingWindow::EventNotify( rNEvt
);
3851 void ToolBox::Command( const CommandEvent
& rCEvt
)
3853 if ( rCEvt
.GetCommand() == CommandEventId::Wheel
)
3855 if ( (mnCurLine
> 1) || (mnCurLine
+mnVisLines
-1 < mnCurLines
) )
3857 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
3858 if ( pData
->GetMode() == CommandWheelMode::SCROLL
)
3860 if ( (mnCurLine
> 1) && (pData
->GetDelta() > 0) )
3862 else if ( (mnCurLine
+mnVisLines
-1 < mnCurLines
) && (pData
->GetDelta() < 0) )
3869 else if ( rCEvt
.GetCommand() == CommandEventId::ContextMenu
)
3871 ExecuteCustomMenu( tools::Rectangle( rCEvt
.GetMousePosPixel(), rCEvt
.GetMousePosPixel() ) );
3875 DockingWindow::Command( rCEvt
);
3878 void ToolBox::StateChanged( StateChangedType nType
)
3880 DockingWindow::StateChanged( nType
);
3882 if ( nType
== StateChangedType::InitShow
)
3884 else if ( nType
== StateChangedType::Enable
)
3886 else if ( nType
== StateChangedType::UpdateMode
)
3888 if ( IsUpdateMode() )
3891 else if ( (nType
== StateChangedType::Zoom
) ||
3892 (nType
== StateChangedType::ControlFont
) )
3896 ImplInitSettings( true, false, false );
3899 else if ( nType
== StateChangedType::ControlForeground
)
3901 ImplInitSettings( false, true, false );
3904 else if ( nType
== StateChangedType::ControlBackground
)
3906 ImplInitSettings( false, false, true ); // font, foreground, background
3910 maStateChangedHandler
.Call( &nType
);
3913 void ToolBox::DataChanged( const DataChangedEvent
& rDCEvt
)
3915 DockingWindow::DataChanged( rDCEvt
);
3917 if ( (rDCEvt
.GetType() == DataChangedEventType::DISPLAY
) ||
3918 (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ||
3919 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
3920 ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
3921 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)) )
3925 ImplInitSettings( true, true, true );
3929 maDataChangedHandler
.Call( &rDCEvt
);
3932 void ToolBox::statusChanged( const css::frame::FeatureStateEvent
& Event
)
3934 // Update image mirroring/rotation
3935 if ( Event
.FeatureURL
.Complete
== ".uno:ImageOrientation" )
3937 SfxImageItem
aItem( 1 );
3938 aItem
.PutValue( Event
.State
, 0 );
3940 mbImagesMirrored
= aItem
.IsMirrored();
3941 mnImagesRotationAngle
= aItem
.GetRotation();
3943 // update image orientation
3944 OUString
aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(mpStatusListener
->getFrame()));
3945 for (auto const& item
: mpData
->m_aItems
)
3947 if (vcl::CommandInfoProvider::IsMirrored(item
.maCommandStr
, aModuleName
))
3948 SetItemImageMirrorMode(item
.mnId
, mbImagesMirrored
);
3949 if (vcl::CommandInfoProvider::IsRotated(item
.maCommandStr
, aModuleName
))
3950 SetItemImageAngle(item
.mnId
, mnImagesRotationAngle
);
3955 void ToolBox::SetStyle(WinBits nNewStyle
)
3957 mnWinStyle
= nNewStyle
;
3958 if (!ImplIsFloatingMode())
3960 bool bOldScroll
= mbScroll
;
3961 mbScroll
= (mnWinStyle
& WB_SCROLL
) != 0;
3962 if (mbScroll
!= bOldScroll
)
3970 void ToolBox::ToggleFloatingMode()
3972 DockingWindow::ToggleFloatingMode();
3977 bool bOldHorz
= mbHorz
;
3979 if ( ImplIsFloatingMode() )
3982 meAlign
= WindowAlign::Top
;
3985 if( bOldHorz
!= mbHorz
)
3986 mbCalc
= true; // orientation was changed !
3988 ImplSetMinMaxFloatSize();
3989 SetOutputSizePixel( ImplCalcFloatSize( mnFloatLines
) );
3993 mbScroll
= (mnWinStyle
& WB_SCROLL
) != 0;
3994 if ( (meAlign
== WindowAlign::Top
) || (meAlign
== WindowAlign::Bottom
) )
3999 // set focus back to document
4000 ImplGetFrameWindow()->GetWindow( GetWindowType::Client
)->GrabFocus();
4003 if( bOldHorz
!= mbHorz
)
4005 // if orientation changes, the toolbox has to be initialized again
4006 // to update the direction of the gradient
4008 ImplInitSettings( true, true, true );
4015 void ToolBox::StartDocking()
4017 meDockAlign
= meAlign
;
4018 mnDockLines
= mnLines
;
4019 mbLastFloatMode
= ImplIsFloatingMode();
4020 DockingWindow::StartDocking();
4023 bool ToolBox::Docking( const Point
& rPos
, tools::Rectangle
& rRect
)
4025 // do nothing during dragging, it was calculated before
4029 bool bFloatMode
= false;
4031 DockingWindow::Docking( rPos
, rRect
);
4033 // if the mouse is outside the area, it can only become a floating window
4034 tools::Rectangle
aDockingRect( rRect
);
4035 if ( !ImplIsFloatingMode() )
4037 // don't use tracking rectangle for alignment check, because it will be too large
4038 // to get a floating mode as result - switch to floating size
4039 // so the calculation only depends on the position of the rectangle, not the current
4040 // docking state of the window
4041 ImplToolItems::size_type nTemp
= 0;
4042 aDockingRect
.SetSize( ImplCalcFloatSize( nTemp
) );
4044 // in this mode docking is never done by keyboard, so it's OK to use the mouse position
4045 aDockingRect
.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
4050 meDockAlign
= meAlign
;
4051 if ( !mbLastFloatMode
)
4053 ImplToolItems::size_type nTemp
= 0;
4054 aDockingRect
.SetSize( ImplCalcFloatSize( nTemp
) );
4057 rRect
= aDockingRect
;
4058 mbLastFloatMode
= bFloatMode
;
4063 void ToolBox::EndDocking( const tools::Rectangle
& rRect
, bool bFloatMode
)
4065 if ( !IsDockingCanceled() )
4067 if ( mnLines
!= mnDockLines
)
4068 SetLineCount( mnDockLines
);
4069 if ( meAlign
!= meDockAlign
)
4070 SetAlign( meDockAlign
);
4072 if ( bFloatMode
|| (bFloatMode
!= ImplIsFloatingMode()) )
4073 DockingWindow::EndDocking( rRect
, bFloatMode
);
4076 void ToolBox::Resizing( Size
& rSize
)
4078 ImplToolItems::size_type nCalcLines
;
4079 ImplToolItems::size_type nTemp
;
4081 // calculate all floating sizes
4082 ImplCalcFloatSizes();
4084 if ( !mnLastResizeDY
)
4085 mnLastResizeDY
= mnDY
;
4087 // is vertical resizing needed
4088 if ( (mnLastResizeDY
!= rSize
.Height()) && (mnDY
!= rSize
.Height()) )
4090 nCalcLines
= ImplCalcLines( rSize
.Height() );
4091 if ( nCalcLines
< 1 )
4093 rSize
= ImplCalcFloatSize( nCalcLines
);
4099 Size aTempSize
= ImplCalcFloatSize( nTemp
);
4100 while ( (aTempSize
.Width() > rSize
.Width()) &&
4101 (nCalcLines
<= maFloatSizes
[0].mnLines
) )
4105 aTempSize
= ImplCalcFloatSize( nTemp
);
4110 mnLastResizeDY
= rSize
.Height();
4113 Size
ToolBox::GetOptimalSize() const
4115 // If we have any expandable entries, then force them to their
4116 // optimal sizes, then reset them afterwards
4117 std::map
<vcl::Window
*, Size
> aExpandables
;
4118 for (const ImplToolItem
& rItem
: mpData
->m_aItems
)
4122 vcl::Window
*pWindow
= rItem
.mpWindow
;
4123 SAL_INFO_IF(!pWindow
, "vcl.layout", "only tabitems with window supported at the moment");
4126 Size
aWinSize(pWindow
->GetSizePixel());
4127 aExpandables
[pWindow
] = aWinSize
;
4128 Size
aPrefSize(pWindow
->get_preferred_size());
4129 aWinSize
.setWidth( aPrefSize
.Width() );
4130 pWindow
->SetSizePixel(aWinSize
);
4134 Size
aSize(const_cast<ToolBox
*>(this)->ImplCalcSize( mnLines
));
4136 for (auto const& expandable
: aExpandables
)
4138 vcl::Window
*pWindow
= expandable
.first
;
4139 Size aWinSize
= expandable
.second
;
4140 pWindow
->SetSizePixel(aWinSize
);
4146 Size
ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines
)
4148 return ImplCalcSize( nCalcLines
);
4151 Size
ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines
, WindowAlign eAlign
)
4153 return ImplCalcSize( nCalcLines
,
4154 (eAlign
== WindowAlign::Top
|| eAlign
== WindowAlign::Bottom
) ? TB_CALCMODE_HORZ
: TB_CALCMODE_VERT
);
4157 ToolBox::ImplToolItems::size_type
ToolBox::ImplCountLineBreaks() const
4159 ImplToolItems::size_type nLines
= 0;
4161 for (auto const& item
: mpData
->m_aItems
)
4163 if( item
.meType
== ToolBoxItemType::BREAK
)
4169 Size
ToolBox::CalcPopupWindowSizePixel()
4171 // count number of breaks and calc corresponding floating window size
4172 ImplToolItems::size_type nLines
= ImplCountLineBreaks();
4175 ++nLines
; // add the first line
4178 // no breaks found: use quadratic layout
4179 nLines
= static_cast<ImplToolItems::size_type
>(ceil( sqrt( static_cast<double>(GetItemCount()) ) ));
4182 bool bPopup
= mpData
->mbAssumePopupMode
;
4183 mpData
->mbAssumePopupMode
= true;
4185 Size aSize
= CalcFloatingWindowSizePixel( nLines
);
4187 mpData
->mbAssumePopupMode
= bPopup
;
4191 Size
ToolBox::CalcFloatingWindowSizePixel()
4193 ImplToolItems::size_type nLines
= ImplCountLineBreaks();
4194 ++nLines
; // add the first line
4195 return CalcFloatingWindowSizePixel( nLines
);
4198 Size
ToolBox::CalcFloatingWindowSizePixel( ImplToolItems::size_type nCalcLines
)
4200 bool bFloat
= mpData
->mbAssumeFloating
;
4201 bool bDocking
= mpData
->mbAssumeDocked
;
4203 // simulate floating mode and force reformat before calculating
4204 mpData
->mbAssumeFloating
= true;
4205 mpData
->mbAssumeDocked
= false;
4207 Size aSize
= ImplCalcFloatSize( nCalcLines
);
4210 mpData
->mbAssumeFloating
= bFloat
;
4211 mpData
->mbAssumeDocked
= bDocking
;
4216 Size
ToolBox::CalcMinimumWindowSizePixel()
4218 if( ImplIsFloatingMode() )
4219 return ImplCalcSize( mnFloatLines
);
4222 // create dummy toolbox for measurements
4223 VclPtrInstance
< ToolBox
> pToolBox( GetParent(), GetStyle() );
4225 // copy until first useful item
4226 for (auto const& item
: mpData
->m_aItems
)
4228 pToolBox
->CopyItem( *this, item
.mnId
);
4229 if( (item
.meType
== ToolBoxItemType::BUTTON
) &&
4230 item
.mbVisible
&& !ImplIsFixedControl( &item
) )
4234 // add to docking manager if required to obtain a drag area
4235 // (which is accounted for in calcwindowsizepixel)
4236 if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
4237 ImplGetDockingManager()->AddWindow( pToolBox
);
4240 if( IsMenuEnabled() )
4241 pToolBox
->SetMenuType( GetMenuType() );
4243 pToolBox
->SetAlign( GetAlign() );
4244 Size aSize
= pToolBox
->CalcWindowSizePixel( 1 );
4246 ImplGetDockingManager()->RemoveWindow( pToolBox
);
4249 pToolBox
.disposeAndClear();
4255 void ToolBox::EnableCustomize( bool bEnable
)
4257 mbCustomize
= bEnable
;
4260 void ToolBox::LoseFocus()
4262 ImplChangeHighlight( nullptr, true );
4264 DockingWindow::LoseFocus();
4267 // performs the action associated with an item, ie simulates clicking the item
4268 void ToolBox::TriggerItem( sal_uInt16 nItemId
)
4270 mnHighItemId
= nItemId
;
4271 vcl::KeyCode
aKeyCode( 0, 0 );
4272 ImplActivateItem( aKeyCode
);
4275 // calls the button's action handler
4276 // returns true if action was called
4277 bool ToolBox::ImplActivateItem( vcl::KeyCode aKeyCode
)
4282 ImplToolItem
*pToolItem
= ImplGetItem( mnHighItemId
);
4284 // #107712#, activate can also be called for disabled entries
4285 if( pToolItem
&& !pToolItem
->mbEnabled
)
4288 if( pToolItem
&& pToolItem
->mpWindow
&& HasFocus() )
4291 mbChangingHighlight
= true; // avoid focus change due to loss of focus
4292 pToolItem
->mpWindow
->ImplControlFocus( GetFocusFlags::Tab
);
4293 mbChangingHighlight
= false;
4297 mnDownItemId
= mnCurItemId
= mnHighItemId
;
4298 if (pToolItem
&& (pToolItem
->mnBits
& ToolBoxItemBits::AUTOCHECK
))
4300 if ( pToolItem
->mnBits
& ToolBoxItemBits::RADIOCHECK
)
4302 if ( pToolItem
->meState
!= TRISTATE_TRUE
)
4303 SetItemState( pToolItem
->mnId
, TRISTATE_TRUE
);
4307 if ( pToolItem
->meState
!= TRISTATE_TRUE
)
4308 pToolItem
->meState
= TRISTATE_TRUE
;
4310 pToolItem
->meState
= TRISTATE_FALSE
;
4313 mnMouseModifier
= aKeyCode
.GetModifier();
4314 mbIsKeyEvent
= true;
4318 // #107776# we might be destroyed in the selecthandler
4319 VclPtr
<vcl::Window
> xWindow
= this;
4321 if ( xWindow
->IsDisposed() )
4325 mbIsKeyEvent
= false;
4326 mnMouseModifier
= 0;
4334 static bool ImplCloseLastPopup( vcl::Window
const *pParent
)
4336 // close last popup toolbox (see also:
4337 // ImplHandleMouseFloatMode(...) in winproc.cxx )
4339 if( ImplGetSVData()->maWinData
.mpFirstFloat
)
4341 FloatingWindow
* pLastLevelFloat
= ImplGetSVData()->maWinData
.mpFirstFloat
->ImplFindLastLevelFloat();
4342 // only close the floater if it is not our direct parent, which would kill ourself
4343 if( pLastLevelFloat
&& pLastLevelFloat
!= pParent
)
4345 pLastLevelFloat
->EndPopupMode( FloatWinPopupEndFlags::Cancel
| FloatWinPopupEndFlags::CloseAll
);
4352 // opens a drop down toolbox item
4353 // returns true if item was opened
4354 bool ToolBox::ImplOpenItem( vcl::KeyCode aKeyCode
)
4356 sal_uInt16 nCode
= aKeyCode
.GetCode();
4359 // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
4360 if ( ((nCode
== KEY_LEFT
|| nCode
== KEY_RIGHT
) && IsHorizontal())
4361 || ((nCode
== KEY_UP
|| nCode
== KEY_DOWN
) && !IsHorizontal()) )
4364 if( mpData
->mbMenubuttonSelected
)
4366 if( ImplCloseLastPopup( GetParent() ) )
4368 mbIsKeyEvent
= true;
4369 if ( maMenuButtonHdl
.IsSet() )
4370 maMenuButtonHdl
.Call( this );
4372 ExecuteCustomMenu( mpData
->maMenubuttonItem
.maRect
);
4373 mpData
->mbMenubuttonWasLastSelected
= true;
4374 mbIsKeyEvent
= false;
4376 else if( mnHighItemId
&& ImplGetItem( mnHighItemId
) &&
4377 (ImplGetItem( mnHighItemId
)->mnBits
& ToolBoxItemBits::DROPDOWN
) )
4379 mnDownItemId
= mnCurItemId
= mnHighItemId
;
4380 mnCurPos
= GetItemPos( mnCurItemId
);
4381 mnLastFocusItemId
= mnCurItemId
; // save item id for possible later focus restore
4382 mnMouseModifier
= aKeyCode
.GetModifier();
4383 mbIsKeyEvent
= true;
4386 mpData
->mbDropDownByKeyboard
= true;
4387 mpData
->maDropdownClickHdl
.Call( this );
4389 mbIsKeyEvent
= false;
4390 mnMouseModifier
= 0;
4398 void ToolBox::KeyInput( const KeyEvent
& rKEvt
)
4400 vcl::KeyCode aKeyCode
= rKEvt
.GetKeyCode();
4401 sal_uInt16 nCode
= aKeyCode
.GetCode();
4403 vcl::Window
*pParent
= ImplGetParent();
4404 bool bOldSchoolContainer
= ((pParent
->GetStyle() & (WB_DIALOGCONTROL
| WB_NODIALOGCONTROL
)) == WB_DIALOGCONTROL
);
4405 bool bParentIsContainer
= bOldSchoolContainer
|| isContainerWindow(pParent
);
4407 bool bForwardKey
= false;
4408 bool bGrabFocusToDocument
= false;
4410 // #107776# we might be destroyed in the keyhandler
4411 VclPtr
<vcl::Window
> xWindow
= this;
4417 // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
4418 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4420 if( !IsHorizontal() )
4421 ImplChangeHighlightUpDn( true );
4423 ImplOpenItem( aKeyCode
);
4428 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4430 if( IsHorizontal() )
4431 ImplChangeHighlightUpDn( true );
4433 ImplOpenItem( aKeyCode
);
4438 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4440 if( !IsHorizontal() )
4441 ImplChangeHighlightUpDn( false );
4443 ImplOpenItem( aKeyCode
);
4448 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4450 if( IsHorizontal() )
4451 ImplChangeHighlightUpDn( false );
4453 ImplOpenItem( aKeyCode
);
4457 if ( mnCurLine
> 1 )
4459 if( mnCurLine
> mnVisLines
)
4460 mnCurLine
= mnCurLine
- mnVisLines
;
4466 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine
) );
4470 if ( mnCurLine
+mnVisLines
-1 < mnCurLines
)
4472 if( mnCurLine
+ 2*mnVisLines
-1 < mnCurLines
)
4473 mnCurLine
= mnCurLine
+ mnVisLines
;
4475 mnCurLine
= mnCurLines
;
4479 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine
) );
4484 ImplChangeHighlight( nullptr );
4485 ImplChangeHighlightUpDn( false );
4490 ImplChangeHighlight( nullptr );
4491 ImplChangeHighlightUpDn( true );
4496 if( !ImplIsFloatingMode() && bParentIsContainer
)
4497 DockingWindow::KeyInput( rKEvt
);
4500 // send focus to document pane
4501 vcl::Window
*pWin
= this;
4504 if( !pWin
->GetParent() )
4506 pWin
->ImplGetFrameWindow()->GetWindow( GetWindowType::Client
)->GrabFocus();
4509 pWin
= pWin
->GetParent();
4516 // #107712#, disabled entries are selectable now
4517 // leave toolbox and move focus to document
4520 ImplToolItem
*pItem
= ImplGetItem(mnHighItemId
);
4521 if (!pItem
|| !pItem
->mbEnabled
)
4523 bGrabFocusToDocument
= true;
4526 if( !bGrabFocusToDocument
)
4527 bForwardKey
= !ImplActivateItem( aKeyCode
);
4532 ImplOpenItem( aKeyCode
);
4537 sal_uInt16 aKeyGroup
= aKeyCode
.GetGroup();
4538 ImplToolItem
*pItem
= nullptr;
4540 pItem
= ImplGetItem( mnHighItemId
);
4541 // #i13931# forward alphanum keyinput into embedded control
4542 if( (aKeyGroup
== KEYGROUP_NUM
|| aKeyGroup
== KEYGROUP_ALPHA
) && pItem
&& pItem
->mpWindow
&& pItem
->mbEnabled
)
4544 vcl::Window
*pFocusWindow
= Application::GetFocusWindow();
4546 mbChangingHighlight
= true; // avoid focus change due to loss of focus
4547 pItem
->mpWindow
->ImplControlFocus( GetFocusFlags::Tab
);
4548 mbChangingHighlight
= false;
4549 if( pFocusWindow
!= Application::GetFocusWindow() )
4550 Application::GetFocusWindow()->KeyInput( rKEvt
);
4554 // do nothing to avoid key presses going into the document
4555 // while the toolbox has the focus
4556 // just forward function and special keys and combinations with Alt-key
4557 if( aKeyGroup
== KEYGROUP_FKEYS
|| aKeyGroup
== KEYGROUP_MISC
|| aKeyCode
.IsMod2() )
4563 if ( xWindow
->IsDisposed() )
4566 // #107251# move focus away if this toolbox was disabled during keyinput
4567 if (HasFocus() && mpData
->mbKeyInputDisabled
&& bParentIsContainer
)
4569 vcl::Window
*pFocusControl
= pParent
->ImplGetDlgWindow( 0, GetDlgWindowType::First
);
4570 if ( pFocusControl
&& pFocusControl
!= this )
4571 pFocusControl
->ImplControlFocus( GetFocusFlags::Init
);
4574 // #107712#, leave toolbox
4575 if( bGrabFocusToDocument
)
4577 GrabFocusToDocument();
4582 DockingWindow::KeyInput( rKEvt
);
4585 // returns the current toolbox line of the item
4586 ToolBox::ImplToolItems::size_type
ToolBox::ImplGetItemLine( ImplToolItem
const * pCurrentItem
)
4588 ImplToolItems::size_type nLine
= 1;
4589 for (auto const& item
: mpData
->m_aItems
)
4593 if( &item
== pCurrentItem
)
4599 // returns the first displayable item in the given line
4600 ImplToolItem
* ToolBox::ImplGetFirstValidItem( ImplToolItems::size_type nLine
)
4602 if( !nLine
|| nLine
> mnCurLines
)
4607 ImplToolItems::iterator it
= mpData
->m_aItems
.begin();
4608 while( it
!= mpData
->m_aItems
.end() )
4610 // find correct line
4615 // find first useful item
4616 while( it
!= mpData
->m_aItems
.end() && ((it
->meType
!= ToolBoxItemType::BUTTON
) ||
4617 /*!it->mbEnabled ||*/ !it
->mbVisible
|| ImplIsFixedControl( &(*it
) )) )
4620 if( it
== mpData
->m_aItems
.end() || it
->mbBreak
)
4621 return nullptr; // no valid items in this line
4628 return (it
== mpData
->m_aItems
.end()) ? nullptr : &(*it
);
4631 ToolBox::ImplToolItems::size_type
ToolBox::ImplFindItemPos( const ImplToolItem
* pItem
, const ImplToolItems
& rList
)
4635 for( ImplToolItems::size_type nPos
= 0; nPos
< rList
.size(); ++nPos
)
4636 if( &rList
[ nPos
] == pItem
)
4639 return ITEM_NOTFOUND
;
4642 void ToolBox::ChangeHighlight( ImplToolItems::size_type nPos
)
4644 if ( nPos
< GetItemCount() ) {
4645 ImplGrabFocus( GetFocusFlags::NONE
);
4646 ImplChangeHighlight ( ImplGetItem ( GetItemId ( nPos
) ) );
4650 void ToolBox::ImplChangeHighlight( ImplToolItem
const * pItem
, bool bNoGrabFocus
)
4652 // avoid recursion due to focus change
4653 if( mbChangingHighlight
)
4656 mbChangingHighlight
= true;
4658 ImplToolItem
* pOldItem
= nullptr;
4663 ImplToolItems::size_type nPos
= GetItemPos( mnHighItemId
);
4664 pOldItem
= ImplGetItem( mnHighItemId
);
4665 // #i89962# ImplDrawItem can cause Invalidate/Update
4666 // which will in turn ImplShowFocus again
4667 // set mnHighItemId to 0 already to prevent this hen/egg problem
4669 InvalidateItem(nPos
);
4670 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nPos
) );
4673 if( !bNoGrabFocus
&& pItem
!= pOldItem
&& pOldItem
&& pOldItem
->mpWindow
)
4675 // move focus into toolbox
4681 ImplToolItems::size_type aPos
= ToolBox::ImplFindItemPos( pItem
, mpData
->m_aItems
);
4682 if( aPos
!= ITEM_NOTFOUND
)
4684 // check for line breaks
4685 ImplToolItems::size_type nLine
= ImplGetItemLine( pItem
);
4687 if( nLine
>= mnCurLine
+ mnVisLines
)
4689 mnCurLine
= nLine
- mnVisLines
+ 1;
4692 else if ( nLine
< mnCurLine
)
4703 mnHighItemId
= pItem
->mnId
;
4704 InvalidateItem(aPos
);
4710 if( pItem
->mpWindow
)
4711 pItem
->mpWindow
->GrabFocus();
4712 if( pItem
!= pOldItem
)
4713 CallEventListeners( VclEventId::ToolboxHighlight
);
4720 mnCurPos
= ITEM_NOTFOUND
;
4723 mbChangingHighlight
= false;
4726 // check for keyboard accessible items
4727 static bool ImplIsValidItem( const ImplToolItem
* pItem
, bool bNotClipped
)
4729 bool bValid
= (pItem
&& pItem
->meType
== ToolBoxItemType::BUTTON
&& pItem
->mbVisible
&& !ImplIsFixedControl( pItem
)
4730 && pItem
->mbEnabled
);
4731 if( bValid
&& bNotClipped
&& pItem
->IsClipped() )
4736 bool ToolBox::ChangeHighlightUpDn( bool bUp
)
4738 return ImplChangeHighlightUpDn(bUp
, /*bNoCycle*/ false);
4741 bool ToolBox::ImplChangeHighlightUpDn( bool bUp
, bool bNoCycle
)
4743 ImplToolItem
* pToolItem
= ImplGetItem( mnHighItemId
);
4745 if( !pToolItem
|| !mnHighItemId
)
4747 // menubutton highlighted ?
4748 if( mpData
->mbMenubuttonSelected
)
4750 mpData
->mbMenubuttonSelected
= false;
4753 // select last valid non-clipped item
4754 ImplToolItem
* pItem
= nullptr;
4755 auto it
= std::find_if(mpData
->m_aItems
.rbegin(), mpData
->m_aItems
.rend(),
4756 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, true ); });
4757 if( it
!= mpData
->m_aItems
.rend() )
4760 InvalidateMenuButton();
4761 ImplChangeHighlight( pItem
);
4765 // select first valid non-clipped item
4766 ImplToolItems::iterator it
= std::find_if(mpData
->m_aItems
.begin(), mpData
->m_aItems
.end(),
4767 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, true ); });
4768 if( it
!= mpData
->m_aItems
.end() )
4770 InvalidateMenuButton();
4771 ImplChangeHighlight( &(*it
) );
4779 // Select first valid item
4780 ImplToolItems::iterator it
= std::find_if(mpData
->m_aItems
.begin(), mpData
->m_aItems
.end(),
4781 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, false ); });
4783 // select the menu button if a clipped item would be selected
4784 if( (it
!= mpData
->m_aItems
.end() && &(*it
) == ImplGetFirstClippedItem()) && IsMenuEnabled() )
4786 ImplChangeHighlight( nullptr );
4787 mpData
->mbMenubuttonSelected
= true;
4788 InvalidateMenuButton();
4791 ImplChangeHighlight( (it
!= mpData
->m_aItems
.end()) ? &(*it
) : nullptr );
4796 // Select last valid item
4798 // docked toolbars have the menubutton as last item - if this button is enabled
4799 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4801 ImplChangeHighlight( nullptr );
4802 mpData
->mbMenubuttonSelected
= true;
4803 InvalidateMenuButton();
4807 ImplToolItem
* pItem
= nullptr;
4808 auto it
= std::find_if(mpData
->m_aItems
.rbegin(), mpData
->m_aItems
.rend(),
4809 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, false ); });
4810 if( it
!= mpData
->m_aItems
.rend() )
4813 ImplChangeHighlight( pItem
);
4821 ImplToolItems::size_type pos
= ToolBox::ImplFindItemPos( pToolItem
, mpData
->m_aItems
);
4822 ImplToolItems::size_type nCount
= mpData
->m_aItems
.size();
4824 ImplToolItems::size_type i
=0;
4834 // highlight the menu button if it is the last item
4835 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4837 ImplChangeHighlight( nullptr );
4838 mpData
->mbMenubuttonSelected
= true;
4839 InvalidateMenuButton();
4848 if( ++pos
>= nCount
)
4853 // highlight the menu button if it is the last item
4854 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4856 ImplChangeHighlight( nullptr );
4857 mpData
->mbMenubuttonSelected
= true;
4858 InvalidateMenuButton();
4866 pToolItem
= &mpData
->m_aItems
[pos
];
4868 if ( ImplIsValidItem( pToolItem
, false ) )
4871 } while( ++i
< nCount
);
4873 if( pToolItem
->IsClipped() && IsMenuEnabled() )
4875 // select the menu button if a clipped item would be selected
4876 ImplChangeHighlight( nullptr );
4877 mpData
->mbMenubuttonSelected
= true;
4878 InvalidateMenuButton();
4880 else if( i
!= nCount
)
4881 ImplChangeHighlight( pToolItem
);
4888 void ToolBox::ImplShowFocus()
4890 if( mnHighItemId
&& HasFocus() )
4892 ImplToolItem
* pItem
= ImplGetItem( mnHighItemId
);
4893 if (pItem
&& pItem
->mpWindow
&& !pItem
->mpWindow
->IsDisposed())
4895 vcl::Window
*pWin
= pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
? pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
.get() : pItem
->mpWindow
.get();
4896 pWin
->ImplGetWindowImpl()->mbDrawSelectionBackground
= true;
4902 void ToolBox::ImplHideFocus()
4906 mpData
->mbMenubuttonWasLastSelected
= false;
4907 ImplToolItem
* pItem
= ImplGetItem( mnHighItemId
);
4908 if( pItem
&& pItem
->mpWindow
)
4910 vcl::Window
*pWin
= pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
? pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
.get() : pItem
->mpWindow
.get();
4911 pWin
->ImplGetWindowImpl()->mbDrawSelectionBackground
= false;
4916 if ( mpData
&& mpData
->mbMenubuttonSelected
)
4918 mpData
->mbMenubuttonWasLastSelected
= true;
4919 // remove highlight from menubutton
4920 mpData
->mbMenubuttonSelected
= false;
4921 InvalidateMenuButton();
4925 void ToolBox::ImplDisableFlatButtons()
4927 #ifdef _WIN32 // Check in the Windows registry if an AT tool wants no flat toolboxes
4928 static bool bInit
= false, bValue
= false;
4934 if( ERROR_SUCCESS
== RegOpenKeyW(HKEY_CURRENT_USER
, L
"Software\\LibreOffice\\Accessibility\\AtToolSupport", &hkey
) )
4937 wchar_t Data
[6]; // possible values: "true", "false", "1", "0", DWORD
4938 DWORD cbData
= sizeof(Data
);
4940 if( ERROR_SUCCESS
== RegQueryValueExW(hkey
, L
"DisableFlatToolboxButtons",
4941 nullptr, &dwType
, reinterpret_cast<LPBYTE
>(Data
), &cbData
) )
4946 bValue
= ((0 == wcsicmp(Data
, L
"1")) || (0 == wcsicmp(Data
, L
"true")));
4949 bValue
= static_cast<bool>(reinterpret_cast<DWORD
*>(Data
)[0]);
4957 mnOutStyle
&= ~TOOLBOX_STYLE_FLAT
;
4959 (void) this; // loplugin:staticmethods
4963 void ToolBox::SetToolbarLayoutMode( ToolBoxLayoutMode eLayout
)
4965 if ( meLayoutMode
!= eLayout
)
4966 meLayoutMode
= eLayout
;
4969 void ToolBox::SetToolBoxTextPosition( ToolBoxTextPosition ePosition
)
4971 meTextPosition
= ePosition
;
4974 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */