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();
509 const bool isHeader
= GetAlign() == WindowAlign::Top
&& !rSetting
.GetPersonaHeader().IsEmpty();
510 const bool isFooter
= GetAlign() == WindowAlign::Bottom
&& !rSetting
.GetPersonaFooter().IsEmpty();
511 if (!IsBackground() || isHeader
|| isFooter
)
514 ImplDrawTransparentBackground(aPaintRegion
);
517 ImplDrawGradientBackground(rRenderContext
);
521 // restore clip region
522 rRenderContext
.Pop();
525 void ToolBox::ImplErase(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&rRect
, bool bHighlight
, bool bHasOpenPopup
)
527 // the background of non NWF buttons is painted in a constant color
528 // to have the same highlight color (transparency in DrawSelectionBackground())
529 // items with open popups will also painted using a constant color
530 if (!mpData
->mbNativeButtons
&&
531 (bHighlight
|| !(GetStyle() & WB_3DLOOK
)))
533 if (GetStyle() & WB_3DLOOK
)
535 rRenderContext
.Push(vcl::PushFlags::LINECOLOR
| vcl::PushFlags::FILLCOLOR
);
536 rRenderContext
.SetLineColor();
538 // choose the same color as the popup will use
539 rRenderContext
.SetFillColor(rRenderContext
.GetSettings().GetStyleSettings().GetFaceColor());
541 rRenderContext
.SetFillColor(rRenderContext
.GetSettings().GetStyleSettings().GetWindowColor());
543 rRenderContext
.DrawRect(rRect
);
544 rRenderContext
.Pop();
547 ImplDrawBackground(rRenderContext
, rRect
);
550 ImplDrawBackground(rRenderContext
, rRect
);
553 void ToolBox::ImplDrawBorder(vcl::RenderContext
& rRenderContext
)
555 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
556 tools::Long nDX
= mnDX
;
557 tools::Long nDY
= mnDY
;
559 ImplDockingWindowWrapper
* pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
561 // draw borders for ordinary toolbars only (not dockable), do not draw borders for toolbars with WB_NOSHADOW bit set,
562 // e.g. Calc's formulabar
564 if( pWrapper
|| mnWinStyle
& WB_NOSHADOW
)
567 if (meAlign
== WindowAlign::Bottom
)
569 // draw bottom border
570 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
571 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-1, nDY
-2 ) );
572 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
573 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
578 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
579 rRenderContext
.DrawLine( Point( 0, 0 ), Point( nDX
-1, 0 ) );
580 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
581 rRenderContext
.DrawLine( Point( 0, 1 ), Point( nDX
-1, 1 ) );
583 if (meAlign
== WindowAlign::Left
|| meAlign
== WindowAlign::Right
)
585 if (meAlign
== WindowAlign::Left
)
587 // draw left-bottom border
588 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
589 rRenderContext
.DrawLine( Point( 0, 0 ), Point( 0, nDY
-1 ) );
590 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-1, nDY
-2 ) );
591 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
592 rRenderContext
.DrawLine( Point( 1, 1 ), Point( 1, nDY
-3 ) );
593 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
597 // draw right-bottom border
598 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
599 rRenderContext
.DrawLine( Point( nDX
-2, 0 ), Point( nDX
-2, nDY
-3 ) );
600 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-2, nDY
-2 ) );
601 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
602 rRenderContext
.DrawLine( Point( nDX
-1, 0 ), Point( nDX
-1, nDY
-1 ) );
603 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
608 if ( meAlign
== WindowAlign::Bottom
|| meAlign
== WindowAlign::Top
)
611 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
612 rRenderContext
.DrawLine( Point( nDX
-2, 0 ), Point( nDX
-2, nDY
-1 ) );
613 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
614 rRenderContext
.DrawLine( Point( nDX
-1, 0 ), Point( nDX
-1, nDY
-1 ) );
618 static bool ImplIsFixedControl( const ImplToolItem
*pItem
)
620 return ( pItem
->mpWindow
&&
621 (pItem
->mbNonInteractiveWindow
||
622 pItem
->mpWindow
->GetType() == WindowType::FIXEDTEXT
||
623 pItem
->mpWindow
->GetType() == WindowType::FIXEDLINE
||
624 pItem
->mpWindow
->GetType() == WindowType::GROUPBOX
) );
627 const ImplToolItem
*ToolBox::ImplGetFirstClippedItem() const
629 for (auto & item
: mpData
->m_aItems
)
631 if( item
.IsClipped() )
637 Size
ToolBox::ImplCalcSize( ImplToolItems::size_type nCalcLines
, sal_uInt16 nCalcMode
)
640 tools::Long nLeft
= 0;
641 tools::Long nTop
= 0;
642 tools::Long nRight
= 0;
643 tools::Long nBottom
= 0;
645 WindowAlign eOldAlign
= meAlign
;
646 bool bOldHorz
= mbHorz
;
647 bool bOldAssumeDocked
= mpData
->mbAssumeDocked
;
648 bool bOldAssumeFloating
= mpData
->mbAssumeFloating
;
652 bool bOldFloatingMode
= ImplIsFloatingMode();
654 mpData
->mbAssumeDocked
= false;
655 mpData
->mbAssumeFloating
= false;
657 if ( nCalcMode
== TB_CALCMODE_HORZ
)
659 mpData
->mbAssumeDocked
= true; // force non-floating mode during calculation
660 ImplCalcBorder( WindowAlign::Top
, nLeft
, nTop
, nRight
, nBottom
);
662 if ( mbHorz
!= bOldHorz
)
663 meAlign
= WindowAlign::Top
;
665 else if ( nCalcMode
== TB_CALCMODE_VERT
)
667 mpData
->mbAssumeDocked
= true; // force non-floating mode during calculation
668 ImplCalcBorder( WindowAlign::Left
, nLeft
, nTop
, nRight
, nBottom
);
670 if ( mbHorz
!= bOldHorz
)
671 meAlign
= WindowAlign::Left
;
673 else if ( nCalcMode
== TB_CALCMODE_FLOAT
)
675 mpData
->mbAssumeFloating
= true; // force non-floating mode during calculation
676 nLeft
= nTop
= nRight
= nBottom
= 0;
678 if ( mbHorz
!= bOldHorz
)
679 meAlign
= WindowAlign::Top
;
682 if ( (meAlign
!= eOldAlign
) || (mbHorz
!= bOldHorz
) ||
683 (ImplIsFloatingMode() != bOldFloatingMode
) )
687 ImplCalcBorder( meAlign
, nLeft
, nTop
, nRight
, nBottom
);
691 if( !nCalcMode
&& ImplIsFloatingMode() )
693 aSize
= ImplCalcFloatSize( nCalcLines
);
699 if ( mnWinHeight
> mnMaxItemHeight
)
700 aSize
.setHeight( nCalcLines
* mnWinHeight
);
702 aSize
.setHeight( nCalcLines
* mnMaxItemHeight
);
705 aSize
.AdjustHeight((nCalcLines
-1)*TB_LINESPACING
);
707 if ( mnWinStyle
& WB_BORDER
)
708 aSize
.AdjustHeight((TB_BORDER_OFFSET2
*2) + nTop
+ nBottom
);
711 ImplCalcBreaks( TB_MAXNOSCROLL
, &nMax
, mbHorz
);
713 aSize
.AdjustWidth(nMax
);
715 if ( mnWinStyle
& WB_BORDER
)
716 aSize
.AdjustWidth((TB_BORDER_OFFSET1
*2) + nLeft
+ nRight
);
720 aSize
.setWidth( nCalcLines
* mnMaxItemWidth
);
723 aSize
.AdjustWidth((nCalcLines
-1)*TB_LINESPACING
);
725 if ( mnWinStyle
& WB_BORDER
)
726 aSize
.AdjustWidth((TB_BORDER_OFFSET2
*2) + nLeft
+ nRight
);
729 ImplCalcBreaks( TB_MAXNOSCROLL
, &nMax
, mbHorz
);
731 aSize
.AdjustHeight(nMax
);
733 if ( mnWinStyle
& WB_BORDER
)
734 aSize
.AdjustHeight((TB_BORDER_OFFSET1
*2) + nTop
+ nBottom
);
737 // restore previous values
740 mpData
->mbAssumeDocked
= bOldAssumeDocked
;
741 mpData
->mbAssumeFloating
= bOldAssumeFloating
;
742 if ( (meAlign
!= eOldAlign
) || (mbHorz
!= bOldHorz
) )
753 void ToolBox::ImplCalcFloatSizes()
755 if ( !maFloatSizes
.empty() )
758 // calculate the minimal size, i.e. where the biggest item just fits
759 tools::Long nCalcSize
= 0;
761 for (auto const& item
: mpData
->m_aItems
)
763 if ( item
.mbVisible
)
767 tools::Long nTempSize
= item
.mpWindow
->GetSizePixel().Width();
768 if ( nTempSize
> nCalcSize
)
769 nCalcSize
= nTempSize
;
773 if( item
.maItemSize
.Width() > nCalcSize
)
774 nCalcSize
= item
.maItemSize
.Width();
779 // calc an upper bound for ImplCalcBreaks below
780 tools::Long upperBoundWidth
= nCalcSize
* mpData
->m_aItems
.size();
782 ImplToolItems::size_type nLines
;
783 ImplToolItems::size_type nCalcLines
;
784 ImplToolItems::size_type nTempLines
;
785 sal_Int32 nMaxLineWidth
;
786 nCalcLines
= ImplCalcBreaks( nCalcSize
, &nMaxLineWidth
, true );
788 maFloatSizes
.reserve( nCalcLines
);
790 nTempLines
= nLines
= nCalcLines
;
793 tools::Long nHeight
= ImplCalcSize( nTempLines
, TB_CALCMODE_FLOAT
).Height();
796 aSize
.mnWidth
= nMaxLineWidth
+(TB_BORDER_OFFSET1
*2);
797 aSize
.mnHeight
= nHeight
;
798 aSize
.mnLines
= nTempLines
;
799 maFloatSizes
.push_back( aSize
);
805 nCalcSize
+= mnMaxItemWidth
;
806 nTempLines
= ImplCalcBreaks( nCalcSize
, &nMaxLineWidth
, true );
808 while ((nCalcSize
< upperBoundWidth
) && (nLines
< nTempLines
)); // implies nTempLines>1
809 if ( nTempLines
< nLines
)
815 Size
ToolBox::ImplCalcFloatSize( ImplToolItems::size_type
& rLines
)
817 ImplCalcFloatSizes();
821 rLines
= mnFloatLines
;
827 while ( i
+ 1u < maFloatSizes
.size() && rLines
< maFloatSizes
[i
].mnLines
)
832 Size
aSize( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
833 rLines
= maFloatSizes
[i
].mnLines
;
838 void ToolBox::ImplCalcMinMaxFloatSize( Size
& rMinSize
, Size
& rMaxSize
)
840 ImplCalcFloatSizes();
843 rMinSize
= Size( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
844 rMaxSize
= Size( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
845 while ( ++i
< maFloatSizes
.size() )
847 if( maFloatSizes
[i
].mnWidth
< rMinSize
.Width() )
848 rMinSize
.setWidth( maFloatSizes
[i
].mnWidth
);
849 if( maFloatSizes
[i
].mnHeight
< rMinSize
.Height() )
850 rMinSize
.setHeight( maFloatSizes
[i
].mnHeight
);
852 if( maFloatSizes
[i
].mnWidth
> rMaxSize
.Width() )
853 rMaxSize
.setWidth( maFloatSizes
[i
].mnWidth
);
854 if( maFloatSizes
[i
].mnHeight
> rMaxSize
.Height() )
855 rMaxSize
.setHeight( maFloatSizes
[i
].mnHeight
);
859 void ToolBox::ImplSetMinMaxFloatSize()
861 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
862 Size aMinSize
, aMaxSize
;
863 ImplCalcMinMaxFloatSize( aMinSize
, aMaxSize
);
866 pWrapper
->SetMinOutputSizePixel( aMinSize
);
867 pWrapper
->SetMaxOutputSizePixel( aMaxSize
);
868 pWrapper
->ShowMenuTitleButton( bool( GetMenuType() & ToolBoxMenuType::Customize
) );
872 // TODO: change SetMinOutputSizePixel to be not inline
873 SetMinOutputSizePixel( aMinSize
);
874 SetMaxOutputSizePixel( aMaxSize
);
878 ToolBox::ImplToolItems::size_type
ToolBox::ImplCalcLines( tools::Long nToolSize
) const
880 tools::Long nLineHeight
;
884 if ( mnWinHeight
> mnMaxItemHeight
)
885 nLineHeight
= mnWinHeight
;
887 nLineHeight
= mnMaxItemHeight
;
890 nLineHeight
= mnMaxItemWidth
;
892 if ( mnWinStyle
& WB_BORDER
)
893 nToolSize
-= TB_BORDER_OFFSET2
*2;
897 nLineHeight
+= TB_LINESPACING
;
898 nToolSize
+= TB_LINESPACING
;
901 // #i91917# always report at least one line
902 tools::Long nLines
= nToolSize
/nLineHeight
;
909 sal_uInt16
ToolBox::ImplTestLineSize( const Point
& rPos
) const
911 if ( !ImplIsFloatingMode() &&
912 (!mbScroll
|| (mnLines
> 1) || (mnCurLines
> mnVisLines
)) )
914 WindowAlign eAlign
= GetAlign();
916 if ( eAlign
== WindowAlign::Left
)
918 if ( rPos
.X() > mnDX
-DOCK_LINEOFFSET
)
919 return DOCK_LINEHSIZE
| DOCK_LINERIGHT
;
921 else if ( eAlign
== WindowAlign::Top
)
923 if ( rPos
.Y() > mnDY
-DOCK_LINEOFFSET
)
924 return DOCK_LINEVSIZE
| DOCK_LINEBOTTOM
;
926 else if ( eAlign
== WindowAlign::Right
)
928 if ( rPos
.X() < DOCK_LINEOFFSET
)
929 return DOCK_LINEHSIZE
| DOCK_LINELEFT
;
931 else if ( eAlign
== WindowAlign::Bottom
)
933 if ( rPos
.Y() < DOCK_LINEOFFSET
)
934 return DOCK_LINEVSIZE
| DOCK_LINETOP
;
941 void ToolBox::ImplLineSizing( const Point
& rPos
, tools::Rectangle
& rRect
, sal_uInt16 nLineMode
)
944 tools::Long nOneLineSize
;
945 tools::Long nCurSize
;
946 tools::Long nMaxSize
;
950 if ( nLineMode
& DOCK_LINERIGHT
)
952 nCurSize
= rPos
.X() - rRect
.Left();
955 else if ( nLineMode
& DOCK_LINEBOTTOM
)
957 nCurSize
= rPos
.Y() - rRect
.Top();
960 else if ( nLineMode
& DOCK_LINELEFT
)
962 nCurSize
= rRect
.Right() - rPos
.X();
965 else if ( nLineMode
& DOCK_LINETOP
)
967 nCurSize
= rRect
.Bottom() - rPos
.Y();
971 OSL_FAIL( "ImplLineSizing: Trailing else" );
976 Size aWinSize
= GetSizePixel();
977 ImplToolItems::size_type nMaxLines
= std::max(mnLines
, mnCurLines
);
978 if ( nMaxLines
> TB_MAXLINES
)
979 nMaxLines
= TB_MAXLINES
;
982 nOneLineSize
= ImplCalcSize( 1 ).Height();
984 if ( nMaxSize
< aWinSize
.Height() )
985 nMaxSize
= aWinSize
.Height();
989 nOneLineSize
= ImplCalcSize( 1 ).Width();
991 if ( nMaxSize
< aWinSize
.Width() )
992 nMaxSize
= aWinSize
.Width();
995 ImplToolItems::size_type i
= 1;
996 if ( nCurSize
<= nOneLineSize
)
997 nSize
= nOneLineSize
;
1001 while ( (nSize
< nCurSize
) && (i
< nMaxLines
) )
1004 aSize
= ImplCalcSize( i
);
1006 nSize
= aSize
.Height();
1008 nSize
= aSize
.Width();
1009 if ( nSize
> nMaxSize
)
1012 aSize
= ImplCalcSize( i
);
1014 nSize
= aSize
.Height();
1016 nSize
= aSize
.Width();
1022 if ( nLineMode
& DOCK_LINERIGHT
)
1023 rRect
.SetRight( rRect
.Left()+nSize
-1 );
1024 else if ( nLineMode
& DOCK_LINEBOTTOM
)
1025 rRect
.SetBottom( rRect
.Top()+nSize
-1 );
1026 else if ( nLineMode
& DOCK_LINELEFT
)
1027 rRect
.SetLeft( rRect
.Right()-nSize
);
1029 rRect
.SetTop( rRect
.Bottom()-nSize
);
1034 ImplTBDragMgr::ImplTBDragMgr()
1035 : mpDragBox(nullptr)
1039 maAccel
.InsertItem( KEY_RETURN
, vcl::KeyCode( KEY_RETURN
) );
1040 maAccel
.InsertItem( KEY_ESCAPE
, vcl::KeyCode( KEY_ESCAPE
) );
1041 maAccel
.SetSelectHdl( LINK( this, ImplTBDragMgr
, SelectHdl
) );
1044 void ImplTBDragMgr::StartDragging( ToolBox
* pToolBox
,
1045 const Point
& rPos
, const tools::Rectangle
& rRect
,
1046 sal_uInt16 nDragLineMode
)
1048 mpDragBox
= pToolBox
;
1049 pToolBox
->CaptureMouse();
1050 pToolBox
->mbDragging
= true;
1051 Application::InsertAccel( &maAccel
);
1053 mnLineMode
= nDragLineMode
;
1054 mnStartLines
= pToolBox
->mnDockLines
;
1056 // calculate MouseOffset
1057 maMouseOff
.setX( rRect
.Left() - rPos
.X() );
1058 maMouseOff
.setY( rRect
.Top() - rPos
.Y() );
1060 maStartRect
= rRect
;
1061 pToolBox
->ShowTracking( maRect
);
1064 void ImplTBDragMgr::Dragging( const Point
& rPos
)
1066 mpDragBox
->ImplLineSizing( rPos
, maRect
, mnLineMode
);
1067 Point aOff
= mpDragBox
->OutputToScreenPixel( Point() );
1068 maRect
.Move( aOff
.X(), aOff
.Y() );
1069 mpDragBox
->Docking( rPos
, maRect
);
1070 maRect
.Move( -aOff
.X(), -aOff
.Y() );
1071 mpDragBox
->ShowTracking( maRect
);
1074 void ImplTBDragMgr::EndDragging( bool bOK
)
1076 mpDragBox
->HideTracking();
1077 if (mpDragBox
->IsMouseCaptured())
1078 mpDragBox
->ReleaseMouse();
1079 mpDragBox
->mbDragging
= false;
1080 Application::RemoveAccel( &maAccel
);
1084 mpDragBox
->mnDockLines
= mnStartLines
;
1085 mpDragBox
->EndDocking( maStartRect
, false );
1088 mpDragBox
->EndDocking( maRect
, false );
1091 mpDragBox
= nullptr;
1094 IMPL_LINK( ImplTBDragMgr
, SelectHdl
, Accelerator
&, rAccel
, void )
1096 if ( rAccel
.GetCurItemId() == KEY_ESCAPE
)
1097 EndDragging( false );
1102 void ToolBox::ImplInitToolBoxData()
1104 // initialize variables
1105 ImplGetWindowImpl()->mbToolBox
= true;
1106 mpData
.reset(new ImplToolBoxPrivateData
);
1108 mpFloatWin
= nullptr;
1112 mnMaxItemHeight
= 0;
1119 mnHighItemId
= ToolBoxItemId(0);
1120 mnCurItemId
= ToolBoxItemId(0);
1121 mnDownItemId
= ToolBoxItemId(0);
1122 mnCurPos
= ITEM_NOTFOUND
;
1129 mnMouseModifier
= 0;
1136 mbFullPaint
= false;
1139 mbLastFloatMode
= false;
1140 mbCustomize
= false;
1142 mbIsKeyEvent
= false;
1143 mbChangingHighlight
= false;
1144 mbLineSpacing
= false;
1145 mbIsArranged
= false;
1146 meButtonType
= ButtonType::SYMBOLONLY
;
1147 meAlign
= WindowAlign::Top
;
1148 meDockAlign
= WindowAlign::Top
;
1149 meLastStyle
= PointerStyle::Arrow
;
1151 meLayoutMode
= ToolBoxLayoutMode::Normal
;
1152 meTextPosition
= ToolBoxTextPosition::Right
;
1153 mnLastFocusItemId
= ToolBoxItemId(0);
1154 mnActivateCount
= 0;
1156 mpIdle
.reset(new Idle("vcl::ToolBox maIdle update"));
1157 mpIdle
->SetPriority( TaskPriority::RESIZE
);
1158 mpIdle
->SetInvokeHandler( LINK( this, ToolBox
, ImplUpdateHdl
) );
1160 // set timeout and handler for dropdown items
1161 mpData
->maDropdownTimer
.SetTimeout( 250 );
1162 mpData
->maDropdownTimer
.SetInvokeHandler( LINK( this, ToolBox
, ImplDropdownLongClickHdl
) );
1165 void ToolBox::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
1167 // initialize variables
1168 mbScroll
= (nStyle
& WB_SCROLL
) != 0;
1169 mnWinStyle
= nStyle
;
1171 DockingWindow::ImplInit( pParent
, nStyle
& ~WB_BORDER
);
1173 // dockingwindow's ImplInit removes some bits, so restore them here to allow keyboard handling for toolbars
1174 ImplGetWindowImpl()->mnStyle
|= WB_TABSTOP
|WB_NODIALOGCONTROL
; // always set WB_TABSTOP for ToolBars
1175 ImplGetWindowImpl()->mnStyle
&= ~WB_DIALOGCONTROL
;
1177 ImplInitSettings(true, true, true);
1180 void ToolBox::ApplyForegroundSettings(vcl::RenderContext
& rRenderContext
, const StyleSettings
& rStyleSettings
)
1183 if (IsControlForeground())
1184 aColor
= GetControlForeground();
1185 else if (Window::GetStyle() & WB_3DLOOK
)
1186 aColor
= rStyleSettings
.GetButtonTextColor();
1188 aColor
= rStyleSettings
.GetWindowTextColor();
1189 rRenderContext
.SetTextColor(aColor
);
1190 rRenderContext
.SetTextFillColor();
1193 void ToolBox::ApplyBackgroundSettings(vcl::RenderContext
& rRenderContext
, const StyleSettings
& rStyleSettings
)
1195 if (IsControlBackground())
1197 rRenderContext
.SetBackground(GetControlBackground());
1198 SetPaintTransparent(false);
1199 SetParentClipMode();
1203 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ControlPart::Entire
)
1204 || (GetAlign() == WindowAlign::Top
&& !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty())
1205 || (GetAlign() == WindowAlign::Bottom
&& !Application::GetSettings().GetStyleSettings().GetPersonaFooter().IsEmpty()))
1207 rRenderContext
.SetBackground();
1208 rRenderContext
.SetTextColor(rStyleSettings
.GetToolTextColor());
1209 SetPaintTransparent(true);
1210 SetParentClipMode(ParentClipMode::NoClip
);
1211 mpData
->maDisplayBackground
= Wallpaper(rStyleSettings
.GetFaceColor());
1216 if (Window::GetStyle() & WB_3DLOOK
)
1217 aColor
= rStyleSettings
.GetFaceColor();
1219 aColor
= rStyleSettings
.GetWindowColor();
1220 rRenderContext
.SetBackground(aColor
);
1221 SetPaintTransparent(false);
1222 SetParentClipMode();
1227 void ToolBox::ApplySettings(vcl::RenderContext
& rRenderContext
)
1229 mpData
->mbNativeButtons
= rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ControlPart::Button
);
1231 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
1233 ApplyControlFont(rRenderContext
, rStyleSettings
.GetToolFont());
1234 ApplyForegroundSettings(rRenderContext
, rStyleSettings
);
1235 ApplyBackgroundSettings(rRenderContext
, rStyleSettings
);
1238 void ToolBox::ImplInitSettings(bool bFont
, bool bForeground
, bool bBackground
)
1240 mpData
->mbNativeButtons
= IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
);
1242 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
1245 ApplyControlFont(*GetOutDev(), rStyleSettings
.GetToolFont());
1246 if (bForeground
|| bFont
)
1247 ApplyForegroundSettings(*GetOutDev(), rStyleSettings
);
1250 ApplyBackgroundSettings(*GetOutDev(), rStyleSettings
);
1251 EnableChildTransparentMode(IsPaintTransparent());
1255 void ToolBox::doDeferredInit(WinBits nBits
)
1257 VclPtr
<vcl::Window
> pParent
= mpDialogParent
;
1258 mpDialogParent
= nullptr;
1259 ImplInit(pParent
, nBits
);
1260 mbIsDeferredInit
= false;
1263 void ToolBox::queue_resize(StateChangedType eReason
)
1265 Window::queue_resize(eReason
);
1268 ToolBox::ToolBox( vcl::Window
* pParent
, WinBits nStyle
) :
1269 DockingWindow( WindowType::TOOLBOX
, "vcl::ToolBox maLayoutIdle" )
1271 ImplInitToolBoxData();
1272 ImplInit( pParent
, nStyle
);
1275 ToolBox::ToolBox(vcl::Window
* pParent
, const OUString
& rID
,
1276 const OUString
& rUIXMLDescription
, const css::uno::Reference
<css::frame::XFrame
> &rFrame
)
1277 : DockingWindow(WindowType::TOOLBOX
, "vcl::ToolBox maLayoutIdle")
1279 ImplInitToolBoxData();
1281 loadUI(pParent
, rID
, rUIXMLDescription
, rFrame
);
1283 // calculate size of floating windows and switch if the
1284 // toolbox is initially in floating mode
1285 if ( ImplIsFloatingMode() )
1290 if (!(GetStyle() & WB_HIDE
))
1299 void ToolBox::dispose()
1301 // #103005# make sure our activate/deactivate balance is right
1302 while( mnActivateCount
> 0 )
1305 // terminate popupmode if the floating window is
1308 mpFloatWin
->EndPopupMode( FloatWinPopupEndFlags::Cancel
);
1309 mpFloatWin
= nullptr;
1311 // delete private data
1314 ImplSVData
* pSVData
= ImplGetSVData();
1315 delete pSVData
->maCtrlData
.mpTBDragMgr
;
1316 pSVData
->maCtrlData
.mpTBDragMgr
= nullptr;
1322 DockingWindow::dispose();
1325 ImplToolItem
* ToolBox::ImplGetItem( ToolBoxItemId nItemId
) const
1330 for (auto & item
: mpData
->m_aItems
)
1332 if ( item
.mnId
== nItemId
)
1339 static void ImplAddButtonBorder( tools::Long
&rWidth
, tools::Long
& rHeight
, bool bNativeButtons
)
1341 rWidth
+= SMALLBUTTON_HSIZE
;
1342 rHeight
+= SMALLBUTTON_VSIZE
;
1344 if( bNativeButtons
)
1346 // give more border space for rounded buttons
1352 bool ToolBox::ImplCalcItem()
1354 // recalc required ?
1358 OutputDevice
*pDefault
= Application::GetDefaultDevice();
1359 float fScaleFactor
= pDefault
? pDefault
->GetDPIScaleFactor() : 1.0;
1361 tools::Long nDefWidth
;
1362 tools::Long nDefHeight
;
1363 tools::Long nMaxWidth
= 0;
1364 tools::Long nMaxHeight
= 0;
1365 tools::Long nMinWidth
= 6;
1366 tools::Long nMinHeight
= 6;
1367 tools::Long nDropDownArrowWidth
= TB_DROPDOWNARROWWIDTH
* fScaleFactor
;
1369 nDropDownArrowWidth
*= 3;
1372 // set defaults if image or text is needed but empty
1373 nDefWidth
= GetDefaultImageSize().Width();
1374 nDefHeight
= GetDefaultImageSize().Height();
1377 // determine minimum size necessary in NWF
1379 tools::Rectangle
aRect( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1380 tools::Rectangle
aReg( aRect
);
1381 ImplControlValue aVal
;
1382 tools::Rectangle aNativeBounds
, aNativeContent
;
1383 if( IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
) )
1385 if( GetNativeControlRegion( ControlType::Toolbar
, ControlPart::Button
,
1387 ControlState::ENABLED
| ControlState::ROLLOVER
,
1389 aNativeBounds
, aNativeContent
) )
1391 aRect
= aNativeBounds
;
1392 if( aRect
.GetWidth() > nMinWidth
)
1393 nMinWidth
= aRect
.GetWidth();
1394 if( aRect
.GetHeight() > nMinHeight
)
1395 nMinHeight
= aRect
.GetHeight();
1396 if( nDropDownArrowWidth
< nMinWidth
)
1397 nDropDownArrowWidth
= nMinWidth
;
1398 if( nMinWidth
> mpData
->mnMenuButtonWidth
)
1399 mpData
->mnMenuButtonWidth
= nMinWidth
;
1400 else if( nMinWidth
< TB_MENUBUTTON_SIZE
)
1401 mpData
->mnMenuButtonWidth
= TB_MENUBUTTON_SIZE
;
1405 // also calculate the area for comboboxes, drop down list boxes and spinfields
1406 // as these are often inserted into toolboxes; set mnWinHeight to the
1407 // greater of those values to prevent toolbar flickering (#i103385#)
1408 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1410 if( GetNativeControlRegion( ControlType::Combobox
, ControlPart::Entire
,
1412 ControlState::ENABLED
| ControlState::ROLLOVER
,
1414 aNativeBounds
, aNativeContent
) )
1416 aRect
= aNativeBounds
;
1417 if( aRect
.GetHeight() > mnWinHeight
)
1418 mnWinHeight
= aRect
.GetHeight();
1420 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1422 if( GetNativeControlRegion( ControlType::Listbox
, ControlPart::Entire
,
1424 ControlState::ENABLED
| ControlState::ROLLOVER
,
1426 aNativeBounds
, aNativeContent
) )
1428 aRect
= aNativeBounds
;
1429 if( aRect
.GetHeight() > mnWinHeight
)
1430 mnWinHeight
= aRect
.GetHeight();
1432 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1434 if( GetNativeControlRegion( ControlType::Spinbox
, ControlPart::Entire
,
1436 ControlState::ENABLED
| ControlState::ROLLOVER
,
1438 aNativeBounds
, aNativeContent
) )
1440 aRect
= aNativeBounds
;
1441 if( aRect
.GetHeight() > mnWinHeight
)
1442 mnWinHeight
= aRect
.GetHeight();
1446 if ( ! mpData
->m_aItems
.empty() )
1448 for (auto & item
: mpData
->m_aItems
)
1450 item
.mbVisibleText
= false; // indicates if text will definitely be drawn, influences dropdown pos
1452 if ( item
.meType
== ToolBoxItemType::BUTTON
)
1457 // check if image and/or text exists
1458 bImage
= !!item
.maImage
;
1459 bText
= !item
.maText
.isEmpty();
1460 ButtonType tmpButtonType
= determineButtonType( &item
, meButtonType
); // default to toolbox setting
1461 if ( bImage
|| bText
)
1464 item
.mbEmptyBtn
= false;
1466 if ( tmpButtonType
== ButtonType::SYMBOLONLY
)
1468 // we're drawing images only
1469 if ( bImage
|| !bText
)
1471 item
.maItemSize
= item
.maImage
.GetSizePixel();
1475 item
.maItemSize
= Size( GetOutDev()->GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
,
1477 item
.mbVisibleText
= true;
1480 else if ( tmpButtonType
== ButtonType::TEXT
)
1482 // we're drawing text only
1483 if ( bText
|| !bImage
)
1485 item
.maItemSize
= Size( GetOutDev()->GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
,
1487 item
.mbVisibleText
= true;
1491 item
.maItemSize
= item
.maImage
.GetSizePixel();
1496 // we're drawing images and text
1497 item
.maItemSize
.setWidth( bText
? GetOutDev()->GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
: 0 );
1498 item
.maItemSize
.setHeight( bText
? GetTextHeight() : 0 );
1500 if ( meTextPosition
== ToolBoxTextPosition::Right
)
1502 // leave space between image and text
1504 item
.maItemSize
.AdjustWidth(TB_IMAGETEXTOFFSET
);
1506 // image and text side by side
1507 item
.maItemSize
.AdjustWidth(item
.maImage
.GetSizePixel().Width() );
1508 if ( item
.maImage
.GetSizePixel().Height() > item
.maItemSize
.Height() )
1509 item
.maItemSize
.setHeight( item
.maImage
.GetSizePixel().Height() );
1513 // leave space between image and text
1515 item
.maItemSize
.AdjustHeight(TB_IMAGETEXTOFFSET
);
1518 item
.maItemSize
.AdjustHeight(item
.maImage
.GetSizePixel().Height() );
1519 if ( item
.maImage
.GetSizePixel().Width() > item
.maItemSize
.Width() )
1520 item
.maItemSize
.setWidth( item
.maImage
.GetSizePixel().Width() );
1523 item
.mbVisibleText
= bText
;
1527 { // no image and no text
1528 item
.maItemSize
= Size( nDefWidth
, nDefHeight
);
1529 item
.mbEmptyBtn
= true;
1532 // save the content size
1533 item
.maContentSize
= item
.maItemSize
;
1535 // if required, take window height into consideration
1536 if ( item
.mpWindow
)
1538 tools::Long nHeight
= item
.mpWindow
->GetSizePixel().Height();
1539 if ( nHeight
> mnWinHeight
)
1540 mnWinHeight
= nHeight
;
1543 // add in drop down arrow
1544 if( item
.mnBits
& ToolBoxItemBits::DROPDOWN
)
1546 item
.maItemSize
.AdjustWidth(nDropDownArrowWidth
);
1547 item
.mnDropDownArrowWidth
= nDropDownArrowWidth
;
1550 // text items will be rotated in vertical mode
1551 // -> swap width and height
1552 if( item
.mbVisibleText
&& !mbHorz
)
1554 tools::Long tmp
= item
.maItemSize
.Width();
1555 item
.maItemSize
.setWidth( item
.maItemSize
.Height() );
1556 item
.maItemSize
.setHeight( tmp
);
1558 tmp
= item
.maContentSize
.Width();
1559 item
.maContentSize
.setWidth( item
.maContentSize
.Height() );
1560 item
.maContentSize
.setHeight( tmp
);
1563 else if ( item
.meType
== ToolBoxItemType::SPACE
)
1565 item
.maItemSize
= Size( nDefWidth
, nDefHeight
);
1566 item
.maContentSize
= item
.maItemSize
;
1569 if ( item
.meType
== ToolBoxItemType::BUTTON
|| item
.meType
== ToolBoxItemType::SPACE
)
1572 tools::Long w
= item
.maItemSize
.Width();
1573 tools::Long h
= item
.maItemSize
.Height();
1574 ImplAddButtonBorder( w
, h
, mpData
->mbNativeButtons
);
1575 item
.maItemSize
.setWidth(w
);
1576 item
.maItemSize
.setHeight(h
);
1578 if( item
.meType
== ToolBoxItemType::BUTTON
)
1580 tools::Long nMinW
= std::max(nMinWidth
, item
.maMinimalItemSize
.Width());
1581 tools::Long nMinH
= std::max(nMinHeight
, item
.maMinimalItemSize
.Height());
1583 tools::Long nGrowContentWidth
= 0;
1584 tools::Long nGrowContentHeight
= 0;
1586 if( item
.maItemSize
.Width() < nMinW
)
1588 nGrowContentWidth
= nMinW
- item
.maItemSize
.Width();
1589 item
.maItemSize
.setWidth( nMinW
);
1591 if( item
.maItemSize
.Height() < nMinH
)
1593 nGrowContentHeight
= nMinH
- item
.maItemSize
.Height();
1594 item
.maItemSize
.setHeight( nMinH
);
1597 // grow the content size by the additional available space
1598 item
.maContentSize
.AdjustWidth(nGrowContentWidth
);
1599 item
.maContentSize
.AdjustHeight(nGrowContentHeight
);
1602 // keep track of max item size
1603 if ( item
.maItemSize
.Width() > nMaxWidth
)
1604 nMaxWidth
= item
.maItemSize
.Width();
1605 if ( item
.maItemSize
.Height() > nMaxHeight
)
1606 nMaxHeight
= item
.maItemSize
.Height();
1612 nMaxWidth
= nDefWidth
;
1613 nMaxHeight
= nDefHeight
;
1615 ImplAddButtonBorder( nMaxWidth
, nMaxHeight
, mpData
->mbNativeButtons
);
1618 if( !ImplIsFloatingMode() && GetToolboxButtonSize() != ToolBoxButtonSize::DontCare
1619 && ( meTextPosition
== ToolBoxTextPosition::Right
) )
1621 // make sure all vertical toolbars have the same width and horizontal have the same height
1622 // this depends on the used button sizes
1623 // as this is used for alignment of multiple toolbars
1624 // it is only required for docked toolbars
1626 tools::Long nFixedWidth
= nDefWidth
+nDropDownArrowWidth
;
1627 tools::Long nFixedHeight
= nDefHeight
;
1628 ImplAddButtonBorder( nFixedWidth
, nFixedHeight
, mpData
->mbNativeButtons
);
1631 nMaxHeight
= nFixedHeight
;
1633 nMaxWidth
= nFixedWidth
;
1639 // do we have to recalc the sizes ?
1640 if ( (nMaxWidth
!= mnMaxItemWidth
) || (nMaxHeight
!= mnMaxItemHeight
) )
1642 mnMaxItemWidth
= nMaxWidth
;
1643 mnMaxItemHeight
= nMaxHeight
;
1651 ToolBox::ImplToolItems::size_type
ToolBox::ImplCalcBreaks( tools::Long nWidth
, sal_Int32
* pMaxLineWidth
, bool bCalcHorz
) const
1653 sal_uLong nLineStart
= 0;
1654 sal_uLong nGroupStart
= 0;
1655 tools::Long nLineWidth
= 0;
1656 tools::Long nCurWidth
;
1657 tools::Long nLastGroupLineWidth
= 0;
1658 tools::Long nMaxLineWidth
= 0;
1659 ImplToolItems::size_type nLines
= 1;
1661 bool bBreak
= false;
1662 tools::Long nWidthTotal
= nWidth
;
1663 tools::Long nMenuWidth
= 0;
1665 // when docked the menubutton will be in the first line
1666 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1667 nMenuWidth
= mpData
->maMenubuttonItem
.maItemSize
.Width();
1669 // we need to know which item is the last visible one to be able to add
1670 // the menu width in case we are unable to show all the items
1671 ImplToolItems::iterator it
, lastVisible
;
1672 for ( it
= mpData
->m_aItems
.begin(); it
!= mpData
->m_aItems
.end(); ++it
)
1674 if ( it
->mbVisible
)
1678 it
= mpData
->m_aItems
.begin();
1679 while ( it
!= mpData
->m_aItems
.end() )
1681 it
->mbBreak
= bBreak
;
1684 if ( it
->mbVisible
)
1690 if ( it
->meType
== ToolBoxItemType::BUTTON
|| it
->meType
== ToolBoxItemType::SPACE
)
1693 nCurWidth
= it
->maItemSize
.Width();
1695 nCurWidth
= it
->maItemSize
.Height();
1697 if ( it
->mpWindow
&& bCalcHorz
)
1699 tools::Long nWinItemWidth
= it
->mpWindow
->GetSizePixel().Width();
1700 if ( !mbScroll
|| (nWinItemWidth
<= nWidthTotal
) )
1702 nCurWidth
= nWinItemWidth
;
1707 if ( it
->mbEmptyBtn
)
1714 // in case we are able to show all the items, we do not want
1715 // to show the toolbar's menu; otherwise yes
1716 if ( ( ( it
== lastVisible
) && (nLineWidth
+nCurWidth
> nWidthTotal
) && mbScroll
) ||
1717 ( ( it
!= lastVisible
) && (nLineWidth
+nCurWidth
+nMenuWidth
> nWidthTotal
) && mbScroll
) )
1720 else if ( it
->meType
== ToolBoxItemType::SEPARATOR
)
1722 nCurWidth
= it
->mnSepSize
;
1723 if ( !ImplIsFloatingMode() && ( it
!= lastVisible
) && (nLineWidth
+nCurWidth
+nMenuWidth
> nWidthTotal
) )
1726 // treat breaks as separators, except when using old style toolbars (ie. no menu button)
1727 else if ( (it
->meType
== ToolBoxItemType::BREAK
) && !IsMenuEnabled() )
1734 // Add break before the entire group or take group apart?
1735 if ( (it
->meType
== ToolBoxItemType::BREAK
) ||
1736 (nLineStart
== nGroupStart
) )
1738 if ( nLineWidth
> nMaxLineWidth
)
1739 nMaxLineWidth
= nLineWidth
;
1742 nLineStart
= it
- mpData
->m_aItems
.begin();
1743 nGroupStart
= nLineStart
;
1749 if ( nLastGroupLineWidth
> nMaxLineWidth
)
1750 nMaxLineWidth
= nLastGroupLineWidth
;
1752 // if the break is added before the group, set it to
1753 // beginning of line and re-calculate
1755 nLineStart
= nGroupStart
;
1756 it
= mpData
->m_aItems
.begin() + nGroupStart
;
1762 if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
1764 if ( (it
->meType
!= ToolBoxItemType::BUTTON
) || bWindow
)
1766 // found separator or break
1767 nLastGroupLineWidth
= nLineWidth
;
1768 nGroupStart
= it
- mpData
->m_aItems
.begin();
1775 nLineWidth
+= nCurWidth
;
1781 if ( pMaxLineWidth
)
1783 if ( nLineWidth
> nMaxLineWidth
)
1784 nMaxLineWidth
= nLineWidth
;
1786 if( ImplIsFloatingMode() && !ImplIsInPopupMode() )
1788 // leave enough space to display buttons in the decoration
1789 tools::Long aMinWidth
= 2 * GetSettings().GetStyleSettings().GetFloatTitleHeight();
1790 if( nMaxLineWidth
< aMinWidth
)
1791 nMaxLineWidth
= aMinWidth
;
1793 *pMaxLineWidth
= nMaxLineWidth
;
1799 Size
ToolBox::ImplGetOptimalFloatingSize()
1801 if( !ImplIsFloatingMode() )
1804 Size
aCurrentSize( mnDX
, mnDY
);
1805 Size
aSize1( aCurrentSize
);
1806 Size
aSize2( aCurrentSize
);
1808 // try to preserve current height
1810 // calc number of floating lines for current window height
1811 ImplToolItems::size_type nFloatLinesHeight
= ImplCalcLines( mnDY
);
1812 // calc window size according to this number
1813 aSize1
= ImplCalcFloatSize( nFloatLinesHeight
);
1815 if( aCurrentSize
== aSize1
)
1818 // try to preserve current width
1820 tools::Long nLineHeight
= std::max( mnWinHeight
, mnMaxItemHeight
);
1821 int nBorderX
= 2*TB_BORDER_OFFSET1
+ mnLeftBorder
+ mnRightBorder
;
1822 int nBorderY
= 2*TB_BORDER_OFFSET2
+ mnTopBorder
+ mnBottomBorder
;
1823 Size
aSz( aCurrentSize
);
1825 ImplToolItems::size_type nLines
= ImplCalcBreaks( aSz
.Width()-nBorderX
, &maxX
, mbHorz
);
1827 ImplToolItems::size_type manyLines
= 1000;
1828 Size aMinimalFloatSize
= ImplCalcFloatSize( manyLines
);
1830 aSz
.setHeight( nBorderY
+ nLineHeight
* nLines
);
1831 // line space when more than one line
1832 if ( mbLineSpacing
)
1833 aSz
.AdjustHeight((nLines
-1)*TB_LINESPACING
);
1835 aSz
.setWidth( nBorderX
+ maxX
);
1837 // avoid clipping of any items
1838 if( aSz
.Width() < aMinimalFloatSize
.Width() )
1839 aSize2
= ImplCalcFloatSize( nLines
);
1843 if( aCurrentSize
== aSize2
)
1846 // set the size with the smallest delta as the current size
1847 tools::Long dx1
= std::abs( mnDX
- aSize1
.Width() );
1848 tools::Long dy1
= std::abs( mnDY
- aSize1
.Height() );
1850 tools::Long dx2
= std::abs( mnDX
- aSize2
.Width() );
1851 tools::Long dy2
= std::abs( mnDY
- aSize2
.Height() );
1853 if( dx1
*dy1
< dx2
*dy2
)
1854 aCurrentSize
= aSize1
;
1856 aCurrentSize
= aSize2
;
1858 return aCurrentSize
;
1863 void lcl_hideDoubleSeparators( ToolBox::ImplToolItems
& rItems
)
1865 bool bLastSep( true );
1866 ToolBox::ImplToolItems::iterator it
;
1867 for ( it
= rItems
.begin(); it
!= rItems
.end(); ++it
)
1869 if ( it
->meType
== ToolBoxItemType::SEPARATOR
)
1871 it
->mbVisible
= false;
1874 // check if any visible items have to appear behind it
1875 if (std::any_of(it
+ 1, rItems
.end(), [](const ImplToolItem
& rItem
) {
1876 return (rItem
.meType
== ToolBoxItemType::BUTTON
) && rItem
.mbVisible
; }))
1877 it
->mbVisible
= true;
1881 else if ( it
->mbVisible
)
1887 void ToolBox::ImplFormat( bool bResize
)
1889 // Has to re-formatted
1893 mpData
->ImplClearLayoutData();
1895 // recalculate positions and sizes
1896 tools::Rectangle aEmptyRect
;
1897 tools::Long nLineSize
;
1900 tools::Long nMax
; // width of layoutarea in pixels
1901 ImplToolItems::size_type nFormatLine
;
1902 bool bMustFullPaint
;
1904 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
1905 bool bIsInPopupMode
= ImplIsInPopupMode();
1907 maFloatSizes
.clear();
1909 // compute border sizes
1910 ImplCalcBorder( meAlign
, mnLeftBorder
, mnTopBorder
, mnRightBorder
, mnBottomBorder
);
1912 // update drag area (where the 'grip' will be placed)
1913 tools::Rectangle aOldDragRect
;
1915 aOldDragRect
= pWrapper
->GetDragArea();
1916 ImplUpdateDragArea();
1918 bMustFullPaint
= ImplCalcItem();
1920 // calculate new size during interactive resize or
1921 // set computed size when formatting only
1922 if ( ImplIsFloatingMode() )
1925 mnFloatLines
= ImplCalcLines( mnDY
);
1927 SetOutputSizePixel( ImplGetOptimalFloatingSize() );
1933 tools::Long nBottom
;
1934 // nLineSize: height of a single line, will fit highest item
1935 nLineSize
= mnMaxItemHeight
;
1937 if ( mnWinHeight
> mnMaxItemHeight
)
1938 nLineSize
= mnWinHeight
;
1943 mnVisLines
= ImplCalcLines( mnDY
);
1947 // layout over all lines
1948 mnVisLines
= mnLines
;
1949 nMax
= TB_MAXNOSCROLL
;
1952 // add in all border offsets
1953 if ( mnWinStyle
& WB_BORDER
)
1955 nLeft
= TB_BORDER_OFFSET1
+ mnLeftBorder
;
1956 nTop
= TB_BORDER_OFFSET2
+ mnTopBorder
;
1957 nBottom
= TB_BORDER_OFFSET1
+ mnBottomBorder
;
1958 nMax
-= nLeft
+ TB_BORDER_OFFSET1
+ mnRightBorder
;
1967 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
1968 // we have to center all items in the window height
1969 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1971 tools::Long nWinHeight
= mnDY
- nTop
- nBottom
;
1972 if( nWinHeight
> nLineSize
)
1973 nLineSize
= nWinHeight
;
1979 nLineSize
= mnMaxItemWidth
;
1983 mnVisLines
= ImplCalcLines( mnDX
);
1988 mnVisLines
= mnLines
;
1989 nMax
= TB_MAXNOSCROLL
;
1992 if ( mnWinStyle
& WB_BORDER
)
1994 nTop
= TB_BORDER_OFFSET1
+ mnTopBorder
;
1995 nLeft
= TB_BORDER_OFFSET2
+ mnLeftBorder
;
1996 nRight
= TB_BORDER_OFFSET2
+ mnRightBorder
;
1997 nMax
-= nTop
+ TB_BORDER_OFFSET1
+ mnBottomBorder
;
2006 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
2007 // we have to center all items in the window height
2008 if( !ImplIsFloatingMode() && IsMenuEnabled() )
2010 tools::Long nWinWidth
= mnDX
- nLeft
- nRight
;
2011 if( nWinWidth
> nLineSize
)
2012 nLineSize
= nWinWidth
;
2016 // no calculation if the window has no size (nMax=0)
2017 // non scrolling toolboxes must be computed though
2018 if ( (nMax
<= 0) && mbScroll
)
2024 for (auto & item
: mpData
->m_aItems
)
2026 item
.maRect
= aEmptyRect
;
2029 maLowerRect
= aEmptyRect
;
2030 maUpperRect
= aEmptyRect
;
2034 // init start values
2035 tools::Long nX
= nLeft
; // top-left offset
2036 tools::Long nY
= nTop
;
2039 // save old scroll rectangles and reset them
2040 tools::Rectangle aOldLowerRect
= maLowerRect
;
2041 tools::Rectangle aOldUpperRect
= maUpperRect
;
2042 tools::Rectangle aOldMenubuttonRect
= mpData
->maMenubuttonItem
.maRect
;
2043 maUpperRect
= aEmptyRect
;
2044 maLowerRect
= aEmptyRect
;
2045 mpData
->maMenubuttonItem
.maRect
= aEmptyRect
;
2047 // do we have any toolbox items at all ?
2048 if ( !mpData
->m_aItems
.empty() || IsMenuEnabled() )
2050 lcl_hideDoubleSeparators( mpData
->m_aItems
);
2052 // compute line breaks and visible lines give the current window width (nMax)
2053 // the break indicators will be stored within each item (it->mbBreak)
2054 mnCurLines
= ImplCalcBreaks( nMax
, nullptr, mbHorz
);
2056 // check for scrollbar buttons or dropdown menu
2057 // (if a menu is enabled, this will be used to store clipped
2058 // items and no scroll buttons will appear)
2059 if ( (!ImplIsFloatingMode() && (mnCurLines
> mnVisLines
) && mbScroll
) ||
2062 // compute linebreaks again, incorporating scrollbar buttons
2063 if( !IsMenuEnabled() )
2065 nMax
-= TB_SPIN_SIZE
+TB_SPIN_OFFSET
;
2066 mnCurLines
= ImplCalcBreaks( nMax
, nullptr, mbHorz
);
2069 // compute scroll rectangles or menu button
2072 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2074 if( !ImplIsFloatingMode() )
2076 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
- 2 );
2077 mpData
->maMenubuttonItem
.maRect
.SetTop( nTop
);
2078 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2082 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
- mnRightBorder
-TB_BORDER_OFFSET1
-1 );
2083 mpData
->maMenubuttonItem
.maRect
.SetTop( nTop
);
2084 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2086 mpData
->maMenubuttonItem
.maRect
.SetLeft( mpData
->maMenubuttonItem
.maRect
.Right() - mpData
->mnMenuButtonWidth
);
2090 maUpperRect
.SetLeft( nLeft
+nMax
+TB_SPIN_OFFSET
);
2091 maUpperRect
.SetRight( maUpperRect
.Left()+TB_SPIN_SIZE
-1 );
2092 maUpperRect
.SetTop( nTop
);
2093 maLowerRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2094 maLowerRect
.SetLeft( maUpperRect
.Left() );
2095 maLowerRect
.SetRight( maUpperRect
.Right() );
2096 maUpperRect
.SetBottom( maUpperRect
.Top() +
2097 (maLowerRect
.Bottom()-maUpperRect
.Top())/2 );
2098 maLowerRect
.SetTop( maUpperRect
.Bottom() );
2103 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2105 if( !ImplIsFloatingMode() )
2107 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
- 2 );
2108 mpData
->maMenubuttonItem
.maRect
.SetLeft( nLeft
);
2109 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2113 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
- mnBottomBorder
-TB_BORDER_OFFSET1
-1 );
2114 mpData
->maMenubuttonItem
.maRect
.SetLeft( nLeft
);
2115 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2117 mpData
->maMenubuttonItem
.maRect
.SetTop( mpData
->maMenubuttonItem
.maRect
.Bottom() - mpData
->mnMenuButtonWidth
);
2121 maUpperRect
.SetTop( nTop
+nMax
+TB_SPIN_OFFSET
);
2122 maUpperRect
.SetBottom( maUpperRect
.Top()+TB_SPIN_SIZE
-1 );
2123 maUpperRect
.SetLeft( nLeft
);
2124 maLowerRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2125 maLowerRect
.SetTop( maUpperRect
.Top() );
2126 maLowerRect
.SetBottom( maUpperRect
.Bottom() );
2127 maUpperRect
.SetRight( maUpperRect
.Left() +
2128 (maLowerRect
.Right()-maUpperRect
.Left())/2 );
2129 maLowerRect
.SetLeft( maUpperRect
.Right() );
2134 // no scrolling when there is a "more"-menu
2135 // anything will "fit" in a single line then
2136 if( IsMenuEnabled() )
2139 // determine the currently visible line
2140 if ( mnVisLines
>= mnCurLines
)
2142 else if ( mnCurLine
+mnVisLines
-1 > mnCurLines
)
2143 mnCurLine
= mnCurLines
- (mnVisLines
-1);
2145 tools::Long firstItemCenter
= 0;
2146 for (auto & item
: mpData
->m_aItems
)
2148 item
.mbShowWindow
= false;
2150 // check for line break and advance nX/nY accordingly
2155 // increment starting with the second line
2156 if ( nFormatLine
> mnCurLine
)
2161 if ( mbLineSpacing
)
2162 nY
+= nLineSize
+TB_LINESPACING
;
2169 if ( mbLineSpacing
)
2170 nX
+= nLineSize
+TB_LINESPACING
;
2177 if ( !item
.mbVisible
|| (nFormatLine
< mnCurLine
) ||
2178 (nFormatLine
> mnCurLine
+mnVisLines
-1) )
2179 // item is not visible
2180 item
.maCalcRect
= aEmptyRect
;
2183 // 1. determine current item width/height
2184 // take window size and orientation into account, because this affects the size of item windows
2186 Size
aCurrentItemSize( item
.GetSize( mbHorz
, mbScroll
, nMax
, Size(mnMaxItemWidth
, mnMaxItemHeight
) ) );
2188 // 2. position item rect and use size from step 1
2189 // items will be centered horizontally (if mbHorz) or vertically
2190 // advance nX and nY accordingly
2194 // In special mode Locked horizontal positions of all items remain unchanged.
2196 if ( mbIsArranged
&& meLayoutMode
== ToolBoxLayoutMode::Locked
&& mnLines
== 1 && item
.maRect
.Left() > 0 )
2197 nX
= item
.maRect
.Left();
2198 item
.maCalcRect
.SetLeft( nX
);
2200 // In special mode Locked first item's vertical position remains unchanged. Consecutive items vertical
2201 // positions are centered around first item's vertical position. If an item's height exceeds available
2202 // space, item's vertical position remains unchanged too.
2204 if ( mbIsArranged
&& meLayoutMode
== ToolBoxLayoutMode::Locked
&& mnLines
== 1 )
2205 if ( firstItemCenter
> 0 )
2206 if ( firstItemCenter
-aCurrentItemSize
.Height()/2 > nY
)
2207 item
.maCalcRect
.SetTop( firstItemCenter
-aCurrentItemSize
.Height()/2 );
2209 item
.maCalcRect
.SetTop( item
.maRect
.Top() );
2212 item
.maCalcRect
.SetTop( item
.maRect
.Top() );
2213 firstItemCenter
= item
.maRect
.Top()+aCurrentItemSize
.Height()/2;
2216 item
.maCalcRect
.SetTop( nY
+(nLineSize
-aCurrentItemSize
.Height())/2 );
2217 item
.maCalcRect
.SetRight( nX
+aCurrentItemSize
.Width()-1 );
2218 item
.maCalcRect
.SetBottom( item
.maCalcRect
.Top()+aCurrentItemSize
.Height()-1 );
2219 nX
+= aCurrentItemSize
.Width();
2223 item
.maCalcRect
.SetLeft( nX
+(nLineSize
-aCurrentItemSize
.Width())/2 );
2224 item
.maCalcRect
.SetTop( nY
);
2225 item
.maCalcRect
.SetRight( item
.maCalcRect
.Left()+aCurrentItemSize
.Width()-1 );
2226 item
.maCalcRect
.SetBottom( nY
+aCurrentItemSize
.Height()-1 );
2227 nY
+= aCurrentItemSize
.Height();
2231 // position window items into calculated item rect
2232 if ( item
.mpWindow
)
2234 if ( item
.mbShowWindow
)
2236 Point
aPos( item
.maCalcRect
.Left(), item
.maCalcRect
.Top() );
2238 assert( item
.maCalcRect
.Top() >= 0 );
2240 item
.mpWindow
->SetPosPixel( aPos
);
2241 item
.mpWindow
->Show();
2244 item
.mpWindow
->Hide();
2246 } // end of loop over all items
2247 mbIsArranged
= true;
2250 // we have no toolbox items
2253 if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2255 // custom menu will be the last button in floating mode
2256 ImplToolItem
&rIt
= mpData
->maMenubuttonItem
;
2260 rIt
.maRect
.SetLeft( nX
+TB_MENUBUTTON_OFFSET
);
2261 rIt
.maRect
.SetTop( nY
);
2262 rIt
.maRect
.SetRight( rIt
.maRect
.Left() + mpData
->mnMenuButtonWidth
);
2263 rIt
.maRect
.SetBottom( nY
+nLineSize
-1 );
2264 nX
+= rIt
.maItemSize
.Width();
2268 rIt
.maRect
.SetLeft( nX
);
2269 rIt
.maRect
.SetTop( nY
+TB_MENUBUTTON_OFFSET
);
2270 rIt
.maRect
.SetRight( nX
+nLineSize
-1 );
2271 rIt
.maRect
.SetBottom( rIt
.maRect
.Top() + mpData
->mnMenuButtonWidth
);
2272 nY
+= rIt
.maItemSize
.Height();
2276 // if toolbox visible trigger paint for changed regions
2277 if ( IsVisible() && !mbFullPaint
)
2279 if ( bMustFullPaint
)
2281 maPaintRect
= tools::Rectangle( mnLeftBorder
, mnTopBorder
,
2282 mnDX
-mnRightBorder
, mnDY
-mnBottomBorder
);
2286 if ( aOldLowerRect
!= maLowerRect
)
2288 maPaintRect
.Union( maLowerRect
);
2289 maPaintRect
.Union( aOldLowerRect
);
2291 if ( aOldUpperRect
!= maUpperRect
)
2293 maPaintRect
.Union( maUpperRect
);
2294 maPaintRect
.Union( aOldUpperRect
);
2296 if ( aOldMenubuttonRect
!= mpData
->maMenubuttonItem
.maRect
)
2298 maPaintRect
.Union( mpData
->maMenubuttonItem
.maRect
);
2299 maPaintRect
.Union( aOldMenubuttonRect
);
2301 if ( pWrapper
&& aOldDragRect
!= pWrapper
->GetDragArea() )
2303 maPaintRect
.Union( pWrapper
->GetDragArea() );
2304 maPaintRect
.Union( aOldDragRect
);
2307 for (auto const& item
: mpData
->m_aItems
)
2309 if ( item
.maRect
!= item
.maCalcRect
)
2311 maPaintRect
.Union( item
.maRect
);
2312 maPaintRect
.Union( item
.maCalcRect
);
2317 Invalidate( maPaintRect
);
2320 // store the new calculated item rects
2321 maPaintRect
= aEmptyRect
;
2322 for (auto & item
: mpData
->m_aItems
)
2323 item
.maRect
= item
.maCalcRect
;
2326 // indicate formatting is done
2330 IMPL_LINK_NOARG(ToolBox
, ImplDropdownLongClickHdl
, Timer
*, void)
2332 if (mnCurPos
== ITEM_NOTFOUND
||
2333 !(mpData
->m_aItems
[ mnCurPos
].mnBits
& ToolBoxItemBits::DROPDOWN
))
2336 mpData
->mbDropDownByKeyboard
= false;
2337 mpData
->maDropdownClickHdl
.Call( this );
2339 // do not reset data if the dropdown handler opened a floating window
2340 // see ImplFloatControl()
2343 // no floater was opened
2345 InvalidateItem(mnCurPos
);
2347 mnCurPos
= ITEM_NOTFOUND
;
2348 mnCurItemId
= ToolBoxItemId(0);
2349 mnDownItemId
= ToolBoxItemId(0);
2350 mnMouseModifier
= 0;
2351 mnHighItemId
= ToolBoxItemId(0);
2355 IMPL_LINK_NOARG(ToolBox
, ImplUpdateHdl
, Timer
*, void)
2358 if( mbFormat
&& mpData
)
2362 static void ImplDrawMoreIndicator(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
2364 const Image
pImage(StockImage::Yes
, CHEVRON
);
2365 Size aImageSize
= pImage
.GetSizePixel();
2366 tools::Long x
= rRect
.Left() + (rRect
.getOpenWidth() - aImageSize
.Width())/2;
2367 tools::Long y
= rRect
.Top() + (rRect
.getOpenHeight() - aImageSize
.Height())/2;
2368 DrawImageFlags nImageStyle
= DrawImageFlags::NONE
;
2370 rRenderContext
.DrawImage(Point(x
,y
), pImage
, nImageStyle
);
2373 static void ImplDrawDropdownArrow(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rDropDownRect
, bool bSetColor
, bool bRotate
)
2375 bool bLineColor
= rRenderContext
.IsLineColor();
2376 bool bFillColor
= rRenderContext
.IsFillColor();
2377 Color aOldFillColor
= rRenderContext
.GetFillColor();
2378 Color aOldLineColor
= rRenderContext
.GetLineColor();
2379 rRenderContext
.SetLineColor();
2383 if (rRenderContext
.GetSettings().GetStyleSettings().GetFaceColor().IsDark())
2384 rRenderContext
.SetFillColor(COL_WHITE
);
2386 rRenderContext
.SetFillColor(COL_BLACK
);
2389 tools::Polygon
aPoly(4);
2391 // the assumption is, that the width always specifies the size of the expected arrow.
2392 const tools::Long nMargin
= round(2 * rRenderContext
.GetDPIScaleFactor());
2393 const tools::Long nSize
= rDropDownRect
.getOpenWidth() - 2 * nMargin
;
2394 const tools::Long nHalfSize
= (nSize
+ 1) / 2;
2395 const tools::Long x
= rDropDownRect
.Left() + nMargin
+ (bRotate
? (rDropDownRect
.getOpenWidth() - nHalfSize
) / 2 : 0);
2396 const tools::Long y
= rDropDownRect
.Top() + nMargin
+ (rDropDownRect
.getOpenHeight() - (bRotate
? nSize
: nHalfSize
)) / 2;
2398 aPoly
.SetPoint(Point(x
, y
), 0);
2401 aPoly
.SetPoint(Point(x
, y
+ nSize
), 1);
2402 aPoly
.SetPoint(Point(x
+ nHalfSize
, y
+ nHalfSize
), 2);
2406 aPoly
.SetPoint(Point(x
+ nHalfSize
, y
+ nHalfSize
), 1);
2407 aPoly
.SetPoint(Point(x
+ nSize
, y
), 2);
2409 aPoly
.SetPoint(Point(x
, y
), 3);
2411 auto aaflags
= rRenderContext
.GetAntialiasing();
2412 rRenderContext
.SetAntialiasing(AntialiasingFlags::Enable
);
2413 rRenderContext
.DrawPolygon( aPoly
);
2414 rRenderContext
.SetAntialiasing(aaflags
);
2417 rRenderContext
.SetFillColor(aOldFillColor
);
2419 rRenderContext
.SetFillColor();
2421 rRenderContext
.SetLineColor(aOldLineColor
);
2423 rRenderContext
.SetLineColor();
2426 void ToolBox::ImplDrawMenuButton(vcl::RenderContext
& rRenderContext
, bool bHighlight
)
2428 if (mpData
->maMenubuttonItem
.maRect
.IsEmpty())
2431 // #i53937# paint menu button only if necessary
2432 if (!ImplHasClippedItems())
2435 // execute pending paint requests
2438 rRenderContext
.Push(vcl::PushFlags::FILLCOLOR
| vcl::PushFlags::LINECOLOR
);
2440 // draw the 'more' indicator / button (>>)
2441 ImplErase(rRenderContext
, mpData
->maMenubuttonItem
.maRect
, bHighlight
);
2444 ImplDrawButton(rRenderContext
, mpData
->maMenubuttonItem
.maRect
, 2, false, true, false );
2446 if (ImplHasClippedItems())
2447 ImplDrawMoreIndicator(rRenderContext
, mpData
->maMenubuttonItem
.maRect
);
2449 // store highlight state
2450 mpData
->mbMenubuttonSelected
= bHighlight
;
2453 rRenderContext
.Pop();
2456 void ToolBox::ImplDrawSpin(vcl::RenderContext
& rRenderContext
)
2461 if ( maUpperRect
.IsEmpty() || maLowerRect
.IsEmpty() )
2464 bTmpUpper
= mnCurLine
> 1;
2466 bTmpLower
= mnCurLine
+mnVisLines
-1 < mnCurLines
;
2474 ImplDrawUpDownButtons(rRenderContext
, maUpperRect
, maLowerRect
,
2475 false/*bUpperIn*/, false/*bLowerIn*/, bTmpUpper
, bTmpLower
, !mbHorz
);
2478 void ToolBox::ImplDrawSeparator(vcl::RenderContext
& rRenderContext
, ImplToolItems::size_type nPos
, const tools::Rectangle
& rRect
)
2480 if ( nPos
>= mpData
->m_aItems
.size() - 1 )
2481 // no separator if it's the last item
2484 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPos
];
2485 ImplToolItem
* pPreviousItem
= &mpData
->m_aItems
[nPos
-1];
2486 ImplToolItem
* pNextItem
= &mpData
->m_aItems
[nPos
+1];
2488 if ( ( pPreviousItem
->mbShowWindow
&& pNextItem
->mbShowWindow
) || pNextItem
->mbBreak
)
2489 // no separator between two windows or before a break
2492 bool bNativeOk
= false;
2493 ControlPart nPart
= IsHorizontal() ? ControlPart::SeparatorVert
: ControlPart::SeparatorHorz
;
2494 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, nPart
))
2496 ImplControlValue aControlValue
;
2497 bNativeOk
= rRenderContext
.DrawNativeControl(ControlType::Toolbar
, nPart
, rRect
, ControlState::NONE
, aControlValue
, OUString());
2500 /* Draw the widget only if it can't be drawn natively. */
2504 tools::Long nCenterPos
, nSlim
;
2505 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
2506 rRenderContext
.SetLineColor(rStyleSettings
.GetSeparatorColor());
2509 nSlim
= (pItem
->maRect
.Bottom() - pItem
->maRect
.Top ()) / 4;
2510 nCenterPos
= pItem
->maRect
.Center().X();
2511 rRenderContext
.DrawLine(Point(nCenterPos
, pItem
->maRect
.Top() + nSlim
),
2512 Point(nCenterPos
, pItem
->maRect
.Bottom() - nSlim
));
2516 nSlim
= (pItem
->maRect
.Right() - pItem
->maRect
.Left ()) / 4;
2517 nCenterPos
= pItem
->maRect
.Center().Y();
2518 rRenderContext
.DrawLine(Point(pItem
->maRect
.Left() + nSlim
, nCenterPos
),
2519 Point(pItem
->maRect
.Right() - nSlim
, nCenterPos
));
2523 void ToolBox::ImplDrawButton(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&rRect
, sal_uInt16 highlight
,
2524 bool bChecked
, bool bEnabled
, bool bIsWindow
)
2526 // draws toolbar button background either native or using a coloured selection
2527 // if bIsWindow is true, the corresponding item is a control and only a selection border will be drawn
2529 bool bNativeOk
= false;
2530 if( !bIsWindow
&& rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
) )
2532 ImplControlValue aControlValue
;
2533 ControlState nState
= ControlState::NONE
;
2535 if ( highlight
== 1 ) nState
|= ControlState::PRESSED
;
2536 if ( highlight
== 2 ) nState
|= ControlState::ROLLOVER
;
2537 if ( bEnabled
) nState
|= ControlState::ENABLED
;
2539 aControlValue
.setTristateVal( bChecked
? ButtonValue::On
: ButtonValue::Off
);
2541 bNativeOk
= rRenderContext
.DrawNativeControl( ControlType::Toolbar
, ControlPart::Button
,
2542 rRect
, nState
, aControlValue
, OUString() );
2546 vcl::RenderTools::DrawSelectionBackground(rRenderContext
, *this, rRect
, bIsWindow
? 3 : highlight
,
2547 bChecked
, true, bIsWindow
, nullptr, 2);
2550 void ToolBox::ImplDrawItem(vcl::RenderContext
& rRenderContext
, ImplToolItems::size_type nPos
, sal_uInt16 nHighlight
)
2552 if (nPos
>= mpData
->m_aItems
.size())
2555 // execute pending paint requests
2558 rRenderContext
.SetFillColor();
2560 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPos
];
2562 if (!pItem
->mbEnabled
)
2565 // if the rectangle is outside visible area
2566 if (pItem
->maRect
.IsEmpty())
2569 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
2571 // no gradient background for items that have a popup open
2572 bool bHasOpenPopup
= mpFloatWin
&& (mnDownItemId
==pItem
->mnId
);
2574 bool bHighContrastWhite
= false;
2575 // check the face color as highcontrast indicator
2576 // because the toolbox itself might have a gradient
2577 if (rStyleSettings
.GetFaceColor() == COL_WHITE
)
2578 bHighContrastWhite
= true;
2580 // Compute buttons area.
2581 Size aBtnSize
= pItem
->maRect
.GetSize();
2583 /* Compute the button/separator rectangle here, we'll need it for
2584 * both the buttons and the separators. */
2585 tools::Rectangle
aButtonRect( pItem
->maRect
.TopLeft(), aBtnSize
);
2586 tools::Long nOffX
= SMALLBUTTON_OFF_NORMAL_X
;
2587 tools::Long nOffY
= SMALLBUTTON_OFF_NORMAL_Y
;
2588 tools::Long nImageOffX
= 0;
2589 tools::Long nImageOffY
= 0;
2590 DrawButtonFlags nStyle
= DrawButtonFlags::NONE
;
2593 if ( (pItem
->meType
== ToolBoxItemType::SEPARATOR
) && nPos
> 0 )
2595 ImplDrawSeparator(rRenderContext
, nPos
, aButtonRect
);
2598 // do nothing if item is no button or will be displayed as window
2599 if ( (pItem
->meType
!= ToolBoxItemType::BUTTON
) || pItem
->mbShowWindow
)
2602 if ( pItem
->meState
== TRISTATE_TRUE
)
2604 nStyle
|= DrawButtonFlags::Checked
;
2606 else if ( pItem
->meState
== TRISTATE_INDET
)
2608 nStyle
|= DrawButtonFlags::DontKnow
;
2610 if ( nHighlight
== 1 )
2612 nStyle
|= DrawButtonFlags::Pressed
;
2615 ImplErase(rRenderContext
, pItem
->maRect
, nHighlight
!= 0, bHasOpenPopup
);
2617 nOffX
+= pItem
->maRect
.Left();
2618 nOffY
+= pItem
->maRect
.Top();
2620 // determine what has to be drawn on the button: image, text or both
2623 ButtonType tmpButtonType
= determineButtonType( pItem
, meButtonType
); // default to toolbox setting
2624 pItem
->DetermineButtonDrawStyle( tmpButtonType
, bImage
, bText
);
2626 // compute output values
2627 tools::Long nBtnWidth
= aBtnSize
.Width()-SMALLBUTTON_HSIZE
;
2628 tools::Long nBtnHeight
= aBtnSize
.Height()-SMALLBUTTON_VSIZE
;
2631 const bool bDropDown
= (pItem
->mnBits
& ToolBoxItemBits::DROPDOWN
) == ToolBoxItemBits::DROPDOWN
;
2632 tools::Rectangle aDropDownRect
;
2634 aDropDownRect
= pItem
->GetDropDownRect(mbHorz
);
2638 const Image
* pImage
= &(pItem
->maImage
);
2639 aImageSize
= pImage
->GetSizePixel();
2641 // determine drawing flags
2642 DrawImageFlags nImageStyle
= DrawImageFlags::NONE
;
2644 if ( !pItem
->mbEnabled
|| !IsEnabled() )
2645 nImageStyle
|= DrawImageFlags::Disable
;
2647 // #i35563# the dontknow state indicates different states at the same time
2648 // which should not be rendered disabled but normal
2653 if ( ( (pItem
->mnBits
& (ToolBoxItemBits::LEFT
|ToolBoxItemBits::DROPDOWN
)) || bText
)
2654 && ( meTextPosition
== ToolBoxTextPosition::Right
) )
2656 // left align also to leave space for drop down arrow
2657 // and when drawing text+image
2658 // just center in y, except for vertical (ie rotated text)
2659 if( mbHorz
|| !bText
)
2660 nImageOffY
+= (nBtnHeight
-aImageSize
.Height())/2;
2664 nImageOffX
+= (nBtnWidth
-(bDropDown
? aDropDownRect
.getOpenWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X
-aImageSize
.Width())/2;
2665 if ( meTextPosition
== ToolBoxTextPosition::Right
)
2666 nImageOffY
+= (nBtnHeight
-aImageSize
.Height())/2;
2668 if ( nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) )
2671 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2673 ImplDrawButton(rRenderContext
, aButtonRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2674 pItem
->mbEnabled
&& IsEnabled(), pItem
->mbShowWindow
);
2676 if( nHighlight
!= 0 )
2678 if( bHighContrastWhite
)
2679 nImageStyle
|= DrawImageFlags::ColorTransform
;
2682 rRenderContext
.DrawImage(Point( nImageOffX
, nImageOffY
), *pImage
, nImageStyle
);
2686 bool bRotate
= false;
2689 const Size
aTxtSize(GetOutDev()->GetCtrlTextWidth(pItem
->maText
), GetTextHeight());
2690 tools::Long nTextOffX
= nOffX
;
2691 tools::Long nTextOffY
= nOffY
;
2693 // rotate text when vertically docked
2694 vcl::Font aOldFont
= rRenderContext
.GetFont();
2695 if( pItem
->mbVisibleText
&& !ImplIsFloatingMode() &&
2696 ((meAlign
== WindowAlign::Left
) || (meAlign
== WindowAlign::Right
)) )
2700 vcl::Font aRotateFont
= aOldFont
;
2701 aRotateFont
.SetOrientation( 2700_deg10
);
2703 // center horizontally
2704 nTextOffX
+= aTxtSize
.Height();
2705 nTextOffX
+= (nBtnWidth
-aTxtSize
.Height())/2;
2707 // add in image offset
2709 nTextOffY
= nImageOffY
+ aImageSize
.Height() + TB_IMAGETEXTOFFSET
;
2711 rRenderContext
.SetFont(aRotateFont
);
2715 if ( meTextPosition
== ToolBoxTextPosition::Right
)
2717 // center vertically
2718 nTextOffY
+= (nBtnHeight
-aTxtSize
.Height())/2;
2720 // add in image offset
2722 nTextOffX
= nImageOffX
+ aImageSize
.Width() + TB_IMAGETEXTOFFSET
;
2726 // center horizontally
2727 nTextOffX
+= (nBtnWidth
-(bDropDown
? aDropDownRect
.getOpenWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X
-aTxtSize
.Width() - TB_IMAGETEXTOFFSET
)/2;
2728 // set vertical position
2729 nTextOffY
+= nBtnHeight
- aTxtSize
.Height();
2733 // draw selection only if not already drawn during image output (see above)
2734 if ( !bImage
&& (nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) ) )
2737 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2739 ImplDrawButton(rRenderContext
, pItem
->maRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2740 pItem
->mbEnabled
&& IsEnabled(), pItem
->mbShowWindow
);
2743 DrawTextFlags nTextStyle
= DrawTextFlags::NONE
;
2744 if ( !pItem
->mbEnabled
)
2745 nTextStyle
|= DrawTextFlags::Disable
;
2746 rRenderContext
.DrawCtrlText( Point( nTextOffX
, nTextOffY
), pItem
->maText
,
2747 0, pItem
->maText
.getLength(), nTextStyle
);
2749 SetFont( aOldFont
);
2752 // paint optional drop down arrow
2756 bool bSetColor
= true;
2757 if ( !pItem
->mbEnabled
|| !IsEnabled() )
2760 rRenderContext
.SetFillColor(rStyleSettings
.GetShadowColor());
2763 // dropdown only will be painted without inner border
2764 if( (pItem
->mnBits
& ToolBoxItemBits::DROPDOWNONLY
) != ToolBoxItemBits::DROPDOWNONLY
)
2766 ImplErase(rRenderContext
, aDropDownRect
, nHighlight
!= 0, bHasOpenPopup
);
2768 if( nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) )
2771 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2773 ImplDrawButton(rRenderContext
, aDropDownRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2774 pItem
->mbEnabled
&& IsEnabled(), false);
2777 ImplDrawDropdownArrow(rRenderContext
, aDropDownRect
, bSetColor
, bRotate
);
2780 void ToolBox::ImplDrawFloatwinBorder(vcl::RenderContext
& rRenderContext
, ImplToolItem
const * pItem
)
2782 if ( pItem
->maRect
.IsEmpty() )
2785 tools::Rectangle
aRect( mpFloatWin
->ImplGetItemEdgeClipRect() );
2786 aRect
.SetPos( AbsoluteScreenToOutputPixel( aRect
.TopLeft() ) );
2787 rRenderContext
.SetLineColor(rRenderContext
.GetSettings().GetStyleSettings().GetShadowColor());
2790 p1
= pItem
->maRect
.TopLeft();
2792 p2
= pItem
->maRect
.TopRight();
2794 rRenderContext
.DrawLine( p1
, p2
);
2795 p1
= pItem
->maRect
.BottomLeft();
2797 p2
= pItem
->maRect
.BottomRight();
2799 rRenderContext
.DrawLine( p1
, p2
);
2801 p1
= pItem
->maRect
.TopLeft();
2803 p2
= pItem
->maRect
.BottomLeft();
2805 rRenderContext
.DrawLine( p1
, p2
);
2806 p1
= pItem
->maRect
.TopRight();
2808 p2
= pItem
->maRect
.BottomRight();
2810 rRenderContext
.DrawLine( p1
, p2
);
2814 void ToolBox::ImplFloatControl( bool bStart
, FloatingWindow
* pFloatWindow
)
2819 mpFloatWin
= pFloatWindow
;
2821 // redraw item, to trigger drawing of a special border
2822 InvalidateItem(mnCurPos
);
2826 if (IsMouseCaptured())
2831 mpFloatWin
= nullptr;
2833 // if focus is still in this toolbox, then the floater was opened by keyboard
2834 // draw current item with highlight and keep old state
2835 bool bWasKeyboardActivate
= mpData
->mbDropDownByKeyboard
;
2837 if ( mnCurPos
!= ITEM_NOTFOUND
)
2838 InvalidateItem(mnCurPos
);
2841 if( !bWasKeyboardActivate
)
2843 mnCurPos
= ITEM_NOTFOUND
;
2844 mnCurItemId
= ToolBoxItemId(0);
2845 mnHighItemId
= ToolBoxItemId(0);
2847 mnDownItemId
= ToolBoxItemId(0);
2852 void ToolBox::ShowLine( bool bNext
)
2864 bool ToolBox::ImplHandleMouseMove( const MouseEvent
& rMEvt
, bool bRepeat
)
2866 Point aMousePos
= rMEvt
.GetPosPixel();
2872 if ( mbDrag
&& mnCurPos
!= ITEM_NOTFOUND
)
2874 // is the cursor over the item?
2875 ImplToolItem
* pItem
= &mpData
->m_aItems
[mnCurPos
];
2876 if ( pItem
->maRect
.Contains( aMousePos
) )
2880 InvalidateItem(mnCurPos
);
2881 mnCurItemId
= pItem
->mnId
;
2885 if ( (pItem
->mnBits
& ToolBoxItemBits::REPEAT
) && bRepeat
)
2892 InvalidateItem(mnCurPos
);
2893 mnCurItemId
= ToolBoxItemId(0);
2894 InvalidateItem(mnCurPos
);
2904 bool bNewIn
= maUpperRect
.Contains( aMousePos
);
2905 if ( bNewIn
!= mbIn
)
2908 InvalidateSpin(true, false);
2915 bool bNewIn
= maLowerRect
.Contains( aMousePos
);
2916 if ( bNewIn
!= mbIn
)
2919 InvalidateSpin(false);
2927 bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent
& rMEvt
, bool bCancel
)
2932 // stop eventual running dropdown timer
2933 if( mnCurPos
< mpData
->m_aItems
.size() &&
2934 (mpData
->m_aItems
[mnCurPos
].mnBits
& ToolBoxItemBits::DROPDOWN
) )
2936 mpData
->maDropdownTimer
.Stop();
2947 if ( mnCurPos
== ITEM_NOTFOUND
)
2951 // has mouse been released on top of item?
2952 if( mnCurPos
< mpData
->m_aItems
.size() )
2954 ImplToolItem
* pItem
= &mpData
->m_aItems
[mnCurPos
];
2955 if ( pItem
->maRect
.Contains( rMEvt
.GetPosPixel() ) )
2957 mnCurItemId
= pItem
->mnId
;
2960 // execute AutoCheck if required
2961 if ( pItem
->mnBits
& ToolBoxItemBits::AUTOCHECK
)
2963 if ( pItem
->mnBits
& ToolBoxItemBits::RADIOCHECK
)
2965 if ( pItem
->meState
!= TRISTATE_TRUE
)
2966 SetItemState( pItem
->mnId
, TRISTATE_TRUE
);
2970 if ( pItem
->meState
!= TRISTATE_TRUE
)
2971 pItem
->meState
= TRISTATE_TRUE
;
2973 pItem
->meState
= TRISTATE_FALSE
;
2977 // do not call Select when Repeat is active, as in this
2978 // case that was triggered already in MouseButtonDown
2979 if ( !(pItem
->mnBits
& ToolBoxItemBits::REPEAT
) )
2981 // prevent from being destroyed in the select handler
2982 VclPtr
<vcl::Window
> xWindow
= this;
2984 if ( xWindow
->isDisposed() )
2992 // Items not destroyed, in Select handler
2995 // Get current pos for the case that items are inserted/removed
2997 mnCurPos
= GetItemPos( mnCurItemId
);
2998 if ( mnCurPos
!= ITEM_NOTFOUND
)
3000 InvalidateItem(mnCurPos
);
3001 GetOutDev()->Flush();
3007 mnCurPos
= ITEM_NOTFOUND
;
3008 mnCurItemId
= ToolBoxItemId(0);
3009 mnDownItemId
= ToolBoxItemId(0);
3010 mnMouseModifier
= 0;
3013 else if ( mbUpper
|| mbLower
)
3016 ShowLine( !mbUpper
);
3027 void ToolBox::MouseMove( const MouseEvent
& rMEvt
)
3029 // pressing a modifier generates synthetic mouse moves
3030 // ignore it if keyboard selection is active
3031 if( HasFocus() && ( rMEvt
.GetMode() & MouseEventModifiers::MODIFIERCHANGED
) )
3034 if ( ImplHandleMouseMove( rMEvt
) )
3037 Point aMousePos
= rMEvt
.GetPosPixel();
3039 // only highlight when the focus is not inside a child window of a toolbox
3040 // eg, in an edit control
3041 // and do not highlight when focus is in a different toolbox
3042 bool bDrawHotSpot
= true;
3043 vcl::Window
*pFocusWin
= Application::GetFocusWindow();
3045 bool bFocusWindowIsAToolBoxChild
= false;
3048 vcl::Window
*pWin
= pFocusWin
->GetParent();
3051 if(pWin
->ImplGetWindowImpl() && pWin
->ImplGetWindowImpl()->mbToolBox
)
3053 bFocusWindowIsAToolBoxChild
= true;
3056 pWin
= pWin
->GetParent();
3060 if( bFocusWindowIsAToolBoxChild
|| (pFocusWin
&& pFocusWin
->ImplGetWindowImpl() && pFocusWin
->ImplGetWindowImpl()->mbToolBox
&& pFocusWin
!= this) )
3061 bDrawHotSpot
= false;
3065 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3066 pMgr
->Dragging( aMousePos
);
3070 PointerStyle eStyle
= PointerStyle::Arrow
;
3072 // change mouse cursor over drag area
3073 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
3074 if( pWrapper
&& pWrapper
->GetDragArea().Contains( rMEvt
.GetPosPixel() ) )
3075 eStyle
= PointerStyle::Move
;
3077 if ( (mnWinStyle
& TB_WBLINESIZING
) == TB_WBLINESIZING
)
3079 if ( rMEvt
.GetMode() & MouseEventModifiers::SIMPLEMOVE
)
3081 sal_uInt16 nLinePtr
= ImplTestLineSize( rMEvt
.GetPosPixel() );
3082 if ( nLinePtr
& DOCK_LINEHSIZE
)
3084 if ( meAlign
== WindowAlign::Left
)
3085 eStyle
= PointerStyle::WindowESize
;
3087 eStyle
= PointerStyle::WindowWSize
;
3089 else if ( nLinePtr
& DOCK_LINEVSIZE
)
3091 if ( meAlign
== WindowAlign::Top
)
3092 eStyle
= PointerStyle::WindowSSize
;
3094 eStyle
= PointerStyle::WindowNSize
;
3101 bool bClearHigh
= true;
3102 if ( !rMEvt
.IsLeaveWindow() && (mnCurPos
== ITEM_NOTFOUND
) )
3104 ImplToolItems::size_type nTempPos
= 0;
3105 for (auto const& item
: mpData
->m_aItems
)
3107 if ( item
.maRect
.Contains( aMousePos
) )
3109 if ( (item
.meType
== ToolBoxItemType::BUTTON
) && item
.mbEnabled
)
3112 if ( mnHighItemId
!= item
.mnId
)
3117 ImplToolItems::size_type nPos
= GetItemPos( mnHighItemId
);
3118 InvalidateItem(nPos
);
3119 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nPos
) );
3121 if ( mpData
->mbMenubuttonSelected
)
3123 // remove highlight from menubutton
3124 InvalidateMenuButton();
3126 mnHighItemId
= item
.mnId
;
3127 InvalidateItem(nTempPos
);
3129 CallEventListeners( VclEventId::ToolboxHighlight
);
3138 // only clear highlight when focus is not in toolbar
3139 bool bMenuButtonHit
= mpData
->maMenubuttonItem
.maRect
.Contains( aMousePos
) && ImplHasClippedItems();
3140 if ( !HasFocus() && (bClearHigh
|| bMenuButtonHit
) )
3142 if ( !bMenuButtonHit
&& mpData
->mbMenubuttonSelected
)
3144 // remove highlight from menubutton
3145 InvalidateMenuButton();
3150 ImplToolItems::size_type nClearPos
= GetItemPos( mnHighItemId
);
3151 if ( nClearPos
!= ITEM_NOTFOUND
)
3153 InvalidateItem(nClearPos
);
3154 if( nClearPos
!= mnCurPos
)
3155 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nClearPos
) );
3158 mnHighItemId
= ToolBoxItemId(0);
3161 if( bMenuButtonHit
)
3163 InvalidateMenuButton();
3168 if ( meLastStyle
!= eStyle
)
3170 meLastStyle
= eStyle
;
3171 SetPointer( eStyle
);
3174 DockingWindow::MouseMove( rMEvt
);
3177 void ToolBox::MouseButtonDown( const MouseEvent
& rMEvt
)
3179 // only trigger toolbox for left mouse button and when
3180 // we're not in normal operation
3181 if ( rMEvt
.IsLeft() && !mbDrag
&& (mnCurPos
== ITEM_NOTFOUND
) )
3183 // call activate already here, as items could
3187 // update ToolBox here, such that user knows it
3194 Point aMousePos
= rMEvt
.GetPosPixel();
3195 ImplToolItems::size_type i
= 0;
3196 ImplToolItems::size_type nNewPos
= ITEM_NOTFOUND
;
3198 // search for item that was clicked
3199 for (auto const& item
: mpData
->m_aItems
)
3201 // is this the item?
3202 if ( item
.maRect
.Contains( aMousePos
) )
3204 // do nothing if it is a separator or
3205 // if the item has been disabled
3206 if ( (item
.meType
== ToolBoxItemType::BUTTON
) &&
3207 !item
.mbShowWindow
)
3217 if ( nNewPos
!= ITEM_NOTFOUND
)
3219 if ( !mpData
->m_aItems
[nNewPos
].mbEnabled
)
3225 // update actual data
3226 StartTrackingFlags nTrackFlags
= StartTrackingFlags::NONE
;
3228 mnCurItemId
= mpData
->m_aItems
[nNewPos
].mnId
;
3229 mnDownItemId
= mnCurItemId
;
3230 mnMouseModifier
= rMEvt
.GetModifier();
3231 if ( mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::REPEAT
)
3232 nTrackFlags
|= StartTrackingFlags::ButtonRepeat
;
3234 // update bDrag here, as it is evaluated in the EndSelection
3237 // on double-click: only call the handler, but do so before the button
3238 // is hit, as in the handler dragging
3239 // can be terminated
3240 if ( rMEvt
.GetClicks() == 2 )
3245 InvalidateItem(mnCurPos
);
3249 // was dropdown arrow pressed
3250 if( mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::DROPDOWN
)
3252 if( ( (mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::DROPDOWNONLY
) == ToolBoxItemBits::DROPDOWNONLY
)
3253 || mpData
->m_aItems
[nNewPos
].GetDropDownRect( mbHorz
).Contains( aMousePos
))
3255 // dropdownonly always triggers the dropdown handler, over the whole button area
3257 // the drop down arrow should not trigger the item action
3258 mpData
->mbDropDownByKeyboard
= false;
3259 mpData
->maDropdownClickHdl
.Call( this );
3261 // do not reset data if the dropdown handler opened a floating window
3262 // see ImplFloatControl()
3265 // no floater was opened
3267 InvalidateItem(mnCurPos
);
3269 mnCurPos
= ITEM_NOTFOUND
;
3270 mnCurItemId
= ToolBoxItemId(0);
3271 mnDownItemId
= ToolBoxItemId(0);
3272 mnMouseModifier
= 0;
3273 mnHighItemId
= ToolBoxItemId(0);
3277 else // activate long click timer
3278 mpData
->maDropdownTimer
.Start();
3281 // call Click handler
3282 if ( rMEvt
.GetClicks() != 2 )
3285 // also call Select handler at repeat
3286 if ( nTrackFlags
& StartTrackingFlags::ButtonRepeat
)
3289 // if the actions was not aborted in Click handler
3291 StartTracking( nTrackFlags
);
3293 // if mouse was clicked over an item we
3300 // menu button hit ?
3301 if( mpData
->maMenubuttonItem
.maRect
.Contains( aMousePos
) && ImplHasClippedItems() )
3303 if ( maMenuButtonHdl
.IsSet() )
3304 maMenuButtonHdl
.Call( this );
3306 ExecuteCustomMenu( mpData
->maMenubuttonItem
.maRect
);
3310 // check scroll- and next-buttons here
3311 if ( maUpperRect
.Contains( aMousePos
) )
3313 if ( mnCurLine
> 1 )
3318 InvalidateSpin(true, false);
3322 if ( maLowerRect
.Contains( aMousePos
) )
3324 if ( mnCurLine
+mnVisLines
-1 < mnCurLines
)
3329 InvalidateSpin(false);
3334 // Linesizing testen
3335 if ( (mnWinStyle
& TB_WBLINESIZING
) == TB_WBLINESIZING
)
3337 sal_uInt16 nLineMode
= ImplTestLineSize( aMousePos
);
3340 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3342 // call handler, such that we can set the
3346 Point aPos
= GetParent()->OutputToScreenPixel( GetPosPixel() );
3347 Size aSize
= GetSizePixel();
3348 aPos
= ScreenToOutputPixel( aPos
);
3351 pMgr
->StartDragging( this, aMousePos
, tools::Rectangle( aPos
, aSize
),
3357 // no item, then only click or double click
3358 if ( rMEvt
.GetClicks() == 2 )
3364 if ( !mbDrag
&& (mnCurPos
== ITEM_NOTFOUND
) )
3365 DockingWindow::MouseButtonDown( rMEvt
);
3368 void ToolBox::MouseButtonUp( const MouseEvent
& rMEvt
)
3370 if ( ImplHandleMouseButtonUp( rMEvt
) )
3373 if ( mbDragging
&& rMEvt
.IsLeft() )
3375 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3376 pMgr
->EndDragging();
3380 DockingWindow::MouseButtonUp( rMEvt
);
3383 void ToolBox::Tracking( const TrackingEvent
& rTEvt
)
3385 VclPtr
<vcl::Window
> xWindow
= this;
3387 if ( rTEvt
.IsTrackingEnded() )
3388 ImplHandleMouseButtonUp( rTEvt
.GetMouseEvent(), rTEvt
.IsTrackingCanceled() );
3390 ImplHandleMouseMove( rTEvt
.GetMouseEvent(), rTEvt
.IsTrackingRepeat() );
3392 if ( xWindow
->isDisposed() )
3393 // toolbox was deleted
3395 DockingWindow::Tracking( rTEvt
);
3398 void ToolBox::InvalidateItem(ImplToolItems::size_type nPosition
)
3400 if (mpData
&& nPosition
< mpData
->m_aItems
.size())
3402 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPosition
];
3403 Invalidate(pItem
->maRect
);
3407 void ToolBox::InvalidateMenuButton()
3409 if (!mpData
->maMenubuttonItem
.maRect
.IsEmpty())
3410 Invalidate(mpData
->maMenubuttonItem
.maRect
);
3413 void ToolBox::InvalidateSpin(bool bUpperIn
, bool bLowerIn
)
3415 if (bUpperIn
&& !maUpperRect
.IsEmpty())
3416 Invalidate(maUpperRect
);
3418 if (bLowerIn
&& !maLowerRect
.IsEmpty())
3419 Invalidate(maLowerRect
);
3422 void ToolBox::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rPaintRect
)
3424 if( mpData
->mbIsPaintLocked
)
3427 if (rPaintRect
== tools::Rectangle(0, 0, mnDX
-1, mnDY
-1))
3430 mbFullPaint
= false;
3432 ImplDrawBackground(rRenderContext
, rPaintRect
);
3434 if ( (mnWinStyle
& WB_BORDER
) && !ImplIsFloatingMode() )
3435 ImplDrawBorder(rRenderContext
);
3437 if( !ImplIsFloatingMode() )
3438 ImplDrawGrip(rRenderContext
);
3440 ImplDrawMenuButton(rRenderContext
, mpData
->mbMenubuttonSelected
);
3443 if (mnWinStyle
& WB_SCROLL
)
3445 if (mnCurLines
> mnLines
)
3446 ImplDrawSpin(rRenderContext
);
3450 ImplToolItems::size_type nHighPos
;
3452 nHighPos
= GetItemPos( mnHighItemId
);
3454 nHighPos
= ITEM_NOTFOUND
;
3456 ImplToolItems::size_type nCount
= mpData
->m_aItems
.size();
3457 for( ImplToolItems::size_type i
= 0; i
< nCount
; i
++ )
3459 ImplToolItem
* pItem
= &mpData
->m_aItems
[i
];
3461 // only draw when the rectangle is in the draw rectangle
3462 if ( !pItem
->maRect
.IsEmpty() && rPaintRect
.Overlaps( pItem
->maRect
) )
3464 sal_uInt16 nHighlight
= 0;
3465 if ( i
== mnCurPos
)
3467 else if ( i
== nHighPos
)
3469 ImplDrawItem(rRenderContext
, i
, nHighlight
);
3475 void ToolBox::Resize()
3477 Size aSize
= GetOutputSizePixel();
3478 // #i31422# some WindowManagers send (0,0) sizes when
3479 // switching virtual desktops - ignore this and avoid reformatting
3480 if( !aSize
.Width() && !aSize
.Height() )
3483 tools::Long nOldDX
= mnDX
;
3484 tools::Long nOldDY
= mnDY
;
3485 mnDX
= aSize
.Width();
3486 mnDY
= aSize
.Height();
3490 // invalidate everything to have gradient backgrounds properly drawn
3493 // If we have any expandable entries, then force a reformat first using
3494 // their optimal sizes, then share out the excess space evenly across those
3495 // expandables and reformat again
3496 std::vector
<size_t> aExpandables
;
3497 for (size_t i
= 0; i
< mpData
->m_aItems
.size(); ++i
)
3499 if (mpData
->m_aItems
[i
].mbExpand
)
3501 vcl::Window
*pWindow
= mpData
->m_aItems
[i
].mpWindow
;
3502 SAL_INFO_IF(!pWindow
, "vcl.layout", "only tabitems with window supported at the moment");
3505 Size
aWinSize(pWindow
->GetSizePixel());
3506 Size
aPrefSize(pWindow
->get_preferred_size());
3507 aWinSize
.setWidth( aPrefSize
.Width() );
3508 pWindow
->SetSizePixel(aWinSize
);
3509 aExpandables
.push_back(i
);
3513 // re-format or re-draw
3514 if ( mbScroll
|| !aExpandables
.empty() )
3516 if ( !mbFormat
|| !aExpandables
.empty() )
3519 if( IsReallyVisible() || !aExpandables
.empty() )
3523 if (!aExpandables
.empty())
3525 //Get how big the optimal size is
3526 tools::Rectangle aBounds
;
3527 for (const ImplToolItem
& rItem
: mpData
->m_aItems
)
3529 aBounds
.Union( rItem
.maRect
);
3532 auto nOptimalWidth
= aBounds
.GetWidth();
3533 auto nDiff
= aSize
.Width() - nOptimalWidth
;
3534 decltype(nDiff
) nExpandablesSize
= aExpandables
.size();
3535 nDiff
/= nExpandablesSize
;
3537 //share out the diff from optimal to real across
3538 //expandable entries
3539 for (size_t nIndex
: aExpandables
)
3541 vcl::Window
*pWindow
= mpData
->m_aItems
[nIndex
].mpWindow
;
3542 Size
aWinSize(pWindow
->GetSizePixel());
3543 Size
aPrefSize(pWindow
->get_preferred_size());
3544 aWinSize
.setWidth( aPrefSize
.Width() + nDiff
);
3545 pWindow
->SetSizePixel(aWinSize
);
3548 //now reformat with final sizes
3557 if ( !(mnWinStyle
& WB_BORDER
) )
3560 // as otherwise, when painting we might think we have to re-draw everything
3561 if ( mbFormat
&& IsReallyVisible() )
3565 if ( mnRightBorder
)
3567 if ( nOldDX
> mnDX
)
3568 Invalidate( tools::Rectangle( mnDX
-mnRightBorder
-1, 0, mnDX
, mnDY
) );
3570 Invalidate( tools::Rectangle( nOldDX
-mnRightBorder
-1, 0, nOldDX
, nOldDY
) );
3573 if ( mnBottomBorder
)
3575 if ( nOldDY
> mnDY
)
3576 Invalidate( tools::Rectangle( 0, mnDY
-mnBottomBorder
-1, mnDX
, mnDY
) );
3578 Invalidate( tools::Rectangle( 0, nOldDY
-mnBottomBorder
-1, nOldDX
, nOldDY
) );
3585 bool DispatchableCommand(std::u16string_view rName
)
3587 return o3tl::starts_with(rName
, u
".uno") ||
3588 o3tl::starts_with(rName
, u
"slot:") ||
3589 o3tl::starts_with(rName
, u
"macro:") ||
3590 o3tl::starts_with(rName
, u
"vnd.sun.star.script");
3594 const OUString
& ToolBox::ImplGetHelpText( ToolBoxItemId nItemId
) const
3596 ImplToolItem
* pItem
= ImplGetItem( nItemId
);
3600 if ( pItem
->maHelpText
.isEmpty() && ( !pItem
->maHelpId
.isEmpty() || pItem
->maCommandStr
.getLength() ))
3602 Help
* pHelp
= Application::GetHelp();
3605 if (DispatchableCommand(pItem
->maCommandStr
))
3606 pItem
->maHelpText
= pHelp
->GetHelpText( pItem
->maCommandStr
, this );
3607 if ( pItem
->maHelpText
.isEmpty() && !pItem
->maHelpId
.isEmpty() )
3608 pItem
->maHelpText
= pHelp
->GetHelpText( pItem
->maHelpId
, this );
3612 return pItem
->maHelpText
;
3615 void ToolBox::RequestHelp( const HelpEvent
& rHEvt
)
3617 ToolBoxItemId nItemId
;
3620 if( !rHEvt
.KeyboardActivated() )
3622 nItemId
= GetItemId( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ) );
3623 aHelpPos
= rHEvt
.GetMousePosPixel();
3630 nItemId
= mnHighItemId
;
3631 tools::Rectangle
aRect( GetItemRect( nItemId
) );
3632 if( aRect
.IsEmpty() )
3635 aHelpPos
= OutputToScreenPixel( aRect
.Center() );
3640 if ( rHEvt
.GetMode() & (HelpEventMode::BALLOON
| HelpEventMode::QUICK
) )
3643 tools::Rectangle aTempRect
= GetItemRect( nItemId
);
3644 Point aPt
= OutputToScreenPixel( aTempRect
.TopLeft() );
3645 aTempRect
.SetLeft( aPt
.X() );
3646 aTempRect
.SetTop( aPt
.Y() );
3647 aPt
= OutputToScreenPixel( aTempRect
.BottomRight() );
3648 aTempRect
.SetRight( aPt
.X() );
3649 aTempRect
.SetBottom( aPt
.Y() );
3651 // get text and display it
3652 OUString aStr
= GetQuickHelpText( nItemId
);
3654 aStr
= MnemonicGenerator::EraseAllMnemonicChars( GetItemText( nItemId
) );
3655 if ( rHEvt
.GetMode() & HelpEventMode::BALLOON
)
3657 const OUString
& rHelpStr
= GetHelpText( nItemId
);
3658 if (!rHelpStr
.isEmpty())
3660 Help::ShowBalloon( this, aHelpPos
, aTempRect
, aStr
);
3663 Help::ShowQuickHelp( this, aTempRect
, aStr
, QuickHelpFlags::CtrlText
);
3668 DockingWindow::RequestHelp( rHEvt
);
3671 bool ToolBox::EventNotify( NotifyEvent
& rNEvt
)
3673 if ( rNEvt
.GetType() == NotifyEventType::KEYINPUT
)
3675 KeyEvent aKEvt
= *rNEvt
.GetKeyEvent();
3676 vcl::KeyCode aKeyCode
= aKEvt
.GetKeyCode();
3677 sal_uInt16 nKeyCode
= aKeyCode
.GetCode();
3682 // internal TAB cycling only if parent is not a dialog or if we are the only child
3683 // otherwise the dialog control will take over
3684 vcl::Window
*pParent
= ImplGetParent();
3685 bool bOldSchoolContainer
=
3686 ((pParent
->GetStyle() & (WB_DIALOGCONTROL
| WB_NODIALOGCONTROL
)) == WB_DIALOGCONTROL
&&
3687 pParent
->GetChildCount() != 1);
3688 bool bNoTabCycling
= bOldSchoolContainer
|| isContainerWindow(pParent
);
3691 return DockingWindow::EventNotify( rNEvt
);
3692 else if( ImplChangeHighlightUpDn( aKeyCode
.IsShift() , bNoTabCycling
) )
3695 return DockingWindow::EventNotify( rNEvt
);
3701 else if( rNEvt
.GetType() == NotifyEventType::GETFOCUS
)
3703 if( rNEvt
.GetWindow() == this )
3705 // the toolbar itself got the focus
3706 if( mnLastFocusItemId
!= ToolBoxItemId(0) || mpData
->mbMenubuttonWasLastSelected
)
3708 // restore last item
3709 if( mpData
->mbMenubuttonWasLastSelected
)
3711 ImplChangeHighlight( nullptr );
3712 mpData
->mbMenubuttonSelected
= true;
3713 InvalidateMenuButton();
3717 ImplChangeHighlight( ImplGetItem( mnLastFocusItemId
) );
3718 mnLastFocusItemId
= ToolBoxItemId(0);
3721 else if( (GetGetFocusFlags() & (GetFocusFlags::Backward
|GetFocusFlags::Tab
) ) == (GetFocusFlags::Backward
|GetFocusFlags::Tab
))
3722 // Shift-TAB was pressed in the parent
3723 ImplChangeHighlightUpDn( false );
3725 ImplChangeHighlightUpDn( true );
3727 mnLastFocusItemId
= ToolBoxItemId(0);
3733 // a child window got the focus so update current item to
3734 // allow for proper lose focus handling in keyboard navigation
3735 for (auto const& item
: mpData
->m_aItems
)
3737 if ( item
.mbVisible
)
3739 if ( item
.mpWindow
&& item
.mpWindow
->ImplIsWindowOrChild( rNEvt
.GetWindow() ) )
3741 mnHighItemId
= item
.mnId
;
3746 return DockingWindow::EventNotify( rNEvt
);
3749 else if( rNEvt
.GetType() == NotifyEventType::LOSEFOCUS
)
3753 mpData
->mbMenubuttonWasLastSelected
= false;
3754 mnHighItemId
= ToolBoxItemId(0);
3755 mnCurPos
= ITEM_NOTFOUND
;
3758 return DockingWindow::EventNotify( rNEvt
);
3761 void ToolBox::Command( const CommandEvent
& rCEvt
)
3763 if ( rCEvt
.GetCommand() == CommandEventId::Wheel
)
3765 if ( (mnCurLine
> 1) || (mnCurLine
+mnVisLines
-1 < mnCurLines
) )
3767 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
3768 if ( pData
->GetMode() == CommandWheelMode::SCROLL
)
3770 if ( (mnCurLine
> 1) && (pData
->GetDelta() > 0) )
3772 else if ( (mnCurLine
+mnVisLines
-1 < mnCurLines
) && (pData
->GetDelta() < 0) )
3779 else if ( rCEvt
.GetCommand() == CommandEventId::ContextMenu
)
3781 ExecuteCustomMenu( tools::Rectangle( rCEvt
.GetMousePosPixel(), rCEvt
.GetMousePosPixel() ) );
3785 DockingWindow::Command( rCEvt
);
3788 void ToolBox::StateChanged( StateChangedType nType
)
3790 DockingWindow::StateChanged( nType
);
3792 if ( nType
== StateChangedType::InitShow
)
3794 else if ( nType
== StateChangedType::Enable
)
3796 else if ( nType
== StateChangedType::UpdateMode
)
3798 if ( IsUpdateMode() )
3801 else if ( (nType
== StateChangedType::Zoom
) ||
3802 (nType
== StateChangedType::ControlFont
) )
3806 ImplInitSettings( true, false, false );
3809 else if ( nType
== StateChangedType::ControlForeground
)
3811 ImplInitSettings( false, true, false );
3814 else if ( nType
== StateChangedType::ControlBackground
)
3816 ImplInitSettings( false, false, true ); // font, foreground, background
3820 maStateChangedHandler
.Call( &nType
);
3823 void ToolBox::DataChanged( const DataChangedEvent
& rDCEvt
)
3825 DockingWindow::DataChanged( rDCEvt
);
3827 if ( (rDCEvt
.GetType() == DataChangedEventType::DISPLAY
) ||
3828 (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ||
3829 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
3830 ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
3831 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)) )
3835 ImplInitSettings( true, true, true );
3839 maDataChangedHandler
.Call( &rDCEvt
);
3842 void ToolBox::SetStyle(WinBits nNewStyle
)
3844 mnWinStyle
= nNewStyle
;
3845 if (!ImplIsFloatingMode())
3847 bool bOldScroll
= mbScroll
;
3848 mbScroll
= (mnWinStyle
& WB_SCROLL
) != 0;
3849 if (mbScroll
!= bOldScroll
)
3857 void ToolBox::ToggleFloatingMode()
3859 DockingWindow::ToggleFloatingMode();
3864 bool bOldHorz
= mbHorz
;
3866 if ( ImplIsFloatingMode() )
3869 meAlign
= WindowAlign::Top
;
3872 if( bOldHorz
!= mbHorz
)
3873 mbCalc
= true; // orientation was changed !
3875 ImplSetMinMaxFloatSize();
3876 SetOutputSizePixel( ImplCalcFloatSize( mnFloatLines
) );
3880 mbScroll
= (mnWinStyle
& WB_SCROLL
) != 0;
3881 if ( (meAlign
== WindowAlign::Top
) || (meAlign
== WindowAlign::Bottom
) )
3886 // set focus back to document
3887 ImplGetFrameWindow()->GetWindow( GetWindowType::Client
)->GrabFocus();
3890 if( bOldHorz
!= mbHorz
)
3892 // if orientation changes, the toolbox has to be initialized again
3893 // to update the direction of the gradient
3895 ImplInitSettings( true, true, true );
3902 void ToolBox::StartDocking()
3904 meDockAlign
= meAlign
;
3905 mnDockLines
= mnLines
;
3906 mbLastFloatMode
= ImplIsFloatingMode();
3907 DockingWindow::StartDocking();
3910 bool ToolBox::Docking( const Point
& rPos
, tools::Rectangle
& rRect
)
3912 // do nothing during dragging, it was calculated before
3916 bool bFloatMode
= false;
3918 DockingWindow::Docking( rPos
, rRect
);
3920 // if the mouse is outside the area, it can only become a floating window
3921 tools::Rectangle
aDockingRect( rRect
);
3922 if ( !ImplIsFloatingMode() )
3924 // don't use tracking rectangle for alignment check, because it will be too large
3925 // to get a floating mode as result - switch to floating size
3926 // so the calculation only depends on the position of the rectangle, not the current
3927 // docking state of the window
3928 ImplToolItems::size_type nTemp
= 0;
3929 aDockingRect
.SetSize( ImplCalcFloatSize( nTemp
) );
3931 // in this mode docking is never done by keyboard, so it's OK to use the mouse position
3932 aDockingRect
.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
3937 meDockAlign
= meAlign
;
3938 if ( !mbLastFloatMode
)
3940 ImplToolItems::size_type nTemp
= 0;
3941 aDockingRect
.SetSize( ImplCalcFloatSize( nTemp
) );
3944 rRect
= aDockingRect
;
3945 mbLastFloatMode
= bFloatMode
;
3950 void ToolBox::EndDocking( const tools::Rectangle
& rRect
, bool bFloatMode
)
3952 if ( !IsDockingCanceled() )
3954 if ( mnLines
!= mnDockLines
)
3955 SetLineCount( mnDockLines
);
3956 if ( meAlign
!= meDockAlign
)
3957 SetAlign( meDockAlign
);
3959 if ( bFloatMode
|| (bFloatMode
!= ImplIsFloatingMode()) )
3960 DockingWindow::EndDocking( rRect
, bFloatMode
);
3963 void ToolBox::Resizing( Size
& rSize
)
3965 ImplToolItems::size_type nCalcLines
;
3966 ImplToolItems::size_type nTemp
;
3968 // calculate all floating sizes
3969 ImplCalcFloatSizes();
3971 if ( !mnLastResizeDY
)
3972 mnLastResizeDY
= mnDY
;
3974 // is vertical resizing needed
3975 if ( (mnLastResizeDY
!= rSize
.Height()) && (mnDY
!= rSize
.Height()) )
3977 nCalcLines
= ImplCalcLines( rSize
.Height() );
3978 if ( nCalcLines
< 1 )
3980 rSize
= ImplCalcFloatSize( nCalcLines
);
3986 Size aTempSize
= ImplCalcFloatSize( nTemp
);
3987 while ( (aTempSize
.Width() > rSize
.Width()) &&
3988 (nCalcLines
<= maFloatSizes
[0].mnLines
) )
3992 aTempSize
= ImplCalcFloatSize( nTemp
);
3997 mnLastResizeDY
= rSize
.Height();
4000 Size
ToolBox::GetOptimalSize() const
4002 // If we have any expandable entries, then force them to their
4003 // optimal sizes, then reset them afterwards
4004 std::map
<vcl::Window
*, Size
> aExpandables
;
4005 for (const ImplToolItem
& rItem
: mpData
->m_aItems
)
4009 vcl::Window
*pWindow
= rItem
.mpWindow
;
4010 SAL_INFO_IF(!pWindow
, "vcl.layout", "only tabitems with window supported at the moment");
4013 Size
aWinSize(pWindow
->GetSizePixel());
4014 aExpandables
[pWindow
] = aWinSize
;
4015 Size
aPrefSize(pWindow
->get_preferred_size());
4016 aWinSize
.setWidth( aPrefSize
.Width() );
4017 pWindow
->SetSizePixel(aWinSize
);
4021 Size
aSize(const_cast<ToolBox
*>(this)->ImplCalcSize( mnLines
));
4023 for (auto const& [pWindow
, aWinSize
] : aExpandables
)
4024 pWindow
->SetSizePixel(aWinSize
);
4029 Size
ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines
)
4031 return ImplCalcSize( nCalcLines
);
4034 Size
ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines
, WindowAlign eAlign
)
4036 return ImplCalcSize( nCalcLines
,
4037 (eAlign
== WindowAlign::Top
|| eAlign
== WindowAlign::Bottom
) ? TB_CALCMODE_HORZ
: TB_CALCMODE_VERT
);
4040 ToolBox::ImplToolItems::size_type
ToolBox::ImplCountLineBreaks() const
4042 ImplToolItems::size_type nLines
= 0;
4044 for (auto const& item
: mpData
->m_aItems
)
4046 if( item
.meType
== ToolBoxItemType::BREAK
)
4052 Size
ToolBox::CalcPopupWindowSizePixel()
4054 // count number of breaks and calc corresponding floating window size
4055 ImplToolItems::size_type nLines
= ImplCountLineBreaks();
4058 ++nLines
; // add the first line
4061 // no breaks found: use quadratic layout
4062 nLines
= static_cast<ImplToolItems::size_type
>(ceil( sqrt( static_cast<double>(GetItemCount()) ) ));
4065 bool bPopup
= mpData
->mbAssumePopupMode
;
4066 mpData
->mbAssumePopupMode
= true;
4068 Size aSize
= CalcFloatingWindowSizePixel( nLines
);
4070 mpData
->mbAssumePopupMode
= bPopup
;
4074 Size
ToolBox::CalcFloatingWindowSizePixel()
4076 ImplToolItems::size_type nLines
= ImplCountLineBreaks();
4077 ++nLines
; // add the first line
4078 return CalcFloatingWindowSizePixel( nLines
);
4081 Size
ToolBox::CalcFloatingWindowSizePixel( ImplToolItems::size_type nCalcLines
)
4083 bool bFloat
= mpData
->mbAssumeFloating
;
4084 bool bDocking
= mpData
->mbAssumeDocked
;
4086 // simulate floating mode and force reformat before calculating
4087 mpData
->mbAssumeFloating
= true;
4088 mpData
->mbAssumeDocked
= false;
4090 Size aSize
= ImplCalcFloatSize( nCalcLines
);
4093 mpData
->mbAssumeFloating
= bFloat
;
4094 mpData
->mbAssumeDocked
= bDocking
;
4099 Size
ToolBox::CalcMinimumWindowSizePixel()
4101 if( ImplIsFloatingMode() )
4102 return ImplCalcSize( mnFloatLines
);
4105 // create dummy toolbox for measurements
4106 VclPtrInstance
< ToolBox
> pToolBox( GetParent(), GetStyle() );
4108 // copy until first useful item
4109 for (auto const& item
: mpData
->m_aItems
)
4111 pToolBox
->CopyItem( *this, item
.mnId
);
4112 if( (item
.meType
== ToolBoxItemType::BUTTON
) &&
4113 item
.mbVisible
&& !ImplIsFixedControl( &item
) )
4117 // add to docking manager if required to obtain a drag area
4118 // (which is accounted for in calcwindowsizepixel)
4119 if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
4120 ImplGetDockingManager()->AddWindow( pToolBox
);
4123 if( IsMenuEnabled() )
4124 pToolBox
->SetMenuType( GetMenuType() );
4126 pToolBox
->SetAlign( GetAlign() );
4127 Size aSize
= pToolBox
->CalcWindowSizePixel( 1 );
4129 ImplGetDockingManager()->RemoveWindow( pToolBox
);
4132 pToolBox
.disposeAndClear();
4138 void ToolBox::EnableCustomize( bool bEnable
)
4140 mbCustomize
= bEnable
;
4143 void ToolBox::LoseFocus()
4145 ImplChangeHighlight( nullptr, true );
4147 DockingWindow::LoseFocus();
4150 // performs the action associated with an item, ie simulates clicking the item
4151 void ToolBox::TriggerItem( ToolBoxItemId nItemId
)
4153 mnHighItemId
= nItemId
;
4154 vcl::KeyCode
aKeyCode( 0, 0 );
4155 ImplActivateItem( aKeyCode
);
4158 // calls the button's action handler
4159 // returns true if action was called
4160 bool ToolBox::ImplActivateItem( vcl::KeyCode aKeyCode
)
4165 ImplToolItem
*pToolItem
= ImplGetItem( mnHighItemId
);
4167 // #107712#, activate can also be called for disabled entries
4168 if( pToolItem
&& !pToolItem
->mbEnabled
)
4171 if( pToolItem
&& pToolItem
->mpWindow
&& HasFocus() )
4174 mbChangingHighlight
= true; // avoid focus change due to loss of focus
4175 pToolItem
->mpWindow
->ImplControlFocus( GetFocusFlags::Tab
);
4176 mbChangingHighlight
= false;
4180 mnDownItemId
= mnCurItemId
= mnHighItemId
;
4181 if (pToolItem
&& (pToolItem
->mnBits
& ToolBoxItemBits::AUTOCHECK
))
4183 if ( pToolItem
->mnBits
& ToolBoxItemBits::RADIOCHECK
)
4185 if ( pToolItem
->meState
!= TRISTATE_TRUE
)
4186 SetItemState( pToolItem
->mnId
, TRISTATE_TRUE
);
4190 if ( pToolItem
->meState
!= TRISTATE_TRUE
)
4191 pToolItem
->meState
= TRISTATE_TRUE
;
4193 pToolItem
->meState
= TRISTATE_FALSE
;
4196 mnMouseModifier
= aKeyCode
.GetModifier();
4197 mbIsKeyEvent
= true;
4201 // #107776# we might be destroyed in the selecthandler
4202 VclPtr
<vcl::Window
> xWindow
= this;
4204 if ( xWindow
->isDisposed() )
4208 mbIsKeyEvent
= false;
4209 mnMouseModifier
= 0;
4217 static bool ImplCloseLastPopup( vcl::Window
const *pParent
)
4219 // close last popup toolbox (see also:
4220 // ImplHandleMouseFloatMode(...) in winproc.cxx )
4222 if (ImplGetSVData()->mpWinData
->mpFirstFloat
)
4224 FloatingWindow
* pLastLevelFloat
= ImplGetSVData()->mpWinData
->mpFirstFloat
->ImplFindLastLevelFloat();
4225 // only close the floater if it is not our direct parent, which would kill ourself
4226 if( pLastLevelFloat
&& pLastLevelFloat
!= pParent
)
4228 pLastLevelFloat
->EndPopupMode( FloatWinPopupEndFlags::Cancel
| FloatWinPopupEndFlags::CloseAll
);
4235 // opens a drop down toolbox item
4236 // returns true if item was opened
4237 bool ToolBox::ImplOpenItem( vcl::KeyCode aKeyCode
)
4239 sal_uInt16 nCode
= aKeyCode
.GetCode();
4242 // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
4243 if ( ((nCode
== KEY_LEFT
|| nCode
== KEY_RIGHT
) && IsHorizontal())
4244 || ((nCode
== KEY_UP
|| nCode
== KEY_DOWN
) && !IsHorizontal()) )
4247 if( mpData
->mbMenubuttonSelected
)
4249 if( ImplCloseLastPopup( GetParent() ) )
4251 mbIsKeyEvent
= true;
4252 if ( maMenuButtonHdl
.IsSet() )
4253 maMenuButtonHdl
.Call( this );
4255 ExecuteCustomMenu( mpData
->maMenubuttonItem
.maRect
);
4256 mpData
->mbMenubuttonWasLastSelected
= true;
4257 mbIsKeyEvent
= false;
4259 else if( mnHighItemId
&& ImplGetItem( mnHighItemId
) &&
4260 (ImplGetItem( mnHighItemId
)->mnBits
& ToolBoxItemBits::DROPDOWN
) )
4262 mnDownItemId
= mnCurItemId
= mnHighItemId
;
4263 mnCurPos
= GetItemPos( mnCurItemId
);
4264 mnLastFocusItemId
= mnCurItemId
; // save item id for possible later focus restore
4265 mnMouseModifier
= aKeyCode
.GetModifier();
4266 mbIsKeyEvent
= true;
4269 mpData
->mbDropDownByKeyboard
= true;
4270 mpData
->maDropdownClickHdl
.Call( this );
4272 mbIsKeyEvent
= false;
4273 mnMouseModifier
= 0;
4281 void ToolBox::KeyInput( const KeyEvent
& rKEvt
)
4283 vcl::KeyCode aKeyCode
= rKEvt
.GetKeyCode();
4284 sal_uInt16 nCode
= aKeyCode
.GetCode();
4286 vcl::Window
*pParent
= ImplGetParent();
4287 bool bOldSchoolContainer
= ((pParent
->GetStyle() & (WB_DIALOGCONTROL
| WB_NODIALOGCONTROL
)) == WB_DIALOGCONTROL
);
4288 bool bParentIsContainer
= bOldSchoolContainer
|| isContainerWindow(pParent
);
4290 bool bForwardKey
= false;
4291 bool bGrabFocusToDocument
= false;
4293 // #107776# we might be destroyed in the keyhandler
4294 VclPtr
<vcl::Window
> xWindow
= this;
4300 // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
4301 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4303 if( !IsHorizontal() )
4304 ImplChangeHighlightUpDn( true );
4306 ImplOpenItem( aKeyCode
);
4311 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4313 if( IsHorizontal() )
4314 ImplChangeHighlightUpDn( true );
4316 ImplOpenItem( aKeyCode
);
4321 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4323 if( !IsHorizontal() )
4324 ImplChangeHighlightUpDn( false );
4326 ImplOpenItem( aKeyCode
);
4331 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4333 if( IsHorizontal() )
4334 ImplChangeHighlightUpDn( false );
4336 ImplOpenItem( aKeyCode
);
4340 if ( mnCurLine
> 1 )
4342 if( mnCurLine
> mnVisLines
)
4343 mnCurLine
= mnCurLine
- mnVisLines
;
4349 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine
) );
4353 if ( mnCurLine
+mnVisLines
-1 < mnCurLines
)
4355 if( mnCurLine
+ 2*mnVisLines
-1 < mnCurLines
)
4356 mnCurLine
= mnCurLine
+ mnVisLines
;
4358 mnCurLine
= mnCurLines
;
4362 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine
) );
4367 ImplChangeHighlight( nullptr );
4368 ImplChangeHighlightUpDn( false );
4373 ImplChangeHighlight( nullptr );
4374 ImplChangeHighlightUpDn( true );
4379 if( !ImplIsFloatingMode() && bParentIsContainer
)
4380 DockingWindow::KeyInput( rKEvt
);
4383 // send focus to document pane
4384 vcl::Window
*pWin
= this;
4387 if( !pWin
->GetParent() )
4389 pWin
->ImplGetFrameWindow()->GetWindow( GetWindowType::Client
)->GrabFocus();
4392 pWin
= pWin
->GetParent();
4399 // #107712#, disabled entries are selectable now
4400 // leave toolbox and move focus to document
4403 ImplToolItem
*pItem
= ImplGetItem(mnHighItemId
);
4404 if (!pItem
|| !pItem
->mbEnabled
)
4406 bGrabFocusToDocument
= true;
4409 if( !bGrabFocusToDocument
)
4410 bForwardKey
= !ImplActivateItem( aKeyCode
);
4415 ImplOpenItem( aKeyCode
);
4420 sal_uInt16 aKeyGroup
= aKeyCode
.GetGroup();
4421 ImplToolItem
*pItem
= nullptr;
4423 pItem
= ImplGetItem( mnHighItemId
);
4424 // #i13931# forward alphanum keyinput into embedded control
4425 if( (aKeyGroup
== KEYGROUP_NUM
|| aKeyGroup
== KEYGROUP_ALPHA
) && pItem
&& pItem
->mpWindow
&& pItem
->mbEnabled
)
4427 vcl::Window
*pFocusWindow
= Application::GetFocusWindow();
4429 mbChangingHighlight
= true; // avoid focus change due to loss of focus
4430 pItem
->mpWindow
->ImplControlFocus( GetFocusFlags::Tab
);
4431 mbChangingHighlight
= false;
4432 if( pFocusWindow
!= Application::GetFocusWindow() )
4433 Application::GetFocusWindow()->KeyInput( rKEvt
);
4437 // do nothing to avoid key presses going into the document
4438 // while the toolbox has the focus
4439 // just forward function and special keys and combinations with Alt-key
4440 if( aKeyGroup
== KEYGROUP_FKEYS
|| aKeyGroup
== KEYGROUP_MISC
|| aKeyCode
.IsMod2() )
4446 if ( xWindow
->isDisposed() )
4449 // #107251# move focus away if this toolbox was disabled during keyinput
4450 if (HasFocus() && mpData
->mbKeyInputDisabled
&& bParentIsContainer
)
4452 vcl::Window
*pFocusControl
= pParent
->ImplGetDlgWindow( 0, GetDlgWindowType::First
);
4453 if ( pFocusControl
&& pFocusControl
!= this )
4454 pFocusControl
->ImplControlFocus( GetFocusFlags::Init
);
4457 // #107712#, leave toolbox
4458 if( bGrabFocusToDocument
)
4460 GrabFocusToDocument();
4465 DockingWindow::KeyInput( rKEvt
);
4468 // returns the current toolbox line of the item
4469 ToolBox::ImplToolItems::size_type
ToolBox::ImplGetItemLine( ImplToolItem
const * pCurrentItem
)
4471 ImplToolItems::size_type nLine
= 1;
4472 for (auto const& item
: mpData
->m_aItems
)
4476 if( &item
== pCurrentItem
)
4482 // returns the first displayable item in the given line
4483 ImplToolItem
* ToolBox::ImplGetFirstValidItem( ImplToolItems::size_type nLine
)
4485 if( !nLine
|| nLine
> mnCurLines
)
4490 ImplToolItems::iterator it
= mpData
->m_aItems
.begin();
4491 while( it
!= mpData
->m_aItems
.end() )
4493 // find correct line
4498 // find first useful item
4499 while( it
!= mpData
->m_aItems
.end() && ((it
->meType
!= ToolBoxItemType::BUTTON
) ||
4500 /*!it->mbEnabled ||*/ !it
->mbVisible
|| ImplIsFixedControl( &(*it
) )) )
4503 if( it
== mpData
->m_aItems
.end() || it
->mbBreak
)
4504 return nullptr; // no valid items in this line
4511 return (it
== mpData
->m_aItems
.end()) ? nullptr : &(*it
);
4514 ToolBox::ImplToolItems::size_type
ToolBox::ImplFindItemPos( const ImplToolItem
* pItem
, const ImplToolItems
& rList
)
4518 for( ImplToolItems::size_type nPos
= 0; nPos
< rList
.size(); ++nPos
)
4519 if( &rList
[ nPos
] == pItem
)
4522 return ITEM_NOTFOUND
;
4525 void ToolBox::ChangeHighlight( ImplToolItems::size_type nPos
)
4527 if ( nPos
< GetItemCount() ) {
4528 ImplGrabFocus( GetFocusFlags::NONE
);
4529 ImplChangeHighlight ( ImplGetItem ( GetItemId ( nPos
) ) );
4533 void ToolBox::ImplChangeHighlight( ImplToolItem
const * pItem
, bool bNoGrabFocus
)
4535 // avoid recursion due to focus change
4536 if( mbChangingHighlight
)
4539 mbChangingHighlight
= true;
4541 ImplToolItem
* pOldItem
= nullptr;
4546 ImplToolItems::size_type nPos
= GetItemPos( mnHighItemId
);
4547 pOldItem
= ImplGetItem( mnHighItemId
);
4548 // #i89962# ImplDrawItem can cause Invalidate/Update
4549 // which will in turn ImplShowFocus again
4550 // set mnHighItemId to 0 already to prevent this hen/egg problem
4551 mnHighItemId
= ToolBoxItemId(0);
4552 InvalidateItem(nPos
);
4553 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nPos
) );
4556 if( !bNoGrabFocus
&& pItem
!= pOldItem
&& pOldItem
&& pOldItem
->mpWindow
)
4558 // move focus into toolbox
4564 ImplToolItems::size_type aPos
= ToolBox::ImplFindItemPos( pItem
, mpData
->m_aItems
);
4565 if( aPos
!= ITEM_NOTFOUND
)
4567 // check for line breaks
4568 ImplToolItems::size_type nLine
= ImplGetItemLine( pItem
);
4570 if( nLine
>= mnCurLine
+ mnVisLines
)
4572 mnCurLine
= nLine
- mnVisLines
+ 1;
4575 else if ( nLine
< mnCurLine
)
4586 mnHighItemId
= pItem
->mnId
;
4587 InvalidateItem(aPos
);
4591 if( pItem
->mpWindow
)
4592 pItem
->mpWindow
->GrabFocus();
4593 if( pItem
!= pOldItem
)
4594 CallEventListeners( VclEventId::ToolboxHighlight
);
4600 mnHighItemId
= ToolBoxItemId(0);
4601 mnCurPos
= ITEM_NOTFOUND
;
4604 mbChangingHighlight
= false;
4607 // check for keyboard accessible items
4608 static bool ImplIsValidItem( const ImplToolItem
* pItem
, bool bNotClipped
)
4610 bool bValid
= (pItem
&& pItem
->meType
== ToolBoxItemType::BUTTON
&& pItem
->mbVisible
&& !ImplIsFixedControl( pItem
)
4611 && pItem
->mbEnabled
);
4612 if( bValid
&& bNotClipped
&& pItem
->IsClipped() )
4617 bool ToolBox::ImplChangeHighlightUpDn( bool bUp
, bool bNoCycle
)
4619 ImplToolItem
* pToolItem
= ImplGetItem( mnHighItemId
);
4621 if( !pToolItem
|| !mnHighItemId
)
4623 // menubutton highlighted ?
4624 if( mpData
->mbMenubuttonSelected
)
4626 mpData
->mbMenubuttonSelected
= false;
4629 // select last valid non-clipped item
4630 ImplToolItem
* pItem
= nullptr;
4631 auto it
= std::find_if(mpData
->m_aItems
.rbegin(), mpData
->m_aItems
.rend(),
4632 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, true ); });
4633 if( it
!= mpData
->m_aItems
.rend() )
4636 InvalidateMenuButton();
4637 ImplChangeHighlight( pItem
);
4641 // select first valid non-clipped item
4642 ImplToolItems::iterator it
= std::find_if(mpData
->m_aItems
.begin(), mpData
->m_aItems
.end(),
4643 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, true ); });
4644 if( it
!= mpData
->m_aItems
.end() )
4646 InvalidateMenuButton();
4647 ImplChangeHighlight( &(*it
) );
4655 // Select first valid item
4656 ImplToolItems::iterator it
= std::find_if(mpData
->m_aItems
.begin(), mpData
->m_aItems
.end(),
4657 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, false ); });
4659 // select the menu button if a clipped item would be selected
4660 if( (it
!= mpData
->m_aItems
.end() && &(*it
) == ImplGetFirstClippedItem()) && IsMenuEnabled() )
4662 ImplChangeHighlight( nullptr );
4663 mpData
->mbMenubuttonSelected
= true;
4664 InvalidateMenuButton();
4667 ImplChangeHighlight( (it
!= mpData
->m_aItems
.end()) ? &(*it
) : nullptr );
4672 // Select last valid item
4674 // docked toolbars have the menubutton as last item - if this button is enabled
4675 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4677 ImplChangeHighlight( nullptr );
4678 mpData
->mbMenubuttonSelected
= true;
4679 InvalidateMenuButton();
4683 ImplToolItem
* pItem
= nullptr;
4684 auto it
= std::find_if(mpData
->m_aItems
.rbegin(), mpData
->m_aItems
.rend(),
4685 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, false ); });
4686 if( it
!= mpData
->m_aItems
.rend() )
4689 ImplChangeHighlight( pItem
);
4697 ImplToolItems::size_type pos
= ToolBox::ImplFindItemPos( pToolItem
, mpData
->m_aItems
);
4698 ImplToolItems::size_type nCount
= mpData
->m_aItems
.size();
4700 ImplToolItems::size_type i
=0;
4710 // highlight the menu button if it is the last item
4711 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4713 ImplChangeHighlight( nullptr );
4714 mpData
->mbMenubuttonSelected
= true;
4715 InvalidateMenuButton();
4724 if( ++pos
>= nCount
)
4729 // highlight the menu button if it is the last item
4730 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4732 ImplChangeHighlight( nullptr );
4733 mpData
->mbMenubuttonSelected
= true;
4734 InvalidateMenuButton();
4742 pToolItem
= &mpData
->m_aItems
[pos
];
4744 if ( ImplIsValidItem( pToolItem
, false ) )
4747 } while( ++i
< nCount
);
4749 if( pToolItem
->IsClipped() && IsMenuEnabled() )
4751 // select the menu button if a clipped item would be selected
4752 ImplChangeHighlight( nullptr );
4753 mpData
->mbMenubuttonSelected
= true;
4754 InvalidateMenuButton();
4756 else if( i
!= nCount
)
4757 ImplChangeHighlight( pToolItem
);
4764 void ToolBox::ImplShowFocus()
4766 if( mnHighItemId
&& HasFocus() )
4768 ImplToolItem
* pItem
= ImplGetItem( mnHighItemId
);
4769 if (pItem
&& pItem
->mpWindow
&& !pItem
->mpWindow
->isDisposed())
4771 vcl::Window
*pWin
= pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
? pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
.get() : pItem
->mpWindow
.get();
4772 pWin
->ImplGetWindowImpl()->mbDrawSelectionBackground
= true;
4778 void ToolBox::ImplHideFocus()
4782 mpData
->mbMenubuttonWasLastSelected
= false;
4783 ImplToolItem
* pItem
= ImplGetItem( mnHighItemId
);
4784 if( pItem
&& pItem
->mpWindow
)
4786 vcl::Window
*pWin
= pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
? pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
.get() : pItem
->mpWindow
.get();
4787 pWin
->ImplGetWindowImpl()->mbDrawSelectionBackground
= false;
4792 if ( mpData
&& mpData
->mbMenubuttonSelected
)
4794 mpData
->mbMenubuttonWasLastSelected
= true;
4795 // remove highlight from menubutton
4796 mpData
->mbMenubuttonSelected
= false;
4797 InvalidateMenuButton();
4801 void ToolBox::SetToolbarLayoutMode( ToolBoxLayoutMode eLayout
)
4803 if ( meLayoutMode
!= eLayout
)
4804 meLayoutMode
= eLayout
;
4807 void ToolBox::SetToolBoxTextPosition( ToolBoxTextPosition ePosition
)
4809 meTextPosition
= ePosition
;
4812 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */