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