Bug Summary

File:home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx
Warning:line 1517, column 5
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name toolbox2.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/glm -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/libmount -isystem /usr/include/blkid -isystem /usr/include/cairo -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/pixman-1 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/libxml2 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/dbus-1.0 -isystem /usr/lib64/dbus-1.0/include -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D VCL_DLLIMPLEMENTATION -D DLLIMPLEMENTATION_UITEST -D CUI_DLL_NAME="libcuilo.so" -D DESKTOP_DETECTOR_DLL_NAME="libdesktop_detectorlo.so" -D TK_DLL_NAME="libtklo.so" -D SYSTEM_ZLIB -D GLM_FORCE_CTOR_INIT -D SK_USER_CONFIG_HEADER=</home/maarten/src/libreoffice/core/config_host/config_skia.h> -D SKIA_DLL -D ENABLE_CUPS -D HAVE_VALGRIND_HEADERS -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/epoxy/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/core -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/effects -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/gpu -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/config -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/ports -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/third_party/vulkan -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/tools/gpu -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia -I /home/maarten/src/libreoffice/core/external/skia/inc/ -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/mdds/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/lcms2/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/harfbuzz/src -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/graphite/include -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/pdfium -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/pdfium/public -D COMPONENT_BUILD -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/libpng -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/libjpeg-turbo -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/vcl/inc -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libxml2 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx

