1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/toolbox.hxx>
21 #include <vcl/commandinfoprovider.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/decoview.hxx>
24 #include <vcl/accel.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/help.hxx>
27 #include <vcl/mnemonic.hxx>
28 #include <vcl/gradient.hxx>
29 #include <vcl/layout.hxx>
30 #include <vcl/menu.hxx>
31 #include <vcl/settings.hxx>
32 #include <vclstatuslistener.hxx>
33 #include <vcl/ptrstyle.hxx>
34 #include <bitmaps.hlst>
36 #include <tools/poly.hxx>
37 #include <svl/imageitm.hxx>
38 #include <sal/log.hxx>
39 #include <osl/diagnose.h>
54 #define SMALLBUTTON_HSIZE 7
55 #define SMALLBUTTON_VSIZE 7
57 #define SMALLBUTTON_OFF_NORMAL_X 3
58 #define SMALLBUTTON_OFF_NORMAL_Y 3
60 #define TB_TEXTOFFSET 2
61 #define TB_IMAGETEXTOFFSET 3
62 #define TB_LINESPACING 3
63 #define TB_SPIN_SIZE 14
64 #define TB_SPIN_OFFSET 2
65 #define TB_BORDER_OFFSET1 4
66 #define TB_BORDER_OFFSET2 2
68 #define TB_MAXNOSCROLL 32765
70 #define TB_DRAGWIDTH 8 // the default width of the drag grip
72 #define TB_CALCMODE_HORZ 1
73 #define TB_CALCMODE_VERT 2
74 #define TB_CALCMODE_FLOAT 3
76 #define TB_WBLINESIZING (WB_SIZEABLE | WB_DOCKABLE | WB_SCROLL)
78 #define DOCK_LINEHSIZE (sal_uInt16(0x0001))
79 #define DOCK_LINEVSIZE (sal_uInt16(0x0002))
80 #define DOCK_LINERIGHT (sal_uInt16(0x1000))
81 #define DOCK_LINEBOTTOM (sal_uInt16(0x2000))
82 #define DOCK_LINELEFT (sal_uInt16(0x4000))
83 #define DOCK_LINETOP (sal_uInt16(0x8000))
84 #define DOCK_LINEOFFSET 3
89 VclPtr
<ToolBox
> mpDragBox
;
91 tools::Rectangle maRect
;
92 tools::Rectangle maStartRect
;
94 sal_uInt16 mnLineMode
;
95 ToolBox::ImplToolItems::size_type mnStartLines
;
97 ImplTBDragMgr(const ImplTBDragMgr
&) = delete;
98 ImplTBDragMgr
& operator=(const ImplTBDragMgr
&) = delete;
103 void StartDragging( ToolBox
* pDragBox
, const Point
& rPos
, const tools::Rectangle
& rRect
, sal_uInt16 nLineMode
);
104 void Dragging( const Point
& rPos
);
105 void EndDragging( bool bOK
= true );
106 DECL_LINK( SelectHdl
, Accelerator
&, void );
110 static ImplTBDragMgr
* ImplGetTBDragMgr()
112 ImplSVData
* pSVData
= ImplGetSVData();
113 if ( !pSVData
->maCtrlData
.mpTBDragMgr
)
114 pSVData
->maCtrlData
.mpTBDragMgr
= new ImplTBDragMgr
;
115 return pSVData
->maCtrlData
.mpTBDragMgr
;
118 int ToolBox::ImplGetDragWidth( const vcl::RenderContext
& rRenderContext
, bool bHorz
)
120 int nWidth
= TB_DRAGWIDTH
;
121 if( rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Entire
) )
124 ImplControlValue aControlValue
;
125 tools::Rectangle aContent
, aBound
;
126 tools::Rectangle
aArea( Point(), rRenderContext
.GetOutputSizePixel() );
128 if ( rRenderContext
.GetNativeControlRegion(ControlType::Toolbar
,
129 bHorz
? ControlPart::ThumbVert
: ControlPart::ThumbHorz
,
130 aArea
, ControlState::NONE
, aControlValue
, aBound
, aContent
) )
132 nWidth
= bHorz
? aContent
.GetWidth() : aContent
.GetHeight();
136 // increase the hit area of the drag handle according to DPI scale factor
137 nWidth
*= rRenderContext
.GetDPIScaleFactor();
142 int ToolBox::ImplGetDragWidth() const
144 return ToolBox::ImplGetDragWidth( *this, mbHorz
);
147 static ButtonType
determineButtonType( ImplToolItem
const * pItem
, ButtonType defaultType
)
149 ButtonType tmpButtonType
= defaultType
;
150 ToolBoxItemBits nBits
= pItem
->mnBits
& ( ToolBoxItemBits::TEXT_ONLY
| ToolBoxItemBits::ICON_ONLY
);
151 if ( nBits
!= ToolBoxItemBits::NONE
) // item has custom setting
153 tmpButtonType
= ButtonType::SYMBOLTEXT
;
154 if ( nBits
== ToolBoxItemBits::TEXT_ONLY
)
155 tmpButtonType
= ButtonType::TEXT
;
156 else if ( nBits
== ToolBoxItemBits::ICON_ONLY
)
157 tmpButtonType
= ButtonType::SYMBOLONLY
;
159 return tmpButtonType
;
162 void ToolBox::ImplUpdateDragArea() const
164 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
167 if ( ImplIsFloatingMode() || pWrapper
->IsLocked() )
168 pWrapper
->SetDragArea( tools::Rectangle() );
171 if( meAlign
== WindowAlign::Top
|| meAlign
== WindowAlign::Bottom
)
172 pWrapper
->SetDragArea( tools::Rectangle( 0, 0, ImplGetDragWidth(), GetOutputSizePixel().Height() ) );
174 pWrapper
->SetDragArea( tools::Rectangle( 0, 0, GetOutputSizePixel().Width(), ImplGetDragWidth() ) );
179 void ToolBox::ImplCalcBorder( WindowAlign eAlign
, tools::Long
& rLeft
, tools::Long
& rTop
,
180 tools::Long
& rRight
, tools::Long
& rBottom
) const
182 if( ImplIsFloatingMode() || !(mnWinStyle
& WB_BORDER
) )
184 // no border in floating mode
185 rLeft
= rTop
= rRight
= rBottom
= 0;
189 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
191 // reserve DragArea only for dockable toolbars
192 int dragwidth
= ( pWrapper
&& !pWrapper
->IsLocked() ) ? ImplGetDragWidth() : 0;
194 // no shadow border for dockable toolbars and toolbars with WB_NOSHADOW bit set, e.g. Calc's formulabar
195 int borderwidth
= ( pWrapper
|| mnWinStyle
& WB_NOSHADOW
) ? 0 : 2;
197 if ( eAlign
== WindowAlign::Top
)
199 rLeft
= borderwidth
+dragwidth
;
201 rRight
= borderwidth
;
204 else if ( eAlign
== WindowAlign::Left
)
207 rTop
= borderwidth
+dragwidth
;
209 rBottom
= borderwidth
;
211 else if ( eAlign
== WindowAlign::Bottom
)
213 rLeft
= borderwidth
+dragwidth
;
215 rRight
= borderwidth
;
216 rBottom
= borderwidth
;
221 rTop
= borderwidth
+dragwidth
;
222 rRight
= borderwidth
;
223 rBottom
= borderwidth
;
227 void ToolBox::ImplCheckUpdate()
229 // remove any pending invalidates to avoid
230 // have them triggered when paint is locked (see mpData->mbIsPaintLocked)
231 // which would result in erasing the background only and not painting any items
232 // this must not be done when we're already in Paint()
234 // this is only required for transparent toolbars (see ImplDrawTransparentBackground() )
235 if( !IsBackground() && HasPaintEvent() && !IsInPaint() )
239 void ToolBox::ImplDrawGrip(vcl::RenderContext
& rRenderContext
,
240 const tools::Rectangle
&aDragArea
, int nDragWidth
, WindowAlign eAlign
, bool bHorz
)
242 bool bNativeOk
= false;
243 const ControlPart ePart
= bHorz
? ControlPart::ThumbVert
: ControlPart::ThumbHorz
;
244 const Size
aSz( rRenderContext
.GetOutputSizePixel() );
245 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ePart
))
247 ToolbarValue aToolbarValue
;
248 aToolbarValue
.maGripRect
= aDragArea
;
250 tools::Rectangle
aCtrlRegion(Point(), aSz
);
252 bNativeOk
= rRenderContext
.DrawNativeControl( ControlType::Toolbar
, ePart
,
253 aCtrlRegion
, ControlState::ENABLED
, aToolbarValue
, OUString() );
259 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
260 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
261 rRenderContext
.SetFillColor(rStyleSettings
.GetShadowColor());
263 float fScaleFactor
= rRenderContext
.GetDPIScaleFactor();
265 if (eAlign
== WindowAlign::Top
|| eAlign
== WindowAlign::Bottom
)
267 int height
= static_cast<int>(0.6 * aSz
.Height() + 0.5);
268 int i
= (aSz
.Height() - height
) / 2;
272 int x
= nDragWidth
/ 2;
273 rRenderContext
.DrawEllipse(tools::Rectangle(Point(x
, i
), Size(2 * fScaleFactor
, 2 * fScaleFactor
)));
274 i
+= 4 * fScaleFactor
;
279 int width
= static_cast<int>(0.6 * aSz
.Width() + 0.5);
280 int i
= (aSz
.Width() - width
) / 2;
284 int y
= nDragWidth
/ 2;
285 rRenderContext
.DrawEllipse(tools::Rectangle(Point(i
, y
), Size(2 * fScaleFactor
, 2 * fScaleFactor
)));
286 i
+= 4 * fScaleFactor
;
291 void ToolBox::ImplDrawGrip(vcl::RenderContext
& rRenderContext
)
293 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
294 if( pWrapper
&& !pWrapper
->GetDragArea().IsEmpty() )
296 // execute pending paint requests
298 ImplDrawGrip( rRenderContext
, pWrapper
->GetDragArea(),
299 ImplGetDragWidth(), meAlign
, mbHorz
);
303 void ToolBox::ImplDrawGradientBackground(vcl::RenderContext
& rRenderContext
)
305 // draw a nice gradient
307 Color startCol
, endCol
;
308 const StyleSettings rSettings
= rRenderContext
.GetSettings().GetStyleSettings();
310 startCol
= rSettings
.GetFaceGradientColor();
311 endCol
= rSettings
.GetFaceColor();
312 if (rSettings
.GetHighContrastMode())
313 // no 'extreme' gradient when high contrast
317 g
.SetAngle(Degree10(mbHorz
? 0 : 900));
318 g
.SetStyle(GradientStyle::Linear
);
320 g
.SetStartColor(startCol
);
321 g
.SetEndColor(endCol
);
323 bool bLineColor
= rRenderContext
.IsLineColor();
324 Color aOldCol
= rRenderContext
.GetLineColor();
325 rRenderContext
.SetLineColor(rRenderContext
.GetSettings().GetStyleSettings().GetShadowColor());
327 Size
aFullSz(GetOutputSizePixel());
328 Size
aLineSz(aFullSz
);
330 // use the linesize only when floating
331 // full window height is used when docked (single line)
332 if (ImplIsFloatingMode())
334 tools::Long nLineSize
;
337 nLineSize
= mnMaxItemHeight
;
338 if (mnWinHeight
> mnMaxItemHeight
)
339 nLineSize
= mnWinHeight
;
341 aLineSz
.setHeight( nLineSize
);
345 nLineSize
= mnMaxItemWidth
;
346 aLineSz
.setWidth( nLineSize
);
350 tools::Long nLeft
, nTop
, nRight
, nBottom
;
351 ImplCalcBorder(meAlign
, nLeft
, nTop
, nRight
, nBottom
);
353 Size
aTopLineSz(aLineSz
);
354 Size
aBottomLineSz(aLineSz
);
356 if (mnWinStyle
& WB_BORDER
)
360 aTopLineSz
.AdjustHeight(TB_BORDER_OFFSET2
+ nTop
);
361 aBottomLineSz
.AdjustHeight(TB_BORDER_OFFSET2
+ nBottom
);
364 aTopLineSz
.AdjustHeight(TB_BORDER_OFFSET2
+ nBottom
);
368 aTopLineSz
.AdjustWidth(TB_BORDER_OFFSET1
+ nLeft
);
369 aBottomLineSz
.AdjustWidth(TB_BORDER_OFFSET1
+ nRight
);
372 aTopLineSz
.AdjustWidth(TB_BORDER_OFFSET1
+ nLeft
);
380 aLineSz
.AdjustHeight(TB_LINESPACING
);
382 aTopLineSz
.AdjustHeight(TB_LINESPACING
);
386 aLineSz
.AdjustWidth(TB_LINESPACING
);
388 aTopLineSz
.AdjustWidth(TB_LINESPACING
);
396 rRenderContext
.DrawGradient(tools::Rectangle(0, y
, aTopLineSz
.Width(), y
+ aTopLineSz
.Height()), g
);
397 y
+= aTopLineSz
.Height();
399 while (y
< (mnDY
- aBottomLineSz
.Height()))
401 rRenderContext
.DrawGradient(tools::Rectangle(0, y
, aLineSz
.Width(), y
+ aLineSz
.Height()), g
);
402 y
+= aLineSz
.Height();
405 rRenderContext
.DrawGradient(tools::Rectangle(0, y
, aBottomLineSz
.Width(), y
+ aBottomLineSz
.Height()), g
);
411 rRenderContext
.DrawGradient(tools::Rectangle(x
, 0, x
+ aTopLineSz
.Width(), aTopLineSz
.Height()), g
);
412 x
+= aTopLineSz
.Width();
414 while (x
< (mnDX
- aBottomLineSz
.Width()))
416 rRenderContext
.DrawGradient(tools::Rectangle(x
, 0, x
+ aLineSz
.Width(), aLineSz
.Height()), g
);
417 x
+= aLineSz
.Width();
420 rRenderContext
.DrawGradient(tools::Rectangle( x
, 0, x
+ aBottomLineSz
.Width(), aBottomLineSz
.Height()), g
);
424 rRenderContext
.SetLineColor( aOldCol
);
428 bool ToolBox::ImplDrawNativeBackground(vcl::RenderContext
& rRenderContext
)
431 tools::Rectangle
aCtrlRegion(Point(), GetOutputSizePixel());
433 return rRenderContext
.DrawNativeControl( ControlType::Toolbar
, mbHorz
? ControlPart::DrawBackgroundHorz
: ControlPart::DrawBackgroundVert
,
434 aCtrlRegion
, ControlState::ENABLED
, ImplControlValue(), OUString() );
437 void ToolBox::ImplDrawTransparentBackground(const vcl::Region
&rRegion
)
439 // just invalidate to trigger paint of the parent
440 const bool bOldPaintLock
= mpData
->mbIsPaintLocked
;
441 mpData
->mbIsPaintLocked
= true;
443 // send an invalidate to the first opaque parent and invalidate the whole hierarchy from there (noclipchildren)
444 Invalidate(rRegion
, InvalidateFlags::Update
| InvalidateFlags::NoClipChildren
);
446 mpData
->mbIsPaintLocked
= bOldPaintLock
;
449 void ToolBox::ImplDrawConstantBackground(vcl::RenderContext
& rRenderContext
, const vcl::Region
&rRegion
, bool bIsInPopupMode
)
451 // draw a constant color
454 // default background
455 rRenderContext
.Erase(rRegion
.GetBoundRect());
459 // use different color in popupmode
460 const StyleSettings rSettings
= rRenderContext
.GetSettings().GetStyleSettings();
461 Wallpaper
aWallpaper(rSettings
.GetFaceGradientColor());
462 rRenderContext
.DrawWallpaper(rRegion
.GetBoundRect(), aWallpaper
);
466 void ToolBox::ImplDrawBackground(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
468 // execute pending paint requests
471 ImplDockingWindowWrapper
* pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
472 bool bIsInPopupMode
= ImplIsInPopupMode();
474 vcl::Region
aPaintRegion(rRect
);
476 // make sure we do not invalidate/erase too much
478 aPaintRegion
.Intersect(GetActiveClipRegion());
480 rRenderContext
.Push(PushFlags::CLIPREGION
);
481 rRenderContext
.IntersectClipRegion( aPaintRegion
);
485 // no gradient for ordinary toolbars (not dockable)
486 if( !IsBackground() && !IsInPaint() )
487 ImplDrawTransparentBackground(aPaintRegion
);
489 ImplDrawConstantBackground(rRenderContext
, aPaintRegion
, bIsInPopupMode
);
493 // toolbars known to the dockingmanager will be drawn using NWF or a gradient
494 // docked toolbars are transparent and NWF is already used in the docking area which is their common background
495 // so NWF is used here for floating toolbars only
496 bool bNativeOk
= false;
497 if( ImplIsFloatingMode() && rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Entire
) )
498 bNativeOk
= ImplDrawNativeBackground(rRenderContext
);
501 const StyleSettings rSetting
= Application::GetSettings().GetStyleSettings();
502 const bool isHeader
= GetAlign() == WindowAlign::Top
&& !rSetting
.GetPersonaHeader().IsEmpty();
503 const bool isFooter
= GetAlign() == WindowAlign::Bottom
&& !rSetting
.GetPersonaFooter().IsEmpty();
504 if (!IsBackground() || isHeader
|| isFooter
)
507 ImplDrawTransparentBackground(aPaintRegion
);
510 ImplDrawGradientBackground(rRenderContext
);
514 // restore clip region
515 rRenderContext
.Pop();
518 void ToolBox::ImplErase(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&rRect
, bool bHighlight
, bool bHasOpenPopup
)
520 // the background of non NWF buttons is painted in a constant color
521 // to have the same highlight color (transparency in DrawSelectionBackground())
522 // items with open popups will also painted using a constant color
523 if (!mpData
->mbNativeButtons
&&
524 (bHighlight
|| !(GetStyle() & WB_3DLOOK
)))
526 if (GetStyle() & WB_3DLOOK
)
528 rRenderContext
.Push(PushFlags::LINECOLOR
| PushFlags::FILLCOLOR
);
529 rRenderContext
.SetLineColor();
531 // choose the same color as the popup will use
532 rRenderContext
.SetFillColor(rRenderContext
.GetSettings().GetStyleSettings().GetFaceGradientColor());
534 rRenderContext
.SetFillColor(COL_WHITE
);
536 rRenderContext
.DrawRect(rRect
);
537 rRenderContext
.Pop();
540 ImplDrawBackground(rRenderContext
, rRect
);
543 ImplDrawBackground(rRenderContext
, rRect
);
546 void ToolBox::ImplDrawBorder(vcl::RenderContext
& rRenderContext
)
548 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
549 tools::Long nDX
= mnDX
;
550 tools::Long nDY
= mnDY
;
552 ImplDockingWindowWrapper
* pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper(this);
554 // draw borders for ordinary toolbars only (not dockable), do not draw borders for toolbars with WB_NOSHADOW bit set,
555 // e.g. Calc's formulabar
557 if( pWrapper
|| mnWinStyle
& WB_NOSHADOW
)
560 if (meAlign
== WindowAlign::Bottom
)
562 // draw bottom border
563 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
564 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-1, nDY
-2 ) );
565 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
566 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
571 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
572 rRenderContext
.DrawLine( Point( 0, 0 ), Point( nDX
-1, 0 ) );
573 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
574 rRenderContext
.DrawLine( Point( 0, 1 ), Point( nDX
-1, 1 ) );
576 if (meAlign
== WindowAlign::Left
|| meAlign
== WindowAlign::Right
)
578 if (meAlign
== WindowAlign::Left
)
580 // draw left-bottom border
581 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
582 rRenderContext
.DrawLine( Point( 0, 0 ), Point( 0, nDY
-1 ) );
583 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-1, nDY
-2 ) );
584 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
585 rRenderContext
.DrawLine( Point( 1, 1 ), Point( 1, nDY
-3 ) );
586 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
590 // draw right-bottom border
591 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
592 rRenderContext
.DrawLine( Point( nDX
-2, 0 ), Point( nDX
-2, nDY
-3 ) );
593 rRenderContext
.DrawLine( Point( 0, nDY
-2 ), Point( nDX
-2, nDY
-2 ) );
594 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
595 rRenderContext
.DrawLine( Point( nDX
-1, 0 ), Point( nDX
-1, nDY
-1 ) );
596 rRenderContext
.DrawLine( Point( 0, nDY
-1 ), Point( nDX
-1, nDY
-1 ) );
601 if ( meAlign
== WindowAlign::Bottom
|| meAlign
== WindowAlign::Top
)
604 rRenderContext
.SetLineColor( rStyleSettings
.GetShadowColor() );
605 rRenderContext
.DrawLine( Point( nDX
-2, 0 ), Point( nDX
-2, nDY
-1 ) );
606 rRenderContext
.SetLineColor( rStyleSettings
.GetLightColor() );
607 rRenderContext
.DrawLine( Point( nDX
-1, 0 ), Point( nDX
-1, nDY
-1 ) );
611 static bool ImplIsFixedControl( const ImplToolItem
*pItem
)
613 return ( pItem
->mpWindow
&&
614 (pItem
->mbNonInteractiveWindow
||
615 pItem
->mpWindow
->GetType() == WindowType::FIXEDTEXT
||
616 pItem
->mpWindow
->GetType() == WindowType::FIXEDLINE
||
617 pItem
->mpWindow
->GetType() == WindowType::GROUPBOX
) );
620 const ImplToolItem
*ToolBox::ImplGetFirstClippedItem() const
622 for (auto & item
: mpData
->m_aItems
)
624 if( item
.IsClipped() )
630 Size
ToolBox::ImplCalcSize( ImplToolItems::size_type nCalcLines
, sal_uInt16 nCalcMode
)
633 tools::Long nLeft
= 0;
634 tools::Long nTop
= 0;
635 tools::Long nRight
= 0;
636 tools::Long nBottom
= 0;
638 WindowAlign eOldAlign
= meAlign
;
639 bool bOldHorz
= mbHorz
;
640 bool bOldAssumeDocked
= mpData
->mbAssumeDocked
;
641 bool bOldAssumeFloating
= mpData
->mbAssumeFloating
;
645 bool bOldFloatingMode
= ImplIsFloatingMode();
647 mpData
->mbAssumeDocked
= false;
648 mpData
->mbAssumeFloating
= false;
650 if ( nCalcMode
== TB_CALCMODE_HORZ
)
652 mpData
->mbAssumeDocked
= true; // force non-floating mode during calculation
653 ImplCalcBorder( WindowAlign::Top
, nLeft
, nTop
, nRight
, nBottom
);
655 if ( mbHorz
!= bOldHorz
)
656 meAlign
= WindowAlign::Top
;
658 else if ( nCalcMode
== TB_CALCMODE_VERT
)
660 mpData
->mbAssumeDocked
= true; // force non-floating mode during calculation
661 ImplCalcBorder( WindowAlign::Left
, nLeft
, nTop
, nRight
, nBottom
);
663 if ( mbHorz
!= bOldHorz
)
664 meAlign
= WindowAlign::Left
;
666 else if ( nCalcMode
== TB_CALCMODE_FLOAT
)
668 mpData
->mbAssumeFloating
= true; // force non-floating mode during calculation
669 nLeft
= nTop
= nRight
= nBottom
= 0;
671 if ( mbHorz
!= bOldHorz
)
672 meAlign
= WindowAlign::Top
;
675 if ( (meAlign
!= eOldAlign
) || (mbHorz
!= bOldHorz
) ||
676 (ImplIsFloatingMode() != bOldFloatingMode
) )
680 ImplCalcBorder( meAlign
, nLeft
, nTop
, nRight
, nBottom
);
684 if( !nCalcMode
&& ImplIsFloatingMode() )
686 aSize
= ImplCalcFloatSize( nCalcLines
);
692 if ( mnWinHeight
> mnMaxItemHeight
)
693 aSize
.setHeight( nCalcLines
* mnWinHeight
);
695 aSize
.setHeight( nCalcLines
* mnMaxItemHeight
);
698 aSize
.AdjustHeight((nCalcLines
-1)*TB_LINESPACING
);
700 if ( mnWinStyle
& WB_BORDER
)
701 aSize
.AdjustHeight((TB_BORDER_OFFSET2
*2) + nTop
+ nBottom
);
704 ImplCalcBreaks( TB_MAXNOSCROLL
, &nMax
, mbHorz
);
706 aSize
.AdjustWidth(nMax
);
708 if ( mnWinStyle
& WB_BORDER
)
709 aSize
.AdjustWidth((TB_BORDER_OFFSET1
*2) + nLeft
+ nRight
);
713 aSize
.setWidth( nCalcLines
* mnMaxItemWidth
);
716 aSize
.AdjustWidth((nCalcLines
-1)*TB_LINESPACING
);
718 if ( mnWinStyle
& WB_BORDER
)
719 aSize
.AdjustWidth((TB_BORDER_OFFSET2
*2) + nLeft
+ nRight
);
722 ImplCalcBreaks( TB_MAXNOSCROLL
, &nMax
, mbHorz
);
724 aSize
.AdjustHeight(nMax
);
726 if ( mnWinStyle
& WB_BORDER
)
727 aSize
.AdjustHeight((TB_BORDER_OFFSET1
*2) + nTop
+ nBottom
);
730 // restore previous values
733 mpData
->mbAssumeDocked
= bOldAssumeDocked
;
734 mpData
->mbAssumeFloating
= bOldAssumeFloating
;
735 if ( (meAlign
!= eOldAlign
) || (mbHorz
!= bOldHorz
) )
746 void ToolBox::ImplCalcFloatSizes()
748 if ( !maFloatSizes
.empty() )
751 // calculate the minimal size, i.e. where the biggest item just fits
752 tools::Long nCalcSize
= 0;
754 for (auto const& item
: mpData
->m_aItems
)
756 if ( item
.mbVisible
)
760 tools::Long nTempSize
= item
.mpWindow
->GetSizePixel().Width();
761 if ( nTempSize
> nCalcSize
)
762 nCalcSize
= nTempSize
;
766 if( item
.maItemSize
.Width() > nCalcSize
)
767 nCalcSize
= item
.maItemSize
.Width();
772 // calc an upper bound for ImplCalcBreaks below
773 tools::Long upperBoundWidth
= nCalcSize
* mpData
->m_aItems
.size();
775 ImplToolItems::size_type nLines
;
776 ImplToolItems::size_type nCalcLines
;
777 ImplToolItems::size_type nTempLines
;
778 tools::Long nMaxLineWidth
;
779 nCalcLines
= ImplCalcBreaks( nCalcSize
, &nMaxLineWidth
, true );
781 maFloatSizes
.reserve( nCalcLines
);
783 nTempLines
= nLines
= nCalcLines
;
786 tools::Long nHeight
= ImplCalcSize( nTempLines
, TB_CALCMODE_FLOAT
).Height();
789 aSize
.mnWidth
= nMaxLineWidth
+(TB_BORDER_OFFSET1
*2);
790 aSize
.mnHeight
= nHeight
;
791 aSize
.mnLines
= nTempLines
;
792 maFloatSizes
.push_back( aSize
);
798 nCalcSize
+= mnMaxItemWidth
;
799 nTempLines
= ImplCalcBreaks( nCalcSize
, &nMaxLineWidth
, true );
801 while ((nCalcSize
< upperBoundWidth
) && (nLines
< nTempLines
)); // implies nTempLines>1
802 if ( nTempLines
< nLines
)
808 Size
ToolBox::ImplCalcFloatSize( ImplToolItems::size_type
& rLines
)
810 ImplCalcFloatSizes();
814 rLines
= mnFloatLines
;
820 while ( i
+ 1u < maFloatSizes
.size() && rLines
< maFloatSizes
[i
].mnLines
)
825 Size
aSize( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
826 rLines
= maFloatSizes
[i
].mnLines
;
831 void ToolBox::ImplCalcMinMaxFloatSize( Size
& rMinSize
, Size
& rMaxSize
)
833 ImplCalcFloatSizes();
836 rMinSize
= Size( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
837 rMaxSize
= Size( maFloatSizes
[i
].mnWidth
, maFloatSizes
[i
].mnHeight
);
838 while ( ++i
< maFloatSizes
.size() )
840 if( maFloatSizes
[i
].mnWidth
< rMinSize
.Width() )
841 rMinSize
.setWidth( maFloatSizes
[i
].mnWidth
);
842 if( maFloatSizes
[i
].mnHeight
< rMinSize
.Height() )
843 rMinSize
.setHeight( maFloatSizes
[i
].mnHeight
);
845 if( maFloatSizes
[i
].mnWidth
> rMaxSize
.Width() )
846 rMaxSize
.setWidth( maFloatSizes
[i
].mnWidth
);
847 if( maFloatSizes
[i
].mnHeight
> rMaxSize
.Height() )
848 rMaxSize
.setHeight( maFloatSizes
[i
].mnHeight
);
852 void ToolBox::ImplSetMinMaxFloatSize()
854 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
855 Size aMinSize
, aMaxSize
;
856 ImplCalcMinMaxFloatSize( aMinSize
, aMaxSize
);
859 pWrapper
->SetMinOutputSizePixel( aMinSize
);
860 pWrapper
->SetMaxOutputSizePixel( aMaxSize
);
861 pWrapper
->ShowTitleButton( TitleButton::Menu
, bool( GetMenuType() & ToolBoxMenuType::Customize
) );
865 // TODO: change SetMinOutputSizePixel to be not inline
866 SetMinOutputSizePixel( aMinSize
);
867 SetMaxOutputSizePixel( aMaxSize
);
871 ToolBox::ImplToolItems::size_type
ToolBox::ImplCalcLines( tools::Long nToolSize
) const
873 tools::Long nLineHeight
;
877 if ( mnWinHeight
> mnMaxItemHeight
)
878 nLineHeight
= mnWinHeight
;
880 nLineHeight
= mnMaxItemHeight
;
883 nLineHeight
= mnMaxItemWidth
;
885 if ( mnWinStyle
& WB_BORDER
)
886 nToolSize
-= TB_BORDER_OFFSET2
*2;
890 nLineHeight
+= TB_LINESPACING
;
891 nToolSize
+= TB_LINESPACING
;
894 // #i91917# always report at least one line
895 tools::Long nLines
= nToolSize
/nLineHeight
;
902 sal_uInt16
ToolBox::ImplTestLineSize( const Point
& rPos
) const
904 if ( !ImplIsFloatingMode() &&
905 (!mbScroll
|| (mnLines
> 1) || (mnCurLines
> mnVisLines
)) )
907 WindowAlign eAlign
= GetAlign();
909 if ( eAlign
== WindowAlign::Left
)
911 if ( rPos
.X() > mnDX
-DOCK_LINEOFFSET
)
912 return DOCK_LINEHSIZE
| DOCK_LINERIGHT
;
914 else if ( eAlign
== WindowAlign::Top
)
916 if ( rPos
.Y() > mnDY
-DOCK_LINEOFFSET
)
917 return DOCK_LINEVSIZE
| DOCK_LINEBOTTOM
;
919 else if ( eAlign
== WindowAlign::Right
)
921 if ( rPos
.X() < DOCK_LINEOFFSET
)
922 return DOCK_LINEHSIZE
| DOCK_LINELEFT
;
924 else if ( eAlign
== WindowAlign::Bottom
)
926 if ( rPos
.Y() < DOCK_LINEOFFSET
)
927 return DOCK_LINEVSIZE
| DOCK_LINETOP
;
934 void ToolBox::ImplLineSizing( const Point
& rPos
, tools::Rectangle
& rRect
, sal_uInt16 nLineMode
)
937 tools::Long nOneLineSize
;
938 tools::Long nCurSize
;
939 tools::Long nMaxSize
;
943 if ( nLineMode
& DOCK_LINERIGHT
)
945 nCurSize
= rPos
.X() - rRect
.Left();
948 else if ( nLineMode
& DOCK_LINEBOTTOM
)
950 nCurSize
= rPos
.Y() - rRect
.Top();
953 else if ( nLineMode
& DOCK_LINELEFT
)
955 nCurSize
= rRect
.Right() - rPos
.X();
958 else if ( nLineMode
& DOCK_LINETOP
)
960 nCurSize
= rRect
.Bottom() - rPos
.Y();
964 OSL_FAIL( "ImplLineSizing: Trailing else" );
969 Size aWinSize
= GetSizePixel();
970 ImplToolItems::size_type nMaxLines
= std::max(mnLines
, mnCurLines
);
971 if ( nMaxLines
> TB_MAXLINES
)
972 nMaxLines
= TB_MAXLINES
;
975 nOneLineSize
= ImplCalcSize( 1 ).Height();
977 if ( nMaxSize
< aWinSize
.Height() )
978 nMaxSize
= aWinSize
.Height();
982 nOneLineSize
= ImplCalcSize( 1 ).Width();
984 if ( nMaxSize
< aWinSize
.Width() )
985 nMaxSize
= aWinSize
.Width();
988 ImplToolItems::size_type i
= 1;
989 if ( nCurSize
<= nOneLineSize
)
990 nSize
= nOneLineSize
;
994 while ( (nSize
< nCurSize
) && (i
< nMaxLines
) )
997 aSize
= ImplCalcSize( i
);
999 nSize
= aSize
.Height();
1001 nSize
= aSize
.Width();
1002 if ( nSize
> nMaxSize
)
1005 aSize
= ImplCalcSize( i
);
1007 nSize
= aSize
.Height();
1009 nSize
= aSize
.Width();
1015 if ( nLineMode
& DOCK_LINERIGHT
)
1016 rRect
.SetRight( rRect
.Left()+nSize
-1 );
1017 else if ( nLineMode
& DOCK_LINEBOTTOM
)
1018 rRect
.SetBottom( rRect
.Top()+nSize
-1 );
1019 else if ( nLineMode
& DOCK_LINELEFT
)
1020 rRect
.SetLeft( rRect
.Right()-nSize
);
1022 rRect
.SetTop( rRect
.Bottom()-nSize
);
1027 ImplTBDragMgr::ImplTBDragMgr()
1028 : mpDragBox(nullptr)
1032 maAccel
.InsertItem( KEY_RETURN
, vcl::KeyCode( KEY_RETURN
) );
1033 maAccel
.InsertItem( KEY_ESCAPE
, vcl::KeyCode( KEY_ESCAPE
) );
1034 maAccel
.SetSelectHdl( LINK( this, ImplTBDragMgr
, SelectHdl
) );
1037 void ImplTBDragMgr::StartDragging( ToolBox
* pToolBox
,
1038 const Point
& rPos
, const tools::Rectangle
& rRect
,
1039 sal_uInt16 nDragLineMode
)
1041 mpDragBox
= pToolBox
;
1042 pToolBox
->CaptureMouse();
1043 pToolBox
->mbDragging
= true;
1044 Application::InsertAccel( &maAccel
);
1046 mnLineMode
= nDragLineMode
;
1047 mnStartLines
= pToolBox
->mnDockLines
;
1049 // calculate MouseOffset
1050 maMouseOff
.setX( rRect
.Left() - rPos
.X() );
1051 maMouseOff
.setY( rRect
.Top() - rPos
.Y() );
1053 maStartRect
= rRect
;
1054 pToolBox
->ShowTracking( maRect
);
1057 void ImplTBDragMgr::Dragging( const Point
& rPos
)
1059 mpDragBox
->ImplLineSizing( rPos
, maRect
, mnLineMode
);
1060 Point aOff
= mpDragBox
->OutputToScreenPixel( Point() );
1061 maRect
.Move( aOff
.X(), aOff
.Y() );
1062 mpDragBox
->Docking( rPos
, maRect
);
1063 maRect
.Move( -aOff
.X(), -aOff
.Y() );
1064 mpDragBox
->ShowTracking( maRect
);
1067 void ImplTBDragMgr::EndDragging( bool bOK
)
1069 mpDragBox
->HideTracking();
1070 if (mpDragBox
->IsMouseCaptured())
1071 mpDragBox
->ReleaseMouse();
1072 mpDragBox
->mbDragging
= false;
1073 Application::RemoveAccel( &maAccel
);
1077 mpDragBox
->mnDockLines
= mnStartLines
;
1078 mpDragBox
->EndDocking( maStartRect
, false );
1081 mpDragBox
->EndDocking( maRect
, false );
1084 mpDragBox
= nullptr;
1087 IMPL_LINK( ImplTBDragMgr
, SelectHdl
, Accelerator
&, rAccel
, void )
1089 if ( rAccel
.GetCurItemId() == KEY_ESCAPE
)
1090 EndDragging( false );
1095 void ToolBox::ImplInitToolBoxData()
1097 // initialize variables
1098 ImplGetWindowImpl()->mbToolBox
= true;
1099 mpData
.reset(new ImplToolBoxPrivateData
);
1101 mpFloatWin
= nullptr;
1105 mnMaxItemHeight
= 0;
1115 mnCurPos
= ITEM_NOTFOUND
;
1122 mnMouseModifier
= 0;
1129 mbFullPaint
= false;
1132 mbLastFloatMode
= false;
1133 mbCustomize
= false;
1135 mbIsKeyEvent
= false;
1136 mbChangingHighlight
= false;
1137 mbImagesMirrored
= false;
1138 mbLineSpacing
= false;
1139 mbIsArranged
= false;
1140 meButtonType
= ButtonType::SYMBOLONLY
;
1141 meAlign
= WindowAlign::Top
;
1142 meDockAlign
= WindowAlign::Top
;
1143 meLastStyle
= PointerStyle::Arrow
;
1145 meLayoutMode
= ToolBoxLayoutMode::Normal
;
1146 meTextPosition
= ToolBoxTextPosition::Right
;
1147 mnLastFocusItemId
= 0;
1148 mnActivateCount
= 0;
1149 mnImagesRotationAngle
= Degree10(0);
1151 mpStatusListener
= new VclStatusListener
<ToolBox
>(this, ".uno:ImageOrientation");
1152 mpStatusListener
->startListening();
1154 mpIdle
.reset(new Idle("vcl::ToolBox maIdle update"));
1155 mpIdle
->SetPriority( TaskPriority::RESIZE
);
1156 mpIdle
->SetInvokeHandler( LINK( this, ToolBox
, ImplUpdateHdl
) );
1158 // set timeout and handler for dropdown items
1159 mpData
->maDropdownTimer
.SetTimeout( 250 );
1160 mpData
->maDropdownTimer
.SetInvokeHandler( LINK( this, ToolBox
, ImplDropdownLongClickHdl
) );
1161 mpData
->maDropdownTimer
.SetDebugName( "vcl::ToolBox mpData->maDropdownTimer" );
1164 void ToolBox::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
1166 // initialize variables
1167 mbScroll
= (nStyle
& WB_SCROLL
) != 0;
1168 mnWinStyle
= nStyle
;
1170 DockingWindow::ImplInit( pParent
, nStyle
& ~WB_BORDER
);
1172 // dockingwindow's ImplInit removes some bits, so restore them here to allow keyboard handling for toolbars
1173 ImplGetWindowImpl()->mnStyle
|= WB_TABSTOP
|WB_NODIALOGCONTROL
; // always set WB_TABSTOP for ToolBars
1174 ImplGetWindowImpl()->mnStyle
&= ~WB_DIALOGCONTROL
;
1176 ImplInitSettings(true, true, true);
1179 void ToolBox::ApplyForegroundSettings(vcl::RenderContext
& rRenderContext
, const StyleSettings
& rStyleSettings
)
1182 if (IsControlForeground())
1183 aColor
= GetControlForeground();
1184 else if (Window::GetStyle() & WB_3DLOOK
)
1185 aColor
= rStyleSettings
.GetButtonTextColor();
1187 aColor
= rStyleSettings
.GetWindowTextColor();
1188 rRenderContext
.SetTextColor(aColor
);
1189 rRenderContext
.SetTextFillColor();
1192 void ToolBox::ApplyBackgroundSettings(vcl::RenderContext
& rRenderContext
, const StyleSettings
& rStyleSettings
)
1194 if (IsControlBackground())
1196 rRenderContext
.SetBackground(GetControlBackground());
1197 SetPaintTransparent(false);
1198 SetParentClipMode();
1202 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ControlPart::Entire
)
1203 || (GetAlign() == WindowAlign::Top
&& !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty())
1204 || (GetAlign() == WindowAlign::Bottom
&& !Application::GetSettings().GetStyleSettings().GetPersonaFooter().IsEmpty()))
1206 rRenderContext
.SetBackground();
1207 rRenderContext
.SetTextColor(rStyleSettings
.GetToolTextColor());
1208 SetPaintTransparent(true);
1209 SetParentClipMode(ParentClipMode::NoClip
);
1210 mpData
->maDisplayBackground
= Wallpaper(rStyleSettings
.GetFaceColor());
1215 if (Window::GetStyle() & WB_3DLOOK
)
1216 aColor
= rStyleSettings
.GetFaceColor();
1218 aColor
= rStyleSettings
.GetWindowColor();
1219 rRenderContext
.SetBackground(aColor
);
1220 SetPaintTransparent(false);
1221 SetParentClipMode();
1226 void ToolBox::ApplySettings(vcl::RenderContext
& rRenderContext
)
1228 mpData
->mbNativeButtons
= rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, ControlPart::Button
);
1230 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
1232 ApplyControlFont(rRenderContext
, rStyleSettings
.GetToolFont());
1233 ApplyForegroundSettings(rRenderContext
, rStyleSettings
);
1234 ApplyBackgroundSettings(rRenderContext
, rStyleSettings
);
1237 void ToolBox::ImplInitSettings(bool bFont
, bool bForeground
, bool bBackground
)
1239 mpData
->mbNativeButtons
= IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
);
1241 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
1244 ApplyControlFont(*this, rStyleSettings
.GetToolFont());
1245 if (bForeground
|| bFont
)
1246 ApplyForegroundSettings(*this, rStyleSettings
);
1249 ApplyBackgroundSettings(*this, rStyleSettings
);
1250 EnableChildTransparentMode(IsPaintTransparent());
1254 void ToolBox::doDeferredInit(WinBits nBits
)
1256 VclPtr
<vcl::Window
> pParent
= mpDialogParent
;
1257 mpDialogParent
= nullptr;
1258 ImplInit(pParent
, nBits
);
1259 mbIsDeferredInit
= false;
1262 void ToolBox::queue_resize(StateChangedType eReason
)
1264 Window::queue_resize(eReason
);
1267 ToolBox::ToolBox( vcl::Window
* pParent
, WinBits nStyle
) :
1268 DockingWindow( WindowType::TOOLBOX
)
1270 ImplInitToolBoxData();
1271 ImplInit( pParent
, nStyle
);
1274 ToolBox::ToolBox(vcl::Window
* pParent
, const OString
& rID
,
1275 const OUString
& rUIXMLDescription
, const css::uno::Reference
<css::frame::XFrame
> &rFrame
)
1276 : DockingWindow(WindowType::TOOLBOX
)
1278 ImplInitToolBoxData();
1280 loadUI(pParent
, rID
, rUIXMLDescription
, rFrame
);
1282 // calculate size of floating windows and switch if the
1283 // toolbox is initially in floating mode
1284 if ( ImplIsFloatingMode() )
1289 if (!(GetStyle() & WB_HIDE
))
1298 void ToolBox::dispose()
1300 // #103005# make sure our activate/deactivate balance is right
1301 while( mnActivateCount
> 0 )
1304 // terminate popupmode if the floating window is
1307 mpFloatWin
->EndPopupMode( FloatWinPopupEndFlags::Cancel
);
1308 mpFloatWin
= nullptr;
1310 // delete private data
1313 ImplSVData
* pSVData
= ImplGetSVData();
1314 delete pSVData
->maCtrlData
.mpTBDragMgr
;
1315 pSVData
->maCtrlData
.mpTBDragMgr
= nullptr;
1317 if (mpStatusListener
.is())
1318 mpStatusListener
->dispose();
1324 DockingWindow::dispose();
1327 ImplToolItem
* ToolBox::ImplGetItem( sal_uInt16 nItemId
) const
1332 for (auto & item
: mpData
->m_aItems
)
1334 if ( item
.mnId
== nItemId
)
1341 static void ImplAddButtonBorder( tools::Long
&rWidth
, tools::Long
& rHeight
, bool bNativeButtons
)
1343 rWidth
+= SMALLBUTTON_HSIZE
;
1344 rHeight
+= SMALLBUTTON_VSIZE
;
1346 if( bNativeButtons
)
1348 // give more border space for rounded buttons
1354 bool ToolBox::ImplCalcItem()
1356 // recalc required ?
1360 OutputDevice
*pDefault
= Application::GetDefaultDevice();
1361 float fScaleFactor
= pDefault
? pDefault
->GetDPIScaleFactor() : 1.0;
1363 tools::Long nDefWidth
;
1364 tools::Long nDefHeight
;
1365 tools::Long nMaxWidth
= 0;
1366 tools::Long nMaxHeight
= 0;
1367 tools::Long nMinWidth
= 6;
1368 tools::Long nMinHeight
= 6;
1369 tools::Long nDropDownArrowWidth
= TB_DROPDOWNARROWWIDTH
* fScaleFactor
;
1371 nDropDownArrowWidth
*= 3;
1374 // set defaults if image or text is needed but empty
1375 nDefWidth
= GetDefaultImageSize().Width();
1376 nDefHeight
= GetDefaultImageSize().Height();
1379 // determine minimum size necessary in NWF
1381 tools::Rectangle
aRect( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1382 tools::Rectangle
aReg( aRect
);
1383 ImplControlValue aVal
;
1384 tools::Rectangle aNativeBounds
, aNativeContent
;
1385 if( IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
) )
1387 if( GetNativeControlRegion( ControlType::Toolbar
, ControlPart::Button
,
1389 ControlState::ENABLED
| ControlState::ROLLOVER
,
1391 aNativeBounds
, aNativeContent
) )
1393 aRect
= aNativeBounds
;
1394 if( aRect
.GetWidth() > nMinWidth
)
1395 nMinWidth
= aRect
.GetWidth();
1396 if( aRect
.GetHeight() > nMinHeight
)
1397 nMinHeight
= aRect
.GetHeight();
1398 if( nDropDownArrowWidth
< nMinWidth
)
1399 nDropDownArrowWidth
= nMinWidth
;
1400 if( nMinWidth
> mpData
->mnMenuButtonWidth
)
1401 mpData
->mnMenuButtonWidth
= nMinWidth
;
1402 else if( nMinWidth
< TB_MENUBUTTON_SIZE
)
1403 mpData
->mnMenuButtonWidth
= TB_MENUBUTTON_SIZE
;
1407 // also calculate the area for comboboxes, drop down list boxes and spinfields
1408 // as these are often inserted into toolboxes; set mnWinHeight to the
1409 // greater of those values to prevent toolbar flickering (#i103385#)
1410 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1412 if( GetNativeControlRegion( ControlType::Combobox
, ControlPart::Entire
,
1414 ControlState::ENABLED
| ControlState::ROLLOVER
,
1416 aNativeBounds
, aNativeContent
) )
1418 aRect
= aNativeBounds
;
1419 if( aRect
.GetHeight() > mnWinHeight
)
1420 mnWinHeight
= aRect
.GetHeight();
1422 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1424 if( GetNativeControlRegion( ControlType::Listbox
, ControlPart::Entire
,
1426 ControlState::ENABLED
| ControlState::ROLLOVER
,
1428 aNativeBounds
, aNativeContent
) )
1430 aRect
= aNativeBounds
;
1431 if( aRect
.GetHeight() > mnWinHeight
)
1432 mnWinHeight
= aRect
.GetHeight();
1434 aRect
= tools::Rectangle( Point( 0, 0 ), Size( nMinWidth
, nMinHeight
) );
1436 if( GetNativeControlRegion( ControlType::Spinbox
, ControlPart::Entire
,
1438 ControlState::ENABLED
| ControlState::ROLLOVER
,
1440 aNativeBounds
, aNativeContent
) )
1442 aRect
= aNativeBounds
;
1443 if( aRect
.GetHeight() > mnWinHeight
)
1444 mnWinHeight
= aRect
.GetHeight();
1448 if ( ! mpData
->m_aItems
.empty() )
1450 for (auto & item
: mpData
->m_aItems
)
1452 item
.mbVisibleText
= false; // indicates if text will definitely be drawn, influences dropdown pos
1454 if ( item
.meType
== ToolBoxItemType::BUTTON
)
1459 // check if image and/or text exists
1460 bImage
= !!item
.maImage
;
1461 bText
= !item
.maText
.isEmpty();
1462 ButtonType tmpButtonType
= determineButtonType( &item
, meButtonType
); // default to toolbox setting
1463 if ( bImage
|| bText
)
1466 item
.mbEmptyBtn
= false;
1468 if ( tmpButtonType
== ButtonType::SYMBOLONLY
)
1470 // we're drawing images only
1471 if ( bImage
|| !bText
)
1473 item
.maItemSize
= item
.maImage
.GetSizePixel();
1477 item
.maItemSize
= Size( GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
,
1479 item
.mbVisibleText
= true;
1482 else if ( tmpButtonType
== ButtonType::TEXT
)
1484 // we're drawing text only
1485 if ( bText
|| !bImage
)
1487 item
.maItemSize
= Size( GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
,
1489 item
.mbVisibleText
= true;
1493 item
.maItemSize
= item
.maImage
.GetSizePixel();
1498 // we're drawing images and text
1499 item
.maItemSize
.setWidth( bText
? GetCtrlTextWidth( item
.maText
)+TB_TEXTOFFSET
: 0 );
1500 item
.maItemSize
.setHeight( bText
? GetTextHeight() : 0 );
1502 if ( meTextPosition
== ToolBoxTextPosition::Right
)
1504 // leave space between image and text
1506 item
.maItemSize
.AdjustWidth(TB_IMAGETEXTOFFSET
);
1508 // image and text side by side
1509 item
.maItemSize
.AdjustWidth(item
.maImage
.GetSizePixel().Width() );
1510 if ( item
.maImage
.GetSizePixel().Height() > item
.maItemSize
.Height() )
1511 item
.maItemSize
.setHeight( item
.maImage
.GetSizePixel().Height() );
1515 // leave space between image and text
1517 item
.maItemSize
.AdjustHeight(TB_IMAGETEXTOFFSET
);
1520 item
.maItemSize
.AdjustHeight(item
.maImage
.GetSizePixel().Height() );
1521 if ( item
.maImage
.GetSizePixel().Width() > item
.maItemSize
.Width() )
1522 item
.maItemSize
.setWidth( item
.maImage
.GetSizePixel().Width() );
1525 item
.mbVisibleText
= bText
;
1529 { // no image and no text
1530 item
.maItemSize
= Size( nDefWidth
, nDefHeight
);
1531 item
.mbEmptyBtn
= true;
1534 // save the content size
1535 item
.maContentSize
= item
.maItemSize
;
1537 // if required, take window height into consideration
1538 if ( item
.mpWindow
)
1540 tools::Long nHeight
= item
.mpWindow
->GetSizePixel().Height();
1541 if ( nHeight
> mnWinHeight
)
1542 mnWinHeight
= nHeight
;
1545 // add in drop down arrow
1546 if( item
.mnBits
& ToolBoxItemBits::DROPDOWN
)
1548 item
.maItemSize
.AdjustWidth(nDropDownArrowWidth
);
1549 item
.mnDropDownArrowWidth
= nDropDownArrowWidth
;
1552 // text items will be rotated in vertical mode
1553 // -> swap width and height
1554 if( item
.mbVisibleText
&& !mbHorz
)
1556 tools::Long tmp
= item
.maItemSize
.Width();
1557 item
.maItemSize
.setWidth( item
.maItemSize
.Height() );
1558 item
.maItemSize
.setHeight( tmp
);
1560 tmp
= item
.maContentSize
.Width();
1561 item
.maContentSize
.setWidth( item
.maContentSize
.Height() );
1562 item
.maContentSize
.setHeight( tmp
);
1565 else if ( item
.meType
== ToolBoxItemType::SPACE
)
1567 item
.maItemSize
= Size( nDefWidth
, nDefHeight
);
1568 item
.maContentSize
= item
.maItemSize
;
1571 if ( item
.meType
== ToolBoxItemType::BUTTON
|| item
.meType
== ToolBoxItemType::SPACE
)
1574 tools::Long w
= item
.maItemSize
.Width();
1575 tools::Long h
= item
.maItemSize
.Height();
1576 ImplAddButtonBorder( w
, h
, mpData
->mbNativeButtons
);
1577 item
.maItemSize
.setWidth(w
);
1578 item
.maItemSize
.setHeight(h
);
1580 if( item
.meType
== ToolBoxItemType::BUTTON
)
1582 tools::Long nMinW
= std::max(nMinWidth
, item
.maMinimalItemSize
.Width());
1583 tools::Long nMinH
= std::max(nMinHeight
, item
.maMinimalItemSize
.Height());
1585 tools::Long nGrowContentWidth
= 0;
1586 tools::Long nGrowContentHeight
= 0;
1588 if( item
.maItemSize
.Width() < nMinW
)
1590 nGrowContentWidth
= nMinW
- item
.maItemSize
.Width();
1591 item
.maItemSize
.setWidth( nMinW
);
1593 if( item
.maItemSize
.Height() < nMinH
)
1595 nGrowContentHeight
= nMinH
- item
.maItemSize
.Height();
1596 item
.maItemSize
.setHeight( nMinH
);
1599 // grow the content size by the additional available space
1600 item
.maContentSize
.AdjustWidth(nGrowContentWidth
);
1601 item
.maContentSize
.AdjustHeight(nGrowContentHeight
);
1604 // keep track of max item size
1605 if ( item
.maItemSize
.Width() > nMaxWidth
)
1606 nMaxWidth
= item
.maItemSize
.Width();
1607 if ( item
.maItemSize
.Height() > nMaxHeight
)
1608 nMaxHeight
= item
.maItemSize
.Height();
1614 nMaxWidth
= nDefWidth
;
1615 nMaxHeight
= nDefHeight
;
1617 ImplAddButtonBorder( nMaxWidth
, nMaxHeight
, mpData
->mbNativeButtons
);
1620 if( !ImplIsFloatingMode() && GetToolboxButtonSize() != ToolBoxButtonSize::DontCare
1621 && ( meTextPosition
== ToolBoxTextPosition::Right
) )
1623 // make sure all vertical toolbars have the same width and horizontal have the same height
1624 // this depends on the used button sizes
1625 // as this is used for alignment of multiple toolbars
1626 // it is only required for docked toolbars
1628 tools::Long nFixedWidth
= nDefWidth
+nDropDownArrowWidth
;
1629 tools::Long nFixedHeight
= nDefHeight
;
1630 ImplAddButtonBorder( nFixedWidth
, nFixedHeight
, mpData
->mbNativeButtons
);
1633 nMaxHeight
= nFixedHeight
;
1635 nMaxWidth
= nFixedWidth
;
1641 // do we have to recalc the sizes ?
1642 if ( (nMaxWidth
!= mnMaxItemWidth
) || (nMaxHeight
!= mnMaxItemHeight
) )
1644 mnMaxItemWidth
= nMaxWidth
;
1645 mnMaxItemHeight
= nMaxHeight
;
1653 ToolBox::ImplToolItems::size_type
ToolBox::ImplCalcBreaks( tools::Long nWidth
, tools::Long
* pMaxLineWidth
, bool bCalcHorz
) const
1655 sal_uLong nLineStart
= 0;
1656 sal_uLong nGroupStart
= 0;
1657 tools::Long nLineWidth
= 0;
1658 tools::Long nCurWidth
;
1659 tools::Long nLastGroupLineWidth
= 0;
1660 tools::Long nMaxLineWidth
= 0;
1661 ImplToolItems::size_type nLines
= 1;
1663 bool bBreak
= false;
1664 tools::Long nWidthTotal
= nWidth
;
1665 tools::Long nMenuWidth
= 0;
1667 // when docked the menubutton will be in the first line
1668 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1669 nMenuWidth
= mpData
->maMenubuttonItem
.maItemSize
.Width();
1671 // we need to know which item is the last visible one to be able to add
1672 // the menu width in case we are unable to show all the items
1673 ImplToolItems::iterator it
, lastVisible
;
1674 for ( it
= mpData
->m_aItems
.begin(); it
!= mpData
->m_aItems
.end(); ++it
)
1676 if ( it
->mbVisible
)
1680 it
= mpData
->m_aItems
.begin();
1681 while ( it
!= mpData
->m_aItems
.end() )
1683 it
->mbBreak
= bBreak
;
1686 if ( it
->mbVisible
)
1692 if ( it
->meType
== ToolBoxItemType::BUTTON
|| it
->meType
== ToolBoxItemType::SPACE
)
1695 nCurWidth
= it
->maItemSize
.Width();
1697 nCurWidth
= it
->maItemSize
.Height();
1699 if ( it
->mpWindow
&& bCalcHorz
)
1701 tools::Long nWinItemWidth
= it
->mpWindow
->GetSizePixel().Width();
1702 if ( !mbScroll
|| (nWinItemWidth
<= nWidthTotal
) )
1704 nCurWidth
= nWinItemWidth
;
1709 if ( it
->mbEmptyBtn
)
1716 // in case we are able to show all the items, we do not want
1717 // to show the toolbar's menu; otherwise yes
1718 if ( ( ( it
== lastVisible
) && (nLineWidth
+nCurWidth
> nWidthTotal
) && mbScroll
) ||
1719 ( ( it
!= lastVisible
) && (nLineWidth
+nCurWidth
+nMenuWidth
> nWidthTotal
) && mbScroll
) )
1722 else if ( it
->meType
== ToolBoxItemType::SEPARATOR
)
1724 nCurWidth
= it
->mnSepSize
;
1725 if ( !ImplIsFloatingMode() && ( it
!= lastVisible
) && (nLineWidth
+nCurWidth
+nMenuWidth
> nWidthTotal
) )
1728 // treat breaks as separators, except when using old style toolbars (ie. no menu button)
1729 else if ( (it
->meType
== ToolBoxItemType::BREAK
) && !IsMenuEnabled() )
1736 // Add break before the entire group or take group apart?
1737 if ( (it
->meType
== ToolBoxItemType::BREAK
) ||
1738 (nLineStart
== nGroupStart
) )
1740 if ( nLineWidth
> nMaxLineWidth
)
1741 nMaxLineWidth
= nLineWidth
;
1744 nLineStart
= it
- mpData
->m_aItems
.begin();
1745 nGroupStart
= nLineStart
;
1751 if ( nLastGroupLineWidth
> nMaxLineWidth
)
1752 nMaxLineWidth
= nLastGroupLineWidth
;
1754 // if the break is added before the group, set it to
1755 // beginning of line and re-calculate
1757 nLineStart
= nGroupStart
;
1758 it
= mpData
->m_aItems
.begin() + nGroupStart
;
1764 if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
1766 if ( (it
->meType
!= ToolBoxItemType::BUTTON
) || bWindow
)
1768 // found separator or break
1769 nLastGroupLineWidth
= nLineWidth
;
1770 nGroupStart
= it
- mpData
->m_aItems
.begin();
1777 nLineWidth
+= nCurWidth
;
1783 if ( pMaxLineWidth
)
1785 if ( nLineWidth
> nMaxLineWidth
)
1786 nMaxLineWidth
= nLineWidth
;
1788 if( ImplIsFloatingMode() && !ImplIsInPopupMode() )
1790 // leave enough space to display buttons in the decoration
1791 tools::Long aMinWidth
= 2 * GetSettings().GetStyleSettings().GetFloatTitleHeight();
1792 if( nMaxLineWidth
< aMinWidth
)
1793 nMaxLineWidth
= aMinWidth
;
1795 *pMaxLineWidth
= nMaxLineWidth
;
1801 Size
ToolBox::ImplGetOptimalFloatingSize()
1803 if( !ImplIsFloatingMode() )
1806 Size
aCurrentSize( mnDX
, mnDY
);
1807 Size
aSize1( aCurrentSize
);
1808 Size
aSize2( aCurrentSize
);
1810 // try to preserve current height
1812 // calc number of floating lines for current window height
1813 ImplToolItems::size_type nFloatLinesHeight
= ImplCalcLines( mnDY
);
1814 // calc window size according to this number
1815 aSize1
= ImplCalcFloatSize( nFloatLinesHeight
);
1817 if( aCurrentSize
== aSize1
)
1820 // try to preserve current width
1822 tools::Long nLineHeight
= std::max( mnWinHeight
, mnMaxItemHeight
);
1823 int nBorderX
= 2*TB_BORDER_OFFSET1
+ mnLeftBorder
+ mnRightBorder
;
1824 int nBorderY
= 2*TB_BORDER_OFFSET2
+ mnTopBorder
+ mnBottomBorder
;
1825 Size
aSz( aCurrentSize
);
1827 ImplToolItems::size_type nLines
= ImplCalcBreaks( aSz
.Width()-nBorderX
, &maxX
, mbHorz
);
1829 ImplToolItems::size_type manyLines
= 1000;
1830 Size aMinimalFloatSize
= ImplCalcFloatSize( manyLines
);
1832 aSz
.setHeight( nBorderY
+ nLineHeight
* nLines
);
1833 // line space when more than one line
1834 if ( mbLineSpacing
)
1835 aSz
.AdjustHeight((nLines
-1)*TB_LINESPACING
);
1837 aSz
.setWidth( nBorderX
+ maxX
);
1839 // avoid clipping of any items
1840 if( aSz
.Width() < aMinimalFloatSize
.Width() )
1841 aSize2
= ImplCalcFloatSize( nLines
);
1845 if( aCurrentSize
== aSize2
)
1848 // set the size with the smallest delta as the current size
1849 tools::Long dx1
= std::abs( mnDX
- aSize1
.Width() );
1850 tools::Long dy1
= std::abs( mnDY
- aSize1
.Height() );
1852 tools::Long dx2
= std::abs( mnDX
- aSize2
.Width() );
1853 tools::Long dy2
= std::abs( mnDY
- aSize2
.Height() );
1855 if( dx1
*dy1
< dx2
*dy2
)
1856 aCurrentSize
= aSize1
;
1858 aCurrentSize
= aSize2
;
1860 return aCurrentSize
;
1865 void lcl_hideDoubleSeparators( ToolBox::ImplToolItems
& rItems
)
1867 bool bLastSep( true );
1868 ToolBox::ImplToolItems::iterator it
;
1869 for ( it
= rItems
.begin(); it
!= rItems
.end(); ++it
)
1871 if ( it
->meType
== ToolBoxItemType::SEPARATOR
)
1873 it
->mbVisible
= false;
1876 // check if any visible items have to appear behind it
1877 if (std::any_of(it
+ 1, rItems
.end(), [](const ImplToolItem
& rItem
) {
1878 return (rItem
.meType
== ToolBoxItemType::BUTTON
) && rItem
.mbVisible
; }))
1879 it
->mbVisible
= true;
1883 else if ( it
->mbVisible
)
1889 void ToolBox::ImplFormat( bool bResize
)
1891 // Has to re-formatted
1895 mpData
->ImplClearLayoutData();
1897 // recalculate positions and sizes
1898 tools::Rectangle aEmptyRect
;
1899 tools::Long nLineSize
;
1902 tools::Long nMax
; // width of layoutarea in pixels
1903 ImplToolItems::size_type nFormatLine
;
1904 bool bMustFullPaint
;
1906 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
1907 bool bIsInPopupMode
= ImplIsInPopupMode();
1909 maFloatSizes
.clear();
1911 // compute border sizes
1912 ImplCalcBorder( meAlign
, mnLeftBorder
, mnTopBorder
, mnRightBorder
, mnBottomBorder
);
1914 // update drag area (where the 'grip' will be placed)
1915 tools::Rectangle aOldDragRect
;
1917 aOldDragRect
= pWrapper
->GetDragArea();
1918 ImplUpdateDragArea();
1920 bMustFullPaint
= ImplCalcItem();
1922 // calculate new size during interactive resize or
1923 // set computed size when formatting only
1924 if ( ImplIsFloatingMode() )
1927 mnFloatLines
= ImplCalcLines( mnDY
);
1929 SetOutputSizePixel( ImplGetOptimalFloatingSize() );
1935 tools::Long nBottom
;
1936 // nLineSize: height of a single line, will fit highest item
1937 nLineSize
= mnMaxItemHeight
;
1939 if ( mnWinHeight
> mnMaxItemHeight
)
1940 nLineSize
= mnWinHeight
;
1945 mnVisLines
= ImplCalcLines( mnDY
);
1949 // layout over all lines
1950 mnVisLines
= mnLines
;
1951 nMax
= TB_MAXNOSCROLL
;
1954 // add in all border offsets
1955 if ( mnWinStyle
& WB_BORDER
)
1957 nLeft
= TB_BORDER_OFFSET1
+ mnLeftBorder
;
1958 nTop
= TB_BORDER_OFFSET2
+ mnTopBorder
;
1959 nBottom
= TB_BORDER_OFFSET1
+ mnBottomBorder
;
1960 nMax
-= nLeft
+ TB_BORDER_OFFSET1
+ mnRightBorder
;
1969 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
1970 // we have to center all items in the window height
1971 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1973 tools::Long nWinHeight
= mnDY
- nTop
- nBottom
;
1974 if( nWinHeight
> nLineSize
)
1975 nLineSize
= nWinHeight
;
1981 nLineSize
= mnMaxItemWidth
;
1985 mnVisLines
= ImplCalcLines( mnDX
);
1990 mnVisLines
= mnLines
;
1991 nMax
= TB_MAXNOSCROLL
;
1994 if ( mnWinStyle
& WB_BORDER
)
1996 nTop
= TB_BORDER_OFFSET1
+ mnTopBorder
;
1997 nLeft
= TB_BORDER_OFFSET2
+ mnLeftBorder
;
1998 nRight
= TB_BORDER_OFFSET2
+ mnRightBorder
;
1999 nMax
-= nTop
+ TB_BORDER_OFFSET1
+ mnBottomBorder
;
2008 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
2009 // we have to center all items in the window height
2010 if( !ImplIsFloatingMode() && IsMenuEnabled() )
2012 tools::Long nWinWidth
= mnDX
- nLeft
- nRight
;
2013 if( nWinWidth
> nLineSize
)
2014 nLineSize
= nWinWidth
;
2018 // no calculation if the window has no size (nMax=0)
2019 // non scrolling toolboxes must be computed though
2020 if ( (nMax
<= 0) && mbScroll
)
2026 for (auto & item
: mpData
->m_aItems
)
2028 item
.maRect
= aEmptyRect
;
2031 maLowerRect
= aEmptyRect
;
2032 maUpperRect
= aEmptyRect
;
2036 // init start values
2037 tools::Long nX
= nLeft
; // top-left offset
2038 tools::Long nY
= nTop
;
2041 // save old scroll rectangles and reset them
2042 tools::Rectangle aOldLowerRect
= maLowerRect
;
2043 tools::Rectangle aOldUpperRect
= maUpperRect
;
2044 tools::Rectangle aOldMenubuttonRect
= mpData
->maMenubuttonItem
.maRect
;
2045 maUpperRect
= aEmptyRect
;
2046 maLowerRect
= aEmptyRect
;
2047 mpData
->maMenubuttonItem
.maRect
= aEmptyRect
;
2049 // do we have any toolbox items at all ?
2050 if ( !mpData
->m_aItems
.empty() || IsMenuEnabled() )
2052 lcl_hideDoubleSeparators( mpData
->m_aItems
);
2054 // compute line breaks and visible lines give the current window width (nMax)
2055 // the break indicators will be stored within each item (it->mbBreak)
2056 mnCurLines
= ImplCalcBreaks( nMax
, nullptr, mbHorz
);
2058 // check for scrollbar buttons or dropdown menu
2059 // (if a menu is enabled, this will be used to store clipped
2060 // items and no scroll buttons will appear)
2061 if ( (!ImplIsFloatingMode() && (mnCurLines
> mnVisLines
) && mbScroll
) ||
2064 // compute linebreaks again, incorporating scrollbar buttons
2065 if( !IsMenuEnabled() )
2067 nMax
-= TB_SPIN_SIZE
+TB_SPIN_OFFSET
;
2068 mnCurLines
= ImplCalcBreaks( nMax
, nullptr, mbHorz
);
2071 // compute scroll rectangles or menu button
2074 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2076 if( !ImplIsFloatingMode() )
2078 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
- 2 );
2079 mpData
->maMenubuttonItem
.maRect
.SetTop( nTop
);
2080 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2084 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
- mnRightBorder
-TB_BORDER_OFFSET1
-1 );
2085 mpData
->maMenubuttonItem
.maRect
.SetTop( nTop
);
2086 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2088 mpData
->maMenubuttonItem
.maRect
.SetLeft( mpData
->maMenubuttonItem
.maRect
.Right() - mpData
->mnMenuButtonWidth
);
2092 maUpperRect
.SetLeft( nLeft
+nMax
+TB_SPIN_OFFSET
);
2093 maUpperRect
.SetRight( maUpperRect
.Left()+TB_SPIN_SIZE
-1 );
2094 maUpperRect
.SetTop( nTop
);
2095 maLowerRect
.SetBottom( mnDY
-mnBottomBorder
-TB_BORDER_OFFSET2
-1 );
2096 maLowerRect
.SetLeft( maUpperRect
.Left() );
2097 maLowerRect
.SetRight( maUpperRect
.Right() );
2098 maUpperRect
.SetBottom( maUpperRect
.Top() +
2099 (maLowerRect
.Bottom()-maUpperRect
.Top())/2 );
2100 maLowerRect
.SetTop( maUpperRect
.Bottom() );
2105 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2107 if( !ImplIsFloatingMode() )
2109 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
- 2 );
2110 mpData
->maMenubuttonItem
.maRect
.SetLeft( nLeft
);
2111 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2115 mpData
->maMenubuttonItem
.maRect
.SetBottom( mnDY
- mnBottomBorder
-TB_BORDER_OFFSET1
-1 );
2116 mpData
->maMenubuttonItem
.maRect
.SetLeft( nLeft
);
2117 mpData
->maMenubuttonItem
.maRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2119 mpData
->maMenubuttonItem
.maRect
.SetTop( mpData
->maMenubuttonItem
.maRect
.Bottom() - mpData
->mnMenuButtonWidth
);
2123 maUpperRect
.SetTop( nTop
+nMax
+TB_SPIN_OFFSET
);
2124 maUpperRect
.SetBottom( maUpperRect
.Top()+TB_SPIN_SIZE
-1 );
2125 maUpperRect
.SetLeft( nLeft
);
2126 maLowerRect
.SetRight( mnDX
-mnRightBorder
-TB_BORDER_OFFSET2
-1 );
2127 maLowerRect
.SetTop( maUpperRect
.Top() );
2128 maLowerRect
.SetBottom( maUpperRect
.Bottom() );
2129 maUpperRect
.SetRight( maUpperRect
.Left() +
2130 (maLowerRect
.Right()-maUpperRect
.Left())/2 );
2131 maLowerRect
.SetLeft( maUpperRect
.Right() );
2136 // no scrolling when there is a "more"-menu
2137 // anything will "fit" in a single line then
2138 if( IsMenuEnabled() )
2141 // determine the currently visible line
2142 if ( mnVisLines
>= mnCurLines
)
2144 else if ( mnCurLine
+mnVisLines
-1 > mnCurLines
)
2145 mnCurLine
= mnCurLines
- (mnVisLines
-1);
2147 tools::Long firstItemCenter
= 0;
2148 for (auto & item
: mpData
->m_aItems
)
2150 item
.mbShowWindow
= false;
2152 // check for line break and advance nX/nY accordingly
2157 // increment starting with the second line
2158 if ( nFormatLine
> mnCurLine
)
2163 if ( mbLineSpacing
)
2164 nY
+= nLineSize
+TB_LINESPACING
;
2171 if ( mbLineSpacing
)
2172 nX
+= nLineSize
+TB_LINESPACING
;
2179 if ( !item
.mbVisible
|| (nFormatLine
< mnCurLine
) ||
2180 (nFormatLine
> mnCurLine
+mnVisLines
-1) )
2181 // item is not visible
2182 item
.maCalcRect
= aEmptyRect
;
2185 // 1. determine current item width/height
2186 // take window size and orientation into account, because this affects the size of item windows
2188 Size
aCurrentItemSize( item
.GetSize( mbHorz
, mbScroll
, nMax
, Size(mnMaxItemWidth
, mnMaxItemHeight
) ) );
2190 // 2. position item rect and use size from step 1
2191 // items will be centered horizontally (if mbHorz) or vertically
2192 // advance nX and nY accordingly
2196 // In special mode Locked horizontal positions of all items remain unchanged.
2198 if ( mbIsArranged
&& meLayoutMode
== ToolBoxLayoutMode::Locked
&& mnLines
== 1 && item
.maRect
.Left() > 0 )
2199 nX
= item
.maRect
.Left();
2200 item
.maCalcRect
.SetLeft( nX
);
2202 // In special mode Locked first item's vertical position remains unchanged. Consecutive items vertical
2203 // positions are centered around first item's vertical position. If an item's height exceeds available
2204 // space, item's vertical position remains unchanged too.
2206 if ( mbIsArranged
&& meLayoutMode
== ToolBoxLayoutMode::Locked
&& mnLines
== 1 )
2207 if ( firstItemCenter
> 0 )
2208 if ( firstItemCenter
-aCurrentItemSize
.Height()/2 > nY
)
2209 item
.maCalcRect
.SetTop( firstItemCenter
-aCurrentItemSize
.Height()/2 );
2211 item
.maCalcRect
.SetTop( item
.maRect
.Top() );
2214 item
.maCalcRect
.SetTop( item
.maRect
.Top() );
2215 firstItemCenter
= item
.maRect
.Top()+aCurrentItemSize
.Height()/2;
2218 item
.maCalcRect
.SetTop( nY
+(nLineSize
-aCurrentItemSize
.Height())/2 );
2219 item
.maCalcRect
.SetRight( nX
+aCurrentItemSize
.Width()-1 );
2220 item
.maCalcRect
.SetBottom( item
.maCalcRect
.Top()+aCurrentItemSize
.Height()-1 );
2221 nX
+= aCurrentItemSize
.Width();
2225 item
.maCalcRect
.SetLeft( nX
+(nLineSize
-aCurrentItemSize
.Width())/2 );
2226 item
.maCalcRect
.SetTop( nY
);
2227 item
.maCalcRect
.SetRight( item
.maCalcRect
.Left()+aCurrentItemSize
.Width()-1 );
2228 item
.maCalcRect
.SetBottom( nY
+aCurrentItemSize
.Height()-1 );
2229 nY
+= aCurrentItemSize
.Height();
2233 // position window items into calculated item rect
2234 if ( item
.mpWindow
)
2236 if ( item
.mbShowWindow
)
2238 Point
aPos( item
.maCalcRect
.Left(), item
.maCalcRect
.Top() );
2240 assert( item
.maCalcRect
.Top() >= 0 );
2242 item
.mpWindow
->SetPosPixel( aPos
);
2243 item
.mpWindow
->Show();
2246 item
.mpWindow
->Hide();
2248 } // end of loop over all items
2249 mbIsArranged
= true;
2252 // we have no toolbox items
2255 if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode
)
2257 // custom menu will be the last button in floating mode
2258 ImplToolItem
&rIt
= mpData
->maMenubuttonItem
;
2262 rIt
.maRect
.SetLeft( nX
+TB_MENUBUTTON_OFFSET
);
2263 rIt
.maRect
.SetTop( nY
);
2264 rIt
.maRect
.SetRight( rIt
.maRect
.Left() + mpData
->mnMenuButtonWidth
);
2265 rIt
.maRect
.SetBottom( nY
+nLineSize
-1 );
2266 nX
+= rIt
.maItemSize
.Width();
2270 rIt
.maRect
.SetLeft( nX
);
2271 rIt
.maRect
.SetTop( nY
+TB_MENUBUTTON_OFFSET
);
2272 rIt
.maRect
.SetRight( nX
+nLineSize
-1 );
2273 rIt
.maRect
.SetBottom( rIt
.maRect
.Top() + mpData
->mnMenuButtonWidth
);
2274 nY
+= rIt
.maItemSize
.Height();
2278 // if toolbox visible trigger paint for changed regions
2279 if ( IsVisible() && !mbFullPaint
)
2281 if ( bMustFullPaint
)
2283 maPaintRect
= tools::Rectangle( mnLeftBorder
, mnTopBorder
,
2284 mnDX
-mnRightBorder
, mnDY
-mnBottomBorder
);
2288 if ( aOldLowerRect
!= maLowerRect
)
2290 maPaintRect
.Union( maLowerRect
);
2291 maPaintRect
.Union( aOldLowerRect
);
2293 if ( aOldUpperRect
!= maUpperRect
)
2295 maPaintRect
.Union( maUpperRect
);
2296 maPaintRect
.Union( aOldUpperRect
);
2298 if ( aOldMenubuttonRect
!= mpData
->maMenubuttonItem
.maRect
)
2300 maPaintRect
.Union( mpData
->maMenubuttonItem
.maRect
);
2301 maPaintRect
.Union( aOldMenubuttonRect
);
2303 if ( pWrapper
&& aOldDragRect
!= pWrapper
->GetDragArea() )
2305 maPaintRect
.Union( pWrapper
->GetDragArea() );
2306 maPaintRect
.Union( aOldDragRect
);
2309 for (auto const& item
: mpData
->m_aItems
)
2311 if ( item
.maRect
!= item
.maCalcRect
)
2313 maPaintRect
.Union( item
.maRect
);
2314 maPaintRect
.Union( item
.maCalcRect
);
2319 Invalidate( maPaintRect
);
2322 // store the new calculated item rects
2323 maPaintRect
= aEmptyRect
;
2324 for (auto & item
: mpData
->m_aItems
)
2325 item
.maRect
= item
.maCalcRect
;
2328 // indicate formatting is done
2332 IMPL_LINK_NOARG(ToolBox
, ImplDropdownLongClickHdl
, Timer
*, void)
2334 if (mnCurPos
== ITEM_NOTFOUND
||
2335 !(mpData
->m_aItems
[ mnCurPos
].mnBits
& ToolBoxItemBits::DROPDOWN
))
2338 mpData
->mbDropDownByKeyboard
= false;
2339 mpData
->maDropdownClickHdl
.Call( this );
2341 // do not reset data if the dropdown handler opened a floating window
2342 // see ImplFloatControl()
2345 // no floater was opened
2347 InvalidateItem(mnCurPos
);
2349 mnCurPos
= ITEM_NOTFOUND
;
2352 mnMouseModifier
= 0;
2357 IMPL_LINK_NOARG(ToolBox
, ImplUpdateHdl
, Timer
*, void)
2360 if( mbFormat
&& mpData
)
2364 static void ImplDrawMoreIndicator(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
2366 const Image
pImage(StockImage::Yes
, CHEVRON
);
2367 Size aImageSize
= pImage
.GetSizePixel();
2368 tools::Long x
= rRect
.Left() + (rRect
.getWidth() - aImageSize
.Width())/2;
2369 tools::Long y
= rRect
.Top() + (rRect
.getHeight() - aImageSize
.Height())/2;
2370 DrawImageFlags nImageStyle
= DrawImageFlags::NONE
;
2372 rRenderContext
.DrawImage(Point(x
,y
), pImage
, nImageStyle
);
2375 static void ImplDrawDropdownArrow(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rDropDownRect
, bool bSetColor
, bool bRotate
)
2377 bool bLineColor
= rRenderContext
.IsLineColor();
2378 bool bFillColor
= rRenderContext
.IsFillColor();
2379 Color aOldFillColor
= rRenderContext
.GetFillColor();
2380 Color aOldLineColor
= rRenderContext
.GetLineColor();
2381 rRenderContext
.SetLineColor();
2385 if (rRenderContext
.GetSettings().GetStyleSettings().GetFaceColor().IsDark())
2386 rRenderContext
.SetFillColor(COL_WHITE
);
2388 rRenderContext
.SetFillColor(COL_BLACK
);
2391 tools::Polygon
aPoly(4);
2393 // the assumption is, that the width always specifies the size of the expected arrow.
2394 const tools::Long nMargin
= round(2 * rRenderContext
.GetDPIScaleFactor());
2395 const tools::Long nSize
= rDropDownRect
.getWidth() - 2 * nMargin
;
2396 const tools::Long nHalfSize
= (nSize
+ 1) / 2;
2397 const tools::Long x
= rDropDownRect
.Left() + nMargin
+ (bRotate
? (rDropDownRect
.getWidth() - nHalfSize
) / 2 : 0);
2398 const tools::Long y
= rDropDownRect
.Top() + nMargin
+ (rDropDownRect
.getHeight() - (bRotate
? nSize
: nHalfSize
)) / 2;
2400 aPoly
.SetPoint(Point(x
, y
), 0);
2403 aPoly
.SetPoint(Point(x
, y
+ nSize
), 1);
2404 aPoly
.SetPoint(Point(x
+ nHalfSize
, y
+ nHalfSize
), 2);
2408 aPoly
.SetPoint(Point(x
+ nHalfSize
, y
+ nHalfSize
), 1);
2409 aPoly
.SetPoint(Point(x
+ nSize
, y
), 2);
2411 aPoly
.SetPoint(Point(x
, y
), 3);
2413 auto aaflags
= rRenderContext
.GetAntialiasing();
2414 rRenderContext
.SetAntialiasing(AntialiasingFlags::Enable
);
2415 rRenderContext
.DrawPolygon( aPoly
);
2416 rRenderContext
.SetAntialiasing(aaflags
);
2419 rRenderContext
.SetFillColor(aOldFillColor
);
2421 rRenderContext
.SetFillColor();
2423 rRenderContext
.SetLineColor(aOldLineColor
);
2425 rRenderContext
.SetLineColor();
2428 void ToolBox::ImplDrawMenuButton(vcl::RenderContext
& rRenderContext
, bool bHighlight
)
2430 if (mpData
->maMenubuttonItem
.maRect
.IsEmpty())
2433 // #i53937# paint menu button only if necessary
2434 if (!ImplHasClippedItems())
2437 // execute pending paint requests
2440 rRenderContext
.Push(PushFlags::FILLCOLOR
| PushFlags::LINECOLOR
);
2442 // draw the 'more' indicator / button (>>)
2443 ImplErase(rRenderContext
, mpData
->maMenubuttonItem
.maRect
, bHighlight
);
2446 ImplDrawButton(rRenderContext
, mpData
->maMenubuttonItem
.maRect
, 2, false, true, false );
2448 if (ImplHasClippedItems())
2449 ImplDrawMoreIndicator(rRenderContext
, mpData
->maMenubuttonItem
.maRect
);
2451 // store highlight state
2452 mpData
->mbMenubuttonSelected
= bHighlight
;
2455 rRenderContext
.Pop();
2458 void ToolBox::ImplDrawSpin(vcl::RenderContext
& rRenderContext
)
2463 if ( maUpperRect
.IsEmpty() || maLowerRect
.IsEmpty() )
2466 bTmpUpper
= mnCurLine
> 1;
2468 bTmpLower
= mnCurLine
+mnVisLines
-1 < mnCurLines
;
2476 ImplDrawUpDownButtons(rRenderContext
, maUpperRect
, maLowerRect
,
2477 false/*bUpperIn*/, false/*bLowerIn*/, bTmpUpper
, bTmpLower
, !mbHorz
);
2480 void ToolBox::ImplDrawSeparator(vcl::RenderContext
& rRenderContext
, ImplToolItems::size_type nPos
, const tools::Rectangle
& rRect
)
2482 if ( nPos
>= mpData
->m_aItems
.size() - 1 )
2483 // no separator if it's the last item
2486 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPos
];
2487 ImplToolItem
* pPreviousItem
= &mpData
->m_aItems
[nPos
-1];
2488 ImplToolItem
* pNextItem
= &mpData
->m_aItems
[nPos
+1];
2490 if ( ( pPreviousItem
->mbShowWindow
&& pNextItem
->mbShowWindow
) || pNextItem
->mbBreak
)
2491 // no separator between two windows or before a break
2494 bool bNativeOk
= false;
2495 ControlPart nPart
= IsHorizontal() ? ControlPart::SeparatorVert
: ControlPart::SeparatorHorz
;
2496 if (rRenderContext
.IsNativeControlSupported(ControlType::Toolbar
, nPart
))
2498 ImplControlValue aControlValue
;
2499 bNativeOk
= rRenderContext
.DrawNativeControl(ControlType::Toolbar
, nPart
, rRect
, ControlState::NONE
, aControlValue
, OUString());
2502 /* Draw the widget only if it can't be drawn natively. */
2506 tools::Long nCenterPos
, nSlim
;
2507 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
2508 rRenderContext
.SetLineColor(rStyleSettings
.GetSeparatorColor());
2511 nSlim
= (pItem
->maRect
.Bottom() - pItem
->maRect
.Top ()) / 4;
2512 nCenterPos
= pItem
->maRect
.Center().X();
2513 rRenderContext
.DrawLine(Point(nCenterPos
, pItem
->maRect
.Top() + nSlim
),
2514 Point(nCenterPos
, pItem
->maRect
.Bottom() - nSlim
));
2518 nSlim
= (pItem
->maRect
.Right() - pItem
->maRect
.Left ()) / 4;
2519 nCenterPos
= pItem
->maRect
.Center().Y();
2520 rRenderContext
.DrawLine(Point(pItem
->maRect
.Left() + nSlim
, nCenterPos
),
2521 Point(pItem
->maRect
.Right() - nSlim
, nCenterPos
));
2525 void ToolBox::ImplDrawButton(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&rRect
, sal_uInt16 highlight
,
2526 bool bChecked
, bool bEnabled
, bool bIsWindow
)
2528 // draws toolbar button background either native or using a coloured selection
2529 // if bIsWindow is true, the corresponding item is a control and only a selection border will be drawn
2531 bool bNativeOk
= false;
2532 if( !bIsWindow
&& rRenderContext
.IsNativeControlSupported( ControlType::Toolbar
, ControlPart::Button
) )
2534 ImplControlValue aControlValue
;
2535 ControlState nState
= ControlState::NONE
;
2537 if ( highlight
== 1 ) nState
|= ControlState::PRESSED
;
2538 if ( highlight
== 2 ) nState
|= ControlState::ROLLOVER
;
2539 if ( bEnabled
) nState
|= ControlState::ENABLED
;
2541 aControlValue
.setTristateVal( bChecked
? ButtonValue::On
: ButtonValue::Off
);
2543 bNativeOk
= rRenderContext
.DrawNativeControl( ControlType::Toolbar
, ControlPart::Button
,
2544 rRect
, nState
, aControlValue
, OUString() );
2548 vcl::RenderTools::DrawSelectionBackground(rRenderContext
, *this, rRect
, bIsWindow
? 3 : highlight
,
2549 bChecked
, true, bIsWindow
, nullptr, 2);
2552 void ToolBox::ImplDrawItem(vcl::RenderContext
& rRenderContext
, ImplToolItems::size_type nPos
, sal_uInt16 nHighlight
)
2554 if (nPos
>= mpData
->m_aItems
.size())
2557 // execute pending paint requests
2560 rRenderContext
.SetFillColor();
2562 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPos
];
2564 if (!pItem
->mbEnabled
)
2567 // if the rectangle is outside visible area
2568 if (pItem
->maRect
.IsEmpty())
2571 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
2573 // no gradient background for items that have a popup open
2574 bool bHasOpenPopup
= mpFloatWin
&& (mnDownItemId
==pItem
->mnId
);
2576 bool bHighContrastWhite
= false;
2577 // check the face color as highcontrast indicator
2578 // because the toolbox itself might have a gradient
2579 if (rStyleSettings
.GetFaceColor() == COL_WHITE
)
2580 bHighContrastWhite
= true;
2582 // Compute buttons area.
2583 Size aBtnSize
= pItem
->maRect
.GetSize();
2585 /* Compute the button/separator rectangle here, we'll need it for
2586 * both the buttons and the separators. */
2587 tools::Rectangle
aButtonRect( pItem
->maRect
.TopLeft(), aBtnSize
);
2588 tools::Long nOffX
= SMALLBUTTON_OFF_NORMAL_X
;
2589 tools::Long nOffY
= SMALLBUTTON_OFF_NORMAL_Y
;
2590 tools::Long nImageOffX
= 0;
2591 tools::Long nImageOffY
= 0;
2592 DrawButtonFlags nStyle
= DrawButtonFlags::NONE
;
2595 if ( (pItem
->meType
== ToolBoxItemType::SEPARATOR
) && nPos
> 0 )
2597 ImplDrawSeparator(rRenderContext
, nPos
, aButtonRect
);
2600 // do nothing if item is no button or will be displayed as window
2601 if ( (pItem
->meType
!= ToolBoxItemType::BUTTON
) || pItem
->mbShowWindow
)
2604 if ( pItem
->meState
== TRISTATE_TRUE
)
2606 nStyle
|= DrawButtonFlags::Checked
;
2608 else if ( pItem
->meState
== TRISTATE_INDET
)
2610 nStyle
|= DrawButtonFlags::DontKnow
;
2612 if ( nHighlight
== 1 )
2614 nStyle
|= DrawButtonFlags::Pressed
;
2617 ImplErase(rRenderContext
, pItem
->maRect
, nHighlight
!= 0, bHasOpenPopup
);
2619 nOffX
+= pItem
->maRect
.Left();
2620 nOffY
+= pItem
->maRect
.Top();
2622 // determine what has to be drawn on the button: image, text or both
2625 ButtonType tmpButtonType
= determineButtonType( pItem
, meButtonType
); // default to toolbox setting
2626 pItem
->DetermineButtonDrawStyle( tmpButtonType
, bImage
, bText
);
2628 // compute output values
2629 tools::Long nBtnWidth
= aBtnSize
.Width()-SMALLBUTTON_HSIZE
;
2630 tools::Long nBtnHeight
= aBtnSize
.Height()-SMALLBUTTON_VSIZE
;
2633 const bool bDropDown
= (pItem
->mnBits
& ToolBoxItemBits::DROPDOWN
) == ToolBoxItemBits::DROPDOWN
;
2634 tools::Rectangle aDropDownRect
;
2636 aDropDownRect
= pItem
->GetDropDownRect(mbHorz
);
2640 const Image
* pImage
= &(pItem
->maImage
);
2641 aImageSize
= pImage
->GetSizePixel();
2643 // determine drawing flags
2644 DrawImageFlags nImageStyle
= DrawImageFlags::NONE
;
2646 if ( !pItem
->mbEnabled
|| !IsEnabled() )
2647 nImageStyle
|= DrawImageFlags::Disable
;
2649 // #i35563# the dontknow state indicates different states at the same time
2650 // which should not be rendered disabled but normal
2655 if ( ( (pItem
->mnBits
& (ToolBoxItemBits::LEFT
|ToolBoxItemBits::DROPDOWN
)) || bText
)
2656 && ( meTextPosition
== ToolBoxTextPosition::Right
) )
2658 // left align also to leave space for drop down arrow
2659 // and when drawing text+image
2660 // just center in y, except for vertical (ie rotated text)
2661 if( mbHorz
|| !bText
)
2662 nImageOffY
+= (nBtnHeight
-aImageSize
.Height())/2;
2666 nImageOffX
+= (nBtnWidth
-(bDropDown
? aDropDownRect
.getWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X
-aImageSize
.Width())/2;
2667 if ( meTextPosition
== ToolBoxTextPosition::Right
)
2668 nImageOffY
+= (nBtnHeight
-aImageSize
.Height())/2;
2670 if ( nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) )
2673 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2675 ImplDrawButton(rRenderContext
, aButtonRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2676 pItem
->mbEnabled
&& IsEnabled(), pItem
->mbShowWindow
);
2678 if( nHighlight
!= 0 )
2680 if( bHighContrastWhite
)
2681 nImageStyle
|= DrawImageFlags::ColorTransform
;
2684 rRenderContext
.DrawImage(Point( nImageOffX
, nImageOffY
), *pImage
, nImageStyle
);
2688 bool bRotate
= false;
2691 const Size
aTxtSize(GetCtrlTextWidth(pItem
->maText
), GetTextHeight());
2692 tools::Long nTextOffX
= nOffX
;
2693 tools::Long nTextOffY
= nOffY
;
2695 // rotate text when vertically docked
2696 vcl::Font aOldFont
= rRenderContext
.GetFont();
2697 if( pItem
->mbVisibleText
&& !ImplIsFloatingMode() &&
2698 ((meAlign
== WindowAlign::Left
) || (meAlign
== WindowAlign::Right
)) )
2702 vcl::Font aRotateFont
= aOldFont
;
2703 aRotateFont
.SetOrientation( Degree10(2700) );
2705 // center horizontally
2706 nTextOffX
+= aTxtSize
.Height();
2707 nTextOffX
+= (nBtnWidth
-aTxtSize
.Height())/2;
2709 // add in image offset
2711 nTextOffY
= nImageOffY
+ aImageSize
.Height() + TB_IMAGETEXTOFFSET
;
2713 rRenderContext
.SetFont(aRotateFont
);
2717 if ( meTextPosition
== ToolBoxTextPosition::Right
)
2719 // center vertically
2720 nTextOffY
+= (nBtnHeight
-aTxtSize
.Height())/2;
2722 // add in image offset
2724 nTextOffX
= nImageOffX
+ aImageSize
.Width() + TB_IMAGETEXTOFFSET
;
2728 // center horizontally
2729 nTextOffX
+= (nBtnWidth
-(bDropDown
? aDropDownRect
.getWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X
-aTxtSize
.Width() - TB_IMAGETEXTOFFSET
)/2;
2730 // set vertical position
2731 nTextOffY
+= nBtnHeight
- aTxtSize
.Height();
2735 // draw selection only if not already drawn during image output (see above)
2736 if ( !bImage
&& (nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) ) )
2739 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2741 ImplDrawButton(rRenderContext
, pItem
->maRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2742 pItem
->mbEnabled
&& IsEnabled(), pItem
->mbShowWindow
);
2745 DrawTextFlags nTextStyle
= DrawTextFlags::NONE
;
2746 if ( !pItem
->mbEnabled
)
2747 nTextStyle
|= DrawTextFlags::Disable
;
2748 rRenderContext
.DrawCtrlText( Point( nTextOffX
, nTextOffY
), pItem
->maText
,
2749 0, pItem
->maText
.getLength(), nTextStyle
);
2751 SetFont( aOldFont
);
2754 // paint optional drop down arrow
2758 bool bSetColor
= true;
2759 if ( !pItem
->mbEnabled
|| !IsEnabled() )
2762 rRenderContext
.SetFillColor(rStyleSettings
.GetShadowColor());
2765 // dropdown only will be painted without inner border
2766 if( (pItem
->mnBits
& ToolBoxItemBits::DROPDOWNONLY
) != ToolBoxItemBits::DROPDOWNONLY
)
2768 ImplErase(rRenderContext
, aDropDownRect
, nHighlight
!= 0, bHasOpenPopup
);
2770 if( nHighlight
!= 0 || (pItem
->meState
== TRISTATE_TRUE
) )
2773 ImplDrawFloatwinBorder(rRenderContext
, pItem
);
2775 ImplDrawButton(rRenderContext
, aDropDownRect
, nHighlight
, pItem
->meState
== TRISTATE_TRUE
,
2776 pItem
->mbEnabled
&& IsEnabled(), false);
2779 ImplDrawDropdownArrow(rRenderContext
, aDropDownRect
, bSetColor
, bRotate
);
2782 void ToolBox::ImplDrawFloatwinBorder(vcl::RenderContext
& rRenderContext
, ImplToolItem
const * pItem
)
2784 if ( pItem
->maRect
.IsEmpty() )
2787 tools::Rectangle
aRect( mpFloatWin
->ImplGetItemEdgeClipRect() );
2788 aRect
.SetPos( AbsoluteScreenToOutputPixel( aRect
.TopLeft() ) );
2789 rRenderContext
.SetLineColor(rRenderContext
.GetSettings().GetStyleSettings().GetShadowColor());
2792 p1
= pItem
->maRect
.TopLeft();
2794 p2
= pItem
->maRect
.TopRight();
2796 rRenderContext
.DrawLine( p1
, p2
);
2797 p1
= pItem
->maRect
.BottomLeft();
2799 p2
= pItem
->maRect
.BottomRight();
2801 rRenderContext
.DrawLine( p1
, p2
);
2803 p1
= pItem
->maRect
.TopLeft();
2805 p2
= pItem
->maRect
.BottomLeft();
2807 rRenderContext
.DrawLine( p1
, p2
);
2808 p1
= pItem
->maRect
.TopRight();
2810 p2
= pItem
->maRect
.BottomRight();
2812 rRenderContext
.DrawLine( p1
, p2
);
2816 void ToolBox::ImplFloatControl( bool bStart
, FloatingWindow
* pFloatWindow
)
2821 mpFloatWin
= pFloatWindow
;
2823 // redraw item, to trigger drawing of a special border
2824 InvalidateItem(mnCurPos
);
2828 if (IsMouseCaptured())
2833 mpFloatWin
= nullptr;
2835 // if focus is still in this toolbox, then the floater was opened by keyboard
2836 // draw current item with highlight and keep old state
2837 bool bWasKeyboardActivate
= mpData
->mbDropDownByKeyboard
;
2839 if ( mnCurPos
!= ITEM_NOTFOUND
)
2840 InvalidateItem(mnCurPos
);
2843 if( !bWasKeyboardActivate
)
2845 mnCurPos
= ITEM_NOTFOUND
;
2854 void ToolBox::ShowLine( bool bNext
)
2866 bool ToolBox::ImplHandleMouseMove( const MouseEvent
& rMEvt
, bool bRepeat
)
2868 Point aMousePos
= rMEvt
.GetPosPixel();
2874 if ( mbDrag
&& mnCurPos
!= ITEM_NOTFOUND
)
2876 // is the cursor over the item?
2877 ImplToolItem
* pItem
= &mpData
->m_aItems
[mnCurPos
];
2878 if ( pItem
->maRect
.IsInside( aMousePos
) )
2882 InvalidateItem(mnCurPos
);
2883 mnCurItemId
= pItem
->mnId
;
2887 if ( (pItem
->mnBits
& ToolBoxItemBits::REPEAT
) && bRepeat
)
2894 InvalidateItem(mnCurPos
);
2896 InvalidateItem(mnCurPos
);
2906 bool bNewIn
= maUpperRect
.IsInside( aMousePos
);
2907 if ( bNewIn
!= mbIn
)
2910 InvalidateSpin(true, false);
2917 bool bNewIn
= maLowerRect
.IsInside( aMousePos
);
2918 if ( bNewIn
!= mbIn
)
2921 InvalidateSpin(false);
2929 bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent
& rMEvt
, bool bCancel
)
2934 // stop eventual running dropdown timer
2935 if( mnCurPos
< mpData
->m_aItems
.size() &&
2936 (mpData
->m_aItems
[mnCurPos
].mnBits
& ToolBoxItemBits::DROPDOWN
) )
2938 mpData
->maDropdownTimer
.Stop();
2949 if ( mnCurPos
== ITEM_NOTFOUND
)
2953 // has mouse been released on top of item?
2954 if( mnCurPos
< mpData
->m_aItems
.size() )
2956 ImplToolItem
* pItem
= &mpData
->m_aItems
[mnCurPos
];
2957 if ( pItem
->maRect
.IsInside( rMEvt
.GetPosPixel() ) )
2959 mnCurItemId
= pItem
->mnId
;
2962 // execute AutoCheck if required
2963 if ( pItem
->mnBits
& ToolBoxItemBits::AUTOCHECK
)
2965 if ( pItem
->mnBits
& ToolBoxItemBits::RADIOCHECK
)
2967 if ( pItem
->meState
!= TRISTATE_TRUE
)
2968 SetItemState( pItem
->mnId
, TRISTATE_TRUE
);
2972 if ( pItem
->meState
!= TRISTATE_TRUE
)
2973 pItem
->meState
= TRISTATE_TRUE
;
2975 pItem
->meState
= TRISTATE_FALSE
;
2979 // do not call Select when Repeat is active, as in this
2980 // case that was triggered already in MouseButtonDown
2981 if ( !(pItem
->mnBits
& ToolBoxItemBits::REPEAT
) )
2983 // prevent from being destroyed in the select handler
2984 VclPtr
<vcl::Window
> xWindow
= this;
2986 if ( xWindow
->IsDisposed() )
2994 // Items not destroyed, in Select handler
2997 // Get current pos for the case that items are inserted/removed
2999 mnCurPos
= GetItemPos( mnCurItemId
);
3000 if ( mnCurPos
!= ITEM_NOTFOUND
)
3002 InvalidateItem(mnCurPos
);
3009 mnCurPos
= ITEM_NOTFOUND
;
3012 mnMouseModifier
= 0;
3015 else if ( mbUpper
|| mbLower
)
3018 ShowLine( !mbUpper
);
3029 void ToolBox::MouseMove( const MouseEvent
& rMEvt
)
3031 // pressing a modifier generates synthetic mouse moves
3032 // ignore it if keyboard selection is active
3033 if( HasFocus() && ( rMEvt
.GetMode() & MouseEventModifiers::MODIFIERCHANGED
) )
3036 if ( ImplHandleMouseMove( rMEvt
) )
3039 Point aMousePos
= rMEvt
.GetPosPixel();
3041 // only highlight when the focus is not inside a child window of a toolbox
3042 // eg, in an edit control
3043 // and do not highlight when focus is in a different toolbox
3044 bool bDrawHotSpot
= true;
3045 vcl::Window
*pFocusWin
= Application::GetFocusWindow();
3047 bool bFocusWindowIsAToolBoxChild
= false;
3050 vcl::Window
*pWin
= pFocusWin
->GetParent();
3053 if(pWin
->ImplGetWindowImpl()->mbToolBox
)
3055 bFocusWindowIsAToolBoxChild
= true;
3058 pWin
= pWin
->GetParent();
3062 if( bFocusWindowIsAToolBoxChild
|| (pFocusWin
&& pFocusWin
->ImplGetWindowImpl()->mbToolBox
&& pFocusWin
!= this) )
3063 bDrawHotSpot
= false;
3067 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3068 pMgr
->Dragging( aMousePos
);
3072 PointerStyle eStyle
= PointerStyle::Arrow
;
3074 // change mouse cursor over drag area
3075 ImplDockingWindowWrapper
*pWrapper
= ImplGetDockingManager()->GetDockingWindowWrapper( this );
3076 if( pWrapper
&& pWrapper
->GetDragArea().IsInside( rMEvt
.GetPosPixel() ) )
3077 eStyle
= PointerStyle::Move
;
3079 if ( (mnWinStyle
& TB_WBLINESIZING
) == TB_WBLINESIZING
)
3081 if ( rMEvt
.GetMode() & MouseEventModifiers::SIMPLEMOVE
)
3083 sal_uInt16 nLinePtr
= ImplTestLineSize( rMEvt
.GetPosPixel() );
3084 if ( nLinePtr
& DOCK_LINEHSIZE
)
3086 if ( meAlign
== WindowAlign::Left
)
3087 eStyle
= PointerStyle::WindowESize
;
3089 eStyle
= PointerStyle::WindowWSize
;
3091 else if ( nLinePtr
& DOCK_LINEVSIZE
)
3093 if ( meAlign
== WindowAlign::Top
)
3094 eStyle
= PointerStyle::WindowSSize
;
3096 eStyle
= PointerStyle::WindowNSize
;
3103 bool bClearHigh
= true;
3104 if ( !rMEvt
.IsLeaveWindow() && (mnCurPos
== ITEM_NOTFOUND
) )
3106 ImplToolItems::size_type nTempPos
= 0;
3107 for (auto const& item
: mpData
->m_aItems
)
3109 if ( item
.maRect
.IsInside( aMousePos
) )
3111 if ( (item
.meType
== ToolBoxItemType::BUTTON
) && item
.mbEnabled
)
3114 if ( mnHighItemId
!= item
.mnId
)
3119 ImplToolItems::size_type nPos
= GetItemPos( mnHighItemId
);
3120 InvalidateItem(nPos
);
3121 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nPos
) );
3123 if ( mpData
->mbMenubuttonSelected
)
3125 // remove highlight from menubutton
3126 InvalidateMenuButton();
3128 mnHighItemId
= item
.mnId
;
3129 InvalidateItem(nTempPos
);
3131 CallEventListeners( VclEventId::ToolboxHighlight
);
3140 // only clear highlight when focus is not in toolbar
3141 bool bMenuButtonHit
= mpData
->maMenubuttonItem
.maRect
.IsInside( aMousePos
) && ImplHasClippedItems();
3142 if ( !HasFocus() && (bClearHigh
|| bMenuButtonHit
) )
3144 if ( !bMenuButtonHit
&& mpData
->mbMenubuttonSelected
)
3146 // remove highlight from menubutton
3147 InvalidateMenuButton();
3152 ImplToolItems::size_type nClearPos
= GetItemPos( mnHighItemId
);
3153 if ( nClearPos
!= ITEM_NOTFOUND
)
3155 InvalidateItem(nClearPos
);
3156 if( nClearPos
!= mnCurPos
)
3157 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nClearPos
) );
3163 if( bMenuButtonHit
)
3165 InvalidateMenuButton();
3170 if ( meLastStyle
!= eStyle
)
3172 meLastStyle
= eStyle
;
3173 SetPointer( eStyle
);
3176 DockingWindow::MouseMove( rMEvt
);
3179 void ToolBox::MouseButtonDown( const MouseEvent
& rMEvt
)
3181 // only trigger toolbox for left mouse button and when
3182 // we're not in normal operation
3183 if ( rMEvt
.IsLeft() && !mbDrag
&& (mnCurPos
== ITEM_NOTFOUND
) )
3185 // call activate already here, as items could
3189 // update ToolBox here, such that user knows it
3196 Point aMousePos
= rMEvt
.GetPosPixel();
3197 ImplToolItems::size_type i
= 0;
3198 ImplToolItems::size_type nNewPos
= ITEM_NOTFOUND
;
3200 // search for item that was clicked
3201 for (auto const& item
: mpData
->m_aItems
)
3203 // is this the item?
3204 if ( item
.maRect
.IsInside( aMousePos
) )
3206 // do nothing if it is a separator or
3207 // if the item has been disabled
3208 if ( (item
.meType
== ToolBoxItemType::BUTTON
) &&
3209 !item
.mbShowWindow
)
3219 if ( nNewPos
!= ITEM_NOTFOUND
)
3221 if ( !mpData
->m_aItems
[nNewPos
].mbEnabled
)
3227 // update actual data
3228 StartTrackingFlags nTrackFlags
= StartTrackingFlags::NONE
;
3230 mnCurItemId
= mpData
->m_aItems
[nNewPos
].mnId
;
3231 mnDownItemId
= mnCurItemId
;
3232 mnMouseModifier
= rMEvt
.GetModifier();
3233 if ( mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::REPEAT
)
3234 nTrackFlags
|= StartTrackingFlags::ButtonRepeat
;
3236 // update bDrag here, as it is evaluated in the EndSelection
3239 // on double-click: only call the handler, but do so before the button
3240 // is hit, as in the handler dragging
3241 // can be terminated
3242 if ( rMEvt
.GetClicks() == 2 )
3247 InvalidateItem(mnCurPos
);
3251 // was dropdown arrow pressed
3252 if( mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::DROPDOWN
)
3254 if( ( (mpData
->m_aItems
[nNewPos
].mnBits
& ToolBoxItemBits::DROPDOWNONLY
) == ToolBoxItemBits::DROPDOWNONLY
)
3255 || mpData
->m_aItems
[nNewPos
].GetDropDownRect( mbHorz
).IsInside( aMousePos
))
3257 // dropdownonly always triggers the dropdown handler, over the whole button area
3259 // the drop down arrow should not trigger the item action
3260 mpData
->mbDropDownByKeyboard
= false;
3261 mpData
->maDropdownClickHdl
.Call( this );
3263 // do not reset data if the dropdown handler opened a floating window
3264 // see ImplFloatControl()
3267 // no floater was opened
3269 InvalidateItem(mnCurPos
);
3271 mnCurPos
= ITEM_NOTFOUND
;
3274 mnMouseModifier
= 0;
3279 else // activate long click timer
3280 mpData
->maDropdownTimer
.Start();
3283 // call Click handler
3284 if ( rMEvt
.GetClicks() != 2 )
3287 // also call Select handler at repeat
3288 if ( nTrackFlags
& StartTrackingFlags::ButtonRepeat
)
3291 // if the actions was not aborted in Click handler
3293 StartTracking( nTrackFlags
);
3295 // if mouse was clicked over an item we
3302 // menu button hit ?
3303 if( mpData
->maMenubuttonItem
.maRect
.IsInside( aMousePos
) && ImplHasClippedItems() )
3305 if ( maMenuButtonHdl
.IsSet() )
3306 maMenuButtonHdl
.Call( this );
3308 ExecuteCustomMenu( mpData
->maMenubuttonItem
.maRect
);
3312 // check scroll- and next-buttons here
3313 if ( maUpperRect
.IsInside( aMousePos
) )
3315 if ( mnCurLine
> 1 )
3320 InvalidateSpin(true, false);
3324 if ( maLowerRect
.IsInside( aMousePos
) )
3326 if ( mnCurLine
+mnVisLines
-1 < mnCurLines
)
3331 InvalidateSpin(false);
3336 // Linesizing testen
3337 if ( (mnWinStyle
& TB_WBLINESIZING
) == TB_WBLINESIZING
)
3339 sal_uInt16 nLineMode
= ImplTestLineSize( aMousePos
);
3342 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3344 // call handler, such that we can set the
3348 Point aPos
= GetParent()->OutputToScreenPixel( GetPosPixel() );
3349 Size aSize
= GetSizePixel();
3350 aPos
= ScreenToOutputPixel( aPos
);
3353 pMgr
->StartDragging( this, aMousePos
, tools::Rectangle( aPos
, aSize
),
3359 // no item, then only click or double click
3360 if ( rMEvt
.GetClicks() == 2 )
3366 if ( !mbDrag
&& (mnCurPos
== ITEM_NOTFOUND
) )
3367 DockingWindow::MouseButtonDown( rMEvt
);
3370 void ToolBox::MouseButtonUp( const MouseEvent
& rMEvt
)
3372 if ( ImplHandleMouseButtonUp( rMEvt
) )
3375 if ( mbDragging
&& rMEvt
.IsLeft() )
3377 ImplTBDragMgr
* pMgr
= ImplGetTBDragMgr();
3378 pMgr
->EndDragging();
3382 DockingWindow::MouseButtonUp( rMEvt
);
3385 void ToolBox::Tracking( const TrackingEvent
& rTEvt
)
3387 VclPtr
<vcl::Window
> xWindow
= this;
3389 if ( rTEvt
.IsTrackingEnded() )
3390 ImplHandleMouseButtonUp( rTEvt
.GetMouseEvent(), rTEvt
.IsTrackingCanceled() );
3392 ImplHandleMouseMove( rTEvt
.GetMouseEvent(), rTEvt
.IsTrackingRepeat() );
3394 if ( xWindow
->IsDisposed() )
3395 // toolbox was deleted
3397 DockingWindow::Tracking( rTEvt
);
3400 void ToolBox::InvalidateItem(ImplToolItems::size_type nPosition
)
3402 if (mpData
&& nPosition
< mpData
->m_aItems
.size())
3404 ImplToolItem
* pItem
= &mpData
->m_aItems
[nPosition
];
3405 Invalidate(pItem
->maRect
);
3409 void ToolBox::InvalidateMenuButton()
3411 if (!mpData
->maMenubuttonItem
.maRect
.IsEmpty())
3412 Invalidate(mpData
->maMenubuttonItem
.maRect
);
3415 void ToolBox::InvalidateSpin(bool bUpperIn
, bool bLowerIn
)
3417 if (bUpperIn
&& !maUpperRect
.IsEmpty())
3418 Invalidate(maUpperRect
);
3420 if (bLowerIn
&& !maLowerRect
.IsEmpty())
3421 Invalidate(maLowerRect
);
3424 void ToolBox::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rPaintRect
)
3426 if( mpData
->mbIsPaintLocked
)
3429 if (rPaintRect
== tools::Rectangle(0, 0, mnDX
-1, mnDY
-1))
3432 mbFullPaint
= false;
3434 ImplDrawBackground(rRenderContext
, rPaintRect
);
3436 if ( (mnWinStyle
& WB_BORDER
) && !ImplIsFloatingMode() )
3437 ImplDrawBorder(rRenderContext
);
3439 if( !ImplIsFloatingMode() )
3440 ImplDrawGrip(rRenderContext
);
3442 ImplDrawMenuButton(rRenderContext
, mpData
->mbMenubuttonSelected
);
3445 if (mnWinStyle
& WB_SCROLL
)
3447 if (mnCurLines
> mnLines
)
3448 ImplDrawSpin(rRenderContext
);
3452 ImplToolItems::size_type nHighPos
;
3454 nHighPos
= GetItemPos( mnHighItemId
);
3456 nHighPos
= ITEM_NOTFOUND
;
3458 ImplToolItems::size_type nCount
= mpData
->m_aItems
.size();
3459 for( ImplToolItems::size_type i
= 0; i
< nCount
; i
++ )
3461 ImplToolItem
* pItem
= &mpData
->m_aItems
[i
];
3463 // only draw when the rectangle is in the draw rectangle
3464 if ( !pItem
->maRect
.IsEmpty() && rPaintRect
.IsOver( pItem
->maRect
) )
3466 sal_uInt16 nHighlight
= 0;
3467 if ( i
== mnCurPos
)
3469 else if ( i
== nHighPos
)
3471 ImplDrawItem(rRenderContext
, i
, nHighlight
);
3477 void ToolBox::Resize()
3479 Size aSize
= GetOutputSizePixel();
3480 // #i31422# some WindowManagers send (0,0) sizes when
3481 // switching virtual desktops - ignore this and avoid reformatting
3482 if( !aSize
.Width() && !aSize
.Height() )
3485 tools::Long nOldDX
= mnDX
;
3486 tools::Long nOldDY
= mnDY
;
3487 mnDX
= aSize
.Width();
3488 mnDY
= aSize
.Height();
3492 // invalidate everything to have gradient backgrounds properly drawn
3495 // If we have any expandable entries, then force a reformat first using
3496 // their optimal sizes, then share out the excess space evenly across those
3497 // expandables and reformat again
3498 std::vector
<size_t> aExpandables
;
3499 for (size_t i
= 0; i
< mpData
->m_aItems
.size(); ++i
)
3501 if (mpData
->m_aItems
[i
].mbExpand
)
3503 vcl::Window
*pWindow
= mpData
->m_aItems
[i
].mpWindow
;
3504 SAL_INFO_IF(!pWindow
, "vcl.layout", "only tabitems with window supported at the moment");
3507 Size
aWinSize(pWindow
->GetSizePixel());
3508 Size
aPrefSize(pWindow
->get_preferred_size());
3509 aWinSize
.setWidth( aPrefSize
.Width() );
3510 pWindow
->SetSizePixel(aWinSize
);
3511 aExpandables
.push_back(i
);
3515 // re-format or re-draw
3516 if ( mbScroll
|| !aExpandables
.empty() )
3518 if ( !mbFormat
|| !aExpandables
.empty() )
3521 if( IsReallyVisible() || !aExpandables
.empty() )
3525 if (!aExpandables
.empty())
3527 //Get how big the optimal size is
3528 tools::Rectangle aBounds
;
3529 for (const ImplToolItem
& rItem
: mpData
->m_aItems
)
3531 aBounds
.Union( rItem
.maRect
);
3534 auto nOptimalWidth
= aBounds
.GetWidth();
3535 auto nDiff
= aSize
.Width() - nOptimalWidth
;
3536 decltype(nDiff
) nExpandablesSize
= aExpandables
.size();
3537 nDiff
/= nExpandablesSize
;
3539 //share out the diff from optimal to real across
3540 //expandable entries
3541 for (size_t nIndex
: aExpandables
)
3543 vcl::Window
*pWindow
= mpData
->m_aItems
[nIndex
].mpWindow
;
3544 Size
aWinSize(pWindow
->GetSizePixel());
3545 Size
aPrefSize(pWindow
->get_preferred_size());
3546 aWinSize
.setWidth( aPrefSize
.Width() + nDiff
);
3547 pWindow
->SetSizePixel(aWinSize
);
3550 //now reformat with final sizes
3559 if ( !(mnWinStyle
& WB_BORDER
) )
3562 // as otherwise, when painting we might think we have to re-draw everything
3563 if ( mbFormat
&& IsReallyVisible() )
3567 if ( mnRightBorder
)
3569 if ( nOldDX
> mnDX
)
3570 Invalidate( tools::Rectangle( mnDX
-mnRightBorder
-1, 0, mnDX
, mnDY
) );
3572 Invalidate( tools::Rectangle( nOldDX
-mnRightBorder
-1, 0, nOldDX
, nOldDY
) );
3575 if ( mnBottomBorder
)
3577 if ( nOldDY
> mnDY
)
3578 Invalidate( tools::Rectangle( 0, mnDY
-mnBottomBorder
-1, mnDX
, mnDY
) );
3580 Invalidate( tools::Rectangle( 0, nOldDY
-mnBottomBorder
-1, nOldDX
, nOldDY
) );
3587 bool DispatchableCommand(const OUString
& rName
)
3589 return rName
.startsWith(".uno") ||
3590 rName
.startsWith("slot:") ||
3591 rName
.startsWith("macro:") ||
3592 rName
.startsWith("vnd.sun.star.script");
3596 const OUString
& ToolBox::ImplGetHelpText( sal_uInt16 nItemId
) const
3598 ImplToolItem
* pItem
= ImplGetItem( nItemId
);
3602 if ( pItem
->maHelpText
.isEmpty() && ( !pItem
->maHelpId
.isEmpty() || pItem
->maCommandStr
.getLength() ))
3604 Help
* pHelp
= Application::GetHelp();
3607 if (DispatchableCommand(pItem
->maCommandStr
))
3608 pItem
->maHelpText
= pHelp
->GetHelpText( pItem
->maCommandStr
, this );
3609 if ( pItem
->maHelpText
.isEmpty() && !pItem
->maHelpId
.isEmpty() )
3610 pItem
->maHelpText
= pHelp
->GetHelpText( OStringToOUString( pItem
->maHelpId
, RTL_TEXTENCODING_UTF8
), this );
3614 return pItem
->maHelpText
;
3617 void ToolBox::RequestHelp( const HelpEvent
& rHEvt
)
3622 if( !rHEvt
.KeyboardActivated() )
3624 nItemId
= GetItemId( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ) );
3625 aHelpPos
= rHEvt
.GetMousePosPixel();
3632 nItemId
= mnHighItemId
;
3633 tools::Rectangle
aRect( GetItemRect( nItemId
) );
3634 if( aRect
.IsEmpty() )
3637 aHelpPos
= OutputToScreenPixel( aRect
.Center() );
3642 if ( rHEvt
.GetMode() & (HelpEventMode::BALLOON
| HelpEventMode::QUICK
) )
3645 tools::Rectangle aTempRect
= GetItemRect( nItemId
);
3646 Point aPt
= OutputToScreenPixel( aTempRect
.TopLeft() );
3647 aTempRect
.SetLeft( aPt
.X() );
3648 aTempRect
.SetTop( aPt
.Y() );
3649 aPt
= OutputToScreenPixel( aTempRect
.BottomRight() );
3650 aTempRect
.SetRight( aPt
.X() );
3651 aTempRect
.SetBottom( aPt
.Y() );
3653 // get text and display it
3654 OUString aStr
= GetQuickHelpText( nItemId
);
3656 aStr
= MnemonicGenerator::EraseAllMnemonicChars( GetItemText( nItemId
) );
3657 if ( rHEvt
.GetMode() & HelpEventMode::BALLOON
)
3659 const OUString
& rHelpStr
= GetHelpText( nItemId
);
3660 if (!rHelpStr
.isEmpty())
3662 Help::ShowBalloon( this, aHelpPos
, aTempRect
, aStr
);
3665 Help::ShowQuickHelp( this, aTempRect
, aStr
, QuickHelpFlags::CtrlText
);
3670 DockingWindow::RequestHelp( rHEvt
);
3673 bool ToolBox::EventNotify( NotifyEvent
& rNEvt
)
3675 if ( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
3677 KeyEvent aKEvt
= *rNEvt
.GetKeyEvent();
3678 vcl::KeyCode aKeyCode
= aKEvt
.GetKeyCode();
3679 sal_uInt16 nKeyCode
= aKeyCode
.GetCode();
3684 // internal TAB cycling only if parent is not a dialog or if we are the only child
3685 // otherwise the dialog control will take over
3686 vcl::Window
*pParent
= ImplGetParent();
3687 bool bOldSchoolContainer
=
3688 ((pParent
->GetStyle() & (WB_DIALOGCONTROL
| WB_NODIALOGCONTROL
)) == WB_DIALOGCONTROL
&&
3689 pParent
->GetChildCount() != 1);
3690 bool bNoTabCycling
= bOldSchoolContainer
|| isContainerWindow(pParent
);
3693 return DockingWindow::EventNotify( rNEvt
);
3694 else if( ImplChangeHighlightUpDn( aKeyCode
.IsShift() , bNoTabCycling
) )
3697 return DockingWindow::EventNotify( rNEvt
);
3703 else if( rNEvt
.GetType() == MouseNotifyEvent::GETFOCUS
)
3705 if( rNEvt
.GetWindow() == this )
3707 // the toolbar itself got the focus
3708 if( mnLastFocusItemId
!= 0 || mpData
->mbMenubuttonWasLastSelected
)
3710 // restore last item
3711 if( mpData
->mbMenubuttonWasLastSelected
)
3713 ImplChangeHighlight( nullptr );
3714 mpData
->mbMenubuttonSelected
= true;
3715 InvalidateMenuButton();
3719 ImplChangeHighlight( ImplGetItem( mnLastFocusItemId
) );
3720 mnLastFocusItemId
= 0;
3723 else if( (GetGetFocusFlags() & (GetFocusFlags::Backward
|GetFocusFlags::Tab
) ) == (GetFocusFlags::Backward
|GetFocusFlags::Tab
))
3724 // Shift-TAB was pressed in the parent
3725 ImplChangeHighlightUpDn( false );
3727 ImplChangeHighlightUpDn( true );
3729 mnLastFocusItemId
= 0;
3735 // a child window got the focus so update current item to
3736 // allow for proper lose focus handling in keyboard navigation
3737 for (auto const& item
: mpData
->m_aItems
)
3739 if ( item
.mbVisible
)
3741 if ( item
.mpWindow
&& item
.mpWindow
->ImplIsWindowOrChild( rNEvt
.GetWindow() ) )
3743 mnHighItemId
= item
.mnId
;
3748 return DockingWindow::EventNotify( rNEvt
);
3751 else if( rNEvt
.GetType() == MouseNotifyEvent::LOSEFOCUS
)
3755 mpData
->mbMenubuttonWasLastSelected
= false;
3757 mnCurPos
= ITEM_NOTFOUND
;
3760 return DockingWindow::EventNotify( rNEvt
);
3763 void ToolBox::Command( const CommandEvent
& rCEvt
)
3765 if ( rCEvt
.GetCommand() == CommandEventId::Wheel
)
3767 if ( (mnCurLine
> 1) || (mnCurLine
+mnVisLines
-1 < mnCurLines
) )
3769 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
3770 if ( pData
->GetMode() == CommandWheelMode::SCROLL
)
3772 if ( (mnCurLine
> 1) && (pData
->GetDelta() > 0) )
3774 else if ( (mnCurLine
+mnVisLines
-1 < mnCurLines
) && (pData
->GetDelta() < 0) )
3781 else if ( rCEvt
.GetCommand() == CommandEventId::ContextMenu
)
3783 ExecuteCustomMenu( tools::Rectangle( rCEvt
.GetMousePosPixel(), rCEvt
.GetMousePosPixel() ) );
3787 DockingWindow::Command( rCEvt
);
3790 void ToolBox::StateChanged( StateChangedType nType
)
3792 DockingWindow::StateChanged( nType
);
3794 if ( nType
== StateChangedType::InitShow
)
3796 else if ( nType
== StateChangedType::Enable
)
3798 else if ( nType
== StateChangedType::UpdateMode
)
3800 if ( IsUpdateMode() )
3803 else if ( (nType
== StateChangedType::Zoom
) ||
3804 (nType
== StateChangedType::ControlFont
) )
3808 ImplInitSettings( true, false, false );
3811 else if ( nType
== StateChangedType::ControlForeground
)
3813 ImplInitSettings( false, true, false );
3816 else if ( nType
== StateChangedType::ControlBackground
)
3818 ImplInitSettings( false, false, true ); // font, foreground, background
3822 maStateChangedHandler
.Call( &nType
);
3825 void ToolBox::DataChanged( const DataChangedEvent
& rDCEvt
)
3827 DockingWindow::DataChanged( rDCEvt
);
3829 if ( (rDCEvt
.GetType() == DataChangedEventType::DISPLAY
) ||
3830 (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ||
3831 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
3832 ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
3833 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)) )
3837 ImplInitSettings( true, true, true );
3841 maDataChangedHandler
.Call( &rDCEvt
);
3844 void ToolBox::statusChanged( const css::frame::FeatureStateEvent
& Event
)
3846 // Update image mirroring/rotation
3847 if ( Event
.FeatureURL
.Complete
!= ".uno:ImageOrientation" )
3850 SfxImageItem
aItem( 1 );
3851 aItem
.PutValue( Event
.State
, 0 );
3853 mbImagesMirrored
= aItem
.IsMirrored();
3854 mnImagesRotationAngle
= aItem
.GetRotation();
3856 // update image orientation
3857 OUString
aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(mpStatusListener
->getFrame()));
3858 for (auto const& item
: mpData
->m_aItems
)
3860 if (vcl::CommandInfoProvider::IsMirrored(item
.maCommandStr
, aModuleName
))
3861 SetItemImageMirrorMode(item
.mnId
, mbImagesMirrored
);
3862 if (vcl::CommandInfoProvider::IsRotated(item
.maCommandStr
, aModuleName
))
3863 SetItemImageAngle(item
.mnId
, mnImagesRotationAngle
);
3867 void ToolBox::SetStyle(WinBits nNewStyle
)
3869 mnWinStyle
= nNewStyle
;
3870 if (!ImplIsFloatingMode())
3872 bool bOldScroll
= mbScroll
;
3873 mbScroll
= (mnWinStyle
& WB_SCROLL
) != 0;
3874 if (mbScroll
!= bOldScroll
)
3882 void ToolBox::ToggleFloatingMode()
3884 DockingWindow::ToggleFloatingMode();
3889 bool bOldHorz
= mbHorz
;
3891 if ( ImplIsFloatingMode() )
3894 meAlign
= WindowAlign::Top
;
3897 if( bOldHorz
!= mbHorz
)
3898 mbCalc
= true; // orientation was changed !
3900 ImplSetMinMaxFloatSize();
3901 SetOutputSizePixel( ImplCalcFloatSize( mnFloatLines
) );
3905 mbScroll
= (mnWinStyle
& WB_SCROLL
) != 0;
3906 if ( (meAlign
== WindowAlign::Top
) || (meAlign
== WindowAlign::Bottom
) )
3911 // set focus back to document
3912 ImplGetFrameWindow()->GetWindow( GetWindowType::Client
)->GrabFocus();
3915 if( bOldHorz
!= mbHorz
)
3917 // if orientation changes, the toolbox has to be initialized again
3918 // to update the direction of the gradient
3920 ImplInitSettings( true, true, true );
3927 void ToolBox::StartDocking()
3929 meDockAlign
= meAlign
;
3930 mnDockLines
= mnLines
;
3931 mbLastFloatMode
= ImplIsFloatingMode();
3932 DockingWindow::StartDocking();
3935 bool ToolBox::Docking( const Point
& rPos
, tools::Rectangle
& rRect
)
3937 // do nothing during dragging, it was calculated before
3941 bool bFloatMode
= false;
3943 DockingWindow::Docking( rPos
, rRect
);
3945 // if the mouse is outside the area, it can only become a floating window
3946 tools::Rectangle
aDockingRect( rRect
);
3947 if ( !ImplIsFloatingMode() )
3949 // don't use tracking rectangle for alignment check, because it will be too large
3950 // to get a floating mode as result - switch to floating size
3951 // so the calculation only depends on the position of the rectangle, not the current
3952 // docking state of the window
3953 ImplToolItems::size_type nTemp
= 0;
3954 aDockingRect
.SetSize( ImplCalcFloatSize( nTemp
) );
3956 // in this mode docking is never done by keyboard, so it's OK to use the mouse position
3957 aDockingRect
.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
3962 meDockAlign
= meAlign
;
3963 if ( !mbLastFloatMode
)
3965 ImplToolItems::size_type nTemp
= 0;
3966 aDockingRect
.SetSize( ImplCalcFloatSize( nTemp
) );
3969 rRect
= aDockingRect
;
3970 mbLastFloatMode
= bFloatMode
;
3975 void ToolBox::EndDocking( const tools::Rectangle
& rRect
, bool bFloatMode
)
3977 if ( !IsDockingCanceled() )
3979 if ( mnLines
!= mnDockLines
)
3980 SetLineCount( mnDockLines
);
3981 if ( meAlign
!= meDockAlign
)
3982 SetAlign( meDockAlign
);
3984 if ( bFloatMode
|| (bFloatMode
!= ImplIsFloatingMode()) )
3985 DockingWindow::EndDocking( rRect
, bFloatMode
);
3988 void ToolBox::Resizing( Size
& rSize
)
3990 ImplToolItems::size_type nCalcLines
;
3991 ImplToolItems::size_type nTemp
;
3993 // calculate all floating sizes
3994 ImplCalcFloatSizes();
3996 if ( !mnLastResizeDY
)
3997 mnLastResizeDY
= mnDY
;
3999 // is vertical resizing needed
4000 if ( (mnLastResizeDY
!= rSize
.Height()) && (mnDY
!= rSize
.Height()) )
4002 nCalcLines
= ImplCalcLines( rSize
.Height() );
4003 if ( nCalcLines
< 1 )
4005 rSize
= ImplCalcFloatSize( nCalcLines
);
4011 Size aTempSize
= ImplCalcFloatSize( nTemp
);
4012 while ( (aTempSize
.Width() > rSize
.Width()) &&
4013 (nCalcLines
<= maFloatSizes
[0].mnLines
) )
4017 aTempSize
= ImplCalcFloatSize( nTemp
);
4022 mnLastResizeDY
= rSize
.Height();
4025 Size
ToolBox::GetOptimalSize() const
4027 // If we have any expandable entries, then force them to their
4028 // optimal sizes, then reset them afterwards
4029 std::map
<vcl::Window
*, Size
> aExpandables
;
4030 for (const ImplToolItem
& rItem
: mpData
->m_aItems
)
4034 vcl::Window
*pWindow
= rItem
.mpWindow
;
4035 SAL_INFO_IF(!pWindow
, "vcl.layout", "only tabitems with window supported at the moment");
4038 Size
aWinSize(pWindow
->GetSizePixel());
4039 aExpandables
[pWindow
] = aWinSize
;
4040 Size
aPrefSize(pWindow
->get_preferred_size());
4041 aWinSize
.setWidth( aPrefSize
.Width() );
4042 pWindow
->SetSizePixel(aWinSize
);
4046 Size
aSize(const_cast<ToolBox
*>(this)->ImplCalcSize( mnLines
));
4048 for (auto const& expandable
: aExpandables
)
4050 vcl::Window
*pWindow
= expandable
.first
;
4051 Size aWinSize
= expandable
.second
;
4052 pWindow
->SetSizePixel(aWinSize
);
4058 Size
ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines
)
4060 return ImplCalcSize( nCalcLines
);
4063 Size
ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines
, WindowAlign eAlign
)
4065 return ImplCalcSize( nCalcLines
,
4066 (eAlign
== WindowAlign::Top
|| eAlign
== WindowAlign::Bottom
) ? TB_CALCMODE_HORZ
: TB_CALCMODE_VERT
);
4069 ToolBox::ImplToolItems::size_type
ToolBox::ImplCountLineBreaks() const
4071 ImplToolItems::size_type nLines
= 0;
4073 for (auto const& item
: mpData
->m_aItems
)
4075 if( item
.meType
== ToolBoxItemType::BREAK
)
4081 Size
ToolBox::CalcPopupWindowSizePixel()
4083 // count number of breaks and calc corresponding floating window size
4084 ImplToolItems::size_type nLines
= ImplCountLineBreaks();
4087 ++nLines
; // add the first line
4090 // no breaks found: use quadratic layout
4091 nLines
= static_cast<ImplToolItems::size_type
>(ceil( sqrt( static_cast<double>(GetItemCount()) ) ));
4094 bool bPopup
= mpData
->mbAssumePopupMode
;
4095 mpData
->mbAssumePopupMode
= true;
4097 Size aSize
= CalcFloatingWindowSizePixel( nLines
);
4099 mpData
->mbAssumePopupMode
= bPopup
;
4103 Size
ToolBox::CalcFloatingWindowSizePixel()
4105 ImplToolItems::size_type nLines
= ImplCountLineBreaks();
4106 ++nLines
; // add the first line
4107 return CalcFloatingWindowSizePixel( nLines
);
4110 Size
ToolBox::CalcFloatingWindowSizePixel( ImplToolItems::size_type nCalcLines
)
4112 bool bFloat
= mpData
->mbAssumeFloating
;
4113 bool bDocking
= mpData
->mbAssumeDocked
;
4115 // simulate floating mode and force reformat before calculating
4116 mpData
->mbAssumeFloating
= true;
4117 mpData
->mbAssumeDocked
= false;
4119 Size aSize
= ImplCalcFloatSize( nCalcLines
);
4122 mpData
->mbAssumeFloating
= bFloat
;
4123 mpData
->mbAssumeDocked
= bDocking
;
4128 Size
ToolBox::CalcMinimumWindowSizePixel()
4130 if( ImplIsFloatingMode() )
4131 return ImplCalcSize( mnFloatLines
);
4134 // create dummy toolbox for measurements
4135 VclPtrInstance
< ToolBox
> pToolBox( GetParent(), GetStyle() );
4137 // copy until first useful item
4138 for (auto const& item
: mpData
->m_aItems
)
4140 pToolBox
->CopyItem( *this, item
.mnId
);
4141 if( (item
.meType
== ToolBoxItemType::BUTTON
) &&
4142 item
.mbVisible
&& !ImplIsFixedControl( &item
) )
4146 // add to docking manager if required to obtain a drag area
4147 // (which is accounted for in calcwindowsizepixel)
4148 if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
4149 ImplGetDockingManager()->AddWindow( pToolBox
);
4152 if( IsMenuEnabled() )
4153 pToolBox
->SetMenuType( GetMenuType() );
4155 pToolBox
->SetAlign( GetAlign() );
4156 Size aSize
= pToolBox
->CalcWindowSizePixel( 1 );
4158 ImplGetDockingManager()->RemoveWindow( pToolBox
);
4161 pToolBox
.disposeAndClear();
4167 void ToolBox::EnableCustomize( bool bEnable
)
4169 mbCustomize
= bEnable
;
4172 void ToolBox::LoseFocus()
4174 ImplChangeHighlight( nullptr, true );
4176 DockingWindow::LoseFocus();
4179 // performs the action associated with an item, ie simulates clicking the item
4180 void ToolBox::TriggerItem( sal_uInt16 nItemId
)
4182 mnHighItemId
= nItemId
;
4183 vcl::KeyCode
aKeyCode( 0, 0 );
4184 ImplActivateItem( aKeyCode
);
4187 // calls the button's action handler
4188 // returns true if action was called
4189 bool ToolBox::ImplActivateItem( vcl::KeyCode aKeyCode
)
4194 ImplToolItem
*pToolItem
= ImplGetItem( mnHighItemId
);
4196 // #107712#, activate can also be called for disabled entries
4197 if( pToolItem
&& !pToolItem
->mbEnabled
)
4200 if( pToolItem
&& pToolItem
->mpWindow
&& HasFocus() )
4203 mbChangingHighlight
= true; // avoid focus change due to loss of focus
4204 pToolItem
->mpWindow
->ImplControlFocus( GetFocusFlags::Tab
);
4205 mbChangingHighlight
= false;
4209 mnDownItemId
= mnCurItemId
= mnHighItemId
;
4210 if (pToolItem
&& (pToolItem
->mnBits
& ToolBoxItemBits::AUTOCHECK
))
4212 if ( pToolItem
->mnBits
& ToolBoxItemBits::RADIOCHECK
)
4214 if ( pToolItem
->meState
!= TRISTATE_TRUE
)
4215 SetItemState( pToolItem
->mnId
, TRISTATE_TRUE
);
4219 if ( pToolItem
->meState
!= TRISTATE_TRUE
)
4220 pToolItem
->meState
= TRISTATE_TRUE
;
4222 pToolItem
->meState
= TRISTATE_FALSE
;
4225 mnMouseModifier
= aKeyCode
.GetModifier();
4226 mbIsKeyEvent
= true;
4230 // #107776# we might be destroyed in the selecthandler
4231 VclPtr
<vcl::Window
> xWindow
= this;
4233 if ( xWindow
->IsDisposed() )
4237 mbIsKeyEvent
= false;
4238 mnMouseModifier
= 0;
4246 static bool ImplCloseLastPopup( vcl::Window
const *pParent
)
4248 // close last popup toolbox (see also:
4249 // ImplHandleMouseFloatMode(...) in winproc.cxx )
4251 if (ImplGetSVData()->mpWinData
->mpFirstFloat
)
4253 FloatingWindow
* pLastLevelFloat
= ImplGetSVData()->mpWinData
->mpFirstFloat
->ImplFindLastLevelFloat();
4254 // only close the floater if it is not our direct parent, which would kill ourself
4255 if( pLastLevelFloat
&& pLastLevelFloat
!= pParent
)
4257 pLastLevelFloat
->EndPopupMode( FloatWinPopupEndFlags::Cancel
| FloatWinPopupEndFlags::CloseAll
);
4264 // opens a drop down toolbox item
4265 // returns true if item was opened
4266 bool ToolBox::ImplOpenItem( vcl::KeyCode aKeyCode
)
4268 sal_uInt16 nCode
= aKeyCode
.GetCode();
4271 // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
4272 if ( ((nCode
== KEY_LEFT
|| nCode
== KEY_RIGHT
) && IsHorizontal())
4273 || ((nCode
== KEY_UP
|| nCode
== KEY_DOWN
) && !IsHorizontal()) )
4276 if( mpData
->mbMenubuttonSelected
)
4278 if( ImplCloseLastPopup( GetParent() ) )
4280 mbIsKeyEvent
= true;
4281 if ( maMenuButtonHdl
.IsSet() )
4282 maMenuButtonHdl
.Call( this );
4284 ExecuteCustomMenu( mpData
->maMenubuttonItem
.maRect
);
4285 mpData
->mbMenubuttonWasLastSelected
= true;
4286 mbIsKeyEvent
= false;
4288 else if( mnHighItemId
&& ImplGetItem( mnHighItemId
) &&
4289 (ImplGetItem( mnHighItemId
)->mnBits
& ToolBoxItemBits::DROPDOWN
) )
4291 mnDownItemId
= mnCurItemId
= mnHighItemId
;
4292 mnCurPos
= GetItemPos( mnCurItemId
);
4293 mnLastFocusItemId
= mnCurItemId
; // save item id for possible later focus restore
4294 mnMouseModifier
= aKeyCode
.GetModifier();
4295 mbIsKeyEvent
= true;
4298 mpData
->mbDropDownByKeyboard
= true;
4299 mpData
->maDropdownClickHdl
.Call( this );
4301 mbIsKeyEvent
= false;
4302 mnMouseModifier
= 0;
4310 void ToolBox::KeyInput( const KeyEvent
& rKEvt
)
4312 vcl::KeyCode aKeyCode
= rKEvt
.GetKeyCode();
4313 sal_uInt16 nCode
= aKeyCode
.GetCode();
4315 vcl::Window
*pParent
= ImplGetParent();
4316 bool bOldSchoolContainer
= ((pParent
->GetStyle() & (WB_DIALOGCONTROL
| WB_NODIALOGCONTROL
)) == WB_DIALOGCONTROL
);
4317 bool bParentIsContainer
= bOldSchoolContainer
|| isContainerWindow(pParent
);
4319 bool bForwardKey
= false;
4320 bool bGrabFocusToDocument
= false;
4322 // #107776# we might be destroyed in the keyhandler
4323 VclPtr
<vcl::Window
> xWindow
= this;
4329 // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
4330 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4332 if( !IsHorizontal() )
4333 ImplChangeHighlightUpDn( true );
4335 ImplOpenItem( aKeyCode
);
4340 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4342 if( IsHorizontal() )
4343 ImplChangeHighlightUpDn( true );
4345 ImplOpenItem( aKeyCode
);
4350 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4352 if( !IsHorizontal() )
4353 ImplChangeHighlightUpDn( false );
4355 ImplOpenItem( aKeyCode
);
4360 if( aKeyCode
.GetModifier() ) // allow only pure cursor keys
4362 if( IsHorizontal() )
4363 ImplChangeHighlightUpDn( false );
4365 ImplOpenItem( aKeyCode
);
4369 if ( mnCurLine
> 1 )
4371 if( mnCurLine
> mnVisLines
)
4372 mnCurLine
= mnCurLine
- mnVisLines
;
4378 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine
) );
4382 if ( mnCurLine
+mnVisLines
-1 < mnCurLines
)
4384 if( mnCurLine
+ 2*mnVisLines
-1 < mnCurLines
)
4385 mnCurLine
= mnCurLine
+ mnVisLines
;
4387 mnCurLine
= mnCurLines
;
4391 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine
) );
4396 ImplChangeHighlight( nullptr );
4397 ImplChangeHighlightUpDn( false );
4402 ImplChangeHighlight( nullptr );
4403 ImplChangeHighlightUpDn( true );
4408 if( !ImplIsFloatingMode() && bParentIsContainer
)
4409 DockingWindow::KeyInput( rKEvt
);
4412 // send focus to document pane
4413 vcl::Window
*pWin
= this;
4416 if( !pWin
->GetParent() )
4418 pWin
->ImplGetFrameWindow()->GetWindow( GetWindowType::Client
)->GrabFocus();
4421 pWin
= pWin
->GetParent();
4428 // #107712#, disabled entries are selectable now
4429 // leave toolbox and move focus to document
4432 ImplToolItem
*pItem
= ImplGetItem(mnHighItemId
);
4433 if (!pItem
|| !pItem
->mbEnabled
)
4435 bGrabFocusToDocument
= true;
4438 if( !bGrabFocusToDocument
)
4439 bForwardKey
= !ImplActivateItem( aKeyCode
);
4444 ImplOpenItem( aKeyCode
);
4449 sal_uInt16 aKeyGroup
= aKeyCode
.GetGroup();
4450 ImplToolItem
*pItem
= nullptr;
4452 pItem
= ImplGetItem( mnHighItemId
);
4453 // #i13931# forward alphanum keyinput into embedded control
4454 if( (aKeyGroup
== KEYGROUP_NUM
|| aKeyGroup
== KEYGROUP_ALPHA
) && pItem
&& pItem
->mpWindow
&& pItem
->mbEnabled
)
4456 vcl::Window
*pFocusWindow
= Application::GetFocusWindow();
4458 mbChangingHighlight
= true; // avoid focus change due to loss of focus
4459 pItem
->mpWindow
->ImplControlFocus( GetFocusFlags::Tab
);
4460 mbChangingHighlight
= false;
4461 if( pFocusWindow
!= Application::GetFocusWindow() )
4462 Application::GetFocusWindow()->KeyInput( rKEvt
);
4466 // do nothing to avoid key presses going into the document
4467 // while the toolbox has the focus
4468 // just forward function and special keys and combinations with Alt-key
4469 if( aKeyGroup
== KEYGROUP_FKEYS
|| aKeyGroup
== KEYGROUP_MISC
|| aKeyCode
.IsMod2() )
4475 if ( xWindow
->IsDisposed() )
4478 // #107251# move focus away if this toolbox was disabled during keyinput
4479 if (HasFocus() && mpData
->mbKeyInputDisabled
&& bParentIsContainer
)
4481 vcl::Window
*pFocusControl
= pParent
->ImplGetDlgWindow( 0, GetDlgWindowType::First
);
4482 if ( pFocusControl
&& pFocusControl
!= this )
4483 pFocusControl
->ImplControlFocus( GetFocusFlags::Init
);
4486 // #107712#, leave toolbox
4487 if( bGrabFocusToDocument
)
4489 GrabFocusToDocument();
4494 DockingWindow::KeyInput( rKEvt
);
4497 // returns the current toolbox line of the item
4498 ToolBox::ImplToolItems::size_type
ToolBox::ImplGetItemLine( ImplToolItem
const * pCurrentItem
)
4500 ImplToolItems::size_type nLine
= 1;
4501 for (auto const& item
: mpData
->m_aItems
)
4505 if( &item
== pCurrentItem
)
4511 // returns the first displayable item in the given line
4512 ImplToolItem
* ToolBox::ImplGetFirstValidItem( ImplToolItems::size_type nLine
)
4514 if( !nLine
|| nLine
> mnCurLines
)
4519 ImplToolItems::iterator it
= mpData
->m_aItems
.begin();
4520 while( it
!= mpData
->m_aItems
.end() )
4522 // find correct line
4527 // find first useful item
4528 while( it
!= mpData
->m_aItems
.end() && ((it
->meType
!= ToolBoxItemType::BUTTON
) ||
4529 /*!it->mbEnabled ||*/ !it
->mbVisible
|| ImplIsFixedControl( &(*it
) )) )
4532 if( it
== mpData
->m_aItems
.end() || it
->mbBreak
)
4533 return nullptr; // no valid items in this line
4540 return (it
== mpData
->m_aItems
.end()) ? nullptr : &(*it
);
4543 ToolBox::ImplToolItems::size_type
ToolBox::ImplFindItemPos( const ImplToolItem
* pItem
, const ImplToolItems
& rList
)
4547 for( ImplToolItems::size_type nPos
= 0; nPos
< rList
.size(); ++nPos
)
4548 if( &rList
[ nPos
] == pItem
)
4551 return ITEM_NOTFOUND
;
4554 void ToolBox::ChangeHighlight( ImplToolItems::size_type nPos
)
4556 if ( nPos
< GetItemCount() ) {
4557 ImplGrabFocus( GetFocusFlags::NONE
);
4558 ImplChangeHighlight ( ImplGetItem ( GetItemId ( nPos
) ) );
4562 void ToolBox::ImplChangeHighlight( ImplToolItem
const * pItem
, bool bNoGrabFocus
)
4564 // avoid recursion due to focus change
4565 if( mbChangingHighlight
)
4568 mbChangingHighlight
= true;
4570 ImplToolItem
* pOldItem
= nullptr;
4575 ImplToolItems::size_type nPos
= GetItemPos( mnHighItemId
);
4576 pOldItem
= ImplGetItem( mnHighItemId
);
4577 // #i89962# ImplDrawItem can cause Invalidate/Update
4578 // which will in turn ImplShowFocus again
4579 // set mnHighItemId to 0 already to prevent this hen/egg problem
4581 InvalidateItem(nPos
);
4582 CallEventListeners( VclEventId::ToolboxHighlightOff
, reinterpret_cast< void* >( nPos
) );
4585 if( !bNoGrabFocus
&& pItem
!= pOldItem
&& pOldItem
&& pOldItem
->mpWindow
)
4587 // move focus into toolbox
4593 ImplToolItems::size_type aPos
= ToolBox::ImplFindItemPos( pItem
, mpData
->m_aItems
);
4594 if( aPos
!= ITEM_NOTFOUND
)
4596 // check for line breaks
4597 ImplToolItems::size_type nLine
= ImplGetItemLine( pItem
);
4599 if( nLine
>= mnCurLine
+ mnVisLines
)
4601 mnCurLine
= nLine
- mnVisLines
+ 1;
4604 else if ( nLine
< mnCurLine
)
4615 mnHighItemId
= pItem
->mnId
;
4616 InvalidateItem(aPos
);
4620 if( pItem
->mpWindow
)
4621 pItem
->mpWindow
->GrabFocus();
4622 if( pItem
!= pOldItem
)
4623 CallEventListeners( VclEventId::ToolboxHighlight
);
4630 mnCurPos
= ITEM_NOTFOUND
;
4633 mbChangingHighlight
= false;
4636 // check for keyboard accessible items
4637 static bool ImplIsValidItem( const ImplToolItem
* pItem
, bool bNotClipped
)
4639 bool bValid
= (pItem
&& pItem
->meType
== ToolBoxItemType::BUTTON
&& pItem
->mbVisible
&& !ImplIsFixedControl( pItem
)
4640 && pItem
->mbEnabled
);
4641 if( bValid
&& bNotClipped
&& pItem
->IsClipped() )
4646 bool ToolBox::ImplChangeHighlightUpDn( bool bUp
, bool bNoCycle
)
4648 ImplToolItem
* pToolItem
= ImplGetItem( mnHighItemId
);
4650 if( !pToolItem
|| !mnHighItemId
)
4652 // menubutton highlighted ?
4653 if( mpData
->mbMenubuttonSelected
)
4655 mpData
->mbMenubuttonSelected
= false;
4658 // select last valid non-clipped item
4659 ImplToolItem
* pItem
= nullptr;
4660 auto it
= std::find_if(mpData
->m_aItems
.rbegin(), mpData
->m_aItems
.rend(),
4661 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, true ); });
4662 if( it
!= mpData
->m_aItems
.rend() )
4665 InvalidateMenuButton();
4666 ImplChangeHighlight( pItem
);
4670 // select first valid non-clipped item
4671 ImplToolItems::iterator it
= std::find_if(mpData
->m_aItems
.begin(), mpData
->m_aItems
.end(),
4672 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, true ); });
4673 if( it
!= mpData
->m_aItems
.end() )
4675 InvalidateMenuButton();
4676 ImplChangeHighlight( &(*it
) );
4684 // Select first valid item
4685 ImplToolItems::iterator it
= std::find_if(mpData
->m_aItems
.begin(), mpData
->m_aItems
.end(),
4686 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, false ); });
4688 // select the menu button if a clipped item would be selected
4689 if( (it
!= mpData
->m_aItems
.end() && &(*it
) == ImplGetFirstClippedItem()) && IsMenuEnabled() )
4691 ImplChangeHighlight( nullptr );
4692 mpData
->mbMenubuttonSelected
= true;
4693 InvalidateMenuButton();
4696 ImplChangeHighlight( (it
!= mpData
->m_aItems
.end()) ? &(*it
) : nullptr );
4701 // Select last valid item
4703 // docked toolbars have the menubutton as last item - if this button is enabled
4704 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4706 ImplChangeHighlight( nullptr );
4707 mpData
->mbMenubuttonSelected
= true;
4708 InvalidateMenuButton();
4712 ImplToolItem
* pItem
= nullptr;
4713 auto it
= std::find_if(mpData
->m_aItems
.rbegin(), mpData
->m_aItems
.rend(),
4714 [](const ImplToolItem
& rItem
) { return ImplIsValidItem( &rItem
, false ); });
4715 if( it
!= mpData
->m_aItems
.rend() )
4718 ImplChangeHighlight( pItem
);
4726 ImplToolItems::size_type pos
= ToolBox::ImplFindItemPos( pToolItem
, mpData
->m_aItems
);
4727 ImplToolItems::size_type nCount
= mpData
->m_aItems
.size();
4729 ImplToolItems::size_type i
=0;
4739 // highlight the menu button if it is the last item
4740 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4742 ImplChangeHighlight( nullptr );
4743 mpData
->mbMenubuttonSelected
= true;
4744 InvalidateMenuButton();
4753 if( ++pos
>= nCount
)
4758 // highlight the menu button if it is the last item
4759 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4761 ImplChangeHighlight( nullptr );
4762 mpData
->mbMenubuttonSelected
= true;
4763 InvalidateMenuButton();
4771 pToolItem
= &mpData
->m_aItems
[pos
];
4773 if ( ImplIsValidItem( pToolItem
, false ) )
4776 } while( ++i
< nCount
);
4778 if( pToolItem
->IsClipped() && IsMenuEnabled() )
4780 // select the menu button if a clipped item would be selected
4781 ImplChangeHighlight( nullptr );
4782 mpData
->mbMenubuttonSelected
= true;
4783 InvalidateMenuButton();
4785 else if( i
!= nCount
)
4786 ImplChangeHighlight( pToolItem
);
4793 void ToolBox::ImplShowFocus()
4795 if( mnHighItemId
&& HasFocus() )
4797 ImplToolItem
* pItem
= ImplGetItem( mnHighItemId
);
4798 if (pItem
&& pItem
->mpWindow
&& !pItem
->mpWindow
->IsDisposed())
4800 vcl::Window
*pWin
= pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
? pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
.get() : pItem
->mpWindow
.get();
4801 pWin
->ImplGetWindowImpl()->mbDrawSelectionBackground
= true;
4807 void ToolBox::ImplHideFocus()
4811 mpData
->mbMenubuttonWasLastSelected
= false;
4812 ImplToolItem
* pItem
= ImplGetItem( mnHighItemId
);
4813 if( pItem
&& pItem
->mpWindow
)
4815 vcl::Window
*pWin
= pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
? pItem
->mpWindow
->ImplGetWindowImpl()->mpBorderWindow
.get() : pItem
->mpWindow
.get();
4816 pWin
->ImplGetWindowImpl()->mbDrawSelectionBackground
= false;
4821 if ( mpData
&& mpData
->mbMenubuttonSelected
)
4823 mpData
->mbMenubuttonWasLastSelected
= true;
4824 // remove highlight from menubutton
4825 mpData
->mbMenubuttonSelected
= false;
4826 InvalidateMenuButton();
4830 void ToolBox::SetToolbarLayoutMode( ToolBoxLayoutMode eLayout
)
4832 if ( meLayoutMode
!= eLayout
)
4833 meLayoutMode
= eLayout
;
4836 void ToolBox::SetToolBoxTextPosition( ToolBoxTextPosition ePosition
)
4838 meTextPosition
= ePosition
;
4841 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */