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/event.hxx>
22 #include <vcl/decoview.hxx>
23 #include <vcl/toolkit/floatwin.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/help.hxx>
26 #include <vcl/mnemonic.hxx>
27 #include <vcl/gradient.hxx>
28 #include <vcl/layout.hxx>
29 #include <vcl/menu.hxx>
30 #include <vcl/settings.hxx>
31 #include <vcl/ptrstyle.hxx>
32 #include <bitmaps.hlst>
33 #include <toolbarvalue.hxx>
35 #include <tools/poly.hxx>
36 #include <sal/log.hxx>
37 #include <o3tl/string_view.hxx>
38 #include <osl/diagnose.h>
51 #include <string_view>
55 #include "impldockingwrapper.hxx"
57 #define SMALLBUTTON_HSIZE 7
58 #define SMALLBUTTON_VSIZE 7
60 #define SMALLBUTTON_OFF_NORMAL_X 3
61 #define SMALLBUTTON_OFF_NORMAL_Y 3
63 #define TB_TEXTOFFSET 2
64 #define TB_IMAGETEXTOFFSET 3
65 #define TB_LINESPACING 3
66 #define TB_SPIN_SIZE 14
67 #define TB_SPIN_OFFSET 2
68 #define TB_BORDER_OFFSET1 4
69 #define TB_BORDER_OFFSET2 2
71 #define TB_MAXNOSCROLL 32765
73 #define TB_DRAGWIDTH 8 // the default width of the drag grip
75 #define TB_CALCMODE_HORZ 1
76 #define TB_CALCMODE_VERT 2
77 #define TB_CALCMODE_FLOAT 3
79 #define TB_WBLINESIZING (WB_SIZEABLE | WB_DOCKABLE | WB_SCROLL)
81 #define DOCK_LINEHSIZE (sal_uInt16(0x0001))
82 #define DOCK_LINEVSIZE (sal_uInt16(0x0002))
83 #define DOCK_LINERIGHT (sal_uInt16(0x1000))
84 #define DOCK_LINEBOTTOM (sal_uInt16(0x2000))
85 #define DOCK_LINELEFT (sal_uInt16(0x4000))
86 #define DOCK_LINETOP (sal_uInt16(0x8000))
87 #define DOCK_LINEOFFSET 3
92 VclPtr
<ToolBox
> mpDragBox
;
94 tools::Rectangle maRect
;
95 tools::Rectangle maStartRect
;
97 sal_uInt16 mnLineMode
;
98 ToolBox::ImplToolItems::size_type mnStartLines
;
100 ImplTBDragMgr(const ImplTBDragMgr
&) = delete;
101 ImplTBDragMgr
& operator=(const ImplTBDragMgr
&) = delete;
106 void StartDragging( ToolBox
* pDragBox
, const Point
& rPos
, const tools::Rectangle
& rRect
, sal_uInt16 nLineMode
);
107 void Dragging( const Point
& rPos
);
108 void EndDragging( bool bOK
= true );
109 DECL_LINK( SelectHdl
, Accelerator
&, void );
113 static ImplTBDragMgr
* ImplGetTBDragMgr()
115 ImplSVData
* pSVData
= ImplGetSVData();
116 if ( !pSVData
->maCtrlData
.mpTBDragMgr
)
117 pSVData
->maCtrlData
.mpTBDragMgr
= new ImplTBDragMgr
;
118 return pSVData
->maCtrlData
.mpTBDragMgr
;
121 int ToolBox::ImplGetDragWidth( const vcl::Window
& rWindow
, bool bHorz
)
123 return ImplGetDragWidth(*rWindow
.GetOutDev(), bHorz
);
125 int ToolBox::ImplGetDragWidth( const vcl::RenderContext
& rRenderContext
, bool bHorz
)
127 int nWidth
= TB_DRAGWIDTH
;
128 if( rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Entire
) )
131 ImplControlValue aControlValue
;
132 tools::Rectangle aContent
, aBound
;
133 tools::Rectangle
aArea( Point(), rRenderContext
.GetOutputSizePixel() );
135 if ( rRenderContext
.GetNativeControlRegion(ControlType::Toolbar
,
136 bHorz
? ControlPart::ThumbVert
: ControlPart::ThumbHorz
,
137 aArea
, ControlState::NONE
, aControlValue
, aBound
, aContent
) )
139 nWidth
= bHorz
? aContent
.GetWidth() : aContent
.GetHeight();
143 // increase the hit area of the drag handle according to DPI scale factor
144 nWidth
*= rRenderContext
.GetDPIScaleFactor();
149 int ToolBox::ImplGetDragWidth() const
151 return ToolBox::ImplGetDragWidth( *this, mbHorz
);
154 static ButtonType
determineButtonType( ImplToolItem
const * pItem
, ButtonType defaultType
)
156 ButtonType tmpButtonType
= defaultType
;
157 ToolBoxItemBits nBits
= pItem
->mnBits
& ( ToolBoxItemBits::TEXT_ONLY
| ToolBoxItemBits::ICON_ONLY
);
158 if ( nBits
!= ToolBoxItemBits::NONE
) // item has custom setting
160 tmpButtonType
= ButtonType::SYMBOLTEXT
;
161 if ( nBits
== ToolBoxItemBits::TEXT_ONLY
)
162 tmpButtonType
= ButtonType::TEXT
;
163 else if ( nBits
== ToolBoxItemBits::ICON_ONLY
)
164 tmpButtonType
= ButtonType::SYMBOLONLY
;
166 return tmpButtonType
;
169 void ToolBox::ImplUpdateDragArea() const
171 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
174 if ( ImplIsFloatingMode() || pWrapper
->IsLocked() )
175 pWrapper
->SetDragArea( tools::Rectangle() );
178 if( meAlign
== WindowAlign::Top
|| meAlign
== WindowAlign::Bottom
)
179 pWrapper
->SetDragArea( tools::Rectangle( 0, 0, ImplGetDragWidth(), GetOutputSizePixel().Height() ) );
181 pWrapper
->SetDragArea( tools::Rectangle( 0, 0, GetOutputSizePixel().Width(), ImplGetDragWidth() ) );
186 void ToolBox::ImplCalcBorder( WindowAlign eAlign
, tools::Long
& rLeft
, tools::Long
& rTop
,
187 tools::Long
& rRight
, tools::Long
& rBottom
) const
189 if( ImplIsFloatingMode() || !(mnWinStyle
& WB_BORDER
) )
191 // no border in floating mode
192 rLeft
= rTop
= rRight
= rBottom
= 0;
196 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
198 // reserve DragArea only for dockable toolbars
199 int dragwidth
= ( pWrapper
&& !pWrapper
->IsLocked() ) ? ImplGetDragWidth() : 0;
201 // no shadow border for dockable toolbars and toolbars with WB_NOSHADOW bit set, e.g. Calc's formulabar
202 int borderwidth
= ( pWrapper
|| mnWinStyle
& WB_NOSHADOW
) ? 0 : 2;
204 if ( eAlign
== WindowAlign::Top
)
206 rLeft
= borderwidth
+dragwidth
;
208 rRight
= borderwidth
;
211 else if ( eAlign
== WindowAlign::Left
)
214 rTop
= borderwidth
+dragwidth
;
216 rBottom
= borderwidth
;
218 else if ( eAlign
== WindowAlign::Bottom
)
220 rLeft
= borderwidth
+dragwidth
;
222 rRight
= borderwidth
;
223 rBottom
= borderwidth
;
228 rTop
= borderwidth
+dragwidth
;
229 rRight
= borderwidth
;
230 rBottom
= borderwidth
;
234 void ToolBox::ImplCheckUpdate()
236 // remove any pending invalidates to avoid
237 // have them triggered when paint is locked (see mpData->mbIsPaintLocked)
238 // which would result in erasing the background only and not painting any items
239 // this must not be done when we're already in Paint()
241 // this is only required for transparent toolbars (see ImplDrawTransparentBackground() )
242 if( !IsBackground() && HasPaintEvent() && !IsInPaint() )
246 void ToolBox::ImplDrawGrip(vcl::RenderContext
& rRenderContext
,
247 const tools::Rectangle
&aDragArea
, int nDragWidth
, WindowAlign eAlign
, bool bHorz
)
249 bool bNativeOk
= false;
250 const ControlPart ePart
= bHorz
? ControlPart::ThumbVert
: ControlPart::ThumbHorz
;
251 const Size
aSz( rRenderContext
.GetOutputSizePixel() );
252 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ePart
))
254 ToolbarValue aToolbarValue
;
255 aToolbarValue
.maGripRect
= aDragArea
;
257 tools::Rectangle
aCtrlRegion(Point(), aSz
);
259 bNativeOk
= rRenderContext
.DrawNativeControl( ControlType::Toolbar
, ePart
,
260 aCtrlRegion
, ControlState::ENABLED
, aToolbarValue
, OUString() );
266 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
267 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
268 rRenderContext
.SetFillColor(rStyleSettings
.GetShadowColor());
270 float fScaleFactor
= rRenderContext
.GetDPIScaleFactor();
272 if (eAlign
== WindowAlign::Top
|| eAlign
== WindowAlign::Bottom
)
274 int height
= static_cast<int>(0.6 * aSz
.Height() + 0.5);
275 int i
= (aSz
.Height() - height
) / 2;
279 int x
= nDragWidth
/ 2;
280 rRenderContext
.DrawEllipse(tools::Rectangle(Point(x
, i
), Size(2 * fScaleFactor
, 2 * fScaleFactor
)));
281 i
+= 4 * fScaleFactor
;
286 int width
= static_cast<int>(0.6 * aSz
.Width() + 0.5);
287 int i
= (aSz
.Width() - width
) / 2;
291 int y
= nDragWidth
/ 2;
292 rRenderContext
.DrawEllipse(tools::Rectangle(Point(i
, y
), Size(2 * fScaleFactor
, 2 * fScaleFactor
)));
293 i
+= 4 * fScaleFactor
;
298 void ToolBox::ImplDrawGrip(vcl::RenderContext
& rRenderContext
)
300 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
301 if( pWrapper
&& !pWrapper
->GetDragArea().IsEmpty() )
303 // execute pending paint requests
305 ImplDrawGrip( rRenderContext
, pWrapper
->GetDragArea(),
306 ImplGetDragWidth(), meAlign
, mbHorz
);
310 void ToolBox::ImplDrawGradientBackground(vcl::RenderContext
& rRenderContext
)
312 // draw a nice gradient
314 Color startCol
, endCol
;
315 const StyleSettings rSettings
= rRenderContext
.GetSettings().GetStyleSettings();
317 startCol
= rSettings
.GetFaceGradientColor();
318 endCol
= rSettings
.GetFaceColor();
319 if (rSettings
.GetHighContrastMode())
320 // no 'extreme' gradient when high contrast
324 g
.SetAngle(Degree10(mbHorz
? 0 : 900));
325 g
.SetStyle(css::awt::GradientStyle_LINEAR
);
327 g
.SetStartColor(startCol
);
328 g
.SetEndColor(endCol
);
330 bool bLineColor
= rRenderContext
.IsLineColor();
331 Color aOldCol
= rRenderContext
.GetLineColor();
332 rRenderContext
.SetLineColor(rRenderContext
.GetSettings().GetStyleSettings().GetShadowColor());
334 Size
aFullSz(GetOutputSizePixel());
335 Size
aLineSz(aFullSz
);
337 // use the linesize only when floating
338 // full window height is used when docked (single line)
339 if (ImplIsFloatingMode())
341 tools::Long nLineSize
;
344 nLineSize
= mnMaxItemHeight
;
345 if (mnWinHeight
> mnMaxItemHeight
)
346 nLineSize
= mnWinHeight
;
348 aLineSz
.setHeight( nLineSize
);
352 nLineSize
= mnMaxItemWidth
;
353 aLineSz
.setWidth( nLineSize
);
357 tools::Long nLeft
, nTop
, nRight
, nBottom
;
358 ImplCalcBorder(meAlign
, nLeft
, nTop
, nRight
, nBottom
);
360 Size
aTopLineSz(aLineSz
);
361 Size
aBottomLineSz(aLineSz
);
363 if (mnWinStyle
& WB_BORDER
)
367 aTopLineSz
.AdjustHeight(TB_BORDER_OFFSET2
+ nTop
);
368 aBottomLineSz
.AdjustHeight(TB_BORDER_OFFSET2
+ nBottom
);
371 aTopLineSz
.AdjustHeight(TB_BORDER_OFFSET2
+ nBottom
);
375 aTopLineSz
.AdjustWidth(TB_BORDER_OFFSET1
+ nLeft
);
376 aBottomLineSz
.AdjustWidth(TB_BORDER_OFFSET1
+ nRight
);
379 aTopLineSz
.AdjustWidth(TB_BORDER_OFFSET1
+ nLeft
);
387 aLineSz
.AdjustHeight(TB_LINESPACING
);
389 aTopLineSz
.AdjustHeight(TB_LINESPACING
);
393 aLineSz
.AdjustWidth(TB_LINESPACING
);
395 aTopLineSz
.AdjustWidth(TB_LINESPACING
);
403 rRenderContext
.DrawGradient(tools::Rectangle(0, y
, aTopLineSz
.Width(), y
+ aTopLineSz
.Height()), g
);
404 y
+= aTopLineSz
.Height();
406 while (y
< (mnDY
- aBottomLineSz
.Height()))
408 rRenderContext
.DrawGradient(tools::Rectangle(0, y
, aLineSz
.Width(), y
+ aLineSz
.Height()), g
);
409 y
+= aLineSz
.Height();
412 rRenderContext
.DrawGradient(tools::Rectangle(0, y
, aBottomLineSz
.Width(), y
+ aBottomLineSz
.Height()), g
);
418 rRenderContext
.DrawGradient(tools::Rectangle(x
, 0, x
+ aTopLineSz
.Width(), aTopLineSz
.Height()), g
);
419 x
+= aTopLineSz
.Width();
421 while (x
< (mnDX
- aBottomLineSz
.Width()))
423 rRenderContext
.DrawGradient(tools::Rectangle(x
, 0, x
+ aLineSz
.Width(), aLineSz
.Height()), g
);
424 x
+= aLineSz
.Width();
427 rRenderContext
.DrawGradient(tools::Rectangle( x
, 0, x
+ aBottomLineSz
.Width(), aBottomLineSz
.Height()), g
);
431 rRenderContext
.SetLineColor( aOldCol
);
435 bool ToolBox::ImplDrawNativeBackground(vcl::RenderContext
& rRenderContext
) const
438 tools::Rectangle
aCtrlRegion(Point(), GetOutputSizePixel());
440 return rRenderContext
.DrawNativeControl( ControlType::Toolbar
, mbHorz
? ControlPart::DrawBackgroundHorz
: ControlPart::DrawBackgroundVert
,
441 aCtrlRegion
, ControlState::ENABLED
, ImplControlValue(), OUString() );
444 void ToolBox::ImplDrawTransparentBackground(const vcl::Region
&rRegion
)
446 // just invalidate to trigger paint of the parent
447 const bool bOldPaintLock
= mpData
->mbIsPaintLocked
;
448 mpData
->mbIsPaintLocked
= true;
450 // send an invalidate to the first opaque parent and invalidate the whole hierarchy from there (noclipchildren)
451 Invalidate(rRegion
, InvalidateFlags::Update
| InvalidateFlags::NoClipChildren
);
453 mpData
->mbIsPaintLocked
= bOldPaintLock
;
456 void ToolBox::ImplDrawConstantBackground(vcl::RenderContext
& rRenderContext
, const vcl::Region
&rRegion
, bool bIsInPopupMode
)
458 // draw a constant color
461 // default background
462 rRenderContext
.Erase(rRegion
.GetBoundRect());
466 // use different color in popupmode
467 const StyleSettings rSettings
= rRenderContext
.GetSettings().GetStyleSettings();
468 Wallpaper
aWallpaper(rSettings
.GetFaceGradientColor());
469 rRenderContext
.DrawWallpaper(rRegion
.GetBoundRect(), aWallpaper
);
473 void ToolBox::ImplDrawBackground(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
475 // execute pending paint requests
478 ImplDockingWindowWrapper
* pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
479 bool bIsInPopupMode
= ImplIsInPopupMode();
481 vcl::Region
aPaintRegion(rRect
);
483 // make sure we do not invalidate/erase too much
485 aPaintRegion
.Intersect(GetOutDev()->GetActiveClipRegion());
487 rRenderContext
.Push(vcl::PushFlags::CLIPREGION
);
488 rRenderContext
.IntersectClipRegion( aPaintRegion
);
492 // no gradient for ordinary toolbars (not dockable)
493 if( !IsBackground() && !IsInPaint() )
494 ImplDrawTransparentBackground(aPaintRegion
);
496 ImplDrawConstantBackground(rRenderContext
, aPaintRegion
, bIsInPopupMode
);
500 // toolbars known to the dockingmanager will be drawn using NWF or a gradient
501 // docked toolbars are transparent and NWF is already used in the docking area which is their common background
502 // so NWF is used here for floating toolbars only
503 bool bNativeOk
= false;
504 if( ImplIsFloatingMode() && rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Entire
) )
505 bNativeOk
= ImplDrawNativeBackground(rRenderContext
);
508 const StyleSettings rSetting
= Application::GetSettings().GetStyleSettings();
512 ImplDrawTransparentBackground(aPaintRegion
);
515 ImplDrawGradientBackground(rRenderContext
);
519 // restore clip region
520 rRenderContext
.Pop();
523 void ToolBox::ImplErase(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&rRect
, bool bHighlight
, bool bHasOpenPopup
)
525 // the background of non NWF buttons is painted in a constant color
526 // to have the same highlight color (transparency in DrawSelectionBackground())
527 // items with open popups will also painted using a constant color
528 if (!mpData
->mbNativeButtons
&&
529 (bHighlight
|| !(GetStyle() & WB_3DLOOK
)))
531 if (GetStyle() & WB_3DLOOK
)
533 rRenderContext
.Push(vcl::PushFlags::LINECOLOR
| vcl::PushFlags::FILLCOLOR
);
534 rRenderContext
.SetLineColor();
536 // choose the same color as the popup will use
537 rRenderContext
.SetFillColor(rRenderContext
.GetSettings().GetStyleSettings().GetFaceColor());
539 rRenderContext
.SetFillColor(rRenderContext
.GetSettings().GetStyleSettings().GetWindowColor());
541 rRenderContext
.DrawRect(rRect
);
542 rRenderContext
.Pop();
545 ImplDrawBackground(rRenderContext
, rRect
);
548 ImplDrawBackground(rRenderContext
, rRect
);
551 void ToolBox::ImplDrawBorder(vcl::RenderContext
& rRenderContext
)
553 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
554 tools::Long nDX
= mnDX
;
555 tools::Long nDY
= mnDY
;
557 ImplDockingWindowWrapper
* pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
559 // draw borders for ordinary toolbars only (not dockable), do not draw borders for toolbars with WB_NOSHADOW bit set,
560 // e.g. Calc's formulabar
562 if( pWrapper
|| mnWinStyle
& WB_NOSHADOW
)
565 if (meAlign
== WindowAlign::Bottom
)
567 // draw bottom border
568 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
569 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-1, nDY
-2 ) );
570 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
571 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
576 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
577 rRenderContext
.DrawLine( Point( 0, 0 ), Point( nDX
-1, 0 ) );
578 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
579 rRenderContext
.DrawLine( Point( 0, 1 ), Point( nDX
-1, 1 ) );
581 if (meAlign
== WindowAlign::Left
|| meAlign
== WindowAlign::Right
)
583 if (meAlign
== WindowAlign::Left
)
585 // draw left-bottom border
586 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
587 rRenderContext
.DrawLine( Point( 0, 0 ), Point( 0, nDY
-1 ) );
588 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-1, nDY
-2 ) );
589 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
590 rRenderContext
.DrawLine( Point( 1, 1 ), Point( 1, nDY
-3 ) );
591 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
595 // draw right-bottom border
596 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
597 rRenderContext
.DrawLine( Point( nDX
-2, 0 ), Point( nDX
-2, nDY
-3 ) );
598 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-2, nDY
-2 ) );
599 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
600 rRenderContext
.DrawLine( Point( nDX
-1, 0 ), Point( nDX
-1, nDY
-1 ) );
601 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
606 if ( meAlign
== WindowAlign::Bottom
|| meAlign
== WindowAlign::Top
)
609 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
610 rRenderContext
.DrawLine( Point( nDX
-2, 0 ), Point( nDX
-2, nDY
-1 ) );
611 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
612 rRenderContext
.DrawLine( Point( nDX
-1, 0 ), Point( nDX
-1, nDY
-1 ) );
616 static bool ImplIsFixedControl( const ImplToolItem
*pItem
)
618 return ( pItem
->mpWindow
&&
619 (pItem
->mbNonInteractiveWindow
||
620 pItem
->mpWindow
->GetType() == WindowType::FIXEDTEXT
||
621 pItem
->mpWindow
->GetType() == WindowType::FIXEDLINE
||
622 pItem
->mpWindow
->GetType() == WindowType::GROUPBOX
) );
625 const ImplToolItem
*ToolBox::ImplGetFirstClippedItem() const
627 for (auto & item
: mpData
->m_aItems
)
629 if( item
.IsClipped() )
635 Size
ToolBox::ImplCalcSize( ImplToolItems::size_type nCalcLines
, sal_uInt16 nCalcMode
)
638 tools::Long nLeft
= 0;
639 tools::Long nTop
= 0;
640 tools::Long nRight
= 0;
641 tools::Long nBottom
= 0;
643 WindowAlign eOldAlign
= meAlign
;
644 bool bOldHorz
= mbHorz
;
645 bool bOldAssumeDocked
= mpData
->mbAssumeDocked
;
646 bool bOldAssumeFloating
= mpData
->mbAssumeFloating
;
650 bool bOldFloatingMode
= ImplIsFloatingMode();
652 mpData
->mbAssumeDocked
= false;
653 mpData
->mbAssumeFloating
= false;
655 if ( nCalcMode
== TB_CALCMODE_HORZ
)
657 mpData
->mbAssumeDocked
= true; // force non-floating mode during calculation
658 ImplCalcBorder( WindowAlign::Top
, nLeft
, nTop
, nRight
, nBottom
);
660 if ( mbHorz
!= bOldHorz
)
661 meAlign
= WindowAlign::Top
;
663 else if ( nCalcMode
== TB_CALCMODE_VERT
)
665 mpData
->mbAssumeDocked
= true; // force non-floating mode during calculation
666 ImplCalcBorder( WindowAlign::Left
, nLeft
, nTop
, nRight
, nBottom
);
668 if ( mbHorz
!= bOldHorz
)
669 meAlign
= WindowAlign::Left
;
671 else if ( nCalcMode
== TB_CALCMODE_FLOAT
)
673 mpData
->mbAssumeFloating
= true; // force non-floating mode during calculation
674 nLeft
= nTop
= nRight
= nBottom
= 0;
676 if ( mbHorz
!= bOldHorz
)
677 meAlign
= WindowAlign::Top
;
680 if ( (meAlign
!= eOldAlign
) || (mbHorz
!= bOldHorz
) ||
681 (ImplIsFloatingMode() != bOldFloatingMode
) )
685 ImplCalcBorder( meAlign
, nLeft
, nTop
, nRight
, nBottom
);
689 if( !nCalcMode
&& ImplIsFloatingMode() )
691 aSize
= ImplCalcFloatSize( nCalcLines
);
697 if ( mnWinHeight
> mnMaxItemHeight
)
698 aSize
.setHeight( nCalcLines
* mnWinHeight
);
700 aSize
.setHeight( nCalcLines
* mnMaxItemHeight
);
703 aSize
.AdjustHeight((nCalcLines
-1)*TB_LINESPACING
);
705 if ( mnWinStyle
& WB_BORDER
)
706 aSize
.AdjustHeight((TB_BORDER_OFFSET2
*2) + nTop
+ nBottom
);
709 ImplCalcBreaks( TB_MAXNOSCROLL
, &nMax
, mbHorz
);
711 aSize
.AdjustWidth(nMax
);
713 if ( mnWinStyle
& WB_BORDER
)
714 aSize
.AdjustWidth((TB_BORDER_OFFSET1
*2) + nLeft
+ nRight
);
718 aSize
.setWidth( nCalcLines
* mnMaxItemWidth
);
721 aSize
.AdjustWidth((nCalcLines
-1)*TB_LINESPACING
);
723 if ( mnWinStyle
& WB_BORDER
)
724 aSize
.AdjustWidth((TB_BORDER_OFFSET2
*2) + nLeft
+ nRight
);
727 ImplCalcBreaks( TB_MAXNOSCROLL
, &nMax
, mbHorz
);
729 aSize
.AdjustHeight(nMax
);
731 if ( mnWinStyle
& WB_BORDER
)
732 aSize
.AdjustHeight((TB_BORDER_OFFSET1
*2) + nTop
+ nBottom
);
735 // restore previous values
738 mpData
->mbAssumeDocked
= bOldAssumeDocked
;
739 mpData
->mbAssumeFloating
= bOldAssumeFloating
;
740 if ( (meAlign
!= eOldAlign
) || (mbHorz
!= bOldHorz
) )
751 void ToolBox::ImplCalcFloatSizes()
753 if ( !maFloatSizes
.empty() )
756 // calculate the minimal size, i.e. where the biggest item just fits
757 tools::Long nCalcSize
= 0;
759 for (auto const& item
: mpData
->m_aItems
)
761 if ( item
.mbVisible
)
765 tools::Long nTempSize
= item
.mpWindow
->GetSizePixel().Width();
766 if ( nTempSize
> nCalcSize
)
767 nCalcSize
= nTempSize
;
771 if( item
.maItemSize
.Width() > nCalcSize
)
772 nCalcSize
= item
.maItemSize
.Width();
777 // calc an upper bound for ImplCalcBreaks below
778 tools::Long upperBoundWidth
= nCalcSize
* mpData
->m_aItems
.size();
780 ImplToolItems::size_type nLines
;
781 ImplToolItems::size_type nCalcLines
;
782 ImplToolItems::size_type nTempLines
;
783 sal_Int32 nMaxLineWidth
;
784 nCalcLines
= ImplCalcBreaks( nCalcSize
, &nMaxLineWidth
, true );
786 maFloatSizes
.reserve( nCalcLines
);
788 nTempLines
= nLines
= nCalcLines
;
791 tools::Long nHeight
= ImplCalcSize( nTempLines
, TB_CALCMODE_FLOAT
).Height();
794 aSize
.mnWidth
= nMaxLineWidth
+(TB_BORDER_OFFSET1
*2);
795 aSize
.mnHeight
= nHeight
;
796 aSize
.mnLines
= nTempLines
;
797 maFloatSizes
.push_back( aSize
);
803 nCalcSize
+= mnMaxItemWidth
;
804 nTempLines
= ImplCalcBreaks( nCalcSize
, &nMaxLineWidth
, true );
806 while ((nCalcSize
< upperBoundWidth
) && (nLines
< nTempLines
)); // implies nTempLines>1
807 if ( nTempLines
< nLines
)
813 Size
ToolBox::ImplCalcFloatSize( ImplToolItems::size_type
& rLines
)
815 ImplCalcFloatSizes();
819 rLines
= mnFloatLines
;
825 while ( i
+ 1u < maFloatSizes
.size() && rLines
< maFloatSizes
[i
].mnLines
)
830 Size
aSize( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
831 rLines
= maFloatSizes
[i
].mnLines
;
836 void ToolBox::ImplCalcMinMaxFloatSize( Size
& rMinSize
, Size
& rMaxSize
)
838 ImplCalcFloatSizes();
841 rMinSize
= Size( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
842 rMaxSize
= Size( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
843 while ( ++i
< maFloatSizes
.size() )
845 if( maFloatSizes
[i
].mnWidth
< rMinSize
.Width() )
846 rMinSize
.setWidth( maFloatSizes
[i
].mnWidth
);
847 if( maFloatSizes
[i
].mnHeight
< rMinSize
.Height() )
848 rMinSize
.setHeight( maFloatSizes
[i
].mnHeight
);
850 if( maFloatSizes
[i
].mnWidth
> rMaxSize
.Width() )
851 rMaxSize
.setWidth( maFloatSizes
[i
].mnWidth
);
852 if( maFloatSizes
[i
].mnHeight
> rMaxSize
.Height() )
853 rMaxSize
.setHeight( maFloatSizes
[i
].mnHeight
);
857 void ToolBox::ImplSetMinMaxFloatSize()
859 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
860 Size aMinSize
, aMaxSize
;
861 ImplCalcMinMaxFloatSize( aMinSize
, aMaxSize
);
864 pWrapper
->SetMinOutputSizePixel( aMinSize
);
865 pWrapper
->SetMaxOutputSizePixel( aMaxSize
);
866 pWrapper
->ShowMenuTitleButton( bool( GetMenuType() & ToolBoxMenuType::Customize
) );
870 // TODO: change SetMinOutputSizePixel to be not inline
871 SetMinOutputSizePixel( aMinSize
);
872 SetMaxOutputSizePixel( aMaxSize
);
876 ToolBox::ImplToolItems::size_type
ToolBox::ImplCalcLines( tools::Long nToolSize
) const
878 tools::Long nLineHeight
;
882 if ( mnWinHeight
> mnMaxItemHeight
)
883 nLineHeight
= mnWinHeight
;
885 nLineHeight
= mnMaxItemHeight
;
888 nLineHeight
= mnMaxItemWidth
;
890 if ( mnWinStyle
& WB_BORDER
)
891 nToolSize
-= TB_BORDER_OFFSET2
*2;
895 nLineHeight
+= TB_LINESPACING
;
896 nToolSize
+= TB_LINESPACING
;
899 // #i91917# always report at least one line
900 tools::Long nLines
= nToolSize
/nLineHeight
;
907 sal_uInt16
ToolBox::ImplTestLineSize( const Point
& rPos
) const
909 if ( !ImplIsFloatingMode() &&
910 (!mbScroll
|| (mnLines
> 1) || (mnCurLines
> mnVisLines
)) )
912 WindowAlign eAlign
= GetAlign();
914 if ( eAlign
== WindowAlign::Left
)
916 if ( rPos
.X() > mnDX
-DOCK_LINEOFFSET
)
917 return DOCK_LINEHSIZE
| DOCK_LINERIGHT
;
919 else if ( eAlign
== WindowAlign::Top
)
921 if ( rPos
.Y() > mnDY
-DOCK_LINEOFFSET
)
922 return DOCK_LINEVSIZE
| DOCK_LINEBOTTOM
;
924 else if ( eAlign
== WindowAlign::Right
)
926 if ( rPos
.X() < DOCK_LINEOFFSET
)
927 return DOCK_LINEHSIZE
| DOCK_LINELEFT
;
929 else if ( eAlign
== WindowAlign::Bottom
)
931 if ( rPos
.Y() < DOCK_LINEOFFSET
)
932 return DOCK_LINEVSIZE
| DOCK_LINETOP
;
939 void ToolBox::ImplLineSizing( const Point
& rPos
, tools::Rectangle
& rRect
, sal_uInt16 nLineMode
)
942 tools::Long nOneLineSize
;
943 tools::Long nCurSize
;
944 tools::Long nMaxSize
;
948 if ( nLineMode
& DOCK_LINERIGHT
)
950 nCurSize
= rPos
.X() - rRect
.Left();
953 else if ( nLineMode
& DOCK_LINEBOTTOM
)
955 nCurSize
= rPos
.Y() - rRect
.Top();
958 else if ( nLineMode
& DOCK_LINELEFT
)
960 nCurSize
= rRect
.Right() - rPos
.X();
963 else if ( nLineMode
& DOCK_LINETOP
)
965 nCurSize
= rRect
.Bottom() - rPos
.Y();
969 OSL_FAIL( "ImplLineSizing: Trailing else" );
974 Size aWinSize
= GetSizePixel();
975 ImplToolItems::size_type nMaxLines
= std::max(mnLines
, mnCurLines
);
976 if ( nMaxLines
> TB_MAXLINES
)
977 nMaxLines
= TB_MAXLINES
;
980 nOneLineSize
= ImplCalcSize( 1 ).Height();
982 if ( nMaxSize
< aWinSize
.Height() )
983 nMaxSize
= aWinSize
.Height();
987 nOneLineSize
= ImplCalcSize( 1 ).Width();
989 if ( nMaxSize
< aWinSize
.Width() )
990 nMaxSize
= aWinSize
.Width();
993 ImplToolItems::size_type i
= 1;
994 if ( nCurSize
<= nOneLineSize
)
995 nSize
= nOneLineSize
;
999 while ( (nSize
< nCurSize
) && (i
< nMaxLines
) )
1002 aSize
= ImplCalcSize( i
);
1004 nSize
= aSize
.Height();
1006 nSize
= aSize
.Width();
1007 if ( nSize
> nMaxSize
)
1010 aSize
= ImplCalcSize( i
);
1012 nSize
= aSize
.Height();
1014 nSize
= aSize
.Width();
1020 if ( nLineMode
& DOCK_LINERIGHT
)
1021 rRect
.SetRight( rRect
.Left()+nSize
-1 );
1022 else if ( nLineMode
& DOCK_LINEBOTTOM
)
1023 rRect
.SetBottom( rRect
.Top()+nSize
-1 );
1024 else if ( nLineMode
& DOCK_LINELEFT
)
1025 rRect
.SetLeft( rRect
.Right()-nSize
);
1027 rRect
.SetTop( rRect
.Bottom()-nSize
);
1032 ImplTBDragMgr::ImplTBDragMgr()
1033 : mpDragBox(nullptr)
1037 maAccel
.InsertItem( KEY_RETURN
, vcl::KeyCode( KEY_RETURN
) );
1038 maAccel
.InsertItem( KEY_ESCAPE
, vcl::KeyCode( KEY_ESCAPE
) );
1039 maAccel
.SetSelectHdl( LINK( this, ImplTBDragMgr
, SelectHdl
) );
1042 void ImplTBDragMgr::StartDragging( ToolBox
* pToolBox
,
1043 const Point
& rPos
, const tools::Rectangle
& rRect
,
1044 sal_uInt16 nDragLineMode
)
1046 mpDragBox
= pToolBox
;
1047 pToolBox
->CaptureMouse();
1048 pToolBox
->mbDragging
= true;
1049 Application::InsertAccel( &maAccel
);
1051 mnLineMode
= nDragLineMode
;
1052 mnStartLines
= pToolBox
->mnDockLines
;
1054 // calculate MouseOffset
1055 maMouseOff
.setX( rRect
.Left() - rPos
.X() );
1056 maMouseOff
.setY( rRect
.Top() - rPos
.Y() );
1058 maStartRect
= rRect
;
1059 pToolBox
->ShowTracking( maRect
);
1062 void ImplTBDragMgr::Dragging( const Point
& rPos
)
1064 mpDragBox
->ImplLineSizing( rPos
, maRect
, mnLineMode
);
1065 Point aOff
= mpDragBox
->OutputToScreenPixel( Point() );
1066 maRect
.Move( aOff
.X(), aOff
.Y() );
1067 mpDragBox
->Docking( rPos
, maRect
);
1068 maRect
.Move( -aOff
.X(), -aOff
.Y() );
1069 mpDragBox
->ShowTracking( maRect
);
1072 void ImplTBDragMgr::EndDragging( bool bOK
)
1074 mpDragBox
->HideTracking();
1075 if (mpDragBox
->IsMouseCaptured())
1076 mpDragBox
->ReleaseMouse();
1077 mpDragBox
->mbDragging
= false;
1078 Application::RemoveAccel( &maAccel
);
1082 mpDragBox
->mnDockLines
= mnStartLines
;
1083 mpDragBox
->EndDocking( maStartRect
, false );
1086 mpDragBox
->EndDocking( maRect
, false );
1089 mpDragBox
= nullptr;
1092 IMPL_LINK( ImplTBDragMgr
, SelectHdl
, Accelerator
&, rAccel
, void )
1094 if ( rAccel
.GetCurItemId() == KEY_ESCAPE
)
1095 EndDragging( false );
1100 void ToolBox::ImplInitToolBoxData()
1102 // initialize variables
1103 ImplGetWindowImpl()->mbToolBox
= true;
1104 mpData
.reset(new ImplToolBoxPrivateData
);
1106 mpFloatWin
= nullptr;
1110 mnMaxItemHeight
= 0;
1117 mnHighItemId
= ToolBoxItemId(0);
1118 mnCurItemId
= ToolBoxItemId(0);
1119 mnDownItemId
= ToolBoxItemId(0);
1120 mnCurPos
= ITEM_NOTFOUND
;
1127 mnMouseModifier
= 0;
1134 mbFullPaint
= false;
1137 mbLastFloatMode
= false;
1138 mbCustomize
= false;
1140 mbIsKeyEvent
= false;
1141 mbChangingHighlight
= false;
1142 mbLineSpacing
= false;
1143 mbIsArranged
= false;
1144 meButtonType
= ButtonType::SYMBOLONLY
;
1145 meAlign
= WindowAlign::Top
;
1146 meDockAlign
= WindowAlign::Top
;
1147 meLastStyle
= PointerStyle::Arrow
;
1149 meLayoutMode
= ToolBoxLayoutMode::Normal
;
1150 meTextPosition
= ToolBoxTextPosition::Right
;
1151 mnLastFocusItemId
= ToolBoxItemId(0);
1152 mnActivateCount
= 0;
1154 mpIdle
.reset(new Idle("vcl::ToolBox maIdle update"));
1155 mpIdle
->SetPriority( TaskPriority::RESIZE
);
1156 mpIdle
->SetInvokeHandler( LINK( this, ToolBox
, ImplUpdateHdl
) );
1158 // set timeout and handler for dropdown items
1159 mpData
->maDropdownTimer
.SetTimeout( 250 );
1160 mpData
->maDropdownTimer
.SetInvokeHandler( LINK( this, ToolBox
, ImplDropdownLongClickHdl
) );
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
))
1203 rRenderContext
.SetBackground();
1204 rRenderContext
.SetTextColor(rStyleSettings
.GetToolTextColor());
1205 SetPaintTransparent(true);
1206 SetParentClipMode(ParentClipMode::NoClip
);
1207 mpData
->maDisplayBackground
= Wallpaper(rStyleSettings
.GetFaceColor());
1212 if (Window::GetStyle() & WB_3DLOOK
)
1213 aColor
= rStyleSettings
.GetFaceColor();
1215 aColor
= rStyleSettings
.GetWindowColor();
1216 rRenderContext
.SetBackground(aColor
);
1217 SetPaintTransparent(false);
1218 SetParentClipMode();
1223 void ToolBox::ApplySettings(vcl::RenderContext
& rRenderContext
)
1225 mpData
->mbNativeButtons
= rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ControlPart::Button
);
1227 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
1229 ApplyControlFont(rRenderContext
, rStyleSettings
.GetToolFont());
1230 ApplyForegroundSettings(rRenderContext
, rStyleSettings
);
1231 ApplyBackgroundSettings(rRenderContext
, rStyleSettings
);
1234 void ToolBox::ImplInitSettings(bool bFont
, bool bForeground
, bool bBackground
)
1236 mpData
->mbNativeButtons
= IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
);
1238 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
1241 ApplyControlFont(*GetOutDev(), rStyleSettings
.GetToolFont());
1242 if (bForeground
|| bFont
)
1243 ApplyForegroundSettings(*GetOutDev(), rStyleSettings
);
1246 ApplyBackgroundSettings(*GetOutDev(), rStyleSettings
);
1247 EnableChildTransparentMode(IsPaintTransparent());
1251 void ToolBox::doDeferredInit(WinBits nBits
)
1253 VclPtr
<vcl::Window
> pParent
= mpDialogParent
;
1254 mpDialogParent
= nullptr;
1255 ImplInit(pParent
, nBits
);
1256 mbIsDeferredInit
= false;
1259 void ToolBox::queue_resize(StateChangedType eReason
)
1261 Window::queue_resize(eReason
);
1264 ToolBox::ToolBox( vcl::Window
* pParent
, WinBits nStyle
) :
1265 DockingWindow( WindowType::TOOLBOX
, "vcl::ToolBox maLayoutIdle" )
1267 ImplInitToolBoxData();
1268 ImplInit( pParent
, nStyle
);
1271 ToolBox::ToolBox(vcl::Window
* pParent
, const OUString
& rID
,
1272 const OUString
& rUIXMLDescription
, const css::uno::Reference
<css::frame::XFrame
> &rFrame
)
1273 : DockingWindow(WindowType::TOOLBOX
, "vcl::ToolBox maLayoutIdle")
1275 ImplInitToolBoxData();
1277 loadUI(pParent
, rID
, rUIXMLDescription
, rFrame
);
1279 // calculate size of floating windows and switch if the
1280 // toolbox is initially in floating mode
1281 if ( ImplIsFloatingMode() )
1286 if (!(GetStyle() & WB_HIDE
))
1295 void ToolBox::dispose()
1297 // #103005# make sure our activate/deactivate balance is right
1298 while( mnActivateCount
> 0 )
1301 // terminate popupmode if the floating window is
1304 mpFloatWin
->EndPopupMode( FloatWinPopupEndFlags::Cancel
);
1305 mpFloatWin
= nullptr;
1307 // delete private data
1310 ImplSVData
* pSVData
= ImplGetSVData();
1311 delete pSVData
->maCtrlData
.mpTBDragMgr
;
1312 pSVData
->maCtrlData
.mpTBDragMgr
= nullptr;
1318 DockingWindow::dispose();
1321 ImplToolItem
* ToolBox::ImplGetItem( ToolBoxItemId nItemId
) const
1326 for (auto & item
: mpData
->m_aItems
)
1328 if ( item
.mnId
== nItemId
)
1335 static void ImplAddButtonBorder( tools::Long
&rWidth
, tools::Long
& rHeight
, bool bNativeButtons
)
1337 rWidth
+= SMALLBUTTON_HSIZE
;
1338 rHeight
+= SMALLBUTTON_VSIZE
;
1340 if( bNativeButtons
)
1342 // give more border space for rounded buttons
1348 bool ToolBox::ImplCalcItem()
1350 // recalc required ?
1354 OutputDevice
*pDefault
= Application::GetDefaultDevice();
1355 float fScaleFactor
= pDefault
? pDefault
->GetDPIScaleFactor() : 1.0;
1357 tools::Long nDefWidth
;
1358 tools::Long nDefHeight
;
1359 tools::Long nMaxWidth
= 0;
1360 tools::Long nMaxHeight
= 0;
1361 tools::Long nMinWidth
= 6;
1362 tools::Long nMinHeight
= 6;
1363 tools::Long nDropDownArrowWidth
= TB_DROPDOWNARROWWIDTH
* fScaleFactor
;
1365 nDropDownArrowWidth
*= 3;
1368 // set defaults if image or text is needed but empty
1369 nDefWidth
= GetDefaultImageSize().Width();
1370 nDefHeight
= GetDefaultImageSize().Height();
1373 // determine minimum size necessary in NWF
1375 tools::Rectangle
aRect( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1376 tools::Rectangle
aReg( aRect
);
1377 ImplControlValue aVal
;
1378 tools::Rectangle aNativeBounds
, aNativeContent
;
1379 if( IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
) )
1381 if( GetNativeControlRegion( ControlType::Toolbar
, ControlPart::Button
,
1383 ControlState::ENABLED
| ControlState::ROLLOVER
,
1385 aNativeBounds
, aNativeContent
) )
1387 aRect
= aNativeBounds
;
1388 if( aRect
.GetWidth() > nMinWidth
)
1389 nMinWidth
= aRect
.GetWidth();
1390 if( aRect
.GetHeight() > nMinHeight
)
1391 nMinHeight
= aRect
.GetHeight();
1392 if( nDropDownArrowWidth
< nMinWidth
)
1393 nDropDownArrowWidth
= nMinWidth
;
1394 if( nMinWidth
> mpData
->mnMenuButtonWidth
)
1395 mpData
->mnMenuButtonWidth
= nMinWidth
;
1396 else if( nMinWidth
< TB_MENUBUTTON_SIZE
)
1397 mpData
->mnMenuButtonWidth
= TB_MENUBUTTON_SIZE
;
1401 // also calculate the area for comboboxes, drop down list boxes and spinfields
1402 // as these are often inserted into toolboxes; set mnWinHeight to the
1403 // greater of those values to prevent toolbar flickering (#i103385#)
1404 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1406 if( GetNativeControlRegion( ControlType::Combobox
, ControlPart::Entire
,
1408 ControlState::ENABLED
| ControlState::ROLLOVER
,
1410 aNativeBounds
, aNativeContent
) )
1412 aRect
= aNativeBounds
;
1413 if( aRect
.GetHeight() > mnWinHeight
)
1414 mnWinHeight
= aRect
.GetHeight();
1416 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1418 if( GetNativeControlRegion( ControlType::Listbox
, ControlPart::Entire
,
1420 ControlState::ENABLED
| ControlState::ROLLOVER
,
1422 aNativeBounds
, aNativeContent
) )
1424 aRect
= aNativeBounds
;
1425 if( aRect
.GetHeight() > mnWinHeight
)
1426 mnWinHeight
= aRect
.GetHeight();
1428 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1430 if( GetNativeControlRegion( ControlType::Spinbox
, ControlPart::Entire
,
1432 ControlState::ENABLED
| ControlState::ROLLOVER
,
1434 aNativeBounds
, aNativeContent
) )
1436 aRect
= aNativeBounds
;
1437 if( aRect
.GetHeight() > mnWinHeight
)
1438 mnWinHeight
= aRect
.GetHeight();
1442 if ( ! mpData
->m_aItems
.empty() )
1444 for (auto & item
: mpData
->m_aItems
)
1446 item
.mbVisibleText
= false; // indicates if text will definitely be drawn, influences dropdown pos
1448 if ( item
.meType
== ToolBoxItemType::BUTTON
)
1453 // check if image and/or text exists
1454 bImage
= !!item
.maImage
;
1455 bText
= !item
.maText
.isEmpty();
1456 ButtonType tmpButtonType
= determineButtonType( &item
, meButtonType
); // default to toolbox setting
1457 if ( bImage
|| bText
)
1460 item
.mbEmptyBtn
= false;
1462 if ( tmpButtonType
== ButtonType::SYMBOLONLY
)
1464 // we're drawing images only
1465 if ( bImage
|| !bText
)
1467 item
.maItemSize
= item
.maImage
.GetSizePixel();
1471 item
.maItemSize
= Size( GetOutDev()->GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
,
1473 item
.mbVisibleText
= true;
1476 else if ( tmpButtonType
== ButtonType::TEXT
)
1478 // we're drawing text only
1479 if ( bText
|| !bImage
)
1481 item
.maItemSize
= Size( GetOutDev()->GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
,
1483 item
.mbVisibleText
= true;
1487 item
.maItemSize
= item
.maImage
.GetSizePixel();
1492 // we're drawing images and text
1493 item
.maItemSize
.setWidth( bText
? GetOutDev()->GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
: 0 );
1494 item
.maItemSize
.setHeight( bText
? GetTextHeight() : 0 );
1496 if ( meTextPosition
== ToolBoxTextPosition::Right
)
1498 // leave space between image and text
1500 item
.maItemSize
.AdjustWidth(TB_IMAGETEXTOFFSET
);
1502 // image and text side by side
1503 item
.maItemSize
.AdjustWidth(item
.maImage
.GetSizePixel().Width() );
1504 if ( item
.maImage
.GetSizePixel().Height() > item
.maItemSize
.Height() )
1505 item
.maItemSize
.setHeight( item
.maImage
.GetSizePixel().Height() );
1509 // leave space between image and text
1511 item
.maItemSize
.AdjustHeight(TB_IMAGETEXTOFFSET
);
1514 item
.maItemSize
.AdjustHeight(item
.maImage
.GetSizePixel().Height() );
1515 if ( item
.maImage
.GetSizePixel().Width() > item
.maItemSize
.Width() )
1516 item
.maItemSize
.setWidth( item
.maImage
.GetSizePixel().Width() );
1519 item
.mbVisibleText
= bText
;
1523 { // no image and no text
1524 item
.maItemSize
= Size( nDefWidth
, nDefHeight
);
1525 item
.mbEmptyBtn
= true;
1528 // save the content size
1529 item
.maContentSize
= item
.maItemSize
;
1531 // if required, take window height into consideration
1532 if ( item
.mpWindow
)
1534 tools::Long nHeight
= item
.mpWindow
->GetSizePixel().Height();
1535 if ( nHeight
> mnWinHeight
)
1536 mnWinHeight
= nHeight
;
1539 // add in drop down arrow
1540 if( item
.mnBits
& ToolBoxItemBits::DROPDOWN
)
1542 item
.maItemSize
.AdjustWidth(nDropDownArrowWidth
);
1543 item
.mnDropDownArrowWidth
= nDropDownArrowWidth
;
1546 // text items will be rotated in vertical mode
1547 // -> swap width and height
1548 if( item
.mbVisibleText
&& !mbHorz
)
1550 tools::Long tmp
= item
.maItemSize
.Width();
1551 item
.maItemSize
.setWidth( item
.maItemSize
.Height() );
1552 item
.maItemSize
.setHeight( tmp
);
1554 tmp
= item
.maContentSize
.Width();
1555 item
.maContentSize
.setWidth( item
.maContentSize
.Height() );
1556 item
.maContentSize
.setHeight( tmp
);
1559 else if ( item
.meType
== ToolBoxItemType::SPACE
)
1561 item
.maItemSize
= Size( nDefWidth
, nDefHeight
);
1562 item
.maContentSize
= item
.maItemSize
;
1565 if ( item
.meType
== ToolBoxItemType::BUTTON
|| item
.meType
== ToolBoxItemType::SPACE
)
1568 tools::Long w
= item
.maItemSize
.Width();
1569 tools::Long h
= item
.maItemSize
.Height();
1570 ImplAddButtonBorder( w
, h
, mpData
->mbNativeButtons
);
1571 item
.maItemSize
.setWidth(w
);
1572 item
.maItemSize
.setHeight(h
);
1574 if( item
.meType
== ToolBoxItemType::BUTTON
)
1576 tools::Long nMinW
= std::max(nMinWidth
, item
.maMinimalItemSize
.Width());
1577 tools::Long nMinH
= std::max(nMinHeight
, item
.maMinimalItemSize
.Height());
1579 tools::Long nGrowContentWidth
= 0;
1580 tools::Long nGrowContentHeight
= 0;
1582 if( item
.maItemSize
.Width() < nMinW
)
1584 nGrowContentWidth
= nMinW
- item
.maItemSize
.Width();
1585 item
.maItemSize
.setWidth( nMinW
);
1587 if( item
.maItemSize
.Height() < nMinH
)
1589 nGrowContentHeight
= nMinH
- item
.maItemSize
.Height();
1590 item
.maItemSize
.setHeight( nMinH
);
1593 // grow the content size by the additional available space
1594 item
.maContentSize
.AdjustWidth(nGrowContentWidth
);
1595 item
.maContentSize
.AdjustHeight(nGrowContentHeight
);
1598 // keep track of max item size
1599 if ( item
.maItemSize
.Width() > nMaxWidth
)
1600 nMaxWidth
= item
.maItemSize
.Width();
1601 if ( item
.maItemSize
.Height() > nMaxHeight
)
1602 nMaxHeight
= item
.maItemSize
.Height();
1608 nMaxWidth
= nDefWidth
;
1609 nMaxHeight
= nDefHeight
;
1611 ImplAddButtonBorder( nMaxWidth
, nMaxHeight
, mpData
->mbNativeButtons
);
1614 if( !ImplIsFloatingMode() && GetToolboxButtonSize() != ToolBoxButtonSize::DontCare
1615 && ( meTextPosition
== ToolBoxTextPosition::Right
) )
1617 // make sure all vertical toolbars have the same width and horizontal have the same height
1618 // this depends on the used button sizes
1619 // as this is used for alignment of multiple toolbars
1620 // it is only required for docked toolbars
1622 tools::Long nFixedWidth
= nDefWidth
+nDropDownArrowWidth
;
1623 tools::Long nFixedHeight
= nDefHeight
;
1624 ImplAddButtonBorder( nFixedWidth
, nFixedHeight
, mpData
->mbNativeButtons
);
1627 nMaxHeight
= nFixedHeight
;
1629 nMaxWidth
= nFixedWidth
;
1635 // do we have to recalc the sizes ?
1636 if ( (nMaxWidth
!= mnMaxItemWidth
) || (nMaxHeight
!= mnMaxItemHeight
) )
1638 mnMaxItemWidth
= nMaxWidth
;
1639 mnMaxItemHeight
= nMaxHeight
;
1647 ToolBox::ImplToolItems::size_type
ToolBox::ImplCalcBreaks( tools::Long nWidth
, sal_Int32
* pMaxLineWidth
, bool bCalcHorz
) const
1649 sal_uLong nLineStart
= 0;
1650 sal_uLong nGroupStart
= 0;
1651 tools::Long nLineWidth
= 0;
1652 tools::Long nCurWidth
;
1653 tools::Long nLastGroupLineWidth
= 0;
1654 tools::Long nMaxLineWidth
= 0;
1655 ImplToolItems::size_type nLines
= 1;
1657 bool bBreak
= false;
1658 tools::Long nWidthTotal
= nWidth
;
1659 tools::Long nMenuWidth
= 0;
1661 // when docked the menubutton will be in the first line
1662 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1663 nMenuWidth
= mpData
->maMenubuttonItem
.maItemSize
.Width();
1665 // we need to know which item is the last visible one to be able to add
1666 // the menu width in case we are unable to show all the items
1667 ImplToolItems::iterator it
, lastVisible
;
1668 for ( it
= mpData
->m_aItems
.begin(); it
!= mpData
->m_aItems
.end(); ++it
)
1670 if ( it
->mbVisible
)
1674 it
= mpData
->m_aItems
.begin();
1675 while ( it
!= mpData
->m_aItems
.end() )
1677 it
->mbBreak
= bBreak
;
1680 if ( it
->mbVisible
)
1686 if ( it
->meType
== ToolBoxItemType::BUTTON
|| it
->meType
== ToolBoxItemType::SPACE
)
1689 nCurWidth
= it
->maItemSize
.Width();
1691 nCurWidth
= it
->maItemSize
.Height();
1693 if ( it
->mpWindow
&& bCalcHorz
)
1695 tools::Long nWinItemWidth
= it
->mpWindow
->GetSizePixel().Width();
1696 if ( !mbScroll
|| (nWinItemWidth
<= nWidthTotal
) )
1698 nCurWidth
= nWinItemWidth
;
1703 if ( it
->mbEmptyBtn
)
1710 // in case we are able to show all the items, we do not want
1711 // to show the toolbar's menu; otherwise yes
1712 if ( ( ( it
== lastVisible
) && (nLineWidth
+nCurWidth
> nWidthTotal
) && mbScroll
) ||
1713 ( ( it
!= lastVisible
) && (nLineWidth
+nCurWidth
+nMenuWidth
> nWidthTotal
) && mbScroll
) )
1716 else if ( it
->meType
== ToolBoxItemType::SEPARATOR
)
1718 nCurWidth
= it
->mnSepSize
;
1719 if ( !ImplIsFloatingMode() && ( it
!= lastVisible
) && (nLineWidth
+nCurWidth
+nMenuWidth
> nWidthTotal
) )
1722 // treat breaks as separators, except when using old style toolbars (ie. no menu button)
1723 else if ( (it
->meType
== ToolBoxItemType::BREAK
) && !IsMenuEnabled() )
1730 // Add break before the entire group or take group apart?
1731 if ( (it
->meType
== ToolBoxItemType::BREAK
) ||
1732 (nLineStart
== nGroupStart
) )
1734 if ( nLineWidth
> nMaxLineWidth
)
1735 nMaxLineWidth
= nLineWidth
;
1738 nLineStart
= it
- mpData
->m_aItems
.begin();
1739 nGroupStart
= nLineStart
;
1745 if ( nLastGroupLineWidth
> nMaxLineWidth
)
1746 nMaxLineWidth
= nLastGroupLineWidth
;
1748 // if the break is added before the group, set it to
1749 // beginning of line and re-calculate
1751 nLineStart
= nGroupStart
;
1752 it
= mpData
->m_aItems
.begin() + nGroupStart
;
1758 if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
1760 if ( (it
->meType
!= ToolBoxItemType::BUTTON
) || bWindow
)
1762 // found separator or break
1763 nLastGroupLineWidth
= nLineWidth
;
1764 nGroupStart
= it
- mpData
->m_aItems
.begin();
1771 nLineWidth
+= nCurWidth
;
1777 if ( pMaxLineWidth
)
1779 if ( nLineWidth
> nMaxLineWidth
)
1780 nMaxLineWidth
= nLineWidth
;
1782 if( ImplIsFloatingMode() && !ImplIsInPopupMode() )
1784 // leave enough space to display buttons in the decoration
1785 tools::Long aMinWidth
= 2 * GetSettings().GetStyleSettings().GetFloatTitleHeight();
1786 if( nMaxLineWidth
< aMinWidth
)
1787 nMaxLineWidth
= aMinWidth
;
1789 *pMaxLineWidth
= nMaxLineWidth
;
1795 Size
ToolBox::ImplGetOptimalFloatingSize()
1797 if( !ImplIsFloatingMode() )
1800 Size
aCurrentSize( mnDX
, mnDY
);
1801 Size
aSize1( aCurrentSize
);
1802 Size
aSize2( aCurrentSize
);
1804 // try to preserve current height
1806 // calc number of floating lines for current window height
1807 ImplToolItems::size_type nFloatLinesHeight
= ImplCalcLines( mnDY
);
1808 // calc window size according to this number
1809 aSize1
= ImplCalcFloatSize( nFloatLinesHeight
);
1811 if( aCurrentSize
== aSize1
)
1814 // try to preserve current width
1816 tools::Long nLineHeight
= std::max( mnWinHeight
, mnMaxItemHeight
);
1817 int nBorderX
= 2*TB_BORDER_OFFSET1
+ mnLeftBorder
+ mnRightBorder
;
1818 int nBorderY
= 2*TB_BORDER_OFFSET2
+ mnTopBorder
+ mnBottomBorder
;
1819 Size
aSz( aCurrentSize
);
1821 ImplToolItems::size_type nLines
= ImplCalcBreaks( aSz
.Width()-nBorderX
, &maxX
, mbHorz
);
1823 ImplToolItems::size_type manyLines
= 1000;
1824 Size aMinimalFloatSize
= ImplCalcFloatSize( manyLines
);
1826 aSz
.setHeight( nBorderY
+ nLineHeight
* nLines
);
1827 // line space when more than one line
1828 if ( mbLineSpacing
)
1829 aSz
.AdjustHeight((nLines
-1)*TB_LINESPACING
);
1831 aSz
.setWidth( nBorderX
+ maxX
);
1833 // avoid clipping of any items
1834 if( aSz
.Width() < aMinimalFloatSize
.Width() )
1835 aSize2
= ImplCalcFloatSize( nLines
);
1839 if( aCurrentSize
== aSize2
)
1842 // set the size with the smallest delta as the current size
1843 tools::Long dx1
= std::abs( mnDX
- aSize1
.Width() );
1844 tools::Long dy1
= std::abs( mnDY
- aSize1
.Height() );
1846 tools::Long dx2
= std::abs( mnDX
- aSize2
.Width() );
1847 tools::Long dy2
= std::abs( mnDY
- aSize2
.Height() );
1849 if( dx1
*dy1
< dx2
*dy2
)
1850 aCurrentSize
= aSize1
;
1852 aCurrentSize
= aSize2
;
1854 return aCurrentSize
;
1859 void lcl_hideDoubleSeparators( ToolBox::ImplToolItems
& rItems
)
1861 bool bLastSep( true );
1862 ToolBox::ImplToolItems::iterator it
;
1863 for ( it
= rItems
.begin(); it
!= rItems
.end(); ++it
)
1865 if ( it
->meType
== ToolBoxItemType::SEPARATOR
)
1867 it
->mbVisible
= false;
1870 // check if any visible items have to appear behind it
1871 if (std::any_of(it
+ 1, rItems
.end(), [](const ImplToolItem
& rItem
) {
1872 return (rItem
.meType
== ToolBoxItemType::BUTTON
) && rItem
.mbVisible
; }))
1873 it
->mbVisible
= true;
1877 else if ( it
->mbVisible
)
1883 void ToolBox::ImplFormat( bool bResize
)
1885 // Has to re-formatted
1889 mpData
->ImplClearLayoutData();
1891 // recalculate positions and sizes
1892 tools::Rectangle aEmptyRect
;
1893 tools::Long nLineSize
;
1896 tools::Long nMax
; // width of layoutarea in pixels
1897 ImplToolItems::size_type nFormatLine
;
1898 bool bMustFullPaint
;
1900 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
1901 bool bIsInPopupMode
= ImplIsInPopupMode();
1903 maFloatSizes
.clear();
1905 // compute border sizes
1906 ImplCalcBorder( meAlign
, mnLeftBorder
, mnTopBorder
, mnRightBorder
, mnBottomBorder
);
1908 // update drag area (where the 'grip' will be placed)
1909 tools::Rectangle aOldDragRect
;
1911 aOldDragRect
= pWrapper
->GetDragArea();
1912 ImplUpdateDragArea();
1914 bMustFullPaint
= ImplCalcItem();
1916 // calculate new size during interactive resize or
1917 // set computed size when formatting only
1918 if ( ImplIsFloatingMode() )
1921 mnFloatLines
= ImplCalcLines( mnDY
);
1923 SetOutputSizePixel( ImplGetOptimalFloatingSize() );
1929 tools::Long nBottom
;
1930 // nLineSize: height of a single line, will fit highest item
1931 nLineSize
= mnMaxItemHeight
;
1933 if ( mnWinHeight
> mnMaxItemHeight
)
1934 nLineSize
= mnWinHeight
;
1939 mnVisLines
= ImplCalcLines( mnDY
);
1943 // layout over all lines
1944 mnVisLines
= mnLines
;
1945 nMax
= TB_MAXNOSCROLL
;
1948 // add in all border offsets
1949 if ( mnWinStyle
& WB_BORDER
)
1951 nLeft
= TB_BORDER_OFFSET1
+ mnLeftBorder
;
1952 nTop
= TB_BORDER_OFFSET2
+ mnTopBorder
;
1953 nBottom
= TB_BORDER_OFFSET1
+ mnBottomBorder
;
1954 nMax
-= nLeft
+ TB_BORDER_OFFSET1
+ mnRightBorder
;
1963 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
1964 // we have to center all items in the window height
1965 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1967 tools::Long nWinHeight
= mnDY
- nTop
- nBottom
;
1968 if( nWinHeight
> nLineSize
)
1969 nLineSize
= nWinHeight
;
1975 nLineSize
= mnMaxItemWidth
;
1979 mnVisLines
= ImplCalcLines( mnDX
);
1984 mnVisLines
= mnLines
;
1985 nMax
= TB_MAXNOSCROLL
;
1988 if ( mnWinStyle
& WB_BORDER
)
1990 nTop
= TB_BORDER_OFFSET1
+ mnTopBorder
;
1991 nLeft
= TB_BORDER_OFFSET2
+ mnLeftBorder
;
1992 nRight
= TB_BORDER_OFFSET2
+ mnRightBorder
;
1993 nMax
-= nTop
+ TB_BORDER_OFFSET1
+ mnBottomBorder
;
2002 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
2003 // we have to center all items in the window height
2004 if( !ImplIsFloatingMode() && IsMenuEnabled() )
2006 tools::Long nWinWidth
= mnDX
- nLeft
- nRight
;
2007 if( nWinWidth
> nLineSize
)
2008 nLineSize
= nWinWidth
;
2012 // no calculation if the window has no size (nMax=0)
2013 // non scrolling toolboxes must be computed though
2014 if ( (nMax
<= 0) && mbScroll
)
2020 for (auto & item
: mpData
->m_aItems
)
2022 item
.maRect
= aEmptyRect
;
2025 maLowerRect
= aEmptyRect
;
2026 maUpperRect
= aEmptyRect
;
2030 // init start values
2031 tools::Long nX
= nLeft
; // top-left offset
2032 tools::Long nY
= nTop
;
2035 // save old scroll rectangles and reset them
2036 tools::Rectangle aOldLowerRect
= maLowerRect
;
2037 tools::Rectangle aOldUpperRect
= maUpperRect
;
2038 tools::Rectangle aOldMenubuttonRect
= mpData
->maMenubuttonItem
.maRect
;
2039 maUpperRect
= aEmptyRect
;
2040 maLowerRect
= aEmptyRect
;
2041 mpData
->maMenubuttonItem
.maRect
= aEmptyRect
;
2043 // do we have any toolbox items at all ?
2044 if ( !mpData
->m_aItems
.empty() || IsMenuEnabled() )
2046 lcl_hideDoubleSeparators( mpData
->m_aItems
);
2048 // compute line breaks and visible lines give the current window width (nMax)
2049 // the break indicators will be stored within each item (it->mbBreak)
2050 mnCurLines
= ImplCalcBreaks( nMax
, nullptr, mbHorz
);
2052 // check for scrollbar buttons or dropdown menu
2053 // (if a menu is enabled, this will be used to store clipped
2054 // items and no scroll buttons will appear)
2055 if ( (!ImplIsFloatingMode() && (mnCurLines
> mnVisLines
) && mbScroll
) ||
2058 // compute linebreaks again, incorporating scrollbar buttons
2059 if( !IsMenuEnabled() )
2061 nMax
-= TB_SPIN_SIZE
+TB_SPIN_OFFSET
;
2062 mnCurLines
= ImplCalcBreaks( nMax
, nullptr, mbHorz
);
2065 // compute scroll rectangles or menu button
2068 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2070 if( !ImplIsFloatingMode() )
2072 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
- 2 );
2073 mpData
->maMenubuttonItem
.maRect
.SetTop( nTop
);
2074 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2078 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
- mnRightBorder
-TB_BORDER_OFFSET1
-1 );
2079 mpData
->maMenubuttonItem
.maRect
.SetTop( nTop
);
2080 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2082 mpData
->maMenubuttonItem
.maRect
.SetLeft( mpData
->maMenubuttonItem
.maRect
.Right() - mpData
->mnMenuButtonWidth
);
2086 maUpperRect
.SetLeft( nLeft
+nMax
+TB_SPIN_OFFSET
);
2087 maUpperRect
.SetRight( maUpperRect
.Left()+TB_SPIN_SIZE
-1 );
2088 maUpperRect
.SetTop( nTop
);
2089 maLowerRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2090 maLowerRect
.SetLeft( maUpperRect
.Left() );
2091 maLowerRect
.SetRight( maUpperRect
.Right() );
2092 maUpperRect
.SetBottom( maUpperRect
.Top() +
2093 (maLowerRect
.Bottom()-maUpperRect
.Top())/2 );
2094 maLowerRect
.SetTop( maUpperRect
.Bottom() );
2099 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2101 if( !ImplIsFloatingMode() )
2103 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
- 2 );
2104 mpData
->maMenubuttonItem
.maRect
.SetLeft( nLeft
);
2105 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2109 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
- mnBottomBorder
-TB_BORDER_OFFSET1
-1 );
2110 mpData
->maMenubuttonItem
.maRect
.SetLeft( nLeft
);
2111 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2113 mpData
->maMenubuttonItem
.maRect
.SetTop( mpData
->maMenubuttonItem
.maRect
.Bottom() - mpData
->mnMenuButtonWidth
);
2117 maUpperRect
.SetTop( nTop
+nMax
+TB_SPIN_OFFSET
);
2118 maUpperRect
.SetBottom( maUpperRect
.Top()+TB_SPIN_SIZE
-1 );
2119 maUpperRect
.SetLeft( nLeft
);
2120 maLowerRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2121 maLowerRect
.SetTop( maUpperRect
.Top() );
2122 maLowerRect
.SetBottom( maUpperRect
.Bottom() );
2123 maUpperRect
.SetRight( maUpperRect
.Left() +
2124 (maLowerRect
.Right()-maUpperRect
.Left())/2 );
2125 maLowerRect
.SetLeft( maUpperRect
.Right() );
2130 // no scrolling when there is a "more"-menu
2131 // anything will "fit" in a single line then
2132 if( IsMenuEnabled() )
2135 // determine the currently visible line
2136 if ( mnVisLines
>= mnCurLines
)
2138 else if ( mnCurLine
+mnVisLines
-1 > mnCurLines
)
2139 mnCurLine
= mnCurLines
- (mnVisLines
-1);
2141 tools::Long firstItemCenter
= 0;
2142 for (auto & item
: mpData
->m_aItems
)
2144 item
.mbShowWindow
= false;
2146 // check for line break and advance nX/nY accordingly
2151 // increment starting with the second line
2152 if ( nFormatLine
> mnCurLine
)
2157 if ( mbLineSpacing
)
2158 nY
+= nLineSize
+TB_LINESPACING
;
2165 if ( mbLineSpacing
)
2166 nX
+= nLineSize
+TB_LINESPACING
;
2173 if ( !item
.mbVisible
|| (nFormatLine
< mnCurLine
) ||
2174 (nFormatLine
> mnCurLine
+mnVisLines
-1) )
2175 // item is not visible
2176 item
.maCalcRect
= aEmptyRect
;
2179 // 1. determine current item width/height
2180 // take window size and orientation into account, because this affects the size of item windows
2182 Size
aCurrentItemSize( item
.GetSize( mbHorz
, mbScroll
, nMax
, Size(mnMaxItemWidth
, mnMaxItemHeight
) ) );
2184 // 2. position item rect and use size from step 1
2185 // items will be centered horizontally (if mbHorz) or vertically
2186 // advance nX and nY accordingly
2190 // In special mode Locked horizontal positions of all items remain unchanged.
2192 if ( mbIsArranged
&& meLayoutMode
== ToolBoxLayoutMode::Locked
&& mnLines
== 1 && item
.maRect
.Left() > 0 )
2193 nX
= item
.maRect
.Left();
2194 item
.maCalcRect
.SetLeft( nX
);
2196 // In special mode Locked first item's vertical position remains unchanged. Consecutive items vertical
2197 // positions are centered around first item's vertical position. If an item's height exceeds available
2198 // space, item's vertical position remains unchanged too.
2200 if ( mbIsArranged
&& meLayoutMode
== ToolBoxLayoutMode::Locked
&& mnLines
== 1 )
2201 if ( firstItemCenter
> 0 )
2202 if ( firstItemCenter
-aCurrentItemSize
.Height()/2 > nY
)
2203 item
.maCalcRect
.SetTop( firstItemCenter
-aCurrentItemSize
.Height()/2 );
2205 item
.maCalcRect
.SetTop( item
.maRect
.Top() );
2208 item
.maCalcRect
.SetTop( item
.maRect
.Top() );
2209 firstItemCenter
= item
.maRect
.Top()+aCurrentItemSize
.Height()/2;
2212 item
.maCalcRect
.SetTop( nY
+(nLineSize
-aCurrentItemSize
.Height())/2 );
2213 item
.maCalcRect
.SetRight( nX
+aCurrentItemSize
.Width()-1 );
2214 item
.maCalcRect
.SetBottom( item
.maCalcRect
.Top()+aCurrentItemSize
.Height()-1 );
2215 nX
+= aCurrentItemSize
.Width();
2219 item
.maCalcRect
.SetLeft( nX
+(nLineSize
-aCurrentItemSize
.Width())/2 );
2220 item
.maCalcRect
.SetTop( nY
);
2221 item
.maCalcRect
.SetRight( item
.maCalcRect
.Left()+aCurrentItemSize
.Width()-1 );
2222 item
.maCalcRect
.SetBottom( nY
+aCurrentItemSize
.Height()-1 );
2223 nY
+= aCurrentItemSize
.Height();
2227 // position window items into calculated item rect
2228 if ( item
.mpWindow
)
2230 if ( item
.mbShowWindow
)
2232 Point
aPos( item
.maCalcRect
.Left(), item
.maCalcRect
.Top() );
2234 assert( item
.maCalcRect
.Top() >= 0 );
2236 item
.mpWindow
->SetPosPixel( aPos
);
2237 item
.mpWindow
->Show();
2240 item
.mpWindow
->Hide();
2242 } // end of loop over all items
2243 mbIsArranged
= true;
2246 // we have no toolbox items
2249 if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2251 // custom menu will be the last button in floating mode
2252 ImplToolItem
&rIt
= mpData
->maMenubuttonItem
;
2256 rIt
.maRect
.SetLeft( nX
+TB_MENUBUTTON_OFFSET
);
2257 rIt
.maRect
.SetTop( nY
);
2258 rIt
.maRect
.SetRight( rIt
.maRect
.Left() + mpData
->mnMenuButtonWidth
);
2259 rIt
.maRect
.SetBottom( nY
+nLineSize
-1 );
2260 nX
+= rIt
.maItemSize
.Width();
2264 rIt
.maRect
.SetLeft( nX
);
2265 rIt
.maRect
.SetTop( nY
+TB_MENUBUTTON_OFFSET
);
2266 rIt
.maRect
.SetRight( nX
+nLineSize
-1 );
2267 rIt
.maRect
.SetBottom( rIt
.maRect
.Top() + mpData
->mnMenuButtonWidth
);
2268 nY
+= rIt
.maItemSize
.Height();
2272 // if toolbox visible trigger paint for changed regions
2273 if ( IsVisible() && !mbFullPaint
)
2275 if ( bMustFullPaint
)
2277 maPaintRect
= tools::Rectangle( mnLeftBorder
, mnTopBorder
,
2278 mnDX
-mnRightBorder
, mnDY
-mnBottomBorder
);
2282 if ( aOldLowerRect
!= maLowerRect
)
2284 maPaintRect
.Union( maLowerRect
);
2285 maPaintRect
.Union( aOldLowerRect
);
2287 if ( aOldUpperRect
!= maUpperRect
)
2289 maPaintRect
.Union( maUpperRect
);
2290 maPaintRect
.Union( aOldUpperRect
);
2292 if ( aOldMenubuttonRect
!= mpData
->maMenubuttonItem
.maRect
)
2294 maPaintRect
.Union( mpData
->maMenubuttonItem
.maRect
);
2295 maPaintRect
.Union( aOldMenubuttonRect
);
2297 if ( pWrapper
&& aOldDragRect
!= pWrapper
->GetDragArea() )
2299 maPaintRect
.Union( pWrapper
->GetDragArea() );
2300 maPaintRect
.Union( aOldDragRect
);
2303 for (auto const& item
: mpData
->m_aItems
)
2305 if ( item
.maRect
!= item
.maCalcRect
)
2307 maPaintRect
.Union( item
.maRect
);
2308 maPaintRect
.Union( item
.maCalcRect
);
2313 Invalidate( maPaintRect
);
2316 // store the new calculated item rects
2317 maPaintRect
= aEmptyRect
;
2318 for (auto & item
: mpData
->m_aItems
)
2319 item
.maRect
= item
.maCalcRect
;
2322 // indicate formatting is done
2326 IMPL_LINK_NOARG(ToolBox
, ImplDropdownLongClickHdl
, Timer
*, void)
2328 if (mnCurPos
== ITEM_NOTFOUND
||
2329 !(mpData
->m_aItems
[ mnCurPos
].mnBits
& ToolBoxItemBits::DROPDOWN
))
2332 mpData
->mbDropDownByKeyboard
= false;
2333 mpData
->maDropdownClickHdl
.Call( this );
2335 // do not reset data if the dropdown handler opened a floating window
2336 // see ImplFloatControl()
2339 // no floater was opened
2341 InvalidateItem(mnCurPos
);
2343 mnCurPos
= ITEM_NOTFOUND
;
2344 mnCurItemId
= ToolBoxItemId(0);
2345 mnDownItemId
= ToolBoxItemId(0);
2346 mnMouseModifier
= 0;
2347 mnHighItemId
= ToolBoxItemId(0);
2351 IMPL_LINK_NOARG(ToolBox
, ImplUpdateHdl
, Timer
*, void)
2354 if( mbFormat
&& mpData
)
2358 static void ImplDrawMoreIndicator(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
2360 const Image
pImage(StockImage::Yes
, CHEVRON
);
2361 Size aImageSize
= pImage
.GetSizePixel();
2362 tools::Long x
= rRect
.Left() + (rRect
.getOpenWidth() - aImageSize
.Width())/2;
2363 tools::Long y
= rRect
.Top() + (rRect
.getOpenHeight() - aImageSize
.Height())/2;
2364 DrawImageFlags nImageStyle
= DrawImageFlags::NONE
;
2366 rRenderContext
.DrawImage(Point(x
,y
), pImage
, nImageStyle
);
2369 static void ImplDrawDropdownArrow(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rDropDownRect
, bool bSetColor
, bool bRotate
)
2371 bool bLineColor
= rRenderContext
.IsLineColor();
2372 bool bFillColor
= rRenderContext
.IsFillColor();
2373 Color aOldFillColor
= rRenderContext
.GetFillColor();
2374 Color aOldLineColor
= rRenderContext
.GetLineColor();
2375 rRenderContext
.SetLineColor();
2379 if (rRenderContext
.GetSettings().GetStyleSettings().GetFaceColor().IsDark())
2380 rRenderContext
.SetFillColor(COL_WHITE
);
2382 rRenderContext
.SetFillColor(COL_BLACK
);
2385 tools::Polygon
aPoly(4);
2387 // the assumption is, that the width always specifies the size of the expected arrow.
2388 const tools::Long nMargin
= round(2 * rRenderContext
.GetDPIScaleFactor());
2389 const tools::Long nSize
= rDropDownRect
.getOpenWidth() - 2 * nMargin
;
2390 const tools::Long nHalfSize
= (nSize
+ 1) / 2;
2391 const tools::Long x
= rDropDownRect
.Left() + nMargin
+ (bRotate
? (rDropDownRect
.getOpenWidth() - nHalfSize
) / 2 : 0);
2392 const tools::Long y
= rDropDownRect
.Top() + nMargin
+ (rDropDownRect
.getOpenHeight() - (bRotate
? nSize
: nHalfSize
)) / 2;
2394 aPoly
.SetPoint(Point(x
, y
), 0);
2397 aPoly
.SetPoint(Point(x
, y
+ nSize
), 1);
2398 aPoly
.SetPoint(Point(x
+ nHalfSize
, y
+ nHalfSize
), 2);
2402 aPoly
.SetPoint(Point(x
+ nHalfSize
, y
+ nHalfSize
), 1);
2403 aPoly
.SetPoint(Point(x
+ nSize
, y
), 2);
2405 aPoly
.SetPoint(Point(x
, y
), 3);
2407 auto aaflags
= rRenderContext
.GetAntialiasing();
2408 rRenderContext
.SetAntialiasing(AntialiasingFlags::Enable
);
2409 rRenderContext
.DrawPolygon( aPoly
);
2410 rRenderContext
.SetAntialiasing(aaflags
);
2413 rRenderContext
.SetFillColor(aOldFillColor
);
2415 rRenderContext
.SetFillColor();
2417 rRenderContext
.SetLineColor(aOldLineColor
);
2419 rRenderContext
.SetLineColor();
2422 void ToolBox::ImplDrawMenuButton(vcl::RenderContext
& rRenderContext
, bool bHighlight
)
2424 if (mpData
->maMenubuttonItem
.maRect
.IsEmpty())
2427 // #i53937# paint menu button only if necessary
2428 if (!ImplHasClippedItems())
2431 // execute pending paint requests
2434 rRenderContext
.Push(vcl::PushFlags::FILLCOLOR
| vcl::PushFlags::LINECOLOR
);
2436 // draw the 'more' indicator / button (>>)
2437 ImplErase(rRenderContext
, mpData
->maMenubuttonItem
.maRect
, bHighlight
);
2440 ImplDrawButton(rRenderContext
, mpData
->maMenubuttonItem
.maRect
, 2, false, true, false );
2442 if (ImplHasClippedItems())
2443 ImplDrawMoreIndicator(rRenderContext
, mpData
->maMenubuttonItem
.maRect
);
2445 // store highlight state
2446 mpData
->mbMenubuttonSelected
= bHighlight
;
2449 rRenderContext
.Pop();
2452 void ToolBox::ImplDrawSpin(vcl::RenderContext
& rRenderContext
)
2457 if ( maUpperRect
.IsEmpty() || maLowerRect
.IsEmpty() )
2460 bTmpUpper
= mnCurLine
> 1;
2462 bTmpLower
= mnCurLine
+mnVisLines
-1 < mnCurLines
;
2470 ImplDrawUpDownButtons(rRenderContext
, maUpperRect
, maLowerRect
,
2471 false/*bUpperIn*/, false/*bLowerIn*/, bTmpUpper
, bTmpLower
, !mbHorz
);
2474 void ToolBox::ImplDrawSeparator(vcl::RenderContext
& rRenderContext
, ImplToolItems::size_type nPos
, const tools::Rectangle
& rRect
)
2476 if ( nPos
>= mpData
->m_aItems
.size() - 1 )
2477 // no separator if it's the last item
2480 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPos
];
2481 ImplToolItem
* pPreviousItem
= &mpData
->m_aItems
[nPos
-1];
2482 ImplToolItem
* pNextItem
= &mpData
->m_aItems
[nPos
+1];
2484 if ( ( pPreviousItem
->mbShowWindow
&& pNextItem
->mbShowWindow
) || pNextItem
->mbBreak
)
2485 // no separator between two windows or before a break
2488 bool bNativeOk
= false;
2489 ControlPart nPart
= IsHorizontal() ? ControlPart::SeparatorVert
: ControlPart::SeparatorHorz
;
2490 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, nPart
))
2492 ImplControlValue aControlValue
;
2493 bNativeOk
= rRenderContext
.DrawNativeControl(ControlType::Toolbar
, nPart
, rRect
, ControlState::NONE
, aControlValue
, OUString());
2496 /* Draw the widget only if it can't be drawn natively. */
2500 tools::Long nCenterPos
, nSlim
;
2501 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
2502 rRenderContext
.SetLineColor(rStyleSettings
.GetSeparatorColor());
2505 nSlim
= (pItem
->maRect
.Bottom() - pItem
->maRect
.Top ()) / 4;
2506 nCenterPos
= pItem
->maRect
.Center().X();
2507 rRenderContext
.DrawLine(Point(nCenterPos
, pItem
->maRect
.Top() + nSlim
),
2508 Point(nCenterPos
, pItem
->maRect
.Bottom() - nSlim
));
2512 nSlim
= (pItem
->maRect
.Right() - pItem
->maRect
.Left ()) / 4;
2513 nCenterPos
= pItem
->maRect
.Center().Y();
2514 rRenderContext
.DrawLine(Point(pItem
->maRect
.Left() + nSlim
, nCenterPos
),
2515 Point(pItem
->maRect
.Right() - nSlim
, nCenterPos
));
2519 void ToolBox::ImplDrawButton(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&rRect
, sal_uInt16 highlight
,
2520 bool bChecked
, bool bEnabled
, bool bIsWindow
)
2522 // draws toolbar button background either native or using a coloured selection
2523 // if bIsWindow is true, the corresponding item is a control and only a selection border will be drawn
2525 bool bNativeOk
= false;
2526 if( !bIsWindow
&& rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
) )
2528 ImplControlValue aControlValue
;
2529 ControlState nState
= ControlState::NONE
;
2531 if ( highlight
== 1 ) nState
|= ControlState::PRESSED
;
2532 if ( highlight
== 2 ) nState
|= ControlState::ROLLOVER
;
2533 if ( bEnabled
) nState
|= ControlState::ENABLED
;
2535 aControlValue
.setTristateVal( bChecked
? ButtonValue::On
: ButtonValue::Off
);
2537 bNativeOk
= rRenderContext
.DrawNativeControl( ControlType::Toolbar
, ControlPart::Button
,
2538 rRect
, nState
, aControlValue
, OUString() );
2542 vcl::RenderTools::DrawSelectionBackground(rRenderContext
, *this, rRect
, bIsWindow
? 3 : highlight
,
2543 bChecked
, true, bIsWindow
, nullptr, 2);
2546 void ToolBox::ImplDrawItem(vcl::RenderContext
& rRenderContext
, ImplToolItems::size_type nPos
, sal_uInt16 nHighlight
)
2548 if (nPos
>= mpData
->m_aItems
.size())
2551 // execute pending paint requests
2554 rRenderContext
.SetFillColor();
2556 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPos
];
2558 if (!pItem
->mbEnabled
)
2561 // if the rectangle is outside visible area
2562 if (pItem
->maRect
.IsEmpty())
2565 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
2567 // no gradient background for items that have a popup open
2568 bool bHasOpenPopup
= mpFloatWin
&& (mnDownItemId
==pItem
->mnId
);
2570 bool bHighContrastWhite
= false;
2571 // check the face color as highcontrast indicator
2572 // because the toolbox itself might have a gradient
2573 if (rStyleSettings
.GetFaceColor() == COL_WHITE
)
2574 bHighContrastWhite
= true;
2576 // Compute buttons area.
2577 Size aBtnSize
= pItem
->maRect
.GetSize();
2579 /* Compute the button/separator rectangle here, we'll need it for
2580 * both the buttons and the separators. */
2581 tools::Rectangle
aButtonRect( pItem
->maRect
.TopLeft(), aBtnSize
);
2582 tools::Long nOffX
= SMALLBUTTON_OFF_NORMAL_X
;
2583 tools::Long nOffY
= SMALLBUTTON_OFF_NORMAL_Y
;
2584 tools::Long nImageOffX
= 0;
2585 tools::Long nImageOffY
= 0;
2586 DrawButtonFlags nStyle
= DrawButtonFlags::NONE
;
2589 if ( (pItem
->meType
== ToolBoxItemType::SEPARATOR
) && nPos
> 0 )
2591 ImplDrawSeparator(rRenderContext
, nPos
, aButtonRect
);
2594 // do nothing if item is no button or will be displayed as window
2595 if ( (pItem
->meType
!= ToolBoxItemType::BUTTON
) || pItem
->mbShowWindow
)
2598 if ( pItem
->meState
== TRISTATE_TRUE
)
2600 nStyle
|= DrawButtonFlags::Checked
;
2602 else if ( pItem
->meState
== TRISTATE_INDET
)
2604 nStyle
|= DrawButtonFlags::DontKnow
;
2606 if ( nHighlight
== 1 )
2608 nStyle
|= DrawButtonFlags::Pressed
;
2611 ImplErase(rRenderContext
, pItem
->maRect
, nHighlight
!= 0, bHasOpenPopup
);
2613 nOffX
+= pItem
->maRect
.Left();
2614 nOffY
+= pItem
->maRect
.Top();
2616 // determine what has to be drawn on the button: image, text or both
2619 ButtonType tmpButtonType
= determineButtonType( pItem
, meButtonType
); // default to toolbox setting
2620 pItem
->DetermineButtonDrawStyle( tmpButtonType
, bImage
, bText
);
2622 // compute output values
2623 tools::Long nBtnWidth
= aBtnSize
.Width()-SMALLBUTTON_HSIZE
;
2624 tools::Long nBtnHeight
= aBtnSize
.Height()-SMALLBUTTON_VSIZE
;
2627 const bool bDropDown
= (pItem
->mnBits
& ToolBoxItemBits::DROPDOWN
) == ToolBoxItemBits::DROPDOWN
;
2628 tools::Rectangle aDropDownRect
;
2630 aDropDownRect
= pItem
->GetDropDownRect(mbHorz
);
2634 const Image
* pImage
= &(pItem
->maImage
);
2635 aImageSize
= pImage
->GetSizePixel();
2637 // determine drawing flags
2638 DrawImageFlags nImageStyle
= DrawImageFlags::NONE
;
2640 if ( !pItem
->mbEnabled
|| !IsEnabled() )
2641 nImageStyle
|= DrawImageFlags::Disable
;
2643 // #i35563# the dontknow state indicates different states at the same time
2644 // which should not be rendered disabled but normal
2649 if ( ( (pItem
->mnBits
& (ToolBoxItemBits::LEFT
|ToolBoxItemBits::DROPDOWN
)) || bText
)
2650 && ( meTextPosition
== ToolBoxTextPosition::Right
) )
2652 // left align also to leave space for drop down arrow
2653 // and when drawing text+image
2654 // just center in y, except for vertical (ie rotated text)
2655 if( mbHorz
|| !bText
)
2656 nImageOffY
+= (nBtnHeight
-aImageSize
.Height())/2;
2660 nImageOffX
+= (nBtnWidth
-(bDropDown
? aDropDownRect
.getOpenWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X
-aImageSize
.Width())/2;
2661 if ( meTextPosition
== ToolBoxTextPosition::Right
)
2662 nImageOffY
+= (nBtnHeight
-aImageSize
.Height())/2;
2664 if ( nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) )
2667 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2669 ImplDrawButton(rRenderContext
, aButtonRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2670 pItem
->mbEnabled
&& IsEnabled(), pItem
->mbShowWindow
);
2672 if( nHighlight
!= 0 )
2674 if( bHighContrastWhite
)
2675 nImageStyle
|= DrawImageFlags::ColorTransform
;
2678 rRenderContext
.DrawImage(Point( nImageOffX
, nImageOffY
), *pImage
, nImageStyle
);
2682 bool bRotate
= false;
2685 const Size
aTxtSize(GetOutDev()->GetCtrlTextWidth(pItem
->maText
), GetTextHeight());
2686 tools::Long nTextOffX
= nOffX
;
2687 tools::Long nTextOffY
= nOffY
;
2689 // rotate text when vertically docked
2690 vcl::Font aOldFont
= rRenderContext
.GetFont();
2691 if( pItem
->mbVisibleText
&& !ImplIsFloatingMode() &&
2692 ((meAlign
== WindowAlign::Left
) || (meAlign
== WindowAlign::Right
)) )
2696 vcl::Font aRotateFont
= aOldFont
;
2697 aRotateFont
.SetOrientation( 2700_deg10
);
2699 // center horizontally
2700 nTextOffX
+= aTxtSize
.Height();
2701 nTextOffX
+= (nBtnWidth
-aTxtSize
.Height())/2;
2703 // add in image offset
2705 nTextOffY
= nImageOffY
+ aImageSize
.Height() + TB_IMAGETEXTOFFSET
;
2707 rRenderContext
.SetFont(aRotateFont
);
2711 if ( meTextPosition
== ToolBoxTextPosition::Right
)
2713 // center vertically
2714 nTextOffY
+= (nBtnHeight
-aTxtSize
.Height())/2;
2716 // add in image offset
2718 nTextOffX
= nImageOffX
+ aImageSize
.Width() + TB_IMAGETEXTOFFSET
;
2722 // center horizontally
2723 nTextOffX
+= (nBtnWidth
-(bDropDown
? aDropDownRect
.getOpenWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X
-aTxtSize
.Width() - TB_IMAGETEXTOFFSET
)/2;
2724 // set vertical position
2725 nTextOffY
+= nBtnHeight
- aTxtSize
.Height();
2729 // draw selection only if not already drawn during image output (see above)
2730 if ( !bImage
&& (nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) ) )
2733 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2735 ImplDrawButton(rRenderContext
, pItem
->maRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2736 pItem
->mbEnabled
&& IsEnabled(), pItem
->mbShowWindow
);
2739 DrawTextFlags nTextStyle
= DrawTextFlags::NONE
;
2740 if ( !pItem
->mbEnabled
)
2741 nTextStyle
|= DrawTextFlags::Disable
;
2742 rRenderContext
.DrawCtrlText( Point( nTextOffX
, nTextOffY
), pItem
->maText
,
2743 0, pItem
->maText
.getLength(), nTextStyle
);
2745 SetFont( aOldFont
);
2748 // paint optional drop down arrow
2752 bool bSetColor
= true;
2753 if ( !pItem
->mbEnabled
|| !IsEnabled() )
2756 rRenderContext
.SetFillColor(rStyleSettings
.GetShadowColor());
2759 // dropdown only will be painted without inner border
2760 if( (pItem
->mnBits
& ToolBoxItemBits::DROPDOWNONLY
) != ToolBoxItemBits::DROPDOWNONLY
)
2762 ImplErase(rRenderContext
, aDropDownRect
, nHighlight
!= 0, bHasOpenPopup
);
2764 if( nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) )
2767 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2769 ImplDrawButton(rRenderContext
, aDropDownRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2770 pItem
->mbEnabled
&& IsEnabled(), false);
2773 ImplDrawDropdownArrow(rRenderContext
, aDropDownRect
, bSetColor
, bRotate
);
2776 void ToolBox::ImplDrawFloatwinBorder(vcl::RenderContext
& rRenderContext
, ImplToolItem
const * pItem
)
2778 if ( pItem
->maRect
.IsEmpty() )
2781 rRenderContext
.SetLineColor(rRenderContext
.GetSettings().GetStyleSettings().GetShadowColor());
2784 p1
= pItem
->maRect
.TopLeft();
2786 p2
= pItem
->maRect
.TopRight();
2788 rRenderContext
.DrawLine( p1
, p2
);
2789 p1
= pItem
->maRect
.BottomLeft();
2791 p2
= pItem
->maRect
.BottomRight();
2793 rRenderContext
.DrawLine( p1
, p2
);
2795 p1
= pItem
->maRect
.TopLeft();
2797 p2
= pItem
->maRect
.BottomLeft();
2799 rRenderContext
.DrawLine( p1
, p2
);
2800 p1
= pItem
->maRect
.TopRight();
2802 p2
= pItem
->maRect
.BottomRight();
2804 rRenderContext
.DrawLine( p1
, p2
);
2808 void ToolBox::ImplFloatControl( bool bStart
, FloatingWindow
* pFloatWindow
)
2813 mpFloatWin
= pFloatWindow
;
2815 // redraw item, to trigger drawing of a special border
2816 InvalidateItem(mnCurPos
);
2820 if (IsMouseCaptured())
2825 mpFloatWin
= nullptr;
2827 // if focus is still in this toolbox, then the floater was opened by keyboard
2828 // draw current item with highlight and keep old state
2829 bool bWasKeyboardActivate
= mpData
->mbDropDownByKeyboard
;
2831 if ( mnCurPos
!= ITEM_NOTFOUND
)
2832 InvalidateItem(mnCurPos
);
2835 if( !bWasKeyboardActivate
)
2837 mnCurPos
= ITEM_NOTFOUND
;
2838 mnCurItemId
= ToolBoxItemId(0);
2839 mnHighItemId
= ToolBoxItemId(0);
2841 mnDownItemId
= ToolBoxItemId(0);
2846 void ToolBox::ShowLine( bool bNext
)
2858 bool ToolBox::ImplHandleMouseMove( const MouseEvent
& rMEvt
, bool bRepeat
)
2860 Point aMousePos
= rMEvt
.GetPosPixel();
2866 if ( mbDrag
&& mnCurPos
!= ITEM_NOTFOUND
)
2868 // is the cursor over the item?
2869 ImplToolItem
* pItem
= &mpData
->m_aItems
[mnCurPos
];
2870 if ( pItem
->maRect
.Contains( aMousePos
) )
2874 InvalidateItem(mnCurPos
);
2875 mnCurItemId
= pItem
->mnId
;
2879 if ( (pItem
->mnBits
& ToolBoxItemBits::REPEAT
) && bRepeat
)
2886 InvalidateItem(mnCurPos
);
2887 mnCurItemId
= ToolBoxItemId(0);
2888 InvalidateItem(mnCurPos
);
2898 bool bNewIn
= maUpperRect
.Contains( aMousePos
);
2899 if ( bNewIn
!= mbIn
)
2902 InvalidateSpin(true, false);
2909 bool bNewIn
= maLowerRect
.Contains( aMousePos
);
2910 if ( bNewIn
!= mbIn
)
2913 InvalidateSpin(false);
2921 bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent
& rMEvt
, bool bCancel
)
2926 // stop eventual running dropdown timer
2927 if( mnCurPos
< mpData
->m_aItems
.size() &&
2928 (mpData
->m_aItems
[mnCurPos
].mnBits
& ToolBoxItemBits::DROPDOWN
) )
2930 mpData
->maDropdownTimer
.Stop();
2941 if ( mnCurPos
== ITEM_NOTFOUND
)
2945 // has mouse been released on top of item?
2946 if( mnCurPos
< mpData
->m_aItems
.size() )
2948 ImplToolItem
* pItem
= &mpData
->m_aItems
[mnCurPos
];
2949 if ( pItem
->maRect
.Contains( rMEvt
.GetPosPixel() ) )
2951 mnCurItemId
= pItem
->mnId
;
2954 // execute AutoCheck if required
2955 if ( pItem
->mnBits
& ToolBoxItemBits::AUTOCHECK
)
2957 if ( pItem
->mnBits
& ToolBoxItemBits::RADIOCHECK
)
2959 if ( pItem
->meState
!= TRISTATE_TRUE
)
2960 SetItemState( pItem
->mnId
, TRISTATE_TRUE
);
2964 if ( pItem
->meState
!= TRISTATE_TRUE
)
2965 pItem
->meState
= TRISTATE_TRUE
;
2967 pItem
->meState
= TRISTATE_FALSE
;
2971 // do not call Select when Repeat is active, as in this
2972 // case that was triggered already in MouseButtonDown
2973 if ( !(pItem
->mnBits
& ToolBoxItemBits::REPEAT
) )
2975 // prevent from being destroyed in the select handler
2976 VclPtr
<vcl::Window
> xWindow
= this;
2978 if ( xWindow
->isDisposed() )
2986 // Items not destroyed, in Select handler
2989 // Get current pos for the case that items are inserted/removed
2991 mnCurPos
= GetItemPos( mnCurItemId
);
2992 if ( mnCurPos
!= ITEM_NOTFOUND
)
2994 InvalidateItem(mnCurPos
);
2995 GetOutDev()->Flush();
3001 mnCurPos
= ITEM_NOTFOUND
;
3002 mnCurItemId
= ToolBoxItemId(0);
3003 mnDownItemId
= ToolBoxItemId(0);
3004 mnMouseModifier
= 0;
3007 else if ( mbUpper
|| mbLower
)
3010 ShowLine( !mbUpper
);
3021 void ToolBox::MouseMove( const MouseEvent
& rMEvt
)
3023 // pressing a modifier generates synthetic mouse moves
3024 // ignore it if keyboard selection is active
3025 if( HasFocus() && ( rMEvt
.GetMode() & MouseEventModifiers::MODIFIERCHANGED
) )
3028 if ( ImplHandleMouseMove( rMEvt
) )
3031 Point aMousePos
= rMEvt
.GetPosPixel();
3033 // only highlight when the focus is not inside a child window of a toolbox
3034 // eg, in an edit control
3035 // and do not highlight when focus is in a different toolbox
3036 bool bDrawHotSpot
= true;
3037 vcl::Window
*pFocusWin
= Application::GetFocusWindow();
3039 bool bFocusWindowIsAToolBoxChild
= false;
3042 vcl::Window
*pWin
= pFocusWin
->GetParent();
3045 if(pWin
->ImplGetWindowImpl() && pWin
->ImplGetWindowImpl()->mbToolBox
)
3047 bFocusWindowIsAToolBoxChild
= true;
3050 pWin
= pWin
->GetParent();
3054 if( bFocusWindowIsAToolBoxChild
|| (pFocusWin
&& pFocusWin
->ImplGetWindowImpl() && pFocusWin
->ImplGetWindowImpl()->mbToolBox
&& pFocusWin
!= this) )
3055 bDrawHotSpot
= false;
3059 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3060 pMgr
->Dragging( aMousePos
);
3064 PointerStyle eStyle
= PointerStyle::Arrow
;
3066 // change mouse cursor over drag area
3067 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
3068 if( pWrapper
&& pWrapper
->GetDragArea().Contains( rMEvt
.GetPosPixel() ) )
3069 eStyle
= PointerStyle::Move
;
3071 if ( (mnWinStyle
& TB_WBLINESIZING
) == TB_WBLINESIZING
)
3073 if ( rMEvt
.GetMode() & MouseEventModifiers::SIMPLEMOVE
)
3075 sal_uInt16 nLinePtr
= ImplTestLineSize( rMEvt
.GetPosPixel() );
3076 if ( nLinePtr
& DOCK_LINEHSIZE
)
3078 if ( meAlign
== WindowAlign::Left
)
3079 eStyle
= PointerStyle::WindowESize
;
3081 eStyle
= PointerStyle::WindowWSize
;
3083 else if ( nLinePtr
& DOCK_LINEVSIZE
)
3085 if ( meAlign
== WindowAlign::Top
)
3086 eStyle
= PointerStyle::WindowSSize
;
3088 eStyle
= PointerStyle::WindowNSize
;
3095 bool bClearHigh
= true;
3096 if ( !rMEvt
.IsLeaveWindow() && (mnCurPos
== ITEM_NOTFOUND
) )
3098 ImplToolItems::size_type nTempPos
= 0;
3099 for (auto const& item
: mpData
->m_aItems
)
3101 if ( item
.maRect
.Contains( aMousePos
) )
3103 if ( (item
.meType
== ToolBoxItemType::BUTTON
) && item
.mbEnabled
)
3106 if ( mnHighItemId
!= item
.mnId
)
3111 ImplToolItems::size_type nPos
= GetItemPos( mnHighItemId
);
3112 InvalidateItem(nPos
);
3113 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nPos
) );
3115 if ( mpData
->mbMenubuttonSelected
)
3117 // remove highlight from menubutton
3118 InvalidateMenuButton();
3120 mnHighItemId
= item
.mnId
;
3121 InvalidateItem(nTempPos
);
3123 CallEventListeners( VclEventId::ToolboxHighlight
);
3132 // only clear highlight when focus is not in toolbar
3133 bool bMenuButtonHit
= mpData
->maMenubuttonItem
.maRect
.Contains( aMousePos
) && ImplHasClippedItems();
3134 if ( !HasFocus() && (bClearHigh
|| bMenuButtonHit
) )
3136 if ( !bMenuButtonHit
&& mpData
->mbMenubuttonSelected
)
3138 // remove highlight from menubutton
3139 InvalidateMenuButton();
3144 ImplToolItems::size_type nClearPos
= GetItemPos( mnHighItemId
);
3145 if ( nClearPos
!= ITEM_NOTFOUND
)
3147 InvalidateItem(nClearPos
);
3148 if( nClearPos
!= mnCurPos
)
3149 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nClearPos
) );
3152 mnHighItemId
= ToolBoxItemId(0);
3155 if( bMenuButtonHit
)
3157 InvalidateMenuButton();
3162 if ( meLastStyle
!= eStyle
)
3164 meLastStyle
= eStyle
;
3165 SetPointer( eStyle
);
3168 DockingWindow::MouseMove( rMEvt
);
3171 void ToolBox::MouseButtonDown( const MouseEvent
& rMEvt
)
3173 // only trigger toolbox for left mouse button and when
3174 // we're not in normal operation
3175 if ( rMEvt
.IsLeft() && !mbDrag
&& (mnCurPos
== ITEM_NOTFOUND
) )
3177 // call activate already here, as items could
3181 // update ToolBox here, such that user knows it
3188 Point aMousePos
= rMEvt
.GetPosPixel();
3189 ImplToolItems::size_type i
= 0;
3190 ImplToolItems::size_type nNewPos
= ITEM_NOTFOUND
;
3192 // search for item that was clicked
3193 for (auto const& item
: mpData
->m_aItems
)
3195 // is this the item?
3196 if ( item
.maRect
.Contains( aMousePos
) )
3198 // do nothing if it is a separator or
3199 // if the item has been disabled
3200 if ( (item
.meType
== ToolBoxItemType::BUTTON
) &&
3201 !item
.mbShowWindow
)
3211 if ( nNewPos
!= ITEM_NOTFOUND
)
3213 if ( !mpData
->m_aItems
[nNewPos
].mbEnabled
)
3219 // update actual data
3220 StartTrackingFlags nTrackFlags
= StartTrackingFlags::NONE
;
3222 mnCurItemId
= mpData
->m_aItems
[nNewPos
].mnId
;
3223 mnDownItemId
= mnCurItemId
;
3224 mnMouseModifier
= rMEvt
.GetModifier();
3225 if ( mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::REPEAT
)
3226 nTrackFlags
|= StartTrackingFlags::ButtonRepeat
;
3228 // update bDrag here, as it is evaluated in the EndSelection
3231 // on double-click: only call the handler, but do so before the button
3232 // is hit, as in the handler dragging
3233 // can be terminated
3234 if ( rMEvt
.GetClicks() == 2 )
3239 InvalidateItem(mnCurPos
);
3243 // was dropdown arrow pressed
3244 if( mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::DROPDOWN
)
3246 if( ( (mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::DROPDOWNONLY
) == ToolBoxItemBits::DROPDOWNONLY
)
3247 || mpData
->m_aItems
[nNewPos
].GetDropDownRect( mbHorz
).Contains( aMousePos
))
3249 // dropdownonly always triggers the dropdown handler, over the whole button area
3251 // the drop down arrow should not trigger the item action
3252 mpData
->mbDropDownByKeyboard
= false;
3253 mpData
->maDropdownClickHdl
.Call( this );
3255 // do not reset data if the dropdown handler opened a floating window
3256 // see ImplFloatControl()
3259 // no floater was opened
3261 InvalidateItem(mnCurPos
);
3263 mnCurPos
= ITEM_NOTFOUND
;
3264 mnCurItemId
= ToolBoxItemId(0);
3265 mnDownItemId
= ToolBoxItemId(0);
3266 mnMouseModifier
= 0;
3267 mnHighItemId
= ToolBoxItemId(0);
3271 else // activate long click timer
3272 mpData
->maDropdownTimer
.Start();
3275 // call Click handler
3276 if ( rMEvt
.GetClicks() != 2 )
3279 // also call Select handler at repeat
3280 if ( nTrackFlags
& StartTrackingFlags::ButtonRepeat
)
3283 // if the actions was not aborted in Click handler
3285 StartTracking( nTrackFlags
);
3287 // if mouse was clicked over an item we
3294 // menu button hit ?
3295 if( mpData
->maMenubuttonItem
.maRect
.Contains( aMousePos
) && ImplHasClippedItems() )
3297 if ( maMenuButtonHdl
.IsSet() )
3298 maMenuButtonHdl
.Call( this );
3300 ExecuteCustomMenu( mpData
->maMenubuttonItem
.maRect
);
3304 // check scroll- and next-buttons here
3305 if ( maUpperRect
.Contains( aMousePos
) )
3307 if ( mnCurLine
> 1 )
3312 InvalidateSpin(true, false);
3316 if ( maLowerRect
.Contains( aMousePos
) )
3318 if ( mnCurLine
+mnVisLines
-1 < mnCurLines
)
3323 InvalidateSpin(false);
3328 // Linesizing testen
3329 if ( (mnWinStyle
& TB_WBLINESIZING
) == TB_WBLINESIZING
)
3331 sal_uInt16 nLineMode
= ImplTestLineSize( aMousePos
);
3334 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3336 // call handler, such that we can set the
3340 Point aPos
= GetParent()->OutputToScreenPixel( GetPosPixel() );
3341 Size aSize
= GetSizePixel();
3342 aPos
= ScreenToOutputPixel( aPos
);
3345 pMgr
->StartDragging( this, aMousePos
, tools::Rectangle( aPos
, aSize
),
3351 // no item, then only click or double click
3352 if ( rMEvt
.GetClicks() == 2 )
3358 if ( !mbDrag
&& (mnCurPos
== ITEM_NOTFOUND
) )
3359 DockingWindow::MouseButtonDown( rMEvt
);
3362 void ToolBox::MouseButtonUp( const MouseEvent
& rMEvt
)
3364 if ( ImplHandleMouseButtonUp( rMEvt
) )
3367 if ( mbDragging
&& rMEvt
.IsLeft() )
3369 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3370 pMgr
->EndDragging();
3374 DockingWindow::MouseButtonUp( rMEvt
);
3377 void ToolBox::Tracking( const TrackingEvent
& rTEvt
)
3379 VclPtr
<vcl::Window
> xWindow
= this;
3381 if ( rTEvt
.IsTrackingEnded() )
3382 ImplHandleMouseButtonUp( rTEvt
.GetMouseEvent(), rTEvt
.IsTrackingCanceled() );
3384 ImplHandleMouseMove( rTEvt
.GetMouseEvent(), rTEvt
.IsTrackingRepeat() );
3386 if ( xWindow
->isDisposed() )
3387 // toolbox was deleted
3389 DockingWindow::Tracking( rTEvt
);
3392 void ToolBox::InvalidateItem(ImplToolItems::size_type nPosition
)
3394 if (mpData
&& nPosition
< mpData
->m_aItems
.size())
3396 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPosition
];
3397 Invalidate(pItem
->maRect
);
3401 void ToolBox::InvalidateMenuButton()
3403 if (!mpData
->maMenubuttonItem
.maRect
.IsEmpty())
3404 Invalidate(mpData
->maMenubuttonItem
.maRect
);
3407 void ToolBox::InvalidateSpin(bool bUpperIn
, bool bLowerIn
)
3409 if (bUpperIn
&& !maUpperRect
.IsEmpty())
3410 Invalidate(maUpperRect
);
3412 if (bLowerIn
&& !maLowerRect
.IsEmpty())
3413 Invalidate(maLowerRect
);
3416 void ToolBox::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rPaintRect
)
3418 if( mpData
->mbIsPaintLocked
)
3421 if (rPaintRect
== tools::Rectangle(0, 0, mnDX
-1, mnDY
-1))
3424 mbFullPaint
= false;
3426 ImplDrawBackground(rRenderContext
, rPaintRect
);
3428 if ( (mnWinStyle
& WB_BORDER
) && !ImplIsFloatingMode() )
3429 ImplDrawBorder(rRenderContext
);
3431 if( !ImplIsFloatingMode() )
3432 ImplDrawGrip(rRenderContext
);
3434 ImplDrawMenuButton(rRenderContext
, mpData
->mbMenubuttonSelected
);
3437 if (mnWinStyle
& WB_SCROLL
)
3439 if (mnCurLines
> mnLines
)
3440 ImplDrawSpin(rRenderContext
);
3444 ImplToolItems::size_type nHighPos
;
3446 nHighPos
= GetItemPos( mnHighItemId
);
3448 nHighPos
= ITEM_NOTFOUND
;
3450 ImplToolItems::size_type nCount
= mpData
->m_aItems
.size();
3451 for( ImplToolItems::size_type i
= 0; i
< nCount
; i
++ )
3453 ImplToolItem
* pItem
= &mpData
->m_aItems
[i
];
3455 // only draw when the rectangle is in the draw rectangle
3456 if ( !pItem
->maRect
.IsEmpty() && rPaintRect
.Overlaps( pItem
->maRect
) )
3458 sal_uInt16 nHighlight
= 0;
3459 if ( i
== mnCurPos
)
3461 else if ( i
== nHighPos
)
3463 ImplDrawItem(rRenderContext
, i
, nHighlight
);
3469 void ToolBox::Resize()
3471 Size aSize
= GetOutputSizePixel();
3472 // #i31422# some WindowManagers send (0,0) sizes when
3473 // switching virtual desktops - ignore this and avoid reformatting
3474 if( !aSize
.Width() && !aSize
.Height() )
3477 tools::Long nOldDX
= mnDX
;
3478 tools::Long nOldDY
= mnDY
;
3479 mnDX
= aSize
.Width();
3480 mnDY
= aSize
.Height();
3484 // invalidate everything to have gradient backgrounds properly drawn
3487 // If we have any expandable entries, then force a reformat first using
3488 // their optimal sizes, then share out the excess space evenly across those
3489 // expandables and reformat again
3490 std::vector
<size_t> aExpandables
;
3491 for (size_t i
= 0; i
< mpData
->m_aItems
.size(); ++i
)
3493 if (mpData
->m_aItems
[i
].mbExpand
)
3495 vcl::Window
*pWindow
= mpData
->m_aItems
[i
].mpWindow
;
3496 SAL_INFO_IF(!pWindow
, "vcl.layout", "only tabitems with window supported at the moment");
3499 Size
aWinSize(pWindow
->GetSizePixel());
3500 Size
aPrefSize(pWindow
->get_preferred_size());
3501 aWinSize
.setWidth( aPrefSize
.Width() );
3502 pWindow
->SetSizePixel(aWinSize
);
3503 aExpandables
.push_back(i
);
3507 // re-format or re-draw
3508 if ( mbScroll
|| !aExpandables
.empty() )
3510 if ( !mbFormat
|| !aExpandables
.empty() )
3513 if( IsReallyVisible() || !aExpandables
.empty() )
3517 if (!aExpandables
.empty())
3519 //Get how big the optimal size is
3520 tools::Rectangle aBounds
;
3521 for (const ImplToolItem
& rItem
: mpData
->m_aItems
)
3523 aBounds
.Union( rItem
.maRect
);
3526 auto nOptimalWidth
= aBounds
.GetWidth();
3527 auto nDiff
= aSize
.Width() - nOptimalWidth
;
3528 decltype(nDiff
) nExpandablesSize
= aExpandables
.size();
3529 nDiff
/= nExpandablesSize
;
3531 //share out the diff from optimal to real across
3532 //expandable entries
3533 for (size_t nIndex
: aExpandables
)
3535 vcl::Window
*pWindow
= mpData
->m_aItems
[nIndex
].mpWindow
;
3536 Size
aWinSize(pWindow
->GetSizePixel());
3537 Size
aPrefSize(pWindow
->get_preferred_size());
3538 aWinSize
.setWidth( aPrefSize
.Width() + nDiff
);
3539 pWindow
->SetSizePixel(aWinSize
);
3542 //now reformat with final sizes
3551 if ( !(mnWinStyle
& WB_BORDER
) )
3554 // as otherwise, when painting we might think we have to re-draw everything
3555 if ( mbFormat
&& IsReallyVisible() )
3559 if ( mnRightBorder
)
3561 if ( nOldDX
> mnDX
)
3562 Invalidate( tools::Rectangle( mnDX
-mnRightBorder
-1, 0, mnDX
, mnDY
) );
3564 Invalidate( tools::Rectangle( nOldDX
-mnRightBorder
-1, 0, nOldDX
, nOldDY
) );
3567 if ( mnBottomBorder
)
3569 if ( nOldDY
> mnDY
)
3570 Invalidate( tools::Rectangle( 0, mnDY
-mnBottomBorder
-1, mnDX
, mnDY
) );
3572 Invalidate( tools::Rectangle( 0, nOldDY
-mnBottomBorder
-1, nOldDX
, nOldDY
) );
3579 bool DispatchableCommand(std::u16string_view rName
)
3581 return o3tl::starts_with(rName
, u
".uno") ||
3582 o3tl::starts_with(rName
, u
"slot:") ||
3583 o3tl::starts_with(rName
, u
"macro:") ||
3584 o3tl::starts_with(rName
, u
"vnd.sun.star.script");
3588 const OUString
& ToolBox::ImplGetHelpText( ToolBoxItemId nItemId
) const
3590 ImplToolItem
* pItem
= ImplGetItem( nItemId
);
3594 if ( pItem
->maHelpText
.isEmpty() && ( !pItem
->maHelpId
.isEmpty() || pItem
->maCommandStr
.getLength() ))
3596 Help
* pHelp
= Application::GetHelp();
3599 if (DispatchableCommand(pItem
->maCommandStr
))
3600 pItem
->maHelpText
= pHelp
->GetHelpText( pItem
->maCommandStr
);
3601 if ( pItem
->maHelpText
.isEmpty() && !pItem
->maHelpId
.isEmpty() )
3602 pItem
->maHelpText
= pHelp
->GetHelpText( pItem
->maHelpId
);
3606 return pItem
->maHelpText
;
3609 void ToolBox::RequestHelp( const HelpEvent
& rHEvt
)
3611 ToolBoxItemId nItemId
;
3614 if( !rHEvt
.KeyboardActivated() )
3616 nItemId
= GetItemId( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ) );
3617 aHelpPos
= rHEvt
.GetMousePosPixel();
3624 nItemId
= mnHighItemId
;
3625 tools::Rectangle
aRect( GetItemRect( nItemId
) );
3626 if( aRect
.IsEmpty() )
3629 aHelpPos
= OutputToScreenPixel( aRect
.Center() );
3634 if ( rHEvt
.GetMode() & (HelpEventMode::BALLOON
| HelpEventMode::QUICK
) )
3637 tools::Rectangle aTempRect
= GetItemRect( nItemId
);
3638 Point aPt
= OutputToScreenPixel( aTempRect
.TopLeft() );
3639 aTempRect
.SetLeft( aPt
.X() );
3640 aTempRect
.SetTop( aPt
.Y() );
3641 aPt
= OutputToScreenPixel( aTempRect
.BottomRight() );
3642 aTempRect
.SetRight( aPt
.X() );
3643 aTempRect
.SetBottom( aPt
.Y() );
3645 // get text and display it
3646 OUString aStr
= GetQuickHelpText( nItemId
);
3648 aStr
= MnemonicGenerator::EraseAllMnemonicChars( GetItemText( nItemId
) );
3649 if ( rHEvt
.GetMode() & HelpEventMode::BALLOON
)
3651 const OUString
& rHelpStr
= GetHelpText( nItemId
);
3652 if (!rHelpStr
.isEmpty())
3654 Help::ShowBalloon( this, aHelpPos
, aTempRect
, aStr
);
3657 Help::ShowQuickHelp( this, aTempRect
, aStr
, QuickHelpFlags::CtrlText
);
3662 DockingWindow::RequestHelp( rHEvt
);
3665 bool ToolBox::EventNotify( NotifyEvent
& rNEvt
)
3667 if ( rNEvt
.GetType() == NotifyEventType::KEYINPUT
)
3669 KeyEvent aKEvt
= *rNEvt
.GetKeyEvent();
3670 vcl::KeyCode aKeyCode
= aKEvt
.GetKeyCode();
3671 sal_uInt16 nKeyCode
= aKeyCode
.GetCode();
3676 // internal TAB cycling only if parent is not a dialog or if we are the only child
3677 // otherwise the dialog control will take over
3678 vcl::Window
*pParent
= ImplGetParent();
3679 bool bOldSchoolContainer
=
3680 ((pParent
->GetStyle() & (WB_DIALOGCONTROL
| WB_NODIALOGCONTROL
)) == WB_DIALOGCONTROL
&&
3681 pParent
->GetChildCount() != 1);
3682 bool bNoTabCycling
= bOldSchoolContainer
|| isContainerWindow(pParent
);
3685 return DockingWindow::EventNotify( rNEvt
);
3686 else if( ImplChangeHighlightUpDn( aKeyCode
.IsShift() , bNoTabCycling
) )
3689 return DockingWindow::EventNotify( rNEvt
);
3695 else if( rNEvt
.GetType() == NotifyEventType::GETFOCUS
)
3697 if( rNEvt
.GetWindow() == this )
3699 // the toolbar itself got the focus
3700 if( mnLastFocusItemId
!= ToolBoxItemId(0) || mpData
->mbMenubuttonWasLastSelected
)
3702 // restore last item
3703 if( mpData
->mbMenubuttonWasLastSelected
)
3705 ImplChangeHighlight( nullptr );
3706 mpData
->mbMenubuttonSelected
= true;
3707 InvalidateMenuButton();
3711 ImplChangeHighlight( ImplGetItem( mnLastFocusItemId
) );
3712 mnLastFocusItemId
= ToolBoxItemId(0);
3715 else if( (GetGetFocusFlags() & (GetFocusFlags::Backward
|GetFocusFlags::Tab
) ) == (GetFocusFlags::Backward
|GetFocusFlags::Tab
))
3716 // Shift-TAB was pressed in the parent
3717 ImplChangeHighlightUpDn( false );
3719 ImplChangeHighlightUpDn( true );
3721 mnLastFocusItemId
= ToolBoxItemId(0);
3727 // a child window got the focus so update current item to
3728 // allow for proper lose focus handling in keyboard navigation
3729 for (auto const& item
: mpData
->m_aItems
)
3731 if ( item
.mbVisible
)
3733 if ( item
.mpWindow
&& item
.mpWindow
->ImplIsWindowOrChild( rNEvt
.GetWindow() ) )
3735 mnHighItemId
= item
.mnId
;
3740 return DockingWindow::EventNotify( rNEvt
);
3743 else if( rNEvt
.GetType() == NotifyEventType::LOSEFOCUS
)
3747 mpData
->mbMenubuttonWasLastSelected
= false;
3748 mnHighItemId
= ToolBoxItemId(0);
3749 mnCurPos
= ITEM_NOTFOUND
;
3752 return DockingWindow::EventNotify( rNEvt
);
3755 void ToolBox::Command( const CommandEvent
& rCEvt
)
3757 if ( rCEvt
.GetCommand() == CommandEventId::Wheel
)
3759 if ( (mnCurLine
> 1) || (mnCurLine
+mnVisLines
-1 < mnCurLines
) )
3761 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
3762 if ( pData
->GetMode() == CommandWheelMode::SCROLL
)
3764 if ( (mnCurLine
> 1) && (pData
->GetDelta() > 0) )
3766 else if ( (mnCurLine
+mnVisLines
-1 < mnCurLines
) && (pData
->GetDelta() < 0) )
3773 else if ( rCEvt
.GetCommand() == CommandEventId::ContextMenu
)
3775 ExecuteCustomMenu( tools::Rectangle( rCEvt
.GetMousePosPixel(), rCEvt
.GetMousePosPixel() ) );
3779 DockingWindow::Command( rCEvt
);
3782 void ToolBox::StateChanged( StateChangedType nType
)
3784 DockingWindow::StateChanged( nType
);
3786 if ( nType
== StateChangedType::InitShow
)
3788 else if ( nType
== StateChangedType::Enable
)
3790 else if ( nType
== StateChangedType::UpdateMode
)
3792 if ( IsUpdateMode() )
3795 else if ( (nType
== StateChangedType::Zoom
) ||
3796 (nType
== StateChangedType::ControlFont
) )
3800 ImplInitSettings( true, false, false );
3803 else if ( nType
== StateChangedType::ControlForeground
)
3805 ImplInitSettings( false, true, false );
3808 else if ( nType
== StateChangedType::ControlBackground
)
3810 ImplInitSettings( false, false, true ); // font, foreground, background
3814 maStateChangedHandler
.Call( &nType
);
3817 void ToolBox::DataChanged( const DataChangedEvent
& rDCEvt
)
3819 DockingWindow::DataChanged( rDCEvt
);
3821 if ( (rDCEvt
.GetType() == DataChangedEventType::DISPLAY
) ||
3822 (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ||
3823 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
3824 ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
3825 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)) )
3829 ImplInitSettings( true, true, true );
3833 maDataChangedHandler
.Call( &rDCEvt
);
3836 void ToolBox::SetStyle(WinBits nNewStyle
)
3838 mnWinStyle
= nNewStyle
;
3839 if (!ImplIsFloatingMode())
3841 bool bOldScroll
= mbScroll
;
3842 mbScroll
= (mnWinStyle
& WB_SCROLL
) != 0;
3843 if (mbScroll
!= bOldScroll
)
3851 void ToolBox::ToggleFloatingMode()
3853 DockingWindow::ToggleFloatingMode();
3858 bool bOldHorz
= mbHorz
;
3860 if ( ImplIsFloatingMode() )
3863 meAlign
= WindowAlign::Top
;
3866 if( bOldHorz
!= mbHorz
)
3867 mbCalc
= true; // orientation was changed !
3869 ImplSetMinMaxFloatSize();
3870 SetOutputSizePixel( ImplCalcFloatSize( mnFloatLines
) );
3874 mbScroll
= (mnWinStyle
& WB_SCROLL
) != 0;
3875 if ( (meAlign
== WindowAlign::Top
) || (meAlign
== WindowAlign::Bottom
) )
3880 // set focus back to document
3881 ImplGetFrameWindow()->GetWindow( GetWindowType::Client
)->GrabFocus();
3884 if( bOldHorz
!= mbHorz
)
3886 // if orientation changes, the toolbox has to be initialized again
3887 // to update the direction of the gradient
3889 ImplInitSettings( true, true, true );
3896 void ToolBox::StartDocking()
3898 meDockAlign
= meAlign
;
3899 mnDockLines
= mnLines
;
3900 mbLastFloatMode
= ImplIsFloatingMode();
3901 DockingWindow::StartDocking();
3904 bool ToolBox::Docking( const Point
& rPos
, tools::Rectangle
& rRect
)
3906 // do nothing during dragging, it was calculated before
3910 bool bFloatMode
= false;
3912 DockingWindow::Docking( rPos
, rRect
);
3914 // if the mouse is outside the area, it can only become a floating window
3915 tools::Rectangle
aDockingRect( rRect
);
3916 if ( !ImplIsFloatingMode() )
3918 // don't use tracking rectangle for alignment check, because it will be too large
3919 // to get a floating mode as result - switch to floating size
3920 // so the calculation only depends on the position of the rectangle, not the current
3921 // docking state of the window
3922 ImplToolItems::size_type nTemp
= 0;
3923 aDockingRect
.SetSize( ImplCalcFloatSize( nTemp
) );
3925 // in this mode docking is never done by keyboard, so it's OK to use the mouse position
3926 aDockingRect
.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
3931 meDockAlign
= meAlign
;
3932 if ( !mbLastFloatMode
)
3934 ImplToolItems::size_type nTemp
= 0;
3935 aDockingRect
.SetSize( ImplCalcFloatSize( nTemp
) );
3938 rRect
= aDockingRect
;
3939 mbLastFloatMode
= bFloatMode
;
3944 void ToolBox::EndDocking( const tools::Rectangle
& rRect
, bool bFloatMode
)
3946 if ( !IsDockingCanceled() )
3948 if ( mnLines
!= mnDockLines
)
3949 SetLineCount( mnDockLines
);
3950 if ( meAlign
!= meDockAlign
)
3951 SetAlign( meDockAlign
);
3953 if ( bFloatMode
|| (bFloatMode
!= ImplIsFloatingMode()) )
3954 DockingWindow::EndDocking( rRect
, bFloatMode
);
3957 void ToolBox::Resizing( Size
& rSize
)
3959 ImplToolItems::size_type nCalcLines
;
3960 ImplToolItems::size_type nTemp
;
3962 // calculate all floating sizes
3963 ImplCalcFloatSizes();
3965 if ( !mnLastResizeDY
)
3966 mnLastResizeDY
= mnDY
;
3968 // is vertical resizing needed
3969 if ( (mnLastResizeDY
!= rSize
.Height()) && (mnDY
!= rSize
.Height()) )
3971 nCalcLines
= ImplCalcLines( rSize
.Height() );
3972 if ( nCalcLines
< 1 )
3974 rSize
= ImplCalcFloatSize( nCalcLines
);
3980 Size aTempSize
= ImplCalcFloatSize( nTemp
);
3981 while ( (aTempSize
.Width() > rSize
.Width()) &&
3982 (nCalcLines
<= maFloatSizes
[0].mnLines
) )
3986 aTempSize
= ImplCalcFloatSize( nTemp
);
3991 mnLastResizeDY
= rSize
.Height();
3994 Size
ToolBox::GetOptimalSize() const
3996 // If we have any expandable entries, then force them to their
3997 // optimal sizes, then reset them afterwards
3998 std::map
<vcl::Window
*, Size
> aExpandables
;
3999 for (const ImplToolItem
& rItem
: mpData
->m_aItems
)
4003 vcl::Window
*pWindow
= rItem
.mpWindow
;
4004 SAL_INFO_IF(!pWindow
, "vcl.layout", "only tabitems with window supported at the moment");
4007 Size
aWinSize(pWindow
->GetSizePixel());
4008 aExpandables
[pWindow
] = aWinSize
;
4009 Size
aPrefSize(pWindow
->get_preferred_size());
4010 aWinSize
.setWidth( aPrefSize
.Width() );
4011 pWindow
->SetSizePixel(aWinSize
);
4015 Size
aSize(const_cast<ToolBox
*>(this)->ImplCalcSize( mnLines
));
4017 for (auto const& [pWindow
, aWinSize
] : aExpandables
)
4018 pWindow
->SetSizePixel(aWinSize
);
4023 Size
ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines
)
4025 return ImplCalcSize( nCalcLines
);
4028 Size
ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines
, WindowAlign eAlign
)
4030 return ImplCalcSize( nCalcLines
,
4031 (eAlign
== WindowAlign::Top
|| eAlign
== WindowAlign::Bottom
) ? TB_CALCMODE_HORZ
: TB_CALCMODE_VERT
);
4034 ToolBox::ImplToolItems::size_type
ToolBox::ImplCountLineBreaks() const
4036 ImplToolItems::size_type nLines
= 0;
4038 for (auto const& item
: mpData
->m_aItems
)
4040 if( item
.meType
== ToolBoxItemType::BREAK
)
4046 Size
ToolBox::CalcPopupWindowSizePixel()
4048 // count number of breaks and calc corresponding floating window size
4049 ImplToolItems::size_type nLines
= ImplCountLineBreaks();
4052 ++nLines
; // add the first line
4055 // no breaks found: use quadratic layout
4056 nLines
= static_cast<ImplToolItems::size_type
>(ceil( sqrt( static_cast<double>(GetItemCount()) ) ));
4059 bool bPopup
= mpData
->mbAssumePopupMode
;
4060 mpData
->mbAssumePopupMode
= true;
4062 Size aSize
= CalcFloatingWindowSizePixel( nLines
);
4064 mpData
->mbAssumePopupMode
= bPopup
;
4068 Size
ToolBox::CalcFloatingWindowSizePixel()
4070 ImplToolItems::size_type nLines
= ImplCountLineBreaks();
4071 ++nLines
; // add the first line
4072 return CalcFloatingWindowSizePixel( nLines
);
4075 Size
ToolBox::CalcFloatingWindowSizePixel( ImplToolItems::size_type nCalcLines
)
4077 bool bFloat
= mpData
->mbAssumeFloating
;
4078 bool bDocking
= mpData
->mbAssumeDocked
;
4080 // simulate floating mode and force reformat before calculating
4081 mpData
->mbAssumeFloating
= true;
4082 mpData
->mbAssumeDocked
= false;
4084 Size aSize
= ImplCalcFloatSize( nCalcLines
);
4087 mpData
->mbAssumeFloating
= bFloat
;
4088 mpData
->mbAssumeDocked
= bDocking
;
4093 Size
ToolBox::CalcMinimumWindowSizePixel()
4095 if( ImplIsFloatingMode() )
4096 return ImplCalcSize( mnFloatLines
);
4099 // create dummy toolbox for measurements
4100 VclPtrInstance
< ToolBox
> pToolBox( GetParent(), GetStyle() );
4102 // copy until first useful item
4103 for (auto const& item
: mpData
->m_aItems
)
4105 pToolBox
->CopyItem( *this, item
.mnId
);
4106 if( (item
.meType
== ToolBoxItemType::BUTTON
) &&
4107 item
.mbVisible
&& !ImplIsFixedControl( &item
) )
4111 // add to docking manager if required to obtain a drag area
4112 // (which is accounted for in calcwindowsizepixel)
4113 if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
4114 ImplGetDockingManager()->AddWindow( pToolBox
);
4117 if( IsMenuEnabled() )
4118 pToolBox
->SetMenuType( GetMenuType() );
4120 pToolBox
->SetAlign( GetAlign() );
4121 Size aSize
= pToolBox
->CalcWindowSizePixel( 1 );
4123 ImplGetDockingManager()->RemoveWindow( pToolBox
);
4126 pToolBox
.disposeAndClear();
4132 void ToolBox::EnableCustomize( bool bEnable
)
4134 mbCustomize
= bEnable
;
4137 void ToolBox::LoseFocus()
4139 ImplChangeHighlight( nullptr, true );
4141 DockingWindow::LoseFocus();
4144 // performs the action associated with an item, ie simulates clicking the item
4145 void ToolBox::TriggerItem( ToolBoxItemId nItemId
)
4147 mnHighItemId
= nItemId
;
4148 vcl::KeyCode
aKeyCode( 0, 0 );
4149 ImplActivateItem( aKeyCode
);
4152 bool ToolBox::ItemHasDropdown( ToolBoxItemId nItemId
)
4154 ImplToolItem
* pItem
= ImplGetItem( nItemId
);
4155 return pItem
&& pItem
->mnBits
& ToolBoxItemBits::DROPDOWN
;
4158 void ToolBox::TriggerItemDropdown( ToolBoxItemId nItemId
)
4160 if( mpFloatWin
|| !ItemHasDropdown( nItemId
) )
4163 // Prevent highlighting of triggered item
4164 mnHighItemId
= ToolBoxItemId(0);
4166 mnDownItemId
= mnCurItemId
= nItemId
;
4167 mnCurPos
= GetItemPos( mnCurItemId
);
4168 mnMouseModifier
= 0;
4170 mpData
->mbDropDownByKeyboard
= false;
4171 mpData
->maDropdownClickHdl
.Call( this );
4174 // calls the button's action handler
4175 // returns true if action was called
4176 bool ToolBox::ImplActivateItem( vcl::KeyCode aKeyCode
)
4181 ImplToolItem
*pToolItem
= ImplGetItem( mnHighItemId
);
4183 // #107712#, activate can also be called for disabled entries
4184 if( pToolItem
&& !pToolItem
->mbEnabled
)
4187 if( pToolItem
&& pToolItem
->mpWindow
&& HasFocus() )
4190 mbChangingHighlight
= true; // avoid focus change due to loss of focus
4191 pToolItem
->mpWindow
->ImplControlFocus( GetFocusFlags::Tab
);
4192 mbChangingHighlight
= false;
4196 mnDownItemId
= mnCurItemId
= mnHighItemId
;
4197 if (pToolItem
&& (pToolItem
->mnBits
& ToolBoxItemBits::AUTOCHECK
))
4199 if ( pToolItem
->mnBits
& ToolBoxItemBits::RADIOCHECK
)
4201 if ( pToolItem
->meState
!= TRISTATE_TRUE
)
4202 SetItemState( pToolItem
->mnId
, TRISTATE_TRUE
);
4206 if ( pToolItem
->meState
!= TRISTATE_TRUE
)
4207 pToolItem
->meState
= TRISTATE_TRUE
;
4209 pToolItem
->meState
= TRISTATE_FALSE
;
4212 mnMouseModifier
= aKeyCode
.GetModifier();
4213 mbIsKeyEvent
= true;
4217 // #107776# we might be destroyed in the selecthandler
4218 VclPtr
<vcl::Window
> xWindow
= this;
4220 if ( xWindow
->isDisposed() )
4224 mbIsKeyEvent
= false;
4225 mnMouseModifier
= 0;
4233 static bool ImplCloseLastPopup( vcl::Window
const *pParent
)
4235 // close last popup toolbox (see also:
4236 // ImplHandleMouseFloatMode(...) in winproc.cxx )
4238 if (ImplGetSVData()->mpWinData
->mpFirstFloat
)
4240 FloatingWindow
* pLastLevelFloat
= ImplGetSVData()->mpWinData
->mpFirstFloat
->ImplFindLastLevelFloat();
4241 // only close the floater if it is not our direct parent, which would kill ourself
4242 if( pLastLevelFloat
&& pLastLevelFloat
!= pParent
)
4244 pLastLevelFloat
->EndPopupMode( FloatWinPopupEndFlags::Cancel
| FloatWinPopupEndFlags::CloseAll
);
4251 // opens a drop down toolbox item
4252 // returns true if item was opened
4253 bool ToolBox::ImplOpenItem( vcl::KeyCode aKeyCode
)
4255 sal_uInt16 nCode
= aKeyCode
.GetCode();
4258 // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
4259 if ( ((nCode
== KEY_LEFT
|| nCode
== KEY_RIGHT
) && IsHorizontal())
4260 || ((nCode
== KEY_UP
|| nCode
== KEY_DOWN
) && !IsHorizontal()) )
4263 if( mpData
->mbMenubuttonSelected
)
4265 if( ImplCloseLastPopup( GetParent() ) )
4267 mbIsKeyEvent
= true;
4268 if ( maMenuButtonHdl
.IsSet() )
4269 maMenuButtonHdl
.Call( this );
4271 ExecuteCustomMenu( mpData
->maMenubuttonItem
.maRect
);
4272 mpData
->mbMenubuttonWasLastSelected
= true;
4273 mbIsKeyEvent
= false;
4275 else if( mnHighItemId
&& ImplGetItem( mnHighItemId
) &&
4276 (ImplGetItem( mnHighItemId
)->mnBits
& ToolBoxItemBits::DROPDOWN
) )
4278 mnDownItemId
= mnCurItemId
= mnHighItemId
;
4279 mnCurPos
= GetItemPos( mnCurItemId
);
4280 mnLastFocusItemId
= mnCurItemId
; // save item id for possible later focus restore
4281 mnMouseModifier
= aKeyCode
.GetModifier();
4282 mbIsKeyEvent
= true;
4285 mpData
->mbDropDownByKeyboard
= true;
4286 mpData
->maDropdownClickHdl
.Call( this );
4288 mbIsKeyEvent
= false;
4289 mnMouseModifier
= 0;
4297 void ToolBox::KeyInput( const KeyEvent
& rKEvt
)
4299 vcl::KeyCode aKeyCode
= rKEvt
.GetKeyCode();
4300 sal_uInt16 nCode
= aKeyCode
.GetCode();
4302 vcl::Window
*pParent
= ImplGetParent();
4303 bool bOldSchoolContainer
= ((pParent
->GetStyle() & (WB_DIALOGCONTROL
| WB_NODIALOGCONTROL
)) == WB_DIALOGCONTROL
);
4304 bool bParentIsContainer
= bOldSchoolContainer
|| isContainerWindow(pParent
);
4306 bool bForwardKey
= false;
4307 bool bGrabFocusToDocument
= false;
4309 // #107776# we might be destroyed in the keyhandler
4310 VclPtr
<vcl::Window
> xWindow
= this;
4316 // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
4317 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4319 if( !IsHorizontal() )
4320 ImplChangeHighlightUpDn( true );
4322 ImplOpenItem( aKeyCode
);
4327 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4329 if( IsHorizontal() )
4330 ImplChangeHighlightUpDn( true );
4332 ImplOpenItem( aKeyCode
);
4337 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4339 if( !IsHorizontal() )
4340 ImplChangeHighlightUpDn( false );
4342 ImplOpenItem( aKeyCode
);
4347 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4349 if( IsHorizontal() )
4350 ImplChangeHighlightUpDn( false );
4352 ImplOpenItem( aKeyCode
);
4356 if ( mnCurLine
> 1 )
4358 if( mnCurLine
> mnVisLines
)
4359 mnCurLine
= mnCurLine
- mnVisLines
;
4365 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine
) );
4369 if ( mnCurLine
+mnVisLines
-1 < mnCurLines
)
4371 if( mnCurLine
+ 2*mnVisLines
-1 < mnCurLines
)
4372 mnCurLine
= mnCurLine
+ mnVisLines
;
4374 mnCurLine
= mnCurLines
;
4378 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine
) );
4383 ImplChangeHighlight( nullptr );
4384 ImplChangeHighlightUpDn( false );
4389 ImplChangeHighlight( nullptr );
4390 ImplChangeHighlightUpDn( true );
4395 if( !ImplIsFloatingMode() && bParentIsContainer
)
4396 DockingWindow::KeyInput( rKEvt
);
4399 // send focus to document pane
4400 vcl::Window
*pWin
= this;
4403 if( !pWin
->GetParent() )
4405 pWin
->ImplGetFrameWindow()->GetWindow( GetWindowType::Client
)->GrabFocus();
4408 pWin
= pWin
->GetParent();
4415 // #107712#, disabled entries are selectable now
4416 // leave toolbox and move focus to document
4419 ImplToolItem
*pItem
= ImplGetItem(mnHighItemId
);
4420 if (!pItem
|| !pItem
->mbEnabled
)
4422 bGrabFocusToDocument
= true;
4425 if( !bGrabFocusToDocument
)
4426 bForwardKey
= !ImplActivateItem( aKeyCode
);
4431 ImplOpenItem( aKeyCode
);
4436 sal_uInt16 aKeyGroup
= aKeyCode
.GetGroup();
4437 ImplToolItem
*pItem
= nullptr;
4439 pItem
= ImplGetItem( mnHighItemId
);
4440 // #i13931# forward alphanum keyinput into embedded control
4441 if( (aKeyGroup
== KEYGROUP_NUM
|| aKeyGroup
== KEYGROUP_ALPHA
) && pItem
&& pItem
->mpWindow
&& pItem
->mbEnabled
)
4443 vcl::Window
*pFocusWindow
= Application::GetFocusWindow();
4445 mbChangingHighlight
= true; // avoid focus change due to loss of focus
4446 pItem
->mpWindow
->ImplControlFocus( GetFocusFlags::Tab
);
4447 mbChangingHighlight
= false;
4448 if( pFocusWindow
!= Application::GetFocusWindow() )
4449 Application::GetFocusWindow()->KeyInput( rKEvt
);
4453 // do nothing to avoid key presses going into the document
4454 // while the toolbox has the focus
4455 // just forward function and special keys and combinations with Alt-key
4457 if( aKeyGroup
== KEYGROUP_FKEYS
|| aKeyGroup
== KEYGROUP_MISC
|| aKeyCode
.IsMod2()
4458 || aKeyCode
.IsMod1() )
4464 if ( xWindow
->isDisposed() )
4467 // #107251# move focus away if this toolbox was disabled during keyinput
4468 if (HasFocus() && mpData
->mbKeyInputDisabled
&& bParentIsContainer
)
4470 vcl::Window
*pFocusControl
= pParent
->ImplGetDlgWindow( 0, GetDlgWindowType::First
);
4471 if ( pFocusControl
&& pFocusControl
!= this )
4472 pFocusControl
->ImplControlFocus( GetFocusFlags::Init
);
4475 // #107712#, leave toolbox
4476 if( bGrabFocusToDocument
)
4478 GrabFocusToDocument();
4483 DockingWindow::KeyInput( rKEvt
);
4486 // returns the current toolbox line of the item
4487 ToolBox::ImplToolItems::size_type
ToolBox::ImplGetItemLine( ImplToolItem
const * pCurrentItem
)
4489 ImplToolItems::size_type nLine
= 1;
4490 for (auto const& item
: mpData
->m_aItems
)
4494 if( &item
== pCurrentItem
)
4500 // returns the first displayable item in the given line
4501 ImplToolItem
* ToolBox::ImplGetFirstValidItem( ImplToolItems::size_type nLine
)
4503 if( !nLine
|| nLine
> mnCurLines
)
4508 ImplToolItems::iterator it
= mpData
->m_aItems
.begin();
4509 while( it
!= mpData
->m_aItems
.end() )
4511 // find correct line
4516 // find first useful item
4517 while( it
!= mpData
->m_aItems
.end() && ((it
->meType
!= ToolBoxItemType::BUTTON
) ||
4518 /*!it->mbEnabled ||*/ !it
->mbVisible
|| ImplIsFixedControl( &(*it
) )) )
4521 if( it
== mpData
->m_aItems
.end() || it
->mbBreak
)
4522 return nullptr; // no valid items in this line
4529 return (it
== mpData
->m_aItems
.end()) ? nullptr : &(*it
);
4532 ToolBox::ImplToolItems::size_type
ToolBox::ImplFindItemPos( const ImplToolItem
* pItem
, const ImplToolItems
& rList
)
4536 for( ImplToolItems::size_type nPos
= 0; nPos
< rList
.size(); ++nPos
)
4537 if( &rList
[ nPos
] == pItem
)
4540 return ITEM_NOTFOUND
;
4543 void ToolBox::ChangeHighlight( ImplToolItems::size_type nPos
)
4545 if ( nPos
< GetItemCount() ) {
4546 ImplGrabFocus( GetFocusFlags::NONE
);
4547 ImplChangeHighlight ( ImplGetItem ( GetItemId ( nPos
) ) );
4551 void ToolBox::ImplChangeHighlight( ImplToolItem
const * pItem
, bool bNoGrabFocus
)
4553 // avoid recursion due to focus change
4554 if( mbChangingHighlight
)
4557 mbChangingHighlight
= true;
4559 ImplToolItem
* pOldItem
= nullptr;
4564 ImplToolItems::size_type nPos
= GetItemPos( mnHighItemId
);
4565 pOldItem
= ImplGetItem( mnHighItemId
);
4566 // #i89962# ImplDrawItem can cause Invalidate/Update
4567 // which will in turn ImplShowFocus again
4568 // set mnHighItemId to 0 already to prevent this hen/egg problem
4569 mnHighItemId
= ToolBoxItemId(0);
4570 InvalidateItem(nPos
);
4571 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nPos
) );
4574 if( !bNoGrabFocus
&& pItem
!= pOldItem
&& pOldItem
&& pOldItem
->mpWindow
)
4576 // move focus into toolbox
4582 ImplToolItems::size_type aPos
= ToolBox::ImplFindItemPos( pItem
, mpData
->m_aItems
);
4583 if( aPos
!= ITEM_NOTFOUND
)
4585 // check for line breaks
4586 ImplToolItems::size_type nLine
= ImplGetItemLine( pItem
);
4588 if( nLine
>= mnCurLine
+ mnVisLines
)
4590 mnCurLine
= nLine
- mnVisLines
+ 1;
4593 else if ( nLine
< mnCurLine
)
4604 mnHighItemId
= pItem
->mnId
;
4605 InvalidateItem(aPos
);
4609 if( pItem
->mpWindow
)
4610 pItem
->mpWindow
->GrabFocus();
4611 if( pItem
!= pOldItem
)
4612 CallEventListeners( VclEventId::ToolboxHighlight
);
4618 mnHighItemId
= ToolBoxItemId(0);
4619 mnCurPos
= ITEM_NOTFOUND
;
4622 mbChangingHighlight
= false;
4625 // check for keyboard accessible items
4626 static bool ImplIsValidItem( const ImplToolItem
* pItem
, bool bNotClipped
)
4628 bool bValid
= (pItem
&& pItem
->meType
== ToolBoxItemType::BUTTON
&& pItem
->mbVisible
&& !ImplIsFixedControl( pItem
)
4629 && pItem
->mbEnabled
);
4630 if( bValid
&& bNotClipped
&& pItem
->IsClipped() )
4635 bool ToolBox::ImplChangeHighlightUpDn( bool bUp
, bool bNoCycle
)
4637 ImplToolItem
* pToolItem
= ImplGetItem( mnHighItemId
);
4639 if( !pToolItem
|| !mnHighItemId
)
4641 // menubutton highlighted ?
4642 if( mpData
->mbMenubuttonSelected
)
4644 mpData
->mbMenubuttonSelected
= false;
4647 // select last valid non-clipped item
4648 ImplToolItem
* pItem
= nullptr;
4649 auto it
= std::find_if(mpData
->m_aItems
.rbegin(), mpData
->m_aItems
.rend(),
4650 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, true ); });
4651 if( it
!= mpData
->m_aItems
.rend() )
4654 InvalidateMenuButton();
4655 ImplChangeHighlight( pItem
);
4659 // select first valid non-clipped item
4660 ImplToolItems::iterator it
= std::find_if(mpData
->m_aItems
.begin(), mpData
->m_aItems
.end(),
4661 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, true ); });
4662 if( it
!= mpData
->m_aItems
.end() )
4664 InvalidateMenuButton();
4665 ImplChangeHighlight( &(*it
) );
4673 // Select first valid item
4674 ImplToolItems::iterator it
= std::find_if(mpData
->m_aItems
.begin(), mpData
->m_aItems
.end(),
4675 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, false ); });
4677 // select the menu button if a clipped item would be selected
4678 if( (it
!= mpData
->m_aItems
.end() && &(*it
) == ImplGetFirstClippedItem()) && IsMenuEnabled() )
4680 ImplChangeHighlight( nullptr );
4681 mpData
->mbMenubuttonSelected
= true;
4682 InvalidateMenuButton();
4685 ImplChangeHighlight( (it
!= mpData
->m_aItems
.end()) ? &(*it
) : nullptr );
4690 // Select last valid item
4692 // docked toolbars have the menubutton as last item - if this button is enabled
4693 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4695 ImplChangeHighlight( nullptr );
4696 mpData
->mbMenubuttonSelected
= true;
4697 InvalidateMenuButton();
4701 ImplToolItem
* pItem
= nullptr;
4702 auto it
= std::find_if(mpData
->m_aItems
.rbegin(), mpData
->m_aItems
.rend(),
4703 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, false ); });
4704 if( it
!= mpData
->m_aItems
.rend() )
4707 ImplChangeHighlight( pItem
);
4715 ImplToolItems::size_type pos
= ToolBox::ImplFindItemPos( pToolItem
, mpData
->m_aItems
);
4716 ImplToolItems::size_type nCount
= mpData
->m_aItems
.size();
4718 ImplToolItems::size_type i
=0;
4728 // highlight the menu button if it is the last item
4729 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4731 ImplChangeHighlight( nullptr );
4732 mpData
->mbMenubuttonSelected
= true;
4733 InvalidateMenuButton();
4742 if( ++pos
>= nCount
)
4747 // highlight the menu button if it is the last item
4748 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4750 ImplChangeHighlight( nullptr );
4751 mpData
->mbMenubuttonSelected
= true;
4752 InvalidateMenuButton();
4760 pToolItem
= &mpData
->m_aItems
[pos
];
4762 if ( ImplIsValidItem( pToolItem
, false ) )
4765 } while( ++i
< nCount
);
4767 if( pToolItem
->IsClipped() && IsMenuEnabled() )
4769 // select the menu button if a clipped item would be selected
4770 ImplChangeHighlight( nullptr );
4771 mpData
->mbMenubuttonSelected
= true;
4772 InvalidateMenuButton();
4774 else if( i
!= nCount
)
4775 ImplChangeHighlight( pToolItem
);
4782 void ToolBox::ImplShowFocus()
4784 if( mnHighItemId
&& HasFocus() )
4786 ImplToolItem
* pItem
= ImplGetItem( mnHighItemId
);
4787 if (pItem
&& pItem
->mpWindow
&& !pItem
->mpWindow
->isDisposed())
4789 vcl::Window
*pWin
= pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
? pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
.get() : pItem
->mpWindow
.get();
4790 pWin
->ImplGetWindowImpl()->mbDrawSelectionBackground
= true;
4796 void ToolBox::ImplHideFocus()
4800 mpData
->mbMenubuttonWasLastSelected
= false;
4801 ImplToolItem
* pItem
= ImplGetItem( mnHighItemId
);
4802 if( pItem
&& pItem
->mpWindow
)
4804 vcl::Window
*pWin
= pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
? pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
.get() : pItem
->mpWindow
.get();
4805 pWin
->ImplGetWindowImpl()->mbDrawSelectionBackground
= false;
4810 if ( mpData
&& mpData
->mbMenubuttonSelected
)
4812 mpData
->mbMenubuttonWasLastSelected
= true;
4813 // remove highlight from menubutton
4814 mpData
->mbMenubuttonSelected
= false;
4815 InvalidateMenuButton();
4819 void ToolBox::SetToolbarLayoutMode( ToolBoxLayoutMode eLayout
)
4821 if ( meLayoutMode
!= eLayout
)
4822 meLayoutMode
= eLayout
;
4825 void ToolBox::SetToolBoxTextPosition( ToolBoxTextPosition ePosition
)
4827 meTextPosition
= ePosition
;
4830 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */