xref: /aoo42x/main/sw/source/ui/utlui/uitool.cxx (revision 56b35d86)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <hintids.hxx>
29 
30 #include <tools/datetime.hxx>
31 #include <vcl/svapp.hxx>
32 #include <unotools/collatorwrapper.hxx>
33 #include <svl/urihelper.hxx>
34 #include <svl/stritem.hxx>
35 #include <unotools/syslocale.hxx>
36 #include <sfx2/app.hxx>
37 #include <sfx2/docfile.hxx>
38 #include <sfx2/docfilt.hxx>
39 #include <editeng/pmdlitem.hxx>
40 #ifndef _SVX_TSTPITEM_HXX //autogen
41 #include <editeng/tstpitem.hxx>
42 #endif
43 #include <editeng/boxitem.hxx>
44 #include <editeng/sizeitem.hxx>
45 #include <svx/pageitem.hxx>
46 #include <editeng/lrspitem.hxx>
47 #include <svl/style.hxx>
48 #ifndef _VCL_LSTBOX_HXX //autogen
49 #include <vcl/lstbox.hxx>
50 #endif
51 #include <unotools/localedatawrapper.hxx>
52 #include <com/sun/star/frame/XDispatch.hpp>
53 #include <com/sun/star/frame/XDispatchProvider.hpp>
54 #include <com/sun/star/util/XURLTransformer.hpp>
55 #include <comphelper/processfactory.hxx>
56 #include <sfx2/viewfrm.hxx>
57 #include <fmtornt.hxx>
58 #include <tabcol.hxx>
59 #include <edtwin.hxx>
60 #include <fmtfsize.hxx>
61 #include <fmthdft.hxx>
62 #include <fmtpdsc.hxx>
63 #include <wview.hxx>
64 #include <uiitems.hxx>
65 #ifndef _DOCSH_HXX
66 #include <docsh.hxx>
67 #endif
68 #include <wrtsh.hxx>
69 #include <swmodule.hxx>
70 #ifndef _VIEW_HXX
71 #include <view.hxx>
72 #endif
73 #include <uitool.hxx>
74 #include <frmatr.hxx>
75 #include <paratr.hxx>
76 #include <fmtcol.hxx>
77 #include <poolfmt.hxx>
78 #include "usrpref.hxx"
79 
80 #ifndef _ERROR_H
81 #include <error.h>
82 #endif
83 #ifndef _CMDID_H
84 #include <cmdid.h>
85 #endif
86 #ifndef _GLOBALS_HRC
87 #include <globals.hrc>
88 #endif
89 #ifndef _UTLUI_HRC
90 #include <utlui.hrc>
91 #endif
92 #include <doc.hxx>
93 #include <docary.hxx>
94 #include <charfmt.hxx>
95 #include <SwStyleNameMapper.hxx>
96 // 50 cm 28350
97 //
98 #define MAXHEIGHT 28350
99 #define MAXWIDTH  28350
100 
101 using namespace ::com::sun::star;
102 /*--------------------------------------------------------------------
103 	Beschreibung: Allgemeine List von StringPointern
104  --------------------------------------------------------------------*/
105 
106 
107 /*--------------------------------------------------------------------
108 	Beschreibung: Metric umschalten
109  --------------------------------------------------------------------*/
110 
111 
SetMetric(MetricFormatter & rCtrl,FieldUnit eUnit)112 void SetMetric(MetricFormatter& rCtrl, FieldUnit eUnit)
113 {
114     SwTwips nMin = static_cast< SwTwips >(rCtrl.GetMin(FUNIT_TWIP));
115     SwTwips nMax = static_cast< SwTwips >(rCtrl.GetMax(FUNIT_TWIP));
116 
117 	rCtrl.SetUnit(eUnit);
118 
119 	rCtrl.SetMin(nMin, FUNIT_TWIP);
120 	rCtrl.SetMax(nMax, FUNIT_TWIP);
121 }
122 
123 /*--------------------------------------------------------------------
124 	Beschreibung:	Boxinfo-Attribut setzen
125  --------------------------------------------------------------------*/
126 
127 
PrepareBoxInfo(SfxItemSet & rSet,const SwWrtShell & rSh)128 void PrepareBoxInfo(SfxItemSet& rSet, const SwWrtShell& rSh)
129 {
130     SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
131 	const SfxPoolItem *pBoxInfo;
132 	if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER,
133 										sal_True, &pBoxInfo))
134 		aBoxInfo = *(SvxBoxInfoItem*)pBoxInfo;
135 
136 		// Tabellenvariante, wenn mehrere Tabellenzellen selektiert
137 	rSh.GetCrsr();					//Damit GetCrsrCnt() auch das Richtige liefert
138 	aBoxInfo.SetTable          (rSh.IsTableMode() && rSh.GetCrsrCnt() > 1);
139 		// Abstandsfeld immer anzeigen
140 	aBoxInfo.SetDist           ((sal_Bool) sal_True);
141 		// Minimalgroesse in Tabellen und Absaetzen setzen
142 	aBoxInfo.SetMinDist        (rSh.IsTableMode() || rSh.GetSelectionType() & (nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL));
143 		// Default-Abstand immer setzen
144 	aBoxInfo.SetDefDist        (MIN_BORDER_DIST);
145 		// Einzelne Linien koennen nur in Tabellen DontCare-Status haben
146 	aBoxInfo.SetValid(VALID_DISABLE, !rSh.IsTableMode());
147 
148 	rSet.Put(aBoxInfo);
149 }
150 
151 /*--------------------------------------------------------------------
152 	Beschreibung:	Header Footer fuellen
153  --------------------------------------------------------------------*/
154 
155 
FillHdFt(SwFrmFmt * pFmt,const SfxItemSet & rSet)156 void FillHdFt(SwFrmFmt* pFmt, const  SfxItemSet& rSet)
157 {
158 	SwAttrSet aSet(pFmt->GetAttrSet());
159 	aSet.Put(rSet);
160 
161 	const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get(SID_ATTR_PAGE_SIZE);
162 	const SfxBoolItem& rDynamic = (const SfxBoolItem&)rSet.Get(SID_ATTR_PAGE_DYNAMIC);
163 
164 	// Groesse umsetzen
165 	//
166 	SwFmtFrmSize aFrmSize(rDynamic.GetValue() ? ATT_MIN_SIZE : ATT_FIX_SIZE,
167 							rSize.GetSize().Width(),
168 							rSize.GetSize().Height());
169 	aSet.Put(aFrmSize);
170     pFmt->SetFmtAttr(aSet);
171 }
172 
173 /*--------------------------------------------------------------------
174 	Beschreibung:	PageDesc <-> in Sets wandeln und zurueck
175  --------------------------------------------------------------------*/
176 
177 
ItemSetToPageDesc(const SfxItemSet & rSet,SwPageDesc & rPageDesc)178 void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc )
179 {
180 	SwFrmFmt& rMaster = rPageDesc.GetMaster();
181 
182 	// alle allgemeinen Rahmen-Attribute uebertragen
183 	//
184     rMaster.SetFmtAttr(rSet);
185 
186 	// PageData
187 	//
188 	if(rSet.GetItemState(SID_ATTR_PAGE) == SFX_ITEM_SET)
189 	{
190 		const SvxPageItem& rPageItem = (const SvxPageItem&)rSet.Get(SID_ATTR_PAGE);
191 
192 		sal_uInt16 nUse = (sal_uInt16)rPageItem.GetPageUsage();
193 		if(nUse & 0x04)
194 			nUse |= 0x03;
195 		if(nUse)
196 			rPageDesc.SetUseOn( (UseOnPage) nUse );
197 		rPageDesc.SetLandscape(rPageItem.IsLandscape());
198 		SvxNumberType aNumType;
199         aNumType.SetNumberingType( static_cast< sal_Int16 >(rPageItem.GetNumType()) );
200 		rPageDesc.SetNumType(aNumType);
201 	}
202 	// Groesse
203 	//
204 	if(rSet.GetItemState(SID_ATTR_PAGE_SIZE) == SFX_ITEM_SET)
205 	{
206 		const SvxSizeItem& rSizeItem = (const SvxSizeItem&)rSet.Get(SID_ATTR_PAGE_SIZE);
207 		SwFmtFrmSize aSize(ATT_FIX_SIZE);
208 		aSize.SetSize(rSizeItem.GetSize());
209         rMaster.SetFmtAttr(aSize);
210 	}
211 	// Kopzeilen-Attribute auswerten
212 	//
213 	const SfxPoolItem* pItem;
214 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PAGE_HEADERSET,
215 			sal_False, &pItem ) )
216 	{
217 		const SfxItemSet& rHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
218 		const SfxBoolItem& rHeaderOn = (const SfxBoolItem&)rHeaderSet.Get(SID_ATTR_PAGE_ON);
219 
220 		if(rHeaderOn.GetValue())
221 		{
222 			// Werte uebernehmen
223 			if(!rMaster.GetHeader().IsActive())
224                 rMaster.SetFmtAttr(SwFmtHeader(sal_True));
225 
226 			// Das Headerformat rausholen und anpassen
227 			//
228 			SwFmtHeader aHeaderFmt(rMaster.GetHeader());
229 			SwFrmFmt *pHeaderFmt = aHeaderFmt.GetHeaderFmt();
230 			ASSERT(pHeaderFmt != 0, "kein HeaderFormat");
231 
232 			::FillHdFt(pHeaderFmt, rHeaderSet);
233 
234 			rPageDesc.ChgHeaderShare(((const SfxBoolItem&)
235 						rHeaderSet.Get(SID_ATTR_PAGE_SHARED)).GetValue());
236 		}
237 		else
238 		{	// Header ausschalten
239 			//
240 			if(rMaster.GetHeader().IsActive())
241 			{
242                 rMaster.SetFmtAttr(SwFmtHeader(sal_Bool(sal_False)));
243 				rPageDesc.ChgHeaderShare(sal_False);
244 			}
245 		}
246 	}
247 
248 	// Fusszeilen-Attribute auswerten
249 	//
250 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PAGE_FOOTERSET,
251 			sal_False, &pItem ) )
252 	{
253 		const SfxItemSet& rFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
254 		const SfxBoolItem& rFooterOn = (const SfxBoolItem&)rFooterSet.Get(SID_ATTR_PAGE_ON);
255 
256 		if(rFooterOn.GetValue())
257 		{
258 			// Werte uebernehmen
259 			if(!rMaster.GetFooter().IsActive())
260                 rMaster.SetFmtAttr(SwFmtFooter(sal_True));
261 
262 			// Das Footerformat rausholen und anpassen
263 			//
264 			SwFmtFooter aFooterFmt(rMaster.GetFooter());
265 			SwFrmFmt *pFooterFmt = aFooterFmt.GetFooterFmt();
266 			ASSERT(pFooterFmt != 0, "kein FooterFormat");
267 
268 			::FillHdFt(pFooterFmt, rFooterSet);
269 
270 			rPageDesc.ChgFooterShare(((const SfxBoolItem&)
271 						rFooterSet.Get(SID_ATTR_PAGE_SHARED)).GetValue());
272 		}
273 		else
274 		{	// Footer ausschalten
275 			//
276 			if(rMaster.GetFooter().IsActive())
277 			{
278                 rMaster.SetFmtAttr(SwFmtFooter(sal_Bool(sal_False)));
279 				rPageDesc.ChgFooterShare(sal_False);
280 			}
281 		}
282 	}
283 
284 	// Fussnoten
285 	//
286 	if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_FTN_INFO,
287 			sal_False, &pItem ) )
288 		rPageDesc.SetFtnInfo( ((SwPageFtnInfoItem*)pItem)->GetPageFtnInfo() );
289 
290 
291 	//
292 	// Columns
293 	//
294 
295 	// Registerhaltigkeit
296 
297 	if(SFX_ITEM_SET == rSet.GetItemState(
298 							SID_SWREGISTER_MODE, sal_False, &pItem))
299 	{
300 		sal_Bool bSet = ((const SfxBoolItem*)pItem)->GetValue();
301 		if(!bSet)
302 			rPageDesc.SetRegisterFmtColl(0);
303 		else if(SFX_ITEM_SET == rSet.GetItemState(
304 								SID_SWREGISTER_COLLECTION, sal_False, &pItem))
305 		{
306 			const String& rColl = ((const SfxStringItem*)pItem)->GetValue();
307 			SwDoc& rDoc = *rMaster.GetDoc();
308 			SwTxtFmtColl* pColl = rDoc.FindTxtFmtCollByName( rColl );
309 			if( !pColl )
310 			{
311 				sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rColl, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
312 				if( USHRT_MAX != nId )
313 					pColl = rDoc.GetTxtCollFromPool( nId );
314 				else
315 					pColl = rDoc.MakeTxtFmtColl( rColl,
316 								(SwTxtFmtColl*)rDoc.GetDfltTxtFmtColl() );
317 			}
318 			if( pColl )
319                 pColl->SetFmtAttr( SwRegisterItem ( sal_True ));
320 			rPageDesc.SetRegisterFmtColl( pColl );
321 		}
322 	}
323 }
324 
325 /*--------------------------------------------------------------------
326 	Beschreibung:
327  --------------------------------------------------------------------*/
328 
329 
PageDescToItemSet(const SwPageDesc & rPageDesc,SfxItemSet & rSet)330 void PageDescToItemSet(	const SwPageDesc& rPageDesc, SfxItemSet& rSet)
331 {
332 	const SwFrmFmt& rMaster = rPageDesc.GetMaster();
333 
334 	// Seitendaten
335 	//
336 	SvxPageItem aPageItem(SID_ATTR_PAGE);
337 	aPageItem.SetDescName(rPageDesc.GetName());
338     aPageItem.SetPageUsage(rPageDesc.GetUseOn());
339 	aPageItem.SetLandscape(rPageDesc.GetLandscape());
340 	aPageItem.SetNumType((SvxNumType)rPageDesc.GetNumType().GetNumberingType());
341 	rSet.Put(aPageItem);
342 
343 	// Groesse
344 	SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, rMaster.GetFrmSize().GetSize());
345 	rSet.Put(aSizeItem);
346 
347 	// Maximale Groesse
348 	SvxSizeItem aMaxSizeItem(SID_ATTR_PAGE_MAXSIZE, Size(MAXWIDTH, MAXHEIGHT));
349 	rSet.Put(aMaxSizeItem);
350 
351 	// Raender, Umrandung und das andere Zeug
352 	//
353 	rSet.Put(rMaster.GetAttrSet());
354 
355     SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
356 	const SfxPoolItem *pBoxInfo;
357 	if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER,
358 											sal_True, &pBoxInfo) )
359 		aBoxInfo = *(SvxBoxInfoItem*)pBoxInfo;
360 
361 	aBoxInfo.SetTable( sal_False );
362 		// Abstandsfeld immer anzeigen
363 	aBoxInfo.SetDist( sal_True);
364 		// Minimalgroesse in Tabellen und Absaetzen setzen
365 	aBoxInfo.SetMinDist( sal_False );
366 	// Default-Abstand immer setzen
367 	aBoxInfo.SetDefDist( MIN_BORDER_DIST );
368 		// Einzelne Linien koennen nur in Tabellen DontCare-Status haben
369 	aBoxInfo.SetValid( VALID_DISABLE );
370 	rSet.Put( aBoxInfo );
371 
372 
373 	SfxStringItem aFollow(SID_ATTR_PAGE_EXT1, aEmptyStr);
374 	if(rPageDesc.GetFollow())
375 		aFollow.SetValue(rPageDesc.GetFollow()->GetName());
376 	rSet.Put(aFollow);
377 
378 	// Header
379 	//
380 	if(rMaster.GetHeader().IsActive())
381 	{
382 		const SwFmtHeader &rHeaderFmt = rMaster.GetHeader();
383 		const SwFrmFmt *pHeaderFmt = rHeaderFmt.GetHeaderFmt();
384 		ASSERT(pHeaderFmt != 0, kein HeaderFormat.);
385 
386 		// HeaderInfo, Raender, Hintergrund, Umrandung
387 		//
388         SfxItemSet aHeaderSet(*rSet.GetPool(),
389             RES_FRMATR_BEGIN,RES_FRMATR_END - 1,            // [82
390 
391             //UUUU FillAttribute support
392             XATTR_FILL_FIRST, XATTR_FILL_LAST,              // [1014
393 
394             SID_ATTR_BORDER_INNER,SID_ATTR_BORDER_INNER,    // [10023
395             SID_ATTR_PAGE_SIZE,SID_ATTR_PAGE_SIZE,          // [10051
396             SID_ATTR_PAGE_ON,SID_ATTR_PAGE_SHARED,          // [10060
397             0, 0);
398 
399         //UUUU set correct parent to get the XFILL_NONE FillStyle as needed
400         aHeaderSet.SetParent(&rMaster.GetDoc()->GetDfltFrmFmt()->GetAttrSet());
401 
402 		// dynamische oder feste Hoehe
403 		//
404 		SfxBoolItem aOn(SID_ATTR_PAGE_ON, sal_True);
405 		aHeaderSet.Put(aOn);
406 
407 		const SwFmtFrmSize &rFrmSize = pHeaderFmt->GetFrmSize();
408         const SwFrmSize eSizeType = rFrmSize.GetHeightSizeType();
409 		SfxBoolItem aDynamic(SID_ATTR_PAGE_DYNAMIC, eSizeType != ATT_FIX_SIZE);
410 		aHeaderSet.Put(aDynamic);
411 
412 		// Links gleich rechts
413 		//
414 		SfxBoolItem aShared(SID_ATTR_PAGE_SHARED, rPageDesc.IsHeaderShared());
415 		aHeaderSet.Put(aShared);
416 
417 		// Groesse
418 		SvxSizeItem aSize(SID_ATTR_PAGE_SIZE, Size(rFrmSize.GetSize()));
419 		aHeaderSet.Put(aSize);
420 
421 		// Rahmen-Attribute umschaufeln
422 		//
423 		aHeaderSet.Put(pHeaderFmt->GetAttrSet());
424 		aHeaderSet.Put( aBoxInfo );
425 
426 		// SetItem erzeugen
427 		//
428 		SvxSetItem aSetItem(SID_ATTR_PAGE_HEADERSET, aHeaderSet);
429 		rSet.Put(aSetItem);
430 	}
431 
432 	// Footer
433 	if(rMaster.GetFooter().IsActive())
434 	{
435 		const SwFmtFooter &rFooterFmt = rMaster.GetFooter();
436 		const SwFrmFmt *pFooterFmt = rFooterFmt.GetFooterFmt();
437 		ASSERT(pFooterFmt != 0, kein FooterFormat.);
438 
439 		// FooterInfo, Raender, Hintergrund, Umrandung
440 		//
441         SfxItemSet aFooterSet(*rSet.GetPool(),
442             RES_FRMATR_BEGIN,RES_FRMATR_END - 1,            // [82
443 
444             //UUUU FillAttribute support
445             XATTR_FILL_FIRST, XATTR_FILL_LAST,              // [1014
446 
447             SID_ATTR_BORDER_INNER,SID_ATTR_BORDER_INNER,    // [10023
448             SID_ATTR_PAGE_SIZE,SID_ATTR_PAGE_SIZE,          // [10051
449             SID_ATTR_PAGE_ON,SID_ATTR_PAGE_SHARED,          // [10060
450             0, 0);
451 
452         //UUUU set correct parent to get the XFILL_NONE FillStyle as needed
453         aFooterSet.SetParent(&rMaster.GetDoc()->GetDfltFrmFmt()->GetAttrSet());
454 
455 		// dynamische oder feste Hoehe
456 		//
457 		SfxBoolItem aOn(SID_ATTR_PAGE_ON, sal_True);
458 		aFooterSet.Put(aOn);
459 
460 		const SwFmtFrmSize &rFrmSize = pFooterFmt->GetFrmSize();
461         const SwFrmSize eSizeType = rFrmSize.GetHeightSizeType();
462 		SfxBoolItem aDynamic(SID_ATTR_PAGE_DYNAMIC, eSizeType != ATT_FIX_SIZE);
463 		aFooterSet.Put(aDynamic);
464 
465 		// Links gleich rechts
466 		//
467 		SfxBoolItem aShared(SID_ATTR_PAGE_SHARED, rPageDesc.IsFooterShared());
468 		aFooterSet.Put(aShared);
469 
470 		// Groesse
471 		SvxSizeItem aSize(SID_ATTR_PAGE_SIZE, Size(rFrmSize.GetSize()));
472 		aFooterSet.Put(aSize);
473 
474 		// Rahmen-Attribute umschaufeln
475 		//
476 		aFooterSet.Put(pFooterFmt->GetAttrSet());
477 		aFooterSet.Put( aBoxInfo );
478 
479 		// SetItem erzeugen
480 		//
481 		SvxSetItem aSetItem(SID_ATTR_PAGE_FOOTERSET, aFooterSet);
482 		rSet.Put(aSetItem);
483 	}
484 
485 	// Fussnoten einbauen
486 	//
487 	SwPageFtnInfo& rInfo = (SwPageFtnInfo&)rPageDesc.GetFtnInfo();
488 	SwPageFtnInfoItem aFtnItem(FN_PARAM_FTN_INFO, rInfo);
489 	rSet.Put(aFtnItem);
490 
491 	// Registerhaltigkeit
492 
493 	const SwTxtFmtColl* pCol = rPageDesc.GetRegisterFmtColl();
494 	SwRegisterItem aReg(pCol != 0);
495 	aReg.SetWhich(SID_SWREGISTER_MODE);
496 	rSet.Put(aReg);
497 	if(pCol)
498 		rSet.Put(SfxStringItem(SID_SWREGISTER_COLLECTION, pCol->GetName()));
499 
500 }
501 
502 
503 /*--------------------------------------------------------------------
504 	Beschreibung:	DefaultTabs setzen
505  --------------------------------------------------------------------*/
506 
507 
MakeDefTabs(SwTwips nDefDist,SvxTabStopItem & rTabs)508 void MakeDefTabs(SwTwips nDefDist, SvxTabStopItem& rTabs)
509 {
510 	if( rTabs.Count() )
511 		return;
512 	{
513 		SvxTabStop aSwTabStop( nDefDist, SVX_TAB_ADJUST_DEFAULT );
514 		rTabs.Insert( aSwTabStop );
515 	}
516 }
517 
518 /*--------------------------------------------------------------------
519 	Beschreibung:	Abstand zwischen zwei Tabs
520  --------------------------------------------------------------------*/
521 
522 
GetTabDist(const SvxTabStopItem & rTabs)523 sal_uInt16 GetTabDist(const SvxTabStopItem& rTabs)
524 {
525 	sal_uInt16 nDefDist;
526 	if( rTabs.Count() )
527 		nDefDist = (sal_uInt16)( rTabs[0].GetTabPos() );
528 	else
529 		nDefDist = 1134;     // 2cm
530 	return nDefDist;
531 }
532 
533 
534 // erfrage ob im Set eine Sfx-PageDesc-Kombination vorliegt und returne diese
SfxToSwPageDescAttr(const SwWrtShell & rShell,SfxItemSet & rSet)535 void SfxToSwPageDescAttr( const SwWrtShell& rShell, SfxItemSet& rSet )
536 {
537 	const SfxPoolItem* pItem;
538 	SwFmtPageDesc aPgDesc;
539 
540 	sal_Bool bChanged = sal_False;
541 	// Seitennummer
542 	if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_PARA_PAGENUM, sal_False, &pItem))
543 	{
544 		aPgDesc.SetNumOffset(((SfxUInt16Item*)pItem)->GetValue());
545 		bChanged = sal_True;
546 	}
547 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_PARA_MODEL, sal_False, &pItem ))
548 	{
549 		const String& rDescName = ((SvxPageModelItem*)pItem)->GetValue();
550 		if( rDescName.Len() )	// kein Name -> PageDesc ausschalten!
551 		{
552 			// nur loeschen, wenn PageDesc eingschaltet wird!
553 			rSet.ClearItem( RES_BREAK );
554 			SwPageDesc* pDesc = ((SwWrtShell&)rShell).FindPageDescByName(
555 													rDescName, sal_True );
556 			if( pDesc )
557                 aPgDesc.RegisterToPageDesc( *pDesc );
558 		}
559 		rSet.ClearItem( SID_ATTR_PARA_MODEL );
560 		bChanged = sal_True;
561 	}
562 	else
563 	{
564 		SfxItemSet aCoreSet(rShell.GetView().GetPool(), RES_PAGEDESC, RES_PAGEDESC );
565         rShell.GetCurAttr( aCoreSet );
566 		if(SFX_ITEM_SET == aCoreSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) )
567 		{
568 			if( ((SwFmtPageDesc*)pItem)->GetPageDesc() )
569 			{
570                 aPgDesc.RegisterToPageDesc( *((SwFmtPageDesc*)pItem)->GetPageDesc() );
571 			}
572 		}
573 	}
574 
575 
576 	if(bChanged)
577 		rSet.Put( aPgDesc );
578 }
579 
580 
581 // erfrage ob im Set eine Sfx-PageDesc-Kombination vorliegt und returne diese
SwToSfxPageDescAttr(SfxItemSet & rCoreSet)582 void SwToSfxPageDescAttr( SfxItemSet& rCoreSet )
583 {
584 	const SfxPoolItem* pItem = 0;
585 	String aName;
586 	sal_uInt16 nPageNum = 0;
587 	sal_Bool bPut = sal_True;
588 	switch( rCoreSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) )
589 	{
590 	case SFX_ITEM_SET:
591 		{
592 			if( ((SwFmtPageDesc*)pItem)->GetPageDesc() )
593 			{
594 				aName = ((SwFmtPageDesc*)pItem)->GetPageDesc()->GetName();
595 				nPageNum = ((SwFmtPageDesc*)pItem)->GetNumOffset();
596 			}
597 			rCoreSet.ClearItem( RES_PAGEDESC );
598 			// Seitennummer
599 		}
600 		break;
601 
602 	case SFX_ITEM_AVAILABLE:
603 		break;
604 
605 	default:
606 		bPut = sal_False;
607 	}
608 	SfxUInt16Item aPageNum( SID_ATTR_PARA_PAGENUM, nPageNum );
609 	rCoreSet.Put( aPageNum );
610 
611 	if(bPut)
612 		rCoreSet.Put( SvxPageModelItem( aName, sal_True, SID_ATTR_PARA_MODEL ) );
613 }
614 
615 /*--------------------------------------------------------------------
616 	Beschreibung:	Metric ermitteln
617  --------------------------------------------------------------------*/
618 
619 
GetDfltMetric(sal_Bool bWeb)620 FieldUnit	GetDfltMetric(sal_Bool bWeb)
621 {
622 	return SW_MOD()->GetUsrPref(bWeb)->GetMetric();
623 }
624 
625 /*--------------------------------------------------------------------
626 	Beschreibung:	Metric ermitteln
627  --------------------------------------------------------------------*/
628 
629 
SetDfltMetric(FieldUnit eMetric,sal_Bool bWeb)630 void	SetDfltMetric( FieldUnit eMetric, sal_Bool bWeb )
631 {
632 	SW_MOD()->ApplyUserMetric(eMetric, bWeb);
633 }
634 
635 /*-----------------09.04.98 16:58-------------------
636 
637 --------------------------------------------------*/
InsertStringSorted(const String & rEntry,ListBox & rToFill,sal_uInt16 nOffset)638 sal_uInt16 InsertStringSorted(const String& rEntry, ListBox& rToFill, sal_uInt16 nOffset )
639 {
640     sal_uInt16 i = nOffset;
641 	CollatorWrapper& rCaseColl = ::GetAppCaseCollator();
642 
643 	for( ; i < rToFill.GetEntryCount(); i++ )
644 	{
645 		if( 0 < rCaseColl.compareString( rToFill.GetEntry(i), rEntry ))
646 			break;
647 	}
648 	return rToFill.InsertEntry(rEntry, i);
649 }
FillCharStyleListBox(ListBox & rToFill,SwDocShell * pDocSh,sal_Bool bSorted,sal_Bool bWithDefault)650 void FillCharStyleListBox(ListBox& rToFill, SwDocShell* pDocSh, sal_Bool bSorted, sal_Bool bWithDefault)
651 {
652 	sal_Bool bHasOffset = rToFill.GetEntryCount() > 0;
653 	SfxStyleSheetBasePool* pPool = pDocSh->GetStyleSheetPool();
654 	pPool->SetSearchMask(SFX_STYLE_FAMILY_CHAR, SFXSTYLEBIT_ALL);
655 	SwDoc* pDoc = pDocSh->GetDoc();
656 	const SfxStyleSheetBase* pBase = pPool->First();
657 	String sStandard;
658 	SwStyleNameMapper::FillUIName( RES_POOLCOLL_STANDARD, sStandard );
659 	while(pBase)
660 	{
661         if(bWithDefault || pBase->GetName() !=  sStandard)
662 		{
663 			sal_uInt16 nPos;
664 			if(bSorted)
665 				nPos = InsertStringSorted(pBase->GetName(), rToFill, bHasOffset );
666 			else
667 				nPos = rToFill.InsertEntry(pBase->GetName());
668 			long nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( pBase->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
669 			rToFill.SetEntryData( nPos, (void*) (nPoolId));
670 		}
671 		pBase = pPool->Next();
672 	}
673 	// non-pool styles
674 	const SwCharFmts* pFmts = pDoc->GetCharFmts();
675 	for(sal_uInt16 i = 0; i < pFmts->Count(); i++)
676 	{
677 		const SwCharFmt* pFmt = (*pFmts)[i];
678 		if(pFmt->IsDefault())
679 			continue;
680 		const String& rName = pFmt->GetName();
681 		if(rToFill.GetEntryPos(rName) == LISTBOX_ENTRY_NOTFOUND)
682 		{
683 			sal_uInt16 nPos;
684 			if(bSorted)
685 				nPos = InsertStringSorted(rName, rToFill, bHasOffset );
686 			else
687 				nPos = rToFill.InsertEntry(rName);
688 			long nPoolId = USHRT_MAX;
689 			rToFill.SetEntryData( nPos, (void*) (nPoolId));
690 		}
691 	}
692 };
693 
694 /* -----------------27.04.98 08:26-------------------
695  *
696  * --------------------------------------------------*/
GetTableWidth(SwFrmFmt * pFmt,SwTabCols & rCols,sal_uInt16 * pPercent,SwWrtShell * pSh)697 SwTwips GetTableWidth( SwFrmFmt* pFmt, SwTabCols& rCols, sal_uInt16 *pPercent,
698 			SwWrtShell* pSh )
699 {
700 	//Die Breite zu besorgen ist etwas komplizierter.
701     SwTwips nWidth = 0;
702     const sal_Int16 eOri = pFmt->GetHoriOrient().GetHoriOrient();
703 	switch(eOri)
704 	{
705         case text::HoriOrientation::FULL: nWidth = rCols.GetRight(); break;
706         case text::HoriOrientation::LEFT_AND_WIDTH:
707         case text::HoriOrientation::LEFT:
708         case text::HoriOrientation::RIGHT:
709         case text::HoriOrientation::CENTER:
710 			nWidth = pFmt->GetFrmSize().GetWidth();
711 		break;
712 		default:
713 		{
714 			if(pSh)
715 			{
716 				const SwFrmFmt *pFlyFmt;
717 				if ( 0 == (pFlyFmt = pSh->GetFlyFrmFmt()) )
718 				{
719 					nWidth = pSh->GetAnyCurRect(RECT_PAGE_PRT).Width();
720 				}
721 				else
722 				{
723 					nWidth = pSh->GetAnyCurRect(RECT_FLY_PRT_EMBEDDED).Width();
724 				}
725 			}
726 			else
727 			{
728 				DBG_ERROR("wo soll die Breite denn herkommen?");
729 			}
730 			const SvxLRSpaceItem& rLRSpace = pFmt->GetLRSpace();
731 			nWidth -= (rLRSpace.GetRight() + rLRSpace.GetLeft());
732 		}
733 	}
734 	if (pPercent)
735 		*pPercent = pFmt->GetFrmSize().GetWidthPercent();
736 	return nWidth;
737 }
738 
739 /*------------------------------------------------------------------------*/
740 
GetAppLangDateTimeString(const DateTime & rDT)741 String GetAppLangDateTimeString( const DateTime& rDT )
742 {
743     const SvtSysLocale aSysLocale;
744 	const LocaleDataWrapper& rAppLclData = aSysLocale.GetLocaleData();
745 	String sRet( rAppLclData.getDate( rDT ));
746 	( sRet += ' ' ) += rAppLclData.getTime( rDT, sal_False, sal_False );
747 	return sRet;
748 }
749 
750 /*-- 26.01.2006 08:06:33---------------------------------------------------
751 
752   -----------------------------------------------------------------------*/
ExecuteMenuCommand(PopupMenu & rMenu,SfxViewFrame & rViewFrame,sal_uInt16 nId)753 bool ExecuteMenuCommand( PopupMenu& rMenu, SfxViewFrame& rViewFrame, sal_uInt16 nId )
754 {
755     bool bRet = false;
756     sal_uInt16 nItemCount = rMenu.GetItemCount();
757     String sCommand;
758     for( sal_uInt16 nItem = 0; nItem < nItemCount; ++nItem)
759     {
760         PopupMenu* pPopup = rMenu.GetPopupMenu( rMenu.GetItemId( nItem ) );
761         if(pPopup)
762         {
763             sCommand = pPopup->GetItemCommand(nId);
764             if(sCommand.Len())
765                 break;
766         }
767     }
768     if(sCommand.Len())
769     {
770         uno::Reference< frame::XFrame >  xFrame = rViewFrame.GetFrame().GetFrameInterface();
771         uno::Reference < frame::XDispatchProvider > xProv( xFrame, uno::UNO_QUERY );
772         util::URL aURL;
773         aURL.Complete = sCommand;
774         uno::Reference < util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), uno::UNO_QUERY );
775         xTrans->parseStrict( aURL );
776         uno::Reference< frame::XDispatch >  xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
777         if( xDisp.is() )
778         {
779             uno::Sequence< beans::PropertyValue > aSeq;
780             xDisp->dispatch( aURL, aSeq );
781             bRet = true;
782         }
783     }
784     return bRet;
785 }
786