Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <hintids.hxx>
21 :
22 : #include <osl/diagnose.h>
23 : #include <tools/datetime.hxx>
24 : #include <vcl/svapp.hxx>
25 : #include <unotools/collatorwrapper.hxx>
26 : #include <svl/urihelper.hxx>
27 : #include <svl/stritem.hxx>
28 : #include <unotools/syslocale.hxx>
29 : #include <sfx2/app.hxx>
30 : #include <sfx2/docfile.hxx>
31 : #include <sfx2/docfilt.hxx>
32 : #include <editeng/pmdlitem.hxx>
33 : #include <editeng/tstpitem.hxx>
34 : #include <editeng/boxitem.hxx>
35 : #include <editeng/sizeitem.hxx>
36 : #include <svx/pageitem.hxx>
37 : #include <editeng/lrspitem.hxx>
38 : #include <svl/style.hxx>
39 : #include <vcl/lstbox.hxx>
40 : #include <unotools/localedatawrapper.hxx>
41 : #include <com/sun/star/frame/XDispatch.hpp>
42 : #include <com/sun/star/frame/XDispatchProvider.hpp>
43 : #include <com/sun/star/util/URLTransformer.hpp>
44 : #include <com/sun/star/util/XURLTransformer.hpp>
45 : #include <comphelper/processfactory.hxx>
46 : #include <sfx2/viewfrm.hxx>
47 : #include <fmtornt.hxx>
48 : #include <tabcol.hxx>
49 : #include <edtwin.hxx>
50 : #include <fmtfsize.hxx>
51 : #include <fmthdft.hxx>
52 : #include <fmtpdsc.hxx>
53 : #include <wview.hxx>
54 : #include <uiitems.hxx>
55 : #include <docsh.hxx>
56 : #include <wrtsh.hxx>
57 : #include <swmodule.hxx>
58 : #include <view.hxx>
59 : #include <uitool.hxx>
60 : #include <frmatr.hxx>
61 : #include <paratr.hxx>
62 : #include <fmtcol.hxx>
63 : #include <poolfmt.hxx>
64 : #include "usrpref.hxx"
65 :
66 : #include <cmdid.h>
67 : #include <globals.hrc>
68 : #include <utlui.hrc>
69 : #include <doc.hxx>
70 : #include <docary.hxx>
71 : #include <charfmt.hxx>
72 : #include <SwStyleNameMapper.hxx>
73 : // 50 cm 28350
74 : //
75 : #define MAXHEIGHT 28350
76 : #define MAXWIDTH 28350
77 :
78 : using namespace ::com::sun::star;
79 :
80 : // General list of string pointer
81 :
82 : // Switch metric
83 :
84 0 : void SetMetric(MetricFormatter& rCtrl, FieldUnit eUnit)
85 : {
86 0 : SwTwips nMin = static_cast< SwTwips >(rCtrl.GetMin(FUNIT_TWIP));
87 0 : SwTwips nMax = static_cast< SwTwips >(rCtrl.GetMax(FUNIT_TWIP));
88 :
89 0 : rCtrl.SetUnit(eUnit);
90 :
91 0 : rCtrl.SetMin(nMin, FUNIT_TWIP);
92 0 : rCtrl.SetMax(nMax, FUNIT_TWIP);
93 0 : }
94 :
95 : // Set boxinfo attribute
96 :
97 0 : void PrepareBoxInfo(SfxItemSet& rSet, const SwWrtShell& rSh)
98 : {
99 0 : SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
100 : const SfxPoolItem *pBoxInfo;
101 0 : if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER,
102 0 : sal_True, &pBoxInfo))
103 0 : aBoxInfo = *(SvxBoxInfoItem*)pBoxInfo;
104 :
105 : // Table variant: If more than one table cells are selected
106 0 : rSh.GetCrsr(); //So that GetCrsrCnt() returns the right thing
107 0 : aBoxInfo.SetTable (rSh.IsTableMode() && rSh.GetCrsrCnt() > 1);
108 : // Always show the distance field
109 0 : aBoxInfo.SetDist ((sal_Bool) sal_True);
110 : // Set minimal size in tables and paragraphs
111 0 : aBoxInfo.SetMinDist (rSh.IsTableMode() || rSh.GetSelectionType() & (nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL));
112 : // Set always the default distance
113 0 : aBoxInfo.SetDefDist (MIN_BORDER_DIST);
114 : // Single lines can have only in tables DontCare-Status
115 0 : aBoxInfo.SetValid(VALID_DISABLE, !rSh.IsTableMode());
116 :
117 0 : rSet.Put(aBoxInfo);
118 0 : }
119 :
120 : // Fill header footer
121 :
122 250 : void FillHdFt(SwFrmFmt* pFmt, const SfxItemSet& rSet)
123 : {
124 250 : SwAttrSet aSet(pFmt->GetAttrSet());
125 250 : aSet.Put(rSet);
126 :
127 250 : const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get(SID_ATTR_PAGE_SIZE);
128 250 : const SfxBoolItem& rDynamic = (const SfxBoolItem&)rSet.Get(SID_ATTR_PAGE_DYNAMIC);
129 :
130 : // Convert size
131 250 : SwFmtFrmSize aFrmSize(rDynamic.GetValue() ? ATT_MIN_SIZE : ATT_FIX_SIZE,
132 250 : rSize.GetSize().Width(),
133 1000 : rSize.GetSize().Height());
134 250 : aSet.Put(aFrmSize);
135 500 : pFmt->SetFmtAttr(aSet);
136 250 : }
137 :
138 : /// Convert from UseOnPage to SvxPageUsage.
139 2151 : UseOnPage lcl_convertUseToSvx(UseOnPage nUse)
140 : {
141 2151 : UseOnPage nRet = nsUseOnPage::PD_NONE;
142 2151 : if ((nUse & nsUseOnPage::PD_LEFT) == nsUseOnPage::PD_LEFT)
143 2148 : nRet |= SVX_PAGE_LEFT;
144 2151 : if ((nUse & nsUseOnPage::PD_RIGHT) == nsUseOnPage::PD_RIGHT)
145 2146 : nRet |= SVX_PAGE_RIGHT;
146 2151 : if ((nUse & nsUseOnPage::PD_ALL) == nsUseOnPage::PD_ALL)
147 2143 : nRet |= SVX_PAGE_ALL;
148 2151 : if ((nUse & nsUseOnPage::PD_MIRROR) == nsUseOnPage::PD_MIRROR)
149 120 : nRet |= SVX_PAGE_MIRROR;
150 2151 : return nRet;
151 : }
152 :
153 : /// Convert from SvxPageUsage to UseOnPage.
154 733 : UseOnPage lcl_convertUseFromSvx(UseOnPage nUse)
155 : {
156 733 : UseOnPage nRet = nsUseOnPage::PD_NONE;
157 733 : if ((nUse & SVX_PAGE_LEFT) == SVX_PAGE_LEFT)
158 728 : nRet |= nsUseOnPage::PD_LEFT;
159 733 : if ((nUse & SVX_PAGE_RIGHT) == SVX_PAGE_RIGHT)
160 729 : nRet |= nsUseOnPage::PD_RIGHT;
161 733 : if ((nUse & SVX_PAGE_ALL) == SVX_PAGE_ALL)
162 724 : nRet |= nsUseOnPage::PD_ALL;
163 733 : if ((nUse & SVX_PAGE_MIRROR) == SVX_PAGE_MIRROR)
164 44 : nRet |= nsUseOnPage::PD_MIRROR;
165 733 : return nRet;
166 : }
167 :
168 : // PageDesc <-> convert into sets and back
169 :
170 733 : void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc )
171 : {
172 733 : SwFrmFmt& rMaster = rPageDesc.GetMaster();
173 733 : int nFirstShare = -1;
174 :
175 : // Transfer all general frame attributes
176 733 : rMaster.SetFmtAttr(rSet);
177 :
178 : // PageData
179 733 : if(rSet.GetItemState(SID_ATTR_PAGE) == SFX_ITEM_SET)
180 : {
181 733 : const SvxPageItem& rPageItem = (const SvxPageItem&)rSet.Get(SID_ATTR_PAGE);
182 :
183 733 : sal_uInt16 nUse = (sal_uInt16)rPageItem.GetPageUsage();
184 733 : if(nUse)
185 733 : rPageDesc.SetUseOn( lcl_convertUseFromSvx((UseOnPage) nUse) );
186 733 : rPageDesc.SetLandscape(rPageItem.IsLandscape());
187 733 : SvxNumberType aNumType;
188 733 : aNumType.SetNumberingType( static_cast< sal_Int16 >(rPageItem.GetNumType()) );
189 733 : rPageDesc.SetNumType(aNumType);
190 : }
191 : // Size
192 733 : if(rSet.GetItemState(SID_ATTR_PAGE_SIZE) == SFX_ITEM_SET)
193 : {
194 733 : const SvxSizeItem& rSizeItem = (const SvxSizeItem&)rSet.Get(SID_ATTR_PAGE_SIZE);
195 733 : SwFmtFrmSize aSize(ATT_FIX_SIZE);
196 733 : aSize.SetSize(rSizeItem.GetSize());
197 733 : rMaster.SetFmtAttr(aSize);
198 : }
199 : // Evaluate header attributes
200 : const SfxPoolItem* pItem;
201 733 : if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PAGE_HEADERSET,
202 733 : sal_False, &pItem ) )
203 : {
204 146 : const SfxItemSet& rHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
205 146 : const SfxBoolItem& rHeaderOn = (const SfxBoolItem&)rHeaderSet.Get(SID_ATTR_PAGE_ON);
206 :
207 146 : if(rHeaderOn.GetValue())
208 : {
209 : // Take over values
210 146 : if(!rMaster.GetHeader().IsActive())
211 46 : rMaster.SetFmtAttr(SwFmtHeader(sal_True));
212 :
213 : // Pick out everything and adapt the header format
214 146 : SwFmtHeader aHeaderFmt(rMaster.GetHeader());
215 146 : SwFrmFmt *pHeaderFmt = aHeaderFmt.GetHeaderFmt();
216 : OSL_ENSURE(pHeaderFmt != 0, "no header format");
217 :
218 146 : ::FillHdFt(pHeaderFmt, rHeaderSet);
219 :
220 : rPageDesc.ChgHeaderShare(((const SfxBoolItem&)
221 146 : rHeaderSet.Get(SID_ATTR_PAGE_SHARED)).GetValue());
222 146 : if (nFirstShare < 0)
223 : {
224 : rPageDesc.ChgFirstShare(((const SfxBoolItem&)
225 146 : rHeaderSet.Get(SID_ATTR_PAGE_SHARED_FIRST)).GetValue());
226 146 : nFirstShare = rPageDesc.IsFirstShared();
227 146 : }
228 : }
229 : else
230 : {
231 : // Disable header
232 0 : if(rMaster.GetHeader().IsActive())
233 : {
234 0 : rMaster.SetFmtAttr(SwFmtHeader(sal_Bool(sal_False)));
235 0 : rPageDesc.ChgHeaderShare(sal_False);
236 : }
237 : }
238 : }
239 :
240 : // Evaluate footer attributes
241 733 : if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PAGE_FOOTERSET,
242 733 : sal_False, &pItem ) )
243 : {
244 104 : const SfxItemSet& rFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
245 104 : const SfxBoolItem& rFooterOn = (const SfxBoolItem&)rFooterSet.Get(SID_ATTR_PAGE_ON);
246 :
247 104 : if(rFooterOn.GetValue())
248 : {
249 : // Take over values
250 104 : if(!rMaster.GetFooter().IsActive())
251 44 : rMaster.SetFmtAttr(SwFmtFooter(sal_True));
252 :
253 : // Pick out everything and adapt the footer format
254 104 : SwFmtFooter aFooterFmt(rMaster.GetFooter());
255 104 : SwFrmFmt *pFooterFmt = aFooterFmt.GetFooterFmt();
256 : OSL_ENSURE(pFooterFmt != 0, "no footer format");
257 :
258 104 : ::FillHdFt(pFooterFmt, rFooterSet);
259 :
260 : rPageDesc.ChgFooterShare(((const SfxBoolItem&)
261 104 : rFooterSet.Get(SID_ATTR_PAGE_SHARED)).GetValue());
262 104 : if (nFirstShare < 0)
263 : {
264 : rPageDesc.ChgFirstShare(((const SfxBoolItem&)
265 24 : rFooterSet.Get(SID_ATTR_PAGE_SHARED_FIRST)).GetValue());
266 24 : nFirstShare = rPageDesc.IsFirstShared();
267 104 : }
268 : }
269 : else
270 : {
271 : // Disable footer
272 0 : if(rMaster.GetFooter().IsActive())
273 : {
274 0 : rMaster.SetFmtAttr(SwFmtFooter(sal_Bool(sal_False)));
275 0 : rPageDesc.ChgFooterShare(sal_False);
276 : }
277 : }
278 : }
279 :
280 : // Footnotes
281 : //
282 733 : if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_FTN_INFO,
283 733 : sal_False, &pItem ) )
284 733 : rPageDesc.SetFtnInfo( ((SwPageFtnInfoItem*)pItem)->GetPageFtnInfo() );
285 :
286 : // Columns
287 :
288 : // Register compliant
289 :
290 733 : if(SFX_ITEM_SET == rSet.GetItemState(
291 733 : SID_SWREGISTER_MODE, sal_False, &pItem))
292 : {
293 733 : sal_Bool bSet = ((const SfxBoolItem*)pItem)->GetValue();
294 733 : if(!bSet)
295 733 : rPageDesc.SetRegisterFmtColl(0);
296 0 : else if(SFX_ITEM_SET == rSet.GetItemState(
297 0 : SID_SWREGISTER_COLLECTION, sal_False, &pItem))
298 : {
299 0 : const String& rColl = ((const SfxStringItem*)pItem)->GetValue();
300 0 : SwDoc& rDoc = *rMaster.GetDoc();
301 0 : SwTxtFmtColl* pColl = rDoc.FindTxtFmtCollByName( rColl );
302 0 : if( !pColl )
303 : {
304 0 : sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rColl, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
305 0 : if( USHRT_MAX != nId )
306 0 : pColl = rDoc.GetTxtCollFromPool( nId );
307 : else
308 : pColl = rDoc.MakeTxtFmtColl( rColl,
309 0 : (SwTxtFmtColl*)rDoc.GetDfltTxtFmtColl() );
310 : }
311 0 : if( pColl )
312 0 : pColl->SetFmtAttr( SwRegisterItem ( sal_True ));
313 0 : rPageDesc.SetRegisterFmtColl( pColl );
314 : }
315 : }
316 733 : }
317 :
318 2151 : void PageDescToItemSet( const SwPageDesc& rPageDesc, SfxItemSet& rSet)
319 : {
320 2151 : const SwFrmFmt& rMaster = rPageDesc.GetMaster();
321 :
322 : // Page data
323 2151 : SvxPageItem aPageItem(SID_ATTR_PAGE);
324 2151 : aPageItem.SetDescName(rPageDesc.GetName());
325 2151 : aPageItem.SetPageUsage(lcl_convertUseToSvx(rPageDesc.GetUseOn()));
326 2151 : aPageItem.SetLandscape(rPageDesc.GetLandscape());
327 2151 : aPageItem.SetNumType((SvxNumType)rPageDesc.GetNumType().GetNumberingType());
328 2151 : rSet.Put(aPageItem);
329 :
330 : // Size
331 4302 : SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, rMaster.GetFrmSize().GetSize());
332 2151 : rSet.Put(aSizeItem);
333 :
334 : // Maximum size
335 4302 : SvxSizeItem aMaxSizeItem(SID_ATTR_PAGE_MAXSIZE, Size(MAXWIDTH, MAXHEIGHT));
336 2151 : rSet.Put(aMaxSizeItem);
337 :
338 : // Margins, border and the other stuff.
339 2151 : rSet.Put(rMaster.GetAttrSet());
340 :
341 4302 : SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
342 : const SfxPoolItem *pBoxInfo;
343 2151 : if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER,
344 2151 : sal_True, &pBoxInfo) )
345 76 : aBoxInfo = *(SvxBoxInfoItem*)pBoxInfo;
346 :
347 2151 : aBoxInfo.SetTable( sal_False );
348 : // Show always the distance field
349 2151 : aBoxInfo.SetDist( sal_True);
350 : // Set minimal size in tables and paragraphs
351 2151 : aBoxInfo.SetMinDist( sal_False );
352 : // Set always the default distance
353 2151 : aBoxInfo.SetDefDist( MIN_BORDER_DIST );
354 : // Single lines can have only in tables DontCare-Status
355 2151 : aBoxInfo.SetValid( VALID_DISABLE );
356 2151 : rSet.Put( aBoxInfo );
357 :
358 :
359 4302 : SfxStringItem aFollow(SID_ATTR_PAGE_EXT1, aEmptyStr);
360 2151 : if(rPageDesc.GetFollow())
361 2151 : aFollow.SetValue(rPageDesc.GetFollow()->GetName());
362 2151 : rSet.Put(aFollow);
363 :
364 : // Header
365 2151 : if(rMaster.GetHeader().IsActive())
366 : {
367 294 : const SwFmtHeader &rHeaderFmt = rMaster.GetHeader();
368 294 : const SwFrmFmt *pHeaderFmt = rHeaderFmt.GetHeaderFmt();
369 : OSL_ENSURE(pHeaderFmt != 0, "no header format");
370 :
371 : // HeaderInfo, margins, background, border
372 294 : SfxItemSet aHeaderSet( *rSet.GetPool(),
373 : SID_ATTR_PAGE_ON, SID_ATTR_PAGE_SHARED,
374 : SID_ATTR_PAGE_SHARED_FIRST, SID_ATTR_PAGE_SHARED_FIRST,
375 : SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
376 : SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
377 : RES_FRMATR_BEGIN, RES_FRMATR_END-1,
378 294 : 0);
379 :
380 : // Dynamic or fixed height
381 588 : SfxBoolItem aOn(SID_ATTR_PAGE_ON, sal_True);
382 294 : aHeaderSet.Put(aOn);
383 :
384 294 : const SwFmtFrmSize &rFrmSize = pHeaderFmt->GetFrmSize();
385 294 : const SwFrmSize eSizeType = rFrmSize.GetHeightSizeType();
386 588 : SfxBoolItem aDynamic(SID_ATTR_PAGE_DYNAMIC, eSizeType != ATT_FIX_SIZE);
387 294 : aHeaderSet.Put(aDynamic);
388 :
389 : // Left equal right
390 588 : SfxBoolItem aShared(SID_ATTR_PAGE_SHARED, rPageDesc.IsHeaderShared());
391 294 : aHeaderSet.Put(aShared);
392 588 : SfxBoolItem aFirstShared(SID_ATTR_PAGE_SHARED_FIRST, rPageDesc.IsFirstShared());
393 294 : aHeaderSet.Put(aFirstShared);
394 :
395 : // Size
396 588 : SvxSizeItem aSize(SID_ATTR_PAGE_SIZE, Size(rFrmSize.GetSize()));
397 294 : aHeaderSet.Put(aSize);
398 :
399 : // Shifting frame attributes
400 294 : aHeaderSet.Put(pHeaderFmt->GetAttrSet());
401 294 : aHeaderSet.Put( aBoxInfo );
402 :
403 : // Create SetItem
404 588 : SvxSetItem aSetItem(SID_ATTR_PAGE_HEADERSET, aHeaderSet);
405 588 : rSet.Put(aSetItem);
406 : }
407 :
408 : // Footer
409 2151 : if(rMaster.GetFooter().IsActive())
410 : {
411 216 : const SwFmtFooter &rFooterFmt = rMaster.GetFooter();
412 216 : const SwFrmFmt *pFooterFmt = rFooterFmt.GetFooterFmt();
413 : OSL_ENSURE(pFooterFmt != 0, "no footer format");
414 :
415 : // FooterInfo, margins, background, border
416 216 : SfxItemSet aFooterSet( *rSet.GetPool(),
417 : SID_ATTR_PAGE_ON, SID_ATTR_PAGE_SHARED,
418 : SID_ATTR_PAGE_SHARED_FIRST, SID_ATTR_PAGE_SHARED_FIRST,
419 : SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
420 : SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
421 : RES_FRMATR_BEGIN, RES_FRMATR_END-1,
422 216 : 0);
423 :
424 : // Dynamic or fixed height
425 432 : SfxBoolItem aOn(SID_ATTR_PAGE_ON, sal_True);
426 216 : aFooterSet.Put(aOn);
427 :
428 216 : const SwFmtFrmSize &rFrmSize = pFooterFmt->GetFrmSize();
429 216 : const SwFrmSize eSizeType = rFrmSize.GetHeightSizeType();
430 432 : SfxBoolItem aDynamic(SID_ATTR_PAGE_DYNAMIC, eSizeType != ATT_FIX_SIZE);
431 216 : aFooterSet.Put(aDynamic);
432 :
433 : // Left equal right
434 432 : SfxBoolItem aShared(SID_ATTR_PAGE_SHARED, rPageDesc.IsFooterShared());
435 216 : aFooterSet.Put(aShared);
436 432 : SfxBoolItem aFirstShared(SID_ATTR_PAGE_SHARED_FIRST, rPageDesc.IsFirstShared());
437 216 : aFooterSet.Put(aFirstShared);
438 :
439 : // Size
440 432 : SvxSizeItem aSize(SID_ATTR_PAGE_SIZE, Size(rFrmSize.GetSize()));
441 216 : aFooterSet.Put(aSize);
442 :
443 : // Shifting Frame attributes
444 216 : aFooterSet.Put(pFooterFmt->GetAttrSet());
445 216 : aFooterSet.Put( aBoxInfo );
446 :
447 : // Create SetItem
448 432 : SvxSetItem aSetItem(SID_ATTR_PAGE_FOOTERSET, aFooterSet);
449 432 : rSet.Put(aSetItem);
450 : }
451 :
452 : // Integrate footnotes
453 2151 : SwPageFtnInfo& rInfo = (SwPageFtnInfo&)rPageDesc.GetFtnInfo();
454 4302 : SwPageFtnInfoItem aFtnItem(FN_PARAM_FTN_INFO, rInfo);
455 2151 : rSet.Put(aFtnItem);
456 :
457 : // Register compliant
458 2151 : const SwTxtFmtColl* pCol = rPageDesc.GetRegisterFmtColl();
459 4302 : SwRegisterItem aReg(pCol != 0);
460 2151 : aReg.SetWhich(SID_SWREGISTER_MODE);
461 2151 : rSet.Put(aReg);
462 2151 : if(pCol)
463 2151 : rSet.Put(SfxStringItem(SID_SWREGISTER_COLLECTION, pCol->GetName()));
464 :
465 2151 : }
466 :
467 : // Set DefaultTabs
468 :
469 0 : void MakeDefTabs(SwTwips nDefDist, SvxTabStopItem& rTabs)
470 : {
471 0 : if( rTabs.Count() )
472 0 : return;
473 : {
474 0 : SvxTabStop aSwTabStop( nDefDist, SVX_TAB_ADJUST_DEFAULT );
475 0 : rTabs.Insert( aSwTabStop );
476 : }
477 : }
478 :
479 : // Distance between two tabs
480 :
481 261 : sal_uInt16 GetTabDist(const SvxTabStopItem& rTabs)
482 : {
483 : sal_uInt16 nDefDist;
484 261 : if( rTabs.Count() )
485 261 : nDefDist = (sal_uInt16)( rTabs[0].GetTabPos() );
486 : else
487 0 : nDefDist = 1134; // 2cm
488 261 : return nDefDist;
489 : }
490 :
491 :
492 : // Inquire if in the set is a Sfx-PageDesc combination present and return it.
493 0 : void SfxToSwPageDescAttr( const SwWrtShell& rShell, SfxItemSet& rSet )
494 : {
495 : const SfxPoolItem* pItem;
496 0 : SwFmtPageDesc aPgDesc;
497 :
498 0 : bool bChanged = false;
499 : // Page number
500 0 : if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_PARA_PAGENUM, sal_False, &pItem))
501 : {
502 0 : aPgDesc.SetNumOffset(((SfxUInt16Item*)pItem)->GetValue());
503 0 : bChanged = true;
504 : }
505 0 : if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PARA_MODEL, sal_False, &pItem ))
506 : {
507 0 : const String& rDescName = ((SvxPageModelItem*)pItem)->GetValue();
508 0 : if( rDescName.Len() ) // No name -> disable PageDesc!
509 : {
510 : // Delete only, if PageDesc will be enabled!
511 0 : rSet.ClearItem( RES_BREAK );
512 : SwPageDesc* pDesc = ((SwWrtShell&)rShell).FindPageDescByName(
513 0 : rDescName, sal_True );
514 0 : if( pDesc )
515 0 : aPgDesc.RegisterToPageDesc( *pDesc );
516 : }
517 0 : rSet.ClearItem( SID_ATTR_PARA_MODEL );
518 0 : bChanged = true;
519 : }
520 : else
521 : {
522 0 : SfxItemSet aCoreSet(rShell.GetView().GetPool(), RES_PAGEDESC, RES_PAGEDESC );
523 0 : rShell.GetCurAttr( aCoreSet );
524 0 : if(SFX_ITEM_SET == aCoreSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) )
525 : {
526 0 : if( ((SwFmtPageDesc*)pItem)->GetPageDesc() )
527 : {
528 0 : aPgDesc.RegisterToPageDesc( *((SwFmtPageDesc*)pItem)->GetPageDesc() );
529 : }
530 0 : }
531 : }
532 :
533 0 : if(bChanged)
534 0 : rSet.Put( aPgDesc );
535 0 : }
536 :
537 : // Inquire if in the set is a Sfx-PageDesc combination present and return it.
538 0 : void SwToSfxPageDescAttr( SfxItemSet& rCoreSet )
539 : {
540 0 : const SfxPoolItem* pItem = 0;
541 0 : String aName;
542 0 : sal_uInt16 nPageNum = 0;
543 0 : bool bPut = true;
544 0 : switch( rCoreSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) )
545 : {
546 : case SFX_ITEM_SET:
547 : {
548 0 : if( ((SwFmtPageDesc*)pItem)->GetPageDesc() )
549 : {
550 0 : aName = ((SwFmtPageDesc*)pItem)->GetPageDesc()->GetName();
551 0 : nPageNum = ((SwFmtPageDesc*)pItem)->GetNumOffset();
552 : }
553 0 : rCoreSet.ClearItem( RES_PAGEDESC );
554 : // Page number
555 : }
556 0 : break;
557 :
558 : case SFX_ITEM_AVAILABLE:
559 0 : break;
560 :
561 : default:
562 0 : bPut = false;
563 : }
564 0 : SfxUInt16Item aPageNum( SID_ATTR_PARA_PAGENUM, nPageNum );
565 0 : rCoreSet.Put( aPageNum );
566 :
567 0 : if(bPut)
568 0 : rCoreSet.Put( SvxPageModelItem( aName, sal_True, SID_ATTR_PARA_MODEL ) );
569 0 : }
570 :
571 : // Determine metric
572 :
573 0 : FieldUnit GetDfltMetric(sal_Bool bWeb)
574 : {
575 0 : return SW_MOD()->GetUsrPref(bWeb)->GetMetric();
576 : }
577 :
578 : // Determine metric
579 :
580 0 : void SetDfltMetric( FieldUnit eMetric, sal_Bool bWeb )
581 : {
582 0 : SW_MOD()->ApplyUserMetric(eMetric, bWeb);
583 0 : }
584 :
585 0 : sal_uInt16 InsertStringSorted(const String& rEntry, ListBox& rToFill, sal_uInt16 nOffset )
586 : {
587 0 : sal_uInt16 i = nOffset;
588 0 : CollatorWrapper& rCaseColl = ::GetAppCaseCollator();
589 :
590 0 : for( ; i < rToFill.GetEntryCount(); i++ )
591 : {
592 0 : if( 0 < rCaseColl.compareString( rToFill.GetEntry(i), rEntry ))
593 0 : break;
594 : }
595 0 : return rToFill.InsertEntry(rEntry, i);
596 : }
597 0 : void FillCharStyleListBox(ListBox& rToFill, SwDocShell* pDocSh, bool bSorted, bool bWithDefault)
598 : {
599 0 : sal_Bool bHasOffset = rToFill.GetEntryCount() > 0;
600 0 : SfxStyleSheetBasePool* pPool = pDocSh->GetStyleSheetPool();
601 0 : pPool->SetSearchMask(SFX_STYLE_FAMILY_CHAR, SFXSTYLEBIT_ALL);
602 0 : SwDoc* pDoc = pDocSh->GetDoc();
603 0 : const SfxStyleSheetBase* pBase = pPool->First();
604 0 : String sStandard;
605 0 : SwStyleNameMapper::FillUIName( RES_POOLCOLL_STANDARD, sStandard );
606 0 : while(pBase)
607 : {
608 0 : if(bWithDefault || pBase->GetName() != sStandard)
609 : {
610 : sal_uInt16 nPos;
611 0 : if(bSorted)
612 0 : nPos = InsertStringSorted(pBase->GetName(), rToFill, bHasOffset );
613 : else
614 0 : nPos = rToFill.InsertEntry(pBase->GetName());
615 0 : sal_IntPtr nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( pBase->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
616 0 : rToFill.SetEntryData( nPos, (void*) (nPoolId));
617 : }
618 0 : pBase = pPool->Next();
619 : }
620 : // non-pool styles
621 0 : const SwCharFmts* pFmts = pDoc->GetCharFmts();
622 0 : for(sal_uInt16 i = 0; i < pFmts->size(); i++)
623 : {
624 0 : const SwCharFmt* pFmt = (*pFmts)[i];
625 0 : if(pFmt->IsDefault())
626 0 : continue;
627 0 : const String& rName = pFmt->GetName();
628 0 : if(rToFill.GetEntryPos(rName) == LISTBOX_ENTRY_NOTFOUND)
629 : {
630 : sal_uInt16 nPos;
631 0 : if(bSorted)
632 0 : nPos = InsertStringSorted(rName, rToFill, bHasOffset );
633 : else
634 0 : nPos = rToFill.InsertEntry(rName);
635 0 : sal_IntPtr nPoolId = USHRT_MAX;
636 0 : rToFill.SetEntryData( nPos, (void*) (nPoolId));
637 : }
638 0 : }
639 0 : };
640 :
641 0 : SwTwips GetTableWidth( SwFrmFmt* pFmt, SwTabCols& rCols, sal_uInt16 *pPercent,
642 : SwWrtShell* pSh )
643 : {
644 : // To get the width is slightly more complicated.
645 0 : SwTwips nWidth = 0;
646 0 : const sal_Int16 eOri = pFmt->GetHoriOrient().GetHoriOrient();
647 0 : switch(eOri)
648 : {
649 0 : case text::HoriOrientation::FULL: nWidth = rCols.GetRight(); break;
650 : case text::HoriOrientation::LEFT_AND_WIDTH:
651 : case text::HoriOrientation::LEFT:
652 : case text::HoriOrientation::RIGHT:
653 : case text::HoriOrientation::CENTER:
654 0 : nWidth = pFmt->GetFrmSize().GetWidth();
655 0 : break;
656 : default:
657 : {
658 0 : if(pSh)
659 : {
660 0 : if ( 0 == pSh->GetFlyFrmFmt() )
661 : {
662 0 : nWidth = pSh->GetAnyCurRect(RECT_PAGE_PRT).Width();
663 : }
664 : else
665 : {
666 0 : nWidth = pSh->GetAnyCurRect(RECT_FLY_PRT_EMBEDDED).Width();
667 : }
668 : }
669 : else
670 : {
671 : OSL_FAIL("where to get the actual width from?");
672 : }
673 0 : const SvxLRSpaceItem& rLRSpace = pFmt->GetLRSpace();
674 0 : nWidth -= (rLRSpace.GetRight() + rLRSpace.GetLeft());
675 : }
676 : }
677 0 : if (pPercent)
678 0 : *pPercent = pFmt->GetFrmSize().GetWidthPercent();
679 0 : return nWidth;
680 : }
681 :
682 0 : String GetAppLangDateTimeString( const DateTime& rDT )
683 : {
684 0 : const SvtSysLocale aSysLocale;
685 0 : const LocaleDataWrapper& rAppLclData = aSysLocale.GetLocaleData();
686 0 : String sRet( rAppLclData.getDate( rDT ));
687 0 : ( sRet += ' ' ) += rAppLclData.getTime( rDT, sal_False, sal_False );
688 0 : return sRet;
689 : }
690 :
691 : // Add a new function which can get and set the current "SID_ATTR_APPLYCHARUNIT" value
692 :
693 0 : sal_Bool HasCharUnit( sal_Bool bWeb)
694 : {
695 0 : return SW_MOD()->GetUsrPref(bWeb)->IsApplyCharUnit();
696 : }
697 :
698 0 : void SetApplyCharUnit(sal_Bool bApplyChar, sal_Bool bWeb)
699 : {
700 0 : SW_MOD()->ApplyUserCharUnit(bApplyChar, bWeb);
701 0 : }
702 :
703 0 : bool ExecuteMenuCommand( PopupMenu& rMenu, SfxViewFrame& rViewFrame, sal_uInt16 nId )
704 : {
705 0 : bool bRet = false;
706 0 : sal_uInt16 nItemCount = rMenu.GetItemCount();
707 0 : String sCommand;
708 0 : for( sal_uInt16 nItem = 0; nItem < nItemCount; ++nItem)
709 : {
710 0 : PopupMenu* pPopup = rMenu.GetPopupMenu( rMenu.GetItemId( nItem ) );
711 0 : if(pPopup)
712 : {
713 0 : sCommand = pPopup->GetItemCommand(nId);
714 0 : if(sCommand.Len())
715 0 : break;
716 : }
717 : }
718 0 : if(sCommand.Len())
719 : {
720 0 : uno::Reference< frame::XFrame > xFrame = rViewFrame.GetFrame().GetFrameInterface();
721 0 : uno::Reference < frame::XDispatchProvider > xProv( xFrame, uno::UNO_QUERY );
722 0 : util::URL aURL;
723 0 : aURL.Complete = sCommand;
724 0 : uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create(::comphelper::getProcessComponentContext() ) );
725 0 : xTrans->parseStrict( aURL );
726 0 : uno::Reference< frame::XDispatch > xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
727 0 : if( xDisp.is() )
728 : {
729 0 : uno::Sequence< beans::PropertyValue > aSeq;
730 0 : xDisp->dispatch( aURL, aSeq );
731 0 : bRet = true;
732 0 : }
733 : }
734 0 : return bRet;
735 99 : }
736 :
737 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|