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