bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / utlui / uitool.cxx
blob530363976d20b97f616f304e45ad8d262f9e19ec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <hintids.hxx>
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"
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
75 #define MAXHEIGHT 28350
76 #define MAXWIDTH 28350
78 using namespace ::com::sun::star;
80 // General list of string pointer
82 // Switch metric
84 void SetMetric(MetricFormatter& rCtrl, FieldUnit eUnit)
86 SwTwips nMin = static_cast< SwTwips >(rCtrl.GetMin(FUNIT_TWIP));
87 SwTwips nMax = static_cast< SwTwips >(rCtrl.GetMax(FUNIT_TWIP));
89 rCtrl.SetUnit(eUnit);
91 rCtrl.SetMin(nMin, FUNIT_TWIP);
92 rCtrl.SetMax(nMax, FUNIT_TWIP);
95 // Set boxinfo attribute
97 void PrepareBoxInfo(SfxItemSet& rSet, const SwWrtShell& rSh)
99 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
100 const SfxPoolItem *pBoxInfo;
101 if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER,
102 sal_True, &pBoxInfo))
103 aBoxInfo = *(SvxBoxInfoItem*)pBoxInfo;
105 // Table variant: If more than one table cells are selected
106 rSh.GetCrsr(); //So that GetCrsrCnt() returns the right thing
107 aBoxInfo.SetTable (rSh.IsTableMode() && rSh.GetCrsrCnt() > 1);
108 // Always show the distance field
109 aBoxInfo.SetDist ((sal_Bool) sal_True);
110 // Set minimal size in tables and paragraphs
111 aBoxInfo.SetMinDist (rSh.IsTableMode() || rSh.GetSelectionType() & (nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL));
112 // Set always the default distance
113 aBoxInfo.SetDefDist (MIN_BORDER_DIST);
114 // Single lines can have only in tables DontCare-Status
115 aBoxInfo.SetValid(VALID_DISABLE, !rSh.IsTableMode());
117 rSet.Put(aBoxInfo);
120 // Fill header footer
122 void FillHdFt(SwFrmFmt* pFmt, const SfxItemSet& rSet)
124 SwAttrSet aSet(pFmt->GetAttrSet());
125 aSet.Put(rSet);
127 const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get(SID_ATTR_PAGE_SIZE);
128 const SfxBoolItem& rDynamic = (const SfxBoolItem&)rSet.Get(SID_ATTR_PAGE_DYNAMIC);
130 // Convert size
131 SwFmtFrmSize aFrmSize(rDynamic.GetValue() ? ATT_MIN_SIZE : ATT_FIX_SIZE,
132 rSize.GetSize().Width(),
133 rSize.GetSize().Height());
134 aSet.Put(aFrmSize);
135 pFmt->SetFmtAttr(aSet);
138 /// Convert from UseOnPage to SvxPageUsage.
139 UseOnPage lcl_convertUseToSvx(UseOnPage nUse)
141 UseOnPage nRet = nsUseOnPage::PD_NONE;
142 if ((nUse & nsUseOnPage::PD_LEFT) == nsUseOnPage::PD_LEFT)
143 nRet |= SVX_PAGE_LEFT;
144 if ((nUse & nsUseOnPage::PD_RIGHT) == nsUseOnPage::PD_RIGHT)
145 nRet |= SVX_PAGE_RIGHT;
146 if ((nUse & nsUseOnPage::PD_ALL) == nsUseOnPage::PD_ALL)
147 nRet |= SVX_PAGE_ALL;
148 if ((nUse & nsUseOnPage::PD_MIRROR) == nsUseOnPage::PD_MIRROR)
149 nRet |= SVX_PAGE_MIRROR;
150 return nRet;
153 /// Convert from SvxPageUsage to UseOnPage.
154 UseOnPage lcl_convertUseFromSvx(UseOnPage nUse)
156 UseOnPage nRet = nsUseOnPage::PD_NONE;
157 if ((nUse & SVX_PAGE_LEFT) == SVX_PAGE_LEFT)
158 nRet |= nsUseOnPage::PD_LEFT;
159 if ((nUse & SVX_PAGE_RIGHT) == SVX_PAGE_RIGHT)
160 nRet |= nsUseOnPage::PD_RIGHT;
161 if ((nUse & SVX_PAGE_ALL) == SVX_PAGE_ALL)
162 nRet |= nsUseOnPage::PD_ALL;
163 if ((nUse & SVX_PAGE_MIRROR) == SVX_PAGE_MIRROR)
164 nRet |= nsUseOnPage::PD_MIRROR;
165 return nRet;
168 // PageDesc <-> convert into sets and back
170 void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc )
172 SwFrmFmt& rMaster = rPageDesc.GetMaster();
173 int nFirstShare = -1;
175 // Transfer all general frame attributes
176 rMaster.SetFmtAttr(rSet);
178 // PageData
179 if(rSet.GetItemState(SID_ATTR_PAGE) == SFX_ITEM_SET)
181 const SvxPageItem& rPageItem = (const SvxPageItem&)rSet.Get(SID_ATTR_PAGE);
183 sal_uInt16 nUse = (sal_uInt16)rPageItem.GetPageUsage();
184 if(nUse)
185 rPageDesc.SetUseOn( lcl_convertUseFromSvx((UseOnPage) nUse) );
186 rPageDesc.SetLandscape(rPageItem.IsLandscape());
187 SvxNumberType aNumType;
188 aNumType.SetNumberingType( static_cast< sal_Int16 >(rPageItem.GetNumType()) );
189 rPageDesc.SetNumType(aNumType);
191 // Size
192 if(rSet.GetItemState(SID_ATTR_PAGE_SIZE) == SFX_ITEM_SET)
194 const SvxSizeItem& rSizeItem = (const SvxSizeItem&)rSet.Get(SID_ATTR_PAGE_SIZE);
195 SwFmtFrmSize aSize(ATT_FIX_SIZE);
196 aSize.SetSize(rSizeItem.GetSize());
197 rMaster.SetFmtAttr(aSize);
199 // Evaluate header attributes
200 const SfxPoolItem* pItem;
201 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PAGE_HEADERSET,
202 sal_False, &pItem ) )
204 const SfxItemSet& rHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
205 const SfxBoolItem& rHeaderOn = (const SfxBoolItem&)rHeaderSet.Get(SID_ATTR_PAGE_ON);
207 if(rHeaderOn.GetValue())
209 // Take over values
210 if(!rMaster.GetHeader().IsActive())
211 rMaster.SetFmtAttr(SwFmtHeader(sal_True));
213 // Pick out everything and adapt the header format
214 SwFmtHeader aHeaderFmt(rMaster.GetHeader());
215 SwFrmFmt *pHeaderFmt = aHeaderFmt.GetHeaderFmt();
216 OSL_ENSURE(pHeaderFmt != 0, "no header format");
218 ::FillHdFt(pHeaderFmt, rHeaderSet);
220 rPageDesc.ChgHeaderShare(((const SfxBoolItem&)
221 rHeaderSet.Get(SID_ATTR_PAGE_SHARED)).GetValue());
222 if (nFirstShare < 0)
224 rPageDesc.ChgFirstShare(((const SfxBoolItem&)
225 rHeaderSet.Get(SID_ATTR_PAGE_SHARED_FIRST)).GetValue());
226 nFirstShare = rPageDesc.IsFirstShared();
229 else
231 // Disable header
232 if(rMaster.GetHeader().IsActive())
234 rMaster.SetFmtAttr(SwFmtHeader(sal_Bool(sal_False)));
235 rPageDesc.ChgHeaderShare(sal_False);
240 // Evaluate footer attributes
241 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PAGE_FOOTERSET,
242 sal_False, &pItem ) )
244 const SfxItemSet& rFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
245 const SfxBoolItem& rFooterOn = (const SfxBoolItem&)rFooterSet.Get(SID_ATTR_PAGE_ON);
247 if(rFooterOn.GetValue())
249 // Take over values
250 if(!rMaster.GetFooter().IsActive())
251 rMaster.SetFmtAttr(SwFmtFooter(sal_True));
253 // Pick out everything and adapt the footer format
254 SwFmtFooter aFooterFmt(rMaster.GetFooter());
255 SwFrmFmt *pFooterFmt = aFooterFmt.GetFooterFmt();
256 OSL_ENSURE(pFooterFmt != 0, "no footer format");
258 ::FillHdFt(pFooterFmt, rFooterSet);
260 rPageDesc.ChgFooterShare(((const SfxBoolItem&)
261 rFooterSet.Get(SID_ATTR_PAGE_SHARED)).GetValue());
262 if (nFirstShare < 0)
264 rPageDesc.ChgFirstShare(((const SfxBoolItem&)
265 rFooterSet.Get(SID_ATTR_PAGE_SHARED_FIRST)).GetValue());
266 nFirstShare = rPageDesc.IsFirstShared();
269 else
271 // Disable footer
272 if(rMaster.GetFooter().IsActive())
274 rMaster.SetFmtAttr(SwFmtFooter(sal_Bool(sal_False)));
275 rPageDesc.ChgFooterShare(sal_False);
280 // Footnotes
282 if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_FTN_INFO,
283 sal_False, &pItem ) )
284 rPageDesc.SetFtnInfo( ((SwPageFtnInfoItem*)pItem)->GetPageFtnInfo() );
286 // Columns
288 // Register compliant
290 if(SFX_ITEM_SET == rSet.GetItemState(
291 SID_SWREGISTER_MODE, sal_False, &pItem))
293 sal_Bool bSet = ((const SfxBoolItem*)pItem)->GetValue();
294 if(!bSet)
295 rPageDesc.SetRegisterFmtColl(0);
296 else if(SFX_ITEM_SET == rSet.GetItemState(
297 SID_SWREGISTER_COLLECTION, sal_False, &pItem))
299 const String& rColl = ((const SfxStringItem*)pItem)->GetValue();
300 SwDoc& rDoc = *rMaster.GetDoc();
301 SwTxtFmtColl* pColl = rDoc.FindTxtFmtCollByName( rColl );
302 if( !pColl )
304 sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rColl, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
305 if( USHRT_MAX != nId )
306 pColl = rDoc.GetTxtCollFromPool( nId );
307 else
308 pColl = rDoc.MakeTxtFmtColl( rColl,
309 (SwTxtFmtColl*)rDoc.GetDfltTxtFmtColl() );
311 if( pColl )
312 pColl->SetFmtAttr( SwRegisterItem ( sal_True ));
313 rPageDesc.SetRegisterFmtColl( pColl );
318 void PageDescToItemSet( const SwPageDesc& rPageDesc, SfxItemSet& rSet)
320 const SwFrmFmt& rMaster = rPageDesc.GetMaster();
322 // Page data
323 SvxPageItem aPageItem(SID_ATTR_PAGE);
324 aPageItem.SetDescName(rPageDesc.GetName());
325 aPageItem.SetPageUsage(lcl_convertUseToSvx(rPageDesc.GetUseOn()));
326 aPageItem.SetLandscape(rPageDesc.GetLandscape());
327 aPageItem.SetNumType((SvxNumType)rPageDesc.GetNumType().GetNumberingType());
328 rSet.Put(aPageItem);
330 // Size
331 SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, rMaster.GetFrmSize().GetSize());
332 rSet.Put(aSizeItem);
334 // Maximum size
335 SvxSizeItem aMaxSizeItem(SID_ATTR_PAGE_MAXSIZE, Size(MAXWIDTH, MAXHEIGHT));
336 rSet.Put(aMaxSizeItem);
338 // Margins, border and the other stuff.
339 rSet.Put(rMaster.GetAttrSet());
341 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
342 const SfxPoolItem *pBoxInfo;
343 if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER,
344 sal_True, &pBoxInfo) )
345 aBoxInfo = *(SvxBoxInfoItem*)pBoxInfo;
347 aBoxInfo.SetTable( sal_False );
348 // Show always the distance field
349 aBoxInfo.SetDist( sal_True);
350 // Set minimal size in tables and paragraphs
351 aBoxInfo.SetMinDist( sal_False );
352 // Set always the default distance
353 aBoxInfo.SetDefDist( MIN_BORDER_DIST );
354 // Single lines can have only in tables DontCare-Status
355 aBoxInfo.SetValid( VALID_DISABLE );
356 rSet.Put( aBoxInfo );
359 SfxStringItem aFollow(SID_ATTR_PAGE_EXT1, aEmptyStr);
360 if(rPageDesc.GetFollow())
361 aFollow.SetValue(rPageDesc.GetFollow()->GetName());
362 rSet.Put(aFollow);
364 // Header
365 if(rMaster.GetHeader().IsActive())
367 const SwFmtHeader &rHeaderFmt = rMaster.GetHeader();
368 const SwFrmFmt *pHeaderFmt = rHeaderFmt.GetHeaderFmt();
369 OSL_ENSURE(pHeaderFmt != 0, "no header format");
371 // HeaderInfo, margins, background, border
372 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,
380 // Dynamic or fixed height
381 SfxBoolItem aOn(SID_ATTR_PAGE_ON, sal_True);
382 aHeaderSet.Put(aOn);
384 const SwFmtFrmSize &rFrmSize = pHeaderFmt->GetFrmSize();
385 const SwFrmSize eSizeType = rFrmSize.GetHeightSizeType();
386 SfxBoolItem aDynamic(SID_ATTR_PAGE_DYNAMIC, eSizeType != ATT_FIX_SIZE);
387 aHeaderSet.Put(aDynamic);
389 // Left equal right
390 SfxBoolItem aShared(SID_ATTR_PAGE_SHARED, rPageDesc.IsHeaderShared());
391 aHeaderSet.Put(aShared);
392 SfxBoolItem aFirstShared(SID_ATTR_PAGE_SHARED_FIRST, rPageDesc.IsFirstShared());
393 aHeaderSet.Put(aFirstShared);
395 // Size
396 SvxSizeItem aSize(SID_ATTR_PAGE_SIZE, Size(rFrmSize.GetSize()));
397 aHeaderSet.Put(aSize);
399 // Shifting frame attributes
400 aHeaderSet.Put(pHeaderFmt->GetAttrSet());
401 aHeaderSet.Put( aBoxInfo );
403 // Create SetItem
404 SvxSetItem aSetItem(SID_ATTR_PAGE_HEADERSET, aHeaderSet);
405 rSet.Put(aSetItem);
408 // Footer
409 if(rMaster.GetFooter().IsActive())
411 const SwFmtFooter &rFooterFmt = rMaster.GetFooter();
412 const SwFrmFmt *pFooterFmt = rFooterFmt.GetFooterFmt();
413 OSL_ENSURE(pFooterFmt != 0, "no footer format");
415 // FooterInfo, margins, background, border
416 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,
424 // Dynamic or fixed height
425 SfxBoolItem aOn(SID_ATTR_PAGE_ON, sal_True);
426 aFooterSet.Put(aOn);
428 const SwFmtFrmSize &rFrmSize = pFooterFmt->GetFrmSize();
429 const SwFrmSize eSizeType = rFrmSize.GetHeightSizeType();
430 SfxBoolItem aDynamic(SID_ATTR_PAGE_DYNAMIC, eSizeType != ATT_FIX_SIZE);
431 aFooterSet.Put(aDynamic);
433 // Left equal right
434 SfxBoolItem aShared(SID_ATTR_PAGE_SHARED, rPageDesc.IsFooterShared());
435 aFooterSet.Put(aShared);
436 SfxBoolItem aFirstShared(SID_ATTR_PAGE_SHARED_FIRST, rPageDesc.IsFirstShared());
437 aFooterSet.Put(aFirstShared);
439 // Size
440 SvxSizeItem aSize(SID_ATTR_PAGE_SIZE, Size(rFrmSize.GetSize()));
441 aFooterSet.Put(aSize);
443 // Shifting Frame attributes
444 aFooterSet.Put(pFooterFmt->GetAttrSet());
445 aFooterSet.Put( aBoxInfo );
447 // Create SetItem
448 SvxSetItem aSetItem(SID_ATTR_PAGE_FOOTERSET, aFooterSet);
449 rSet.Put(aSetItem);
452 // Integrate footnotes
453 SwPageFtnInfo& rInfo = (SwPageFtnInfo&)rPageDesc.GetFtnInfo();
454 SwPageFtnInfoItem aFtnItem(FN_PARAM_FTN_INFO, rInfo);
455 rSet.Put(aFtnItem);
457 // Register compliant
458 const SwTxtFmtColl* pCol = rPageDesc.GetRegisterFmtColl();
459 SwRegisterItem aReg(pCol != 0);
460 aReg.SetWhich(SID_SWREGISTER_MODE);
461 rSet.Put(aReg);
462 if(pCol)
463 rSet.Put(SfxStringItem(SID_SWREGISTER_COLLECTION, pCol->GetName()));
467 // Set DefaultTabs
469 void MakeDefTabs(SwTwips nDefDist, SvxTabStopItem& rTabs)
471 if( rTabs.Count() )
472 return;
474 SvxTabStop aSwTabStop( nDefDist, SVX_TAB_ADJUST_DEFAULT );
475 rTabs.Insert( aSwTabStop );
479 // Distance between two tabs
481 sal_uInt16 GetTabDist(const SvxTabStopItem& rTabs)
483 sal_uInt16 nDefDist;
484 if( rTabs.Count() )
485 nDefDist = (sal_uInt16)( rTabs[0].GetTabPos() );
486 else
487 nDefDist = 1134; // 2cm
488 return nDefDist;
492 // Inquire if in the set is a Sfx-PageDesc combination present and return it.
493 void SfxToSwPageDescAttr( const SwWrtShell& rShell, SfxItemSet& rSet )
495 const SfxPoolItem* pItem;
496 SwFmtPageDesc aPgDesc;
498 bool bChanged = false;
499 // Page number
500 if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_PARA_PAGENUM, sal_False, &pItem))
502 aPgDesc.SetNumOffset(((SfxUInt16Item*)pItem)->GetValue());
503 bChanged = true;
505 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PARA_MODEL, sal_False, &pItem ))
507 const String& rDescName = ((SvxPageModelItem*)pItem)->GetValue();
508 if( rDescName.Len() ) // No name -> disable PageDesc!
510 // Delete only, if PageDesc will be enabled!
511 rSet.ClearItem( RES_BREAK );
512 SwPageDesc* pDesc = ((SwWrtShell&)rShell).FindPageDescByName(
513 rDescName, sal_True );
514 if( pDesc )
515 aPgDesc.RegisterToPageDesc( *pDesc );
517 rSet.ClearItem( SID_ATTR_PARA_MODEL );
518 bChanged = true;
520 else
522 SfxItemSet aCoreSet(rShell.GetView().GetPool(), RES_PAGEDESC, RES_PAGEDESC );
523 rShell.GetCurAttr( aCoreSet );
524 if(SFX_ITEM_SET == aCoreSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) )
526 if( ((SwFmtPageDesc*)pItem)->GetPageDesc() )
528 aPgDesc.RegisterToPageDesc( *((SwFmtPageDesc*)pItem)->GetPageDesc() );
533 if(bChanged)
534 rSet.Put( aPgDesc );
537 // Inquire if in the set is a Sfx-PageDesc combination present and return it.
538 void SwToSfxPageDescAttr( SfxItemSet& rCoreSet )
540 const SfxPoolItem* pItem = 0;
541 String aName;
542 sal_uInt16 nPageNum = 0;
543 bool bPut = true;
544 switch( rCoreSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) )
546 case SFX_ITEM_SET:
548 if( ((SwFmtPageDesc*)pItem)->GetPageDesc() )
550 aName = ((SwFmtPageDesc*)pItem)->GetPageDesc()->GetName();
551 nPageNum = ((SwFmtPageDesc*)pItem)->GetNumOffset();
553 rCoreSet.ClearItem( RES_PAGEDESC );
554 // Page number
556 break;
558 case SFX_ITEM_AVAILABLE:
559 break;
561 default:
562 bPut = false;
564 SfxUInt16Item aPageNum( SID_ATTR_PARA_PAGENUM, nPageNum );
565 rCoreSet.Put( aPageNum );
567 if(bPut)
568 rCoreSet.Put( SvxPageModelItem( aName, sal_True, SID_ATTR_PARA_MODEL ) );
571 // Determine metric
573 FieldUnit GetDfltMetric(sal_Bool bWeb)
575 return SW_MOD()->GetUsrPref(bWeb)->GetMetric();
578 // Determine metric
580 void SetDfltMetric( FieldUnit eMetric, sal_Bool bWeb )
582 SW_MOD()->ApplyUserMetric(eMetric, bWeb);
585 sal_uInt16 InsertStringSorted(const String& rEntry, ListBox& rToFill, sal_uInt16 nOffset )
587 sal_uInt16 i = nOffset;
588 CollatorWrapper& rCaseColl = ::GetAppCaseCollator();
590 for( ; i < rToFill.GetEntryCount(); i++ )
592 if( 0 < rCaseColl.compareString( rToFill.GetEntry(i), rEntry ))
593 break;
595 return rToFill.InsertEntry(rEntry, i);
597 void FillCharStyleListBox(ListBox& rToFill, SwDocShell* pDocSh, bool bSorted, bool bWithDefault)
599 sal_Bool bHasOffset = rToFill.GetEntryCount() > 0;
600 SfxStyleSheetBasePool* pPool = pDocSh->GetStyleSheetPool();
601 pPool->SetSearchMask(SFX_STYLE_FAMILY_CHAR, SFXSTYLEBIT_ALL);
602 SwDoc* pDoc = pDocSh->GetDoc();
603 const SfxStyleSheetBase* pBase = pPool->First();
604 String sStandard;
605 SwStyleNameMapper::FillUIName( RES_POOLCOLL_STANDARD, sStandard );
606 while(pBase)
608 if(bWithDefault || pBase->GetName() != sStandard)
610 sal_uInt16 nPos;
611 if(bSorted)
612 nPos = InsertStringSorted(pBase->GetName(), rToFill, bHasOffset );
613 else
614 nPos = rToFill.InsertEntry(pBase->GetName());
615 long nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( pBase->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
616 rToFill.SetEntryData( nPos, (void*) (nPoolId));
618 pBase = pPool->Next();
620 // non-pool styles
621 const SwCharFmts* pFmts = pDoc->GetCharFmts();
622 for(sal_uInt16 i = 0; i < pFmts->size(); i++)
624 const SwCharFmt* pFmt = (*pFmts)[i];
625 if(pFmt->IsDefault())
626 continue;
627 const String& rName = pFmt->GetName();
628 if(rToFill.GetEntryPos(rName) == LISTBOX_ENTRY_NOTFOUND)
630 sal_uInt16 nPos;
631 if(bSorted)
632 nPos = InsertStringSorted(rName, rToFill, bHasOffset );
633 else
634 nPos = rToFill.InsertEntry(rName);
635 long nPoolId = USHRT_MAX;
636 rToFill.SetEntryData( nPos, (void*) (nPoolId));
641 SwTwips GetTableWidth( SwFrmFmt* pFmt, SwTabCols& rCols, sal_uInt16 *pPercent,
642 SwWrtShell* pSh )
644 // To get the width is slightly more complicated.
645 SwTwips nWidth = 0;
646 const sal_Int16 eOri = pFmt->GetHoriOrient().GetHoriOrient();
647 switch(eOri)
649 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 nWidth = pFmt->GetFrmSize().GetWidth();
655 break;
656 default:
658 if(pSh)
660 if ( 0 == pSh->GetFlyFrmFmt() )
662 nWidth = pSh->GetAnyCurRect(RECT_PAGE_PRT).Width();
664 else
666 nWidth = pSh->GetAnyCurRect(RECT_FLY_PRT_EMBEDDED).Width();
669 else
671 OSL_FAIL("where to get the actual width from?");
673 const SvxLRSpaceItem& rLRSpace = pFmt->GetLRSpace();
674 nWidth -= (rLRSpace.GetRight() + rLRSpace.GetLeft());
677 if (pPercent)
678 *pPercent = pFmt->GetFrmSize().GetWidthPercent();
679 return nWidth;
682 String GetAppLangDateTimeString( const DateTime& rDT )
684 const SvtSysLocale aSysLocale;
685 const LocaleDataWrapper& rAppLclData = aSysLocale.GetLocaleData();
686 String sRet( rAppLclData.getDate( rDT ));
687 ( sRet += ' ' ) += rAppLclData.getTime( rDT, sal_False, sal_False );
688 return sRet;
691 // Add a new function which can get and set the current "SID_ATTR_APPLYCHARUNIT" value
693 sal_Bool HasCharUnit( sal_Bool bWeb)
695 return SW_MOD()->GetUsrPref(bWeb)->IsApplyCharUnit();
698 void SetApplyCharUnit(sal_Bool bApplyChar, sal_Bool bWeb)
700 SW_MOD()->ApplyUserCharUnit(bApplyChar, bWeb);
703 bool ExecuteMenuCommand( PopupMenu& rMenu, SfxViewFrame& rViewFrame, sal_uInt16 nId )
705 bool bRet = false;
706 sal_uInt16 nItemCount = rMenu.GetItemCount();
707 String sCommand;
708 for( sal_uInt16 nItem = 0; nItem < nItemCount; ++nItem)
710 PopupMenu* pPopup = rMenu.GetPopupMenu( rMenu.GetItemId( nItem ) );
711 if(pPopup)
713 sCommand = pPopup->GetItemCommand(nId);
714 if(sCommand.Len())
715 break;
718 if(sCommand.Len())
720 uno::Reference< frame::XFrame > xFrame = rViewFrame.GetFrame().GetFrameInterface();
721 uno::Reference < frame::XDispatchProvider > xProv( xFrame, uno::UNO_QUERY );
722 util::URL aURL;
723 aURL.Complete = sCommand;
724 uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create(::comphelper::getProcessComponentContext() ) );
725 xTrans->parseStrict( aURL );
726 uno::Reference< frame::XDispatch > xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
727 if( xDisp.is() )
729 uno::Sequence< beans::PropertyValue > aSeq;
730 xDisp->dispatch( aURL, aSeq );
731 bRet = true;
734 return bRet;
737 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */