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