/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx

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 <sal/config.h>
21#include <vcl/uitest/logger.hxx>
22#include <sal/log.hxx>
23
24#include <comphelper/processfactory.hxx>
25#include <boost/property_tree/ptree.hpp>
26
27#include <vcl/svapp.hxx>
28#include <vcl/idle.hxx>
29#include <vcl/bitmap.hxx>
30#include <vcl/toolbox.hxx>
31#include <vcl/mnemonic.hxx>
32#include <vcl/menu.hxx>
33#include <vcl/settings.hxx>
34#include <vcl/IconThemeInfo.hxx>
35#include <vcl/commandinfoprovider.hxx>
36
37#include <svdata.hxx>
38#include <brdwin.hxx>
39#include <toolbox.h>
40
41#include <unotools/confignode.hxx>
42#include <tools/json_writer.hxx>
43
44#include <vcl/uitest/uiobject.hxx>
45
46using namespace vcl;
47
48#define TB_SEP_SIZE8 8 // Separator size
49
50
51ImplToolBoxPrivateData::ImplToolBoxPrivateData()
52{
53 meButtonSize = ToolBoxButtonSize::DontCare;
54 mpMenu = VclPtr<PopupMenu>::Create();
55
56 maMenuType = ToolBoxMenuType::NONE;
57 maMenubuttonItem.maItemSize = Size( TB_MENUBUTTON_SIZE12+TB_MENUBUTTON_OFFSET2, TB_MENUBUTTON_SIZE12+TB_MENUBUTTON_OFFSET2 );
58 maMenubuttonItem.meState = TRISTATE_FALSE;
59 mnMenuButtonWidth = TB_MENUBUTTON_SIZE12;
60
61 mbIsLocked = false;
62 mbNativeButtons = false;
63 mbIsPaintLocked = false;
64 mbAssumeDocked = false;
65 mbAssumePopupMode = false;
66 mbAssumeFloating = false;
67 mbKeyInputDisabled = false;
68 mbMenubuttonSelected = false;
69 mbMenubuttonWasLastSelected = false;
70 mbWillUsePopupMode = false;
71 mbDropDownByKeyboard = false;
72}
73
74ImplToolBoxPrivateData::~ImplToolBoxPrivateData()
75{
76 m_pLayoutData.reset();
77 mpMenu.disposeAndClear();
78}
79
80void ImplToolItem::init(sal_uInt16 nItemId, ToolBoxItemBits nItemBits,
81 bool bEmptyBtn)
82{
83 mnId = nItemId;
84 mpWindow = nullptr;
85 mbNonInteractiveWindow = false;
86 mpUserData = nullptr;
87 meType = ToolBoxItemType::BUTTON;
88 mnBits = nItemBits;
89 meState = TRISTATE_FALSE;
90 mbEnabled = true;
91 mbVisible = true;
92 mbEmptyBtn = bEmptyBtn;
93 mbShowWindow = false;
94 mbBreak = false;
95 mnSepSize = TB_SEP_SIZE8;
96 mnDropDownArrowWidth = TB_DROPDOWNARROWWIDTH11;
97 mnImageAngle = 0;
98 mbMirrorMode = false;
99 mbVisibleText = false;
100 mbExpand = false;
101}
102
103ImplToolItem::ImplToolItem()
104{
105 init(0, ToolBoxItemBits::NONE, true);
106}
107
108ImplToolItem::ImplToolItem( sal_uInt16 nItemId, const Image& rImage,
109 ToolBoxItemBits nItemBits ) :
110 maImage( rImage )
111{
112 init(nItemId, nItemBits, false);
113}
114
115ImplToolItem::ImplToolItem( sal_uInt16 nItemId, const OUString& rText,
116 ToolBoxItemBits nItemBits ) :
117 maText( rText )
118{
119 init(nItemId, nItemBits, false);
120}
121
122ImplToolItem::ImplToolItem( sal_uInt16 nItemId, const Image& rImage,
123 const OUString& rText, ToolBoxItemBits nItemBits ) :
124 maImage( rImage ),
125 maText( rText )
126{
127 init(nItemId, nItemBits, false);
128}
129
130Size ImplToolItem::GetSize( bool bHorz, bool bCheckMaxWidth, long maxWidth, const Size& rDefaultSize )
131{
132 Size aSize( rDefaultSize ); // the size of 'standard' toolbox items
133 // non-standard items are eg windows or buttons with text
134
135 if ( (meType == ToolBoxItemType::BUTTON) || (meType == ToolBoxItemType::SPACE) )
136 {
137 aSize = maItemSize;
138
139 if ( mpWindow && bHorz )
140 {
141 // get size of item window and check if it fits
142 // no windows in vertical toolbars (the default is mbShowWindow=false)
143 Size aWinSize = mpWindow->GetSizePixel();
144
145 if (mpWindow->GetStyle() & WB_NOLABEL)
146 // Window wants no label? Then don't check width, it'll be just
147 // clipped.
148 bCheckMaxWidth = false;
149
150 if ( !bCheckMaxWidth || (aWinSize.Width() <= maxWidth) )
151 {
152 aSize.setWidth( aWinSize.Width() );
153 aSize.setHeight( aWinSize.Height() );
154 mbShowWindow = true;
155 }
156 else
157 {
158 if ( mbEmptyBtn )
159 {
160 aSize.setWidth( 0 );
161 aSize.setHeight( 0 );
162 }
163 }
164 }
165 }
166 else if ( meType == ToolBoxItemType::SEPARATOR )
167 {
168 if ( bHorz )
169 {
170 aSize.setWidth( mnSepSize );
171 aSize.setHeight( rDefaultSize.Height() );
172 }
173 else
174 {
175 aSize.setWidth( rDefaultSize.Width() );
176 aSize.setHeight( mnSepSize );
177 }
178 }
179 else if ( meType == ToolBoxItemType::BREAK )
180 {
181 aSize.setWidth( 0 );
182 aSize.setHeight( 0 );
183 }
184
185 return aSize;
186}
187
188void ImplToolItem::DetermineButtonDrawStyle( ButtonType eButtonType, bool& rbImage, bool& rbText ) const
189{
190 if ( meType != ToolBoxItemType::BUTTON )
191 {
192 // no button -> draw nothing
193 rbImage = rbText = false;
194 return;
195 }
196
197 bool bHasImage;
198 bool bHasText;
199
200 // check for image and/or text
201 bHasImage = !!maImage;
202 bHasText = !maText.isEmpty();
203
204 // prefer images if symbolonly buttons are drawn
205 // prefer texts if textonly buttons are drawn
206
207 if ( eButtonType == ButtonType::SYMBOLONLY ) // drawing icons only
208 {
209 if( bHasImage || !bHasText )
210 {
211 rbImage = true;
212 rbText = false;
213 }
214 else
215 {
216 rbImage = false;
217 rbText = true;
218 }
219 }
220 else if ( eButtonType == ButtonType::TEXT ) // drawing text only
221 {
222 if( bHasText || !bHasImage )
223 {
224 rbImage = false;
225 rbText = true;
226 }
227 else
228 {
229 rbImage = true;
230 rbText = false;
231 }
232 }
233 else // drawing icons and text both
234 {
235 rbImage = true;
236 rbText = true;
237 }
238}
239
240tools::Rectangle ImplToolItem::GetDropDownRect( bool bHorz ) const
241{
242 tools::Rectangle aRect;
243 if( (mnBits & ToolBoxItemBits::DROPDOWN) && !maRect.IsEmpty() )
244 {
245 aRect = maRect;
246 if( mbVisibleText && !bHorz )
247 // item will be rotated -> place dropdown to the bottom
248 aRect.SetTop( aRect.Bottom() - mnDropDownArrowWidth );
249 else
250 // place dropdown to the right
251 aRect.SetLeft( aRect.Right() - mnDropDownArrowWidth );
252 }
253 return aRect;
254}
255
256bool ImplToolItem::IsClipped() const
257{
258 return ( meType == ToolBoxItemType::BUTTON && mbVisible && maRect.IsEmpty() );
259}
260
261bool ImplToolItem::IsItemHidden() const
262{
263 return ( meType == ToolBoxItemType::BUTTON && !mbVisible );
264}
265
266void ToolBox::ImplInvalidate( bool bNewCalc, bool bFullPaint )
267{
268 ImplUpdateInputEnable();
269
270 if ( bNewCalc )
271 mbCalc = true;
272
273 if ( bFullPaint )
274 {
275 mbFormat = true;
276
277 // do we need to redraw?
278 if ( IsReallyVisible() && IsUpdateMode() )
279 {
280 Invalidate( tools::Rectangle( mnLeftBorder, mnTopBorder,
281 mnDX-mnRightBorder-1, mnDY-mnBottomBorder-1 ) );
282 mpIdle->Stop();
283 }
284 }
285 else
286 {
287 if ( !mbFormat )
288 {
289 mbFormat = true;
290
291 // do we need to redraw?
292 if ( IsReallyVisible() && IsUpdateMode() )
293 mpIdle->Start();
294 }
295 }
296
297 // request new layout by layoutmanager
298 CallEventListeners( VclEventId::ToolboxFormatChanged );
299}
300
301void ToolBox::ImplUpdateItem( ImplToolItems::size_type nIndex )
302{
303 // do we need to redraw?
304 if ( !(IsReallyVisible() && IsUpdateMode()) )
305 return;
306
307 if ( nIndex == ITEM_NOTFOUND )
308 {
309 // #i52217# no immediate draw as this might lead to paint problems
310 Invalidate( tools::Rectangle( mnLeftBorder, mnTopBorder, mnDX-mnRightBorder-1, mnDY-mnBottomBorder-1 ) );
311 }
312 else
313 {
314 if ( !mbFormat )
315 {
316 // #i52217# no immediate draw as this might lead to paint problems
317 Invalidate( mpData->m_aItems[nIndex].maRect );
318 }
319 else
320 maPaintRect.Union( mpData->m_aItems[nIndex].maRect );
321 }
322}
323
324void ToolBox::Click()
325{
326 CallEventListeners( VclEventId::ToolboxClick );
327 maClickHdl.Call( this );
328 UITestLogger::getInstance().logAction( this, VclEventId::ToolboxClick);
329}
330
331void ToolBox::DoubleClick()
332{
333 CallEventListeners( VclEventId::ToolboxDoubleClick );
334 maDoubleClickHdl.Call( this );
335}
336
337void ToolBox::Activate()
338{
339 mnActivateCount++;
340 CallEventListeners( VclEventId::ToolboxActivate );
341 maActivateHdl.Call( this );
342}
343
344void ToolBox::Deactivate()
345{
346 mnActivateCount--;
347 CallEventListeners( VclEventId::ToolboxDeactivate );
348 maDeactivateHdl.Call( this );
349}
350
351void ToolBox::Highlight()
352{
353 CallEventListeners( VclEventId::ToolboxHighlight );
354}
355
356FactoryFunction ToolBox::GetUITestFactory() const
357{
358 return ToolBoxUIObject::create;
359}
360
361void ToolBox::Select()
362{
363 VclPtr<vcl::Window> xWindow = this;
364
365 CallEventListeners( VclEventId::ToolboxSelect );
366 maSelectHdl.Call( this );
367
368 if ( xWindow->IsDisposed() )
369 return;
370
371 // TODO: GetFloatingWindow in DockingWindow is currently inline, change it to check dockingwrapper
372 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
373 if( pWrapper && pWrapper->GetFloatingWindow() && pWrapper->GetFloatingWindow()->IsInPopupMode() )
374 pWrapper->GetFloatingWindow()->EndPopupMode();
375}
376
377void ToolBox::InsertItem( sal_uInt16 nItemId, const Image& rImage, ToolBoxItemBits nBits, ImplToolItems::size_type nPos )
378{
379 SAL_WARN_IF( !nItemId, "vcl", "ToolBox::InsertItem(): ItemId == 0" )do { if (true && (!nItemId)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "ToolBox::InsertItem(): ItemId == 0"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "379" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId == 0"),
0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId == 0"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "379" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId == 0") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "379" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId == 0"),
0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId == 0"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "379" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
380 SAL_WARN_IF( GetItemPos( nItemId ) != ITEM_NOTFOUND, "vcl",do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "381" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "381" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "381" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "381" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
381 "ToolBox::InsertItem(): ItemId already exists" )do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "381" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "381" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "381" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "381" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
382
383 // create item and add to list
384 mpData->m_aItems.insert( (nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(),
385 ImplToolItem( nItemId, rImage, nBits ) );
386 mpData->ImplClearLayoutData();
387
388 ImplInvalidate( true );
389
390 // Notify
391 ImplToolItems::size_type nNewPos = ( nPos == APPEND ) ? ( mpData->m_aItems.size() - 1 ) : nPos;
392 CallEventListeners( VclEventId::ToolboxItemAdded, reinterpret_cast< void* >(nNewPos ) );
393}
394
395void ToolBox::InsertItem( sal_uInt16 nItemId, const Image& rImage, const OUString& rText, ToolBoxItemBits nBits,
396 ImplToolItems::size_type nPos )
397{
398 SAL_WARN_IF( !nItemId, "vcl", "ToolBox::InsertItem(): ItemId == 0" )do { if (true && (!nItemId)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "ToolBox::InsertItem(): ItemId == 0"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "398" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId == 0"),
0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId == 0"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "398" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId == 0") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "398" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId == 0"),
0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId == 0"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "398" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
399 SAL_WARN_IF( GetItemPos( nItemId ) != ITEM_NOTFOUND, "vcl",do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "400" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "400" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "400" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "400" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
400 "ToolBox::InsertItem(): ItemId already exists" )do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "400" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "400" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "400" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "400" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
401
402 // create item and add to list
403 mpData->m_aItems.insert( (nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(),
404 ImplToolItem( nItemId, rImage, MnemonicGenerator::EraseAllMnemonicChars(rText), nBits ) );
405 mpData->ImplClearLayoutData();
406
407 ImplInvalidate( true );
408
409 // Notify
410 ImplToolItems::size_type nNewPos = ( nPos == APPEND ) ? ( mpData->m_aItems.size() - 1 ) : nPos;
411 CallEventListeners( VclEventId::ToolboxItemAdded, reinterpret_cast< void* >( nNewPos ) );
412}
413
414void ToolBox::InsertItem( sal_uInt16 nItemId, const OUString& rText, ToolBoxItemBits nBits, ImplToolItems::size_type nPos )
415{
416 SAL_WARN_IF( !nItemId, "vcl", "ToolBox::InsertItem(): ItemId == 0" )do { if (true && (!nItemId)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "ToolBox::InsertItem(): ItemId == 0"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "416" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId == 0"),
0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId == 0"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "416" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId == 0") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "416" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId == 0"),
0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId == 0"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "416" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
417 SAL_WARN_IF( GetItemPos( nItemId ) != ITEM_NOTFOUND, "vcl",do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "418" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "418" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "418" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "418" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
418 "ToolBox::InsertItem(): ItemId already exists" )do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "418" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "418" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertItem(): ItemId already exists") ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "418" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "418" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
419
420 // create item and add to list
421 mpData->m_aItems.insert( (nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(),
422 ImplToolItem( nItemId, MnemonicGenerator::EraseAllMnemonicChars(rText), nBits ) );
423 mpData->ImplClearLayoutData();
424
425 ImplInvalidate( true );
426
427 // Notify
428 ImplToolItems::size_type nNewPos = ( nPos == APPEND ) ? ( mpData->m_aItems.size() - 1 ) : nPos;
429 CallEventListeners( VclEventId::ToolboxItemAdded, reinterpret_cast< void* >( nNewPos ) );
430}
431
432void ToolBox::InsertItem(const OUString& rCommand, const css::uno::Reference<css::frame::XFrame>& rFrame, ToolBoxItemBits nBits,
433 const Size& rRequestedSize, ImplToolItems::size_type nPos)
434{
435 OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(rFrame));
436 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(rCommand, aModuleName);
437 OUString aLabel(vcl::CommandInfoProvider::GetLabelForCommand(aProperties));
438 OUString aTooltip(vcl::CommandInfoProvider::GetTooltipForCommand(rCommand, aProperties, rFrame));
439 Image aImage(CommandInfoProvider::GetImageForCommand(rCommand, rFrame, GetImageSize()));
440
441 sal_uInt16 nItemId = GetItemCount() + 1;
442 //TODO: ImplToolItems::size_type -> sal_uInt16!
443 InsertItem(nItemId, aImage, aLabel, nBits, nPos);
444 SetItemCommand(nItemId, rCommand);
445 SetQuickHelpText(nItemId, aTooltip);
446
447 // set the minimal size
448 ImplToolItem* pItem = ImplGetItem( nItemId );
449 if ( pItem )
450 pItem->maMinimalItemSize = rRequestedSize;
451}
452
453void ToolBox::InsertWindow( sal_uInt16 nItemId, vcl::Window* pWindow,
454 ToolBoxItemBits nBits, ImplToolItems::size_type nPos )
455{
456 SAL_WARN_IF( !nItemId, "vcl", "ToolBox::InsertWindow(): ItemId == 0" )do { if (true && (!nItemId)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "ToolBox::InsertWindow(): ItemId == 0"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "456" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertWindow(): ItemId == 0"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertWindow(): ItemId == 0"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "456" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertWindow(): ItemId == 0") == 1) { ::
sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "456" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertWindow(): ItemId == 0"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertWindow(): ItemId == 0"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "456" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
457 SAL_WARN_IF( GetItemPos( nItemId ) != ITEM_NOTFOUND, "vcl",do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertWindow(): ItemId already exists")
== 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "458" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertWindow(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertWindow(): ItemId already exists"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "458" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertWindow(): ItemId already exists")
== 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "458" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertWindow(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertWindow(): ItemId already exists"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "458" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
458 "ToolBox::InsertWindow(): ItemId already exists" )do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertWindow(): ItemId already exists")
== 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "458" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertWindow(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertWindow(): ItemId already exists"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "458" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::InsertWindow(): ItemId already exists")
== 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "458" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::InsertWindow(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::InsertWindow(): ItemId already exists"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "458" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
459
460 // create item and add to list
461 ImplToolItem aItem;
462 aItem.mnId = nItemId;
463 aItem.meType = ToolBoxItemType::BUTTON;
464 aItem.mnBits = nBits;
465 aItem.mpWindow = pWindow;
466 mpData->m_aItems.insert( (nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(), aItem );
467 mpData->ImplClearLayoutData();
468
469 if ( pWindow )
470 pWindow->Hide();
471
472 ImplInvalidate( true );
473
474 // Notify
475 ImplToolItems::size_type nNewPos = ( nPos == APPEND ) ? ( mpData->m_aItems.size() - 1 ) : nPos;
476 CallEventListeners( VclEventId::ToolboxItemAdded, reinterpret_cast< void* >( nNewPos ) );
477}
478
479void ToolBox::InsertSpace()
480{
481 // create item and add to list
482 ImplToolItem aItem;
483 aItem.meType = ToolBoxItemType::SPACE;
484 aItem.mbEnabled = false;
485 mpData->m_aItems.push_back( aItem );
486 mpData->ImplClearLayoutData();
487
488 ImplInvalidate();
489
490 // Notify
491 ImplToolItems::size_type nNewPos = mpData->m_aItems.size() - 1;
492 CallEventListeners( VclEventId::ToolboxItemAdded, reinterpret_cast< void* >( nNewPos ) );
493}
494
495void ToolBox::InsertSeparator( ImplToolItems::size_type nPos, sal_uInt16 nPixSize )
496{
497 // create item and add to list
498 ImplToolItem aItem;
499 aItem.meType = ToolBoxItemType::SEPARATOR;
500 aItem.mbEnabled = false;
501 if ( nPixSize )
502 aItem.mnSepSize = nPixSize;
503 mpData->m_aItems.insert( (nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(), aItem );
504 mpData->ImplClearLayoutData();
505
506 ImplInvalidate();
507
508 // Notify
509 ImplToolItems::size_type nNewPos = ( nPos == APPEND ) ? ( mpData->m_aItems.size() - 1 ) : nPos;
510 CallEventListeners( VclEventId::ToolboxItemAdded, reinterpret_cast< void* >( nNewPos ) );
511}
512
513void ToolBox::InsertBreak( ImplToolItems::size_type nPos )
514{
515 // create item and add to list
516 ImplToolItem aItem;
517 aItem.meType = ToolBoxItemType::BREAK;
518 aItem.mbEnabled = false;
519 mpData->m_aItems.insert( (nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(), aItem );
520 mpData->ImplClearLayoutData();
521
522 ImplInvalidate();
523
524 // Notify
525 ImplToolItems::size_type nNewPos = ( nPos == APPEND ) ? ( mpData->m_aItems.size() - 1 ) : nPos;
526 CallEventListeners( VclEventId::ToolboxItemAdded, reinterpret_cast< void* >( nNewPos ) );
527}
528
529void ToolBox::RemoveItem( ImplToolItems::size_type nPos )
530{
531 if( nPos >= mpData->m_aItems.size() )
532 return;
533
534 bool bMustCalc;
535 bMustCalc = mpData->m_aItems[nPos].meType == ToolBoxItemType::BUTTON;
536
537 if ( mpData->m_aItems[nPos].mpWindow )
538 mpData->m_aItems[nPos].mpWindow->Hide();
539
540 // add the removed item to PaintRect
541 maPaintRect.Union( mpData->m_aItems[nPos].maRect );
542
543 // ensure not to delete in the Select-Handler
544 if ( mpData->m_aItems[nPos].mnId == mnCurItemId )
545 mnCurItemId = 0;
546 if ( mpData->m_aItems[nPos].mnId == mnHighItemId )
547 mnHighItemId = 0;
548
549 ImplInvalidate( bMustCalc );
550
551 mpData->m_aItems.erase( mpData->m_aItems.begin()+nPos );
552 mpData->ImplClearLayoutData();
553
554 // Notify
555 CallEventListeners( VclEventId::ToolboxItemRemoved, reinterpret_cast< void* >( nPos ) );
556}
557
558void ToolBox::CopyItem( const ToolBox& rToolBox, sal_uInt16 nItemId )
559{
560 SAL_WARN_IF( GetItemPos( nItemId ) != ITEM_NOTFOUND, "vcl",do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::CopyItem(): ItemId already exists") == 1
) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"),
("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "561" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::CopyItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::CopyItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "561" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::CopyItem(): ItemId already exists") == 1
) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"),
("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "561" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::CopyItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::CopyItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "561" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
561 "ToolBox::CopyItem(): ItemId already exists" )do { if (true && (GetItemPos( nItemId ) != ITEM_NOTFOUND
)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::CopyItem(): ItemId already exists") == 1
) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"),
("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "561" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::CopyItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::CopyItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "561" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ToolBox::CopyItem(): ItemId already exists") == 1
) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"),
("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "561" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ToolBox::CopyItem(): ItemId already exists"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ToolBox::CopyItem(): ItemId already exists"; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "561" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
562
563 ImplToolItems::size_type nPos = rToolBox.GetItemPos( nItemId );
564
565 // found item
566 if ( nPos == ITEM_NOTFOUND )
567 return;
568
569 // push ToolBox item onto the list
570 ImplToolItem aNewItem = rToolBox.mpData->m_aItems[nPos];
571 // reset state
572 aNewItem.mpWindow = nullptr;
573 aNewItem.mbShowWindow = false;
574
575 mpData->m_aItems.push_back( aNewItem );
576 mpData->ImplClearLayoutData();
577 // redraw ToolBox
578 ImplInvalidate();
579
580 // Notify
581 ImplToolItems::size_type nNewPos2 = mpData->m_aItems.size() - 1;
582 CallEventListeners( VclEventId::ToolboxItemAdded, reinterpret_cast< void* >( nNewPos2 ) );
583}
584
585void ToolBox::Clear()
586{
587 mpData->m_aItems.clear();
588 mpData->ImplClearLayoutData();
589
590 // ensure not to delete in the Select-Handler
591 mnCurItemId = 0;
592 mnHighItemId = 0;
593
594 ImplInvalidate( true, true );
595
596 // Notify
597 CallEventListeners( VclEventId::ToolboxAllItemsChanged );
598}
599
600void ToolBox::SetButtonType( ButtonType eNewType )
601{
602 if ( meButtonType != eNewType )
603 {
604 meButtonType = eNewType;
605
606 // better redraw everything, as otherwise there might be problems
607 // with regions that were copied with CopyBits
608 ImplInvalidate( true );
609 }
610}
611
612void ToolBox::SetToolboxButtonSize( ToolBoxButtonSize eSize )
613{
614 if( mpData->meButtonSize != eSize )
615 {
616 mpData->meButtonSize = eSize;
617 mbCalc = true;
618 mbFormat = true;
619 }
620}
621
622ToolBoxButtonSize ToolBox::GetToolboxButtonSize() const
623{
624 return mpData->meButtonSize;
625}
626
627ImageType ToolBox::GetImageSize() const
628{
629 ImageType eImageType = ImageType::Size16;
630 if (mpData->meButtonSize == ToolBoxButtonSize::Large)
631 eImageType = ImageType::Size26;
632 else if (mpData->meButtonSize == ToolBoxButtonSize::Size32)
633 eImageType = ImageType::Size32;
634
635 return eImageType;
636}
637
638/*static*/ Size ToolBox::GetDefaultImageSize(ToolBoxButtonSize eToolBoxButtonSize)
639{
640 OutputDevice *pDefault = Application::GetDefaultDevice();
641 float fScaleFactor = pDefault ? pDefault->GetDPIScaleFactor() : 1.0;
642
643 Size aUnscaledSize(16, 16);
644
645 if (eToolBoxButtonSize == ToolBoxButtonSize::Large)
646 {
647 OUString iconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
648 aUnscaledSize = vcl::IconThemeInfo::SizeByThemeName(iconTheme);
649 }
650 else if (eToolBoxButtonSize == ToolBoxButtonSize::Size32)
651 {
652 aUnscaledSize = Size(32, 32);
653 }
654 return Size(aUnscaledSize.Width() * fScaleFactor,
655 aUnscaledSize.Height() * fScaleFactor);
656}
657
658Size ToolBox::GetDefaultImageSize() const
659{
660 return GetDefaultImageSize(GetToolboxButtonSize());
661}
662
663void ToolBox::SetAlign( WindowAlign eNewAlign )
664{
665 if ( meAlign == eNewAlign )
666 return;
667
668 meAlign = eNewAlign;
669
670 if ( ImplIsFloatingMode() )
671 return;
672
673 // set horizontal/vertical alignment
674 if ( (eNewAlign == WindowAlign::Left) || (eNewAlign == WindowAlign::Right) )
675 mbHorz = false;
676 else
677 mbHorz = true;
678
679 // Update the background according to Persona if necessary
680 ImplInitSettings( false, false, true );
681
682 // redraw everything, as the border has changed
683 mbCalc = true;
684 mbFormat = true;
685 if ( IsReallyVisible() && IsUpdateMode() )
686 Invalidate();
687}
688
689void ToolBox::SetLineCount( ImplToolItems::size_type nNewLines )
690{
691 if ( !nNewLines )
692 nNewLines = 1;
693
694 if ( mnLines != nNewLines )
695 {
696 mnLines = nNewLines;
697
698 // better redraw everything, as otherwise there might be problems
699 // with regions that were copied with CopyBits
700 Invalidate();
701 }
702}
703
704ToolBox::ImplToolItems::size_type ToolBox::GetItemCount() const
705{
706 return mpData ? mpData->m_aItems.size() : 0;
707}
708
709ToolBoxItemType ToolBox::GetItemType( ImplToolItems::size_type nPos ) const
710{
711 return (nPos < mpData->m_aItems.size()) ? mpData->m_aItems[nPos].meType : ToolBoxItemType::DONTKNOW;
712}
713
714ToolBox::ImplToolItems::size_type ToolBox::GetItemPos( sal_uInt16 nItemId ) const
715{
716 if (mpData)
717 {
718 ImplToolItems::size_type nCount = mpData->m_aItems.size();
719 for( ImplToolItems::size_type nPos = 0; nPos < nCount; nPos++ )
720 if( mpData->m_aItems[nPos].mnId == nItemId )
721 return nPos;
722 }
723 return ITEM_NOTFOUND;
724}
725
726ToolBox::ImplToolItems::size_type ToolBox::GetItemPos( const Point& rPos ) const
727{
728 // search the item position on the given point
729 auto it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
730 [&rPos](const ImplToolItem& rItem) { return rItem.maRect.IsInside( rPos ); });
731
732 if( it != mpData->m_aItems.end() )
733 return std::distance(mpData->m_aItems.begin(), it);
734
735 return ITEM_NOTFOUND;
736}
737
738sal_uInt16 ToolBox::GetItemId( ImplToolItems::size_type nPos ) const
739{
740 return (nPos < mpData->m_aItems.size()) ? mpData->m_aItems[nPos].mnId : 0;
741}
742
743sal_uInt16 ToolBox::GetItemId( const Point& rPos ) const
744{
745 // find item that was clicked
746 auto it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
747 [&rPos](const ImplToolItem& rItem) { return rItem.maRect.IsInside( rPos ); });
748
749 if( (it != mpData->m_aItems.end()) && (it->meType == ToolBoxItemType::BUTTON) )
750 return it->mnId;
751
752 return 0;
753}
754
755Size ToolBox::GetItemContentSize( sal_uInt16 nItemId )
756{
757 if ( mbCalc || mbFormat )
758 ImplFormat();
759
760 ImplToolItems::size_type nPos = GetItemPos( nItemId );
761 if ( nPos < mpData->m_aItems.size() )
762 return mpData->m_aItems[nPos].maContentSize;
763 else
764 return Size();
765}
766
767sal_uInt16 ToolBox::GetItemId(const OUString &rCommand) const
768{
769 if (!mpData)
770 return 0;
771
772 auto it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(),
773 [&rCommand](const ImplToolItem& rItem) { return rItem.maCommandStr == rCommand; });
774 if (it != mpData->m_aItems.end())
775 return it->mnId;
776
777 return 0;
778}
779
780Point ToolBox::ImplGetPopupPosition( const tools::Rectangle& rRect ) const
781{
782 Point aPos;
783 if( !rRect.IsEmpty() )
784 {
785 tools::Rectangle aScreen = GetDesktopRectPixel();
786
787 // the popup should be positioned so that it will not cover
788 // the item rect and that it fits the desktop
789 // the preferred direction is always towards the center of
790 // the application window
791
792 Point devPos; // the position in device coordinates for screen comparison
793 switch( meAlign )
794 {
795 case WindowAlign::Top:
796 aPos = rRect.BottomLeft();
797 aPos.AdjustY( 1 );
798 devPos = OutputToAbsoluteScreenPixel( aPos );
799 if( devPos.Y() >= aScreen.Bottom() )
800 aPos.setY( rRect.Top() );
801 break;
802 case WindowAlign::Bottom:
803 aPos = rRect.TopLeft();
804 aPos.AdjustY( -1 );
805 devPos = OutputToAbsoluteScreenPixel( aPos );
806 if( devPos.Y() <= aScreen.Top() )
807 aPos.setY( rRect.Bottom() );
808 break;
809 case WindowAlign::Left:
810 aPos = rRect.TopRight();
811 aPos.AdjustX( 1 );
812 devPos = OutputToAbsoluteScreenPixel( aPos );
813 if( devPos.X() >= aScreen.Right() )
814 aPos.setX( rRect.Left() );
815 break;
816 case WindowAlign::Right:
817 aPos = rRect.TopLeft();
818 aPos.AdjustX( -1 );
819 devPos = OutputToAbsoluteScreenPixel( aPos );
820 if( devPos.X() <= aScreen.Left() )
821 aPos.setX( rRect.Right() );
822 break;
823 default:
824 break;
825 }
826 }
827 return aPos;
828}
829
830tools::Rectangle ToolBox::GetItemRect( sal_uInt16 nItemId )
831{
832 if ( mbCalc || mbFormat )
833 ImplFormat();
834
835 ImplToolItems::size_type nPos = GetItemPos( nItemId );
836 return GetItemPosRect( nPos );
837}
838
839tools::Rectangle ToolBox::GetItemPosRect( ImplToolItems::size_type nPos )
840{
841 if ( mbCalc || mbFormat )
842 ImplFormat();
843
844 if ( nPos < mpData->m_aItems.size() )
845 return mpData->m_aItems[nPos].maRect;
846 else
847 return tools::Rectangle();
848}
849
850tools::Rectangle const & ToolBox::GetOverflowRect() const
851{
852 return mpData->maMenubuttonItem.maRect;
853}
854
855bool ToolBox::ImplHasExternalMenubutton()
856{
857 // check if the borderwindow (i.e. the decoration) provides the menu button
858 bool bRet = false;
859 if( ImplIsFloatingMode() )
860 {
861 // custom menu is placed in the decoration
862 ImplBorderWindow *pBorderWin = dynamic_cast<ImplBorderWindow*>( GetWindow( GetWindowType::Border ) );
863 if( pBorderWin && !pBorderWin->GetMenuRect().IsEmpty() )
864 bRet = true;
865 }
866 return bRet;
867}
868
869void ToolBox::SetItemBits( sal_uInt16 nItemId, ToolBoxItemBits nBits )
870{
871 ImplToolItems::size_type nPos = GetItemPos( nItemId );
872
873 if ( nPos < GetItemCount() )
874 {
875 ToolBoxItemBits nOldBits = mpData->m_aItems[nPos].mnBits;
876 mpData->m_aItems[nPos].mnBits = nBits;
877 nBits &= ToolBoxItemBits::LEFT | ToolBoxItemBits::AUTOSIZE | ToolBoxItemBits::DROPDOWN;
878 nOldBits &= ToolBoxItemBits::LEFT | ToolBoxItemBits::AUTOSIZE | ToolBoxItemBits::DROPDOWN;
879 // trigger reformat when the item width has changed (dropdown arrow)
880 bool bFormat = ToolBoxItemBits(nBits & ToolBoxItemBits::DROPDOWN) != ToolBoxItemBits(nOldBits & ToolBoxItemBits::DROPDOWN);
881 if ( nBits != nOldBits )
882 ImplInvalidate( true, bFormat );
883 }
884}
885
886void ToolBox::SetItemWindowNonInteractive(sal_uInt16 nItemId, bool bNonInteractive)
887{
888 ImplToolItems::size_type nPos = GetItemPos( nItemId );
889
890 if ( nPos < GetItemCount() )
891 {
892 mpData->m_aItems[nPos].mbNonInteractiveWindow = bNonInteractive;
893 }
894}
895
896ToolBoxItemBits ToolBox::GetItemBits( sal_uInt16 nItemId ) const
897{
898 ImplToolItem* pItem = ImplGetItem( nItemId );
899
900 if ( pItem )
901 return pItem->mnBits;
902 else
903 return ToolBoxItemBits::NONE;
904}
905
906void ToolBox::SetItemExpand( sal_uInt16 nItemId, bool bExpand )
907{
908 ImplToolItem* pItem = ImplGetItem( nItemId );
909 if (!pItem)
910 return;
911
912 if (pItem->mbExpand != bExpand)
913 {
914 pItem->mbExpand = bExpand;
915 ImplInvalidate(true, true);
916 }
917}
918
919void ToolBox::SetItemData( sal_uInt16 nItemId, void* pNewData )
920{
921 ImplToolItems::size_type nPos = GetItemPos( nItemId );
922
923 if ( nPos < mpData->m_aItems.size() )
924 {
925 mpData->m_aItems[nPos].mpUserData = pNewData;
926 ImplUpdateItem( nPos );
927 }
928}
929
930void* ToolBox::GetItemData( sal_uInt16 nItemId ) const
931{
932 ImplToolItem* pItem = ImplGetItem( nItemId );
933
934 if ( pItem )
935 return pItem->mpUserData;
936 else
937 return nullptr;
938}
939
940void ToolBox::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
941{
942 ImplToolItems::size_type nPos = GetItemPos( nItemId );
943
944 if ( nPos == ITEM_NOTFOUND )
945 return;
946
947 ImplToolItem* pItem = &mpData->m_aItems[nPos];
948 Size aOldSize = pItem->maImage.GetSizePixel();
949
950 pItem->maImage = rImage;
951
952 // only once all is calculated, do extra work
953 if (!mbCalc)
954 {
955 if (aOldSize != pItem->maImage.GetSizePixel())
956 ImplInvalidate( true );
957 else
958 ImplUpdateItem( nPos );
959 }
960}
961
962static Image ImplRotImage( const Image& rImage, long nAngle10 )
963{
964 BitmapEx aRotBitmapEx( rImage.GetBitmapEx() );
965
966 aRotBitmapEx.Rotate( nAngle10, COL_WHITE );
967
968 return Image( aRotBitmapEx );
969}
970
971void ToolBox::SetItemImageAngle( sal_uInt16 nItemId, long nAngle10 )
972{
973 ImplToolItems::size_type nPos = GetItemPos( nItemId );
974
975 if ( nPos == ITEM_NOTFOUND )
976 return;
977
978 ImplToolItem* pItem = &mpData->m_aItems[nPos];
979 Size aOldSize = pItem->maImage.GetSizePixel();
980
981 long nDeltaAngle = (nAngle10 - pItem->mnImageAngle) % 3600;
982 while( nDeltaAngle < 0 )
983 nDeltaAngle += 3600;
984
985 pItem->mnImageAngle = nAngle10;
986 if( nDeltaAngle && !!pItem->maImage )
987 {
988 pItem->maImage = ImplRotImage( pItem->maImage, nDeltaAngle );
989 }
990
991 if (!mbCalc)
992 {
993 if (aOldSize != pItem->maImage.GetSizePixel())
994 ImplInvalidate(true);
995 else
996 ImplUpdateItem(nPos);
997 }
998}
999
1000static Image ImplMirrorImage( const Image& rImage )
1001{
1002 BitmapEx aMirrBitmapEx( rImage.GetBitmapEx() );
1003
1004 aMirrBitmapEx.Mirror( BmpMirrorFlags::Horizontal );
1005
1006 return Image( aMirrBitmapEx );
1007}
1008
1009void ToolBox::SetItemImageMirrorMode( sal_uInt16 nItemId, bool bMirror )
1010{
1011 ImplToolItems::size_type nPos = GetItemPos( nItemId );
1012
1013 if ( nPos == ITEM_NOTFOUND )
1014 return;
1015
1016 ImplToolItem* pItem = &mpData->m_aItems[nPos];
1017
1018 if (pItem->mbMirrorMode != bMirror)
1019 {
1020 pItem->mbMirrorMode = bMirror;
1021 if (!!pItem->maImage)
1022 {
1023 pItem->maImage = ImplMirrorImage(pItem->maImage);
1024 }
1025
1026 if (!mbCalc)
1027 ImplUpdateItem(nPos);
1028 }
1029}
1030
1031Image ToolBox::GetItemImage(sal_uInt16 nItemId) const
1032{
1033 ImplToolItem* pItem = ImplGetItem(nItemId);
1034 return pItem ? pItem->maImage : Image();
1035}
1036
1037void ToolBox::SetItemText( sal_uInt16 nItemId, const OUString& rText )
1038{
1039 ImplToolItems::size_type nPos = GetItemPos( nItemId );
1040
1041 if ( nPos == ITEM_NOTFOUND )
1042 return;
1043
1044 ImplToolItem* pItem = &mpData->m_aItems[nPos];
1045 // only once all is calculated, do extra work
1046 if ( !mbCalc &&
1047 ((meButtonType != ButtonType::SYMBOLONLY) || !pItem->maImage) )
1048 {
1049 long nOldWidth = GetCtrlTextWidth( pItem->maText );
1050 pItem->maText = MnemonicGenerator::EraseAllMnemonicChars(rText);
1051 mpData->ImplClearLayoutData();
1052 if ( nOldWidth != GetCtrlTextWidth( pItem->maText ) )
1053 ImplInvalidate( true );
1054 else
1055 ImplUpdateItem( nPos );
1056 }
1057 else
1058 pItem->maText = MnemonicGenerator::EraseAllMnemonicChars(rText);
1059
1060 // Notify button changed event to prepare accessibility bridge
1061 CallEventListeners( VclEventId::ToolboxButtonStateChanged, reinterpret_cast< void* >( nPos ) );
1062
1063 // Notify
1064 CallEventListeners( VclEventId::ToolboxItemTextChanged, reinterpret_cast< void* >( nPos ) );
1065}
1066
1067const OUString& ToolBox::GetItemText( sal_uInt16 nItemId ) const
1068{
1069
1070 ImplToolItem* pItem = ImplGetItem( nItemId );
1071
1072 assert( pItem )(static_cast <bool> (pItem) ? void (0) : __assert_fail (
"pItem", "/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
, 1072, __extension__ __PRETTY_FUNCTION__))
;
1073
1074 return pItem->maText;
1075}
1076
1077void ToolBox::SetItemWindow( sal_uInt16 nItemId, vcl::Window* pNewWindow )
1078{
1079 ImplToolItems::size_type nPos = GetItemPos( nItemId );
1080
1081 if ( nPos != ITEM_NOTFOUND )
1082 {
1083 ImplToolItem* pItem = &mpData->m_aItems[nPos];
1084 pItem->mpWindow = pNewWindow;
1085 if ( pNewWindow )
1086 pNewWindow->Hide();
1087 ImplInvalidate( true );
1088 CallEventListeners( VclEventId::ToolboxItemWindowChanged, reinterpret_cast< void* >( nPos ) );
1089 }
1090}
1091
1092vcl::Window* ToolBox::GetItemWindow( sal_uInt16 nItemId ) const
1093{
1094 ImplToolItem* pItem = ImplGetItem( nItemId );
1095
1096 if ( pItem )
1097 return pItem->mpWindow;
1098 else
1099 return nullptr;
1100}
1101
1102void ToolBox::EndSelection()
1103{
1104 if ( mbDrag )
1105 {
1106 // reset
1107 mbDrag = false;
1108 if (mnCurPos != ITEM_NOTFOUND)
1109 InvalidateItem(mnCurPos);
1110 EndTracking();
1111 if (IsMouseCaptured())
1112 ReleaseMouse();
1113 Deactivate();
1114 }
1115
1116 mnCurPos = ITEM_NOTFOUND;
1117 mnCurItemId = 0;
1118 mnDownItemId = 0;
1119 mnMouseModifier = 0;
1120}
1121
1122void ToolBox::SetItemDown( sal_uInt16 nItemId, bool bDown )
1123{
1124 ImplToolItems::size_type nPos = GetItemPos( nItemId );
1125
1126 if ( nPos == ITEM_NOTFOUND )
1127 return;
1128
1129 if ( bDown )
1130 {
1131 if ( nPos != mnCurPos )
1132 {
1133 mnCurPos = nPos;
1134 InvalidateItem(mnCurPos);
1135 Flush();
1136 }
1137 }
1138 else
1139 {
1140 if ( nPos == mnCurPos )
1141 {
1142 InvalidateItem(mnCurPos);
1143 Flush();
1144 mnCurPos = ITEM_NOTFOUND;
1145 }
1146 }
1147
1148 if ( mbDrag )
1149 {
1150 mbDrag = false;
1151 EndTracking();
1152 if (IsMouseCaptured())
1153 ReleaseMouse();
1154 Deactivate();
1155 }
1156
1157 mnCurItemId = 0;
1158 mnDownItemId = 0;
1159 mnMouseModifier = 0;
1160}
1161
1162void ToolBox::SetItemState( sal_uInt16 nItemId, TriState eState )
1163{
1164 ImplToolItems::size_type nPos = GetItemPos( nItemId );
1165
1166 if ( nPos == ITEM_NOTFOUND )
1167 return;
1168
1169 ImplToolItem* pItem = &mpData->m_aItems[nPos];
1170
1171 // the state has changed
1172 if ( pItem->meState == eState )
1173 return;
1174
1175 // if RadioCheck, un-check the previous
1176 if ( (eState == TRISTATE_TRUE) && (pItem->mnBits & ToolBoxItemBits::AUTOCHECK) &&
1177 (pItem->mnBits & ToolBoxItemBits::RADIOCHECK) )
1178 {
1179 ImplToolItem* pGroupItem;
1180 ImplToolItems::size_type nGroupPos;
1181 ImplToolItems::size_type nItemCount = GetItemCount();
1182
1183 nGroupPos = nPos;
1184 while ( nGroupPos )
1185 {
1186 pGroupItem = &mpData->m_aItems[nGroupPos-1];
1187 if ( pGroupItem->mnBits & ToolBoxItemBits::RADIOCHECK )
1188 {
1189 if ( pGroupItem->meState != TRISTATE_FALSE )
1190 SetItemState( pGroupItem->mnId, TRISTATE_FALSE );
1191 }
1192 else
1193 break;
1194 nGroupPos--;
1195 }
1196
1197 nGroupPos = nPos+1;
1198 while ( nGroupPos < nItemCount )
1199 {
1200 pGroupItem = &mpData->m_aItems[nGroupPos];
1201 if ( pGroupItem->mnBits & ToolBoxItemBits::RADIOCHECK )
1202 {
1203 if ( pGroupItem->meState != TRISTATE_FALSE )
1204 SetItemState( pGroupItem->mnId, TRISTATE_FALSE );
1205 }
1206 else
1207 break;
1208 nGroupPos++;
1209 }
1210 }
1211
1212 pItem->meState = eState;
1213 ImplUpdateItem( nPos );
1214
1215 // Notify button changed event to prepare accessibility bridge
1216 CallEventListeners( VclEventId::ToolboxButtonStateChanged, reinterpret_cast< void* >( nPos ) );
1217
1218 // Call accessible listener to notify state_changed event
1219 CallEventListeners( VclEventId::ToolboxItemUpdated, reinterpret_cast< void* >(nPos) );
1220}
1221
1222TriState ToolBox::GetItemState( sal_uInt16 nItemId ) const
1223{
1224 ImplToolItem* pItem = ImplGetItem( nItemId );
1225
1226 if ( pItem )
1227 return pItem->meState;
1228 else
1229 return TRISTATE_FALSE;
1230}
1231
1232void ToolBox::EnableItem( sal_uInt16 nItemId, bool bEnable )
1233{
1234 ImplToolItems::size_type nPos = GetItemPos( nItemId );
1235
1236 if ( nPos == ITEM_NOTFOUND )
1237 return;
1238
1239 ImplToolItem* pItem = &mpData->m_aItems[nPos];
1240 if ( pItem->mbEnabled == bEnable )
1241 return;
1242
1243 pItem->mbEnabled = bEnable;
1244
1245 // if existing, also redraw the window
1246 if ( pItem->mpWindow )
1247 pItem->mpWindow->Enable( pItem->mbEnabled );
1248
1249 // update item
1250 ImplUpdateItem( nPos );
1251
1252 ImplUpdateInputEnable();
1253
1254 // Notify button changed event to prepare accessibility bridge
1255 CallEventListeners( VclEventId::ToolboxButtonStateChanged, reinterpret_cast< void* >( nPos ) );
1256
1257 CallEventListeners( bEnable ? VclEventId::ToolboxItemEnabled : VclEventId::ToolboxItemDisabled, reinterpret_cast< void* >( nPos ) );
1258}
1259
1260bool ToolBox::IsItemEnabled( sal_uInt16 nItemId ) const
1261{
1262 ImplToolItem* pItem = ImplGetItem( nItemId );
1263
1264 if ( pItem )
1265 return pItem->mbEnabled;
1266 else
1267 return false;
1268}
1269
1270void ToolBox::ShowItem( sal_uInt16 nItemId, bool bVisible )
1271{
1272 ImplToolItems::size_type nPos = GetItemPos( nItemId );
1273 mpData->ImplClearLayoutData();
1274
1275 if ( nPos != ITEM_NOTFOUND )
1276 {
1277 ImplToolItem* pItem = &mpData->m_aItems[nPos];
1278 if ( pItem->mbVisible != bVisible )
1279 {
1280 pItem->mbVisible = bVisible;
1281 ImplInvalidate();
1282 }
1283 }
1284}
1285
1286bool ToolBox::IsItemClipped( sal_uInt16 nItemId ) const
1287{
1288 ImplToolItem* pItem = ImplGetItem( nItemId );
1289
1290 if ( pItem )
1291 return pItem->IsClipped();
1292 else
1293 return false;
1294}
1295
1296bool ToolBox::IsItemVisible( sal_uInt16 nItemId ) const
1297{
1298 ImplToolItem* pItem = ImplGetItem( nItemId );
1299
1300 if ( pItem )
1301 return pItem->mbVisible;
1302 else
1303 return false;
1304}
1305
1306bool ToolBox::IsItemReallyVisible( sal_uInt16 nItemId ) const
1307{
1308 // is the item on the visible area of the toolbox?
1309 bool bRet = false;
1310 tools::Rectangle aRect( mnLeftBorder, mnTopBorder, mnDX-mnRightBorder, mnDY-mnBottomBorder );
1311 ImplToolItem* pItem = ImplGetItem( nItemId );
1312
1313 if ( pItem && pItem->mbVisible &&
1314 !pItem->maRect.IsEmpty() && aRect.IsOver( pItem->maRect ) )
1315 {
1316 bRet = true;
1317 }
1318
1319 return bRet;
1320}
1321
1322void ToolBox::SetItemCommand(sal_uInt16 nItemId, const OUString& rCommand)
1323{
1324 ImplToolItem* pItem = ImplGetItem( nItemId );
1325
1326 if (pItem)
1327 pItem->maCommandStr = rCommand;
1328}
1329
1330OUString ToolBox::GetItemCommand( sal_uInt16 nItemId ) const
1331{
1332 ImplToolItem* pItem = ImplGetItem( nItemId );
1333
1334 if (pItem)
1335 return pItem->maCommandStr;
1336
1337 return OUString();
1338}
1339
1340void ToolBox::SetQuickHelpText( sal_uInt16 nItemId, const OUString& rText )
1341{
1342 ImplToolItem* pItem = ImplGetItem( nItemId );
1343
1344 if ( pItem )
1345 pItem->maQuickHelpText = rText;
1346}
1347
1348OUString ToolBox::GetQuickHelpText( sal_uInt16 nItemId ) const
1349{
1350 ImplToolItem* pItem = ImplGetItem( nItemId );
1351
1352 if ( pItem )
1353 return pItem->maQuickHelpText;
1354 else
1355 return OUString();
1356}
1357
1358void ToolBox::SetHelpText( sal_uInt16 nItemId, const OUString& rText )
1359{
1360 ImplToolItem* pItem = ImplGetItem( nItemId );
1361
1362 if ( pItem )
1363 pItem->maHelpText = rText;
1364}
1365
1366const OUString& ToolBox::GetHelpText( sal_uInt16 nItemId ) const
1367{
1368 return ImplGetHelpText( nItemId );
1369}
1370
1371void ToolBox::SetHelpId( sal_uInt16 nItemId, const OString& rHelpId )
1372{
1373 ImplToolItem* pItem = ImplGetItem( nItemId );
1374
1375 if ( pItem )
1376 pItem->maHelpId = rHelpId;
1377}
1378
1379void ToolBox::SetOutStyle( sal_uInt16 nNewStyle )
1380{
1381 // always force flat looking toolbars since NWF
1382 nNewStyle |= TOOLBOX_STYLE_FLAT;
1383
1384 if ( mnOutStyle == nNewStyle )
1385 return;
1386
1387 mnOutStyle = nNewStyle;
1388 ImplDisableFlatButtons();
1389
1390 // so as to redo the ButtonDevice
1391 if ( !(mnOutStyle & TOOLBOX_STYLE_FLAT) )
1392 {
1393 mnMaxItemWidth = 1;
1394 mnMaxItemHeight = 1;
1395 }
1396
1397 ImplInvalidate( true, true );
1398}
1399
1400// disable key input if all items are disabled
1401void ToolBox::ImplUpdateInputEnable()
1402{
1403 mpData->mbKeyInputDisabled = std::none_of(mpData->m_aItems.begin(), mpData->m_aItems.end(),
1404 [](const ImplToolItem& rItem) {
1405 // at least one useful entry
1406 return rItem.mbEnabled;
1407 });
1408}
1409
1410void ToolBox::ImplFillLayoutData()
1411{
1412 mpData->m_pLayoutData.reset(new ToolBoxLayoutData);
1413
1414 ImplToolItems::size_type nCount = mpData->m_aItems.size();
1415 for( ImplToolItems::size_type i = 0; i < nCount; i++ )
1416 {
1417 ImplToolItem* pItem = &mpData->m_aItems[i];
1418
1419 // only draw, if the rectangle is within PaintRectangle
1420 if (!pItem->maRect.IsEmpty())
1421 InvalidateItem(i);
1422 }
1423}
1424
1425OUString ToolBox::GetDisplayText() const
1426{
1427 if( ! mpData->m_pLayoutData )
1428 const_cast<ToolBox *>(this)->ImplFillLayoutData();
1429 return mpData->m_pLayoutData ? mpData->m_pLayoutData->m_aDisplayText : OUString();
1430}
1431
1432tools::Rectangle ToolBox::GetCharacterBounds( sal_uInt16 nItemID, long nIndex )
1433{
1434 long nItemIndex = -1;
1435 if( ! mpData->m_pLayoutData )
1436 ImplFillLayoutData();
1437 if( mpData->m_pLayoutData )
1438 {
1439 for( sal_uLong i = 0; i < mpData->m_pLayoutData->m_aLineItemIds.size(); i++ )
1440 {
1441 if( mpData->m_pLayoutData->m_aLineItemIds[i] == nItemID )
1442 {
1443 nItemIndex = mpData->m_pLayoutData->m_aLineIndices[i];
1444 break;
1445 }
1446 }
1447 }
1448 return (mpData->m_pLayoutData && nItemIndex != -1) ? mpData->m_pLayoutData->GetCharacterBounds( nItemIndex+nIndex ) : tools::Rectangle();
1449}
1450
1451long ToolBox::GetIndexForPoint( const Point& rPoint, sal_uInt16& rItemID )
1452{
1453 long nIndex = -1;
1454 rItemID = 0;
1455 if( ! mpData->m_pLayoutData )
1456 ImplFillLayoutData();
1457 if( mpData->m_pLayoutData )
1458 {
1459 nIndex = mpData->m_pLayoutData->GetIndexForPoint( rPoint );
1460 for( sal_uLong i = 0; i < mpData->m_pLayoutData->m_aLineIndices.size(); i++ )
1461 {
1462 if( mpData->m_pLayoutData->m_aLineIndices[i] <= nIndex &&
1463 (i == mpData->m_pLayoutData->m_aLineIndices.size()-1 || mpData->m_pLayoutData->m_aLineIndices[i+1] > nIndex) )
1464 {
1465 rItemID = mpData->m_pLayoutData->m_aLineItemIds[i];
1466 break;
1467 }
1468 }
1469 }
1470 return nIndex;
1471}
1472
1473void ToolBox::SetDropdownClickHdl( const Link<ToolBox *, void>& rLink )
1474{
1475 if (mpData != nullptr) {
1476 mpData->maDropdownClickHdl = rLink;
1477 }
1478}
1479
1480void ToolBox::SetMenuType( ToolBoxMenuType aType )
1481{
1482 if( aType == mpData->maMenuType )
1483 return;
1484
1485 mpData->maMenuType = aType;
1486 if( IsFloatingMode() )
1487 {
1488 // the menu button may have to be moved into the decoration which changes the layout
1489 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
1490 if( pWrapper )
1491 pWrapper->ShowTitleButton( TitleButton::Menu, bool( aType & ToolBoxMenuType::Customize) );
1492
1493 mbFormat = true;
1494 ImplFormat();
1495 ImplSetMinMaxFloatSize();
1496 }
1497 else
1498 {
1499 // trigger redraw of menu button
1500 if( !mpData->maMenubuttonItem.maRect.IsEmpty() )
1501 Invalidate(mpData->maMenubuttonItem.maRect);
1502 }
1503}
1504
1505ToolBoxMenuType ToolBox::GetMenuType() const
1506{
1507 return mpData->maMenuType;
1508}
1509
1510bool ToolBox::IsMenuEnabled() const
1511{
1512 return mpData->maMenuType != ToolBoxMenuType::NONE;
1513}
1514
1515PopupMenu* ToolBox::GetMenu() const
1516{
1517 return mpData == nullptr ? nullptr : mpData->mpMenu;
3
'?' condition is false
4
Calling implicit copy constructor for 'VclPtr<PopupMenu>'
5
Calling copy constructor for 'Reference<PopupMenu>'
8
Returning from copy constructor for 'Reference<PopupMenu>'
9
Returning from copy constructor for 'VclPtr<PopupMenu>'
10
Calling implicit destructor for 'VclPtr<PopupMenu>'
11
Calling '~Reference'
18
Returning from '~Reference'
19
Returning from destructor for 'VclPtr<PopupMenu>'
20
Use of memory after it is freed
1518}
1519
1520void ToolBox::SetMenuExecuteHdl( const Link<ToolBox *, void>& rLink )
1521{
1522 mpData->maMenuButtonHdl = rLink;
1523}
1524
1525bool ToolBox::ImplHasClippedItems()
1526{
1527 // are any items currently clipped ?
1528 ImplFormat();
1529 return std::any_of(mpData->m_aItems.begin(), mpData->m_aItems.end(),
1530 [](const ImplToolItem& rItem) { return rItem.IsClipped(); });
1531}
1532
1533namespace
1534{
1535 MenuItemBits ConvertBitsFromToolBoxToMenu(ToolBoxItemBits nToolItemBits)
1536 {
1537 MenuItemBits nMenuItemBits = MenuItemBits::NONE;
1538 if ((nToolItemBits & ToolBoxItemBits::CHECKABLE) ||
1539 (nToolItemBits & ToolBoxItemBits::DROPDOWN))
1540 {
1541 nMenuItemBits |= MenuItemBits::CHECKABLE;
1542 }
1543 return nMenuItemBits;
1544 }
1545}
1546
1547void ToolBox::UpdateCustomMenu()
1548{
1549 // fill clipped items into menu
1550 PopupMenu *pMenu = GetMenu();
1551 pMenu->Clear();
1552
1553 // add menu items: first the overflow items, then hidden items, both in the
1554 // order they would usually appear in the toolbar. Separators that would be
1555 // in the toolbar are ignored as they would introduce too much clutter,
1556 // instead we have a single separator to help distinguish between overflow
1557 // and hidden items.
1558 if ( mpData->m_aItems.empty() )
1559 return;
1560
1561 // nStartPos will hold the number of clipped items appended from first loop
1562 for ( const auto& rItem : mpData->m_aItems )
1563 {
1564 if( rItem.IsClipped() )
1565 {
1566 sal_uInt16 id = rItem.mnId + TOOLBOX_MENUITEM_START;
1567 MenuItemBits nMenuItemBits = ConvertBitsFromToolBoxToMenu(rItem.mnBits);
1568 pMenu->InsertItem( id, rItem.maText, rItem.maImage, nMenuItemBits);
1569 pMenu->SetItemCommand( id, rItem.maCommandStr );
1570 pMenu->EnableItem( id, rItem.mbEnabled );
1571 pMenu->CheckItem ( id, rItem.meState == TRISTATE_TRUE );
1572 }
1573 }
1574
1575 // add a separator below the inserted clipped-items
1576 pMenu->InsertSeparator();
1577
1578 // now append the items that are explicitly disabled
1579 for ( const auto& rItem : mpData->m_aItems )
1580 {
1581 if( rItem.IsItemHidden() )
1582 {
1583 sal_uInt16 id = rItem.mnId + TOOLBOX_MENUITEM_START;
1584 MenuItemBits nMenuItemBits = ConvertBitsFromToolBoxToMenu(rItem.mnBits);
1585 pMenu->InsertItem( id, rItem.maText, rItem.maImage, nMenuItemBits );
1586 pMenu->SetItemCommand( id, rItem.maCommandStr );
1587 pMenu->EnableItem( id, rItem.mbEnabled );
1588 pMenu->CheckItem( id, rItem.meState == TRISTATE_TRUE );
1589 }
1590 }
1591}
1592
1593IMPL_LINK( ToolBox, ImplCustomMenuListener, VclMenuEvent&, rEvent, void )void ToolBox::LinkStubImplCustomMenuListener(void * instance,
VclMenuEvent& data) { return static_cast<ToolBox *>
(instance)->ImplCustomMenuListener(data); } void ToolBox::
ImplCustomMenuListener(VclMenuEvent& rEvent)
1
Calling 'ToolBox::ImplCustomMenuListener'
1594{
1595 if( rEvent.GetMenu() == GetMenu() && rEvent.GetId() == VclEventId::MenuSelect )
2
Calling 'ToolBox::GetMenu'
1596 {
1597 sal_uInt16 id = GetMenu()->GetItemId( rEvent.GetItemPos() );
1598 if( id >= TOOLBOX_MENUITEM_START )
1599 TriggerItem( id - TOOLBOX_MENUITEM_START );
1600 }
1601}
1602
1603void ToolBox::ExecuteCustomMenu( const tools::Rectangle& rRect )
1604{
1605 if ( !IsMenuEnabled() || ImplIsInPopupMode() )
1606 return;
1607
1608 UpdateCustomMenu();
1609
1610 if( GetMenuType() & ToolBoxMenuType::Customize )
1611 // call button handler to allow for menu customization
1612 mpData->maMenuButtonHdl.Call( this );
1613
1614 GetMenu()->AddEventListener( LINK( this, ToolBox, ImplCustomMenuListener )::tools::detail::makeLink( ::tools::detail::castTo<ToolBox
*>(this), &ToolBox::LinkStubImplCustomMenuListener)
);
1615
1616 // make sure all disabled entries will be shown
1617 GetMenu()->SetMenuFlags(
1618 GetMenu()->GetMenuFlags() | MenuFlags::AlwaysShowDisabledEntries );
1619
1620 // toolbox might be destroyed during execute
1621 bool bBorderDel = false;
1622
1623 VclPtr<vcl::Window> pWin = this;
1624 tools::Rectangle aMenuRect = rRect;
1625 VclPtr<ImplBorderWindow> pBorderWin;
1626 if( aMenuRect.IsEmpty() && IsFloatingMode() )
1627 {
1628 // custom menu is placed in the decoration
1629 pBorderWin = dynamic_cast<ImplBorderWindow*>( GetWindow( GetWindowType::Border ) );
1630 if( pBorderWin && !pBorderWin->GetMenuRect().IsEmpty() )
1631 {
1632 pWin = pBorderWin;
1633 aMenuRect = pBorderWin->GetMenuRect();
1634 bBorderDel = true;
1635 }
1636 }
1637
1638 sal_uInt16 uId = GetMenu()->Execute( pWin, tools::Rectangle( ImplGetPopupPosition( aMenuRect ), Size() ),
1639 PopupMenuFlags::ExecuteDown | PopupMenuFlags::NoMouseUpClose );
1640
1641 if ( pWin->IsDisposed() )
1642 return;
1643
1644 if( GetMenu() )
1645 GetMenu()->RemoveEventListener( LINK( this, ToolBox, ImplCustomMenuListener )::tools::detail::makeLink( ::tools::detail::castTo<ToolBox
*>(this), &ToolBox::LinkStubImplCustomMenuListener)
);
1646 if( bBorderDel )
1647 {
1648 if( pBorderWin->IsDisposed() )
1649 return;
1650 }
1651
1652 pWin->Invalidate( aMenuRect );
1653
1654 if( uId )
1655 GrabFocusToDocument();
1656}
1657
1658// checks override first, useful during calculation of sizes
1659bool ToolBox::ImplIsFloatingMode() const
1660{
1661 SAL_WARN_IF( mpData->mbAssumeDocked && mpData->mbAssumeFloating, "vcl",do { if (true && (mpData->mbAssumeDocked &&
mpData->mbAssumeFloating)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "cannot assume docked and floating"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "1662" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "cannot assume docked and floating")
, 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "cannot assume docked and floating"; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "1662" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "cannot assume docked and floating") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "1662" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "cannot assume docked and floating")
, 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "cannot assume docked and floating"; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "1662" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1662 "cannot assume docked and floating" )do { if (true && (mpData->mbAssumeDocked &&
mpData->mbAssumeFloating)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "cannot assume docked and floating"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "1662" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "cannot assume docked and floating")
, 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "cannot assume docked and floating"; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "1662" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "cannot assume docked and floating") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "1662" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "cannot assume docked and floating")
, 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "cannot assume docked and floating"; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/toolbox2.cxx"
":" "1662" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1663
1664 if( mpData->mbAssumeDocked )
1665 return false;
1666 else if( mpData->mbAssumeFloating )
1667 return true;
1668 else
1669 return IsFloatingMode();
1670}
1671
1672// checks override first, useful during calculation of sizes
1673bool ToolBox::ImplIsInPopupMode() const
1674{
1675 if( mpData->mbAssumePopupMode )
1676 return true;
1677 else
1678 {
1679 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
1680 return ( pWrapper && pWrapper->GetFloatingWindow() && pWrapper->GetFloatingWindow()->IsInPopupMode() );
1681 }
1682}
1683
1684void ToolBox::Lock( bool bLock )
1685{
1686 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
1687 if( !pWrapper )
1688 return;
1689 if( mpData->mbIsLocked != bLock )
1690 {
1691 mpData->mbIsLocked = bLock;
1692 if( !ImplIsFloatingMode() )
1693 {
1694 mbCalc = true;
1695 mbFormat = true;
1696 SetSizePixel( CalcWindowSizePixel(1) );
1697 Invalidate();
1698 }
1699 }
1700}
1701
1702bool ToolBox::AlwaysLocked()
1703{
1704 // read config item to determine toolbox behaviour, used for subtoolbars
1705
1706 static int nAlwaysLocked = -1;
1707
1708 if( nAlwaysLocked == -1 )
1709 {
1710 nAlwaysLocked = 0; // ask configuration only once
1711
1712 utl::OConfigurationNode aNode = utl::OConfigurationTreeRoot::tryCreateWithComponentContext(
1713 comphelper::getProcessComponentContext(),
1714 "/org.openoffice.Office.UI.GlobalSettings/Toolbars" ); // note: case sensitive !
1715 if ( aNode.isValid() )
1716 {
1717 // feature enabled ?
1718 bool bStatesEnabled = bool();
1719 css::uno::Any aValue = aNode.getNodeValue( "StatesEnabled" );
1720 if( aValue >>= bStatesEnabled )
1721 {
1722 if( bStatesEnabled )
1723 {
1724 // now read the locking state
1725 utl::OConfigurationNode aNode2 = utl::OConfigurationTreeRoot::tryCreateWithComponentContext(
1726 comphelper::getProcessComponentContext(),
1727 "/org.openoffice.Office.UI.GlobalSettings/Toolbars/States" ); // note: case sensitive !
1728
1729 bool bLocked = bool();
1730 css::uno::Any aValue2 = aNode2.getNodeValue( "Locked" );
1731 if( aValue2 >>= bLocked )
1732 nAlwaysLocked = bLocked ? 1 : 0;
1733 }
1734 }
1735 }
1736 }
1737
1738 return nAlwaysLocked == 1;
1739}
1740
1741bool ToolBox::WillUsePopupMode() const
1742{
1743 return mpData->mbWillUsePopupMode;
1744}
1745
1746void ToolBox::WillUsePopupMode( bool b )
1747{
1748 mpData->mbWillUsePopupMode = b;
1749}
1750
1751void ToolBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter)
1752{
1753 DockingWindow::DumpAsPropertyTree(rJsonWriter);
1754
1755 auto childrenNode = rJsonWriter.startNode("children");
1756 for (ToolBox::ImplToolItems::size_type i = 0; i < GetItemCount(); ++i)
1757 {
1758 ToolBoxItemType type = GetItemType(i);
1759 if (type == ToolBoxItemType::BUTTON)
1760 {
1761 auto childNode = rJsonWriter.startNode("");
1762 int nId = GetItemId(i);
1763 if (!IsItemVisible(nId))
1764 continue;
1765 rJsonWriter.put("type", "toolitem");
1766 rJsonWriter.put("text", GetItemText(nId));
1767 rJsonWriter.put("command", GetItemCommand(nId));
1768 }
1769 }
1770}
1771
1772/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
6
Assuming field 'm_pBody' is non-null
7
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody
11.1
Field 'm_pBody' is non-null
11.1
Field 'm_pBody' is non-null
11.1
Field 'm_pBody' is non-null
)
12
Taking true branch
113 m_pBody->release();
13
Calling 'VclReferenceBase::release'
17
Returning; memory was released
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody)
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
14
Assuming the condition is true
15
Taking true branch
40 delete this;
16
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif