xref: /aoo42x/main/sw/source/ui/app/docst.cxx (revision baef7ff7)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sw.hxx"
24 
25 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <hintids.hxx>
29 #include <sfx2/app.hxx>
30 #include <svl/whiter.hxx>
31 #include <sfx2/templdlg.hxx>
32 #include <sfx2/tplpitem.hxx>
33 #include <sfx2/request.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/newstyle.hxx>
36 #include <sfx2/printer.hxx>
37 #include <svl/macitem.hxx>
38 #include <editeng/brshitem.hxx>
39 #include <svl/stritem.hxx>
40 #include <svl/languageoptions.hxx>
41 #include <editeng/eeitem.hxx>
42 #include <svx/htmlmode.hxx>
43 #include <svx/xdef.hxx>
44 #include <swmodule.hxx>
45 #include <wdocsh.hxx>
46 #include <fmtfsize.hxx>
47 #include <fchrfmt.hxx>
48 #include <svtools/htmlcfg.hxx>
49 #include <SwStyleNameMapper.hxx>
50 #include <SwRewriter.hxx>
51 #include <numrule.hxx>
52 #include <swundo.hxx>
53 #include <svx/svdmodel.hxx>
54 #include <svx/drawitem.hxx>
55 #include "view.hxx"
56 #include "wrtsh.hxx"
57 #include "docsh.hxx"
58 #include "uitool.hxx"
59 #include "cmdid.h"
60 #include "globals.hrc"
61 #include "viewopt.hxx"
62 #include <doc.hxx>
63 #include <IDocumentUndoRedo.hxx>
64 #include "swstyle.h"
65 #include "frmfmt.hxx"
66 #include "charfmt.hxx"
67 #include "poolfmt.hxx"
68 #include "pagedesc.hxx"
69 #include "docstyle.hxx"
70 #include "uiitems.hxx"
71 #include "fmtcol.hxx"
72 #include "frmmgr.hxx"		//SwFrmValid
73 #include "swevent.hxx"
74 #include "edtwin.hxx"
75 #include "unochart.hxx"
76 #include "app.hrc"
77 #include <fmtui.hrc>
78 #include "swabstdlg.hxx"
79 #include <list.hxx>
80 #include <paratr.hxx>	//#outline level,add by zhaojianwei
81 #include <drawdoc.hxx>
82 
83 using namespace ::com::sun::star;
84 
85 /*--------------------------------------------------------------------
86 	Beschreibung:
87  --------------------------------------------------------------------*/
88 
89 
StateStyleSheet(SfxItemSet & rSet,SwWrtShell * pSh)90 void  SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh)
91 {
92 	SfxWhichIter aIter(rSet);
93 	sal_uInt16 	nWhich 	= aIter.FirstWhich();
94 	sal_uInt16 nActualFamily = USHRT_MAX;
95 
96 	SwWrtShell* pShell = pSh ? pSh : GetWrtShell();
97     if(!pShell)
98 	{
99 		while (nWhich)
100 		{
101 			rSet.DisableItem(nWhich);
102 			nWhich = aIter.NextWhich();
103 		}
104 		return;
105 	}
106 	else
107 	{
108 		SfxViewFrame* pFrame = pShell->GetView().GetViewFrame();
109 		const ISfxTemplateCommon* pCommon = SFX_APP()->GetCurrentTemplateCommon(pFrame->GetBindings());
110 		if( pCommon )
111             nActualFamily = static_cast< sal_uInt16 >(pCommon->GetActualFamily());
112 	}
113 
114 	while (nWhich)
115 	{
116 		// aktuelle Vorlage zu jeder Familie ermitteln
117 		//
118 		String aName;
119 		switch (nWhich)
120 		{
121 			case SID_STYLE_APPLY:
122 			{//hier wird die Vorlage und ihre Familie an die StyleBox
123 			 //uebergeben, damit diese Familie angezeigt wird
124 				if(pShell->IsFrmSelected())
125 				{
126 					SwFrmFmt* pFmt = pShell->GetCurFrmFmt();
127 					if( pFmt )
128 						aName = pFmt->GetName();
129 				}
130 				else
131 				{
132 					SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
133 					if(pColl)
134 						aName = pColl->GetName();
135 				}
136 				rSet.Put(SfxTemplateItem(nWhich, aName));
137 			}
138 			break;
139 			case SID_STYLE_FAMILY1:
140 				if( !pShell->IsFrmSelected() )
141 				{
142 					SwCharFmt* pFmt = pShell->GetCurCharFmt();
143 					if(pFmt)
144 						aName = pFmt->GetName();
145 					else
146 						aName = *SwStyleNameMapper::GetTextUINameArray()[
147 							RES_POOLCOLL_STANDARD - RES_POOLCOLL_TEXT_BEGIN ];
148                     rSet.Put(SfxTemplateItem(nWhich, aName));
149                 }
150                 break;
151 
152 			case SID_STYLE_FAMILY2:
153 				if(!pShell->IsFrmSelected())
154 				{
155 					SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
156 					if(pColl)
157 						aName = pColl->GetName();
158 
159 					SfxTemplateItem aItem(nWhich, aName);
160 
161 					sal_uInt16 nMask = 0;
162 					if( mpDoc->get(IDocumentSettingAccess::HTML_MODE) )
163 						nMask = SWSTYLEBIT_HTML;
164 					else
165 					{
166 						const int nSelection = pShell->GetFrmType(0,sal_True);
167 						if(pShell->GetCurTOX())
168 							nMask = SWSTYLEBIT_IDX	;
169 						else if(nSelection & FRMTYPE_HEADER 	||
170 								nSelection & FRMTYPE_FOOTER 	||
171 								nSelection & FRMTYPE_TABLE 		||
172 								nSelection & FRMTYPE_FLY_ANY 	||
173 								nSelection & FRMTYPE_FOOTNOTE 	||
174 								nSelection & FRMTYPE_FTNPAGE)
175 							nMask = SWSTYLEBIT_EXTRA;
176 						else
177 							nMask = SWSTYLEBIT_TEXT;
178 					}
179 
180 					aItem.SetValue(nMask);
181 					rSet.Put(aItem);
182 				}
183 
184 				break;
185 
186 			case SID_STYLE_FAMILY3:
187 
188 				if( mpDoc->get(IDocumentSettingAccess::HTML_MODE) )
189 					rSet.DisableItem( nWhich );
190 				else
191 				{
192 					SwFrmFmt* pFmt = pShell->GetCurFrmFmt();
193 					if(pFmt && pShell->IsFrmSelected())
194                     {
195 						aName = pFmt->GetName();
196                         rSet.Put(SfxTemplateItem(nWhich, aName));
197                     }
198                 }
199 				break;
200 
201 			case SID_STYLE_FAMILY4:
202 			{
203 				SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
204 				if( mpDoc->get(IDocumentSettingAccess::HTML_MODE) && !pHtmlOpt->IsPrintLayoutExtension())
205 					rSet.DisableItem( nWhich );
206 				else
207 				{
208 					sal_uInt16 n = pShell->GetCurPageDesc( sal_False );
209 					if( n < pShell->GetPageDescCnt() )
210 						aName = pShell->GetPageDesc( n ).GetName();
211 
212 					rSet.Put(SfxTemplateItem(nWhich, aName));
213 				}
214 			}
215 			break;
216 			case SID_STYLE_FAMILY5:
217 				{
218 					const SwNumRule* pRule = pShell->GetNumRuleAtCurrCrsrPos();
219 					if( pRule )
220 						aName = pRule->GetName();
221 
222 					rSet.Put(SfxTemplateItem(nWhich, aName));
223 				}
224 				break;
225 
226 			case SID_STYLE_WATERCAN:
227 			{
228                 SwEditWin& rEdtWin = pShell->GetView().GetEditWin();
229                 SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
230                 rSet.Put(SfxBoolItem(nWhich, pApply && pApply->eType != 0));
231 			}
232             break;
233 			case SID_STYLE_UPDATE_BY_EXAMPLE:
234 				if( pShell->IsFrmSelected()
235 						? SFX_STYLE_FAMILY_FRAME != nActualFamily
236 						: ( SFX_STYLE_FAMILY_FRAME == nActualFamily ||
237 							SFX_STYLE_FAMILY_PAGE == nActualFamily ||
238 							(SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetNumRuleAtCurrCrsrPos())) )
239 				{
240 					rSet.DisableItem( nWhich );
241 				}
242 				break;
243 
244 			case SID_STYLE_NEW_BY_EXAMPLE:
245 				if( (pShell->IsFrmSelected()
246 						? SFX_STYLE_FAMILY_FRAME != nActualFamily
247 						: SFX_STYLE_FAMILY_FRAME == nActualFamily) ||
248 					(SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetNumRuleAtCurrCrsrPos()) )
249 				{
250 					rSet.DisableItem( nWhich );
251 				}
252 				break;
253 
254 			default:
255 				DBG_ERROR( "Invalid SlotId");
256 		}
257 		nWhich = aIter.NextWhich();
258 	}
259 }
260 
261 
262 /*--------------------------------------------------------------------
263 	Beschreibung:	StyleSheet-Requeste auswerten
264  --------------------------------------------------------------------*/
265 
266 
ExecStyleSheet(SfxRequest & rReq)267 void SwDocShell::ExecStyleSheet( SfxRequest& rReq )
268 {
269 	sal_uInt16 	nSlot 	= rReq.GetSlot();
270 	sal_uInt16 	nRet 	= 0xffff;
271 
272 	const SfxItemSet* pArgs = rReq.GetArgs();
273 	const SfxPoolItem* pItem;
274 	SwWrtShell* pActShell = 0;
275 	sal_Bool bSetReturn = sal_True;
276 	switch (nSlot)
277 	{
278 	case SID_STYLE_NEW:
279 		if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_FAMILY,
280 			sal_False, &pItem ))
281 		{
282 			const sal_uInt16 nFamily = ((const SfxUInt16Item*)pItem)->GetValue();
283 
284 			String sName;
285 			sal_uInt16 nMask = 0;
286 			if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_NEW,
287 				sal_False, &pItem ))
288 				sName = ((const SfxStringItem*)pItem)->GetValue();
289 			if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_MASK,
290 				sal_False, &pItem ))
291 				nMask = ((const SfxUInt16Item*)pItem)->GetValue();
292 			String sParent;
293 			if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_REFERENCE,
294 				sal_False, &pItem ))
295 				sParent = ((const SfxStringItem*)pItem)->GetValue();
296 
297 			nRet = Edit( sName, sParent, nFamily, nMask, sal_True, 0, 0, rReq.IsAPI() );
298 		}
299 		break;
300 
301 		case SID_STYLE_APPLY:
302 			if( !pArgs )
303 			{
304 				GetView()->GetViewFrame()->GetDispatcher()->Execute(SID_STYLE_DESIGNER, sal_False);
305 				break;
306             }
307             else
308             {
309                 // convert internal StyleName to DisplayName (slot implementation uses the latter)
310                 SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_APPLY_STYLE, sal_False );
311                 SFX_REQUEST_ARG( rReq, pFamilyItem, SfxStringItem, SID_STYLE_FAMILYNAME, sal_False );
312                 if ( pFamilyItem && pNameItem )
313                 {
314                     uno::Reference< style::XStyleFamiliesSupplier > xModel(GetModel(), uno::UNO_QUERY);
315                     try
316                     {
317                         uno::Reference< container::XNameAccess > xStyles;
318                         uno::Reference< container::XNameAccess > xCont = xModel->getStyleFamilies();
319                         xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
320                         uno::Reference< beans::XPropertySet > xInfo;
321                         xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
322                         ::rtl::OUString aUIName;
323                         xInfo->getPropertyValue( ::rtl::OUString::createFromAscii("DisplayName") ) >>= aUIName;
324                         if ( aUIName.getLength() )
325                             rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
326                     }
327                     catch( uno::Exception& )
328                     {
329                     }
330                 }
331             }
332 
333             // intentionally no break
334 
335 		case SID_STYLE_EDIT:
336 		case SID_STYLE_DELETE:
337 		case SID_STYLE_WATERCAN:
338 		case SID_STYLE_FAMILY:
339 		case SID_STYLE_UPDATE_BY_EXAMPLE:
340 		case SID_STYLE_NEW_BY_EXAMPLE:
341 		{
342 			String aParam;
343             sal_uInt16 nFamily = SFX_STYLE_FAMILY_PARA;
344             sal_uInt16 nMask = 0;
345 
346 			if( !pArgs )
347 			{
348 				nFamily = SFX_STYLE_FAMILY_PARA;
349 
350 				switch (nSlot)
351 				{
352 					case SID_STYLE_NEW_BY_EXAMPLE:
353 					{
354 						SfxNewStyleDlg *pDlg = new SfxNewStyleDlg( 0,
355 													*GetStyleSheetPool());
356 						if(RET_OK == pDlg->Execute())
357                         {
358 							aParam = pDlg->GetName();
359 							rReq.AppendItem(SfxStringItem(nSlot, aParam));
360                         }
361 
362 						delete pDlg;
363 					}
364 					break;
365 
366 					case SID_STYLE_UPDATE_BY_EXAMPLE:
367 					case SID_STYLE_EDIT:
368 					{
369 						SwTxtFmtColl* pColl = GetWrtShell()->GetCurTxtFmtColl();
370 						if(pColl)
371 						{
372 							aParam = pColl->GetName();
373 							rReq.AppendItem(SfxStringItem(nSlot, aParam));
374 						}
375 					}
376 					break;
377 				}
378 			}
379 			else
380 			{
381 				ASSERT( pArgs->Count(), "SfxBug ItemSet ist leer");
382 
383 				SwWrtShell* pShell = GetWrtShell();
384 				if( SFX_ITEM_SET == pArgs->GetItemState(nSlot, sal_False, &pItem ))
385 					aParam = ((const SfxStringItem*)pItem)->GetValue();
386 
387 				if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILY,
388 					sal_False, &pItem ))
389 					nFamily = ((const SfxUInt16Item*)pItem)->GetValue();
390 
391 				if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILYNAME, sal_False, &pItem ))
392                 {
393 					String aFamily = ((const SfxStringItem*)pItem)->GetValue();
394                     if(aFamily.CompareToAscii("CharacterStyles") == COMPARE_EQUAL)
395                         nFamily = SFX_STYLE_FAMILY_CHAR;
396                     else
397                     if(aFamily.CompareToAscii("ParagraphStyles") == COMPARE_EQUAL)
398                         nFamily = SFX_STYLE_FAMILY_PARA;
399                     else
400                     if(aFamily.CompareToAscii("PageStyles") == COMPARE_EQUAL)
401                         nFamily = SFX_STYLE_FAMILY_PAGE;
402                     else
403                     if(aFamily.CompareToAscii("FrameStyles") == COMPARE_EQUAL)
404                         nFamily = SFX_STYLE_FAMILY_FRAME;
405                     else
406                     if(aFamily.CompareToAscii("NumberingStyles") == COMPARE_EQUAL)
407                         nFamily = SFX_STYLE_FAMILY_PSEUDO;
408                 }
409 
410 				if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_MASK,
411 					sal_False, &pItem ))
412 					nMask = ((const SfxUInt16Item*)pItem)->GetValue();
413 				if( SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_WRTSHELL,
414 					sal_False, &pItem ))
415 					pActShell = pShell = (SwWrtShell*)((SwPtrItem*)pItem)->GetValue();
416 
417 				if( nSlot == SID_STYLE_UPDATE_BY_EXAMPLE )
418 				{
419 					switch( nFamily )
420 					{
421 						case SFX_STYLE_FAMILY_PARA:
422 						{
423 							SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
424 							if(pColl)
425 								aParam = pColl->GetName();
426 						}
427 						break;
428 						case SFX_STYLE_FAMILY_FRAME:
429 						{
430 							SwFrmFmt* pFrm = mpWrtShell->GetCurFrmFmt();
431 							if( pFrm )
432 								aParam = pFrm->GetName();
433 						}
434 						break;
435 						case SFX_STYLE_FAMILY_CHAR:
436 						{
437 							SwCharFmt* pChar = mpWrtShell->GetCurCharFmt();
438 							if( pChar )
439 								aParam = pChar->GetName();
440 						}
441 						break;
442 						case SFX_STYLE_FAMILY_PSEUDO:
443 						if(SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, sal_False, &pItem))
444 						{
445 							aParam = ((const SfxStringItem*)pItem)->GetValue();
446 						}
447 						break;
448 					}
449 					rReq.AppendItem(SfxStringItem(nSlot, aParam));
450 				}
451 			}
452 			if (aParam.Len() || nSlot == SID_STYLE_WATERCAN )
453 			{
454 				switch(nSlot)
455 				{
456 					case SID_STYLE_EDIT:
457 						nRet = Edit(aParam, aEmptyStr, nFamily, nMask, sal_False, 0, pActShell );
458 						break;
459 					case SID_STYLE_DELETE:
460 						nRet = Delete(aParam, nFamily);
461 						break;
462 					case SID_STYLE_APPLY:
463 						// Shellwechsel in ApplyStyles
464                         nRet = ApplyStyles(aParam, nFamily, pActShell, rReq.GetModifier() );
465 						break;
466 					case SID_STYLE_WATERCAN:
467 						nRet = DoWaterCan(aParam, nFamily);
468 						break;
469 					case SID_STYLE_UPDATE_BY_EXAMPLE:
470 						nRet = UpdateStyle(aParam, nFamily, pActShell);
471 						break;
472 					case SID_STYLE_NEW_BY_EXAMPLE:
473 					{
474 						nRet = MakeByExample(aParam, nFamily, nMask, pActShell );
475 						SfxTemplateDialog* pDlg = SFX_APP()->GetTemplateDialog();
476 
477 						if(pDlg && pDlg->IsVisible())
478 							pDlg->Update();
479 					}
480 					break;
481 
482 					default:
483 						DBG_ERROR( "Falsche Slot-Id");
484 				}
485 
486                 rReq.Done();
487 			}
488 
489 			break;
490 		}
491 	}
492 
493 	if(bSetReturn)
494 	{
495 		if(rReq.IsAPI()) // Basic bekommt nur sal_True oder sal_False
496 			rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet !=0));
497 		else
498 			rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet));
499 	}
500 
501 }
502 
503 /*--------------------------------------------------------------------
504 	Beschreibung:	Edit
505  --------------------------------------------------------------------*/
506 
Edit(const String & rName,const String & rParent,const sal_uInt16 nFamily,sal_uInt16 nMask,const sal_Bool bNew,const sal_uInt16 nSlot,SwWrtShell * pActShell,const sal_Bool bBasic)507 sal_uInt16 SwDocShell::Edit(
508     const String &rName,
509     const String &rParent,
510     const sal_uInt16 nFamily,
511     sal_uInt16 nMask,
512     const sal_Bool bNew,
513     const sal_uInt16 nSlot,
514     SwWrtShell* pActShell,
515     const sal_Bool bBasic )
516 {
517 	ASSERT(GetWrtShell(), "Keine Shell, keine Styles");
518 	SfxStyleSheetBase *pStyle = 0;
519 
520 	sal_uInt16 nRet = nMask;
521 	sal_Bool bModified = mpDoc->IsModified();
522 
523 	if( bNew )
524 	{
525 		if( SFXSTYLEBIT_ALL != nMask && SFXSTYLEBIT_USED != nMask )
526 			nMask |= SFXSTYLEBIT_USERDEF;
527 		else
528 			nMask = SFXSTYLEBIT_USERDEF;
529 
530 		pStyle = &mxBasePool->Make( rName, (SfxStyleFamily)nFamily, nMask );
531 
532 		// die aktuellen als Parent setzen
533 		SwDocStyleSheet* pDStyle = (SwDocStyleSheet*)pStyle;
534 		switch( nFamily )
535 		{
536 			case SFX_STYLE_FAMILY_PARA:
537 			{
538 				if(rParent.Len())
539 				{
540 					SwTxtFmtColl* pColl = mpWrtShell->FindTxtFmtCollByName( rParent );
541                     if(!pColl)
542                     {
543                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
544                         if(USHRT_MAX != nId)
545                             pColl =  mpWrtShell->GetTxtCollFromPool( nId );
546                     }
547 					pDStyle->GetCollection()->SetDerivedFrom( pColl );
548 					pDStyle->PresetParent( rParent );
549 
550 					 /*When a new paragraph style is created based on a "to outline style
551 						assigned" paragraph style, the outline level attribute and the list
552 						style attribute of the new paragraph style have to be set to 0
553 						respectively "".*/
554 					if( pColl->IsAssignedToListLevelOfOutlineStyle())
555 					{
556 						SwNumRuleItem aItem(aEmptyStr);
557 						pDStyle->GetCollection()->SetFmtAttr( aItem );
558 						pDStyle->GetCollection()->SetAttrOutlineLevel( 0 );
559 					}
560 
561 				}
562 				else
563 				{
564 					SwTxtFmtColl* pColl = mpWrtShell->GetCurTxtFmtColl();
565 					pDStyle->GetCollection()->SetDerivedFrom( pColl );
566 					if( pColl )
567 						pDStyle->PresetParent( pColl->GetName() );
568 				}
569 			}
570 			break;
571 			case SFX_STYLE_FAMILY_CHAR:
572 			{
573 				if(rParent.Len())
574 				{
575 					SwCharFmt* pCFmt = mpWrtShell->FindCharFmtByName( rParent );
576                     if(!pCFmt)
577                     {
578                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
579                         if(USHRT_MAX != nId)
580                             pCFmt =  mpWrtShell->GetCharFmtFromPool( nId );
581                     }
582 
583 					pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt );
584 					pDStyle->PresetParent( rParent );
585 				}
586 				else
587 				{
588 					SwCharFmt* pCFmt = mpWrtShell->GetCurCharFmt();
589 					pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt );
590 						if( pCFmt )
591 							pDStyle->PresetParent( pCFmt->GetName() );
592 				}
593 			}
594 			break;
595 			case SFX_STYLE_FAMILY_FRAME :
596 			{
597 				if(rParent.Len())
598 				{
599 					SwFrmFmt* pFFmt = mpWrtShell->GetDoc()->FindFrmFmtByName( rParent );
600                     if(!pFFmt)
601                     {
602                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT);
603                         if(USHRT_MAX != nId)
604                             pFFmt =  mpWrtShell->GetFrmFmtFromPool( nId );
605                     }
606                     pDStyle->GetFrmFmt()->SetDerivedFrom( pFFmt );
607 					pDStyle->PresetParent( rParent );
608 				}
609 			}
610 			break;
611 		}
612 	}
613 	else
614 	{
615 		pStyle = mxBasePool->Find( rName, (SfxStyleFamily)nFamily );
616 		ASSERT(pStyle, "Vorlage nicht gefunden");
617 	}
618 
619 	if(!pStyle)
620 		return sal_False;
621 
622 	// Dialoge zusammenstoepseln
623 	//
624 	rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
625 	if( SFX_STYLE_FAMILY_PARA == nFamily )
626 	{
627 		SfxItemSet& rSet = xTmp->GetItemSet();
628 		::SwToSfxPageDescAttr( rSet );
629 		// erstmal nur eine Null
630 		rSet.Put(SwBackgroundDestinationItem(SID_PARA_BACKGRND_DESTINATION, 0));
631         // --> OD 2008-02-13 #newlistlevelattrs#
632         // merge list level indent attributes into the item set if needed
633         xTmp->MergeIndentAttrsOfListStyle( rSet );
634         // <--
635 	}
636 /*	else if( SFX_STYLE_FAMILY_FRAME == nFamily )
637 	{
638 		// Auskommentiert wegen Bug #45776 (per default keine Breite&Groesse in Rahmenvorlagen)
639 		SfxItemSet& rSet = aTmp.GetItemSet();
640 		if( SFX_ITEM_SET != rSet.GetItemState( RES_FRM_SIZE ))
641 		{
642 			// dann sollten wir spaetesten hier eines anlegen
643 			SwFrmValid aFrmDefValues;
644 			rSet.Put( SwFmtFrmSize( ATT_VAR_SIZE, aFrmDefValues.nWidth,
645 									aFrmDefValues.nHeight ));
646 		}
647 	}*/
648 	else if( SFX_STYLE_FAMILY_CHAR == nFamily )
649 	{
650 		SfxItemSet& rSet = xTmp->GetItemSet();
651 		const SfxPoolItem *pTmpBrush;
652 		if( SFX_ITEM_SET == rSet.GetItemState( RES_CHRATR_BACKGROUND,
653 			sal_True, &pTmpBrush ) )
654 		{
655 			SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
656 			aTmpBrush.SetWhich( RES_BACKGROUND );
657 			rSet.Put( aTmpBrush );
658 		}
659 	}
660 
661     if(SFX_STYLE_FAMILY_PAGE == nFamily || SFX_STYLE_FAMILY_PARA == nFamily)
662     {
663         //UUUU create needed items for XPropertyList entries from the DrawModel so that
664         // the Area TabPage can access them
665         SfxItemSet& rSet = xTmp->GetItemSet();
666         const SwDrawModel* pDrawModel = GetDoc()->GetDrawModel();
667 
668         rSet.Put(SvxColorTableItem(pDrawModel->GetColorTableFromSdrModel(), SID_COLOR_TABLE));
669         rSet.Put(SvxGradientListItem(pDrawModel->GetGradientListFromSdrModel(), SID_GRADIENT_LIST));
670         rSet.Put(SvxHatchListItem(pDrawModel->GetHatchListFromSdrModel(), SID_HATCH_LIST));
671         rSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapListFromSdrModel(), SID_BITMAP_LIST));
672     }
673 
674     if (!bBasic)
675     {
676         // vor dem Dialog wird der HtmlMode an der DocShell versenkt
677         sal_uInt16 nHtmlMode = ::GetHtmlMode(this);
678 
679         // In HTML mode, we do not always have a printer. In order to show
680         // the correct page size in the Format - Page dialog, we have to
681         // get one here.
682         SwWrtShell* pCurrShell = ( pActShell ? pActShell : mpWrtShell );
683         if( ( HTMLMODE_ON & nHtmlMode ) &&
684             !pCurrShell->getIDocumentDeviceAccess()->getPrinter( false ) )
685             pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess()->getPrinter( true ) );
686 
687         PutItem(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
688         FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode));
689         SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
690         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
691         DBG_ASSERT(pFact, "Dialogdiet fail!");
692         SfxAbstractTabDialog* pDlg = pFact->CreateTemplateDialog( DLG_TEMPLATE_BASE,
693                                                     0, *(xTmp.get()), nFamily, nSlot,
694                                                     pActShell ? pActShell : mpWrtShell, bNew);
695         DBG_ASSERT(pDlg, "Dialogdiet fail!");
696 		if(RET_OK == pDlg->Execute())
697 		{
698 			GetWrtShell()->StartAllAction();
699 
700 			// nur bei Absatz-Vorlagen die Maske neu setzen
701 			if( bNew )
702 			{
703 				nRet = SFX_STYLE_FAMILY_PARA == pStyle->GetFamily()
704 						? xTmp->GetMask()
705 						: SFXSTYLEBIT_USERDEF;
706 			}
707 			else if( pStyle->GetMask() != xTmp->GetMask() )
708 				nRet = xTmp->GetMask();
709 
710 			if( SFX_STYLE_FAMILY_PARA == nFamily )
711 			{
712 				SfxItemSet aSet( *pDlg->GetOutputItemSet() );
713 				::SfxToSwPageDescAttr( *GetWrtShell(), aSet  );
714                 // --> OD 2008-02-12 #newlistlevelattrs#
715                 // reset indent attributes at paragraph style, if a list style
716                 // will be applied and no indent attributes will be applied.
717 				xTmp->SetItemSet( aSet, true );
718                 // <--
719 			}
720 			else
721 			{
722                 if(SFX_STYLE_FAMILY_PAGE == nFamily)
723                 {
724                     static const sal_uInt16 aInval[] = {
725                         SID_IMAGE_ORIENTATION,
726 						SID_ATTR_CHAR_FONT,
727 						FN_INSERT_CTRL, FN_INSERT_OBJ_CTRL, 0};
728                     mpView->GetViewFrame()->GetBindings().Invalidate(aInval);
729                 }
730                 SfxItemSet aTmpSet( *pDlg->GetOutputItemSet() );
731 				if( SFX_STYLE_FAMILY_CHAR == nFamily )
732 				{
733 					const SfxPoolItem *pTmpBrush;
734 					if( SFX_ITEM_SET == aTmpSet.GetItemState( RES_BACKGROUND,
735 						sal_False, &pTmpBrush ) )
736 					{
737 						SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
738 						aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
739 						aTmpSet.Put( aTmpBrush );
740 					}
741 					aTmpSet.ClearItem( RES_BACKGROUND );
742 				}
743 
744 				xTmp->SetItemSet( aTmpSet );
745 
746                 if( SFX_STYLE_FAMILY_PAGE == nFamily && SvtLanguageOptions().IsCTLFontEnabled() )
747                 {
748                     const SfxPoolItem *pItem = NULL;
749                     if( aTmpSet.GetItemState( GetPool().GetTrueWhich( SID_ATTR_FRAMEDIRECTION, sal_False ) , sal_True, &pItem ) == SFX_ITEM_SET )
750                         SwChartHelper::DoUpdateAllCharts( mpDoc );
751                 }
752 			}
753 
754             //UUUU
755             if(bNew)
756             {
757                 if(SFX_STYLE_FAMILY_FRAME == nFamily || SFX_STYLE_FAMILY_PARA == nFamily)
758                 {
759                     // clear FillStyle so that it works as a derived attribute
760                     SfxItemSet aTmpSet(*pDlg->GetOutputItemSet());
761 
762                     aTmpSet.ClearItem(XATTR_FILLSTYLE);
763                     xTmp->SetItemSet(aTmpSet);
764                 }
765             }
766 
767 			if(SFX_STYLE_FAMILY_PAGE == nFamily)
768 				mpView->InvalidateRulerPos();
769 
770 			if( bNew )
771 				mxBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xTmp.get() ) );
772 
773 			// JP 19.09.97:
774 			// Dialog vorm EndAction zerstoeren - bei Seitenvorlagen kann
775 			// muss der ItemSet zerstoert werden, damit die Cursor aus den
776 			// Kopf-/Fusszeilen entfernt werden. Sonst kommts zu GPFs!!!
777 			delete pDlg;
778 
779 			mpDoc->SetModified();
780 			if( !bModified )	// Bug 57028
781             {
782                 mpDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
783             }
784 
785 			GetWrtShell()->EndAllAction();
786 		}
787 		else
788 		{
789 			if( bNew )
790             {
791                 // #116530#
792 				//pBasePool->Erase( &aTmp );
793                 GetWrtShell()->Undo(1);
794                 mpDoc->GetIDocumentUndoRedo().ClearRedo();
795             }
796 
797 			if( !bModified )
798 				mpDoc->ResetModified();
799 			delete pDlg;
800 		}
801 	}
802 	else
803 	{
804 		// vor dem Dialog wird der HtmlMode an der DocShell versenkt
805 		PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
806 
807 		GetWrtShell()->StartAllAction();
808 
809 		// nur bei Absatz-Vorlagen die Maske neu setzen
810 		if( bNew )
811 		{
812 			nRet = SFX_STYLE_FAMILY_PARA == pStyle->GetFamily()
813 					? xTmp->GetMask()
814 					: SFXSTYLEBIT_USERDEF;
815 		}
816 		else if( pStyle->GetMask() != xTmp->GetMask() )
817 			nRet = xTmp->GetMask();
818 
819 		if( SFX_STYLE_FAMILY_PARA == nFamily )
820 			::SfxToSwPageDescAttr( *GetWrtShell(), xTmp->GetItemSet() );
821 		else
822 		{
823 			SfxItemSet aTmpSet( xTmp->GetItemSet() );
824 			if( SFX_STYLE_FAMILY_CHAR == nFamily )
825 			{
826 				const SfxPoolItem *pTmpBrush;
827 				if( SFX_ITEM_SET == aTmpSet.GetItemState( RES_BACKGROUND,
828 					sal_False, &pTmpBrush ) )
829 				{
830 					SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
831 					aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
832 					aTmpSet.Put( aTmpBrush );
833 				}
834 				aTmpSet.ClearItem( RES_BACKGROUND );
835 			}
836 			xTmp->SetItemSet( aTmpSet );
837 		}
838 		if(SFX_STYLE_FAMILY_PAGE == nFamily)
839 			mpView->InvalidateRulerPos();
840 
841 		if( bNew )
842 			mxBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xTmp.get() ) );
843 
844 		mpDoc->SetModified();
845 		if( !bModified )		// Bug 57028
846         {
847             mpDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
848         }
849 		GetWrtShell()->EndAllAction();
850 	}
851 
852 	return nRet;
853 }
854 
855 /*--------------------------------------------------------------------
856 	Beschreibung:	Delete
857  --------------------------------------------------------------------*/
858 
859 
Delete(const String & rName,sal_uInt16 nFamily)860 sal_uInt16 SwDocShell::Delete(const String &rName, sal_uInt16 nFamily)
861 {
862 	SfxStyleSheetBase *pStyle = mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
863 
864 	if(pStyle)
865 	{
866 		ASSERT(GetWrtShell(), "Keine Shell, keine Styles");
867 
868 		GetWrtShell()->StartAllAction();
869 		mxBasePool->Remove(pStyle);
870 		GetWrtShell()->EndAllAction();
871 
872 		return sal_True;
873 	}
874 	return sal_False;
875 }
876 
877 /*--------------------------------------------------------------------
878 	Beschreibung:	Vorlage anwenden
879  --------------------------------------------------------------------*/
880 
881 
ApplyStyles(const String & rName,const sal_uInt16 nFamily,SwWrtShell * pShell,const sal_uInt16 nMode)882 sal_uInt16 SwDocShell::ApplyStyles(
883     const String &rName,
884     const sal_uInt16 nFamily,
885     SwWrtShell* pShell,
886     const sal_uInt16 nMode )
887 {
888     SwDocStyleSheet* pStyle = (SwDocStyleSheet*) mxBasePool->Find( rName, (SfxStyleFamily) nFamily );
889 
890     ASSERT( pStyle, "Wo ist der StyleSheet" );
891     if ( !pStyle )
892         return sal_False;
893 
894     SwWrtShell *pSh = pShell ? pShell : GetWrtShell();
895 
896     ASSERT( pSh, "Keine Shell, keine Styles" );
897 
898     pSh->StartAllAction();
899 
900     switch (nFamily)
901     {
902     case SFX_STYLE_FAMILY_CHAR:
903     {
904         SwFmtCharFmt aFmt( pStyle->GetCharFmt() );
905         pSh->SetAttrItem( aFmt, ( nMode & KEY_SHIFT ) ? nsSetAttrMode::SETATTR_DONTREPLACE : nsSetAttrMode::SETATTR_DEFAULT );
906         break;
907     }
908     case SFX_STYLE_FAMILY_PARA:
909     {
910         // clear also list attributes at affected text nodes, if paragraph style has the list style attribute set.
911         pSh->SetTxtFmtColl( pStyle->GetCollection(), true );
912         break;
913     }
914     case SFX_STYLE_FAMILY_FRAME:
915     {
916         if ( pSh->IsFrmSelected() )
917             pSh->SetFrmFmt( pStyle->GetFrmFmt() );
918         break;
919     }
920     case SFX_STYLE_FAMILY_PAGE:
921     {
922         pSh->SetPageStyle( pStyle->GetPageDesc()->GetName() );
923         break;
924     }
925 
926     case SFX_STYLE_FAMILY_PSEUDO:
927     {
928         const SwNumRule* pNumRule = pStyle->GetNumRule();
929         const String sListIdForStyle = pNumRule->GetDefaultListId();
930         pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true );
931         break;
932     }
933 
934     default:
935         DBG_ERROR( "Unbekannte Familie" );
936     }
937     pSh->EndAllAction();
938 
939     return nFamily;
940 }
941 
942 /*--------------------------------------------------------------------
943 	Beschreibung:	Giesskanne starten
944  --------------------------------------------------------------------*/
945 
946 
947 
DoWaterCan(const String & rName,sal_uInt16 nFamily)948 sal_uInt16 SwDocShell::DoWaterCan(const String &rName, sal_uInt16 nFamily)
949 {
950 	ASSERT(GetWrtShell(), "Keine Shell, keine Styles");
951 
952 	SwEditWin& rEdtWin = mpView->GetEditWin();
953 	SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
954 	sal_Bool bWaterCan = !(pApply && pApply->eType != 0);
955 	if( !rName.Len() )
956 		bWaterCan = sal_False;
957 	SwApplyTemplate aTemplate;
958 	aTemplate.eType = nFamily;
959 
960 	if(bWaterCan)
961 	{
962 		SwDocStyleSheet* pStyle =
963 			(SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
964 
965 		ASSERT(pStyle, "Wo ist der StyleSheet");
966 		if(!pStyle) return nFamily;
967 
968 		switch(nFamily)
969 		{
970 			case SFX_STYLE_FAMILY_CHAR:
971 				aTemplate.aColl.pCharFmt = pStyle->GetCharFmt();
972 				break;
973 			case SFX_STYLE_FAMILY_PARA:
974 				aTemplate.aColl.pTxtColl = pStyle->GetCollection();
975 				break;
976 			case SFX_STYLE_FAMILY_FRAME:
977 				aTemplate.aColl.pFrmFmt = pStyle->GetFrmFmt();
978 				break;
979 			case SFX_STYLE_FAMILY_PAGE:
980 				aTemplate.aColl.pPageDesc = (SwPageDesc*)pStyle->GetPageDesc();
981 				break;
982 			case SFX_STYLE_FAMILY_PSEUDO:
983 				aTemplate.aColl.pNumRule = (SwNumRule*)pStyle->GetNumRule();
984 				break;
985 
986 			default:
987 				DBG_ERROR( "Unbekannte Familie");
988 		}
989 	}
990 	else
991 		aTemplate.eType = 0;
992 
993 	// Template anwenden
994 	mpView->GetEditWin().SetApplyTemplate(aTemplate);
995 
996 	return nFamily;
997 }
998 
999 /*--------------------------------------------------------------------
1000 	Beschreibung:	Vorlage Updaten
1001  --------------------------------------------------------------------*/
1002 
1003 
UpdateStyle(const String & rName,sal_uInt16 nFamily,SwWrtShell * pShell)1004 sal_uInt16 SwDocShell::UpdateStyle(const String &rName, sal_uInt16 nFamily, SwWrtShell* pShell)
1005 {
1006     SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1007 	ASSERT(GetWrtShell(), "Keine Shell, keine Styles");
1008 
1009 	SwDocStyleSheet* pStyle =
1010 		(SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
1011 
1012 	if(!pStyle)
1013 		return nFamily;
1014 
1015 	switch(nFamily)
1016 	{
1017 		case SFX_STYLE_FAMILY_PARA:
1018 		{
1019 			SwTxtFmtColl* pColl = pStyle->GetCollection();
1020 			if(pColl && !pColl->IsDefault())
1021 			{
1022 				GetWrtShell()->StartAllAction();
1023 
1024                 SwRewriter aRewriter;
1025                 aRewriter.AddRule(UNDO_ARG1, pColl->GetName());
1026 
1027                 GetWrtShell()->StartUndo(UNDO_INSFMTATTR, &aRewriter);
1028 				GetWrtShell()->FillByEx(pColl);
1029 					// Vorlage auch anwenden, um harte Attributierung
1030 					// zu entfernen
1031 				GetWrtShell()->SetTxtFmtColl( pColl );
1032                 GetWrtShell()->EndUndo();
1033 				GetWrtShell()->EndAllAction();
1034 			}
1035 			break;
1036 		}
1037 		case SFX_STYLE_FAMILY_FRAME:
1038 		{
1039 			SwFrmFmt* pFrm = pStyle->GetFrmFmt();
1040             if( pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault() )
1041 			{
1042 				SfxItemSet aSet( GetPool(), aFrmFmtSetRange );
1043                 pCurrWrtShell->StartAllAction();
1044                 pCurrWrtShell->GetFlyFrmAttr( aSet );
1045 
1046                 // --> OD 2009-12-28 #i105535#
1047                 // no update of anchor attribute
1048                 aSet.ClearItem( RES_ANCHOR );
1049                 // <--
1050 
1051                 pFrm->SetFmtAttr( aSet );
1052 
1053 					// Vorlage auch anwenden, um harte Attributierung
1054 					// zu entfernen
1055                 pCurrWrtShell->SetFrmFmt( pFrm, sal_True );
1056                 pCurrWrtShell->EndAllAction();
1057 			}
1058 		}
1059 		break;
1060 		case SFX_STYLE_FAMILY_CHAR:
1061 		{
1062 			SwCharFmt* pChar = pStyle->GetCharFmt();
1063 			if( pChar && !pChar->IsDefault() )
1064 			{
1065                 pCurrWrtShell->StartAllAction();
1066                 pCurrWrtShell->FillByEx(pChar);
1067 					// Vorlage auch anwenden, um harte Attributierung
1068 					// zu entfernen
1069                 pCurrWrtShell->EndAllAction();
1070 			}
1071 
1072 		}
1073 		break;
1074 		case SFX_STYLE_FAMILY_PSEUDO:
1075 		{
1076 			const SwNumRule* pCurRule;
1077 			if( pStyle->GetNumRule() &&
1078                 0 != ( pCurRule = pCurrWrtShell->GetNumRuleAtCurrCrsrPos() ))
1079 			{
1080 				SwNumRule aRule( *pCurRule );
1081                 // --> OD 2008-07-08 #i91400#
1082                 aRule.SetName( pStyle->GetNumRule()->GetName(),
1083                                *(pCurrWrtShell->GetDoc()) );
1084                 // <--
1085                 pCurrWrtShell->ChgNumRuleFmts( aRule );
1086 			}
1087 		}
1088 		break;
1089 	}
1090 	return nFamily;
1091 }
1092 
1093 /*--------------------------------------------------------------------
1094 	Beschreibung:	NewByExample
1095  --------------------------------------------------------------------*/
1096 
1097 
MakeByExample(const String & rName,sal_uInt16 nFamily,sal_uInt16 nMask,SwWrtShell * pShell)1098 sal_uInt16 SwDocShell::MakeByExample( const String &rName, sal_uInt16 nFamily,
1099 									sal_uInt16 nMask, SwWrtShell* pShell )
1100 {
1101     SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1102 	SwDocStyleSheet* pStyle = (SwDocStyleSheet*)mxBasePool->Find(
1103 											rName, (SfxStyleFamily)nFamily );
1104 	if(!pStyle)
1105 	{
1106 		// JP 07.07.95: behalte die akt. Maske vom PI bei, dadurch werden
1107 		//				neue sofort in den sichtbaren Bereich einsortiert
1108 		if( SFXSTYLEBIT_ALL == nMask || SFXSTYLEBIT_USED == nMask )
1109 			nMask = SFXSTYLEBIT_USERDEF;
1110 		else
1111 			nMask |= SFXSTYLEBIT_USERDEF;
1112 
1113 		pStyle = (SwDocStyleSheet*)&mxBasePool->Make(rName,
1114 								(SfxStyleFamily)nFamily, nMask );
1115 	}
1116 
1117 	switch(nFamily)
1118 	{
1119 		case  SFX_STYLE_FAMILY_PARA:
1120 		{
1121 			SwTxtFmtColl* pColl = pStyle->GetCollection();
1122 			if(pColl && !pColl->IsDefault())
1123 			{
1124                 pCurrWrtShell->StartAllAction();
1125                 pCurrWrtShell->FillByEx(pColl);
1126 					// Vorlage auch anwenden, um harte Attributierung
1127 					// zu entfernen
1128                 pColl->SetDerivedFrom(pCurrWrtShell->GetCurTxtFmtColl());
1129 
1130 					// setze die Maske noch an der Collection:
1131 				sal_uInt16 nId = pColl->GetPoolFmtId() & 0x87ff;
1132 				switch( nMask & 0x0fff )
1133 				{
1134 				case SWSTYLEBIT_TEXT:
1135 					nId |= COLL_TEXT_BITS;
1136 					break;
1137 				case SWSTYLEBIT_CHAPTER:
1138 					nId |= COLL_DOC_BITS;
1139 					break;
1140 				case SWSTYLEBIT_LIST:
1141 					nId |= COLL_LISTS_BITS;
1142 					break;
1143 				case SWSTYLEBIT_IDX:
1144 					nId |= COLL_REGISTER_BITS;
1145 					break;
1146 				case SWSTYLEBIT_EXTRA:
1147 					nId |= COLL_EXTRA_BITS;
1148 					break;
1149 				case SWSTYLEBIT_HTML:
1150 					nId |= COLL_HTML_BITS;
1151 					break;
1152 				}
1153 				pColl->SetPoolFmtId(nId);
1154 
1155                 pCurrWrtShell->SetTxtFmtColl(pColl);
1156                 pCurrWrtShell->EndAllAction();
1157 			}
1158 		}
1159 		break;
1160 		case SFX_STYLE_FAMILY_FRAME:
1161 		{
1162 			SwFrmFmt* pFrm = pStyle->GetFrmFmt();
1163             if(pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault())
1164 			{
1165                 pCurrWrtShell->StartAllAction();
1166 
1167 				SfxItemSet aSet(GetPool(), aFrmFmtSetRange );
1168                 pCurrWrtShell->GetFlyFrmAttr( aSet );
1169 
1170                 SwFrmFmt* pFFmt = pCurrWrtShell->GetCurFrmFmt();
1171                 pFrm->SetDerivedFrom( pFFmt );
1172 
1173 				// JP 10.06.98: nur automatische Orientierungen uebernehmen
1174 /*				#61359# jetzt auch wieder alle Orientierungen
1175 				const SfxPoolItem* pItem;
1176 				if( SFX_ITEM_SET == aSet.GetItemState( RES_VERT_ORIENT,
1177 					sal_False, &pItem ) &&
1178                     text::VertOrientation::NONE == ((SwFmtVertOrient*)pItem)->GetVertOrient())
1179 					aSet.ClearItem( RES_VERT_ORIENT );
1180 
1181 				if( SFX_ITEM_SET == aSet.GetItemState( RES_HORI_ORIENT,
1182 					sal_False, &pItem ) &&
1183                     text::HoriOrientation::NONE == ((SwFmtHoriOrient*)pItem)->GetHoriOrient())
1184 					aSet.ClearItem( RES_HORI_ORIENT );
1185  */
1186 
1187                 pFrm->SetFmtAttr( aSet );
1188 					// Vorlage auch anwenden, um harte Attributierung
1189 					// zu entfernen
1190                 pCurrWrtShell->SetFrmFmt( pFrm );
1191                 pCurrWrtShell->EndAllAction();
1192 			}
1193 		}
1194 		break;
1195 		case SFX_STYLE_FAMILY_CHAR:
1196 		{
1197 			SwCharFmt* pChar = pStyle->GetCharFmt();
1198 			if(pChar && !pChar->IsDefault())
1199 			{
1200                 pCurrWrtShell->StartAllAction();
1201                 pCurrWrtShell->FillByEx( pChar );
1202                 pChar->SetDerivedFrom( pCurrWrtShell->GetCurCharFmt() );
1203 				SwFmtCharFmt aFmt( pChar );
1204                 pCurrWrtShell->SetAttrItem( aFmt );
1205                 pCurrWrtShell->EndAllAction();
1206 			}
1207 		}
1208 		break;
1209 
1210 		case SFX_STYLE_FAMILY_PAGE:
1211 		{
1212             pCurrWrtShell->StartAllAction();
1213             sal_uInt16 nPgDsc = pCurrWrtShell->GetCurPageDesc();
1214             SwPageDesc& rSrc = (SwPageDesc&)pCurrWrtShell->GetPageDesc( nPgDsc );
1215 			SwPageDesc& rDest = *(SwPageDesc*)pStyle->GetPageDesc();
1216 
1217 			sal_uInt16 nPoolId = rDest.GetPoolFmtId();
1218 			sal_uInt16 nHId = rDest.GetPoolHelpId();
1219 			sal_uInt8 nHFId = rDest.GetPoolHlpFileId();
1220 
1221             pCurrWrtShell->GetDoc()->CopyPageDesc( rSrc, rDest );
1222 
1223 			// PoolId darf NIE kopiert werden!
1224 			rDest.SetPoolFmtId( nPoolId );
1225 			rDest.SetPoolHelpId( nHId );
1226 			rDest.SetPoolHlpFileId( nHFId );
1227 
1228 			// werden Kopf-/Fusszeilen angelegt, so gibt es kein Undo mehr!
1229             pCurrWrtShell->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
1230 
1231             pCurrWrtShell->EndAllAction();
1232 		}
1233 		break;
1234 
1235 		case SFX_STYLE_FAMILY_PSEUDO:
1236 		{
1237             pCurrWrtShell->StartAllAction();
1238 
1239             SwNumRule aRule( *pCurrWrtShell->GetNumRuleAtCurrCrsrPos() );
1240 			String sOrigRule( aRule.GetName() );
1241             // --> OD 2008-07-08 #i91400#
1242             aRule.SetName( pStyle->GetNumRule()->GetName(),
1243                            *(pCurrWrtShell->GetDoc()) );
1244             // <--
1245             pCurrWrtShell->ChgNumRuleFmts( aRule );
1246 
1247             pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() );
1248 
1249 
1250             pCurrWrtShell->EndAllAction();
1251 		}
1252 		break;
1253 	}
1254 	return nFamily;
1255 }
1256 
LoadStyles(SfxObjectShell & rSource)1257 void  SwDocShell::LoadStyles( SfxObjectShell& rSource )
1258 {
1259     _LoadStyles(rSource, sal_False);
1260 }
1261 /* -----------------16.05.2003 15:45-----------------
1262     bPreserveCurrentDocument determines whether SetFixFields() is called
1263     This call modifies the source document. This mustn't happen when the source
1264     is a document the user is working on.
1265     Calls of ::LoadStyles() normally use files especially loaded for the purpose
1266     of importing styles.
1267  --------------------------------------------------*/
_LoadStyles(SfxObjectShell & rSource,sal_Bool bPreserveCurrentDocument)1268 void SwDocShell::_LoadStyles( SfxObjectShell& rSource, sal_Bool bPreserveCurrentDocument )
1269 {
1270 /*	[Beschreibung]
1271 
1272 	Diese Methode wird vom SFx gerufen, wenn aus einer Dokument-Vorlage
1273 	Styles nachgeladen werden sollen. Bestehende Styles soll dabei
1274 	"uberschrieben werden. Das Dokument mu"s daher neu formatiert werden.
1275 	Daher werden die Applikationen in der Regel diese Methode "uberladen
1276 	und in ihrer Implementierung die Implementierung der Basisklasse
1277 	rufen.
1278 */
1279 	// ist die Source unser Document, dann uebernehmen wir das
1280 	// abpruefen selbst (wesentlich schneller und laeuft nicht ueber
1281 	// die Kruecke SfxStylePool
1282 	if( rSource.ISA( SwDocShell ))
1283 	{
1284 		//JP 28.05.99: damit die Kopf-/Fusszeilen nicht den fixen Inhalt
1285 		// 				der Vorlage erhalten, einmal alle FixFelder der
1286 		//				Source aktualisieren
1287         if(!bPreserveCurrentDocument)
1288             ((SwDocShell&)rSource).mpDoc->SetFixFields(false, NULL);
1289 		if( mpWrtShell )
1290 		{
1291 			mpWrtShell->StartAllAction();
1292 			mpDoc->ReplaceStyles( *((SwDocShell&)rSource).mpDoc );
1293 			mpWrtShell->EndAllAction();
1294 		}
1295 		else
1296 		{
1297 			sal_Bool bModified = mpDoc->IsModified();
1298 			mpDoc->ReplaceStyles( *((SwDocShell&)rSource).mpDoc );
1299 			if( !bModified && mpDoc->IsModified() && !mpView )
1300 			{
1301 				// die View wird spaeter angelegt, ueberschreibt aber das
1302 				// Modify-Flag. Per Undo ist sowieso nichts mehr zu machen
1303                 mpDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1304             }
1305         }
1306     }
1307 	else
1308 		SfxObjectShell::LoadStyles( rSource );
1309 }
1310 
1311 
FormatPage(const String & rPage,const sal_uInt16 nSlot,SwWrtShell & rActShell)1312 void SwDocShell::FormatPage(
1313     const String& rPage,
1314     const sal_uInt16 nSlot,
1315     SwWrtShell& rActShell )
1316 {
1317     Edit( rPage, aEmptyStr, SFX_STYLE_FAMILY_PAGE, 0, sal_False, nSlot, &rActShell);
1318 }
1319 
GetStyleFamilyBitmap(SfxStyleFamily eFamily,BmpColorMode eColorMode)1320 Bitmap SwDocShell::GetStyleFamilyBitmap( SfxStyleFamily eFamily, BmpColorMode eColorMode )
1321 {
1322 	if( SFX_STYLE_FAMILY_PSEUDO == eFamily )
1323 	{
1324 		if ( eColorMode == BMP_COLOR_NORMAL )
1325 			return Bitmap( SW_RES( BMP_STYLES_FAMILY_NUM ));
1326 		else
1327 			return Bitmap( SW_RES( BMP_STYLES_FAMILY_NUM_HC ));
1328 	}
1329 
1330 	return SfxObjectShell::GetStyleFamilyBitmap( eFamily, eColorMode );
1331 }
1332 
1333 
1334 
1335