LibreOffice Module vcl (master)  1
toolbox.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <vcl/toolbox.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/decoview.hxx>
24 #include <vcl/accel.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/help.hxx>
27 #include <vcl/mnemonic.hxx>
28 #include <vcl/gradient.hxx>
29 #include <vcl/layout.hxx>
30 #include <vcl/menu.hxx>
31 #include <vcl/settings.hxx>
32 #include <vclstatuslistener.hxx>
33 #include <vcl/ptrstyle.hxx>
34 #include <bitmaps.hlst>
35 
36 #include <tools/poly.hxx>
37 #include <svl/imageitm.hxx>
38 #include <sal/log.hxx>
39 #include <osl/diagnose.h>
40 
41 #include <svdata.hxx>
42 #include <window.h>
43 #include <toolbox.h>
44 #include <spin.hxx>
45 #if defined(_WIN32)
46 #include <svsys.h>
47 #endif
48 
49 #include <cstdlib>
50 #include <vector>
51 #include <math.h>
52 
53 
54 #define SMALLBUTTON_HSIZE 7
55 #define SMALLBUTTON_VSIZE 7
56 
57 #define SMALLBUTTON_OFF_NORMAL_X 3
58 #define SMALLBUTTON_OFF_NORMAL_Y 3
59 
60 #define TB_TEXTOFFSET 2
61 #define TB_IMAGETEXTOFFSET 3
62 #define TB_LINESPACING 3
63 #define TB_SPIN_SIZE 14
64 #define TB_SPIN_OFFSET 2
65 #define TB_BORDER_OFFSET1 4
66 #define TB_BORDER_OFFSET2 2
67 #define TB_MAXLINES 5
68 #define TB_MAXNOSCROLL 32765
69 
70 #define TB_DRAGWIDTH 8 // the default width of the drag grip
71 
72 #define TB_CALCMODE_HORZ 1
73 #define TB_CALCMODE_VERT 2
74 #define TB_CALCMODE_FLOAT 3
75 
76 #define TB_WBLINESIZING (WB_SIZEABLE | WB_DOCKABLE | WB_SCROLL)
77 
78 #define DOCK_LINEHSIZE (sal_uInt16(0x0001))
79 #define DOCK_LINEVSIZE (sal_uInt16(0x0002))
80 #define DOCK_LINERIGHT (sal_uInt16(0x1000))
81 #define DOCK_LINEBOTTOM (sal_uInt16(0x2000))
82 #define DOCK_LINELEFT (sal_uInt16(0x4000))
83 #define DOCK_LINETOP (sal_uInt16(0x8000))
84 #define DOCK_LINEOFFSET 3
85 
87 {
88 private:
93  Accelerator maAccel;
94  sal_uInt16 mnLineMode;
95  ToolBox::ImplToolItems::size_type mnStartLines;
96 
97  ImplTBDragMgr(const ImplTBDragMgr&) = delete;
98  ImplTBDragMgr& operator=(const ImplTBDragMgr&) = delete;
99 
100 public:
101  ImplTBDragMgr();
102 
103  void StartDragging( ToolBox* pDragBox, const Point& rPos, const tools::Rectangle& rRect, sal_uInt16 nLineMode );
104  void Dragging( const Point& rPos );
105  void EndDragging( bool bOK = true );
106  DECL_LINK( SelectHdl, Accelerator&, void );
107 };
108 
109 
111 {
112  ImplSVData* pSVData = ImplGetSVData();
113  if ( !pSVData->maCtrlData.mpTBDragMgr )
114  pSVData->maCtrlData.mpTBDragMgr = new ImplTBDragMgr;
115  return pSVData->maCtrlData.mpTBDragMgr;
116 }
117 
118 int ToolBox::ImplGetDragWidth( const vcl::RenderContext& rRenderContext, bool bHorz )
119 {
120  int nWidth = TB_DRAGWIDTH;
122  {
123 
124  ImplControlValue aControlValue;
125  tools::Rectangle aContent, aBound;
126  tools::Rectangle aArea( Point(), rRenderContext.GetOutputSizePixel() );
127 
128  if ( rRenderContext.GetNativeControlRegion(ControlType::Toolbar,
130  aArea, ControlState::NONE, aControlValue, aBound, aContent) )
131  {
132  nWidth = bHorz ? aContent.GetWidth() : aContent.GetHeight();
133  }
134  }
135 
136  // increase the hit area of the drag handle according to DPI scale factor
137  nWidth *= rRenderContext.GetDPIScaleFactor();
138 
139  return nWidth;
140 }
141 
143 {
144  return ToolBox::ImplGetDragWidth( *this, mbHorz );
145 }
146 
147 static ButtonType determineButtonType( ImplToolItem const * pItem, ButtonType defaultType )
148 {
149  ButtonType tmpButtonType = defaultType;
151  if ( nBits != ToolBoxItemBits::NONE ) // item has custom setting
152  {
153  tmpButtonType = ButtonType::SYMBOLTEXT;
154  if ( nBits == ToolBoxItemBits::TEXT_ONLY )
155  tmpButtonType = ButtonType::TEXT;
156  else if ( nBits == ToolBoxItemBits::ICON_ONLY )
157  tmpButtonType = ButtonType::SYMBOLONLY;
158  }
159  return tmpButtonType;
160 }
161 
163 {
164  ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
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 
189  ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
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 {
293  ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper(this);
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 
471  ImplDockingWindowWrapper* pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper(this);
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 
552  ImplDockingWindowWrapper* pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper(this);
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->mbNonInteractiveWindow ||
613  pItem->mpWindow->GetType() == WindowType::FIXEDTEXT ||
614  pItem->mpWindow->GetType() == WindowType::FIXEDLINE ||
615  pItem->mpWindow->GetType() == WindowType::GROUPBOX) );
616 }
617 
619 {
620  for (auto & item : mpData->m_aItems)
621  {
622  if( item.IsClipped() )
623  return &item;
624  }
625  return nullptr;
626 }
627 
628 Size ToolBox::ImplCalcSize( ImplToolItems::size_type nCalcLines, sal_uInt16 nCalcMode )
629 {
630  long nMax;
631  long nLeft = 0;
632  long nTop = 0;
633  long nRight = 0;
634  long nBottom = 0;
635  Size aSize;
636  WindowAlign eOldAlign = meAlign;
637  bool bOldHorz = mbHorz;
638  bool bOldAssumeDocked = mpData->mbAssumeDocked;
639  bool bOldAssumeFloating = mpData->mbAssumeFloating;
640 
641  if ( nCalcMode )
642  {
643  bool bOldFloatingMode = ImplIsFloatingMode();
644 
645  mpData->mbAssumeDocked = false;
646  mpData->mbAssumeFloating = false;
647 
648  if ( nCalcMode == TB_CALCMODE_HORZ )
649  {
650  mpData->mbAssumeDocked = true; // force non-floating mode during calculation
651  ImplCalcBorder( WindowAlign::Top, nLeft, nTop, nRight, nBottom );
652  mbHorz = true;
653  if ( mbHorz != bOldHorz )
654  meAlign = WindowAlign::Top;
655  }
656  else if ( nCalcMode == TB_CALCMODE_VERT )
657  {
658  mpData->mbAssumeDocked = true; // force non-floating mode during calculation
659  ImplCalcBorder( WindowAlign::Left, nLeft, nTop, nRight, nBottom );
660  mbHorz = false;
661  if ( mbHorz != bOldHorz )
662  meAlign = WindowAlign::Left;
663  }
664  else if ( nCalcMode == TB_CALCMODE_FLOAT )
665  {
666  mpData->mbAssumeFloating = true; // force non-floating mode during calculation
667  nLeft = nTop = nRight = nBottom = 0;
668  mbHorz = true;
669  if ( mbHorz != bOldHorz )
670  meAlign = WindowAlign::Top;
671  }
672 
673  if ( (meAlign != eOldAlign) || (mbHorz != bOldHorz) ||
674  (ImplIsFloatingMode() != bOldFloatingMode ) )
675  mbCalc = true;
676  }
677  else
678  ImplCalcBorder( meAlign, nLeft, nTop, nRight, nBottom );
679 
680  ImplCalcItem();
681 
682  if( !nCalcMode && ImplIsFloatingMode() )
683  {
684  aSize = ImplCalcFloatSize( nCalcLines );
685  }
686  else
687  {
688  if ( mbHorz )
689  {
691  aSize.setHeight( nCalcLines * mnWinHeight );
692  else
693  aSize.setHeight( nCalcLines * mnMaxItemHeight );
694 
695  if ( mbLineSpacing )
696  aSize.AdjustHeight((nCalcLines-1)*TB_LINESPACING );
697 
698  if ( mnWinStyle & WB_BORDER )
699  aSize.AdjustHeight((TB_BORDER_OFFSET2*2) + nTop + nBottom );
700 
701  nMax = 0;
703  if ( nMax )
704  aSize.AdjustWidth(nMax );
705 
706  if ( mnWinStyle & WB_BORDER )
707  aSize.AdjustWidth((TB_BORDER_OFFSET1*2) + nLeft + nRight );
708  }
709  else
710  {
711  aSize.setWidth( nCalcLines * mnMaxItemWidth );
712 
713  if ( mbLineSpacing )
714  aSize.AdjustWidth((nCalcLines-1)*TB_LINESPACING );
715 
716  if ( mnWinStyle & WB_BORDER )
717  aSize.AdjustWidth((TB_BORDER_OFFSET2*2) + nLeft + nRight );
718 
719  nMax = 0;
721  if ( nMax )
722  aSize.AdjustHeight(nMax );
723 
724  if ( mnWinStyle & WB_BORDER )
725  aSize.AdjustHeight((TB_BORDER_OFFSET1*2) + nTop + nBottom );
726  }
727  }
728  // restore previous values
729  if ( nCalcMode )
730  {
731  mpData->mbAssumeDocked = bOldAssumeDocked;
732  mpData->mbAssumeFloating = bOldAssumeFloating;
733  if ( (meAlign != eOldAlign) || (mbHorz != bOldHorz) )
734  {
735  meAlign = eOldAlign;
736  mbHorz = bOldHorz;
737  mbCalc = true;
738  }
739  }
740 
741  return aSize;
742 }
743 
745 {
746  if ( !maFloatSizes.empty() )
747  return;
748 
749  // calculate the minimal size, i.e. where the biggest item just fits
750  long nCalcSize = 0;
751 
752  for (auto const& item : mpData->m_aItems)
753  {
754  if ( item.mbVisible )
755  {
756  if ( item.mpWindow )
757  {
758  long nTempSize = item.mpWindow->GetSizePixel().Width();
759  if ( nTempSize > nCalcSize )
760  nCalcSize = nTempSize;
761  }
762  else
763  {
764  if( item.maItemSize.Width() > nCalcSize )
765  nCalcSize = item.maItemSize.Width();
766  }
767  }
768  }
769 
770  // calc an upper bound for ImplCalcBreaks below
771  long upperBoundWidth = nCalcSize * mpData->m_aItems.size();
772 
773  ImplToolItems::size_type nLines;
774  ImplToolItems::size_type nCalcLines;
775  ImplToolItems::size_type nTempLines;
776  long nMaxLineWidth;
777  nCalcLines = ImplCalcBreaks( nCalcSize, &nMaxLineWidth, true );
778 
779  maFloatSizes.reserve( nCalcLines );
780 
781  nTempLines = nLines = nCalcLines;
782  while ( nLines )
783  {
784  long nHeight = ImplCalcSize( nTempLines, TB_CALCMODE_FLOAT ).Height();
785 
786  ImplToolSize aSize;
787  aSize.mnWidth = nMaxLineWidth+(TB_BORDER_OFFSET1*2);
788  aSize.mnHeight = nHeight;
789  aSize.mnLines = nTempLines;
790  maFloatSizes.push_back( aSize );
791  nLines--;
792  if ( nLines )
793  {
794  do
795  {
796  nCalcSize += mnMaxItemWidth;
797  nTempLines = ImplCalcBreaks( nCalcSize, &nMaxLineWidth, true );
798  }
799  while ((nCalcSize < upperBoundWidth) && (nLines < nTempLines)); // implies nTempLines>1
800  if ( nTempLines < nLines )
801  nLines = nTempLines;
802  }
803  }
804 }
805 
806 Size ToolBox::ImplCalcFloatSize( ImplToolItems::size_type& rLines )
807 {
809 
810  if ( !rLines )
811  {
812  rLines = mnFloatLines;
813  if ( !rLines )
814  rLines = mnLines;
815  }
816 
817  sal_uInt16 i = 0;
818  while ( i + 1u < maFloatSizes.size() && rLines < maFloatSizes[i].mnLines )
819  {
820  i++;
821  }
822 
824  rLines = maFloatSizes[i].mnLines;
825 
826  return aSize;
827 }
828 
829 void ToolBox::ImplCalcMinMaxFloatSize( Size& rMinSize, Size& rMaxSize )
830 {
832 
833  sal_uInt16 i = 0;
834  rMinSize = Size( maFloatSizes[i].mnWidth, maFloatSizes[i].mnHeight );
835  rMaxSize = Size( maFloatSizes[i].mnWidth, maFloatSizes[i].mnHeight );
836  while ( ++i < maFloatSizes.size() )
837  {
838  if( maFloatSizes[i].mnWidth < rMinSize.Width() )
839  rMinSize.setWidth( maFloatSizes[i].mnWidth );
840  if( maFloatSizes[i].mnHeight < rMinSize.Height() )
841  rMinSize.setHeight( maFloatSizes[i].mnHeight );
842 
843  if( maFloatSizes[i].mnWidth > rMaxSize.Width() )
844  rMaxSize.setWidth( maFloatSizes[i].mnWidth );
845  if( maFloatSizes[i].mnHeight > rMaxSize.Height() )
846  rMaxSize.setHeight( maFloatSizes[i].mnHeight );
847  }
848 }
849 
851 {
852  ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
853  Size aMinSize, aMaxSize;
854  ImplCalcMinMaxFloatSize( aMinSize, aMaxSize );
855  if( pWrapper )
856  {
857  pWrapper->SetMinOutputSizePixel( aMinSize );
858  pWrapper->SetMaxOutputSizePixel( aMaxSize );
860  }
861  else
862  {
863  // TODO: change SetMinOutputSizePixel to be not inline
864  SetMinOutputSizePixel( aMinSize );
865  SetMaxOutputSizePixel( aMaxSize );
866  }
867 }
868 
869 ToolBox::ImplToolItems::size_type ToolBox::ImplCalcLines( long nToolSize ) const
870 {
871  long nLineHeight;
872 
873  if ( mbHorz )
874  {
876  nLineHeight = mnWinHeight;
877  else
878  nLineHeight = mnMaxItemHeight;
879  }
880  else
881  nLineHeight = mnMaxItemWidth;
882 
883  if ( mnWinStyle & WB_BORDER )
884  nToolSize -= TB_BORDER_OFFSET2*2;
885 
886  if ( mbLineSpacing )
887  {
888  nLineHeight += TB_LINESPACING;
889  nToolSize += TB_LINESPACING;
890  }
891 
892  // #i91917# always report at least one line
893  long nLines = nToolSize/nLineHeight;
894  if( nLines < 1 )
895  nLines = 1;
896 
897  return nLines;
898 }
899 
900 sal_uInt16 ToolBox::ImplTestLineSize( const Point& rPos ) const
901 {
902  if ( !ImplIsFloatingMode() &&
903  (!mbScroll || (mnLines > 1) || (mnCurLines > mnVisLines)) )
904  {
905  WindowAlign eAlign = GetAlign();
906 
907  if ( eAlign == WindowAlign::Left )
908  {
909  if ( rPos.X() > mnDX-DOCK_LINEOFFSET )
911  }
912  else if ( eAlign == WindowAlign::Top )
913  {
914  if ( rPos.Y() > mnDY-DOCK_LINEOFFSET )
916  }
917  else if ( eAlign == WindowAlign::Right )
918  {
919  if ( rPos.X() < DOCK_LINEOFFSET )
920  return DOCK_LINEHSIZE | DOCK_LINELEFT;
921  }
922  else if ( eAlign == WindowAlign::Bottom )
923  {
924  if ( rPos.Y() < DOCK_LINEOFFSET )
925  return DOCK_LINEVSIZE | DOCK_LINETOP;
926  }
927  }
928 
929  return 0;
930 }
931 
932 void ToolBox::ImplLineSizing( const Point& rPos, tools::Rectangle& rRect, sal_uInt16 nLineMode )
933 {
934  bool bHorz;
935  long nOneLineSize;
936  long nCurSize;
937  long nMaxSize;
938  long nSize;
939  Size aSize;
940 
941  if ( nLineMode & DOCK_LINERIGHT )
942  {
943  nCurSize = rPos.X() - rRect.Left();
944  bHorz = false;
945  }
946  else if ( nLineMode & DOCK_LINEBOTTOM )
947  {
948  nCurSize = rPos.Y() - rRect.Top();
949  bHorz = true;
950  }
951  else if ( nLineMode & DOCK_LINELEFT )
952  {
953  nCurSize = rRect.Right() - rPos.X();
954  bHorz = false;
955  }
956  else if ( nLineMode & DOCK_LINETOP )
957  {
958  nCurSize = rRect.Bottom() - rPos.Y();
959  bHorz = true;
960  }
961  else {
962  OSL_FAIL( "ImplLineSizing: Trailing else" );
963  nCurSize = 0;
964  bHorz = false;
965  }
966 
967  Size aWinSize = GetSizePixel();
968  ImplToolItems::size_type nMaxLines = std::max(mnLines, mnCurLines);
969  if ( nMaxLines > TB_MAXLINES )
970  nMaxLines = TB_MAXLINES;
971  if ( bHorz )
972  {
973  nOneLineSize = ImplCalcSize( 1 ).Height();
974  nMaxSize = - 20;
975  if ( nMaxSize < aWinSize.Height() )
976  nMaxSize = aWinSize.Height();
977  }
978  else
979  {
980  nOneLineSize = ImplCalcSize( 1 ).Width();
981  nMaxSize = - 20;
982  if ( nMaxSize < aWinSize.Width() )
983  nMaxSize = aWinSize.Width();
984  }
985 
986  ImplToolItems::size_type i = 1;
987  if ( nCurSize <= nOneLineSize )
988  nSize = nOneLineSize;
989  else
990  {
991  nSize = 0;
992  while ( (nSize < nCurSize) && (i < nMaxLines) )
993  {
994  i++;
995  aSize = ImplCalcSize( i );
996  if ( bHorz )
997  nSize = aSize.Height();
998  else
999  nSize = aSize.Width();
1000  if ( nSize > nMaxSize )
1001  {
1002  i--;
1003  aSize = ImplCalcSize( i );
1004  if ( bHorz )
1005  nSize = aSize.Height();
1006  else
1007  nSize = aSize.Width();
1008  break;
1009  }
1010  }
1011  }
1012 
1013  if ( nLineMode & DOCK_LINERIGHT )
1014  rRect.SetRight( rRect.Left()+nSize-1 );
1015  else if ( nLineMode & DOCK_LINEBOTTOM )
1016  rRect.SetBottom( rRect.Top()+nSize-1 );
1017  else if ( nLineMode & DOCK_LINELEFT )
1018  rRect.SetLeft( rRect.Right()-nSize );
1019  else
1020  rRect.SetTop( rRect.Bottom()-nSize );
1021 
1022  mnDockLines = i;
1023 }
1024 
1026  : mpDragBox(nullptr)
1027  , mnLineMode(0)
1028  , mnStartLines(0)
1029 {
1030  maAccel.InsertItem( KEY_RETURN, vcl::KeyCode( KEY_RETURN ) );
1031  maAccel.InsertItem( KEY_ESCAPE, vcl::KeyCode( KEY_ESCAPE ) );
1032  maAccel.SetSelectHdl( LINK( this, ImplTBDragMgr, SelectHdl ) );
1033 }
1034 
1036  const Point& rPos, const tools::Rectangle& rRect,
1037  sal_uInt16 nDragLineMode )
1038 {
1039  mpDragBox = pToolBox;
1040  pToolBox->CaptureMouse();
1041  pToolBox->mbDragging = true;
1043 
1044  mnLineMode = nDragLineMode;
1045  mnStartLines = pToolBox->mnDockLines;
1046 
1047  // calculate MouseOffset
1048  maMouseOff.setX( rRect.Left() - rPos.X() );
1049  maMouseOff.setY( rRect.Top() - rPos.Y() );
1050  maRect = rRect;
1051  maStartRect = rRect;
1052  pToolBox->ShowTracking( maRect );
1053 }
1054 
1055 void ImplTBDragMgr::Dragging( const Point& rPos )
1056 {
1059  maRect.Move( aOff.X(), aOff.Y() );
1060  mpDragBox->Docking( rPos, maRect );
1061  maRect.Move( -aOff.X(), -aOff.Y() );
1063 }
1064 
1066 {
1068  if (mpDragBox->IsMouseCaptured())
1070  mpDragBox->mbDragging = false;
1072 
1073  if ( !bOK )
1074  {
1076  mpDragBox->EndDocking( maStartRect, false );
1077  }
1078  else
1079  mpDragBox->EndDocking( maRect, false );
1080  mnStartLines = 0;
1081 
1082  mpDragBox = nullptr;
1083 }
1084 
1085 IMPL_LINK( ImplTBDragMgr, SelectHdl, Accelerator&, rAccel, void )
1086 {
1087  if ( rAccel.GetCurItemId() == KEY_ESCAPE )
1088  EndDragging( false );
1089  else
1090  EndDragging();
1091 }
1092 
1094 {
1095  // initialize variables
1096  ImplGetWindowImpl()->mbToolBox = true;
1097  mpData.reset(new ImplToolBoxPrivateData);
1098 
1099  mpFloatWin = nullptr;
1100  mnDX = 0;
1101  mnDY = 0;
1102  mnMaxItemWidth = 0;
1103  mnMaxItemHeight = 0;
1104  mnWinHeight = 0;
1105  mnLeftBorder = 0;
1106  mnTopBorder = 0;
1107  mnRightBorder = 0;
1108  mnBottomBorder = 0;
1109  mnLastResizeDY = 0;
1110  mnOutStyle = TOOLBOX_STYLE_FLAT; // force flat buttons since NWF
1111  mnHighItemId = 0;
1112  mnCurItemId = 0;
1113  mnDownItemId = 0;
1115  mnLines = 1;
1116  mnCurLine = 1;
1117  mnCurLines = 1;
1118  mnVisLines = 1;
1119  mnFloatLines = 0;
1120  mnDockLines = 0;
1121  mnMouseModifier = 0;
1122  mbDrag = 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 
1905  ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
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  aImageSize = pImage->GetSizePixel();
2655 
2656  // determine drawing flags
2657  DrawImageFlags nImageStyle = DrawImageFlags::NONE;
2658 
2659  if ( !pItem->mbEnabled || !IsEnabled() )
2660  nImageStyle |= DrawImageFlags::Disable;
2661 
2662  // #i35563# the dontknow state indicates different states at the same time
2663  // which should not be rendered disabled but normal
2664 
2665  // draw the image
2666  nImageOffX = nOffX;
2667  nImageOffY = nOffY;
2668  if ( ( (pItem->mnBits & (ToolBoxItemBits::LEFT|ToolBoxItemBits::DROPDOWN)) || bText )
2670  {
2671  // left align also to leave space for drop down arrow
2672  // and when drawing text+image
2673  // just center in y, except for vertical (ie rotated text)
2674  if( mbHorz || !bText )
2675  nImageOffY += (nBtnHeight-aImageSize.Height())/2;
2676  }
2677  else
2678  {
2679  nImageOffX += (nBtnWidth-aImageSize.Width())/2;
2681  nImageOffY += (nBtnHeight-aImageSize.Height())/2;
2682  }
2683  if ( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
2684  {
2685  if( bHasOpenPopup )
2686  ImplDrawFloatwinBorder(rRenderContext, pItem);
2687  else
2688  ImplDrawButton(rRenderContext, aButtonRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2689  pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow);
2690 
2691  if( nHighlight != 0 )
2692  {
2693  if( bHighContrastWhite )
2694  nImageStyle |= DrawImageFlags::ColorTransform;
2695  }
2696  }
2697  rRenderContext.DrawImage(Point( nImageOffX, nImageOffY ), *pImage, nImageStyle);
2698  }
2699 
2700  // draw the text
2701  bool bRotate = false;
2702  if ( bText )
2703  {
2704  long nTextOffX = nOffX;
2705  long nTextOffY = nOffY;
2706 
2707  // rotate text when vertically docked
2708  vcl::Font aOldFont = rRenderContext.GetFont();
2709  if( pItem->mbVisibleText && !ImplIsFloatingMode() &&
2710  ((meAlign == WindowAlign::Left) || (meAlign == WindowAlign::Right)) )
2711  {
2712  bRotate = true;
2713 
2714  vcl::Font aRotateFont = aOldFont;
2715  aRotateFont.SetOrientation( 2700 );
2716 
2717  // center horizontally
2718  nTextOffX += aTxtSize.Height();
2719  nTextOffX += (nBtnWidth-aTxtSize.Height())/2;
2720 
2721  // add in image offset
2722  if( bImage )
2723  nTextOffY = nImageOffY + aImageSize.Height() + TB_IMAGETEXTOFFSET;
2724 
2725  rRenderContext.SetFont(aRotateFont);
2726  }
2727  else
2728  {
2730  {
2731  // center vertically
2732  nTextOffY += (nBtnHeight-aTxtSize.Height())/2;
2733 
2734  // add in image offset
2735  if( bImage )
2736  nTextOffX = nImageOffX + aImageSize.Width() + TB_IMAGETEXTOFFSET;
2737  }
2738  else
2739  {
2740  // center horizontally
2741  nTextOffX += (nBtnWidth-aTxtSize.Width() - TB_IMAGETEXTOFFSET)/2;
2742  // set vertical position
2743  nTextOffY += nBtnHeight - aTxtSize.Height();
2744  }
2745  }
2746 
2747  // draw selection only if not already drawn during image output (see above)
2748  if ( !bImage && (nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) ) )
2749  {
2750  if( bHasOpenPopup )
2751  ImplDrawFloatwinBorder(rRenderContext, pItem);
2752  else
2753  ImplDrawButton(rRenderContext, pItem->maRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2754  pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow );
2755  }
2756 
2757  DrawTextFlags nTextStyle = DrawTextFlags::NONE;
2758  if ( !pItem->mbEnabled )
2759  nTextStyle |= DrawTextFlags::Disable;
2760  rRenderContext.DrawCtrlText( Point( nTextOffX, nTextOffY ), pItem->maText,
2761  0, pItem->maText.getLength(), nTextStyle );
2762  if ( bRotate )
2763  SetFont( aOldFont );
2764  }
2765 
2766  // paint optional drop down arrow
2767  if ( pItem->mnBits & ToolBoxItemBits::DROPDOWN )
2768  {
2769  tools::Rectangle aDropDownRect( pItem->GetDropDownRect( mbHorz ) );
2770  bool bSetColor = true;
2771  if ( !pItem->mbEnabled || !IsEnabled() )
2772  {
2773  bSetColor = false;
2774  rRenderContext.SetFillColor(rStyleSettings.GetShadowColor());
2775  }
2776 
2777  // dropdown only will be painted without inner border
2779  {
2780  ImplErase(rRenderContext, aDropDownRect, nHighlight != 0, bHasOpenPopup);
2781 
2782  if( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
2783  {
2784  if( bHasOpenPopup )
2785  ImplDrawFloatwinBorder(rRenderContext, pItem);
2786  else
2787  ImplDrawButton(rRenderContext, aDropDownRect, nHighlight, pItem->meState == TRISTATE_TRUE,
2788  pItem->mbEnabled && IsEnabled(), false);
2789  }
2790  }
2791  ImplDrawDropdownArrow(rRenderContext, aDropDownRect, bSetColor, bRotate);
2792  }
2793 }
2794 
2796 {
2797  if ( pItem->maRect.IsEmpty() )
2798  return;
2799 
2801  aRect.SetPos( AbsoluteScreenToOutputPixel( aRect.TopLeft() ) );
2802  rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetShadowColor());
2803  Point p1, p2;
2804 
2805  p1 = pItem->maRect.TopLeft();
2806  p1.AdjustX( 1 );
2807  p2 = pItem->maRect.TopRight();
2808  p2.AdjustX( -1 );
2809  rRenderContext.DrawLine( p1, p2);
2810  p1 = pItem->maRect.BottomLeft();
2811  p1.AdjustX( 1 );
2812  p2 = pItem->maRect.BottomRight();
2813  p2.AdjustX( -1 );
2814  rRenderContext.DrawLine( p1, p2);
2815 
2816  p1 = pItem->maRect.TopLeft();
2817  p1.AdjustY( 1 );
2818  p2 = pItem->maRect.BottomLeft();
2819  p2.AdjustY( -1 );
2820  rRenderContext.DrawLine( p1, p2);
2821  p1 = pItem->maRect.TopRight();
2822  p1.AdjustY( 1 );
2823  p2 = pItem->maRect.BottomRight();
2824  p2.AdjustY( -1 );
2825  rRenderContext.DrawLine( p1, p2);
2826 
2827 }
2828 
2829 void ToolBox::ImplFloatControl( bool bStart, FloatingWindow* pFloatWindow )
2830 {
2831 
2832  if ( bStart )
2833  {
2834  mpFloatWin = pFloatWindow;
2835 
2836  // redraw item, to trigger drawing of a special border
2838 
2839  mbDrag = false;
2840  EndTracking();
2841  if (IsMouseCaptured())
2842  ReleaseMouse();
2843  }
2844  else
2845  {
2846  mpFloatWin = nullptr;
2847 
2848  // if focus is still in this toolbox, then the floater was opened by keyboard
2849  // draw current item with highlight and keep old state
2850  bool bWasKeyboardActivate = mpData->mbDropDownByKeyboard;
2851 
2852  if ( mnCurPos != ITEM_NOTFOUND )
2854  Deactivate();
2855 
2856  if( !bWasKeyboardActivate )
2857  {
2859  mnCurItemId = 0;
2860  mnHighItemId = 0;
2861  }
2862  mnDownItemId = 0;
2863 
2864  }
2865 }
2866 
2867 void ToolBox::ShowLine( bool bNext )
2868 {
2869  mbFormat = true;
2870 
2871  if ( bNext )
2872  mnCurLine++;
2873  else
2874  mnCurLine--;
2875 
2876  ImplFormat();
2877 }
2878 
2879 bool ToolBox::ImplHandleMouseMove( const MouseEvent& rMEvt, bool bRepeat )
2880 {
2881  Point aMousePos = rMEvt.GetPosPixel();
2882 
2883  if ( !mpData )
2884  return false;
2885 
2886  // ToolBox active?
2887  if ( mbDrag && mnCurPos != ITEM_NOTFOUND )
2888  {
2889  // is the cursor over the item?
2890  ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
2891  if ( pItem->maRect.IsInside( aMousePos ) )
2892  {
2893  if ( !mnCurItemId )
2894  {
2896  mnCurItemId = pItem->mnId;
2897  Highlight();
2898  }
2899 
2900  if ( (pItem->mnBits & ToolBoxItemBits::REPEAT) && bRepeat )
2901  Select();
2902  }
2903  else
2904  {
2905  if ( mnCurItemId )
2906  {
2908  mnCurItemId = 0;
2910  Highlight();
2911  }
2912  }
2913 
2914  return true;
2915  }
2916 
2917  if ( mbUpper )
2918  {
2919  bool bNewIn = maUpperRect.IsInside( aMousePos );
2920  if ( bNewIn != mbIn )
2921  {
2922  mbIn = bNewIn;
2923  InvalidateSpin(true, false);
2924  }
2925  return true;
2926  }
2927 
2928  if ( mbLower )
2929  {
2930  bool bNewIn = maLowerRect.IsInside( aMousePos );
2931  if ( bNewIn != mbIn )
2932  {
2933  mbIn = bNewIn;
2934  InvalidateSpin(false);
2935  }
2936  return true;
2937  }
2938 
2939  return false;
2940 }
2941 
2942 bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent& rMEvt, bool bCancel )
2943 {
2945 
2946  if ( !mpData )
2947  return false;
2948 
2949  // stop eventual running dropdown timer
2950  if( mnCurPos < mpData->m_aItems.size() &&
2951  (mpData->m_aItems[mnCurPos].mnBits & ToolBoxItemBits::DROPDOWN ) )
2952  {
2953  mpData->maDropdownTimer.Stop();
2954  }
2955 
2956  if ( mbDrag )
2957  {
2958  Deactivate();
2959 
2960  if ( mbDrag )
2961  mbDrag = false;
2962  else
2963  {
2964  if ( mnCurPos == ITEM_NOTFOUND )
2965  return true;
2966  }
2967 
2968  // has mouse been released on top of item?
2969  if( mnCurPos < mpData->m_aItems.size() )
2970  {
2971  ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
2972  if ( pItem->maRect.IsInside( rMEvt.GetPosPixel() ) )
2973  {
2974  mnCurItemId = pItem->mnId;
2975  if ( !bCancel )
2976  {
2977  // execute AutoCheck if required
2978  if ( pItem->mnBits & ToolBoxItemBits::AUTOCHECK )
2979  {
2980  if ( pItem->mnBits & ToolBoxItemBits::RADIOCHECK )
2981  {
2982  if ( pItem->meState != TRISTATE_TRUE )
2983  SetItemState( pItem->mnId, TRISTATE_TRUE );
2984  }
2985  else
2986  {
2987  if ( pItem->meState != TRISTATE_TRUE )
2988  pItem->meState = TRISTATE_TRUE;
2989  else
2990  pItem->meState = TRISTATE_FALSE;
2991  }
2992  }
2993 
2994  // do not call Select when Repeat is active, as in this
2995  // case that was triggered already in MouseButtonDown
2996  if ( !(pItem->mnBits & ToolBoxItemBits::REPEAT) )
2997  {
2998  // prevent from being destroyed in the select handler
2999  VclPtr<vcl::Window> xWindow = this;
3000  Select();
3001  if ( xWindow->IsDisposed() )
3002  return true;
3003  }
3004  }
3005 
3006  {
3007  }
3008 
3009  // Items not destroyed, in Select handler
3010  if ( mnCurItemId )
3011  {
3012  // Get current pos for the case that items are inserted/removed
3013  // in the toolBox
3015  if ( mnCurPos != ITEM_NOTFOUND )
3016  {
3018  Flush();
3019  }
3020  }
3021  }
3022  }
3023 
3025  mnCurItemId = 0;
3026  mnDownItemId = 0;
3027  mnMouseModifier = 0;
3028  return true;
3029  }
3030  else if ( mbUpper || mbLower )
3031  {
3032  if ( mbIn )
3033  ShowLine( !mbUpper );
3034  mbUpper = false;
3035  mbLower = false;
3036  mbIn = false;
3037  InvalidateSpin();
3038  return true;
3039  }
3040 
3041  return false;
3042 }
3043 
3044 void ToolBox::MouseMove( const MouseEvent& rMEvt )
3045 {
3046  // pressing a modifier generates synthetic mouse moves
3047  // ignore it if keyboard selection is active
3048  if( HasFocus() && ( rMEvt.GetMode() & MouseEventModifiers::MODIFIERCHANGED ) )
3049  return;
3050 
3051  if ( ImplHandleMouseMove( rMEvt ) )
3052  return;
3053 
3055 
3056  Point aMousePos = rMEvt.GetPosPixel();
3057 
3058  // only highlight when the focus is not inside a child window of a toolbox
3059  // eg, in an edit control
3060  // and do not highlight when focus is in a different toolbox
3061  bool bDrawHotSpot = true;
3063 
3064  bool bFocusWindowIsAToolBoxChild = false;
3065  if (pFocusWin)
3066  {
3067  vcl::Window *pWin = pFocusWin->GetParent();
3068  while (pWin)
3069  {
3070  if(pWin->ImplGetWindowImpl()->mbToolBox)
3071  {
3072  bFocusWindowIsAToolBoxChild = true;
3073  break;
3074  }
3075  pWin = pWin->GetParent();
3076  }
3077  }
3078 
3079  if( bFocusWindowIsAToolBoxChild || (pFocusWin && pFocusWin->ImplGetWindowImpl()->mbToolBox && pFocusWin != this) )
3080  bDrawHotSpot = false;
3081 
3082  if ( mbDragging )
3083  {
3084  ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
3085  pMgr->Dragging( aMousePos );
3086  return;
3087  }
3088 
3090 
3091  // change mouse cursor over drag area
3092  ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
3093  if( pWrapper && pWrapper->GetDragArea().IsInside( rMEvt.GetPosPixel() ) )
3094  eStyle = PointerStyle::Move;
3095 
3097  {
3098  if ( rMEvt.GetMode() & MouseEventModifiers::SIMPLEMOVE )
3099  {
3100  sal_uInt16 nLinePtr = ImplTestLineSize( rMEvt.GetPosPixel() );
3101  if ( nLinePtr & DOCK_LINEHSIZE )
3102  {
3103  if ( meAlign == WindowAlign::Left )
3104  eStyle = PointerStyle::WindowESize;
3105  else
3106  eStyle = PointerStyle::WindowWSize;
3107  }
3108  else if ( nLinePtr & DOCK_LINEVSIZE )
3109  {
3110  if ( meAlign == WindowAlign::Top )
3111  eStyle = PointerStyle::WindowSSize;
3112  else
3113  eStyle = PointerStyle::WindowNSize;
3114  }
3115  }
3116  }
3117 
3118  if ( bDrawHotSpot && ( (mnOutStyle & TOOLBOX_STYLE_FLAT) || !mnOutStyle ) )
3119  {
3120  bool bClearHigh = true;
3121  if ( !rMEvt.IsLeaveWindow() && (mnCurPos == ITEM_NOTFOUND) )
3122  {
3123  ImplToolItems::size_type nTempPos = 0;
3124  for (auto const& item : mpData->m_aItems)
3125  {
3126  if ( item.maRect.IsInside( aMousePos ) )
3127  {
3128  if ( (item.meType == ToolBoxItemType::BUTTON) && item.mbEnabled )
3129  {
3130  if ( !mnOutStyle || (mnOutStyle & TOOLBOX_STYLE_FLAT) )
3131  {
3132  bClearHigh = false;
3133  if ( mnHighItemId != item.mnId )
3134  {
3135  if ( mnHighItemId )
3136  {
3137  ImplHideFocus();
3138  ImplToolItems::size_type nPos = GetItemPos( mnHighItemId );
3139  InvalidateItem(nPos);
3140  CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nPos ) );
3141  }
3142  if ( mpData->mbMenubuttonSelected )
3143  {
3144  // remove highlight from menubutton
3146  }
3147  mnHighItemId = item.mnId;
3148  InvalidateItem(nTempPos);
3149  ImplShowFocus();
3151  }
3152  }
3153  }
3154  break;
3155  }
3156  ++nTempPos;
3157  }
3158  }
3159 
3160  // only clear highlight when focus is not in toolbar
3161  bool bMenuButtonHit = mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems();
3162  if ( !HasFocus() && (bClearHigh || bMenuButtonHit) )
3163  {
3164  if ( !bMenuButtonHit && mpData->mbMenubuttonSelected )
3165  {
3166  // remove highlight from menubutton
3168  }
3169 
3170  if( mnHighItemId )
3171  {
3172  ImplToolItems::size_type nClearPos = GetItemPos( mnHighItemId );
3173  if ( nClearPos != ITEM_NOTFOUND )
3174  {
3175  InvalidateItem(nClearPos);
3176  if( nClearPos != mnCurPos )
3177  CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nClearPos ) );
3178  }
3179  ImplHideFocus();
3180  mnHighItemId = 0;
3181  }
3182 
3183  if( bMenuButtonHit )
3184  {
3186  }
3187  }
3188  }
3189 
3190  if ( meLastStyle != eStyle )
3191  {
3192  meLastStyle = eStyle;
3193  SetPointer( eStyle );
3194  }
3195 
3196  DockingWindow::MouseMove( rMEvt );
3197 }
3198 
3200 {
3201  // only trigger toolbox for left mouse button and when
3202  // we're not in normal operation
3203  if ( rMEvt.IsLeft() && !mbDrag && (mnCurPos == ITEM_NOTFOUND) )
3204  {
3205  // call activate already here, as items could
3206  // be exchanged
3207  Activate();
3208 
3209  // update ToolBox here, such that user knows it
3210  if ( mbFormat )
3211  {
3212  ImplFormat();
3213  Update();
3214  }
3215 
3216  Point aMousePos = rMEvt.GetPosPixel();
3217  ImplToolItems::size_type i = 0;
3218  ImplToolItems::size_type nNewPos = ITEM_NOTFOUND;
3219 
3220  // search for item that was clicked
3221  for (auto const& item : mpData->m_aItems)
3222  {
3223  // is this the item?
3224  if ( item.maRect.IsInside( aMousePos ) )
3225  {
3226  // do nothing if it is a separator or
3227  // if the item has been disabled
3228  if ( (item.meType == ToolBoxItemType::BUTTON) &&
3229  !item.mbShowWindow )
3230  nNewPos = i;
3231 
3232  break;
3233  }
3234 
3235  i++;
3236  }
3237 
3238  // item found
3239  if ( nNewPos != ITEM_NOTFOUND )
3240  {
3241  if ( !mpData->m_aItems[nNewPos].mbEnabled )
3242  {
3243  Deactivate();
3244  return;
3245  }
3246 
3247  // update actual data
3249  mnCurPos = i;
3250  mnCurItemId = mpData->m_aItems[nNewPos].mnId;
3252  mnMouseModifier = rMEvt.GetModifier();
3253  if ( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::REPEAT )
3254  nTrackFlags |= StartTrackingFlags::ButtonRepeat;
3255 
3256  // update bDrag here, as it is evaluated in the EndSelection
3257  mbDrag = true;
3258 
3259  // on double-click: only call the handler, but do so before the button
3260  // is hit, as in the handler dragging
3261  // can be terminated
3262  if ( rMEvt.GetClicks() == 2 )
3263  DoubleClick();
3264 
3265  if ( mbDrag )
3266  {
3267  InvalidateItem(mnCurPos);
3268  Highlight();
3269  }
3270 
3271  // was dropdown arrow pressed
3272  if( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWN )
3273  {
3274  if( ( (mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWNONLY) == ToolBoxItemBits::DROPDOWNONLY)
3275  || mpData->m_aItems[nNewPos].GetDropDownRect( mbHorz ).IsInside( aMousePos ))
3276  {
3277  // dropdownonly always triggers the dropdown handler, over the whole button area
3278 
3279  // the drop down arrow should not trigger the item action
3280  mpData->mbDropDownByKeyboard = false;
3281  mpData->maDropdownClickHdl.Call( this );
3282 
3283  // do not reset data if the dropdown handler opened a floating window
3284  // see ImplFloatControl()
3285  if( !mpFloatWin )
3286  {
3287  // no floater was opened
3288  Deactivate();
3289  InvalidateItem(mnCurPos);
3290 
3291  mnCurPos = ITEM_NOTFOUND;
3292  mnCurItemId = 0;
3293  mnDownItemId = 0;
3294  mnMouseModifier = 0;
3295  mnHighItemId = 0;
3296  }
3297  return;
3298  }
3299  else // activate long click timer
3300  mpData->maDropdownTimer.Start();
3301  }
3302 
3303  // call Click handler
3304  if ( rMEvt.GetClicks() != 2 )
3305  Click();
3306 
3307  // also call Select handler at repeat
3308  if ( nTrackFlags & StartTrackingFlags::ButtonRepeat )
3309  Select();
3310 
3311  // if the actions was not aborted in Click handler
3312  if ( mbDrag )
3313  StartTracking( nTrackFlags );
3314 
3315  // if mouse was clicked over an item we
3316  // can abort here
3317  return;
3318  }
3319 
3320  Deactivate();
3321 
3322  // menu button hit ?
3323  if( mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems() )
3324  {
3325  if ( maMenuButtonHdl.IsSet() )
3326  maMenuButtonHdl.Call( this );
3327  else
3328  ExecuteCustomMenu( mpData->maMenubuttonItem.maRect );
3329  return;
3330  }
3331 
3332  // check scroll- and next-buttons here
3333  if ( maUpperRect.IsInside( aMousePos ) )
3334  {
3335  if ( mnCurLine > 1 )
3336  {
3337  StartTracking();
3338  mbUpper = true;
3339  mbIn = true;
3340  InvalidateSpin(true, false);
3341  }
3342  return;
3343  }
3344  if ( maLowerRect.IsInside( aMousePos ) )
3345  {
3346  if ( mnCurLine+mnVisLines-1 < mnCurLines )
3347  {
3348  StartTracking();
3349  mbLower = true;
3350  mbIn = true;
3351  InvalidateSpin(false);
3352  }
3353  return;
3354  }
3355 
3356  // Linesizing testen
3357  if ( (mnWinStyle & TB_WBLINESIZING) == TB_WBLINESIZING )
3358  {
3359  sal_uInt16 nLineMode = ImplTestLineSize( aMousePos );
3360  if ( nLineMode )
3361  {
3362  ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
3363 
3364  // call handler, such that we can set the
3365  // dock rectangles
3366  StartDocking();
3367 
3369  Size aSize = GetSizePixel();
3370  aPos = ScreenToOutputPixel( aPos );
3371 
3372  // start dragging
3373  pMgr->StartDragging( this, aMousePos, tools::Rectangle( aPos, aSize ),
3374  nLineMode );
3375  return;
3376  }
3377  }
3378 
3379  // no item, then only click or double click
3380  if ( rMEvt.GetClicks() == 2 )
3381  DoubleClick();
3382  else
3383  Click();
3384  }
3385 
3386  if ( !mbDrag && (mnCurPos == ITEM_NOTFOUND) )
3388 }
3389 
3391 {
3392  if ( ImplHandleMouseButtonUp( rMEvt ) )
3393  return;
3394 
3395  if ( mbDragging && rMEvt.IsLeft() )
3396  {
3397  ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
3398  pMgr->EndDragging();
3399  return;
3400  }
3401 
3403 }
3404 
3405 void ToolBox::Tracking( const TrackingEvent& rTEvt )
3406 {
3407  VclPtr<vcl::Window> xWindow = this;
3408 
3409  if ( rTEvt.IsTrackingEnded() )
3411  else
3413 
3414  if ( xWindow->IsDisposed() )
3415  // toolbox was deleted
3416  return;
3417  DockingWindow::Tracking( rTEvt );
3418 }
3419 
3420 void ToolBox::InvalidateItem(ImplToolItems::size_type nPosition)
3421 {
3422  if (mpData && nPosition < mpData->m_aItems.size())
3423  {
3424  ImplToolItem* pItem = &mpData->m_aItems[nPosition];
3425  Invalidate(pItem->maRect);
3426  }
3427 }
3428 
3430 {
3431  if (!mpData->maMenubuttonItem.maRect.IsEmpty())
3432  Invalidate(mpData->maMenubuttonItem.maRect);
3433 }
3434 
3435 void ToolBox::InvalidateSpin(bool bUpperIn, bool bLowerIn)
3436 {
3437  if (bUpperIn && !maUpperRect.IsEmpty())
3439 
3440  if (bLowerIn && !maLowerRect.IsEmpty())
3442 }
3443 
3444 void ToolBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rPaintRect)
3445 {
3446  if( mpData->mbIsPaintLocked )
3447  return;
3448 
3449  if (rPaintRect == tools::Rectangle(0, 0, mnDX-1, mnDY-1))
3450  mbFullPaint = true;
3451  ImplFormat();
3452  mbFullPaint = false;
3453 
3454  ImplDrawBackground(rRenderContext, rPaintRect);
3455 
3456  if ( (mnWinStyle & WB_BORDER) && !ImplIsFloatingMode() )
3457  ImplDrawBorder(rRenderContext);
3458 
3459  if( !ImplIsFloatingMode() )
3460  ImplDrawGrip(rRenderContext);
3461 
3462  ImplDrawMenuButton(rRenderContext, mpData->mbMenubuttonSelected);
3463 
3464  // draw SpinButtons
3465  if (mnWinStyle & WB_SCROLL)
3466  {
3467  if (mnCurLines > mnLines)
3468  ImplDrawSpin(rRenderContext);
3469  }
3470 
3471  // draw buttons
3472  ImplToolItems::size_type nHighPos;
3473  if ( mnHighItemId )
3474  nHighPos = GetItemPos( mnHighItemId );
3475  else
3476  nHighPos = ITEM_NOTFOUND;
3477 
3478  ImplToolItems::size_type nCount = mpData->m_aItems.size();
3479  for( ImplToolItems::size_type i = 0; i < nCount; i++ )
3480  {
3481  ImplToolItem* pItem = &mpData->m_aItems[i];
3482 
3483  // only draw when the rectangle is in the draw rectangle
3484  if ( !pItem->maRect.IsEmpty() && rPaintRect.IsOver( pItem->maRect ) )
3485  {
3486  sal_uInt16 nHighlight = 0;
3487  if ( i == mnCurPos )
3488  nHighlight = 1;
3489  else if ( i == nHighPos )
3490  nHighlight = 2;
3491  ImplDrawItem(rRenderContext, i, nHighlight);
3492  }
3493  }
3494  ImplShowFocus();
3495 }
3496 
3498 {
3499  Size aSize = GetOutputSizePixel();
3500  // #i31422# some WindowManagers send (0,0) sizes when
3501  // switching virtual desktops - ignore this and avoid reformatting
3502  if( !aSize.Width() && !aSize.Height() )
3503  return;
3504 
3505  long nOldDX = mnDX;
3506  long nOldDY = mnDY;
3507  mnDX = aSize.Width();
3508  mnDY = aSize.Height();
3509 
3510  mnLastResizeDY = 0;
3511 
3512  // invalidate everything to have gradient backgrounds properly drawn
3513  Invalidate();
3514 
3515  // If we have any expandable entries, then force a reformat first using
3516  // their optimal sizes, then share out the excess space evenly across those
3517  // expandables and reformat again
3518  std::vector<size_t> aExpandables;
3519  for (size_t i = 0; i < mpData->m_aItems.size(); ++i)
3520  {
3521  if (mpData->m_aItems[i].mbExpand)
3522  {
3523  vcl::Window *pWindow = mpData->m_aItems[i].mpWindow;
3524  SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
3525  if (!pWindow)
3526  continue;
3527  Size aWinSize(pWindow->GetSizePixel());
3528  Size aPrefSize(pWindow->get_preferred_size());
3529  aWinSize.setWidth( aPrefSize.Width() );
3530  pWindow->SetSizePixel(aWinSize);
3531  aExpandables.push_back(i);
3532  }
3533  }
3534 
3535  // re-format or re-draw
3536  if ( mbScroll || !aExpandables.empty() )
3537  {
3538  if ( !mbFormat || !aExpandables.empty() )
3539  {
3540  mbFormat = true;
3541  if( IsReallyVisible() || !aExpandables.empty() )
3542  {
3543  ImplFormat(true);
3544 
3545  if (!aExpandables.empty())
3546  {
3547  //Get how big the optimal size is
3548  tools::Rectangle aBounds;
3549  for (const ImplToolItem & rItem : mpData->m_aItems)
3550  {
3551  aBounds.Union( rItem.maRect );
3552  }
3553 
3554  long nOptimalWidth = aBounds.GetWidth();
3555  long nDiff = aSize.Width() - nOptimalWidth;
3556  nDiff /= aExpandables.size();
3557 
3558  //share out the diff from optimal to real across
3559  //expandable entries
3560  for (size_t nIndex : aExpandables)
3561  {
3562  vcl::Window *pWindow = mpData->m_aItems[nIndex].mpWindow;
3563  Size aWinSize(pWindow->GetSizePixel());
3564  Size aPrefSize(pWindow->get_preferred_size());
3565  aWinSize.setWidth( aPrefSize.Width() + nDiff );
3566  pWindow->SetSizePixel(aWinSize);
3567  }
3568 
3569  //now reformat with final sizes
3570  mbFormat = true;
3571  ImplFormat(true);
3572  }
3573  }
3574  }
3575  }
3576 
3577  // redraw border
3578  if ( mnWinStyle & WB_BORDER )
3579  {
3580  // as otherwise, when painting we might think we have to re-draw everything
3581  if ( mbFormat && IsReallyVisible() )
3582  Invalidate();
3583  else
3584  {
3585  if ( mnRightBorder )
3586  {
3587  if ( nOldDX > mnDX )
3589  else
3590  Invalidate( tools::Rectangle( nOldDX-mnRightBorder-1, 0, nOldDX, nOldDY ) );
3591  }
3592 
3593  if ( mnBottomBorder )
3594  {
3595  if ( nOldDY > mnDY )
3597  else
3598  Invalidate( tools::Rectangle( 0, nOldDY-mnBottomBorder-1, nOldDX, nOldDY ) );
3599  }
3600  }
3601  }
3602 }
3603 
3604 namespace
3605 {
3606  bool DispatchableCommand(const OUString& rName)
3607  {
3608  return rName.startsWith(".uno") ||
3609  rName.startsWith("slot:") ||
3610  rName.startsWith("macro:") ||
3611  rName.startsWith("vnd.sun.star.script");
3612  }
3613 }
3614 
3615 const OUString& ToolBox::ImplGetHelpText( sal_uInt16 nItemId ) const
3616 {
3617  ImplToolItem* pItem = ImplGetItem( nItemId );
3618 
3619  assert( pItem );
3620 
3621  if ( pItem->maHelpText.isEmpty() && ( !pItem->maHelpId.isEmpty() || pItem->maCommandStr.getLength() ))
3622  {
3623  Help* pHelp = Application::GetHelp();
3624  if ( pHelp )
3625  {
3626  if (DispatchableCommand(pItem->maCommandStr))
3627  pItem->maHelpText = pHelp->GetHelpText( pItem->maCommandStr, this );
3628  if ( pItem->maHelpText.isEmpty() && !pItem->maHelpId.isEmpty() )
3629  pItem->maHelpText = pHelp->GetHelpText( OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
3630  }
3631  }
3632 
3633  return pItem->maHelpText;
3634 }
3635 
3636 void ToolBox::RequestHelp( const HelpEvent& rHEvt )
3637 {
3638  sal_uInt16 nItemId;
3639  Point aHelpPos;
3640 
3641  if( !rHEvt.KeyboardActivated() )
3642  {
3643  nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
3644  aHelpPos = rHEvt.GetMousePosPixel();
3645  }
3646  else
3647  {
3648  if( !mnHighItemId )
3649  return;
3650  else
3651  nItemId = mnHighItemId;
3652  tools::Rectangle aRect( GetItemRect( nItemId ) );
3653  if( aRect.IsEmpty() )
3654  return;
3655  else
3656  aHelpPos = OutputToScreenPixel( aRect.Center() );
3657  }
3658 
3659  if ( nItemId )
3660  {
3662  {
3663  // get rectangle
3664  tools::Rectangle aTempRect = GetItemRect( nItemId );
3665  Point aPt = OutputToScreenPixel( aTempRect.TopLeft() );
3666  aTempRect.SetLeft( aPt.X() );
3667  aTempRect.SetTop( aPt.Y() );
3668  aPt = OutputToScreenPixel( aTempRect.BottomRight() );
3669  aTempRect.SetRight( aPt.X() );
3670  aTempRect.SetBottom( aPt.Y() );
3671 
3672  // get text and display it
3673  OUString aStr = GetQuickHelpText( nItemId );
3674  if (aStr.isEmpty())
3676  if ( rHEvt.GetMode() & HelpEventMode::BALLOON )
3677  {
3678  const OUString& rHelpStr = GetHelpText( nItemId );
3679  if (!rHelpStr.isEmpty())
3680  aStr = rHelpStr;
3681  Help::ShowBalloon( this, aHelpPos, aTempRect, aStr );
3682  }
3683  else
3684  Help::ShowQuickHelp( this, aTempRect, aStr, QuickHelpFlags::CtrlText );
3685  return;
3686  }
3687  }
3688 
3689  DockingWindow::RequestHelp( rHEvt );
3690 }
3691 
3693 {
3694  if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
3695  {
3696  KeyEvent aKEvt = *rNEvt.GetKeyEvent();
3697  vcl::KeyCode aKeyCode = aKEvt.GetKeyCode();
3698  sal_uInt16 nKeyCode = aKeyCode.GetCode();
3699  switch( nKeyCode )
3700  {
3701  case KEY_TAB:
3702  {
3703  // internal TAB cycling only if parent is not a dialog or if we are the only child
3704  // otherwise the dialog control will take over
3705  vcl::Window *pParent = ImplGetParent();
3706  bool bOldSchoolContainer =
3708  pParent->GetChildCount() != 1);
3709  bool bNoTabCycling = bOldSchoolContainer || isContainerWindow(pParent);
3710 
3711  if( bNoTabCycling )
3712  return DockingWindow::EventNotify( rNEvt );
3713  else if( ImplChangeHighlightUpDn( aKeyCode.IsShift() , bNoTabCycling ) )
3714  return true;
3715  else
3716  return DockingWindow::EventNotify( rNEvt );
3717  }
3718  default:
3719  break;
3720  }
3721  }
3722  else if( rNEvt.GetType() == MouseNotifyEvent::GETFOCUS )
3723  {
3724  if( rNEvt.GetWindow() == this )
3725  {
3726  // the toolbar itself got the focus
3727  if( mnLastFocusItemId != 0 || mpData->mbMenubuttonWasLastSelected )
3728  {
3729  // restore last item
3730  if( mpData->mbMenubuttonWasLastSelected )
3731  {
3732  ImplChangeHighlight( nullptr );
3733  mpData->mbMenubuttonSelected = true;
3735  }
3736  else
3737  {
3739  mnLastFocusItemId = 0;
3740  }
3741  }
3743  // Shift-TAB was pressed in the parent
3744  ImplChangeHighlightUpDn( false );
3745  else
3746  ImplChangeHighlightUpDn( true );
3747 
3748  mnLastFocusItemId = 0;
3749 
3750  return true;
3751  }
3752  else
3753  {
3754  // a child window got the focus so update current item to
3755  // allow for proper lose focus handling in keyboard navigation
3756  for (auto const& item : mpData->m_aItems)
3757  {
3758  if ( item.mbVisible )
3759  {
3760  if ( item.mpWindow && item.mpWindow->ImplIsWindowOrChild( rNEvt.GetWindow() ) )
3761  {
3762  mnHighItemId = item.mnId;
3763  break;
3764  }
3765  }
3766  }
3767  return DockingWindow::EventNotify( rNEvt );
3768  }
3769  }
3770  else if( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS )
3771  {
3772  // deselect
3773  ImplHideFocus();
3774  mpData->mbMenubuttonWasLastSelected = false;
3775  mnHighItemId = 0;
3777  }
3778 
3779  return DockingWindow::EventNotify( rNEvt );
3780 }
3781 
3782 void ToolBox::Command( const CommandEvent& rCEvt )
3783 {
3784  if ( rCEvt.GetCommand() == CommandEventId::Wheel )
3785  {
3786  if ( (mnCurLine > 1) || (mnCurLine+mnVisLines-1 < mnCurLines) )
3787  {
3788  const CommandWheelData* pData = rCEvt.GetWheelData();
3789  if ( pData->GetMode() == CommandWheelMode::SCROLL )
3790  {
3791  if ( (mnCurLine > 1) && (pData->GetDelta() > 0) )
3792  ShowLine( false );
3793  else if ( (mnCurLine+mnVisLines-1 < mnCurLines) && (pData->GetDelta() < 0) )
3794  ShowLine( true );
3795  InvalidateSpin();
3796  return;
3797  }
3798  }
3799  }
3800  else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
3801  {
3803  return;
3804  }
3805 
3806  DockingWindow::Command( rCEvt );
3807 }
3808 
3810 {
3811  DockingWindow::StateChanged( nType );
3812 
3813  if ( nType == StateChangedType::InitShow )
3814  ImplFormat();
3815  else if ( nType == StateChangedType::Enable )
3816  ImplUpdateItem();
3817  else if ( nType == StateChangedType::UpdateMode )
3818  {
3819  if ( IsUpdateMode() )
3820  Invalidate();
3821  }
3822  else if ( (nType == StateChangedType::Zoom) ||
3823  (nType == StateChangedType::ControlFont) )
3824  {
3825  mbCalc = true;
3826  mbFormat = true;
3827  ImplInitSettings( true, false, false );
3828  Invalidate();
3829  }
3830  else if ( nType == StateChangedType::ControlForeground )
3831  {
3832  ImplInitSettings( false, true, false );
3833  Invalidate();
3834  }
3835  else if ( nType == StateChangedType::ControlBackground )
3836  {
3837  ImplInitSettings( false, false, true ); // font, foreground, background
3838  Invalidate();
3839  }
3840 
3841  maStateChangedHandler.Call( &nType );
3842 }
3843 
3845 {
3846  DockingWindow::DataChanged( rDCEvt );
3847 
3848  if ( (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
3849  (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
3851  ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
3852  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
3853  {
3854  mbCalc = true;
3855  mbFormat = true;
3856  ImplInitSettings( true, true, true );
3857  Invalidate();
3858  }
3859 
3860  maDataChangedHandler.Call( &rDCEvt );
3861 }
3862 
3863 void ToolBox::statusChanged( const css::frame::FeatureStateEvent& Event )
3864 {
3865  // Update image mirroring/rotation
3866  if ( Event.FeatureURL.Complete == ".uno:ImageOrientation" )
3867  {
3868  SfxImageItem aItem( 1 );
3869  aItem.PutValue( Event.State, 0 );
3870 
3871  mbImagesMirrored = aItem.IsMirrored();
3873 
3874  // update image orientation
3875  OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(mpStatusListener->getFrame()));
3876  for (auto const& item : mpData->m_aItems)
3877  {
3878  if (vcl::CommandInfoProvider::IsMirrored(item.maCommandStr, aModuleName))
3880  if (vcl::CommandInfoProvider::IsRotated(item.maCommandStr, aModuleName))
3882  }
3883  }
3884 }
3885 
3887 {
3888  mnWinStyle = nNewStyle;
3889  if (!ImplIsFloatingMode())
3890  {
3891  bool bOldScroll = mbScroll;
3892  mbScroll = (mnWinStyle & WB_SCROLL) != 0;
3893  if (mbScroll != bOldScroll)
3894  {
3895  mbFormat = true;
3896  ImplFormat();
3897  }
3898  }
3899 }
3900 
3902 {
3904 
3905  if (!mpData)
3906  return;
3907 
3908  bool bOldHorz = mbHorz;
3909 
3910  if ( ImplIsFloatingMode() )
3911  {
3912  mbHorz = true;
3913  meAlign = WindowAlign::Top;
3914  mbScroll = true;
3915 
3916  if( bOldHorz != mbHorz )
3917  mbCalc = true; // orientation was changed !
3918 
3921  }
3922  else
3923  {
3924  mbScroll = (mnWinStyle & WB_SCROLL) != 0;
3925  if ( (meAlign == WindowAlign::Top) || (meAlign == WindowAlign::Bottom) )
3926  mbHorz = true;
3927  else
3928  mbHorz = false;
3929 
3930  // set focus back to document
3932  }
3933 
3934  if( bOldHorz != mbHorz )
3935  {
3936  // if orientation changes, the toolbox has to be initialized again
3937  // to update the direction of the gradient
3938  mbCalc = true;
3939  ImplInitSettings( true, true, true );
3940  }
3941 
3942  mbFormat = true;
3943  ImplFormat();
3944 }
3945 
3947 {
3948  meDockAlign = meAlign;
3949  mnDockLines = mnLines;
3952 }
3953 
3954 bool ToolBox::Docking( const Point& rPos, tools::Rectangle& rRect )
3955 {
3956  // do nothing during dragging, it was calculated before
3957  if ( mbDragging )
3958  return false;
3959 
3960  bool bFloatMode = false;
3961 
3962  DockingWindow::Docking( rPos, rRect );
3963 
3964  // if the mouse is outside the area, it can only become a floating window
3965  tools::Rectangle aDockingRect( rRect );
3966  if ( !ImplIsFloatingMode() )
3967  {
3968  // don't use tracking rectangle for alignment check, because it will be too large
3969  // to get a floating mode as result - switch to floating size
3970  // so the calculation only depends on the position of the rectangle, not the current
3971  // docking state of the window
3972  ImplToolItems::size_type nTemp = 0;
3973  aDockingRect.SetSize( ImplCalcFloatSize( nTemp ) );
3974 
3975  // in this mode docking is never done by keyboard, so it's OK to use the mouse position
3976  aDockingRect.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
3977  }
3978 
3979  bFloatMode = true;
3980 
3981  meDockAlign = meAlign;
3982  if ( !mbLastFloatMode )
3983  {
3984  ImplToolItems::size_type nTemp = 0;
3985  aDockingRect.SetSize( ImplCalcFloatSize( nTemp ) );
3986  }
3987 
3988  rRect = aDockingRect;
3989  mbLastFloatMode = bFloatMode;
3990 
3991  return bFloatMode;
3992 }
3993 
3994 void ToolBox::EndDocking( const tools::Rectangle& rRect, bool bFloatMode )
3995 {
3996  if ( !IsDockingCanceled() )
3997  {
3998  if ( mnLines != mnDockLines )
4000  if ( meAlign != meDockAlign )
4001  SetAlign( meDockAlign );
4002  }
4003  if ( bFloatMode || (bFloatMode != ImplIsFloatingMode()) )
4004  DockingWindow::EndDocking( rRect, bFloatMode );
4005 }
4006 
4007 void ToolBox::Resizing( Size& rSize )
4008 {
4009  ImplToolItems::size_type nCalcLines;
4010  ImplToolItems::size_type nTemp;
4011 
4012  // calculate all floating sizes
4014 
4015  if ( !mnLastResizeDY )
4016  mnLastResizeDY = mnDY;
4017 
4018  // is vertical resizing needed
4019  if ( (mnLastResizeDY != rSize.Height()) && (mnDY != rSize.Height()) )
4020  {
4021  nCalcLines = ImplCalcLines( rSize.Height() );
4022  if ( nCalcLines < 1 )
4023  nCalcLines = 1;
4024  rSize = ImplCalcFloatSize( nCalcLines );
4025  }
4026  else
4027  {
4028  nCalcLines = 1;
4029  nTemp = nCalcLines;
4030  Size aTempSize = ImplCalcFloatSize( nTemp );
4031  while ( (aTempSize.Width() > rSize.Width()) &&
4032  (nCalcLines <= maFloatSizes[0].mnLines) )
4033  {
4034  nCalcLines++;
4035  nTemp = nCalcLines;
4036  aTempSize = ImplCalcFloatSize( nTemp );
4037  }
4038  rSize = aTempSize;
4039  }
4040 
4041  mnLastResizeDY = rSize.Height();
4042 }
4043 
4045 {
4046  // If we have any expandable entries, then force them to their
4047  // optimal sizes, then reset them afterwards
4048  std::map<vcl::Window*, Size> aExpandables;
4049  for (const ImplToolItem & rItem : mpData->m_aItems)
4050  {
4051  if (rItem.mbExpand)
4052  {
4053  vcl::Window *pWindow = rItem.mpWindow;
4054  SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
4055  if (!pWindow)
4056  continue;
4057  Size aWinSize(pWindow->GetSizePixel());
4058  aExpandables[pWindow] = aWinSize;
4059  Size aPrefSize(pWindow->get_preferred_size());
4060  aWinSize.setWidth( aPrefSize.Width() );
4061  pWindow->SetSizePixel(aWinSize);
4062  }
4063  }
4064 
4065  Size aSize(const_cast<ToolBox *>(this)->ImplCalcSize( mnLines ));
4066 
4067  for (auto const& expandable : aExpandables)
4068  {
4069  vcl::Window *pWindow = expandable.first;
4070  Size aWinSize = expandable.second;
4071  pWindow->SetSizePixel(aWinSize);
4072  }
4073 
4074  return aSize;
4075 }
4076 
4077 Size ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines )
4078 {
4079  return ImplCalcSize( nCalcLines );
4080 }
4081 
4082 Size ToolBox::CalcWindowSizePixel( ImplToolItems::size_type nCalcLines, WindowAlign eAlign )
4083 {
4084  return ImplCalcSize( nCalcLines,
4085  (eAlign == WindowAlign::Top || eAlign == WindowAlign::Bottom) ? TB_CALCMODE_HORZ : TB_CALCMODE_VERT );
4086 }
4087 
4088 ToolBox::ImplToolItems::size_type ToolBox::ImplCountLineBreaks() const
4089 {
4090  ImplToolItems::size_type nLines = 0;
4091 
4092  for (auto const& item : mpData->m_aItems)
4093  {
4094  if( item.meType == ToolBoxItemType::BREAK )
4095  ++nLines;
4096  }
4097  return nLines;
4098 }
4099 
4101 {
4102  // count number of breaks and calc corresponding floating window size
4103  ImplToolItems::size_type nLines = ImplCountLineBreaks();
4104 
4105  if( nLines )
4106  ++nLines; // add the first line
4107  else
4108  {
4109  // no breaks found: use quadratic layout
4110  nLines = static_cast<ImplToolItems::size_type>(ceil( sqrt( static_cast<double>(GetItemCount()) ) ));
4111  }
4112 
4113  bool bPopup = mpData->mbAssumePopupMode;
4114  mpData->mbAssumePopupMode = true;
4115 
4116  Size aSize = CalcFloatingWindowSizePixel( nLines );
4117 
4118  mpData->mbAssumePopupMode = bPopup;
4119  return aSize;
4120 }
4121 
4123 {
4124  ImplToolItems::size_type nLines = ImplCountLineBreaks();
4125  ++nLines; // add the first line
4126  return CalcFloatingWindowSizePixel( nLines );
4127 }
4128 
4129 Size ToolBox::CalcFloatingWindowSizePixel( ImplToolItems::size_type nCalcLines )
4130 {
4131  bool bFloat = mpData->mbAssumeFloating;
4132  bool bDocking = mpData->mbAssumeDocked;
4133 
4134  // simulate floating mode and force reformat before calculating
4135  mpData->mbAssumeFloating = true;
4136  mpData->mbAssumeDocked = false;
4137 
4138  Size aSize = ImplCalcFloatSize( nCalcLines );
4139 
4140  mbFormat = true;
4141  mpData->mbAssumeFloating = bFloat;
4142  mpData->mbAssumeDocked = bDocking;
4143 
4144  return aSize;
4145 }
4146 
4148 {
4149  if( ImplIsFloatingMode() )
4150  return ImplCalcSize( mnFloatLines );
4151  else
4152  {
4153  // create dummy toolbox for measurements
4154  VclPtrInstance< ToolBox > pToolBox( GetParent(), GetStyle() );
4155 
4156  // copy until first useful item
4157  for (auto const& item : mpData->m_aItems)
4158  {
4159  pToolBox->CopyItem( *this, item.mnId );
4160  if( (item.meType == ToolBoxItemType::BUTTON) &&
4161  item.mbVisible && !ImplIsFixedControl( &item ) )
4162  break;
4163  }
4164 
4165  // add to docking manager if required to obtain a drag area
4166  // (which is accounted for in calcwindowsizepixel)
4167  if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
4168  ImplGetDockingManager()->AddWindow( pToolBox );
4169 
4170  // account for menu
4171  if( IsMenuEnabled() )
4172  pToolBox->SetMenuType( GetMenuType() );
4173 
4174  pToolBox->SetAlign( GetAlign() );
4175  Size aSize = pToolBox->CalcWindowSizePixel( 1 );
4176 
4177  ImplGetDockingManager()->RemoveWindow( pToolBox );
4178  pToolBox->Clear();
4179 
4180  pToolBox.disposeAndClear();
4181 
4182  return aSize;
4183  }
4184 }
4185 
4186 void ToolBox::EnableCustomize( bool bEnable )
4187 {
4188  mbCustomize = bEnable;
4189 }
4190 
4192 {
4193  ImplChangeHighlight( nullptr, true );
4194 
4196 }
4197 
4198 // performs the action associated with an item, ie simulates clicking the item
4199 void ToolBox::TriggerItem( sal_uInt16 nItemId )
4200 {
4201  mnHighItemId = nItemId;
4202  vcl::KeyCode aKeyCode( 0, 0 );
4203  ImplActivateItem( aKeyCode );
4204 }
4205 
4206 // calls the button's action handler
4207 // returns true if action was called
4209 {
4210  bool bRet = true;
4211  if( mnHighItemId )
4212  {
4213  ImplToolItem *pToolItem = ImplGetItem( mnHighItemId );
4214 
4215  // #107712#, activate can also be called for disabled entries
4216  if( pToolItem && !pToolItem->mbEnabled )
4217  return true;
4218 
4219  if( pToolItem && pToolItem->mpWindow && HasFocus() )
4220  {
4221  ImplHideFocus();
4222  mbChangingHighlight = true; // avoid focus change due to loss of focus
4224  mbChangingHighlight = false;
4225  }
4226  else
4227  {
4229  if (pToolItem && (pToolItem->mnBits & ToolBoxItemBits::AUTOCHECK))
4230  {
4231  if ( pToolItem->mnBits & ToolBoxItemBits::RADIOCHECK )
4232  {
4233  if ( pToolItem->meState != TRISTATE_TRUE )
4234  SetItemState( pToolItem->mnId, TRISTATE_TRUE );
4235  }
4236  else
4237  {
4238  if ( pToolItem->meState != TRISTATE_TRUE )
4239  pToolItem->meState = TRISTATE_TRUE;
4240  else
4241  pToolItem->meState = TRISTATE_FALSE;
4242  }
4243  }
4244  mnMouseModifier = aKeyCode.GetModifier();
4245  mbIsKeyEvent = true;
4246  Activate();
4247  Click();
4248 
4249  // #107776# we might be destroyed in the selecthandler
4250  VclPtr<vcl::Window> xWindow = this;
4251  Select();
4252  if ( xWindow->IsDisposed() )
4253  return bRet;
4254 
4255  Deactivate();
4256  mbIsKeyEvent = false;
4257  mnMouseModifier = 0;
4258  }
4259  }
4260  else
4261  bRet = false;
4262  return bRet;
4263 }
4264 
4265 static bool ImplCloseLastPopup( vcl::Window const *pParent )
4266 {
4267  // close last popup toolbox (see also:
4268  // ImplHandleMouseFloatMode(...) in winproc.cxx )
4269 
4270  if (ImplGetSVData()->mpWinData->mpFirstFloat)
4271  {
4273  // only close the floater if it is not our direct parent, which would kill ourself
4274  if( pLastLevelFloat && pLastLevelFloat != pParent )
4275  {
4277  return true;
4278  }
4279  }
4280  return false;
4281 }
4282 
4283 // opens a drop down toolbox item
4284 // returns true if item was opened
4286 {
4287  sal_uInt16 nCode = aKeyCode.GetCode();
4288  bool bRet = true;
4289 
4290  // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
4291  if ( ((nCode == KEY_LEFT || nCode == KEY_RIGHT) && IsHorizontal())
4292  || ((nCode == KEY_UP || nCode == KEY_DOWN) && !IsHorizontal()) )
4293  return false;
4294 
4295  if( mpData->mbMenubuttonSelected )
4296  {
4297  if( ImplCloseLastPopup( GetParent() ) )
4298  return bRet;
4299  mbIsKeyEvent = true;
4300  if ( maMenuButtonHdl.IsSet() )
4301  maMenuButtonHdl.Call( this );
4302  else
4303  ExecuteCustomMenu( mpData->maMenubuttonItem.maRect );
4304  mpData->mbMenubuttonWasLastSelected = true;
4305  mbIsKeyEvent = false;
4306  }
4307  else if( mnHighItemId && ImplGetItem( mnHighItemId ) &&
4309  {
4312  mnLastFocusItemId = mnCurItemId; // save item id for possible later focus restore
4313  mnMouseModifier = aKeyCode.GetModifier();
4314  mbIsKeyEvent = true;
4315  Activate();
4316 
4317  mpData->mbDropDownByKeyboard = true;
4318  mpData->maDropdownClickHdl.Call( this );
4319 
4320  mbIsKeyEvent = false;
4321  mnMouseModifier = 0;
4322  }
4323  else
4324  bRet = false;
4325 
4326  return bRet;
4327 }
4328 
4329 void ToolBox::KeyInput( const KeyEvent& rKEvt )
4330 {
4331  vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
4332  sal_uInt16 nCode = aKeyCode.GetCode();
4333 
4334  vcl::Window *pParent = ImplGetParent();
4335  bool bOldSchoolContainer = ((pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL);
4336  bool bParentIsContainer = bOldSchoolContainer || isContainerWindow(pParent);
4337 
4338  bool bForwardKey = false;
4339  bool bGrabFocusToDocument = false;
4340 
4341  // #107776# we might be destroyed in the keyhandler
4342  VclPtr<vcl::Window> xWindow = this;
4343 
4344  switch ( nCode )
4345  {
4346  case KEY_UP:
4347  {
4348  // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
4349  if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4350  break;
4351  if( !IsHorizontal() )
4352  ImplChangeHighlightUpDn( true );
4353  else
4354  ImplOpenItem( aKeyCode );
4355  }
4356  break;
4357  case KEY_LEFT:
4358  {
4359  if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4360  break;
4361  if( IsHorizontal() )
4362  ImplChangeHighlightUpDn( true );
4363  else
4364  ImplOpenItem( aKeyCode );
4365  }
4366  break;
4367  case KEY_DOWN:
4368  {
4369  if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4370  break;
4371  if( !IsHorizontal() )
4372  ImplChangeHighlightUpDn( false );
4373  else
4374  ImplOpenItem( aKeyCode );
4375  }
4376  break;
4377  case KEY_RIGHT:
4378  {
4379  if( aKeyCode.GetModifier() ) // allow only pure cursor keys
4380  break;
4381  if( IsHorizontal() )
4382  ImplChangeHighlightUpDn( false );
4383  else
4384  ImplOpenItem( aKeyCode );
4385  }
4386  break;
4387  case KEY_PAGEUP:
4388  if ( mnCurLine > 1 )
4389  {
4390  if( mnCurLine > mnVisLines )
4392  else
4393  mnCurLine = 1;
4394  mbFormat = true;
4395  ImplFormat();
4396  InvalidateSpin();
4398  }
4399  break;
4400  case KEY_PAGEDOWN:
4401  if ( mnCurLine+mnVisLines-1 < mnCurLines )
4402  {
4403  if( mnCurLine + 2*mnVisLines-1 < mnCurLines )
4405  else
4407  mbFormat = true;
4408  ImplFormat();
4409  InvalidateSpin();
4411  }
4412  break;
4413  case KEY_END:
4414  {
4415  ImplChangeHighlight( nullptr );
4416  ImplChangeHighlightUpDn( false );
4417  }
4418  break;
4419  case KEY_HOME:
4420  {
4421  ImplChangeHighlight( nullptr );
4422  ImplChangeHighlightUpDn( true );
4423  }
4424  break;
4425  case KEY_ESCAPE:
4426  {
4427  if( !ImplIsFloatingMode() && bParentIsContainer )
4428  DockingWindow::KeyInput( rKEvt );
4429  else
4430  {
4431  // send focus to document pane
4432  vcl::Window *pWin = this;
4433  while( pWin )
4434  {
4435  if( !pWin->GetParent() )
4436  {
4438  break;
4439  }
4440  pWin = pWin->GetParent();
4441  }
4442  }
4443  }
4444  break;
4445  case KEY_RETURN:
4446  {
4447  // #107712#, disabled entries are selectable now
4448  // leave toolbox and move focus to document
4449  if( mnHighItemId )
4450  {
4452  if (!pItem || !pItem->mbEnabled)
4453  {
4454  bGrabFocusToDocument = true;
4455  }
4456  }
4457  if( !bGrabFocusToDocument )
4458  bForwardKey = !ImplActivateItem( aKeyCode );
4459  }
4460  break;
4461  case KEY_SPACE:
4462  {
4463  ImplOpenItem( aKeyCode );
4464  }
4465  break;
4466  default:
4467  {
4468  sal_uInt16 aKeyGroup = aKeyCode.GetGroup();
4469  ImplToolItem *pItem = nullptr;
4470  if( mnHighItemId )
4471  pItem = ImplGetItem( mnHighItemId );
4472  // #i13931# forward alphanum keyinput into embedded control
4473  if( (aKeyGroup == KEYGROUP_NUM || aKeyGroup == KEYGROUP_ALPHA ) && pItem && pItem->mpWindow && pItem->mbEnabled )
4474  {
4475  vcl::Window *pFocusWindow = Application::GetFocusWindow();
4476  ImplHideFocus();
4477  mbChangingHighlight = true; // avoid focus change due to loss of focus
4479  mbChangingHighlight = false;
4480  if( pFocusWindow != Application::GetFocusWindow() )
4482  }
4483  else
4484  {
4485  // do nothing to avoid key presses going into the document
4486  // while the toolbox has the focus
4487  // just forward function and special keys and combinations with Alt-key
4488  if( aKeyGroup == KEYGROUP_FKEYS || aKeyGroup == KEYGROUP_MISC || aKeyCode.IsMod2() )
4489  bForwardKey = true;
4490  }
4491  }
4492  }
4493 
4494  if ( xWindow->IsDisposed() )
4495  return;
4496 
4497  // #107251# move focus away if this toolbox was disabled during keyinput
4498  if (HasFocus() && mpData->mbKeyInputDisabled && bParentIsContainer)
4499  {
4500  vcl::Window *pFocusControl = pParent->ImplGetDlgWindow( 0, GetDlgWindowType::First );
4501  if ( pFocusControl && pFocusControl != this )
4502  pFocusControl->ImplControlFocus( GetFocusFlags::Init );
4503  }
4504 
4505  // #107712#, leave toolbox
4506  if( bGrabFocusToDocument )
4507  {
4509  return;
4510  }
4511 
4512  if( bForwardKey )
4513  DockingWindow::KeyInput( rKEvt );
4514 }
4515 
4516 // returns the current toolbox line of the item
4517 ToolBox::ImplToolItems::size_type ToolBox::ImplGetItemLine( ImplToolItem const * pCurrentItem )
4518 {
4519  ImplToolItems::size_type nLine = 1;
4520  for (auto const& item : mpData->m_aItems)
4521  {
4522  if ( item.mbBreak )
4523  ++nLine;
4524  if( &item == pCurrentItem)
4525  break;
4526  }
4527  return nLine;
4528 }
4529 
4530 // returns the first displayable item in the given line
4531 ImplToolItem* ToolBox::ImplGetFirstValidItem( ImplToolItems::size_type nLine )
4532 {
4533  if( !nLine || nLine > mnCurLines )
4534  return nullptr;
4535 
4536  nLine--;
4537 
4538  ImplToolItems::iterator it = mpData->m_aItems.begin();
4539  while( it != mpData->m_aItems.end() )
4540  {
4541  // find correct line
4542  if ( it->mbBreak )
4543  nLine--;
4544  if( !nLine )
4545  {
4546  // find first useful item
4547  while( it != mpData->m_aItems.end() && ((it->meType != ToolBoxItemType::BUTTON) || !it->mbVisible || ImplIsFixedControl( &(*it) )) )
4549  {
4550  ++it;
4551  if( it == mpData->m_aItems.end() || it->mbBreak )
4552  return nullptr; // no valid items in this line
4553  }
4554  return &(*it);
4555  }
4556  ++it;
4557  }
4558 
4559  return (it == mpData->m_aItems.end()) ? nullptr : &(*it);
4560 }
4561 
4562 ToolBox::ImplToolItems::size_type ToolBox::ImplFindItemPos( const ImplToolItem* pItem, const ImplToolItems& rList )
4563 {
4564  if( pItem )
4565  {
4566  for( ImplToolItems::size_type nPos = 0; nPos < rList.size(); ++nPos )
4567  if( &rList[ nPos ] == pItem )
4568  return nPos;
4569  }
4570  return ITEM_NOTFOUND;
4571 }
4572 
4573 void ToolBox::ChangeHighlight( ImplToolItems::size_type nPos )
4574 {
4575  if ( nPos < GetItemCount() ) {
4577  ImplChangeHighlight ( ImplGetItem ( GetItemId ( nPos ) ) );
4578  }
4579 }
4580 
4581 void ToolBox::ImplChangeHighlight( ImplToolItem const * pItem, bool bNoGrabFocus )
4582 {
4583  // avoid recursion due to focus change
4584  if( mbChangingHighlight )
4585  return;
4586 
4587  mbChangingHighlight = true;
4588 
4589  ImplToolItem* pOldItem = nullptr;
4590 
4591  if ( mnHighItemId )
4592  {
4593  ImplHideFocus();
4594  ImplToolItems::size_type nPos = GetItemPos( mnHighItemId );
4595  pOldItem = ImplGetItem( mnHighItemId );
4596  // #i89962# ImplDrawItem can cause Invalidate/Update
4597  // which will in turn ImplShowFocus again
4598  // set mnHighItemId to 0 already to prevent this hen/egg problem
4599  mnHighItemId = 0;
4600  InvalidateItem(nPos);
4601  CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nPos ) );
4602  }
4603 
4604  if( !bNoGrabFocus && pItem != pOldItem && pOldItem && pOldItem->mpWindow )
4605  {
4606  // move focus into toolbox
4607  GrabFocus();
4608  }
4609 
4610  if( pItem )
4611  {
4612  ImplToolItems::size_type aPos = ToolBox::ImplFindItemPos( pItem, mpData->m_aItems );
4613  if( aPos != ITEM_NOTFOUND)
4614  {
4615  // check for line breaks
4616  ImplToolItems::size_type nLine = ImplGetItemLine( pItem );
4617 
4618  if( nLine >= mnCurLine + mnVisLines )
4619  {
4620  mnCurLine = nLine - mnVisLines + 1;
4621  mbFormat = true;
4622  }
4623  else if ( nLine < mnCurLine )
4624  {
4625  mnCurLine = nLine;
4626  mbFormat = true;
4627  }
4628 
4629  if( mbFormat )
4630  {
4631  ImplFormat();
4632  }
4633 
4634  mnHighItemId = pItem->mnId;
4635  InvalidateItem(aPos);
4636 
4637  ImplShowFocus();
4638 
4639  if( pItem->mpWindow )
4640  pItem->mpWindow->GrabFocus();
4641  if( pItem != pOldItem )
4643  }
4644  }
4645  else
4646  {
4647  ImplHideFocus();
4648  mnHighItemId = 0;
4650  }
4651 
4652  mbChangingHighlight = false;
4653 }
4654 
4655 // check for keyboard accessible items
4656 static bool ImplIsValidItem( const ImplToolItem* pItem, bool bNotClipped )
4657 {
4658  bool bValid = (pItem && pItem->meType == ToolBoxItemType::BUTTON && pItem->mbVisible && !ImplIsFixedControl( pItem )
4659  && pItem->mbEnabled);
4660  if( bValid && bNotClipped && pItem->IsClipped() )
4661  bValid = false;
4662  return bValid;
4663 }
4664 
4665 bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
4666 {
4667  ImplToolItem* pToolItem = ImplGetItem( mnHighItemId );
4668 
4669  if( !pToolItem || !mnHighItemId )
4670  {
4671  // menubutton highlighted ?
4672  if( mpData->mbMenubuttonSelected )
4673  {
4674  mpData->mbMenubuttonSelected = false;
4675  if( bUp )
4676  {
4677  // select last valid non-clipped item
4678  ImplToolItem* pItem = nullptr;
4679  auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(),
4680  [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); });
4681  if( it != mpData->m_aItems.rend() )
4682  pItem = &(*it);
4683 
4685  ImplChangeHighlight( pItem );
4686  }
4687  else
4688  {
4689  // select first valid non-clipped item
4690  ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
4691  [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); });
4692  if( it != mpData->m_aItems.end() )
4693  {
4695  ImplChangeHighlight( &(*it) );
4696  }
4697  }
4698  return true;
4699  }
4700 
4701  if( bUp )
4702  {
4703  // Select first valid item
4704  ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
4705  [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); });
4706 
4707  // select the menu button if a clipped item would be selected
4708  if( (it != mpData->m_aItems.end() && &(*it) == ImplGetFirstClippedItem()) && IsMenuEnabled() )
4709  {
4710  ImplChangeHighlight( nullptr );
4711  mpData->mbMenubuttonSelected = true;
4713  }
4714  else
4715  ImplChangeHighlight( (it != mpData->m_aItems.end()) ? &(*it) : nullptr );
4716  return true;
4717  }
4718  else
4719  {
4720  // Select last valid item
4721 
4722  // docked toolbars have the menubutton as last item - if this button is enabled
4724  {
4725  ImplChangeHighlight( nullptr );
4726  mpData->mbMenubuttonSelected = true;
4728  }
4729  else
4730  {
4731  ImplToolItem* pItem = nullptr;
4732  auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(),
4733  [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); });
4734  if( it != mpData->m_aItems.rend() )
4735  pItem = &(*it);
4736 
4737  ImplChangeHighlight( pItem );
4738  }
4739  return true;
4740  }
4741  }
4742 
4743  assert(pToolItem);
4744 
4745  ImplToolItems::size_type pos = ToolBox::ImplFindItemPos( pToolItem, mpData->m_aItems );
4746  ImplToolItems::size_type nCount = mpData->m_aItems.size();
4747 
4748  ImplToolItems::size_type i=0;
4749  do
4750  {
4751  if( bUp )
4752  {
4753  if( !pos-- )
4754  {
4755  if( bNoCycle )
4756  return false;
4757 
4758  // highlight the menu button if it is the last item
4760  {
4761  ImplChangeHighlight( nullptr );
4762  mpData->mbMenubuttonSelected = true;
4764  return true;
4765  }
4766  else
4767  pos = nCount-1;
4768  }
4769  }
4770  else
4771  {
4772  if( ++pos >= nCount )
4773  {
4774  if( bNoCycle )
4775  return false;
4776 
4777  // highlight the menu button if it is the last item
4779  {
4780  ImplChangeHighlight( nullptr );
4781  mpData->mbMenubuttonSelected = true;
4783  return true;
4784  }
4785  else
4786  pos = 0;
4787  }
4788  }
4789 
4790  pToolItem = &mpData->m_aItems[pos];
4791 
4792  if ( ImplIsValidItem( pToolItem, false ) )
4793  break;
4794 
4795  } while( ++i < nCount);
4796 
4797  if( pToolItem->IsClipped() && IsMenuEnabled() )
4798  {
4799  // select the menu button if a clipped item would be selected
4800  ImplChangeHighlight( nullptr );
4801  mpData->mbMenubuttonSelected = true;
4803  }
4804  else if( i != nCount )
4805  ImplChangeHighlight( pToolItem );
4806  else
4807  return false;
4808 
4809  return true;
4810 }
4811 
4813 {
4814  if( mnHighItemId && HasFocus() )
4815  {
4817  if (pItem && pItem->mpWindow && !pItem->mpWindow->IsDisposed())
4818  {
4821  pWin->Invalidate();
4822  }
4823  }
4824 }
4825 
4827 {
4828  if( mnHighItemId )
4829  {
4830  mpData->mbMenubuttonWasLastSelected = false;
4832  if( pItem && pItem->mpWindow )
4833  {
4836  pWin->Invalidate();
4837  }
4838  }
4839 
4840  if ( mpData && mpData->mbMenubuttonSelected )
4841  {
4842  mpData->mbMenubuttonWasLastSelected = true;
4843  // remove highlight from menubutton
4844  mpData->mbMenubuttonSelected = false;
4846  }
4847 }
4848 
4850 {
4851 #ifdef _WIN32 // Check in the Windows registry if an AT tool wants no flat toolboxes
4852  static bool bInit = false, bValue = false;
4853  if( ! bInit )
4854  {
4855  bInit = true;
4856  HKEY hkey;
4857 
4858  if( ERROR_SUCCESS == RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\LibreOffice\\Accessibility\\AtToolSupport", &hkey) )
4859  {
4860  DWORD dwType = 0;
4861  wchar_t Data[6]; // possible values: "true", "false", "1", "0", DWORD
4862  DWORD cbData = sizeof(Data);
4863 
4864  if( ERROR_SUCCESS == RegQueryValueExW(hkey, L"DisableFlatToolboxButtons",
4865  nullptr, &dwType, reinterpret_cast<LPBYTE>(Data), &cbData) )
4866  {
4867  switch (dwType)
4868  {
4869  case REG_SZ:
4870  bValue = ((0 == wcsicmp(Data, L"1")) || (0 == wcsicmp(Data, L"true")));
4871  break;
4872  case REG_DWORD:
4873  bValue = static_cast<bool>(reinterpret_cast<DWORD *>(Data)[0]);
4874  break;
4875  }
4876  }
4877  RegCloseKey(hkey);
4878  }
4879  }
4880  if( bValue )
4882 #else
4883  (void) this; // loplugin:staticmethods
4884 #endif
4885 }
4886 
4888 {
4889  if ( meLayoutMode != eLayout )
4890  meLayoutMode = eLayout;
4891 }
4892 
4894 {
4895  meTextPosition = ePosition;
4896 }
4897 
4898 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE Size ImplCalcFloatSize(ImplToolItems::size_type &rLines)
Definition: toolbox.cxx:806
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:932
constexpr sal_uInt16 KEYGROUP_MISC
Definition: keycodes.hxx:41
Point TopLeft() const
void DetermineButtonDrawStyle(ButtonType eButtonType, bool &rbImage, bool &rbText) const
Definition: toolbox2.cxx:185
long getHeight() const
long Width() const
void SetOutputSizePixel(const Size &rNewSize) override
Definition: dockwin.cxx:883
#define DOCK_LINEVSIZE
Definition: toolbox.cxx:79
WindowAlign
Size GetSizePixel() const
Definition: Image.cxx:86
static void ImplDrawMoreIndicator(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: toolbox.cxx:2363
double mnHeight
void SetPos(const Point &rPoint)
const Color & GetShadowColor() const
bool IsControlBackground() const
Definition: window2.cxx:1087
SAL_DLLPRIVATE bool ImplChangeHighlightUpDn(bool bUp, bool bNoCycle=false)
Definition: toolbox.cxx:4665
const Color & GetToolTextColor() const
void Dragging(const Point &rPos)
Definition: toolbox.cxx:1055
IMPL_LINK_NOARG(ToolBox, ImplDropdownLongClickHdl, Timer *, void)
Definition: toolbox.cxx:2331
virtual void StartDocking() override
Definition: toolbox.cxx:3946
long mnRightBorder
Definition: toolbox.hxx:109
GetFocusFlags GetGetFocusFlags() const
Definition: window2.cxx:1188
long GetWidth() const
void CaptureMouse()
Definition: mouse.cxx:440
Point GetPointerPosPixel()
Definition: mouse.cxx:550
#define DOCK_LINELEFT
Definition: toolbox.cxx:82
#define SMALLBUTTON_OFF_NORMAL_Y
Definition: toolbox.cxx:58
sal_Int32 nIndex
#define SMALLBUTTON_OFF_NORMAL_X
Definition: toolbox.cxx:57
ToolBoxLayoutMode
Definition: toolbox.hxx:61
PointerStyle meLastStyle
Definition: toolbox.hxx:147
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:405
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:156
SAL_DLLPRIVATE bool ImplCalcItem()
Definition: toolbox.cxx:1353
SAL_DLLPRIVATE bool ImplHasClippedItems()
Definition: toolbox2.cxx:1521
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:1476
long AdjustWidth(long n)
SAL_DLLPRIVATE Size ImplGetOptimalFloatingSize()
Definition: toolbox.cxx:1800
SAL_DLLPRIVATE void ImplUpdateDragArea() const
Definition: toolbox.cxx:162
#define TB_CALCMODE_HORZ
Definition: toolbox.cxx:72
bool GetNativeControlRegion(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion) const
Query the native control's actual drawing region (including adornment)
virtual void MouseButtonDown(const MouseEvent &rMEvt)
Definition: mouse.cxx:414
SAL_DLLPRIVATE bool ImplActivateItem(vcl::KeyCode aKeyCode)
Definition: toolbox.cxx:4208
SAL_DLLPRIVATE void ImplUpdateItem(ImplToolItems::size_type nIndex=ITEM_NOTFOUND)
Definition: toolbox2.cxx:298
StartTrackingFlags
Definition: window.hxx:285
SAL_DLLPRIVATE bool ImplHandleMouseButtonUp(const MouseEvent &rMEvt, bool bCancel=false)
Definition: toolbox.cxx:2942
std::unique_ptr< ContentProperties > pData
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:321
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
WinBits const WB_NODIALOGCONTROL
SAL_DLLPRIVATE ImplToolItems::size_type ImplCalcLines(long nToolSize) const
Definition: toolbox.cxx:869
Definition: help.hxx:60
static Help * GetHelp()
Gets the application's help.
Definition: svapp.cxx:1346
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:1063
void DoubleClick()
Definition: toolbox2.cxx:327
void DrawCtrlText(const Point &rPos, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, DrawTextFlags nStyle=DrawTextFlags::Mnemonic, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pGlyphs=nullptr)
Definition: text.cxx:2057
void ImplDrawUpDownButtons(vcl::RenderContext &rRenderContext, const tools::Rectangle &rUpperRect, const tools::Rectangle &rLowerRect, bool bUpperIn, bool bLowerIn, bool bUpperEnabled, bool bLowerEnabled, bool bHorz, bool bMirrorHorz)
Definition: spinfld.cxx:207
long getWidth() const
bool IsBackground() const
Definition: outdev.hxx:640
bool IsMirrored(const OUString &rsCommandName, const OUString &rsModuleName)
SAL_DLLPRIVATE void ImplFloatControl(bool bStart, FloatingWindow *pWindow)
Definition: toolbox.cxx:2829
Resize runs before repaint, so we won't paint twice.
virtual void StateChanged(StateChangedType nType) override
Definition: toolbox.cxx:3809
Point AbsoluteScreenToOutputPixel(const Point &rPos) const
Definition: window.cxx:2928
bool IsMenuEnabled() const
Definition: toolbox2.cxx:1506
sal_uIntPtr sal_uLong
#define SAL_INFO_IF(condition, area, stream)
void ExecuteCustomMenu(const tools::Rectangle &rRect=tools::Rectangle())
Definition: toolbox2.cxx:1600
MouseEventModifiers GetMode() const
Definition: event.hxx:121
SAL_DLLPRIVATE void ImplInitToolBoxData()
Definition: toolbox.cxx:1093
void disposeAndClear()
Definition: vclptr.hxx:200
ImplToolItems::size_type mnCurLines
Definition: toolbox.hxx:122
bool mbIsDeferredInit
Definition: dockwin.hxx:244
const StyleSettings & GetStyleSettings() const
SAL_DLLPRIVATE sal_uInt16 ImplTestLineSize(const Point &rPos) const
Definition: toolbox.cxx:900
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:714
ToolBoxLayoutMode meLayoutMode
Definition: toolbox.hxx:149
void statusChanged(const css::frame::FeatureStateEvent &rEvent)
Definition: toolbox.cxx:3863
const Color & GetFaceColor() const
bool mbLower
Definition: toolbox.hxx:127
BitmapEx const & GetPersonaHeader() const
const OUString & GetHelpText() const
Definition: window.cxx:3145
void Flush() override
Definition: window.cxx:3013
#define TB_TEXTOFFSET
Definition: toolbox.cxx:60
ImplToolItems::size_type mnFloatLines
Definition: toolbox.hxx:124
SAL_DLLPRIVATE void ImplGrabFocus(GetFocusFlags nFlags)
Definition: mouse.cxx:195
void SetStyle(WinBits nNewStyle)
Definition: toolbox.cxx:3886
const OUString & GetQuickHelpText() const
Definition: window2.cxx:1232
ImplToolItems::size_type mnVisLines
Definition: toolbox.hxx:123
static constexpr auto ITEM_NOTFOUND
Definition: toolbox.hxx:85
void DrawPolygon(const tools::Polygon &rPoly)
Render the given polygon.
Definition: polygon.cxx:157
virtual Size GetOptimalSize() const override
Definition: toolbox.cxx:4044
DECL_LINK(SelectHdl, Accelerator &, void)
bool mbIsArranged
Definition: toolbox.hxx:127
void HideTracking()
Definition: window2.cxx:147
virtual Size GetSizePixel() const
Definition: window.cxx:2415
VclPtr< FloatingWindow > mpFloatWin
Definition: toolbox.hxx:101
SAL_DLLPRIVATE vcl::Window * ImplGetFrameWindow() const
Definition: window2.cxx:901
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1262
virtual bool Docking(const Point &rPos, tools::Rectangle &rRect) override
Definition: toolbox.cxx:3954
SAL_DLLPRIVATE WindowImpl * ImplGetWindowImpl() const
Definition: window.hxx:555
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: toolbox.cxx:1297
bool IsMirrored() const
sal_uInt16 mnMouseModifier
Definition: toolbox.hxx:126
static ImplTBDragMgr * ImplGetTBDragMgr()
Definition: toolbox.cxx:110
Color GetSeparatorColor() const
WindowAlign meAlign
Definition: toolbox.hxx:144
#define SMALLBUTTON_HSIZE
Definition: toolbox.cxx:54
bool IsOver(const tools::Rectangle &rRect) const
bool mbNonInteractiveWindow
Definition: toolbox.h:38
std::unique_ptr< ImplToolBoxPrivateData > mpData
Definition: toolbox.hxx:95
sal_uInt16 GetGroup() const
Definition: keycod.hxx:66
void SetTextFillColor()
Definition: text.cxx:699
sal_uInt16 GetCode() const
Definition: keycod.hxx:53
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
long mnImagesRotationAngle
Definition: toolbox.hxx:113
void setTristateVal(ButtonValue nTristate)
SAL_DLLPRIVATE void ApplyForegroundSettings(vcl::RenderContext &, const StyleSettings &)
Definition: toolbox.cxx:1178