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