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 <com/sun/star/text/HoriOrientation.hpp> | |||
21 | #include <com/sun/star/text/VertOrientation.hpp> | |||
22 | ||||
23 | #include <numpages.hxx> | |||
24 | #include <dialmgr.hxx> | |||
25 | #include <tools/mapunit.hxx> | |||
26 | #include <i18nlangtag/languagetag.hxx> | |||
27 | #include <i18nlangtag/mslangid.hxx> | |||
28 | #include <editeng/numitem.hxx> | |||
29 | #include <svl/eitem.hxx> | |||
30 | #include <vcl/svapp.hxx> | |||
31 | #include <svx/colorbox.hxx> | |||
32 | #include <svx/strarray.hxx> | |||
33 | #include <svx/gallery.hxx> | |||
34 | #include <editeng/brushitem.hxx> | |||
35 | #include <svl/intitem.hxx> | |||
36 | #include <sfx2/objsh.hxx> | |||
37 | #include <vcl/graph.hxx> | |||
38 | #include <vcl/settings.hxx> | |||
39 | #include <cui/cuicharmap.hxx> | |||
40 | #include <editeng/flstitem.hxx> | |||
41 | #include <svx/numvset.hxx> | |||
42 | #include <sfx2/htmlmode.hxx> | |||
43 | #include <unotools/pathoptions.hxx> | |||
44 | #include <svtools/ctrltool.hxx> | |||
45 | #include <svtools/unitconv.hxx> | |||
46 | #include <com/sun/star/style/NumberingType.hpp> | |||
47 | #include <com/sun/star/lang/XMultiServiceFactory.hpp> | |||
48 | #include <com/sun/star/container/XIndexAccess.hpp> | |||
49 | #include <com/sun/star/text/XDefaultNumberingProvider.hpp> | |||
50 | #include <com/sun/star/text/XNumberingFormatter.hpp> | |||
51 | #include <com/sun/star/beans/PropertyValue.hpp> | |||
52 | #include <comphelper/processfactory.hxx> | |||
53 | #include <svx/svxids.hrc> | |||
54 | ||||
55 | #include <algorithm> | |||
56 | #include <memory> | |||
57 | #include <vector> | |||
58 | #include <sfx2/opengrf.hxx> | |||
59 | ||||
60 | #include <strings.hrc> | |||
61 | #include <svl/stritem.hxx> | |||
62 | #include <svl/slstitm.hxx> | |||
63 | #include <sfx2/filedlghelper.hxx> | |||
64 | #include <unotools/ucbstreamhelper.hxx> | |||
65 | #include <com/sun/star/ucb/SimpleFileAccess.hpp> | |||
66 | #include <sal/log.hxx> | |||
67 | #include <vcl/cvtgrf.hxx> | |||
68 | #include <vcl/graphicfilter.hxx> | |||
69 | #include <svx/SvxNumOptionsTabPageHelper.hxx> | |||
70 | #include <tools/urlobj.hxx> | |||
71 | #include <osl/diagnose.h> | |||
72 | ||||
73 | using namespace css; | |||
74 | using namespace css::uno; | |||
75 | using namespace css::beans; | |||
76 | using namespace css::lang; | |||
77 | using namespace css::text; | |||
78 | using namespace css::container; | |||
79 | using namespace css::style; | |||
80 | ||||
81 | #define SHOW_NUMBERING0 0 | |||
82 | #define SHOW_BULLET1 1 | |||
83 | #define SHOW_BITMAP2 2 | |||
84 | ||||
85 | #define MAX_BMP_WIDTH16 16 | |||
86 | #define MAX_BMP_HEIGHT16 16 | |||
87 | #define SEARCHPATH_DELIMITERu';' u';' | |||
88 | #define SEARCHFILENAME_DELIMITERu'/' u'/' | |||
89 | ||||
90 | static bool bLastRelative = false; | |||
91 | ||||
92 | static SvxNumSettings_Impl* lcl_CreateNumSettingsPtr(const Sequence<PropertyValue>& rLevelProps) | |||
93 | { | |||
94 | const PropertyValue* pValues = rLevelProps.getConstArray(); | |||
95 | SvxNumSettings_Impl* pNew = new SvxNumSettings_Impl; | |||
96 | for(sal_Int32 j = 0; j < rLevelProps.getLength(); j++) | |||
97 | { | |||
98 | if ( pValues[j].Name == "NumberingType" ) | |||
99 | { | |||
100 | sal_Int16 nTmp; | |||
101 | if (pValues[j].Value >>= nTmp) | |||
102 | pNew->nNumberType = static_cast<SvxNumType>(nTmp); | |||
103 | } | |||
104 | else if ( pValues[j].Name == "Prefix" ) | |||
105 | pValues[j].Value >>= pNew->sPrefix; | |||
106 | else if ( pValues[j].Name == "Suffix" ) | |||
107 | pValues[j].Value >>= pNew->sSuffix; | |||
108 | else if ( pValues[j].Name == "ParentNumbering" ) | |||
109 | pValues[j].Value >>= pNew->nParentNumbering; | |||
110 | else if ( pValues[j].Name == "BulletChar" ) | |||
111 | pValues[j].Value >>= pNew->sBulletChar; | |||
112 | else if ( pValues[j].Name == "BulletFontName" ) | |||
113 | pValues[j].Value >>= pNew->sBulletFont; | |||
114 | } | |||
115 | return pNew; | |||
116 | } | |||
117 | ||||
118 | // the selection of bullets from the OpenSymbol | |||
119 | const sal_Unicode aBulletTypes[] = | |||
120 | { | |||
121 | 0x2022, | |||
122 | 0x25cf, | |||
123 | 0xe00c, | |||
124 | 0xe00a, | |||
125 | 0x2794, | |||
126 | 0x27a2, | |||
127 | 0x2717, | |||
128 | 0x2714 | |||
129 | }; | |||
130 | ||||
131 | // Is one of the masked formats set? | |||
132 | static bool lcl_IsNumFmtSet(SvxNumRule const * pNum, sal_uInt16 nLevelMask) | |||
133 | { | |||
134 | bool bRet = false; | |||
135 | sal_uInt16 nMask = 1; | |||
136 | for( sal_uInt16 i = 0; i < SVX_MAX_NUM10 && !bRet; i++ ) | |||
137 | { | |||
138 | if(nLevelMask & nMask) | |||
139 | bRet |= nullptr != pNum->Get( i ); | |||
140 | nMask <<= 1 ; | |||
141 | } | |||
142 | return bRet; | |||
143 | } | |||
144 | ||||
145 | static const vcl::Font& lcl_GetDefaultBulletFont() | |||
146 | { | |||
147 | static vcl::Font aDefBulletFont = [&]() | |||
148 | { | |||
149 | vcl::Font tmp("OpenSymbol", "", Size(0, 14)); | |||
150 | tmp.SetCharSet( RTL_TEXTENCODING_SYMBOL(((rtl_TextEncoding) 10)) ); | |||
151 | tmp.SetFamily( FAMILY_DONTKNOW ); | |||
152 | tmp.SetPitch( PITCH_DONTKNOW ); | |||
153 | tmp.SetWeight( WEIGHT_DONTKNOW ); | |||
154 | tmp.SetTransparent( true ); | |||
155 | return tmp; | |||
156 | }(); | |||
157 | return aDefBulletFont; | |||
158 | } | |||
159 | ||||
160 | SvxSingleNumPickTabPage::SvxSingleNumPickTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) | |||
161 | : SfxTabPage(pPage, pController, "cui/ui/picknumberingpage.ui", "PickNumberingPage", &rSet) | |||
162 | , nActNumLvl(SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
163 | , bModified(false) | |||
164 | , bPreset(false) | |||
165 | , nNumItemId(SID_ATTR_NUMBERING_RULE( 10000 + 855 )) | |||
166 | , m_xExamplesVS(new SvxNumValueSet(nullptr)) | |||
167 | , m_xExamplesVSWin(new weld::CustomWeld(*m_xBuilder, "valueset", *m_xExamplesVS)) | |||
168 | { | |||
169 | SetExchangeSupport(); | |||
170 | m_xExamplesVS->init(NumberingPageType::SINGLENUM); | |||
171 | m_xExamplesVS->SetSelectHdl(LINK(this, SvxSingleNumPickTabPage, NumSelectHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxSingleNumPickTabPage *>(this), &SvxSingleNumPickTabPage::LinkStubNumSelectHdl_Impl )); | |||
172 | m_xExamplesVS->SetDoubleClickHdl(LINK(this, SvxSingleNumPickTabPage, DoubleClickHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxSingleNumPickTabPage *>(this), &SvxSingleNumPickTabPage::LinkStubDoubleClickHdl_Impl )); | |||
173 | ||||
174 | Reference<XDefaultNumberingProvider> xDefNum = SvxNumOptionsTabPageHelper::GetNumberingProvider(); | |||
175 | if(!xDefNum.is()) | |||
176 | return; | |||
177 | ||||
178 | Sequence< Sequence< PropertyValue > > aNumberings; | |||
179 | const Locale& rLocale = Application::GetSettings().GetLanguageTag().getLocale(); | |||
180 | try | |||
181 | { | |||
182 | aNumberings = | |||
183 | xDefNum->getDefaultContinuousNumberingLevels( rLocale ); | |||
184 | ||||
185 | ||||
186 | sal_Int32 nLength = std::min<sal_Int32>(aNumberings.getLength(), NUM_VALUSET_COUNT16); | |||
187 | ||||
188 | const Sequence<PropertyValue>* pValuesArr = aNumberings.getConstArray(); | |||
189 | for(sal_Int32 i = 0; i < nLength; i++) | |||
190 | { | |||
191 | SvxNumSettings_Impl* pNew = lcl_CreateNumSettingsPtr(pValuesArr[i]); | |||
192 | aNumSettingsArr.push_back(std::unique_ptr<SvxNumSettings_Impl>(pNew)); | |||
193 | } | |||
194 | } | |||
195 | catch(const Exception&) | |||
196 | { | |||
197 | } | |||
198 | Reference<XNumberingFormatter> xFormat(xDefNum, UNO_QUERY); | |||
199 | m_xExamplesVS->SetNumberingSettings(aNumberings, xFormat, rLocale); | |||
200 | } | |||
201 | ||||
202 | SvxSingleNumPickTabPage::~SvxSingleNumPickTabPage() | |||
203 | { | |||
204 | m_xExamplesVSWin.reset(); | |||
205 | m_xExamplesVS.reset(); | |||
206 | } | |||
207 | ||||
208 | std::unique_ptr<SfxTabPage> SvxSingleNumPickTabPage::Create(weld::Container* pPage, weld::DialogController* pController, | |||
209 | const SfxItemSet* rAttrSet) | |||
210 | { | |||
211 | return std::make_unique<SvxSingleNumPickTabPage>(pPage, pController, *rAttrSet); | |||
212 | } | |||
213 | ||||
214 | bool SvxSingleNumPickTabPage::FillItemSet( SfxItemSet* rSet ) | |||
215 | { | |||
216 | if( (bPreset || bModified) && pSaveNum) | |||
217 | { | |||
218 | *pSaveNum = *pActNum; | |||
219 | rSet->Put(SvxNumBulletItem( *pSaveNum, nNumItemId )); | |||
220 | rSet->Put(SfxBoolItem(SID_PARAM_NUM_PRESET( 10000 + 856 ), bPreset)); | |||
221 | } | |||
222 | ||||
223 | return bModified; | |||
224 | } | |||
225 | ||||
226 | void SvxSingleNumPickTabPage::ActivatePage(const SfxItemSet& rSet) | |||
227 | { | |||
228 | const SfxPoolItem* pItem; | |||
229 | bPreset = false; | |||
230 | bool bIsPreset = false; | |||
231 | const SfxItemSet* pExampleSet = GetDialogExampleSet(); | |||
232 | if(pExampleSet) | |||
233 | { | |||
234 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_NUM_PRESET( 10000 + 856 ), false, &pItem)) | |||
235 | bIsPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
236 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 ), false, &pItem)) | |||
237 | nActNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
238 | } | |||
239 | if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem)) | |||
240 | { | |||
241 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
242 | } | |||
243 | if(pActNum && *pSaveNum != *pActNum) | |||
244 | { | |||
245 | *pActNum = *pSaveNum; | |||
246 | m_xExamplesVS->SetNoSelection(); | |||
247 | } | |||
248 | ||||
249 | if(pActNum && (!lcl_IsNumFmtSet(pActNum.get(), nActNumLvl) || bIsPreset)) | |||
250 | { | |||
251 | m_xExamplesVS->SelectItem(1); | |||
252 | NumSelectHdl_Impl(m_xExamplesVS.get()); | |||
253 | bPreset = true; | |||
254 | } | |||
255 | bPreset |= bIsPreset; | |||
256 | ||||
257 | bModified = false; | |||
258 | } | |||
259 | ||||
260 | DeactivateRC SvxSingleNumPickTabPage::DeactivatePage(SfxItemSet *_pSet) | |||
261 | { | |||
262 | if(_pSet) | |||
263 | FillItemSet(_pSet); | |||
264 | return DeactivateRC::LeavePage; | |||
265 | } | |||
266 | ||||
267 | void SvxSingleNumPickTabPage::Reset( const SfxItemSet* rSet ) | |||
268 | { | |||
269 | const SfxPoolItem* pItem; | |||
270 | ||||
271 | // in Draw the item exists as WhichId, in Writer only as SlotId | |||
272 | SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE( 10000 + 855 ), false, &pItem); | |||
273 | if(eState != SfxItemState::SET) | |||
274 | { | |||
275 | nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 )); | |||
276 | eState = rSet->GetItemState(nNumItemId, false, &pItem); | |||
277 | ||||
278 | if( eState != SfxItemState::SET ) | |||
279 | { | |||
280 | pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( nNumItemId ) ); | |||
281 | eState = SfxItemState::SET; | |||
282 | } | |||
283 | } | |||
284 | DBG_ASSERT(eState == SfxItemState::SET, "no item found!")do { if (true && (!(eState == SfxItemState::SET))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "284" ": "), "%s", "no item found!"); } } while (false); | |||
285 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
286 | ||||
287 | if(!pActNum) | |||
288 | pActNum.reset( new SvxNumRule(*pSaveNum) ); | |||
289 | else if(*pSaveNum != *pActNum) | |||
290 | *pActNum = *pSaveNum; | |||
291 | } | |||
292 | ||||
293 | IMPL_LINK_NOARG(SvxSingleNumPickTabPage, NumSelectHdl_Impl, ValueSet*, void)void SvxSingleNumPickTabPage::LinkStubNumSelectHdl_Impl(void * instance, ValueSet* data) { return static_cast<SvxSingleNumPickTabPage *>(instance)->NumSelectHdl_Impl(data); } void SvxSingleNumPickTabPage ::NumSelectHdl_Impl(__attribute__ ((unused)) ValueSet*) | |||
294 | { | |||
295 | if(!pActNum) | |||
296 | return; | |||
297 | ||||
298 | bPreset = false; | |||
299 | bModified = true; | |||
300 | sal_uInt16 nIdx = m_xExamplesVS->GetSelectedItemId() - 1; | |||
301 | DBG_ASSERT(aNumSettingsArr.size() > nIdx, "wrong index")do { if (true && (!(aNumSettingsArr.size() > nIdx) )) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "301" ": "), "%s", "wrong index"); } } while (false); | |||
302 | if(aNumSettingsArr.size() <= nIdx) | |||
303 | return; | |||
304 | SvxNumSettings_Impl* _pSet = aNumSettingsArr[nIdx].get(); | |||
305 | SvxNumType eNewType = _pSet->nNumberType; | |||
306 | const sal_Unicode cLocalPrefix = !_pSet->sPrefix.isEmpty() ? _pSet->sPrefix[0] : 0; | |||
307 | const sal_Unicode cLocalSuffix = !_pSet->sSuffix.isEmpty() ? _pSet->sSuffix[0] : 0; | |||
308 | ||||
309 | sal_uInt16 nMask = 1; | |||
310 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
311 | { | |||
312 | if(nActNumLvl & nMask) | |||
313 | { | |||
314 | SvxNumberFormat aFmt(pActNum->GetLevel(i)); | |||
315 | aFmt.SetNumberingType(eNewType); | |||
316 | if(cLocalPrefix == ' ') | |||
317 | aFmt.SetPrefix( "" ); | |||
318 | else | |||
319 | aFmt.SetPrefix(_pSet->sPrefix); | |||
320 | if(cLocalSuffix == ' ') | |||
321 | aFmt.SetSuffix( "" ); | |||
322 | else | |||
323 | aFmt.SetSuffix(_pSet->sSuffix); | |||
324 | aFmt.SetCharFormatName(""); | |||
325 | aFmt.SetBulletRelSize(100); | |||
326 | pActNum->SetLevel(i, aFmt); | |||
327 | } | |||
328 | nMask <<= 1; | |||
329 | } | |||
330 | } | |||
331 | ||||
332 | IMPL_LINK_NOARG(SvxSingleNumPickTabPage, DoubleClickHdl_Impl, ValueSet*, void)void SvxSingleNumPickTabPage::LinkStubDoubleClickHdl_Impl(void * instance, ValueSet* data) { return static_cast<SvxSingleNumPickTabPage *>(instance)->DoubleClickHdl_Impl(data); } void SvxSingleNumPickTabPage ::DoubleClickHdl_Impl(__attribute__ ((unused)) ValueSet*) | |||
333 | { | |||
334 | NumSelectHdl_Impl(m_xExamplesVS.get()); | |||
335 | weld::Button& rOk = GetDialogController()->GetOKButton(); | |||
336 | rOk.clicked(); | |||
337 | } | |||
338 | ||||
339 | SvxBulletPickTabPage::SvxBulletPickTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) | |||
340 | : SfxTabPage(pPage, pController, "cui/ui/pickbulletpage.ui", "PickBulletPage", &rSet) | |||
341 | , nActNumLvl(SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
342 | , bModified(false) | |||
343 | , bPreset(false) | |||
344 | , nNumItemId(SID_ATTR_NUMBERING_RULE( 10000 + 855 )) | |||
345 | , m_xExamplesVS(new SvxNumValueSet(nullptr)) | |||
346 | , m_xExamplesVSWin(new weld::CustomWeld(*m_xBuilder, "valueset", *m_xExamplesVS)) | |||
347 | { | |||
348 | SetExchangeSupport(); | |||
349 | m_xExamplesVS->init(NumberingPageType::BULLET); | |||
350 | m_xExamplesVS->SetSelectHdl(LINK(this, SvxBulletPickTabPage, NumSelectHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxBulletPickTabPage *>(this), &SvxBulletPickTabPage::LinkStubNumSelectHdl_Impl )); | |||
351 | m_xExamplesVS->SetDoubleClickHdl(LINK(this, SvxBulletPickTabPage, DoubleClickHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxBulletPickTabPage *>(this), &SvxBulletPickTabPage::LinkStubDoubleClickHdl_Impl )); | |||
352 | } | |||
353 | ||||
354 | SvxBulletPickTabPage::~SvxBulletPickTabPage() | |||
355 | { | |||
356 | m_xExamplesVSWin.reset(); | |||
357 | m_xExamplesVS.reset(); | |||
358 | } | |||
359 | ||||
360 | std::unique_ptr<SfxTabPage> SvxBulletPickTabPage::Create(weld::Container* pPage, weld::DialogController* pController, | |||
361 | const SfxItemSet* rAttrSet) | |||
362 | { | |||
363 | return std::make_unique<SvxBulletPickTabPage>(pPage, pController, *rAttrSet); | |||
364 | } | |||
365 | ||||
366 | bool SvxBulletPickTabPage::FillItemSet( SfxItemSet* rSet ) | |||
367 | { | |||
368 | if( (bPreset || bModified) && pActNum) | |||
369 | { | |||
370 | *pSaveNum = *pActNum; | |||
371 | rSet->Put(SvxNumBulletItem( *pSaveNum, nNumItemId )); | |||
372 | rSet->Put(SfxBoolItem(SID_PARAM_NUM_PRESET( 10000 + 856 ), bPreset)); | |||
373 | } | |||
374 | return bModified; | |||
375 | } | |||
376 | ||||
377 | void SvxBulletPickTabPage::ActivatePage(const SfxItemSet& rSet) | |||
378 | { | |||
379 | const SfxPoolItem* pItem; | |||
380 | bPreset = false; | |||
381 | bool bIsPreset = false; | |||
382 | const SfxItemSet* pExampleSet = GetDialogExampleSet(); | |||
383 | if(pExampleSet) | |||
384 | { | |||
385 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_NUM_PRESET( 10000 + 856 ), false, &pItem)) | |||
386 | bIsPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
387 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 ), false, &pItem)) | |||
388 | nActNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
389 | } | |||
390 | if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem)) | |||
391 | { | |||
392 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
393 | } | |||
394 | if(pActNum && *pSaveNum != *pActNum) | |||
395 | { | |||
396 | *pActNum = *pSaveNum; | |||
397 | m_xExamplesVS->SetNoSelection(); | |||
398 | } | |||
399 | ||||
400 | if(pActNum && (!lcl_IsNumFmtSet(pActNum.get(), nActNumLvl) || bIsPreset)) | |||
401 | { | |||
402 | m_xExamplesVS->SelectItem(1); | |||
403 | NumSelectHdl_Impl(m_xExamplesVS.get()); | |||
404 | bPreset = true; | |||
405 | } | |||
406 | bPreset |= bIsPreset; | |||
407 | bModified = false; | |||
408 | } | |||
409 | ||||
410 | DeactivateRC SvxBulletPickTabPage::DeactivatePage(SfxItemSet *_pSet) | |||
411 | { | |||
412 | if(_pSet) | |||
413 | FillItemSet(_pSet); | |||
414 | return DeactivateRC::LeavePage; | |||
415 | } | |||
416 | ||||
417 | void SvxBulletPickTabPage::Reset( const SfxItemSet* rSet ) | |||
418 | { | |||
419 | const SfxPoolItem* pItem; | |||
420 | // in Draw the item exists as WhichId, in Writer only as SlotId | |||
421 | SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE( 10000 + 855 ), false, &pItem); | |||
422 | if(eState != SfxItemState::SET) | |||
423 | { | |||
424 | nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 )); | |||
425 | eState = rSet->GetItemState(nNumItemId, false, &pItem); | |||
426 | ||||
427 | if( eState != SfxItemState::SET ) | |||
428 | { | |||
429 | pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( nNumItemId ) ); | |||
430 | eState = SfxItemState::SET; | |||
431 | } | |||
432 | ||||
433 | } | |||
434 | DBG_ASSERT(eState == SfxItemState::SET, "no item found!")do { if (true && (!(eState == SfxItemState::SET))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "434" ": "), "%s", "no item found!"); } } while (false); | |||
435 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
436 | ||||
437 | if(!pActNum) | |||
438 | pActNum.reset( new SvxNumRule(*pSaveNum) ); | |||
439 | else if(*pSaveNum != *pActNum) | |||
440 | *pActNum = *pSaveNum; | |||
441 | } | |||
442 | ||||
443 | IMPL_LINK_NOARG(SvxBulletPickTabPage, NumSelectHdl_Impl, ValueSet*, void)void SvxBulletPickTabPage::LinkStubNumSelectHdl_Impl(void * instance , ValueSet* data) { return static_cast<SvxBulletPickTabPage *>(instance)->NumSelectHdl_Impl(data); } void SvxBulletPickTabPage ::NumSelectHdl_Impl(__attribute__ ((unused)) ValueSet*) | |||
444 | { | |||
445 | if(!pActNum) | |||
446 | return; | |||
447 | ||||
448 | bPreset = false; | |||
449 | bModified = true; | |||
450 | sal_Unicode cChar = aBulletTypes[m_xExamplesVS->GetSelectedItemId() - 1]; | |||
451 | const vcl::Font& rActBulletFont = lcl_GetDefaultBulletFont(); | |||
452 | ||||
453 | sal_uInt16 nMask = 1; | |||
454 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
455 | { | |||
456 | if(nActNumLvl & nMask) | |||
457 | { | |||
458 | SvxNumberFormat aFmt(pActNum->GetLevel(i)); | |||
459 | aFmt.SetNumberingType( SVX_NUM_CHAR_SPECIAL ); | |||
460 | // #i93908# clear suffix for bullet lists | |||
461 | aFmt.SetPrefix( OUString() ); | |||
462 | aFmt.SetSuffix( OUString() ); | |||
463 | aFmt.SetBulletFont(&rActBulletFont); | |||
464 | aFmt.SetBulletChar(cChar ); | |||
465 | aFmt.SetCharFormatName(sBulletCharFormatName); | |||
466 | aFmt.SetBulletRelSize(45); | |||
467 | pActNum->SetLevel(i, aFmt); | |||
468 | } | |||
469 | nMask <<= 1; | |||
470 | } | |||
471 | } | |||
472 | ||||
473 | IMPL_LINK_NOARG(SvxBulletPickTabPage, DoubleClickHdl_Impl, ValueSet*, void)void SvxBulletPickTabPage::LinkStubDoubleClickHdl_Impl(void * instance, ValueSet* data) { return static_cast<SvxBulletPickTabPage *>(instance)->DoubleClickHdl_Impl(data); } void SvxBulletPickTabPage ::DoubleClickHdl_Impl(__attribute__ ((unused)) ValueSet*) | |||
474 | { | |||
475 | NumSelectHdl_Impl(m_xExamplesVS.get()); | |||
476 | weld::Button& rOk = GetDialogController()->GetOKButton(); | |||
477 | rOk.clicked(); | |||
478 | } | |||
479 | ||||
480 | void SvxBulletPickTabPage::PageCreated(const SfxAllItemSet& aSet) | |||
481 | { | |||
482 | const SfxStringItem* pBulletCharFmt = aSet.GetItem<SfxStringItem>(SID_BULLET_CHAR_FMT( 10000 + 1026 ), false); | |||
483 | ||||
484 | if (pBulletCharFmt) | |||
485 | sBulletCharFormatName = pBulletCharFmt->GetValue(); | |||
486 | } | |||
487 | ||||
488 | SvxNumPickTabPage::SvxNumPickTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) | |||
489 | : SfxTabPage(pPage, pController, "cui/ui/pickoutlinepage.ui", "PickOutlinePage", &rSet) | |||
490 | , nActNumLvl(SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
491 | , nNumItemId(SID_ATTR_NUMBERING_RULE( 10000 + 855 )) | |||
492 | , bModified(false) | |||
493 | , bPreset(false) | |||
494 | , m_xExamplesVS(new SvxNumValueSet(nullptr)) | |||
495 | , m_xExamplesVSWin(new weld::CustomWeld(*m_xBuilder, "valueset", *m_xExamplesVS)) | |||
496 | { | |||
497 | SetExchangeSupport(); | |||
498 | ||||
499 | m_xExamplesVS->init(NumberingPageType::OUTLINE); | |||
500 | m_xExamplesVS->SetSelectHdl(LINK(this, SvxNumPickTabPage, NumSelectHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPickTabPage *>(this), &SvxNumPickTabPage::LinkStubNumSelectHdl_Impl )); | |||
501 | m_xExamplesVS->SetDoubleClickHdl(LINK(this, SvxNumPickTabPage, DoubleClickHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPickTabPage *>(this), &SvxNumPickTabPage::LinkStubDoubleClickHdl_Impl )); | |||
502 | ||||
503 | Reference<XDefaultNumberingProvider> xDefNum = SvxNumOptionsTabPageHelper::GetNumberingProvider(); | |||
504 | if(!xDefNum.is()) | |||
505 | return; | |||
506 | ||||
507 | Sequence<Reference<XIndexAccess> > aOutlineAccess; | |||
508 | const Locale& rLocale = Application::GetSettings().GetLanguageTag().getLocale(); | |||
509 | try | |||
510 | { | |||
511 | aOutlineAccess = xDefNum->getDefaultOutlineNumberings( rLocale ); | |||
512 | ||||
513 | for(sal_Int32 nItem = 0; | |||
514 | nItem < aOutlineAccess.getLength() && nItem < NUM_VALUSET_COUNT16; | |||
515 | nItem++ ) | |||
516 | { | |||
517 | SvxNumSettingsArr_Impl& rItemArr = aNumSettingsArrays[ nItem ]; | |||
518 | ||||
519 | Reference<XIndexAccess> xLevel = aOutlineAccess.getConstArray()[nItem]; | |||
520 | for(sal_Int32 nLevel = 0; nLevel < xLevel->getCount() && nLevel < 5; nLevel++) | |||
521 | { | |||
522 | Any aValueAny = xLevel->getByIndex(nLevel); | |||
523 | Sequence<PropertyValue> aLevelProps; | |||
524 | aValueAny >>= aLevelProps; | |||
525 | SvxNumSettings_Impl* pNew = lcl_CreateNumSettingsPtr(aLevelProps); | |||
526 | rItemArr.push_back( std::unique_ptr<SvxNumSettings_Impl>(pNew) ); | |||
527 | } | |||
528 | } | |||
529 | } | |||
530 | catch(const Exception&) | |||
531 | { | |||
532 | } | |||
533 | Reference<XNumberingFormatter> xFormat(xDefNum, UNO_QUERY); | |||
534 | m_xExamplesVS->SetOutlineNumberingSettings(aOutlineAccess, xFormat, rLocale); | |||
535 | } | |||
536 | ||||
537 | SvxNumPickTabPage::~SvxNumPickTabPage() | |||
538 | { | |||
539 | m_xExamplesVSWin.reset(); | |||
540 | m_xExamplesVS.reset(); | |||
541 | } | |||
542 | ||||
543 | std::unique_ptr<SfxTabPage> SvxNumPickTabPage::Create(weld::Container* pPage, weld::DialogController* pController, | |||
544 | const SfxItemSet* rAttrSet) | |||
545 | { | |||
546 | return std::make_unique<SvxNumPickTabPage>(pPage, pController, *rAttrSet); | |||
547 | } | |||
548 | ||||
549 | bool SvxNumPickTabPage::FillItemSet( SfxItemSet* rSet ) | |||
550 | { | |||
551 | if( (bPreset || bModified) && pActNum) | |||
552 | { | |||
553 | *pSaveNum = *pActNum; | |||
554 | rSet->Put(SvxNumBulletItem( *pSaveNum, nNumItemId )); | |||
555 | rSet->Put(SfxBoolItem(SID_PARAM_NUM_PRESET( 10000 + 856 ), bPreset)); | |||
556 | } | |||
557 | return bModified; | |||
558 | } | |||
559 | ||||
560 | void SvxNumPickTabPage::ActivatePage(const SfxItemSet& rSet) | |||
561 | { | |||
562 | const SfxPoolItem* pItem; | |||
563 | bPreset = false; | |||
564 | bool bIsPreset = false; | |||
565 | const SfxItemSet* pExampleSet = GetDialogExampleSet(); | |||
566 | if(pExampleSet) | |||
567 | { | |||
568 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_NUM_PRESET( 10000 + 856 ), false, &pItem)) | |||
569 | bIsPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
570 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 ), false, &pItem)) | |||
571 | nActNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
572 | } | |||
573 | if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem)) | |||
574 | { | |||
575 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
576 | } | |||
577 | if(pActNum && *pSaveNum != *pActNum) | |||
578 | { | |||
579 | *pActNum = *pSaveNum; | |||
580 | m_xExamplesVS->SetNoSelection(); | |||
581 | } | |||
582 | ||||
583 | if(pActNum && (!lcl_IsNumFmtSet(pActNum.get(), nActNumLvl) || bIsPreset)) | |||
584 | { | |||
585 | m_xExamplesVS->SelectItem(1); | |||
586 | NumSelectHdl_Impl(m_xExamplesVS.get()); | |||
587 | bPreset = true; | |||
588 | } | |||
589 | bPreset |= bIsPreset; | |||
590 | bModified = false; | |||
591 | } | |||
592 | ||||
593 | DeactivateRC SvxNumPickTabPage::DeactivatePage(SfxItemSet *_pSet) | |||
594 | { | |||
595 | if(_pSet) | |||
596 | FillItemSet(_pSet); | |||
597 | return DeactivateRC::LeavePage; | |||
598 | } | |||
599 | ||||
600 | void SvxNumPickTabPage::Reset( const SfxItemSet* rSet ) | |||
601 | { | |||
602 | const SfxPoolItem* pItem; | |||
603 | // in Draw the item exists as WhichId, in Writer only as SlotId | |||
604 | SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE( 10000 + 855 ), false, &pItem); | |||
605 | if(eState != SfxItemState::SET) | |||
606 | { | |||
607 | nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 )); | |||
608 | eState = rSet->GetItemState(nNumItemId, false, &pItem); | |||
609 | ||||
610 | if( eState != SfxItemState::SET ) | |||
611 | { | |||
612 | pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( nNumItemId ) ); | |||
613 | eState = SfxItemState::SET; | |||
614 | } | |||
615 | ||||
616 | } | |||
617 | DBG_ASSERT(eState == SfxItemState::SET, "no item found!")do { if (true && (!(eState == SfxItemState::SET))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "617" ": "), "%s", "no item found!"); } } while (false); | |||
618 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
619 | ||||
620 | if(!pActNum) | |||
621 | pActNum.reset( new SvxNumRule(*pSaveNum) ); | |||
622 | else if(*pSaveNum != *pActNum) | |||
623 | *pActNum = *pSaveNum; | |||
624 | ||||
625 | } | |||
626 | ||||
627 | // all levels are changed here | |||
628 | IMPL_LINK_NOARG(SvxNumPickTabPage, NumSelectHdl_Impl, ValueSet*, void)void SvxNumPickTabPage::LinkStubNumSelectHdl_Impl(void * instance , ValueSet* data) { return static_cast<SvxNumPickTabPage * >(instance)->NumSelectHdl_Impl(data); } void SvxNumPickTabPage ::NumSelectHdl_Impl(__attribute__ ((unused)) ValueSet*) | |||
629 | { | |||
630 | if(!pActNum) | |||
631 | return; | |||
632 | ||||
633 | bPreset = false; | |||
634 | bModified = true; | |||
635 | ||||
636 | const FontList* pList = nullptr; | |||
637 | ||||
638 | SvxNumSettingsArr_Impl& rItemArr = aNumSettingsArrays[m_xExamplesVS->GetSelectedItemId() - 1]; | |||
639 | ||||
640 | const vcl::Font& rActBulletFont = lcl_GetDefaultBulletFont(); | |||
641 | SvxNumSettings_Impl* pLevelSettings = nullptr; | |||
642 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
643 | { | |||
644 | if(rItemArr.size() > i) | |||
645 | pLevelSettings = rItemArr[i].get(); | |||
646 | if(!pLevelSettings) | |||
647 | break; | |||
648 | SvxNumberFormat aFmt(pActNum->GetLevel(i)); | |||
649 | aFmt.SetNumberingType( pLevelSettings->nNumberType ); | |||
650 | sal_uInt16 nUpperLevelOrChar = static_cast<sal_uInt16>(pLevelSettings->nParentNumbering); | |||
651 | if(aFmt.GetNumberingType() == SVX_NUM_CHAR_SPECIAL) | |||
652 | { | |||
653 | // #i93908# clear suffix for bullet lists | |||
654 | aFmt.SetPrefix(OUString()); | |||
655 | aFmt.SetSuffix(OUString()); | |||
656 | if( !pLevelSettings->sBulletFont.isEmpty() && | |||
657 | pLevelSettings->sBulletFont != rActBulletFont.GetFamilyName()) | |||
658 | { | |||
659 | //search for the font | |||
660 | if(!pList) | |||
661 | { | |||
662 | SfxObjectShell* pCurDocShell = SfxObjectShell::Current(); | |||
663 | const SvxFontListItem* pFontListItem = | |||
664 | static_cast<const SvxFontListItem*>( pCurDocShell | |||
665 | ->GetItem( SID_ATTR_CHAR_FONTLIST( 10000 + 22 ) )); | |||
666 | pList = pFontListItem ? pFontListItem->GetFontList() : nullptr; | |||
667 | } | |||
668 | if(pList && pList->IsAvailable( pLevelSettings->sBulletFont ) ) | |||
669 | { | |||
670 | FontMetric aFontMetric = pList->Get( | |||
671 | pLevelSettings->sBulletFont,WEIGHT_NORMAL, ITALIC_NONE); | |||
672 | vcl::Font aFont(aFontMetric); | |||
673 | aFmt.SetBulletFont(&aFont); | |||
674 | } | |||
675 | else | |||
676 | { | |||
677 | //if it cannot be found then create a new one | |||
678 | vcl::Font aCreateFont( pLevelSettings->sBulletFont, | |||
679 | OUString(), Size( 0, 14 ) ); | |||
680 | aCreateFont.SetCharSet( RTL_TEXTENCODING_DONTKNOW(((rtl_TextEncoding) 0)) ); | |||
681 | aCreateFont.SetFamily( FAMILY_DONTKNOW ); | |||
682 | aCreateFont.SetPitch( PITCH_DONTKNOW ); | |||
683 | aCreateFont.SetWeight( WEIGHT_DONTKNOW ); | |||
684 | aCreateFont.SetTransparent( true ); | |||
685 | aFmt.SetBulletFont( &aCreateFont ); | |||
686 | } | |||
687 | } | |||
688 | else | |||
689 | aFmt.SetBulletFont( &rActBulletFont ); | |||
690 | ||||
691 | sal_Int32 nIndexUtf16 = 0; | |||
692 | aFmt.SetBulletChar( !pLevelSettings->sBulletChar.isEmpty() | |||
693 | ? pLevelSettings->sBulletChar.iterateCodePoints(&nIndexUtf16) | |||
694 | : 0 ); | |||
695 | aFmt.SetCharFormatName( sBulletCharFormatName ); | |||
696 | aFmt.SetBulletRelSize(45); | |||
697 | } | |||
698 | else | |||
699 | { | |||
700 | aFmt.SetIncludeUpperLevels(sal::static_int_cast< sal_uInt8 >(0 != nUpperLevelOrChar ? pActNum->GetLevelCount() : 0)); | |||
701 | aFmt.SetCharFormatName(sNumCharFmtName); | |||
702 | aFmt.SetBulletRelSize(100); | |||
703 | // #i93908# | |||
704 | aFmt.SetPrefix(pLevelSettings->sPrefix); | |||
705 | aFmt.SetSuffix(pLevelSettings->sSuffix); | |||
706 | } | |||
707 | pActNum->SetLevel(i, aFmt); | |||
708 | } | |||
709 | } | |||
710 | ||||
711 | IMPL_LINK_NOARG(SvxNumPickTabPage, DoubleClickHdl_Impl, ValueSet*, void)void SvxNumPickTabPage::LinkStubDoubleClickHdl_Impl(void * instance , ValueSet* data) { return static_cast<SvxNumPickTabPage * >(instance)->DoubleClickHdl_Impl(data); } void SvxNumPickTabPage ::DoubleClickHdl_Impl(__attribute__ ((unused)) ValueSet*) | |||
712 | { | |||
713 | NumSelectHdl_Impl(m_xExamplesVS.get()); | |||
714 | weld::Button& rOk = GetDialogController()->GetOKButton(); | |||
715 | rOk.clicked(); | |||
716 | } | |||
717 | ||||
718 | void SvxNumPickTabPage::PageCreated(const SfxAllItemSet& aSet) | |||
719 | { | |||
720 | const SfxStringItem* pNumCharFmt = aSet.GetItem<SfxStringItem>(SID_NUM_CHAR_FMT( 10000 + 1025 ), false); | |||
721 | const SfxStringItem* pBulletCharFmt = aSet.GetItem<SfxStringItem>(SID_BULLET_CHAR_FMT( 10000 + 1026 ), false); | |||
722 | ||||
723 | ||||
724 | if (pNumCharFmt &&pBulletCharFmt) | |||
725 | SetCharFormatNames( pNumCharFmt->GetValue(),pBulletCharFmt->GetValue()); | |||
726 | } | |||
727 | ||||
728 | SvxBitmapPickTabPage::SvxBitmapPickTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) | |||
729 | : SfxTabPage(pPage, pController, "cui/ui/pickgraphicpage.ui", "PickGraphicPage", &rSet) | |||
730 | , nActNumLvl(SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
731 | , nNumItemId(SID_ATTR_NUMBERING_RULE( 10000 + 855 )) | |||
732 | , bModified(false) | |||
733 | , bPreset(false) | |||
734 | , m_xErrorText(m_xBuilder->weld_label("errorft")) | |||
735 | , m_xBtBrowseFile(m_xBuilder->weld_button("browseBtn")) | |||
736 | , m_xExamplesVS(new SvxBmpNumValueSet(m_xBuilder->weld_scrolled_window("valuesetwin", true))) | |||
737 | , m_xExamplesVSWin(new weld::CustomWeld(*m_xBuilder, "valueset", *m_xExamplesVS)) | |||
738 | { | |||
739 | SetExchangeSupport(); | |||
740 | ||||
741 | m_xExamplesVS->init(); | |||
742 | m_xExamplesVS->SetSelectHdl(LINK(this, SvxBitmapPickTabPage, NumSelectHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxBitmapPickTabPage *>(this), &SvxBitmapPickTabPage::LinkStubNumSelectHdl_Impl )); | |||
743 | m_xExamplesVS->SetDoubleClickHdl(LINK(this, SvxBitmapPickTabPage, DoubleClickHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxBitmapPickTabPage *>(this), &SvxBitmapPickTabPage::LinkStubDoubleClickHdl_Impl )); | |||
744 | m_xBtBrowseFile->connect_clicked(LINK(this, SvxBitmapPickTabPage, ClickAddBrowseHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxBitmapPickTabPage *>(this), &SvxBitmapPickTabPage::LinkStubClickAddBrowseHdl_Impl )); | |||
745 | ||||
746 | eCoreUnit = rSet.GetPool()->GetMetric(rSet.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 ))); | |||
747 | ||||
748 | // determine graphic name | |||
749 | GalleryExplorer::FillObjList(GALLERY_THEME_BULLETS3, aGrfNames); | |||
750 | ||||
751 | size_t i = 0; | |||
752 | for (auto & grfName : aGrfNames) | |||
753 | { | |||
754 | m_xExamplesVS->InsertItem( i + 1, i); | |||
755 | ||||
756 | INetURLObject aObj(grfName); | |||
757 | if(aObj.GetProtocol() == INetProtocol::File) | |||
758 | grfName = aObj.PathToFileName(); | |||
759 | ||||
760 | m_xExamplesVS->SetItemText( i + 1, grfName ); | |||
761 | ++i; | |||
762 | } | |||
763 | ||||
764 | if(aGrfNames.empty()) | |||
765 | { | |||
766 | m_xErrorText->show(); | |||
767 | } | |||
768 | else | |||
769 | { | |||
770 | m_xExamplesVS->Show(); | |||
771 | m_xExamplesVS->SetFormat(); | |||
772 | m_xExamplesVS->Invalidate(); | |||
773 | } | |||
774 | } | |||
775 | ||||
776 | SvxBitmapPickTabPage::~SvxBitmapPickTabPage() | |||
777 | { | |||
778 | m_xExamplesVSWin.reset(); | |||
779 | m_xExamplesVS.reset(); | |||
780 | } | |||
781 | ||||
782 | std::unique_ptr<SfxTabPage> SvxBitmapPickTabPage::Create(weld::Container* pPage, weld::DialogController* pController, | |||
783 | const SfxItemSet* rAttrSet) | |||
784 | { | |||
785 | return std::make_unique<SvxBitmapPickTabPage>(pPage, pController, *rAttrSet); | |||
786 | } | |||
787 | ||||
788 | void SvxBitmapPickTabPage::ActivatePage(const SfxItemSet& rSet) | |||
789 | { | |||
790 | const SfxPoolItem* pItem; | |||
791 | bPreset = false; | |||
792 | bool bIsPreset = false; | |||
793 | const SfxItemSet* pExampleSet = GetDialogExampleSet(); | |||
794 | if(pExampleSet) | |||
795 | { | |||
796 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_NUM_PRESET( 10000 + 856 ), false, &pItem)) | |||
797 | bIsPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
798 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 ), false, &pItem)) | |||
799 | nActNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
800 | } | |||
801 | if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem)) | |||
802 | { | |||
803 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
804 | } | |||
805 | if(pActNum && *pSaveNum != *pActNum) | |||
806 | { | |||
807 | *pActNum = *pSaveNum; | |||
808 | m_xExamplesVS->SetNoSelection(); | |||
809 | } | |||
810 | ||||
811 | if(!aGrfNames.empty() && | |||
812 | (pActNum && (!lcl_IsNumFmtSet(pActNum.get(), nActNumLvl) || bIsPreset))) | |||
813 | { | |||
814 | m_xExamplesVS->SelectItem(1); | |||
815 | NumSelectHdl_Impl(m_xExamplesVS.get()); | |||
816 | bPreset = true; | |||
817 | } | |||
818 | bPreset |= bIsPreset; | |||
819 | bModified = false; | |||
820 | } | |||
821 | ||||
822 | DeactivateRC SvxBitmapPickTabPage::DeactivatePage(SfxItemSet *_pSet) | |||
823 | { | |||
824 | if(_pSet) | |||
825 | FillItemSet(_pSet); | |||
826 | return DeactivateRC::LeavePage; | |||
827 | } | |||
828 | ||||
829 | bool SvxBitmapPickTabPage::FillItemSet( SfxItemSet* rSet ) | |||
830 | { | |||
831 | if ( aGrfNames.empty() ) | |||
832 | { | |||
833 | return false; | |||
834 | } | |||
835 | if( (bPreset || bModified) && pActNum) | |||
836 | { | |||
837 | *pSaveNum = *pActNum; | |||
838 | rSet->Put(SvxNumBulletItem( *pSaveNum, nNumItemId ) ); | |||
839 | rSet->Put(SfxBoolItem(SID_PARAM_NUM_PRESET( 10000 + 856 ), bPreset)); | |||
840 | } | |||
841 | ||||
842 | return bModified; | |||
843 | } | |||
844 | ||||
845 | void SvxBitmapPickTabPage::Reset( const SfxItemSet* rSet ) | |||
846 | { | |||
847 | const SfxPoolItem* pItem; | |||
848 | // in Draw the item exists as WhichId, in Writer only as SlotId | |||
849 | SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE( 10000 + 855 ), false, &pItem); | |||
850 | if(eState != SfxItemState::SET) | |||
851 | { | |||
852 | nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 )); | |||
853 | eState = rSet->GetItemState(nNumItemId, false, &pItem); | |||
854 | ||||
855 | if( eState != SfxItemState::SET ) | |||
856 | { | |||
857 | pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( nNumItemId ) ); | |||
858 | eState = SfxItemState::SET; | |||
859 | } | |||
860 | ||||
861 | } | |||
862 | DBG_ASSERT(eState == SfxItemState::SET, "no item found!")do { if (true && (!(eState == SfxItemState::SET))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "862" ": "), "%s", "no item found!"); } } while (false); | |||
863 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
864 | ||||
865 | if(!pActNum) | |||
866 | pActNum.reset( new SvxNumRule(*pSaveNum) ); | |||
867 | else if(*pSaveNum != *pActNum) | |||
868 | *pActNum = *pSaveNum; | |||
869 | } | |||
870 | ||||
871 | IMPL_LINK_NOARG(SvxBitmapPickTabPage, NumSelectHdl_Impl, ValueSet*, void)void SvxBitmapPickTabPage::LinkStubNumSelectHdl_Impl(void * instance , ValueSet* data) { return static_cast<SvxBitmapPickTabPage *>(instance)->NumSelectHdl_Impl(data); } void SvxBitmapPickTabPage ::NumSelectHdl_Impl(__attribute__ ((unused)) ValueSet*) | |||
872 | { | |||
873 | if(!pActNum) | |||
874 | return; | |||
875 | ||||
876 | bPreset = false; | |||
877 | bModified = true; | |||
878 | sal_uInt16 nIdx = m_xExamplesVS->GetSelectedItemId() - 1; | |||
879 | ||||
880 | sal_uInt16 nMask = 1; | |||
881 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
882 | { | |||
883 | if(nActNumLvl & nMask) | |||
884 | { | |||
885 | SvxNumberFormat aFmt(pActNum->GetLevel(i)); | |||
886 | aFmt.SetNumberingType(SVX_NUM_BITMAP); | |||
887 | aFmt.SetPrefix( "" ); | |||
888 | aFmt.SetSuffix( "" ); | |||
889 | aFmt.SetCharFormatName( "" ); | |||
890 | ||||
891 | Graphic aGraphic; | |||
892 | if(GalleryExplorer::GetGraphicObj( GALLERY_THEME_BULLETS3, nIdx, &aGraphic)) | |||
893 | { | |||
894 | Size aSize = SvxNumberFormat::GetGraphicSizeMM100(&aGraphic); | |||
895 | sal_Int16 eOrient = text::VertOrientation::LINE_CENTER; | |||
896 | aSize = OutputDevice::LogicToLogic(aSize, MapMode(MapUnit::Map100thMM), MapMode(eCoreUnit)); | |||
897 | SvxBrushItem aBrush(aGraphic, GPOS_AREA, SID_ATTR_BRUSH( 10000 + 1 ) ); | |||
898 | aFmt.SetGraphicBrush( &aBrush, &aSize, &eOrient ); | |||
899 | } | |||
900 | else if(aGrfNames.size() > nIdx) | |||
901 | aFmt.SetGraphic( aGrfNames[nIdx] ); | |||
902 | pActNum->SetLevel(i, aFmt); | |||
903 | } | |||
904 | nMask <<= 1; | |||
905 | } | |||
906 | } | |||
907 | ||||
908 | IMPL_LINK_NOARG(SvxBitmapPickTabPage, DoubleClickHdl_Impl, ValueSet*, void)void SvxBitmapPickTabPage::LinkStubDoubleClickHdl_Impl(void * instance, ValueSet* data) { return static_cast<SvxBitmapPickTabPage *>(instance)->DoubleClickHdl_Impl(data); } void SvxBitmapPickTabPage ::DoubleClickHdl_Impl(__attribute__ ((unused)) ValueSet*) | |||
909 | { | |||
910 | NumSelectHdl_Impl(m_xExamplesVS.get()); | |||
911 | weld::Button& rOk = GetDialogController()->GetOKButton(); | |||
912 | rOk.clicked(); | |||
913 | } | |||
914 | ||||
915 | IMPL_LINK_NOARG(SvxBitmapPickTabPage, ClickAddBrowseHdl_Impl, weld::Button&, void)void SvxBitmapPickTabPage::LinkStubClickAddBrowseHdl_Impl(void * instance, weld::Button& data) { return static_cast< SvxBitmapPickTabPage *>(instance)->ClickAddBrowseHdl_Impl (data); } void SvxBitmapPickTabPage::ClickAddBrowseHdl_Impl(__attribute__ ((unused)) weld::Button&) | |||
916 | { | |||
917 | sfx2::FileDialogHelper aFileDialog(0, FileDialogFlags::NONE, GetFrameWeld()); | |||
918 | aFileDialog.SetTitle(CuiResId(RID_SVXSTR_ADD_IMAGEreinterpret_cast<char const *>("RID_SVXSTR_ADD_IMAGE" "\004" u8"Add Image"))); | |||
919 | if ( aFileDialog.Execute() != ERRCODE_NONEErrCode(0) ) | |||
920 | return; | |||
921 | ||||
922 | OUString aPath = SvtPathOptions().GetGalleryPath(); | |||
923 | OUString aPathToken = aPath.getToken( 1 , SEARCHPATH_DELIMITERu';' ); | |||
924 | ||||
925 | OUString aUserImageURL = aFileDialog.GetPath(); | |||
926 | ||||
927 | OUString aFileName; | |||
928 | const sal_Int32 nPos {aUserImageURL.lastIndexOf(SEARCHFILENAME_DELIMITERu'/')+1}; | |||
929 | if (nPos<=0) | |||
930 | aFileName = aUserImageURL; | |||
931 | else if (nPos<aUserImageURL.getLength()) | |||
932 | aFileName = aUserImageURL.copy(nPos); | |||
933 | ||||
934 | OUString aUserGalleryURL = aPathToken + "/" + aFileName; | |||
935 | INetURLObject aURL( aUserImageURL ); | |||
936 | DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" )do { if (true && (!(aURL.GetProtocol() != INetProtocol ::NotValid))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "936" ": "), "%s", "invalid URL"); } } while (false); | |||
937 | ||||
938 | GraphicDescriptor aDescriptor(aURL); | |||
939 | if (!aDescriptor.Detect()) | |||
940 | return; | |||
941 | ||||
942 | uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); | |||
943 | uno::Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess( | |||
944 | ucb::SimpleFileAccess::create( ::comphelper::getComponentContext(xFactory) ) ); | |||
945 | if ( !xSimpleFileAccess->exists( aUserImageURL )) | |||
946 | return; | |||
947 | ||||
948 | xSimpleFileAccess->copy( aUserImageURL, aUserGalleryURL ); | |||
949 | INetURLObject gURL( aUserGalleryURL ); | |||
950 | std::unique_ptr<SvStream> pIn(::utl::UcbStreamHelper::CreateStream( | |||
951 | gURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ )); | |||
952 | if ( !pIn ) | |||
953 | return; | |||
954 | ||||
955 | Graphic aGraphic; | |||
956 | GraphicConverter::Import( *pIn, aGraphic ); | |||
957 | ||||
958 | BitmapEx aBitmap = aGraphic.GetBitmapEx(); | |||
959 | long nPixelX = aBitmap.GetSizePixel().Width(); | |||
960 | long nPixelY = aBitmap.GetSizePixel().Height(); | |||
961 | double ratio = nPixelY/static_cast<double>(nPixelX); | |||
962 | if(nPixelX > 30) | |||
963 | { | |||
964 | nPixelX = 30; | |||
965 | nPixelY = static_cast<long>(nPixelX*ratio); | |||
966 | } | |||
967 | if(nPixelY > 30) | |||
968 | { | |||
969 | nPixelY = 30; | |||
970 | nPixelX = static_cast<long>(nPixelY/ratio); | |||
971 | } | |||
972 | ||||
973 | aBitmap.Scale( Size( nPixelX, nPixelY ), BmpScaleFlag::Fast ); | |||
974 | Graphic aScaledGraphic( aBitmap ); | |||
975 | GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); | |||
976 | ||||
977 | Sequence< PropertyValue > aFilterData( 2 ); | |||
978 | aFilterData[ 0 ].Name = "Compression"; | |||
979 | aFilterData[ 0 ].Value <<= sal_Int32(-1) ; | |||
980 | aFilterData[ 1 ].Name = "Quality"; | |||
981 | aFilterData[ 1 ].Value <<= sal_Int32(1); | |||
982 | ||||
983 | sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( gURL.GetFileExtension() ); | |||
984 | rFilter.ExportGraphic( aScaledGraphic, gURL , nFilterFormat, &aFilterData ); | |||
985 | GalleryExplorer::InsertURL( GALLERY_THEME_BULLETS3, aUserGalleryURL ); | |||
986 | ||||
987 | aGrfNames.push_back(aUserGalleryURL); | |||
988 | size_t i = 0; | |||
989 | for (auto & grfName : aGrfNames) | |||
990 | { | |||
991 | m_xExamplesVS->InsertItem( i + 1, i); | |||
992 | INetURLObject aObj(grfName); | |||
993 | if(aObj.GetProtocol() == INetProtocol::File) | |||
994 | grfName = aObj.PathToFileName(); | |||
995 | m_xExamplesVS->SetItemText( i + 1, grfName ); | |||
996 | ++i; | |||
997 | } | |||
998 | ||||
999 | if(aGrfNames.empty()) | |||
1000 | { | |||
1001 | m_xErrorText->show(); | |||
1002 | } | |||
1003 | else | |||
1004 | { | |||
1005 | m_xExamplesVS->Show(); | |||
1006 | m_xExamplesVS->SetFormat(); | |||
1007 | } | |||
1008 | } | |||
1009 | ||||
1010 | // tabpage numbering options | |||
1011 | SvxNumOptionsTabPage::SvxNumOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, | |||
1012 | const SfxItemSet& rSet) | |||
1013 | : SfxTabPage(pPage, pController, "cui/ui/numberingoptionspage.ui", "NumberingOptionsPage", &rSet) | |||
1014 | , m_pLevelHdlEvent(nullptr) | |||
1015 | , bLastWidthModified(false) | |||
1016 | , bModified(false) | |||
1017 | , bPreset(false) | |||
1018 | , bAutomaticCharStyles(true) | |||
1019 | , bHTMLMode(false) | |||
1020 | , nBullet(0xff) | |||
1021 | , nActNumLvl(1) | |||
1022 | , nNumItemId(SID_ATTR_NUMBERING_RULE( 10000 + 855 )) | |||
1023 | , m_xGrid(m_xBuilder->weld_widget("grid2")) | |||
1024 | , m_xLevelLB(m_xBuilder->weld_tree_view("levellb")) | |||
1025 | , m_xFmtLB(m_xBuilder->weld_combo_box("numfmtlb")) | |||
1026 | , m_xSeparatorFT(m_xBuilder->weld_label("separator")) | |||
1027 | , m_xPrefixFT(m_xBuilder->weld_label("prefixft")) | |||
1028 | , m_xPrefixED(m_xBuilder->weld_entry("prefix")) | |||
1029 | , m_xSuffixFT(m_xBuilder->weld_label("suffixft")) | |||
1030 | , m_xSuffixED(m_xBuilder->weld_entry("suffix")) | |||
1031 | , m_xCharFmtFT(m_xBuilder->weld_label("charstyleft")) | |||
1032 | , m_xCharFmtLB(m_xBuilder->weld_combo_box("charstyle")) | |||
1033 | , m_xBulColorFT(m_xBuilder->weld_label("colorft")) | |||
1034 | , m_xBulColLB(new ColorListBox(m_xBuilder->weld_menu_button("color"), pController->getDialog())) | |||
1035 | , m_xBulRelSizeFT(m_xBuilder->weld_label("relsizeft")) | |||
1036 | , m_xBulRelSizeMF(m_xBuilder->weld_metric_spin_button("relsize", FieldUnit::PERCENT)) | |||
1037 | , m_xAllLevelFT(m_xBuilder->weld_label("sublevelsft")) | |||
1038 | , m_xAllLevelNF(m_xBuilder->weld_spin_button("sublevels")) | |||
1039 | , m_xStartFT(m_xBuilder->weld_label("startatft")) | |||
1040 | , m_xStartED(m_xBuilder->weld_spin_button("startat")) | |||
1041 | , m_xBulletFT(m_xBuilder->weld_label("bulletft")) | |||
1042 | , m_xBulletPB(m_xBuilder->weld_button("bullet")) | |||
1043 | , m_xBitmapFT(m_xBuilder->weld_label("bitmapft")) | |||
1044 | , m_xBitmapMB(m_xBuilder->weld_menu_button("bitmap")) | |||
1045 | , m_xWidthFT(m_xBuilder->weld_label("widthft")) | |||
1046 | , m_xWidthMF(m_xBuilder->weld_metric_spin_button("widthmf", FieldUnit::CM)) | |||
1047 | , m_xHeightFT(m_xBuilder->weld_label("heightft")) | |||
1048 | , m_xHeightMF(m_xBuilder->weld_metric_spin_button("heightmf", FieldUnit::CM)) | |||
1049 | , m_xRatioCB(m_xBuilder->weld_check_button("keepratio")) | |||
1050 | , m_xOrientFT(m_xBuilder->weld_label("orientft")) | |||
1051 | , m_xOrientLB(m_xBuilder->weld_combo_box("orientlb")) | |||
1052 | , m_xAllLevelsFrame(m_xBuilder->weld_widget("levelsframe")) | |||
1053 | , m_xSameLevelCB(m_xBuilder->weld_check_button("allsame")) | |||
1054 | , m_xPreviewWIN(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWIN)) | |||
1055 | { | |||
1056 | m_xBulColLB->SetSlotId(SID_ATTR_CHAR_COLOR( 10000 + 17 )); | |||
1057 | m_xBulRelSizeMF->set_min(SVX_NUM_REL_SIZE_MIN25, FieldUnit::PERCENT); | |||
1058 | m_xBulRelSizeMF->set_increments(5, 50, FieldUnit::PERCENT); | |||
1059 | SetExchangeSupport(); | |||
1060 | aActBulletFont = lcl_GetDefaultBulletFont(); | |||
1061 | ||||
1062 | m_xBulletPB->connect_clicked(LINK(this, SvxNumOptionsTabPage, BulletHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubBulletHdl_Impl )); | |||
1063 | m_xFmtLB->connect_changed(LINK(this, SvxNumOptionsTabPage, NumberTypeSelectHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubNumberTypeSelectHdl_Impl )); | |||
1064 | m_xBitmapMB->connect_selected(LINK(this, SvxNumOptionsTabPage, GraphicHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubGraphicHdl_Impl )); | |||
1065 | m_xBitmapMB->connect_toggled(LINK(this, SvxNumOptionsTabPage, PopupActivateHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubPopupActivateHdl_Impl )); | |||
1066 | m_xLevelLB->set_selection_mode(SelectionMode::Multiple); | |||
1067 | m_xLevelLB->connect_changed(LINK(this, SvxNumOptionsTabPage, LevelHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubLevelHdl_Impl )); | |||
1068 | m_xCharFmtLB->connect_changed(LINK(this, SvxNumOptionsTabPage, CharFmtHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubCharFmtHdl_Impl )); | |||
1069 | m_xWidthMF->connect_value_changed(LINK(this, SvxNumOptionsTabPage, SizeHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubSizeHdl_Impl )); | |||
1070 | m_xHeightMF->connect_value_changed(LINK(this, SvxNumOptionsTabPage, SizeHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubSizeHdl_Impl )); | |||
1071 | m_xRatioCB->connect_toggled(LINK(this, SvxNumOptionsTabPage, RatioHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubRatioHdl_Impl )); | |||
1072 | m_xStartED->connect_value_changed(LINK(this, SvxNumOptionsTabPage, SpinModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubSpinModifyHdl_Impl )); | |||
1073 | m_xPrefixED->connect_changed(LINK(this, SvxNumOptionsTabPage, EditModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubEditModifyHdl_Impl )); | |||
1074 | m_xSuffixED->connect_changed(LINK(this, SvxNumOptionsTabPage, EditModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubEditModifyHdl_Impl )); | |||
1075 | m_xAllLevelNF->connect_value_changed(LINK(this,SvxNumOptionsTabPage, AllLevelHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubAllLevelHdl_Impl )); | |||
1076 | m_xOrientLB->connect_changed(LINK(this, SvxNumOptionsTabPage, OrientHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubOrientHdl_Impl )); | |||
1077 | m_xSameLevelCB->connect_toggled(LINK(this, SvxNumOptionsTabPage, SameLevelHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubSameLevelHdl_Impl )); | |||
1078 | m_xBulRelSizeMF->connect_value_changed(LINK(this,SvxNumOptionsTabPage, BulRelSizeHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubBulRelSizeHdl_Impl )); | |||
1079 | m_xBulColLB->SetSelectHdl(LINK(this, SvxNumOptionsTabPage, BulColorHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubBulColorHdl_Impl )); | |||
1080 | aInvalidateTimer.SetInvokeHandler(LINK(this, SvxNumOptionsTabPage, PreviewInvalidateHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubPreviewInvalidateHdl_Impl )); | |||
1081 | aInvalidateTimer.SetTimeout(50); | |||
1082 | ||||
1083 | eCoreUnit = rSet.GetPool()->GetMetric(rSet.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 ))); | |||
1084 | ||||
1085 | // Fill ListBox with predefined / translated numbering types. | |||
1086 | sal_uInt32 nCount = SvxNumberingTypeTable::Count(); | |||
1087 | for (sal_uInt32 i = 0; i < nCount; ++i) | |||
1088 | { | |||
1089 | m_xFmtLB->append(OUString::number(SvxNumberingTypeTable::GetValue(i)), SvxNumberingTypeTable::GetString(i)); | |||
1090 | } | |||
1091 | ||||
1092 | // Get advanced numbering types from the component. | |||
1093 | // Watch out for the ugly | |||
1094 | // 136 == 0x88 == SVX_NUM_BITMAP|0x80 == SVX_NUM_BITMAP|LINK_TOKEN | |||
1095 | // to not remove that. | |||
1096 | SvxNumOptionsTabPageHelper::GetI18nNumbering( *m_xFmtLB, (SVX_NUM_BITMAP | LINK_TOKEN0x80)); | |||
1097 | ||||
1098 | m_xFmtLB->set_active(0); | |||
1099 | ||||
1100 | m_xCharFmtLB->set_size_request(m_xCharFmtLB->get_approximate_digit_width() * 10, -1); | |||
1101 | Size aSize(m_xGrid->get_preferred_size()); | |||
1102 | m_xGrid->set_size_request(aSize.Width(), -1); | |||
1103 | } | |||
1104 | ||||
1105 | SvxNumOptionsTabPage::~SvxNumOptionsTabPage() | |||
1106 | { | |||
1107 | m_xPreviewWIN.reset(); | |||
1108 | m_xBulColLB.reset(); | |||
1109 | pActNum.reset(); | |||
1110 | pSaveNum.reset(); | |||
1111 | if (m_pLevelHdlEvent) | |||
1112 | { | |||
1113 | Application::RemoveUserEvent(m_pLevelHdlEvent); | |||
1114 | m_pLevelHdlEvent = nullptr; | |||
1115 | } | |||
1116 | } | |||
1117 | ||||
1118 | void SvxNumOptionsTabPage::SetMetric(FieldUnit eMetric) | |||
1119 | { | |||
1120 | if(eMetric == FieldUnit::MM) | |||
1121 | { | |||
1122 | m_xWidthMF->set_digits(1); | |||
1123 | m_xHeightMF->set_digits(1); | |||
1124 | } | |||
1125 | m_xWidthMF->set_unit(eMetric); | |||
1126 | m_xHeightMF->set_unit(eMetric); | |||
1127 | } | |||
1128 | ||||
1129 | std::unique_ptr<SfxTabPage> SvxNumOptionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, | |||
1130 | const SfxItemSet* rAttrSet) | |||
1131 | { | |||
1132 | return std::make_unique<SvxNumOptionsTabPage>(pPage, pController, *rAttrSet); | |||
1133 | }; | |||
1134 | ||||
1135 | void SvxNumOptionsTabPage::ActivatePage(const SfxItemSet& rSet) | |||
1136 | { | |||
1137 | const SfxPoolItem* pItem; | |||
1138 | const SfxItemSet* pExampleSet = GetDialogExampleSet(); | |||
1139 | sal_uInt16 nTmpNumLvl = 1; | |||
1140 | if(pExampleSet) | |||
1141 | { | |||
1142 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_NUM_PRESET( 10000 + 856 ), false, &pItem)) | |||
1143 | bPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
1144 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 ), false, &pItem)) | |||
1145 | nTmpNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
1146 | } | |||
1147 | if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem)) | |||
1148 | { | |||
1149 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
1150 | } | |||
1151 | ||||
1152 | bModified = (!pActNum->Get( 0 ) || bPreset); | |||
1153 | if(*pActNum == *pSaveNum && nActNumLvl == nTmpNumLvl) | |||
1154 | return; | |||
1155 | ||||
1156 | nActNumLvl = nTmpNumLvl; | |||
1157 | sal_uInt16 nMask = 1; | |||
1158 | m_xLevelLB->unselect_all(); | |||
1159 | if (nActNumLvl == SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
1160 | m_xLevelLB->select(pActNum->GetLevelCount()); | |||
1161 | if(nActNumLvl != SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
1162 | { | |||
1163 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1164 | { | |||
1165 | if(nActNumLvl & nMask) | |||
1166 | m_xLevelLB->select(i); | |||
1167 | nMask <<= 1 ; | |||
1168 | } | |||
1169 | } | |||
1170 | *pActNum = *pSaveNum; | |||
1171 | ||||
1172 | InitControls(); | |||
1173 | } | |||
1174 | ||||
1175 | DeactivateRC SvxNumOptionsTabPage::DeactivatePage(SfxItemSet * _pSet) | |||
1176 | { | |||
1177 | if(_pSet) | |||
1178 | FillItemSet(_pSet); | |||
1179 | return DeactivateRC::LeavePage; | |||
1180 | } | |||
1181 | ||||
1182 | bool SvxNumOptionsTabPage::FillItemSet( SfxItemSet* rSet ) | |||
1183 | { | |||
1184 | rSet->Put(SfxUInt16Item(SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 ), nActNumLvl)); | |||
1185 | if(bModified && pActNum) | |||
1186 | { | |||
1187 | *pSaveNum = *pActNum; | |||
1188 | rSet->Put(SvxNumBulletItem( *pSaveNum, nNumItemId )); | |||
1189 | rSet->Put(SfxBoolItem(SID_PARAM_NUM_PRESET( 10000 + 856 ), false)); | |||
1190 | } | |||
1191 | return bModified; | |||
1192 | }; | |||
1193 | ||||
1194 | void SvxNumOptionsTabPage::Reset( const SfxItemSet* rSet ) | |||
1195 | { | |||
1196 | const SfxPoolItem* pItem; | |||
1197 | // in Draw the item exists as WhichId, in Writer only as SlotId | |||
1198 | SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE( 10000 + 855 ), false, &pItem); | |||
1199 | if(eState != SfxItemState::SET) | |||
1200 | { | |||
1201 | nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 )); | |||
1202 | eState = rSet->GetItemState(nNumItemId, false, &pItem); | |||
1203 | ||||
1204 | if( eState != SfxItemState::SET ) | |||
1205 | { | |||
1206 | pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( nNumItemId ) ); | |||
1207 | eState = SfxItemState::SET; | |||
1208 | } | |||
1209 | ||||
1210 | } | |||
1211 | DBG_ASSERT(eState == SfxItemState::SET, "no item found!")do { if (true && (!(eState == SfxItemState::SET))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "1211" ": "), "%s", "no item found!"); } } while (false); | |||
1212 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
1213 | ||||
1214 | // insert levels | |||
1215 | if (!m_xLevelLB->n_children()) | |||
1216 | { | |||
1217 | for(sal_uInt16 i = 1; i <= pSaveNum->GetLevelCount(); i++) | |||
1218 | m_xLevelLB->append_text(OUString::number(i)); | |||
1219 | if(pSaveNum->GetLevelCount() > 1) | |||
1220 | { | |||
1221 | OUString sEntry = "1 - " + OUString::number( pSaveNum->GetLevelCount() ); | |||
1222 | m_xLevelLB->append_text(sEntry); | |||
1223 | m_xLevelLB->select_text(sEntry); | |||
1224 | } | |||
1225 | else | |||
1226 | m_xLevelLB->select(0); | |||
1227 | } | |||
1228 | else | |||
1229 | m_xLevelLB->select(m_xLevelLB->n_children() - 1); | |||
1230 | ||||
1231 | sal_uInt16 nMask = 1; | |||
1232 | m_xLevelLB->unselect_all(); | |||
1233 | if (nActNumLvl == SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
1234 | { | |||
1235 | m_xLevelLB->select( pSaveNum->GetLevelCount() ); | |||
1236 | } | |||
1237 | else | |||
1238 | { | |||
1239 | for(sal_uInt16 i = 0; i < pSaveNum->GetLevelCount(); i++) | |||
1240 | { | |||
1241 | if(nActNumLvl & nMask) | |||
1242 | m_xLevelLB->select( i ); | |||
1243 | nMask <<= 1 ; | |||
1244 | } | |||
1245 | } | |||
1246 | ||||
1247 | if(!pActNum) | |||
1248 | pActNum.reset( new SvxNumRule(*pSaveNum) ); | |||
1249 | else if(*pSaveNum != *pActNum) | |||
1250 | *pActNum = *pSaveNum; | |||
1251 | m_aPreviewWIN.SetNumRule(pActNum.get()); | |||
1252 | m_xSameLevelCB->set_active(pActNum->IsContinuousNumbering()); | |||
1253 | ||||
1254 | SfxObjectShell* pShell; | |||
1255 | if ( SfxItemState::SET == rSet->GetItemState( SID_HTML_MODE(10000 + 414), false, &pItem ) | |||
1256 | || ( nullptr != ( pShell = SfxObjectShell::Current()) && | |||
1257 | nullptr != ( pItem = pShell->GetItem( SID_HTML_MODE(10000 + 414) ) ) ) ) | |||
1258 | { | |||
1259 | sal_uInt16 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
1260 | bHTMLMode = 0 != (nHtmlMode&HTMLMODE_ON); | |||
1261 | } | |||
1262 | ||||
1263 | bool bCharFmt = pActNum->IsFeatureSupported(SvxNumRuleFlags::CHAR_STYLE); | |||
1264 | m_xCharFmtFT->set_visible(bCharFmt); | |||
1265 | m_xCharFmtLB->set_visible(bCharFmt); | |||
1266 | ||||
1267 | bool bContinuous = pActNum->IsFeatureSupported(SvxNumRuleFlags::CONTINUOUS); | |||
1268 | ||||
1269 | bool bAllLevel = bContinuous && !bHTMLMode; | |||
1270 | m_xAllLevelFT->set_visible(bAllLevel); | |||
1271 | m_xAllLevelNF->set_visible(bAllLevel); | |||
1272 | ||||
1273 | m_xAllLevelsFrame->set_visible(bContinuous); | |||
1274 | ||||
1275 | // again misusage: in Draw there is numeration only until the bitmap | |||
1276 | // without SVX_NUM_NUMBER_NONE | |||
1277 | //remove types that are unsupported by Draw/Impress | |||
1278 | if(!bContinuous) | |||
1279 | { | |||
1280 | sal_Int32 nFmtCount = m_xFmtLB->get_count(); | |||
1281 | for(sal_Int32 i = nFmtCount; i; i--) | |||
1282 | { | |||
1283 | sal_uInt16 nEntryData = m_xFmtLB->get_id(i - 1).toUInt32(); | |||
1284 | if(/*SVX_NUM_NUMBER_NONE == nEntryData ||*/ | |||
1285 | (SVX_NUM_BITMAP|LINK_TOKEN0x80) == nEntryData) | |||
1286 | m_xFmtLB->remove(i - 1); | |||
1287 | } | |||
1288 | } | |||
1289 | //one must be enabled | |||
1290 | if(!pActNum->IsFeatureSupported(SvxNumRuleFlags::ENABLE_LINKED_BMP)) | |||
1291 | { | |||
1292 | auto nPos = m_xFmtLB->find_id(OUString::number(SVX_NUM_BITMAP|LINK_TOKEN0x80)); | |||
1293 | if (nPos != -1) | |||
1294 | m_xFmtLB->remove(nPos); | |||
1295 | } | |||
1296 | else if(!pActNum->IsFeatureSupported(SvxNumRuleFlags::ENABLE_EMBEDDED_BMP)) | |||
1297 | { | |||
1298 | auto nPos = m_xFmtLB->find_id(OUString::number(SVX_NUM_BITMAP)); | |||
1299 | if (nPos != -1) | |||
1300 | m_xFmtLB->remove(nPos); | |||
1301 | } | |||
1302 | ||||
1303 | // MegaHack: because of a not-fixable 'design mistake/error' in Impress | |||
1304 | // delete all kinds of numeric enumerations | |||
1305 | if(pActNum->IsFeatureSupported(SvxNumRuleFlags::NO_NUMBERS)) | |||
1306 | { | |||
1307 | sal_Int32 nFmtCount = m_xFmtLB->get_count(); | |||
1308 | for(sal_Int32 i = nFmtCount; i; i--) | |||
1309 | { | |||
1310 | sal_uInt16 nEntryData = m_xFmtLB->get_id(i - 1).toUInt32(); | |||
1311 | if( /*nEntryData >= SVX_NUM_CHARS_UPPER_LETTER &&*/ nEntryData <= SVX_NUM_NUMBER_NONE) | |||
1312 | m_xFmtLB->remove(i - 1); | |||
1313 | } | |||
1314 | } | |||
1315 | ||||
1316 | InitControls(); | |||
1317 | bModified = false; | |||
1318 | } | |||
1319 | ||||
1320 | void SvxNumOptionsTabPage::InitControls() | |||
1321 | { | |||
1322 | bool bShowBullet = true; | |||
1323 | bool bShowBitmap = true; | |||
1324 | bool bSameType = true; | |||
1325 | bool bSameStart = true; | |||
1326 | bool bSamePrefix = true; | |||
1327 | bool bSameSuffix = true; | |||
1328 | bool bAllLevel = true; | |||
1329 | bool bSameCharFmt = true; | |||
1330 | bool bSameVOrient = true; | |||
1331 | bool bSameSize = true; | |||
1332 | bool bSameBulColor = true; | |||
1333 | bool bSameBulRelSize= true; | |||
1334 | ||||
1335 | const SvxNumberFormat* aNumFmtArr[SVX_MAX_NUM10]; | |||
1336 | OUString sFirstCharFmt; | |||
1337 | sal_Int16 eFirstOrient = text::VertOrientation::NONE; | |||
1338 | Size aFirstSize(0,0); | |||
1339 | sal_uInt16 nMask = 1; | |||
1340 | sal_uInt16 nLvl = SAL_MAX_UINT16((sal_uInt16) 0xFFFF); | |||
1341 | sal_uInt16 nHighestLevel = 0; | |||
1342 | ||||
1343 | bool bBullColor = pActNum->IsFeatureSupported(SvxNumRuleFlags::BULLET_COLOR); | |||
1344 | bool bBullRelSize = pActNum->IsFeatureSupported(SvxNumRuleFlags::BULLET_REL_SIZE); | |||
1345 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1346 | { | |||
1347 | if(nActNumLvl & nMask) | |||
1348 | { | |||
1349 | aNumFmtArr[i] = &pActNum->GetLevel(i); | |||
1350 | bShowBullet &= aNumFmtArr[i]->GetNumberingType() == SVX_NUM_CHAR_SPECIAL; | |||
1351 | bShowBitmap &= (aNumFmtArr[i]->GetNumberingType()&(~LINK_TOKEN0x80)) == SVX_NUM_BITMAP; | |||
1352 | if(SAL_MAX_UINT16((sal_uInt16) 0xFFFF) == nLvl) | |||
1353 | { | |||
1354 | nLvl = i; | |||
1355 | sFirstCharFmt = aNumFmtArr[i]->GetCharFormatName(); | |||
1356 | eFirstOrient = aNumFmtArr[i]->GetVertOrient(); | |||
1357 | if(bShowBitmap) | |||
1358 | aFirstSize = aNumFmtArr[i]->GetGraphicSize(); | |||
1359 | } | |||
1360 | if( i > nLvl) | |||
1361 | { | |||
1362 | bSameType &= aNumFmtArr[i]->GetNumberingType() == aNumFmtArr[nLvl]->GetNumberingType(); | |||
1363 | bSameStart = aNumFmtArr[i]->GetStart() == aNumFmtArr[nLvl]->GetStart(); | |||
1364 | ||||
1365 | bSamePrefix = aNumFmtArr[i]->GetPrefix() == aNumFmtArr[nLvl]->GetPrefix(); | |||
1366 | bSameSuffix = aNumFmtArr[i]->GetSuffix() == aNumFmtArr[nLvl]->GetSuffix(); | |||
1367 | bAllLevel &= aNumFmtArr[i]->GetIncludeUpperLevels() == aNumFmtArr[nLvl]->GetIncludeUpperLevels(); | |||
1368 | bSameCharFmt &= sFirstCharFmt == aNumFmtArr[i]->GetCharFormatName(); | |||
1369 | bSameVOrient &= eFirstOrient == aNumFmtArr[i]->GetVertOrient(); | |||
1370 | if(bShowBitmap && bSameSize) | |||
1371 | bSameSize &= aNumFmtArr[i]->GetGraphicSize() == aFirstSize; | |||
1372 | bSameBulColor &= aNumFmtArr[i]->GetBulletColor() == aNumFmtArr[nLvl]->GetBulletColor(); | |||
1373 | bSameBulRelSize &= aNumFmtArr[i]->GetBulletRelSize() == aNumFmtArr[nLvl]->GetBulletRelSize(); | |||
1374 | } | |||
1375 | nHighestLevel = i; | |||
1376 | } | |||
1377 | else | |||
1378 | aNumFmtArr[i] = nullptr; | |||
1379 | ||||
1380 | nMask <<= 1 ; | |||
1381 | } | |||
1382 | SwitchNumberType(bShowBullet ? 1 : bShowBitmap ? 2 : 0); | |||
1383 | ||||
1384 | sal_uInt16 nNumberingType; | |||
1385 | if (nLvl != SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
1386 | nNumberingType = aNumFmtArr[nLvl]->GetNumberingType(); | |||
1387 | else | |||
1388 | { | |||
1389 | nNumberingType = SVX_NUM_NUMBER_NONE; | |||
1390 | bAllLevel = false; | |||
1391 | bSameBulRelSize = false; | |||
1392 | bSameBulColor = false; | |||
1393 | bSameStart = false; | |||
1394 | bSamePrefix = false; | |||
1395 | bSameSuffix = false; | |||
1396 | } | |||
1397 | ||||
1398 | CheckForStartValue_Impl(nNumberingType); | |||
1399 | ||||
1400 | if(bShowBitmap) | |||
1401 | { | |||
1402 | if(!bSameVOrient || eFirstOrient == text::VertOrientation::NONE) | |||
1403 | m_xOrientLB->set_active(-1); | |||
1404 | else | |||
1405 | m_xOrientLB->set_active( | |||
1406 | sal::static_int_cast< sal_Int32 >(eFirstOrient - 1)); | |||
1407 | // no text::VertOrientation::NONE | |||
1408 | ||||
1409 | if(bSameSize) | |||
1410 | { | |||
1411 | SetMetricValue(*m_xHeightMF, aFirstSize.Height(), eCoreUnit); | |||
1412 | SetMetricValue(*m_xWidthMF, aFirstSize.Width(), eCoreUnit); | |||
1413 | } | |||
1414 | else | |||
1415 | { | |||
1416 | m_xHeightMF->set_text(""); | |||
1417 | m_xWidthMF->set_text(""); | |||
1418 | } | |||
1419 | } | |||
1420 | ||||
1421 | if(bSameType) | |||
1422 | { | |||
1423 | sal_uInt16 nLBData = nNumberingType; | |||
1424 | m_xFmtLB->set_active_id(OUString::number(nLBData)); | |||
1425 | } | |||
1426 | else | |||
1427 | m_xFmtLB->set_active(-1); | |||
1428 | ||||
1429 | m_xAllLevelNF->set_sensitive(nHighestLevel > 0 && !m_xSameLevelCB->get_active()); | |||
1430 | m_xAllLevelNF->set_max(nHighestLevel + 1); | |||
1431 | if(bAllLevel) | |||
1432 | { | |||
1433 | m_xAllLevelNF->set_value(aNumFmtArr[nLvl]->GetIncludeUpperLevels()); | |||
1434 | } | |||
1435 | else | |||
1436 | { | |||
1437 | m_xAllLevelNF->set_text(""); | |||
1438 | } | |||
1439 | ||||
1440 | if(bBullRelSize) | |||
1441 | { | |||
1442 | if(bSameBulRelSize) | |||
1443 | m_xBulRelSizeMF->set_value(aNumFmtArr[nLvl]->GetBulletRelSize(), FieldUnit::PERCENT); | |||
1444 | else | |||
1445 | m_xBulRelSizeMF->set_text(""); | |||
1446 | } | |||
1447 | if(bBullColor) | |||
1448 | { | |||
1449 | if(bSameBulColor) | |||
1450 | m_xBulColLB->SelectEntry(aNumFmtArr[nLvl]->GetBulletColor()); | |||
1451 | else | |||
1452 | m_xBulColLB->SetNoSelection(); | |||
1453 | } | |||
1454 | switch(nBullet) | |||
1455 | { | |||
1456 | case SHOW_NUMBERING0: | |||
1457 | if(bSameStart) | |||
1458 | { | |||
1459 | m_xStartED->set_value(aNumFmtArr[nLvl]->GetStart()); | |||
1460 | } | |||
1461 | else | |||
1462 | m_xStartED->set_text(""); | |||
1463 | break; | |||
1464 | case SHOW_BULLET1: | |||
1465 | break; | |||
1466 | case SHOW_BITMAP2: | |||
1467 | break; | |||
1468 | } | |||
1469 | ||||
1470 | if(bSamePrefix) | |||
1471 | m_xPrefixED->set_text(aNumFmtArr[nLvl]->GetPrefix()); | |||
1472 | else | |||
1473 | m_xPrefixED->set_text(""); | |||
1474 | if(bSameSuffix) | |||
1475 | m_xSuffixED->set_text(aNumFmtArr[nLvl]->GetSuffix()); | |||
1476 | else | |||
1477 | m_xSuffixED->set_text(""); | |||
1478 | ||||
1479 | if(bSameCharFmt) | |||
1480 | { | |||
1481 | if (!sFirstCharFmt.isEmpty()) | |||
1482 | m_xCharFmtLB->set_active_text(sFirstCharFmt); | |||
1483 | else | |||
1484 | m_xCharFmtLB->set_active(0); | |||
1485 | } | |||
1486 | else | |||
1487 | m_xCharFmtLB->set_active(-1); | |||
1488 | ||||
1489 | m_aPreviewWIN.SetLevel(nActNumLvl); | |||
1490 | m_aPreviewWIN.Invalidate(); | |||
1491 | } | |||
1492 | ||||
1493 | // 0 - Number; 1 - Bullet; 2 - Bitmap | |||
1494 | void SvxNumOptionsTabPage::SwitchNumberType( sal_uInt8 nType ) | |||
1495 | { | |||
1496 | if(nBullet == nType) | |||
1497 | return; | |||
1498 | nBullet = nType; | |||
1499 | bool bBullet = (nType == SHOW_BULLET1); | |||
1500 | bool bBitmap = (nType == SHOW_BITMAP2); | |||
1501 | bool bEnableBitmap = (nType == SHOW_BITMAP2); | |||
1502 | bool bNumeric = !(bBitmap||bBullet); | |||
1503 | m_xSeparatorFT->set_visible(bNumeric); | |||
1504 | m_xPrefixFT->set_visible(bNumeric); | |||
1505 | m_xPrefixED->set_visible(bNumeric); | |||
1506 | m_xSuffixFT->set_visible(bNumeric); | |||
1507 | m_xSuffixED->set_visible(bNumeric); | |||
1508 | ||||
1509 | bool bCharFmt = pActNum->IsFeatureSupported(SvxNumRuleFlags::CHAR_STYLE); | |||
1510 | m_xCharFmtFT->set_visible(!bBitmap && bCharFmt); | |||
1511 | m_xCharFmtLB->set_visible(!bBitmap && bCharFmt); | |||
1512 | ||||
1513 | // this is rather misusage, as there is no own flag | |||
1514 | // for complete numeration | |||
1515 | bool bAllLevelFeature = pActNum->IsFeatureSupported(SvxNumRuleFlags::CONTINUOUS); | |||
1516 | bool bAllLevel = bNumeric && bAllLevelFeature && !bHTMLMode; | |||
1517 | m_xAllLevelFT->set_visible(bAllLevel); | |||
1518 | m_xAllLevelNF->set_visible(bAllLevel); | |||
1519 | ||||
1520 | m_xStartFT->set_visible(!(bBullet||bBitmap)); | |||
1521 | m_xStartED->set_visible(!(bBullet||bBitmap)); | |||
1522 | ||||
1523 | m_xBulletFT->set_visible(bBullet); | |||
1524 | m_xBulletPB->set_visible(bBullet); | |||
1525 | bool bBullColor = pActNum->IsFeatureSupported(SvxNumRuleFlags::BULLET_COLOR); | |||
1526 | m_xBulColorFT->set_visible(!bBitmap && bBullColor); | |||
1527 | m_xBulColLB->set_visible(!bBitmap && bBullColor); | |||
1528 | bool bBullResSize = pActNum->IsFeatureSupported(SvxNumRuleFlags::BULLET_REL_SIZE); | |||
1529 | m_xBulRelSizeFT->set_visible(!bBitmap && bBullResSize); | |||
1530 | m_xBulRelSizeMF->set_visible(!bBitmap && bBullResSize); | |||
1531 | ||||
1532 | m_xBitmapFT->set_visible(bBitmap); | |||
1533 | m_xBitmapMB->set_visible(bBitmap); | |||
1534 | ||||
1535 | m_xWidthFT->set_visible(bBitmap); | |||
1536 | m_xWidthMF->set_visible(bBitmap); | |||
1537 | m_xHeightFT->set_visible(bBitmap); | |||
1538 | m_xHeightMF->set_visible(bBitmap); | |||
1539 | m_xRatioCB->set_visible(bBitmap); | |||
1540 | ||||
1541 | m_xOrientFT->set_visible(bBitmap && bAllLevelFeature); | |||
1542 | m_xOrientLB->set_visible(bBitmap && bAllLevelFeature); | |||
1543 | ||||
1544 | m_xWidthFT->set_sensitive(bEnableBitmap); | |||
1545 | m_xWidthMF->set_sensitive(bEnableBitmap); | |||
1546 | m_xHeightFT->set_sensitive(bEnableBitmap); | |||
1547 | m_xHeightMF->set_sensitive(bEnableBitmap); | |||
1548 | m_xRatioCB->set_sensitive(bEnableBitmap); | |||
1549 | m_xOrientFT->set_sensitive(bEnableBitmap); | |||
1550 | m_xOrientLB->set_sensitive(bEnableBitmap); | |||
1551 | } | |||
1552 | ||||
1553 | IMPL_LINK_NOARG(SvxNumOptionsTabPage, LevelHdl_Impl, weld::TreeView&, void)void SvxNumOptionsTabPage::LinkStubLevelHdl_Impl(void * instance , weld::TreeView& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->LevelHdl_Impl(data); } void SvxNumOptionsTabPage ::LevelHdl_Impl(__attribute__ ((unused)) weld::TreeView&) | |||
1554 | { | |||
1555 | if (m_pLevelHdlEvent) | |||
1556 | return; | |||
1557 | // tdf#127112 (borrowing tdf#127120 solution) multiselection may be implemented by deselect follow by select so | |||
1558 | // fire off the handler to happen on next event loop and only process the | |||
1559 | // final state | |||
1560 | m_pLevelHdlEvent = Application::PostUserEvent(LINK(this, SvxNumOptionsTabPage, LevelHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumOptionsTabPage *>(this), &SvxNumOptionsTabPage::LinkStubLevelHdl)); | |||
1561 | } | |||
1562 | ||||
1563 | IMPL_LINK_NOARG(SvxNumOptionsTabPage, LevelHdl, void*, void)void SvxNumOptionsTabPage::LinkStubLevelHdl(void * instance, void * data) { return static_cast<SvxNumOptionsTabPage *>(instance )->LevelHdl(data); } void SvxNumOptionsTabPage::LevelHdl(__attribute__ ((unused)) void*) | |||
1564 | { | |||
1565 | m_pLevelHdlEvent = nullptr; | |||
1566 | ||||
1567 | sal_uInt16 nSaveNumLvl = nActNumLvl; | |||
1568 | nActNumLvl = 0; | |||
1569 | std::vector<int> aSelectedRows = m_xLevelLB->get_selected_rows(); | |||
1570 | if (std::find(aSelectedRows.begin(), aSelectedRows.end(), pActNum->GetLevelCount()) != aSelectedRows.end() && | |||
1571 | (aSelectedRows.size() == 1 || nSaveNumLvl != 0xffff)) | |||
1572 | { | |||
1573 | nActNumLvl = 0xFFFF; | |||
1574 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++ ) | |||
1575 | m_xLevelLB->unselect(i); | |||
1576 | } | |||
1577 | else if (!aSelectedRows.empty()) | |||
1578 | { | |||
1579 | sal_uInt16 nMask = 1; | |||
1580 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++ ) | |||
1581 | { | |||
1582 | if (std::find(aSelectedRows.begin(), aSelectedRows.end(), i) != aSelectedRows.end()) | |||
1583 | nActNumLvl |= nMask; | |||
1584 | nMask <<= 1; | |||
1585 | } | |||
1586 | m_xLevelLB->unselect(pActNum->GetLevelCount()); | |||
1587 | } | |||
1588 | else | |||
1589 | { | |||
1590 | nActNumLvl = nSaveNumLvl; | |||
1591 | sal_uInt16 nMask = 1; | |||
1592 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++ ) | |||
1593 | { | |||
1594 | if(nActNumLvl & nMask) | |||
1595 | { | |||
1596 | m_xLevelLB->select(i); | |||
1597 | break; | |||
1598 | } | |||
1599 | nMask <<=1; | |||
1600 | } | |||
1601 | } | |||
1602 | InitControls(); | |||
1603 | } | |||
1604 | ||||
1605 | IMPL_LINK_NOARG(SvxNumOptionsTabPage, PreviewInvalidateHdl_Impl, Timer *, void)void SvxNumOptionsTabPage::LinkStubPreviewInvalidateHdl_Impl( void * instance, Timer * data) { return static_cast<SvxNumOptionsTabPage *>(instance)->PreviewInvalidateHdl_Impl(data); } void SvxNumOptionsTabPage ::PreviewInvalidateHdl_Impl(__attribute__ ((unused)) Timer *) | |||
1606 | { | |||
1607 | m_aPreviewWIN.Invalidate(); | |||
1608 | } | |||
1609 | ||||
1610 | IMPL_LINK(SvxNumOptionsTabPage, AllLevelHdl_Impl, weld::SpinButton&, rBox, void)void SvxNumOptionsTabPage::LinkStubAllLevelHdl_Impl(void * instance , weld::SpinButton& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->AllLevelHdl_Impl(data); } void SvxNumOptionsTabPage ::AllLevelHdl_Impl(weld::SpinButton& rBox) | |||
1611 | { | |||
1612 | sal_uInt16 nMask = 1; | |||
1613 | for(sal_uInt16 e = 0; e < pActNum->GetLevelCount(); e++) | |||
1614 | { | |||
1615 | if(nActNumLvl & nMask) | |||
1616 | { | |||
1617 | SvxNumberFormat aNumFmt(pActNum->GetLevel(e)); | |||
1618 | aNumFmt.SetIncludeUpperLevels(static_cast<sal_uInt8>(std::min(rBox.get_value(), int(e + 1))) ); | |||
1619 | pActNum->SetLevel(e, aNumFmt); | |||
1620 | } | |||
1621 | nMask <<= 1; | |||
1622 | } | |||
1623 | SetModified(); | |||
1624 | } | |||
1625 | ||||
1626 | IMPL_LINK(SvxNumOptionsTabPage, NumberTypeSelectHdl_Impl, weld::ComboBox&, rBox, void)void SvxNumOptionsTabPage::LinkStubNumberTypeSelectHdl_Impl(void * instance, weld::ComboBox& data) { return static_cast< SvxNumOptionsTabPage *>(instance)->NumberTypeSelectHdl_Impl (data); } void SvxNumOptionsTabPage::NumberTypeSelectHdl_Impl (weld::ComboBox& rBox) | |||
1627 | { | |||
1628 | OUString sSelectStyle; | |||
1629 | bool bShowOrient = false; | |||
1630 | bool bBmp = false; | |||
1631 | sal_uInt16 nMask = 1; | |||
1632 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1633 | { | |||
1634 | if(nActNumLvl & nMask) | |||
1635 | { | |||
1636 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
1637 | // PAGEDESC does not exist | |||
1638 | SvxNumType nNumType = static_cast<SvxNumType>(rBox.get_active_id().toUInt32()); | |||
1639 | aNumFmt.SetNumberingType(nNumType); | |||
1640 | sal_uInt16 nNumberingType = aNumFmt.GetNumberingType(); | |||
1641 | if(SVX_NUM_BITMAP == (nNumberingType&(~LINK_TOKEN0x80))) | |||
1642 | { | |||
1643 | bBmp |= nullptr != aNumFmt.GetBrush(); | |||
1644 | aNumFmt.SetIncludeUpperLevels( 0 ); | |||
1645 | aNumFmt.SetSuffix( "" ); | |||
1646 | aNumFmt.SetPrefix( "" ); | |||
1647 | if(!bBmp) | |||
1648 | aNumFmt.SetGraphic(""); | |||
1649 | pActNum->SetLevel(i, aNumFmt); | |||
1650 | SwitchNumberType(SHOW_BITMAP2); | |||
1651 | bShowOrient = true; | |||
1652 | } | |||
1653 | else if( SVX_NUM_CHAR_SPECIAL == nNumberingType ) | |||
1654 | { | |||
1655 | aNumFmt.SetIncludeUpperLevels( 0 ); | |||
1656 | aNumFmt.SetSuffix( "" ); | |||
1657 | aNumFmt.SetPrefix( "" ); | |||
1658 | if( !aNumFmt.GetBulletFont() ) | |||
1659 | aNumFmt.SetBulletFont(&aActBulletFont); | |||
1660 | if( !aNumFmt.GetBulletChar() ) | |||
1661 | aNumFmt.SetBulletChar( SVX_DEF_BULLET(0xF000 + 149) ); | |||
1662 | pActNum->SetLevel(i, aNumFmt); | |||
1663 | SwitchNumberType(SHOW_BULLET1); | |||
1664 | // allocation of the drawing pattern is automatic | |||
1665 | if(bAutomaticCharStyles) | |||
1666 | { | |||
1667 | sSelectStyle = m_sBulletCharFormatName; | |||
1668 | } | |||
1669 | } | |||
1670 | else | |||
1671 | { | |||
1672 | aNumFmt.SetPrefix( m_xPrefixED->get_text() ); | |||
1673 | aNumFmt.SetSuffix( m_xSuffixED->get_text() ); | |||
1674 | SwitchNumberType(SHOW_NUMBERING0); | |||
1675 | pActNum->SetLevel(i, aNumFmt); | |||
1676 | CheckForStartValue_Impl(nNumberingType); | |||
1677 | ||||
1678 | // allocation of the drawing pattern is automatic | |||
1679 | if(bAutomaticCharStyles) | |||
1680 | { | |||
1681 | sSelectStyle = m_sNumCharFmtName; | |||
1682 | } | |||
1683 | } | |||
1684 | } | |||
1685 | nMask <<= 1; | |||
1686 | } | |||
1687 | bool bAllLevelFeature = pActNum->IsFeatureSupported(SvxNumRuleFlags::CONTINUOUS); | |||
1688 | if(bShowOrient && bAllLevelFeature) | |||
1689 | { | |||
1690 | m_xOrientFT->show(); | |||
1691 | m_xOrientLB->show(); | |||
1692 | } | |||
1693 | else | |||
1694 | { | |||
1695 | m_xOrientFT->hide(); | |||
1696 | m_xOrientLB->hide(); | |||
1697 | } | |||
1698 | SetModified(); | |||
1699 | if(!sSelectStyle.isEmpty()) | |||
1700 | { | |||
1701 | m_xCharFmtLB->set_active_text(sSelectStyle); | |||
1702 | CharFmtHdl_Impl(*m_xCharFmtLB); | |||
1703 | bAutomaticCharStyles = true; | |||
1704 | } | |||
1705 | } | |||
1706 | ||||
1707 | void SvxNumOptionsTabPage::CheckForStartValue_Impl(sal_uInt16 nNumberingType) | |||
1708 | { | |||
1709 | bool bIsNull = m_xStartED->get_value() == 0; | |||
1710 | bool bNoZeroAllowed = nNumberingType < SVX_NUM_ARABIC || | |||
1711 | SVX_NUM_CHARS_UPPER_LETTER_N == nNumberingType || | |||
1712 | SVX_NUM_CHARS_LOWER_LETTER_N == nNumberingType; | |||
1713 | m_xStartED->set_min(bNoZeroAllowed ? 1 : 0); | |||
1714 | if (bIsNull && bNoZeroAllowed) | |||
1715 | EditModifyHdl_Impl(*m_xStartED); | |||
1716 | } | |||
1717 | ||||
1718 | IMPL_LINK(SvxNumOptionsTabPage, OrientHdl_Impl, weld::ComboBox&, rBox, void)void SvxNumOptionsTabPage::LinkStubOrientHdl_Impl(void * instance , weld::ComboBox& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->OrientHdl_Impl(data); } void SvxNumOptionsTabPage ::OrientHdl_Impl(weld::ComboBox& rBox) | |||
1719 | { | |||
1720 | sal_Int32 nPos = rBox.get_active(); | |||
1721 | nPos ++; // no VERT_NONE | |||
1722 | ||||
1723 | sal_uInt16 nMask = 1; | |||
1724 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1725 | { | |||
1726 | if(nActNumLvl & nMask) | |||
1727 | { | |||
1728 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
1729 | if(SVX_NUM_BITMAP == (aNumFmt.GetNumberingType()&(~LINK_TOKEN0x80))) | |||
1730 | { | |||
1731 | const SvxBrushItem* pBrushItem = aNumFmt.GetBrush(); | |||
1732 | const Size& rSize = aNumFmt.GetGraphicSize(); | |||
1733 | sal_Int16 eOrient = static_cast<sal_Int16>(nPos); | |||
1734 | aNumFmt.SetGraphicBrush( pBrushItem, &rSize, &eOrient ); | |||
1735 | pActNum->SetLevel(i, aNumFmt); | |||
1736 | } | |||
1737 | } | |||
1738 | nMask <<= 1; | |||
1739 | } | |||
1740 | SetModified(false); | |||
1741 | } | |||
1742 | ||||
1743 | IMPL_LINK(SvxNumOptionsTabPage, SameLevelHdl_Impl, weld::ToggleButton&, rBox, void)void SvxNumOptionsTabPage::LinkStubSameLevelHdl_Impl(void * instance , weld::ToggleButton& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->SameLevelHdl_Impl(data); } void SvxNumOptionsTabPage ::SameLevelHdl_Impl(weld::ToggleButton& rBox) | |||
1744 | { | |||
1745 | bool bSet = rBox.get_active(); | |||
1746 | pActNum->SetContinuousNumbering(bSet); | |||
1747 | bool bRepaint = false; | |||
1748 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1749 | { | |||
1750 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
1751 | if(aNumFmt.GetNumberingType() != SVX_NUM_NUMBER_NONE) | |||
1752 | { | |||
1753 | bRepaint = true; | |||
1754 | break; | |||
1755 | } | |||
1756 | } | |||
1757 | SetModified(bRepaint); | |||
1758 | InitControls(); | |||
1759 | } | |||
1760 | ||||
1761 | IMPL_LINK(SvxNumOptionsTabPage, BulColorHdl_Impl, ColorListBox&, rColorBox, void)void SvxNumOptionsTabPage::LinkStubBulColorHdl_Impl(void * instance , ColorListBox& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->BulColorHdl_Impl(data); } void SvxNumOptionsTabPage ::BulColorHdl_Impl(ColorListBox& rColorBox) | |||
1762 | { | |||
1763 | Color nSetColor = rColorBox.GetSelectEntryColor(); | |||
1764 | ||||
1765 | sal_uInt16 nMask = 1; | |||
1766 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1767 | { | |||
1768 | if(nActNumLvl & nMask) | |||
1769 | { | |||
1770 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
1771 | aNumFmt.SetBulletColor(nSetColor); | |||
1772 | pActNum->SetLevel(i, aNumFmt); | |||
1773 | } | |||
1774 | nMask <<= 1; | |||
1775 | } | |||
1776 | SetModified(); | |||
1777 | } | |||
1778 | ||||
1779 | IMPL_LINK(SvxNumOptionsTabPage, BulRelSizeHdl_Impl, weld::MetricSpinButton&, rField, void)void SvxNumOptionsTabPage::LinkStubBulRelSizeHdl_Impl(void * instance , weld::MetricSpinButton& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->BulRelSizeHdl_Impl(data); } void SvxNumOptionsTabPage ::BulRelSizeHdl_Impl(weld::MetricSpinButton& rField) | |||
1780 | { | |||
1781 | sal_uInt16 nRelSize = rField.get_value(FieldUnit::PERCENT); | |||
1782 | ||||
1783 | sal_uInt16 nMask = 1; | |||
1784 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1785 | { | |||
1786 | if(nActNumLvl & nMask) | |||
1787 | { | |||
1788 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
1789 | aNumFmt.SetBulletRelSize(nRelSize); | |||
1790 | pActNum->SetLevel(i, aNumFmt); | |||
1791 | } | |||
1792 | nMask <<= 1; | |||
1793 | } | |||
1794 | SetModified(); | |||
1795 | } | |||
1796 | ||||
1797 | IMPL_LINK(SvxNumOptionsTabPage, GraphicHdl_Impl, const OString&, rIdent, void)void SvxNumOptionsTabPage::LinkStubGraphicHdl_Impl(void * instance , const OString& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->GraphicHdl_Impl(data); } void SvxNumOptionsTabPage ::GraphicHdl_Impl(const OString& rIdent) | |||
1798 | { | |||
1799 | OUString aGrfName; | |||
1800 | Size aSize; | |||
1801 | bool bSucc(false); | |||
1802 | SvxOpenGraphicDialog aGrfDlg(CuiResId(RID_SVXSTR_EDIT_GRAPHICreinterpret_cast<char const *>("RID_SVXSTR_EDIT_GRAPHIC" "\004" u8"Link")), GetFrameWeld()); | |||
1803 | ||||
1804 | OString sNumber; | |||
1805 | if (rIdent.startsWith("gallery", &sNumber)) | |||
1806 | { | |||
1807 | auto idx = sNumber.toUInt32(); | |||
1808 | if (idx < aGrfNames.size()) | |||
1809 | { | |||
1810 | aGrfName = aGrfNames[idx]; | |||
1811 | Graphic aGraphic; | |||
1812 | if(GalleryExplorer::GetGraphicObj( GALLERY_THEME_BULLETS3, idx, &aGraphic)) | |||
1813 | { | |||
1814 | aSize = SvxNumberFormat::GetGraphicSizeMM100(&aGraphic); | |||
1815 | bSucc = true; | |||
1816 | } | |||
1817 | } | |||
1818 | } | |||
1819 | else if (rIdent == "fromfile") | |||
1820 | { | |||
1821 | aGrfDlg.EnableLink( false ); | |||
1822 | aGrfDlg.AsLink( false ); | |||
1823 | if ( !aGrfDlg.Execute() ) | |||
1824 | { | |||
1825 | // memorize selected filter | |||
1826 | aGrfName = aGrfDlg.GetPath(); | |||
1827 | ||||
1828 | Graphic aGraphic; | |||
1829 | if( !aGrfDlg.GetGraphic(aGraphic) ) | |||
1830 | { | |||
1831 | aSize = SvxNumberFormat::GetGraphicSizeMM100(&aGraphic); | |||
1832 | bSucc = true; | |||
1833 | } | |||
1834 | } | |||
1835 | } | |||
1836 | if(!bSucc) | |||
1837 | return; | |||
1838 | ||||
1839 | aSize = OutputDevice::LogicToLogic(aSize, MapMode(MapUnit::Map100thMM), MapMode(eCoreUnit)); | |||
1840 | ||||
1841 | sal_uInt16 nMask = 1; | |||
1842 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1843 | { | |||
1844 | if(nActNumLvl & nMask) | |||
1845 | { | |||
1846 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
1847 | aNumFmt.SetCharFormatName(m_sNumCharFmtName); | |||
1848 | aNumFmt.SetGraphic(aGrfName); | |||
1849 | ||||
1850 | // set size for a later comparison | |||
1851 | const SvxBrushItem* pBrushItem = aNumFmt.GetBrush(); | |||
1852 | // initiate asynchronous loading | |||
1853 | sal_Int16 eOrient = aNumFmt.GetVertOrient(); | |||
1854 | aNumFmt.SetGraphicBrush( pBrushItem, &aSize, &eOrient ); | |||
1855 | aInitSize[i] = aNumFmt.GetGraphicSize(); | |||
1856 | ||||
1857 | pActNum->SetLevel(i, aNumFmt); | |||
1858 | } | |||
1859 | nMask <<= 1; | |||
1860 | } | |||
1861 | m_xRatioCB->set_sensitive(true); | |||
1862 | m_xWidthFT->set_sensitive(true); | |||
1863 | m_xHeightFT->set_sensitive(true); | |||
1864 | m_xWidthMF->set_sensitive(true); | |||
1865 | m_xHeightMF->set_sensitive(true); | |||
1866 | SetMetricValue(*m_xWidthMF, aSize.Width(), eCoreUnit); | |||
1867 | SetMetricValue(*m_xHeightMF, aSize.Height(), eCoreUnit); | |||
1868 | m_xOrientFT->set_sensitive(true); | |||
1869 | m_xOrientLB->set_sensitive(true); | |||
1870 | SetModified(); | |||
1871 | //needed due to asynchronous loading of graphics in the SvxBrushItem | |||
1872 | aInvalidateTimer.Start(); | |||
1873 | } | |||
1874 | ||||
1875 | IMPL_LINK_NOARG(SvxNumOptionsTabPage, PopupActivateHdl_Impl, weld::ToggleButton&, void)void SvxNumOptionsTabPage::LinkStubPopupActivateHdl_Impl(void * instance, weld::ToggleButton& data) { return static_cast <SvxNumOptionsTabPage *>(instance)->PopupActivateHdl_Impl (data); } void SvxNumOptionsTabPage::PopupActivateHdl_Impl(__attribute__ ((unused)) weld::ToggleButton&) | |||
1876 | { | |||
1877 | if (m_xGalleryMenu) | |||
1878 | return; | |||
1879 | ||||
1880 | m_xGalleryMenu = m_xBuilder->weld_menu("gallerysubmenu"); | |||
1881 | weld::WaitObject aWait(GetFrameWeld()); | |||
1882 | ||||
1883 | if (!GalleryExplorer::FillObjList(GALLERY_THEME_BULLETS3, aGrfNames)) | |||
1884 | return; | |||
1885 | ||||
1886 | GalleryExplorer::BeginLocking(GALLERY_THEME_BULLETS3); | |||
1887 | ||||
1888 | Graphic aGraphic; | |||
1889 | OUString sGrfName; | |||
1890 | ScopedVclPtrInstance< VirtualDevice > pVD; | |||
1891 | size_t i = 0; | |||
1892 | for (const auto & grfName : aGrfNames) | |||
1893 | { | |||
1894 | sGrfName = grfName; | |||
1895 | OUString sItemId = "gallery" + OUString::number(i); | |||
1896 | INetURLObject aObj(sGrfName); | |||
1897 | if(aObj.GetProtocol() == INetProtocol::File) | |||
1898 | sGrfName = aObj.PathToFileName(); | |||
1899 | if(GalleryExplorer::GetGraphicObj( GALLERY_THEME_BULLETS3, i, &aGraphic)) | |||
1900 | { | |||
1901 | BitmapEx aBitmap(aGraphic.GetBitmapEx()); | |||
1902 | Size aSize(aBitmap.GetSizePixel()); | |||
1903 | if(aSize.Width() > MAX_BMP_WIDTH16 || | |||
1904 | aSize.Height() > MAX_BMP_HEIGHT16) | |||
1905 | { | |||
1906 | bool bWidth = aSize.Width() > aSize.Height(); | |||
1907 | double nScale = bWidth ? | |||
1908 | double(MAX_BMP_WIDTH16) / static_cast<double>(aSize.Width()): | |||
1909 | double(MAX_BMP_HEIGHT16) / static_cast<double>(aSize.Height()); | |||
1910 | aBitmap.Scale(nScale, nScale); | |||
1911 | } | |||
1912 | pVD->SetOutputSizePixel(aBitmap.GetSizePixel(), false); | |||
1913 | pVD->DrawBitmapEx(Point(), aBitmap); | |||
1914 | m_xGalleryMenu->append(sItemId, sGrfName, *pVD); | |||
1915 | } | |||
1916 | else | |||
1917 | { | |||
1918 | m_xGalleryMenu->append(sItemId, sGrfName); | |||
1919 | } | |||
1920 | ++i; | |||
1921 | } | |||
1922 | GalleryExplorer::EndLocking(GALLERY_THEME_BULLETS3); | |||
1923 | } | |||
1924 | ||||
1925 | IMPL_LINK_NOARG(SvxNumOptionsTabPage, BulletHdl_Impl, weld::Button&, void)void SvxNumOptionsTabPage::LinkStubBulletHdl_Impl(void * instance , weld::Button& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->BulletHdl_Impl(data); } void SvxNumOptionsTabPage ::BulletHdl_Impl(__attribute__ ((unused)) weld::Button&) | |||
1926 | { | |||
1927 | SvxCharacterMap aMap(GetFrameWeld(), nullptr, nullptr); | |||
1928 | ||||
1929 | sal_uInt16 nMask = 1; | |||
1930 | const vcl::Font* pFmtFont = nullptr; | |||
1931 | bool bSameBullet = true; | |||
1932 | sal_UCS4 cBullet = 0; | |||
1933 | bool bFirst = true; | |||
1934 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1935 | { | |||
1936 | if(nActNumLvl & nMask) | |||
1937 | { | |||
1938 | const SvxNumberFormat& rCurFmt = pActNum->GetLevel(i); | |||
1939 | if(bFirst) | |||
1940 | { | |||
1941 | cBullet = rCurFmt.GetBulletChar(); | |||
1942 | } | |||
1943 | else if(rCurFmt.GetBulletChar() != cBullet ) | |||
1944 | { | |||
1945 | bSameBullet = false; | |||
1946 | break; | |||
1947 | } | |||
1948 | if(!pFmtFont) | |||
1949 | pFmtFont = rCurFmt.GetBulletFont(); | |||
1950 | bFirst = false; | |||
1951 | } | |||
1952 | nMask <<= 1; | |||
1953 | ||||
1954 | } | |||
1955 | ||||
1956 | if (pFmtFont) | |||
1957 | aMap.SetCharFont(*pFmtFont); | |||
1958 | else | |||
1959 | aMap.SetCharFont(aActBulletFont); | |||
1960 | if (bSameBullet) | |||
1961 | aMap.SetChar(cBullet); | |||
1962 | if (aMap.run() != RET_OK) | |||
1963 | return; | |||
1964 | ||||
1965 | // change Font Numrules | |||
1966 | aActBulletFont = aMap.GetCharFont(); | |||
1967 | ||||
1968 | sal_uInt16 _nMask = 1; | |||
1969 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
1970 | { | |||
1971 | if(nActNumLvl & _nMask) | |||
1972 | { | |||
1973 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
1974 | aNumFmt.SetBulletFont(&aActBulletFont); | |||
1975 | aNumFmt.SetBulletChar(aMap.GetChar()); | |||
1976 | pActNum->SetLevel(i, aNumFmt); | |||
1977 | } | |||
1978 | _nMask <<= 1; | |||
1979 | } | |||
1980 | ||||
1981 | SetModified(); | |||
1982 | } | |||
1983 | ||||
1984 | IMPL_LINK( SvxNumOptionsTabPage, SizeHdl_Impl, weld::MetricSpinButton&, rField, void)void SvxNumOptionsTabPage::LinkStubSizeHdl_Impl(void * instance , weld::MetricSpinButton& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->SizeHdl_Impl(data); } void SvxNumOptionsTabPage ::SizeHdl_Impl(weld::MetricSpinButton& rField) | |||
1985 | { | |||
1986 | bool bWidth = &rField == m_xWidthMF.get(); | |||
1987 | bLastWidthModified = bWidth; | |||
1988 | bool bRatio = m_xRatioCB->get_active(); | |||
1989 | long nWidthVal = static_cast<long>(m_xWidthMF->denormalize(m_xWidthMF->get_value(FieldUnit::MM_100TH))); | |||
1990 | long nHeightVal = static_cast<long>(m_xHeightMF->denormalize(m_xHeightMF->get_value(FieldUnit::MM_100TH))); | |||
1991 | nWidthVal = OutputDevice::LogicToLogic( nWidthVal , | |||
1992 | MapUnit::Map100thMM, eCoreUnit ); | |||
1993 | nHeightVal = OutputDevice::LogicToLogic( nHeightVal, | |||
1994 | MapUnit::Map100thMM, eCoreUnit); | |||
1995 | double fSizeRatio; | |||
1996 | ||||
1997 | bool bRepaint = false; | |||
1998 | sal_uInt16 nMask = 1; | |||
1999 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
2000 | { | |||
2001 | if(nActNumLvl & nMask) | |||
2002 | { | |||
2003 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
2004 | if(SVX_NUM_BITMAP == (aNumFmt.GetNumberingType()&(~LINK_TOKEN0x80))) | |||
2005 | { | |||
2006 | Size aSize(aNumFmt.GetGraphicSize() ); | |||
2007 | Size aSaveSize(aSize); | |||
2008 | ||||
2009 | if (aInitSize[i].Height()) | |||
2010 | fSizeRatio = static_cast<double>(aInitSize[i].Width()) / static_cast<double>(aInitSize[i].Height()); | |||
2011 | else | |||
2012 | fSizeRatio = double(1); | |||
2013 | ||||
2014 | if(bWidth) | |||
2015 | { | |||
2016 | long nDelta = nWidthVal - aInitSize[i].Width(); | |||
2017 | aSize.setWidth( nWidthVal ); | |||
2018 | if (bRatio) | |||
2019 | { | |||
2020 | aSize.setHeight( aInitSize[i].Height() + static_cast<long>(static_cast<double>(nDelta) / fSizeRatio) ); | |||
2021 | m_xHeightMF->set_value(m_xHeightMF->normalize( | |||
2022 | OutputDevice::LogicToLogic( aSize.Height(), eCoreUnit, MapUnit::Map100thMM )), | |||
2023 | FieldUnit::MM_100TH); | |||
2024 | } | |||
2025 | } | |||
2026 | else | |||
2027 | { | |||
2028 | long nDelta = nHeightVal - aInitSize[i].Height(); | |||
2029 | aSize.setHeight( nHeightVal ); | |||
2030 | if (bRatio) | |||
2031 | { | |||
2032 | aSize.setWidth( aInitSize[i].Width() + static_cast<long>(static_cast<double>(nDelta) * fSizeRatio) ); | |||
2033 | m_xWidthMF->set_value(m_xWidthMF->normalize( | |||
2034 | OutputDevice::LogicToLogic( aSize.Width(), eCoreUnit, MapUnit::Map100thMM )), | |||
2035 | FieldUnit::MM_100TH); | |||
2036 | } | |||
2037 | } | |||
2038 | const SvxBrushItem* pBrushItem = aNumFmt.GetBrush(); | |||
2039 | sal_Int16 eOrient = aNumFmt.GetVertOrient(); | |||
2040 | if(aSize != aSaveSize) | |||
2041 | bRepaint = true; | |||
2042 | aNumFmt.SetGraphicBrush( pBrushItem, &aSize, &eOrient ); | |||
2043 | pActNum->SetLevel(i, aNumFmt); | |||
2044 | } | |||
2045 | } | |||
2046 | nMask <<= 1; | |||
2047 | } | |||
2048 | SetModified(bRepaint); | |||
2049 | } | |||
2050 | ||||
2051 | IMPL_LINK(SvxNumOptionsTabPage, RatioHdl_Impl, weld::ToggleButton&, rBox, void)void SvxNumOptionsTabPage::LinkStubRatioHdl_Impl(void * instance , weld::ToggleButton& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->RatioHdl_Impl(data); } void SvxNumOptionsTabPage ::RatioHdl_Impl(weld::ToggleButton& rBox) | |||
2052 | { | |||
2053 | if (rBox.get_active()) | |||
2054 | { | |||
2055 | if (bLastWidthModified) | |||
2056 | SizeHdl_Impl(*m_xWidthMF); | |||
2057 | else | |||
2058 | SizeHdl_Impl(*m_xHeightMF); | |||
2059 | } | |||
2060 | } | |||
2061 | ||||
2062 | IMPL_LINK_NOARG(SvxNumOptionsTabPage, CharFmtHdl_Impl, weld::ComboBox&, void)void SvxNumOptionsTabPage::LinkStubCharFmtHdl_Impl(void * instance , weld::ComboBox& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->CharFmtHdl_Impl(data); } void SvxNumOptionsTabPage ::CharFmtHdl_Impl(__attribute__ ((unused)) weld::ComboBox& ) | |||
2063 | { | |||
2064 | bAutomaticCharStyles = false; | |||
2065 | sal_Int32 nEntryPos = m_xCharFmtLB->get_active(); | |||
2066 | OUString sEntry = m_xCharFmtLB->get_active_text(); | |||
2067 | sal_uInt16 nMask = 1; | |||
2068 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
2069 | { | |||
2070 | if(nActNumLvl & nMask) | |||
2071 | { | |||
2072 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
2073 | if( 0 == nEntryPos ) | |||
2074 | aNumFmt.SetCharFormatName(""); | |||
2075 | else | |||
2076 | { | |||
2077 | if(SVX_NUM_BITMAP != (aNumFmt.GetNumberingType()&(~LINK_TOKEN0x80))) | |||
2078 | aNumFmt.SetCharFormatName(sEntry); | |||
2079 | } | |||
2080 | pActNum->SetLevel(i, aNumFmt); | |||
2081 | } | |||
2082 | nMask <<= 1; | |||
2083 | } | |||
2084 | SetModified(false); | |||
2085 | }; | |||
2086 | ||||
2087 | IMPL_LINK(SvxNumOptionsTabPage, EditModifyHdl_Impl, weld::Entry&, rEdit, void)void SvxNumOptionsTabPage::LinkStubEditModifyHdl_Impl(void * instance , weld::Entry& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->EditModifyHdl_Impl(data); } void SvxNumOptionsTabPage ::EditModifyHdl_Impl(weld::Entry& rEdit) | |||
2088 | { | |||
2089 | EditModifyHdl_Impl(&rEdit); | |||
2090 | } | |||
2091 | ||||
2092 | IMPL_LINK(SvxNumOptionsTabPage, SpinModifyHdl_Impl, weld::SpinButton&, rSpinButton, void)void SvxNumOptionsTabPage::LinkStubSpinModifyHdl_Impl(void * instance , weld::SpinButton& data) { return static_cast<SvxNumOptionsTabPage *>(instance)->SpinModifyHdl_Impl(data); } void SvxNumOptionsTabPage ::SpinModifyHdl_Impl(weld::SpinButton& rSpinButton) | |||
2093 | { | |||
2094 | EditModifyHdl_Impl(&rSpinButton); | |||
2095 | } | |||
2096 | ||||
2097 | void SvxNumOptionsTabPage::EditModifyHdl_Impl(const weld::Entry* pEdit) | |||
2098 | { | |||
2099 | bool bPrefix = pEdit == m_xPrefixED.get(); | |||
2100 | bool bSuffix = pEdit == m_xSuffixED.get(); | |||
2101 | bool bStart = pEdit == m_xStartED.get(); | |||
2102 | sal_uInt16 nMask = 1; | |||
2103 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
2104 | { | |||
2105 | if(nActNumLvl & nMask) | |||
2106 | { | |||
2107 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
2108 | if(bPrefix) | |||
2109 | aNumFmt.SetPrefix(m_xPrefixED->get_text()); | |||
2110 | else if(bSuffix) | |||
2111 | aNumFmt.SetSuffix(m_xSuffixED->get_text()); | |||
2112 | else if(bStart) | |||
2113 | aNumFmt.SetStart(m_xStartED->get_value()); | |||
2114 | pActNum->SetLevel(i, aNumFmt); | |||
2115 | } | |||
2116 | nMask <<= 1; | |||
2117 | } | |||
2118 | SetModified(); | |||
2119 | } | |||
2120 | ||||
2121 | static long lcl_DrawGraphic(VirtualDevice* pVDev, const SvxNumberFormat &rFmt, long nXStart, | |||
2122 | long nYMiddle, long nDivision) | |||
2123 | { | |||
2124 | const SvxBrushItem* pBrushItem = rFmt.GetBrush(); | |||
2125 | long nRet = 0; | |||
2126 | if(pBrushItem) | |||
2127 | { | |||
2128 | const Graphic* pGrf = pBrushItem->GetGraphic(); | |||
2129 | if(pGrf) | |||
2130 | { | |||
2131 | Size aGSize( rFmt.GetGraphicSize() ); | |||
2132 | aGSize.setWidth( aGSize.Width() / nDivision ); | |||
2133 | nRet = aGSize.Width(); | |||
2134 | aGSize.setHeight( aGSize.Height() / nDivision ); | |||
2135 | pGrf->Draw( pVDev, Point(nXStart,nYMiddle - ( aGSize.Height() / 2) ), | |||
2136 | pVDev->PixelToLogic( aGSize ) ); | |||
2137 | } | |||
2138 | } | |||
2139 | return nRet; | |||
2140 | ||||
2141 | } | |||
2142 | ||||
2143 | static long lcl_DrawBullet(VirtualDevice* pVDev, | |||
2144 | const SvxNumberFormat& rFmt, long nXStart, | |||
2145 | long nYStart, const Size& rSize) | |||
2146 | { | |||
2147 | vcl::Font aTmpFont(pVDev->GetFont()); | |||
2148 | ||||
2149 | // via Uno it's possible that no font has been set! | |||
2150 | vcl::Font aFont(rFmt.GetBulletFont() ? *rFmt.GetBulletFont() : aTmpFont); | |||
2151 | Size aTmpSize(rSize); | |||
2152 | aTmpSize.setWidth( aTmpSize.Width() * ( rFmt.GetBulletRelSize()) ); | |||
2153 | aTmpSize.setWidth( aTmpSize.Width() / 100 ) ; | |||
2154 | aTmpSize.setHeight( aTmpSize.Height() * ( rFmt.GetBulletRelSize()) ); | |||
2155 | aTmpSize.setHeight( aTmpSize.Height() / 100 ) ; | |||
2156 | // in case of a height of zero it is drawn in original height | |||
2157 | if(!aTmpSize.Height()) | |||
2158 | aTmpSize.setHeight( 1 ); | |||
2159 | aFont.SetFontSize(aTmpSize); | |||
2160 | aFont.SetTransparent(true); | |||
2161 | Color aBulletColor = rFmt.GetBulletColor(); | |||
2162 | if(aBulletColor == COL_AUTO) | |||
2163 | aBulletColor = pVDev->GetFillColor().IsDark() ? COL_WHITE : COL_BLACK; | |||
2164 | else if(aBulletColor == pVDev->GetFillColor()) | |||
2165 | aBulletColor.Invert(); | |||
2166 | aFont.SetColor(aBulletColor); | |||
2167 | pVDev->SetFont( aFont ); | |||
2168 | sal_UCS4 cChar = rFmt.GetBulletChar(); | |||
2169 | OUString aText(&cChar, 1); | |||
2170 | long nY = nYStart; | |||
2171 | nY -= ((aTmpSize.Height() - rSize.Height())/ 2); | |||
2172 | pVDev->DrawText( Point(nXStart, nY), aText ); | |||
2173 | long nRet = pVDev->GetTextWidth(aText); | |||
2174 | ||||
2175 | pVDev->SetFont(aTmpFont); | |||
2176 | return nRet; | |||
2177 | } | |||
2178 | ||||
2179 | SvxNumberingPreview::SvxNumberingPreview() | |||
2180 | : pActNum(nullptr) | |||
2181 | , bPosition(false) | |||
2182 | , nActLevel(SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
2183 | { | |||
2184 | } | |||
2185 | ||||
2186 | // paint preview of numeration | |||
2187 | void SvxNumberingPreview::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& /*rRect*/) | |||
2188 | { | |||
2189 | Size aSize(rRenderContext.PixelToLogic(GetOutputSizePixel())); | |||
2190 | ||||
2191 | const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); | |||
2192 | const Color aBackColor = rStyleSettings.GetFieldColor(); | |||
2193 | const Color aTextColor = rStyleSettings.GetFieldTextColor(); | |||
2194 | ||||
2195 | ScopedVclPtrInstance<VirtualDevice> pVDev(rRenderContext); | |||
| ||||
2196 | pVDev->EnableRTL(rRenderContext.IsRTLEnabled()); | |||
2197 | pVDev->SetMapMode(rRenderContext.GetMapMode()); | |||
2198 | pVDev->SetOutputSize(aSize); | |||
2199 | ||||
2200 | Color aLineColor(COL_LIGHTGRAY); | |||
2201 | if (aLineColor == aBackColor) | |||
2202 | aLineColor.Invert(); | |||
2203 | pVDev->SetLineColor(aLineColor); | |||
2204 | pVDev->SetFillColor(aBackColor); | |||
2205 | ||||
2206 | if (pActNum) | |||
2207 | { | |||
2208 | long nWidthRelation = 30; // chapter dialog | |||
2209 | ||||
2210 | // height per level | |||
2211 | long nXStep = aSize.Width() / (3 * pActNum->GetLevelCount()); | |||
2212 | if (pActNum->GetLevelCount() < 10) | |||
2213 | nXStep /= 2; | |||
2214 | long nYStart = 4; | |||
2215 | // the whole height mustn't be used for a single level | |||
2216 | long nYStep = (aSize.Height() - 6)/ (pActNum->GetLevelCount() > 1 ? pActNum->GetLevelCount() : 5); | |||
2217 | ||||
2218 | aStdFont = OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getSystemLanguage(), GetDefaultFontFlags::OnlyOne); | |||
2219 | aStdFont.SetColor(aTextColor); | |||
2220 | aStdFont.SetFillColor(aBackColor); | |||
2221 | ||||
2222 | long nFontHeight = nYStep * 6 / 10; | |||
2223 | if (bPosition) | |||
2224 | nFontHeight = nYStep * 15 / 10; | |||
2225 | aStdFont.SetFontSize(Size( 0, nFontHeight )); | |||
2226 | ||||
2227 | SvxNodeNum aNum; | |||
2228 | sal_uInt16 nPreNum = pActNum->GetLevel(0).GetStart(); | |||
2229 | ||||
2230 | if (bPosition) | |||
2231 | { | |||
2232 | long nLineHeight = nFontHeight * 8 / 7; | |||
2233 | sal_uInt8 nStart = 0; | |||
2234 | while (!(nActLevel & (1<<nStart))) | |||
2235 | { | |||
2236 | nStart++; | |||
2237 | } | |||
2238 | if (nStart) | |||
2239 | nStart--; | |||
2240 | sal_uInt8 nEnd = std::min(sal_uInt8(nStart + 3), sal_uInt8(pActNum->GetLevelCount())); | |||
2241 | for (sal_uInt8 nLevel = nStart; nLevel < nEnd; ++nLevel) | |||
2242 | { | |||
2243 | const SvxNumberFormat &rFmt = pActNum->GetLevel(nLevel); | |||
2244 | aNum.GetLevelVal()[nLevel] = rFmt.GetStart(); | |||
2245 | ||||
2246 | long nXStart( 0 ); | |||
2247 | short nTextOffset( 0 ); | |||
2248 | long nNumberXPos( 0 ); | |||
2249 | if (rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION) | |||
2250 | { | |||
2251 | nXStart = rFmt.GetAbsLSpace() / nWidthRelation; | |||
2252 | nTextOffset = rFmt.GetCharTextDistance() / nWidthRelation; | |||
2253 | nNumberXPos = nXStart; | |||
2254 | long nFirstLineOffset = (-rFmt.GetFirstLineOffset()) / nWidthRelation; | |||
2255 | ||||
2256 | if (nFirstLineOffset <= nNumberXPos) | |||
2257 | nNumberXPos = nNumberXPos - nFirstLineOffset; | |||
2258 | else | |||
2259 | nNumberXPos = 0; | |||
2260 | // in draw this is valid | |||
2261 | if (nTextOffset < 0) | |||
2262 | nNumberXPos = nNumberXPos + nTextOffset; | |||
2263 | } | |||
2264 | else if (rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT) | |||
2265 | { | |||
2266 | const long nTmpNumberXPos((rFmt.GetIndentAt() + rFmt.GetFirstLineIndent() ) / nWidthRelation); | |||
2267 | if (nTmpNumberXPos < 0) | |||
2268 | { | |||
2269 | nNumberXPos = 0; | |||
2270 | } | |||
2271 | else | |||
2272 | { | |||
2273 | nNumberXPos = nTmpNumberXPos; | |||
2274 | } | |||
2275 | } | |||
2276 | ||||
2277 | long nBulletWidth = 0; | |||
2278 | if (SVX_NUM_BITMAP == (rFmt.GetNumberingType() &(~LINK_TOKEN0x80))) | |||
2279 | { | |||
2280 | long nYMiddle = nYStart + ( nFontHeight / 2 ); | |||
2281 | nBulletWidth = rFmt.IsShowSymbol() ? lcl_DrawGraphic(pVDev.get(), rFmt, nNumberXPos, nYMiddle, nWidthRelation) : 0; | |||
2282 | } | |||
2283 | else if (SVX_NUM_CHAR_SPECIAL == rFmt.GetNumberingType()) | |||
2284 | { | |||
2285 | nBulletWidth = rFmt.IsShowSymbol() ? lcl_DrawBullet(pVDev.get(), rFmt, nNumberXPos, nYStart, aStdFont.GetFontSize()) : 0; | |||
2286 | } | |||
2287 | else | |||
2288 | { | |||
2289 | pVDev->SetFont(aStdFont); | |||
2290 | aNum.SetLevel(nLevel); | |||
2291 | if (pActNum->IsContinuousNumbering()) | |||
2292 | aNum.GetLevelVal()[nLevel] = nPreNum; | |||
2293 | OUString aText(pActNum->MakeNumString( aNum )); | |||
2294 | vcl::Font aSaveFont = pVDev->GetFont(); | |||
2295 | vcl::Font aColorFont(aSaveFont); | |||
2296 | Color aTmpBulletColor = rFmt.GetBulletColor(); | |||
2297 | if (aTmpBulletColor == COL_AUTO) | |||
2298 | aTmpBulletColor = aBackColor.IsDark() ? COL_WHITE : COL_BLACK; | |||
2299 | else if (aTmpBulletColor == aBackColor) | |||
2300 | aTmpBulletColor.Invert(); | |||
2301 | aColorFont.SetColor(aTmpBulletColor); | |||
2302 | pVDev->SetFont(aColorFont); | |||
2303 | pVDev->DrawText(Point(nNumberXPos, nYStart), aText); | |||
2304 | pVDev->SetFont(aSaveFont); | |||
2305 | nBulletWidth = pVDev->GetTextWidth(aText); | |||
2306 | nPreNum++; | |||
2307 | } | |||
2308 | if (rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT && | |||
2309 | rFmt.GetLabelFollowedBy() == SvxNumberFormat::SPACE ) | |||
2310 | { | |||
2311 | pVDev->SetFont(aStdFont); | |||
2312 | OUString aText(' '); | |||
2313 | pVDev->DrawText( Point(nNumberXPos, nYStart), aText ); | |||
2314 | nBulletWidth = nBulletWidth + pVDev->GetTextWidth(aText); | |||
2315 | } | |||
2316 | ||||
2317 | long nTextXPos( 0 ); | |||
2318 | if (rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION) | |||
2319 | { | |||
2320 | nTextXPos = nXStart; | |||
2321 | if (nTextOffset < 0) | |||
2322 | nTextXPos = nTextXPos + nTextOffset; | |||
2323 | if (nNumberXPos + nBulletWidth + nTextOffset > nTextXPos) | |||
2324 | nTextXPos = nNumberXPos + nBulletWidth + nTextOffset; | |||
2325 | } | |||
2326 | else if (rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT) | |||
2327 | { | |||
2328 | switch (rFmt.GetLabelFollowedBy()) | |||
2329 | { | |||
2330 | case SvxNumberFormat::LISTTAB: | |||
2331 | { | |||
2332 | nTextXPos = rFmt.GetListtabPos() / nWidthRelation; | |||
2333 | if (nTextXPos < nNumberXPos + nBulletWidth) | |||
2334 | { | |||
2335 | nTextXPos = nNumberXPos + nBulletWidth; | |||
2336 | } | |||
2337 | } | |||
2338 | break; | |||
2339 | case SvxNumberFormat::SPACE: | |||
2340 | case SvxNumberFormat::NOTHING: | |||
2341 | case SvxNumberFormat::NEWLINE: | |||
2342 | { | |||
2343 | nTextXPos = nNumberXPos + nBulletWidth; | |||
2344 | } | |||
2345 | break; | |||
2346 | } | |||
2347 | ||||
2348 | nXStart = rFmt.GetIndentAt() / nWidthRelation; | |||
2349 | } | |||
2350 | ||||
2351 | ::tools::Rectangle aRect1(Point(nTextXPos, nYStart + nFontHeight / 2), Size(aSize.Width() / 2, 2)); | |||
2352 | pVDev->SetFillColor(aBackColor); | |||
2353 | pVDev->DrawRect(aRect1); | |||
2354 | ||||
2355 | ::tools::Rectangle aRect2(Point(nXStart, nYStart + nLineHeight + nFontHeight / 2 ), Size(aSize.Width() / 2, 2)); | |||
2356 | pVDev->DrawRect(aRect2); | |||
2357 | nYStart += 2 * nLineHeight; | |||
2358 | } | |||
2359 | } | |||
2360 | else | |||
2361 | { | |||
2362 | //#i5153# painting gray or black rectangles as 'normal' numbering text | |||
2363 | long nWidth = pVDev->GetTextWidth("Preview"); | |||
2364 | long nTextHeight = pVDev->GetTextHeight(); | |||
2365 | long nRectHeight = nTextHeight * 2 / 3; | |||
2366 | long nTopOffset = nTextHeight - nRectHeight; | |||
2367 | Color aBlackColor(COL_BLACK); | |||
2368 | if (aBlackColor == aBackColor) | |||
2369 | aBlackColor.Invert(); | |||
2370 | ||||
2371 | for (sal_uInt16 nLevel = 0; nLevel < pActNum->GetLevelCount(); ++nLevel, nYStart = nYStart + nYStep) | |||
2372 | { | |||
2373 | const SvxNumberFormat &rFmt = pActNum->GetLevel(nLevel); | |||
2374 | aNum.GetLevelVal()[ nLevel ] = rFmt.GetStart(); | |||
2375 | long nXStart( 0 ); | |||
2376 | pVDev->SetFillColor( aBackColor ); | |||
2377 | ||||
2378 | if (rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION) | |||
2379 | { | |||
2380 | nXStart = rFmt.GetAbsLSpace() / nWidthRelation; | |||
2381 | } | |||
2382 | else if (rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT) | |||
2383 | { | |||
2384 | const long nTmpXStart((rFmt.GetIndentAt() + rFmt.GetFirstLineIndent() ) / nWidthRelation); | |||
2385 | if (nTmpXStart < 0) | |||
2386 | { | |||
2387 | nXStart = 0; | |||
2388 | } | |||
2389 | else | |||
2390 | { | |||
2391 | nXStart = nTmpXStart; | |||
2392 | } | |||
2393 | } | |||
2394 | nXStart /= 2; | |||
2395 | nXStart += 2; | |||
2396 | long nTextOffset = 2 * nXStep; | |||
2397 | if (SVX_NUM_BITMAP == (rFmt.GetNumberingType()&(~LINK_TOKEN0x80))) | |||
2398 | { | |||
2399 | if (rFmt.IsShowSymbol()) | |||
2400 | { | |||
2401 | long nYMiddle = nYStart + ( nFontHeight / 2 ); | |||
2402 | nTextOffset = lcl_DrawGraphic(pVDev.get(), rFmt, nXStart, nYMiddle, nWidthRelation); | |||
2403 | nTextOffset = nTextOffset + nXStep; | |||
2404 | } | |||
2405 | } | |||
2406 | else if (SVX_NUM_CHAR_SPECIAL == rFmt.GetNumberingType()) | |||
2407 | { | |||
2408 | if (rFmt.IsShowSymbol()) | |||
2409 | { | |||
2410 | nTextOffset = lcl_DrawBullet(pVDev.get(), rFmt, nXStart, nYStart, aStdFont.GetFontSize()); | |||
2411 | nTextOffset = nTextOffset + nXStep; | |||
2412 | } | |||
2413 | } | |||
2414 | else | |||
2415 | { | |||
2416 | vcl::Font aFont(aStdFont); | |||
2417 | Size aTmpSize(aStdFont.GetFontSize()); | |||
2418 | if(pActNum->IsFeatureSupported(SvxNumRuleFlags::BULLET_REL_SIZE)) | |||
2419 | { | |||
2420 | aTmpSize.setWidth( aTmpSize.Width() * ( rFmt.GetBulletRelSize()) ); | |||
2421 | aTmpSize.setWidth( aTmpSize.Width() / 100 ) ; | |||
2422 | aTmpSize.setHeight( aTmpSize.Height() * ( rFmt.GetBulletRelSize()) ); | |||
2423 | aTmpSize.setHeight( aTmpSize.Height() / 100 ) ; | |||
2424 | } | |||
2425 | if(!aTmpSize.Height()) | |||
2426 | aTmpSize.setHeight( 1 ); | |||
2427 | aFont.SetFontSize(aTmpSize); | |||
2428 | Color aTmpBulletColor = rFmt.GetBulletColor(); | |||
2429 | if (aTmpBulletColor == COL_AUTO) | |||
2430 | aTmpBulletColor = aBackColor.IsDark() ? COL_WHITE : COL_BLACK; | |||
2431 | else if (aTmpBulletColor == aBackColor) | |||
2432 | aTmpBulletColor.Invert(); | |||
2433 | aFont.SetColor(aTmpBulletColor); | |||
2434 | pVDev->SetFont(aFont); | |||
2435 | aNum.SetLevel( nLevel ); | |||
2436 | if (pActNum->IsContinuousNumbering()) | |||
2437 | aNum.GetLevelVal()[nLevel] = nPreNum; | |||
2438 | OUString aText(pActNum->MakeNumString(aNum)); | |||
2439 | long nY = nYStart; | |||
2440 | nY -= (pVDev->GetTextHeight() - nTextHeight - pVDev->GetFontMetric().GetDescent()); | |||
2441 | pVDev->DrawText(Point(nXStart, nY), aText); | |||
2442 | nTextOffset = pVDev->GetTextWidth(aText); | |||
2443 | nTextOffset = nTextOffset + nXStep; | |||
2444 | nPreNum++; | |||
2445 | pVDev->SetFont(aStdFont); | |||
2446 | } | |||
2447 | //#i5153# the selected rectangle(s) should be black | |||
2448 | if (0 != (nActLevel & (1<<nLevel))) | |||
2449 | { | |||
2450 | pVDev->SetFillColor( aBlackColor ); | |||
2451 | pVDev->SetLineColor( aBlackColor ); | |||
2452 | } | |||
2453 | else | |||
2454 | { | |||
2455 | //#i5153# unselected levels are gray | |||
2456 | pVDev->SetFillColor( aLineColor ); | |||
2457 | pVDev->SetLineColor( aLineColor ); | |||
2458 | } | |||
2459 | ::tools::Rectangle aRect1(Point(nXStart + nTextOffset, nYStart + nTopOffset), Size(nWidth, nRectHeight)); | |||
2460 | pVDev->DrawRect(aRect1); | |||
2461 | } | |||
2462 | } | |||
2463 | } | |||
2464 | rRenderContext.DrawOutDev(Point(), aSize, Point(), aSize, *pVDev); | |||
2465 | } | |||
2466 | ||||
2467 | ||||
2468 | //See uiconfig/swriter/ui/outlinepositionpage.ui for effectively a duplicate | |||
2469 | //dialog to this one, except with a different preview window impl. | |||
2470 | //TODO, determine if SwNumPositionTabPage and SvxNumPositionTabPage can be | |||
2471 | //merged | |||
2472 | SvxNumPositionTabPage::SvxNumPositionTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) | |||
2473 | : SfxTabPage(pPage, pController, "cui/ui/numberingpositionpage.ui", "NumberingPositionPage", &rSet) | |||
2474 | , m_pLevelHdlEvent(nullptr) | |||
2475 | , nActNumLvl(1) | |||
2476 | , nNumItemId(SID_ATTR_NUMBERING_RULE( 10000 + 855 )) | |||
2477 | , bModified(false) | |||
2478 | , bPreset(false) | |||
2479 | , bInInintControl(false) | |||
2480 | , bLabelAlignmentPosAndSpaceModeActive(false) | |||
2481 | , m_xLevelLB(m_xBuilder->weld_tree_view("levellb")) | |||
2482 | , m_xDistBorderFT(m_xBuilder->weld_label("indent")) | |||
2483 | , m_xDistBorderMF(m_xBuilder->weld_metric_spin_button("indentmf", FieldUnit::CM)) | |||
2484 | , m_xRelativeCB(m_xBuilder->weld_check_button("relative")) | |||
2485 | , m_xIndentFT(m_xBuilder->weld_label("numberingwidth")) | |||
2486 | , m_xIndentMF(m_xBuilder->weld_metric_spin_button("numberingwidthmf", FieldUnit::CM)) | |||
2487 | , m_xDistNumFT(m_xBuilder->weld_label("numdist")) | |||
2488 | , m_xDistNumMF(m_xBuilder->weld_metric_spin_button("numdistmf", FieldUnit::CM)) | |||
2489 | , m_xAlignFT(m_xBuilder->weld_label("numalign")) | |||
2490 | , m_xAlignLB(m_xBuilder->weld_combo_box("numalignlb")) | |||
2491 | , m_xLabelFollowedByFT(m_xBuilder->weld_label("numfollowedby")) | |||
2492 | , m_xLabelFollowedByLB(m_xBuilder->weld_combo_box("numfollowedbylb")) | |||
2493 | , m_xListtabFT(m_xBuilder->weld_label("at")) | |||
2494 | , m_xListtabMF(m_xBuilder->weld_metric_spin_button("atmf", FieldUnit::CM)) | |||
2495 | , m_xAlign2FT(m_xBuilder->weld_label("num2align")) | |||
2496 | , m_xAlign2LB(m_xBuilder->weld_combo_box("num2alignlb")) | |||
2497 | , m_xAlignedAtFT(m_xBuilder->weld_label("alignedat")) | |||
2498 | , m_xAlignedAtMF(m_xBuilder->weld_metric_spin_button("alignedatmf", FieldUnit::CM)) | |||
2499 | , m_xIndentAtFT(m_xBuilder->weld_label("indentat")) | |||
2500 | , m_xIndentAtMF(m_xBuilder->weld_metric_spin_button("indentatmf", FieldUnit::CM)) | |||
2501 | , m_xStandardPB(m_xBuilder->weld_button("standard")) | |||
2502 | , m_xPreviewWIN(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWIN)) | |||
2503 | { | |||
2504 | SetExchangeSupport(); | |||
2505 | ||||
2506 | m_xAlignedAtMF->set_range(0, SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF), FieldUnit::NONE); | |||
2507 | m_xListtabMF->set_range(0, SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF), FieldUnit::NONE); | |||
2508 | m_xIndentAtMF->set_range(0, SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF), FieldUnit::NONE); | |||
2509 | ||||
2510 | m_xRelativeCB->set_active(true); | |||
2511 | m_xAlignLB->connect_changed(LINK(this, SvxNumPositionTabPage, EditModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubEditModifyHdl_Impl )); | |||
2512 | m_xAlign2LB->connect_changed(LINK(this, SvxNumPositionTabPage, EditModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubEditModifyHdl_Impl )); | |||
2513 | for ( sal_Int32 i = 0; i < m_xAlignLB->get_count(); ++i ) | |||
2514 | { | |||
2515 | m_xAlign2LB->append_text(m_xAlignLB->get_text(i)); | |||
2516 | } | |||
2517 | ||||
2518 | Link<weld::MetricSpinButton&,void> aLk3 = LINK(this, SvxNumPositionTabPage, DistanceHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubDistanceHdl_Impl ); | |||
2519 | m_xDistBorderMF->connect_value_changed(aLk3); | |||
2520 | m_xDistNumMF->connect_value_changed(aLk3); | |||
2521 | m_xIndentMF->connect_value_changed(aLk3); | |||
2522 | ||||
2523 | m_xLabelFollowedByLB->connect_changed(LINK(this, SvxNumPositionTabPage, LabelFollowedByHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubLabelFollowedByHdl_Impl )); | |||
2524 | ||||
2525 | m_xListtabMF->connect_value_changed(LINK(this, SvxNumPositionTabPage, ListtabPosHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubListtabPosHdl_Impl )); | |||
2526 | m_xAlignedAtMF->connect_value_changed(LINK(this, SvxNumPositionTabPage, AlignAtHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubAlignAtHdl_Impl )); | |||
2527 | m_xIndentAtMF->connect_value_changed(LINK(this, SvxNumPositionTabPage, IndentAtHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubIndentAtHdl_Impl )); | |||
2528 | ||||
2529 | m_xLevelLB->set_selection_mode(SelectionMode::Multiple); | |||
2530 | m_xLevelLB->connect_changed(LINK(this, SvxNumPositionTabPage, LevelHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubLevelHdl_Impl )); | |||
2531 | m_xRelativeCB->connect_toggled(LINK(this, SvxNumPositionTabPage, RelativeHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubRelativeHdl_Impl )); | |||
2532 | m_xStandardPB->connect_clicked(LINK(this, SvxNumPositionTabPage, StandardHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubStandardHdl_Impl )); | |||
2533 | ||||
2534 | m_xRelativeCB->set_active(bLastRelative); | |||
2535 | m_aPreviewWIN.SetPositionMode(); | |||
2536 | eCoreUnit = rSet.GetPool()->GetMetric(rSet.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 ))); | |||
2537 | } | |||
2538 | ||||
2539 | SvxNumPositionTabPage::~SvxNumPositionTabPage() | |||
2540 | { | |||
2541 | if (m_pLevelHdlEvent) | |||
2542 | { | |||
2543 | Application::RemoveUserEvent(m_pLevelHdlEvent); | |||
2544 | m_pLevelHdlEvent = nullptr; | |||
2545 | } | |||
2546 | m_xPreviewWIN.reset(); | |||
2547 | } | |||
2548 | ||||
2549 | /*-------------------------------------------------------*/ | |||
2550 | ||||
2551 | void SvxNumPositionTabPage::InitControls() | |||
2552 | { | |||
2553 | bInInintControl = true; | |||
2554 | const bool bRelative = !bLabelAlignmentPosAndSpaceModeActive && | |||
2555 | m_xRelativeCB->get_sensitive() && m_xRelativeCB->get_active(); | |||
2556 | const bool bSingleSelection = m_xLevelLB->count_selected_rows() == 1 && | |||
2557 | SAL_MAX_UINT16((sal_uInt16) 0xFFFF) != nActNumLvl; | |||
2558 | ||||
2559 | m_xDistBorderMF->set_sensitive( !bLabelAlignmentPosAndSpaceModeActive && | |||
2560 | ( bSingleSelection || bRelative ) ); | |||
2561 | m_xDistBorderFT->set_sensitive( !bLabelAlignmentPosAndSpaceModeActive && | |||
2562 | ( bSingleSelection || bRelative ) ); | |||
2563 | ||||
2564 | bool bSetDistEmpty = false; | |||
2565 | bool bSameDistBorderNum = !bLabelAlignmentPosAndSpaceModeActive; | |||
2566 | bool bSameDist = !bLabelAlignmentPosAndSpaceModeActive; | |||
2567 | bool bSameIndent = !bLabelAlignmentPosAndSpaceModeActive; | |||
2568 | bool bSameAdjust = true; | |||
2569 | ||||
2570 | bool bSameLabelFollowedBy = bLabelAlignmentPosAndSpaceModeActive; | |||
2571 | bool bSameListtab = bLabelAlignmentPosAndSpaceModeActive; | |||
2572 | bool bSameAlignAt = bLabelAlignmentPosAndSpaceModeActive; | |||
2573 | bool bSameIndentAt = bLabelAlignmentPosAndSpaceModeActive; | |||
2574 | ||||
2575 | const SvxNumberFormat* aNumFmtArr[SVX_MAX_NUM10]; | |||
2576 | sal_uInt16 nMask = 1; | |||
2577 | sal_uInt16 nLvl = SAL_MAX_UINT16((sal_uInt16) 0xFFFF); | |||
2578 | long nFirstBorderTextRelative = -1; | |||
2579 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
2580 | { | |||
2581 | aNumFmtArr[i] = &pActNum->GetLevel(i); | |||
2582 | if(nActNumLvl & nMask) | |||
2583 | { | |||
2584 | if(SAL_MAX_UINT16((sal_uInt16) 0xFFFF) == nLvl) | |||
2585 | nLvl = i; | |||
2586 | ||||
2587 | if( i > nLvl) | |||
2588 | { | |||
2589 | bSameAdjust &= aNumFmtArr[i]->GetNumAdjust() == aNumFmtArr[nLvl]->GetNumAdjust(); | |||
2590 | if ( !bLabelAlignmentPosAndSpaceModeActive ) | |||
2591 | { | |||
2592 | if(bRelative) | |||
2593 | { | |||
2594 | if(nFirstBorderTextRelative == -1) | |||
2595 | nFirstBorderTextRelative = | |||
2596 | (aNumFmtArr[i]->GetAbsLSpace() + aNumFmtArr[i]->GetFirstLineOffset() - | |||
2597 | aNumFmtArr[i - 1]->GetAbsLSpace() + aNumFmtArr[i - 1]->GetFirstLineOffset()); | |||
2598 | else | |||
2599 | bSameDistBorderNum &= nFirstBorderTextRelative == | |||
2600 | (aNumFmtArr[i]->GetAbsLSpace() + aNumFmtArr[i]->GetFirstLineOffset() - | |||
2601 | aNumFmtArr[i - 1]->GetAbsLSpace() + aNumFmtArr[i - 1]->GetFirstLineOffset()); | |||
2602 | } | |||
2603 | else | |||
2604 | bSameDistBorderNum &= | |||
2605 | aNumFmtArr[i]->GetAbsLSpace() - aNumFmtArr[i]->GetFirstLineOffset() == | |||
2606 | aNumFmtArr[i - 1]->GetAbsLSpace() - aNumFmtArr[i - 1]->GetFirstLineOffset(); | |||
2607 | ||||
2608 | bSameDist &= aNumFmtArr[i]->GetCharTextDistance() == aNumFmtArr[nLvl]->GetCharTextDistance(); | |||
2609 | bSameIndent &= aNumFmtArr[i]->GetFirstLineOffset() == aNumFmtArr[nLvl]->GetFirstLineOffset(); | |||
2610 | } | |||
2611 | else | |||
2612 | { | |||
2613 | bSameLabelFollowedBy &= | |||
2614 | aNumFmtArr[i]->GetLabelFollowedBy() == aNumFmtArr[nLvl]->GetLabelFollowedBy(); | |||
2615 | bSameListtab &= | |||
2616 | aNumFmtArr[i]->GetListtabPos() == aNumFmtArr[nLvl]->GetListtabPos(); | |||
2617 | bSameAlignAt &= | |||
2618 | ( ( aNumFmtArr[i]->GetIndentAt() + aNumFmtArr[i]->GetFirstLineIndent() ) | |||
2619 | == ( aNumFmtArr[nLvl]->GetIndentAt() + aNumFmtArr[nLvl]->GetFirstLineIndent() ) ); | |||
2620 | bSameIndentAt &= | |||
2621 | aNumFmtArr[i]->GetIndentAt() == aNumFmtArr[nLvl]->GetIndentAt(); | |||
2622 | } | |||
2623 | } | |||
2624 | } | |||
2625 | nMask <<= 1; | |||
2626 | ||||
2627 | } | |||
2628 | if (SVX_MAX_NUM10 <= nLvl) | |||
2629 | { | |||
2630 | OSL_ENSURE(false, "cannot happen.")do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2630" ": "), "%s", "cannot happen."); } } while (false); | |||
2631 | return; | |||
2632 | } | |||
2633 | ||||
2634 | if(bSameDistBorderNum) | |||
2635 | { | |||
2636 | long nDistBorderNum; | |||
2637 | if(bRelative) | |||
2638 | { | |||
2639 | nDistBorderNum = static_cast<long>(aNumFmtArr[nLvl]->GetAbsLSpace())+ aNumFmtArr[nLvl]->GetFirstLineOffset(); | |||
2640 | if(nLvl) | |||
2641 | nDistBorderNum -= static_cast<long>(aNumFmtArr[nLvl - 1]->GetAbsLSpace())+ aNumFmtArr[nLvl - 1]->GetFirstLineOffset(); | |||
2642 | } | |||
2643 | else | |||
2644 | { | |||
2645 | nDistBorderNum = static_cast<long>(aNumFmtArr[nLvl]->GetAbsLSpace())+ aNumFmtArr[nLvl]->GetFirstLineOffset(); | |||
2646 | } | |||
2647 | SetMetricValue(*m_xDistBorderMF, nDistBorderNum, eCoreUnit); | |||
2648 | } | |||
2649 | else | |||
2650 | bSetDistEmpty = true; | |||
2651 | ||||
2652 | if(bSameDist) | |||
2653 | SetMetricValue(*m_xDistNumMF, aNumFmtArr[nLvl]->GetCharTextDistance(), eCoreUnit); | |||
2654 | else | |||
2655 | m_xDistNumMF->set_text(""); | |||
2656 | if(bSameIndent) | |||
2657 | SetMetricValue(*m_xIndentMF, - aNumFmtArr[nLvl]->GetFirstLineOffset(), eCoreUnit); | |||
2658 | else | |||
2659 | m_xIndentMF->set_text(""); | |||
2660 | ||||
2661 | if(bSameAdjust) | |||
2662 | { | |||
2663 | sal_Int32 nPos = 1; // centered | |||
2664 | if(aNumFmtArr[nLvl]->GetNumAdjust() == SvxAdjust::Left) | |||
2665 | nPos = 0; | |||
2666 | else if(aNumFmtArr[nLvl]->GetNumAdjust() == SvxAdjust::Right) | |||
2667 | nPos = 2; | |||
2668 | m_xAlignLB->set_active(nPos); | |||
2669 | m_xAlign2LB->set_active(nPos); | |||
2670 | } | |||
2671 | else | |||
2672 | { | |||
2673 | m_xAlignLB->set_active(-1); | |||
2674 | m_xAlign2LB->set_active(-1); | |||
2675 | } | |||
2676 | ||||
2677 | if ( bSameLabelFollowedBy ) | |||
2678 | { | |||
2679 | sal_Int32 nPos = 0; // LISTTAB | |||
2680 | if ( aNumFmtArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::SPACE ) | |||
2681 | { | |||
2682 | nPos = 1; | |||
2683 | } | |||
2684 | else if ( aNumFmtArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NOTHING ) | |||
2685 | { | |||
2686 | nPos = 2; | |||
2687 | } | |||
2688 | else if ( aNumFmtArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NEWLINE ) | |||
2689 | { | |||
2690 | nPos = 3; | |||
2691 | } | |||
2692 | m_xLabelFollowedByLB->set_active(nPos); | |||
2693 | } | |||
2694 | else | |||
2695 | { | |||
2696 | m_xLabelFollowedByLB->set_active(-1); | |||
2697 | } | |||
2698 | ||||
2699 | if ( aNumFmtArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::LISTTAB ) | |||
2700 | { | |||
2701 | m_xListtabFT->set_sensitive(true); | |||
2702 | m_xListtabMF->set_sensitive(true); | |||
2703 | if ( bSameListtab ) | |||
2704 | { | |||
2705 | SetMetricValue(*m_xListtabMF, aNumFmtArr[nLvl]->GetListtabPos(), eCoreUnit); | |||
2706 | } | |||
2707 | else | |||
2708 | { | |||
2709 | m_xListtabMF->set_text(""); | |||
2710 | } | |||
2711 | } | |||
2712 | else | |||
2713 | { | |||
2714 | m_xListtabFT->set_sensitive(false); | |||
2715 | m_xListtabMF->set_sensitive(false); | |||
2716 | m_xListtabMF->set_text(""); | |||
2717 | } | |||
2718 | ||||
2719 | if ( bSameAlignAt ) | |||
2720 | { | |||
2721 | SetMetricValue(*m_xAlignedAtMF, | |||
2722 | aNumFmtArr[nLvl]->GetIndentAt() + aNumFmtArr[nLvl]->GetFirstLineIndent(), | |||
2723 | eCoreUnit); | |||
2724 | } | |||
2725 | else | |||
2726 | { | |||
2727 | m_xAlignedAtMF->set_text(""); | |||
2728 | } | |||
2729 | ||||
2730 | if ( bSameIndentAt ) | |||
2731 | { | |||
2732 | SetMetricValue(*m_xIndentAtMF, aNumFmtArr[nLvl]->GetIndentAt(), eCoreUnit); | |||
2733 | } | |||
2734 | else | |||
2735 | { | |||
2736 | m_xIndentAtMF->set_text(""); | |||
2737 | } | |||
2738 | ||||
2739 | if ( bSetDistEmpty ) | |||
2740 | m_xDistBorderMF->set_text(""); | |||
2741 | ||||
2742 | bInInintControl = false; | |||
2743 | } | |||
2744 | ||||
2745 | void SvxNumPositionTabPage::ActivatePage(const SfxItemSet& rSet) | |||
2746 | { | |||
2747 | const SfxPoolItem* pItem; | |||
2748 | sal_uInt16 nTmpNumLvl = 1; | |||
2749 | const SfxItemSet* pExampleSet = GetDialogExampleSet(); | |||
2750 | if(pExampleSet) | |||
2751 | { | |||
2752 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_NUM_PRESET( 10000 + 856 ), false, &pItem)) | |||
2753 | bPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
2754 | if(SfxItemState::SET == pExampleSet->GetItemState(SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 ), false, &pItem)) | |||
2755 | nTmpNumLvl = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
2756 | } | |||
2757 | if(SfxItemState::SET == rSet.GetItemState(nNumItemId, false, &pItem)) | |||
2758 | { | |||
2759 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
2760 | } | |||
2761 | bModified = (!pActNum->Get( 0 ) || bPreset); | |||
2762 | if(*pSaveNum != *pActNum || | |||
2763 | nActNumLvl != nTmpNumLvl ) | |||
2764 | { | |||
2765 | *pActNum = *pSaveNum; | |||
2766 | nActNumLvl = nTmpNumLvl; | |||
2767 | sal_uInt16 nMask = 1; | |||
2768 | m_xLevelLB->unselect_all(); | |||
2769 | if (nActNumLvl == SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
2770 | m_xLevelLB->select(pActNum->GetLevelCount()); | |||
2771 | if (nActNumLvl != SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
2772 | for (sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
2773 | { | |||
2774 | if (nActNumLvl & nMask) | |||
2775 | m_xLevelLB->select(i); | |||
2776 | nMask <<= 1 ; | |||
2777 | } | |||
2778 | m_xRelativeCB->set_sensitive(nActNumLvl != 1); | |||
2779 | ||||
2780 | InitPosAndSpaceMode(); | |||
2781 | ShowControlsDependingOnPosAndSpaceMode(); | |||
2782 | ||||
2783 | InitControls(); | |||
2784 | } | |||
2785 | m_aPreviewWIN.SetLevel(nActNumLvl); | |||
2786 | m_aPreviewWIN.Invalidate(); | |||
2787 | } | |||
2788 | ||||
2789 | DeactivateRC SvxNumPositionTabPage::DeactivatePage(SfxItemSet *_pSet) | |||
2790 | { | |||
2791 | if(_pSet) | |||
2792 | { | |||
2793 | if (m_xDistBorderMF->get_sensitive()) | |||
2794 | DistanceHdl_Impl(*m_xDistBorderMF); | |||
2795 | DistanceHdl_Impl(*m_xIndentMF); | |||
2796 | FillItemSet(_pSet); | |||
2797 | } | |||
2798 | return DeactivateRC::LeavePage; | |||
2799 | } | |||
2800 | ||||
2801 | bool SvxNumPositionTabPage::FillItemSet( SfxItemSet* rSet ) | |||
2802 | { | |||
2803 | rSet->Put(SfxUInt16Item(SID_PARAM_CUR_NUM_LEVEL( 10000 + 859 ), nActNumLvl)); | |||
2804 | ||||
2805 | if(bModified && pActNum) | |||
2806 | { | |||
2807 | *pSaveNum = *pActNum; | |||
2808 | rSet->Put(SvxNumBulletItem( *pSaveNum, nNumItemId )); | |||
2809 | rSet->Put(SfxBoolItem(SID_PARAM_NUM_PRESET( 10000 + 856 ), false)); | |||
2810 | } | |||
2811 | return bModified; | |||
2812 | } | |||
2813 | ||||
2814 | void SvxNumPositionTabPage::Reset( const SfxItemSet* rSet ) | |||
2815 | { | |||
2816 | const SfxPoolItem* pItem; | |||
2817 | // in Draw the item exists as WhichId, in Writer only as SlotId | |||
2818 | SfxItemState eState = rSet->GetItemState(SID_ATTR_NUMBERING_RULE( 10000 + 855 ), false, &pItem); | |||
2819 | if(eState != SfxItemState::SET) | |||
2820 | { | |||
2821 | nNumItemId = rSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 )); | |||
2822 | eState = rSet->GetItemState(nNumItemId, false, &pItem); | |||
2823 | ||||
2824 | if( eState != SfxItemState::SET ) | |||
2825 | { | |||
2826 | pItem = &static_cast< const SvxNumBulletItem& >( rSet->Get( nNumItemId ) ); | |||
2827 | eState = SfxItemState::SET; | |||
2828 | } | |||
2829 | ||||
2830 | } | |||
2831 | DBG_ASSERT(eState == SfxItemState::SET, "no item found!")do { if (true && (!(eState == SfxItemState::SET))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2831" ": "), "%s", "no item found!"); } } while (false); | |||
2832 | pSaveNum.reset( new SvxNumRule(*static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule()) ); | |||
2833 | ||||
2834 | // insert levels | |||
2835 | if (!m_xLevelLB->count_selected_rows()) | |||
2836 | { | |||
2837 | for(sal_uInt16 i = 1; i <= pSaveNum->GetLevelCount(); i++) | |||
2838 | m_xLevelLB->append_text(OUString::number(i)); | |||
2839 | if(pSaveNum->GetLevelCount() > 1) | |||
2840 | { | |||
2841 | OUString sEntry = "1 - " + OUString::number( pSaveNum->GetLevelCount() ); | |||
2842 | m_xLevelLB->append_text(sEntry); | |||
2843 | m_xLevelLB->select_text(sEntry); | |||
2844 | } | |||
2845 | else | |||
2846 | m_xLevelLB->select(0); | |||
2847 | } | |||
2848 | else | |||
2849 | m_xLevelLB->select(m_xLevelLB->count_selected_rows() - 1); | |||
2850 | sal_uInt16 nMask = 1; | |||
2851 | m_xLevelLB->unselect_all(); | |||
2852 | if (nActNumLvl == SAL_MAX_UINT16((sal_uInt16) 0xFFFF)) | |||
2853 | { | |||
2854 | m_xLevelLB->select(pSaveNum->GetLevelCount()); | |||
2855 | } | |||
2856 | else | |||
2857 | { | |||
2858 | for(sal_uInt16 i = 0; i < pSaveNum->GetLevelCount(); i++) | |||
2859 | { | |||
2860 | if(nActNumLvl & nMask) | |||
2861 | m_xLevelLB->select(i); | |||
2862 | nMask <<= 1; | |||
2863 | } | |||
2864 | } | |||
2865 | ||||
2866 | if(!pActNum) | |||
2867 | pActNum.reset( new SvxNumRule(*pSaveNum) ); | |||
2868 | else if(*pSaveNum != *pActNum) | |||
2869 | *pActNum = *pSaveNum; | |||
2870 | m_aPreviewWIN.SetNumRule(pActNum.get()); | |||
2871 | ||||
2872 | InitPosAndSpaceMode(); | |||
2873 | ShowControlsDependingOnPosAndSpaceMode(); | |||
2874 | ||||
2875 | InitControls(); | |||
2876 | bModified = false; | |||
2877 | } | |||
2878 | ||||
2879 | void SvxNumPositionTabPage::InitPosAndSpaceMode() | |||
2880 | { | |||
2881 | if ( pActNum == nullptr ) | |||
2882 | { | |||
2883 | SAL_WARN( "cui.tabpages",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.tabpages")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2884" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2884" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2884" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2884" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | |||
2884 | "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.tabpages")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2884" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2884" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2884" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<SvxNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/numpages.cxx" ":" "2884" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
2885 | return; | |||
2886 | } | |||
2887 | ||||
2888 | SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode = | |||
2889 | SvxNumberFormat::LABEL_ALIGNMENT; | |||
2890 | sal_uInt16 nMask = 1; | |||
2891 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); ++i ) | |||
2892 | { | |||
2893 | if(nActNumLvl & nMask) | |||
2894 | { | |||
2895 | SvxNumberFormat aNumFmt( pActNum->GetLevel(i) ); | |||
2896 | ePosAndSpaceMode = aNumFmt.GetPositionAndSpaceMode(); | |||
2897 | if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT ) | |||
2898 | { | |||
2899 | break; | |||
2900 | } | |||
2901 | } | |||
2902 | nMask <<= 1; | |||
2903 | } | |||
2904 | ||||
2905 | bLabelAlignmentPosAndSpaceModeActive = | |||
2906 | ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT; | |||
2907 | } | |||
2908 | ||||
2909 | void SvxNumPositionTabPage::ShowControlsDependingOnPosAndSpaceMode() | |||
2910 | { | |||
2911 | m_xDistBorderFT->set_visible( !bLabelAlignmentPosAndSpaceModeActive ); | |||
2912 | m_xDistBorderMF->set_visible( !bLabelAlignmentPosAndSpaceModeActive ); | |||
2913 | m_xRelativeCB->set_visible( !bLabelAlignmentPosAndSpaceModeActive ); | |||
2914 | m_xIndentFT->set_visible( !bLabelAlignmentPosAndSpaceModeActive ); | |||
2915 | m_xIndentMF->set_visible( !bLabelAlignmentPosAndSpaceModeActive ); | |||
2916 | m_xDistNumFT->set_visible( !bLabelAlignmentPosAndSpaceModeActive && | |||
2917 | pActNum->IsFeatureSupported(SvxNumRuleFlags::CONTINUOUS) ); | |||
2918 | m_xDistNumMF->set_visible( !bLabelAlignmentPosAndSpaceModeActive && | |||
2919 | pActNum->IsFeatureSupported(SvxNumRuleFlags::CONTINUOUS)); | |||
2920 | m_xAlignFT->set_visible( !bLabelAlignmentPosAndSpaceModeActive ); | |||
2921 | m_xAlignLB->set_visible( !bLabelAlignmentPosAndSpaceModeActive ); | |||
2922 | ||||
2923 | m_xLabelFollowedByFT->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2924 | m_xLabelFollowedByLB->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2925 | m_xListtabFT->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2926 | m_xListtabMF->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2927 | m_xAlign2FT->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2928 | m_xAlign2LB->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2929 | m_xAlignedAtFT->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2930 | m_xAlignedAtMF->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2931 | m_xIndentAtFT->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2932 | m_xIndentAtMF->set_visible( bLabelAlignmentPosAndSpaceModeActive ); | |||
2933 | } | |||
2934 | ||||
2935 | std::unique_ptr<SfxTabPage> SvxNumPositionTabPage::Create(weld::Container* pPage, weld::DialogController* pController, | |||
2936 | const SfxItemSet* rAttrSet) | |||
2937 | { | |||
2938 | return std::make_unique<SvxNumPositionTabPage>(pPage, pController, *rAttrSet); | |||
2939 | } | |||
2940 | ||||
2941 | void SvxNumPositionTabPage::SetMetric(FieldUnit eMetric) | |||
2942 | { | |||
2943 | if (eMetric == FieldUnit::MM) | |||
2944 | { | |||
2945 | m_xDistBorderMF->set_digits(1); | |||
2946 | m_xDistNumMF->set_digits(1); | |||
2947 | m_xIndentMF->set_digits(1); | |||
2948 | m_xListtabMF->set_digits(1); | |||
2949 | m_xAlignedAtMF->set_digits(1); | |||
2950 | m_xIndentAtMF->set_digits(1); | |||
2951 | } | |||
2952 | m_xDistBorderMF->set_unit(eMetric); | |||
2953 | m_xDistNumMF->set_unit(eMetric); | |||
2954 | m_xIndentMF->set_unit(eMetric); | |||
2955 | m_xListtabMF->set_unit(eMetric); | |||
2956 | m_xAlignedAtMF->set_unit(eMetric); | |||
2957 | m_xIndentAtMF->set_unit(eMetric); | |||
2958 | } | |||
2959 | ||||
2960 | IMPL_LINK_NOARG(SvxNumPositionTabPage, EditModifyHdl_Impl, weld::ComboBox&, void)void SvxNumPositionTabPage::LinkStubEditModifyHdl_Impl(void * instance, weld::ComboBox& data) { return static_cast< SvxNumPositionTabPage *>(instance)->EditModifyHdl_Impl( data); } void SvxNumPositionTabPage::EditModifyHdl_Impl(__attribute__ ((unused)) weld::ComboBox&) | |||
2961 | { | |||
2962 | sal_uInt16 nMask = 1; | |||
2963 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
2964 | { | |||
2965 | if(nActNumLvl & nMask) | |||
2966 | { | |||
2967 | SvxNumberFormat aNumFmt(pActNum->GetLevel(i)); | |||
2968 | ||||
2969 | const sal_Int32 nPos = m_xAlignLB->get_visible() | |||
2970 | ? m_xAlignLB->get_active() | |||
2971 | : m_xAlign2LB->get_active(); | |||
2972 | SvxAdjust eAdjust = SvxAdjust::Center; | |||
2973 | if(nPos == 0) | |||
2974 | eAdjust = SvxAdjust::Left; | |||
2975 | else if(nPos == 2) | |||
2976 | eAdjust = SvxAdjust::Right; | |||
2977 | aNumFmt.SetNumAdjust( eAdjust ); | |||
2978 | pActNum->SetLevel(i, aNumFmt); | |||
2979 | } | |||
2980 | nMask <<= 1; | |||
2981 | } | |||
2982 | SetModified(); | |||
2983 | } | |||
2984 | ||||
2985 | IMPL_LINK_NOARG(SvxNumPositionTabPage, LevelHdl_Impl, weld::TreeView&, void)void SvxNumPositionTabPage::LinkStubLevelHdl_Impl(void * instance , weld::TreeView& data) { return static_cast<SvxNumPositionTabPage *>(instance)->LevelHdl_Impl(data); } void SvxNumPositionTabPage ::LevelHdl_Impl(__attribute__ ((unused)) weld::TreeView&) | |||
2986 | { | |||
2987 | if (m_pLevelHdlEvent) | |||
2988 | return; | |||
2989 | // tdf#127120 multiselection may be implemented by deselect follow by select so | |||
2990 | // fire off the handler to happen on next event loop and only process the | |||
2991 | // final state | |||
2992 | m_pLevelHdlEvent = Application::PostUserEvent(LINK(this, SvxNumPositionTabPage, LevelHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxNumPositionTabPage *>(this), &SvxNumPositionTabPage::LinkStubLevelHdl)); | |||
2993 | } | |||
2994 | ||||
2995 | IMPL_LINK_NOARG(SvxNumPositionTabPage, LevelHdl, void*, void)void SvxNumPositionTabPage::LinkStubLevelHdl(void * instance, void* data) { return static_cast<SvxNumPositionTabPage *> (instance)->LevelHdl(data); } void SvxNumPositionTabPage:: LevelHdl(__attribute__ ((unused)) void*) | |||
2996 | { | |||
2997 | m_pLevelHdlEvent = nullptr; | |||
2998 | ||||
2999 | sal_uInt16 nSaveNumLvl = nActNumLvl; | |||
3000 | nActNumLvl = 0; | |||
3001 | std::vector<int> aSelectedRows = m_xLevelLB->get_selected_rows(); | |||
3002 | if (std::find(aSelectedRows.begin(), aSelectedRows.end(), pActNum->GetLevelCount()) != aSelectedRows.end() && | |||
3003 | (aSelectedRows.size() == 1 || nSaveNumLvl != 0xffff)) | |||
3004 | { | |||
3005 | nActNumLvl = 0xFFFF; | |||
3006 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++ ) | |||
3007 | m_xLevelLB->unselect(i); | |||
3008 | } | |||
3009 | else if (!aSelectedRows.empty()) | |||
3010 | { | |||
3011 | sal_uInt16 nMask = 1; | |||
3012 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++ ) | |||
3013 | { | |||
3014 | if (std::find(aSelectedRows.begin(), aSelectedRows.end(), i) != aSelectedRows.end()) | |||
3015 | nActNumLvl |= nMask; | |||
3016 | nMask <<= 1; | |||
3017 | } | |||
3018 | m_xLevelLB->unselect(pActNum->GetLevelCount()); | |||
3019 | } | |||
3020 | else | |||
3021 | { | |||
3022 | nActNumLvl = nSaveNumLvl; | |||
3023 | sal_uInt16 nMask = 1; | |||
3024 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++ ) | |||
3025 | { | |||
3026 | if(nActNumLvl & nMask) | |||
3027 | { | |||
3028 | m_xLevelLB->select(i); | |||
3029 | break; | |||
3030 | } | |||
3031 | nMask <<=1; | |||
3032 | } | |||
3033 | } | |||
3034 | m_xRelativeCB->set_sensitive(nActNumLvl != 1); | |||
3035 | SetModified(); | |||
3036 | InitPosAndSpaceMode(); | |||
3037 | ShowControlsDependingOnPosAndSpaceMode(); | |||
3038 | InitControls(); | |||
3039 | } | |||
3040 | ||||
3041 | IMPL_LINK(SvxNumPositionTabPage, DistanceHdl_Impl, weld::MetricSpinButton&, rFld, void)void SvxNumPositionTabPage::LinkStubDistanceHdl_Impl(void * instance , weld::MetricSpinButton& data) { return static_cast<SvxNumPositionTabPage *>(instance)->DistanceHdl_Impl(data); } void SvxNumPositionTabPage ::DistanceHdl_Impl(weld::MetricSpinButton& rFld) | |||
3042 | { | |||
3043 | if(bInInintControl) | |||
3044 | return; | |||
3045 | long nValue = GetCoreValue(rFld, eCoreUnit); | |||
3046 | sal_uInt16 nMask = 1; | |||
3047 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
3048 | { | |||
3049 | if(nActNumLvl & nMask) | |||
3050 | { | |||
3051 | SvxNumberFormat aNumFmt( pActNum->GetLevel( i ) ); | |||
3052 | if (&rFld == m_xDistBorderMF.get()) | |||
3053 | { | |||
3054 | ||||
3055 | if (m_xRelativeCB->get_active()) | |||
3056 | { | |||
3057 | if(0 == i) | |||
3058 | { | |||
3059 | auto const nTmp = aNumFmt.GetFirstLineOffset(); | |||
3060 | aNumFmt.SetAbsLSpace( nValue - nTmp); | |||
3061 | } | |||
3062 | else | |||
3063 | { | |||
3064 | long nTmp = pActNum->GetLevel( i - 1 ).GetAbsLSpace() + | |||
3065 | pActNum->GetLevel( i - 1 ).GetFirstLineOffset() - | |||
3066 | pActNum->GetLevel( i ).GetFirstLineOffset(); | |||
3067 | ||||
3068 | aNumFmt.SetAbsLSpace( nValue + nTmp); | |||
3069 | } | |||
3070 | } | |||
3071 | else | |||
3072 | { | |||
3073 | aNumFmt.SetAbsLSpace( nValue - aNumFmt.GetFirstLineOffset()); | |||
3074 | } | |||
3075 | } | |||
3076 | else if (&rFld == m_xDistNumMF.get()) | |||
3077 | { | |||
3078 | aNumFmt.SetCharTextDistance( static_cast<short>(nValue) ); | |||
3079 | } | |||
3080 | else if (&rFld == m_xIndentMF.get()) | |||
3081 | { | |||
3082 | // together with the FirstLineOffset the AbsLSpace must be changed, too | |||
3083 | long nDiff = nValue + aNumFmt.GetFirstLineOffset(); | |||
3084 | auto const nAbsLSpace = aNumFmt.GetAbsLSpace(); | |||
3085 | aNumFmt.SetAbsLSpace(nAbsLSpace + nDiff); | |||
3086 | aNumFmt.SetFirstLineOffset( -nValue ); | |||
3087 | } | |||
3088 | ||||
3089 | pActNum->SetLevel( i, aNumFmt ); | |||
3090 | } | |||
3091 | nMask <<= 1; | |||
3092 | } | |||
3093 | ||||
3094 | SetModified(); | |||
3095 | if (!m_xDistBorderMF->get_sensitive()) | |||
3096 | { | |||
3097 | m_xDistBorderMF->set_text(""); | |||
3098 | } | |||
3099 | } | |||
3100 | ||||
3101 | IMPL_LINK(SvxNumPositionTabPage, RelativeHdl_Impl, weld::ToggleButton&, rBox, void)void SvxNumPositionTabPage::LinkStubRelativeHdl_Impl(void * instance , weld::ToggleButton& data) { return static_cast<SvxNumPositionTabPage *>(instance)->RelativeHdl_Impl(data); } void SvxNumPositionTabPage ::RelativeHdl_Impl(weld::ToggleButton& rBox) | |||
3102 | { | |||
3103 | bool bOn = rBox.get_active(); | |||
3104 | bool bSingleSelection = m_xLevelLB->count_selected_rows() == 1 && SAL_MAX_UINT16((sal_uInt16) 0xFFFF) != nActNumLvl; | |||
3105 | bool bSetValue = false; | |||
3106 | long nValue = 0; | |||
3107 | if(bOn || bSingleSelection) | |||
3108 | { | |||
3109 | sal_uInt16 nMask = 1; | |||
3110 | bool bFirst = true; | |||
3111 | bSetValue = true; | |||
3112 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
3113 | { | |||
3114 | if(nActNumLvl & nMask) | |||
3115 | { | |||
3116 | const SvxNumberFormat &rNumFmt = pActNum->GetLevel(i); | |||
3117 | if(bFirst) | |||
3118 | { | |||
3119 | nValue = rNumFmt.GetAbsLSpace() + rNumFmt.GetFirstLineOffset(); | |||
3120 | if(bOn && i) | |||
3121 | nValue -= (pActNum->GetLevel(i - 1).GetAbsLSpace() + pActNum->GetLevel(i - 1).GetFirstLineOffset()); | |||
3122 | } | |||
3123 | else | |||
3124 | bSetValue = nValue == | |||
3125 | (rNumFmt.GetAbsLSpace() + rNumFmt.GetFirstLineOffset()) - | |||
3126 | (pActNum->GetLevel(i - 1).GetAbsLSpace() + pActNum->GetLevel(i - 1).GetFirstLineOffset()); | |||
3127 | bFirst = false; | |||
3128 | } | |||
3129 | nMask <<= 1; | |||
3130 | } | |||
3131 | ||||
3132 | } | |||
3133 | if(bSetValue) | |||
3134 | SetMetricValue(*m_xDistBorderMF, nValue, eCoreUnit); | |||
3135 | else | |||
3136 | m_xDistBorderMF->set_text(""); | |||
3137 | m_xDistBorderMF->set_sensitive(bOn || bSingleSelection); | |||
3138 | m_xDistBorderFT->set_sensitive(bOn || bSingleSelection); | |||
3139 | bLastRelative = bOn; | |||
3140 | } | |||
3141 | ||||
3142 | IMPL_LINK_NOARG(SvxNumPositionTabPage, LabelFollowedByHdl_Impl, weld::ComboBox&, void)void SvxNumPositionTabPage::LinkStubLabelFollowedByHdl_Impl(void * instance, weld::ComboBox& data) { return static_cast< SvxNumPositionTabPage *>(instance)->LabelFollowedByHdl_Impl (data); } void SvxNumPositionTabPage::LabelFollowedByHdl_Impl (__attribute__ ((unused)) weld::ComboBox&) | |||
3143 | { | |||
3144 | // determine value to be set at the chosen list levels | |||
3145 | SvxNumberFormat::LabelFollowedBy eLabelFollowedBy = SvxNumberFormat::LISTTAB; | |||
3146 | { | |||
3147 | const auto nPos = m_xLabelFollowedByLB->get_active(); | |||
3148 | if ( nPos == 1 ) | |||
3149 | { | |||
3150 | eLabelFollowedBy = SvxNumberFormat::SPACE; | |||
3151 | } | |||
3152 | else if ( nPos == 2 ) | |||
3153 | { | |||
3154 | eLabelFollowedBy = SvxNumberFormat::NOTHING; | |||
3155 | } | |||
3156 | else if ( nPos == 3 ) | |||
3157 | { | |||
3158 | eLabelFollowedBy = SvxNumberFormat::NEWLINE; | |||
3159 | } | |||
3160 | } | |||
3161 | ||||
3162 | // set value at the chosen list levels | |||
3163 | bool bSameListtabPos = true; | |||
3164 | sal_uInt16 nFirstLvl = SAL_MAX_UINT16((sal_uInt16) 0xFFFF); | |||
3165 | sal_uInt16 nMask = 1; | |||
3166 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); ++i ) | |||
3167 | { | |||
3168 | if ( nActNumLvl & nMask ) | |||
3169 | { | |||
3170 | SvxNumberFormat aNumFmt( pActNum->GetLevel(i) ); | |||
3171 | aNumFmt.SetLabelFollowedBy( eLabelFollowedBy ); | |||
3172 | pActNum->SetLevel( i, aNumFmt ); | |||
3173 | ||||
3174 | if ( nFirstLvl == SAL_MAX_UINT16((sal_uInt16) 0xFFFF) ) | |||
3175 | { | |||
3176 | nFirstLvl = i; | |||
3177 | } | |||
3178 | else | |||
3179 | { | |||
3180 | bSameListtabPos &= aNumFmt.GetListtabPos() == | |||
3181 | pActNum->GetLevel( nFirstLvl ).GetListtabPos(); | |||
3182 | } | |||
3183 | } | |||
3184 | nMask <<= 1; | |||
3185 | } | |||
3186 | ||||
3187 | // enable/disable metric field for list tab stop position depending on | |||
3188 | // selected item following the list label. | |||
3189 | m_xListtabFT->set_sensitive( eLabelFollowedBy == SvxNumberFormat::LISTTAB ); | |||
3190 | m_xListtabMF->set_sensitive( eLabelFollowedBy == SvxNumberFormat::LISTTAB ); | |||
3191 | if ( bSameListtabPos && eLabelFollowedBy == SvxNumberFormat::LISTTAB ) | |||
3192 | { | |||
3193 | SetMetricValue(*m_xListtabMF, pActNum->GetLevel( nFirstLvl ).GetListtabPos(), eCoreUnit); | |||
3194 | } | |||
3195 | else | |||
3196 | { | |||
3197 | m_xListtabMF->set_text(OUString()); | |||
3198 | } | |||
3199 | ||||
3200 | SetModified(); | |||
3201 | } | |||
3202 | ||||
3203 | IMPL_LINK(SvxNumPositionTabPage, ListtabPosHdl_Impl, weld::MetricSpinButton&, rFld, void)void SvxNumPositionTabPage::LinkStubListtabPosHdl_Impl(void * instance, weld::MetricSpinButton& data) { return static_cast <SvxNumPositionTabPage *>(instance)->ListtabPosHdl_Impl (data); } void SvxNumPositionTabPage::ListtabPosHdl_Impl(weld ::MetricSpinButton& rFld) | |||
3204 | { | |||
3205 | // determine value to be set at the chosen list levels | |||
3206 | const long nValue = GetCoreValue(rFld, eCoreUnit); | |||
3207 | ||||
3208 | // set value at the chosen list levels | |||
3209 | sal_uInt16 nMask = 1; | |||
3210 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); ++i ) | |||
3211 | { | |||
3212 | if ( nActNumLvl & nMask ) | |||
3213 | { | |||
3214 | SvxNumberFormat aNumFmt( pActNum->GetLevel(i) ); | |||
3215 | aNumFmt.SetListtabPos( nValue ); | |||
3216 | pActNum->SetLevel( i, aNumFmt ); | |||
3217 | } | |||
3218 | nMask <<= 1; | |||
3219 | } | |||
3220 | ||||
3221 | SetModified(); | |||
3222 | } | |||
3223 | ||||
3224 | IMPL_LINK(SvxNumPositionTabPage, AlignAtHdl_Impl, weld::MetricSpinButton&, rFld, void)void SvxNumPositionTabPage::LinkStubAlignAtHdl_Impl(void * instance , weld::MetricSpinButton& data) { return static_cast<SvxNumPositionTabPage *>(instance)->AlignAtHdl_Impl(data); } void SvxNumPositionTabPage ::AlignAtHdl_Impl(weld::MetricSpinButton& rFld) | |||
3225 | { | |||
3226 | // determine value to be set at the chosen list levels | |||
3227 | const long nValue = GetCoreValue(rFld, eCoreUnit); | |||
3228 | ||||
3229 | // set value at the chosen list levels | |||
3230 | sal_uInt16 nMask = 1; | |||
3231 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); ++i ) | |||
3232 | { | |||
3233 | if ( nActNumLvl & nMask ) | |||
3234 | { | |||
3235 | SvxNumberFormat aNumFmt( pActNum->GetLevel(i) ); | |||
3236 | const long nFirstLineIndent = nValue - aNumFmt.GetIndentAt(); | |||
3237 | aNumFmt.SetFirstLineIndent( nFirstLineIndent ); | |||
3238 | pActNum->SetLevel( i, aNumFmt ); | |||
3239 | } | |||
3240 | nMask <<= 1; | |||
3241 | } | |||
3242 | ||||
3243 | SetModified(); | |||
3244 | } | |||
3245 | ||||
3246 | IMPL_LINK(SvxNumPositionTabPage, IndentAtHdl_Impl, weld::MetricSpinButton&, rFld, void)void SvxNumPositionTabPage::LinkStubIndentAtHdl_Impl(void * instance , weld::MetricSpinButton& data) { return static_cast<SvxNumPositionTabPage *>(instance)->IndentAtHdl_Impl(data); } void SvxNumPositionTabPage ::IndentAtHdl_Impl(weld::MetricSpinButton& rFld) | |||
3247 | { | |||
3248 | // determine value to be set at the chosen list levels | |||
3249 | const long nValue = GetCoreValue(rFld, eCoreUnit); | |||
3250 | ||||
3251 | // set value at the chosen list levels | |||
3252 | sal_uInt16 nMask = 1; | |||
3253 | for( sal_uInt16 i = 0; i < pActNum->GetLevelCount(); ++i ) | |||
3254 | { | |||
3255 | if ( nActNumLvl & nMask ) | |||
3256 | { | |||
3257 | SvxNumberFormat aNumFmt( pActNum->GetLevel(i) ); | |||
3258 | const long nAlignedAt = aNumFmt.GetIndentAt() + | |||
3259 | aNumFmt.GetFirstLineIndent(); | |||
3260 | aNumFmt.SetIndentAt( nValue ); | |||
3261 | const long nNewFirstLineIndent = nAlignedAt - nValue; | |||
3262 | aNumFmt.SetFirstLineIndent( nNewFirstLineIndent ); | |||
3263 | pActNum->SetLevel( i, aNumFmt ); | |||
3264 | } | |||
3265 | nMask <<= 1; | |||
3266 | } | |||
3267 | ||||
3268 | SetModified(); | |||
3269 | } | |||
3270 | ||||
3271 | IMPL_LINK_NOARG(SvxNumPositionTabPage, StandardHdl_Impl, weld::Button&, void)void SvxNumPositionTabPage::LinkStubStandardHdl_Impl(void * instance , weld::Button& data) { return static_cast<SvxNumPositionTabPage *>(instance)->StandardHdl_Impl(data); } void SvxNumPositionTabPage ::StandardHdl_Impl(__attribute__ ((unused)) weld::Button& ) | |||
3272 | { | |||
3273 | sal_uInt16 nMask = 1; | |||
3274 | SvxNumRule aTmpNumRule( pActNum->GetFeatureFlags(), | |||
3275 | pActNum->GetLevelCount(), | |||
3276 | pActNum->IsContinuousNumbering(), | |||
3277 | SvxNumRuleType::NUMBERING, | |||
3278 | pActNum->GetLevel( 0 ).GetPositionAndSpaceMode() ); | |||
3279 | for(sal_uInt16 i = 0; i < pActNum->GetLevelCount(); i++) | |||
3280 | { | |||
3281 | if(nActNumLvl & nMask) | |||
3282 | { | |||
3283 | SvxNumberFormat aNumFmt( pActNum->GetLevel( i ) ); | |||
3284 | const SvxNumberFormat& aTempFmt(aTmpNumRule.GetLevel( i )); | |||
3285 | aNumFmt.SetPositionAndSpaceMode( aTempFmt.GetPositionAndSpaceMode() ); | |||
3286 | if ( aTempFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION ) | |||
3287 | { | |||
3288 | aNumFmt.SetAbsLSpace( aTempFmt.GetAbsLSpace() ); | |||
3289 | aNumFmt.SetCharTextDistance( aTempFmt.GetCharTextDistance() ); | |||
3290 | aNumFmt.SetFirstLineOffset( aTempFmt.GetFirstLineOffset() ); | |||
3291 | } | |||
3292 | else if ( aTempFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) | |||
3293 | { | |||
3294 | aNumFmt.SetNumAdjust( aTempFmt.GetNumAdjust() ); | |||
3295 | aNumFmt.SetLabelFollowedBy( aTempFmt.GetLabelFollowedBy() ); | |||
3296 | aNumFmt.SetListtabPos( aTempFmt.GetListtabPos() ); | |||
3297 | aNumFmt.SetFirstLineIndent( aTempFmt.GetFirstLineIndent() ); | |||
3298 | aNumFmt.SetIndentAt( aTempFmt.GetIndentAt() ); | |||
3299 | } | |||
3300 | ||||
3301 | pActNum->SetLevel( i, aNumFmt ); | |||
3302 | } | |||
3303 | nMask <<= 1; | |||
3304 | } | |||
3305 | ||||
3306 | InitControls(); | |||
3307 | SetModified(); | |||
3308 | } | |||
3309 | ||||
3310 | void SvxNumPositionTabPage::SetModified() | |||
3311 | { | |||
3312 | bModified = true; | |||
3313 | m_aPreviewWIN.SetLevel(nActNumLvl); | |||
3314 | m_aPreviewWIN.Invalidate(); | |||
3315 | } | |||
3316 | ||||
3317 | void SvxNumOptionsTabPage::SetModified(bool bRepaint) | |||
3318 | { | |||
3319 | bModified = true; | |||
3320 | if (bRepaint) | |||
3321 | { | |||
3322 | m_aPreviewWIN.SetLevel(nActNumLvl); | |||
3323 | m_aPreviewWIN.Invalidate(); | |||
3324 | } | |||
3325 | } | |||
3326 | ||||
3327 | void SvxNumOptionsTabPage::PageCreated(const SfxAllItemSet& aSet) | |||
3328 | { | |||
3329 | const SfxStringListItem* pListItem = aSet.GetItem<SfxStringListItem>(SID_CHAR_FMT_LIST_BOX( 10000 + 1023 ), false); | |||
3330 | const SfxStringItem* pNumCharFmt = aSet.GetItem<SfxStringItem>(SID_NUM_CHAR_FMT( 10000 + 1025 ), false); | |||
3331 | const SfxStringItem* pBulletCharFmt = aSet.GetItem<SfxStringItem>(SID_BULLET_CHAR_FMT( 10000 + 1026 ), false); | |||
3332 | const SfxUInt16Item* pMetricItem = aSet.GetItem<SfxUInt16Item>(SID_METRIC_ITEMTypedWhichId<SfxUInt16Item>( 10000 + 1024 ), false); | |||
3333 | ||||
3334 | if (pNumCharFmt &&pBulletCharFmt) | |||
3335 | SetCharFmts( pNumCharFmt->GetValue(),pBulletCharFmt->GetValue()); | |||
3336 | ||||
3337 | if (pListItem) | |||
3338 | { | |||
3339 | const std::vector<OUString> &aList = pListItem->GetList(); | |||
3340 | sal_uInt32 nCount = aList.size(); | |||
3341 | for(sal_uInt32 i = 0; i < nCount; i++) | |||
3342 | m_xCharFmtLB->append_text(aList[i]); | |||
3343 | } | |||
3344 | if (pMetricItem) | |||
3345 | SetMetric(static_cast<FieldUnit>(pMetricItem->GetValue())); | |||
3346 | } | |||
3347 | ||||
3348 | void SvxNumPositionTabPage::PageCreated(const SfxAllItemSet& aSet) | |||
3349 | { | |||
3350 | const SfxUInt16Item* pMetricItem = aSet.GetItem<SfxUInt16Item>(SID_METRIC_ITEMTypedWhichId<SfxUInt16Item>( 10000 + 1024 ), false); | |||
3351 | ||||
3352 | if (pMetricItem) | |||
3353 | SetMetric(static_cast<FieldUnit>(pMetricItem->GetValue())); | |||
3354 | } | |||
3355 | ||||
3356 | /* 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 |