File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <svl/itemiter.hxx> | |||
21 | #include <sfx2/objsh.hxx> | |||
22 | #include <svx/svxids.hrc> | |||
23 | ||||
24 | #include <svl/intitem.hxx> | |||
25 | #include <svtools/unitconv.hxx> | |||
26 | ||||
27 | #include <svx/hdft.hxx> | |||
28 | #include <svx/pageitem.hxx> | |||
29 | ||||
30 | #include <svx/dlgutil.hxx> | |||
31 | #include <sfx2/htmlmode.hxx> | |||
32 | #include <osl/diagnose.h> | |||
33 | ||||
34 | #include <editeng/brushitem.hxx> | |||
35 | #include <editeng/lrspitem.hxx> | |||
36 | #include <editeng/ulspitem.hxx> | |||
37 | #include <editeng/sizeitem.hxx> | |||
38 | #include <editeng/boxitem.hxx> | |||
39 | ||||
40 | #include <svx/svxdlg.hxx> | |||
41 | #include <memory> | |||
42 | ||||
43 | #include <svx/xdef.hxx> | |||
44 | #include <svx/xfillit0.hxx> | |||
45 | #include <svx/unobrushitemhelper.hxx> | |||
46 | ||||
47 | using namespace com::sun::star; | |||
48 | ||||
49 | // Word 97 incompatibility (#i19922#) | |||
50 | // #i19922# - tdf#126051 see cui/source/tabpages/page.cxx and sw/source/uibase/sidebar/PageMarginControl.hxx | |||
51 | const long MINBODY = 56; // 1mm in twips rounded | |||
52 | ||||
53 | // default distance to Header or footer | |||
54 | const long DEF_DIST_WRITER = 500; // 5mm (Writer) | |||
55 | const long DEF_DIST_CALC = 250; // 2.5mm (Calc) | |||
56 | ||||
57 | const sal_uInt16 SvxHFPage::pRanges[] = | |||
58 | { | |||
59 | SID_ATTR_BRUSH( 10000 + 1 ), SID_ATTR_BRUSH( 10000 + 1 ), | |||
60 | ||||
61 | // Support DrawingLayer FillStyles (no real call to below GetRanges() | |||
62 | // detected, still do the complete transition) | |||
63 | XATTR_FILL_FIRST, XATTR_FILL_LAST, | |||
64 | ||||
65 | SID_ATTR_BORDER_OUTER( 10000 + 24 ), SID_ATTR_BORDER_OUTER( 10000 + 24 ), | |||
66 | SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), | |||
67 | SID_ATTR_BORDER_SHADOW( 10000 + 25 ), SID_ATTR_BORDER_SHADOW( 10000 + 25 ), | |||
68 | SID_ATTR_LRSPACE( 10000 + 48 ), SID_ATTR_LRSPACE( 10000 + 48 ), | |||
69 | SID_ATTR_ULSPACE( 10000 + 49 ), SID_ATTR_ULSPACE( 10000 + 49 ), | |||
70 | SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ), SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ), | |||
71 | SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ), SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ), | |||
72 | SID_ATTR_PAGE_FOOTERSETTypedWhichId<SvxSetItem>( 10000 + 58 ), SID_ATTR_PAGE_FOOTERSETTypedWhichId<SvxSetItem>( 10000 + 58 ), | |||
73 | SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 ), SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 ), | |||
74 | SID_ATTR_PAGE_DYNAMICTypedWhichId<SfxBoolItem>( 10000 + 60 ), SID_ATTR_PAGE_DYNAMICTypedWhichId<SfxBoolItem>( 10000 + 60 ), | |||
75 | SID_ATTR_PAGE_SHAREDTypedWhichId<SfxBoolItem>( 10000 + 61 ), SID_ATTR_PAGE_SHAREDTypedWhichId<SfxBoolItem>( 10000 + 61 ), | |||
76 | SID_ATTR_PAGE_SHARED_FIRST( 10000 + 1114 ), SID_ATTR_PAGE_SHARED_FIRST( 10000 + 1114 ), | |||
77 | SID_ATTR_HDFT_DYNAMIC_SPACING( 10000 + 953 ), SID_ATTR_HDFT_DYNAMIC_SPACING( 10000 + 953 ), | |||
78 | 0 | |||
79 | }; | |||
80 | ||||
81 | namespace svx { | |||
82 | ||||
83 | bool ShowBorderBackgroundDlg(weld::Window* pParent, SfxItemSet* pBBSet) | |||
84 | { | |||
85 | bool bRes = false; | |||
86 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | |||
87 | ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxBorderBackgroundDlg(pParent, *pBBSet, true /*bEnableDrawingLayerFillStyles*/)); | |||
| ||||
88 | if ( pDlg->Execute() == RET_OK && pDlg->GetOutputItemSet() ) | |||
89 | { | |||
90 | SfxItemIter aIter( *pDlg->GetOutputItemSet() ); | |||
91 | ||||
92 | for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) | |||
93 | { | |||
94 | if ( !IsInvalidItem( pItem ) ) | |||
95 | pBBSet->Put( *pItem ); | |||
96 | } | |||
97 | bRes = true; | |||
98 | } | |||
99 | return bRes; | |||
100 | } | |||
101 | } | |||
102 | ||||
103 | std::unique_ptr<SfxTabPage> SvxHeaderPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet ) | |||
104 | { | |||
105 | return std::make_unique<SvxHeaderPage>( pPage, pController, *rSet ); | |||
106 | } | |||
107 | ||||
108 | std::unique_ptr<SfxTabPage> SvxFooterPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet ) | |||
109 | { | |||
110 | return std::make_unique<SvxFooterPage>( pPage, pController, *rSet ); | |||
111 | } | |||
112 | ||||
113 | SvxHeaderPage::SvxHeaderPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttr) | |||
114 | : SvxHFPage( pPage, pController, rAttr, SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) ) | |||
115 | { | |||
116 | } | |||
117 | ||||
118 | SvxFooterPage::SvxFooterPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttr) | |||
119 | : SvxHFPage( pPage, pController, rAttr, SID_ATTR_PAGE_FOOTERSETTypedWhichId<SvxSetItem>( 10000 + 58 ) ) | |||
120 | { | |||
121 | } | |||
122 | ||||
123 | SvxHFPage::SvxHFPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet, sal_uInt16 nSetId) | |||
124 | : SfxTabPage(pPage, pController, "svx/ui/headfootformatpage.ui", "HFFormatPage", &rSet) | |||
125 | , nId(nSetId) | |||
126 | , mbDisableQueryBox(false) | |||
127 | , mbEnableDrawingLayerFillStyles(false) | |||
128 | , m_xCntSharedBox(m_xBuilder->weld_check_button("checkSameLR")) | |||
129 | , m_xCntSharedFirstBox(m_xBuilder->weld_check_button("checkSameFP")) | |||
130 | , m_xLMLbl(m_xBuilder->weld_label("labelLeftMarg")) | |||
131 | , m_xLMEdit(m_xBuilder->weld_metric_spin_button("spinMargLeft", FieldUnit::CM)) | |||
132 | , m_xRMLbl(m_xBuilder->weld_label("labelRightMarg")) | |||
133 | , m_xRMEdit(m_xBuilder->weld_metric_spin_button("spinMargRight", FieldUnit::CM)) | |||
134 | , m_xDistFT(m_xBuilder->weld_label("labelSpacing")) | |||
135 | , m_xDistEdit(m_xBuilder->weld_metric_spin_button("spinSpacing", FieldUnit::CM)) | |||
136 | , m_xDynSpacingCB(m_xBuilder->weld_check_button("checkDynSpacing")) | |||
137 | , m_xHeightFT(m_xBuilder->weld_label("labelHeight")) | |||
138 | , m_xHeightEdit(m_xBuilder->weld_metric_spin_button("spinHeight", FieldUnit::CM)) | |||
139 | , m_xHeightDynBtn(m_xBuilder->weld_check_button("checkAutofit")) | |||
140 | , m_xBackgroundBtn(m_xBuilder->weld_button("buttonMore")) | |||
141 | , m_xBspWin(new weld::CustomWeld(*m_xBuilder, "drawingareaPageHF", m_aBspWin)) | |||
142 | { | |||
143 | //swap header <-> footer in UI | |||
144 | if (nId == SID_ATTR_PAGE_FOOTERSETTypedWhichId<SvxSetItem>( 10000 + 58 )) | |||
145 | { | |||
146 | m_xContainer->set_help_id("svx/ui/headfootformatpage/FFormatPage"); | |||
147 | m_xPageLbl = m_xBuilder->weld_label("labelFooterFormat"); | |||
148 | m_xTurnOnBox = m_xBuilder->weld_check_button("checkFooterOn"); | |||
149 | ||||
150 | /* Set custom HIDs for the Footer help page (shared/01/05040400.xhp) | |||
151 | otherwise it would display the same extended help | |||
152 | on both the Header and Footer tabs */ | |||
153 | m_xCntSharedBox->set_help_id( "SVX_HID_FOOTER_CHECKSAMELR" ); | |||
154 | m_xCntSharedFirstBox->set_help_id( "SVX_HID_FOOTER_CHECKSAMEFP" ); | |||
155 | m_xLMEdit->set_help_id( "SVX_HID_FOOTER_SPINMARGLEFT" ); | |||
156 | m_xRMEdit->set_help_id( "SVX_HID_FOOTER_SPINMARGRIGHT" ); | |||
157 | m_xDistEdit->set_help_id( "SVX_HID_FOOTER_SPINSPACING" ); | |||
158 | m_xDynSpacingCB->set_help_id( "SVX_HID_FOOTER_CHECKDYNSPACING" ); | |||
159 | m_xHeightEdit->set_help_id( "SVX_HID_FOOTER_SPINHEIGHT" ); | |||
160 | m_xHeightDynBtn->set_help_id( "SVX_HID_FOOTER_CHECKAUTOFIT" ); | |||
161 | m_xBackgroundBtn->set_help_id( "SVX_HID_FOOTER_BUTTONMORE" ); | |||
162 | } | |||
163 | else //Header | |||
164 | { | |||
165 | m_xContainer->set_help_id("svx/ui/headfootformatpage/HFormatPage"); | |||
166 | m_xPageLbl = m_xBuilder->weld_label("labelHeaderFormat"); | |||
167 | m_xTurnOnBox = m_xBuilder->weld_check_button("checkHeaderOn"); | |||
168 | } | |||
169 | m_xTurnOnBox->show(); | |||
170 | m_xPageLbl->show(); | |||
171 | ||||
172 | InitHandler(); | |||
173 | m_aBspWin.EnableRTL(false); | |||
174 | ||||
175 | // This Page needs ExchangeSupport | |||
176 | SetExchangeSupport(); | |||
177 | ||||
178 | // Set metrics | |||
179 | FieldUnit eFUnit = GetModuleFieldUnit( rSet ); | |||
180 | SetFieldUnit( *m_xDistEdit, eFUnit ); | |||
181 | SetFieldUnit( *m_xHeightEdit, eFUnit ); | |||
182 | SetFieldUnit( *m_xLMEdit, eFUnit ); | |||
183 | SetFieldUnit( *m_xRMEdit, eFUnit ); | |||
184 | } | |||
185 | ||||
186 | SvxHFPage::~SvxHFPage() | |||
187 | { | |||
188 | } | |||
189 | ||||
190 | bool SvxHFPage::FillItemSet( SfxItemSet* rSet ) | |||
191 | { | |||
192 | const sal_uInt16 nWSize = GetWhich(SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 )); | |||
193 | const sal_uInt16 nWLRSpace = GetWhich(SID_ATTR_LRSPACE( 10000 + 48 )); | |||
194 | const sal_uInt16 nWULSpace = GetWhich(SID_ATTR_ULSPACE( 10000 + 49 )); | |||
195 | const sal_uInt16 nWOn = GetWhich(SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 )); | |||
196 | const sal_uInt16 nWDynamic = GetWhich(SID_ATTR_PAGE_DYNAMICTypedWhichId<SfxBoolItem>( 10000 + 60 )); | |||
197 | const sal_uInt16 nWDynSpacing = GetWhich(SID_ATTR_HDFT_DYNAMIC_SPACING( 10000 + 953 )); | |||
198 | const sal_uInt16 nWShared = GetWhich(SID_ATTR_PAGE_SHAREDTypedWhichId<SfxBoolItem>( 10000 + 61 )); | |||
199 | const sal_uInt16 nWSharedFirst = GetWhich( SID_ATTR_PAGE_SHARED_FIRST( 10000 + 1114 ) ); | |||
200 | const sal_uInt16 nWBrush = GetWhich(SID_ATTR_BRUSH( 10000 + 1 )); | |||
201 | const sal_uInt16 nWBox = GetWhich(SID_ATTR_BORDER_OUTER( 10000 + 24 )); | |||
202 | const sal_uInt16 nWBoxInfo = GetWhich(SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 )); | |||
203 | const sal_uInt16 nWShadow = GetWhich(SID_ATTR_BORDER_SHADOW( 10000 + 25 )); | |||
204 | ||||
205 | const sal_uInt16 aWhichTab[] = { | |||
206 | nWSize, nWSize, | |||
207 | nWLRSpace, nWLRSpace, | |||
208 | nWULSpace, nWULSpace, | |||
209 | nWOn, nWOn, | |||
210 | nWDynamic, nWDynamic, | |||
211 | nWShared, nWShared, | |||
212 | nWSharedFirst, nWSharedFirst, | |||
213 | nWBrush, nWBrush, | |||
214 | nWBoxInfo, nWBoxInfo, | |||
215 | nWBox, nWBox, | |||
216 | nWShadow, nWShadow, | |||
217 | nWDynSpacing, nWDynSpacing, | |||
218 | ||||
219 | // take over DrawingLayer FillStyles | |||
220 | XATTR_FILL_FIRST, XATTR_FILL_LAST, // [1014 | |||
221 | ||||
222 | 0, 0}; | |||
223 | ||||
224 | const SfxItemSet& rOldSet = GetItemSet(); | |||
225 | SfxItemPool* pPool = rOldSet.GetPool(); | |||
226 | DBG_ASSERT(pPool,"no pool :-(")do { if (true && (!(pPool))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/dialog/hdft.cxx" ":" "226" ": "), "%s", "no pool :-("); } } while (false); | |||
227 | MapUnit eUnit = pPool->GetMetric(nWSize); | |||
228 | SfxItemSet aSet(*pPool,aWhichTab); | |||
229 | ||||
230 | if(mbEnableDrawingLayerFillStyles) | |||
231 | { | |||
232 | // When using the XATTR_FILLSTYLE DrawingLayer FillStyle definition | |||
233 | // extra action has to be done here since the pool default is drawing::FillStyle_SOLID | |||
234 | // instead of drawing::FillStyle_NONE (to have the default blue fill color at start). | |||
235 | aSet.Put(XFillStyleItem(drawing::FillStyle_NONE)); | |||
236 | } | |||
237 | ||||
238 | aSet.Put( SfxBoolItem( nWOn, m_xTurnOnBox->get_active() ) ); | |||
239 | aSet.Put( SfxBoolItem( nWDynamic, m_xHeightDynBtn->get_active() ) ); | |||
240 | aSet.Put( SfxBoolItem( nWShared, m_xCntSharedBox->get_active() ) ); | |||
241 | if(m_xCntSharedFirstBox->get_visible()) | |||
242 | aSet.Put(SfxBoolItem(nWSharedFirst, m_xCntSharedFirstBox->get_active())); | |||
243 | if (m_xDynSpacingCB->get_visible() && SfxItemPool::IsWhich(nWDynSpacing)) | |||
244 | { | |||
245 | std::unique_ptr<SfxBoolItem> pBoolItem(static_cast<SfxBoolItem*>(pPool->GetDefaultItem(nWDynSpacing).Clone())); | |||
246 | pBoolItem->SetValue(m_xDynSpacingCB->get_active()); | |||
247 | aSet.Put(std::move(pBoolItem)); | |||
248 | } | |||
249 | ||||
250 | // Size | |||
251 | SvxSizeItem aSizeItem( static_cast<const SvxSizeItem&>(rOldSet.Get( nWSize )) ); | |||
252 | Size aSize( aSizeItem.GetSize() ); | |||
253 | long nDist = GetCoreValue( *m_xDistEdit, eUnit ); | |||
254 | long nH = GetCoreValue( *m_xHeightEdit, eUnit ); | |||
255 | ||||
256 | nH += nDist; // add distance | |||
257 | aSize.setHeight( nH ); | |||
258 | aSizeItem.SetSize( aSize ); | |||
259 | aSet.Put( aSizeItem ); | |||
260 | ||||
261 | // Margins | |||
262 | SvxLRSpaceItem aLR( nWLRSpace ); | |||
263 | aLR.SetLeft( static_cast<sal_uInt16>(GetCoreValue( *m_xLMEdit, eUnit )) ); | |||
264 | aLR.SetRight( static_cast<sal_uInt16>(GetCoreValue( *m_xRMEdit, eUnit )) ); | |||
265 | aSet.Put( aLR ); | |||
266 | ||||
267 | SvxULSpaceItem aUL( nWULSpace ); | |||
268 | if ( nId == SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) ) | |||
269 | aUL.SetLower( static_cast<sal_uInt16>(nDist) ); | |||
270 | else | |||
271 | aUL.SetUpper( static_cast<sal_uInt16>(nDist) ); | |||
272 | aSet.Put( aUL ); | |||
273 | ||||
274 | // Background and border? | |||
275 | if (pBBSet) | |||
276 | { | |||
277 | aSet.Put(*pBBSet); | |||
278 | } | |||
279 | else | |||
280 | { | |||
281 | const SfxPoolItem* pItem; | |||
282 | ||||
283 | if(SfxItemState::SET == GetItemSet().GetItemState(GetWhich(nId), false, &pItem)) | |||
284 | { | |||
285 | const SfxItemSet* _pSet = &(static_cast< const SvxSetItem* >(pItem)->GetItemSet()); | |||
286 | ||||
287 | if(_pSet->GetItemState(nWBrush) == SfxItemState::SET) | |||
288 | { | |||
289 | aSet.Put(_pSet->Get(nWBrush)); | |||
290 | } | |||
291 | ||||
292 | if(_pSet->GetItemState(nWBoxInfo) == SfxItemState::SET) | |||
293 | { | |||
294 | aSet.Put(_pSet->Get(nWBoxInfo)); | |||
295 | } | |||
296 | ||||
297 | if(_pSet->GetItemState(nWBox) == SfxItemState::SET) | |||
298 | { | |||
299 | aSet.Put(_pSet->Get(nWBox)); | |||
300 | } | |||
301 | ||||
302 | if(_pSet->GetItemState(nWShadow) == SfxItemState::SET) | |||
303 | { | |||
304 | aSet.Put(_pSet->Get(nWShadow)); | |||
305 | } | |||
306 | ||||
307 | // take care of [XATTR_XATTR_FILL_FIRST .. XATTR_FILL_LAST] | |||
308 | for(sal_uInt16 nFillStyleId(XATTR_FILL_FIRST); nFillStyleId <= XATTR_FILL_LAST; nFillStyleId++) | |||
309 | { | |||
310 | if(_pSet->GetItemState(nFillStyleId) == SfxItemState::SET) | |||
311 | { | |||
312 | aSet.Put(_pSet->Get(nFillStyleId)); | |||
313 | } | |||
314 | } | |||
315 | } | |||
316 | } | |||
317 | ||||
318 | // Flush the SetItem | |||
319 | SvxSetItem aSetItem( GetWhich( nId ), aSet ); | |||
320 | rSet->Put( aSetItem ); | |||
321 | ||||
322 | return true; | |||
323 | } | |||
324 | ||||
325 | ||||
326 | void SvxHFPage::Reset( const SfxItemSet* rSet ) | |||
327 | { | |||
328 | ActivatePage( *rSet ); | |||
329 | ResetBackground_Impl( *rSet ); | |||
330 | ||||
331 | SfxItemPool* pPool = GetItemSet().GetPool(); | |||
332 | 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/svx/source/dialog/hdft.cxx" ":" "332" ": "), "%s", "Where is the pool"); } } while (false ); | |||
333 | MapUnit eUnit = pPool->GetMetric( GetWhich( SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) ) ); | |||
334 | ||||
335 | //hide "same content on first page when this is calc | |||
336 | bool bIsCalc = false; | |||
337 | const SfxPoolItem* pExt1 = GetItem(*rSet, SID_ATTR_PAGE_EXT1( 10000 + 55 )); | |||
338 | const SfxPoolItem* pExt2 = GetItem(*rSet, SID_ATTR_PAGE_EXT2TypedWhichId<SfxBoolItem>( 10000 + 56 )); | |||
339 | if (dynamic_cast<const SfxBoolItem*>(pExt1) && dynamic_cast<const SfxBoolItem*>(pExt2) ) | |||
340 | bIsCalc = true; | |||
341 | m_xCntSharedFirstBox->set_visible(!bIsCalc); | |||
342 | ||||
343 | // Evaluate header-/footer- attributes | |||
344 | const SvxSetItem* pSetItem = nullptr; | |||
345 | ||||
346 | if ( SfxItemState::SET == rSet->GetItemState( GetWhich(nId), false, | |||
347 | reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) ) | |||
348 | { | |||
349 | const SfxItemSet& rHeaderSet = pSetItem->GetItemSet(); | |||
350 | const SfxBoolItem& rHeaderOn = | |||
351 | static_cast<const SfxBoolItem&>(rHeaderSet.Get(GetWhich(SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 )))); | |||
352 | ||||
353 | m_xTurnOnBox->set_active(rHeaderOn.GetValue()); | |||
354 | ||||
355 | if ( rHeaderOn.GetValue() ) | |||
356 | { | |||
357 | const SfxBoolItem& rDynamic = | |||
358 | static_cast<const SfxBoolItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_DYNAMICTypedWhichId<SfxBoolItem>( 10000 + 60 ) ) )); | |||
359 | const SfxBoolItem& rShared = | |||
360 | static_cast<const SfxBoolItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SHAREDTypedWhichId<SfxBoolItem>( 10000 + 61 ) ) )); | |||
361 | const SfxBoolItem* pSharedFirst = nullptr; | |||
362 | if (rHeaderSet.HasItem(GetWhich(SID_ATTR_PAGE_SHARED_FIRST( 10000 + 1114 )))) | |||
363 | pSharedFirst = static_cast<const SfxBoolItem*>(&rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SHARED_FIRST( 10000 + 1114 ) ) )); | |||
364 | const SvxSizeItem& rSize = | |||
365 | static_cast<const SvxSizeItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) ) )); | |||
366 | const SvxULSpaceItem& rUL = | |||
367 | static_cast<const SvxULSpaceItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE( 10000 + 49 ) ) )); | |||
368 | const SvxLRSpaceItem& rLR = | |||
369 | static_cast<const SvxLRSpaceItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE( 10000 + 48 ) ) )); | |||
370 | if (m_xDynSpacingCB->get_visible()) | |||
371 | { | |||
372 | const SfxBoolItem& rDynSpacing = | |||
373 | static_cast<const SfxBoolItem&>(rHeaderSet.Get(GetWhich(SID_ATTR_HDFT_DYNAMIC_SPACING( 10000 + 953 )))); | |||
374 | m_xDynSpacingCB->set_active(rDynSpacing.GetValue()); | |||
375 | } | |||
376 | ||||
377 | ||||
378 | if ( nId == SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) ) | |||
379 | { // Header | |||
380 | SetMetricValue( *m_xDistEdit, rUL.GetLower(), eUnit ); | |||
381 | SetMetricValue( *m_xHeightEdit, rSize.GetSize().Height() - rUL.GetLower(), eUnit ); | |||
382 | } | |||
383 | else | |||
384 | { // Footer | |||
385 | SetMetricValue( *m_xDistEdit, rUL.GetUpper(), eUnit ); | |||
386 | SetMetricValue( *m_xHeightEdit, rSize.GetSize().Height() - rUL.GetUpper(), eUnit ); | |||
387 | } | |||
388 | ||||
389 | m_xHeightDynBtn->set_active(rDynamic.GetValue()); | |||
390 | SetMetricValue( *m_xLMEdit, rLR.GetLeft(), eUnit ); | |||
391 | SetMetricValue( *m_xRMEdit, rLR.GetRight(), eUnit ); | |||
392 | m_xCntSharedBox->set_active(rShared.GetValue()); | |||
393 | if (pSharedFirst) | |||
394 | m_xCntSharedFirstBox->set_active(pSharedFirst->GetValue()); | |||
395 | else | |||
396 | m_xCntSharedFirstBox->hide(); | |||
397 | } | |||
398 | else | |||
399 | pSetItem = nullptr; | |||
400 | } | |||
401 | else | |||
402 | { | |||
403 | // defaults for distance and height | |||
404 | long nDefaultDist = bIsCalc ? DEF_DIST_CALC : DEF_DIST_WRITER; | |||
405 | SetMetricValue( *m_xDistEdit, nDefaultDist, MapUnit::Map100thMM ); | |||
406 | SetMetricValue( *m_xHeightEdit, 500, MapUnit::Map100thMM ); | |||
407 | } | |||
408 | ||||
409 | if ( !pSetItem ) | |||
410 | { | |||
411 | m_xTurnOnBox->set_active(false); | |||
412 | m_xHeightDynBtn->set_active(true); | |||
413 | m_xCntSharedBox->set_active(true); | |||
414 | m_xCntSharedFirstBox->set_active(true); | |||
415 | } | |||
416 | ||||
417 | TurnOn(nullptr); | |||
418 | ||||
419 | m_xTurnOnBox->save_state(); | |||
420 | m_xDistEdit->save_value(); | |||
421 | m_xHeightEdit->save_value(); | |||
422 | m_xHeightDynBtn->save_state(); | |||
423 | m_xLMEdit->save_value(); | |||
424 | m_xRMEdit->save_value(); | |||
425 | m_xCntSharedBox->save_state(); | |||
426 | RangeHdl(); | |||
427 | ||||
428 | const SfxPoolItem* pItem = nullptr; | |||
429 | SfxObjectShell* pShell; | |||
430 | if(SfxItemState::SET == rSet->GetItemState(SID_HTML_MODE(10000 + 414), false, &pItem) || | |||
431 | ( nullptr != (pShell = SfxObjectShell::Current()) && | |||
432 | nullptr != (pItem = pShell->GetItem(SID_HTML_MODE(10000 + 414))))) | |||
433 | { | |||
434 | sal_uInt16 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
435 | if (nHtmlMode & HTMLMODE_ON) | |||
436 | { | |||
437 | m_xCntSharedBox->hide(); | |||
438 | m_xBackgroundBtn->hide(); | |||
439 | } | |||
440 | } | |||
441 | ||||
442 | } | |||
443 | ||||
444 | void SvxHFPage::InitHandler() | |||
445 | { | |||
446 | m_xTurnOnBox->connect_toggled(LINK(this, SvxHFPage, TurnOnHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxHFPage *>(this), &SvxHFPage::LinkStubTurnOnHdl)); | |||
447 | m_xDistEdit->connect_value_changed(LINK(this, SvxHFPage, ValueChangeHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxHFPage *>(this), &SvxHFPage::LinkStubValueChangeHdl)); | |||
448 | m_xHeightEdit->connect_value_changed(LINK(this,SvxHFPage,ValueChangeHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxHFPage *>(this), &SvxHFPage::LinkStubValueChangeHdl)); | |||
449 | ||||
450 | m_xLMEdit->connect_value_changed(LINK(this, SvxHFPage, ValueChangeHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxHFPage *>(this), &SvxHFPage::LinkStubValueChangeHdl)); | |||
451 | m_xRMEdit->connect_value_changed(LINK(this, SvxHFPage, ValueChangeHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxHFPage *>(this), &SvxHFPage::LinkStubValueChangeHdl)); | |||
452 | m_xBackgroundBtn->connect_clicked(LINK(this,SvxHFPage, BackgroundHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxHFPage *>(this), &SvxHFPage::LinkStubBackgroundHdl)); | |||
453 | } | |||
454 | ||||
455 | void SvxHFPage::TurnOn(const weld::ToggleButton* pBox) | |||
456 | { | |||
457 | if (m_xTurnOnBox->get_active()) | |||
458 | { | |||
459 | m_xDistFT->set_sensitive(true); | |||
460 | m_xDistEdit->set_sensitive(true); | |||
461 | m_xDynSpacingCB->set_sensitive(true); | |||
462 | m_xHeightFT->set_sensitive(true); | |||
463 | m_xHeightEdit->set_sensitive(true); | |||
464 | m_xHeightDynBtn->set_sensitive(true); | |||
465 | m_xLMLbl->set_sensitive(true); | |||
466 | m_xLMEdit->set_sensitive(true); | |||
467 | m_xRMLbl->set_sensitive(true); | |||
468 | m_xRMEdit->set_sensitive(true); | |||
469 | ||||
470 | SvxPageUsage nUsage = m_aBspWin.GetUsage(); | |||
471 | ||||
472 | if( nUsage == SvxPageUsage::Right || nUsage == SvxPageUsage::Left ) | |||
473 | m_xCntSharedBox->set_sensitive(false); | |||
474 | else | |||
475 | { | |||
476 | m_xCntSharedBox->set_sensitive(true); | |||
477 | m_xCntSharedFirstBox->set_sensitive(true); | |||
478 | } | |||
479 | m_xBackgroundBtn->set_sensitive(true); | |||
480 | } | |||
481 | else | |||
482 | { | |||
483 | bool bDelete = true; | |||
484 | ||||
485 | if (!mbDisableQueryBox && pBox && m_xTurnOnBox->get_saved_state() == TRISTATE_TRUE) | |||
486 | { | |||
487 | short nResult; | |||
488 | if (nId == SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 )) | |||
489 | { | |||
490 | DeleteHeaderDialog aDlg(GetFrameWeld()); | |||
491 | nResult = aDlg.run(); | |||
492 | } | |||
493 | else | |||
494 | { | |||
495 | DeleteFooterDialog aDlg(GetFrameWeld()); | |||
496 | nResult = aDlg.run(); | |||
497 | } | |||
498 | bDelete = nResult == RET_YES; | |||
499 | } | |||
500 | ||||
501 | if ( bDelete ) | |||
502 | { | |||
503 | m_xDistFT->set_sensitive(false); | |||
504 | m_xDistEdit->set_sensitive(false); | |||
505 | m_xDynSpacingCB->set_sensitive(false); | |||
506 | m_xHeightFT->set_sensitive(false); | |||
507 | m_xHeightEdit->set_sensitive(false); | |||
508 | m_xHeightDynBtn->set_sensitive(false); | |||
509 | ||||
510 | m_xLMLbl->set_sensitive(false); | |||
511 | m_xLMEdit->set_sensitive(false); | |||
512 | m_xRMLbl->set_sensitive(false); | |||
513 | m_xRMEdit->set_sensitive(false); | |||
514 | ||||
515 | m_xCntSharedBox->set_sensitive(false); | |||
516 | m_xBackgroundBtn->set_sensitive(false); | |||
517 | m_xCntSharedFirstBox->set_sensitive(false); | |||
518 | } | |||
519 | else | |||
520 | m_xTurnOnBox->set_active(true); | |||
521 | } | |||
522 | UpdateExample(); | |||
523 | } | |||
524 | ||||
525 | IMPL_LINK(SvxHFPage, TurnOnHdl, weld::ToggleButton&, rBox, void)void SvxHFPage::LinkStubTurnOnHdl(void * instance, weld::ToggleButton & data) { return static_cast<SvxHFPage *>(instance) ->TurnOnHdl(data); } void SvxHFPage::TurnOnHdl(weld::ToggleButton & rBox) | |||
526 | { | |||
527 | TurnOn(&rBox); | |||
528 | } | |||
529 | ||||
530 | IMPL_LINK_NOARG(SvxHFPage, BackgroundHdl, weld::Button&, void)void SvxHFPage::LinkStubBackgroundHdl(void * instance, weld:: Button& data) { return static_cast<SvxHFPage *>(instance )->BackgroundHdl(data); } void SvxHFPage::BackgroundHdl(__attribute__ ((unused)) weld::Button&) | |||
531 | { | |||
532 | if(!pBBSet) | |||
533 | { | |||
534 | // Use only the necessary items for border and background | |||
535 | const sal_uInt16 nOuter(GetWhich(SID_ATTR_BORDER_OUTER( 10000 + 24 ))); | |||
536 | const sal_uInt16 nInner(GetWhich(SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), false)); | |||
537 | const sal_uInt16 nShadow(GetWhich(SID_ATTR_BORDER_SHADOW( 10000 + 25 ))); | |||
538 | ||||
539 | if(mbEnableDrawingLayerFillStyles) | |||
540 | { | |||
541 | pBBSet.reset(new SfxItemSet( | |||
542 | *GetItemSet().GetPool(), | |||
543 | {{XATTR_FILL_FIRST, XATTR_FILL_LAST}, // DrawingLayer FillStyle definitions | |||
544 | {SID_COLOR_TABLETypedWhichId<SvxColorListItem>( 10000 + 179 ), SID_PATTERN_LISTTypedWhichId<SvxPatternListItem>( 10000 + 183 )}, // XPropertyLists for Color, Gradient, Hatch and Graphic fills | |||
545 | {nOuter, nOuter}, | |||
546 | {nInner, nInner}, | |||
547 | {nShadow, nShadow}})); | |||
548 | ||||
549 | // copy items for XPropertyList entries from the DrawModel so that | |||
550 | // the Area TabPage can access them | |||
551 | static const sal_uInt16 nCopyFlags[] = { | |||
552 | SID_COLOR_TABLETypedWhichId<SvxColorListItem>( 10000 + 179 ), | |||
553 | SID_GRADIENT_LISTTypedWhichId<SvxGradientListItem>( 10000 + 180 ), | |||
554 | SID_HATCH_LISTTypedWhichId<SvxHatchListItem>( 10000 + 181 ), | |||
555 | SID_BITMAP_LISTTypedWhichId<SvxBitmapListItem>( 10000 + 182 ), | |||
556 | SID_PATTERN_LISTTypedWhichId<SvxPatternListItem>( 10000 + 183 ), | |||
557 | 0 | |||
558 | }; | |||
559 | ||||
560 | for(sal_uInt16 a(0); nCopyFlags[a]; a++) | |||
561 | { | |||
562 | const SfxPoolItem* pItem = GetItemSet().GetItem(nCopyFlags[a]); | |||
563 | ||||
564 | if(pItem) | |||
565 | { | |||
566 | pBBSet->Put(*pItem); | |||
567 | } | |||
568 | else | |||
569 | { | |||
570 | OSL_ENSURE(false, "XPropertyList missing (!)")do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svx/source/dialog/hdft.cxx" ":" "570" ": "), "%s", "XPropertyList missing (!)"); } } while (false); | |||
571 | } | |||
572 | } | |||
573 | } | |||
574 | else | |||
575 | { | |||
576 | const sal_uInt16 nBrush(GetWhich(SID_ATTR_BRUSH( 10000 + 1 ))); | |||
577 | ||||
578 | pBBSet.reset( new SfxItemSet( | |||
579 | *GetItemSet().GetPool(), | |||
580 | {{XATTR_FILL_FIRST, XATTR_FILL_LAST}, | |||
581 | {nBrush, nBrush}, | |||
582 | {nOuter, nOuter}, | |||
583 | {nInner, nInner}, | |||
584 | {nShadow, nShadow}}) ); | |||
585 | } | |||
586 | ||||
587 | const SfxPoolItem* pItem; | |||
588 | ||||
589 | if(SfxItemState::SET == GetItemSet().GetItemState(GetWhich(nId), false, &pItem)) | |||
590 | { | |||
591 | // If a SfxItemSet from the SetItem for SID_ATTR_PAGE_HEADERSET or | |||
592 | // SID_ATTR_PAGE_FOOTERSET exists, use its content | |||
593 | pBBSet->Put(static_cast<const SvxSetItem*>(pItem)->GetItemSet()); | |||
594 | } | |||
595 | else | |||
596 | { | |||
597 | if(mbEnableDrawingLayerFillStyles) | |||
598 | { | |||
599 | // The style for header/footer is not yet created, need to reset | |||
600 | // XFillStyleItem to drawing::FillStyle_NONE which is the same as in the style | |||
601 | // initialization. This needs to be done since the pool default for | |||
602 | // XFillStyleItem is drawing::FillStyle_SOLID | |||
603 | pBBSet->Put(XFillStyleItem(drawing::FillStyle_NONE)); | |||
604 | } | |||
605 | } | |||
606 | ||||
607 | if(SfxItemState::SET == GetItemSet().GetItemState(nInner, false, &pItem)) | |||
608 | { | |||
609 | // The set InfoItem is always required | |||
610 | pBBSet->Put(*pItem); | |||
611 | } | |||
612 | } | |||
613 | ||||
614 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | |||
615 | ||||
616 | VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxBorderBackgroundDlg( | |||
617 | GetFrameWeld(), | |||
618 | *pBBSet, | |||
619 | mbEnableDrawingLayerFillStyles)); | |||
620 | ||||
621 | pDlg->StartExecuteAsync([pDlg, this](sal_Int32 nResult) { | |||
622 | if (nResult == RET_OK && pDlg->GetOutputItemSet()) | |||
623 | { | |||
624 | SfxItemIter aIter(*pDlg->GetOutputItemSet()); | |||
625 | ||||
626 | for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) | |||
627 | { | |||
628 | if(!IsInvalidItem(pItem)) | |||
629 | { | |||
630 | pBBSet->Put(*pItem); | |||
631 | } | |||
632 | } | |||
633 | ||||
634 | { | |||
635 | drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes; | |||
636 | ||||
637 | if (mbEnableDrawingLayerFillStyles) | |||
638 | { | |||
639 | // create FillAttributes directly from DrawingLayer FillStyle entries | |||
640 | aFillAttributes = | |||
641 | std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(*pBBSet); | |||
642 | } | |||
643 | else | |||
644 | { | |||
645 | const sal_uInt16 nWhich = GetWhich(SID_ATTR_BRUSH( 10000 + 1 )); | |||
646 | ||||
647 | if (pBBSet->GetItemState(nWhich) == SfxItemState::SET) | |||
648 | { | |||
649 | // create FillAttributes from SvxBrushItem | |||
650 | const SvxBrushItem& rItem | |||
651 | = static_cast<const SvxBrushItem&>(pBBSet->Get(nWhich)); | |||
652 | SfxItemSet aTempSet(*pBBSet->GetPool(), | |||
653 | svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}); | |||
654 | ||||
655 | setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet); | |||
656 | aFillAttributes = | |||
657 | std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet); | |||
658 | } | |||
659 | } | |||
660 | ||||
661 | if (SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) == nId) | |||
662 | { | |||
663 | //m_aBspWin.SetHdColor(rItem.GetColor()); | |||
664 | m_aBspWin.setHeaderFillAttributes(aFillAttributes); | |||
665 | } | |||
666 | else | |||
667 | { | |||
668 | //m_aBspWin.SetFtColor(rItem.GetColor()); | |||
669 | m_aBspWin.setFooterFillAttributes(aFillAttributes); | |||
670 | } | |||
671 | } | |||
672 | } | |||
673 | pDlg->disposeOnce(); | |||
674 | }); | |||
675 | ||||
676 | UpdateExample(); | |||
677 | } | |||
678 | ||||
679 | void SvxHFPage::UpdateExample() | |||
680 | { | |||
681 | if ( nId == SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) ) | |||
682 | { | |||
683 | m_aBspWin.SetHeader( m_xTurnOnBox->get_active() ); | |||
684 | m_aBspWin.SetHdHeight( GetCoreValue( *m_xHeightEdit, MapUnit::MapTwip ) ); | |||
685 | m_aBspWin.SetHdDist( GetCoreValue( *m_xDistEdit, MapUnit::MapTwip ) ); | |||
686 | m_aBspWin.SetHdLeft( GetCoreValue( *m_xLMEdit, MapUnit::MapTwip ) ); | |||
687 | m_aBspWin.SetHdRight( GetCoreValue( *m_xRMEdit, MapUnit::MapTwip ) ); | |||
688 | } | |||
689 | else | |||
690 | { | |||
691 | m_aBspWin.SetFooter( m_xTurnOnBox->get_active() ); | |||
692 | m_aBspWin.SetFtHeight( GetCoreValue( *m_xHeightEdit, MapUnit::MapTwip ) ); | |||
693 | m_aBspWin.SetFtDist( GetCoreValue( *m_xDistEdit, MapUnit::MapTwip ) ); | |||
694 | m_aBspWin.SetFtLeft( GetCoreValue( *m_xLMEdit, MapUnit::MapTwip ) ); | |||
695 | m_aBspWin.SetFtRight( GetCoreValue( *m_xRMEdit, MapUnit::MapTwip ) ); | |||
696 | } | |||
697 | m_aBspWin.Invalidate(); | |||
698 | } | |||
699 | ||||
700 | void SvxHFPage::ResetBackground_Impl( const SfxItemSet& rSet ) | |||
701 | { | |||
702 | sal_uInt16 nWhich(GetWhich(SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ))); | |||
703 | ||||
704 | if (SfxItemState::SET == rSet.GetItemState(nWhich, false)) | |||
705 | { | |||
706 | const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich, false)); | |||
707 | const SfxItemSet& rTmpSet = rSetItem.GetItemSet(); | |||
708 | const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 )))); | |||
709 | ||||
710 | if(rOn.GetValue()) | |||
711 | { | |||
712 | drawinglayer::attribute::SdrAllFillAttributesHelperPtr aHeaderFillAttributes; | |||
713 | ||||
714 | if(mbEnableDrawingLayerFillStyles) | |||
715 | { | |||
716 | // create FillAttributes directly from DrawingLayer FillStyle entries | |||
717 | aHeaderFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rTmpSet); | |||
718 | } | |||
719 | else | |||
720 | { | |||
721 | nWhich = GetWhich(SID_ATTR_BRUSH( 10000 + 1 )); | |||
722 | ||||
723 | if(SfxItemState::SET == rTmpSet.GetItemState(nWhich)) | |||
724 | { | |||
725 | // create FillAttributes from SvxBrushItem | |||
726 | const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich)); | |||
727 | SfxItemSet aTempSet(*rTmpSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}); | |||
728 | ||||
729 | setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet); | |||
730 | aHeaderFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet); | |||
731 | } | |||
732 | } | |||
733 | ||||
734 | m_aBspWin.setHeaderFillAttributes(aHeaderFillAttributes); | |||
735 | } | |||
736 | } | |||
737 | ||||
738 | nWhich = GetWhich(SID_ATTR_PAGE_FOOTERSETTypedWhichId<SvxSetItem>( 10000 + 58 )); | |||
739 | ||||
740 | if (SfxItemState::SET == rSet.GetItemState(nWhich, false)) | |||
741 | { | |||
742 | const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich, false)); | |||
743 | const SfxItemSet& rTmpSet = rSetItem.GetItemSet(); | |||
744 | const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 )))); | |||
745 | ||||
746 | if(rOn.GetValue()) | |||
747 | { | |||
748 | drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFooterFillAttributes; | |||
749 | ||||
750 | if(mbEnableDrawingLayerFillStyles) | |||
751 | { | |||
752 | // create FillAttributes directly from DrawingLayer FillStyle entries | |||
753 | aFooterFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rTmpSet); | |||
754 | } | |||
755 | else | |||
756 | { | |||
757 | nWhich = GetWhich(SID_ATTR_BRUSH( 10000 + 1 )); | |||
758 | ||||
759 | if(SfxItemState::SET == rTmpSet.GetItemState(nWhich)) | |||
760 | { | |||
761 | // create FillAttributes from SvxBrushItem | |||
762 | const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich)); | |||
763 | SfxItemSet aTempSet(*rTmpSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}); | |||
764 | ||||
765 | setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet); | |||
766 | aFooterFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet); | |||
767 | } | |||
768 | } | |||
769 | ||||
770 | m_aBspWin.setFooterFillAttributes(aFooterFillAttributes); | |||
771 | } | |||
772 | } | |||
773 | ||||
774 | drawinglayer::attribute::SdrAllFillAttributesHelperPtr aPageFillAttributes; | |||
775 | ||||
776 | if(mbEnableDrawingLayerFillStyles) | |||
777 | { | |||
778 | // create FillAttributes directly from DrawingLayer FillStyle entries | |||
779 | aPageFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rSet); | |||
780 | } | |||
781 | else | |||
782 | { | |||
783 | nWhich = GetWhich(SID_ATTR_BRUSH( 10000 + 1 )); | |||
784 | ||||
785 | if(rSet.GetItemState(nWhich) >= SfxItemState::DEFAULT) | |||
786 | { | |||
787 | // create FillAttributes from SvxBrushItem | |||
788 | const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rSet.Get(nWhich)); | |||
789 | SfxItemSet aTempSet(*rSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}); | |||
790 | ||||
791 | setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet); | |||
792 | aPageFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet); | |||
793 | } | |||
794 | } | |||
795 | ||||
796 | m_aBspWin.setPageFillAttributes(aPageFillAttributes); | |||
797 | } | |||
798 | ||||
799 | void SvxHFPage::ActivatePage( const SfxItemSet& rSet ) | |||
800 | { | |||
801 | const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_LRSPACE( 10000 + 48 ) ); | |||
802 | ||||
803 | if ( pItem ) | |||
804 | { | |||
805 | // Set left and right margins | |||
806 | const SvxLRSpaceItem& rLRSpace = static_cast<const SvxLRSpaceItem&>(*pItem); | |||
807 | ||||
808 | m_aBspWin.SetLeft( rLRSpace.GetLeft() ); | |||
809 | m_aBspWin.SetRight( rLRSpace.GetRight() ); | |||
810 | } | |||
811 | else | |||
812 | { | |||
813 | m_aBspWin.SetLeft( 0 ); | |||
814 | m_aBspWin.SetRight( 0 ); | |||
815 | } | |||
816 | ||||
817 | pItem = GetItem( rSet, SID_ATTR_ULSPACE( 10000 + 49 ) ); | |||
818 | ||||
819 | if ( pItem ) | |||
820 | { | |||
821 | // Set top and bottom margins | |||
822 | const SvxULSpaceItem& rULSpace = static_cast<const SvxULSpaceItem&>(*pItem); | |||
823 | ||||
824 | m_aBspWin.SetTop( rULSpace.GetUpper() ); | |||
825 | m_aBspWin.SetBottom( rULSpace.GetLower() ); | |||
826 | } | |||
827 | else | |||
828 | { | |||
829 | m_aBspWin.SetTop( 0 ); | |||
830 | m_aBspWin.SetBottom( 0 ); | |||
831 | } | |||
832 | ||||
833 | SvxPageUsage nUsage = SvxPageUsage::All; | |||
834 | pItem = GetItem( rSet, SID_ATTR_PAGETypedWhichId<SvxPageItem>( 10000 + 50 ) ); | |||
835 | ||||
836 | if ( pItem ) | |||
837 | nUsage = static_cast<const SvxPageItem*>(pItem)->GetPageUsage(); | |||
838 | ||||
839 | m_aBspWin.SetUsage( nUsage ); | |||
840 | ||||
841 | if ( SvxPageUsage::Right == nUsage || SvxPageUsage::Left == nUsage ) | |||
842 | m_xCntSharedBox->set_sensitive(false); | |||
843 | else | |||
844 | { | |||
845 | m_xCntSharedBox->set_sensitive(true); | |||
846 | m_xCntSharedFirstBox->set_sensitive(true); | |||
847 | } | |||
848 | pItem = GetItem( rSet, SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) ); | |||
849 | ||||
850 | if ( pItem ) | |||
851 | { | |||
852 | // Orientation and Size from the PageItem | |||
853 | const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>(*pItem); | |||
854 | // if the size is already swapped (Landscape) | |||
855 | m_aBspWin.SetSize( rSize.GetSize() ); | |||
856 | } | |||
857 | ||||
858 | // Evaluate Header attribute | |||
859 | const SvxSetItem* pSetItem = nullptr; | |||
860 | ||||
861 | if ( SfxItemState::SET == rSet.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) ), | |||
862 | false, | |||
863 | reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) ) | |||
864 | { | |||
865 | const SfxItemSet& rHeaderSet = pSetItem->GetItemSet(); | |||
866 | const SfxBoolItem& rHeaderOn = | |||
867 | static_cast<const SfxBoolItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 ) ) )); | |||
868 | ||||
869 | if ( rHeaderOn.GetValue() ) | |||
870 | { | |||
871 | const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>( | |||
872 | rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) ) )); | |||
873 | const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>( | |||
874 | rHeaderSet.Get( GetWhich(SID_ATTR_ULSPACE( 10000 + 49 ) ) )); | |||
875 | const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>( | |||
876 | rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE( 10000 + 48 ) ) )); | |||
877 | long nDist = rUL.GetLower(); | |||
878 | ||||
879 | m_aBspWin.SetHdHeight( rSize.GetSize().Height() - nDist ); | |||
880 | m_aBspWin.SetHdDist( nDist ); | |||
881 | m_aBspWin.SetHdLeft( rLR.GetLeft() ); | |||
882 | m_aBspWin.SetHdRight( rLR.GetRight() ); | |||
883 | m_aBspWin.SetHeader( true ); | |||
884 | } | |||
885 | else | |||
886 | pSetItem = nullptr; | |||
887 | } | |||
888 | ||||
889 | if ( !pSetItem ) | |||
890 | { | |||
891 | m_aBspWin.SetHeader( false ); | |||
892 | ||||
893 | if ( SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) == nId ) | |||
894 | { | |||
895 | m_xCntSharedBox->set_sensitive(false); | |||
896 | m_xCntSharedFirstBox->set_sensitive(false); | |||
897 | } | |||
898 | } | |||
899 | pSetItem = nullptr; | |||
900 | ||||
901 | if ( SfxItemState::SET == rSet.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSETTypedWhichId<SvxSetItem>( 10000 + 58 ) ), | |||
902 | false, | |||
903 | reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) ) | |||
904 | { | |||
905 | const SfxItemSet& rFooterSet = pSetItem->GetItemSet(); | |||
906 | const SfxBoolItem& rFooterOn = | |||
907 | static_cast<const SfxBoolItem&>(rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 ) ) )); | |||
908 | ||||
909 | if ( rFooterOn.GetValue() ) | |||
910 | { | |||
911 | const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>( | |||
912 | rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) ) )); | |||
913 | const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>( | |||
914 | rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE( 10000 + 49 ) ) )); | |||
915 | const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>( | |||
916 | rFooterSet.Get( GetWhich( SID_ATTR_LRSPACE( 10000 + 48 ) ) )); | |||
917 | long nDist = rUL.GetUpper(); | |||
918 | ||||
919 | m_aBspWin.SetFtHeight( rSize.GetSize().Height() - nDist ); | |||
920 | m_aBspWin.SetFtDist( nDist ); | |||
921 | m_aBspWin.SetFtLeft( rLR.GetLeft() ); | |||
922 | m_aBspWin.SetFtRight( rLR.GetRight() ); | |||
923 | m_aBspWin.SetFooter( true ); | |||
924 | } | |||
925 | else | |||
926 | pSetItem = nullptr; | |||
927 | } | |||
928 | ||||
929 | if ( !pSetItem ) | |||
930 | { | |||
931 | m_aBspWin.SetFooter( false ); | |||
932 | ||||
933 | if ( SID_ATTR_PAGE_FOOTERSETTypedWhichId<SvxSetItem>( 10000 + 58 ) == nId ) | |||
934 | { | |||
935 | m_xCntSharedBox->set_sensitive(false); | |||
936 | m_xCntSharedFirstBox->set_sensitive(false); | |||
937 | } | |||
938 | } | |||
939 | ||||
940 | pItem = GetItem( rSet, SID_ATTR_PAGE_EXT1( 10000 + 55 ) ); | |||
941 | ||||
942 | if ( auto pBoolItem = dynamic_cast<const SfxBoolItem*>( pItem) ) | |||
943 | { | |||
944 | m_aBspWin.SetTable( true ); | |||
945 | m_aBspWin.SetHorz( pBoolItem->GetValue() ); | |||
946 | } | |||
947 | ||||
948 | pItem = GetItem( rSet, SID_ATTR_PAGE_EXT2TypedWhichId<SfxBoolItem>( 10000 + 56 ) ); | |||
949 | ||||
950 | if ( auto pBoolItem = dynamic_cast<const SfxBoolItem*>( pItem) ) | |||
951 | { | |||
952 | m_aBspWin.SetTable( true ); | |||
953 | m_aBspWin.SetVert( pBoolItem->GetValue() ); | |||
954 | } | |||
955 | ResetBackground_Impl( rSet ); | |||
956 | RangeHdl(); | |||
957 | } | |||
958 | ||||
959 | DeactivateRC SvxHFPage::DeactivatePage( SfxItemSet* _pSet ) | |||
960 | { | |||
961 | if ( _pSet ) | |||
962 | FillItemSet( _pSet ); | |||
963 | return DeactivateRC::LeavePage; | |||
964 | } | |||
965 | ||||
966 | IMPL_LINK_NOARG(SvxHFPage, ValueChangeHdl, weld::MetricSpinButton&, void)void SvxHFPage::LinkStubValueChangeHdl(void * instance, weld:: MetricSpinButton& data) { return static_cast<SvxHFPage *>(instance)->ValueChangeHdl(data); } void SvxHFPage:: ValueChangeHdl(__attribute__ ((unused)) weld::MetricSpinButton &) | |||
967 | { | |||
968 | UpdateExample(); | |||
969 | RangeHdl(); | |||
970 | } | |||
971 | ||||
972 | void SvxHFPage::RangeHdl() | |||
973 | { | |||
974 | long nHHeight = m_aBspWin.GetHdHeight(); | |||
975 | long nHDist = m_aBspWin.GetHdDist(); | |||
976 | ||||
977 | long nFHeight = m_aBspWin.GetFtHeight(); | |||
978 | long nFDist = m_aBspWin.GetFtDist(); | |||
979 | ||||
980 | long nHeight = std::max(long(MINBODY), | |||
981 | static_cast<long>(m_xHeightEdit->denormalize(m_xHeightEdit->get_value(FieldUnit::TWIP)))); | |||
982 | long nDist = m_xTurnOnBox->get_active() ? | |||
983 | static_cast<long>(m_xDistEdit->denormalize(m_xDistEdit->get_value(FieldUnit::TWIP))) : 0; | |||
984 | ||||
985 | long nMin; | |||
986 | long nMax; | |||
987 | ||||
988 | if ( nId == SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) ) | |||
989 | { | |||
990 | nHHeight = nHeight; | |||
991 | nHDist = nDist; | |||
992 | } | |||
993 | else | |||
994 | { | |||
995 | nFHeight = nHeight; | |||
996 | nFDist = nDist; | |||
997 | } | |||
998 | ||||
999 | // Current values of the side edges | |||
1000 | long nBT = m_aBspWin.GetTop(); | |||
1001 | long nBB = m_aBspWin.GetBottom(); | |||
1002 | long nBL = m_aBspWin.GetLeft(); | |||
1003 | long nBR = m_aBspWin.GetRight(); | |||
1004 | ||||
1005 | long nH = m_aBspWin.GetSize().Height(); | |||
1006 | long nW = m_aBspWin.GetSize().Width(); | |||
1007 | ||||
1008 | // Borders | |||
1009 | if ( nId == SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) ) | |||
1010 | { | |||
1011 | // Header | |||
1012 | nMin = ( nH - nBB - nBT ) / 5; // 20% | |||
1013 | nMax = std::max( nH - nMin - nHDist - nFDist - nFHeight - nBB - nBT, | |||
1014 | nMin ); | |||
1015 | m_xHeightEdit->set_max(m_xHeightEdit->normalize(nMax), FieldUnit::TWIP); | |||
1016 | nMin = ( nH - nBB - nBT ) / 5; // 20% | |||
1017 | nDist = std::max( nH - nMin - nHHeight - nFDist - nFHeight - nBB - nBT, | |||
1018 | long(0) ); | |||
1019 | m_xDistEdit->set_max(m_xDistEdit->normalize(nDist), FieldUnit::TWIP); | |||
1020 | } | |||
1021 | else | |||
1022 | { | |||
1023 | // Footer | |||
1024 | nMin = ( nH - nBT - nBB ) / 5; // 20% | |||
1025 | nMax = std::max( nH - nMin - nFDist - nHDist - nHHeight - nBT - nBB, | |||
1026 | nMin ); | |||
1027 | m_xHeightEdit->set_max(m_xHeightEdit->normalize(nMax), FieldUnit::TWIP); | |||
1028 | nMin = ( nH - nBT - nBB ) / 5; // 20% | |||
1029 | nDist = std::max( nH - nMin - nFHeight - nHDist - nHHeight - nBT - nBB, | |||
1030 | long(0) ); | |||
1031 | m_xDistEdit->set_max(m_xDistEdit->normalize(nDist), FieldUnit::TWIP); | |||
1032 | } | |||
1033 | ||||
1034 | // Limit Indentation | |||
1035 | nMax = nW - nBL - nBR - | |||
1036 | static_cast<long>(m_xRMEdit->denormalize(m_xRMEdit->get_value(FieldUnit::TWIP))) - MINBODY; | |||
1037 | m_xLMEdit->set_max(m_xLMEdit->normalize(nMax), FieldUnit::TWIP); | |||
1038 | ||||
1039 | nMax = nW - nBL - nBR - | |||
1040 | static_cast<long>(m_xLMEdit->denormalize(m_xLMEdit->get_value(FieldUnit::TWIP))) - MINBODY; | |||
1041 | m_xRMEdit->set_max(m_xLMEdit->normalize(nMax), FieldUnit::TWIP); | |||
1042 | } | |||
1043 | ||||
1044 | void SvxHFPage::EnableDynamicSpacing() | |||
1045 | { | |||
1046 | m_xDynSpacingCB->show(); | |||
1047 | } | |||
1048 | ||||
1049 | void SvxHFPage::PageCreated(const SfxAllItemSet &rSet) | |||
1050 | { | |||
1051 | const SfxBoolItem* pSupportDrawingLayerFillStyleItem = rSet.GetItem<SfxBoolItem>(SID_DRAWINGLAYER_FILLSTYLES( 10000 + 1144), false); | |||
1052 | ||||
1053 | if (pSupportDrawingLayerFillStyleItem) | |||
1054 | { | |||
1055 | const bool bNew(pSupportDrawingLayerFillStyleItem->GetValue()); | |||
1056 | ||||
1057 | mbEnableDrawingLayerFillStyles = bNew; | |||
1058 | } | |||
1059 | } | |||
1060 | ||||
1061 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<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 | */ |
56 | template <class reference_type> |
57 | class 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 | |
66 | public: |
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 ;-) |
205 | if (aTmp.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 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<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 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
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 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
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(); |
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 | |
378 | private: |
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 | |
387 | protected: |
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 |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
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 | |
421 | private: |
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: */ |
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 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
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) | ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace 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 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct 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: */ |
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 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
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) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |