bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / window / toolbox.cxx
blob3b0d6b5a5f7efe1b3825371bd99763f83b5ff898
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/toolbox.hxx>
21 #include <vcl/commandinfoprovider.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/decoview.hxx>
24 #include <vcl/accel.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/help.hxx>
27 #include <vcl/mnemonic.hxx>
28 #include <vcl/gradient.hxx>
29 #include <vcl/layout.hxx>
30 #include <vcl/menu.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/vclstatuslistener.hxx>
33 #include <vcl/ptrstyle.hxx>
34 #include <bitmaps.hlst>
36 #include <tools/poly.hxx>
37 #include <svl/imageitm.hxx>
38 #include <sal/log.hxx>
39 #include <osl/diagnose.h>
41 #include <svdata.hxx>
42 #include <window.h>
43 #include <toolbox.h>
44 #include <spin.hxx>
45 #if defined(_WIN32)
46 #include <svsys.h>
47 #endif
49 #include <cstdlib>
50 #include <vector>
51 #include <math.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
67 #define TB_MAXLINES 5
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
86 class ImplTBDragMgr
88 private:
89 VclPtr<ToolBox> mpDragBox;
90 Point maMouseOff;
91 tools::Rectangle maRect;
92 tools::Rectangle maStartRect;
93 Accelerator maAccel;
94 sal_uInt16 mnLineMode;
95 ToolBox::ImplToolItems::size_type mnStartLines;
97 ImplTBDragMgr(const ImplTBDragMgr&) = delete;
98 ImplTBDragMgr& operator=(const ImplTBDragMgr&) = delete;
100 public:
101 ImplTBDragMgr();
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();
139 return nWidth;
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 );
165 if( pWrapper )
167 if ( ImplIsFloatingMode() || pWrapper->IsLocked() )
168 pWrapper->SetDragArea( tools::Rectangle() );
169 else
171 if( meAlign == WindowAlign::Top || meAlign == WindowAlign::Bottom )
172 pWrapper->SetDragArea( tools::Rectangle( 0, 0, ImplGetDragWidth(), GetOutputSizePixel().Height() ) );
173 else
174 pWrapper->SetDragArea( tools::Rectangle( 0, 0, GetOutputSizePixel().Width(), ImplGetDragWidth() ) );
179 void ToolBox::ImplCalcBorder( WindowAlign eAlign, long& rLeft, long& rTop,
180 long& rRight, long& rBottom ) const
182 if( ImplIsFloatingMode() || !(mnWinStyle & WB_BORDER) )
184 // no border in floating mode
185 rLeft = rTop = rRight = rBottom = 0;
186 return;
189 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
191 // reserve DragArea only for dockable toolbars
192 int dragwidth = ( pWrapper && !pWrapper->IsLocked() ) ? ImplGetDragWidth() : 0;
194 // no shadow border for dockable toolbars
195 int borderwidth = pWrapper ? 0: 2;
197 if ( eAlign == WindowAlign::Top )
199 rLeft = borderwidth+dragwidth;
200 rTop = borderwidth;
201 rRight = borderwidth;
202 rBottom = 0;
204 else if ( eAlign == WindowAlign::Left )
206 rLeft = borderwidth;
207 rTop = borderwidth+dragwidth;
208 rRight = 0;
209 rBottom = borderwidth;
211 else if ( eAlign == WindowAlign::Bottom )
213 rLeft = borderwidth+dragwidth;
214 rTop = 0;
215 rRight = borderwidth;
216 rBottom = borderwidth;
218 else
220 rLeft = 0;
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() )
236 Update();
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() );
256 if( bNativeOk )
257 return;
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;
269 height += i;
270 while (i <= height)
272 int x = nDragWidth / 2;
273 rRenderContext.DrawEllipse(tools::Rectangle(Point(x, i), Size(2 * fScaleFactor, 2 * fScaleFactor)));
274 i += 4 * fScaleFactor;
277 else
279 int width = static_cast<int>(0.6 * aSz.Width() + 0.5);
280 int i = (aSz.Width() - width) / 2;
281 width += i;
282 while (i <= width)
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
297 ImplCheckUpdate();
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
314 startCol = endCol;
316 Gradient g;
317 g.SetAngle(mbHorz ? 0 : 900);
318 g.SetStyle(GradientStyle::Linear);
320 g.SetStartColor(startCol);
321 g.SetEndColor(endCol);
323 bool bLineColor = rRenderContext.IsLineColor();
324 Color aOldCol = rRenderContext.GetLineColor();
325 rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetShadowColor());
327 Size aFullSz(GetOutputSizePixel());
328 Size aLineSz(aFullSz);
330 // use the linesize only when floating
331 // full window height is used when docked (single line)
332 if (ImplIsFloatingMode())
334 long nLineSize;
335 if (mbHorz)
337 nLineSize = mnMaxItemHeight;
338 if (mnWinHeight > mnMaxItemHeight)
339 nLineSize = mnWinHeight;
341 aLineSz.setHeight( nLineSize );
343 else
345 nLineSize = mnMaxItemWidth;
346 aLineSz.setWidth( nLineSize );
350 long nLeft, nTop, nRight, nBottom;
351 ImplCalcBorder(meAlign, nLeft, nTop, nRight, nBottom);
353 Size aTopLineSz(aLineSz);
354 Size aBottomLineSz(aLineSz);
356 if (mnWinStyle & WB_BORDER)
358 if (mbHorz)
360 aTopLineSz.AdjustHeight(TB_BORDER_OFFSET2 + nTop );
361 aBottomLineSz.AdjustHeight(TB_BORDER_OFFSET2 + nBottom );
363 if (mnCurLines == 1)
364 aTopLineSz.AdjustHeight(TB_BORDER_OFFSET2 + nBottom );
366 else
368 aTopLineSz.AdjustWidth(TB_BORDER_OFFSET1 + nLeft );
369 aBottomLineSz.AdjustWidth(TB_BORDER_OFFSET1 + nRight );
371 if (mnCurLines == 1)
372 aTopLineSz.AdjustWidth(TB_BORDER_OFFSET1 + nLeft );
376 if (mbLineSpacing)
378 if (mbHorz)
380 aLineSz.AdjustHeight(TB_LINESPACING );
381 if (mnCurLines > 1)
382 aTopLineSz.AdjustHeight(TB_LINESPACING );
384 else
386 aLineSz.AdjustWidth(TB_LINESPACING );
387 if (mnCurLines > 1)
388 aTopLineSz.AdjustWidth(TB_LINESPACING );
392 if (mbHorz)
394 long y = 0;
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);
407 else
409 long x = 0;
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);
423 if( bLineColor )
424 rRenderContext.SetLineColor( aOldCol );
428 bool ToolBox::ImplDrawNativeBackground(vcl::RenderContext& rRenderContext)
430 // use NWF
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
452 if (!bIsInPopupMode)
454 // default background
455 rRenderContext.Erase(rRegion.GetBoundRect());
457 else
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
469 ImplCheckUpdate();
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
477 if (IsInPaint())
478 aPaintRegion.Intersect(GetActiveClipRegion());
480 rRenderContext.Push(PushFlags::CLIPREGION);
481 rRenderContext.IntersectClipRegion( aPaintRegion );
483 if (!pWrapper)
485 // no gradient for ordinary toolbars (not dockable)
486 if( !IsBackground() && !IsInPaint() )
487 ImplDrawTransparentBackground(aPaintRegion);
488 else
489 ImplDrawConstantBackground(rRenderContext, aPaintRegion, bIsInPopupMode);
491 else
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);
499 if (!bNativeOk)
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)
506 if (!IsInPaint())
507 ImplDrawTransparentBackground(aPaintRegion);
509 else
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();
530 if (bHasOpenPopup)
531 // choose the same color as the popup will use
532 rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetFaceGradientColor());
533 else
534 rRenderContext.SetFillColor(COL_WHITE);
536 rRenderContext.DrawRect(rRect);
537 rRenderContext.Pop();
539 else
540 ImplDrawBackground(rRenderContext, rRect);
542 else
543 ImplDrawBackground(rRenderContext, rRect);
546 void ToolBox::ImplDrawBorder(vcl::RenderContext& rRenderContext)
548 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
549 long nDX = mnDX;
550 long nDY = mnDY;
552 ImplDockingWindowWrapper* pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper(this);
554 // draw borders for ordinary toolbars only (not dockable)
555 if( pWrapper )
556 return;
558 if (meAlign == WindowAlign::Bottom)
560 // draw bottom border
561 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
562 rRenderContext.DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
563 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
564 rRenderContext.DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
566 else
568 // draw top border
569 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
570 rRenderContext.DrawLine( Point( 0, 0 ), Point( nDX-1, 0 ) );
571 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
572 rRenderContext.DrawLine( Point( 0, 1 ), Point( nDX-1, 1 ) );
574 if (meAlign == WindowAlign::Left || meAlign == WindowAlign::Right)
576 if (meAlign == WindowAlign::Left)
578 // draw left-bottom border
579 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
580 rRenderContext.DrawLine( Point( 0, 0 ), Point( 0, nDY-1 ) );
581 rRenderContext.DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
582 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
583 rRenderContext.DrawLine( Point( 1, 1 ), Point( 1, nDY-3 ) );
584 rRenderContext.DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
586 else
588 // draw right-bottom border
589 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
590 rRenderContext.DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-3 ) );
591 rRenderContext.DrawLine( Point( 0, nDY-2 ), Point( nDX-2, nDY-2 ) );
592 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
593 rRenderContext.DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
594 rRenderContext.DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
599 if ( meAlign == WindowAlign::Bottom || meAlign == WindowAlign::Top )
601 // draw right border
602 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
603 rRenderContext.DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-1 ) );
604 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
605 rRenderContext.DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
609 static bool ImplIsFixedControl( const ImplToolItem *pItem )
611 return ( pItem->mpWindow &&
612 (pItem->mpWindow->GetType() == WindowType::FIXEDTEXT ||
613 pItem->mpWindow->GetType() == WindowType::FIXEDLINE ||
614 pItem->mpWindow->GetType() == WindowType::GROUPBOX) );
617 const ImplToolItem *ToolBox::ImplGetFirstClippedItem() const
619 for (auto & item : mpData->m_aItems)
621 if( item.IsClipped() )
622 return &item;
624 return nullptr;
627 Size ToolBox::ImplCalcSize( ImplToolItems::size_type nCalcLines, sal_uInt16 nCalcMode )
629 long nMax;
630 long nLeft = 0;
631 long nTop = 0;
632 long nRight = 0;
633 long nBottom = 0;
634 Size aSize;
635 WindowAlign eOldAlign = meAlign;
636 bool bOldHorz = mbHorz;
637 bool bOldAssumeDocked = mpData->mbAssumeDocked;
638 bool bOldAssumeFloating = mpData->mbAssumeFloating;
640 if ( nCalcMode )
642 bool bOldFloatingMode = ImplIsFloatingMode();
644 mpData->mbAssumeDocked = false;
645 mpData->mbAssumeFloating = false;
647 if ( nCalcMode == TB_CALCMODE_HORZ )
649 mpData->mbAssumeDocked = true; // force non-floating mode during calculation
650 ImplCalcBorder( WindowAlign::Top, nLeft, nTop, nRight, nBottom );
651 mbHorz = true;
652 if ( mbHorz != bOldHorz )
653 meAlign = WindowAlign::Top;
655 else if ( nCalcMode == TB_CALCMODE_VERT )
657 mpData->mbAssumeDocked = true; // force non-floating mode during calculation
658 ImplCalcBorder( WindowAlign::Left, nLeft, nTop, nRight, nBottom );
659 mbHorz = false;
660 if ( mbHorz != bOldHorz )
661 meAlign = WindowAlign::Left;
663 else if ( nCalcMode == TB_CALCMODE_FLOAT )
665 mpData->mbAssumeFloating = true; // force non-floating mode during calculation
666 nLeft = nTop = nRight = nBottom = 0;
667 mbHorz = true;
668 if ( mbHorz != bOldHorz )
669 meAlign = WindowAlign::Top;
672 if ( (meAlign != eOldAlign) || (mbHorz != bOldHorz) ||
673 (ImplIsFloatingMode() != bOldFloatingMode ) )
674 mbCalc = true;
676 else
677 ImplCalcBorder( meAlign, nLeft, nTop, nRight, nBottom );
679 ImplCalcItem();
681 if( !nCalcMode && ImplIsFloatingMode() )
683 aSize = ImplCalcFloatSize( nCalcLines );
685 else
687 if ( mbHorz )
689 if ( mnWinHeight > mnMaxItemHeight )
690 aSize.setHeight( nCalcLines * mnWinHeight );
691 else
692 aSize.setHeight( nCalcLines * mnMaxItemHeight );
694 if ( mbLineSpacing )
695 aSize.AdjustHeight((nCalcLines-1)*TB_LINESPACING );
697 if ( mnWinStyle & WB_BORDER )
698 aSize.AdjustHeight((TB_BORDER_OFFSET2*2) + nTop + nBottom );
700 nMax = 0;
701 ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, mbHorz );
702 if ( nMax )
703 aSize.AdjustWidth(nMax );
705 if ( mnWinStyle & WB_BORDER )
706 aSize.AdjustWidth((TB_BORDER_OFFSET1*2) + nLeft + nRight );
708 else
710 aSize.setWidth( nCalcLines * mnMaxItemWidth );
712 if ( mbLineSpacing )
713 aSize.AdjustWidth((nCalcLines-1)*TB_LINESPACING );
715 if ( mnWinStyle & WB_BORDER )
716 aSize.AdjustWidth((TB_BORDER_OFFSET2*2) + nLeft + nRight );
718 nMax = 0;
719 ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, mbHorz );
720 if ( nMax )
721 aSize.AdjustHeight(nMax );
723 if ( mnWinStyle & WB_BORDER )
724 aSize.AdjustHeight((TB_BORDER_OFFSET1*2) + nTop + nBottom );
727 // restore previous values
728 if ( nCalcMode )
730 mpData->mbAssumeDocked = bOldAssumeDocked;
731 mpData->mbAssumeFloating = bOldAssumeFloating;
732 if ( (meAlign != eOldAlign) || (mbHorz != bOldHorz) )
734 meAlign = eOldAlign;
735 mbHorz = bOldHorz;
736 mbCalc = true;
740 return aSize;
743 void ToolBox::ImplCalcFloatSizes()
745 if ( !maFloatSizes.empty() )
746 return;
748 // calculate the minimal size, i.e. where the biggest item just fits
749 long nCalcSize = 0;
751 for (auto const& item : mpData->m_aItems)
753 if ( item.mbVisible )
755 if ( item.mpWindow )
757 long nTempSize = item.mpWindow->GetSizePixel().Width();
758 if ( nTempSize > nCalcSize )
759 nCalcSize = nTempSize;
761 else
763 if( item.maItemSize.Width() > nCalcSize )
764 nCalcSize = item.maItemSize.Width();
769 // calc an upper bound for ImplCalcBreaks below
770 long upperBoundWidth = nCalcSize * mpData->m_aItems.size();
772 ImplToolItems::size_type nLines;
773 ImplToolItems::size_type nCalcLines;
774 ImplToolItems::size_type nTempLines;
775 long nMaxLineWidth;
776 nCalcLines = ImplCalcBreaks( nCalcSize, &nMaxLineWidth, true );
778 maFloatSizes.reserve( nCalcLines );
780 nTempLines = nLines = nCalcLines;
781 while ( nLines )
783 long nHeight = ImplCalcSize( nTempLines, TB_CALCMODE_FLOAT ).Height();
785 ImplToolSize aSize;
786 aSize.mnWidth = nMaxLineWidth+(TB_BORDER_OFFSET1*2);
787 aSize.mnHeight = nHeight;
788 aSize.mnLines = nTempLines;
789 maFloatSizes.push_back( aSize );
790 nLines--;
791 if ( nLines )
795 nCalcSize += mnMaxItemWidth;
796 nTempLines = ImplCalcBreaks( nCalcSize, &nMaxLineWidth, true );
798 while ((nCalcSize < upperBoundWidth) && (nLines < nTempLines)); // implies nTempLines>1
799 if ( nTempLines < nLines )
800 nLines = nTempLines;
805 Size ToolBox::ImplCalcFloatSize( ImplToolItems::size_type& rLines )
807 ImplCalcFloatSizes();
809 if ( !rLines )
811 rLines = mnFloatLines;
812 if ( !rLines )
813 rLines = mnLines;
816 sal_uInt16 i = 0;
817 while ( i + 1u < maFloatSizes.size() && rLines < maFloatSizes[i].mnLines )
819 i++;
822 Size aSize( maFloatSizes[i].mnWidth, maFloatSizes[i].mnHeight );
823 rLines = maFloatSizes[i].mnLines;
825 return aSize;
828 void ToolBox::ImplCalcMinMaxFloatSize( Size& rMinSize, Size& rMaxSize )
830 ImplCalcFloatSizes();
832 sal_uInt16 i = 0;
833 rMinSize = Size( maFloatSizes[i].mnWidth, maFloatSizes[i].mnHeight );
834 rMaxSize = Size( maFloatSizes[i].mnWidth, maFloatSizes[i].mnHeight );
835 while ( ++i < maFloatSizes.size() )
837 if( maFloatSizes[i].mnWidth < rMinSize.Width() )
838 rMinSize.setWidth( maFloatSizes[i].mnWidth );
839 if( maFloatSizes[i].mnHeight < rMinSize.Height() )
840 rMinSize.setHeight( maFloatSizes[i].mnHeight );
842 if( maFloatSizes[i].mnWidth > rMaxSize.Width() )
843 rMaxSize.setWidth( maFloatSizes[i].mnWidth );
844 if( maFloatSizes[i].mnHeight > rMaxSize.Height() )
845 rMaxSize.setHeight( maFloatSizes[i].mnHeight );
849 void ToolBox::ImplSetMinMaxFloatSize()
851 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
852 Size aMinSize, aMaxSize;
853 ImplCalcMinMaxFloatSize( aMinSize, aMaxSize );
854 if( pWrapper )
856 pWrapper->SetMinOutputSizePixel( aMinSize );
857 pWrapper->SetMaxOutputSizePixel( aMaxSize );
858 pWrapper->ShowTitleButton( TitleButton::Menu, bool( GetMenuType() & ToolBoxMenuType::Customize) );
860 else
862 // TODO: change SetMinOutputSizePixel to be not inline
863 SetMinOutputSizePixel( aMinSize );
864 SetMaxOutputSizePixel( aMaxSize );
868 ToolBox::ImplToolItems::size_type ToolBox::ImplCalcLines( long nToolSize ) const
870 long nLineHeight;
872 if ( mbHorz )
874 if ( mnWinHeight > mnMaxItemHeight )
875 nLineHeight = mnWinHeight;
876 else
877 nLineHeight = mnMaxItemHeight;
879 else
880 nLineHeight = mnMaxItemWidth;
882 if ( mnWinStyle & WB_BORDER )
883 nToolSize -= TB_BORDER_OFFSET2*2;
885 if ( mbLineSpacing )
887 nLineHeight += TB_LINESPACING;
888 nToolSize += TB_LINESPACING;
891 // #i91917# always report at least one line
892 long nLines = nToolSize/nLineHeight;
893 if( nLines < 1 )
894 nLines = 1;
896 return nLines;
899 sal_uInt16 ToolBox::ImplTestLineSize( const Point& rPos ) const
901 if ( !ImplIsFloatingMode() &&
902 (!mbScroll || (mnLines > 1) || (mnCurLines > mnVisLines)) )
904 WindowAlign eAlign = GetAlign();
906 if ( eAlign == WindowAlign::Left )
908 if ( rPos.X() > mnDX-DOCK_LINEOFFSET )
909 return DOCK_LINEHSIZE | DOCK_LINERIGHT;
911 else if ( eAlign == WindowAlign::Top )
913 if ( rPos.Y() > mnDY-DOCK_LINEOFFSET )
914 return DOCK_LINEVSIZE | DOCK_LINEBOTTOM;
916 else if ( eAlign == WindowAlign::Right )
918 if ( rPos.X() < DOCK_LINEOFFSET )
919 return DOCK_LINEHSIZE | DOCK_LINELEFT;
921 else if ( eAlign == WindowAlign::Bottom )
923 if ( rPos.Y() < DOCK_LINEOFFSET )
924 return DOCK_LINEVSIZE | DOCK_LINETOP;
928 return 0;
931 void ToolBox::ImplLineSizing( const Point& rPos, tools::Rectangle& rRect, sal_uInt16 nLineMode )
933 bool bHorz;
934 long nOneLineSize;
935 long nCurSize;
936 long nMaxSize;
937 long nSize;
938 Size aSize;
940 if ( nLineMode & DOCK_LINERIGHT )
942 nCurSize = rPos.X() - rRect.Left();
943 bHorz = false;
945 else if ( nLineMode & DOCK_LINEBOTTOM )
947 nCurSize = rPos.Y() - rRect.Top();
948 bHorz = true;
950 else if ( nLineMode & DOCK_LINELEFT )
952 nCurSize = rRect.Right() - rPos.X();
953 bHorz = false;
955 else if ( nLineMode & DOCK_LINETOP )
957 nCurSize = rRect.Bottom() - rPos.Y();
958 bHorz = true;
960 else {
961 OSL_FAIL( "ImplLineSizing: Trailing else" );
962 nCurSize = 0;
963 bHorz = false;
966 Size aWinSize = GetSizePixel();
967 ImplToolItems::size_type nMaxLines = std::max(mnLines, mnCurLines);
968 if ( nMaxLines > TB_MAXLINES )
969 nMaxLines = TB_MAXLINES;
970 if ( bHorz )
972 nOneLineSize = ImplCalcSize( 1 ).Height();
973 nMaxSize = - 20;
974 if ( nMaxSize < aWinSize.Height() )
975 nMaxSize = aWinSize.Height();
977 else
979 nOneLineSize = ImplCalcSize( 1 ).Width();
980 nMaxSize = - 20;
981 if ( nMaxSize < aWinSize.Width() )
982 nMaxSize = aWinSize.Width();
985 ImplToolItems::size_type i = 1;
986 if ( nCurSize <= nOneLineSize )
987 nSize = nOneLineSize;
988 else
990 nSize = 0;
991 while ( (nSize < nCurSize) && (i < nMaxLines) )
993 i++;
994 aSize = ImplCalcSize( i );
995 if ( bHorz )
996 nSize = aSize.Height();
997 else
998 nSize = aSize.Width();
999 if ( nSize > nMaxSize )
1001 i--;
1002 aSize = ImplCalcSize( i );
1003 if ( bHorz )
1004 nSize = aSize.Height();
1005 else
1006 nSize = aSize.Width();
1007 break;
1012 if ( nLineMode & DOCK_LINERIGHT )
1013 rRect.SetRight( rRect.Left()+nSize-1 );
1014 else if ( nLineMode & DOCK_LINEBOTTOM )
1015 rRect.SetBottom( rRect.Top()+nSize-1 );
1016 else if ( nLineMode & DOCK_LINELEFT )
1017 rRect.SetLeft( rRect.Right()-nSize );
1018 else
1019 rRect.SetTop( rRect.Bottom()-nSize );
1021 mnDockLines = i;
1024 ImplTBDragMgr::ImplTBDragMgr()
1025 : mpDragBox(nullptr)
1026 , mnLineMode(0)
1027 , mnStartLines(0)
1029 maAccel.InsertItem( KEY_RETURN, vcl::KeyCode( KEY_RETURN ) );
1030 maAccel.InsertItem( KEY_ESCAPE, vcl::KeyCode( KEY_ESCAPE ) );
1031 maAccel.SetSelectHdl( LINK( this, ImplTBDragMgr, SelectHdl ) );
1034 void ImplTBDragMgr::StartDragging( ToolBox* pToolBox,
1035 const Point& rPos, const tools::Rectangle& rRect,
1036 sal_uInt16 nDragLineMode )
1038 mpDragBox = pToolBox;
1039 pToolBox->CaptureMouse();
1040 pToolBox->mbDragging = true;
1041 Application::InsertAccel( &maAccel );
1043 mnLineMode = nDragLineMode;
1044 mnStartLines = pToolBox->mnDockLines;
1046 // calculate MouseOffset
1047 maMouseOff.setX( rRect.Left() - rPos.X() );
1048 maMouseOff.setY( rRect.Top() - rPos.Y() );
1049 maRect = rRect;
1050 maStartRect = rRect;
1051 pToolBox->ShowTracking( maRect );
1054 void ImplTBDragMgr::Dragging( const Point& rPos )
1056 mpDragBox->ImplLineSizing( rPos, maRect, mnLineMode );
1057 Point aOff = mpDragBox->OutputToScreenPixel( Point() );
1058 maRect.Move( aOff.X(), aOff.Y() );
1059 mpDragBox->Docking( rPos, maRect );
1060 maRect.Move( -aOff.X(), -aOff.Y() );
1061 mpDragBox->ShowTracking( maRect );
1064 void ImplTBDragMgr::EndDragging( bool bOK )
1066 mpDragBox->HideTracking();
1067 if (mpDragBox->IsMouseCaptured())
1068 mpDragBox->ReleaseMouse();
1069 mpDragBox->mbDragging = false;
1070 Application::RemoveAccel( &maAccel );
1072 if ( !bOK )
1074 mpDragBox->mnDockLines = mnStartLines;
1075 mpDragBox->EndDocking( maStartRect, false );
1077 else
1078 mpDragBox->EndDocking( maRect, false );
1079 mnStartLines = 0;
1081 mpDragBox = nullptr;
1084 IMPL_LINK( ImplTBDragMgr, SelectHdl, Accelerator&, rAccel, void )
1086 if ( rAccel.GetCurItemId() == KEY_ESCAPE )
1087 EndDragging( false );
1088 else
1089 EndDragging();
1092 void ToolBox::ImplInitToolBoxData()
1094 // initialize variables
1095 ImplGetWindowImpl()->mbToolBox = true;
1096 mpData.reset(new ImplToolBoxPrivateData);
1098 mpFloatWin = nullptr;
1099 mnDX = 0;
1100 mnDY = 0;
1101 mnMaxItemWidth = 0;
1102 mnMaxItemHeight = 0;
1103 mnWinHeight = 0;
1104 mnLeftBorder = 0;
1105 mnTopBorder = 0;
1106 mnRightBorder = 0;
1107 mnBottomBorder = 0;
1108 mnLastResizeDY = 0;
1109 mnOutStyle = TOOLBOX_STYLE_FLAT; // force flat buttons since NWF
1110 mnHighItemId = 0;
1111 mnCurItemId = 0;
1112 mnDownItemId = 0;
1113 mnCurPos = ITEM_NOTFOUND;
1114 mnLines = 1;
1115 mnCurLine = 1;
1116 mnCurLines = 1;
1117 mnVisLines = 1;
1118 mnFloatLines = 0;
1119 mnDockLines = 0;
1120 mnMouseModifier = 0;
1121 mbDrag = false;
1122 mbSelection = false;
1123 mbUpper = false;
1124 mbLower = false;
1125 mbIn = false;
1126 mbCalc = true;
1127 mbFormat = false;
1128 mbFullPaint = false;
1129 mbHorz = true;
1130 mbScroll = false;
1131 mbLastFloatMode = false;
1132 mbCustomize = false;
1133 mbDragging = false;
1134 mbIsKeyEvent = false;
1135 mbChangingHighlight = false;
1136 mbImagesMirrored = false;
1137 mbLineSpacing = false;
1138 mbIsArranged = false;
1139 meButtonType = ButtonType::SYMBOLONLY;
1140 meAlign = WindowAlign::Top;
1141 meDockAlign = WindowAlign::Top;
1142 meLastStyle = PointerStyle::Arrow;
1143 mnWinStyle = 0;
1144 meLayoutMode = ToolBoxLayoutMode::Normal;
1145 meTextPosition = ToolBoxTextPosition::Right;
1146 mnLastFocusItemId = 0;
1147 mnActivateCount = 0;
1148 mnImagesRotationAngle = 0;
1150 mpStatusListener = new VclStatusListener<ToolBox>(this, ".uno:ImageOrientation");
1151 mpStatusListener->startListening();
1153 mpIdle.reset(new Idle("vcl::ToolBox maIdle update"));
1154 mpIdle->SetPriority( TaskPriority::RESIZE );
1155 mpIdle->SetInvokeHandler( LINK( this, ToolBox, ImplUpdateHdl ) );
1157 // set timeout and handler for dropdown items
1158 mpData->maDropdownTimer.SetTimeout( 250 );
1159 mpData->maDropdownTimer.SetInvokeHandler( LINK( this, ToolBox, ImplDropdownLongClickHdl ) );
1160 mpData->maDropdownTimer.SetDebugName( "vcl::ToolBox mpData->maDropdownTimer" );
1163 void ToolBox::ImplInit( vcl::Window* pParent, WinBits nStyle )
1165 // initialize variables
1166 mbScroll = (nStyle & WB_SCROLL) != 0;
1167 mnWinStyle = nStyle;
1169 DockingWindow::ImplInit( pParent, nStyle & ~WB_BORDER );
1171 // dockingwindow's ImplInit removes some bits, so restore them here to allow keyboard handling for toolbars
1172 ImplGetWindowImpl()->mnStyle |= WB_TABSTOP|WB_NODIALOGCONTROL; // always set WB_TABSTOP for ToolBars
1173 ImplGetWindowImpl()->mnStyle &= ~WB_DIALOGCONTROL;
1175 ImplInitSettings(true, true, true);
1178 void ToolBox::ApplyForegroundSettings(vcl::RenderContext& rRenderContext, const StyleSettings& rStyleSettings)
1180 Color aColor;
1181 if (IsControlForeground())
1182 aColor = GetControlForeground();
1183 else if (Window::GetStyle() & WB_3DLOOK)
1184 aColor = rStyleSettings.GetButtonTextColor();
1185 else
1186 aColor = rStyleSettings.GetWindowTextColor();
1187 rRenderContext.SetTextColor(aColor);
1188 rRenderContext.SetTextFillColor();
1191 void ToolBox::ApplyBackgroundSettings(vcl::RenderContext& rRenderContext, const StyleSettings& rStyleSettings)
1193 if (IsControlBackground())
1195 rRenderContext.SetBackground(GetControlBackground());
1196 SetPaintTransparent(false);
1197 SetParentClipMode();
1199 else
1201 if (rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ControlPart::Entire)
1202 || (GetAlign() == WindowAlign::Top && !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty())
1203 || (GetAlign() == WindowAlign::Bottom && !Application::GetSettings().GetStyleSettings().GetPersonaFooter().IsEmpty()))
1205 rRenderContext.SetBackground();
1206 rRenderContext.SetTextColor(rStyleSettings.GetToolTextColor());
1207 SetPaintTransparent(true);
1208 SetParentClipMode(ParentClipMode::NoClip);
1209 mpData->maDisplayBackground = Wallpaper(rStyleSettings.GetFaceColor());
1211 else
1213 Color aColor;
1214 if (Window::GetStyle() & WB_3DLOOK)
1215 aColor = rStyleSettings.GetFaceColor();
1216 else
1217 aColor = rStyleSettings.GetWindowColor();
1218 rRenderContext.SetBackground(aColor);
1219 SetPaintTransparent(false);
1220 SetParentClipMode();
1225 void ToolBox::ApplySettings(vcl::RenderContext& rRenderContext)
1227 mpData->mbNativeButtons = rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ControlPart::Button);
1229 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
1231 ApplyControlFont(rRenderContext, rStyleSettings.GetToolFont());
1232 ApplyForegroundSettings(rRenderContext, rStyleSettings);
1233 ApplyBackgroundSettings(rRenderContext, rStyleSettings);
1236 void ToolBox::ImplInitSettings(bool bFont, bool bForeground, bool bBackground)
1238 mpData->mbNativeButtons = IsNativeControlSupported( ControlType::Toolbar, ControlPart::Button );
1240 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1242 if (bFont)
1243 ApplyControlFont(*this, rStyleSettings.GetToolFont());
1244 if (bForeground || bFont)
1245 ApplyForegroundSettings(*this, rStyleSettings);
1246 if (bBackground)
1248 ApplyBackgroundSettings(*this, rStyleSettings);
1249 EnableChildTransparentMode(IsPaintTransparent());
1253 void ToolBox::doDeferredInit(WinBits nBits)
1255 VclPtr<vcl::Window> pParent = mpDialogParent;
1256 mpDialogParent = nullptr;
1257 ImplInit(pParent, nBits);
1258 mbIsDeferredInit = false;
1261 void ToolBox::queue_resize(StateChangedType eReason)
1263 Window::queue_resize(eReason);
1266 ToolBox::ToolBox( vcl::Window* pParent, WinBits nStyle ) :
1267 DockingWindow( WindowType::TOOLBOX )
1269 ImplInitToolBoxData();
1270 ImplInit( pParent, nStyle );
1273 ToolBox::ToolBox(vcl::Window* pParent, const OString& rID,
1274 const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame> &rFrame)
1275 : DockingWindow(WindowType::TOOLBOX)
1277 ImplInitToolBoxData();
1279 loadUI(pParent, rID, rUIXMLDescription, rFrame);
1281 // calculate size of floating windows and switch if the
1282 // toolbox is initially in floating mode
1283 if ( ImplIsFloatingMode() )
1284 mbHorz = true;
1285 else
1286 Resize();
1288 if (!(GetStyle() & WB_HIDE))
1289 Show();
1292 ToolBox::~ToolBox()
1294 disposeOnce();
1297 void ToolBox::dispose()
1299 // #103005# make sure our activate/deactivate balance is right
1300 while( mnActivateCount > 0 )
1301 Deactivate();
1303 // terminate popupmode if the floating window is
1304 // still connected
1305 if ( mpFloatWin )
1306 mpFloatWin->EndPopupMode( FloatWinPopupEndFlags::Cancel );
1307 mpFloatWin = nullptr;
1309 // delete private data
1310 mpData.reset();
1312 ImplSVData* pSVData = ImplGetSVData();
1313 delete pSVData->maCtrlData.mpTBDragMgr;
1314 pSVData->maCtrlData.mpTBDragMgr = nullptr;
1316 if (mpStatusListener.is())
1317 mpStatusListener->dispose();
1319 mpFloatWin.clear();
1321 mpIdle.reset();
1323 DockingWindow::dispose();
1326 ImplToolItem* ToolBox::ImplGetItem( sal_uInt16 nItemId ) const
1328 if (!mpData)
1329 return nullptr;
1331 for (auto & item : mpData->m_aItems)
1333 if ( item.mnId == nItemId )
1334 return &item;
1337 return nullptr;
1340 static void ImplAddButtonBorder( long &rWidth, long& rHeight, bool bNativeButtons )
1342 rWidth += SMALLBUTTON_HSIZE;
1343 rHeight += SMALLBUTTON_VSIZE;
1345 if( bNativeButtons )
1347 // give more border space for rounded buttons
1348 rWidth += 2;
1349 rHeight += 4;
1353 bool ToolBox::ImplCalcItem()
1356 // recalc required ?
1357 if ( !mbCalc )
1358 return false;
1360 ImplDisableFlatButtons();
1362 long nDefWidth;
1363 long nDefHeight;
1364 long nMaxWidth = 0;
1365 long nMaxHeight = 0;
1366 long nMinWidth = 6;
1367 long nMinHeight = 6;
1368 long nDropDownArrowWidth = TB_DROPDOWNARROWWIDTH;
1369 #ifdef IOS
1370 nDropDownArrowWidth *= 3;
1371 #endif
1373 // set defaults if image or text is needed but empty
1374 nDefWidth = GetDefaultImageSize().Width();
1375 nDefHeight = GetDefaultImageSize().Height();
1377 mnWinHeight = 0;
1378 // determine minimum size necessary in NWF
1380 tools::Rectangle aRect( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1381 tools::Rectangle aReg( aRect );
1382 ImplControlValue aVal;
1383 tools::Rectangle aNativeBounds, aNativeContent;
1384 if( IsNativeControlSupported( ControlType::Toolbar, ControlPart::Button ) )
1386 if( GetNativeControlRegion( ControlType::Toolbar, ControlPart::Button,
1387 aReg,
1388 ControlState::ENABLED | ControlState::ROLLOVER,
1389 aVal,
1390 aNativeBounds, aNativeContent ) )
1392 aRect = aNativeBounds;
1393 if( aRect.GetWidth() > nMinWidth )
1394 nMinWidth = aRect.GetWidth();
1395 if( aRect.GetHeight() > nMinHeight )
1396 nMinHeight = aRect.GetHeight();
1397 if( nDropDownArrowWidth < nMinWidth )
1398 nDropDownArrowWidth = nMinWidth;
1399 if( nMinWidth > mpData->mnMenuButtonWidth )
1400 mpData->mnMenuButtonWidth = nMinWidth;
1401 else if( nMinWidth < TB_MENUBUTTON_SIZE )
1402 mpData->mnMenuButtonWidth = TB_MENUBUTTON_SIZE;
1406 // also calculate the area for comboboxes, drop down list boxes and spinfields
1407 // as these are often inserted into toolboxes; set mnWinHeight to the
1408 // greater of those values to prevent toolbar flickering (#i103385#)
1409 aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1410 aReg = aRect;
1411 if( GetNativeControlRegion( ControlType::Combobox, ControlPart::Entire,
1412 aReg,
1413 ControlState::ENABLED | ControlState::ROLLOVER,
1414 aVal,
1415 aNativeBounds, aNativeContent ) )
1417 aRect = aNativeBounds;
1418 if( aRect.GetHeight() > mnWinHeight )
1419 mnWinHeight = aRect.GetHeight();
1421 aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1422 aReg = aRect;
1423 if( GetNativeControlRegion( ControlType::Listbox, ControlPart::Entire,
1424 aReg,
1425 ControlState::ENABLED | ControlState::ROLLOVER,
1426 aVal,
1427 aNativeBounds, aNativeContent ) )
1429 aRect = aNativeBounds;
1430 if( aRect.GetHeight() > mnWinHeight )
1431 mnWinHeight = aRect.GetHeight();
1433 aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1434 aReg = aRect;
1435 if( GetNativeControlRegion( ControlType::Spinbox, ControlPart::Entire,
1436 aReg,
1437 ControlState::ENABLED | ControlState::ROLLOVER,
1438 aVal,
1439 aNativeBounds, aNativeContent ) )
1441 aRect = aNativeBounds;
1442 if( aRect.GetHeight() > mnWinHeight )
1443 mnWinHeight = aRect.GetHeight();
1447 if ( ! mpData->m_aItems.empty() )
1449 for (auto & item : mpData->m_aItems)
1451 item.mbVisibleText = false; // indicates if text will definitely be drawn, influences dropdown pos
1453 if ( item.meType == ToolBoxItemType::BUTTON )
1455 bool bImage;
1456 bool bText;
1458 // check if image and/or text exists
1459 bImage = !!item.maImage;
1460 bText = !item.maText.isEmpty();
1461 ButtonType tmpButtonType = determineButtonType( &item, meButtonType ); // default to toolbox setting
1462 if ( bImage || bText )
1465 item.mbEmptyBtn = false;
1467 if ( tmpButtonType == ButtonType::SYMBOLONLY )
1469 // we're drawing images only
1470 if ( bImage || !bText )
1472 item.maItemSize = item.maImage.GetSizePixel();
1474 else
1476 item.maItemSize = Size( GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET,
1477 GetTextHeight() );
1478 item.mbVisibleText = true;
1481 else if ( tmpButtonType == ButtonType::TEXT )
1483 // we're drawing text only
1484 if ( bText || !bImage )
1486 item.maItemSize = Size( GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET,
1487 GetTextHeight() );
1488 item.mbVisibleText = true;
1490 else
1492 item.maItemSize = item.maImage.GetSizePixel();
1495 else
1497 // we're drawing images and text
1498 item.maItemSize.setWidth( bText ? GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET : 0 );
1499 item.maItemSize.setHeight( bText ? GetTextHeight() : 0 );
1501 if ( meTextPosition == ToolBoxTextPosition::Right )
1503 // leave space between image and text
1504 if( bText )
1505 item.maItemSize.AdjustWidth(TB_IMAGETEXTOFFSET );
1507 // image and text side by side
1508 item.maItemSize.AdjustWidth(item.maImage.GetSizePixel().Width() );
1509 if ( item.maImage.GetSizePixel().Height() > item.maItemSize.Height() )
1510 item.maItemSize.setHeight( item.maImage.GetSizePixel().Height() );
1512 else
1514 // leave space between image and text
1515 if( bText )
1516 item.maItemSize.AdjustHeight(TB_IMAGETEXTOFFSET );
1518 // text below image
1519 item.maItemSize.AdjustHeight(item.maImage.GetSizePixel().Height() );
1520 if ( item.maImage.GetSizePixel().Width() > item.maItemSize.Width() )
1521 item.maItemSize.setWidth( item.maImage.GetSizePixel().Width() );
1524 item.mbVisibleText = bText;
1527 else
1528 { // no image and no text
1529 item.maItemSize = Size( nDefWidth, nDefHeight );
1530 item.mbEmptyBtn = true;
1533 // save the content size
1534 item.maContentSize = item.maItemSize;
1536 // if required, take window height into consideration
1537 if ( item.mpWindow )
1539 long nHeight = item.mpWindow->GetSizePixel().Height();
1540 if ( nHeight > mnWinHeight )
1541 mnWinHeight = nHeight;
1544 // add in drop down arrow
1545 if( item.mnBits & ToolBoxItemBits::DROPDOWN )
1547 item.maItemSize.AdjustWidth(nDropDownArrowWidth );
1548 item.mnDropDownArrowWidth = nDropDownArrowWidth;
1551 // text items will be rotated in vertical mode
1552 // -> swap width and height
1553 if( item.mbVisibleText && !mbHorz )
1555 long tmp = item.maItemSize.Width();
1556 item.maItemSize.setWidth( item.maItemSize.Height() );
1557 item.maItemSize.setHeight( tmp );
1559 tmp = item.maContentSize.Width();
1560 item.maContentSize.setWidth( item.maContentSize.Height() );
1561 item.maContentSize.setHeight( tmp );
1564 else if ( item.meType == ToolBoxItemType::SPACE )
1566 item.maItemSize = Size( nDefWidth, nDefHeight );
1567 item.maContentSize = item.maItemSize;
1570 if ( item.meType == ToolBoxItemType::BUTTON || item.meType == ToolBoxItemType::SPACE )
1572 // add borders
1573 long w = item.maItemSize.Width();
1574 long h = item.maItemSize.Height();
1575 ImplAddButtonBorder( w, h, mpData->mbNativeButtons );
1576 item.maItemSize.setWidth(w);
1577 item.maItemSize.setHeight(h);
1579 if( item.meType == ToolBoxItemType::BUTTON )
1581 long nMinW = std::max(nMinWidth, item.maMinimalItemSize.Width());
1582 long nMinH = std::max(nMinHeight, item.maMinimalItemSize.Height());
1584 long nGrowContentWidth = 0;
1585 long nGrowContentHeight = 0;
1587 if( item.maItemSize.Width() < nMinW )
1589 nGrowContentWidth = nMinW - item.maItemSize.Width();
1590 item.maItemSize.setWidth( nMinW );
1592 if( item.maItemSize.Height() < nMinH )
1594 nGrowContentHeight = nMinH - item.maItemSize.Height();
1595 item.maItemSize.setHeight( nMinH );
1598 // grow the content size by the additional available space
1599 item.maContentSize.AdjustWidth(nGrowContentWidth );
1600 item.maContentSize.AdjustHeight(nGrowContentHeight );
1603 // keep track of max item size
1604 if ( item.maItemSize.Width() > nMaxWidth )
1605 nMaxWidth = item.maItemSize.Width();
1606 if ( item.maItemSize.Height() > nMaxHeight )
1607 nMaxHeight = item.maItemSize.Height();
1611 else
1613 nMaxWidth = nDefWidth;
1614 nMaxHeight = nDefHeight;
1616 ImplAddButtonBorder( nMaxWidth, nMaxHeight, mpData->mbNativeButtons );
1619 if( !ImplIsFloatingMode() && GetToolboxButtonSize() != ToolBoxButtonSize::DontCare
1620 && ( meTextPosition == ToolBoxTextPosition::Right ) )
1622 // make sure all vertical toolbars have the same width and horizontal have the same height
1623 // this depends on the used button sizes
1624 // as this is used for alignment of multiple toolbars
1625 // it is only required for docked toolbars
1627 long nFixedWidth = nDefWidth+nDropDownArrowWidth;
1628 long nFixedHeight = nDefHeight;
1629 ImplAddButtonBorder( nFixedWidth, nFixedHeight, mpData->mbNativeButtons );
1631 if( mbHorz )
1632 nMaxHeight = nFixedHeight;
1633 else
1634 nMaxWidth = nFixedWidth;
1637 mbCalc = false;
1638 mbFormat = true;
1640 // do we have to recalc the sizes ?
1641 if ( (nMaxWidth != mnMaxItemWidth) || (nMaxHeight != mnMaxItemHeight) )
1643 mnMaxItemWidth = nMaxWidth;
1644 mnMaxItemHeight = nMaxHeight;
1646 return true;
1648 else
1649 return false;
1652 ToolBox::ImplToolItems::size_type ToolBox::ImplCalcBreaks( long nWidth, long* pMaxLineWidth, bool bCalcHorz ) const
1654 sal_uLong nLineStart = 0;
1655 sal_uLong nGroupStart = 0;
1656 long nLineWidth = 0;
1657 long nCurWidth;
1658 long nLastGroupLineWidth = 0;
1659 long nMaxLineWidth = 0;
1660 ImplToolItems::size_type nLines = 1;
1661 bool bWindow;
1662 bool bBreak = false;
1663 long nWidthTotal = nWidth;
1664 long nMenuWidth = 0;
1666 // when docked the menubutton will be in the first line
1667 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1668 nMenuWidth = mpData->maMenubuttonItem.maItemSize.Width();
1670 // we need to know which item is the last visible one to be able to add
1671 // the menu width in case we are unable to show all the items
1672 ImplToolItems::iterator it, lastVisible;
1673 for ( it = mpData->m_aItems.begin(); it != mpData->m_aItems.end(); ++it )
1675 if ( it->mbVisible )
1676 lastVisible = it;
1679 it = mpData->m_aItems.begin();
1680 while ( it != mpData->m_aItems.end() )
1682 it->mbBreak = bBreak;
1683 bBreak = false;
1685 if ( it->mbVisible )
1687 bWindow = false;
1688 bBreak = false;
1689 nCurWidth = 0;
1691 if ( it->meType == ToolBoxItemType::BUTTON || it->meType == ToolBoxItemType::SPACE )
1693 if ( bCalcHorz )
1694 nCurWidth = it->maItemSize.Width();
1695 else
1696 nCurWidth = it->maItemSize.Height();
1698 if ( it->mpWindow && bCalcHorz )
1700 long nWinItemWidth = it->mpWindow->GetSizePixel().Width();
1701 if ( !mbScroll || (nWinItemWidth <= nWidthTotal) )
1703 nCurWidth = nWinItemWidth;
1704 bWindow = true;
1706 else
1708 if ( it->mbEmptyBtn )
1710 nCurWidth = 0;
1715 // in case we are able to show all the items, we do not want
1716 // to show the toolbar's menu; otherwise yes
1717 if ( ( ( it == lastVisible ) && (nLineWidth+nCurWidth > nWidthTotal) && mbScroll ) ||
1718 ( ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) && mbScroll ) )
1719 bBreak = true;
1721 else if ( it->meType == ToolBoxItemType::SEPARATOR )
1723 nCurWidth = it->mnSepSize;
1724 if ( !ImplIsFloatingMode() && ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) )
1725 bBreak = true;
1727 // treat breaks as separators, except when using old style toolbars (ie. no menu button)
1728 else if ( (it->meType == ToolBoxItemType::BREAK) && !IsMenuEnabled() )
1729 bBreak = true;
1731 if ( bBreak )
1733 nLines++;
1735 // Add break before the entire group or take group apart?
1736 if ( (it->meType == ToolBoxItemType::BREAK) ||
1737 (nLineStart == nGroupStart) )
1739 if ( nLineWidth > nMaxLineWidth )
1740 nMaxLineWidth = nLineWidth;
1742 nLineWidth = 0;
1743 nLineStart = it - mpData->m_aItems.begin();
1744 nGroupStart = nLineStart;
1745 it->mbBreak = true;
1746 bBreak = false;
1748 else
1750 if ( nLastGroupLineWidth > nMaxLineWidth )
1751 nMaxLineWidth = nLastGroupLineWidth;
1753 // if the break is added before the group, set it to
1754 // beginning of line and re-calculate
1755 nLineWidth = 0;
1756 nLineStart = nGroupStart;
1757 it = mpData->m_aItems.begin() + nGroupStart;
1758 continue;
1761 else
1763 if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
1765 if ( (it->meType != ToolBoxItemType::BUTTON) || bWindow )
1767 // found separator or break
1768 nLastGroupLineWidth = nLineWidth;
1769 nGroupStart = it - mpData->m_aItems.begin();
1770 if ( !bWindow )
1771 nGroupStart++;
1776 nLineWidth += nCurWidth;
1779 ++it;
1782 if ( pMaxLineWidth )
1784 if ( nLineWidth > nMaxLineWidth )
1785 nMaxLineWidth = nLineWidth;
1787 if( ImplIsFloatingMode() && !ImplIsInPopupMode() )
1789 // leave enough space to display buttons in the decoration
1790 long aMinWidth = 2 * GetSettings().GetStyleSettings().GetFloatTitleHeight();
1791 if( nMaxLineWidth < aMinWidth )
1792 nMaxLineWidth = aMinWidth;
1794 *pMaxLineWidth = nMaxLineWidth;
1797 return nLines;
1800 Size ToolBox::ImplGetOptimalFloatingSize()
1802 if( !ImplIsFloatingMode() )
1803 return Size();
1805 Size aCurrentSize( mnDX, mnDY );
1806 Size aSize1( aCurrentSize );
1807 Size aSize2( aCurrentSize );
1809 // try to preserve current height
1811 // calc number of floating lines for current window height
1812 ImplToolItems::size_type nFloatLinesHeight = ImplCalcLines( mnDY );
1813 // calc window size according to this number
1814 aSize1 = ImplCalcFloatSize( nFloatLinesHeight );
1816 if( aCurrentSize == aSize1 )
1817 return aSize1;
1819 // try to preserve current width
1821 long nLineHeight = std::max( mnWinHeight, mnMaxItemHeight );
1822 int nBorderX = 2*TB_BORDER_OFFSET1 + mnLeftBorder + mnRightBorder;
1823 int nBorderY = 2*TB_BORDER_OFFSET2 + mnTopBorder + mnBottomBorder;
1824 Size aSz( aCurrentSize );
1825 long maxX;
1826 ImplToolItems::size_type nLines = ImplCalcBreaks( aSz.Width()-nBorderX, &maxX, mbHorz );
1828 ImplToolItems::size_type manyLines = 1000;
1829 Size aMinimalFloatSize = ImplCalcFloatSize( manyLines );
1831 aSz.setHeight( nBorderY + nLineHeight * nLines );
1832 // line space when more than one line
1833 if ( mbLineSpacing )
1834 aSz.AdjustHeight((nLines-1)*TB_LINESPACING );
1836 aSz.setWidth( nBorderX + maxX );
1838 // avoid clipping of any items
1839 if( aSz.Width() < aMinimalFloatSize.Width() )
1840 aSize2 = ImplCalcFloatSize( nLines );
1841 else
1842 aSize2 = aSz;
1844 if( aCurrentSize == aSize2 )
1845 return aSize2;
1847 // set the size with the smallest delta as the current size
1848 long dx1 = std::abs( mnDX - aSize1.Width() );
1849 long dy1 = std::abs( mnDY - aSize1.Height() );
1851 long dx2 = std::abs( mnDX - aSize2.Width() );
1852 long dy2 = std::abs( mnDY - aSize2.Height() );
1854 if( dx1*dy1 < dx2*dy2 )
1855 aCurrentSize = aSize1;
1856 else
1857 aCurrentSize = aSize2;
1859 return aCurrentSize;
1862 namespace
1864 void lcl_hideDoubleSeparators( ToolBox::ImplToolItems& rItems )
1866 bool bLastSep( true );
1867 ToolBox::ImplToolItems::iterator it;
1868 for ( it = rItems.begin(); it != rItems.end(); ++it )
1870 if ( it->meType == ToolBoxItemType::SEPARATOR )
1872 it->mbVisible = false;
1873 if ( !bLastSep )
1875 // check if any visible items have to appear behind it
1876 if (std::any_of(it + 1, rItems.end(), [](const ImplToolItem& rItem) {
1877 return (rItem.meType == ToolBoxItemType::BUTTON) && rItem.mbVisible; }))
1878 it->mbVisible = true;
1880 bLastSep = true;
1882 else if ( it->mbVisible )
1883 bLastSep = false;
1888 void ToolBox::ImplFormat( bool bResize )
1890 // Has to re-formatted
1891 if ( !mbFormat )
1892 return;
1894 mpData->ImplClearLayoutData();
1896 // recalculate positions and sizes
1897 tools::Rectangle aEmptyRect;
1898 long nLineSize;
1899 long nLeft;
1900 long nTop;
1901 long nMax; // width of layoutarea in pixels
1902 ImplToolItems::size_type nFormatLine;
1903 bool bMustFullPaint;
1905 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
1906 bool bIsInPopupMode = ImplIsInPopupMode();
1908 maFloatSizes.clear();
1910 // compute border sizes
1911 ImplCalcBorder( meAlign, mnLeftBorder, mnTopBorder, mnRightBorder, mnBottomBorder );
1913 // update drag area (where the 'grip' will be placed)
1914 tools::Rectangle aOldDragRect;
1915 if( pWrapper )
1916 aOldDragRect = pWrapper->GetDragArea();
1917 ImplUpdateDragArea();
1919 bMustFullPaint = ImplCalcItem();
1921 // calculate new size during interactive resize or
1922 // set computed size when formatting only
1923 if ( ImplIsFloatingMode() )
1925 if ( bResize )
1926 mnFloatLines = ImplCalcLines( mnDY );
1927 else
1928 SetOutputSizePixel( ImplGetOptimalFloatingSize() );
1931 // Horizontal
1932 if ( mbHorz )
1934 long nBottom;
1935 // nLineSize: height of a single line, will fit highest item
1936 nLineSize = mnMaxItemHeight;
1938 if ( mnWinHeight > mnMaxItemHeight )
1939 nLineSize = mnWinHeight;
1941 if ( mbScroll )
1943 nMax = mnDX;
1944 mnVisLines = ImplCalcLines( mnDY );
1946 else
1948 // layout over all lines
1949 mnVisLines = mnLines;
1950 nMax = TB_MAXNOSCROLL;
1953 // add in all border offsets
1954 if ( mnWinStyle & WB_BORDER )
1956 nLeft = TB_BORDER_OFFSET1 + mnLeftBorder;
1957 nTop = TB_BORDER_OFFSET2 + mnTopBorder;
1958 nBottom = TB_BORDER_OFFSET1 + mnBottomBorder;
1959 nMax -= nLeft + TB_BORDER_OFFSET1 + mnRightBorder;
1961 else
1963 nLeft = 0;
1964 nTop = 0;
1965 nBottom = 0;
1968 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
1969 // we have to center all items in the window height
1970 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1972 long nWinHeight = mnDY - nTop - nBottom;
1973 if( nWinHeight > nLineSize )
1974 nLineSize = nWinHeight;
1977 else
1979 long nRight;
1980 nLineSize = mnMaxItemWidth;
1982 if ( mbScroll )
1984 mnVisLines = ImplCalcLines( mnDX );
1985 nMax = mnDY;
1987 else
1989 mnVisLines = mnLines;
1990 nMax = TB_MAXNOSCROLL;
1993 if ( mnWinStyle & WB_BORDER )
1995 nTop = TB_BORDER_OFFSET1 + mnTopBorder;
1996 nLeft = TB_BORDER_OFFSET2 + mnLeftBorder;
1997 nRight = TB_BORDER_OFFSET2 + mnRightBorder;
1998 nMax -= nTop + TB_BORDER_OFFSET1 + mnBottomBorder;
2000 else
2002 nLeft = 0;
2003 nTop = 0;
2004 nRight = 0;
2007 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
2008 // we have to center all items in the window height
2009 if( !ImplIsFloatingMode() && IsMenuEnabled() )
2011 long nWinWidth = mnDX - nLeft - nRight;
2012 if( nWinWidth > nLineSize )
2013 nLineSize = nWinWidth;
2017 // no calculation if the window has no size (nMax=0)
2018 // non scrolling toolboxes must be computed though
2019 if ( (nMax <= 0) && mbScroll )
2021 mnVisLines = 1;
2022 mnCurLine = 1;
2023 mnCurLines = 1;
2025 for (auto & item : mpData->m_aItems)
2027 item.maRect = aEmptyRect;
2030 maLowerRect = aEmptyRect;
2031 maUpperRect = aEmptyRect;
2033 else
2035 // init start values
2036 long nX = nLeft; // top-left offset
2037 long nY = nTop;
2038 nFormatLine = 1;
2040 // save old scroll rectangles and reset them
2041 tools::Rectangle aOldLowerRect = maLowerRect;
2042 tools::Rectangle aOldUpperRect = maUpperRect;
2043 tools::Rectangle aOldMenubuttonRect = mpData->maMenubuttonItem.maRect;
2044 maUpperRect = aEmptyRect;
2045 maLowerRect = aEmptyRect;
2046 mpData->maMenubuttonItem.maRect = aEmptyRect;
2048 // do we have any toolbox items at all ?
2049 if ( !mpData->m_aItems.empty() || IsMenuEnabled() )
2051 lcl_hideDoubleSeparators( mpData->m_aItems );
2053 // compute line breaks and visible lines give the current window width (nMax)
2054 // the break indicators will be stored within each item (it->mbBreak)
2055 mnCurLines = ImplCalcBreaks( nMax, nullptr, mbHorz );
2057 // check for scrollbar buttons or dropdown menu
2058 // (if a menu is enabled, this will be used to store clipped
2059 // items and no scroll buttons will appear)
2060 if ( (!ImplIsFloatingMode() && (mnCurLines > mnVisLines) && mbScroll ) ||
2061 IsMenuEnabled() )
2063 // compute linebreaks again, incorporating scrollbar buttons
2064 if( !IsMenuEnabled() )
2066 nMax -= TB_SPIN_SIZE+TB_SPIN_OFFSET;
2067 mnCurLines = ImplCalcBreaks( nMax, nullptr, mbHorz );
2070 // compute scroll rectangles or menu button
2071 if ( mbHorz )
2073 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
2075 if( !ImplIsFloatingMode() )
2077 mpData->maMenubuttonItem.maRect.SetRight( mnDX - 2 );
2078 mpData->maMenubuttonItem.maRect.SetTop( nTop );
2079 mpData->maMenubuttonItem.maRect.SetBottom( mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1 );
2081 else
2083 mpData->maMenubuttonItem.maRect.SetRight( mnDX - mnRightBorder-TB_BORDER_OFFSET1-1 );
2084 mpData->maMenubuttonItem.maRect.SetTop( nTop );
2085 mpData->maMenubuttonItem.maRect.SetBottom( mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1 );
2087 mpData->maMenubuttonItem.maRect.SetLeft( mpData->maMenubuttonItem.maRect.Right() - mpData->mnMenuButtonWidth );
2089 else
2091 maUpperRect.SetLeft( nLeft+nMax+TB_SPIN_OFFSET );
2092 maUpperRect.SetRight( maUpperRect.Left()+TB_SPIN_SIZE-1 );
2093 maUpperRect.SetTop( nTop );
2094 maLowerRect.SetBottom( mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1 );
2095 maLowerRect.SetLeft( maUpperRect.Left() );
2096 maLowerRect.SetRight( maUpperRect.Right() );
2097 maUpperRect.SetBottom( maUpperRect.Top() +
2098 (maLowerRect.Bottom()-maUpperRect.Top())/2 );
2099 maLowerRect.SetTop( maUpperRect.Bottom() );
2102 else
2104 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
2106 if( !ImplIsFloatingMode() )
2108 mpData->maMenubuttonItem.maRect.SetBottom( mnDY - 2 );
2109 mpData->maMenubuttonItem.maRect.SetLeft( nLeft );
2110 mpData->maMenubuttonItem.maRect.SetRight( mnDX-mnRightBorder-TB_BORDER_OFFSET2-1 );
2112 else
2114 mpData->maMenubuttonItem.maRect.SetBottom( mnDY - mnBottomBorder-TB_BORDER_OFFSET1-1 );
2115 mpData->maMenubuttonItem.maRect.SetLeft( nLeft );
2116 mpData->maMenubuttonItem.maRect.SetRight( mnDX-mnRightBorder-TB_BORDER_OFFSET2-1 );
2118 mpData->maMenubuttonItem.maRect.SetTop( mpData->maMenubuttonItem.maRect.Bottom() - mpData->mnMenuButtonWidth );
2120 else
2122 maUpperRect.SetTop( nTop+nMax+TB_SPIN_OFFSET );
2123 maUpperRect.SetBottom( maUpperRect.Top()+TB_SPIN_SIZE-1 );
2124 maUpperRect.SetLeft( nLeft );
2125 maLowerRect.SetRight( mnDX-mnRightBorder-TB_BORDER_OFFSET2-1 );
2126 maLowerRect.SetTop( maUpperRect.Top() );
2127 maLowerRect.SetBottom( maUpperRect.Bottom() );
2128 maUpperRect.SetRight( maUpperRect.Left() +
2129 (maLowerRect.Right()-maUpperRect.Left())/2 );
2130 maLowerRect.SetLeft( maUpperRect.Right() );
2135 // no scrolling when there is a "more"-menu
2136 // anything will "fit" in a single line then
2137 if( IsMenuEnabled() )
2138 mnCurLines = 1;
2140 // determine the currently visible line
2141 if ( mnVisLines >= mnCurLines )
2142 mnCurLine = 1;
2143 else if ( mnCurLine+mnVisLines-1 > mnCurLines )
2144 mnCurLine = mnCurLines - (mnVisLines-1);
2146 long firstItemCenter = 0;
2147 for (auto & item : mpData->m_aItems)
2149 item.mbShowWindow = false;
2151 // check for line break and advance nX/nY accordingly
2152 if ( item.mbBreak )
2154 nFormatLine++;
2156 // increment starting with the second line
2157 if ( nFormatLine > mnCurLine )
2159 if ( mbHorz )
2161 nX = nLeft;
2162 if ( mbLineSpacing )
2163 nY += nLineSize+TB_LINESPACING;
2164 else
2165 nY += nLineSize;
2167 else
2169 nY = nTop;
2170 if ( mbLineSpacing )
2171 nX += nLineSize+TB_LINESPACING;
2172 else
2173 nX += nLineSize;
2178 if ( !item.mbVisible || (nFormatLine < mnCurLine) ||
2179 (nFormatLine > mnCurLine+mnVisLines-1) )
2180 // item is not visible
2181 item.maCalcRect = aEmptyRect;
2182 else
2184 // 1. determine current item width/height
2185 // take window size and orientation into account, because this affects the size of item windows
2187 Size aCurrentItemSize( item.GetSize( mbHorz, mbScroll, nMax, Size(mnMaxItemWidth, mnMaxItemHeight) ) );
2189 // 2. position item rect and use size from step 1
2190 // items will be centered horizontally (if mbHorz) or vertically
2191 // advance nX and nY accordingly
2193 if ( mbHorz )
2195 // In special mode Locked horizontal positions of all items remain unchanged.
2197 if ( mbIsArranged && meLayoutMode == ToolBoxLayoutMode::Locked && mnLines == 1 && item.maRect.Left() > 0 )
2198 nX = item.maRect.Left();
2199 item.maCalcRect.SetLeft( nX );
2201 // In special mode Locked first item's vertical position remains unchanged. Consecutive items vertical
2202 // positions are centered around first item's vertical position. If an item's height exceeds available
2203 // space, item's vertical position remains unchanged too.
2205 if ( mbIsArranged && meLayoutMode == ToolBoxLayoutMode::Locked && mnLines == 1 )
2206 if ( firstItemCenter > 0 )
2207 if ( firstItemCenter-aCurrentItemSize.Height()/2 > nY )
2208 item.maCalcRect.SetTop( firstItemCenter-aCurrentItemSize.Height()/2 );
2209 else
2210 item.maCalcRect.SetTop( item.maRect.Top() );
2211 else
2213 item.maCalcRect.SetTop( item.maRect.Top() );
2214 firstItemCenter = item.maRect.Top()+aCurrentItemSize.Height()/2;
2216 else
2217 item.maCalcRect.SetTop( nY+(nLineSize-aCurrentItemSize.Height())/2 );
2218 item.maCalcRect.SetRight( nX+aCurrentItemSize.Width()-1 );
2219 item.maCalcRect.SetBottom( item.maCalcRect.Top()+aCurrentItemSize.Height()-1 );
2220 nX += aCurrentItemSize.Width();
2222 else
2224 item.maCalcRect.SetLeft( nX+(nLineSize-aCurrentItemSize.Width())/2 );
2225 item.maCalcRect.SetTop( nY );
2226 item.maCalcRect.SetRight( item.maCalcRect.Left()+aCurrentItemSize.Width()-1 );
2227 item.maCalcRect.SetBottom( nY+aCurrentItemSize.Height()-1 );
2228 nY += aCurrentItemSize.Height();
2232 // position window items into calculated item rect
2233 if ( item.mpWindow )
2235 if ( item.mbShowWindow )
2237 Point aPos( item.maCalcRect.Left(), item.maCalcRect.Top() );
2239 assert( item.maCalcRect.Top() >= 0 );
2241 item.mpWindow->SetPosPixel( aPos );
2242 item.mpWindow->Show();
2244 else
2245 item.mpWindow->Hide();
2247 } // end of loop over all items
2248 mbIsArranged = true;
2250 else
2251 // we have no toolbox items
2252 mnCurLines = 1;
2254 if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
2256 // custom menu will be the last button in floating mode
2257 ImplToolItem &rIt = mpData->maMenubuttonItem;
2259 if ( mbHorz )
2261 rIt.maRect.SetLeft( nX+TB_MENUBUTTON_OFFSET );
2262 rIt.maRect.SetTop( nY );
2263 rIt.maRect.SetRight( rIt.maRect.Left() + mpData->mnMenuButtonWidth );
2264 rIt.maRect.SetBottom( nY+nLineSize-1 );
2265 nX += rIt.maItemSize.Width();
2267 else
2269 rIt.maRect.SetLeft( nX );
2270 rIt.maRect.SetTop( nY+TB_MENUBUTTON_OFFSET );
2271 rIt.maRect.SetRight( nX+nLineSize-1 );
2272 rIt.maRect.SetBottom( rIt.maRect.Top() + mpData->mnMenuButtonWidth );
2273 nY += rIt.maItemSize.Height();
2277 // if toolbox visible trigger paint for changed regions
2278 if ( IsVisible() && !mbFullPaint )
2280 if ( bMustFullPaint )
2282 maPaintRect = tools::Rectangle( mnLeftBorder, mnTopBorder,
2283 mnDX-mnRightBorder, mnDY-mnBottomBorder );
2285 else
2287 if ( aOldLowerRect != maLowerRect )
2289 maPaintRect.Union( maLowerRect );
2290 maPaintRect.Union( aOldLowerRect );
2292 if ( aOldUpperRect != maUpperRect )
2294 maPaintRect.Union( maUpperRect );
2295 maPaintRect.Union( aOldUpperRect );
2297 if ( aOldMenubuttonRect != mpData->maMenubuttonItem.maRect )
2299 maPaintRect.Union( mpData->maMenubuttonItem.maRect );
2300 maPaintRect.Union( aOldMenubuttonRect );
2302 if ( pWrapper && aOldDragRect != pWrapper->GetDragArea() )
2304 maPaintRect.Union( pWrapper->GetDragArea() );
2305 maPaintRect.Union( aOldDragRect );
2308 for (auto const& item : mpData->m_aItems)
2310 if ( item.maRect != item.maCalcRect )
2312 maPaintRect.Union( item.maRect );
2313 maPaintRect.Union( item.maCalcRect );
2318 Invalidate( maPaintRect );
2321 // store the new calculated item rects
2322 maPaintRect = aEmptyRect;
2323 for (auto & item : mpData->m_aItems)
2324 item.maRect = item.maCalcRect;
2327 // indicate formatting is done
2328 mbFormat = false;
2331 IMPL_LINK_NOARG(ToolBox, ImplDropdownLongClickHdl, Timer *, void)
2333 if (mnCurPos != ITEM_NOTFOUND &&
2334 (mpData->m_aItems[ mnCurPos ].mnBits & ToolBoxItemBits::DROPDOWN))
2336 mpData->mbDropDownByKeyboard = false;
2337 mpData->maDropdownClickHdl.Call( this );
2339 // do not reset data if the dropdown handler opened a floating window
2340 // see ImplFloatControl()
2341 if( !mpFloatWin )
2343 // no floater was opened
2344 Deactivate();
2345 InvalidateItem(mnCurPos);
2347 mnCurPos = ITEM_NOTFOUND;
2348 mnCurItemId = 0;
2349 mnDownItemId = 0;
2350 mnMouseModifier = 0;
2351 mnHighItemId = 0;
2356 IMPL_LINK_NOARG(ToolBox, ImplUpdateHdl, Timer *, void)
2359 if( mbFormat && mpData )
2360 ImplFormat();
2363 static void ImplDrawMoreIndicator(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
2365 const Image pImage(StockImage::Yes, CHEVRON);
2366 Size aImageSize = pImage.GetSizePixel();
2367 long x = rRect.Left() + (rRect.getWidth() - aImageSize.Width())/2;
2368 long y = rRect.Top() + (rRect.getHeight() - aImageSize.Height())/2;
2369 DrawImageFlags nImageStyle = DrawImageFlags::NONE;
2371 rRenderContext.DrawImage(Point(x,y), pImage, nImageStyle);
2374 static void ImplDrawDropdownArrow(vcl::RenderContext& rRenderContext, const tools::Rectangle& rDropDownRect, bool bSetColor, bool bRotate )
2376 bool bLineColor = rRenderContext.IsLineColor();
2377 bool bFillColor = rRenderContext.IsFillColor();
2378 Color aOldFillColor = rRenderContext.GetFillColor();
2379 Color aOldLineColor = rRenderContext.GetLineColor();
2380 rRenderContext.SetLineColor();
2382 if ( bSetColor )
2384 if (rRenderContext.GetSettings().GetStyleSettings().GetFaceColor().IsDark())
2385 rRenderContext.SetFillColor(COL_WHITE);
2386 else
2387 rRenderContext.SetFillColor(COL_BLACK);
2390 float fScaleFactor = rRenderContext.GetDPIScaleFactor();
2392 tools::Polygon aPoly(4);
2394 long width = round(rDropDownRect.getHeight()/5.5) * fScaleFactor; // scale triangle depending on theme/toolbar height with 7 for gtk, 5 for gen
2395 long height = round(rDropDownRect.getHeight()/9.5) * fScaleFactor; // 4 for gtk, 3 for gen
2396 if (width < 4) width = 4;
2397 if (height < 3) height = 3;
2399 long x = rDropDownRect.Left() + (rDropDownRect.getWidth() - width)/2;
2400 long y = rDropDownRect.Top() + (rDropDownRect.getHeight() - height)/2;
2402 long halfwidth = (width+1)>>1;
2403 aPoly.SetPoint(Point(x, y), 0);
2404 aPoly.SetPoint(Point(x + halfwidth, y + height), 1);
2405 aPoly.SetPoint(Point(x + halfwidth*2, y), 2);
2406 aPoly.SetPoint(Point(x, y), 3);
2408 if (bRotate) // TESTME: harder ...
2409 aPoly.Rotate(Point(x,y+height/2),2700);
2411 auto aaflags = rRenderContext.GetAntialiasing();
2412 rRenderContext.SetAntialiasing(AntialiasingFlags::EnableB2dDraw);
2413 rRenderContext.DrawPolygon( aPoly );
2414 rRenderContext.SetAntialiasing(aaflags);
2416 if( bFillColor )
2417 rRenderContext.SetFillColor(aOldFillColor);
2418 else
2419 rRenderContext.SetFillColor();
2420 if( bLineColor )
2421 rRenderContext.SetLineColor(aOldLineColor);
2422 else
2423 rRenderContext.SetLineColor();
2426 void ToolBox::ImplDrawMenuButton(vcl::RenderContext& rRenderContext, bool bHighlight)
2428 if (!mpData->maMenubuttonItem.maRect.IsEmpty())
2430 // #i53937# paint menu button only if necessary
2431 if (!ImplHasClippedItems())
2432 return;
2434 // execute pending paint requests
2435 ImplCheckUpdate();
2437 rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR);
2439 // draw the 'more' indicator / button (>>)
2440 ImplErase(rRenderContext, mpData->maMenubuttonItem.maRect, bHighlight);
2442 if (bHighlight)
2443 ImplDrawButton(rRenderContext, mpData->maMenubuttonItem.maRect, 2, false, true, false );
2445 if (ImplHasClippedItems())
2446 ImplDrawMoreIndicator(rRenderContext, mpData->maMenubuttonItem.maRect);
2448 // store highlight state
2449 mpData->mbMenubuttonSelected = bHighlight;
2451 // restore colors
2452 rRenderContext.Pop();
2456 void ToolBox::ImplDrawSpin(vcl::RenderContext& rRenderContext)
2458 bool bTmpUpper;
2459 bool bTmpLower;
2461 if ( maUpperRect.IsEmpty() || maLowerRect.IsEmpty() )
2462 return;
2464 bTmpUpper = mnCurLine > 1;
2466 bTmpLower = mnCurLine+mnVisLines-1 < mnCurLines;
2468 if ( !IsEnabled() )
2470 bTmpUpper = false;
2471 bTmpLower = false;
2474 ImplDrawUpDownButtons(rRenderContext, maUpperRect, maLowerRect,
2475 false/*bUpperIn*/, false/*bLowerIn*/, bTmpUpper, bTmpLower, !mbHorz);
2478 void ToolBox::ImplDrawSeparator(vcl::RenderContext& rRenderContext, ImplToolItems::size_type nPos, const tools::Rectangle& rRect)
2480 if ( nPos >= mpData->m_aItems.size() - 1 )
2481 // no separator if it's the last item
2482 return;
2484 ImplToolItem* pItem = &mpData->m_aItems[nPos];
2485 ImplToolItem* pPreviousItem = &mpData->m_aItems[nPos-1];
2486 ImplToolItem* pNextItem = &mpData->m_aItems[nPos+1];
2488 if ( ( pPreviousItem->mbShowWindow && pNextItem->mbShowWindow ) || pNextItem->mbBreak )
2489 // no separator between two windows or before a break
2490 return;
2492 bool bNativeOk = false;
2493 ControlPart nPart = IsHorizontal() ? ControlPart::SeparatorVert : ControlPart::SeparatorHorz;
2494 if (rRenderContext.IsNativeControlSupported(ControlType::Toolbar, nPart))
2496 ImplControlValue aControlValue;
2497 bNativeOk = rRenderContext.DrawNativeControl(ControlType::Toolbar, nPart, rRect, ControlState::NONE, aControlValue, OUString());
2500 /* Draw the widget only if it can't be drawn natively. */
2501 if (!bNativeOk)
2503 long nCenterPos, nSlim;
2504 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
2505 rRenderContext.SetLineColor(rStyleSettings.GetSeparatorColor());
2506 if (IsHorizontal())
2508 nSlim = (pItem->maRect.Bottom() - pItem->maRect.Top ()) / 4;
2509 nCenterPos = pItem->maRect.Center().X();
2510 rRenderContext.DrawLine(Point(nCenterPos, pItem->maRect.Top() + nSlim),
2511 Point(nCenterPos, pItem->maRect.Bottom() - nSlim));
2513 else
2515 nSlim = (pItem->maRect.Right() - pItem->maRect.Left ()) / 4;
2516 nCenterPos = pItem->maRect.Center().Y();
2517 rRenderContext.DrawLine(Point(pItem->maRect.Left() + nSlim, nCenterPos),
2518 Point(pItem->maRect.Right() - nSlim, nCenterPos));
2523 void ToolBox::ImplDrawButton(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect, sal_uInt16 highlight,
2524 bool bChecked, bool bEnabled, bool bIsWindow )
2526 // draws toolbar button background either native or using a coloured selection
2527 // if bIsWindow is true, the corresponding item is a control and only a selection border will be drawn
2529 bool bNativeOk = false;
2530 if( !bIsWindow && rRenderContext.IsNativeControlSupported( ControlType::Toolbar, ControlPart::Button ) )
2532 ImplControlValue aControlValue;
2533 ControlState nState = ControlState::NONE;
2535 if ( highlight == 1 ) nState |= ControlState::PRESSED;
2536 if ( highlight == 2 ) nState |= ControlState::ROLLOVER;
2537 if ( bEnabled ) nState |= ControlState::ENABLED;
2539 aControlValue.setTristateVal( bChecked ? ButtonValue::On : ButtonValue::Off );
2541 bNativeOk = rRenderContext.DrawNativeControl( ControlType::Toolbar, ControlPart::Button,
2542 rRect, nState, aControlValue, OUString() );
2545 if (!bNativeOk)
2546 vcl::RenderTools::DrawSelectionBackground(rRenderContext, *this, rRect, bIsWindow ? 3 : highlight,
2547 bChecked, true, bIsWindow, nullptr, 2);
2550 void ToolBox::ImplDrawItem(vcl::RenderContext& rRenderContext, ImplToolItems::size_type nPos, sal_uInt16 nHighlight)
2552 if (nPos >= mpData->m_aItems.size())
2553 return;
2555 // execute pending paint requests
2556 ImplCheckUpdate();
2558 ImplDisableFlatButtons();
2560 rRenderContext.SetFillColor();
2562 ImplToolItem* pItem = &mpData->m_aItems[nPos];
2564 if (!pItem->mbEnabled)
2565 nHighlight = 0;
2567 // if the rectangle is outside visible area
2568 if (pItem->maRect.IsEmpty())
2569 return;
2571 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
2573 // no gradient background for items that have a popup open
2574 bool bHasOpenPopup = mpFloatWin && (mnDownItemId==pItem->mnId);
2576 bool bHighContrastWhite = false;
2577 // check the face color as highcontrast indicator
2578 // because the toolbox itself might have a gradient
2579 if (rStyleSettings.GetFaceColor() == COL_WHITE)
2580 bHighContrastWhite = true;
2582 // Compute buttons area.
2583 Size aBtnSize = pItem->maRect.GetSize();
2585 /* Compute the button/separator rectangle here, we'll need it for
2586 * both the buttons and the separators. */
2587 tools::Rectangle aButtonRect( pItem->maRect.TopLeft(), aBtnSize );
2588 long nOffX = SMALLBUTTON_OFF_NORMAL_X;
2589 long nOffY = SMALLBUTTON_OFF_NORMAL_Y;
2590 long nImageOffX = 0;
2591 long nImageOffY = 0;
2592 DrawButtonFlags nStyle = DrawButtonFlags::NONE;
2594 // draw separators in flat style only
2595 if ( (mnOutStyle & TOOLBOX_STYLE_FLAT) &&
2596 (pItem->meType == ToolBoxItemType::SEPARATOR) &&
2597 nPos > 0
2600 ImplDrawSeparator(rRenderContext, nPos, aButtonRect);
2603 // do nothing if item is no button or will be displayed as window
2604 if ( (pItem->meType != ToolBoxItemType::BUTTON) || pItem->mbShowWindow )
2605 return;
2607 if ( pItem->meState == TRISTATE_TRUE )
2609 nStyle |= DrawButtonFlags::Checked;
2611 else if ( pItem->meState == TRISTATE_INDET )
2613 nStyle |= DrawButtonFlags::DontKnow;
2615 if ( nHighlight == 1 )
2617 nStyle |= DrawButtonFlags::Pressed;
2620 if ( mnOutStyle & TOOLBOX_STYLE_FLAT )
2622 ImplErase(rRenderContext, pItem->maRect, nHighlight != 0, bHasOpenPopup );
2624 else
2626 DecorationView aDecoView(&rRenderContext);
2627 aDecoView.DrawButton(aButtonRect, nStyle);
2630 nOffX += pItem->maRect.Left();
2631 nOffY += pItem->maRect.Top();
2633 // determine what has to be drawn on the button: image, text or both
2634 bool bImage;
2635 bool bText;
2636 ButtonType tmpButtonType = determineButtonType( pItem, meButtonType ); // default to toolbox setting
2637 pItem->DetermineButtonDrawStyle( tmpButtonType, bImage, bText );
2639 // compute output values
2640 long nBtnWidth = aBtnSize.Width()-SMALLBUTTON_HSIZE;
2641 long nBtnHeight = aBtnSize.Height()-SMALLBUTTON_VSIZE;
2642 Size aImageSize;
2643 Size aTxtSize;
2645 if ( bText )
2647 aTxtSize.setWidth( GetCtrlTextWidth( pItem->maText ) );
2648 aTxtSize.setHeight( GetTextHeight() );
2651 if ( bImage )
2653 const Image* pImage = &(pItem->maImage);
2654 const Image& rOverlayImage = pItem->maOverlayImage;
2655 aImageSize = pImage->GetSizePixel();
2657 // determine drawing flags
2658 DrawImageFlags nImageStyle = DrawImageFlags::NONE;
2660 if ( !pItem->mbEnabled || !IsEnabled() )
2661 nImageStyle |= DrawImageFlags::Disable;
2663 // #i35563# the dontknow state indicates different states at the same time
2664 // which should not be rendered disabled but normal
2666 // draw the image
2667 nImageOffX = nOffX;
2668 nImageOffY = nOffY;
2669 if ( ( (pItem->mnBits & (ToolBoxItemBits::LEFT|ToolBoxItemBits::DROPDOWN)) || bText )
2670 && ( meTextPosition == ToolBoxTextPosition::Right ) )
2672 // left align also to leave space for drop down arrow
2673 // and when drawing text+image
2674 // just center in y, except for vertical (ie rotated text)
2675 if( mbHorz || !bText )
2676 nImageOffY += (nBtnHeight-aImageSize.Height())/2;
2678 else
2680 nImageOffX += (nBtnWidth-aImageSize.Width())/2;
2681 if ( meTextPosition == ToolBoxTextPosition::Right )
2682 nImageOffY += (nBtnHeight-aImageSize.Height())/2;
2684 if ( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
2686 if( bHasOpenPopup )
2687 ImplDrawFloatwinBorder(rRenderContext, pItem);
2688 else
2689 ImplDrawButton(rRenderContext, aButtonRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2690 pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow);
2692 if( nHighlight != 0 )
2694 if( bHighContrastWhite )
2695 nImageStyle |= DrawImageFlags::ColorTransform;
2698 rRenderContext.DrawImage(Point( nImageOffX, nImageOffY ), *pImage, nImageStyle);
2699 if (!!rOverlayImage)
2700 rRenderContext.DrawImage(Point( nImageOffX, nImageOffY ), rOverlayImage, nImageStyle);
2703 // draw the text
2704 bool bRotate = false;
2705 if ( bText )
2707 long nTextOffX = nOffX;
2708 long nTextOffY = nOffY;
2710 // rotate text when vertically docked
2711 vcl::Font aOldFont = rRenderContext.GetFont();
2712 if( pItem->mbVisibleText && !ImplIsFloatingMode() &&
2713 ((meAlign == WindowAlign::Left) || (meAlign == WindowAlign::Right)) )
2715 bRotate = true;
2717 vcl::Font aRotateFont = aOldFont;
2718 aRotateFont.SetOrientation( 2700 );
2720 // center horizontally
2721 nTextOffX += aTxtSize.Height();
2722 nTextOffX += (nBtnWidth-aTxtSize.Height())/2;
2724 // add in image offset
2725 if( bImage )
2726 nTextOffY = nImageOffY + aImageSize.Height() + TB_IMAGETEXTOFFSET;
2728 rRenderContext.SetFont(aRotateFont);
2730 else
2732 if ( meTextPosition == ToolBoxTextPosition::Right )
2734 // center vertically
2735 nTextOffY += (nBtnHeight-aTxtSize.Height())/2;
2737 // add in image offset
2738 if( bImage )
2739 nTextOffX = nImageOffX + aImageSize.Width() + TB_IMAGETEXTOFFSET;
2741 else
2743 // center horizontally
2744 nTextOffX += (nBtnWidth-aTxtSize.Width() - TB_IMAGETEXTOFFSET)/2;
2745 // set vertical position
2746 nTextOffY += nBtnHeight - aTxtSize.Height();
2750 // draw selection only if not already drawn during image output (see above)
2751 if ( !bImage && (nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) ) )
2753 if( bHasOpenPopup )
2754 ImplDrawFloatwinBorder(rRenderContext, pItem);
2755 else
2756 ImplDrawButton(rRenderContext, pItem->maRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2757 pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow );
2760 DrawTextFlags nTextStyle = DrawTextFlags::NONE;
2761 if ( !pItem->mbEnabled )
2762 nTextStyle |= DrawTextFlags::Disable;
2763 rRenderContext.DrawCtrlText( Point( nTextOffX, nTextOffY ), pItem->maText,
2764 0, pItem->maText.getLength(), nTextStyle );
2765 if ( bRotate )
2766 SetFont( aOldFont );
2769 // paint optional drop down arrow
2770 if ( pItem->mnBits & ToolBoxItemBits::DROPDOWN )
2772 tools::Rectangle aDropDownRect( pItem->GetDropDownRect( mbHorz ) );
2773 bool bSetColor = true;
2774 if ( !pItem->mbEnabled || !IsEnabled() )
2776 bSetColor = false;
2777 rRenderContext.SetFillColor(rStyleSettings.GetShadowColor());
2780 // dropdown only will be painted without inner border
2781 if( (pItem->mnBits & ToolBoxItemBits::DROPDOWNONLY) != ToolBoxItemBits::DROPDOWNONLY )
2783 ImplErase(rRenderContext, aDropDownRect, nHighlight != 0, bHasOpenPopup);
2785 if( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
2787 if( bHasOpenPopup )
2788 ImplDrawFloatwinBorder(rRenderContext, pItem);
2789 else
2790 ImplDrawButton(rRenderContext, aDropDownRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2791 pItem->mbEnabled && IsEnabled(), false);
2794 ImplDrawDropdownArrow(rRenderContext, aDropDownRect, bSetColor, bRotate);
2798 void ToolBox::ImplDrawFloatwinBorder(vcl::RenderContext& rRenderContext, ImplToolItem const * pItem)
2800 if ( pItem->maRect.IsEmpty() )
2801 return;
2803 tools::Rectangle aRect( mpFloatWin->ImplGetItemEdgeClipRect() );
2804 aRect.SetPos( AbsoluteScreenToOutputPixel( aRect.TopLeft() ) );
2805 rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetShadowColor());
2806 Point p1, p2;
2808 p1 = pItem->maRect.TopLeft();
2809 p1.AdjustX( 1 );
2810 p2 = pItem->maRect.TopRight();
2811 p2.AdjustX( -1 );
2812 rRenderContext.DrawLine( p1, p2);
2813 p1 = pItem->maRect.BottomLeft();
2814 p1.AdjustX( 1 );
2815 p2 = pItem->maRect.BottomRight();
2816 p2.AdjustX( -1 );
2817 rRenderContext.DrawLine( p1, p2);
2819 p1 = pItem->maRect.TopLeft();
2820 p1.AdjustY( 1 );
2821 p2 = pItem->maRect.BottomLeft();
2822 p2.AdjustY( -1 );
2823 rRenderContext.DrawLine( p1, p2);
2824 p1 = pItem->maRect.TopRight();
2825 p1.AdjustY( 1 );
2826 p2 = pItem->maRect.BottomRight();
2827 p2.AdjustY( -1 );
2828 rRenderContext.DrawLine( p1, p2);
2832 void ToolBox::ImplFloatControl( bool bStart, FloatingWindow* pFloatWindow )
2835 if ( bStart )
2837 mpFloatWin = pFloatWindow;
2839 // redraw item, to trigger drawing of a special border
2840 InvalidateItem(mnCurPos);
2842 mbDrag = false;
2843 EndTracking();
2844 if (IsMouseCaptured())
2845 ReleaseMouse();
2847 else
2849 mpFloatWin = nullptr;
2851 // if focus is still in this toolbox, then the floater was opened by keyboard
2852 // draw current item with highlight and keep old state
2853 bool bWasKeyboardActivate = mpData->mbDropDownByKeyboard;
2855 if ( mnCurPos != ITEM_NOTFOUND )
2856 InvalidateItem(mnCurPos);
2857 Deactivate();
2859 if( !bWasKeyboardActivate )
2861 mnCurPos = ITEM_NOTFOUND;
2862 mnCurItemId = 0;
2863 mnHighItemId = 0;
2865 mnDownItemId = 0;
2870 void ToolBox::ShowLine( bool bNext )
2872 mbFormat = true;
2874 if ( bNext )
2875 mnCurLine++;
2876 else
2877 mnCurLine--;
2879 ImplFormat();
2882 bool ToolBox::ImplHandleMouseMove( const MouseEvent& rMEvt, bool bRepeat )
2884 Point aMousePos = rMEvt.GetPosPixel();
2886 if ( !mpData )
2887 return false;
2889 // ToolBox active?
2890 if ( mbDrag && mnCurPos != ITEM_NOTFOUND )
2892 // is the cursor over the item?
2893 ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
2894 if ( pItem->maRect.IsInside( aMousePos ) )
2896 if ( !mnCurItemId )
2898 InvalidateItem(mnCurPos);
2899 mnCurItemId = pItem->mnId;
2900 Highlight();
2903 if ( (pItem->mnBits & ToolBoxItemBits::REPEAT) && bRepeat )
2904 Select();
2906 else
2908 if ( mnCurItemId )
2910 InvalidateItem(mnCurPos);
2911 mnCurItemId = 0;
2912 InvalidateItem(mnCurPos);
2913 Highlight();
2917 return true;
2920 if ( mbUpper )
2922 bool bNewIn = maUpperRect.IsInside( aMousePos );
2923 if ( bNewIn != mbIn )
2925 mbIn = bNewIn;
2926 InvalidateSpin(true, false);
2928 return true;
2931 if ( mbLower )
2933 bool bNewIn = maLowerRect.IsInside( aMousePos );
2934 if ( bNewIn != mbIn )
2936 mbIn = bNewIn;
2937 InvalidateSpin(false);
2939 return true;
2942 return false;
2945 bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent& rMEvt, bool bCancel )
2947 ImplDisableFlatButtons();
2949 if ( !mpData )
2950 return false;
2952 // stop eventual running dropdown timer
2953 if( mnCurPos < mpData->m_aItems.size() &&
2954 (mpData->m_aItems[mnCurPos].mnBits & ToolBoxItemBits::DROPDOWN ) )
2956 mpData->maDropdownTimer.Stop();
2959 if ( mbDrag || mbSelection )
2961 // set mouse data if in selection mode, as then
2962 // the MouseButtonDown handler cannot be called
2963 if ( mbSelection )
2964 mnMouseModifier = rMEvt.GetModifier();
2966 Deactivate();
2968 if ( mbDrag )
2969 mbDrag = false;
2970 else
2972 mbSelection = false;
2973 if ( mnCurPos == ITEM_NOTFOUND )
2974 return true;
2977 // has mouse been released on top of item?
2978 if( mnCurPos < mpData->m_aItems.size() )
2980 ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
2981 if ( pItem->maRect.IsInside( rMEvt.GetPosPixel() ) )
2983 mnCurItemId = pItem->mnId;
2984 if ( !bCancel )
2986 // execute AutoCheck if required
2987 if ( pItem->mnBits & ToolBoxItemBits::AUTOCHECK )
2989 if ( pItem->mnBits & ToolBoxItemBits::RADIOCHECK )
2991 if ( pItem->meState != TRISTATE_TRUE )
2992 SetItemState( pItem->mnId, TRISTATE_TRUE );
2994 else
2996 if ( pItem->meState != TRISTATE_TRUE )
2997 pItem->meState = TRISTATE_TRUE;
2998 else
2999 pItem->meState = TRISTATE_FALSE;
3003 // do not call Select when Repeat is active, as in this
3004 // case that was triggered already in MouseButtonDown
3005 if ( !(pItem->mnBits & ToolBoxItemBits::REPEAT) )
3007 // prevent from being destroyed in the select handler
3008 VclPtr<vcl::Window> xWindow = this;
3009 Select();
3010 if ( xWindow->IsDisposed() )
3011 return true;
3018 // Items not destroyed, in Select handler
3019 if ( mnCurItemId )
3021 // Get current pos for the case that items are inserted/removed
3022 // in the toolBox
3023 mnCurPos = GetItemPos( mnCurItemId );
3024 if ( mnCurPos != ITEM_NOTFOUND )
3026 InvalidateItem(mnCurPos);
3027 Flush();
3033 mnCurPos = ITEM_NOTFOUND;
3034 mnCurItemId = 0;
3035 mnDownItemId = 0;
3036 mnMouseModifier = 0;
3037 return true;
3039 else if ( mbUpper || mbLower )
3041 if ( mbIn )
3042 ShowLine( !mbUpper );
3043 mbUpper = false;
3044 mbLower = false;
3045 mbIn = false;
3046 InvalidateSpin();
3047 return true;
3050 return false;
3053 void ToolBox::MouseMove( const MouseEvent& rMEvt )
3055 // pressing a modifier generates synthetic mouse moves
3056 // ignore it if keyboard selection is active
3057 if( HasFocus() && ( rMEvt.GetMode() & MouseEventModifiers::MODIFIERCHANGED ) )
3058 return;
3060 if ( ImplHandleMouseMove( rMEvt ) )
3061 return;
3063 ImplDisableFlatButtons();
3065 Point aMousePos = rMEvt.GetPosPixel();
3067 // only highlight when the focus is not inside a child window of a toolbox
3068 // eg, in an edit control
3069 // and do not highlight when focus is in a different toolbox
3070 bool bDrawHotSpot = true;
3071 vcl::Window *pFocusWin = Application::GetFocusWindow();
3073 bool bFocusWindowIsAToolBoxChild = false;
3074 if (pFocusWin)
3076 vcl::Window *pWin = pFocusWin->GetParent();
3077 while (pWin)
3079 if(pWin->ImplGetWindowImpl()->mbToolBox)
3081 bFocusWindowIsAToolBoxChild = true;
3082 break;
3084 pWin = pWin->GetParent();
3088 if( bFocusWindowIsAToolBoxChild || (pFocusWin && pFocusWin->ImplGetWindowImpl()->mbToolBox && pFocusWin != this) )
3089 bDrawHotSpot = false;
3091 if ( mbSelection && bDrawHotSpot )
3093 ImplToolItems::size_type i = 0;
3094 ImplToolItems::size_type nNewPos = ITEM_NOTFOUND;
3096 // search the item that has been clicked
3097 for (auto const& item : mpData->m_aItems)
3099 // if the mouse position is in this item,
3100 // we can stop the search
3101 if ( item.maRect.IsInside( aMousePos ) )
3103 // select it if it is a button
3104 if ( item.meType == ToolBoxItemType::BUTTON )
3106 // if button is disabled, do not
3107 // change it
3108 if ( !item.mbEnabled || item.mbShowWindow )
3109 nNewPos = mnCurPos;
3110 else
3111 nNewPos = i;
3113 break;
3115 ++i;
3118 // was a new entry selected?
3119 // don't change selection if keyboard selection is active and
3120 // mouse leaves the toolbox
3121 if ( nNewPos != mnCurPos && !( HasFocus() && nNewPos == ITEM_NOTFOUND ) )
3123 if ( mnCurPos != ITEM_NOTFOUND )
3125 InvalidateItem(mnCurPos);
3126 CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( mnCurPos ) );
3129 mnCurPos = nNewPos;
3130 if ( mnCurPos != ITEM_NOTFOUND )
3132 mnCurItemId = mnHighItemId = mpData->m_aItems[mnCurPos].mnId;
3133 InvalidateItem(mnCurPos);
3135 else
3136 mnCurItemId = mnHighItemId = 0;
3138 Highlight();
3140 return;
3143 if ( mbDragging )
3145 ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
3146 pMgr->Dragging( aMousePos );
3147 return;
3150 PointerStyle eStyle = PointerStyle::Arrow;
3152 // change mouse cursor over drag area
3153 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
3154 if( pWrapper && pWrapper->GetDragArea().IsInside( rMEvt.GetPosPixel() ) )
3155 eStyle = PointerStyle::Move;
3157 if ( (mnWinStyle & TB_WBLINESIZING) == TB_WBLINESIZING )
3159 if ( rMEvt.GetMode() & MouseEventModifiers::SIMPLEMOVE )
3161 sal_uInt16 nLinePtr = ImplTestLineSize( rMEvt.GetPosPixel() );
3162 if ( nLinePtr & DOCK_LINEHSIZE )
3164 if ( meAlign == WindowAlign::Left )
3165 eStyle = PointerStyle::WindowESize;
3166 else
3167 eStyle = PointerStyle::WindowWSize;
3169 else if ( nLinePtr & DOCK_LINEVSIZE )
3171 if ( meAlign == WindowAlign::Top )
3172 eStyle = PointerStyle::WindowSSize;
3173 else
3174 eStyle = PointerStyle::WindowNSize;
3179 if ( bDrawHotSpot && ( (mnOutStyle & TOOLBOX_STYLE_FLAT) || !mnOutStyle ) )
3181 bool bClearHigh = true;
3182 if ( !rMEvt.IsLeaveWindow() && (mnCurPos == ITEM_NOTFOUND) )
3184 ImplToolItems::size_type nTempPos = 0;
3185 for (auto const& item : mpData->m_aItems)
3187 if ( item.maRect.IsInside( aMousePos ) )
3189 if ( (item.meType == ToolBoxItemType::BUTTON) && item.mbEnabled )
3191 if ( !mnOutStyle || (mnOutStyle & TOOLBOX_STYLE_FLAT) )
3193 bClearHigh = false;
3194 if ( mnHighItemId != item.mnId )
3196 if ( mnHighItemId )
3198 ImplHideFocus();
3199 ImplToolItems::size_type nPos = GetItemPos( mnHighItemId );
3200 InvalidateItem(nPos);
3201 CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nPos ) );
3203 if ( mpData->mbMenubuttonSelected )
3205 // remove highlight from menubutton
3206 InvalidateMenuButton();
3208 mnHighItemId = item.mnId;
3209 InvalidateItem(nTempPos);
3210 ImplShowFocus();
3211 CallEventListeners( VclEventId::ToolboxHighlight );
3215 break;
3217 ++nTempPos;
3221 // only clear highlight when focus is not in toolbar
3222 bool bMenuButtonHit = mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems();
3223 if ( !HasFocus() && (bClearHigh || bMenuButtonHit) )
3225 if ( !bMenuButtonHit && mpData->mbMenubuttonSelected )
3227 // remove highlight from menubutton
3228 InvalidateMenuButton();
3231 if( mnHighItemId )
3233 ImplToolItems::size_type nClearPos = GetItemPos( mnHighItemId );
3234 if ( nClearPos != ITEM_NOTFOUND )
3236 InvalidateItem(nClearPos);
3237 if( nClearPos != mnCurPos )
3238 CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nClearPos ) );
3240 ImplHideFocus();
3241 mnHighItemId = 0;
3244 if( bMenuButtonHit )
3246 InvalidateMenuButton();
3251 if ( meLastStyle != eStyle )
3253 meLastStyle = eStyle;
3254 SetPointer( eStyle );
3257 DockingWindow::MouseMove( rMEvt );
3260 void ToolBox::MouseButtonDown( const MouseEvent& rMEvt )
3262 // only trigger toolbox for left mouse button and when
3263 // we're not in normal operation
3264 if ( rMEvt.IsLeft() && !mbDrag && (mnCurPos == ITEM_NOTFOUND) )
3266 // call activate already here, as items could
3267 // be exchanged
3268 Activate();
3270 // update ToolBox here, such that user knows it
3271 if ( mbFormat )
3273 ImplFormat();
3274 Update();
3277 Point aMousePos = rMEvt.GetPosPixel();
3278 ImplToolItems::size_type i = 0;
3279 ImplToolItems::size_type nNewPos = ITEM_NOTFOUND;
3281 // search for item that was clicked
3282 for (auto const& item : mpData->m_aItems)
3284 // is this the item?
3285 if ( item.maRect.IsInside( aMousePos ) )
3287 // do nothing if it is a separator or
3288 // if the item has been disabled
3289 if ( (item.meType == ToolBoxItemType::BUTTON) &&
3290 !item.mbShowWindow )
3291 nNewPos = i;
3293 break;
3296 i++;
3299 // item found
3300 if ( nNewPos != ITEM_NOTFOUND )
3302 if ( !mpData->m_aItems[nNewPos].mbEnabled )
3304 Deactivate();
3305 return;
3308 // update actual data
3309 StartTrackingFlags nTrackFlags = StartTrackingFlags::NONE;
3310 mnCurPos = i;
3311 mnCurItemId = mpData->m_aItems[nNewPos].mnId;
3312 mnDownItemId = mnCurItemId;
3313 mnMouseModifier = rMEvt.GetModifier();
3314 if ( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::REPEAT )
3315 nTrackFlags |= StartTrackingFlags::ButtonRepeat;
3317 if ( mbSelection )
3319 InvalidateItem(mnCurPos);
3320 Highlight();
3322 else
3324 // update bDrag here, as it is evaluated in the EndSelection
3325 mbDrag = true;
3327 // on double-click: only call the handler, but do so before the button
3328 // is hit, as in the handler dragging
3329 // can be terminated
3330 if ( rMEvt.GetClicks() == 2 )
3331 DoubleClick();
3333 if ( mbDrag )
3335 InvalidateItem(mnCurPos);
3336 Highlight();
3339 // was dropdown arrow pressed
3340 if( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWN )
3342 if( ( (mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWNONLY) == ToolBoxItemBits::DROPDOWNONLY)
3343 || mpData->m_aItems[nNewPos].GetDropDownRect( mbHorz ).IsInside( aMousePos ))
3345 // dropdownonly always triggers the dropdown handler, over the whole button area
3347 // the drop down arrow should not trigger the item action
3348 mpData->mbDropDownByKeyboard = false;
3349 mpData->maDropdownClickHdl.Call( this );
3351 // do not reset data if the dropdown handler opened a floating window
3352 // see ImplFloatControl()
3353 if( !mpFloatWin )
3355 // no floater was opened
3356 Deactivate();
3357 InvalidateItem(mnCurPos);
3359 mnCurPos = ITEM_NOTFOUND;
3360 mnCurItemId = 0;
3361 mnDownItemId = 0;
3362 mnMouseModifier = 0;
3363 mnHighItemId = 0;
3365 return;
3367 else // activate long click timer
3368 mpData->maDropdownTimer.Start();
3371 // call Click handler
3372 if ( rMEvt.GetClicks() != 2 )
3373 Click();
3375 // also call Select handler at repeat
3376 if ( nTrackFlags & StartTrackingFlags::ButtonRepeat )
3377 Select();
3379 // if the actions was not aborted in Click handler
3380 if ( mbDrag )
3381 StartTracking( nTrackFlags );
3384 // if mouse was clicked over an item we
3385 // can abort here
3386 return;
3389 Deactivate();
3391 // menu button hit ?
3392 if( mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems() )
3394 if ( maMenuButtonHdl.IsSet() )
3395 maMenuButtonHdl.Call( this );
3396 else
3397 ExecuteCustomMenu( mpData->maMenubuttonItem.maRect );
3398 return;
3401 // check scroll- and next-buttons here
3402 if ( maUpperRect.IsInside( aMousePos ) )
3404 if ( mnCurLine > 1 )
3406 StartTracking();
3407 mbUpper = true;
3408 mbIn = true;
3409 InvalidateSpin(true, false);
3411 return;
3413 if ( maLowerRect.IsInside( aMousePos ) )
3415 if ( mnCurLine+mnVisLines-1 < mnCurLines )
3417 StartTracking();
3418 mbLower = true;
3419 mbIn = true;
3420 InvalidateSpin(false);
3422 return;
3425 // Linesizing testen
3426 if ( (mnWinStyle & TB_WBLINESIZING) == TB_WBLINESIZING )
3428 sal_uInt16 nLineMode = ImplTestLineSize( aMousePos );
3429 if ( nLineMode )
3431 ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
3433 // call handler, such that we can set the
3434 // dock rectangles
3435 StartDocking();
3437 Point aPos = GetParent()->OutputToScreenPixel( GetPosPixel() );
3438 Size aSize = GetSizePixel();
3439 aPos = ScreenToOutputPixel( aPos );
3441 // start dragging
3442 pMgr->StartDragging( this, aMousePos, tools::Rectangle( aPos, aSize ),
3443 nLineMode );
3444 return;
3448 // no item, then only click or double click
3449 if ( rMEvt.GetClicks() == 2 )
3450 DoubleClick();
3451 else
3452 Click();
3455 if ( !mbDrag && !mbSelection && (mnCurPos == ITEM_NOTFOUND) )
3456 DockingWindow::MouseButtonDown( rMEvt );
3459 void ToolBox::MouseButtonUp( const MouseEvent& rMEvt )
3461 if ( ImplHandleMouseButtonUp( rMEvt ) )
3462 return;
3464 if ( mbDragging && rMEvt.IsLeft() )
3466 ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
3467 pMgr->EndDragging();
3468 return;
3471 DockingWindow::MouseButtonUp( rMEvt );
3474 void ToolBox::Tracking( const TrackingEvent& rTEvt )
3476 VclPtr<vcl::Window> xWindow = this;
3478 if ( rTEvt.IsTrackingEnded() )
3479 ImplHandleMouseButtonUp( rTEvt.GetMouseEvent(), rTEvt.IsTrackingCanceled() );
3480 else
3481 ImplHandleMouseMove( rTEvt.GetMouseEvent(), rTEvt.IsTrackingRepeat() );
3483 if ( xWindow->IsDisposed() )
3484 // toolbox was deleted
3485 return;
3486 DockingWindow::Tracking( rTEvt );
3489 void ToolBox::InvalidateItem(ImplToolItems::size_type nPosition)
3491 if (mpData && nPosition < mpData->m_aItems.size())
3493 ImplToolItem* pItem = &mpData->m_aItems[nPosition];
3494 Invalidate(pItem->maRect);
3498 void ToolBox::InvalidateMenuButton()
3500 if (!mpData->maMenubuttonItem.maRect.IsEmpty())
3501 Invalidate(mpData->maMenubuttonItem.maRect);
3504 void ToolBox::InvalidateSpin(bool bUpperIn, bool bLowerIn)
3506 if (bUpperIn && !maUpperRect.IsEmpty())
3507 Invalidate(maUpperRect);
3509 if (bLowerIn && !maLowerRect.IsEmpty())
3510 Invalidate(maLowerRect);
3513 void ToolBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rPaintRect)
3515 if( mpData->mbIsPaintLocked )
3516 return;
3518 if (rPaintRect == tools::Rectangle(0, 0, mnDX-1, mnDY-1))
3519 mbFullPaint = true;
3520 ImplFormat();
3521 mbFullPaint = false;
3523 ImplDrawBackground(rRenderContext, rPaintRect);
3525 if ( (mnWinStyle & WB_BORDER) && !ImplIsFloatingMode() )
3526 ImplDrawBorder(rRenderContext);
3528 if( !ImplIsFloatingMode() )
3529 ImplDrawGrip(rRenderContext);
3531 ImplDrawMenuButton(rRenderContext, mpData->mbMenubuttonSelected);
3533 // draw SpinButtons
3534 if (mnWinStyle & WB_SCROLL)
3536 if (mnCurLines > mnLines)
3537 ImplDrawSpin(rRenderContext);
3540 // draw buttons
3541 ImplToolItems::size_type nHighPos;
3542 if ( mnHighItemId )
3543 nHighPos = GetItemPos( mnHighItemId );
3544 else
3545 nHighPos = ITEM_NOTFOUND;
3547 ImplToolItems::size_type nCount = mpData->m_aItems.size();
3548 for( ImplToolItems::size_type i = 0; i < nCount; i++ )
3550 ImplToolItem* pItem = &mpData->m_aItems[i];
3552 // only draw when the rectangle is in the draw rectangle
3553 if ( !pItem->maRect.IsEmpty() && rPaintRect.IsOver( pItem->maRect ) )
3555 sal_uInt16 nHighlight = 0;
3556 if ( i == mnCurPos )
3557 nHighlight = 1;
3558 else if ( i == nHighPos )
3559 nHighlight = 2;
3560 ImplDrawItem(rRenderContext, i, nHighlight);
3563 ImplShowFocus();
3566 void ToolBox::Resize()
3568 Size aSize = GetOutputSizePixel();
3569 // #i31422# some WindowManagers send (0,0) sizes when
3570 // switching virtual desktops - ignore this and avoid reformatting
3571 if( !aSize.Width() && !aSize.Height() )
3572 return;
3574 long nOldDX = mnDX;
3575 long nOldDY = mnDY;
3576 mnDX = aSize.Width();
3577 mnDY = aSize.Height();
3579 mnLastResizeDY = 0;
3581 // invalidate everything to have gradient backgrounds properly drawn
3582 Invalidate();
3584 // If we have any expandable entries, then force a reformat first using
3585 // their optimal sizes, then share out the excess space evenly across those
3586 // expandables and reformat again
3587 std::vector<size_t> aExpandables;
3588 for (size_t i = 0; i < mpData->m_aItems.size(); ++i)
3590 if (mpData->m_aItems[i].mbExpand)
3592 vcl::Window *pWindow = mpData->m_aItems[i].mpWindow;
3593 SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
3594 if (!pWindow)
3595 continue;
3596 Size aWinSize(pWindow->GetSizePixel());
3597 Size aPrefSize(pWindow->get_preferred_size());
3598 aWinSize.setWidth( aPrefSize.Width() );
3599 pWindow->SetSizePixel(aWinSize);
3600 aExpandables.push_back(i);
3604 // re-format or re-draw
3605 if ( mbScroll || !aExpandables.empty() )
3607 if ( !mbFormat || !aExpandables.empty() )
3609 mbFormat = true;
3610 if( IsReallyVisible() || !aExpandables.empty() )
3612 ImplFormat(true);
3614 if (!aExpandables.empty())
3616 //Get how big the optimal size is
3617 tools::Rectangle aBounds;
3618 for (const ImplToolItem & rItem : mpData->m_aItems)
3620 aBounds.Union( rItem.maRect );
3623 long nOptimalWidth = aBounds.GetWidth();
3624 long nDiff = aSize.Width() - nOptimalWidth;
3625 nDiff /= aExpandables.size();
3627 //share out the diff from optimal to real across
3628 //expandable entries
3629 for (size_t nIndex : aExpandables)
3631 vcl::Window *pWindow = mpData->m_aItems[nIndex].mpWindow;
3632 Size aWinSize(pWindow->GetSizePixel());
3633 Size aPrefSize(pWindow->get_preferred_size());
3634 aWinSize.setWidth( aPrefSize.Width() + nDiff );
3635 pWindow->SetSizePixel(aWinSize);
3638 //now reformat with final sizes
3639 mbFormat = true;
3640 ImplFormat(true);
3646 // redraw border
3647 if ( mnWinStyle & WB_BORDER )
3649 // as otherwise, when painting we might think we have to re-draw everything
3650 if ( mbFormat && IsReallyVisible() )
3651 Invalidate();
3652 else
3654 if ( mnRightBorder )
3656 if ( nOldDX > mnDX )
3657 Invalidate( tools::Rectangle( mnDX-mnRightBorder-1, 0, mnDX, mnDY ) );
3658 else
3659 Invalidate( tools::Rectangle( nOldDX-mnRightBorder-1, 0, nOldDX, nOldDY ) );
3662 if ( mnBottomBorder )
3664 if ( nOldDY > mnDY )
3665 Invalidate( tools::Rectangle( 0, mnDY-mnBottomBorder-1, mnDX, mnDY ) );
3666 else
3667 Invalidate( tools::Rectangle( 0, nOldDY-mnBottomBorder-1, nOldDX, nOldDY ) );
3673 namespace
3675 bool DispatchableCommand(const OUString& rName)
3677 return rName.startsWith(".uno") ||
3678 rName.startsWith("slot:") ||
3679 rName.startsWith("macro:") ||
3680 rName.startsWith("vnd.sun.star.script");
3684 const OUString& ToolBox::ImplGetHelpText( sal_uInt16 nItemId ) const
3686 ImplToolItem* pItem = ImplGetItem( nItemId );
3688 assert( pItem );
3690 if ( pItem->maHelpText.isEmpty() && ( !pItem->maHelpId.isEmpty() || pItem->maCommandStr.getLength() ))
3692 Help* pHelp = Application::GetHelp();
3693 if ( pHelp )
3695 if (DispatchableCommand(pItem->maCommandStr))
3696 pItem->maHelpText = pHelp->GetHelpText( pItem->maCommandStr, this );
3697 if ( pItem->maHelpText.isEmpty() && !pItem->maHelpId.isEmpty() )
3698 pItem->maHelpText = pHelp->GetHelpText( OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
3702 return pItem->maHelpText;
3705 void ToolBox::RequestHelp( const HelpEvent& rHEvt )
3707 sal_uInt16 nItemId;
3708 Point aHelpPos;
3710 if( !rHEvt.KeyboardActivated() )
3712 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
3713 aHelpPos = rHEvt.GetMousePosPixel();
3715 else
3717 if( !mnHighItemId )
3718 return;
3719 else
3720 nItemId = mnHighItemId;
3721 tools::Rectangle aRect( GetItemRect( nItemId ) );
3722 if( aRect.IsEmpty() )
3723 return;
3724 else
3725 aHelpPos = OutputToScreenPixel( aRect.Center() );
3728 if ( nItemId )
3730 if ( rHEvt.GetMode() & (HelpEventMode::BALLOON | HelpEventMode::QUICK) )
3732 // get rectangle
3733 tools::Rectangle aTempRect = GetItemRect( nItemId );
3734 Point aPt = OutputToScreenPixel( aTempRect.TopLeft() );
3735 aTempRect.SetLeft( aPt.X() );
3736 aTempRect.SetTop( aPt.Y() );
3737 aPt = OutputToScreenPixel( aTempRect.BottomRight() );
3738 aTempRect.SetRight( aPt.X() );
3739 aTempRect.SetBottom( aPt.Y() );
3741 // get text and display it
3742 OUString aStr = GetQuickHelpText( nItemId );
3743 if (aStr.isEmpty())
3744 aStr = MnemonicGenerator::EraseAllMnemonicChars( GetItemText( nItemId ) );
3745 if ( rHEvt.GetMode() & HelpEventMode::BALLOON )
3747 const OUString& rHelpStr = GetHelpText( nItemId );
3748 if (!rHelpStr.isEmpty())
3749 aStr = rHelpStr;
3750 Help::ShowBalloon( this, aHelpPos, aTempRect, aStr );
3752 else
3753 Help::ShowQuickHelp( this, aTempRect, aStr, QuickHelpFlags::CtrlText );
3754 return;
3758 DockingWindow::RequestHelp( rHEvt );
3761 bool ToolBox::EventNotify( NotifyEvent& rNEvt )
3763 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
3765 KeyEvent aKEvt = *rNEvt.GetKeyEvent();
3766 vcl::KeyCode aKeyCode = aKEvt.GetKeyCode();
3767 sal_uInt16 nKeyCode = aKeyCode.GetCode();
3768 switch( nKeyCode )
3770 case KEY_TAB:
3772 // internal TAB cycling only if parent is not a dialog or if we are the only child
3773 // otherwise the dialog control will take over
3774 vcl::Window *pParent = ImplGetParent();
3775 bool bOldSchoolContainer =
3776 ((pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL &&
3777 pParent->GetChildCount() != 1);
3778 bool bNoTabCycling = bOldSchoolContainer || isContainerWindow(pParent);
3780 if( bNoTabCycling )
3781 return DockingWindow::EventNotify( rNEvt );
3782 else if( ImplChangeHighlightUpDn( aKeyCode.IsShift() , bNoTabCycling ) )
3783 return false;
3784 else
3785 return DockingWindow::EventNotify( rNEvt );
3787 default:
3788 break;
3791 else if( rNEvt.GetType() == MouseNotifyEvent::GETFOCUS )
3793 if( rNEvt.GetWindow() == this )
3795 // the toolbar itself got the focus
3796 if( mnLastFocusItemId != 0 || mpData->mbMenubuttonWasLastSelected )
3798 // restore last item
3799 if( mpData->mbMenubuttonWasLastSelected )
3801 ImplChangeHighlight( nullptr );
3802 mpData->mbMenubuttonSelected = true;
3803 InvalidateMenuButton();
3805 else
3807 ImplChangeHighlight( ImplGetItem( mnLastFocusItemId ) );
3808 mnLastFocusItemId = 0;
3811 else if( (GetGetFocusFlags() & (GetFocusFlags::Backward|GetFocusFlags::Tab) ) == (GetFocusFlags::Backward|GetFocusFlags::Tab))
3812 // Shift-TAB was pressed in the parent
3813 ImplChangeHighlightUpDn( false );
3814 else
3815 ImplChangeHighlightUpDn( true );
3817 mnLastFocusItemId = 0;
3819 return true;
3821 else
3823 // a child window got the focus so update current item to
3824 // allow for proper lose focus handling in keyboard navigation
3825 for (auto const& item : mpData->m_aItems)
3827 if ( item.mbVisible )
3829 if ( item.mpWindow && item.mpWindow->ImplIsWindowOrChild( rNEvt.GetWindow() ) )
3831 mnHighItemId = item.mnId;
3832 break;
3836 return DockingWindow::EventNotify( rNEvt );
3839 else if( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS )
3841 // deselect
3842 ImplHideFocus();
3843 mpData->mbMenubuttonWasLastSelected = false;
3844 mnHighItemId = 0;
3845 mnCurPos = ITEM_NOTFOUND;
3848 return DockingWindow::EventNotify( rNEvt );
3851 void ToolBox::Command( const CommandEvent& rCEvt )
3853 if ( rCEvt.GetCommand() == CommandEventId::Wheel )
3855 if ( (mnCurLine > 1) || (mnCurLine+mnVisLines-1 < mnCurLines) )
3857 const CommandWheelData* pData = rCEvt.GetWheelData();
3858 if ( pData->GetMode() == CommandWheelMode::SCROLL )
3860 if ( (mnCurLine > 1) && (pData->GetDelta() > 0) )
3861 ShowLine( false );
3862 else if ( (mnCurLine+mnVisLines-1 < mnCurLines) && (pData->GetDelta() < 0) )
3863 ShowLine( true );
3864 InvalidateSpin();
3865 return;
3869 else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
3871 ExecuteCustomMenu( tools::Rectangle( rCEvt.GetMousePosPixel(), rCEvt.GetMousePosPixel() ) );
3872 return;
3875 DockingWindow::Command( rCEvt );
3878 void ToolBox::StateChanged( StateChangedType nType )
3880 DockingWindow::StateChanged( nType );
3882 if ( nType == StateChangedType::InitShow )
3883 ImplFormat();
3884 else if ( nType == StateChangedType::Enable )
3885 ImplUpdateItem();
3886 else if ( nType == StateChangedType::UpdateMode )
3888 if ( IsUpdateMode() )
3889 Invalidate();
3891 else if ( (nType == StateChangedType::Zoom) ||
3892 (nType == StateChangedType::ControlFont) )
3894 mbCalc = true;
3895 mbFormat = true;
3896 ImplInitSettings( true, false, false );
3897 Invalidate();
3899 else if ( nType == StateChangedType::ControlForeground )
3901 ImplInitSettings( false, true, false );
3902 Invalidate();
3904 else if ( nType == StateChangedType::ControlBackground )
3906 ImplInitSettings( false, false, true ); // font, foreground, background
3907 Invalidate();
3910 maStateChangedHandler.Call( &nType );
3913 void ToolBox::DataChanged( const DataChangedEvent& rDCEvt )
3915 DockingWindow::DataChanged( rDCEvt );
3917 if ( (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
3918 (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
3919 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
3920 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
3921 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
3923 mbCalc = true;
3924 mbFormat = true;
3925 ImplInitSettings( true, true, true );
3926 Invalidate();
3929 maDataChangedHandler.Call( &rDCEvt );
3932 void ToolBox::statusChanged( const css::frame::FeatureStateEvent& Event )
3934 // Update image mirroring/rotation
3935 if ( Event.FeatureURL.Complete == ".uno:ImageOrientation" )
3937 SfxImageItem aItem( 1 );
3938 aItem.PutValue( Event.State, 0 );
3940 mbImagesMirrored = aItem.IsMirrored();
3941 mnImagesRotationAngle = aItem.GetRotation();
3943 // update image orientation
3944 OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(mpStatusListener->getFrame()));
3945 for (auto const& item : mpData->m_aItems)
3947 if (vcl::CommandInfoProvider::IsMirrored(item.maCommandStr, aModuleName))
3948 SetItemImageMirrorMode(item.mnId, mbImagesMirrored);
3949 if (vcl::CommandInfoProvider::IsRotated(item.maCommandStr, aModuleName))
3950 SetItemImageAngle(item.mnId, mnImagesRotationAngle);
3955 void ToolBox::SetStyle(WinBits nNewStyle)
3957 mnWinStyle = nNewStyle;
3958 if (!ImplIsFloatingMode())
3960 bool bOldScroll = mbScroll;
3961 mbScroll = (mnWinStyle & WB_SCROLL) != 0;
3962 if (mbScroll != bOldScroll)
3964 mbFormat = true;
3965 ImplFormat();
3970 void ToolBox::ToggleFloatingMode()
3972 DockingWindow::ToggleFloatingMode();
3974 if (!mpData)
3975 return;
3977 bool bOldHorz = mbHorz;
3979 if ( ImplIsFloatingMode() )
3981 mbHorz = true;
3982 meAlign = WindowAlign::Top;
3983 mbScroll = true;
3985 if( bOldHorz != mbHorz )
3986 mbCalc = true; // orientation was changed !
3988 ImplSetMinMaxFloatSize();
3989 SetOutputSizePixel( ImplCalcFloatSize( mnFloatLines ) );
3991 else
3993 mbScroll = (mnWinStyle & WB_SCROLL) != 0;
3994 if ( (meAlign == WindowAlign::Top) || (meAlign == WindowAlign::Bottom) )
3995 mbHorz = true;
3996 else
3997 mbHorz = false;
3999 // set focus back to document
4000 ImplGetFrameWindow()->GetWindow( GetWindowType::Client )->GrabFocus();
4003 if( bOldHorz != mbHorz )
4005 // if orientation changes, the toolbox has to be initialized again
4006 // to update the direction of the gradient
4007 mbCalc = true;
4008 ImplInitSettings( true, true, true );
4011 mbFormat = true;
4012 ImplFormat();
4015 void ToolBox::StartDocking()
4017 meDockAlign = meAlign;
4018 mnDockLines = mnLines;
4019 mbLastFloatMode = ImplIsFloatingMode();
4020 DockingWindow::StartDocking();
4023 bool ToolBox::Docking( const Point& rPos, tools::Rectangle& rRect )
4025 // do nothing during dragging, it was calculated before
4026 if ( mbDragging )
4027 return false;
4029 bool bFloatMode = false;
4031 DockingWindow::Docking( rPos, rRect );
4033 // if the mouse is outside the area, it can only become a floating window
4034 tools::Rectangle aDockingRect( rRect );
4035 if ( !ImplIsFloatingMode() )
4037 // don't use tracking rectangle for alignment check, because it will be too large
4038 // to get a floating mode as result - switch to floating size
4039 // so the calculation only depends on the position of the rectangle, not the current
4040 // docking state of the window
4041 ImplToolItems::size_type nTemp = 0;
4042 aDockingRect.SetSize( ImplCalcFloatSize( nTemp ) );
4044 // in this mode docking is never done by keyboard, so it's OK to use the mouse position
4045 aDockingRect.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
4048 bFloatMode = true;
4050 meDockAlign = meAlign;
4051 if ( !mbLastFloatMode )
4053 ImplToolItems::size_type nTemp = 0;
4054 aDockingRect.SetSize( ImplCalcFloatSize( nTemp ) );
4057 rRect = aDockingRect;
4058 mbLastFloatMode = bFloatMode;
4060 return bFloatMode;
4063 void ToolBox::EndDocking( const tools::Rectangle& rRect, bool bFloatMode )
4065 if ( !IsDockingCanceled() )
4067 if ( mnLines != mnDockLines )
4068 SetLineCount( mnDockLines );
4069 if ( meAlign != meDockAlign )
4070 SetAlign( meDockAlign );
4072 if ( bFloatMode || (bFloatMode != ImplIsFloatingMode()) )
4073 DockingWindow::EndDocking( rRect, bFloatMode );
4076 void ToolBox::Resizing( Size& rSize )
4078 ImplToolItems::size_type nCalcLines;
4079 ImplToolItems::size_type nTemp;
4081 // calculate all floating sizes
4082 ImplCalcFloatSizes();
4084 if ( !mnLastResizeDY )
4085 mnLastResizeDY = mnDY;
4087 // is vertical resizing needed
4088 if ( (mnLastResizeDY != rSize.Height()) && (mnDY != rSize.Height()) )
4090 nCalcLines = ImplCalcLines( rSize.Height() );
4091 if ( nCalcLines < 1 )
4092 nCalcLines = 1;
4093 rSize = ImplCalcFloatSize( nCalcLines );
4095 else
4097 nCalcLines = 1;
4098 nTemp = nCalcLines;
4099 Size aTempSize = ImplCalcFloatSize( nTemp );
4100 while ( (aTempSize.Width() > rSize.Width()) &&
4101 (nCalcLines <= maFloatSizes[0].mnLines) )
4103 nCalcLines++;
4104 nTemp = nCalcLines;
4105 aTempSize = ImplCalcFloatSize( nTemp );
4107 rSize = aTempSize;
4110 mnLastResizeDY = rSize.Height();
4113 Size ToolBox::GetOptimalSize() const
4115 // If we have any expandable entries, then force them to their
4116 // optimal sizes, then reset them afterwards
4117 std::map<vcl::Window*, Size> aExpandables;
4118 for (const ImplToolItem & rItem : mpData->m_aItems)
4120 if (rItem.mbExpand)
4122 vcl::Window *pWindow = rItem.mpWindow;
4123 SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
4124 if (!pWindow)
4125 continue;
4126 Size aWinSize(pWindow->GetSizePixel());
4127 aExpandables[pWindow] = aWinSize;
4128 Size aPrefSize(pWindow->get_preferred_size());
4129 aWinSize.setWidth( aPrefSize.Width() );
4130 pWindow->SetSizePixel(aWinSize);
4134 Size aSize(const_cast<ToolBox *>(this)->ImplCalcSize( mnLines ));
4136 for (auto const& expandable : aExpandables)
4138 vcl::Window *pWindow = expandable.first;
4139 Size aWinSize = expandable.second;
4140 pWindow->SetSizePixel(aWinSize);
4143 return aSize;
4146 Size ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines )
4148 return ImplCalcSize( nCalcLines );
4151 Size ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines, WindowAlign eAlign )
4153 return ImplCalcSize( nCalcLines,
4154 (eAlign == WindowAlign::Top || eAlign == WindowAlign::Bottom) ? TB_CALCMODE_HORZ : TB_CALCMODE_VERT );
4157 ToolBox::ImplToolItems::size_type ToolBox::ImplCountLineBreaks() const
4159 ImplToolItems::size_type nLines = 0;
4161 for (auto const& item : mpData->m_aItems)
4163 if( item.meType == ToolBoxItemType::BREAK )
4164 ++nLines;
4166 return nLines;
4169 Size ToolBox::CalcPopupWindowSizePixel()
4171 // count number of breaks and calc corresponding floating window size
4172 ImplToolItems::size_type nLines = ImplCountLineBreaks();
4174 if( nLines )
4175 ++nLines; // add the first line
4176 else
4178 // no breaks found: use quadratic layout
4179 nLines = static_cast<ImplToolItems::size_type>(ceil( sqrt( static_cast<double>(GetItemCount()) ) ));
4182 bool bPopup = mpData->mbAssumePopupMode;
4183 mpData->mbAssumePopupMode = true;
4185 Size aSize = CalcFloatingWindowSizePixel( nLines );
4187 mpData->mbAssumePopupMode = bPopup;
4188 return aSize;
4191 Size ToolBox::CalcFloatingWindowSizePixel()
4193 ImplToolItems::size_type nLines = ImplCountLineBreaks();
4194 ++nLines; // add the first line
4195 return CalcFloatingWindowSizePixel( nLines );
4198 Size ToolBox::CalcFloatingWindowSizePixel( ImplToolItems::size_type nCalcLines )
4200 bool bFloat = mpData->mbAssumeFloating;
4201 bool bDocking = mpData->mbAssumeDocked;
4203 // simulate floating mode and force reformat before calculating
4204 mpData->mbAssumeFloating = true;
4205 mpData->mbAssumeDocked = false;
4207 Size aSize = ImplCalcFloatSize( nCalcLines );
4209 mbFormat = true;
4210 mpData->mbAssumeFloating = bFloat;
4211 mpData->mbAssumeDocked = bDocking;
4213 return aSize;
4216 Size ToolBox::CalcMinimumWindowSizePixel()
4218 if( ImplIsFloatingMode() )
4219 return ImplCalcSize( mnFloatLines );
4220 else
4222 // create dummy toolbox for measurements
4223 VclPtrInstance< ToolBox > pToolBox( GetParent(), GetStyle() );
4225 // copy until first useful item
4226 for (auto const& item : mpData->m_aItems)
4228 pToolBox->CopyItem( *this, item.mnId );
4229 if( (item.meType == ToolBoxItemType::BUTTON) &&
4230 item.mbVisible && !ImplIsFixedControl( &item ) )
4231 break;
4234 // add to docking manager if required to obtain a drag area
4235 // (which is accounted for in calcwindowsizepixel)
4236 if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
4237 ImplGetDockingManager()->AddWindow( pToolBox );
4239 // account for menu
4240 if( IsMenuEnabled() )
4241 pToolBox->SetMenuType( GetMenuType() );
4243 pToolBox->SetAlign( GetAlign() );
4244 Size aSize = pToolBox->CalcWindowSizePixel( 1 );
4246 ImplGetDockingManager()->RemoveWindow( pToolBox );
4247 pToolBox->Clear();
4249 pToolBox.disposeAndClear();
4251 return aSize;
4255 void ToolBox::EnableCustomize( bool bEnable )
4257 mbCustomize = bEnable;
4260 void ToolBox::LoseFocus()
4262 ImplChangeHighlight( nullptr, true );
4264 DockingWindow::LoseFocus();
4267 // performs the action associated with an item, ie simulates clicking the item
4268 void ToolBox::TriggerItem( sal_uInt16 nItemId )
4270 mnHighItemId = nItemId;
4271 vcl::KeyCode aKeyCode( 0, 0 );
4272 ImplActivateItem( aKeyCode );
4275 // calls the button's action handler
4276 // returns true if action was called
4277 bool ToolBox::ImplActivateItem( vcl::KeyCode aKeyCode )
4279 bool bRet = true;
4280 if( mnHighItemId )
4282 ImplToolItem *pToolItem = ImplGetItem( mnHighItemId );
4284 // #107712#, activate can also be called for disabled entries
4285 if( pToolItem && !pToolItem->mbEnabled )
4286 return true;
4288 if( pToolItem && pToolItem->mpWindow && HasFocus() )
4290 ImplHideFocus();
4291 mbChangingHighlight = true; // avoid focus change due to loss of focus
4292 pToolItem->mpWindow->ImplControlFocus( GetFocusFlags::Tab );
4293 mbChangingHighlight = false;
4295 else
4297 mnDownItemId = mnCurItemId = mnHighItemId;
4298 if (pToolItem && (pToolItem->mnBits & ToolBoxItemBits::AUTOCHECK))
4300 if ( pToolItem->mnBits & ToolBoxItemBits::RADIOCHECK )
4302 if ( pToolItem->meState != TRISTATE_TRUE )
4303 SetItemState( pToolItem->mnId, TRISTATE_TRUE );
4305 else
4307 if ( pToolItem->meState != TRISTATE_TRUE )
4308 pToolItem->meState = TRISTATE_TRUE;
4309 else
4310 pToolItem->meState = TRISTATE_FALSE;
4313 mnMouseModifier = aKeyCode.GetModifier();
4314 mbIsKeyEvent = true;
4315 Activate();
4316 Click();
4318 // #107776# we might be destroyed in the selecthandler
4319 VclPtr<vcl::Window> xWindow = this;
4320 Select();
4321 if ( xWindow->IsDisposed() )
4322 return bRet;
4324 Deactivate();
4325 mbIsKeyEvent = false;
4326 mnMouseModifier = 0;
4329 else
4330 bRet = false;
4331 return bRet;
4334 static bool ImplCloseLastPopup( vcl::Window const *pParent )
4336 // close last popup toolbox (see also:
4337 // ImplHandleMouseFloatMode(...) in winproc.cxx )
4339 if( ImplGetSVData()->maWinData.mpFirstFloat )
4341 FloatingWindow* pLastLevelFloat = ImplGetSVData()->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
4342 // only close the floater if it is not our direct parent, which would kill ourself
4343 if( pLastLevelFloat && pLastLevelFloat != pParent )
4345 pLastLevelFloat->EndPopupMode( FloatWinPopupEndFlags::Cancel | FloatWinPopupEndFlags::CloseAll );
4346 return true;
4349 return false;
4352 // opens a drop down toolbox item
4353 // returns true if item was opened
4354 bool ToolBox::ImplOpenItem( vcl::KeyCode aKeyCode )
4356 sal_uInt16 nCode = aKeyCode.GetCode();
4357 bool bRet = true;
4359 // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
4360 if ( ((nCode == KEY_LEFT || nCode == KEY_RIGHT) && IsHorizontal())
4361 || ((nCode == KEY_UP || nCode == KEY_DOWN) && !IsHorizontal()) )
4362 return false;
4364 if( mpData->mbMenubuttonSelected )
4366 if( ImplCloseLastPopup( GetParent() ) )
4367 return bRet;
4368 mbIsKeyEvent = true;
4369 if ( maMenuButtonHdl.IsSet() )
4370 maMenuButtonHdl.Call( this );
4371 else
4372 ExecuteCustomMenu( mpData->maMenubuttonItem.maRect );
4373 mpData->mbMenubuttonWasLastSelected = true;
4374 mbIsKeyEvent = false;
4376 else if( mnHighItemId && ImplGetItem( mnHighItemId ) &&
4377 (ImplGetItem( mnHighItemId )->mnBits & ToolBoxItemBits::DROPDOWN) )
4379 mnDownItemId = mnCurItemId = mnHighItemId;
4380 mnCurPos = GetItemPos( mnCurItemId );
4381 mnLastFocusItemId = mnCurItemId; // save item id for possible later focus restore
4382 mnMouseModifier = aKeyCode.GetModifier();
4383 mbIsKeyEvent = true;
4384 Activate();
4386 mpData->mbDropDownByKeyboard = true;
4387 mpData->maDropdownClickHdl.Call( this );
4389 mbIsKeyEvent = false;
4390 mnMouseModifier = 0;
4392 else
4393 bRet = false;
4395 return bRet;
4398 void ToolBox::KeyInput( const KeyEvent& rKEvt )
4400 vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
4401 sal_uInt16 nCode = aKeyCode.GetCode();
4403 vcl::Window *pParent = ImplGetParent();
4404 bool bOldSchoolContainer = ((pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL);
4405 bool bParentIsContainer = bOldSchoolContainer || isContainerWindow(pParent);
4407 bool bForwardKey = false;
4408 bool bGrabFocusToDocument = false;
4410 // #107776# we might be destroyed in the keyhandler
4411 VclPtr<vcl::Window> xWindow = this;
4413 switch ( nCode )
4415 case KEY_UP:
4417 // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
4418 if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4419 break;
4420 if( !IsHorizontal() )
4421 ImplChangeHighlightUpDn( true );
4422 else
4423 ImplOpenItem( aKeyCode );
4425 break;
4426 case KEY_LEFT:
4428 if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4429 break;
4430 if( IsHorizontal() )
4431 ImplChangeHighlightUpDn( true );
4432 else
4433 ImplOpenItem( aKeyCode );
4435 break;
4436 case KEY_DOWN:
4438 if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4439 break;
4440 if( !IsHorizontal() )
4441 ImplChangeHighlightUpDn( false );
4442 else
4443 ImplOpenItem( aKeyCode );
4445 break;
4446 case KEY_RIGHT:
4448 if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4449 break;
4450 if( IsHorizontal() )
4451 ImplChangeHighlightUpDn( false );
4452 else
4453 ImplOpenItem( aKeyCode );
4455 break;
4456 case KEY_PAGEUP:
4457 if ( mnCurLine > 1 )
4459 if( mnCurLine > mnVisLines )
4460 mnCurLine = mnCurLine - mnVisLines;
4461 else
4462 mnCurLine = 1;
4463 mbFormat = true;
4464 ImplFormat();
4465 InvalidateSpin();
4466 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine ) );
4468 break;
4469 case KEY_PAGEDOWN:
4470 if ( mnCurLine+mnVisLines-1 < mnCurLines )
4472 if( mnCurLine + 2*mnVisLines-1 < mnCurLines )
4473 mnCurLine = mnCurLine + mnVisLines;
4474 else
4475 mnCurLine = mnCurLines;
4476 mbFormat = true;
4477 ImplFormat();
4478 InvalidateSpin();
4479 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine ) );
4481 break;
4482 case KEY_END:
4484 ImplChangeHighlight( nullptr );
4485 ImplChangeHighlightUpDn( false );
4487 break;
4488 case KEY_HOME:
4490 ImplChangeHighlight( nullptr );
4491 ImplChangeHighlightUpDn( true );
4493 break;
4494 case KEY_ESCAPE:
4496 if( !ImplIsFloatingMode() && bParentIsContainer )
4497 DockingWindow::KeyInput( rKEvt );
4498 else
4500 // send focus to document pane
4501 vcl::Window *pWin = this;
4502 while( pWin )
4504 if( !pWin->GetParent() )
4506 pWin->ImplGetFrameWindow()->GetWindow( GetWindowType::Client )->GrabFocus();
4507 break;
4509 pWin = pWin->GetParent();
4513 break;
4514 case KEY_RETURN:
4516 // #107712#, disabled entries are selectable now
4517 // leave toolbox and move focus to document
4518 if( mnHighItemId )
4520 ImplToolItem *pItem = ImplGetItem(mnHighItemId);
4521 if (!pItem || !pItem->mbEnabled)
4523 bGrabFocusToDocument = true;
4526 if( !bGrabFocusToDocument )
4527 bForwardKey = !ImplActivateItem( aKeyCode );
4529 break;
4530 case KEY_SPACE:
4532 ImplOpenItem( aKeyCode );
4534 break;
4535 default:
4537 sal_uInt16 aKeyGroup = aKeyCode.GetGroup();
4538 ImplToolItem *pItem = nullptr;
4539 if( mnHighItemId )
4540 pItem = ImplGetItem( mnHighItemId );
4541 // #i13931# forward alphanum keyinput into embedded control
4542 if( (aKeyGroup == KEYGROUP_NUM || aKeyGroup == KEYGROUP_ALPHA ) && pItem && pItem->mpWindow && pItem->mbEnabled )
4544 vcl::Window *pFocusWindow = Application::GetFocusWindow();
4545 ImplHideFocus();
4546 mbChangingHighlight = true; // avoid focus change due to loss of focus
4547 pItem->mpWindow->ImplControlFocus( GetFocusFlags::Tab );
4548 mbChangingHighlight = false;
4549 if( pFocusWindow != Application::GetFocusWindow() )
4550 Application::GetFocusWindow()->KeyInput( rKEvt );
4552 else
4554 // do nothing to avoid key presses going into the document
4555 // while the toolbox has the focus
4556 // just forward function and special keys and combinations with Alt-key
4557 if( aKeyGroup == KEYGROUP_FKEYS || aKeyGroup == KEYGROUP_MISC || aKeyCode.IsMod2() )
4558 bForwardKey = true;
4563 if ( xWindow->IsDisposed() )
4564 return;
4566 // #107251# move focus away if this toolbox was disabled during keyinput
4567 if (HasFocus() && mpData->mbKeyInputDisabled && bParentIsContainer)
4569 vcl::Window *pFocusControl = pParent->ImplGetDlgWindow( 0, GetDlgWindowType::First );
4570 if ( pFocusControl && pFocusControl != this )
4571 pFocusControl->ImplControlFocus( GetFocusFlags::Init );
4574 // #107712#, leave toolbox
4575 if( bGrabFocusToDocument )
4577 GrabFocusToDocument();
4578 return;
4581 if( bForwardKey )
4582 DockingWindow::KeyInput( rKEvt );
4585 // returns the current toolbox line of the item
4586 ToolBox::ImplToolItems::size_type ToolBox::ImplGetItemLine( ImplToolItem const * pCurrentItem )
4588 ImplToolItems::size_type nLine = 1;
4589 for (auto const& item : mpData->m_aItems)
4591 if ( item.mbBreak )
4592 ++nLine;
4593 if( &item == pCurrentItem)
4594 break;
4596 return nLine;
4599 // returns the first displayable item in the given line
4600 ImplToolItem* ToolBox::ImplGetFirstValidItem( ImplToolItems::size_type nLine )
4602 if( !nLine || nLine > mnCurLines )
4603 return nullptr;
4605 nLine--;
4607 ImplToolItems::iterator it = mpData->m_aItems.begin();
4608 while( it != mpData->m_aItems.end() )
4610 // find correct line
4611 if ( it->mbBreak )
4612 nLine--;
4613 if( !nLine )
4615 // find first useful item
4616 while( it != mpData->m_aItems.end() && ((it->meType != ToolBoxItemType::BUTTON) ||
4617 /*!it->mbEnabled ||*/ !it->mbVisible || ImplIsFixedControl( &(*it) )) )
4619 ++it;
4620 if( it == mpData->m_aItems.end() || it->mbBreak )
4621 return nullptr; // no valid items in this line
4623 return &(*it);
4625 ++it;
4628 return (it == mpData->m_aItems.end()) ? nullptr : &(*it);
4631 ToolBox::ImplToolItems::size_type ToolBox::ImplFindItemPos( const ImplToolItem* pItem, const ImplToolItems& rList )
4633 if( pItem )
4635 for( ImplToolItems::size_type nPos = 0; nPos < rList.size(); ++nPos )
4636 if( &rList[ nPos ] == pItem )
4637 return nPos;
4639 return ITEM_NOTFOUND;
4642 void ToolBox::ChangeHighlight( ImplToolItems::size_type nPos )
4644 if ( nPos < GetItemCount() ) {
4645 ImplGrabFocus( GetFocusFlags::NONE );
4646 ImplChangeHighlight ( ImplGetItem ( GetItemId ( nPos ) ) );
4650 void ToolBox::ImplChangeHighlight( ImplToolItem const * pItem, bool bNoGrabFocus )
4652 // avoid recursion due to focus change
4653 if( mbChangingHighlight )
4654 return;
4656 mbChangingHighlight = true;
4658 ImplToolItem* pOldItem = nullptr;
4660 if ( mnHighItemId )
4662 ImplHideFocus();
4663 ImplToolItems::size_type nPos = GetItemPos( mnHighItemId );
4664 pOldItem = ImplGetItem( mnHighItemId );
4665 // #i89962# ImplDrawItem can cause Invalidate/Update
4666 // which will in turn ImplShowFocus again
4667 // set mnHighItemId to 0 already to prevent this hen/egg problem
4668 mnHighItemId = 0;
4669 InvalidateItem(nPos);
4670 CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nPos ) );
4673 if( !bNoGrabFocus && pItem != pOldItem && pOldItem && pOldItem->mpWindow )
4675 // move focus into toolbox
4676 GrabFocus();
4679 if( pItem )
4681 ImplToolItems::size_type aPos = ToolBox::ImplFindItemPos( pItem, mpData->m_aItems );
4682 if( aPos != ITEM_NOTFOUND)
4684 // check for line breaks
4685 ImplToolItems::size_type nLine = ImplGetItemLine( pItem );
4687 if( nLine >= mnCurLine + mnVisLines )
4689 mnCurLine = nLine - mnVisLines + 1;
4690 mbFormat = true;
4692 else if ( nLine < mnCurLine )
4694 mnCurLine = nLine;
4695 mbFormat = true;
4698 if( mbFormat )
4700 ImplFormat();
4703 mnHighItemId = pItem->mnId;
4704 InvalidateItem(aPos);
4706 if( mbSelection )
4707 mnCurPos = aPos;
4708 ImplShowFocus();
4710 if( pItem->mpWindow )
4711 pItem->mpWindow->GrabFocus();
4712 if( pItem != pOldItem )
4713 CallEventListeners( VclEventId::ToolboxHighlight );
4716 else
4718 ImplHideFocus();
4719 mnHighItemId = 0;
4720 mnCurPos = ITEM_NOTFOUND;
4723 mbChangingHighlight = false;
4726 // check for keyboard accessible items
4727 static bool ImplIsValidItem( const ImplToolItem* pItem, bool bNotClipped )
4729 bool bValid = (pItem && pItem->meType == ToolBoxItemType::BUTTON && pItem->mbVisible && !ImplIsFixedControl( pItem )
4730 && pItem->mbEnabled);
4731 if( bValid && bNotClipped && pItem->IsClipped() )
4732 bValid = false;
4733 return bValid;
4736 bool ToolBox::ChangeHighlightUpDn( bool bUp )
4738 return ImplChangeHighlightUpDn(bUp, /*bNoCycle*/ false);
4741 bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
4743 ImplToolItem* pToolItem = ImplGetItem( mnHighItemId );
4745 if( !pToolItem || !mnHighItemId )
4747 // menubutton highlighted ?
4748 if( mpData->mbMenubuttonSelected )
4750 mpData->mbMenubuttonSelected = false;
4751 if( bUp )
4753 // select last valid non-clipped item
4754 ImplToolItem* pItem = nullptr;
4755 auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(),
4756 [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); });
4757 if( it != mpData->m_aItems.rend() )
4758 pItem = &(*it);
4760 InvalidateMenuButton();
4761 ImplChangeHighlight( pItem );
4763 else
4765 // select first valid non-clipped item
4766 ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
4767 [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); });
4768 if( it != mpData->m_aItems.end() )
4770 InvalidateMenuButton();
4771 ImplChangeHighlight( &(*it) );
4774 return true;
4777 if( bUp )
4779 // Select first valid item
4780 ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
4781 [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); });
4783 // select the menu button if a clipped item would be selected
4784 if( (it != mpData->m_aItems.end() && &(*it) == ImplGetFirstClippedItem()) && IsMenuEnabled() )
4786 ImplChangeHighlight( nullptr );
4787 mpData->mbMenubuttonSelected = true;
4788 InvalidateMenuButton();
4790 else
4791 ImplChangeHighlight( (it != mpData->m_aItems.end()) ? &(*it) : nullptr );
4792 return true;
4794 else
4796 // Select last valid item
4798 // docked toolbars have the menubutton as last item - if this button is enabled
4799 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4801 ImplChangeHighlight( nullptr );
4802 mpData->mbMenubuttonSelected = true;
4803 InvalidateMenuButton();
4805 else
4807 ImplToolItem* pItem = nullptr;
4808 auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(),
4809 [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); });
4810 if( it != mpData->m_aItems.rend() )
4811 pItem = &(*it);
4813 ImplChangeHighlight( pItem );
4815 return true;
4819 assert(pToolItem);
4821 ImplToolItems::size_type pos = ToolBox::ImplFindItemPos( pToolItem, mpData->m_aItems );
4822 ImplToolItems::size_type nCount = mpData->m_aItems.size();
4824 ImplToolItems::size_type i=0;
4827 if( bUp )
4829 if( !pos-- )
4831 if( bNoCycle )
4832 return false;
4834 // highlight the menu button if it is the last item
4835 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4837 ImplChangeHighlight( nullptr );
4838 mpData->mbMenubuttonSelected = true;
4839 InvalidateMenuButton();
4840 return true;
4842 else
4843 pos = nCount-1;
4846 else
4848 if( ++pos >= nCount )
4850 if( bNoCycle )
4851 return false;
4853 // highlight the menu button if it is the last item
4854 if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
4856 ImplChangeHighlight( nullptr );
4857 mpData->mbMenubuttonSelected = true;
4858 InvalidateMenuButton();
4859 return true;
4861 else
4862 pos = 0;
4866 pToolItem = &mpData->m_aItems[pos];
4868 if ( ImplIsValidItem( pToolItem, false ) )
4869 break;
4871 } while( ++i < nCount);
4873 if( pToolItem->IsClipped() && IsMenuEnabled() )
4875 // select the menu button if a clipped item would be selected
4876 ImplChangeHighlight( nullptr );
4877 mpData->mbMenubuttonSelected = true;
4878 InvalidateMenuButton();
4880 else if( i != nCount )
4881 ImplChangeHighlight( pToolItem );
4882 else
4883 return false;
4885 return true;
4888 void ToolBox::ImplShowFocus()
4890 if( mnHighItemId && HasFocus() )
4892 ImplToolItem* pItem = ImplGetItem( mnHighItemId );
4893 if (pItem && pItem->mpWindow && !pItem->mpWindow->IsDisposed())
4895 vcl::Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow.get() : pItem->mpWindow.get();
4896 pWin->ImplGetWindowImpl()->mbDrawSelectionBackground = true;
4897 pWin->Invalidate();
4902 void ToolBox::ImplHideFocus()
4904 if( mnHighItemId )
4906 mpData->mbMenubuttonWasLastSelected = false;
4907 ImplToolItem* pItem = ImplGetItem( mnHighItemId );
4908 if( pItem && pItem->mpWindow )
4910 vcl::Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow.get() : pItem->mpWindow.get();
4911 pWin->ImplGetWindowImpl()->mbDrawSelectionBackground = false;
4912 pWin->Invalidate();
4916 if ( mpData && mpData->mbMenubuttonSelected )
4918 mpData->mbMenubuttonWasLastSelected = true;
4919 // remove highlight from menubutton
4920 mpData->mbMenubuttonSelected = false;
4921 InvalidateMenuButton();
4925 void ToolBox::ImplDisableFlatButtons()
4927 #ifdef _WIN32 // Check in the Windows registry if an AT tool wants no flat toolboxes
4928 static bool bInit = false, bValue = false;
4929 if( ! bInit )
4931 bInit = true;
4932 HKEY hkey;
4934 if( ERROR_SUCCESS == RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\LibreOffice\\Accessibility\\AtToolSupport", &hkey) )
4936 DWORD dwType = 0;
4937 wchar_t Data[6]; // possible values: "true", "false", "1", "0", DWORD
4938 DWORD cbData = sizeof(Data);
4940 if( ERROR_SUCCESS == RegQueryValueExW(hkey, L"DisableFlatToolboxButtons",
4941 nullptr, &dwType, reinterpret_cast<LPBYTE>(Data), &cbData) )
4943 switch (dwType)
4945 case REG_SZ:
4946 bValue = ((0 == wcsicmp(Data, L"1")) || (0 == wcsicmp(Data, L"true")));
4947 break;
4948 case REG_DWORD:
4949 bValue = static_cast<bool>(reinterpret_cast<DWORD *>(Data)[0]);
4950 break;
4953 RegCloseKey(hkey);
4956 if( bValue )
4957 mnOutStyle &= ~TOOLBOX_STYLE_FLAT;
4958 #else
4959 (void) this; // loplugin:staticmethods
4960 #endif
4963 void ToolBox::SetToolbarLayoutMode( ToolBoxLayoutMode eLayout )
4965 if ( meLayoutMode != eLayout )
4966 meLayoutMode = eLayout;
4969 void ToolBox::SetToolBoxTextPosition( ToolBoxTextPosition ePosition )
4971 meTextPosition = ePosition;
4974 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */