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