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 <hintids.hxx> | |||
21 | #include <vcl/settings.hxx> | |||
22 | #include <vcl/virdev.hxx> | |||
23 | #include <sfx2/tabdlg.hxx> | |||
24 | #include <editeng/brushitem.hxx> | |||
25 | #include <unotools/configmgr.hxx> | |||
26 | #include <SwStyleNameMapper.hxx> | |||
27 | #include <num.hxx> | |||
28 | #include <view.hxx> | |||
29 | #include <docsh.hxx> | |||
30 | #include <uitool.hxx> | |||
31 | #include <wrtsh.hxx> | |||
32 | #include <swmodule.hxx> | |||
33 | #include <fmtcol.hxx> | |||
34 | #include <outline.hxx> | |||
35 | #include <uinums.hxx> | |||
36 | #include <poolfmt.hxx> | |||
37 | #include <shellres.hxx> | |||
38 | #include <svl/style.hxx> | |||
39 | #include <charfmt.hxx> | |||
40 | #include <docstyle.hxx> | |||
41 | #include <viewopt.hxx> | |||
42 | #include <outline.hrc> | |||
43 | #include <strings.hrc> | |||
44 | #include <paratr.hxx> | |||
45 | ||||
46 | #include <IDocumentOutlineNodes.hxx> | |||
47 | ||||
48 | using namespace ::com::sun::star; | |||
49 | ||||
50 | namespace { | |||
51 | ||||
52 | class SwNumNamesDlg : public weld::GenericDialogController | |||
53 | { | |||
54 | std::unique_ptr<weld::Entry> m_xFormEdit; | |||
55 | std::unique_ptr<weld::TreeView> m_xFormBox; | |||
56 | std::unique_ptr<weld::Button> m_xOKBtn; | |||
57 | ||||
58 | DECL_LINK( ModifyHdl, weld::Entry&, void )static void LinkStubModifyHdl(void *, weld::Entry&); void ModifyHdl(weld::Entry&); | |||
59 | DECL_LINK( SelectHdl, weld::TreeView&, void )static void LinkStubSelectHdl(void *, weld::TreeView&); void SelectHdl(weld::TreeView&); | |||
60 | DECL_LINK( DoubleClickHdl, weld::TreeView&, bool )static bool LinkStubDoubleClickHdl(void *, weld::TreeView& ); bool DoubleClickHdl(weld::TreeView&); | |||
61 | ||||
62 | public: | |||
63 | explicit SwNumNamesDlg(weld::Window *pParent); | |||
64 | void SetUserNames(const OUString *pList[]); | |||
65 | OUString GetName() const { return m_xFormEdit->get_text(); } | |||
66 | int GetCurEntryPos() const { return m_xFormBox->get_selected_index(); } | |||
67 | }; | |||
68 | ||||
69 | } | |||
70 | ||||
71 | // remember selected entry | |||
72 | IMPL_LINK( SwNumNamesDlg, SelectHdl, weld::TreeView&, rBox, void )void SwNumNamesDlg::LinkStubSelectHdl(void * instance, weld:: TreeView& data) { return static_cast<SwNumNamesDlg *> (instance)->SelectHdl(data); } void SwNumNamesDlg::SelectHdl (weld::TreeView& rBox) | |||
73 | { | |||
74 | m_xFormEdit->set_text(rBox.get_selected_text()); | |||
75 | m_xFormEdit->select_region(0, -1); | |||
76 | } | |||
77 | ||||
78 | /** set user defined names | |||
79 | * | |||
80 | * @param pList list of user defined names; unknown positions for the user are 0. | |||
81 | */ | |||
82 | void SwNumNamesDlg::SetUserNames(const OUString *pList[]) | |||
83 | { | |||
84 | sal_uInt16 nSelect = 0; | |||
85 | for (sal_uInt16 i = 0; i < SwChapterNumRules::nMaxRules; ++i) | |||
86 | { | |||
87 | if(pList[i]) | |||
88 | { | |||
89 | m_xFormBox->remove(i); | |||
90 | m_xFormBox->insert_text(i, *pList[i]); | |||
91 | if (i == nSelect) | |||
92 | nSelect++; | |||
93 | } | |||
94 | } | |||
95 | m_xFormBox->select(nSelect); | |||
96 | SelectHdl(*m_xFormBox); | |||
97 | } | |||
98 | ||||
99 | // unlock OK-Button when text is in Edit | |||
100 | IMPL_LINK( SwNumNamesDlg, ModifyHdl, weld::Entry&, rBox, void )void SwNumNamesDlg::LinkStubModifyHdl(void * instance, weld:: Entry& data) { return static_cast<SwNumNamesDlg *>( instance)->ModifyHdl(data); } void SwNumNamesDlg::ModifyHdl (weld::Entry& rBox) | |||
101 | { | |||
102 | m_xOKBtn->set_sensitive(!rBox.get_text().isEmpty()); | |||
103 | } | |||
104 | ||||
105 | // DoubleClickHdl | |||
106 | IMPL_LINK_NOARG(SwNumNamesDlg, DoubleClickHdl, weld::TreeView&, bool)bool SwNumNamesDlg::LinkStubDoubleClickHdl(void * instance, weld ::TreeView& data) { return static_cast<SwNumNamesDlg * >(instance)->DoubleClickHdl(data); } bool SwNumNamesDlg ::DoubleClickHdl(__attribute__ ((unused)) weld::TreeView& ) | |||
107 | { | |||
108 | m_xDialog->response(RET_OK); | |||
109 | return true; | |||
110 | } | |||
111 | ||||
112 | SwNumNamesDlg::SwNumNamesDlg(weld::Window *pParent) | |||
113 | : GenericDialogController(pParent, | |||
114 | "modules/swriter/ui/numberingnamedialog.ui", | |||
115 | "NumberingNameDialog") | |||
116 | , m_xFormEdit(m_xBuilder->weld_entry("entry")) | |||
117 | , m_xFormBox(m_xBuilder->weld_tree_view("form")) | |||
118 | , m_xOKBtn(m_xBuilder->weld_button("ok")) | |||
119 | { | |||
120 | for (size_t i = 0; i < SAL_N_ELEMENTS(OUTLINE_STYLE)(sizeof(sal_n_array_size(OUTLINE_STYLE))); ++i) | |||
121 | m_xFormBox->append_text(SwResId(OUTLINE_STYLE[i])); | |||
122 | ||||
123 | m_xFormEdit->connect_changed(LINK(this, SwNumNamesDlg, ModifyHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwNumNamesDlg *>(this), &SwNumNamesDlg::LinkStubModifyHdl)); | |||
124 | m_xFormBox->connect_changed(LINK(this, SwNumNamesDlg, SelectHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwNumNamesDlg *>(this), &SwNumNamesDlg::LinkStubSelectHdl)); | |||
125 | m_xFormBox->connect_row_activated(LINK(this, SwNumNamesDlg, DoubleClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwNumNamesDlg *>(this), &SwNumNamesDlg::LinkStubDoubleClickHdl)); | |||
126 | m_xFormBox->set_size_request(-1, m_xFormBox->get_height_rows(9)); | |||
127 | } | |||
128 | ||||
129 | static sal_uInt16 lcl_BitToLevel(sal_uInt16 nActLevel) | |||
130 | { | |||
131 | sal_uInt16 nTmp = nActLevel; | |||
132 | sal_uInt16 nTmpLevel = 0; | |||
133 | while( 0 != (nTmp >>= 1) ) | |||
134 | nTmpLevel++; | |||
135 | return nTmpLevel; | |||
136 | } | |||
137 | ||||
138 | sal_uInt16 SwOutlineTabDialog::nNumLevel = 1; | |||
139 | ||||
140 | SwOutlineTabDialog::SwOutlineTabDialog(weld::Window* pParent, const SfxItemSet* pSwItemSet, | |||
141 | SwWrtShell &rSh) | |||
142 | : SfxTabDialogController(pParent, "modules/swriter/ui/outlinenumbering.ui", "OutlineNumberingDialog", pSwItemSet) | |||
143 | , rWrtSh(rSh) | |||
144 | , pChapterNumRules(SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetChapterNumRules()) | |||
145 | , bModified(rWrtSh.IsModified()) | |||
146 | , m_xMenuButton(m_xBuilder->weld_menu_button("format")) | |||
147 | { | |||
148 | m_xMenuButton->connect_toggled(LINK(this, SwOutlineTabDialog, FormHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineTabDialog *>(this), &SwOutlineTabDialog::LinkStubFormHdl)); | |||
149 | m_xMenuButton->connect_selected(LINK(this, SwOutlineTabDialog, MenuSelectHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineTabDialog *>(this), &SwOutlineTabDialog::LinkStubMenuSelectHdl)); | |||
150 | ||||
151 | xNumRule.reset(new SwNumRule(*rSh.GetOutlineNumRule())); | |||
152 | GetCancelButton().connect_clicked(LINK(this, SwOutlineTabDialog, CancelHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineTabDialog *>(this), &SwOutlineTabDialog::LinkStubCancelHdl)); | |||
153 | ||||
154 | AddTabPage("position", &SwNumPositionTabPage::Create, nullptr); | |||
155 | AddTabPage("numbering", &SwOutlineSettingsTabPage::Create, nullptr); | |||
156 | ||||
157 | OUString sHeadline; | |||
158 | sal_uInt16 i; | |||
159 | ||||
160 | for( i = 0; i < MAXLEVEL; ++i ) | |||
161 | { | |||
162 | // if the style wasn't created yet, it's still at this position | |||
163 | if( !rWrtSh.GetParaStyle( sHeadline = | |||
164 | SwStyleNameMapper::GetUIName( static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i), | |||
165 | sHeadline )) ) | |||
166 | aCollNames[i] = sHeadline; | |||
167 | } | |||
168 | ||||
169 | // query the text templates' outlining levels | |||
170 | const sal_uInt16 nCount = rWrtSh.GetTextFormatCollCount(); | |||
171 | for(i = 0; i < nCount; ++i ) | |||
172 | { | |||
173 | SwTextFormatColl &rTextColl = rWrtSh.GetTextFormatColl(i); | |||
174 | if(!rTextColl.IsDefault()) | |||
175 | { | |||
176 | if(rTextColl.IsAssignedToListLevelOfOutlineStyle()) | |||
177 | { | |||
178 | int nOutLevel = rTextColl.GetAssignedOutlineStyleLevel(); | |||
179 | aCollNames[ nOutLevel ] = rTextColl.GetName(); | |||
180 | } | |||
181 | } | |||
182 | } | |||
183 | } | |||
184 | ||||
185 | SwOutlineTabDialog::~SwOutlineTabDialog() | |||
186 | { | |||
187 | } | |||
188 | ||||
189 | void SwOutlineTabDialog::PageCreated(const OString& rPageId, SfxTabPage& rPage) | |||
190 | { | |||
191 | if (rPageId == "position") | |||
192 | { | |||
193 | static_cast<SwNumPositionTabPage&>(rPage).SetWrtShell(&rWrtSh); | |||
194 | static_cast<SwNumPositionTabPage&>(rPage).SetOutlineTabDialog(this); | |||
195 | } | |||
196 | else if (rPageId == "numbering") | |||
197 | { | |||
198 | static_cast<SwOutlineSettingsTabPage&>(rPage).SetWrtShell(&rWrtSh); | |||
199 | } | |||
200 | } | |||
201 | ||||
202 | IMPL_LINK_NOARG(SwOutlineTabDialog, CancelHdl, weld::Button&, void)void SwOutlineTabDialog::LinkStubCancelHdl(void * instance, weld ::Button& data) { return static_cast<SwOutlineTabDialog *>(instance)->CancelHdl(data); } void SwOutlineTabDialog ::CancelHdl(__attribute__ ((unused)) weld::Button&) | |||
203 | { | |||
204 | if (!bModified) | |||
205 | rWrtSh.ResetModified(); | |||
206 | m_xDialog->response(RET_CANCEL); | |||
207 | } | |||
208 | ||||
209 | IMPL_LINK_NOARG(SwOutlineTabDialog, FormHdl, weld::ToggleButton&, void)void SwOutlineTabDialog::LinkStubFormHdl(void * instance, weld ::ToggleButton& data) { return static_cast<SwOutlineTabDialog *>(instance)->FormHdl(data); } void SwOutlineTabDialog ::FormHdl(__attribute__ ((unused)) weld::ToggleButton&) | |||
210 | { | |||
211 | if (!m_xMenuButton->get_active()) | |||
212 | return; | |||
213 | ||||
214 | // fill PopupMenu | |||
215 | for(sal_uInt16 i = 0; i < SwChapterNumRules::nMaxRules; ++i) | |||
216 | { | |||
217 | const SwNumRulesWithName *pRules = pChapterNumRules->GetRules(i); | |||
218 | if (!pRules) | |||
219 | continue; | |||
220 | m_xMenuButton->set_item_label("form" + OString::number(i + 1), pRules->GetName()); | |||
221 | } | |||
222 | ||||
223 | OString sHelpId(m_xMenuButton->get_item_help_id("form1")); | |||
224 | for (sal_Int32 i = 2; i <= 9; ++i) | |||
225 | { | |||
226 | m_xMenuButton->set_item_help_id("form" + OString::number(i), sHelpId); | |||
227 | } | |||
228 | } | |||
229 | ||||
230 | IMPL_LINK(SwOutlineTabDialog, MenuSelectHdl, const OString&, rIdent, void)void SwOutlineTabDialog::LinkStubMenuSelectHdl(void * instance , const OString& data) { return static_cast<SwOutlineTabDialog *>(instance)->MenuSelectHdl(data); } void SwOutlineTabDialog ::MenuSelectHdl(const OString& rIdent) | |||
231 | { | |||
232 | sal_uInt8 nLevelNo = 0; | |||
233 | ||||
234 | if (rIdent == "form1") | |||
235 | nLevelNo = 1; | |||
236 | else if (rIdent == "form2") | |||
237 | nLevelNo = 2; | |||
238 | else if (rIdent == "form3") | |||
239 | nLevelNo = 3; | |||
240 | else if (rIdent == "form4") | |||
241 | nLevelNo = 4; | |||
242 | else if (rIdent == "form5") | |||
243 | nLevelNo = 5; | |||
244 | else if (rIdent == "form6") | |||
245 | nLevelNo = 6; | |||
246 | else if (rIdent == "form7") | |||
247 | nLevelNo = 7; | |||
248 | else if (rIdent == "form8") | |||
249 | nLevelNo = 8; | |||
250 | else if (rIdent == "form9") | |||
251 | nLevelNo = 9; | |||
252 | else if (rIdent == "saveas") | |||
253 | { | |||
254 | SwNumNamesDlg aDlg(m_xDialog.get()); | |||
255 | const OUString *aStrArr[SwChapterNumRules::nMaxRules]; | |||
256 | for(sal_uInt16 i = 0; i < SwChapterNumRules::nMaxRules; ++i) | |||
257 | { | |||
258 | const SwNumRulesWithName *pRules = pChapterNumRules->GetRules(i); | |||
259 | if(pRules) | |||
260 | aStrArr[i] = &pRules->GetName(); | |||
261 | else | |||
262 | aStrArr[i] = nullptr; | |||
263 | } | |||
264 | aDlg.SetUserNames(aStrArr); | |||
265 | if (aDlg.run() == RET_OK) | |||
266 | { | |||
267 | const OUString aName(aDlg.GetName()); | |||
268 | pChapterNumRules->ApplyNumRules( SwNumRulesWithName( | |||
269 | *xNumRule, aName ), aDlg.GetCurEntryPos() ); | |||
270 | m_xMenuButton->set_item_label("form" + OString::number(aDlg.GetCurEntryPos() + 1), aName); | |||
271 | } | |||
272 | return; | |||
273 | } | |||
274 | ||||
275 | if( nLevelNo-- ) | |||
276 | { | |||
277 | const SwNumRulesWithName *pRules = pChapterNumRules->GetRules( nLevelNo ); | |||
278 | if( pRules ) | |||
279 | { | |||
280 | xNumRule = pRules->MakeNumRule(rWrtSh); | |||
281 | xNumRule->SetRuleType( OUTLINE_RULE ); | |||
282 | SfxTabPage* pOutlinePage = GetTabPage("numbering"); | |||
283 | assert(pOutlinePage)(static_cast <bool> (pOutlinePage) ? void (0) : __assert_fail ("pOutlinePage", "/home/maarten/src/libreoffice/core/sw/source/ui/misc/outline.cxx" , 283, __extension__ __PRETTY_FUNCTION__)); | |||
284 | static_cast<SwOutlineSettingsTabPage*>(pOutlinePage)->SetNumRule(xNumRule.get()); | |||
285 | } | |||
286 | else | |||
287 | *xNumRule = *rWrtSh.GetOutlineNumRule(); | |||
288 | } | |||
289 | ||||
290 | SfxTabPage* pPage = GetCurTabPage(); | |||
291 | pPage->Reset(GetOutputItemSet()); | |||
292 | } | |||
293 | ||||
294 | sal_uInt16 SwOutlineTabDialog::GetLevel(const OUString &rFormatName) const | |||
295 | { | |||
296 | for(sal_uInt16 i = 0; i < MAXLEVEL; ++i) | |||
297 | { | |||
298 | if(aCollNames[i] == rFormatName) | |||
299 | return i; | |||
300 | } | |||
301 | return MAXLEVEL; | |||
302 | } | |||
303 | ||||
304 | short SwOutlineTabDialog::Ok() | |||
305 | { | |||
306 | SfxTabDialogController::Ok(); | |||
307 | // set levels for all created templates; has to be done in order to | |||
308 | // delete possibly cancelled assignments again. | |||
309 | ||||
310 | // encapsulate changes into an action to avoid effects on the current cursor | |||
311 | // position during the changes. | |||
312 | rWrtSh.StartAction(); | |||
313 | ||||
314 | const SwNumRule * pOutlineRule = rWrtSh.GetOutlineNumRule(); | |||
315 | ||||
316 | sal_uInt16 i, nCount = rWrtSh.GetTextFormatCollCount(); | |||
317 | for( i = 0; i < nCount; ++i ) | |||
318 | { | |||
319 | SwTextFormatColl &rTextColl = rWrtSh.GetTextFormatColl(i); | |||
320 | if( !rTextColl.IsDefault() ) | |||
321 | { | |||
322 | const SfxPoolItem & rItem = | |||
323 | rTextColl.GetFormatAttr(RES_PARATR_NUMRULE, false); | |||
324 | ||||
325 | if (static_cast<sal_uInt8>(GetLevel(rTextColl.GetName())) == MAXLEVEL) | |||
326 | { | |||
327 | if(rTextColl.IsAssignedToListLevelOfOutlineStyle()) | |||
328 | { | |||
329 | rTextColl.DeleteAssignmentToListLevelOfOutlineStyle(); | |||
330 | } | |||
331 | if (static_cast<const SwNumRuleItem &>(rItem).GetValue() == | |||
332 | pOutlineRule->GetName()) | |||
333 | { | |||
334 | rTextColl.ResetFormatAttr(RES_PARATR_NUMRULE); | |||
335 | } | |||
336 | } | |||
337 | else | |||
338 | { | |||
339 | rTextColl.AssignToListLevelOfOutlineStyle(GetLevel(rTextColl.GetName())); | |||
340 | ||||
341 | if (static_cast<const SwNumRuleItem &>(rItem).GetValue() != | |||
342 | pOutlineRule->GetName()) | |||
343 | { | |||
344 | SwNumRuleItem aItem(pOutlineRule->GetName()); | |||
345 | rTextColl.SetFormatAttr(aItem); | |||
346 | } | |||
347 | } | |||
348 | } | |||
349 | } | |||
350 | ||||
351 | for(i = 0; i < MAXLEVEL; ++i ) | |||
352 | { | |||
353 | OUString sHeadline; | |||
354 | ::SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i), | |||
355 | sHeadline ); | |||
356 | SwTextFormatColl* pColl = rWrtSh.FindTextFormatCollByName( sHeadline ); | |||
357 | if( !pColl && aCollNames[i] != sHeadline) | |||
358 | { | |||
359 | SwTextFormatColl* pTextColl = rWrtSh.GetTextCollFromPool( | |||
360 | static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i) ); | |||
361 | pTextColl->DeleteAssignmentToListLevelOfOutlineStyle(); | |||
362 | pTextColl->ResetFormatAttr(RES_PARATR_NUMRULE); | |||
363 | ||||
364 | if( !aCollNames[i].isEmpty() ) | |||
365 | { | |||
366 | pTextColl = rWrtSh.GetParaStyle( | |||
367 | aCollNames[i], SwWrtShell::GETSTYLE_CREATESOME); | |||
368 | if(pTextColl) | |||
369 | { | |||
370 | pTextColl->AssignToListLevelOfOutlineStyle(i); | |||
371 | SwNumRuleItem aItem(pOutlineRule->GetName()); | |||
372 | pTextColl->SetFormatAttr(aItem); | |||
373 | } | |||
374 | } | |||
375 | } | |||
376 | } | |||
377 | ||||
378 | rWrtSh.SetOutlineNumRule(*xNumRule); | |||
379 | ||||
380 | // #i30443# | |||
381 | rWrtSh.EndAction(); | |||
382 | ||||
383 | return RET_OK; | |||
384 | } | |||
385 | ||||
386 | SwOutlineSettingsTabPage::SwOutlineSettingsTabPage(weld::Container* pPage, weld::DialogController* pController, | |||
387 | const SfxItemSet& rSet) | |||
388 | : SfxTabPage(pPage, pController, "modules/swriter/ui/outlinenumberingpage.ui", "OutlineNumberingPage", &rSet) | |||
389 | , aNoFormatName(SwResId(SW_STR_NONEreinterpret_cast<char const *>("SW_STR_NONE" "\004" u8"[None]" ))) | |||
390 | , pSh(nullptr) | |||
391 | , pNumRule(nullptr) | |||
392 | , pCollNames(nullptr) | |||
393 | , nActLevel(1) | |||
394 | , m_xLevelLB(m_xBuilder->weld_tree_view("level")) | |||
395 | , m_xCollBox(m_xBuilder->weld_combo_box("style")) | |||
396 | , m_xNumberBox(new SwNumberingTypeListBox(m_xBuilder->weld_combo_box("numbering"))) | |||
397 | , m_xCharFormatLB(m_xBuilder->weld_combo_box("charstyle")) | |||
398 | , m_xAllLevelFT(m_xBuilder->weld_label("sublevelsft")) | |||
399 | , m_xAllLevelNF(m_xBuilder->weld_spin_button("sublevelsnf")) | |||
400 | , m_xPrefixED(m_xBuilder->weld_entry("prefix")) | |||
401 | , m_xSuffixED(m_xBuilder->weld_entry("suffix")) | |||
402 | , m_xStartEdit(m_xBuilder->weld_spin_button("startat")) | |||
403 | , m_xPreviewWIN(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWIN)) | |||
404 | { | |||
405 | SetExchangeSupport(); | |||
406 | ||||
407 | m_xNumberBox->Reload(SwInsertNumTypes::NoNumbering | SwInsertNumTypes::Extended); | |||
408 | m_xCollBox->make_sorted(); | |||
409 | m_xCollBox->append_text(aNoFormatName); | |||
410 | m_xLevelLB->connect_changed(LINK(this, SwOutlineSettingsTabPage, LevelHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage *>(this), &SwOutlineSettingsTabPage::LinkStubLevelHdl )); | |||
411 | m_xAllLevelNF->connect_value_changed(LINK(this, SwOutlineSettingsTabPage, ToggleComplete)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage *>(this), &SwOutlineSettingsTabPage::LinkStubToggleComplete )); | |||
412 | m_xCollBox->connect_changed(LINK(this, SwOutlineSettingsTabPage, CollSelect)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage *>(this), &SwOutlineSettingsTabPage::LinkStubCollSelect )); | |||
413 | m_xNumberBox->connect_changed(LINK(this, SwOutlineSettingsTabPage, NumberSelect)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage *>(this), &SwOutlineSettingsTabPage::LinkStubNumberSelect )); | |||
414 | m_xPrefixED->connect_changed(LINK(this, SwOutlineSettingsTabPage, DelimModify)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage *>(this), &SwOutlineSettingsTabPage::LinkStubDelimModify )); | |||
415 | m_xSuffixED->connect_changed(LINK(this, SwOutlineSettingsTabPage, DelimModify)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage *>(this), &SwOutlineSettingsTabPage::LinkStubDelimModify )); | |||
416 | m_xStartEdit->connect_value_changed(LINK(this, SwOutlineSettingsTabPage, StartModified)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage *>(this), &SwOutlineSettingsTabPage::LinkStubStartModified )); | |||
417 | m_xCharFormatLB->connect_changed(LINK(this, SwOutlineSettingsTabPage, CharFormatHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage *>(this), &SwOutlineSettingsTabPage::LinkStubCharFormatHdl )); | |||
418 | } | |||
419 | ||||
420 | void SwOutlineSettingsTabPage::Update() | |||
421 | { | |||
422 | // if a template was already selected for this level, select it in the ListBox | |||
423 | m_xCollBox->set_sensitive(USHRT_MAX(32767 *2 +1) != nActLevel); | |||
424 | if(USHRT_MAX(32767 *2 +1) == nActLevel) | |||
425 | { | |||
426 | bool bSamePrefix = true; | |||
427 | bool bSameSuffix = true; | |||
428 | bool bSameType = true; | |||
429 | bool bSameComplete = true; | |||
430 | bool bSameStart = true; | |||
431 | bool bSameCharFormat = true; | |||
432 | ||||
433 | const SwNumFormat* aNumFormatArr[MAXLEVEL]; | |||
434 | const SwCharFormat* pFirstFormat = nullptr; | |||
435 | ||||
436 | for(sal_uInt16 i = 0; i < MAXLEVEL; i++) | |||
437 | { | |||
438 | ||||
439 | aNumFormatArr[ i ] = &pNumRule->Get(i); | |||
440 | if(i == 0) | |||
441 | pFirstFormat = aNumFormatArr[i]->GetCharFormat(); | |||
442 | else | |||
443 | { | |||
444 | bSameType &= aNumFormatArr[i]->GetNumberingType() == aNumFormatArr[0]->GetNumberingType(); | |||
445 | bSameStart &= aNumFormatArr[i]->GetStart() == aNumFormatArr[0]->GetStart(); | |||
446 | bSamePrefix &= aNumFormatArr[i]->GetPrefix() == aNumFormatArr[0]->GetPrefix(); | |||
447 | bSameSuffix &= aNumFormatArr[i]->GetSuffix() == aNumFormatArr[0]->GetSuffix(); | |||
448 | bSameComplete &= aNumFormatArr[i]->GetIncludeUpperLevels() == aNumFormatArr[0]->GetIncludeUpperLevels(); | |||
449 | const SwCharFormat* pFormat = aNumFormatArr[i]->GetCharFormat(); | |||
450 | bSameCharFormat &= (!pFirstFormat && !pFormat) | |||
451 | || (pFirstFormat && pFormat && pFormat->GetName() == pFirstFormat->GetName()); | |||
452 | } | |||
453 | } | |||
454 | CheckForStartValue_Impl(aNumFormatArr[0]->GetNumberingType()); | |||
455 | if (bSameType) | |||
456 | m_xNumberBox->SelectNumberingType( aNumFormatArr[0]->GetNumberingType() ); | |||
457 | else | |||
458 | m_xNumberBox->SetNoSelection(); | |||
459 | if(bSameStart) | |||
460 | m_xStartEdit->set_value(aNumFormatArr[0]->GetStart()); | |||
461 | else | |||
462 | m_xStartEdit->set_text(OUString()); | |||
463 | if(bSamePrefix) | |||
464 | m_xPrefixED->set_text(aNumFormatArr[0]->GetPrefix()); | |||
465 | else | |||
466 | m_xPrefixED->set_text(OUString()); | |||
467 | if(bSameSuffix) | |||
468 | m_xSuffixED->set_text(aNumFormatArr[0]->GetSuffix()); | |||
469 | else | |||
470 | m_xSuffixED->set_text(OUString()); | |||
471 | ||||
472 | if (bSameCharFormat) | |||
473 | { | |||
474 | if (pFirstFormat) | |||
475 | m_xCharFormatLB->set_active_text(pFirstFormat->GetName()); | |||
476 | else | |||
477 | m_xCharFormatLB->set_active_text(SwViewShell::GetShellRes()->aStrNone); | |||
478 | } | |||
479 | else | |||
480 | m_xCharFormatLB->set_active(-1); | |||
481 | ||||
482 | m_xAllLevelFT->set_sensitive(true); | |||
483 | m_xAllLevelNF->set_sensitive(true); | |||
484 | m_xAllLevelNF->set_max(MAXLEVEL); | |||
485 | if (bSameComplete) | |||
486 | { | |||
487 | m_xAllLevelNF->set_value(aNumFormatArr[0]->GetIncludeUpperLevels()); | |||
488 | } | |||
489 | else | |||
490 | { | |||
491 | m_xAllLevelNF->set_text(OUString()); | |||
492 | } | |||
493 | } | |||
494 | else | |||
495 | { | |||
496 | sal_uInt16 nTmpLevel = lcl_BitToLevel(nActLevel); | |||
497 | OUString aColl(pCollNames[nTmpLevel]); | |||
498 | if(!aColl.isEmpty()) | |||
499 | m_xCollBox->set_active_text(aColl); | |||
500 | else | |||
501 | m_xCollBox->set_active_text(aNoFormatName); | |||
502 | const SwNumFormat &rFormat = pNumRule->Get(nTmpLevel); | |||
503 | ||||
504 | m_xNumberBox->SelectNumberingType( rFormat.GetNumberingType() ); | |||
505 | m_xPrefixED->set_text(rFormat.GetPrefix()); | |||
506 | m_xSuffixED->set_text(rFormat.GetSuffix()); | |||
507 | const SwCharFormat* pFormat = rFormat.GetCharFormat(); | |||
508 | if(pFormat) | |||
509 | m_xCharFormatLB->set_active_text(pFormat->GetName()); | |||
510 | else | |||
511 | m_xCharFormatLB->set_active_text(SwViewShell::GetShellRes()->aStrNone); | |||
512 | ||||
513 | if(nTmpLevel) | |||
514 | { | |||
515 | m_xAllLevelFT->set_sensitive(true); | |||
516 | m_xAllLevelNF->set_sensitive(true); | |||
517 | m_xAllLevelNF->set_max(nTmpLevel + 1); | |||
518 | m_xAllLevelNF->set_value(rFormat.GetIncludeUpperLevels()); | |||
519 | } | |||
520 | else | |||
521 | { | |||
522 | m_xAllLevelNF->set_text(OUString()); | |||
523 | m_xAllLevelNF->set_sensitive(false); | |||
524 | m_xAllLevelFT->set_sensitive(false); | |||
525 | } | |||
526 | CheckForStartValue_Impl(rFormat.GetNumberingType()); | |||
527 | m_xStartEdit->set_value( rFormat.GetStart() ); | |||
528 | } | |||
529 | SetModified(); | |||
530 | } | |||
531 | ||||
532 | IMPL_LINK( SwOutlineSettingsTabPage, LevelHdl, weld::TreeView&, rBox, void )void SwOutlineSettingsTabPage::LinkStubLevelHdl(void * instance , weld::TreeView& data) { return static_cast<SwOutlineSettingsTabPage *>(instance)->LevelHdl(data); } void SwOutlineSettingsTabPage ::LevelHdl(weld::TreeView& rBox) | |||
533 | { | |||
534 | nActLevel = 0; | |||
535 | auto aRows = rBox.get_selected_rows(); | |||
536 | if (std::find(aRows.begin(), aRows.end(), MAXLEVEL) != aRows.end()) | |||
537 | { | |||
538 | nActLevel = 0xFFFF; | |||
539 | } | |||
540 | else | |||
541 | { | |||
542 | sal_uInt16 nMask = 1; | |||
543 | for( sal_uInt16 i = 0; i < MAXLEVEL; i++ ) | |||
544 | { | |||
545 | if (std::find(aRows.begin(), aRows.end(), i) != aRows.end()) | |||
546 | nActLevel |= nMask; | |||
547 | nMask <<= 1; | |||
548 | } | |||
549 | } | |||
550 | Update(); | |||
551 | } | |||
552 | ||||
553 | IMPL_LINK(SwOutlineSettingsTabPage, ToggleComplete, weld::SpinButton&, rEdit, void)void SwOutlineSettingsTabPage::LinkStubToggleComplete(void * instance , weld::SpinButton& data) { return static_cast<SwOutlineSettingsTabPage *>(instance)->ToggleComplete(data); } void SwOutlineSettingsTabPage ::ToggleComplete(weld::SpinButton& rEdit) | |||
554 | { | |||
555 | sal_uInt16 nMask = 1; | |||
556 | for(sal_uInt16 i = 0; i < MAXLEVEL; i++) | |||
557 | { | |||
558 | if(nActLevel & nMask) | |||
559 | { | |||
560 | SwNumFormat aNumFormat(pNumRule->Get(i)); | |||
561 | aNumFormat.SetIncludeUpperLevels( std::min( static_cast<sal_uInt8>(rEdit.get_value()), | |||
562 | static_cast<sal_uInt8>(i + 1)) ); | |||
563 | pNumRule->Set(i, aNumFormat); | |||
564 | } | |||
565 | nMask <<= 1; | |||
566 | } | |||
567 | SetModified(); | |||
568 | } | |||
569 | ||||
570 | IMPL_LINK( SwOutlineSettingsTabPage, CollSelect, weld::ComboBox&, rBox, void )void SwOutlineSettingsTabPage::LinkStubCollSelect(void * instance , weld::ComboBox& data) { return static_cast<SwOutlineSettingsTabPage *>(instance)->CollSelect(data); } void SwOutlineSettingsTabPage ::CollSelect(weld::ComboBox& rBox) | |||
571 | { | |||
572 | sal_uInt8 i; | |||
573 | ||||
574 | const OUString aCollName(rBox.get_active_text()); | |||
575 | //0xFFFF not allowed here (disable) | |||
576 | sal_uInt16 nTmpLevel = lcl_BitToLevel(nActLevel); | |||
577 | OUString sOldName( pCollNames[nTmpLevel] ); | |||
578 | ||||
579 | for( i = 0; i < MAXLEVEL; ++i) | |||
580 | pCollNames[i] = aSaveCollNames[i]; | |||
581 | ||||
582 | if(aCollName == aNoFormatName) | |||
583 | pCollNames[nTmpLevel].clear(); | |||
584 | else | |||
585 | { | |||
586 | pCollNames[nTmpLevel] = aCollName; | |||
587 | // template already in use? | |||
588 | for( i = 0; i < MAXLEVEL; ++i) | |||
589 | if(i != nTmpLevel && pCollNames[i] == aCollName ) | |||
590 | pCollNames[i].clear(); | |||
591 | } | |||
592 | ||||
593 | // search the oldname and put it into the current entries | |||
594 | if( !sOldName.isEmpty() ) | |||
595 | for( i = 0; i < MAXLEVEL; ++i) | |||
596 | if( aSaveCollNames[ i ] == sOldName && i != nTmpLevel && | |||
597 | pCollNames[ i ].isEmpty() ) | |||
598 | { | |||
599 | sal_uInt8 n; | |||
600 | for( n = 0; n < MAXLEVEL; ++n ) | |||
601 | if( pCollNames[ n ] == sOldName ) | |||
602 | break; | |||
603 | ||||
604 | if( MAXLEVEL == n ) | |||
605 | // it was an outline level name and the current entries is zero. | |||
606 | pCollNames[ i ] = sOldName; | |||
607 | } | |||
608 | ||||
609 | SetModified(); | |||
610 | CollSave(); | |||
611 | } | |||
612 | ||||
613 | void SwOutlineSettingsTabPage::CollSave() | |||
614 | { | |||
615 | for (sal_uInt8 i = 0; i < MAXLEVEL; ++i) | |||
616 | aSaveCollNames[i] = pCollNames[i]; | |||
617 | } | |||
618 | ||||
619 | IMPL_LINK_NOARG(SwOutlineSettingsTabPage, NumberSelect, weld::ComboBox&, void)void SwOutlineSettingsTabPage::LinkStubNumberSelect(void * instance , weld::ComboBox& data) { return static_cast<SwOutlineSettingsTabPage *>(instance)->NumberSelect(data); } void SwOutlineSettingsTabPage ::NumberSelect(__attribute__ ((unused)) weld::ComboBox&) | |||
620 | { | |||
621 | sal_uInt16 nMask = 1; | |||
622 | SvxNumType nNumberType = m_xNumberBox->GetSelectedNumberingType(); | |||
623 | for(sal_uInt16 i = 0; i < MAXLEVEL; i++) | |||
624 | { | |||
625 | if(nActLevel & nMask) | |||
626 | { | |||
627 | SwNumFormat aNumFormat(pNumRule->Get(i)); | |||
628 | aNumFormat.SetNumberingType(nNumberType); | |||
629 | pNumRule->Set(i, aNumFormat); | |||
630 | CheckForStartValue_Impl(nNumberType); | |||
631 | } | |||
632 | nMask <<= 1; | |||
633 | } | |||
634 | SetModified(); | |||
635 | } | |||
636 | ||||
637 | IMPL_LINK_NOARG(SwOutlineSettingsTabPage, DelimModify, weld::Entry&, void)void SwOutlineSettingsTabPage::LinkStubDelimModify(void * instance , weld::Entry& data) { return static_cast<SwOutlineSettingsTabPage *>(instance)->DelimModify(data); } void SwOutlineSettingsTabPage ::DelimModify(__attribute__ ((unused)) weld::Entry&) | |||
638 | { | |||
639 | sal_uInt16 nMask = 1; | |||
640 | for(sal_uInt16 i = 0; i < MAXLEVEL; i++) | |||
641 | { | |||
642 | if(nActLevel & nMask) | |||
643 | { | |||
644 | SwNumFormat aNumFormat(pNumRule->Get(i)); | |||
645 | aNumFormat.SetPrefix( m_xPrefixED->get_text() ); | |||
646 | aNumFormat.SetSuffix( m_xSuffixED->get_text() ); | |||
647 | pNumRule->Set(i, aNumFormat); | |||
648 | } | |||
649 | nMask <<= 1; | |||
650 | } | |||
651 | SetModified(); | |||
652 | } | |||
653 | ||||
654 | IMPL_LINK( SwOutlineSettingsTabPage, StartModified, weld::SpinButton&, rEdit, void )void SwOutlineSettingsTabPage::LinkStubStartModified(void * instance , weld::SpinButton& data) { return static_cast<SwOutlineSettingsTabPage *>(instance)->StartModified(data); } void SwOutlineSettingsTabPage ::StartModified(weld::SpinButton& rEdit) | |||
655 | { | |||
656 | sal_uInt16 nMask = 1; | |||
657 | for(sal_uInt16 i = 0; i < MAXLEVEL; i++) | |||
658 | { | |||
659 | if(nActLevel & nMask) | |||
660 | { | |||
661 | SwNumFormat aNumFormat(pNumRule->Get(i)); | |||
662 | aNumFormat.SetStart(static_cast<sal_uInt16>(rEdit.get_value())); | |||
663 | pNumRule->Set(i, aNumFormat); | |||
664 | } | |||
665 | nMask <<= 1; | |||
666 | } | |||
667 | SetModified(); | |||
668 | } | |||
669 | ||||
670 | IMPL_LINK_NOARG(SwOutlineSettingsTabPage, CharFormatHdl, weld::ComboBox&, void)void SwOutlineSettingsTabPage::LinkStubCharFormatHdl(void * instance , weld::ComboBox& data) { return static_cast<SwOutlineSettingsTabPage *>(instance)->CharFormatHdl(data); } void SwOutlineSettingsTabPage ::CharFormatHdl(__attribute__ ((unused)) weld::ComboBox&) | |||
671 | { | |||
672 | OUString sEntry = m_xCharFormatLB->get_active_text(); | |||
673 | sal_uInt16 nMask = 1; | |||
674 | bool bFormatNone = sEntry == SwViewShell::GetShellRes()->aStrNone; | |||
675 | SwCharFormat* pFormat = nullptr; | |||
676 | if(!bFormatNone) | |||
677 | { | |||
678 | sal_uInt16 nChCount = pSh->GetCharFormatCount(); | |||
679 | for(sal_uInt16 i = 0; i < nChCount; i++) | |||
680 | { | |||
681 | SwCharFormat& rChFormat = pSh->GetCharFormat(i); | |||
682 | if(rChFormat.GetName() == sEntry) | |||
683 | { | |||
684 | pFormat = &rChFormat; | |||
685 | break; | |||
686 | } | |||
687 | } | |||
688 | if(!pFormat) | |||
689 | { | |||
690 | SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool(); | |||
691 | SfxStyleSheetBase* pBase; | |||
692 | pBase = pPool->Find(sEntry, SfxStyleFamily::Char); | |||
693 | if(!pBase) | |||
694 | pBase = &pPool->Make(sEntry, SfxStyleFamily::Page); | |||
695 | pFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat(); | |||
696 | ||||
697 | } | |||
698 | } | |||
699 | ||||
700 | for(sal_uInt16 i = 0; i < MAXLEVEL; i++) | |||
701 | { | |||
702 | if(nActLevel & nMask) | |||
703 | { | |||
704 | SwNumFormat aNumFormat(pNumRule->Get(i)); | |||
705 | if(bFormatNone) | |||
706 | aNumFormat.SetCharFormat(nullptr); | |||
707 | else | |||
708 | aNumFormat.SetCharFormat(pFormat); | |||
709 | pNumRule->Set(i, aNumFormat); | |||
710 | } | |||
711 | nMask <<= 1; | |||
712 | } | |||
713 | } | |||
714 | ||||
715 | SwOutlineSettingsTabPage::~SwOutlineSettingsTabPage() | |||
716 | { | |||
717 | } | |||
718 | ||||
719 | void SwOutlineSettingsTabPage::SetWrtShell(SwWrtShell* pShell) | |||
720 | { | |||
721 | pSh = pShell; | |||
722 | // query this document's NumRules | |||
723 | pNumRule = static_cast<SwOutlineTabDialog*>(GetDialogController())->GetNumRule(); | |||
724 | pCollNames = static_cast<SwOutlineTabDialog*>(GetDialogController())->GetCollNames(); | |||
725 | ||||
726 | CollSave(); | |||
727 | ||||
728 | m_aPreviewWIN.SetNumRule(pNumRule); | |||
729 | m_aPreviewWIN.SetOutlineNames(pCollNames); | |||
730 | // set start value - nActLevel must be 1 here | |||
731 | sal_uInt16 nTmpLevel = lcl_BitToLevel(nActLevel); | |||
732 | const SwNumFormat& rNumFormat = pNumRule->Get( nTmpLevel ); | |||
733 | m_xStartEdit->set_value( rNumFormat.GetStart() ); | |||
734 | ||||
735 | // create pool formats for headlines | |||
736 | for (sal_uInt16 i = 0; i < MAXLEVEL; ++i) | |||
737 | { | |||
738 | m_xCollBox->append_text( SwStyleNameMapper::GetUIName( | |||
739 | static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i), OUString())); | |||
740 | m_xLevelLB->append_text( OUString::number(i + 1) ); | |||
741 | } | |||
742 | OUString sStr = "1 - " + OUString::number(MAXLEVEL); | |||
743 | m_xLevelLB->append_text(sStr); | |||
744 | ||||
745 | // query the texttemplates' outlining levels | |||
746 | const sal_uInt16 nCount = pSh->GetTextFormatCollCount(); | |||
747 | for (sal_uInt16 i = 0; i < nCount; ++i) | |||
748 | { | |||
749 | SwTextFormatColl &rTextColl = pSh->GetTextFormatColl(i); | |||
750 | if(!rTextColl.IsDefault()) | |||
751 | { | |||
752 | sStr = rTextColl.GetName(); | |||
753 | if (m_xCollBox->find_text(sStr) == -1) | |||
754 | m_xCollBox->append_text(sStr); | |||
755 | } | |||
756 | } | |||
757 | ||||
758 | m_xNumberBox->SelectNumberingType(rNumFormat.GetNumberingType()); | |||
759 | SwOutlineNodes::size_type nOutlinePos = pSh->GetOutlinePos(MAXLEVEL); | |||
760 | int nTmp = 0; | |||
761 | if(nOutlinePos != SwOutlineNodes::npos) | |||
762 | { | |||
763 | nTmp = static_cast<sal_uInt16>(pSh->getIDocumentOutlineNodesAccess()->getOutlineLevel(nOutlinePos)); | |||
764 | } | |||
765 | m_xLevelLB->select(nTmp-1); | |||
766 | ||||
767 | // collect char styles | |||
768 | m_xCharFormatLB->clear(); | |||
769 | m_xCharFormatLB->append_text(SwViewShell::GetShellRes()->aStrNone); | |||
770 | ||||
771 | // char styles | |||
772 | ::FillCharStyleListBox(*m_xCharFormatLB, | |||
773 | pSh->GetView().GetDocShell()); | |||
774 | Update(); | |||
775 | } | |||
776 | ||||
777 | void SwOutlineSettingsTabPage::ActivatePage(const SfxItemSet& ) | |||
778 | { | |||
779 | nActLevel = SwOutlineTabDialog::GetActNumLevel(); | |||
780 | if(nActLevel != USHRT_MAX(32767 *2 +1)) | |||
781 | m_xLevelLB->select(lcl_BitToLevel(nActLevel)); | |||
782 | else | |||
783 | m_xLevelLB->select(MAXLEVEL); | |||
784 | LevelHdl(*m_xLevelLB); | |||
785 | } | |||
786 | ||||
787 | DeactivateRC SwOutlineSettingsTabPage::DeactivatePage(SfxItemSet*) | |||
788 | { | |||
789 | SwOutlineTabDialog::SetActNumLevel(nActLevel); | |||
790 | return DeactivateRC::LeavePage; | |||
791 | } | |||
792 | ||||
793 | bool SwOutlineSettingsTabPage::FillItemSet( SfxItemSet* ) | |||
794 | { | |||
795 | return true; | |||
796 | } | |||
797 | ||||
798 | void SwOutlineSettingsTabPage::Reset( const SfxItemSet* rSet ) | |||
799 | { | |||
800 | ActivatePage(*rSet); | |||
801 | } | |||
802 | ||||
803 | std::unique_ptr<SfxTabPage> SwOutlineSettingsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, | |||
804 | const SfxItemSet* rAttrSet) | |||
805 | { | |||
806 | return std::make_unique<SwOutlineSettingsTabPage>(pPage, pController, *rAttrSet); | |||
807 | } | |||
808 | ||||
809 | void SwOutlineSettingsTabPage::CheckForStartValue_Impl(sal_uInt16 nNumberingType) | |||
810 | { | |||
811 | bool bIsNull = m_xStartEdit->get_value() == 0; | |||
812 | bool bNoZeroAllowed = nNumberingType < SVX_NUM_ARABIC || | |||
813 | SVX_NUM_CHARS_UPPER_LETTER_N == nNumberingType || | |||
814 | SVX_NUM_CHARS_LOWER_LETTER_N == nNumberingType; | |||
815 | m_xStartEdit->set_min(bNoZeroAllowed ? 1 : 0); | |||
816 | if (bIsNull && bNoZeroAllowed) | |||
817 | StartModified(*m_xStartEdit); | |||
818 | } | |||
819 | ||||
820 | static long lcl_DrawBullet(vcl::RenderContext* pVDev, const SwNumFormat& rFormat, long nXStart, long nYStart, const Size& rSize) | |||
821 | { | |||
822 | vcl::Font aTmpFont(pVDev->GetFont()); | |||
823 | ||||
824 | // via Uno it's possible that no font has been set! | |||
825 | vcl::Font aFont(rFormat.GetBulletFont() ? *rFormat.GetBulletFont() : aTmpFont); | |||
826 | Size aTmpSize(rSize); | |||
827 | aTmpSize.setWidth( aTmpSize.Width() * ( rFormat.GetBulletRelSize()) ); | |||
828 | aTmpSize.setWidth( aTmpSize.Width() / 100 ) ; | |||
829 | aTmpSize.setHeight( aTmpSize.Height() * ( rFormat.GetBulletRelSize()) ); | |||
830 | aTmpSize.setHeight( aTmpSize.Height() / 100 ) ; | |||
831 | // in case of a height of zero it is drawn in original height | |||
832 | if(!aTmpSize.Height()) | |||
833 | aTmpSize.setHeight( 1 ); | |||
834 | aFont.SetFontSize(aTmpSize); | |||
835 | aFont.SetTransparent(true); | |||
836 | Color aBulletColor = rFormat.GetBulletColor(); | |||
837 | if(aBulletColor == COL_AUTO) | |||
838 | aBulletColor = pVDev->GetFillColor().IsDark() ? COL_WHITE : COL_BLACK; | |||
839 | else if(aBulletColor == pVDev->GetFillColor()) | |||
840 | aBulletColor.Invert(); | |||
841 | aFont.SetColor(aBulletColor); | |||
842 | pVDev->SetFont( aFont ); | |||
843 | sal_UCS4 cBullet = rFormat.GetBulletChar(); | |||
844 | OUString aText(&cBullet, 1); | |||
845 | long nY = nYStart; | |||
846 | nY -= ((aTmpSize.Height() - rSize.Height())/ 2); | |||
847 | pVDev->DrawText( Point(nXStart, nY), aText ); | |||
848 | long nRet = pVDev->GetTextWidth(aText); | |||
849 | ||||
850 | pVDev->SetFont(aTmpFont); | |||
851 | return nRet; | |||
852 | } | |||
853 | ||||
854 | static long lcl_DrawGraphic(vcl::RenderContext* pVDev, const SwNumFormat &rFormat, long nXStart, long nYStart, long nDivision) | |||
855 | { | |||
856 | const SvxBrushItem* pBrushItem = rFormat.GetBrush(); | |||
857 | long nRet = 0; | |||
858 | if (pBrushItem) | |||
859 | { | |||
860 | const Graphic* pGraphic = pBrushItem->GetGraphic(); | |||
861 | if (pGraphic) | |||
862 | { | |||
863 | Size aGSize( rFormat.GetGraphicSize()); | |||
864 | aGSize.setWidth( aGSize.Width() / nDivision ); | |||
865 | nRet = aGSize.Width(); | |||
866 | aGSize.setHeight( aGSize.Height() / nDivision ); | |||
867 | pGraphic->Draw(pVDev, Point(nXStart, nYStart), pVDev->PixelToLogic(aGSize)); | |||
868 | } | |||
869 | } | |||
870 | return nRet; | |||
871 | } | |||
872 | ||||
873 | void NumberingPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) | |||
874 | { | |||
875 | const Size aSize(rRenderContext.PixelToLogic(GetOutputSizePixel())); | |||
876 | ||||
877 | ScopedVclPtrInstance<VirtualDevice> pVDev(rRenderContext); | |||
| ||||
878 | pVDev->SetMapMode(rRenderContext.GetMapMode()); | |||
879 | pVDev->SetOutputSize(aSize); | |||
880 | ||||
881 | // #101524# OJ | |||
882 | pVDev->SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor()); | |||
883 | pVDev->SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetButtonTextColor()); | |||
884 | pVDev->DrawRect(tools::Rectangle(Point(0,0), aSize)); | |||
885 | ||||
886 | if (pActNum) | |||
887 | { | |||
888 | long nWidthRelation = 30; // chapter dialog | |||
889 | if(nPageWidth) | |||
890 | { | |||
891 | nWidthRelation = nPageWidth / aSize.Width(); | |||
892 | if(bPosition) | |||
893 | nWidthRelation = nWidthRelation * 2 / 3; | |||
894 | else | |||
895 | nWidthRelation = nWidthRelation / 4; | |||
896 | } | |||
897 | ||||
898 | // height per level | |||
899 | const long nXStep = aSize.Width() / (3 * MAXLEVEL * ((MAXLEVEL < 10) ? 2 : 1)); | |||
900 | const long nYStep = (aSize.Height() - 6)/ MAXLEVEL; | |||
901 | long nYStart = 4; | |||
902 | aStdFont = OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, GetAppLanguage(), | |||
903 | GetDefaultFontFlags::OnlyOne, &rRenderContext); | |||
904 | // #101524# OJ | |||
905 | aStdFont.SetColor(SwViewOption::GetFontColor()); | |||
906 | ||||
907 | const long nFontHeight = nYStep * ( bPosition ? 15 : 6 ) / 10; | |||
908 | aStdFont.SetFontSize(Size( 0, nFontHeight )); | |||
909 | ||||
910 | long nPreNum = pActNum->Get(0).GetStart(); | |||
911 | ||||
912 | if (bPosition) | |||
913 | { | |||
914 | const long nLineHeight = nFontHeight * 8 / 7; | |||
915 | sal_uInt8 nStart = 0; | |||
916 | while (!(nActLevel & (1 << nStart))) | |||
917 | { | |||
918 | nStart++; | |||
919 | } | |||
920 | if(nStart) // so that possible predecessors and successors are showed | |||
921 | nStart--; | |||
922 | ||||
923 | SwNumberTree::tNumberVector aNumVector; | |||
924 | sal_uInt8 nEnd = std::min(sal_uInt8(nStart + 3), MAXLEVEL); | |||
925 | for (sal_uInt8 nLevel = nStart; nLevel < nEnd; ++nLevel) | |||
926 | { | |||
927 | const SwNumFormat &rFormat = pActNum->Get(nLevel); | |||
928 | aNumVector.push_back(rFormat.GetStart()); | |||
929 | ||||
930 | long nXStart( 0 ); | |||
931 | long nTextOffset( 0 ); | |||
932 | long nNumberXPos( 0 ); | |||
933 | if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION) | |||
934 | { | |||
935 | nXStart = rFormat.GetAbsLSpace() / nWidthRelation; | |||
936 | nTextOffset = rFormat.GetCharTextDistance() / nWidthRelation; | |||
937 | nNumberXPos = nXStart; | |||
938 | const long nFirstLineOffset = (-rFormat.GetFirstLineOffset()) / nWidthRelation; | |||
939 | ||||
940 | if(nFirstLineOffset <= nNumberXPos) | |||
941 | nNumberXPos -= nFirstLineOffset; | |||
942 | else | |||
943 | nNumberXPos = 0; | |||
944 | } | |||
945 | else if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT) | |||
946 | { | |||
947 | const long nTmpNumberXPos((rFormat.GetIndentAt() + rFormat.GetFirstLineIndent()) / nWidthRelation); | |||
948 | nNumberXPos = (nTmpNumberXPos < 0) ? 0 : nTmpNumberXPos; | |||
949 | } | |||
950 | ||||
951 | long nBulletWidth = 0; | |||
952 | if (SVX_NUM_BITMAP == rFormat.GetNumberingType()) | |||
953 | { | |||
954 | nBulletWidth = lcl_DrawGraphic(pVDev.get(), rFormat, nNumberXPos, | |||
955 | nYStart, nWidthRelation); | |||
956 | } | |||
957 | else if (SVX_NUM_CHAR_SPECIAL == rFormat.GetNumberingType()) | |||
958 | { | |||
959 | nBulletWidth = lcl_DrawBullet(pVDev.get(), rFormat, nNumberXPos, | |||
960 | nYStart, aStdFont.GetFontSize()); | |||
961 | } | |||
962 | else | |||
963 | { | |||
964 | pVDev->SetFont(aStdFont); | |||
965 | if(pActNum->IsContinusNum()) | |||
966 | aNumVector[nLevel] = nPreNum; | |||
967 | OUString aText(pActNum->MakeNumString( aNumVector )); | |||
968 | pVDev->DrawText( Point(nNumberXPos, nYStart), aText ); | |||
969 | nBulletWidth = pVDev->GetTextWidth(aText); | |||
970 | nPreNum++; | |||
971 | } | |||
972 | if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT && | |||
973 | rFormat.GetLabelFollowedBy() == SvxNumberFormat::SPACE ) | |||
974 | { | |||
975 | pVDev->SetFont(aStdFont); | |||
976 | OUString aText(' '); | |||
977 | pVDev->DrawText( Point(nNumberXPos, nYStart), aText ); | |||
978 | nBulletWidth += pVDev->GetTextWidth(aText); | |||
979 | } | |||
980 | ||||
981 | long nTextXPos(0); | |||
982 | if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION) | |||
983 | { | |||
984 | nTextXPos = nXStart; | |||
985 | if (nTextOffset < 0) | |||
986 | nTextXPos = nTextXPos + nTextOffset; | |||
987 | if (nNumberXPos + nBulletWidth + nTextOffset > nTextXPos) | |||
988 | nTextXPos = nNumberXPos + nBulletWidth + nTextOffset; | |||
989 | } | |||
990 | else if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT) | |||
991 | { | |||
992 | switch (rFormat.GetLabelFollowedBy()) | |||
993 | { | |||
994 | case SvxNumberFormat::LISTTAB: | |||
995 | { | |||
996 | nTextXPos = rFormat.GetListtabPos() / nWidthRelation; | |||
997 | if (nTextXPos < nNumberXPos + nBulletWidth) | |||
998 | { | |||
999 | nTextXPos = nNumberXPos + nBulletWidth; | |||
1000 | } | |||
1001 | } | |||
1002 | break; | |||
1003 | case SvxNumberFormat::SPACE: | |||
1004 | case SvxNumberFormat::NOTHING: | |||
1005 | case SvxNumberFormat::NEWLINE: | |||
1006 | { | |||
1007 | nTextXPos = nNumberXPos + nBulletWidth; | |||
1008 | } | |||
1009 | break; | |||
1010 | } | |||
1011 | ||||
1012 | nXStart = rFormat.GetIndentAt() / nWidthRelation; | |||
1013 | } | |||
1014 | ||||
1015 | tools::Rectangle aRect1(Point(nTextXPos, nYStart + nFontHeight / 2), Size(aSize.Width() / 2, 2)); | |||
1016 | pVDev->SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor()); // COL_BLACK ); | |||
1017 | pVDev->DrawRect(aRect1); | |||
1018 | ||||
1019 | tools::Rectangle aRect2(Point(nXStart, nYStart + nLineHeight + nFontHeight / 2), Size(aSize.Width() / 2, 2)); | |||
1020 | pVDev->DrawRect(aRect2); | |||
1021 | nYStart += 2 * nLineHeight; | |||
1022 | } | |||
1023 | } | |||
1024 | else | |||
1025 | { | |||
1026 | SwNumberTree::tNumberVector aNumVector; | |||
1027 | const long nLineHeight = nFontHeight * 3 / 2; | |||
1028 | for (sal_uInt8 nLevel = 0; nLevel < MAXLEVEL; ++nLevel, nYStart = nYStart + nYStep) | |||
1029 | { | |||
1030 | const SwNumFormat &rFormat = pActNum->Get(nLevel); | |||
1031 | aNumVector.push_back(rFormat.GetStart()); | |||
1032 | long nXStart(0); | |||
1033 | if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION) | |||
1034 | { | |||
1035 | nXStart = rFormat.GetAbsLSpace() / nWidthRelation; | |||
1036 | } | |||
1037 | else if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT) | |||
1038 | { | |||
1039 | const long nTmpXStart((rFormat.GetIndentAt() + rFormat.GetFirstLineIndent() ) / nWidthRelation); | |||
1040 | nXStart = (nTmpXStart < 0) ? 0 : nTmpXStart; | |||
1041 | } | |||
1042 | nXStart /= 2; | |||
1043 | nXStart += 2; | |||
1044 | long nTextOffset; | |||
1045 | if (SVX_NUM_BITMAP == rFormat.GetNumberingType()) | |||
1046 | { | |||
1047 | lcl_DrawGraphic(pVDev.get(), rFormat, nXStart, nYStart, nWidthRelation); | |||
1048 | nTextOffset = nLineHeight + nXStep; | |||
1049 | } | |||
1050 | else if (SVX_NUM_CHAR_SPECIAL == rFormat.GetNumberingType()) | |||
1051 | { | |||
1052 | nTextOffset = lcl_DrawBullet(pVDev.get(), rFormat, nXStart, nYStart, aStdFont.GetFontSize()); | |||
1053 | nTextOffset += nXStep; | |||
1054 | } | |||
1055 | else | |||
1056 | { | |||
1057 | pVDev->SetFont(aStdFont); | |||
1058 | if (pActNum->IsContinusNum()) | |||
1059 | aNumVector[nLevel] = nPreNum; | |||
1060 | OUString aText(pActNum->MakeNumString( aNumVector )); | |||
1061 | pVDev->DrawText( Point(nXStart, nYStart), aText ); | |||
1062 | nTextOffset = pVDev->GetTextWidth(aText) + nXStep; | |||
1063 | nPreNum++; | |||
1064 | } | |||
1065 | pVDev->SetFont(aStdFont); | |||
1066 | pVDev->DrawText( | |||
1067 | Point(nXStart + nTextOffset, nYStart), | |||
1068 | (pOutlineNames == nullptr | |||
1069 | ? utl::ConfigManager::getProductName() | |||
1070 | : pOutlineNames[nLevel])); | |||
1071 | } | |||
1072 | } | |||
1073 | } | |||
1074 | rRenderContext.DrawOutDev(Point(0,0), aSize, Point(0,0), aSize, *pVDev); | |||
1075 | } | |||
1076 | ||||
1077 | /* 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 |