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