LibreOffice Module vcl (master) 1
toolbox.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <vcl/toolbox.hxx>
21#include <vcl/event.hxx>
22#include <vcl/decoview.hxx>
24#include <vcl/svapp.hxx>
25#include <vcl/help.hxx>
26#include <vcl/mnemonic.hxx>
27#include <vcl/gradient.hxx>
28#include <vcl/layout.hxx>
29#include <vcl/menu.hxx>
30#include <vcl/settings.hxx>
31#include <vcl/ptrstyle.hxx>
32#include <bitmaps.hlst>
33#include <toolbarvalue.hxx>
34
35#include <tools/poly.hxx>
36#include <sal/log.hxx>
37#include <o3tl/string_view.hxx>
38#include <osl/diagnose.h>
39
40#include <accel.hxx>
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
48
49#include <cstdlib>
50#include <map>
51#include <string_view>
52#include <vector>
53#include <math.h>
54
56
57#define SMALLBUTTON_HSIZE 7
58#define SMALLBUTTON_VSIZE 7
59
60#define SMALLBUTTON_OFF_NORMAL_X 3
61#define SMALLBUTTON_OFF_NORMAL_Y 3
62
63#define TB_TEXTOFFSET 2
64#define TB_IMAGETEXTOFFSET 3
65#define TB_LINESPACING 3
66#define TB_SPIN_SIZE 14
67#define TB_SPIN_OFFSET 2
68#define TB_BORDER_OFFSET1 4
69#define TB_BORDER_OFFSET2 2
70#define TB_MAXLINES 5
71#define TB_MAXNOSCROLL 32765
72
73#define TB_DRAGWIDTH 8 // the default width of the drag grip
74
75#define TB_CALCMODE_HORZ 1
76#define TB_CALCMODE_VERT 2
77#define TB_CALCMODE_FLOAT 3
78
79#define TB_WBLINESIZING (WB_SIZEABLE | WB_DOCKABLE | WB_SCROLL)
80
81#define DOCK_LINEHSIZE (sal_uInt16(0x0001))
82#define DOCK_LINEVSIZE (sal_uInt16(0x0002))
83#define DOCK_LINERIGHT (sal_uInt16(0x1000))
84#define DOCK_LINEBOTTOM (sal_uInt16(0x2000))
85#define DOCK_LINELEFT (sal_uInt16(0x4000))
86#define DOCK_LINETOP (sal_uInt16(0x8000))
87#define DOCK_LINEOFFSET 3
88
90{
91private:
97 sal_uInt16 mnLineMode;
98 ToolBox::ImplToolItems::size_type mnStartLines;
99
100 ImplTBDragMgr(const ImplTBDragMgr&) = delete;
102
103public:
105
106 void StartDragging( ToolBox* pDragBox, const Point& rPos, const tools::Rectangle& rRect, sal_uInt16 nLineMode );
107 void Dragging( const Point& rPos );
108 void EndDragging( bool bOK = true );
109 DECL_LINK( SelectHdl, Accelerator&, void );
110};
111
112
114{
115 ImplSVData* pSVData = ImplGetSVData();
116 if ( !pSVData->maCtrlData.mpTBDragMgr )
117 pSVData->maCtrlData.mpTBDragMgr = new ImplTBDragMgr;
118 return pSVData->maCtrlData.mpTBDragMgr;
119}
120
121int ToolBox::ImplGetDragWidth( const vcl::Window& rWindow, bool bHorz )
122{
123 return ImplGetDragWidth(*rWindow.GetOutDev(), bHorz);
124}
125int ToolBox::ImplGetDragWidth( const vcl::RenderContext& rRenderContext, bool bHorz )
126{
127 int nWidth = TB_DRAGWIDTH;
129 {
130
131 ImplControlValue aControlValue;
132 tools::Rectangle aContent, aBound;
133 tools::Rectangle aArea( Point(), rRenderContext.GetOutputSizePixel() );
134
137 aArea, ControlState::NONE, aControlValue, aBound, aContent) )
138 {
139 nWidth = bHorz ? aContent.GetWidth() : aContent.GetHeight();
140 }
141 }
142
143 // increase the hit area of the drag handle according to DPI scale factor
144 nWidth *= rRenderContext.GetDPIScaleFactor();
145
146 return nWidth;
147}
148
150{
151 return ToolBox::ImplGetDragWidth( *this, mbHorz );
152}
153
154static ButtonType determineButtonType( ImplToolItem const * pItem, ButtonType defaultType )
155{
156 ButtonType tmpButtonType = defaultType;
158 if ( nBits != ToolBoxItemBits::NONE ) // item has custom setting
159 {
160 tmpButtonType = ButtonType::SYMBOLTEXT;
161 if ( nBits == ToolBoxItemBits::TEXT_ONLY )
162 tmpButtonType = ButtonType::TEXT;
163 else if ( nBits == ToolBoxItemBits::ICON_ONLY )
164 tmpButtonType = ButtonType::SYMBOLONLY;
165 }
166 return tmpButtonType;
167}
168
170{
172 if( pWrapper )
173 {
174 if ( ImplIsFloatingMode() || pWrapper->IsLocked() )
175 pWrapper->SetDragArea( tools::Rectangle() );
176 else
177 {
180 else
182 }
183 }
184}
185
187 tools::Long& rRight, tools::Long& rBottom ) const
188{
190 {
191 // no border in floating mode
192 rLeft = rTop = rRight = rBottom = 0;
193 return;
194 }
195
197
198 // reserve DragArea only for dockable toolbars
199 int dragwidth = ( pWrapper && !pWrapper->IsLocked() ) ? ImplGetDragWidth() : 0;
200
201 // no shadow border for dockable toolbars and toolbars with WB_NOSHADOW bit set, e.g. Calc's formulabar
202 int borderwidth = ( pWrapper || mnWinStyle & WB_NOSHADOW ) ? 0 : 2;
203
204 if ( eAlign == WindowAlign::Top )
205 {
206 rLeft = borderwidth+dragwidth;
207 rTop = borderwidth;
208 rRight = borderwidth;
209 rBottom = 0;
210 }
211 else if ( eAlign == WindowAlign::Left )
212 {
213 rLeft = borderwidth;
214 rTop = borderwidth+dragwidth;
215 rRight = 0;
216 rBottom = borderwidth;
217 }
218 else if ( eAlign == WindowAlign::Bottom )
219 {
220 rLeft = borderwidth+dragwidth;
221 rTop = 0;
222 rRight = borderwidth;
223 rBottom = borderwidth;
224 }
225 else
226 {
227 rLeft = 0;
228 rTop = borderwidth+dragwidth;
229 rRight = borderwidth;
230 rBottom = borderwidth;
231 }
232}
233
235{
236 // remove any pending invalidates to avoid
237 // have them triggered when paint is locked (see mpData->mbIsPaintLocked)
238 // which would result in erasing the background only and not painting any items
239 // this must not be done when we're already in Paint()
240
241 // this is only required for transparent toolbars (see ImplDrawTransparentBackground() )
242 if( !IsBackground() && HasPaintEvent() && !IsInPaint() )
244}
245
247 const tools::Rectangle &aDragArea, int nDragWidth, WindowAlign eAlign, bool bHorz)
248{
249 bool bNativeOk = false;
251 const Size aSz( rRenderContext.GetOutputSizePixel() );
252 if (rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ePart))
253 {
254 ToolbarValue aToolbarValue;
255 aToolbarValue.maGripRect = aDragArea;
256
257 tools::Rectangle aCtrlRegion(Point(), aSz);
258
259 bNativeOk = rRenderContext.DrawNativeControl( ControlType::Toolbar, ePart,
260 aCtrlRegion, ControlState::ENABLED, aToolbarValue, OUString() );
261 }
262
263 if( bNativeOk )
264 return;
265
266 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
267 rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
268 rRenderContext.SetFillColor(rStyleSettings.GetShadowColor());
269
270 float fScaleFactor = rRenderContext.GetDPIScaleFactor();
271
272 if (eAlign == WindowAlign::Top || eAlign == WindowAlign::Bottom)
273 {
274 int height = static_cast<int>(0.6 * aSz.Height() + 0.5);
275 int i = (aSz.Height() - height) / 2;
276 height += i;
277 while (i <= height)
278 {
279 int x = nDragWidth / 2;
280 rRenderContext.DrawEllipse(tools::Rectangle(Point(x, i), Size(2 * fScaleFactor, 2 * fScaleFactor)));
281 i += 4 * fScaleFactor;
282 }
283 }
284 else
285 {
286 int width = static_cast<int>(0.6 * aSz.Width() + 0.5);
287 int i = (aSz.Width() - width) / 2;
288 width += i;
289 while (i <= width)
290 {
291 int y = nDragWidth / 2;
292 rRenderContext.DrawEllipse(tools::Rectangle(Point(i, y), Size(2 * fScaleFactor, 2 * fScaleFactor)));
293 i += 4 * fScaleFactor;
294 }
295 }
296}
297
299{
301 if( pWrapper && !pWrapper->GetDragArea().IsEmpty() )
302 {
303 // execute pending paint requests
305 ImplDrawGrip( rRenderContext, pWrapper->GetDragArea(),
307 }
308}
309
311{
312 // draw a nice gradient
313
314 Color startCol, endCol;
315 const StyleSettings rSettings = rRenderContext.GetSettings().GetStyleSettings();
316
317 startCol = rSettings.GetFaceGradientColor();
318 endCol = rSettings.GetFaceColor();
319 if (rSettings.GetHighContrastMode())
320 // no 'extreme' gradient when high contrast
321 startCol = endCol;
322
323 Gradient g;
324 g.SetAngle(Degree10(mbHorz ? 0 : 900));
325 g.SetStyle(GradientStyle::Linear);
326
327 g.SetStartColor(startCol);
328 g.SetEndColor(endCol);
329
330 bool bLineColor = rRenderContext.IsLineColor();
331 Color aOldCol = rRenderContext.GetLineColor();
332 rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetShadowColor());
333
334 Size aFullSz(GetOutputSizePixel());
335 Size aLineSz(aFullSz);
336
337 // use the linesize only when floating
338 // full window height is used when docked (single line)
339 if (ImplIsFloatingMode())
340 {
341 tools::Long nLineSize;
342 if (mbHorz)
343 {
344 nLineSize = mnMaxItemHeight;
346 nLineSize = mnWinHeight;
347
348 aLineSz.setHeight( nLineSize );
349 }
350 else
351 {
352 nLineSize = mnMaxItemWidth;
353 aLineSz.setWidth( nLineSize );
354 }
355 }
356
357 tools::Long nLeft, nTop, nRight, nBottom;
358 ImplCalcBorder(meAlign, nLeft, nTop, nRight, nBottom);
359
360 Size aTopLineSz(aLineSz);
361 Size aBottomLineSz(aLineSz);
362
363 if (mnWinStyle & WB_BORDER)
364 {
365 if (mbHorz)
366 {
367 aTopLineSz.AdjustHeight(TB_BORDER_OFFSET2 + nTop );
368 aBottomLineSz.AdjustHeight(TB_BORDER_OFFSET2 + nBottom );
369
370 if (mnCurLines == 1)
371 aTopLineSz.AdjustHeight(TB_BORDER_OFFSET2 + nBottom );
372 }
373 else
374 {
375 aTopLineSz.AdjustWidth(TB_BORDER_OFFSET1 + nLeft );
376 aBottomLineSz.AdjustWidth(TB_BORDER_OFFSET1 + nRight );
377
378 if (mnCurLines == 1)
379 aTopLineSz.AdjustWidth(TB_BORDER_OFFSET1 + nLeft );
380 }
381 }
382
383 if (mbLineSpacing)
384 {
385 if (mbHorz)
386 {
388 if (mnCurLines > 1)
389 aTopLineSz.AdjustHeight(TB_LINESPACING );
390 }
391 else
392 {
393 aLineSz.AdjustWidth(TB_LINESPACING );
394 if (mnCurLines > 1)
395 aTopLineSz.AdjustWidth(TB_LINESPACING );
396 }
397 }
398
399 if (mbHorz)
400 {
401 tools::Long y = 0;
402
403 rRenderContext.DrawGradient(tools::Rectangle(0, y, aTopLineSz.Width(), y + aTopLineSz.Height()), g);
404 y += aTopLineSz.Height();
405
406 while (y < (mnDY - aBottomLineSz.Height()))
407 {
408 rRenderContext.DrawGradient(tools::Rectangle(0, y, aLineSz.Width(), y + aLineSz.Height()), g);
409 y += aLineSz.Height();
410 }
411
412 rRenderContext.DrawGradient(tools::Rectangle(0, y, aBottomLineSz.Width(), y + aBottomLineSz.Height()), g);
413 }
414 else
415 {
416 tools::Long x = 0;
417
418 rRenderContext.DrawGradient(tools::Rectangle(x, 0, x + aTopLineSz.Width(), aTopLineSz.Height()), g);
419 x += aTopLineSz.Width();
420
421 while (x < (mnDX - aBottomLineSz.Width()))
422 {
423 rRenderContext.DrawGradient(tools::Rectangle(x, 0, x + aLineSz.Width(), aLineSz.Height()), g);
424 x += aLineSz.Width();
425 }
426
427 rRenderContext.DrawGradient(tools::Rectangle( x, 0, x + aBottomLineSz.Width(), aBottomLineSz.Height()), g);
428 }
429
430 if( bLineColor )
431 rRenderContext.SetLineColor( aOldCol );
432
433}
434
436{
437 // use NWF
438 tools::Rectangle aCtrlRegion(Point(), GetOutputSizePixel());
439
441 aCtrlRegion, ControlState::ENABLED, ImplControlValue(), OUString() );
442}
443
445{
446 // just invalidate to trigger paint of the parent
447 const bool bOldPaintLock = mpData->mbIsPaintLocked;
448 mpData->mbIsPaintLocked = true;
449
450 // send an invalidate to the first opaque parent and invalidate the whole hierarchy from there (noclipchildren)
452
453 mpData->mbIsPaintLocked = bOldPaintLock;
454}
455
456void ToolBox::ImplDrawConstantBackground(vcl::RenderContext& rRenderContext, const vcl::Region &rRegion, bool bIsInPopupMode)
457{
458 // draw a constant color
459 if (!bIsInPopupMode)
460 {
461 // default background
462 rRenderContext.Erase(rRegion.GetBoundRect());
463 }
464 else
465 {
466 // use different color in popupmode
467 const StyleSettings rSettings = rRenderContext.GetSettings().GetStyleSettings();
468 Wallpaper aWallpaper(rSettings.GetFaceGradientColor());
469 rRenderContext.DrawWallpaper(rRegion.GetBoundRect(), aWallpaper);
470 }
471}
472
474{
475 // execute pending paint requests
477
479 bool bIsInPopupMode = ImplIsInPopupMode();
480
481 vcl::Region aPaintRegion(rRect);
482
483 // make sure we do not invalidate/erase too much
484 if (IsInPaint())
485 aPaintRegion.Intersect(GetOutDev()->GetActiveClipRegion());
486
487 rRenderContext.Push(vcl::PushFlags::CLIPREGION);
488 rRenderContext.IntersectClipRegion( aPaintRegion );
489
490 if (!pWrapper)
491 {
492 // no gradient for ordinary toolbars (not dockable)
493 if( !IsBackground() && !IsInPaint() )
494 ImplDrawTransparentBackground(aPaintRegion);
495 else
496 ImplDrawConstantBackground(rRenderContext, aPaintRegion, bIsInPopupMode);
497 }
498 else
499 {
500 // toolbars known to the dockingmanager will be drawn using NWF or a gradient
501 // docked toolbars are transparent and NWF is already used in the docking area which is their common background
502 // so NWF is used here for floating toolbars only
503 bool bNativeOk = false;
505 bNativeOk = ImplDrawNativeBackground(rRenderContext);
506 if (!bNativeOk)
507 {
509 const bool isHeader = GetAlign() == WindowAlign::Top && !rSetting.GetPersonaHeader().IsEmpty();
510 const bool isFooter = GetAlign() == WindowAlign::Bottom && !rSetting.GetPersonaFooter().IsEmpty();
511 if (!IsBackground() || isHeader || isFooter)
512 {
513 if (!IsInPaint())
514 ImplDrawTransparentBackground(aPaintRegion);
515 }
516 else
517 ImplDrawGradientBackground(rRenderContext);
518 }
519 }
520
521 // restore clip region
522 rRenderContext.Pop();
523}
524
525void ToolBox::ImplErase(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect, bool bHighlight, bool bHasOpenPopup)
526{
527 // the background of non NWF buttons is painted in a constant color
528 // to have the same highlight color (transparency in DrawSelectionBackground())
529 // items with open popups will also painted using a constant color
530 if (!mpData->mbNativeButtons &&
531 (bHighlight || !(GetStyle() & WB_3DLOOK)))
532 {
533 if (GetStyle() & WB_3DLOOK)
534 {
536 rRenderContext.SetLineColor();
537 if (bHasOpenPopup)
538 // choose the same color as the popup will use
539 rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetFaceColor());
540 else
541 rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor());
542
543 rRenderContext.DrawRect(rRect);
544 rRenderContext.Pop();
545 }
546 else
547 ImplDrawBackground(rRenderContext, rRect);
548 }
549 else
550 ImplDrawBackground(rRenderContext, rRect);
551}
552
554{
555 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
556 tools::Long nDX = mnDX;
557 tools::Long nDY = mnDY;
558
560
561 // draw borders for ordinary toolbars only (not dockable), do not draw borders for toolbars with WB_NOSHADOW bit set,
562 // e.g. Calc's formulabar
563
564 if( pWrapper || mnWinStyle & WB_NOSHADOW )
565 return;
566
568 {
569 // draw bottom border
570 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
571 rRenderContext.DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
572 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
573 rRenderContext.DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
574 }
575 else
576 {
577 // draw top border
578 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
579 rRenderContext.DrawLine( Point( 0, 0 ), Point( nDX-1, 0 ) );
580 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
581 rRenderContext.DrawLine( Point( 0, 1 ), Point( nDX-1, 1 ) );
582
584 {
586 {
587 // draw left-bottom border
588 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
589 rRenderContext.DrawLine( Point( 0, 0 ), Point( 0, nDY-1 ) );
590 rRenderContext.DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
591 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
592 rRenderContext.DrawLine( Point( 1, 1 ), Point( 1, nDY-3 ) );
593 rRenderContext.DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
594 }
595 else
596 {
597 // draw right-bottom border
598 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
599 rRenderContext.DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-3 ) );
600 rRenderContext.DrawLine( Point( 0, nDY-2 ), Point( nDX-2, nDY-2 ) );
601 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
602 rRenderContext.DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
603 rRenderContext.DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
604 }
605 }
606 }
607
609 {
610 // draw right border
611 rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
612 rRenderContext.DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-1 ) );
613 rRenderContext.SetLineColor( rStyleSettings.GetLightColor() );
614 rRenderContext.DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
615 }
616}
617
618static bool ImplIsFixedControl( const ImplToolItem *pItem )
619{
620 return ( pItem->mpWindow &&
621 (pItem->mbNonInteractiveWindow ||
624 pItem->mpWindow->GetType() == WindowType::GROUPBOX) );
625}
626
628{
629 for (auto & item : mpData->m_aItems)
630 {
631 if( item.IsClipped() )
632 return &item;
633 }
634 return nullptr;
635}
636
637Size ToolBox::ImplCalcSize( ImplToolItems::size_type nCalcLines, sal_uInt16 nCalcMode )
638{
639 sal_Int32 nMax;
640 tools::Long nLeft = 0;
641 tools::Long nTop = 0;
642 tools::Long nRight = 0;
643 tools::Long nBottom = 0;
644 Size aSize;
645 WindowAlign eOldAlign = meAlign;
646 bool bOldHorz = mbHorz;
647 bool bOldAssumeDocked = mpData->mbAssumeDocked;
648 bool bOldAssumeFloating = mpData->mbAssumeFloating;
649
650 if ( nCalcMode )
651 {
652 bool bOldFloatingMode = ImplIsFloatingMode();
653
654 mpData->mbAssumeDocked = false;
655 mpData->mbAssumeFloating = false;
656
657 if ( nCalcMode == TB_CALCMODE_HORZ )
658 {
659 mpData->mbAssumeDocked = true; // force non-floating mode during calculation
660 ImplCalcBorder( WindowAlign::Top, nLeft, nTop, nRight, nBottom );
661 mbHorz = true;
662 if ( mbHorz != bOldHorz )
664 }
665 else if ( nCalcMode == TB_CALCMODE_VERT )
666 {
667 mpData->mbAssumeDocked = true; // force non-floating mode during calculation
668 ImplCalcBorder( WindowAlign::Left, nLeft, nTop, nRight, nBottom );
669 mbHorz = false;
670 if ( mbHorz != bOldHorz )
672 }
673 else if ( nCalcMode == TB_CALCMODE_FLOAT )
674 {
675 mpData->mbAssumeFloating = true; // force non-floating mode during calculation
676 nLeft = nTop = nRight = nBottom = 0;
677 mbHorz = true;
678 if ( mbHorz != bOldHorz )
680 }
681
682 if ( (meAlign != eOldAlign) || (mbHorz != bOldHorz) ||
683 (ImplIsFloatingMode() != bOldFloatingMode ) )
684 mbCalc = true;
685 }
686 else
687 ImplCalcBorder( meAlign, nLeft, nTop, nRight, nBottom );
688
689 ImplCalcItem();
690
691 if( !nCalcMode && ImplIsFloatingMode() )
692 {
693 aSize = ImplCalcFloatSize( nCalcLines );
694 }
695 else
696 {
697 if ( mbHorz )
698 {
700 aSize.setHeight( nCalcLines * mnWinHeight );
701 else
702 aSize.setHeight( nCalcLines * mnMaxItemHeight );
703
704 if ( mbLineSpacing )
705 aSize.AdjustHeight((nCalcLines-1)*TB_LINESPACING );
706
707 if ( mnWinStyle & WB_BORDER )
708 aSize.AdjustHeight((TB_BORDER_OFFSET2*2) + nTop + nBottom );
709
710 nMax = 0;
712 if ( nMax )
713 aSize.AdjustWidth(nMax );
714
715 if ( mnWinStyle & WB_BORDER )
716 aSize.AdjustWidth((TB_BORDER_OFFSET1*2) + nLeft + nRight );
717 }
718 else
719 {
720 aSize.setWidth( nCalcLines * mnMaxItemWidth );
721
722 if ( mbLineSpacing )
723 aSize.AdjustWidth((nCalcLines-1)*TB_LINESPACING );
724
725 if ( mnWinStyle & WB_BORDER )
726 aSize.AdjustWidth((TB_BORDER_OFFSET2*2) + nLeft + nRight );
727
728 nMax = 0;
730 if ( nMax )
731 aSize.AdjustHeight(nMax );
732
733 if ( mnWinStyle & WB_BORDER )
734 aSize.AdjustHeight((TB_BORDER_OFFSET1*2) + nTop + nBottom );
735 }
736 }
737 // restore previous values
738 if ( nCalcMode )
739 {
740 mpData->mbAssumeDocked = bOldAssumeDocked;
741 mpData->mbAssumeFloating = bOldAssumeFloating;
742 if ( (meAlign != eOldAlign) || (mbHorz != bOldHorz) )
743 {
744 meAlign = eOldAlign;
745 mbHorz = bOldHorz;
746 mbCalc = true;
747 }
748 }
749
750 return aSize;
751}
752
754{
755 if ( !maFloatSizes.empty() )
756 return;
757
758 // calculate the minimal size, i.e. where the biggest item just fits
759 tools::Long nCalcSize = 0;
760
761 for (auto const& item : mpData->m_aItems)
762 {
763 if ( item.mbVisible )
764 {
765 if ( item.mpWindow )
766 {
767 tools::Long nTempSize = item.mpWindow->GetSizePixel().Width();
768 if ( nTempSize > nCalcSize )
769 nCalcSize = nTempSize;
770 }
771 else
772 {
773 if( item.maItemSize.Width() > nCalcSize )
774 nCalcSize = item.maItemSize.Width();
775 }
776 }
777 }
778
779 // calc an upper bound for ImplCalcBreaks below
780 tools::Long upperBoundWidth = nCalcSize * mpData->m_aItems.size();
781
782 ImplToolItems::size_type nLines;
783 ImplToolItems::size_type nCalcLines;
784 ImplToolItems::size_type nTempLines;
785 sal_Int32 nMaxLineWidth;
786 nCalcLines = ImplCalcBreaks( nCalcSize, &nMaxLineWidth, true );
787
788 maFloatSizes.reserve( nCalcLines );
789
790 nTempLines = nLines = nCalcLines;
791 while ( nLines )
792 {
793 tools::Long nHeight = ImplCalcSize( nTempLines, TB_CALCMODE_FLOAT ).Height();
794
795 ImplToolSize aSize;
796 aSize.mnWidth = nMaxLineWidth+(TB_BORDER_OFFSET1*2);
797 aSize.mnHeight = nHeight;
798 aSize.mnLines = nTempLines;
799 maFloatSizes.push_back( aSize );
800 nLines--;
801 if ( nLines )
802 {
803 do
804 {
805 nCalcSize += mnMaxItemWidth;
806 nTempLines = ImplCalcBreaks( nCalcSize, &nMaxLineWidth, true );
807 }
808 while ((nCalcSize < upperBoundWidth) && (nLines < nTempLines)); // implies nTempLines>1
809 if ( nTempLines < nLines )
810 nLines = nTempLines;
811 }
812 }
813}
814
815Size ToolBox::ImplCalcFloatSize( ImplToolItems::size_type& rLines )
816{
818
819 if ( !rLines )
820 {
821 rLines = mnFloatLines;
822 if ( !rLines )
823 rLines = mnLines;
824 }
825
826 sal_uInt16 i = 0;
827 while ( i + 1u < maFloatSizes.size() && rLines < maFloatSizes[i].mnLines )
828 {
829 i++;
830 }
831
833 rLines = maFloatSizes[i].mnLines;
834
835 return aSize;
836}
837
838void ToolBox::ImplCalcMinMaxFloatSize( Size& rMinSize, Size& rMaxSize )
839{
841
842 sal_uInt16 i = 0;
845 while ( ++i < maFloatSizes.size() )
846 {
847 if( maFloatSizes[i].mnWidth < rMinSize.Width() )
848 rMinSize.setWidth( maFloatSizes[i].mnWidth );
849 if( maFloatSizes[i].mnHeight < rMinSize.Height() )
850 rMinSize.setHeight( maFloatSizes[i].mnHeight );
851
852 if( maFloatSizes[i].mnWidth > rMaxSize.Width() )
853 rMaxSize.setWidth( maFloatSizes[i].mnWidth );
854 if( maFloatSizes[i].mnHeight > rMaxSize.Height() )
855 rMaxSize.setHeight( maFloatSizes[i].mnHeight );
856 }
857}
858
860{
862 Size aMinSize, aMaxSize;
863 ImplCalcMinMaxFloatSize( aMinSize, aMaxSize );
864 if( pWrapper )
865 {
866 pWrapper->SetMinOutputSizePixel( aMinSize );
867 pWrapper->SetMaxOutputSizePixel( aMaxSize );
869 }
870 else
871 {
872 // TODO: change SetMinOutputSizePixel to be not inline
873 SetMinOutputSizePixel( aMinSize );
874 SetMaxOutputSizePixel( aMaxSize );
875 }
876}
877
878ToolBox::ImplToolItems::size_type ToolBox::ImplCalcLines( tools::Long nToolSize ) const
879{
880 tools::Long nLineHeight;
881
882 if ( mbHorz )
883 {
885 nLineHeight = mnWinHeight;
886 else
887 nLineHeight = mnMaxItemHeight;
888 }
889 else
890 nLineHeight = mnMaxItemWidth;
891
892 if ( mnWinStyle & WB_BORDER )
893 nToolSize -= TB_BORDER_OFFSET2*2;
894
895 if ( mbLineSpacing )
896 {
897 nLineHeight += TB_LINESPACING;
898 nToolSize += TB_LINESPACING;
899 }
900
901 // #i91917# always report at least one line
902 tools::Long nLines = nToolSize/nLineHeight;
903 if( nLines < 1 )
904 nLines = 1;
905
906 return nLines;
907}
908
909sal_uInt16 ToolBox::ImplTestLineSize( const Point& rPos ) const
910{
911 if ( !ImplIsFloatingMode() &&
912 (!mbScroll || (mnLines > 1) || (mnCurLines > mnVisLines)) )
913 {
914 WindowAlign eAlign = GetAlign();
915
916 if ( eAlign == WindowAlign::Left )
917 {
918 if ( rPos.X() > mnDX-DOCK_LINEOFFSET )
920 }
921 else if ( eAlign == WindowAlign::Top )
922 {
923 if ( rPos.Y() > mnDY-DOCK_LINEOFFSET )
925 }
926 else if ( eAlign == WindowAlign::Right )
927 {
928 if ( rPos.X() < DOCK_LINEOFFSET )
930 }
931 else if ( eAlign == WindowAlign::Bottom )
932 {
933 if ( rPos.Y() < DOCK_LINEOFFSET )
935 }
936 }
937
938 return 0;
939}
940
941void ToolBox::ImplLineSizing( const Point& rPos, tools::Rectangle& rRect, sal_uInt16 nLineMode )
942{
943 bool bHorz;
944 tools::Long nOneLineSize;
945 tools::Long nCurSize;
946 tools::Long nMaxSize;
947 tools::Long nSize;
948 Size aSize;
949
950 if ( nLineMode & DOCK_LINERIGHT )
951 {
952 nCurSize = rPos.X() - rRect.Left();
953 bHorz = false;
954 }
955 else if ( nLineMode & DOCK_LINEBOTTOM )
956 {
957 nCurSize = rPos.Y() - rRect.Top();
958 bHorz = true;
959 }
960 else if ( nLineMode & DOCK_LINELEFT )
961 {
962 nCurSize = rRect.Right() - rPos.X();
963 bHorz = false;
964 }
965 else if ( nLineMode & DOCK_LINETOP )
966 {
967 nCurSize = rRect.Bottom() - rPos.Y();
968 bHorz = true;
969 }
970 else {
971 OSL_FAIL( "ImplLineSizing: Trailing else" );
972 nCurSize = 0;
973 bHorz = false;
974 }
975
976 Size aWinSize = GetSizePixel();
977 ImplToolItems::size_type nMaxLines = std::max(mnLines, mnCurLines);
978 if ( nMaxLines > TB_MAXLINES )
979 nMaxLines = TB_MAXLINES;
980 if ( bHorz )
981 {
982 nOneLineSize = ImplCalcSize( 1 ).Height();
983 nMaxSize = - 20;
984 if ( nMaxSize < aWinSize.Height() )
985 nMaxSize = aWinSize.Height();
986 }
987 else
988 {
989 nOneLineSize = ImplCalcSize( 1 ).Width();
990 nMaxSize = - 20;
991 if ( nMaxSize < aWinSize.Width() )
992 nMaxSize = aWinSize.Width();
993 }
994
995 ImplToolItems::size_type i = 1;
996 if ( nCurSize <= nOneLineSize )
997 nSize = nOneLineSize;
998 else
999 {
1000 nSize = 0;
1001 while ( (nSize < nCurSize) && (i < nMaxLines) )
1002 {
1003 i++;
1004 aSize = ImplCalcSize( i );
1005 if ( bHorz )
1006 nSize = aSize.Height();
1007 else
1008 nSize = aSize.Width();
1009 if ( nSize > nMaxSize )
1010 {
1011 i--;
1012 aSize = ImplCalcSize( i );
1013 if ( bHorz )
1014 nSize = aSize.Height();
1015 else
1016 nSize = aSize.Width();
1017 break;
1018 }
1019 }
1020 }
1021
1022 if ( nLineMode & DOCK_LINERIGHT )
1023 rRect.SetRight( rRect.Left()+nSize-1 );
1024 else if ( nLineMode & DOCK_LINEBOTTOM )
1025 rRect.SetBottom( rRect.Top()+nSize-1 );
1026 else if ( nLineMode & DOCK_LINELEFT )
1027 rRect.SetLeft( rRect.Right()-nSize );
1028 else
1029 rRect.SetTop( rRect.Bottom()-nSize );
1030
1031 mnDockLines = i;
1032}
1033
1035 : mpDragBox(nullptr)
1036 , mnLineMode(0)
1037 , mnStartLines(0)
1038{
1041 maAccel.SetSelectHdl( LINK( this, ImplTBDragMgr, SelectHdl ) );
1042}
1043
1045 const Point& rPos, const tools::Rectangle& rRect,
1046 sal_uInt16 nDragLineMode )
1047{
1048 mpDragBox = pToolBox;
1049 pToolBox->CaptureMouse();
1050 pToolBox->mbDragging = true;
1052
1053 mnLineMode = nDragLineMode;
1054 mnStartLines = pToolBox->mnDockLines;
1055
1056 // calculate MouseOffset
1057 maMouseOff.setX( rRect.Left() - rPos.X() );
1058 maMouseOff.setY( rRect.Top() - rPos.Y() );
1059 maRect = rRect;
1060 maStartRect = rRect;
1061 pToolBox->ShowTracking( maRect );
1062}
1063
1064void ImplTBDragMgr::Dragging( const Point& rPos )
1065{
1068 maRect.Move( aOff.X(), aOff.Y() );
1069 mpDragBox->Docking( rPos, maRect );
1070 maRect.Move( -aOff.X(), -aOff.Y() );
1072}
1073
1075{
1079 mpDragBox->mbDragging = false;
1081
1082 if ( !bOK )
1083 {
1085 mpDragBox->EndDocking( maStartRect, false );
1086 }
1087 else
1088 mpDragBox->EndDocking( maRect, false );
1089 mnStartLines = 0;
1090
1091 mpDragBox = nullptr;
1092}
1093
1094IMPL_LINK( ImplTBDragMgr, SelectHdl, Accelerator&, rAccel, void )
1095{
1096 if ( rAccel.GetCurItemId() == KEY_ESCAPE )
1097 EndDragging( false );
1098 else
1099 EndDragging();
1100}
1101
1103{
1104 // initialize variables
1105 ImplGetWindowImpl()->mbToolBox = true;
1106 mpData.reset(new ImplToolBoxPrivateData);
1107
1108 mpFloatWin = nullptr;
1109 mnDX = 0;
1110 mnDY = 0;
1111 mnMaxItemWidth = 0;
1112 mnMaxItemHeight = 0;
1113 mnWinHeight = 0;
1114 mnLeftBorder = 0;
1115 mnTopBorder = 0;
1116 mnRightBorder = 0;
1117 mnBottomBorder = 0;
1118 mnLastResizeDY = 0;
1123 mnLines = 1;
1124 mnCurLine = 1;
1125 mnCurLines = 1;
1126 mnVisLines = 1;
1127 mnFloatLines = 0;
1128 mnDockLines = 0;
1129 mnMouseModifier = 0;
1130 mbDrag = false;
1131 mbUpper = false;
1132 mbLower = false;
1133 mbIn = false;
1134 mbCalc = true;
1135 mbFormat = false;
1136 mbFullPaint = false;
1137 mbHorz = true;
1138 mbScroll = false;
1139 mbLastFloatMode = false;
1140 mbCustomize = false;
1141 mbDragging = false;
1142 mbIsKeyEvent = false;
1143 mbChangingHighlight = false;
1144 mbLineSpacing = false;
1145 mbIsArranged = false;
1150 mnWinStyle = 0;
1154 mnActivateCount = 0;
1155
1156 mpIdle.reset(new Idle("vcl::ToolBox maIdle update"));
1157 mpIdle->SetPriority( TaskPriority::RESIZE );
1158 mpIdle->SetInvokeHandler( LINK( this, ToolBox, ImplUpdateHdl ) );
1159
1160 // set timeout and handler for dropdown items
1161 mpData->maDropdownTimer.SetTimeout( 250 );
1162 mpData->maDropdownTimer.SetInvokeHandler( LINK( this, ToolBox, ImplDropdownLongClickHdl ) );
1163}
1164
1165void ToolBox::ImplInit( vcl::Window* pParent, WinBits nStyle )
1166{
1167 // initialize variables
1168 mbScroll = (nStyle & WB_SCROLL) != 0;
1169 mnWinStyle = nStyle;
1170
1171 DockingWindow::ImplInit( pParent, nStyle & ~WB_BORDER );
1172
1173 // dockingwindow's ImplInit removes some bits, so restore them here to allow keyboard handling for toolbars
1174 ImplGetWindowImpl()->mnStyle |= WB_TABSTOP|WB_NODIALOGCONTROL; // always set WB_TABSTOP for ToolBars
1175 ImplGetWindowImpl()->mnStyle &= ~WB_DIALOGCONTROL;
1176
1177 ImplInitSettings(true, true, true);
1178}
1179
1180void ToolBox::ApplyForegroundSettings(vcl::RenderContext& rRenderContext, const StyleSettings& rStyleSettings)
1181{
1182 Color aColor;
1183 if (IsControlForeground())
1184 aColor = GetControlForeground();
1185 else if (Window::GetStyle() & WB_3DLOOK)
1186 aColor = rStyleSettings.GetButtonTextColor();
1187 else
1188 aColor = rStyleSettings.GetWindowTextColor();
1189 rRenderContext.SetTextColor(aColor);
1190 rRenderContext.SetTextFillColor();
1191}
1192
1193void ToolBox::ApplyBackgroundSettings(vcl::RenderContext& rRenderContext, const StyleSettings& rStyleSettings)
1194{
1195 if (IsControlBackground())
1196 {
1197 rRenderContext.SetBackground(GetControlBackground());
1198 SetPaintTransparent(false);
1200 }
1201 else
1202 {
1204 || (GetAlign() == WindowAlign::Top && !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty())
1205 || (GetAlign() == WindowAlign::Bottom && !Application::GetSettings().GetStyleSettings().GetPersonaFooter().IsEmpty()))
1206 {
1207 rRenderContext.SetBackground();
1208 rRenderContext.SetTextColor(rStyleSettings.GetToolTextColor());
1209 SetPaintTransparent(true);
1211 mpData->maDisplayBackground = Wallpaper(rStyleSettings.GetFaceColor());
1212 }
1213 else
1214 {
1215 Color aColor;
1216 if (Window::GetStyle() & WB_3DLOOK)
1217 aColor = rStyleSettings.GetFaceColor();
1218 else
1219 aColor = rStyleSettings.GetWindowColor();
1220 rRenderContext.SetBackground(aColor);
1221 SetPaintTransparent(false);
1223 }
1224 }
1225}
1226
1228{
1229 mpData->mbNativeButtons = rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ControlPart::Button);
1230
1231 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
1232
1233 ApplyControlFont(rRenderContext, rStyleSettings.GetToolFont());
1234 ApplyForegroundSettings(rRenderContext, rStyleSettings);
1235 ApplyBackgroundSettings(rRenderContext, rStyleSettings);
1236}
1237
1238void ToolBox::ImplInitSettings(bool bFont, bool bForeground, bool bBackground)
1239{
1241
1242 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1243
1244 if (bFont)
1245 ApplyControlFont(*GetOutDev(), rStyleSettings.GetToolFont());
1246 if (bForeground || bFont)
1247 ApplyForegroundSettings(*GetOutDev(), rStyleSettings);
1248 if (bBackground)
1249 {
1250 ApplyBackgroundSettings(*GetOutDev(), rStyleSettings);
1252 }
1253}
1254
1256{
1258 mpDialogParent = nullptr;
1259 ImplInit(pParent, nBits);
1260 mbIsDeferredInit = false;
1261}
1262
1264{
1265 Window::queue_resize(eReason);
1266}
1267
1269 DockingWindow( WindowType::TOOLBOX, "vcl::ToolBox maLayoutIdle" )
1270{
1272 ImplInit( pParent, nStyle );
1273}
1274
1275ToolBox::ToolBox(vcl::Window* pParent, const OString& rID,
1276 const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame> &rFrame)
1277 : DockingWindow(WindowType::TOOLBOX, "vcl::ToolBox maLayoutIdle")
1278{
1280
1281 loadUI(pParent, rID, rUIXMLDescription, rFrame);
1282
1283 // calculate size of floating windows and switch if the
1284 // toolbox is initially in floating mode
1285 if ( ImplIsFloatingMode() )
1286 mbHorz = true;
1287 else
1288 Resize();
1289
1290 if (!(GetStyle() & WB_HIDE))
1291 Show();
1292}
1293
1295{
1296 disposeOnce();
1297}
1298
1300{
1301 // #103005# make sure our activate/deactivate balance is right
1302 while( mnActivateCount > 0 )
1303 Deactivate();
1304
1305 // terminate popupmode if the floating window is
1306 // still connected
1307 if ( mpFloatWin )
1309 mpFloatWin = nullptr;
1310
1311 // delete private data
1312 mpData.reset();
1313
1314 ImplSVData* pSVData = ImplGetSVData();
1315 delete pSVData->maCtrlData.mpTBDragMgr;
1316 pSVData->maCtrlData.mpTBDragMgr = nullptr;
1317
1318 mpFloatWin.clear();
1319
1320 mpIdle.reset();
1321
1323}
1324
1326{
1327 if (!mpData)
1328 return nullptr;
1329
1330 for (auto & item : mpData->m_aItems)
1331 {
1332 if ( item.mnId == nItemId )
1333 return &item;
1334 }
1335
1336 return nullptr;
1337}
1338
1339static void ImplAddButtonBorder( tools::Long &rWidth, tools::Long& rHeight, bool bNativeButtons )
1340{
1341 rWidth += SMALLBUTTON_HSIZE;
1342 rHeight += SMALLBUTTON_VSIZE;
1343
1344 if( bNativeButtons )
1345 {
1346 // give more border space for rounded buttons
1347 rWidth += 2;
1348 rHeight += 4;
1349 }
1350}
1351
1353{
1354 // recalc required ?
1355 if ( !mbCalc )
1356 return false;
1357
1359 float fScaleFactor = pDefault ? pDefault->GetDPIScaleFactor() : 1.0;
1360
1361 tools::Long nDefWidth;
1362 tools::Long nDefHeight;
1363 tools::Long nMaxWidth = 0;
1364 tools::Long nMaxHeight = 0;
1365 tools::Long nMinWidth = 6;
1366 tools::Long nMinHeight = 6;
1367 tools::Long nDropDownArrowWidth = TB_DROPDOWNARROWWIDTH * fScaleFactor;
1368#ifdef IOS
1369 nDropDownArrowWidth *= 3;
1370#endif
1371
1372 // set defaults if image or text is needed but empty
1373 nDefWidth = GetDefaultImageSize().Width();
1374 nDefHeight = GetDefaultImageSize().Height();
1375
1376 mnWinHeight = 0;
1377 // determine minimum size necessary in NWF
1378 {
1379 tools::Rectangle aRect( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1380 tools::Rectangle aReg( aRect );
1381 ImplControlValue aVal;
1382 tools::Rectangle aNativeBounds, aNativeContent;
1384 {
1386 aReg,
1388 aVal,
1389 aNativeBounds, aNativeContent ) )
1390 {
1391 aRect = aNativeBounds;
1392 if( aRect.GetWidth() > nMinWidth )
1393 nMinWidth = aRect.GetWidth();
1394 if( aRect.GetHeight() > nMinHeight )
1395 nMinHeight = aRect.GetHeight();
1396 if( nDropDownArrowWidth < nMinWidth )
1397 nDropDownArrowWidth = nMinWidth;
1398 if( nMinWidth > mpData->mnMenuButtonWidth )
1399 mpData->mnMenuButtonWidth = nMinWidth;
1400 else if( nMinWidth < TB_MENUBUTTON_SIZE )
1401 mpData->mnMenuButtonWidth = TB_MENUBUTTON_SIZE;
1402 }
1403 }
1404
1405 // also calculate the area for comboboxes, drop down list boxes and spinfields
1406 // as these are often inserted into toolboxes; set mnWinHeight to the
1407 // greater of those values to prevent toolbar flickering (#i103385#)
1408 aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1409 aReg = aRect;
1411 aReg,
1413 aVal,
1414 aNativeBounds, aNativeContent ) )
1415 {
1416 aRect = aNativeBounds;
1417 if( aRect.GetHeight() > mnWinHeight )
1418 mnWinHeight = aRect.GetHeight();
1419 }
1420 aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1421 aReg = aRect;
1423 aReg,
1425 aVal,
1426 aNativeBounds, aNativeContent ) )
1427 {
1428 aRect = aNativeBounds;
1429 if( aRect.GetHeight() > mnWinHeight )
1430 mnWinHeight = aRect.GetHeight();
1431 }
1432 aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1433 aReg = aRect;
1435 aReg,
1437 aVal,
1438 aNativeBounds, aNativeContent ) )
1439 {
1440 aRect = aNativeBounds;
1441 if( aRect.GetHeight() > mnWinHeight )
1442 mnWinHeight = aRect.GetHeight();
1443 }
1444 }
1445
1446 if ( ! mpData->m_aItems.empty() )
1447 {
1448 for (auto & item : mpData->m_aItems)
1449 {
1450 item.mbVisibleText = false; // indicates if text will definitely be drawn, influences dropdown pos
1451
1452 if ( item.meType == ToolBoxItemType::BUTTON )
1453 {
1454 bool bImage;
1455 bool bText;
1456
1457 // check if image and/or text exists
1458 bImage = !!item.maImage;
1459 bText = !item.maText.isEmpty();
1460 ButtonType tmpButtonType = determineButtonType( &item, meButtonType ); // default to toolbox setting
1461 if ( bImage || bText )
1462 {
1463
1464 item.mbEmptyBtn = false;
1465
1466 if ( tmpButtonType == ButtonType::SYMBOLONLY )
1467 {
1468 // we're drawing images only
1469 if ( bImage || !bText )
1470 {
1471 item.maItemSize = item.maImage.GetSizePixel();
1472 }
1473 else
1474 {
1475 item.maItemSize = Size( GetOutDev()->GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET,
1476 GetTextHeight() );
1477 item.mbVisibleText = true;
1478 }
1479 }
1480 else if ( tmpButtonType == ButtonType::TEXT )
1481 {
1482 // we're drawing text only
1483 if ( bText || !bImage )
1484 {
1485 item.maItemSize = Size( GetOutDev()->GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET,
1486 GetTextHeight() );
1487 item.mbVisibleText = true;
1488 }
1489 else
1490 {
1491 item.maItemSize = item.maImage.GetSizePixel();
1492 }
1493 }
1494 else
1495 {
1496 // we're drawing images and text
1497 item.maItemSize.setWidth( bText ? GetOutDev()->GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET : 0 );
1498 item.maItemSize.setHeight( bText ? GetTextHeight() : 0 );
1499
1501 {
1502 // leave space between image and text
1503 if( bText )
1504 item.maItemSize.AdjustWidth(TB_IMAGETEXTOFFSET );
1505
1506 // image and text side by side
1507 item.maItemSize.AdjustWidth(item.maImage.GetSizePixel().Width() );
1508 if ( item.maImage.GetSizePixel().Height() > item.maItemSize.Height() )
1509 item.maItemSize.setHeight( item.maImage.GetSizePixel().Height() );
1510 }
1511 else
1512 {
1513 // leave space between image and text
1514 if( bText )
1515 item.maItemSize.AdjustHeight(TB_IMAGETEXTOFFSET );
1516
1517 // text below image
1518 item.maItemSize.AdjustHeight(item.maImage.GetSizePixel().Height() );
1519 if ( item.maImage.GetSizePixel().Width() > item.maItemSize.Width() )
1520 item.maItemSize.setWidth( item.maImage.GetSizePixel().Width() );
1521 }
1522
1523 item.mbVisibleText = bText;
1524 }
1525 }
1526 else
1527 { // no image and no text
1528 item.maItemSize = Size( nDefWidth, nDefHeight );
1529 item.mbEmptyBtn = true;
1530 }
1531
1532 // save the content size
1533 item.maContentSize = item.maItemSize;
1534
1535 // if required, take window height into consideration
1536 if ( item.mpWindow )
1537 {
1538 tools::Long nHeight = item.mpWindow->GetSizePixel().Height();
1539 if ( nHeight > mnWinHeight )
1540 mnWinHeight = nHeight;
1541 }
1542
1543 // add in drop down arrow
1544 if( item.mnBits & ToolBoxItemBits::DROPDOWN )
1545 {
1546 item.maItemSize.AdjustWidth(nDropDownArrowWidth );
1547 item.mnDropDownArrowWidth = nDropDownArrowWidth;
1548 }
1549
1550 // text items will be rotated in vertical mode
1551 // -> swap width and height
1552 if( item.mbVisibleText && !mbHorz )
1553 {
1554 tools::Long tmp = item.maItemSize.Width();
1555 item.maItemSize.setWidth( item.maItemSize.Height() );
1556 item.maItemSize.setHeight( tmp );
1557
1558 tmp = item.maContentSize.Width();
1559 item.maContentSize.setWidth( item.maContentSize.Height() );
1560 item.maContentSize.setHeight( tmp );
1561 }
1562 }
1563 else if ( item.meType == ToolBoxItemType::SPACE )
1564 {
1565 item.maItemSize = Size( nDefWidth, nDefHeight );
1566 item.maContentSize = item.maItemSize;
1567 }
1568
1569 if ( item.meType == ToolBoxItemType::BUTTON || item.meType == ToolBoxItemType::SPACE )
1570 {
1571 // add borders
1572 tools::Long w = item.maItemSize.Width();
1573 tools::Long h = item.maItemSize.Height();
1574 ImplAddButtonBorder( w, h, mpData->mbNativeButtons );
1575 item.maItemSize.setWidth(w);
1576 item.maItemSize.setHeight(h);
1577
1578 if( item.meType == ToolBoxItemType::BUTTON )
1579 {
1580 tools::Long nMinW = std::max(nMinWidth, item.maMinimalItemSize.Width());
1581 tools::Long nMinH = std::max(nMinHeight, item.maMinimalItemSize.Height());
1582
1583 tools::Long nGrowContentWidth = 0;
1584 tools::Long nGrowContentHeight = 0;
1585
1586 if( item.maItemSize.Width() < nMinW )
1587 {
1588 nGrowContentWidth = nMinW - item.maItemSize.Width();
1589 item.maItemSize.setWidth( nMinW );
1590 }
1591 if( item.maItemSize.Height() < nMinH )
1592 {
1593 nGrowContentHeight = nMinH - item.maItemSize.Height();
1594 item.maItemSize.setHeight( nMinH );
1595 }
1596
1597 // grow the content size by the additional available space
1598 item.maContentSize.AdjustWidth(nGrowContentWidth );
1599 item.maContentSize.AdjustHeight(nGrowContentHeight );
1600 }
1601
1602 // keep track of max item size
1603 if ( item.maItemSize.Width() > nMaxWidth )
1604 nMaxWidth = item.maItemSize.Width();
1605 if ( item.maItemSize.Height() > nMaxHeight )
1606 nMaxHeight = item.maItemSize.Height();
1607 }
1608 }
1609 }
1610 else
1611 {
1612 nMaxWidth = nDefWidth;
1613 nMaxHeight = nDefHeight;
1614
1615 ImplAddButtonBorder( nMaxWidth, nMaxHeight, mpData->mbNativeButtons );
1616 }
1617
1620 {
1621 // make sure all vertical toolbars have the same width and horizontal have the same height
1622 // this depends on the used button sizes
1623 // as this is used for alignment of multiple toolbars
1624 // it is only required for docked toolbars
1625
1626 tools::Long nFixedWidth = nDefWidth+nDropDownArrowWidth;
1627 tools::Long nFixedHeight = nDefHeight;
1628 ImplAddButtonBorder( nFixedWidth, nFixedHeight, mpData->mbNativeButtons );
1629
1630 if( mbHorz )
1631 nMaxHeight = nFixedHeight;
1632 else
1633 nMaxWidth = nFixedWidth;
1634 }
1635
1636 mbCalc = false;
1637 mbFormat = true;
1638
1639 // do we have to recalc the sizes ?
1640 if ( (nMaxWidth != mnMaxItemWidth) || (nMaxHeight != mnMaxItemHeight) )
1641 {
1642 mnMaxItemWidth = nMaxWidth;
1643 mnMaxItemHeight = nMaxHeight;
1644
1645 return true;
1646 }
1647 else
1648 return false;
1649}
1650
1651ToolBox::ImplToolItems::size_type ToolBox::ImplCalcBreaks( tools::Long nWidth, sal_Int32* pMaxLineWidth, bool bCalcHorz ) const
1652{
1653 sal_uLong nLineStart = 0;
1654 sal_uLong nGroupStart = 0;
1656 tools::Long nCurWidth;
1657 tools::Long nLastGroupLineWidth = 0;
1658 tools::Long nMaxLineWidth = 0;
1659 ImplToolItems::size_type nLines = 1;
1660 bool bWindow;
1661 bool bBreak = false;
1662 tools::Long nWidthTotal = nWidth;
1663 tools::Long nMenuWidth = 0;
1664
1665 // when docked the menubutton will be in the first line
1666 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1667 nMenuWidth = mpData->maMenubuttonItem.maItemSize.Width();
1668
1669 // we need to know which item is the last visible one to be able to add
1670 // the menu width in case we are unable to show all the items
1671 ImplToolItems::iterator it, lastVisible;
1672 for ( it = mpData->m_aItems.begin(); it != mpData->m_aItems.end(); ++it )
1673 {
1674 if ( it->mbVisible )
1675 lastVisible = it;
1676 }
1677
1678 it = mpData->m_aItems.begin();
1679 while ( it != mpData->m_aItems.end() )
1680 {
1681 it->mbBreak = bBreak;
1682 bBreak = false;
1683
1684 if ( it->mbVisible )
1685 {
1686 bWindow = false;
1687 bBreak = false;
1688 nCurWidth = 0;
1689
1690 if ( it->meType == ToolBoxItemType::BUTTON || it->meType == ToolBoxItemType::SPACE )
1691 {
1692 if ( bCalcHorz )
1693 nCurWidth = it->maItemSize.Width();
1694 else
1695 nCurWidth = it->maItemSize.Height();
1696
1697 if ( it->mpWindow && bCalcHorz )
1698 {
1699 tools::Long nWinItemWidth = it->mpWindow->GetSizePixel().Width();
1700 if ( !mbScroll || (nWinItemWidth <= nWidthTotal) )
1701 {
1702 nCurWidth = nWinItemWidth;
1703 bWindow = true;
1704 }
1705 else
1706 {
1707 if ( it->mbEmptyBtn )
1708 {
1709 nCurWidth = 0;
1710 }
1711 }
1712 }
1713
1714 // in case we are able to show all the items, we do not want
1715 // to show the toolbar's menu; otherwise yes
1716 if ( ( ( it == lastVisible ) && (nLineWidth+nCurWidth > nWidthTotal) && mbScroll ) ||
1717 ( ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) && mbScroll ) )
1718 bBreak = true;
1719 }
1720 else if ( it->meType == ToolBoxItemType::SEPARATOR )
1721 {
1722 nCurWidth = it->mnSepSize;
1723 if ( !ImplIsFloatingMode() && ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) )
1724 bBreak = true;
1725 }
1726 // treat breaks as separators, except when using old style toolbars (ie. no menu button)
1727 else if ( (it->meType == ToolBoxItemType::BREAK) && !IsMenuEnabled() )
1728 bBreak = true;
1729
1730 if ( bBreak )
1731 {
1732 nLines++;
1733
1734 // Add break before the entire group or take group apart?
1735 if ( (it->meType == ToolBoxItemType::BREAK) ||
1736 (nLineStart == nGroupStart) )
1737 {
1738 if ( nLineWidth > nMaxLineWidth )
1739 nMaxLineWidth = nLineWidth;
1740
1741 nLineWidth = 0;
1742 nLineStart = it - mpData->m_aItems.begin();
1743 nGroupStart = nLineStart;
1744 it->mbBreak = true;
1745 bBreak = false;
1746 }
1747 else
1748 {
1749 if ( nLastGroupLineWidth > nMaxLineWidth )
1750 nMaxLineWidth = nLastGroupLineWidth;
1751
1752 // if the break is added before the group, set it to
1753 // beginning of line and re-calculate
1754 nLineWidth = 0;
1755 nLineStart = nGroupStart;
1756 it = mpData->m_aItems.begin() + nGroupStart;
1757 continue;
1758 }
1759 }
1760 else
1761 {
1762 if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
1763 {
1764 if ( (it->meType != ToolBoxItemType::BUTTON) || bWindow )
1765 {
1766 // found separator or break
1767 nLastGroupLineWidth = nLineWidth;
1768 nGroupStart = it - mpData->m_aItems.begin();
1769 if ( !bWindow )
1770 nGroupStart++;
1771 }
1772 }
1773 }
1774
1775 nLineWidth += nCurWidth;
1776 }
1777
1778 ++it;
1779 }
1780
1781 if ( pMaxLineWidth )
1782 {
1783 if ( nLineWidth > nMaxLineWidth )
1784 nMaxLineWidth = nLineWidth;
1785
1787 {
1788 // leave enough space to display buttons in the decoration
1790 if( nMaxLineWidth < aMinWidth )
1791 nMaxLineWidth = aMinWidth;
1792 }
1793 *pMaxLineWidth = nMaxLineWidth;
1794 }
1795
1796 return nLines;
1797}
1798
1800{
1801 if( !ImplIsFloatingMode() )
1802 return Size();
1803
1804 Size aCurrentSize( mnDX, mnDY );
1805 Size aSize1( aCurrentSize );
1806 Size aSize2( aCurrentSize );
1807
1808 // try to preserve current height
1809
1810 // calc number of floating lines for current window height
1811 ImplToolItems::size_type nFloatLinesHeight = ImplCalcLines( mnDY );
1812 // calc window size according to this number
1813 aSize1 = ImplCalcFloatSize( nFloatLinesHeight );
1814
1815 if( aCurrentSize == aSize1 )
1816 return aSize1;
1817
1818 // try to preserve current width
1819
1820 tools::Long nLineHeight = std::max( mnWinHeight, mnMaxItemHeight );
1821 int nBorderX = 2*TB_BORDER_OFFSET1 + mnLeftBorder + mnRightBorder;
1822 int nBorderY = 2*TB_BORDER_OFFSET2 + mnTopBorder + mnBottomBorder;
1823 Size aSz( aCurrentSize );
1824 sal_Int32 maxX;
1825 ImplToolItems::size_type nLines = ImplCalcBreaks( aSz.Width()-nBorderX, &maxX, mbHorz );
1826
1827 ImplToolItems::size_type manyLines = 1000;
1828 Size aMinimalFloatSize = ImplCalcFloatSize( manyLines );
1829
1830 aSz.setHeight( nBorderY + nLineHeight * nLines );
1831 // line space when more than one line
1832 if ( mbLineSpacing )
1833 aSz.AdjustHeight((nLines-1)*TB_LINESPACING );
1834
1835 aSz.setWidth( nBorderX + maxX );
1836
1837 // avoid clipping of any items
1838 if( aSz.Width() < aMinimalFloatSize.Width() )
1839 aSize2 = ImplCalcFloatSize( nLines );
1840 else
1841 aSize2 = aSz;
1842
1843 if( aCurrentSize == aSize2 )
1844 return aSize2;
1845
1846 // set the size with the smallest delta as the current size
1847 tools::Long dx1 = std::abs( mnDX - aSize1.Width() );
1848 tools::Long dy1 = std::abs( mnDY - aSize1.Height() );
1849
1850 tools::Long dx2 = std::abs( mnDX - aSize2.Width() );
1851 tools::Long dy2 = std::abs( mnDY - aSize2.Height() );
1852
1853 if( dx1*dy1 < dx2*dy2 )
1854 aCurrentSize = aSize1;
1855 else
1856 aCurrentSize = aSize2;
1857
1858 return aCurrentSize;
1859}
1860
1861namespace
1862{
1863void lcl_hideDoubleSeparators( ToolBox::ImplToolItems& rItems )
1864{
1865 bool bLastSep( true );
1866 ToolBox::ImplToolItems::iterator it;
1867 for ( it = rItems.begin(); it != rItems.end(); ++it )
1868 {
1869 if ( it->meType == ToolBoxItemType::SEPARATOR )
1870 {
1871 it->mbVisible = false;
1872 if ( !bLastSep )
1873 {
1874 // check if any visible items have to appear behind it
1875 if (std::any_of(it + 1, rItems.end(), [](const ImplToolItem& rItem) {
1876 return (rItem.meType == ToolBoxItemType::BUTTON) && rItem.mbVisible; }))
1877 it->mbVisible = true;
1878 }
1879 bLastSep = true;
1880 }
1881 else if ( it->mbVisible )
1882 bLastSep = false;
1883 }
1884}
1885}
1886
1887void ToolBox::ImplFormat( bool bResize )
1888{
1889 // Has to re-formatted
1890 if ( !mbFormat )
1891 return;
1892
1893 mpData->ImplClearLayoutData();
1894
1895 // recalculate positions and sizes
1896 tools::Rectangle aEmptyRect;
1897 tools::Long nLineSize;
1898 tools::Long nLeft;
1899 tools::Long nTop;
1900 tools::Long nMax; // width of layoutarea in pixels
1901 ImplToolItems::size_type nFormatLine;
1902 bool bMustFullPaint;
1903
1905 bool bIsInPopupMode = ImplIsInPopupMode();
1906
1907 maFloatSizes.clear();
1908
1909 // compute border sizes
1911
1912 // update drag area (where the 'grip' will be placed)
1913 tools::Rectangle aOldDragRect;
1914 if( pWrapper )
1915 aOldDragRect = pWrapper->GetDragArea();
1917
1918 bMustFullPaint = ImplCalcItem();
1919
1920 // calculate new size during interactive resize or
1921 // set computed size when formatting only
1922 if ( ImplIsFloatingMode() )
1923 {
1924 if ( bResize )
1926 else
1928 }
1929
1930 // Horizontal
1931 if ( mbHorz )
1932 {
1933 tools::Long nBottom;
1934 // nLineSize: height of a single line, will fit highest item
1935 nLineSize = mnMaxItemHeight;
1936
1938 nLineSize = mnWinHeight;
1939
1940 if ( mbScroll )
1941 {
1942 nMax = mnDX;
1944 }
1945 else
1946 {
1947 // layout over all lines
1949 nMax = TB_MAXNOSCROLL;
1950 }
1951
1952 // add in all border offsets
1953 if ( mnWinStyle & WB_BORDER )
1954 {
1958 nMax -= nLeft + TB_BORDER_OFFSET1 + mnRightBorder;
1959 }
1960 else
1961 {
1962 nLeft = 0;
1963 nTop = 0;
1964 nBottom = 0;
1965 }
1966
1967 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
1968 // we have to center all items in the window height
1969 if( IsMenuEnabled() && !ImplIsFloatingMode() )
1970 {
1971 tools::Long nWinHeight = mnDY - nTop - nBottom;
1972 if( nWinHeight > nLineSize )
1973 nLineSize = nWinHeight;
1974 }
1975 }
1976 else
1977 {
1978 tools::Long nRight;
1979 nLineSize = mnMaxItemWidth;
1980
1981 if ( mbScroll )
1982 {
1984 nMax = mnDY;
1985 }
1986 else
1987 {
1989 nMax = TB_MAXNOSCROLL;
1990 }
1991
1992 if ( mnWinStyle & WB_BORDER )
1993 {
1997 nMax -= nTop + TB_BORDER_OFFSET1 + mnBottomBorder;
1998 }
1999 else
2000 {
2001 nLeft = 0;
2002 nTop = 0;
2003 nRight = 0;
2004 }
2005
2006 // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
2007 // we have to center all items in the window height
2008 if( !ImplIsFloatingMode() && IsMenuEnabled() )
2009 {
2010 tools::Long nWinWidth = mnDX - nLeft - nRight;
2011 if( nWinWidth > nLineSize )
2012 nLineSize = nWinWidth;
2013 }
2014 }
2015
2016 // no calculation if the window has no size (nMax=0)
2017 // non scrolling toolboxes must be computed though
2018 if ( (nMax <= 0) && mbScroll )
2019 {
2020 mnVisLines = 1;
2021 mnCurLine = 1;
2022 mnCurLines = 1;
2023
2024 for (auto & item : mpData->m_aItems)
2025 {
2026 item.maRect = aEmptyRect;
2027 }
2028
2029 maLowerRect = aEmptyRect;
2030 maUpperRect = aEmptyRect;
2031 }
2032 else
2033 {
2034 // init start values
2035 tools::Long nX = nLeft; // top-left offset
2036 tools::Long nY = nTop;
2037 nFormatLine = 1;
2038
2039 // save old scroll rectangles and reset them
2040 tools::Rectangle aOldLowerRect = maLowerRect;
2041 tools::Rectangle aOldUpperRect = maUpperRect;
2042 tools::Rectangle aOldMenubuttonRect = mpData->maMenubuttonItem.maRect;
2043 maUpperRect = aEmptyRect;
2044 maLowerRect = aEmptyRect;
2045 mpData->maMenubuttonItem.maRect = aEmptyRect;
2046
2047 // do we have any toolbox items at all ?
2048 if ( !mpData->m_aItems.empty() || IsMenuEnabled() )
2049 {
2050 lcl_hideDoubleSeparators( mpData->m_aItems );
2051
2052 // compute line breaks and visible lines give the current window width (nMax)
2053 // the break indicators will be stored within each item (it->mbBreak)
2054 mnCurLines = ImplCalcBreaks( nMax, nullptr, mbHorz );
2055
2056 // check for scrollbar buttons or dropdown menu
2057 // (if a menu is enabled, this will be used to store clipped
2058 // items and no scroll buttons will appear)
2059 if ( (!ImplIsFloatingMode() && (mnCurLines > mnVisLines) && mbScroll ) ||
2060 IsMenuEnabled() )
2061 {
2062 // compute linebreaks again, incorporating scrollbar buttons
2063 if( !IsMenuEnabled() )
2064 {
2066 mnCurLines = ImplCalcBreaks( nMax, nullptr, mbHorz );
2067 }
2068
2069 // compute scroll rectangles or menu button
2070 if ( mbHorz )
2071 {
2072 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
2073 {
2074 if( !ImplIsFloatingMode() )
2075 {
2076 mpData->maMenubuttonItem.maRect.SetRight( mnDX - 2 );
2077 mpData->maMenubuttonItem.maRect.SetTop( nTop );
2078 mpData->maMenubuttonItem.maRect.SetBottom( mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1 );
2079 }
2080 else
2081 {
2082 mpData->maMenubuttonItem.maRect.SetRight( mnDX - mnRightBorder-TB_BORDER_OFFSET1-1 );
2083 mpData->maMenubuttonItem.maRect.SetTop( nTop );
2084 mpData->maMenubuttonItem.maRect.SetBottom( mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1 );
2085 }
2086 mpData->maMenubuttonItem.maRect.SetLeft( mpData->maMenubuttonItem.maRect.Right() - mpData->mnMenuButtonWidth );
2087 }
2088 else
2089 {
2090 maUpperRect.SetLeft( nLeft+nMax+TB_SPIN_OFFSET );
2092 maUpperRect.SetTop( nTop );
2099 }
2100 }
2101 else
2102 {
2103 if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
2104 {
2105 if( !ImplIsFloatingMode() )
2106 {
2107 mpData->maMenubuttonItem.maRect.SetBottom( mnDY - 2 );
2108 mpData->maMenubuttonItem.maRect.SetLeft( nLeft );
2109 mpData->maMenubuttonItem.maRect.SetRight( mnDX-mnRightBorder-TB_BORDER_OFFSET2-1 );
2110 }
2111 else
2112 {
2113 mpData->maMenubuttonItem.maRect.SetBottom( mnDY - mnBottomBorder-TB_BORDER_OFFSET1-1 );
2114 mpData->maMenubuttonItem.maRect.SetLeft( nLeft );
2115 mpData->maMenubuttonItem.maRect.SetRight( mnDX-mnRightBorder-TB_BORDER_OFFSET2-1 );
2116 }
2117 mpData->maMenubuttonItem.maRect.SetTop( mpData->maMenubuttonItem.maRect.Bottom() - mpData->mnMenuButtonWidth );
2118 }
2119 else
2120 {
2121 maUpperRect.SetTop( nTop+nMax+TB_SPIN_OFFSET );
2123 maUpperRect.SetLeft( nLeft );
2130 }
2131 }
2132 }
2133
2134 // no scrolling when there is a "more"-menu
2135 // anything will "fit" in a single line then
2136 if( IsMenuEnabled() )
2137 mnCurLines = 1;
2138
2139 // determine the currently visible line
2140 if ( mnVisLines >= mnCurLines )
2141 mnCurLine = 1;
2142 else if ( mnCurLine+mnVisLines-1 > mnCurLines )
2144
2145 tools::Long firstItemCenter = 0;
2146 for (auto & item : mpData->m_aItems)
2147 {
2148 item.mbShowWindow = false;
2149
2150 // check for line break and advance nX/nY accordingly
2151 if ( item.mbBreak )
2152 {
2153 nFormatLine++;
2154
2155 // increment starting with the second line
2156 if ( nFormatLine > mnCurLine )
2157 {
2158 if ( mbHorz )
2159 {
2160 nX = nLeft;
2161 if ( mbLineSpacing )
2162 nY += nLineSize+TB_LINESPACING;
2163 else
2164 nY += nLineSize;
2165 }
2166 else
2167 {
2168 nY = nTop;
2169 if ( mbLineSpacing )
2170 nX += nLineSize+TB_LINESPACING;
2171 else
2172 nX += nLineSize;
2173 }
2174 }
2175 }
2176
2177 if ( !item.mbVisible || (nFormatLine < mnCurLine) ||
2178 (nFormatLine > mnCurLine+mnVisLines-1) )
2179 // item is not visible
2180 item.maCalcRect = aEmptyRect;
2181 else
2182 {
2183 // 1. determine current item width/height
2184 // take window size and orientation into account, because this affects the size of item windows
2185
2186 Size aCurrentItemSize( item.GetSize( mbHorz, mbScroll, nMax, Size(mnMaxItemWidth, mnMaxItemHeight) ) );
2187
2188 // 2. position item rect and use size from step 1
2189 // items will be centered horizontally (if mbHorz) or vertically
2190 // advance nX and nY accordingly
2191
2192 if ( mbHorz )
2193 {
2194 // In special mode Locked horizontal positions of all items remain unchanged.
2195
2196 if ( mbIsArranged && meLayoutMode == ToolBoxLayoutMode::Locked && mnLines == 1 && item.maRect.Left() > 0 )
2197 nX = item.maRect.Left();
2198 item.maCalcRect.SetLeft( nX );
2199
2200 // In special mode Locked first item's vertical position remains unchanged. Consecutive items vertical
2201 // positions are centered around first item's vertical position. If an item's height exceeds available
2202 // space, item's vertical position remains unchanged too.
2203
2205 if ( firstItemCenter > 0 )
2206 if ( firstItemCenter-aCurrentItemSize.Height()/2 > nY )
2207 item.maCalcRect.SetTop( firstItemCenter-aCurrentItemSize.Height()/2 );
2208 else
2209 item.maCalcRect.SetTop( item.maRect.Top() );
2210 else
2211 {
2212 item.maCalcRect.SetTop( item.maRect.Top() );
2213 firstItemCenter = item.maRect.Top()+aCurrentItemSize.Height()/2;
2214 }
2215 else
2216 item.maCalcRect.SetTop( nY+(nLineSize-aCurrentItemSize.Height())/2 );
2217 item.maCalcRect.SetRight( nX+aCurrentItemSize.Width()-1 );
2218 item.maCalcRect.SetBottom( item.maCalcRect.Top()+aCurrentItemSize.Height()-1 );
2219 nX += aCurrentItemSize.Width();
2220 }
2221 else
2222 {
2223 item.maCalcRect.SetLeft( nX+(nLineSize-aCurrentItemSize.Width())/2 );
2224 item.maCalcRect.SetTop( nY );
2225 item.maCalcRect.SetRight( item.maCalcRect.Left()+aCurrentItemSize.Width()-1 );
2226 item.maCalcRect.SetBottom( nY+aCurrentItemSize.Height()-1 );
2227 nY += aCurrentItemSize.Height();
2228 }
2229 }
2230
2231 // position window items into calculated item rect
2232 if ( item.mpWindow )
2233 {
2234 if ( item.mbShowWindow )
2235 {
2236 Point aPos( item.maCalcRect.Left(), item.maCalcRect.Top() );
2237
2238 assert( item.maCalcRect.Top() >= 0 );
2239
2240 item.mpWindow->SetPosPixel( aPos );
2241 item.mpWindow->Show();
2242 }
2243 else
2244 item.mpWindow->Hide();
2245 }
2246 } // end of loop over all items
2247 mbIsArranged = true;
2248 }
2249 else
2250 // we have no toolbox items
2251 mnCurLines = 1;
2252
2253 if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
2254 {
2255 // custom menu will be the last button in floating mode
2256 ImplToolItem &rIt = mpData->maMenubuttonItem;
2257
2258 if ( mbHorz )
2259 {
2261 rIt.maRect.SetTop( nY );
2262 rIt.maRect.SetRight( rIt.maRect.Left() + mpData->mnMenuButtonWidth );
2263 rIt.maRect.SetBottom( nY+nLineSize-1 );
2264 nX += rIt.maItemSize.Width();
2265 }
2266 else
2267 {
2268 rIt.maRect.SetLeft( nX );
2270 rIt.maRect.SetRight( nX+nLineSize-1 );
2271 rIt.maRect.SetBottom( rIt.maRect.Top() + mpData->mnMenuButtonWidth );
2272 nY += rIt.maItemSize.Height();
2273 }
2274 }
2275
2276 // if toolbox visible trigger paint for changed regions
2277 if ( IsVisible() && !mbFullPaint )
2278 {
2279 if ( bMustFullPaint )
2280 {
2283 }
2284 else
2285 {
2286 if ( aOldLowerRect != maLowerRect )
2287 {
2289 maPaintRect.Union( aOldLowerRect );
2290 }
2291 if ( aOldUpperRect != maUpperRect )
2292 {
2294 maPaintRect.Union( aOldUpperRect );
2295 }
2296 if ( aOldMenubuttonRect != mpData->maMenubuttonItem.maRect )
2297 {
2298 maPaintRect.Union( mpData->maMenubuttonItem.maRect );
2299 maPaintRect.Union( aOldMenubuttonRect );
2300 }
2301 if ( pWrapper && aOldDragRect != pWrapper->GetDragArea() )
2302 {
2303 maPaintRect.Union( pWrapper->GetDragArea() );
2304 maPaintRect.Union( aOldDragRect );
2305 }
2306
2307 for (auto const& item : mpData->m_aItems)
2308 {
2309 if ( item.maRect != item.maCalcRect )
2310 {
2311 maPaintRect.Union( item.maRect );
2312 maPaintRect.Union( item.maCalcRect );
2313 }
2314 }
2315 }
2316
2318 }
2319
2320 // store the new calculated item rects
2321 maPaintRect = aEmptyRect;
2322 for (auto & item : mpData->m_aItems)
2323 item.maRect = item.maCalcRect;
2324 }
2325
2326 // indicate formatting is done
2327 mbFormat = false;
2328}
2329
2330IMPL_LINK_NOARG(ToolBox, ImplDropdownLongClickHdl, Timer *, void)
2331{
2332 if (mnCurPos == ITEM_NOTFOUND ||
2333 !(mpData->m_aItems[ mnCurPos ].mnBits & ToolBoxItemBits::DROPDOWN))
2334 return;
2335
2336 mpData->mbDropDownByKeyboard = false;
2337 mpData->maDropdownClickHdl.Call( this );
2338
2339 // do not reset data if the dropdown handler opened a floating window
2340 // see ImplFloatControl()
2341 if( !mpFloatWin )
2342 {
2343 // no floater was opened
2344 Deactivate();
2345 InvalidateItem(mnCurPos);
2346
2347 mnCurPos = ITEM_NOTFOUND;
2348 mnCurItemId = ToolBoxItemId(0);
2349 mnDownItemId = ToolBoxItemId(0);
2350 mnMouseModifier = 0;
2351 mnHighItemId = ToolBoxItemId(0);
2352 }
2353}
2354
2355IMPL_LINK_NOARG(ToolBox, ImplUpdateHdl, Timer *, void)
2356{
2357
2358 if( mbFormat && mpData )
2359 ImplFormat();
2360}
2361
2362static void ImplDrawMoreIndicator(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
2363{
2364 const Image pImage(StockImage::Yes, CHEVRON);
2365 Size aImageSize = pImage.GetSizePixel();
2366 tools::Long x = rRect.Left() + (rRect.getOpenWidth() - aImageSize.Width())/2;
2367 tools::Long y = rRect.Top() + (rRect.getOpenHeight() - aImageSize.Height())/2;
2369
2370 rRenderContext.DrawImage(Point(x,y), pImage, nImageStyle);
2371}
2372
2373static void ImplDrawDropdownArrow(vcl::RenderContext& rRenderContext, const tools::Rectangle& rDropDownRect, bool bSetColor, bool bRotate )
2374{
2375 bool bLineColor = rRenderContext.IsLineColor();
2376 bool bFillColor = rRenderContext.IsFillColor();
2377 Color aOldFillColor = rRenderContext.GetFillColor();
2378 Color aOldLineColor = rRenderContext.GetLineColor();
2379 rRenderContext.SetLineColor();
2380
2381 if ( bSetColor )
2382 {
2383 if (rRenderContext.GetSettings().GetStyleSettings().GetFaceColor().IsDark())
2384 rRenderContext.SetFillColor(COL_WHITE);
2385 else
2386 rRenderContext.SetFillColor(COL_BLACK);
2387 }
2388
2389 tools::Polygon aPoly(4);
2390
2391 // the assumption is, that the width always specifies the size of the expected arrow.
2392 const tools::Long nMargin = round(2 * rRenderContext.GetDPIScaleFactor());
2393 const tools::Long nSize = rDropDownRect.getOpenWidth() - 2 * nMargin;
2394 const tools::Long nHalfSize = (nSize + 1) / 2;
2395 const tools::Long x = rDropDownRect.Left() + nMargin + (bRotate ? (rDropDownRect.getOpenWidth() - nHalfSize) / 2 : 0);
2396 const tools::Long y = rDropDownRect.Top() + nMargin + (rDropDownRect.getOpenHeight() - (bRotate ? nSize : nHalfSize)) / 2;
2397
2398 aPoly.SetPoint(Point(x, y), 0);
2399 if (bRotate) // >
2400 {
2401 aPoly.SetPoint(Point(x, y + nSize), 1);
2402 aPoly.SetPoint(Point(x + nHalfSize, y + nHalfSize), 2);
2403 }
2404 else // v
2405 {
2406 aPoly.SetPoint(Point(x + nHalfSize, y + nHalfSize), 1);
2407 aPoly.SetPoint(Point(x + nSize, y), 2);
2408 }
2409 aPoly.SetPoint(Point(x, y), 3);
2410
2411 auto aaflags = rRenderContext.GetAntialiasing();
2413 rRenderContext.DrawPolygon( aPoly );
2414 rRenderContext.SetAntialiasing(aaflags);
2415
2416 if( bFillColor )
2417 rRenderContext.SetFillColor(aOldFillColor);
2418 else
2419 rRenderContext.SetFillColor();
2420 if( bLineColor )
2421 rRenderContext.SetLineColor(aOldLineColor);
2422 else
2423 rRenderContext.SetLineColor();
2424}
2425
2426void ToolBox::ImplDrawMenuButton(vcl::RenderContext& rRenderContext, bool bHighlight)
2427{
2428 if (mpData->maMenubuttonItem.maRect.IsEmpty())
2429 return;
2430
2431 // #i53937# paint menu button only if necessary
2432 if (!ImplHasClippedItems())
2433 return;
2434
2435 // execute pending paint requests
2437
2439
2440 // draw the 'more' indicator / button (>>)
2441 ImplErase(rRenderContext, mpData->maMenubuttonItem.maRect, bHighlight);
2442
2443 if (bHighlight)
2444 ImplDrawButton(rRenderContext, mpData->maMenubuttonItem.maRect, 2, false, true, false );
2445
2446 if (ImplHasClippedItems())
2447 ImplDrawMoreIndicator(rRenderContext, mpData->maMenubuttonItem.maRect);
2448
2449 // store highlight state
2450 mpData->mbMenubuttonSelected = bHighlight;
2451
2452 // restore colors
2453 rRenderContext.Pop();
2454}
2455
2457{
2458 bool bTmpUpper;
2459 bool bTmpLower;
2460
2462 return;
2463
2464 bTmpUpper = mnCurLine > 1;
2465
2466 bTmpLower = mnCurLine+mnVisLines-1 < mnCurLines;
2467
2468 if ( !IsEnabled() )
2469 {
2470 bTmpUpper = false;
2471 bTmpLower = false;
2472 }
2473
2475 false/*bUpperIn*/, false/*bLowerIn*/, bTmpUpper, bTmpLower, !mbHorz);
2476}
2477
2478void ToolBox::ImplDrawSeparator(vcl::RenderContext& rRenderContext, ImplToolItems::size_type nPos, const tools::Rectangle& rRect)
2479{
2480 if ( nPos >= mpData->m_aItems.size() - 1 )
2481 // no separator if it's the last item
2482 return;
2483
2484 ImplToolItem* pItem = &mpData->m_aItems[nPos];
2485 ImplToolItem* pPreviousItem = &mpData->m_aItems[nPos-1];
2486 ImplToolItem* pNextItem = &mpData->m_aItems[nPos+1];
2487
2488 if ( ( pPreviousItem->mbShowWindow && pNextItem->mbShowWindow ) || pNextItem->mbBreak )
2489 // no separator between two windows or before a break
2490 return;
2491
2492 bool bNativeOk = false;
2494 if (rRenderContext.IsNativeControlSupported(ControlType::Toolbar, nPart))
2495 {
2496 ImplControlValue aControlValue;
2497 bNativeOk = rRenderContext.DrawNativeControl(ControlType::Toolbar, nPart, rRect, ControlState::NONE, aControlValue, OUString());
2498 }
2499
2500 /* Draw the widget only if it can't be drawn natively. */
2501 if (bNativeOk)
2502 return;
2503
2504 tools::Long nCenterPos, nSlim;
2505 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
2506 rRenderContext.SetLineColor(rStyleSettings.GetSeparatorColor());
2507 if (IsHorizontal())
2508 {
2509 nSlim = (pItem->maRect.Bottom() - pItem->maRect.Top ()) / 4;
2510 nCenterPos = pItem->maRect.Center().X();
2511 rRenderContext.DrawLine(Point(nCenterPos, pItem->maRect.Top() + nSlim),
2512 Point(nCenterPos, pItem->maRect.Bottom() - nSlim));
2513 }
2514 else
2515 {
2516 nSlim = (pItem->maRect.Right() - pItem->maRect.Left ()) / 4;
2517 nCenterPos = pItem->maRect.Center().Y();
2518 rRenderContext.DrawLine(Point(pItem->maRect.Left() + nSlim, nCenterPos),
2519 Point(pItem->maRect.Right() - nSlim, nCenterPos));
2520 }
2521}
2522
2523void ToolBox::ImplDrawButton(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect, sal_uInt16 highlight,
2524 bool bChecked, bool bEnabled, bool bIsWindow )
2525{
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
2528
2529 bool bNativeOk = false;
2530 if( !bIsWindow && rRenderContext.IsNativeControlSupported( ControlType::Toolbar, ControlPart::Button ) )
2531 {
2532 ImplControlValue aControlValue;
2534
2535 if ( highlight == 1 ) nState |= ControlState::PRESSED;
2536 if ( highlight == 2 ) nState |= ControlState::ROLLOVER;
2537 if ( bEnabled ) nState |= ControlState::ENABLED;
2538
2539 aControlValue.setTristateVal( bChecked ? ButtonValue::On : ButtonValue::Off );
2540
2541 bNativeOk = rRenderContext.DrawNativeControl( ControlType::Toolbar, ControlPart::Button,
2542 rRect, nState, aControlValue, OUString() );
2543 }
2544
2545 if (!bNativeOk)
2546 vcl::RenderTools::DrawSelectionBackground(rRenderContext, *this, rRect, bIsWindow ? 3 : highlight,
2547 bChecked, true, bIsWindow, nullptr, 2);
2548}
2549
2550void ToolBox::ImplDrawItem(vcl::RenderContext& rRenderContext, ImplToolItems::size_type nPos, sal_uInt16 nHighlight)
2551{
2552 if (nPos >= mpData->m_aItems.size())
2553 return;
2554
2555 // execute pending paint requests
2557
2558 rRenderContext.SetFillColor();
2559
2560 ImplToolItem* pItem = &mpData->m_aItems[nPos];
2561
2562 if (!pItem->mbEnabled)
2563 nHighlight = 0;
2564
2565 // if the rectangle is outside visible area
2566 if (pItem->maRect.IsEmpty())
2567 return;
2568
2569 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
2570
2571 // no gradient background for items that have a popup open
2572 bool bHasOpenPopup = mpFloatWin && (mnDownItemId==pItem->mnId);
2573
2574 bool bHighContrastWhite = false;
2575 // check the face color as highcontrast indicator
2576 // because the toolbox itself might have a gradient
2577 if (rStyleSettings.GetFaceColor() == COL_WHITE)
2578 bHighContrastWhite = true;
2579
2580 // Compute buttons area.
2581 Size aBtnSize = pItem->maRect.GetSize();
2582
2583 /* Compute the button/separator rectangle here, we'll need it for
2584 * both the buttons and the separators. */
2585 tools::Rectangle aButtonRect( pItem->maRect.TopLeft(), aBtnSize );
2588 tools::Long nImageOffX = 0;
2589 tools::Long nImageOffY = 0;
2591
2592 // draw separators
2593 if ( (pItem->meType == ToolBoxItemType::SEPARATOR) && nPos > 0 )
2594 {
2595 ImplDrawSeparator(rRenderContext, nPos, aButtonRect);
2596 }
2597
2598 // do nothing if item is no button or will be displayed as window
2599 if ( (pItem->meType != ToolBoxItemType::BUTTON) || pItem->mbShowWindow )
2600 return;
2601
2602 if ( pItem->meState == TRISTATE_TRUE )
2603 {
2604 nStyle |= DrawButtonFlags::Checked;
2605 }
2606 else if ( pItem->meState == TRISTATE_INDET )
2607 {
2608 nStyle |= DrawButtonFlags::DontKnow;
2609 }
2610 if ( nHighlight == 1 )
2611 {
2612 nStyle |= DrawButtonFlags::Pressed;
2613 }
2614
2615 ImplErase(rRenderContext, pItem->maRect, nHighlight != 0, bHasOpenPopup );
2616
2617 nOffX += pItem->maRect.Left();
2618 nOffY += pItem->maRect.Top();
2619
2620 // determine what has to be drawn on the button: image, text or both
2621 bool bImage;
2622 bool bText;
2623 ButtonType tmpButtonType = determineButtonType( pItem, meButtonType ); // default to toolbox setting
2624 pItem->DetermineButtonDrawStyle( tmpButtonType, bImage, bText );
2625
2626 // compute output values
2627 tools::Long nBtnWidth = aBtnSize.Width()-SMALLBUTTON_HSIZE;
2628 tools::Long nBtnHeight = aBtnSize.Height()-SMALLBUTTON_VSIZE;
2629 Size aImageSize;
2630
2631 const bool bDropDown = (pItem->mnBits & ToolBoxItemBits::DROPDOWN) == ToolBoxItemBits::DROPDOWN;
2632 tools::Rectangle aDropDownRect;
2633 if (bDropDown)
2634 aDropDownRect = pItem->GetDropDownRect(mbHorz);
2635
2636 if ( bImage )
2637 {
2638 const Image* pImage = &(pItem->maImage);
2639 aImageSize = pImage->GetSizePixel();
2640
2641 // determine drawing flags
2643
2644 if ( !pItem->mbEnabled || !IsEnabled() )
2645 nImageStyle |= DrawImageFlags::Disable;
2646
2647 // #i35563# the dontknow state indicates different states at the same time
2648 // which should not be rendered disabled but normal
2649
2650 // draw the image
2651 nImageOffX = nOffX;
2652 nImageOffY = nOffY;
2653 if ( ( (pItem->mnBits & (ToolBoxItemBits::LEFT|ToolBoxItemBits::DROPDOWN)) || bText )
2655 {
2656 // left align also to leave space for drop down arrow
2657 // and when drawing text+image
2658 // just center in y, except for vertical (ie rotated text)
2659 if( mbHorz || !bText )
2660 nImageOffY += (nBtnHeight-aImageSize.Height())/2;
2661 }
2662 else
2663 {
2664 nImageOffX += (nBtnWidth-(bDropDown ? aDropDownRect.getOpenWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X-aImageSize.Width())/2;
2666 nImageOffY += (nBtnHeight-aImageSize.Height())/2;
2667 }
2668 if ( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
2669 {
2670 if( bHasOpenPopup )
2671 ImplDrawFloatwinBorder(rRenderContext, pItem);
2672 else
2673 ImplDrawButton(rRenderContext, aButtonRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2674 pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow);
2675
2676 if( nHighlight != 0 )
2677 {
2678 if( bHighContrastWhite )
2679 nImageStyle |= DrawImageFlags::ColorTransform;
2680 }
2681 }
2682 rRenderContext.DrawImage(Point( nImageOffX, nImageOffY ), *pImage, nImageStyle);
2683 }
2684
2685 // draw the text
2686 bool bRotate = false;
2687 if ( bText )
2688 {
2689 const Size aTxtSize(GetOutDev()->GetCtrlTextWidth(pItem->maText), GetTextHeight());
2690 tools::Long nTextOffX = nOffX;
2691 tools::Long nTextOffY = nOffY;
2692
2693 // rotate text when vertically docked
2694 vcl::Font aOldFont = rRenderContext.GetFont();
2695 if( pItem->mbVisibleText && !ImplIsFloatingMode() &&
2697 {
2698 bRotate = true;
2699
2700 vcl::Font aRotateFont = aOldFont;
2701 aRotateFont.SetOrientation( 2700_deg10 );
2702
2703 // center horizontally
2704 nTextOffX += aTxtSize.Height();
2705 nTextOffX += (nBtnWidth-aTxtSize.Height())/2;
2706
2707 // add in image offset
2708 if( bImage )
2709 nTextOffY = nImageOffY + aImageSize.Height() + TB_IMAGETEXTOFFSET;
2710
2711 rRenderContext.SetFont(aRotateFont);
2712 }
2713 else
2714 {
2716 {
2717 // center vertically
2718 nTextOffY += (nBtnHeight-aTxtSize.Height())/2;
2719
2720 // add in image offset
2721 if( bImage )
2722 nTextOffX = nImageOffX + aImageSize.Width() + TB_IMAGETEXTOFFSET;
2723 }
2724 else
2725 {
2726 // center horizontally
2727 nTextOffX += (nBtnWidth-(bDropDown ? aDropDownRect.getOpenWidth() : 0)+SMALLBUTTON_OFF_NORMAL_X-aTxtSize.Width() - TB_IMAGETEXTOFFSET)/2;
2728 // set vertical position
2729 nTextOffY += nBtnHeight - aTxtSize.Height();
2730 }
2731 }
2732
2733 // draw selection only if not already drawn during image output (see above)
2734 if ( !bImage && (nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) ) )
2735 {
2736 if( bHasOpenPopup )
2737 ImplDrawFloatwinBorder(rRenderContext, pItem);
2738 else
2739 ImplDrawButton(rRenderContext, pItem->maRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2740 pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow );
2741 }
2742
2744 if ( !pItem->mbEnabled )
2745 nTextStyle |= DrawTextFlags::Disable;
2746 rRenderContext.DrawCtrlText( Point( nTextOffX, nTextOffY ), pItem->maText,
2747 0, pItem->maText.getLength(), nTextStyle );
2748 if ( bRotate )
2749 SetFont( aOldFont );
2750 }
2751
2752 // paint optional drop down arrow
2753 if (!bDropDown)
2754 return;
2755
2756 bool bSetColor = true;
2757 if ( !pItem->mbEnabled || !IsEnabled() )
2758 {
2759 bSetColor = false;
2760 rRenderContext.SetFillColor(rStyleSettings.GetShadowColor());
2761 }
2762
2763 // dropdown only will be painted without inner border
2765 {
2766 ImplErase(rRenderContext, aDropDownRect, nHighlight != 0, bHasOpenPopup);
2767
2768 if( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
2769 {
2770 if( bHasOpenPopup )
2771 ImplDrawFloatwinBorder(rRenderContext, pItem);
2772 else
2773 ImplDrawButton(rRenderContext, aDropDownRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2774 pItem->mbEnabled && IsEnabled(), false);
2775 }
2776 }
2777 ImplDrawDropdownArrow(rRenderContext, aDropDownRect, bSetColor, bRotate);
2778}
2779
2781{
2782 if ( pItem->maRect.IsEmpty() )
2783 return;
2784
2786 aRect.SetPos( AbsoluteScreenToOutputPixel( aRect.TopLeft() ) );
2787 rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetShadowColor());
2788 Point p1, p2;
2789
2790 p1 = pItem->maRect.TopLeft();
2791 p1.AdjustX( 1 );
2792 p2 = pItem->maRect.TopRight();
2793 p2.AdjustX( -1 );
2794 rRenderContext.DrawLine( p1, p2);
2795 p1 = pItem->maRect.BottomLeft();
2796 p1.AdjustX( 1 );
2797 p2 = pItem->maRect.BottomRight();
2798 p2.AdjustX( -1 );
2799 rRenderContext.DrawLine( p1, p2);
2800
2801 p1 = pItem->maRect.TopLeft();
2802 p1.AdjustY( 1 );
2803 p2 = pItem->maRect.BottomLeft();
2804 p2.AdjustY( -1 );
2805 rRenderContext.DrawLine( p1, p2);
2806 p1 = pItem->maRect.TopRight();
2807 p1.AdjustY( 1 );
2808 p2 = pItem->maRect.BottomRight();
2809 p2.AdjustY( -1 );
2810 rRenderContext.DrawLine( p1, p2);
2811
2812}
2813
2814void ToolBox::ImplFloatControl( bool bStart, FloatingWindow* pFloatWindow )
2815{
2816
2817 if ( bStart )
2818 {
2819 mpFloatWin = pFloatWindow;
2820
2821 // redraw item, to trigger drawing of a special border
2823
2824 mbDrag = false;
2825 EndTracking();
2826 if (IsMouseCaptured())
2827 ReleaseMouse();
2828 }
2829 else
2830 {
2831 mpFloatWin = nullptr;
2832
2833 // if focus is still in this toolbox, then the floater was opened by keyboard
2834 // draw current item with highlight and keep old state
2835 bool bWasKeyboardActivate = mpData->mbDropDownByKeyboard;
2836
2837 if ( mnCurPos != ITEM_NOTFOUND )
2839 Deactivate();
2840
2841 if( !bWasKeyboardActivate )
2842 {
2846 }
2848
2849 }
2850}
2851
2852void ToolBox::ShowLine( bool bNext )
2853{
2854 mbFormat = true;
2855
2856 if ( bNext )
2857 mnCurLine++;
2858 else
2859 mnCurLine--;
2860
2861 ImplFormat();
2862}
2863
2864bool ToolBox::ImplHandleMouseMove( const MouseEvent& rMEvt, bool bRepeat )
2865{
2866 Point aMousePos = rMEvt.GetPosPixel();
2867
2868 if ( !mpData )
2869 return false;
2870
2871 // ToolBox active?
2872 if ( mbDrag && mnCurPos != ITEM_NOTFOUND )
2873 {
2874 // is the cursor over the item?
2875 ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
2876 if ( pItem->maRect.Contains( aMousePos ) )
2877 {
2878 if ( !mnCurItemId )
2879 {
2881 mnCurItemId = pItem->mnId;
2882 Highlight();
2883 }
2884
2885 if ( (pItem->mnBits & ToolBoxItemBits::REPEAT) && bRepeat )
2886 Select();
2887 }
2888 else
2889 {
2890 if ( mnCurItemId )
2891 {
2895 Highlight();
2896 }
2897 }
2898
2899 return true;
2900 }
2901
2902 if ( mbUpper )
2903 {
2904 bool bNewIn = maUpperRect.Contains( aMousePos );
2905 if ( bNewIn != mbIn )
2906 {
2907 mbIn = bNewIn;
2908 InvalidateSpin(true, false);
2909 }
2910 return true;
2911 }
2912
2913 if ( mbLower )
2914 {
2915 bool bNewIn = maLowerRect.Contains( aMousePos );
2916 if ( bNewIn != mbIn )
2917 {
2918 mbIn = bNewIn;
2919 InvalidateSpin(false);
2920 }
2921 return true;
2922 }
2923
2924 return false;
2925}
2926
2927bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent& rMEvt, bool bCancel )
2928{
2929 if ( !mpData )
2930 return false;
2931
2932 // stop eventual running dropdown timer
2933 if( mnCurPos < mpData->m_aItems.size() &&
2934 (mpData->m_aItems[mnCurPos].mnBits & ToolBoxItemBits::DROPDOWN ) )
2935 {
2936 mpData->maDropdownTimer.Stop();
2937 }
2938
2939 if ( mbDrag )
2940 {
2941 Deactivate();
2942
2943 if ( mbDrag )
2944 mbDrag = false;
2945 else
2946 {
2947 if ( mnCurPos == ITEM_NOTFOUND )
2948 return true;
2949 }
2950
2951 // has mouse been released on top of item?
2952 if( mnCurPos < mpData->m_aItems.size() )
2953 {
2954 ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
2955 if ( pItem->maRect.Contains( rMEvt.GetPosPixel() ) )
2956 {
2957 mnCurItemId = pItem->mnId;
2958 if ( !bCancel )
2959 {
2960 // execute AutoCheck if required
2961 if ( pItem->mnBits & ToolBoxItemBits::AUTOCHECK )
2962 {
2963 if ( pItem->mnBits & ToolBoxItemBits::RADIOCHECK )
2964 {
2965 if ( pItem->meState != TRISTATE_TRUE )
2966 SetItemState( pItem->mnId, TRISTATE_TRUE );
2967 }
2968 else
2969 {
2970 if ( pItem->meState != TRISTATE_TRUE )
2971 pItem->meState = TRISTATE_TRUE;
2972 else
2973 pItem->meState = TRISTATE_FALSE;
2974 }
2975 }
2976
2977 // do not call Select when Repeat is active, as in this
2978 // case that was triggered already in MouseButtonDown
2979 if ( !(pItem->mnBits & ToolBoxItemBits::REPEAT) )
2980 {
2981 // prevent from being destroyed in the select handler
2982 VclPtr<vcl::Window> xWindow = this;
2983 Select();
2984 if ( xWindow->isDisposed() )
2985 return true;
2986 }
2987 }
2988
2989 {
2990 }
2991
2992 // Items not destroyed, in Select handler
2993 if ( mnCurItemId )
2994 {
2995 // Get current pos for the case that items are inserted/removed
2996 // in the toolBox
2998 if ( mnCurPos != ITEM_NOTFOUND )
2999 {
3001 GetOutDev()->Flush();
3002 }
3003 }
3004 }
3005 }
3006
3010 mnMouseModifier = 0;
3011 return true;
3012 }
3013 else if ( mbUpper || mbLower )
3014 {
3015 if ( mbIn )
3016 ShowLine( !mbUpper );
3017 mbUpper = false;
3018 mbLower = false;
3019 mbIn = false;
3021 return true;
3022 }
3023
3024 return false;
3025}
3026
3027void ToolBox::MouseMove( const MouseEvent& rMEvt )
3028{
3029 // pressing a modifier generates synthetic mouse moves
3030 // ignore it if keyboard selection is active
3032 return;
3033
3034 if ( ImplHandleMouseMove( rMEvt ) )
3035 return;
3036
3037 Point aMousePos = rMEvt.GetPosPixel();
3038
3039 // only highlight when the focus is not inside a child window of a toolbox
3040 // eg, in an edit control
3041 // and do not highlight when focus is in a different toolbox
3042 bool bDrawHotSpot = true;
3044
3045 bool bFocusWindowIsAToolBoxChild = false;
3046 if (pFocusWin)
3047 {
3048 vcl::Window *pWin = pFocusWin->GetParent();
3049 while (pWin)
3050 {
3051 if(pWin->ImplGetWindowImpl() && pWin->ImplGetWindowImpl()->mbToolBox)
3052 {
3053 bFocusWindowIsAToolBoxChild = true;
3054 break;
3055 }
3056 pWin = pWin->GetParent();
3057 }
3058 }
3059
3060 if( bFocusWindowIsAToolBoxChild || (pFocusWin && pFocusWin->ImplGetWindowImpl() && pFocusWin->ImplGetWindowImpl()->mbToolBox && pFocusWin != this) )
3061 bDrawHotSpot = false;
3062
3063 if ( mbDragging )
3064 {
3066 pMgr->Dragging( aMousePos );
3067 return;
3068 }
3069
3071
3072 // change mouse cursor over drag area
3074 if( pWrapper && pWrapper->GetDragArea().Contains( rMEvt.GetPosPixel() ) )
3075 eStyle = PointerStyle::Move;
3076
3078 {
3080 {
3081 sal_uInt16 nLinePtr = ImplTestLineSize( rMEvt.GetPosPixel() );
3082 if ( nLinePtr & DOCK_LINEHSIZE )
3083 {
3084 if ( meAlign == WindowAlign::Left )
3086 else
3088 }
3089 else if ( nLinePtr & DOCK_LINEVSIZE )
3090 {
3091 if ( meAlign == WindowAlign::Top )
3093 else
3095 }
3096 }
3097 }
3098
3099 if ( bDrawHotSpot )
3100 {
3101 bool bClearHigh = true;
3102 if ( !rMEvt.IsLeaveWindow() && (mnCurPos == ITEM_NOTFOUND) )
3103 {
3104 ImplToolItems::size_type nTempPos = 0;
3105 for (auto const& item : mpData->m_aItems)
3106 {
3107 if ( item.maRect.Contains( aMousePos ) )
3108 {
3109 if ( (item.meType == ToolBoxItemType::BUTTON) && item.mbEnabled )
3110 {
3111 bClearHigh = false;
3112 if ( mnHighItemId != item.mnId )
3113 {
3114 if ( mnHighItemId )
3115 {
3116 ImplHideFocus();
3117 ImplToolItems::size_type nPos = GetItemPos( mnHighItemId );
3119 CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nPos ) );
3120 }
3121 if ( mpData->mbMenubuttonSelected )
3122 {
3123 // remove highlight from menubutton
3125 }
3126 mnHighItemId = item.mnId;
3127 InvalidateItem(nTempPos);
3128 ImplShowFocus();
3130 }
3131 }
3132 break;
3133 }
3134 ++nTempPos;
3135 }
3136 }
3137
3138 // only clear highlight when focus is not in toolbar
3139 bool bMenuButtonHit = mpData->maMenubuttonItem.maRect.Contains( aMousePos ) && ImplHasClippedItems();
3140 if ( !HasFocus() && (bClearHigh || bMenuButtonHit) )
3141 {
3142 if ( !bMenuButtonHit && mpData->mbMenubuttonSelected )
3143 {
3144 // remove highlight from menubutton
3146 }
3147
3148 if( mnHighItemId )
3149 {
3150 ImplToolItems::size_type nClearPos = GetItemPos( mnHighItemId );
3151 if ( nClearPos != ITEM_NOTFOUND )
3152 {
3153 InvalidateItem(nClearPos);
3154 if( nClearPos != mnCurPos )
3155 CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nClearPos ) );
3156 }
3157 ImplHideFocus();
3159 }
3160
3161 if( bMenuButtonHit )
3162 {
3164 }
3165 }
3166 }
3167
3168 if ( meLastStyle != eStyle )
3169 {
3170 meLastStyle = eStyle;
3171 SetPointer( eStyle );
3172 }
3173
3174 DockingWindow::MouseMove( rMEvt );
3175}
3176
3178{
3179 // only trigger toolbox for left mouse button and when
3180 // we're not in normal operation
3181 if ( rMEvt.IsLeft() && !mbDrag && (mnCurPos == ITEM_NOTFOUND) )
3182 {
3183 // call activate already here, as items could
3184 // be exchanged
3185 Activate();
3186
3187 // update ToolBox here, such that user knows it
3188 if ( mbFormat )
3189 {
3190 ImplFormat();
3192 }
3193
3194 Point aMousePos = rMEvt.GetPosPixel();
3195 ImplToolItems::size_type i = 0;
3196 ImplToolItems::size_type nNewPos = ITEM_NOTFOUND;
3197
3198 // search for item that was clicked
3199 for (auto const& item : mpData->m_aItems)
3200 {
3201 // is this the item?
3202 if ( item.maRect.Contains( aMousePos ) )
3203 {
3204 // do nothing if it is a separator or
3205 // if the item has been disabled
3206 if ( (item.meType == ToolBoxItemType::BUTTON) &&
3207 !item.mbShowWindow )
3208 nNewPos = i;
3209
3210 break;
3211 }
3212
3213 i++;
3214 }
3215
3216 // item found
3217 if ( nNewPos != ITEM_NOTFOUND )
3218 {
3219 if ( !mpData->m_aItems[nNewPos].mbEnabled )
3220 {
3221 Deactivate();
3222 return;
3223 }
3224
3225 // update actual data
3227 mnCurPos = i;
3228 mnCurItemId = mpData->m_aItems[nNewPos].mnId;
3230 mnMouseModifier = rMEvt.GetModifier();
3231 if ( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::REPEAT )
3232 nTrackFlags |= StartTrackingFlags::ButtonRepeat;
3233
3234 // update bDrag here, as it is evaluated in the EndSelection
3235 mbDrag = true;
3236
3237 // on double-click: only call the handler, but do so before the button
3238 // is hit, as in the handler dragging
3239 // can be terminated
3240 if ( rMEvt.GetClicks() == 2 )
3241 DoubleClick();
3242
3243 if ( mbDrag )
3244 {
3246 Highlight();
3247 }
3248
3249 // was dropdown arrow pressed
3250 if( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWN )
3251 {
3252 if( ( (mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWNONLY) == ToolBoxItemBits::DROPDOWNONLY)
3253 || mpData->m_aItems[nNewPos].GetDropDownRect( mbHorz ).Contains( aMousePos ))
3254 {
3255 // dropdownonly always triggers the dropdown handler, over the whole button area
3256
3257 // the drop down arrow should not trigger the item action
3258 mpData->mbDropDownByKeyboard = false;
3259 mpData->maDropdownClickHdl.Call( this );
3260
3261 // do not reset data if the dropdown handler opened a floating window
3262 // see ImplFloatControl()
3263 if( !mpFloatWin )
3264 {
3265 // no floater was opened
3266 Deactivate();
3268
3272 mnMouseModifier = 0;
3274 }
3275 return;
3276 }
3277 else // activate long click timer
3278 mpData->maDropdownTimer.Start();
3279 }
3280
3281 // call Click handler
3282 if ( rMEvt.GetClicks() != 2 )
3283 Click();
3284
3285 // also call Select handler at repeat
3286 if ( nTrackFlags & StartTrackingFlags::ButtonRepeat )
3287 Select();
3288
3289 // if the actions was not aborted in Click handler
3290 if ( mbDrag )
3291 StartTracking( nTrackFlags );
3292
3293 // if mouse was clicked over an item we
3294 // can abort here
3295 return;
3296 }
3297
3298 Deactivate();
3299
3300 // menu button hit ?
3301 if( mpData->maMenubuttonItem.maRect.Contains( aMousePos ) && ImplHasClippedItems() )
3302 {
3303 if ( maMenuButtonHdl.IsSet() )
3304 maMenuButtonHdl.Call( this );
3305 else
3306 ExecuteCustomMenu( mpData->maMenubuttonItem.maRect );
3307 return;
3308 }
3309
3310 // check scroll- and next-buttons here
3311 if ( maUpperRect.Contains( aMousePos ) )
3312 {
3313 if ( mnCurLine > 1 )
3314 {
3315 StartTracking();
3316 mbUpper = true;
3317 mbIn = true;
3318 InvalidateSpin(true, false);
3319 }
3320 return;
3321 }
3322 if ( maLowerRect.Contains( aMousePos ) )
3323 {
3325 {
3326 StartTracking();
3327 mbLower = true;
3328 mbIn = true;
3329 InvalidateSpin(false);
3330 }
3331 return;
3332 }
3333
3334 // Linesizing testen
3336 {
3337 sal_uInt16 nLineMode = ImplTestLineSize( aMousePos );
3338 if ( nLineMode )
3339 {
3341
3342 // call handler, such that we can set the
3343 // dock rectangles
3344 StartDocking();
3345
3347 Size aSize = GetSizePixel();
3348 aPos = ScreenToOutputPixel( aPos );
3349
3350 // start dragging
3351 pMgr->StartDragging( this, aMousePos, tools::Rectangle( aPos, aSize ),
3352 nLineMode );
3353 return;
3354 }
3355 }
3356
3357 // no item, then only click or double click
3358 if ( rMEvt.GetClicks() == 2 )
3359 DoubleClick();
3360 else
3361 Click();
3362 }
3363
3364 if ( !mbDrag && (mnCurPos == ITEM_NOTFOUND) )
3366}
3367
3369{
3370 if ( ImplHandleMouseButtonUp( rMEvt ) )
3371 return;
3372
3373 if ( mbDragging && rMEvt.IsLeft() )
3374 {
3376 pMgr->EndDragging();
3377 return;
3378 }
3379
3381}
3382
3384{
3385 VclPtr<vcl::Window> xWindow = this;
3386
3387 if ( rTEvt.IsTrackingEnded() )
3389 else
3391
3392 if ( xWindow->isDisposed() )
3393 // toolbox was deleted
3394 return;
3395 DockingWindow::Tracking( rTEvt );
3396}
3397
3398void ToolBox::InvalidateItem(ImplToolItems::size_type nPosition)
3399{
3400 if (mpData && nPosition < mpData->m_aItems.size())
3401 {
3402 ImplToolItem* pItem = &mpData->m_aItems[nPosition];
3403 Invalidate(pItem->maRect);
3404 }
3405}
3406
3408{
3409 if (!mpData->maMenubuttonItem.maRect.IsEmpty())
3410 Invalidate(mpData->maMenubuttonItem.maRect);
3411}
3412
3413void ToolBox::InvalidateSpin(bool bUpperIn, bool bLowerIn)
3414{
3415 if (bUpperIn && !maUpperRect.IsEmpty())
3417
3418 if (bLowerIn && !maLowerRect.IsEmpty())
3420}
3421
3422void ToolBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rPaintRect)
3423{
3424 if( mpData->mbIsPaintLocked )
3425 return;
3426
3427 if (rPaintRect == tools::Rectangle(0, 0, mnDX-1, mnDY-1))
3428 mbFullPaint = true;
3429 ImplFormat();
3430 mbFullPaint = false;
3431
3432 ImplDrawBackground(rRenderContext, rPaintRect);
3433
3434 if ( (mnWinStyle & WB_BORDER) && !ImplIsFloatingMode() )
3435 ImplDrawBorder(rRenderContext);
3436
3437 if( !ImplIsFloatingMode() )
3438 ImplDrawGrip(rRenderContext);
3439
3440 ImplDrawMenuButton(rRenderContext, mpData->mbMenubuttonSelected);
3441
3442 // draw SpinButtons
3443 if (mnWinStyle & WB_SCROLL)
3444 {
3445 if (mnCurLines > mnLines)
3446 ImplDrawSpin(rRenderContext);
3447 }
3448
3449 // draw buttons
3450 ImplToolItems::size_type nHighPos;
3451 if ( mnHighItemId )
3452 nHighPos = GetItemPos( mnHighItemId );
3453 else
3454 nHighPos = ITEM_NOTFOUND;
3455
3456 ImplToolItems::size_type nCount = mpData->m_aItems.size();
3457 for( ImplToolItems::size_type i = 0; i < nCount; i++ )
3458 {
3459 ImplToolItem* pItem = &mpData->m_aItems[i];
3460
3461 // only draw when the rectangle is in the draw rectangle
3462 if ( !pItem->maRect.IsEmpty() && rPaintRect.Overlaps( pItem->maRect ) )
3463 {
3464 sal_uInt16 nHighlight = 0;
3465 if ( i == mnCurPos )
3466 nHighlight = 1;
3467 else if ( i == nHighPos )
3468 nHighlight = 2;
3469 ImplDrawItem(rRenderContext, i, nHighlight);
3470 }
3471 }
3472 ImplShowFocus();
3473}
3474
3476{
3477 Size aSize = GetOutputSizePixel();
3478 // #i31422# some WindowManagers send (0,0) sizes when
3479 // switching virtual desktops - ignore this and avoid reformatting
3480 if( !aSize.Width() && !aSize.Height() )
3481 return;
3482
3483 tools::Long nOldDX = mnDX;
3484 tools::Long nOldDY = mnDY;
3485 mnDX = aSize.Width();
3486 mnDY = aSize.Height();
3487
3488 mnLastResizeDY = 0;
3489
3490 // invalidate everything to have gradient backgrounds properly drawn
3491 Invalidate();
3492
3493 // If we have any expandable entries, then force a reformat first using
3494 // their optimal sizes, then share out the excess space evenly across those
3495 // expandables and reformat again
3496 std::vector<size_t> aExpandables;
3497 for (size_t i = 0; i < mpData->m_aItems.size(); ++i)
3498 {
3499 if (mpData->m_aItems[i].mbExpand)
3500 {
3501 vcl::Window *pWindow = mpData->m_aItems[i].mpWindow;
3502 SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
3503 if (!pWindow)
3504 continue;
3505 Size aWinSize(pWindow->GetSizePixel());
3506 Size aPrefSize(pWindow->get_preferred_size());
3507 aWinSize.setWidth( aPrefSize.Width() );
3508 pWindow->SetSizePixel(aWinSize);
3509 aExpandables.push_back(i);
3510 }
3511 }
3512
3513 // re-format or re-draw
3514 if ( mbScroll || !aExpandables.empty() )
3515 {
3516 if ( !mbFormat || !aExpandables.empty() )
3517 {
3518 mbFormat = true;
3519 if( IsReallyVisible() || !aExpandables.empty() )
3520 {
3521 ImplFormat(true);
3522
3523 if (!aExpandables.empty())
3524 {
3525 //Get how big the optimal size is
3526 tools::Rectangle aBounds;
3527 for (const ImplToolItem & rItem : mpData->m_aItems)
3528 {
3529 aBounds.Union( rItem.maRect );
3530 }
3531
3532 auto nOptimalWidth = aBounds.GetWidth();
3533 auto nDiff = aSize.Width() - nOptimalWidth;
3534 decltype(nDiff) nExpandablesSize = aExpandables.size();
3535 nDiff /= nExpandablesSize;
3536
3537 //share out the diff from optimal to real across
3538 //expandable entries
3539 for (size_t nIndex : aExpandables)
3540 {
3541 vcl::Window *pWindow = mpData->m_aItems[nIndex].mpWindow;
3542 Size aWinSize(pWindow->GetSizePixel());
3543 Size aPrefSize(pWindow->get_preferred_size());
3544 aWinSize.setWidth( aPrefSize.Width() + nDiff );
3545 pWindow->SetSizePixel(aWinSize);
3546 }
3547
3548 //now reformat with final sizes
3549 mbFormat = true;
3550 ImplFormat(true);
3551 }
3552 }
3553 }
3554 }
3555
3556 // redraw border
3557 if ( !(mnWinStyle & WB_BORDER) )
3558 return;
3559
3560 // as otherwise, when painting we might think we have to re-draw everything
3561 if ( mbFormat && IsReallyVisible() )
3562 Invalidate();
3563 else
3564 {
3565 if ( mnRightBorder )
3566 {
3567 if ( nOldDX > mnDX )
3569 else
3570 Invalidate( tools::Rectangle( nOldDX-mnRightBorder-1, 0, nOldDX, nOldDY ) );
3571 }
3572
3573 if ( mnBottomBorder )
3574 {
3575 if ( nOldDY > mnDY )
3577 else
3578 Invalidate( tools::Rectangle( 0, nOldDY-mnBottomBorder-1, nOldDX, nOldDY ) );
3579 }
3580 }
3581}
3582
3583namespace
3584{
3585 bool DispatchableCommand(std::u16string_view rName)
3586 {
3587 return o3tl::starts_with(rName, u".uno") ||
3588 o3tl::starts_with(rName, u"slot:") ||
3589 o3tl::starts_with(rName, u"macro:") ||
3590 o3tl::starts_with(rName, u"vnd.sun.star.script");
3591 }
3592}
3593
3594const OUString& ToolBox::ImplGetHelpText( ToolBoxItemId nItemId ) const
3595{
3596 ImplToolItem* pItem = ImplGetItem( nItemId );
3597
3598 assert( pItem );
3599
3600 if ( pItem->maHelpText.isEmpty() && ( !pItem->maHelpId.isEmpty() || pItem->maCommandStr.getLength() ))
3601 {
3602 Help* pHelp = Application::GetHelp();
3603 if ( pHelp )
3604 {
3605 if (DispatchableCommand(pItem->maCommandStr))
3606 pItem->maHelpText = pHelp->GetHelpText( pItem->maCommandStr, this );
3607 if ( pItem->maHelpText.isEmpty() && !pItem->maHelpId.isEmpty() )
3608 pItem->maHelpText = pHelp->GetHelpText( OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
3609 }
3610 }
3611
3612 return pItem->maHelpText;
3613}
3614
3616{
3617 ToolBoxItemId nItemId;
3618 Point aHelpPos;
3619
3620 if( !rHEvt.KeyboardActivated() )
3621 {
3622 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
3623 aHelpPos = rHEvt.GetMousePosPixel();
3624 }
3625 else
3626 {
3627 if( !mnHighItemId )
3628 return;
3629 else
3630 nItemId = mnHighItemId;
3631 tools::Rectangle aRect( GetItemRect( nItemId ) );
3632 if( aRect.IsEmpty() )
3633 return;
3634 else
3635 aHelpPos = OutputToScreenPixel( aRect.Center() );
3636 }
3637
3638 if ( nItemId )
3639 {
3641 {
3642 // get rectangle
3643 tools::Rectangle aTempRect = GetItemRect( nItemId );
3644 Point aPt = OutputToScreenPixel( aTempRect.TopLeft() );
3645 aTempRect.SetLeft( aPt.X() );
3646 aTempRect.SetTop( aPt.Y() );
3647 aPt = OutputToScreenPixel( aTempRect.BottomRight() );
3648 aTempRect.SetRight( aPt.X() );
3649 aTempRect.SetBottom( aPt.Y() );
3650
3651 // get text and display it
3652 OUString aStr = GetQuickHelpText( nItemId );
3653 if (aStr.isEmpty())
3655 if ( rHEvt.GetMode() & HelpEventMode::BALLOON )
3656 {
3657 const OUString& rHelpStr = GetHelpText( nItemId );
3658 if (!rHelpStr.isEmpty())
3659 aStr = rHelpStr;
3660 Help::ShowBalloon( this, aHelpPos, aTempRect, aStr );
3661 }
3662 else
3664 return;
3665 }
3666 }
3667
3669}
3670
3672{
3673 if ( rNEvt.GetType() == NotifyEventType::KEYINPUT )
3674 {
3675 KeyEvent aKEvt = *rNEvt.GetKeyEvent();
3676 vcl::KeyCode aKeyCode = aKEvt.GetKeyCode();
3677 sal_uInt16 nKeyCode = aKeyCode.GetCode();
3678 switch( nKeyCode )
3679 {
3680 case KEY_TAB:
3681 {
3682 // internal TAB cycling only if parent is not a dialog or if we are the only child
3683 // otherwise the dialog control will take over
3684 vcl::Window *pParent = ImplGetParent();
3685 bool bOldSchoolContainer =
3687 pParent->GetChildCount() != 1);
3688 bool bNoTabCycling = bOldSchoolContainer || isContainerWindow(pParent);
3689
3690 if( bNoTabCycling )
3691 return DockingWindow::EventNotify( rNEvt );
3692 else if( ImplChangeHighlightUpDn( aKeyCode.IsShift() , bNoTabCycling ) )
3693 return true;
3694 else
3695 return DockingWindow::EventNotify( rNEvt );
3696 }
3697 default:
3698 break;
3699 }
3700 }
3701 else if( rNEvt.GetType() == NotifyEventType::GETFOCUS )
3702 {
3703 if( rNEvt.GetWindow() == this )
3704 {
3705 // the toolbar itself got the focus
3706 if( mnLastFocusItemId != ToolBoxItemId(0) || mpData->mbMenubuttonWasLastSelected )
3707 {
3708 // restore last item
3709 if( mpData->mbMenubuttonWasLastSelected )
3710 {
3711 ImplChangeHighlight( nullptr );
3712 mpData->mbMenubuttonSelected = true;
3714 }
3715 else
3716 {
3719 }
3720 }
3722 // Shift-TAB was pressed in the parent
3723 ImplChangeHighlightUpDn( false );
3724 else
3726
3728
3729 return true;
3730 }
3731 else
3732 {
3733 // a child window got the focus so update current item to
3734 // allow for proper lose focus handling in keyboard navigation
3735 for (auto const& item : mpData->m_aItems)
3736 {
3737 if ( item.mbVisible )
3738 {
3739 if ( item.mpWindow && item.mpWindow->ImplIsWindowOrChild( rNEvt.GetWindow() ) )
3740 {
3741 mnHighItemId = item.mnId;
3742 break;
3743 }
3744 }
3745 }
3746 return DockingWindow::EventNotify( rNEvt );
3747 }
3748 }
3749 else if( rNEvt.GetType() == NotifyEventType::LOSEFOCUS )
3750 {
3751 // deselect
3752 ImplHideFocus();
3753 mpData->mbMenubuttonWasLastSelected = false;
3756 }
3757
3758 return DockingWindow::EventNotify( rNEvt );
3759}
3760
3761void ToolBox::Command( const CommandEvent& rCEvt )
3762{
3763 if ( rCEvt.GetCommand() == CommandEventId::Wheel )
3764 {
3765 if ( (mnCurLine > 1) || (mnCurLine+mnVisLines-1 < mnCurLines) )
3766 {
3767 const CommandWheelData* pData = rCEvt.GetWheelData();
3768 if ( pData->GetMode() == CommandWheelMode::SCROLL )
3769 {
3770 if ( (mnCurLine > 1) && (pData->GetDelta() > 0) )
3771 ShowLine( false );
3772 else if ( (mnCurLine+mnVisLines-1 < mnCurLines) && (pData->GetDelta() < 0) )
3773 ShowLine( true );
3775 return;
3776 }
3777 }
3778 }
3779 else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
3780 {
3782 return;
3783 }
3784
3785 DockingWindow::Command( rCEvt );
3786}
3787
3789{
3791
3793 ImplFormat();
3794 else if ( nType == StateChangedType::Enable )
3796 else if ( nType == StateChangedType::UpdateMode )
3797 {
3798 if ( IsUpdateMode() )
3799 Invalidate();
3800 }
3801 else if ( (nType == StateChangedType::Zoom) ||
3803 {
3804 mbCalc = true;
3805 mbFormat = true;
3806 ImplInitSettings( true, false, false );
3807 Invalidate();
3808 }
3810 {
3811 ImplInitSettings( false, true, false );
3812 Invalidate();
3813 }
3815 {
3816 ImplInitSettings( false, false, true ); // font, foreground, background
3817 Invalidate();
3818 }
3819
3821}
3822
3824{
3826
3827 if ( (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
3828 (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
3830 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
3831 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
3832 {
3833 mbCalc = true;
3834 mbFormat = true;
3835 ImplInitSettings( true, true, true );
3836 Invalidate();
3837 }
3838
3839 maDataChangedHandler.Call( &rDCEvt );
3840}
3841
3843{
3844 mnWinStyle = nNewStyle;
3845 if (!ImplIsFloatingMode())
3846 {
3847 bool bOldScroll = mbScroll;
3848 mbScroll = (mnWinStyle & WB_SCROLL) != 0;
3849 if (mbScroll != bOldScroll)
3850 {
3851 mbFormat = true;
3852 ImplFormat();
3853 }
3854 }
3855}
3856
3858{
3860
3861 if (!mpData)
3862 return;
3863
3864 bool bOldHorz = mbHorz;
3865
3866 if ( ImplIsFloatingMode() )
3867 {
3868 mbHorz = true;
3870 mbScroll = true;
3871
3872 if( bOldHorz != mbHorz )
3873 mbCalc = true; // orientation was changed !
3874
3877 }
3878 else
3879 {
3880 mbScroll = (mnWinStyle & WB_SCROLL) != 0;
3882 mbHorz = true;
3883 else
3884 mbHorz = false;
3885
3886 // set focus back to document
3888 }
3889
3890 if( bOldHorz != mbHorz )
3891 {
3892 // if orientation changes, the toolbox has to be initialized again
3893 // to update the direction of the gradient
3894 mbCalc = true;
3895 ImplInitSettings( true, true, true );
3896 }
3897
3898 mbFormat = true;
3899 ImplFormat();
3900}
3901
3903{
3908}
3909
3910bool ToolBox::Docking( const Point& rPos, tools::Rectangle& rRect )
3911{
3912 // do nothing during dragging, it was calculated before
3913 if ( mbDragging )
3914 return false;
3915
3916 bool bFloatMode = false;
3917
3918 DockingWindow::Docking( rPos, rRect );
3919
3920 // if the mouse is outside the area, it can only become a floating window
3921 tools::Rectangle aDockingRect( rRect );
3922 if ( !ImplIsFloatingMode() )
3923 {
3924 // don't use tracking rectangle for alignment check, because it will be too large
3925 // to get a floating mode as result - switch to floating size
3926 // so the calculation only depends on the position of the rectangle, not the current
3927 // docking state of the window
3928 ImplToolItems::size_type nTemp = 0;
3929 aDockingRect.SetSize( ImplCalcFloatSize( nTemp ) );
3930
3931 // in this mode docking is never done by keyboard, so it's OK to use the mouse position
3932 aDockingRect.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
3933 }
3934
3935 bFloatMode = true;
3936
3938 if ( !mbLastFloatMode )
3939 {
3940 ImplToolItems::size_type nTemp = 0;
3941 aDockingRect.SetSize( ImplCalcFloatSize( nTemp ) );
3942 }
3943
3944 rRect = aDockingRect;
3945 mbLastFloatMode = bFloatMode;
3946
3947 return bFloatMode;
3948}
3949
3950void ToolBox::EndDocking( const tools::Rectangle& rRect, bool bFloatMode )
3951{
3952 if ( !IsDockingCanceled() )
3953 {
3954 if ( mnLines != mnDockLines )
3956 if ( meAlign != meDockAlign )
3958 }
3959 if ( bFloatMode || (bFloatMode != ImplIsFloatingMode()) )
3960 DockingWindow::EndDocking( rRect, bFloatMode );
3961}
3962
3964{
3965 ImplToolItems::size_type nCalcLines;
3966 ImplToolItems::size_type nTemp;
3967
3968 // calculate all floating sizes
3970
3971 if ( !mnLastResizeDY )
3973
3974 // is vertical resizing needed
3975 if ( (mnLastResizeDY != rSize.Height()) && (mnDY != rSize.Height()) )
3976 {
3977 nCalcLines = ImplCalcLines( rSize.Height() );
3978 if ( nCalcLines < 1 )
3979 nCalcLines = 1;
3980 rSize = ImplCalcFloatSize( nCalcLines );
3981 }
3982 else
3983 {
3984 nCalcLines = 1;
3985 nTemp = nCalcLines;
3986 Size aTempSize = ImplCalcFloatSize( nTemp );
3987 while ( (aTempSize.Width() > rSize.Width()) &&
3988 (nCalcLines <= maFloatSizes[0].mnLines) )
3989 {
3990 nCalcLines++;
3991 nTemp = nCalcLines;
3992 aTempSize = ImplCalcFloatSize( nTemp );
3993 }
3994 rSize = aTempSize;
3995 }
3996
3997 mnLastResizeDY = rSize.Height();
3998}
3999
4001{
4002 // If we have any expandable entries, then force them to their
4003 // optimal sizes, then reset them afterwards
4004 std::map<vcl::Window*, Size> aExpandables;
4005 for (const ImplToolItem & rItem : mpData->m_aItems)
4006 {
4007 if (rItem.mbExpand)
4008 {
4009 vcl::Window *pWindow = rItem.mpWindow;
4010 SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
4011 if (!pWindow)
4012 continue;
4013 Size aWinSize(pWindow->GetSizePixel());
4014 aExpandables[pWindow] = aWinSize;
4015 Size aPrefSize(pWindow->get_preferred_size());
4016 aWinSize.setWidth( aPrefSize.Width() );
4017 pWindow->SetSizePixel(aWinSize);
4018 }
4019 }
4020
4021 Size aSize(const_cast<ToolBox *>(this)->ImplCalcSize( mnLines ));
4022
4023 for (auto const& [pWindow, aWinSize] : aExpandables)
4024 pWindow->SetSizePixel(aWinSize);
4025
4026 return aSize;
4027}
4028
4029Size ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines )
4030{
4031 return ImplCalcSize( nCalcLines );
4032}
4033
4034Size ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines, WindowAlign eAlign )
4035{
4036 return ImplCalcSize( nCalcLines,
4038}
4039
4040ToolBox::ImplToolItems::size_type ToolBox::ImplCountLineBreaks() const
4041{
4042 ImplToolItems::size_type nLines = 0;
4043
4044 for (auto const& item : mpData->m_aItems)
4045 {
4046 if( item.meType == ToolBoxItemType::BREAK )
4047 ++nLines;
4048 }
4049 return nLines;
4050}
4051
4053{
4054 // count number of breaks and calc corresponding floating window size
4055 ImplToolItems::size_type nLines = ImplCountLineBreaks();
4056
4057 if( nLines )
4058 ++nLines; // add the first line
4059 else
4060 {
4061 // no breaks found: use quadratic layout
4062 nLines = static_cast<ImplToolItems::size_type>(ceil( sqrt( static_cast<double>(GetItemCount()) ) ));
4063 }
4064
4065 bool bPopup = mpData->mbAssumePopupMode;
4066 mpData->mbAssumePopupMode = true;
4067
4068 Size aSize = CalcFloatingWindowSizePixel( nLines );
4069
4070 mpData->mbAssumePopupMode = bPopup;
4071 return aSize;
4072}
4073
4075{
4076 ImplToolItems::size_type nLines = ImplCountLineBreaks();
4077 ++nLines; // add the first line
4078 return CalcFloatingWindowSizePixel( nLines );
4079}
4080
4081Size ToolBox::CalcFloatingWindowSizePixel( ImplToolItems::size_type nCalcLines )
4082{
4083 bool bFloat = mpData->mbAssumeFloating;
4084 bool bDocking = mpData->mbAssumeDocked;
4085
4086 // simulate floating mode and force reformat before calculating
4087 mpData->mbAssumeFloating = true;
4088 mpData->mbAssumeDocked = false;
4089
4090 Size aSize = ImplCalcFloatSize( nCalcLines );
4091
4092 mbFormat = true;
4093 mpData->mbAssumeFloating = bFloat;
4094 mpData->mbAssumeDocked = bDocking;
4095
4096 return aSize;
4097}
4098
4100{
4101 if( ImplIsFloatingMode() )
4102 return ImplCalcSize( mnFloatLines );
4103 else
4104 {
4105 // create dummy toolbox for measurements
4107
4108 // copy until first useful item
4109 for (auto const& item : mpData->m_aItems)
4110 {
4111 pToolBox->CopyItem( *this, item.mnId );
4112 if( (item.meType == ToolBoxItemType::BUTTON) &&
4113 item.mbVisible && !ImplIsFixedControl( &item ) )
4114 break;
4115 }
4116
4117 // add to docking manager if required to obtain a drag area
4118 // (which is accounted for in calcwindowsizepixel)
4119 if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
4120 ImplGetDockingManager()->AddWindow( pToolBox );
4121
4122 // account for menu
4123 if( IsMenuEnabled() )
4124 pToolBox->SetMenuType( GetMenuType() );
4125
4126 pToolBox->SetAlign( GetAlign() );
4127 Size aSize = pToolBox->CalcWindowSizePixel( 1 );
4128
4129 ImplGetDockingManager()->RemoveWindow( pToolBox );
4130 pToolBox->Clear();
4131
4132 pToolBox.disposeAndClear();
4133
4134 return aSize;
4135 }
4136}
4137
4138void ToolBox::EnableCustomize( bool bEnable )
4139{
4140 mbCustomize = bEnable;
4141}
4142
4144{
4145 ImplChangeHighlight( nullptr, true );
4146
4148}
4149
4150// performs the action associated with an item, ie simulates clicking the item
4152{
4153 mnHighItemId = nItemId;
4154 vcl::KeyCode aKeyCode( 0, 0 );
4155 ImplActivateItem( aKeyCode );
4156}
4157
4158// calls the button's action handler
4159// returns true if action was called
4161{
4162 bool bRet = true;
4163 if( mnHighItemId )
4164 {
4165 ImplToolItem *pToolItem = ImplGetItem( mnHighItemId );
4166
4167 // #107712#, activate can also be called for disabled entries
4168 if( pToolItem && !pToolItem->mbEnabled )
4169 return true;
4170
4171 if( pToolItem && pToolItem->mpWindow && HasFocus() )
4172 {
4173 ImplHideFocus();
4174 mbChangingHighlight = true; // avoid focus change due to loss of focus
4176 mbChangingHighlight = false;
4177 }
4178 else
4179 {
4181 if (pToolItem && (pToolItem->mnBits & ToolBoxItemBits::AUTOCHECK))
4182 {
4183 if ( pToolItem->mnBits & ToolBoxItemBits::RADIOCHECK )
4184 {
4185 if ( pToolItem->meState != TRISTATE_TRUE )
4186 SetItemState( pToolItem->mnId, TRISTATE_TRUE );
4187 }
4188 else
4189 {
4190 if ( pToolItem->meState != TRISTATE_TRUE )
4191 pToolItem->meState = TRISTATE_TRUE;
4192 else
4193 pToolItem->meState = TRISTATE_FALSE;
4194 }
4195 }
4196 mnMouseModifier = aKeyCode.GetModifier();
4197 mbIsKeyEvent = true;
4198 Activate();
4199 Click();
4200
4201 // #107776# we might be destroyed in the selecthandler
4202 VclPtr<vcl::Window> xWindow = this;
4203 Select();
4204 if ( xWindow->isDisposed() )
4205 return bRet;
4206
4207 Deactivate();
4208 mbIsKeyEvent = false;
4209 mnMouseModifier = 0;
4210 }
4211 }
4212 else
4213 bRet = false;
4214 return bRet;
4215}
4216
4217static bool ImplCloseLastPopup( vcl::Window const *pParent )
4218{
4219 // close last popup toolbox (see also:
4220 // ImplHandleMouseFloatMode(...) in winproc.cxx )
4221
4222 if (ImplGetSVData()->mpWinData->mpFirstFloat)
4223 {
4225 // only close the floater if it is not our direct parent, which would kill ourself
4226 if( pLastLevelFloat && pLastLevelFloat != pParent )
4227 {
4229 return true;
4230 }
4231 }
4232 return false;
4233}
4234
4235// opens a drop down toolbox item
4236// returns true if item was opened
4238{
4239 sal_uInt16 nCode = aKeyCode.GetCode();
4240 bool bRet = true;
4241
4242 // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
4243 if ( ((nCode == KEY_LEFT || nCode == KEY_RIGHT) && IsHorizontal())
4244 || ((nCode == KEY_UP || nCode == KEY_DOWN) && !IsHorizontal()) )
4245 return false;
4246
4247 if( mpData->mbMenubuttonSelected )
4248 {
4249 if( ImplCloseLastPopup( GetParent() ) )
4250 return bRet;
4251 mbIsKeyEvent = true;
4252 if ( maMenuButtonHdl.IsSet() )
4253 maMenuButtonHdl.Call( this );
4254 else
4255 ExecuteCustomMenu( mpData->maMenubuttonItem.maRect );
4256 mpData->mbMenubuttonWasLastSelected = true;
4257 mbIsKeyEvent = false;
4258 }
4259 else if( mnHighItemId && ImplGetItem( mnHighItemId ) &&
4261 {
4264 mnLastFocusItemId = mnCurItemId; // save item id for possible later focus restore
4265 mnMouseModifier = aKeyCode.GetModifier();
4266 mbIsKeyEvent = true;
4267 Activate();
4268
4269 mpData->mbDropDownByKeyboard = true;
4270 mpData->maDropdownClickHdl.Call( this );
4271
4272 mbIsKeyEvent = false;
4273 mnMouseModifier = 0;
4274 }
4275 else
4276 bRet = false;
4277
4278 return bRet;
4279}
4280
4281void ToolBox::KeyInput( const KeyEvent& rKEvt )
4282{
4283 vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
4284 sal_uInt16 nCode = aKeyCode.GetCode();
4285
4286 vcl::Window *pParent = ImplGetParent();
4287 bool bOldSchoolContainer = ((pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL);
4288 bool bParentIsContainer = bOldSchoolContainer || isContainerWindow(pParent);
4289
4290 bool bForwardKey = false;
4291 bool bGrabFocusToDocument = false;
4292
4293 // #107776# we might be destroyed in the keyhandler
4294 VclPtr<vcl::Window> xWindow = this;
4295
4296 switch ( nCode )
4297 {
4298 case KEY_UP:
4299 {
4300 // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
4301 if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4302 break;
4303 if( !IsHorizontal() )
4305 else
4306 ImplOpenItem( aKeyCode );
4307 }
4308 break;
4309 case KEY_LEFT:
4310 {
4311 if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4312 break;
4313 if( IsHorizontal() )
4315 else
4316 ImplOpenItem( aKeyCode );
4317 }
4318 break;
4319 case KEY_DOWN:
4320 {
4321 if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4322 break;
4323 if( !IsHorizontal() )
4324 ImplChangeHighlightUpDn( false );
4325 else
4326 ImplOpenItem( aKeyCode );
4327 }
4328 break;
4329 case KEY_RIGHT:
4330 {
4331 if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4332 break;
4333 if( IsHorizontal() )
4334 ImplChangeHighlightUpDn( false );
4335 else
4336 ImplOpenItem( aKeyCode );
4337 }
4338 break;
4339 case KEY_PAGEUP:
4340 if ( mnCurLine > 1 )
4341 {
4342 if( mnCurLine > mnVisLines )
4344 else
4345 mnCurLine = 1;
4346 mbFormat = true;
4347 ImplFormat();
4350 }
4351 break;
4352 case KEY_PAGEDOWN:
4354 {
4355 if( mnCurLine + 2*mnVisLines-1 < mnCurLines )
4357 else
4359 mbFormat = true;
4360 ImplFormat();
4363 }
4364 break;
4365 case KEY_END:
4366 {
4367 ImplChangeHighlight( nullptr );
4368 ImplChangeHighlightUpDn( false );
4369 }
4370 break;
4371 case KEY_HOME:
4372 {
4373 ImplChangeHighlight( nullptr );
4375 }
4376 break;
4377 case KEY_ESCAPE:
4378 {
4379 if( !ImplIsFloatingMode() && bParentIsContainer )
4380 DockingWindow::KeyInput( rKEvt );
4381 else
4382 {
4383 // send focus to document pane
4384 vcl::Window *pWin = this;
4385 while( pWin )
4386 {
4387 if( !pWin->GetParent() )
4388 {
4390 break;
4391 }
4392 pWin = pWin->GetParent();
4393 }
4394 }
4395 }
4396 break;
4397 case KEY_RETURN:
4398 {
4399 // #107712#, disabled entries are selectable now
4400 // leave toolbox and move focus to document
4401 if( mnHighItemId )
4402 {
4404 if (!pItem || !pItem->mbEnabled)
4405 {
4406 bGrabFocusToDocument = true;
4407 }
4408 }
4409 if( !bGrabFocusToDocument )
4410 bForwardKey = !ImplActivateItem( aKeyCode );
4411 }
4412 break;
4413 case KEY_SPACE:
4414 {
4415 ImplOpenItem( aKeyCode );
4416 }
4417 break;
4418 default:
4419 {
4420 sal_uInt16 aKeyGroup = aKeyCode.GetGroup();
4421 ImplToolItem *pItem = nullptr;
4422 if( mnHighItemId )
4423 pItem = ImplGetItem( mnHighItemId );
4424 // #i13931# forward alphanum keyinput into embedded control
4425 if( (aKeyGroup == KEYGROUP_NUM || aKeyGroup == KEYGROUP_ALPHA ) && pItem && pItem->mpWindow && pItem->mbEnabled )
4426 {
4427 vcl::Window *pFocusWindow = Application::GetFocusWindow();
4428 ImplHideFocus();
4429 mbChangingHighlight = true; // avoid focus change due to loss of focus
4431 mbChangingHighlight = false;
4432 if( pFocusWindow != Application::GetFocusWindow() )
4434 }
4435 else
4436 {
4437 // do nothing to avoid key presses going into the document
4438 // while the toolbox has the focus
4439 // just forward function and special keys and combinations with Alt-key
4440 if( aKeyGroup == KEYGROUP_FKEYS || aKeyGroup == KEYGROUP_MISC || aKeyCode.IsMod2() )
4441 bForwardKey = true;
4442 }
4443 }
4444 }
4445
4446 if ( xWindow->isDisposed() )
4447 return;
4448
4449 // #107251# move focus away if this toolbox was disabled during keyinput
4450 if (HasFocus() && mpData->mbKeyInputDisabled && bParentIsContainer)
4451 {
4452 vcl::Window *pFocusControl = pParent->ImplGetDlgWindow( 0, GetDlgWindowType::First );
4453 if ( pFocusControl && pFocusControl != this )
4454 pFocusControl->ImplControlFocus( GetFocusFlags::Init );
4455 }
4456
4457 // #107712#, leave toolbox
4458 if( bGrabFocusToDocument )
4459 {
4461 return;
4462 }
4463
4464 if( bForwardKey )
4465 DockingWindow::KeyInput( rKEvt );
4466}
4467
4468// returns the current toolbox line of the item
4469ToolBox::ImplToolItems::size_type ToolBox::ImplGetItemLine( ImplToolItem const * pCurrentItem )
4470{
4471 ImplToolItems::size_type nLine = 1;
4472 for (auto const& item : mpData->m_aItems)
4473 {
4474 if ( item.mbBreak )
4475 ++nLine;
4476 if( &item == pCurrentItem)
4477 break;
4478 }
4479 return nLine;
4480}
4481
4482// returns the first displayable item in the given line
4483ImplToolItem* ToolBox::ImplGetFirstValidItem( ImplToolItems::size_type nLine )
4484{
4485 if( !nLine || nLine > mnCurLines )
4486 return nullptr;
4487
4488 nLine--;
4489
4490 ImplToolItems::iterator it = mpData->m_aItems.begin();
4491 while( it != mpData->m_aItems.end() )
4492 {
4493 // find correct line
4494 if ( it->mbBreak )
4495 nLine--;
4496 if( !nLine )
4497 {
4498 // find first useful item
4499 while( it != mpData->m_aItems.end() && ((it->meType != ToolBoxItemType::BUTTON) || !it->mbVisible || ImplIsFixedControl( &(*it) )) )
4501 {
4502 ++it;
4503 if( it == mpData->m_aItems.end() || it->mbBreak )
4504 return nullptr; // no valid items in this line
4505 }
4506 return &(*it);
4507 }
4508 ++it;
4509 }
4510
4511 return (it == mpData->m_aItems.end()) ? nullptr : &(*it);
4512}
4513
4514ToolBox::ImplToolItems::size_type ToolBox::ImplFindItemPos( const ImplToolItem* pItem, const ImplToolItems& rList )
4515{
4516 if( pItem )
4517 {
4518 for( ImplToolItems::size_type nPos = 0; nPos < rList.size(); ++nPos )
4519 if( &rList[ nPos ] == pItem )
4520 return nPos;
4521 }
4522 return ITEM_NOTFOUND;
4523}
4524
4525void ToolBox::ChangeHighlight( ImplToolItems::size_type nPos )
4526{
4527 if ( nPos < GetItemCount() ) {
4530 }
4531}
4532
4533void ToolBox::ImplChangeHighlight( ImplToolItem const * pItem, bool bNoGrabFocus )
4534{
4535 // avoid recursion due to focus change
4537 return;
4538
4539 mbChangingHighlight = true;
4540
4541 ImplToolItem* pOldItem = nullptr;
4542
4543 if ( mnHighItemId )
4544 {
4545 ImplHideFocus();
4546 ImplToolItems::size_type nPos = GetItemPos( mnHighItemId );
4547 pOldItem = ImplGetItem( mnHighItemId );
4548 // #i89962# ImplDrawItem can cause Invalidate/Update
4549 // which will in turn ImplShowFocus again
4550 // set mnHighItemId to 0 already to prevent this hen/egg problem
4553 CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nPos ) );
4554 }
4555
4556 if( !bNoGrabFocus && pItem != pOldItem && pOldItem && pOldItem->mpWindow )
4557 {
4558 // move focus into toolbox
4559 GrabFocus();
4560 }
4561
4562 if( pItem )
4563 {
4564 ImplToolItems::size_type aPos = ToolBox::ImplFindItemPos( pItem, mpData->m_aItems );
4565 if( aPos != ITEM_NOTFOUND)
4566 {
4567 // check for line breaks
4568 ImplToolItems::size_type nLine = ImplGetItemLine( pItem );
4569
4570 if( nLine >= mnCurLine + mnVisLines )
4571 {
4572 mnCurLine = nLine - mnVisLines + 1;
4573 mbFormat = true;
4574 }
4575 else if ( nLine < mnCurLine )
4576 {
4577 mnCurLine = nLine;
4578 mbFormat = true;
4579 }
4580
4581 if( mbFormat )
4582 {
4583 ImplFormat();
4584 }
4585
4586 mnHighItemId = pItem->mnId;
4587 InvalidateItem(aPos);
4588
4589 ImplShowFocus();
4590
4591 if( pItem->mpWindow )
4592 pItem->mpWindow->GrabFocus();
4593 if( pItem != pOldItem )
4595 }
4596 }
4597 else
4598 {
4599 ImplHideFocus();
4602 }
4603
4604 mbChangingHighlight = false;
4605}
4606
4607// check for keyboard accessible items
4608static bool ImplIsValidItem( const ImplToolItem* pItem, bool bNotClipped )
4609{
4610 bool bValid = (pItem && pItem->meType == ToolBoxItemType::BUTTON && pItem->mbVisible && !ImplIsFixedControl( pItem )
4611 && pItem->mbEnabled);
4612 if( bValid && bNotClipped && pItem->IsClipped() )
4613 bValid = false;
4614 return bValid;
4615}
4616
4617bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
4618{
4619 ImplToolItem* pToolItem = ImplGetItem( mnHighItemId );
4620
4621 if( !pToolItem || !mnHighItemId )
4622 {
4623 // menubutton highlighted ?
4624 if( mpData->mbMenubuttonSelected )
4625 {
4626 mpData->mbMenubuttonSelected = false;
4627 if( bUp )
4628 {
4629 // select last valid non-clipped item
4630 ImplToolItem* pItem = nullptr;
4631 auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(),
4632 [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); });
4633 if( it != mpData->m_aItems.rend() )
4634 pItem = &(*it);
4635
4637 ImplChangeHighlight( pItem );
4638 }
4639 else
4640 {
4641 // select first valid non-clipped item
4642 ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
4643 [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); });
4644 if( it != mpData->m_aItems.end() )
4645 {
4647 ImplChangeHighlight( &(*it) );
4648 }
4649 }
4650 return true;
4651 }
4652
4653 if( bUp )
4654 {
4655 // Select first valid item
4656 ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
4657 [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); });
4658
4659 // select the menu button if a clipped item would be selected
4660 if( (it != mpData->m_aItems.end() && &(*it) == ImplGetFirstClippedItem()) && IsMenuEnabled() )
4661 {
4662 ImplChangeHighlight( nullptr );
4663 mpData->mbMenubuttonSelected = true;
4665 }
4666 else
4667 ImplChangeHighlight( (it != mpData->m_aItems.end()) ? &(*it) : nullptr );
4668 return true;
4669 }
4670 else
4671 {
4672 // Select last valid item
4673
4674 // docked toolbars have the menubutton as last item - if this button is enabled
4676 {
4677 ImplChangeHighlight( nullptr );
4678 mpData->mbMenubuttonSelected = true;
4680 }
4681 else
4682 {
4683 ImplToolItem* pItem = nullptr;
4684 auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(),
4685 [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); });
4686 if( it != mpData->m_aItems.rend() )
4687 pItem = &(*it);
4688
4689 ImplChangeHighlight( pItem );
4690 }
4691 return true;
4692 }
4693 }
4694
4695 assert(pToolItem);
4696
4697 ImplToolItems::size_type pos = ToolBox::ImplFindItemPos( pToolItem, mpData->m_aItems );
4698 ImplToolItems::size_type nCount = mpData->m_aItems.size();
4699
4700 ImplToolItems::size_type i=0;
4701 do
4702 {
4703 if( bUp )
4704 {
4705 if( !pos-- )
4706 {
4707 if( bNoCycle )
4708 return false;
4709
4710 // highlight the menu button if it is the last item
4712 {
4713 ImplChangeHighlight( nullptr );
4714 mpData->mbMenubuttonSelected = true;
4716 return true;
4717 }
4718 else
4719 pos = nCount-1;
4720 }
4721 }
4722 else
4723 {
4724 if( ++pos >= nCount )
4725 {
4726 if( bNoCycle )
4727 return false;
4728
4729 // highlight the menu button if it is the last item
4731 {
4732 ImplChangeHighlight( nullptr );
4733 mpData->mbMenubuttonSelected = true;
4735 return true;
4736 }
4737 else
4738 pos = 0;
4739 }
4740 }
4741
4742 pToolItem = &mpData->m_aItems[pos];
4743
4744 if ( ImplIsValidItem( pToolItem, false ) )
4745 break;
4746
4747 } while( ++i < nCount);
4748
4749 if( pToolItem->IsClipped() && IsMenuEnabled() )
4750 {
4751 // select the menu button if a clipped item would be selected
4752 ImplChangeHighlight( nullptr );
4753 mpData->mbMenubuttonSelected = true;
4755 }
4756 else if( i != nCount )
4757 ImplChangeHighlight( pToolItem );
4758 else
4759 return false;
4760
4761 return true;
4762}
4763
4765{
4766 if( mnHighItemId && HasFocus() )
4767 {
4769 if (pItem && pItem->mpWindow && !pItem->mpWindow->isDisposed())
4770 {
4773 pWin->Invalidate();
4774 }
4775 }
4776}
4777
4779{
4780 if( mnHighItemId )
4781 {
4782 mpData->mbMenubuttonWasLastSelected = false;
4784 if( pItem && pItem->mpWindow )
4785 {
4788 pWin->Invalidate();
4789 }
4790 }
4791
4792 if ( mpData && mpData->mbMenubuttonSelected )
4793 {
4794 mpData->mbMenubuttonWasLastSelected = true;
4795 // remove highlight from menubutton
4796 mpData->mbMenubuttonSelected = false;
4798 }
4799}
4800
4802{
4803 if ( meLayoutMode != eLayout )
4804 meLayoutMode = eLayout;
4805}
4806
4808{
4809 meTextPosition = ePosition;
4810}
4811
4812/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawImageFlags
DrawTextFlags
sal_Int32 nLineWidth
void SetSelectHdl(const Link< Accelerator &, void > &rLink)
Definition: accel.hxx:88
void InsertItem(sal_uInt16 nItemId, const vcl::KeyCode &rKeyCode)
Definition: accel.cxx:233
const StyleSettings & GetStyleSettings() const
static OutputDevice * GetDefaultDevice()
Get the default "device" (in this case the default window).
Definition: svapp.cxx:1166
static bool InsertAccel(Accelerator *pAccel)
Insert accelerator.
Definition: svapp.cxx:1447
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:761
static void RemoveAccel(Accelerator const *pAccel)
Remove accelerator.
Definition: svapp.cxx:1456
static Help * GetHelp()
Gets the application's help.
Definition: svapp.cxx:1476
static vcl::Window * GetFocusWindow()
Get the currently focused window.
Definition: svapp.cxx:1161
bool IsEmpty() const
Definition: BitmapEx.cxx:177
bool IsDark() const
CommandEventId GetCommand() const
const CommandWheelData * GetWheelData() const
const Point & GetMousePosPixel() const
DataChangedEventType GetType() const
Definition: event.hxx:362
AllSettingsFlags GetFlags() const
Definition: event.hxx:363
void RemoveWindow(const vcl::Window *pWin)
Definition: dockmgr.cxx:394
void AddWindow(const vcl::Window *pWin)
Definition: dockmgr.cxx:386
ImplDockingWindowWrapper * GetDockingWindowWrapper(const vcl::Window *pWin)
Definition: dockmgr.cxx:280
void SetMinOutputSizePixel(const Size &rSize)
Definition: dockwin.cxx:1063
bool mbIsDeferredInit
Definition: dockwin.hxx:144
void SetOutputSizePixel(const Size &rNewSize) override
Definition: dockwin.cxx:883
Point GetPosPixel() const override
Definition: dockwin.cxx:849
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: dockwin.cxx:686
virtual void StateChanged(StateChangedType nType) override
Definition: dockwin.cxx:662
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: dockwin.cxx:313
Size GetSizePixel() const override
Definition: dockwin.cxx:866
virtual void StartDocking()
Definition: dockwin.cxx:583
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: dockwin.cxx:525
Size GetOutputSizePixel() const
Definition: dockwin.cxx:901
virtual void EndDocking(const tools::Rectangle &rRect, bool bFloatMode)
Definition: dockwin.cxx:593
virtual bool Docking(const Point &rPos, tools::Rectangle &rRect)
Definition: dockwin.cxx:588
void SetMaxOutputSizePixel(const Size &rSize)
Definition: dockwin.cxx:960
virtual void Tracking(const TrackingEvent &rTEvt) override
Definition: dockwin.cxx:410
bool IsDockingCanceled() const
Definition: dockwin.hxx:203
VclPtr< vcl::Window > mpDialogParent
Definition: dockwin.hxx:145
virtual void ToggleFloatingMode()
Definition: dockwin.cxx:639
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
Definition: dockwin.cxx:395
void loadUI(vcl::Window *pParent, const OString &rID, const OUString &rUIXMLDescription, const css::uno::Reference< css::frame::XFrame > &rFrame)
Definition: dockwin.cxx:371
SAL_DLLPRIVATE FloatingWindow * ImplFindLastLevelFloat()
Definition: floatwin.cxx:589
void EndPopupMode(FloatWinPopupEndFlags nFlags=FloatWinPopupEndFlags::NONE)
De