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 #ifdef IOS
1370  nDropDownArrowWidth *= 3;
1371 #endif
1372 
1373  // set defaults if image or text is needed but empty
1374  nDefWidth = GetDefaultImageSize().Width();
1375  nDefHeight = GetDefaultImageSize().Height();
1376 
1377  mnWinHeight = 0;
1378  // determine minimum size necessary in NWF
1379  {
1380  tools::Rectangle aRect( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1381  tools::Rectangle aReg( aRect );
1382  ImplControlValue aVal;
1383  tools::Rectangle aNativeBounds, aNativeContent;
1385  {
1387  aReg,
1389  aVal,
1390  aNativeBounds, aNativeContent ) )
1391  {
1392  aRect = aNativeBounds;
1393  if( aRect.GetWidth() > nMinWidth )
1394  nMinWidth = aRect.GetWidth();
1395  if( aRect.GetHeight() > nMinHeight )
1396  nMinHeight = aRect.GetHeight();
1397  if( nDropDownArrowWidth < nMinWidth )
1398  nDropDownArrowWidth = nMinWidth;
1399  if( nMinWidth > mpData->mnMenuButtonWidth )
1400  mpData->mnMenuButtonWidth = nMinWidth;
1401  else if( nMinWidth < TB_MENUBUTTON_SIZE )
1402  mpData->mnMenuButtonWidth = TB_MENUBUTTON_SIZE;
1403  }
1404  }
1405 
1406  // also calculate the area for comboboxes, drop down list boxes and spinfields
1407  // as these are often inserted into toolboxes; set mnWinHeight to the
1408  // greater of those values to prevent toolbar flickering (#i103385#)
1409  aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1410  aReg = aRect;
1412  aReg,
1414  aVal,
1415  aNativeBounds, aNativeContent ) )
1416  {
1417  aRect = aNativeBounds;
1418  if( aRect.GetHeight() > mnWinHeight )
1419  mnWinHeight = aRect.GetHeight();
1420  }
1421  aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1422  aReg = aRect;
1424  aReg,
1426  aVal,
1427  aNativeBounds, aNativeContent ) )
1428  {
1429  aRect = aNativeBounds;
1430  if( aRect.GetHeight() > mnWinHeight )
1431  mnWinHeight = aRect.GetHeight();
1432  }
1433  aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
1434  aReg = aRect;
1436  aReg,
1438  aVal,
1439  aNativeBounds, aNativeContent ) )
1440  {
1441  aRect = aNativeBounds;
1442  if( aRect.GetHeight() > mnWinHeight )
1443  mnWinHeight = aRect.GetHeight();
1444  }
1445  }
1446 
1447  if ( ! mpData->m_aItems.empty() )
1448  {
1449  for (auto & item : mpData->m_aItems)
1450  {
1451  item.mbVisibleText = false; // indicates if text will definitely be drawn, influences dropdown pos
1452 
1453  if ( item.meType == ToolBoxItemType::BUTTON )
1454  {
1455  bool bImage;
1456  bool bText;
1457 
1458  // check if image and/or text exists
1459  bImage = !!item.maImage;
1460  bText = !item.maText.isEmpty();
1461  ButtonType tmpButtonType = determineButtonType( &item, meButtonType ); // default to toolbox setting
1462  if ( bImage || bText )
1463  {
1464 
1465  item.mbEmptyBtn = false;
1466 
1467  if ( tmpButtonType == ButtonType::SYMBOLONLY )
1468  {
1469  // we're drawing images only
1470  if ( bImage || !bText )
1471  {
1472  item.maItemSize = item.maImage.GetSizePixel();
1473  }
1474  else
1475  {
1476  item.maItemSize = Size( GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET,
1477  GetTextHeight() );
1478  item.mbVisibleText = true;
1479  }
1480  }
1481  else if ( tmpButtonType == ButtonType::TEXT )
1482  {
1483  // we're drawing text only
1484  if ( bText || !bImage )
1485  {
1486  item.maItemSize = Size( GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET,
1487  GetTextHeight() );
1488  item.mbVisibleText = true;
1489  }
1490  else
1491  {
1492  item.maItemSize = item.maImage.GetSizePixel();
1493  }
1494  }
1495  else
1496  {
1497  // we're drawing images and text
1498  item.maItemSize.setWidth( bText ? GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET : 0 );
1499  item.maItemSize.setHeight( bText ? GetTextHeight() : 0 );
1500 
1502  {
1503  // leave space between image and text
1504  if( bText )
1505  item.maItemSize.AdjustWidth(TB_IMAGETEXTOFFSET );
1506 
1507  // image and text side by side
1508  item.maItemSize.AdjustWidth(item.maImage.GetSizePixel().Width() );
1509  if ( item.maImage.GetSizePixel().Height() > item.maItemSize.Height() )
1510  item.maItemSize.setHeight( item.maImage.GetSizePixel().Height() );
1511  }
1512  else
1513  {
1514  // leave space between image and text
1515  if( bText )
1516  item.maItemSize.AdjustHeight(TB_IMAGETEXTOFFSET );
1517 
1518  // text below image
1519  item.maItemSize.AdjustHeight(item.maImage.GetSizePixel().Height() );
1520  if ( item.maImage.GetSizePixel().Width() > item.maItemSize.Width() )
1521  item.maItemSize.setWidth( item.maImage.GetSizePixel().Width() );
1522  }
1523 
1524  item.mbVisibleText = bText;
1525  }
1526  }
1527  else
1528  { // no image and no text
1529  item.maItemSize = Size( nDefWidth, nDefHeight );
1530  item.mbEmptyBtn = true;
1531  }
1532 
1533  // save the content size
1534  item.maContentSize = item.maItemSize;
1535 
1536  // if required, take window height into consideration
1537  if ( item.mpWindow )
1538  {
1539  long nHeight = item.mpWindow->GetSizePixel().Height();
1540  if ( nHeight > mnWinHeight )
1541  mnWinHeight = nHeight;
1542  }
1543 
1544  // add in drop down arrow
1545  if( item.mnBits & ToolBoxItemBits::DROPDOWN )
1546  {
1547  item.maItemSize.AdjustWidth(nDropDownArrowWidth );
1548  item.mnDropDownArrowWidth = nDropDownArrowWidth;
1549  }
1550 
1551  // text items will be rotated in vertical mode
1552  // -> swap width and height
1553  if( item.mbVisibleText && !mbHorz )
1554  {
1555  long tmp = item.maItemSize.Width();
1556  item.maItemSize.setWidth( item.maItemSize.Height() );
1557  item.maItemSize.setHeight( tmp );
1558 
1559  tmp = item.maContentSize.Width();
1560  item.maContentSize.setWidth( item.maContentSize.Height() );
1561  item.maContentSize.setHeight( tmp );
1562  }
1563  }
1564  else if ( item.meType == ToolBoxItemType::SPACE )
1565  {
1566  item.maItemSize = Size( nDefWidth, nDefHeight );
1567  item.maContentSize = item.maItemSize;
1568  }
1569 
1570  if ( item.meType == ToolBoxItemType::BUTTON || item.meType == ToolBoxItemType::SPACE )
1571  {
1572  // add borders
1573  long w = item.maItemSize.Width();
1574  long h = item.maItemSize.Height();
1575  ImplAddButtonBorder( w, h, mpData->mbNativeButtons );
1576  item.maItemSize.setWidth(w);
1577  item.maItemSize.setHeight(h);
1578 
1579  if( item.meType == ToolBoxItemType::BUTTON )
1580  {
1581  long nMinW = std::max(nMinWidth, item.maMinimalItemSize.Width());
1582  long nMinH = std::max(nMinHeight, item.maMinimalItemSize.Height());
1583 
1584  long nGrowContentWidth = 0;
1585  long nGrowContentHeight = 0;
1586 
1587  if( item.maItemSize.Width() < nMinW )
1588  {
1589  nGrowContentWidth = nMinW - item.maItemSize.Width();
1590  item.maItemSize.setWidth( nMinW );
1591  }
1592  if( item.maItemSize.Height() < nMinH )
1593  {
1594  nGrowContentHeight = nMinH - item.maItemSize.Height();
1595  item.maItemSize.setHeight( nMinH );
1596  }
1597 
1598  // grow the content size by the additional available space
1599  item.maContentSize.AdjustWidth(nGrowContentWidth );
1600  item.maContentSize.AdjustHeight(nGrowContentHeight );
1601  }
1602 
1603  // keep track of max item size
1604  if ( item.maItemSize.Width() > nMaxWidth )
1605  nMaxWidth = item.maItemSize.Width();
1606  if ( item.maItemSize.Height() > nMaxHeight )
1607  nMaxHeight = item.maItemSize.Height();
1608  }
1609  }
1610  }
1611  else
1612  {
1613  nMaxWidth = nDefWidth;
1614  nMaxHeight = nDefHeight;
1615 
1616  ImplAddButtonBorder( nMaxWidth, nMaxHeight, mpData->mbNativeButtons );
1617  }
1618 
1621  {
1622  // make sure all vertical toolbars have the same width and horizontal have the same height
1623  // this depends on the used button sizes
1624  // as this is used for alignment of multiple toolbars
1625  // it is only required for docked toolbars
1626 
1627  long nFixedWidth = nDefWidth+nDropDownArrowWidth;
1628  long nFixedHeight = nDefHeight;
1629  ImplAddButtonBorder( nFixedWidth, nFixedHeight, mpData->mbNativeButtons );
1630 
1631  if( mbHorz )
1632  nMaxHeight = nFixedHeight;
1633  else
1634  nMaxWidth = nFixedWidth;
1635  }
1636 
1637  mbCalc = false;
1638  mbFormat = true;
1639 
1640  // do we have to recalc the sizes ?
1641  if ( (nMaxWidth != mnMaxItemWidth) || (nMaxHeight != mnMaxItemHeight) )
1642  {
1643  mnMaxItemWidth = nMaxWidth;
1644  mnMaxItemHeight = nMaxHeight;
1645 
1646  return true;
1647  }
1648  else
1649  return false;
1650 }
1651 
1652 ToolBox::ImplToolItems::size_type ToolBox::ImplCalcBreaks( long nWidth, long* pMaxLineWidth, bool bCalcHorz ) const
1653 {
1654  sal_uLong nLineStart = 0;
1655  sal_uLong nGroupStart = 0;
1656  long nLineWidth = 0;
1657  long nCurWidth;
1658  long nLastGroupLineWidth = 0;
1659  long nMaxLineWidth = 0;
1660  ImplToolItems::size_type nLines = 1;
1661  bool bWindow;
1662  bool bBreak = false;
1663  long nWidthTotal = nWidth;
1664  long nMenuWidth = 0;
1665 
1666  // when docked the menubutton will be in the first line
1667  if( IsMenuEnabled() && !ImplIsFloatingMode() )
1668  nMenuWidth = mpData->maMenubuttonItem.maItemSize.Width();
1669 
1670  // we need to know which item is the last visible one to be able to add
1671  // the menu width in case we are unable to show all the items
1672  ImplToolItems::iterator it, lastVisible;
1673  for ( it = mpData->m_aItems.begin(); it != mpData->m_aItems.end(); ++it )
1674  {
1675  if ( it->mbVisible )
1676  lastVisible = it;
1677  }
1678 
1679  it = mpData->m_aItems.begin();
1680  while ( it != mpData->m_aItems.end() )
1681  {
1682  it->mbBreak = bBreak;
1683  bBreak = false;
1684 
1685  if ( it->mbVisible )
1686  {
1687  bWindow = false;
1688  bBreak = false;
1689  nCurWidth = 0;
1690 
1691  if ( it->meType == ToolBoxItemType::BUTTON || it->meType == ToolBoxItemType::SPACE )
1692  {
1693  if ( bCalcHorz )
1694  nCurWidth = it->maItemSize.Width();
1695  else
1696  nCurWidth = it->maItemSize.Height();
1697 
1698  if ( it->mpWindow && bCalcHorz )
1699  {
1700  long nWinItemWidth = it->mpWindow->GetSizePixel().Width();
1701  if ( !mbScroll || (nWinItemWidth <= nWidthTotal) )
1702  {
1703  nCurWidth = nWinItemWidth;
1704  bWindow = true;
1705  }
1706  else
1707  {
1708  if ( it->mbEmptyBtn )
1709  {
1710  nCurWidth = 0;
1711  }
1712  }
1713  }
1714 
1715  // in case we are able to show all the items, we do not want
1716  // to show the toolbar's menu; otherwise yes
1717  if ( ( ( it == lastVisible ) && (nLineWidth+nCurWidth > nWidthTotal) && mbScroll ) ||
1718  ( ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) && mbScroll ) )
1719  bBreak = true;
1720  }
1721  else if ( it->meType == ToolBoxItemType::SEPARATOR )
1722  {
1723  nCurWidth = it->mnSepSize;
1724  if ( !ImplIsFloatingMode() && ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) )
1725  bBreak = true;
1726  }
1727  // treat breaks as separators, except when using old style toolbars (ie. no menu button)
1728  else if ( (it->meType == ToolBoxItemType::BREAK) && !IsMenuEnabled() )
1729  bBreak = true;
1730 
1731  if ( bBreak )
1732  {
1733  nLines++;
1734 
1735  // Add break before the entire group or take group apart?
1736  if ( (it->meType == ToolBoxItemType::BREAK) ||
1737  (nLineStart == nGroupStart) )
1738  {
1739  if ( nLineWidth > nMaxLineWidth )
1740  nMaxLineWidth = nLineWidth;
1741 
1742  nLineWidth = 0;
1743  nLineStart = it - mpData->m_aItems.begin();
1744  nGroupStart = nLineStart;
1745  it->mbBreak = true;
1746  bBreak = false;
1747  }
1748  else
1749  {
1750  if ( nLastGroupLineWidth > nMaxLineWidth )
1751  nMaxLineWidth = nLastGroupLineWidth;
1752 
1753  // if the break is added before the group, set it to
1754  // beginning of line and re-calculate
1755  nLineWidth = 0;
1756  nLineStart = nGroupStart;
1757  it = mpData->m_aItems.begin() + nGroupStart;
1758  continue;
1759  }
1760  }
1761  else
1762  {
1763  if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
1764  {
1765  if ( (it->meType != ToolBoxItemType::BUTTON) || bWindow )
1766  {
1767  // found separator or break
1768  nLastGroupLineWidth = nLineWidth;
1769  nGroupStart = it - mpData->m_aItems.begin();
1770  if ( !bWindow )
1771  nGroupStart++;
1772  }
1773  }
1774  }
1775 
1776  nLineWidth += nCurWidth;
1777  }
1778 
1779  ++it;
1780  }
1781 
1782  if ( pMaxLineWidth )
1783  {
1784  if ( nLineWidth > nMaxLineWidth )
1785  nMaxLineWidth = nLineWidth;
1786 
1788  {
1789  // leave enough space to display buttons in the decoration
1790  long aMinWidth = 2 * GetSettings().GetStyleSettings().GetFloatTitleHeight();
1791  if( nMaxLineWidth < aMinWidth )
1792  nMaxLineWidth = aMinWidth;
1793  }
1794  *pMaxLineWidth = nMaxLineWidth;
1795  }
1796 
1797  return nLines;
1798 }
1799 
1801 {
1802  if( !ImplIsFloatingMode() )
1803  return Size();
1804 
1805  Size aCurrentSize( mnDX, mnDY );
1806  Size aSize1( aCurrentSize );
1807  Size aSize2( aCurrentSize );
1808 
1809  // try to preserve current height
1810 
1811  // calc number of floating lines for current window height
1812  ImplToolItems::size_type nFloatLinesHeight = ImplCalcLines( mnDY );
1813  // calc window size according to this number
1814  aSize1 = ImplCalcFloatSize( nFloatLinesHeight );
1815 
1816  if( aCurrentSize == aSize1 )
1817  return aSize1;
1818 
1819  // try to preserve current width
1820 
1821  long nLineHeight = std::max( mnWinHeight, mnMaxItemHeight );
1822  int nBorderX = 2*TB_BORDER_OFFSET1 + mnLeftBorder + mnRightBorder;
1823  int nBorderY = 2*TB_BORDER_OFFSET2 + mnTopBorder + mnBottomBorder;
1824  Size aSz( aCurrentSize );
1825  long maxX;
1826  ImplToolItems::size_type nLines = ImplCalcBreaks( aSz.Width()-nBorderX, &maxX, mbHorz );
1827 
1828  ImplToolItems::size_type manyLines = 1000;
1829  Size aMinimalFloatSize = ImplCalcFloatSize( manyLines );
1830 
1831  aSz.setHeight( nBorderY + nLineHeight * nLines );
1832  // line space when more than one line
1833  if ( mbLineSpacing )
1834  aSz.AdjustHeight((nLines-1)*TB_LINESPACING );
1835 
1836  aSz.setWidth( nBorderX + maxX );
1837 
1838  // avoid clipping of any items
1839  if( aSz.Width() < aMinimalFloatSize.Width() )
1840  aSize2 = ImplCalcFloatSize( nLines );
1841  else
1842  aSize2 = aSz;
1843 
1844  if( aCurrentSize == aSize2 )
1845  return aSize2;
1846 
1847  // set the size with the smallest delta as the current size
1848  long dx1 = std::abs( mnDX - aSize1.Width() );
1849  long dy1 = std::abs( mnDY - aSize1.Height() );
1850 
1851  long dx2 = std::abs( mnDX - aSize2.Width() );
1852  long dy2 = std::abs( mnDY - aSize2.Height() );
1853 
1854  if( dx1*dy1 < dx2*dy2 )
1855  aCurrentSize = aSize1;
1856  else
1857  aCurrentSize = aSize2;
1858 
1859  return aCurrentSize;
1860 }
1861 
1862 namespace
1863 {
1864 void lcl_hideDoubleSeparators( ToolBox::ImplToolItems& rItems )
1865 {
1866  bool bLastSep( true );
1867  ToolBox::ImplToolItems::iterator it;
1868  for ( it = rItems.begin(); it != rItems.end(); ++it )
1869  {
1870  if ( it->meType == ToolBoxItemType::SEPARATOR )
1871  {
1872  it->mbVisible = false;
1873  if ( !bLastSep )
1874  {
1875  // check if any visible items have to appear behind it
1876  if (std::any_of(it + 1, rItems.end(), [](const ImplToolItem& rItem) {
1877  return (rItem.meType == ToolBoxItemType::BUTTON) && rItem.mbVisible; }))
1878  it->mbVisible = true;
1879  }
1880  bLastSep = true;
1881  }
1882  else if ( it->mbVisible )
1883  bLastSep = false;
1884  }
1885 }
1886 }
1887 
1888 void ToolBox::ImplFormat( bool bResize )
1889 {
1890  // Has to re-formatted
1891  if ( !mbFormat )
1892  return;
1893 
1894  mpData->ImplClearLayoutData();
1895 
1896  // recalculate positions and sizes
1897  tools::Rectangle aEmptyRect;
1898  long nLineSize;
1899  long nLeft;
1900  long nTop;
1901  long nMax; // width of layoutarea in pixels
1902  ImplToolItems::size_type nFormatLine;
1903  bool bMustFullPaint;
1904 
1906  bool bIsInPopupMode = ImplIsInPopupMode();
1907 
1908  maFloatSizes.clear();
1909 
1910  // compute border sizes
1912 
1913  // update drag area (where the 'grip' will be placed)
1914  tools::Rectangle aOldDragRect;
1915  if( pWrapper )
1916  aOldDragRect = pWrapper->GetDragArea();
1918 
1919  bMustFullPaint = ImplCalcItem();
1920 
1921  // calculate new size during interactive resize or
1922  // set computed size when formatting only
1923  if ( ImplIsFloatingMode() )
1924  {
1925  if ( bResize )
1927  else
1929  }
1930 
1931  // Horizontal
1932  if ( mbHorz )
1933  {
1934  long nBottom;
1935  // nLineSize: height of a single line, will fit highest item
1936  nLineSize = mnMaxItemHeight;
1937 
1938  if ( mnWinHeight > mnMaxItemHeight )
1939  nLineSize = mnWinHeight;
1940 
1941  if ( mbScroll )
1942  {
1943  nMax = mnDX;
1945  }
1946  else
1947  {
1948  // layout over all lines
1949  mnVisLines = mnLines;
1950  nMax = TB_MAXNOSCROLL;
1951  }
1952 
1953  // add in all border offsets
1954  if ( mnWinStyle & WB_BORDER )
1955  {
1956  nLeft = TB_BORDER_OFFSET1 + mnLeftBorder;
1957  nTop = TB_BORDER_OFFSET2 + mnTopBorder;
1958  nBottom = TB_BORDER_OFFSET1 + mnBottomBorder;
1959  nMax -= nLeft + TB_BORDER_OFFSET1 + mnRightBorder;
1960  }
1961  else
1962  {
1963  nLeft = 0;
1964  nTop = 0;
1965  nBottom = 0;
1966  }
1967 
1968  // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
1969  // we have to center all items in the window height
1970  if( IsMenuEnabled() && !ImplIsFloatingMode() )
1971  {
1972  long nWinHeight = mnDY - nTop - nBottom;
1973  if( nWinHeight > nLineSize )
1974  nLineSize = nWinHeight;
1975  }
1976  }
1977  else
1978  {
1979  long nRight;
1980  nLineSize = mnMaxItemWidth;
1981 
1982  if ( mbScroll )
1983  {
1985  nMax = mnDY;
1986  }
1987  else
1988  {
1989  mnVisLines = mnLines;
1990  nMax = TB_MAXNOSCROLL;
1991  }
1992 
1993  if ( mnWinStyle & WB_BORDER )
1994  {
1995  nTop = TB_BORDER_OFFSET1 + mnTopBorder;
1996  nLeft = TB_BORDER_OFFSET2 + mnLeftBorder;
1997  nRight = TB_BORDER_OFFSET2 + mnRightBorder;
1998  nMax -= nTop + TB_BORDER_OFFSET1 + mnBottomBorder;
1999  }
2000  else
2001  {
2002  nLeft = 0;
2003  nTop = 0;
2004  nRight = 0;
2005  }
2006 
2007  // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
2008  // we have to center all items in the window height
2009  if( !ImplIsFloatingMode() && IsMenuEnabled() )
2010  {
2011  long nWinWidth = mnDX - nLeft - nRight;
2012  if( nWinWidth > nLineSize )
2013  nLineSize = nWinWidth;
2014  }
2015  }
2016 
2017  // no calculation if the window has no size (nMax=0)
2018  // non scrolling toolboxes must be computed though
2019  if ( (nMax <= 0) && mbScroll )
2020  {
2021  mnVisLines = 1;
2022  mnCurLine = 1;
2023  mnCurLines = 1;
2024 
2025  for (auto & item : mpData->m_aItems)
2026  {
2027  item.maRect = aEmptyRect;
2028  }
2029 
2030  maLowerRect = aEmptyRect;
2031  maUpperRect = aEmptyRect;
2032  }
2033  else
2034  {
2035  // init start values
2036  long nX = nLeft; // top-left offset
2037  long nY = nTop;
2038  nFormatLine = 1;
2039 
2040  // save old scroll rectangles and reset them
2041  tools::Rectangle aOldLowerRect = maLowerRect;
2042  tools::Rectangle aOldUpperRect = maUpperRect;
2043  tools::Rectangle aOldMenubuttonRect = mpData->maMenubuttonItem.maRect;
2044  maUpperRect = aEmptyRect;
2045  maLowerRect = aEmptyRect;
2046  mpData->maMenubuttonItem.maRect = aEmptyRect;
2047 
2048  // do we have any toolbox items at all ?
2049  if ( !mpData->m_aItems.empty() || IsMenuEnabled() )
2050  {
2051  lcl_hideDoubleSeparators( mpData->m_aItems );
2052 
2053  // compute line breaks and visible lines give the current window width (nMax)
2054  // the break indicators will be stored within each item (it->mbBreak)
2055  mnCurLines = ImplCalcBreaks( nMax, nullptr, mbHorz );
2056 
2057  // check for scrollbar buttons or dropdown menu
2058  // (if a menu is enabled, this will be used to store clipped
2059  // items and no scroll buttons will appear)
2060  if ( (!ImplIsFloatingMode() && (mnCurLines > mnVisLines) && mbScroll ) ||
2061  IsMenuEnabled() )
2062  {
2063  // compute linebreaks again, incorporating scrollbar buttons
2064  if( !IsMenuEnabled() )
2065  {
2066  nMax -= TB_SPIN_SIZE+TB_SPIN_OFFSET;
2067  mnCurLines = ImplCalcBreaks( nMax, nullptr, mbHorz );
2068  }
2069 
2070  // compute scroll rectangles or menu button
2071  if ( mbHorz )
2072  {
2073  if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
2074  {
2075  if( !ImplIsFloatingMode() )
2076  {
2077  mpData->maMenubuttonItem.maRect.SetRight( mnDX - 2 );
2078  mpData->maMenubuttonItem.maRect.SetTop( nTop );
2079  mpData->maMenubuttonItem.maRect.SetBottom( mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1 );
2080  }
2081  else
2082  {
2083  mpData->maMenubuttonItem.maRect.SetRight( mnDX - mnRightBorder-TB_BORDER_OFFSET1-1 );
2084  mpData->maMenubuttonItem.maRect.SetTop( nTop );
2085  mpData->maMenubuttonItem.maRect.SetBottom( mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1 );
2086  }
2087  mpData->maMenubuttonItem.maRect.SetLeft( mpData->maMenubuttonItem.maRect.Right() - mpData->mnMenuButtonWidth );
2088  }
2089  else
2090  {
2091  maUpperRect.SetLeft( nLeft+nMax+TB_SPIN_OFFSET );
2093  maUpperRect.SetTop( nTop );
2098  (maLowerRect.Bottom()-maUpperRect.Top())/2 );
2100  }
2101  }
2102  else
2103  {
2104  if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
2105  {
2106  if( !ImplIsFloatingMode() )
2107  {
2108  mpData->maMenubuttonItem.maRect.SetBottom( mnDY - 2 );
2109  mpData->maMenubuttonItem.maRect.SetLeft( nLeft );
2110  mpData->maMenubuttonItem.maRect.SetRight( mnDX-mnRightBorder-TB_BORDER_OFFSET2-1 );
2111  }
2112  else
2113  {
2114  mpData->maMenubuttonItem.maRect.SetBottom( mnDY - mnBottomBorder-TB_BORDER_OFFSET1-1 );
2115  mpData->maMenubuttonItem.maRect.SetLeft( nLeft );
2116  mpData->maMenubuttonItem.maRect.SetRight( mnDX-mnRightBorder-TB_BORDER_OFFSET2-1 );
2117  }
2118  mpData->maMenubuttonItem.maRect.SetTop( mpData->maMenubuttonItem.maRect.Bottom() - mpData->mnMenuButtonWidth );
2119  }
2120  else
2121  {
2122  maUpperRect.SetTop( nTop+nMax+TB_SPIN_OFFSET );
2124  maUpperRect.SetLeft( nLeft );
2129  (maLowerRect.Right()-maUpperRect.Left())/2 );
2131  }
2132  }
2133  }
2134 
2135  // no scrolling when there is a "more"-menu
2136  // anything will "fit" in a single line then
2137  if( IsMenuEnabled() )
2138  mnCurLines = 1;
2139 
2140  // determine the currently visible line
2141  if ( mnVisLines >= mnCurLines )
2142  mnCurLine = 1;
2143  else if ( mnCurLine+mnVisLines-1 > mnCurLines )
2145 
2146  long firstItemCenter = 0;
2147  for (auto & item : mpData->m_aItems)
2148  {
2149  item.mbShowWindow = false;
2150 
2151  // check for line break and advance nX/nY accordingly
2152  if ( item.mbBreak )
2153  {
2154  nFormatLine++;
2155 
2156  // increment starting with the second line
2157  if ( nFormatLine > mnCurLine )
2158  {
2159  if ( mbHorz )
2160  {
2161  nX = nLeft;
2162  if ( mbLineSpacing )
2163  nY += nLineSize+TB_LINESPACING;
2164  else
2165  nY += nLineSize;
2166  }
2167  else
2168  {
2169  nY = nTop;
2170  if ( mbLineSpacing )
2171  nX += nLineSize+TB_LINESPACING;
2172  else
2173  nX += nLineSize;
2174  }
2175  }
2176  }
2177 
2178  if ( !item.mbVisible || (nFormatLine < mnCurLine) ||
2179  (nFormatLine > mnCurLine+mnVisLines-1) )
2180  // item is not visible
2181  item.maCalcRect = aEmptyRect;
2182  else
2183  {
2184  // 1. determine current item width/height
2185  // take window size and orientation into account, because this affects the size of item windows
2186 
2187  Size aCurrentItemSize( item.GetSize( mbHorz, mbScroll, nMax, Size(mnMaxItemWidth, mnMaxItemHeight) ) );
2188 
2189  // 2. position item rect and use size from step 1
2190  // items will be centered horizontally (if mbHorz) or vertically
2191  // advance nX and nY accordingly
2192 
2193  if ( mbHorz )
2194  {
2195  // In special mode Locked horizontal positions of all items remain unchanged.
2196 
2197  if ( mbIsArranged && meLayoutMode == ToolBoxLayoutMode::Locked && mnLines == 1 && item.maRect.Left() > 0 )
2198  nX = item.maRect.Left();
2199  item.maCalcRect.SetLeft( nX );
2200 
2201  // In special mode Locked first item's vertical position remains unchanged. Consecutive items vertical
2202  // positions are centered around first item's vertical position. If an item's height exceeds available
2203  // space, item's vertical position remains unchanged too.
2204 
2206  if ( firstItemCenter > 0 )
2207  if ( firstItemCenter-aCurrentItemSize.Height()/2 > nY )
2208  item.maCalcRect.SetTop( firstItemCenter-aCurrentItemSize.Height()/2 );
2209  else
2210  item.maCalcRect.SetTop( item.maRect.Top() );
2211  else
2212  {
2213  item.maCalcRect.SetTop( item.maRect.Top() );
2214  firstItemCenter = item.maRect.Top()+aCurrentItemSize.Height()/2;
2215  }
2216  else
2217  item.maCalcRect.SetTop( nY+(nLineSize-aCurrentItemSize.Height())/2 );
2218  item.maCalcRect.SetRight( nX+aCurrentItemSize.Width()-1 );
2219  item.maCalcRect.SetBottom( item.maCalcRect.Top()+aCurrentItemSize.Height()-1 );
2220  nX += aCurrentItemSize.Width();
2221  }
2222  else
2223  {
2224  item.maCalcRect.SetLeft( nX+(nLineSize-aCurrentItemSize.Width())/2 );
2225  item.maCalcRect.SetTop( nY );
2226  item.maCalcRect.SetRight( item.maCalcRect.Left()+aCurrentItemSize.Width()-1 );
2227  item.maCalcRect.SetBottom( nY+aCurrentItemSize.Height()-1 );
2228  nY += aCurrentItemSize.Height();
2229  }
2230  }
2231 
2232  // position window items into calculated item rect
2233  if ( item.mpWindow )
2234  {
2235  if ( item.mbShowWindow )
2236  {
2237  Point aPos( item.maCalcRect.Left(), item.maCalcRect.Top() );
2238 
2239  assert( item.maCalcRect.Top() >= 0 );
2240 
2241  item.mpWindow->SetPosPixel( aPos );
2242  item.mpWindow->Show();
2243  }
2244  else
2245  item.mpWindow->Hide();
2246  }
2247  } // end of loop over all items
2248  mbIsArranged = true;
2249  }
2250  else
2251  // we have no toolbox items
2252  mnCurLines = 1;
2253 
2254  if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
2255  {
2256  // custom menu will be the last button in floating mode
2257  ImplToolItem &rIt = mpData->maMenubuttonItem;
2258 
2259  if ( mbHorz )
2260  {
2262  rIt.maRect.SetTop( nY );
2263  rIt.maRect.SetRight( rIt.maRect.Left() + mpData->mnMenuButtonWidth );
2264  rIt.maRect.SetBottom( nY+nLineSize-1 );
2265  nX += rIt.maItemSize.Width();
2266  }
2267  else
2268  {
2269  rIt.maRect.SetLeft( nX );
2271  rIt.maRect.SetRight( nX+nLineSize-1 );
2272  rIt.maRect.SetBottom( rIt.maRect.Top() + mpData->mnMenuButtonWidth );
2273  nY += rIt.maItemSize.Height();
2274  }
2275  }
2276 
2277  // if toolbox visible trigger paint for changed regions
2278  if ( IsVisible() && !mbFullPaint )
2279  {
2280  if ( bMustFullPaint )
2281  {
2284  }
2285  else
2286  {
2287  if ( aOldLowerRect != maLowerRect )
2288  {
2290  maPaintRect.Union( aOldLowerRect );
2291  }
2292  if ( aOldUpperRect != maUpperRect )
2293  {
2295  maPaintRect.Union( aOldUpperRect );
2296  }
2297  if ( aOldMenubuttonRect != mpData->maMenubuttonItem.maRect )
2298  {
2299  maPaintRect.Union( mpData->maMenubuttonItem.maRect );
2300  maPaintRect.Union( aOldMenubuttonRect );
2301  }
2302  if ( pWrapper && aOldDragRect != pWrapper->GetDragArea() )
2303  {
2304  maPaintRect.Union( pWrapper->GetDragArea() );
2305  maPaintRect.Union( aOldDragRect );
2306  }
2307 
2308  for (auto const& item : mpData->m_aItems)
2309  {
2310  if ( item.maRect != item.maCalcRect )
2311  {
2312  maPaintRect.Union( item.maRect );
2313  maPaintRect.Union( item.maCalcRect );
2314  }
2315  }
2316  }
2317 
2319  }
2320 
2321  // store the new calculated item rects
2322  maPaintRect = aEmptyRect;
2323  for (auto & item : mpData->m_aItems)
2324  item.maRect = item.maCalcRect;
2325  }
2326 
2327  // indicate formatting is done
2328  mbFormat = false;
2329 }
2330 
2331 IMPL_LINK_NOARG(ToolBox, ImplDropdownLongClickHdl, Timer *, void)
2332 {
2333  if (mnCurPos != ITEM_NOTFOUND &&
2334  (mpData->m_aItems[ mnCurPos ].mnBits & ToolBoxItemBits::DROPDOWN))
2335  {
2336  mpData->mbDropDownByKeyboard = false;
2337  mpData->maDropdownClickHdl.Call( this );
2338 
2339  // do not reset data if the dropdown handler opened a floating window
2340  // see ImplFloatControl()
2341  if( !mpFloatWin )
2342  {
2343  // no floater was opened
2344  Deactivate();
2345  InvalidateItem(mnCurPos);
2346 
2347  mnCurPos = ITEM_NOTFOUND;
2348  mnCurItemId = 0;
2349  mnDownItemId = 0;
2350  mnMouseModifier = 0;
2351  mnHighItemId = 0;
2352  }
2353  }
2354 }
2355 
2356 IMPL_LINK_NOARG(ToolBox, ImplUpdateHdl, Timer *, void)
2357 {
2358 
2359  if( mbFormat && mpData )
2360  ImplFormat();
2361 }
2362 
2363 static void ImplDrawMoreIndicator(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
2364 {
2365  const Image pImage(StockImage::Yes, CHEVRON);
2366  Size aImageSize = pImage.GetSizePixel();
2367  long x = rRect.Left() + (rRect.getWidth() - aImageSize.Width())/2;
2368  long y = rRect.Top() + (rRect.getHeight() - aImageSize.Height())/2;
2369  DrawImageFlags nImageStyle = DrawImageFlags::NONE;
2370 
2371  rRenderContext.DrawImage(Point(x,y), pImage, nImageStyle);
2372 }
2373 
2374 static void ImplDrawDropdownArrow(vcl::RenderContext& rRenderContext, const tools::Rectangle& rDropDownRect, bool bSetColor, bool bRotate )
2375 {
2376  bool bLineColor = rRenderContext.IsLineColor();
2377  bool bFillColor = rRenderContext.IsFillColor();
2378  Color aOldFillColor = rRenderContext.GetFillColor();
2379  Color aOldLineColor = rRenderContext.GetLineColor();
2380  rRenderContext.SetLineColor();
2381 
2382  if ( bSetColor )
2383  {
2384  if (rRenderContext.GetSettings().GetStyleSettings().GetFaceColor().IsDark())
2385  rRenderContext.SetFillColor(COL_WHITE);
2386  else
2387  rRenderContext.SetFillColor(COL_BLACK);
2388  }
2389 
2390  float fScaleFactor = rRenderContext.GetDPIScaleFactor();
2391 
2392  tools::Polygon aPoly(4);
2393 
2394  long width = round(rDropDownRect.getHeight()/5.5) * fScaleFactor; // scale triangle depending on theme/toolbar height with 7 for gtk, 5 for gen
2395  long height = round(rDropDownRect.getHeight()/9.5) * fScaleFactor; // 4 for gtk, 3 for gen
2396  if (width < 4) width = 4;
2397  if (height < 3) height = 3;
2398 
2399  long x = rDropDownRect.Left() + (rDropDownRect.getWidth() - width)/2;
2400  long y = rDropDownRect.Top() + (rDropDownRect.getHeight() - height)/2;
2401 
2402  long halfwidth = (width+1)>>1;
2403  aPoly.SetPoint(Point(x, y), 0);
2404  aPoly.SetPoint(Point(x + halfwidth, y + height), 1);
2405  aPoly.SetPoint(Point(x + halfwidth*2, y), 2);
2406  aPoly.SetPoint(Point(x, y), 3);
2407 
2408  if (bRotate) // TESTME: harder ...
2409  aPoly.Rotate(Point(x,y+height/2),2700);
2410 
2411  auto aaflags = rRenderContext.GetAntialiasing();
2413  rRenderContext.DrawPolygon( aPoly );
2414  rRenderContext.SetAntialiasing(aaflags);
2415 
2416  if( bFillColor )
2417  rRenderContext.SetFillColor(aOldFillColor);
2418  else
2419  rRenderContext.SetFillColor();
2420  if( bLineColor )
2421  rRenderContext.SetLineColor(aOldLineColor);
2422  else
2423  rRenderContext.SetLineColor();
2424 }
2425 
2426 void ToolBox::ImplDrawMenuButton(vcl::RenderContext& rRenderContext, bool bHighlight)
2427 {
2428  if (!mpData->maMenubuttonItem.maRect.IsEmpty())
2429  {
2430  // #i53937# paint menu button only if necessary
2431  if (!ImplHasClippedItems())
2432  return;
2433 
2434  // execute pending paint requests
2435  ImplCheckUpdate();
2436 
2438 
2439  // draw the 'more' indicator / button (>>)
2440  ImplErase(rRenderContext, mpData->maMenubuttonItem.maRect, bHighlight);
2441 
2442  if (bHighlight)
2443  ImplDrawButton(rRenderContext, mpData->maMenubuttonItem.maRect, 2, false, true, false );
2444 
2445  if (ImplHasClippedItems())
2446  ImplDrawMoreIndicator(rRenderContext, mpData->maMenubuttonItem.maRect);
2447 
2448  // store highlight state
2449  mpData->mbMenubuttonSelected = bHighlight;
2450 
2451  // restore colors
2452  rRenderContext.Pop();
2453  }
2454 }
2455 
2457 {
2458  bool bTmpUpper;
2459  bool bTmpLower;
2460 
2461  if ( maUpperRect.IsEmpty() || maLowerRect.IsEmpty() )
2462  return;
2463 
2464  bTmpUpper = mnCurLine > 1;
2465 
2466  bTmpLower = mnCurLine+mnVisLines-1 < mnCurLines;
2467 
2468  if ( !IsEnabled() )
2469  {
2470  bTmpUpper = false;
2471  bTmpLower = false;
2472  }
2473 
2475  false/*bUpperIn*/, false/*bLowerIn*/, bTmpUpper, bTmpLower, !mbHorz);
2476 }
2477 
2478 void ToolBox::ImplDrawSeparator(vcl::RenderContext& rRenderContext, ImplToolItems::size_type nPos, const tools::Rectangle& rRect)
2479 {
2480  if ( nPos >= mpData->m_aItems.size() - 1 )
2481  // no separator if it's the last item
2482  return;
2483 
2484  ImplToolItem* pItem = &mpData->m_aItems[nPos];
2485  ImplToolItem* pPreviousItem = &mpData->m_aItems[nPos-1];
2486  ImplToolItem* pNextItem = &mpData->m_aItems[nPos+1];
2487 
2488  if ( ( pPreviousItem->mbShowWindow && pNextItem->mbShowWindow ) || pNextItem->mbBreak )
2489  // no separator between two windows or before a break
2490  return;
2491 
2492  bool bNativeOk = false;
2494  if (rRenderContext.IsNativeControlSupported(ControlType::Toolbar, nPart))
2495  {
2496  ImplControlValue aControlValue;
2497  bNativeOk = rRenderContext.DrawNativeControl(ControlType::Toolbar, nPart, rRect, ControlState::NONE, aControlValue, OUString());
2498  }
2499 
2500  /* Draw the widget only if it can't be drawn natively. */
2501  if (!bNativeOk)
2502  {
2503  long nCenterPos, nSlim;
2504  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
2505  rRenderContext.SetLineColor(rStyleSettings.GetSeparatorColor());
2506  if (IsHorizontal())
2507  {
2508  nSlim = (pItem->maRect.Bottom() - pItem->maRect.Top ()) / 4;
2509  nCenterPos = pItem->maRect.Center().X();
2510  rRenderContext.DrawLine(Point(nCenterPos, pItem->maRect.Top() + nSlim),
2511  Point(nCenterPos, pItem->maRect.Bottom() - nSlim));
2512  }
2513  else
2514  {
2515  nSlim = (pItem->maRect.Right() - pItem->maRect.Left ()) / 4;
2516  nCenterPos = pItem->maRect.Center().Y();
2517  rRenderContext.DrawLine(Point(pItem->maRect.Left() + nSlim, nCenterPos),
2518  Point(pItem->maRect.Right() - nSlim, nCenterPos));
2519  }
2520  }
2521 }
2522 
2523 void ToolBox::ImplDrawButton(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect, sal_uInt16 highlight,
2524  bool bChecked, bool bEnabled, bool bIsWindow )
2525 {
2526  // draws toolbar button background either native or using a coloured selection
2527  // if bIsWindow is true, the corresponding item is a control and only a selection border will be drawn
2528 
2529  bool bNativeOk = false;
2530  if( !bIsWindow && rRenderContext.IsNativeControlSupported( ControlType::Toolbar, ControlPart::Button ) )
2531  {
2532  ImplControlValue aControlValue;
2534 
2535  if ( highlight == 1 ) nState |= ControlState::PRESSED;
2536  if ( highlight == 2 ) nState |= ControlState::ROLLOVER;
2537  if ( bEnabled ) nState |= ControlState::ENABLED;
2538 
2539  aControlValue.setTristateVal( bChecked ? ButtonValue::On : ButtonValue::Off );
2540 
2541  bNativeOk = rRenderContext.DrawNativeControl( ControlType::Toolbar, ControlPart::Button,
2542  rRect, nState, aControlValue, OUString() );
2543  }
2544 
2545  if (!bNativeOk)
2546  vcl::RenderTools::DrawSelectionBackground(rRenderContext, *this, rRect, bIsWindow ? 3 : highlight,
2547  bChecked, true, bIsWindow, nullptr, 2);
2548 }
2549 
2550 void ToolBox::ImplDrawItem(vcl::RenderContext& rRenderContext, ImplToolItems::size_type nPos, sal_uInt16 nHighlight)
2551 {
2552  if (nPos >= mpData->m_aItems.size())
2553  return;
2554 
2555  // execute pending paint requests
2556  ImplCheckUpdate();
2557 
2559 
2560  rRenderContext.SetFillColor();
2561 
2562  ImplToolItem* pItem = &mpData->m_aItems[nPos];
2563 
2564  if (!pItem->mbEnabled)
2565  nHighlight = 0;
2566 
2567  // if the rectangle is outside visible area
2568  if (pItem->maRect.IsEmpty())
2569  return;
2570 
2571  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
2572 
2573  // no gradient background for items that have a popup open
2574  bool bHasOpenPopup = mpFloatWin && (mnDownItemId==pItem->mnId);
2575 
2576  bool bHighContrastWhite = false;
2577  // check the face color as highcontrast indicator
2578  // because the toolbox itself might have a gradient
2579  if (rStyleSettings.GetFaceColor() == COL_WHITE)
2580  bHighContrastWhite = true;
2581 
2582  // Compute buttons area.
2583  Size aBtnSize = pItem->maRect.GetSize();
2584 
2585  /* Compute the button/separator rectangle here, we'll need it for
2586  * both the buttons and the separators. */
2587  tools::Rectangle aButtonRect( pItem->maRect.TopLeft(), aBtnSize );
2588  long nOffX = SMALLBUTTON_OFF_NORMAL_X;
2589  long nOffY = SMALLBUTTON_OFF_NORMAL_Y;
2590  long nImageOffX = 0;
2591  long nImageOffY = 0;
2593 
2594  // draw separators in flat style only
2595  if ( (mnOutStyle & TOOLBOX_STYLE_FLAT) &&
2596  (pItem->meType == ToolBoxItemType::SEPARATOR) &&
2597  nPos > 0
2598  )
2599  {
2600  ImplDrawSeparator(rRenderContext, nPos, aButtonRect);
2601  }
2602 
2603  // do nothing if item is no button or will be displayed as window
2604  if ( (pItem->meType != ToolBoxItemType::BUTTON) || pItem->mbShowWindow )
2605  return;
2606 
2607  if ( pItem->meState == TRISTATE_TRUE )
2608  {
2609  nStyle |= DrawButtonFlags::Checked;
2610  }
2611  else if ( pItem->meState == TRISTATE_INDET )
2612  {
2613  nStyle |= DrawButtonFlags::DontKnow;
2614  }
2615  if ( nHighlight == 1 )
2616  {
2617  nStyle |= DrawButtonFlags::Pressed;
2618  }
2619 
2620  if ( mnOutStyle & TOOLBOX_STYLE_FLAT )
2621  {
2622  ImplErase(rRenderContext, pItem->maRect, nHighlight != 0, bHasOpenPopup );
2623  }
2624  else
2625  {
2626  DecorationView aDecoView(&rRenderContext);
2627  aDecoView.DrawButton(aButtonRect, nStyle);
2628  }
2629 
2630  nOffX += pItem->maRect.Left();
2631  nOffY += pItem->maRect.Top();
2632 
2633  // determine what has to be drawn on the button: image, text or both
2634  bool bImage;
2635  bool bText;
2636  ButtonType tmpButtonType = determineButtonType( pItem, meButtonType ); // default to toolbox setting
2637  pItem->DetermineButtonDrawStyle( tmpButtonType, bImage, bText );
2638 
2639  // compute output values
2640  long nBtnWidth = aBtnSize.Width()-SMALLBUTTON_HSIZE;
2641  long nBtnHeight = aBtnSize.Height()-SMALLBUTTON_VSIZE;
2642  Size aImageSize;
2643  Size aTxtSize;
2644 
2645  if ( bText )
2646  {
2647  aTxtSize.setWidth( GetCtrlTextWidth( pItem->maText ) );
2648  aTxtSize.setHeight( GetTextHeight() );
2649  }
2650 
2651  if ( bImage )
2652  {
2653  const Image* pImage = &(pItem->maImage);
2654  const Image& rOverlayImage = pItem->maOverlayImage;
2655  aImageSize = pImage->GetSizePixel();
2656 
2657  // determine drawing flags
2658  DrawImageFlags nImageStyle = DrawImageFlags::NONE;
2659 
2660  if ( !pItem->mbEnabled || !IsEnabled() )
2661  nImageStyle |= DrawImageFlags::Disable;
2662 
2663  // #i35563# the dontknow state indicates different states at the same time
2664  // which should not be rendered disabled but normal
2665 
2666  // draw the image
2667  nImageOffX = nOffX;
2668  nImageOffY = nOffY;
2669  if ( ( (pItem->mnBits & (ToolBoxItemBits::LEFT|ToolBoxItemBits::DROPDOWN)) || bText )
2671  {
2672  // left align also to leave space for drop down arrow
2673  // and when drawing text+image
2674  // just center in y, except for vertical (ie rotated text)
2675  if( mbHorz || !bText )
2676  nImageOffY += (nBtnHeight-aImageSize.Height())/2;
2677  }
2678  else
2679  {
2680  nImageOffX += (nBtnWidth-aImageSize.Width())/2;
2682  nImageOffY += (nBtnHeight-aImageSize.Height())/2;
2683  }
2684  if ( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
2685  {
2686  if( bHasOpenPopup )
2687  ImplDrawFloatwinBorder(rRenderContext, pItem);
2688  else
2689  ImplDrawButton(rRenderContext, aButtonRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2690  pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow);
2691 
2692  if( nHighlight != 0 )
2693  {
2694  if( bHighContrastWhite )
2695  nImageStyle |= DrawImageFlags::ColorTransform;
2696  }
2697  }
2698  rRenderContext.DrawImage(Point( nImageOffX, nImageOffY ), *pImage, nImageStyle);
2699  if (!!rOverlayImage)
2700  rRenderContext.DrawImage(Point( nImageOffX, nImageOffY ), rOverlayImage, nImageStyle);
2701  }
2702 
2703  // draw the text
2704  bool bRotate = false;
2705  if ( bText )
2706  {
2707  long nTextOffX = nOffX;
2708  long nTextOffY = nOffY;
2709 
2710  // rotate text when vertically docked
2711  vcl::Font aOldFont = rRenderContext.GetFont();
2712  if( pItem->mbVisibleText && !ImplIsFloatingMode() &&
2713  ((meAlign == WindowAlign::Left) || (meAlign == WindowAlign::Right)) )
2714  {
2715  bRotate = true;
2716 
2717  vcl::Font aRotateFont = aOldFont;
2718  aRotateFont.SetOrientation( 2700 );
2719 
2720  // center horizontally
2721  nTextOffX += aTxtSize.Height();
2722  nTextOffX += (nBtnWidth-aTxtSize.Height())/2;
2723 
2724  // add in image offset
2725  if( bImage )
2726  nTextOffY = nImageOffY + aImageSize.Height() + TB_IMAGETEXTOFFSET;
2727 
2728  rRenderContext.SetFont(aRotateFont);
2729  }
2730  else
2731  {
2733  {
2734  // center vertically
2735  nTextOffY += (nBtnHeight-aTxtSize.Height())/2;
2736 
2737  // add in image offset
2738  if( bImage )
2739  nTextOffX = nImageOffX + aImageSize.Width() + TB_IMAGETEXTOFFSET;
2740  }
2741  else
2742  {
2743  // center horizontally
2744  nTextOffX += (nBtnWidth-aTxtSize.Width() - TB_IMAGETEXTOFFSET)/2;
2745  // set vertical position
2746  nTextOffY += nBtnHeight - aTxtSize.Height();
2747  }
2748  }
2749 
2750  // draw selection only if not already drawn during image output (see above)
2751  if ( !bImage && (nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) ) )
2752  {
2753  if( bHasOpenPopup )
2754  ImplDrawFloatwinBorder(rRenderContext, pItem);
2755  else
2756  ImplDrawButton(rRenderContext, pItem->maRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2757  pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow );
2758  }
2759 
2760  DrawTextFlags nTextStyle = DrawTextFlags::NONE;
2761  if ( !pItem->mbEnabled )
2762  nTextStyle |= DrawTextFlags::Disable;
2763  rRenderContext.DrawCtrlText( Point( nTextOffX, nTextOffY ), pItem->maText,
2764  0, pItem->maText.getLength(), nTextStyle );
2765  if ( bRotate )
2766  SetFont( aOldFont );
2767  }
2768 
2769  // paint optional drop down arrow
2770  if ( pItem->mnBits & ToolBoxItemBits::DROPDOWN )
2771  {
2772  tools::Rectangle aDropDownRect( pItem->GetDropDownRect( mbHorz ) );
2773  bool bSetColor = true;
2774  if ( !pItem->mbEnabled || !IsEnabled() )
2775  {
2776  bSetColor = false;
2777  rRenderContext.SetFillColor(rStyleSettings.GetShadowColor());
2778  }
2779 
2780  // dropdown only will be painted without inner border
2782  {
2783  ImplErase(rRenderContext, aDropDownRect, nHighlight != 0, bHasOpenPopup);
2784 
2785  if( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
2786  {
2787  if( bHasOpenPopup )
2788  ImplDrawFloatwinBorder(rRenderContext, pItem);
2789  else
2790  ImplDrawButton(rRenderContext, aDropDownRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2791  pItem->mbEnabled && IsEnabled(), false);
2792  }
2793  }
2794  ImplDrawDropdownArrow(rRenderContext, aDropDownRect, bSetColor, bRotate);
2795  }
2796 }
2797 
2799 {
2800  if ( pItem->maRect.IsEmpty() )
2801  return;
2802 
2804  aRect.SetPos( AbsoluteScreenToOutputPixel( aRect.TopLeft() ) );
2805  rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetShadowColor());
2806  Point p1, p2;
2807 
2808  p1 = pItem->maRect.TopLeft();
2809  p1.AdjustX( 1 );
2810  p2 = pItem->maRect.TopRight();
2811  p2.AdjustX( -1 );
2812  rRenderContext.DrawLine( p1, p2);
2813  p1 = pItem->maRect.BottomLeft();
2814  p1.AdjustX( 1 );
2815  p2 = pItem->maRect.BottomRight();
2816  p2.AdjustX( -1 );
2817  rRenderContext.DrawLine( p1, p2);
2818 
2819  p1 = pItem->maRect.TopLeft();
2820  p1.AdjustY( 1 );
2821  p2 = pItem->maRect.BottomLeft();
2822  p2.AdjustY( -1 );
2823  rRenderContext.DrawLine( p1, p2);
2824  p1 = pItem->maRect.TopRight();
2825  p1.AdjustY( 1 );
2826  p2 = pItem->maRect.BottomRight();
2827  p2.AdjustY( -1 );
2828  rRenderContext.DrawLine( p1, p2);
2829 
2830 }
2831 
2832 void ToolBox::ImplFloatControl( bool bStart, FloatingWindow* pFloatWindow )
2833 {
2834 
2835  if ( bStart )
2836  {
2837  mpFloatWin = pFloatWindow;
2838 
2839  // redraw item, to trigger drawing of a special border
2841 
2842  mbDrag = false;
2843  EndTracking();
2844  if (IsMouseCaptured())
2845  ReleaseMouse();
2846  }
2847  else
2848  {
2849  mpFloatWin = nullptr;
2850 
2851  // if focus is still in this toolbox, then the floater was opened by keyboard
2852  // draw current item with highlight and keep old state
2853  bool bWasKeyboardActivate = mpData->mbDropDownByKeyboard;
2854 
2855  if ( mnCurPos != ITEM_NOTFOUND )
2857  Deactivate();
2858 
2859  if( !bWasKeyboardActivate )
2860  {
2862  mnCurItemId = 0;
2863  mnHighItemId = 0;
2864  }
2865  mnDownItemId = 0;
2866 
2867  }
2868 }
2869 
2870 void ToolBox::ShowLine( bool bNext )
2871 {
2872  mbFormat = true;
2873 
2874  if ( bNext )
2875  mnCurLine++;
2876  else
2877  mnCurLine--;
2878 
2879  ImplFormat();
2880 }
2881 
2882 bool ToolBox::ImplHandleMouseMove( const MouseEvent& rMEvt, bool bRepeat )
2883 {
2884  Point aMousePos = rMEvt.GetPosPixel();
2885 
2886  if ( !mpData )
2887  return false;
2888 
2889  // ToolBox active?
2890  if ( mbDrag && mnCurPos != ITEM_NOTFOUND )
2891  {
2892  // is the cursor over the item?
2893  ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
2894  if ( pItem->maRect.IsInside( aMousePos ) )
2895  {
2896  if ( !mnCurItemId )
2897  {
2899  mnCurItemId = pItem->mnId;
2900  Highlight();
2901  }
2902 
2903  if ( (pItem->mnBits & ToolBoxItemBits::REPEAT) && bRepeat )
2904  Select();
2905  }
2906  else
2907  {
2908  if ( mnCurItemId )
2909  {
2911  mnCurItemId = 0;
2913  Highlight();
2914  }
2915  }
2916 
2917  return true;
2918  }
2919 
2920  if ( mbUpper )
2921  {
2922  bool bNewIn = maUpperRect.IsInside( aMousePos );
2923  if ( bNewIn != mbIn )
2924  {
2925  mbIn = bNewIn;
2926  InvalidateSpin(true, false);
2927  }
2928  return true;
2929  }
2930 
2931  if ( mbLower )
2932  {
2933  bool bNewIn = maLowerRect.IsInside( aMousePos );
2934  if ( bNewIn != mbIn )
2935  {
2936  mbIn = bNewIn;
2937  InvalidateSpin(false);
2938  }
2939  return true;
2940  }
2941 
2942  return false;
2943 }
2944 
2945 bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent& rMEvt, bool bCancel )
2946 {
2948 
2949  if ( !mpData )
2950  return false;
2951 
2952  // stop eventual running dropdown timer
2953  if( mnCurPos < mpData->m_aItems.size() &&
2954  (mpData->m_aItems[mnCurPos].mnBits & ToolBoxItemBits::DROPDOWN ) )
2955  {
2956  mpData->maDropdownTimer.Stop();
2957  }
2958 
2959  if ( mbDrag || mbSelection )
2960  {
2961  // set mouse data if in selection mode, as then
2962  // the MouseButtonDown handler cannot be called
2963  if ( mbSelection )
2964  mnMouseModifier = rMEvt.GetModifier();
2965 
2966  Deactivate();
2967 
2968  if ( mbDrag )
2969  mbDrag = false;
2970  else
2971  {
2972  mbSelection = false;
2973  if ( mnCurPos == ITEM_NOTFOUND )
2974  return true;
2975  }
2976 
2977  // has mouse been released on top of item?
2978  if( mnCurPos < mpData->m_aItems.size() )
2979  {
2980  ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
2981  if ( pItem->maRect.IsInside( rMEvt.GetPosPixel() ) )
2982  {
2983  mnCurItemId = pItem->mnId;
2984  if ( !bCancel )
2985  {
2986  // execute AutoCheck if required
2987  if ( pItem->mnBits & ToolBoxItemBits::AUTOCHECK )
2988  {
2989  if ( pItem->mnBits & ToolBoxItemBits::RADIOCHECK )
2990  {
2991  if ( pItem->meState != TRISTATE_TRUE )
2992  SetItemState( pItem->mnId, TRISTATE_TRUE );
2993  }
2994  else
2995  {
2996  if ( pItem->meState != TRISTATE_TRUE )
2997  pItem->meState = TRISTATE_TRUE;
2998  else
2999  pItem->meState = TRISTATE_FALSE;
3000  }
3001  }
3002 
3003  // do not call Select when Repeat is active, as in this
3004  // case that was triggered already in MouseButtonDown
3005  if ( !(pItem->mnBits & ToolBoxItemBits::REPEAT) )
3006  {
3007  // prevent from being destroyed in the select handler
3008  VclPtr<vcl::Window> xWindow = this;
3009  Select();
3010  if ( xWindow->IsDisposed() )
3011  return true;
3012  }
3013  }
3014 
3015  {
3016  }
3017 
3018  // Items not destroyed, in Select handler
3019  if ( mnCurItemId )
3020  {
3021  // Get current pos for the case that items are inserted/removed
3022  // in the toolBox
3024  if ( mnCurPos != ITEM_NOTFOUND )
3025  {
3027  Flush();
3028  }
3029  }
3030  }
3031  }
3032 
3034  mnCurItemId = 0;
3035  mnDownItemId = 0;
3036  mnMouseModifier = 0;
3037  return true;
3038  }
3039  else if ( mbUpper || mbLower )
3040  {
3041  if ( mbIn )
3042  ShowLine( !mbUpper );
3043  mbUpper = false;
3044  mbLower = false;
3045  mbIn = false;
3046  InvalidateSpin();
3047  return true;
3048  }
3049 
3050  return false;
3051 }
3052 
3053 void ToolBox::MouseMove( const MouseEvent& rMEvt )
3054 {
3055  // pressing a modifier generates synthetic mouse moves
3056  // ignore it if keyboard selection is active
3057  if( HasFocus() && ( rMEvt.GetMode() & MouseEventModifiers::MODIFIERCHANGED ) )
3058  return;
3059 
3060  if ( ImplHandleMouseMove( rMEvt ) )
3061  return;
3062 
3064 
3065  Point aMousePos = rMEvt.GetPosPixel();
3066 
3067  // only highlight when the focus is not inside a child window of a toolbox
3068  // eg, in an edit control
3069  // and do not highlight when focus is in a different toolbox
3070  bool bDrawHotSpot = true;
3072  if( pWin && pWin->ImplGetWindowImpl()->mbToolBox && pWin != this )
3073  bDrawHotSpot = false;
3074 
3075  if ( mbSelection && bDrawHotSpot )
3076  {
3077  ImplToolItems::size_type i = 0;
3078  ImplToolItems::size_type nNewPos = ITEM_NOTFOUND;
3079 
3080  // search the item that has been clicked
3081  for (auto const& item : mpData->m_aItems)
3082  {
3083  // if the mouse position is in this item,
3084  // we can stop the search
3085  if ( item.maRect.IsInside( aMousePos ) )
3086  {
3087  // select it if it is a button
3088  if ( item.meType == ToolBoxItemType::BUTTON )
3089  {
3090  // if button is disabled, do not
3091  // change it
3092  if ( !item.mbEnabled || item.mbShowWindow )
3093  nNewPos = mnCurPos;
3094  else
3095  nNewPos = i;
3096  }
3097  break;
3098  }
3099  ++i;
3100  }
3101 
3102  // was a new entry selected?
3103  // don't change selection if keyboard selection is active and
3104  // mouse leaves the toolbox
3105  if ( nNewPos != mnCurPos && !( HasFocus() && nNewPos == ITEM_NOTFOUND ) )
3106  {
3107  if ( mnCurPos != ITEM_NOTFOUND )
3108  {
3110  CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( mnCurPos ) );
3111  }
3112 
3113  mnCurPos = nNewPos;
3114  if ( mnCurPos != ITEM_NOTFOUND )
3115  {
3116  mnCurItemId = mnHighItemId = mpData->m_aItems[mnCurPos].mnId;
3118  }
3119  else
3120  mnCurItemId = mnHighItemId = 0;
3121 
3122  Highlight();
3123  }
3124  return;
3125  }
3126 
3127  if ( mbDragging )
3128  {
3129  ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
3130  pMgr->Dragging( aMousePos );
3131  return;
3132  }
3133 
3135 
3136  // change mouse cursor over drag area
3138  if( pWrapper && pWrapper->GetDragArea().IsInside( rMEvt.GetPosPixel() ) )
3139  eStyle = PointerStyle::Move;
3140 
3142  {
3143  if ( rMEvt.GetMode() & MouseEventModifiers::SIMPLEMOVE )
3144  {
3145  sal_uInt16 nLinePtr = ImplTestLineSize( rMEvt.GetPosPixel() );
3146  if ( nLinePtr & DOCK_LINEHSIZE )
3147  {
3148  if ( meAlign == WindowAlign::Left )
3149  eStyle = PointerStyle::WindowESize;
3150  else
3151  eStyle = PointerStyle::WindowWSize;
3152  }
3153  else if ( nLinePtr & DOCK_LINEVSIZE )
3154  {
3155  if ( meAlign == WindowAlign::Top )
3156  eStyle = PointerStyle::WindowSSize;
3157  else
3158  eStyle = PointerStyle::WindowNSize;
3159  }
3160  }
3161  }
3162 
3163  if ( bDrawHotSpot && ( (mnOutStyle & TOOLBOX_STYLE_FLAT) || !mnOutStyle ) )
3164  {
3165  bool bClearHigh = true;
3166  if ( !rMEvt.IsLeaveWindow() && (mnCurPos == ITEM_NOTFOUND) )
3167  {
3168  ImplToolItems::size_type nTempPos = 0;
3169  for (auto const& item : mpData->m_aItems)
3170  {
3171  if ( item.maRect.IsInside( aMousePos ) )
3172  {
3173  if ( (item.meType == ToolBoxItemType::BUTTON) && item.mbEnabled )
3174  {
3175  if ( !mnOutStyle || (mnOutStyle & TOOLBOX_STYLE_FLAT) )
3176  {
3177  bClearHigh = false;
3178  if ( mnHighItemId != item.mnId )
3179  {
3180  if ( mnHighItemId )
3181  {
3182  ImplHideFocus();
3183  ImplToolItems::size_type nPos = GetItemPos( mnHighItemId );
3184  InvalidateItem(nPos);
3185  CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nPos ) );
3186  }
3187  if ( mpData->mbMenubuttonSelected )
3188  {
3189  // remove highlight from menubutton
3191  }
3192  mnHighItemId = item.mnId;
3193  InvalidateItem(nTempPos);
3194  ImplShowFocus();
3196  }
3197  }
3198  }
3199  break;
3200  }
3201  ++nTempPos;
3202  }
3203  }
3204 
3205  // only clear highlight when focus is not in toolbar
3206  bool bMenuButtonHit = mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems();
3207  if ( bClearHigh || bMenuButtonHit )
3208  {
3209  if ( !bMenuButtonHit && mpData->mbMenubuttonSelected )
3210  {
3211  // remove highlight from menubutton
3213  }
3214 
3215  if( mnHighItemId )
3216  {
3217  ImplToolItems::size_type nClearPos = GetItemPos( mnHighItemId );
3218  if ( nClearPos != ITEM_NOTFOUND )
3219  {
3220  InvalidateItem(nClearPos);
3221  if( nClearPos != mnCurPos )
3222  CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nClearPos ) );
3223  }
3224  ImplHideFocus();
3225  mnHighItemId = 0;
3226  }
3227 
3228  if( bMenuButtonHit )
3229  {
3231  }
3232  }
3233  }
3234 
3235  if ( meLastStyle != eStyle )
3236  {
3237  meLastStyle = eStyle;
3238  SetPointer( eStyle );
3239  }
3240 
3241  DockingWindow::MouseMove( rMEvt );
3242 }
3243 
3245 {
3246  // only trigger toolbox for left mouse button and when
3247  // we're not in normal operation
3248  if ( rMEvt.IsLeft() && !mbDrag && (mnCurPos == ITEM_NOTFOUND) )
3249  {
3250  // call activate already here, as items could
3251  // be exchanged
3252  Activate();
3253 
3254  // update ToolBox here, such that user knows it
3255  if ( mbFormat )
3256  {
3257  ImplFormat();
3258  Update();
3259  }
3260 
3261  Point aMousePos = rMEvt.GetPosPixel();
3262  ImplToolItems::size_type i = 0;
3263  ImplToolItems::size_type nNewPos = ITEM_NOTFOUND;
3264 
3265  // search for item that was clicked
3266  for (auto const& item : mpData->m_aItems)
3267  {
3268  // is this the item?
3269  if ( item.maRect.IsInside( aMousePos ) )
3270  {
3271  // do nothing if it is a separator or
3272  // if the item has been disabled
3273  if ( (item.meType == ToolBoxItemType::BUTTON) &&
3274  !item.mbShowWindow )
3275  nNewPos = i;
3276 
3277  break;
3278  }
3279 
3280  i++;
3281  }
3282 
3283  // item found
3284  if ( nNewPos != ITEM_NOTFOUND )
3285  {
3286  if ( !mpData->m_aItems[nNewPos].mbEnabled )
3287  {
3288  Deactivate();
3289  return;
3290  }
3291 
3292  // update actual data
3294  mnCurPos = i;
3295  mnCurItemId = mpData->m_aItems[nNewPos].mnId;
3297  mnMouseModifier = rMEvt.GetModifier();
3298  if ( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::REPEAT )
3299  nTrackFlags |= StartTrackingFlags::ButtonRepeat;
3300 
3301  if ( mbSelection )
3302  {
3303  InvalidateItem(mnCurPos);
3304  Highlight();
3305  }
3306  else
3307  {
3308  // update bDrag here, as it is evaluated in the EndSelection
3309  mbDrag = true;
3310 
3311  // on double-click: only call the handler, but do so before the button
3312  // is hit, as in the handler dragging
3313  // can be terminated
3314  if ( rMEvt.GetClicks() == 2 )
3315  DoubleClick();
3316 
3317  if ( mbDrag )
3318  {
3319  InvalidateItem(mnCurPos);
3320  Highlight();
3321  }
3322 
3323  // was dropdown arrow pressed
3324  if( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWN )
3325  {
3326  if( ( (mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWNONLY) == ToolBoxItemBits::DROPDOWNONLY)
3327  || mpData->m_aItems[nNewPos].GetDropDownRect( mbHorz ).IsInside( aMousePos ))
3328  {
3329  // dropdownonly always triggers the dropdown handler, over the whole button area
3330 
3331  // the drop down arrow should not trigger the item action
3332  mpData->mbDropDownByKeyboard = false;
3333  mpData->maDropdownClickHdl.Call( this );
3334 
3335  // do not reset data if the dropdown handler opened a floating window
3336  // see ImplFloatControl()
3337  if( !mpFloatWin )
3338  {
3339  // no floater was opened
3340  Deactivate();
3341  InvalidateItem(mnCurPos);
3342 
3343  mnCurPos = ITEM_NOTFOUND;
3344  mnCurItemId = 0;
3345  mnDownItemId = 0;
3346  mnMouseModifier = 0;
3347  mnHighItemId = 0;
3348  }
3349  return;
3350  }
3351  else // activate long click timer
3352  mpData->maDropdownTimer.Start();
3353  }
3354 
3355  // call Click handler
3356  if ( rMEvt.GetClicks() != 2 )
3357  Click();
3358 
3359  // also call Select handler at repeat
3360  if ( nTrackFlags & StartTrackingFlags::ButtonRepeat )
3361  Select();
3362 
3363  // if the actions was not aborted in Click handler
3364  if ( mbDrag )
3365  StartTracking( nTrackFlags );
3366  }
3367 
3368  // if mouse was clicked over an item we
3369  // can abort here
3370  return;
3371  }
3372 
3373  Deactivate();
3374 
3375  // menu button hit ?
3376  if( mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems() )
3377  {
3378  if ( maMenuButtonHdl.IsSet() )
3379  maMenuButtonHdl.Call( this );
3380  else
3381  ExecuteCustomMenu( mpData->maMenubuttonItem.maRect );
3382  return;
3383  }
3384 
3385  // check scroll- and next-buttons here
3386  if ( maUpperRect.IsInside( aMousePos ) )
3387  {
3388  if ( mnCurLine > 1 )
3389  {
3390  StartTracking();
3391  mbUpper = true;
3392  mbIn = true;
3393  InvalidateSpin(true, false);
3394  }
3395  return;
3396  }
3397  if ( maLowerRect.IsInside( aMousePos ) )
3398  {
3399  if ( mnCurLine+mnVisLines-1 < mnCurLines )
3400  {
3401  StartTracking();
3402  mbLower = true;
3403  mbIn = true;
3404  InvalidateSpin(false);
3405  }
3406  return;
3407  }
3408 
3409  // Linesizing testen
3410  if ( (mnWinStyle & TB_WBLINESIZING) == TB_WBLINESIZING )
3411  {
3412  sal_uInt16 nLineMode = ImplTestLineSize( aMousePos );
3413  if ( nLineMode )
3414  {
3415  ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
3416 
3417  // call handler, such that we can set the
3418  // dock rectangles
3419  StartDocking();
3420 
3422  Size aSize = GetSizePixel();
3423  aPos = ScreenToOutputPixel( aPos );
3424 
3425  // start dragging
3426  pMgr->StartDragging( this, aMousePos, tools::Rectangle( aPos, aSize ),
3427  nLineMode );
3428  return;
3429  }
3430  }
3431 
3432  // no item, then only click or double click
3433  if ( rMEvt.GetClicks() == 2 )
3434  DoubleClick();
3435  else
3436  Click();
3437  }
3438 
3439  if ( !mbDrag && !mbSelection && (mnCurPos == ITEM_NOTFOUND) )
3441 }
3442 
3444 {
3445  if ( ImplHandleMouseButtonUp( rMEvt ) )
3446  return;
3447 
3448  if ( mbDragging && rMEvt.IsLeft() )
3449  {
3450  ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
3451  pMgr->EndDragging();
3452  return;
3453  }
3454 
3456 }
3457 
3458 void ToolBox::Tracking( const TrackingEvent& rTEvt )
3459 {
3460  VclPtr<vcl::Window> xWindow = this;
3461 
3462  if ( rTEvt.IsTrackingEnded() )
3464  else
3466 
3467  if ( xWindow->IsDisposed() )
3468  // toolbox was deleted
3469  return;
3470  DockingWindow::Tracking( rTEvt );
3471 }
3472 
3473 void ToolBox::InvalidateItem(ImplToolItems::size_type nPosition)
3474 {
3475  if (mpData && nPosition < mpData->m_aItems.size())
3476  {
3477  ImplToolItem* pItem = &mpData->m_aItems[nPosition];
3478  Invalidate(pItem->maRect);
3479  }
3480 }
3481 
3483 {
3484  if (!mpData->maMenubuttonItem.maRect.IsEmpty())
3485  Invalidate(mpData->maMenubuttonItem.maRect);
3486 }
3487 
3488 void ToolBox::InvalidateSpin(bool bUpperIn, bool bLowerIn)
3489 {
3490  if (bUpperIn && !maUpperRect.IsEmpty())
3492 
3493  if (bLowerIn && !maLowerRect.IsEmpty())
3495 }
3496 
3497 void ToolBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rPaintRect)
3498 {
3499  if( mpData->mbIsPaintLocked )
3500  return;
3501 
3502  if (rPaintRect == tools::Rectangle(0, 0, mnDX-1, mnDY-1))
3503  mbFullPaint = true;
3504  ImplFormat();
3505  mbFullPaint = false;
3506 
3507  ImplDrawBackground(rRenderContext, rPaintRect);
3508 
3509  if ( (mnWinStyle & WB_BORDER) && !ImplIsFloatingMode() )
3510  ImplDrawBorder(rRenderContext);
3511 
3512  if( !ImplIsFloatingMode() )
3513  ImplDrawGrip(rRenderContext);
3514 
3515  ImplDrawMenuButton(rRenderContext, mpData->mbMenubuttonSelected);
3516 
3517  // draw SpinButtons
3518  if (mnWinStyle & WB_SCROLL)
3519  {
3520  if (mnCurLines > mnLines)
3521  ImplDrawSpin(rRenderContext);
3522  }
3523 
3524  // draw buttons
3525  ImplToolItems::size_type nHighPos;
3526  if ( mnHighItemId )
3527  nHighPos = GetItemPos( mnHighItemId );
3528  else
3529  nHighPos = ITEM_NOTFOUND;
3530 
3531  ImplToolItems::size_type nCount = mpData->m_aItems.size();
3532  for( ImplToolItems::size_type i = 0; i < nCount; i++ )
3533  {
3534  ImplToolItem* pItem = &mpData->m_aItems[i];
3535 
3536  // only draw when the rectangle is in the draw rectangle
3537  if ( !pItem->maRect.IsEmpty() && rPaintRect.IsOver( pItem->maRect ) )
3538  {
3539  sal_uInt16 nHighlight = 0;
3540  if ( i == mnCurPos )
3541  nHighlight = 1;
3542  else if ( i == nHighPos )
3543  nHighlight = 2;
3544  ImplDrawItem(rRenderContext, i, nHighlight);
3545  }
3546  }
3547  ImplShowFocus();
3548 }
3549 
3551 {
3552  Size aSize = GetOutputSizePixel();
3553  // #i31422# some WindowManagers send (0,0) sizes when
3554  // switching virtual desktops - ignore this and avoid reformatting
3555  if( !aSize.Width() && !aSize.Height() )
3556  return;
3557 
3558  long nOldDX = mnDX;
3559  long nOldDY = mnDY;
3560  mnDX = aSize.Width();
3561  mnDY = aSize.Height();
3562 
3563  mnLastResizeDY = 0;
3564 
3565  // invalidate everything to have gradient backgrounds properly drawn
3566  Invalidate();
3567 
3568  // If we have any expandable entries, then force a reformat first using
3569  // their optimal sizes, then share out the excess space evenly across those
3570  // expandables and reformat again
3571  std::vector<size_t> aExpandables;
3572  for (size_t i = 0; i < mpData->m_aItems.size(); ++i)
3573  {
3574  if (mpData->m_aItems[i].mbExpand)
3575  {
3576  vcl::Window *pWindow = mpData->m_aItems[i].mpWindow;
3577  SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
3578  if (!pWindow)
3579  continue;
3580  Size aWinSize(pWindow->GetSizePixel());
3581  Size aPrefSize(pWindow->get_preferred_size());
3582  aWinSize.setWidth( aPrefSize.Width() );
3583  pWindow->SetSizePixel(aWinSize);
3584  aExpandables.push_back(i);
3585  }
3586  }
3587 
3588  // re-format or re-draw
3589  if ( mbScroll || !aExpandables.empty() )
3590  {
3591  if ( !mbFormat || !aExpandables.empty() )
3592  {
3593  mbFormat = true;
3594  if( IsReallyVisible() || !aExpandables.empty() )
3595  {
3596  ImplFormat(true);
3597 
3598  if (!aExpandables.empty())
3599  {
3600  //Get how big the optimal size is
3601  tools::Rectangle aBounds;
3602  for (const ImplToolItem & rItem : mpData->m_aItems)
3603  {
3604  aBounds.Union( rItem.maRect );
3605  }
3606 
3607  long nOptimalWidth = aBounds.GetWidth();
3608  long nDiff = aSize.Width() - nOptimalWidth;
3609  nDiff /= aExpandables.size();
3610 
3611  //share out the diff from optimal to real across
3612  //expandable entries
3613  for (size_t nIndex : aExpandables)
3614  {
3615  vcl::Window *pWindow = mpData->m_aItems[nIndex].mpWindow;
3616  Size aWinSize(pWindow->GetSizePixel());
3617  Size aPrefSize(pWindow->get_preferred_size());
3618  aWinSize.setWidth( aPrefSize.Width() + nDiff );
3619  pWindow->SetSizePixel(aWinSize);
3620  }
3621 
3622  //now reformat with final sizes
3623  mbFormat = true;
3624  ImplFormat(true);
3625  }
3626  }
3627  }
3628  }
3629 
3630  // redraw border
3631  if ( mnWinStyle & WB_BORDER )
3632  {
3633  // as otherwise, when painting we might think we have to re-draw everything
3634  if ( mbFormat && IsReallyVisible() )
3635  Invalidate();
3636  else
3637  {
3638  if ( mnRightBorder )
3639  {
3640  if ( nOldDX > mnDX )
3642  else
3643  Invalidate( tools::Rectangle( nOldDX-mnRightBorder-1, 0, nOldDX, nOldDY ) );
3644  }
3645 
3646  if ( mnBottomBorder )
3647  {
3648  if ( nOldDY > mnDY )
3650  else
3651  Invalidate( tools::Rectangle( 0, nOldDY-mnBottomBorder-1, nOldDX, nOldDY ) );
3652  }
3653  }
3654  }
3655 }
3656 
3657 namespace
3658 {
3659  bool DispatchableCommand(const OUString& rName)
3660  {
3661  return rName.startsWith(".uno") ||
3662  rName.startsWith("slot:") ||
3663  rName.startsWith("macro:") ||
3664  rName.startsWith("vnd.sun.star.script");
3665  }
3666 }
3667 
3668 const OUString& ToolBox::ImplGetHelpText( sal_uInt16 nItemId ) const
3669 {
3670  ImplToolItem* pItem = ImplGetItem( nItemId );
3671 
3672  assert( pItem );
3673 
3674  if ( pItem->maHelpText.isEmpty() && ( !pItem->maHelpId.isEmpty() || pItem->maCommandStr.getLength() ))
3675  {
3676  Help* pHelp = Application::GetHelp();
3677  if ( pHelp )
3678  {
3679  if (DispatchableCommand(pItem->maCommandStr))
3680  pItem->maHelpText = pHelp->GetHelpText( pItem->maCommandStr, this );
3681  if ( pItem->maHelpText.isEmpty() && !pItem->maHelpId.isEmpty() )
3682  pItem->maHelpText = pHelp->GetHelpText( OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
3683  }
3684  }
3685 
3686  return pItem->maHelpText;
3687 }
3688 
3689 void ToolBox::RequestHelp( const HelpEvent& rHEvt )
3690 {
3691  sal_uInt16 nItemId;
3692  Point aHelpPos;
3693 
3694  if( !rHEvt.KeyboardActivated() )
3695  {
3696  nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
3697  aHelpPos = rHEvt.GetMousePosPixel();
3698  }
3699  else
3700  {
3701  if( !mnHighItemId )
3702  return;
3703  else
3704  nItemId = mnHighItemId;
3705  tools::Rectangle aRect( GetItemRect( nItemId ) );
3706  if( aRect.IsEmpty() )
3707  return;
3708  else
3709  aHelpPos = OutputToScreenPixel( aRect.Center() );
3710  }
3711 
3712  if ( nItemId )
3713  {
3715  {
3716  // get rectangle
3717  tools::Rectangle aTempRect = GetItemRect( nItemId );
3718  Point aPt = OutputToScreenPixel( aTempRect.TopLeft() );
3719  aTempRect.SetLeft( aPt.X() );
3720  aTempRect.SetTop( aPt.Y() );
3721  aPt = OutputToScreenPixel( aTempRect.BottomRight() );
3722  aTempRect.SetRight( aPt.X() );
3723  aTempRect.SetBottom( aPt.Y() );
3724 
3725  // get text and display it
3726  OUString aStr = GetQuickHelpText( nItemId );
3727  if (aStr.isEmpty())
3729  if ( rHEvt.GetMode() & HelpEventMode::BALLOON )
3730  {
3731  const OUString& rHelpStr = GetHelpText( nItemId );
3732  if (!rHelpStr.isEmpty())
3733  aStr = rHelpStr;
3734  Help::ShowBalloon( this, aHelpPos, aTempRect, aStr );
3735  }
3736  else
3737  Help::ShowQuickHelp( this, aTempRect, aStr, QuickHelpFlags::CtrlText );
3738  return;
3739  }
3740  }
3741 
3742  DockingWindow::RequestHelp( rHEvt );
3743 }
3744 
3746 {
3747  if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
3748  {
3749  KeyEvent aKEvt = *rNEvt.GetKeyEvent();
3750  vcl::KeyCode aKeyCode = aKEvt.GetKeyCode();
3751  sal_uInt16 nKeyCode = aKeyCode.GetCode();
3752  switch( nKeyCode )
3753  {
3754  case KEY_TAB:
3755  {
3756  // internal TAB cycling only if parent is not a dialog or if we are the only child
3757  // otherwise the dialog control will take over
3758  vcl::Window *pParent = ImplGetParent();
3759  bool bOldSchoolContainer =
3761  pParent->GetChildCount() != 1);
3762  bool bNoTabCycling = bOldSchoolContainer || isContainerWindow(pParent);
3763 
3764  if( bNoTabCycling )
3765  return DockingWindow::EventNotify( rNEvt );
3766  else if( ImplChangeHighlightUpDn( aKeyCode.IsShift() , bNoTabCycling ) )
3767  return false;
3768  else
3769  return DockingWindow::EventNotify( rNEvt );
3770  }
3771  default:
3772  break;
3773  };
3774  }
3775  else if( rNEvt.GetType() == MouseNotifyEvent::GETFOCUS )
3776  {
3777  if( rNEvt.GetWindow() == this )
3778  {
3779  // the toolbar itself got the focus
3780  if( mnLastFocusItemId != 0 || mpData->mbMenubuttonWasLastSelected )
3781  {
3782  // restore last item
3783  if( mpData->mbMenubuttonWasLastSelected )
3784  {
3785  ImplChangeHighlight( nullptr );
3786  mpData->mbMenubuttonSelected = true;
3788  }
3789  else
3790  {
3792  mnLastFocusItemId = 0;
3793  }
3794  }
3796  // Shift-TAB was pressed in the parent
3797  ImplChangeHighlightUpDn( false );
3798  else
3799  ImplChangeHighlightUpDn( true );
3800 
3801  mnLastFocusItemId = 0;
3802 
3803  return true;
3804  }
3805  else
3806  {
3807  // a child window got the focus so update current item to
3808  // allow for proper lose focus handling in keyboard navigation
3809  for (auto const& item : mpData->m_aItems)
3810  {
3811  if ( item.mbVisible )
3812  {
3813  if ( item.mpWindow && item.mpWindow->ImplIsWindowOrChild( rNEvt.GetWindow() ) )
3814  {
3815  mnHighItemId = item.mnId;
3816  break;
3817  }
3818  }
3819  }
3820  return DockingWindow::EventNotify( rNEvt );
3821  }
3822  }
3823  else if( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS )
3824  {
3825  // deselect
3826  ImplHideFocus();
3827  mpData->mbMenubuttonWasLastSelected = false;
3828  mnHighItemId = 0;
3830  }
3831 
3832  return DockingWindow::EventNotify( rNEvt );
3833 }
3834 
3835 void ToolBox::Command( const CommandEvent& rCEvt )
3836 {
3837  if ( rCEvt.GetCommand() == CommandEventId::Wheel )
3838  {
3839  if ( (mnCurLine > 1) || (mnCurLine+mnVisLines-1 < mnCurLines) )
3840  {
3841  const CommandWheelData* pData = rCEvt.GetWheelData();
3842  if ( pData->GetMode() == CommandWheelMode::SCROLL )
3843  {
3844  if ( (mnCurLine > 1) && (pData->GetDelta() > 0) )
3845  ShowLine( false );
3846  else if ( (mnCurLine+mnVisLines-1 < mnCurLines) && (pData->GetDelta() < 0) )
3847  ShowLine( true );
3848  InvalidateSpin();
3849  return;
3850  }
3851  }
3852  }
3853  else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
3854  {
3856  return;
3857  }
3858 
3859  DockingWindow::Command( rCEvt );
3860 }
3861 
3863 {
3864  DockingWindow::StateChanged( nType );
3865 
3866  if ( nType == StateChangedType::InitShow )
3867  ImplFormat();
3868  else if ( nType == StateChangedType::Enable )
3869  ImplUpdateItem();
3870  else if ( nType == StateChangedType::UpdateMode )
3871  {
3872  if ( IsUpdateMode() )
3873  Invalidate();
3874  }
3875  else if ( (nType == StateChangedType::Zoom) ||
3876  (nType == StateChangedType::ControlFont) )
3877  {
3878  mbCalc = true;
3879  mbFormat = true;
3880  ImplInitSettings( true, false, false );
3881  Invalidate();
3882  }
3883  else if ( nType == StateChangedType::ControlForeground )
3884  {
3885  ImplInitSettings( false, true, false );
3886  Invalidate();
3887  }
3888  else if ( nType == StateChangedType::ControlBackground )
3889  {
3890  ImplInitSettings( false, false, true ); // font, foreground, background
3891  Invalidate();
3892  }
3893 
3894  maStateChangedHandler.Call( &nType );
3895 }
3896 
3898 {
3899  DockingWindow::DataChanged( rDCEvt );
3900 
3901  if ( (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
3902  (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
3904  ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
3905  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
3906  {
3907  mbCalc = true;
3908  mbFormat = true;
3909  ImplInitSettings( true, true, true );
3910  Invalidate();
3911  }
3912 
3913  maDataChangedHandler.Call( &rDCEvt );
3914 }
3915 
3916 void ToolBox::statusChanged( const css::frame::FeatureStateEvent& Event )
3917 {
3918  // Update image mirroring/rotation
3919  if ( Event.FeatureURL.Complete == ".uno:ImageOrientation" )
3920  {
3921  SfxImageItem aItem( 1 );
3922  aItem.PutValue( Event.State, 0 );
3923 
3924  mbImagesMirrored = aItem.IsMirrored();
3926 
3927  // update image orientation
3928  OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(mpStatusListener->getFrame()));
3929  for (auto const& item : mpData->m_aItems)
3930  {
3931  if (vcl::CommandInfoProvider::IsMirrored(item.maCommandStr, aModuleName))
3933  if (vcl::CommandInfoProvider::IsRotated(item.maCommandStr, aModuleName))
3935  }
3936  }
3937 }
3938 
3940 {
3941  mnWinStyle = nNewStyle;
3942  if (!ImplIsFloatingMode())
3943  {
3944  bool bOldScroll = mbScroll;
3945  mbScroll = (mnWinStyle & WB_SCROLL) != 0;
3946  if (mbScroll != bOldScroll)
3947  {
3948  mbFormat = true;
3949  ImplFormat();
3950  }
3951  }
3952 }
3953 
3955 {
3957 
3958  if (!mpData)
3959  return;
3960 
3961  bool bOldHorz = mbHorz;
3962 
3963  if ( ImplIsFloatingMode() )
3964  {
3965  mbHorz = true;
3966  meAlign = WindowAlign::Top;
3967  mbScroll = true;
3968 
3969  if( bOldHorz != mbHorz )
3970  mbCalc = true; // orientation was changed !
3971 
3974  }
3975  else
3976  {
3977  mbScroll = (mnWinStyle & WB_SCROLL) != 0;
3978  if ( (meAlign == WindowAlign::Top) || (meAlign == WindowAlign::Bottom) )
3979  mbHorz = true;
3980  else
3981  mbHorz = false;
3982 
3983  // set focus back to document
3985  }
3986 
3987  if( bOldHorz != mbHorz )
3988  {
3989  // if orientation changes, the toolbox has to be initialized again
3990  // to update the direction of the gradient
3991  mbCalc = true;
3992  ImplInitSettings( true, true, true );
3993  }
3994 
3995  mbFormat = true;
3996  ImplFormat();
3997 }
3998 
4000 {
4001  meDockAlign = meAlign;
4002  mnDockLines = mnLines;
4005 }
4006 
4007 bool ToolBox::Docking( const Point& rPos, tools::Rectangle& rRect )
4008 {
4009  // do nothing during dragging, it was calculated before
4010  if ( mbDragging )
4011  return false;
4012 
4013  bool bFloatMode = false;
4014 
4015  DockingWindow::Docking( rPos, rRect );
4016 
4017  // if the mouse is outside the area, it can only become a floating window
4018  tools::Rectangle aDockingRect( rRect );
4019  if ( !ImplIsFloatingMode() )
4020  {
4021  // don't use tracking rectangle for alignment check, because it will be too large
4022  // to get a floating mode as result - switch to floating size
4023  // so the calculation only depends on the position of the rectangle, not the current
4024  // docking state of the window
4025  ImplToolItems::size_type nTemp = 0;
4026  aDockingRect.SetSize( ImplCalcFloatSize( nTemp ) );
4027 
4028  // in this mode docking is never done by keyboard, so it's OK to use the mouse position
4029  aDockingRect.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
4030  }
4031 
4032  bFloatMode = true;
4033 
4034  meDockAlign = meAlign;
4035  if ( !mbLastFloatMode )
4036  {
4037  ImplToolItems::size_type nTemp = 0;
4038  aDockingRect.SetSize( ImplCalcFloatSize( nTemp ) );
4039  }
4040 
4041  rRect = aDockingRect;
4042  mbLastFloatMode = bFloatMode;
4043 
4044  return bFloatMode;
4045 }
4046 
4047 void ToolBox::EndDocking( const tools::Rectangle& rRect, bool bFloatMode )
4048 {
4049  if ( !IsDockingCanceled() )
4050  {
4051  if ( mnLines != mnDockLines )
4053  if ( meAlign != meDockAlign )
4054  SetAlign( meDockAlign );
4055  }
4056  if ( bFloatMode || (bFloatMode != ImplIsFloatingMode()) )
4057  DockingWindow::EndDocking( rRect, bFloatMode );
4058 }
4059 
4060 void ToolBox::Resizing( Size& rSize )
4061 {
4062  ImplToolItems::size_type nCalcLines;
4063  ImplToolItems::size_type nTemp;
4064 
4065  // calculate all floating sizes
4067 
4068  if ( !mnLastResizeDY )
4069  mnLastResizeDY = mnDY;
4070 
4071  // is vertical resizing needed
4072  if ( (mnLastResizeDY != rSize.Height()) && (mnDY != rSize.Height()) )
4073  {
4074  nCalcLines = ImplCalcLines( rSize.Height() );
4075  if ( nCalcLines < 1 )
4076  nCalcLines = 1;
4077  rSize = ImplCalcFloatSize( nCalcLines );
4078  }
4079  else
4080  {
4081  nCalcLines = 1;
4082  nTemp = nCalcLines;
4083  Size aTempSize = ImplCalcFloatSize( nTemp );
4084  while ( (aTempSize.Width() > rSize.Width()) &&
4085  (nCalcLines <= maFloatSizes[0].mnLines) )
4086  {
4087  nCalcLines++;
4088  nTemp = nCalcLines;
4089  aTempSize = ImplCalcFloatSize( nTemp );
4090  }
4091  rSize = aTempSize;
4092  }
4093 
4094  mnLastResizeDY = rSize.Height();
4095 }
4096 
4098 {
4099  // If we have any expandable entries, then force them to their
4100  // optimal sizes, then reset them afterwards
4101  std::map<vcl::Window*, Size> aExpandables;
4102  for (const ImplToolItem & rItem : mpData->m_aItems)
4103  {
4104  if (rItem.mbExpand)
4105  {
4106  vcl::Window *pWindow = rItem.mpWindow;
4107  SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
4108  if (!pWindow)
4109  continue;
4110  Size aWinSize(pWindow->GetSizePixel());
4111  aExpandables[pWindow] = aWinSize;
4112  Size aPrefSize(pWindow->get_preferred_size());
4113  aWinSize.setWidth( aPrefSize.Width() );
4114  pWindow->SetSizePixel(aWinSize);
4115  }
4116  }
4117 
4118  Size aSize(const_cast<ToolBox *>(this)->ImplCalcSize( mnLines ));
4119 
4120  for (auto const& expandable : aExpandables)
4121  {
4122  vcl::Window *pWindow = expandable.first;
4123  Size aWinSize = expandable.second;
4124  pWindow->SetSizePixel(aWinSize);
4125  }
4126 
4127  return aSize;
4128 }
4129 
4130 Size ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines )
4131 {
4132  return ImplCalcSize( nCalcLines );
4133 }
4134 
4135 Size ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines, WindowAlign eAlign )
4136 {
4137  return ImplCalcSize( nCalcLines,
4138  (eAlign == WindowAlign::Top || eAlign == WindowAlign::Bottom) ? TB_CALCMODE_HORZ : TB_CALCMODE_VERT );
4139 }
4140 
4141 ToolBox::ImplToolItems::size_type ToolBox::ImplCountLineBreaks() const
4142 {
4143  ImplToolItems::size_type nLines = 0;
4144 
4145  for (auto const& item : mpData->m_aItems)
4146  {
4147  if( item.meType == ToolBoxItemType::BREAK )
4148  ++nLines;
4149  }
4150  return nLines;
4151 }
4152 
4154 {
4155  // count number of breaks and calc corresponding floating window size
4156  ImplToolItems::size_type nLines = ImplCountLineBreaks();
4157 
4158  if( nLines )
4159  ++nLines; // add the first line
4160  else
4161  {
4162  // no breaks found: use quadratic layout
4163  nLines = static_cast<ImplToolItems::size_type>(ceil( sqrt( static_cast<double>(GetItemCount()) ) ));
4164  }
4165 
4166  bool bPopup = mpData->mbAssumePopupMode;
4167  mpData->mbAssumePopupMode = true;
4168 
4169  Size aSize = CalcFloatingWindowSizePixel( nLines );
4170 
4171  mpData->mbAssumePopupMode = bPopup;
4172  return aSize;
4173 }
4174 
4176 {
4177  ImplToolItems::size_type nLines = ImplCountLineBreaks();
4178  ++nLines; // add the first line
4179  return CalcFloatingWindowSizePixel( nLines );
4180 }
4181 
4182 Size ToolBox::CalcFloatingWindowSizePixel( ImplToolItems::size_type nCalcLines )
4183 {
4184  bool bFloat = mpData->mbAssumeFloating;
4185  bool bDocking = mpData->mbAssumeDocked;
4186 
4187  // simulate floating mode and force reformat before calculating
4188  mpData->mbAssumeFloating = true;
4189  mpData->mbAssumeDocked = false;
4190 
4191  Size aSize = ImplCalcFloatSize( nCalcLines );
4192 
4193  mbFormat = true;
4194  mpData->mbAssumeFloating = bFloat;
4195  mpData->mbAssumeDocked = bDocking;
4196 
4197  return aSize;
4198 }
4199 
4201 {
4202  if( ImplIsFloatingMode() )
4203  return ImplCalcSize( mnFloatLines );
4204  else
4205  {
4206  // create dummy toolbox for measurements
4207  VclPtrInstance< ToolBox > pToolBox( GetParent(), GetStyle() );
4208 
4209  // copy until first useful item
4210  for (auto const& item : mpData->m_aItems)
4211  {
4212  pToolBox->CopyItem( *this, item.mnId );
4213  if( (item.meType == ToolBoxItemType::BUTTON) &&
4214  item.mbVisible && !ImplIsFixedControl( &item ) )
4215  break;
4216  }
4217 
4218  // add to docking manager if required to obtain a drag area
4219  // (which is accounted for in calcwindowsizepixel)
4220  if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
4221  ImplGetDockingManager()->AddWindow( pToolBox );
4222 
4223  // account for menu
4224  if( IsMenuEnabled() )
4225  pToolBox->SetMenuType( GetMenuType() );
4226 
4227  pToolBox->SetAlign( GetAlign() );
4228  Size aSize = pToolBox->CalcWindowSizePixel( 1 );
4229 
4230  ImplGetDockingManager()->RemoveWindow( pToolBox );
4231  pToolBox->Clear();
4232 
4233  pToolBox.disposeAndClear();
4234 
4235  return aSize;
4236  }
4237 }
4238 
4239 void ToolBox::EnableCustomize( bool bEnable )
4240 {
4241  mbCustomize = bEnable;
4242 }
4243 
4245 {
4246  ImplChangeHighlight( nullptr, true );
4247 
4249 }
4250 
4251 // performs the action associated with an item, ie simulates clicking the item
4252 void ToolBox::TriggerItem( sal_uInt16 nItemId )
4253 {
4254  mnHighItemId = nItemId;
4255  vcl::KeyCode aKeyCode( 0, 0 );
4256  ImplActivateItem( aKeyCode );
4257 }
4258 
4259 // calls the button's action handler
4260 // returns true if action was called
4262 {
4263  bool bRet = true;
4264  if( mnHighItemId )
4265  {
4266  ImplToolItem *pToolItem = ImplGetItem( mnHighItemId );
4267 
4268  // #107712#, activate can also be called for disabled entries
4269  if( pToolItem && !pToolItem->mbEnabled )
4270  return true;
4271 
4272  if( pToolItem && pToolItem->mpWindow && HasFocus() )
4273  {
4274  ImplHideFocus();
4275  mbChangingHighlight = true; // avoid focus change due to loss of focus
4277  mbChangingHighlight = false;
4278  }
4279  else
4280  {
4282  if (pToolItem && (pToolItem->mnBits & ToolBoxItemBits::AUTOCHECK))
4283  {
4284  if ( pToolItem->mnBits & ToolBoxItemBits::RADIOCHECK )
4285  {
4286  if ( pToolItem->meState != TRISTATE_TRUE )
4287  SetItemState( pToolItem->mnId, TRISTATE_TRUE );
4288  }
4289  else
4290  {
4291  if ( pToolItem->meState != TRISTATE_TRUE )
4292  pToolItem->meState = TRISTATE_TRUE;
4293  else
4294  pToolItem->meState = TRISTATE_FALSE;
4295  }
4296  }
4297  mnMouseModifier = aKeyCode.GetModifier();
4298  mbIsKeyEvent = true;
4299  Activate();
4300  Click();
4301 
4302  // #107776# we might be destroyed in the selecthandler
4303  VclPtr<vcl::Window> xWindow = this;
4304  Select();
4305  if ( xWindow->IsDisposed() )
4306  return bRet;
4307 
4308  Deactivate();
4309  mbIsKeyEvent = false;
4310  mnMouseModifier = 0;
4311  }
4312  }
4313  else
4314  bRet = false;
4315  return bRet;
4316 }
4317 
4318 static bool ImplCloseLastPopup( vcl::Window const *pParent )
4319 {
4320  // close last popup toolbox (see also:
4321  // ImplHandleMouseFloatMode(...) in winproc.cxx )
4322 
4323  if( ImplGetSVData()->maWinData.mpFirstFloat )
4324  {
4326  // only close the floater if it is not our direct parent, which would kill ourself
4327  if( pLastLevelFloat && pLastLevelFloat != pParent )
4328  {
4330  return true;
4331  }
4332  }
4333  return false;
4334 }
4335 
4336 // opens a drop down toolbox item
4337 // returns true if item was opened
4339 {
4340  sal_uInt16 nCode = aKeyCode.GetCode();
4341  bool bRet = true;
4342 
4343  // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
4344  if ( ((nCode == KEY_LEFT || nCode == KEY_RIGHT) && IsHorizontal())
4345  || ((nCode == KEY_UP || nCode == KEY_DOWN) && !IsHorizontal()) )
4346  return false;
4347 
4348  if( mpData->mbMenubuttonSelected )
4349  {
4350  if( ImplCloseLastPopup( GetParent() ) )
4351  return bRet;
4352  mbIsKeyEvent = true;
4353  if ( maMenuButtonHdl.IsSet() )
4354  maMenuButtonHdl.Call( this );
4355  else
4356  ExecuteCustomMenu( mpData->maMenubuttonItem.maRect );
4357  mpData->mbMenubuttonWasLastSelected = true;
4358  mbIsKeyEvent = false;
4359  }
4360  else if( mnHighItemId && ImplGetItem( mnHighItemId ) &&
4362  {
4365  mnLastFocusItemId = mnCurItemId; // save item id for possible later focus restore
4366  mnMouseModifier = aKeyCode.GetModifier();
4367  mbIsKeyEvent = true;
4368  Activate();
4369 
4370  mpData->mbDropDownByKeyboard = true;
4371  mpData->maDropdownClickHdl.Call( this );
4372 
4373  mbIsKeyEvent = false;
4374  mnMouseModifier = 0;
4375  }
4376  else
4377  bRet = false;
4378 
4379  return bRet;
4380 }
4381 
4382 void ToolBox::KeyInput( const KeyEvent& rKEvt )
4383 {
4384  vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
4385  sal_uInt16 nCode = aKeyCode.GetCode();
4386 
4387  vcl::Window *pParent = ImplGetParent();
4388  bool bOldSchoolContainer = ((pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL);
4389  bool bParentIsContainer = bOldSchoolContainer || isContainerWindow(pParent);
4390 
4391  bool bForwardKey = false;
4392  bool bGrabFocusToDocument = false;
4393 
4394  // #107776# we might be destroyed in the keyhandler
4395  VclPtr<vcl::Window> xWindow = this;
4396 
4397  switch ( nCode )
4398  {
4399  case KEY_UP:
4400  {
4401  // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
4402  if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4403  break;
4404  if( !IsHorizontal() )
4405  ImplChangeHighlightUpDn( true );
4406  else
4407  ImplOpenItem( aKeyCode );
4408  }
4409  break;
4410  case KEY_LEFT:
4411  {
4412  if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4413  break;
4414  if( IsHorizontal() )
4415  ImplChangeHighlightUpDn( true );
4416  else
4417  ImplOpenItem( aKeyCode );
4418  }
4419  break;
4420  case KEY_DOWN:
4421  {
4422  if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4423  break;
4424  if( !IsHorizontal() )
4425  ImplChangeHighlightUpDn( false );
4426  else
4427  ImplOpenItem( aKeyCode );
4428  }
4429  break;
4430  case KEY_RIGHT:
4431  {
4432  if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4433  break;
4434  if( IsHorizontal() )
4435  ImplChangeHighlightUpDn( false );
4436  else
4437  ImplOpenItem( aKeyCode );
4438  }
4439  break;
4440  case KEY_PAGEUP:
4441  if ( mnCurLine > 1 )
4442  {
4443  if( mnCurLine > mnVisLines )
4445  else
4446  mnCurLine = 1;
4447  mbFormat = true;
4448  ImplFormat();
4449  InvalidateSpin();
4451  }
4452  break;
4453  case KEY_PAGEDOWN:
4454  if ( mnCurLine+mnVisLines-1 < mnCurLines )
4455  {
4456  if( mnCurLine + 2*mnVisLines-1 < mnCurLines )
4458  else
4460  mbFormat = true;
4461  ImplFormat();
4462  InvalidateSpin();
4464  }
4465  break;
4466  case KEY_END:
4467  {
4468  ImplChangeHighlight( nullptr );
4469  ImplChangeHighlightUpDn( false );
4470  }
4471  break;
4472  case KEY_HOME:
4473  {
4474  ImplChangeHighlight( nullptr );
4475  ImplChangeHighlightUpDn( true );
4476  }
4477  break;
4478  case KEY_ESCAPE:
4479  {
4480  if( !ImplIsFloatingMode() && bParentIsContainer )
4481  DockingWindow::KeyInput( rKEvt );
4482  else
4483  {
4484  // send focus to document pane
4485  vcl::Window *pWin = this;
4486  while( pWin )
4487  {
4488  if( !pWin->GetParent() )
4489  {
4491  break;
4492  }
4493  pWin = pWin->GetParent();
4494  }
4495  }
4496  }
4497  break;
4498  case KEY_RETURN:
4499  {
4500  // #107712#, disabled entries are selectable now
4501  // leave toolbox and move focus to document
4502  if( mnHighItemId )
4503  {
4505  if (!pItem || !pItem->mbEnabled)
4506  {
4507  bGrabFocusToDocument = true;
4508  }
4509  }
4510  if( !bGrabFocusToDocument )
4511  bForwardKey = !ImplActivateItem( aKeyCode );
4512  }
4513  break;
4514  case KEY_SPACE:
4515  {
4516  ImplOpenItem( aKeyCode );
4517  }
4518  break;
4519  default:
4520  {
4521  sal_uInt16 aKeyGroup = aKeyCode.GetGroup();
4522  ImplToolItem *pItem = nullptr;
4523  if( mnHighItemId )
4524  pItem = ImplGetItem( mnHighItemId );
4525  // #i13931# forward alphanum keyinput into embedded control
4526  if( (aKeyGroup == KEYGROUP_NUM || aKeyGroup == KEYGROUP_ALPHA ) && pItem && pItem->mpWindow && pItem->mbEnabled )
4527  {
4528  vcl::Window *pFocusWindow = Application::GetFocusWindow();
4529  ImplHideFocus();
4530  mbChangingHighlight = true; // avoid focus change due to loss of focus
4532  mbChangingHighlight = false;
4533  if( pFocusWindow != Application::GetFocusWindow() )
4535  }
4536  else
4537  {
4538  // do nothing to avoid key presses going into the document
4539  // while the toolbox has the focus
4540  // just forward function and special keys and combinations with Alt-key
4541  if( aKeyGroup == KEYGROUP_FKEYS || aKeyGroup == KEYGROUP_MISC || aKeyCode.IsMod2() )
4542  bForwardKey = true;
4543  }
4544  }
4545  }
4546 
4547  if ( xWindow->IsDisposed() )
4548  return;
4549 
4550  // #107251# move focus away if this toolbox was disabled during keyinput
4551  if (HasFocus() && mpData->mbKeyInputDisabled && bParentIsContainer)
4552  {
4553  vcl::Window *pFocusControl = pParent->ImplGetDlgWindow( 0, GetDlgWindowType::First );
4554  if ( pFocusControl && pFocusControl != this )
4555  pFocusControl->ImplControlFocus( GetFocusFlags::Init );
4556  }
4557 
4558  // #107712#, leave toolbox
4559  if( bGrabFocusToDocument )
4560  {
4562  return;
4563  }
4564 
4565  if( bForwardKey )
4566  DockingWindow::KeyInput( rKEvt );
4567 }
4568 
4569 // returns the current toolbox line of the item
4570 ToolBox::ImplToolItems::size_type ToolBox::ImplGetItemLine( ImplToolItem const * pCurrentItem )
4571 {
4572  ImplToolItems::size_type nLine = 1;
4573  for (auto const& item : mpData->m_aItems)
4574  {
4575  if ( item.mbBreak )
4576  ++nLine;
4577  if( &item == pCurrentItem)
4578  break;
4579  }
4580  return nLine;
4581 }
4582 
4583 // returns the first displayable item in the given line
4584 ImplToolItem* ToolBox::ImplGetFirstValidItem( ImplToolItems::size_type nLine )
4585 {
4586  if( !nLine || nLine > mnCurLines )
4587  return nullptr;
4588 
4589  nLine--;
4590 
4591  ImplToolItems::iterator it = mpData->m_aItems.begin();
4592  while( it != mpData->m_aItems.end() )
4593  {
4594  // find correct line
4595  if ( it->mbBreak )
4596  nLine--;
4597  if( !nLine )
4598  {
4599  // find first useful item
4600  while( it != mpData->m_aItems.end() && ((it->meType != ToolBoxItemType::BUTTON) || !it->mbVisible || ImplIsFixedControl( &(*it) )) )
4602  {
4603  ++it;
4604  if( it == mpData->m_aItems.end() || it->mbBreak )
4605  return nullptr; // no valid items in this line
4606  }
4607  return &(*it);
4608  }
4609  ++it;
4610  }
4611 
4612  return (it == mpData->m_aItems.end()) ? nullptr : &(*it);
4613 }
4614 
4615 ToolBox::ImplToolItems::size_type ToolBox::ImplFindItemPos( const ImplToolItem* pItem, const ImplToolItems& rList )
4616 {
4617  if( pItem )
4618  {
4619  for( ImplToolItems::size_type nPos = 0; nPos < rList.size(); ++nPos )
4620  if( &rList[ nPos ] == pItem )
4621  return nPos;
4622  }
4623  return ITEM_NOTFOUND;
4624 }
4625 
4626 void ToolBox::ChangeHighlight( ImplToolItems::size_type nPos )
4627 {
4628  if ( nPos < GetItemCount() ) {
4630  ImplChangeHighlight ( ImplGetItem ( GetItemId ( nPos ) ) );
4631  }
4632 }
4633 
4634 void ToolBox::ImplChangeHighlight( ImplToolItem const * pItem, bool bNoGrabFocus )
4635 {
4636  // avoid recursion due to focus change
4637  if( mbChangingHighlight )
4638  return;
4639 
4640  mbChangingHighlight = true;
4641 
4642  ImplToolItem* pOldItem = nullptr;
4643 
4644  if ( mnHighItemId )
4645  {
4646  ImplHideFocus();
4647  ImplToolItems::size_type nPos = GetItemPos( mnHighItemId );
4648  pOldItem = ImplGetItem( mnHighItemId );
4649  // #i89962# ImplDrawItem can cause Invalidate/Update
4650  // which will in turn ImplShowFocus again
4651  // set mnHighItemId to 0 already to prevent this hen/egg problem
4652  mnHighItemId = 0;
4653  InvalidateItem(nPos);
4654  CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nPos ) );
4655  }
4656 
4657  if( !bNoGrabFocus && pItem != pOldItem && pOldItem && pOldItem->mpWindow )
4658  {
4659  // move focus into toolbox
4660  GrabFocus();
4661  }
4662 
4663  if( pItem )
4664  {
4665  ImplToolItems::size_type aPos = ToolBox::ImplFindItemPos( pItem, mpData->m_aItems );
4666  if( aPos != ITEM_NOTFOUND)
4667  {
4668  // check for line breaks
4669  ImplToolItems::size_type nLine = ImplGetItemLine( pItem );
4670 
4671  if( nLine >= mnCurLine + mnVisLines )
4672  {
4673  mnCurLine = nLine - mnVisLines + 1;
4674  mbFormat = true;
4675  }
4676  else if ( nLine < mnCurLine )
4677  {
4678  mnCurLine = nLine;
4679  mbFormat = true;
4680  }
4681 
4682  if( mbFormat )
4683  {
4684  ImplFormat();
4685  }
4686 
4687  mnHighItemId = pItem->mnId;
4688  InvalidateItem(aPos);
4689 
4690  if( mbSelection )
4691  mnCurPos = aPos;
4692  ImplShowFocus();
4693 
4694  if( pItem->mpWindow )
4695  pItem->mpWindow->GrabFocus();
4696  if( pItem != pOldItem )
4698  }
4699  }
4700  else
4701  {
4702  ImplHideFocus();
4703  mnHighItemId = 0;
4705  }
4706 
4707  mbChangingHighlight = false;
4708 }
4709 
4710 // check for keyboard accessible items
4711 static bool ImplIsValidItem( const ImplToolItem* pItem, bool bNotClipped )
4712 {
4713  bool bValid = (pItem && pItem->meType == ToolBoxItemType::BUTTON && pItem->mbVisible && !ImplIsFixedControl( pItem )
4714  && pItem->mbEnabled);
4715  if( bValid && bNotClipped && pItem->IsClipped() )
4716  bValid = false;
4717  return bValid;
4718 }
4719 
4721 {
4722  return ImplChangeHighlightUpDn(bUp, /*bNoCycle*/ false);
4723 }
4724 
4725 bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
4726 {
4727  ImplToolItem* pToolItem = ImplGetItem( mnHighItemId );
4728 
4729  if( !pToolItem || !mnHighItemId )
4730  {
4731  // menubutton highlighted ?
4732  if( mpData->mbMenubuttonSelected )
4733  {
4734  mpData->mbMenubuttonSelected = false;
4735  if( bUp )
4736  {
4737  // select last valid non-clipped item
4738  ImplToolItem* pItem = nullptr;
4739  auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(),
4740  [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); });
4741  if( it != mpData->m_aItems.rend() )
4742  pItem = &(*it);
4743 
4745  ImplChangeHighlight( pItem );
4746  }
4747  else
4748  {
4749  // select first valid non-clipped item
4750  ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
4751  [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); });
4752  if( it != mpData->m_aItems.end() )
4753  {
4755  ImplChangeHighlight( &(*it) );
4756  }
4757  }
4758  return true;
4759  }
4760 
4761  if( bUp )
4762  {
4763  // Select first valid item
4764  ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
4765  [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); });
4766 
4767  // select the menu button if a clipped item would be selected
4768  if( (it != mpData->m_aItems.end() && &(*it) == ImplGetFirstClippedItem()) && IsMenuEnabled() )
4769  {
4770  ImplChangeHighlight( nullptr );
4771  mpData->mbMenubuttonSelected = true;
4773  }
4774  else
4775  ImplChangeHighlight( (it != mpData->m_aItems.end()) ? &(*it) : nullptr );
4776  return true;
4777  }
4778  else
4779  {
4780  // Select last valid item
4781 
4782  // docked toolbars have the menubutton as last item - if this button is enabled
4784  {
4785  ImplChangeHighlight( nullptr );
4786  mpData->mbMenubuttonSelected = true;
4788  }
4789  else
4790  {
4791  ImplToolItem* pItem = nullptr;
4792  auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(),
4793  [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); });
4794  if( it != mpData->m_aItems.rend() )
4795  pItem = &(*it);
4796 
4797  ImplChangeHighlight( pItem );
4798  }
4799  return true;
4800  }
4801  }
4802 
4803  assert(pToolItem);
4804 
4805  ImplToolItems::size_type pos = ToolBox::ImplFindItemPos( pToolItem, mpData->m_aItems );
4806  ImplToolItems::size_type nCount = mpData->m_aItems.size();
4807 
4808  ImplToolItems::size_type i=0;
4809  do
4810  {
4811  if( bUp )
4812  {
4813  if( !pos-- )
4814  {
4815  if( bNoCycle )
4816  return false;
4817 
4818  // highlight the menu button if it is the last item
4820  {
4821  ImplChangeHighlight( nullptr );
4822  mpData->mbMenubuttonSelected = true;
4824  return true;
4825  }
4826  else
4827  pos = nCount-1;
4828  }
4829  }
4830  else
4831  {
4832  if( ++pos >= nCount )
4833  {
4834  if( bNoCycle )
4835  return false;
4836 
4837  // highlight the menu button if it is the last item
4839  {
4840  ImplChangeHighlight( nullptr );
4841  mpData->mbMenubuttonSelected = true;
4843  return true;
4844  }
4845  else
4846  pos = 0;
4847  }
4848  }
4849 
4850  pToolItem = &mpData->m_aItems[pos];
4851 
4852  if ( ImplIsValidItem( pToolItem, false ) )
4853  break;
4854 
4855  } while( ++i < nCount);
4856 
4857  if( pToolItem->IsClipped() && IsMenuEnabled() )
4858  {
4859  // select the menu button if a clipped item would be selected
4860  ImplChangeHighlight( nullptr );
4861  mpData->mbMenubuttonSelected = true;
4863  }
4864  else if( i != nCount )
4865  ImplChangeHighlight( pToolItem );
4866  else
4867  return false;
4868 
4869  return true;
4870 }
4871 
4873 {
4874  if( mnHighItemId && HasFocus() )
4875  {
4877  if (pItem && pItem->mpWindow && !pItem->mpWindow->IsDisposed())
4878  {
4881  pWin->Invalidate();
4882  }
4883  }
4884 }
4885 
4887 {
4888  if( mnHighItemId )
4889  {
4890  mpData->mbMenubuttonWasLastSelected = false;
4892  if( pItem && pItem->mpWindow )
4893  {
4896  pWin->Invalidate();
4897  }
4898  }
4899 
4900  if ( mpData && mpData->mbMenubuttonSelected )
4901  {
4902  mpData->mbMenubuttonWasLastSelected = true;
4903  // remove highlight from menubutton
4904  mpData->mbMenubuttonSelected = false;
4906  }
4907 }
4908 
4910 {
4911 #ifdef _WIN32 // Check in the Windows registry if an AT tool wants no flat toolboxes
4912  static bool bInit = false, bValue = false;
4913  if( ! bInit )
4914  {
4915  bInit = true;
4916  HKEY hkey;
4917 
4918  if( ERROR_SUCCESS == RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\LibreOffice\\Accessibility\\AtToolSupport", &hkey) )
4919  {
4920  DWORD dwType = 0;
4921  wchar_t Data[6]; // possible values: "true", "false", "1", "0", DWORD
4922  DWORD cbData = sizeof(Data);
4923 
4924  if( ERROR_SUCCESS == RegQueryValueExW(hkey, L"DisableFlatToolboxButtons",
4925  nullptr, &dwType, reinterpret_cast<LPBYTE>(Data), &cbData) )
4926  {
4927  switch (dwType)
4928  {
4929  case REG_SZ:
4930  bValue = ((0 == wcsicmp(Data, L"1")) || (0 == wcsicmp(Data, L"true")));
4931  break;
4932  case REG_DWORD:
4933  bValue = static_cast<bool>(reinterpret_cast<DWORD *>(Data)[0]);
4934  break;
4935  }
4936  }
4937  RegCloseKey(hkey);
4938  }
4939  }
4940  if( bValue )
4942 #else
4943  (void) this; // loplugin:staticmethods
4944 #endif
4945 }
4946 
4948 {
4949  if ( meLayoutMode != eLayout )
4950  meLayoutMode = eLayout;
4951 }
4952 
4954 {
4955  meTextPosition = ePosition;
4956 }
4957 
4958 /* 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:183
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:86
static void ImplDrawMoreIndicator(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: toolbox.cxx:2363
double mnHeight
void SetPos(const Point &rPoint)
const Color & GetShadowColor() const
bool IsControlBackground() const
Definition: window2.cxx:1076
SAL_DLLPRIVATE bool ImplChangeHighlightUpDn(bool bUp, bool bNoCycle=false)
Definition: toolbox.cxx:4725
const Color & GetToolTextColor() const
void Dragging(const Point &rPos)
Definition: toolbox.cxx:1054
IMPL_LINK_NOARG(ToolBox, ImplDropdownLongClickHdl, Timer *, void)
Definition: toolbox.cxx:2331
virtual void StartDocking() override
Definition: toolbox.cxx:3999
long mnRightBorder
Definition: toolbox.hxx:109
GetFocusFlags GetGetFocusFlags() const
Definition: window2.cxx:1177
long GetWidth() const
void CaptureMouse()
Definition: mouse.cxx:439
Point GetPointerPosPixel()
Definition: mouse.cxx:549
#define DOCK_LINELEFT
Definition: toolbox.cxx:82
#define SMALLBUTTON_OFF_NORMAL_Y
Definition: toolbox.cxx:58
#define SMALLBUTTON_OFF_NORMAL_X
Definition: toolbox.cxx:57
ToolBoxLayoutMode
Definition: toolbox.hxx:61
PointerStyle meLastStyle
Definition: toolbox.hxx:148
long GetHeight() const
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
ImplToolItems::size_type mnDockLines
Definition: toolbox.hxx:125
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:157
SAL_DLLPRIVATE bool ImplCalcItem()
Definition: toolbox.cxx:1353
SAL_DLLPRIVATE bool ImplHasClippedItems()
Definition: toolbox2.cxx:1541
#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:2478
void SetMenuType(ToolBoxMenuType aType=ToolBoxMenuType::Customize)
Definition: toolbox2.cxx:1496
long AdjustWidth(long n)
SAL_DLLPRIVATE Size ImplGetOptimalFloatingSize()
Definition: toolbox.cxx:1800
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:413
#define KEY_TAB
Definition: keycodes.hxx:121
SAL_DLLPRIVATE bool ImplActivateItem(vcl::KeyCode aKeyCode)
Definition: toolbox.cxx:4261
#define KEY_PAGEDOWN
Definition: keycodes.hxx:117
SAL_DLLPRIVATE void ImplUpdateItem(ImplToolItems::size_type nIndex=ITEM_NOTFOUND)
Definition: toolbox2.cxx:296
StartTrackingFlags
Definition: window.hxx:285
SAL_DLLPRIVATE bool ImplHandleMouseButtonUp(const MouseEvent &rMEvt, bool bCancel=false)
Definition: toolbox.cxx:2945
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:1317
SAL_DLLPRIVATE void ImplDrawTransparentBackground(const vcl::Region &rRegion)
Definition: toolbox.cxx:437
Point BottomLeft() const
const OUString & GetItemText(sal_uInt16 nItemId) const
Definition: toolbox2.cxx:1067
void DoubleClick()
Definition: toolbox2.cxx:325
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:2050
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:634
bool IsMirrored(const OUString &rsCommandName, const OUString &rsModuleName)
SAL_DLLPRIVATE void ImplFloatControl(bool bStart, FloatingWindow *pWindow)
Definition: toolbox.cxx:2832
Resize runs before repaint, so we won't paint twice.
virtual void StateChanged(StateChangedType nType) override
Definition: toolbox.cxx:3862
Point AbsoluteScreenToOutputPixel(const Point &rPos) const
Definition: window.cxx:2878
bool IsMenuEnabled() const
Definition: toolbox2.cxx:1526
sal_uIntPtr sal_uLong
#define SAL_INFO_IF(condition, area, stream)
void ExecuteCustomMenu(const tools::Rectangle &rRect=tools::Rectangle())
Definition: toolbox2.cxx:1620
MouseEventModifiers GetMode() const
Definition: event.hxx:118
SAL_DLLPRIVATE void ImplInitToolBoxData()
Definition: toolbox.cxx:1092
void disposeAndClear()
Definition: vclptr.hxx:200
ImplToolItems::size_type mnCurLines
Definition: toolbox.hxx:122
bool mbIsDeferredInit
Definition: dockwin.hxx:243
const StyleSettings & GetStyleSettings() const
SAL_DLLPRIVATE sal_uInt16 ImplTestLineSize(const Point &rPos) const
Definition: toolbox.cxx:899
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:704
ToolBoxLayoutMode meLayoutMode
Definition: toolbox.hxx:150
void statusChanged(const css::frame::FeatureStateEvent &rEvent)
Definition: toolbox.cxx:3916
const Color & GetFaceColor() const
bool mbLower
Definition: toolbox.hxx:127
BitmapEx const & GetPersonaHeader() const
const OUString & GetHelpText() const
Definition: window.cxx:3095