Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
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 tpline.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 /usr/include/libxml2 -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 CUI_DLLIMPLEMENTATION -D SYSTEM_LIBXML -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/qrcodegen/cpp/ -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/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/curl/include -I /home/maarten/src/libreoffice/core/external/clew/source/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/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/cui/inc -I /home/maarten/src/libreoffice/core/cui/source/inc -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -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/cui/source/tabpages/tpline.cxx

/home/maarten/src/libreoffice/core/cui/source/tabpages/tpline.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 <memory>
21#include <editeng/sizeitem.hxx>
22#include <osl/file.hxx>
23#include <tools/urlobj.hxx>
24
25#include <strings.hrc>
26#include <svx/colorbox.hxx>
27#include <svx/dlgctrl.hxx>
28#include <svx/xlineit0.hxx>
29#include <svx/xlinjoit.hxx>
30#include <svx/xlncapit.hxx>
31#include <svx/xlndsit.hxx>
32#include <svx/xlnwtit.hxx>
33#include <svx/xlnstwit.hxx>
34#include <svx/xlnedwit.hxx>
35#include <svx/xlnclit.hxx>
36#include <svx/xlnstit.hxx>
37#include <svx/xlnedit.hxx>
38#include <svx/xlnstcit.hxx>
39#include <svx/xlnedcit.hxx>
40
41
42#include <svx/tabline.hxx>
43#include <svx/xtable.hxx>
44#include <svx/drawitem.hxx>
45#include <cuitabline.hxx>
46#include <dialmgr.hxx>
47#include <svx/dlgutil.hxx>
48#include <svx/svxgraphicitem.hxx>
49#include <svx/ofaitem.hxx>
50#include <svx/svdobj.hxx>
51#include <svx/svdpage.hxx>
52#include <svx/svdview.hxx>
53#include <svx/svdmodel.hxx>
54#include <svx/xlntrit.hxx>
55#include <svx/xfltrit.hxx>
56#include <editeng/numitem.hxx>
57#include <editeng/brushitem.hxx>
58#include <svx/gallery.hxx>
59#include <sfx2/opengrf.hxx>
60#include <svx/dialmgr.hxx>
61#include <svx/svxids.hrc>
62#include <svx/strings.hrc>
63#include <cuitabarea.hxx>
64#include <svtools/unitconv.hxx>
65#include <comphelper/lok.hxx>
66
67#define MAX_BMP_WIDTH16 16
68#define MAX_BMP_HEIGHT16 16
69
70using namespace com::sun::star;
71
72// static ----------------------------------------------------------------
73
74const sal_uInt16 SvxLineTabPage::pLineRanges[] =
75{
76 XATTR_LINETRANSPARENCE,
77 XATTR_LINETRANSPARENCE,
78 SID_ATTR_LINE_STYLE( 10000 + 169 ),
79 SID_ATTR_LINE_ENDCENTER( 10000 + 178 ),
80 0
81};
82
83SvxLineTabPage::SvxLineTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
84 : SfxTabPage(pPage, pController, "cui/ui/linetabpage.ui", "LineTabPage", &rInAttrs)
85 , m_pSymbolList(nullptr)
86 , m_bNewSize(false)
87 , m_nSymbolType(SVX_SYMBOLTYPE_UNKNOWN(-100)) // unknown respectively unchanged
88 , m_pSymbolAttr(nullptr)
89 , m_bLastWidthModified(false)
90 , m_aSymbolLastSize(Size(0,0))
91 , m_bSymbols(false)
92 , m_rOutAttrs(rInAttrs)
93 , m_bObjSelected(false)
94 , m_aXLineAttr(rInAttrs.GetPool())
95 , m_rXLSet(m_aXLineAttr.GetItemSet())
96 , m_pnLineEndListState(nullptr)
97 , m_pnDashListState(nullptr)
98 , m_pnColorListState(nullptr)
99 , m_nPageType(PageType::Area)
100 , m_nDlgType(0)
101 , m_pPosDashLb(nullptr)
102 , m_pPosLineEndLb(nullptr)
103 , m_xBoxColor(m_xBuilder->weld_widget("boxCOLOR"))
104 , m_xLbLineStyle(new SvxLineLB(m_xBuilder->weld_combo_box("LB_LINE_STYLE")))
105 , m_xLbColor(new ColorListBox(m_xBuilder->weld_menu_button("LB_COLOR"), pController->getDialog()))
106 , m_xBoxWidth(m_xBuilder->weld_widget("boxWIDTH"))
107 , m_xMtrLineWidth(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_WIDTH", FieldUnit::CM))
108 , m_xBoxTransparency(m_xBuilder->weld_widget("boxTRANSPARENCY"))
109 , m_xMtrTransparent(m_xBuilder->weld_metric_spin_button("MTR_LINE_TRANSPARENT", FieldUnit::PERCENT))
110 , m_xFlLineEnds(m_xBuilder->weld_widget("FL_LINE_ENDS"))
111 , m_xBoxArrowStyles(m_xBuilder->weld_widget("boxARROW_STYLES"))
112 , m_xLbStartStyle(new SvxLineEndLB(m_xBuilder->weld_combo_box("LB_START_STYLE")))
113 , m_xBoxStart(m_xBuilder->weld_widget("boxSTART"))
114 , m_xMtrStartWidth(m_xBuilder->weld_metric_spin_button("MTR_FLD_START_WIDTH", FieldUnit::CM))
115 , m_xTsbCenterStart(m_xBuilder->weld_check_button("TSB_CENTER_START"))
116 , m_xBoxEnd(m_xBuilder->weld_widget("boxEND"))
117 , m_xLbEndStyle(new SvxLineEndLB(m_xBuilder->weld_combo_box("LB_END_STYLE")))
118 , m_xMtrEndWidth(m_xBuilder->weld_metric_spin_button("MTR_FLD_END_WIDTH", FieldUnit::CM))
119 , m_xTsbCenterEnd(m_xBuilder->weld_check_button("TSB_CENTER_END"))
120 , m_xCbxSynchronize(m_xBuilder->weld_check_button("CBX_SYNCHRONIZE"))
121 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "CTL_PREVIEW", m_aCtlPreview))
122 , m_xFLEdgeStyle(m_xBuilder->weld_widget("FL_EDGE_STYLE"))
123 , m_xGridEdgeCaps(m_xBuilder->weld_widget("gridEDGE_CAPS"))
124 , m_xLBEdgeStyle(m_xBuilder->weld_combo_box("LB_EDGE_STYLE"))
125 , m_xLBCapStyle(m_xBuilder->weld_combo_box("LB_CAP_STYLE")) // LineCaps
126 , m_xFlSymbol(m_xBuilder->weld_widget("FL_SYMBOL_FORMAT")) //#58425# Symbols on a line (e.g. StarChart)
127 , m_xGridIconSize(m_xBuilder->weld_widget("gridICON_SIZE"))
128 , m_xSymbolMB(m_xBuilder->weld_menu_button("MB_SYMBOL_BITMAP"))
129 , m_xSymbolWidthMF(m_xBuilder->weld_metric_spin_button("MF_SYMBOL_WIDTH", FieldUnit::CM))
130 , m_xSymbolHeightMF(m_xBuilder->weld_metric_spin_button("MF_SYMBOL_HEIGHT", FieldUnit::CM))
131 , m_xSymbolRatioCB(m_xBuilder->weld_check_button("CB_SYMBOL_RATIO"))
132{
133 // This Page requires ExchangeSupport
134 SetExchangeSupport();
135
136 // Metric set
137 FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
138
139 switch ( eFUnit )
140 {
141 case FieldUnit::M:
142 case FieldUnit::KM:
143 eFUnit = FieldUnit::MM;
144 [[fallthrough]]; // we now have mm
145 case FieldUnit::MM:
146 m_xMtrLineWidth->set_increments(50, 500, FieldUnit::NONE);
147 m_xMtrStartWidth->set_increments(50, 500, FieldUnit::NONE);
148 m_xMtrEndWidth->set_increments(50, 500, FieldUnit::NONE);
149 break;
150
151 case FieldUnit::INCH:
152 m_xMtrLineWidth->set_increments(2, 20, FieldUnit::NONE);
153 m_xMtrStartWidth->set_increments(2, 20, FieldUnit::NONE);
154 m_xMtrEndWidth->set_increments(2, 20, FieldUnit::NONE);
155 break;
156 default: ;// prevent warning
157 }
158 SetFieldUnit( *m_xMtrLineWidth, eFUnit );
159 SetFieldUnit( *m_xMtrStartWidth, eFUnit );
160 SetFieldUnit( *m_xMtrEndWidth, eFUnit );
161
162 // determine PoolUnit
163 SfxItemPool* pPool = m_rOutAttrs.GetPool();
164 DBG_ASSERT( pPool, "Where is the pool?" )do { if (true && (!(pPool))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/tpline.cxx"
":" "164" ": "), "%s", "Where is the pool?"); } } while (false
)
;
165 m_ePoolUnit = pPool->GetMetric( SID_ATTR_LINE_WIDTH( 10000 + 171 ) );
166
167 m_xLbLineStyle->connect_changed(LINK(this, SvxLineTabPage, ClickInvisibleHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubClickInvisibleHdl_Impl
)
);
168 m_xLbColor->SetSelectHdl( LINK( this, SvxLineTabPage, ChangePreviewListBoxHdl_Impl )::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangePreviewListBoxHdl_Impl
)
);
169 m_xMtrLineWidth->connect_value_changed(LINK(this, SvxLineTabPage, ChangePreviewModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangePreviewModifyHdl_Impl
)
);
170 m_xMtrTransparent->connect_value_changed(LINK( this, SvxLineTabPage, ChangeTransparentHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangeTransparentHdl_Impl
)
);
171
172 m_xLbStartStyle->connect_changed(LINK(this, SvxLineTabPage, ChangeStartListBoxHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangeStartListBoxHdl_Impl
)
);
173 m_xLbEndStyle->connect_changed(LINK(this, SvxLineTabPage, ChangeEndListBoxHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangeEndListBoxHdl_Impl
)
);
174 m_xMtrStartWidth->connect_value_changed(LINK(this, SvxLineTabPage, ChangeStartModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangeStartModifyHdl_Impl
)
);
175 m_xMtrEndWidth->connect_value_changed(LINK( this, SvxLineTabPage, ChangeEndModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangeEndModifyHdl_Impl
)
);
176 m_xTsbCenterStart->connect_clicked(LINK(this, SvxLineTabPage, ChangeStartClickHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangeStartClickHdl_Impl
)
);
177 m_xTsbCenterEnd->connect_clicked(LINK(this, SvxLineTabPage, ChangeEndClickHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangeEndClickHdl_Impl
)
);
178
179 Link<weld::ComboBox&,void> aEdgeStyle = LINK(this, SvxLineTabPage, ChangeEdgeStyleHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangeEdgeStyleHdl_Impl
)
;
180 m_xLBEdgeStyle->connect_changed(aEdgeStyle);
181
182 // LineCaps
183 Link<weld::ComboBox&,void> aCapStyle = LINK(this, SvxLineTabPage, ChangeCapStyleHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubChangeCapStyleHdl_Impl
)
;
184 m_xLBCapStyle->connect_changed(aCapStyle);
185
186 // Symbols on a line (eg star charts), MB-handler set
187 m_xSymbolMB->connect_selected(LINK(this, SvxLineTabPage, GraphicHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubGraphicHdl_Impl)
);
188 m_xSymbolMB->connect_toggled(LINK(this, SvxLineTabPage, MenuCreateHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubMenuCreateHdl_Impl
)
);
189 m_xSymbolWidthMF->connect_value_changed(LINK(this, SvxLineTabPage, SizeHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubSizeHdl_Impl)
);
190 m_xSymbolHeightMF->connect_value_changed(LINK(this, SvxLineTabPage, SizeHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubSizeHdl_Impl)
);
191 m_xSymbolRatioCB->connect_toggled(LINK(this, SvxLineTabPage, RatioHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxLineTabPage
*>(this), &SvxLineTabPage::LinkStubRatioHdl_Impl)
);
192
193 m_xSymbolRatioCB->set_active(true);
194 ShowSymbolControls(false);
195
196 m_nActLineWidth = -1;
197}
198
199void SvxLineTabPage::ShowSymbolControls(bool bOn)
200{
201 // Symbols on a line (e.g. StarCharts), symbol-enable controls
202
203 m_bSymbols=bOn;
204 m_xFlSymbol->set_visible(bOn);
205 m_aCtlPreview.ShowSymbol(bOn);
206}
207
208SvxLineTabPage::~SvxLineTabPage()
209{
210 m_xCtlPreview.reset();
211 m_xLbEndStyle.reset();
212 m_xLbStartStyle.reset();
213 m_xLbColor.reset();
214 m_xLbLineStyle.reset();
215 m_aGalleryBrushItems.clear();
216 m_aSymbolBrushItems.clear();
217}
218
219void SvxLineTabPage::Construct()
220{
221 FillListboxes();
222}
223
224void SvxLineTabPage::FillListboxes()
225{
226 // Line styles
227 auto nOldSelect = m_xLbLineStyle->get_active();
228 // aLbLineStyle.FillStyles();
229 m_xLbLineStyle->Fill( m_pDashList );
230 m_xLbLineStyle->set_active( nOldSelect );
231
232 // Line end style
233 OUString sNone( comphelper::LibreOfficeKit::isActive() ? SvxResId( RID_SVXSTR_INVISIBLEreinterpret_cast<char const *>("RID_SVXSTR_INVISIBLE" "\004"
u8"None")
)
234 : SvxResId( RID_SVXSTR_NONEreinterpret_cast<char const *>("RID_SVXSTR_NONE" "\004"
u8"- none -")
) );
235 nOldSelect = m_xLbStartStyle->get_active();
236 m_xLbStartStyle->clear();
237 m_xLbStartStyle->append_text(sNone);
238 m_xLbStartStyle->Fill(m_pLineEndList);
239 m_xLbStartStyle->set_active(nOldSelect);
240 nOldSelect = m_xLbEndStyle->get_active();
241 m_xLbEndStyle->clear();
242 m_xLbEndStyle->append_text(sNone);
243 m_xLbEndStyle->Fill(m_pLineEndList, false);
244 m_xLbEndStyle->set_active(nOldSelect);
245}
246
247void SvxLineTabPage::ActivatePage( const SfxItemSet& rSet )
248{
249 const CntUInt16Item* pPageTypeItem = rSet.GetItem<CntUInt16Item>(SID_PAGE_TYPE( 10000 + 1017 ), false);
250 if (pPageTypeItem)
251 SetPageType(static_cast<PageType>(pPageTypeItem->GetValue()));
252 if( m_nDlgType == 0 && m_pDashList.is() )
253 {
254 sal_Int32 nPos;
255 sal_Int32 nCount;
256
257 // Dash list
258 if( ( *m_pnDashListState & ChangeType::MODIFIED ) ||
259 ( *m_pnDashListState & ChangeType::CHANGED ) )
260 {
261 if( *m_pnDashListState & ChangeType::CHANGED )
262 m_pDashList = static_cast<SvxLineTabDialog*>(GetDialogController() )->GetNewDashList();
263
264 *m_pnDashListState = ChangeType::NONE;
265
266 // Style list
267 nPos = m_xLbLineStyle->get_active();
268
269 m_xLbLineStyle->clear();
270 m_xLbLineStyle->append_text(SvxResId(RID_SVXSTR_INVISIBLEreinterpret_cast<char const *>("RID_SVXSTR_INVISIBLE" "\004"
u8"None")
));
271 m_xLbLineStyle->append_text(SvxResId(RID_SVXSTR_SOLIDreinterpret_cast<char const *>("RID_SVXSTR_SOLID" "\004"
u8"Continuous")
));
272 m_xLbLineStyle->Fill(m_pDashList);
273 nCount = m_xLbLineStyle->get_count();
274
275 if ( nCount == 0 )
276 ; // This case should never occur
277 else if( nCount <= nPos )
278 m_xLbLineStyle->set_active(0);
279 else
280 m_xLbLineStyle->set_active(nPos);
281 }
282
283 INetURLObject aDashURL( m_pDashList->GetPath() );
284
285 aDashURL.Append( m_pDashList->GetName() );
286 DBG_ASSERT( aDashURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" )do { if (true && (!(aDashURL.GetProtocol() != INetProtocol
::NotValid))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/tpline.cxx"
":" "286" ": "), "%s", "invalid URL"); } } while (false)
;
287 // LineEnd list
288 if( ( *m_pnLineEndListState & ChangeType::MODIFIED ) || ( *m_pnLineEndListState & ChangeType::CHANGED ) )
289 {
290 if( *m_pnLineEndListState & ChangeType::CHANGED )
291 m_pLineEndList = static_cast<SvxLineTabDialog*>(GetDialogController())->GetNewLineEndList();
292
293 *m_pnLineEndListState = ChangeType::NONE;
294
295 nPos = m_xLbLineStyle->get_active();
296 OUString sNone( comphelper::LibreOfficeKit::isActive() ? SvxResId( RID_SVXSTR_INVISIBLEreinterpret_cast<char const *>("RID_SVXSTR_INVISIBLE" "\004"
u8"None")
)
297 : SvxResId( RID_SVXSTR_NONEreinterpret_cast<char const *>("RID_SVXSTR_NONE" "\004"
u8"- none -")
) );
298
299 m_xLbStartStyle->clear();
300 m_xLbStartStyle->append_text(sNone);
301
302 m_xLbStartStyle->Fill( m_pLineEndList );
303 nCount = m_xLbStartStyle->get_count();
304 if( nCount == 0 )
305 ; // This case should never occur
306 else if( nCount <= nPos )
307 m_xLbStartStyle->set_active(0);
308 else
309 m_xLbStartStyle->set_active(nPos);
310
311 m_xLbEndStyle->clear();
312 m_xLbEndStyle->append_text(sNone);
313
314 m_xLbEndStyle->Fill( m_pLineEndList, false );
315 nCount = m_xLbEndStyle->get_count();
316
317 if( nCount == 0 )
318 ; // This case should never occur
319 else if( nCount <= nPos )
320 m_xLbEndStyle->set_active(0);
321 else
322 m_xLbEndStyle->set_active(nPos);
323 }
324 INetURLObject aLineURL( m_pLineEndList->GetPath() );
325
326 aLineURL.Append( m_pLineEndList->GetName() );
327 DBG_ASSERT( aLineURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" )do { if (true && (!(aLineURL.GetProtocol() != INetProtocol
::NotValid))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/tpline.cxx"
":" "327" ": "), "%s", "invalid URL"); } } while (false)
;
328 // Evaluate if another TabPage set another fill type
329 if( m_xLbLineStyle->get_active() != 0 )
330 {
331 if( m_nPageType == PageType::Hatch ) // 1
332 {
333 m_xLbLineStyle->set_active(*m_pPosDashLb + 2); // +2 due to SOLID and INVISIBLE
334 ChangePreviewHdl_Impl( nullptr );
335 }
336 if( m_nPageType == PageType::Bitmap )
337 {
338 m_xLbStartStyle->set_active(*m_pPosLineEndLb + 1);// +1 due to SOLID
339 m_xLbEndStyle->set_active(*m_pPosLineEndLb + 1);// +1 due to SOLID
340 ChangePreviewHdl_Impl( nullptr );
341 }
342 }
343
344 // ColorList
345 if( *m_pnColorListState != ChangeType::NONE )
346 {
347 ChangePreviewHdl_Impl( nullptr );
348 }
349
350 m_nPageType = PageType::Area;
351 }
352 // Page does not yet exist in the ctor, that's why we do it here!
353
354 else if (m_nDlgType == 1101) // nNoArrowNoShadowDlg from chart2/source/controller/dialogs/dlg_ObjectProperties.cxx
355 {
356 m_xFlLineEnds->hide();
357 m_xFLEdgeStyle->hide();
358 }
359}
360
361
362DeactivateRC SvxLineTabPage::DeactivatePage( SfxItemSet* _pSet )
363{
364 if( m_nDlgType == 0 ) // Line dialog
365 {
366 m_nPageType = PageType::Gradient; // possibly for extensions
367 *m_pPosDashLb = m_xLbLineStyle->get_active() - 2;// First entry SOLID!!!
368 sal_Int32 nPos = m_xLbStartStyle->get_active();
369 if (nPos != -1)
370 nPos--;
371 *m_pPosLineEndLb = nPos;
372 }
373
374 if( _pSet )
375 FillItemSet( _pSet );
376
377 return DeactivateRC::LeavePage;
378}
379
380
381bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
382{
383 const SfxPoolItem* pOld = nullptr;
384 sal_Int32 nPos;
385 bool bModified = false;
386
387 // To prevent modifications to the list, we do not set other page's items.
388 if( m_nDlgType != 0 || m_nPageType != PageType::Hatch )
389 {
390 nPos = m_xLbLineStyle->get_active();
391 if( nPos != -1 &&
392 m_xLbLineStyle->get_value_changed_from_saved() )
393 {
394 std::unique_ptr<XLineStyleItem> pStyleItem;
395
396 if( nPos == 0 )
397 pStyleItem.reset(new XLineStyleItem( drawing::LineStyle_NONE ));
398 else if( nPos == 1 )
399 pStyleItem.reset(new XLineStyleItem( drawing::LineStyle_SOLID ));
400 else
401 {
402 pStyleItem.reset(new XLineStyleItem( drawing::LineStyle_DASH ));
403
404 // For added security
405 if( m_pDashList->Count() > static_cast<long>( nPos - 2 ) )
406 {
407 XLineDashItem aDashItem( m_xLbLineStyle->get_active_text(),
408 m_pDashList->GetDash( nPos - 2 )->GetDash() );
409 pOld = GetOldItem( *rAttrs, XATTR_LINEDASH );
410 if ( !pOld || !( *static_cast<const XLineDashItem*>(pOld) == aDashItem ) )
411 {
412 rAttrs->Put( aDashItem );
413 bModified = true;
414 }
415 }
416 }
417 pOld = GetOldItem( *rAttrs, XATTR_LINESTYLE );
418 if ( !pOld || !( *static_cast<const XLineStyleItem*>(pOld) == *pStyleItem ) )
419 {
420 rAttrs->Put( *pStyleItem );
421 bModified = true;
422 }
423 }
424 }
425 // Line width
426 // GetSavedValue() returns OUString!
427 if( m_xMtrLineWidth->get_value_changed_from_saved() )
428 {
429 XLineWidthItem aItem( GetCoreValue( *m_xMtrLineWidth, m_ePoolUnit ) );
430 pOld = GetOldItem( *rAttrs, XATTR_LINEWIDTH );
431 if ( !pOld || !( *static_cast<const XLineWidthItem*>(pOld) == aItem ) )
432 {
433 rAttrs->Put( aItem );
434 bModified = true;
435 }
436 }
437 // Width line start
438 if( m_xMtrStartWidth->get_value_changed_from_saved() )
439 {
440 XLineStartWidthItem aItem( GetCoreValue( *m_xMtrStartWidth, m_ePoolUnit ) );
441 pOld = GetOldItem( *rAttrs, XATTR_LINESTARTWIDTH );
442 if ( !pOld || !( *static_cast<const XLineStartWidthItem*>(pOld) == aItem ) )
443 {
444 rAttrs->Put( aItem );
445 bModified = true;
446 }
447 }
448 // Width line end
449 if( m_xMtrEndWidth->get_value_changed_from_saved() )
450 {
451 XLineEndWidthItem aItem( GetCoreValue( *m_xMtrEndWidth, m_ePoolUnit ) );
452 pOld = GetOldItem( *rAttrs, XATTR_LINEENDWIDTH );
453 if ( !pOld || !( *static_cast<const XLineEndWidthItem*>(pOld) == aItem ) )
454 {
455 rAttrs->Put( aItem );
456 bModified = true;
457 }
458 }
459
460 // Line color
461 if (m_xLbColor->IsValueChangedFromSaved())
462 {
463 NamedColor aColor = m_xLbColor->GetSelectedEntry();
464 XLineColorItem aItem(aColor.second, aColor.first);
465 pOld = GetOldItem( *rAttrs, XATTR_LINECOLOR );
466 if ( !pOld || !( *static_cast<const XLineColorItem*>(pOld) == aItem ) )
467 {
468 rAttrs->Put( aItem );
469 bModified = true;
470 }
471 }
472
473 if( m_nDlgType != 0 || m_nPageType != PageType::Bitmap )
474 {
475 // Line start
476 nPos = m_xLbStartStyle->get_active();
477 if( nPos != -1 && m_xLbStartStyle->get_value_changed_from_saved() )
478 {
479 std::unique_ptr<XLineStartItem> pItem;
480 if( nPos == 0 )
481 pItem.reset(new XLineStartItem());
482 else if( m_pLineEndList->Count() > static_cast<long>( nPos - 1 ) )
483 pItem.reset(new XLineStartItem( m_xLbStartStyle->get_active_text(), m_pLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() ));
484 pOld = GetOldItem( *rAttrs, XATTR_LINESTART );
485 if( pItem && ( !pOld || *pOld != *pItem ) )
486 {
487 rAttrs->Put( *pItem );
488 bModified = true;
489 }
490 }
491 // Line end
492 nPos = m_xLbEndStyle->get_active();
493 if( nPos != -1 && m_xLbEndStyle->get_value_changed_from_saved() )
494 {
495 std::unique_ptr<XLineEndItem> pItem;
496 if( nPos == 0 )
497 pItem.reset(new XLineEndItem());
498 else if( m_pLineEndList->Count() > static_cast<long>( nPos - 1 ) )
499 pItem.reset(new XLineEndItem( m_xLbEndStyle->get_active_text(), m_pLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() ));
500 pOld = GetOldItem( *rAttrs, XATTR_LINEEND );
501 if( pItem &&
502 ( !pOld || !( *static_cast<const XLineEndItem*>(pOld) == *pItem ) ) )
503 {
504 rAttrs->Put( *pItem );
505 bModified = true;
506 }
507 }
508 }
509
510 // Centered line end
511 TriState eState = m_xTsbCenterStart->get_state();
512 if( m_xTsbCenterStart->get_state_changed_from_saved() )
513 {
514 XLineStartCenterItem aItem( eState != TRISTATE_FALSE );
515 pOld = GetOldItem( *rAttrs, XATTR_LINESTARTCENTER );
516 if ( !pOld || !( *static_cast<const XLineStartCenterItem*>(pOld) == aItem ) )
517 {
518 rAttrs->Put( aItem );
519 bModified = true;
520 }
521 }
522 eState = m_xTsbCenterEnd->get_state();
523 if( m_xTsbCenterEnd->get_state_changed_from_saved() )
524 {
525 XLineEndCenterItem aItem( eState != TRISTATE_FALSE );
526 pOld = GetOldItem( *rAttrs, XATTR_LINEENDCENTER );
527 if ( !pOld || !( *static_cast<const XLineEndCenterItem*>(pOld) == aItem ) )
528 {
529 rAttrs->Put( aItem );
530 bModified = true;
531 }
532 }
533
534 // Transparency
535 sal_uInt16 nVal = m_xMtrTransparent->get_value(FieldUnit::PERCENT);
536 if( m_xMtrTransparent->get_value_changed_from_saved() )
537 {
538 XLineTransparenceItem aItem( nVal );
539 pOld = GetOldItem( *rAttrs, XATTR_LINETRANSPARENCE );
540 if ( !pOld || !( *static_cast<const XLineTransparenceItem*>(pOld) == aItem ) )
541 {
542 rAttrs->Put( aItem );
543 bModified = true;
544 }
545 }
546
547 nPos = m_xLBEdgeStyle->get_active();
548 if (nPos != -1 && m_xLBEdgeStyle->get_value_changed_from_saved())
549 {
550 std::unique_ptr<XLineJointItem> pNew;
551
552 switch(nPos)
553 {
554 case 0: // Rounded, default
555 {
556 pNew.reset(new XLineJointItem(css::drawing::LineJoint_ROUND));
557 break;
558 }
559 case 1: // - none -
560 {
561 pNew.reset(new XLineJointItem(css::drawing::LineJoint_NONE));
562 break;
563 }
564 case 2: // Miter
565 {
566 pNew.reset(new XLineJointItem(css::drawing::LineJoint_MITER));
567 break;
568 }
569 case 3: // Bevel
570 {
571 pNew.reset(new XLineJointItem(css::drawing::LineJoint_BEVEL));
572 break;
573 }
574 }
575
576 if(pNew)
577 {
578 pOld = GetOldItem( *rAttrs, XATTR_LINEJOINT );
579
580 if(!pOld || !(*static_cast<const XLineJointItem*>(pOld) == *pNew))
581 {
582 rAttrs->Put( *pNew );
583 bModified = true;
584 }
585 }
586 }
587
588 // LineCaps
589 nPos = m_xLBCapStyle->get_active();
590 if (nPos != -1 && m_xLBCapStyle->get_value_changed_from_saved())
591 {
592 std::unique_ptr<XLineCapItem> pNew;
593
594 switch(nPos)
595 {
596 case 0: // Butt (=Flat), default
597 {
598 pNew.reset(new XLineCapItem(css::drawing::LineCap_BUTT));
599 break;
600 }
601 case 1: // Round
602 {
603 pNew.reset(new XLineCapItem(css::drawing::LineCap_ROUND));
604 break;
605 }
606 case 2: // Square
607 {
608 pNew.reset(new XLineCapItem(css::drawing::LineCap_SQUARE));
609 break;
610 }
611 }
612
613 if(pNew)
614 {
615 pOld = GetOldItem( *rAttrs, XATTR_LINECAP );
616
617 if(!pOld || !(*static_cast<const XLineCapItem*>(pOld) == *pNew))
618 {
619 rAttrs->Put( *pNew );
620 bModified = true;
621 }
622 }
623 }
624
625 if(m_nSymbolType!=SVX_SYMBOLTYPE_UNKNOWN(-100) || m_bNewSize)
626 {
627 // Was set by selection or the size is different
628 SvxSizeItem aSItem(rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLSIZE(27000 +116)),m_aSymbolSize);
629 const SfxPoolItem* pSOld = GetOldItem( *rAttrs, rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLSIZE(27000 +116)) );
630 m_bNewSize = pSOld ? *static_cast<const SvxSizeItem *>(pSOld) != aSItem : m_bNewSize ;
631 if(m_bNewSize)
632 {
633 rAttrs->Put(aSItem);
634 bModified=true;
635 }
636
637 SfxInt32Item aTItem(rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLTYPE(27000 +115)),m_nSymbolType);
638 const SfxPoolItem* pTOld = GetOldItem( *rAttrs, rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLTYPE(27000 +115)) );
639 bool bNewType = pTOld == nullptr || *static_cast<const SfxInt32Item*>(pTOld) != aTItem;
640 if(bNewType && m_nSymbolType==SVX_SYMBOLTYPE_UNKNOWN(-100))
641 bNewType=false; // a small fix, type wasn't set -> don't create a type item after all!
642 if(bNewType)
643 {
644 rAttrs->Put(aTItem);
645 bModified=true;
646 }
647
648 if(m_nSymbolType!=SVX_SYMBOLTYPE_NONE(-3))
649 {
650 SvxBrushItem aBItem(m_aSymbolGraphic,GPOS_MM,rAttrs->GetPool()->GetWhich(SID_ATTR_BRUSH( 10000 + 1 )));
651 const SfxPoolItem* pBOld = GetOldItem( *rAttrs, rAttrs->GetPool()->GetWhich(SID_ATTR_BRUSH( 10000 + 1 )) );
652 bool bNewBrush =
653 pBOld == nullptr || *static_cast<const SvxBrushItem*>(pBOld) != aBItem;
654 if(bNewBrush)
655 {
656 rAttrs->Put(aBItem);
657 bModified=true;
658 }
659 }
660 }
661 rAttrs->Put (CntUInt16Item(SID_PAGE_TYPE( 10000 + 1017 ), static_cast<sal_uInt16>(m_nPageType)));
662 return bModified;
663}
664
665
666void SvxLineTabPage::FillXLSet_Impl()
667{
668 sal_Int32 nPos;
669
670 if (m_xLbLineStyle->get_active() == -1)
671 {
672 m_rXLSet.Put( XLineStyleItem( drawing::LineStyle_NONE ) );
673 }
674 else if (m_xLbLineStyle->get_active() == 0)
675 m_rXLSet.Put( XLineStyleItem( drawing::LineStyle_NONE ) );
676 else if (m_xLbLineStyle->get_active() == 1)
677 m_rXLSet.Put( XLineStyleItem( drawing::LineStyle_SOLID ) );
678 else
679 {
680 m_rXLSet.Put( XLineStyleItem( drawing::LineStyle_DASH ) );
681
682 nPos = m_xLbLineStyle->get_active();
683 if (nPos != -1)
684 {
685 m_rXLSet.Put( XLineDashItem( m_xLbLineStyle->get_active_text(),
686 m_pDashList->GetDash( nPos - 2 )->GetDash() ) );
687 }
688 }
689
690 nPos = m_xLbStartStyle->get_active();
691 if (nPos != -1)
692 {
693 if( nPos == 0 )
694 m_rXLSet.Put( XLineStartItem() );
695 else
696 m_rXLSet.Put( XLineStartItem( m_xLbStartStyle->get_active_text(),
697 m_pLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() ) );
698 }
699 nPos = m_xLbEndStyle->get_active();
700 if (nPos != -1)
701 {
702 if( nPos == 0 )
703 m_rXLSet.Put( XLineEndItem() );
704 else
705 m_rXLSet.Put( XLineEndItem( m_xLbEndStyle->get_active_text(),
706 m_pLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() ) );
707 }
708
709 nPos = m_xLBEdgeStyle->get_active();
710 if (nPos != -1)
711 {
712 switch(nPos)
713 {
714 case 0: // Rounded, default
715 {
716 m_rXLSet.Put(XLineJointItem(css::drawing::LineJoint_ROUND));
717 break;
718 }
719 case 1: // - none -
720 {
721 m_rXLSet.Put(XLineJointItem(css::drawing::LineJoint_NONE));
722 break;
723 }
724 case 2: // Miter
725 {
726 m_rXLSet.Put(XLineJointItem(css::drawing::LineJoint_MITER));
727 break;
728 }
729 case 3: // Bevel
730 {
731 m_rXLSet.Put(XLineJointItem(css::drawing::LineJoint_BEVEL));
732 break;
733 }
734 }
735 }
736
737 // LineCaps
738 nPos = m_xLBCapStyle->get_active();
739 if (nPos != -1)
740 {
741 switch(nPos)
742 {
743 case 0: // Butt (=Flat), default
744 {
745 m_rXLSet.Put(XLineCapItem(css::drawing::LineCap_BUTT));
746 break;
747 }
748 case 1: // Round
749 {
750 m_rXLSet.Put(XLineCapItem(css::drawing::LineCap_ROUND));
751 break;
752 }
753 case 2: // Square
754 {
755 m_rXLSet.Put(XLineCapItem(css::drawing::LineCap_SQUARE));
756 break;
757 }
758 }
759 }
760
761 m_rXLSet.Put( XLineStartWidthItem( GetCoreValue( *m_xMtrStartWidth, m_ePoolUnit ) ) );
762 m_rXLSet.Put( XLineEndWidthItem( GetCoreValue( *m_xMtrEndWidth, m_ePoolUnit ) ) );
763
764 m_rXLSet.Put( XLineWidthItem( GetCoreValue( *m_xMtrLineWidth, m_ePoolUnit ) ) );
765 NamedColor aColor = m_xLbColor->GetSelectedEntry();
766 m_rXLSet.Put(XLineColorItem(aColor.second, aColor.first));
767
768 // Centered line end
769 if( m_xTsbCenterStart->get_state() == TRISTATE_TRUE )
770 m_rXLSet.Put( XLineStartCenterItem( true ) );
771 else if( m_xTsbCenterStart->get_state() == TRISTATE_FALSE )
772 m_rXLSet.Put( XLineStartCenterItem( false ) );
773
774 if( m_xTsbCenterEnd->get_state() == TRISTATE_TRUE )
775 m_rXLSet.Put( XLineEndCenterItem( true ) );
776 else if( m_xTsbCenterEnd->get_state() == TRISTATE_FALSE )
777 m_rXLSet.Put( XLineEndCenterItem( false ) );
778
779 // Transparency
780 sal_uInt16 nVal = m_xMtrTransparent->get_value(FieldUnit::PERCENT);
781 m_rXLSet.Put( XLineTransparenceItem( nVal ) );
782
783 m_aCtlPreview.SetLineAttributes(m_aXLineAttr.GetItemSet());
784}
785
786
787void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
788{
789 drawing::LineStyle eXLS; // drawing::LineStyle_NONE, drawing::LineStyle_SOLID, drawing::LineStyle_DASH
790
791 // Line style
792 const SfxPoolItem *pPoolItem;
793 long nSymType=SVX_SYMBOLTYPE_UNKNOWN(-100);
794 bool bPrevSym=false;
795 bool bEnable=true;
796 bool bIgnoreGraphic=false;
797 bool bIgnoreSize=false;
798 if(rAttrs->GetItemState(rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLTYPE(27000 +115)),true,&pPoolItem) == SfxItemState::SET)
799 {
800 nSymType=static_cast<const SfxInt32Item *>(pPoolItem)->GetValue();
801 }
802
803 if(nSymType == SVX_SYMBOLTYPE_AUTO(-2))
804 {
805 m_aSymbolGraphic=m_aAutoSymbolGraphic;
806 m_aSymbolSize=m_aSymbolLastSize=m_aAutoSymbolGraphic.GetPrefSize();
807 bPrevSym=true;
808 }
809 else if(nSymType == SVX_SYMBOLTYPE_NONE(-3))
810 {
811 bEnable=false;
812 bIgnoreGraphic=true;
813 bIgnoreSize=true;
814 }
815 else if(nSymType >= 0)
816 {
817 ScopedVclPtrInstance< VirtualDevice > pVDev;
818 pVDev->SetMapMode(MapMode(MapUnit::Map100thMM));
819
820 std::unique_ptr<SdrModel> pModel(
821 new SdrModel(nullptr, nullptr, true));
822 pModel->GetItemPool().FreezeIdRanges();
823 SdrPage* pPage = new SdrPage( *pModel, false );
824 pPage->SetSize(Size(1000,1000));
825 pModel->InsertPage( pPage, 0 );
826 {
827 std::unique_ptr<SdrView> pView(new SdrView( *pModel, pVDev ));
828 pView->hideMarkHandles();
829 pView->ShowSdrPage(pPage);
830 size_t nSymTmp = static_cast<size_t>(nSymType);
831 if(m_pSymbolList)
832 {
833 if(m_pSymbolList->GetObjCount())
834 {
835 nSymTmp %= m_pSymbolList->GetObjCount(); // Treat list as cyclic!
836 SdrObject *pObj=m_pSymbolList->GetObj(nSymTmp);
837 if(pObj)
838 {
839 // directly clone to target SdrModel
840 pObj = pObj->CloneSdrObject(*pModel);
841
842 if(m_pSymbolAttr)
843 {
844 pObj->SetMergedItemSet(*m_pSymbolAttr);
845 }
846 else
847 {
848 pObj->SetMergedItemSet(m_rOutAttrs);
849 }
850
851 pPage->NbcInsertObject(pObj);
852
853 // Generate invisible square to give all symbol types a
854 // bitmap size, which is independent from specific glyph
855 SdrObject* pInvisibleSquare(m_pSymbolList->GetObj(0));
856
857 // directly clone to target SdrModel
858 pInvisibleSquare = pInvisibleSquare->CloneSdrObject(*pModel);
859
860 pPage->NbcInsertObject(pInvisibleSquare);
861 pInvisibleSquare->SetMergedItem(XFillTransparenceItem(100));
862 pInvisibleSquare->SetMergedItem(XLineTransparenceItem(100));
863
864 pView->MarkAll();
865 GDIMetaFile aMeta(pView->GetMarkedObjMetaFile());
866
867 m_aSymbolGraphic=Graphic(aMeta);
868 m_aSymbolSize=pObj->GetSnapRect().GetSize();
869 m_aSymbolGraphic.SetPrefSize(pInvisibleSquare->GetSnapRect().GetSize());
870 m_aSymbolGraphic.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
871 bPrevSym=true;
872 bEnable=true;
873 bIgnoreGraphic=true;
874
875 pView->UnmarkAll();
876 pInvisibleSquare=pPage->RemoveObject(1);
877 SdrObject::Free( pInvisibleSquare);
878 pObj=pPage->RemoveObject(0);
879 SdrObject::Free( pObj );
880 }
881 }
882 }
883 }
884 }
885 if(rAttrs->GetItemState(rAttrs->GetPool()->GetWhich(SID_ATTR_BRUSH( 10000 + 1 )),true,&pPoolItem) == SfxItemState::SET)
886 {
887 const Graphic* pGraphic = static_cast<const SvxBrushItem *>(pPoolItem)->GetGraphic();
888 if( pGraphic )
889 {
890 if(!bIgnoreGraphic)
891 {
892 m_aSymbolGraphic=*pGraphic;
893 }
894 if(!bIgnoreSize)
895 {
896 m_aSymbolSize=OutputDevice::LogicToLogic( pGraphic->GetPrefSize(),
897 pGraphic->GetPrefMapMode(),
898 MapMode(MapUnit::Map100thMM));
899 }
900 bPrevSym=true;
901 }
902 }
903
904 if(rAttrs->GetItemState(rAttrs->GetPool()->GetWhich(SID_ATTR_SYMBOLSIZE(27000 +116)),true,&pPoolItem) == SfxItemState::SET)
905 {
906 m_aSymbolSize = static_cast<const SvxSizeItem *>(pPoolItem)->GetSize();
907 }
908
909 m_xGridIconSize->set_sensitive(bEnable);
910
911 if(bPrevSym)
912 {
913 SetMetricValue(*m_xSymbolWidthMF, m_aSymbolSize.Width(), m_ePoolUnit);
914 SetMetricValue(*m_xSymbolHeightMF, m_aSymbolSize.Height(),m_ePoolUnit);
915 m_aCtlPreview.SetSymbol(&m_aSymbolGraphic,m_aSymbolSize);
916 m_aSymbolLastSize=m_aSymbolSize;
917 }
918
919 if( rAttrs->GetItemState( XATTR_LINESTYLE ) != SfxItemState::DONTCARE )
920 {
921 eXLS = rAttrs->Get( XATTR_LINESTYLE ).GetValue();
922
923 switch( eXLS )
924 {
925 case drawing::LineStyle_NONE:
926 m_xLbLineStyle->set_active(0);
927 break;
928 case drawing::LineStyle_SOLID:
929 m_xLbLineStyle->set_active(1);
930 break;
931
932 case drawing::LineStyle_DASH:
933 m_xLbLineStyle->set_active(-1);
934 m_xLbLineStyle->set_active_text(rAttrs->Get( XATTR_LINEDASH ).GetName());
935 break;
936
937 default:
938 break;
939 }
940 }
941 else
942 {
943 m_xLbLineStyle->set_active(-1);
944 }
945
946 // Line strength
947 if( rAttrs->GetItemState( XATTR_LINEWIDTH ) != SfxItemState::DONTCARE )
948 {
949 SetMetricValue( *m_xMtrLineWidth, rAttrs->Get( XATTR_LINEWIDTH ).GetValue(), m_ePoolUnit );
950 }
951 else
952 m_xMtrLineWidth->set_text("");
953
954 // Line color
955 m_xLbColor->SetNoSelection();
956
957 if ( rAttrs->GetItemState( XATTR_LINECOLOR ) != SfxItemState::DONTCARE )
958 {
959 Color aCol = rAttrs->Get( XATTR_LINECOLOR ).GetColorValue();
960 m_xLbColor->SelectEntry( aCol );
961 }
962
963 // Line start
964 if( m_bObjSelected && rAttrs->GetItemState( XATTR_LINESTART ) == SfxItemState::DEFAULT )
965 {
966 m_xLbStartStyle->set_sensitive(false);
967 }
968 else if( rAttrs->GetItemState( XATTR_LINESTART ) != SfxItemState::DONTCARE )
969 {
970 // #86265# select entry using list and polygon, not string
971 bool bSelected(false);
972 const basegfx::B2DPolyPolygon& rItemPolygon = rAttrs->Get(XATTR_LINESTART).GetLineStartValue();
973
974 for(long a(0);!bSelected && a < m_pLineEndList->Count(); a++)
975 {
976 const XLineEndEntry* pEntry = m_pLineEndList->GetLineEnd(a);
977 const basegfx::B2DPolyPolygon& rEntryPolygon = pEntry->GetLineEnd();
978
979 if(rItemPolygon == rEntryPolygon)
980 {
981 // select this entry
982 m_xLbStartStyle->set_active(a + 1);
983 bSelected = true;
984 }
985 }
986
987 if(!bSelected)
988 m_xLbStartStyle->set_active(0);
989 }
990 else
991 {
992 m_xLbStartStyle->set_active(-1);
993 }
994
995 // Line end
996 if( m_bObjSelected && rAttrs->GetItemState( XATTR_LINEEND ) == SfxItemState::DEFAULT )
997 {
998 m_xLbEndStyle->set_sensitive(false);
999 }
1000 else if( rAttrs->GetItemState( XATTR_LINEEND ) != SfxItemState::DONTCARE )
1001 {
1002 // #86265# select entry using list and polygon, not string
1003 bool bSelected(false);
1004 const basegfx::B2DPolyPolygon& rItemPolygon = rAttrs->Get(XATTR_LINEEND).GetLineEndValue();
1005
1006 for(long a(0);!bSelected && a < m_pLineEndList->Count(); a++)
1007 {
1008 const XLineEndEntry* pEntry = m_pLineEndList->GetLineEnd(a);
1009 const basegfx::B2DPolyPolygon& rEntryPolygon = pEntry->GetLineEnd();
1010
1011 if(rItemPolygon == rEntryPolygon)
1012 {
1013 // select this entry
1014 m_xLbEndStyle->set_active(a + 1);
1015 bSelected = true;
1016 }
1017 }
1018
1019 if(!bSelected)
1020 m_xLbEndStyle->set_active(0);
1021 }
1022 else
1023 {
1024 m_xLbEndStyle->set_active(-1);
1025 }
1026
1027 // Line start strength
1028 if( m_bObjSelected && rAttrs->GetItemState( XATTR_LINESTARTWIDTH ) == SfxItemState::DEFAULT )
1029 {
1030 m_xMtrStartWidth->set_sensitive(false);
1031 }
1032 else if( rAttrs->GetItemState( XATTR_LINESTARTWIDTH ) != SfxItemState::DONTCARE )
1033 {
1034 SetMetricValue( *m_xMtrStartWidth,
1035 rAttrs->Get( XATTR_LINESTARTWIDTH ).GetValue(),
1036 m_ePoolUnit );
1037 }
1038 else
1039 m_xMtrStartWidth->set_text( "" );
1040
1041 // Line end strength
1042 if( m_bObjSelected && rAttrs->GetItemState( XATTR_LINEENDWIDTH ) == SfxItemState::DEFAULT )
1043 {
1044 m_xMtrEndWidth->set_sensitive(false);
1045 }
1046 else if( rAttrs->GetItemState( XATTR_LINEENDWIDTH ) != SfxItemState::DONTCARE )
1047 {
1048 SetMetricValue( *m_xMtrEndWidth,
1049 rAttrs->Get( XATTR_LINEENDWIDTH ).GetValue(),
1050 m_ePoolUnit );
1051 }
1052 else
1053 m_xMtrEndWidth->set_text("");
1054
1055 // Centered line end (start)
1056 if( m_bObjSelected && rAttrs->GetItemState( XATTR_LINESTARTCENTER ) == SfxItemState::DEFAULT )
1057 {
1058 m_xTsbCenterStart->set_sensitive(false);
1059 }
1060 else if( rAttrs->GetItemState( XATTR_LINESTARTCENTER ) != SfxItemState::DONTCARE )
1061 {
1062 if( rAttrs->Get( XATTR_LINESTARTCENTER ).GetValue() )
1063 m_xTsbCenterStart->set_state(TRISTATE_TRUE);
1064 else
1065 m_xTsbCenterStart->set_state(TRISTATE_FALSE);
1066 }
1067 else
1068 {
1069 m_xTsbCenterStart->set_state(TRISTATE_INDET);
1070 }
1071
1072 // Centered line end (end)
1073 if( m_bObjSelected && rAttrs->GetItemState( XATTR_LINEENDCENTER ) == SfxItemState::DEFAULT )
1074 {
1075 m_xTsbCenterEnd->set_sensitive(false);
1076 }
1077 else if( rAttrs->GetItemState( XATTR_LINEENDCENTER ) != SfxItemState::DONTCARE )
1078 {
1079 if( rAttrs->Get( XATTR_LINEENDCENTER ).GetValue() )
1080 m_xTsbCenterEnd->set_state(TRISTATE_TRUE);
1081 else
1082 m_xTsbCenterEnd->set_state(TRISTATE_FALSE);
1083 }
1084 else
1085 {
1086 m_xTsbCenterEnd->set_state(TRISTATE_INDET);
1087 }
1088
1089 // Transparency
1090 if( rAttrs->GetItemState( XATTR_LINETRANSPARENCE ) != SfxItemState::DONTCARE )
1091 {
1092 sal_uInt16 nTransp = rAttrs->Get( XATTR_LINETRANSPARENCE ).GetValue();
1093 m_xMtrTransparent->set_value(nTransp, FieldUnit::PERCENT);
1094 ChangeTransparentHdl_Impl(*m_xMtrTransparent);
1095 }
1096 else
1097 m_xMtrTransparent->set_text( "" );
1098
1099 if( !m_xLbStartStyle->get_sensitive() &&
1100 !m_xLbEndStyle->get_sensitive() &&
1101 !m_xMtrStartWidth->get_sensitive() &&
1102 !m_xMtrEndWidth->get_sensitive() &&
1103 !m_xTsbCenterStart->get_sensitive()&&
1104 !m_xTsbCenterEnd->get_sensitive() )
1105 {
1106 m_xCbxSynchronize->set_sensitive(false);
1107 m_xFlLineEnds->set_sensitive(false);
1108 }
1109
1110 // Synchronize
1111 // We get the value from the INI file now
1112 OUString aStr = GetUserData();
1113 m_xCbxSynchronize->set_active(aStr.toInt32() != 0);
1114
1115 if(m_bObjSelected && SfxItemState::DEFAULT == rAttrs->GetItemState(XATTR_LINEJOINT))
1116 {
1117// maFTEdgeStyle.set_sensitive(false);
1118 m_xLBEdgeStyle->set_sensitive(false);
1119 }
1120 else if(SfxItemState::DONTCARE != rAttrs->GetItemState(XATTR_LINEJOINT))
1121 {
1122 const css::drawing::LineJoint eLineJoint = rAttrs->Get(XATTR_LINEJOINT).GetValue();
1123
1124 switch(eLineJoint)
1125 {
1126 case css::drawing::LineJoint::LineJoint_MAKE_FIXED_SIZE: // fallback to round, unused value
1127 case css::drawing::LineJoint_ROUND : m_xLBEdgeStyle->set_active(0); break;
1128 case css::drawing::LineJoint_NONE : m_xLBEdgeStyle->set_active(1); break;
1129 case css::drawing::LineJoint_MIDDLE : // fallback to mitre, unused value
1130 case css::drawing::LineJoint_MITER : m_xLBEdgeStyle->set_active(2); break;
1131 case css::drawing::LineJoint_BEVEL : m_xLBEdgeStyle->set_active(3); break;
1132 }
1133 }
1134 else
1135 {
1136 m_xLBEdgeStyle->set_active(-1);
1137 }
1138
1139 // fdo#43209
1140 if(m_bObjSelected && SfxItemState::DEFAULT == rAttrs->GetItemState(XATTR_LINECAP))
1141 {
1142 m_xLBCapStyle->set_sensitive(false);
1143 }
1144 else if(SfxItemState::DONTCARE != rAttrs->GetItemState(XATTR_LINECAP))
1145 {
1146 const css::drawing::LineCap eLineCap(rAttrs->Get(XATTR_LINECAP).GetValue());
1147
1148 switch(eLineCap)
1149 {
1150 case css::drawing::LineCap_ROUND: m_xLBCapStyle->set_active(1); break;
1151 case css::drawing::LineCap_SQUARE : m_xLBCapStyle->set_active(2); break;
1152 default /*css::drawing::LineCap_BUTT*/: m_xLBCapStyle->set_active(0); break;
1153 }
1154 }
1155 else
1156 {
1157 m_xLBCapStyle->set_active(-1);
1158 }
1159
1160 // Save values
1161 m_xLbLineStyle->save_value();
1162 m_xMtrLineWidth->save_value();
1163 m_xLbColor->SaveValue();
1164 m_xLbStartStyle->save_value();
1165 m_xLbEndStyle->save_value();
1166 m_xMtrStartWidth->save_value();
1167 m_xMtrEndWidth->save_value();
1168 m_xTsbCenterStart->save_state();
1169 m_xTsbCenterEnd->save_state();
1170 m_xMtrTransparent->save_value();
1171
1172 m_xLBEdgeStyle->save_value();
1173
1174 // LineCaps
1175 m_xLBCapStyle->save_value();
1176
1177 ClickInvisibleHdl_Impl();
1178
1179 ChangePreviewHdl_Impl( nullptr );
1180}
1181
1182std::unique_ptr<SfxTabPage> SvxLineTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
1183 const SfxItemSet* rAttrs)
1184{
1185 return std::make_unique<SvxLineTabPage>(pPage, pController, *rAttrs);
1186}
1187
1188IMPL_LINK_NOARG(SvxLineTabPage, ChangePreviewListBoxHdl_Impl, ColorListBox&, void)void SvxLineTabPage::LinkStubChangePreviewListBoxHdl_Impl(void
* instance, ColorListBox& data) { return static_cast<
SvxLineTabPage *>(instance)->ChangePreviewListBoxHdl_Impl
(data); } void SvxLineTabPage::ChangePreviewListBoxHdl_Impl(__attribute__
((unused)) ColorListBox&)
1189{
1190 ChangePreviewHdl_Impl(nullptr);
1191}
1192
1193IMPL_LINK(SvxLineTabPage, ChangePreviewModifyHdl_Impl, weld::MetricSpinButton&, rEdit, void)void SvxLineTabPage::LinkStubChangePreviewModifyHdl_Impl(void
* instance, weld::MetricSpinButton& data) { return static_cast
<SvxLineTabPage *>(instance)->ChangePreviewModifyHdl_Impl
(data); } void SvxLineTabPage::ChangePreviewModifyHdl_Impl(weld
::MetricSpinButton& rEdit)
1194{
1195 ChangePreviewHdl_Impl(&rEdit);
1196}
1197
1198void SvxLineTabPage::ChangePreviewHdl_Impl(const weld::MetricSpinButton* pCntrl)
1199{
1200 if (pCntrl == m_xMtrLineWidth.get())
1201 {
1202 // Line width and start end width
1203 sal_Int32 nNewLineWidth = GetCoreValue( *m_xMtrLineWidth, m_ePoolUnit );
1204 if(m_nActLineWidth == -1)
1205 {
1206 // Don't initialize yet, get the start value
1207 const SfxPoolItem* pOld = GetOldItem( m_rXLSet, XATTR_LINEWIDTH );
1208 sal_Int32 nStartLineWidth = 0;
1209 if(pOld)
1210 nStartLineWidth = static_cast<const XLineWidthItem *>(pOld)->GetValue();
1211 m_nActLineWidth = nStartLineWidth;
1212 }
1213
1214 if(m_nActLineWidth != nNewLineWidth)
1215 {
1216 // Adapt start/end width
1217 sal_Int32 nValAct = GetCoreValue( *m_xMtrStartWidth, m_ePoolUnit );
1218 sal_Int32 nValNew = nValAct + (((nNewLineWidth - m_nActLineWidth) * 15) / 10);
1219 if(nValNew < 0)
1220 nValNew = 0;
1221 SetMetricValue( *m_xMtrStartWidth, nValNew, m_ePoolUnit );
1222
1223 nValAct = GetCoreValue( *m_xMtrEndWidth, m_ePoolUnit );
1224 nValNew = nValAct + (((nNewLineWidth - m_nActLineWidth) * 15) / 10);
1225 if(nValNew < 0)
1226 nValNew = 0;
1227 SetMetricValue( *m_xMtrEndWidth, nValNew, m_ePoolUnit );
1228 }
1229
1230 // Remember current value
1231 m_nActLineWidth = nNewLineWidth;
1232 }
1233
1234 FillXLSet_Impl();
1235 m_aCtlPreview.Invalidate();
1236
1237 // Make transparency accessible accordingly
1238 if( m_xLbLineStyle->get_active() == 0 ) // invisible
1239 {
1240 m_xBoxTransparency->set_sensitive(false);
1241 }
1242 else
1243 {
1244 m_xBoxTransparency->set_sensitive(true);
1245 }
1246
1247 const bool bHasLineStyle = m_xLbLineStyle->get_active() !=0;
1248 const bool bHasLineStart = m_xLbStartStyle->get_active() != 0;
1249
1250 m_xBoxStart->set_sensitive(bHasLineStart && bHasLineStyle);
1251
1252 const bool bHasLineEnd = m_xLbEndStyle->get_active() != 0;
1253
1254 m_xBoxEnd->set_sensitive(bHasLineEnd && bHasLineStyle);
1255}
1256
1257IMPL_LINK_NOARG(SvxLineTabPage, ChangeStartClickHdl_Impl, weld::Button&, void)void SvxLineTabPage::LinkStubChangeStartClickHdl_Impl(void * instance
, weld::Button& data) { return static_cast<SvxLineTabPage
*>(instance)->ChangeStartClickHdl_Impl(data); } void SvxLineTabPage
::ChangeStartClickHdl_Impl(__attribute__ ((unused)) weld::Button
&)
1258{
1259 if (m_xCbxSynchronize->get_active())
1260 m_xTsbCenterEnd->set_state(m_xTsbCenterStart->get_state());
1261 ChangePreviewHdl_Impl(nullptr);
1262}
1263
1264IMPL_LINK_NOARG(SvxLineTabPage, ChangeStartListBoxHdl_Impl, weld::ComboBox&, void)void SvxLineTabPage::LinkStubChangeStartListBoxHdl_Impl(void *
instance, weld::ComboBox& data) { return static_cast<
SvxLineTabPage *>(instance)->ChangeStartListBoxHdl_Impl
(data); } void SvxLineTabPage::ChangeStartListBoxHdl_Impl(__attribute__
((unused)) weld::ComboBox&)
1265{
1266 if (m_xCbxSynchronize->get_active())
1267 m_xLbEndStyle->set_active(m_xLbStartStyle->get_active());
1268
1269 ChangePreviewHdl_Impl(nullptr);
1270}
1271
1272IMPL_LINK_NOARG(SvxLineTabPage, ChangeStartModifyHdl_Impl, weld::MetricSpinButton&, void)void SvxLineTabPage::LinkStubChangeStartModifyHdl_Impl(void *
instance, weld::MetricSpinButton& data) { return static_cast
<SvxLineTabPage *>(instance)->ChangeStartModifyHdl_Impl
(data); } void SvxLineTabPage::ChangeStartModifyHdl_Impl(__attribute__
((unused)) weld::MetricSpinButton&)
1273{
1274 if (m_xCbxSynchronize->get_active())
1275 m_xMtrEndWidth->set_value(m_xMtrStartWidth->get_value(FieldUnit::NONE), FieldUnit::NONE);
1276
1277 ChangePreviewHdl_Impl(nullptr);
1278}
1279
1280IMPL_LINK_NOARG(SvxLineTabPage, ChangeEdgeStyleHdl_Impl, weld::ComboBox&, void)void SvxLineTabPage::LinkStubChangeEdgeStyleHdl_Impl(void * instance
, weld::ComboBox& data) { return static_cast<SvxLineTabPage
*>(instance)->ChangeEdgeStyleHdl_Impl(data); } void SvxLineTabPage
::ChangeEdgeStyleHdl_Impl(__attribute__ ((unused)) weld::ComboBox
&)
1281{
1282 ChangePreviewHdl_Impl( nullptr );
1283}
1284
1285// fdo#43209
1286IMPL_LINK_NOARG(SvxLineTabPage, ChangeCapStyleHdl_Impl, weld::ComboBox&, void)void SvxLineTabPage::LinkStubChangeCapStyleHdl_Impl(void * instance
, weld::ComboBox& data) { return static_cast<SvxLineTabPage
*>(instance)->ChangeCapStyleHdl_Impl(data); } void SvxLineTabPage
::ChangeCapStyleHdl_Impl(__attribute__ ((unused)) weld::ComboBox
&)
1287{
1288 ChangePreviewHdl_Impl( nullptr );
1289}
1290
1291IMPL_LINK_NOARG(SvxLineTabPage, ClickInvisibleHdl_Impl, weld::ComboBox&, void)void SvxLineTabPage::LinkStubClickInvisibleHdl_Impl(void * instance
, weld::ComboBox& data) { return static_cast<SvxLineTabPage
*>(instance)->ClickInvisibleHdl_Impl(data); } void SvxLineTabPage
::ClickInvisibleHdl_Impl(__attribute__ ((unused)) weld::ComboBox
&)
1292{
1293 ClickInvisibleHdl_Impl();
1294}
1295
1296void SvxLineTabPage::ClickInvisibleHdl_Impl()
1297{
1298 if( m_xLbLineStyle->get_active() == 0 ) // invisible
1299 {
1300 if(!m_bSymbols)
1301 m_xBoxColor->set_sensitive(false);
1302
1303 m_xBoxWidth->set_sensitive(false);
1304
1305 if( m_xFlLineEnds->get_sensitive() )
1306 {
1307 m_xBoxStart->set_sensitive(false);
1308 m_xBoxArrowStyles->set_sensitive(false);
1309 m_xGridEdgeCaps->set_sensitive(false);
1310 }
1311 }
1312 else
1313 {
1314 m_xBoxColor->set_sensitive(true);
1315 m_xBoxWidth->set_sensitive(true);
1316
1317 if (m_xFlLineEnds->get_sensitive())
1318 {
1319 m_xBoxArrowStyles->set_sensitive(true);
1320 m_xGridEdgeCaps->set_sensitive(true);
1321 }
1322 }
1323 ChangePreviewHdl_Impl( nullptr );
1324}
1325
1326IMPL_LINK_NOARG(SvxLineTabPage, ChangeEndClickHdl_Impl, weld::Button&, void)void SvxLineTabPage::LinkStubChangeEndClickHdl_Impl(void * instance
, weld::Button& data) { return static_cast<SvxLineTabPage
*>(instance)->ChangeEndClickHdl_Impl(data); } void SvxLineTabPage
::ChangeEndClickHdl_Impl(__attribute__ ((unused)) weld::Button
&)
1327{
1328 if (m_xCbxSynchronize->get_active())
1329 m_xTsbCenterStart->set_state(m_xTsbCenterEnd->get_state());
1330
1331 ChangePreviewHdl_Impl(nullptr);
1332}
1333
1334IMPL_LINK_NOARG(SvxLineTabPage, ChangeEndListBoxHdl_Impl, weld::ComboBox&, void)void SvxLineTabPage::LinkStubChangeEndListBoxHdl_Impl(void * instance
, weld::ComboBox& data) { return static_cast<SvxLineTabPage
*>(instance)->ChangeEndListBoxHdl_Impl(data); } void SvxLineTabPage
::ChangeEndListBoxHdl_Impl(__attribute__ ((unused)) weld::ComboBox
&)
1335{
1336 if (m_xCbxSynchronize->get_active())
1337 m_xLbStartStyle->set_active(m_xLbEndStyle->get_active());
1338
1339 ChangePreviewHdl_Impl(nullptr);
1340}
1341
1342IMPL_LINK_NOARG(SvxLineTabPage, ChangeEndModifyHdl_Impl, weld::MetricSpinButton&, void)void SvxLineTabPage::LinkStubChangeEndModifyHdl_Impl(void * instance
, weld::MetricSpinButton& data) { return static_cast<SvxLineTabPage
*>(instance)->ChangeEndModifyHdl_Impl(data); } void SvxLineTabPage
::ChangeEndModifyHdl_Impl(__attribute__ ((unused)) weld::MetricSpinButton
&)
1343{
1344 if (m_xCbxSynchronize->get_active())
1345 m_xMtrStartWidth->set_value(m_xMtrEndWidth->get_value(FieldUnit::NONE), FieldUnit::NONE);
1346
1347 ChangePreviewHdl_Impl(nullptr);
1348}
1349
1350IMPL_LINK_NOARG(SvxLineTabPage, ChangeTransparentHdl_Impl, weld::MetricSpinButton&, void)void SvxLineTabPage::LinkStubChangeTransparentHdl_Impl(void *
instance, weld::MetricSpinButton& data) { return static_cast
<SvxLineTabPage *>(instance)->ChangeTransparentHdl_Impl
(data); } void SvxLineTabPage::ChangeTransparentHdl_Impl(__attribute__
((unused)) weld::MetricSpinButton&)
1351{
1352 sal_uInt16 nVal = m_xMtrTransparent->get_value(FieldUnit::PERCENT);
1353
1354 m_rXLSet.Put(XLineTransparenceItem(nVal));
1355
1356 FillXLSet_Impl();
1357
1358 m_aCtlPreview.Invalidate();
1359}
1360
1361void SvxLineTabPage::FillUserData()
1362{
1363 // Write the synched value to the INI file
1364 OUString aStrUserData = OUString::boolean(m_xCbxSynchronize->get_active());
1365 SetUserData( aStrUserData );
1366}
1367
1368// #58425# Symbols on a list (e.g. StarChart)
1369// Handler for the symbol selection's popup menu (NumMenueButton)
1370// The following link originates from SvxNumOptionsTabPage
1371IMPL_LINK_NOARG(SvxLineTabPage, MenuCreateHdl_Impl, weld::ToggleButton&, void)void SvxLineTabPage::LinkStubMenuCreateHdl_Impl(void * instance
, weld::ToggleButton& data) { return static_cast<SvxLineTabPage
*>(instance)->MenuCreateHdl_Impl(data); } void SvxLineTabPage
::MenuCreateHdl_Impl(__attribute__ ((unused)) weld::ToggleButton
&)
1
Calling 'SvxLineTabPage::MenuCreateHdl_Impl'
1372{
1373 ScopedVclPtrInstance< VirtualDevice > pVD;
2
Calling default constructor for 'ScopedVclPtrInstance<VirtualDevice>'
4
Returning from default constructor for 'ScopedVclPtrInstance<VirtualDevice>'
1374
1375 // Initialize popup
1376 if (!m_xGalleryMenu)
5
Taking false branch
1377 {
1378 m_xGalleryMenu = m_xBuilder->weld_menu("gallerysubmenu");
1379 weld::WaitObject aWait(GetFrameWeld());
1380 // Get gallery entries
1381 GalleryExplorer::FillObjList(GALLERY_THEME_BULLETS3, m_aGrfNames);
1382
1383 sal_uInt32 i = 0;
1384 for (auto const& grfName : m_aGrfNames)
1385 {
1386 const OUString *pUIName = &grfName;
1387
1388 // Convert URL encodings to UI characters (e.g. %20 for spaces)
1389 OUString aPhysicalName;
1390 if (osl::FileBase::getSystemPathFromFileURL(grfName, aPhysicalName)
1391 == osl::FileBase::E_None)
1392 {
1393 pUIName = &aPhysicalName;
1394 }
1395
1396 SvxBmpItemInfo* pInfo = new SvxBmpItemInfo;
1397 pInfo->pBrushItem.reset(new SvxBrushItem(grfName, "", GPOS_AREA, SID_ATTR_BRUSH( 10000 + 1 )));
1398 pInfo->sItemId = "gallery" + OUString::number(i);
1399 m_aGalleryBrushItems.emplace_back(pInfo);
1400 const Graphic* pGraphic = pInfo->pBrushItem->GetGraphic();
1401
1402 if(pGraphic)
1403 {
1404 BitmapEx aBitmap(pGraphic->GetBitmapEx());
1405 Size aSize(aBitmap.GetSizePixel());
1406 if(aSize.Width() > MAX_BMP_WIDTH16 || aSize.Height() > MAX_BMP_HEIGHT16)
1407 {
1408 bool bWidth = aSize.Width() > aSize.Height();
1409 double nScale = bWidth ?
1410 double(MAX_BMP_WIDTH16) / static_cast<double>(aSize.Width()):
1411 double(MAX_BMP_HEIGHT16) / static_cast<double>(aSize.Height());
1412 aBitmap.Scale(nScale, nScale);
1413
1414 }
1415 pVD->SetOutputSizePixel(aBitmap.GetSizePixel());
1416 pVD->DrawBitmapEx(Point(), aBitmap);
1417 m_xGalleryMenu->append(pInfo->sItemId, *pUIName, *pVD);
1418 }
1419 else
1420 {
1421 m_xGalleryMenu->append(pInfo->sItemId, *pUIName);
1422 }
1423 ++i;
1424 }
1425
1426 if (m_aGrfNames.empty())
1427 m_xSymbolMB->set_item_sensitive("gallery", false);
1428 }
1429
1430 if (m_xSymbolsMenu || !m_pSymbolList)
1431 return;
6
Calling implicit destructor for 'ScopedVclPtrInstance<VirtualDevice>'
7
Calling '~ScopedVclPtr'
1432
1433 m_xSymbolsMenu = m_xBuilder->weld_menu("symbolssubmenu");
1434 ScopedVclPtrInstance< VirtualDevice > pVDev;
1435 pVDev->SetMapMode(MapMode(MapUnit::Map100thMM));
1436 std::unique_ptr<SdrModel> pModel(
1437 new SdrModel(nullptr, nullptr, true));
1438 pModel->GetItemPool().FreezeIdRanges();
1439 // Page
1440 SdrPage* pPage = new SdrPage( *pModel, false );
1441 pPage->SetSize(Size(1000,1000));
1442 pModel->InsertPage( pPage, 0 );
1443 {
1444 // 3D View
1445 std::unique_ptr<SdrView> pView(new SdrView( *pModel, pVDev ));
1446 pView->hideMarkHandles();
1447 pView->ShowSdrPage(pPage);
1448
1449 // Generate invisible square to give all symbols a
1450 // bitmap size, which is independent from specific glyph
1451 SdrObject *pInvisibleSquare=m_pSymbolList->GetObj(0);
1452
1453 // directly clone to target SdrModel
1454 pInvisibleSquare = pInvisibleSquare->CloneSdrObject(*pModel);
1455
1456 pPage->NbcInsertObject(pInvisibleSquare);
1457 pInvisibleSquare->SetMergedItem(XFillTransparenceItem(100));
1458 pInvisibleSquare->SetMergedItem(XLineTransparenceItem(100));
1459
1460 for(size_t i=0; i < m_pSymbolList->GetObjCount(); ++i)
1461 {
1462 SdrObject *pObj=m_pSymbolList->GetObj(i);
1463 assert(pObj)(static_cast <bool> (pObj) ? void (0) : __assert_fail (
"pObj", "/home/maarten/src/libreoffice/core/cui/source/tabpages/tpline.cxx"
, 1463, __extension__ __PRETTY_FUNCTION__))
;
1464
1465 // directly clone to target SdrModel
1466 pObj = pObj->CloneSdrObject(*pModel);
1467
1468 m_aGrfNames.emplace_back("");
1469 pPage->NbcInsertObject(pObj);
1470 if(m_pSymbolAttr)
1471 {
1472 pObj->SetMergedItemSet(*m_pSymbolAttr);
1473 }
1474 else
1475 {
1476 pObj->SetMergedItemSet(m_rOutAttrs);
1477 }
1478 pView->MarkAll();
1479 BitmapEx aBitmapEx(pView->GetMarkedObjBitmapEx());
1480 GDIMetaFile aMeta(pView->GetMarkedObjMetaFile());
1481 pView->UnmarkAll();
1482 pObj=pPage->RemoveObject(1);
1483 SdrObject::Free(pObj);
1484
1485 SvxBmpItemInfo* pInfo = new SvxBmpItemInfo;
1486 pInfo->pBrushItem.reset(new SvxBrushItem(Graphic(aMeta), GPOS_AREA, SID_ATTR_BRUSH( 10000 + 1 )));
1487 pInfo->sItemId = "symbol" + OUString::number(i);
1488 m_aSymbolBrushItems.emplace_back(pInfo);
1489
1490 Size aSize(aBitmapEx.GetSizePixel());
1491 if(aSize.Width() > MAX_BMP_WIDTH16 || aSize.Height() > MAX_BMP_HEIGHT16)
1492 {
1493 bool bWidth = aSize.Width() > aSize.Height();
1494 double nScale = bWidth ?
1495 double(MAX_BMP_WIDTH16) / static_cast<double>(aSize.Width()):
1496 double(MAX_BMP_HEIGHT16) / static_cast<double>(aSize.Height());
1497 aBitmapEx.Scale(nScale, nScale);
1498 }
1499 pVD->SetOutputSizePixel(aBitmapEx.GetSizePixel());
1500 pVD->DrawBitmapEx(Point(), aBitmapEx);
1501 m_xSymbolsMenu->append(pInfo->sItemId, "", *pVD);
1502 }
1503 pInvisibleSquare=pPage->RemoveObject(0);
1504 SdrObject::Free(pInvisibleSquare);
1505
1506 if (m_aGrfNames.empty())
1507 m_xSymbolMB->set_item_sensitive("symbols", false);
1508 }
1509}
1510
1511// #58425# Symbols on a list (e.g. StarChart)
1512// Handler for menu button
1513IMPL_LINK(SvxLineTabPage, GraphicHdl_Impl, const OString&, rIdent, void)void SvxLineTabPage::LinkStubGraphicHdl_Impl(void * instance,
const OString& data) { return static_cast<SvxLineTabPage
*>(instance)->GraphicHdl_Impl(data); } void SvxLineTabPage
::GraphicHdl_Impl(const OString& rIdent)
1514{
1515 const Graphic* pGraphic = nullptr;
1516 Graphic aGraphic;
1517 bool bResetSize = false;
1518 bool bEnable = true;
1519 long nPreviousSymbolType = m_nSymbolType;
1520
1521 OString sNumber;
1522 if (rIdent.startsWith("gallery", &sNumber))
1523 {
1524 SvxBmpItemInfo* pInfo = m_aGalleryBrushItems[sNumber.toUInt32()].get();
1525 pGraphic = pInfo->pBrushItem->GetGraphic();
1526 m_nSymbolType = SVX_SYMBOLTYPE_BRUSHITEM(-1);
1527 }
1528 else if (rIdent.startsWith("symbol", &sNumber))
1529 {
1530 m_nSymbolType = sNumber.toUInt32();
1531 SvxBmpItemInfo* pInfo = m_aSymbolBrushItems[m_nSymbolType].get();
1532 pGraphic = pInfo->pBrushItem->GetGraphic();
1533 }
1534 else if (rIdent == "automatic")
1535 {
1536 pGraphic=&m_aAutoSymbolGraphic;
1537 m_aAutoSymbolGraphic.SetPrefSize( Size(253,253) );
1538 m_nSymbolType=SVX_SYMBOLTYPE_AUTO(-2);
1539 }
1540 else if (rIdent == "none")
1541 {
1542 m_nSymbolType=SVX_SYMBOLTYPE_NONE(-3);
1543 pGraphic=nullptr;
1544 bEnable = false;
1545 }
1546 else if (rIdent == "file")
1547 {
1548 SvxOpenGraphicDialog aGrfDlg(CuiResId(RID_SVXSTR_EDIT_GRAPHICreinterpret_cast<char const *>("RID_SVXSTR_EDIT_GRAPHIC"
"\004" u8"Link")
), GetFrameWeld());
1549 aGrfDlg.EnableLink(false);
1550 aGrfDlg.AsLink(false);
1551 if( !aGrfDlg.Execute() )
1552 {
1553 // Remember selected filters
1554 if( !aGrfDlg.GetGraphic(aGraphic) )
1555 {
1556 m_nSymbolType=SVX_SYMBOLTYPE_BRUSHITEM(-1);
1557 pGraphic = &aGraphic;
1558 bResetSize = true;
1559 }
1560 }
1561 if( !pGraphic )
1562 return;
1563 }
1564
1565 if (pGraphic)
1566 {
1567 Size aSize = SvxNumberFormat::GetGraphicSizeMM100(pGraphic);
1568 aSize = OutputDevice::LogicToLogic(aSize, MapMode(MapUnit::Map100thMM), MapMode(m_ePoolUnit));
1569 m_aSymbolGraphic=*pGraphic;
1570 if( bResetSize )
1571 {
1572 m_aSymbolSize=aSize;
1573 }
1574 else if( nPreviousSymbolType == SVX_SYMBOLTYPE_BRUSHITEM(-1) )
1575 { //#i31097# Data Point Symbol size changes when a different symbol is chosen(maoyg)
1576 if( m_aSymbolSize.Width() != m_aSymbolSize.Height() )
1577 {
1578 aSize.setWidth( static_cast<long>( m_aSymbolSize.Width() + m_aSymbolSize.Height() )/2 );
1579 aSize.setHeight( static_cast<long>( m_aSymbolSize.Width() + m_aSymbolSize.Height() )/2 );
1580 m_aSymbolSize = aSize;
1581 }
1582 }
1583 m_aCtlPreview.SetSymbol(&m_aSymbolGraphic,m_aSymbolSize);
1584 }
1585 else
1586 {
1587 m_aSymbolGraphic=Graphic();
1588 m_aCtlPreview.SetSymbol(nullptr,m_aSymbolSize);
1589 bEnable = false;
1590 }
1591 m_aSymbolLastSize=m_aSymbolSize;
1592 SetMetricValue(*m_xSymbolWidthMF, m_aSymbolSize.Width(), m_ePoolUnit);
1593 SetMetricValue(*m_xSymbolHeightMF, m_aSymbolSize.Height(), m_ePoolUnit);
1594
1595 m_xGridIconSize->set_sensitive(bEnable);
1596 m_aCtlPreview.Invalidate();
1597}
1598
1599IMPL_LINK( SvxLineTabPage, SizeHdl_Impl, weld::MetricSpinButton&, rField, void)void SvxLineTabPage::LinkStubSizeHdl_Impl(void * instance, weld
::MetricSpinButton& data) { return static_cast<SvxLineTabPage
*>(instance)->SizeHdl_Impl(data); } void SvxLineTabPage
::SizeHdl_Impl(weld::MetricSpinButton& rField)
1600{
1601 m_bNewSize = true;
1602 bool bWidth = &rField == m_xSymbolWidthMF.get();
1603 m_bLastWidthModified = bWidth;
1604 bool bRatio = m_xSymbolRatioCB->get_active();
1605 long nWidthVal = static_cast<long>(m_xSymbolWidthMF->denormalize(m_xSymbolWidthMF->get_value(FieldUnit::MM_100TH)));
1606 long nHeightVal= static_cast<long>(m_xSymbolHeightMF->denormalize(m_xSymbolHeightMF->get_value(FieldUnit::MM_100TH)));
1607 nWidthVal = OutputDevice::LogicToLogic(nWidthVal,MapUnit::Map100thMM, m_ePoolUnit );
1608 nHeightVal = OutputDevice::LogicToLogic(nHeightVal,MapUnit::Map100thMM, m_ePoolUnit);
1609 m_aSymbolSize = Size(nWidthVal,nHeightVal);
1610 double fSizeRatio = double(1);
1611
1612 if(bRatio)
1613 {
1614 if (m_aSymbolLastSize.Height() && m_aSymbolLastSize.Width())
1615 fSizeRatio = static_cast<double>(m_aSymbolLastSize.Width()) / m_aSymbolLastSize.Height();
1616 }
1617
1618 if (bWidth)
1619 {
1620 long nDelta = nWidthVal - m_aSymbolLastSize.Width();
1621 m_aSymbolSize.setWidth( nWidthVal );
1622 if (bRatio)
1623 {
1624 m_aSymbolSize.setHeight( m_aSymbolLastSize.Height() + static_cast<long>(static_cast<double>(nDelta) / fSizeRatio) );
1625 m_aSymbolSize.setHeight( OutputDevice::LogicToLogic( m_aSymbolSize.Height(), m_ePoolUnit, MapUnit::Map100thMM ) );
1626//TODO m_xSymbolHeightMF->SetUserValue(m_xSymbolHeightMF->normalize(m_aSymbolSize.Height()), FieldUnit::MM_100TH);
1627 m_xSymbolHeightMF->set_value(m_xSymbolHeightMF->normalize(m_aSymbolSize.Height()), FieldUnit::MM_100TH);
1628 }
1629 }
1630 else
1631 {
1632 long nDelta = nHeightVal - m_aSymbolLastSize.Height();
1633 m_aSymbolSize.setHeight( nHeightVal );
1634 if (bRatio)
1635 {
1636 m_aSymbolSize.setWidth( m_aSymbolLastSize.Width() + static_cast<long>(static_cast<double>(nDelta) * fSizeRatio) );
1637 m_aSymbolSize.setWidth( OutputDevice::LogicToLogic( m_aSymbolSize.Width(), m_ePoolUnit, MapUnit::Map100thMM ) );
1638//TODO m_xSymbolWidthMF->SetUserValue(m_xSymbolWidthMF->normalize(m_aSymbolSize.Width()), FieldUnit::MM_100TH);
1639 m_xSymbolWidthMF->set_value(m_xSymbolWidthMF->normalize(m_aSymbolSize.Width()), FieldUnit::MM_100TH);
1640 }
1641 }
1642 m_aCtlPreview.ResizeSymbol(m_aSymbolSize);
1643 m_aSymbolLastSize=m_aSymbolSize;
1644}
1645
1646IMPL_LINK(SvxLineTabPage, RatioHdl_Impl, weld::ToggleButton&, rBox, void)void SvxLineTabPage::LinkStubRatioHdl_Impl(void * instance, weld
::ToggleButton& data) { return static_cast<SvxLineTabPage
*>(instance)->RatioHdl_Impl(data); } void SvxLineTabPage
::RatioHdl_Impl(weld::ToggleButton& rBox)
1647{
1648 if (rBox.get_active())
1649 {
1650 if (m_bLastWidthModified)
1651 SizeHdl_Impl(*m_xSymbolWidthMF);
1652 else
1653 SizeHdl_Impl(*m_xSymbolHeightMF);
1654 }
1655}
1656
1657void SvxLineTabPage::PageCreated(const SfxAllItemSet& aSet)
1658{
1659 const SvxDashListItem* pDashListItem = aSet.GetItem<SvxDashListItem>(SID_DASH_LISTTypedWhichId<SvxDashListItem>( 10000 + 184 ), false);
1660 const SvxLineEndListItem* pLineEndListItem = aSet.GetItem<SvxLineEndListItem>(SID_LINEEND_LISTTypedWhichId<SvxLineEndListItem>( 10000 + 185 ), false);
1661 const SfxUInt16Item* pPageTypeItem = aSet.GetItem<SfxUInt16Item>(SID_PAGE_TYPE( 10000 + 1017 ), false);
1662 const SfxUInt16Item* pDlgTypeItem = aSet.GetItem<SfxUInt16Item>(SID_DLG_TYPE( 10000 + 1018 ), false);
1663 const OfaPtrItem* pSdrObjListItem = aSet.GetItem<OfaPtrItem>(SID_OBJECT_LIST( 10000 + 1021 ), false);
1664 const SfxTabDialogItem* pSymbolAttrItem = aSet.GetItem<SfxTabDialogItem>(SID_ATTR_SET( 10000 + 1022 ), false);
1665 const SvxGraphicItem* pGraphicItem = aSet.GetItem<SvxGraphicItem>(SID_GRAPHIC( 10000 + 1020 ), false);
1666
1667 if (pDashListItem)
1668 SetDashList(pDashListItem->GetDashList());
1669 if (pLineEndListItem)
1670 SetLineEndList(pLineEndListItem->GetLineEndList());
1671 if (pPageTypeItem)
1672 SetPageType(static_cast<PageType>(pPageTypeItem->GetValue()));
1673 if (pDlgTypeItem)
1674 SetDlgType(pDlgTypeItem->GetValue());
1675 Construct();
1676
1677 if(pSdrObjListItem) //symbols
1678 {
1679 ShowSymbolControls(true);
1680 m_pSymbolList = static_cast<SdrObjList*>(pSdrObjListItem->GetValue());
1681 if (pSymbolAttrItem)
1682 m_pSymbolAttr = new SfxItemSet(pSymbolAttrItem->GetItemSet());
1683 if(pGraphicItem)
1684 m_aAutoSymbolGraphic = pGraphicItem->GetGraphic();
1685 }
1686}
1687
1688/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.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_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
9
Calling 'Reference::clear'
16
Returning; memory was released
205 if (aTmp.get()) {
17
Calling 'Reference::get'
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
8
Calling 'VclPtr::disposeAndClear'
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
3
Memory is allocated
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* 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)
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)
113 m_pBody->release();
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
9.1
Field 'm_pBody' is non-null
9.1
Field 'm_pBody' is non-null
9.1
Field 'm_pBody' is non-null
9.1
Field 'm_pBody' is non-null
)
10
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
11
Calling 'VclReferenceBase::release'
15
Returning; memory was released
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;
18
Use of memory after it is freed
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)
12
Assuming the condition is true
13
Taking true branch
40 delete this;
14
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