Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
22 : #include <com/sun/star/beans/XPropertySet.hpp>
23 : #include <com/sun/star/container/XNameAccess.hpp>
24 :
25 : #include <comphelper/flagguard.hxx>
26 :
27 : #include <hintids.hxx>
28 : #include <sfx2/app.hxx>
29 : #include <svl/whiter.hxx>
30 : #include <sfx2/templdlg.hxx>
31 : #include <sfx2/tplpitem.hxx>
32 : #include <sfx2/request.hxx>
33 : #include <sfx2/dispatch.hxx>
34 : #include <sfx2/newstyle.hxx>
35 : #include <sfx2/printer.hxx>
36 : #include <svl/macitem.hxx>
37 : #include <editeng/brushitem.hxx>
38 : #include <svl/stritem.hxx>
39 : #include <svl/languageoptions.hxx>
40 : #include <editeng/eeitem.hxx>
41 : #include <sfx2/htmlmode.hxx>
42 : #include <swmodule.hxx>
43 : #include <wdocsh.hxx>
44 : #include <fmtfsize.hxx>
45 : #include <fchrfmt.hxx>
46 : #include <svtools/htmlcfg.hxx>
47 : #include <SwStyleNameMapper.hxx>
48 : #include <SwRewriter.hxx>
49 : #include <numrule.hxx>
50 : #include <swundo.hxx>
51 :
52 : #include "view.hxx"
53 : #include "wrtsh.hxx"
54 : #include "docsh.hxx"
55 : #include "uitool.hxx"
56 : #include "cmdid.h"
57 : #include "globals.hrc"
58 : #include "viewopt.hxx"
59 : #include <doc.hxx>
60 : #include <IDocumentUndoRedo.hxx>
61 : #include "swstyle.h"
62 : #include "frmfmt.hxx"
63 : #include "charfmt.hxx"
64 : #include "poolfmt.hxx"
65 : #include "pagedesc.hxx"
66 : #include "docstyle.hxx"
67 : #include "uiitems.hxx"
68 : #include "fmtcol.hxx"
69 : #include "frmmgr.hxx" //SwFrmValid
70 : #include "swevent.hxx"
71 : #include "edtwin.hxx"
72 : #include "unochart.hxx"
73 :
74 : #include "app.hrc"
75 : #include <fmtui.hrc>
76 : #include "swabstdlg.hxx"
77 :
78 : #include <list.hxx>
79 :
80 : #include <paratr.hxx> //#outline level,add by zhaojianwei
81 :
82 : extern bool bNoInterrupt; // in mainwn.cxx
83 :
84 : using namespace ::com::sun::star;
85 :
86 4589 : void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh)
87 : {
88 4589 : SfxWhichIter aIter(rSet);
89 4589 : sal_uInt16 nWhich = aIter.FirstWhich();
90 4589 : sal_uInt16 nActualFamily = USHRT_MAX;
91 :
92 4589 : SwWrtShell* pShell = pSh ? pSh : GetWrtShell();
93 4589 : if(!pShell)
94 : {
95 0 : while (nWhich)
96 : {
97 0 : rSet.DisableItem(nWhich);
98 0 : nWhich = aIter.NextWhich();
99 : }
100 4589 : return;
101 : }
102 : else
103 : {
104 4589 : SfxViewFrame* pFrame = pShell->GetView().GetViewFrame();
105 4589 : const ISfxTemplateCommon* pCommon = SFX_APP()->GetCurrentTemplateCommon(pFrame->GetBindings());
106 4589 : if( pCommon )
107 584 : nActualFamily = static_cast< sal_uInt16 >(pCommon->GetActualFamily());
108 : }
109 :
110 17419 : while (nWhich)
111 : {
112 : // determine current template to every family
113 8241 : String aName;
114 8241 : switch (nWhich)
115 : {
116 : case SID_STYLE_APPLY:
117 : {// here the template and its family are passed to the StyleBox
118 : // so that this family is being showed
119 1554 : if(pShell->IsFrmSelected())
120 : {
121 0 : SwFrmFmt* pFmt = pShell->GetCurFrmFmt();
122 0 : if( pFmt )
123 0 : aName = pFmt->GetName();
124 : }
125 : else
126 : {
127 1554 : SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
128 1554 : if(pColl)
129 1554 : aName = pColl->GetName();
130 : }
131 1554 : rSet.Put(SfxTemplateItem(nWhich, aName));
132 : }
133 1554 : break;
134 : case SID_STYLE_FAMILY1:
135 1613 : if( !pShell->IsFrmSelected() )
136 : {
137 1613 : SwCharFmt* pFmt = pShell->GetCurCharFmt();
138 1613 : if(pFmt)
139 27 : aName = pFmt->GetName();
140 : else
141 1586 : aName = SwStyleNameMapper::GetTextUINameArray()[
142 1586 : RES_POOLCOLL_STANDARD - RES_POOLCOLL_TEXT_BEGIN ];
143 1613 : rSet.Put(SfxTemplateItem(nWhich, aName));
144 : }
145 1613 : break;
146 :
147 : case SID_STYLE_FAMILY2:
148 1613 : if(!pShell->IsFrmSelected())
149 : {
150 1613 : SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
151 1613 : if(pColl)
152 1613 : aName = pColl->GetName();
153 :
154 1613 : SfxTemplateItem aItem(nWhich, aName);
155 :
156 1613 : sal_uInt16 nMask = 0;
157 1613 : if( pDoc->get(IDocumentSettingAccess::HTML_MODE) )
158 5 : nMask = SWSTYLEBIT_HTML;
159 : else
160 : {
161 1608 : const int nSelection = pShell->GetFrmType(0,sal_True);
162 1608 : if(pShell->GetCurTOX())
163 0 : nMask = SWSTYLEBIT_IDX ;
164 3216 : else if(nSelection & FRMTYPE_HEADER ||
165 3216 : nSelection & FRMTYPE_FOOTER ||
166 3211 : nSelection & FRMTYPE_TABLE ||
167 3206 : nSelection & FRMTYPE_FLY_ANY ||
168 3206 : nSelection & FRMTYPE_FOOTNOTE ||
169 1603 : nSelection & FRMTYPE_FTNPAGE)
170 5 : nMask = SWSTYLEBIT_EXTRA;
171 : else
172 1603 : nMask = SWSTYLEBIT_TEXT;
173 : }
174 :
175 1613 : aItem.SetValue(nMask);
176 1613 : rSet.Put(aItem);
177 : }
178 :
179 1613 : break;
180 :
181 : case SID_STYLE_FAMILY3:
182 :
183 1613 : if( pDoc->get(IDocumentSettingAccess::HTML_MODE) )
184 5 : rSet.DisableItem( nWhich );
185 : else
186 : {
187 1608 : SwFrmFmt* pFmt = pShell->GetCurFrmFmt();
188 1608 : if(pFmt && pShell->IsFrmSelected())
189 : {
190 0 : aName = pFmt->GetName();
191 0 : rSet.Put(SfxTemplateItem(nWhich, aName));
192 : }
193 : }
194 1613 : break;
195 :
196 : case SID_STYLE_FAMILY4:
197 : {
198 1613 : SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
199 1613 : if( pDoc->get(IDocumentSettingAccess::HTML_MODE) && !rHtmlOpt.IsPrintLayoutExtension())
200 5 : rSet.DisableItem( nWhich );
201 : else
202 : {
203 1608 : sal_uInt16 n = pShell->GetCurPageDesc( sal_False );
204 1608 : if( n < pShell->GetPageDescCnt() )
205 1608 : aName = pShell->GetPageDesc( n ).GetName();
206 :
207 1608 : rSet.Put(SfxTemplateItem(nWhich, aName));
208 : }
209 : }
210 1613 : break;
211 : case SID_STYLE_FAMILY5:
212 : {
213 103 : const SwNumRule* pRule = pShell->GetCurNumRule();
214 103 : if( pRule )
215 0 : aName = pRule->GetName();
216 :
217 103 : rSet.Put(SfxTemplateItem(nWhich, aName));
218 : }
219 103 : break;
220 :
221 : case SID_STYLE_WATERCAN:
222 : {
223 44 : SwEditWin& rEdtWin = pShell->GetView().GetEditWin();
224 44 : SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
225 44 : rSet.Put(SfxBoolItem(nWhich, pApply && pApply->eType != 0));
226 : }
227 44 : break;
228 : case SID_STYLE_UPDATE_BY_EXAMPLE:
229 88 : if( pShell->IsFrmSelected()
230 : ? SFX_STYLE_FAMILY_FRAME != nActualFamily
231 44 : : ( SFX_STYLE_FAMILY_FRAME == nActualFamily ||
232 88 : SFX_STYLE_FAMILY_PAGE == nActualFamily ||
233 0 : (SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetCurNumRule())) )
234 : {
235 0 : rSet.DisableItem( nWhich );
236 : }
237 44 : break;
238 :
239 : case SID_STYLE_NEW_BY_EXAMPLE:
240 88 : if( (pShell->IsFrmSelected()
241 : ? SFX_STYLE_FAMILY_FRAME != nActualFamily
242 44 : : SFX_STYLE_FAMILY_FRAME == nActualFamily) ||
243 0 : (SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetCurNumRule()) )
244 : {
245 0 : rSet.DisableItem( nWhich );
246 : }
247 44 : break;
248 :
249 : default:
250 : OSL_FAIL("Invalid SlotId");
251 : }
252 8241 : nWhich = aIter.NextWhich();
253 12830 : }
254 : }
255 :
256 : // evaluate StyleSheet-Requests
257 0 : void SwDocShell::ExecStyleSheet( SfxRequest& rReq )
258 : {
259 0 : sal_uInt16 nSlot = rReq.GetSlot();
260 0 : sal_uInt16 nRet = SFXSTYLEBIT_ALL;
261 :
262 0 : const SfxItemSet* pArgs = rReq.GetArgs();
263 : const SfxPoolItem* pItem;
264 0 : SwWrtShell* pActShell = 0;
265 0 : switch (nSlot)
266 : {
267 : case SID_STYLE_NEW:
268 0 : if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_FAMILY,
269 0 : sal_False, &pItem ))
270 : {
271 0 : const sal_uInt16 nFamily = ((const SfxUInt16Item*)pItem)->GetValue();
272 :
273 0 : String sName;
274 0 : sal_uInt16 nMask = 0;
275 0 : if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_NEW,
276 0 : sal_False, &pItem ))
277 0 : sName = ((const SfxStringItem*)pItem)->GetValue();
278 0 : if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_MASK,
279 0 : sal_False, &pItem ))
280 0 : nMask = ((const SfxUInt16Item*)pItem)->GetValue();
281 0 : String sParent;
282 0 : if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_REFERENCE,
283 0 : sal_False, &pItem ))
284 0 : sParent = ((const SfxStringItem*)pItem)->GetValue();
285 :
286 0 : nRet = Edit( sName, sParent, nFamily, nMask, sal_True, 0, 0, rReq.IsAPI() );
287 : }
288 0 : break;
289 :
290 : case SID_STYLE_APPLY:
291 0 : if( !pArgs )
292 : {
293 0 : GetView()->GetViewFrame()->GetDispatcher()->Execute(SID_STYLE_DESIGNER, sal_False);
294 0 : break;
295 : }
296 : else
297 : {
298 : // convert internal StyleName to DisplayName (slot implementation uses the latter)
299 0 : SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_APPLY_STYLE, sal_False );
300 0 : SFX_REQUEST_ARG( rReq, pFamilyItem, SfxStringItem, SID_STYLE_FAMILYNAME, sal_False );
301 0 : if ( pFamilyItem && pNameItem )
302 : {
303 0 : uno::Reference< style::XStyleFamiliesSupplier > xModel(GetModel(), uno::UNO_QUERY);
304 : try
305 : {
306 0 : uno::Reference< container::XNameAccess > xStyles;
307 0 : uno::Reference< container::XNameAccess > xCont = xModel->getStyleFamilies();
308 0 : xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
309 0 : uno::Reference< beans::XPropertySet > xInfo;
310 0 : xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
311 0 : OUString aUIName;
312 0 : xInfo->getPropertyValue("DisplayName") >>= aUIName;
313 0 : if ( !aUIName.isEmpty() )
314 0 : rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
315 : }
316 0 : catch (const uno::Exception&)
317 : {
318 0 : }
319 : }
320 : }
321 :
322 : // intentionally no break
323 :
324 : case SID_STYLE_EDIT:
325 : case SID_STYLE_DELETE:
326 : case SID_STYLE_HIDE:
327 : case SID_STYLE_SHOW:
328 : case SID_STYLE_WATERCAN:
329 : case SID_STYLE_FAMILY:
330 : case SID_STYLE_UPDATE_BY_EXAMPLE:
331 : case SID_STYLE_NEW_BY_EXAMPLE:
332 : {
333 0 : String aParam;
334 0 : sal_uInt16 nFamily = SFX_STYLE_FAMILY_PARA;
335 0 : sal_uInt16 nMask = 0;
336 :
337 0 : if( !pArgs )
338 : {
339 0 : nFamily = SFX_STYLE_FAMILY_PARA;
340 :
341 0 : switch (nSlot)
342 : {
343 : case SID_STYLE_NEW_BY_EXAMPLE:
344 : {
345 : SfxNewStyleDlg *pDlg = new SfxNewStyleDlg( 0,
346 0 : *GetStyleSheetPool());
347 0 : if(RET_OK == pDlg->Execute())
348 : {
349 0 : aParam = pDlg->GetName();
350 0 : rReq.AppendItem(SfxStringItem(nSlot, aParam));
351 : }
352 :
353 0 : delete pDlg;
354 : }
355 0 : break;
356 :
357 : case SID_STYLE_UPDATE_BY_EXAMPLE:
358 : case SID_STYLE_EDIT:
359 : {
360 0 : SwTxtFmtColl* pColl = GetWrtShell()->GetCurTxtFmtColl();
361 0 : if(pColl)
362 : {
363 0 : aParam = pColl->GetName();
364 0 : rReq.AppendItem(SfxStringItem(nSlot, aParam));
365 : }
366 : }
367 0 : break;
368 : }
369 : }
370 : else
371 : {
372 : OSL_ENSURE( pArgs->Count(), "SfxBug ItemSet is empty");
373 :
374 0 : SwWrtShell* pShell = GetWrtShell();
375 0 : if( SFX_ITEM_SET == pArgs->GetItemState(nSlot, sal_False, &pItem ))
376 0 : aParam = ((const SfxStringItem*)pItem)->GetValue();
377 :
378 0 : if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILY,
379 0 : sal_False, &pItem ))
380 0 : nFamily = ((const SfxUInt16Item*)pItem)->GetValue();
381 :
382 0 : if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILYNAME, sal_False, &pItem ))
383 : {
384 0 : String aFamily = ((const SfxStringItem*)pItem)->GetValue();
385 0 : if(aFamily.CompareToAscii("CharacterStyles") == COMPARE_EQUAL)
386 0 : nFamily = SFX_STYLE_FAMILY_CHAR;
387 : else
388 0 : if(aFamily.CompareToAscii("ParagraphStyles") == COMPARE_EQUAL)
389 0 : nFamily = SFX_STYLE_FAMILY_PARA;
390 : else
391 0 : if(aFamily.CompareToAscii("PageStyles") == COMPARE_EQUAL)
392 0 : nFamily = SFX_STYLE_FAMILY_PAGE;
393 : else
394 0 : if(aFamily.CompareToAscii("FrameStyles") == COMPARE_EQUAL)
395 0 : nFamily = SFX_STYLE_FAMILY_FRAME;
396 : else
397 0 : if(aFamily.CompareToAscii("NumberingStyles") == COMPARE_EQUAL)
398 0 : nFamily = SFX_STYLE_FAMILY_PSEUDO;
399 : }
400 :
401 0 : if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_MASK,
402 0 : sal_False, &pItem ))
403 0 : nMask = ((const SfxUInt16Item*)pItem)->GetValue();
404 0 : if( SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_WRTSHELL,
405 0 : sal_False, &pItem ))
406 0 : pActShell = pShell = (SwWrtShell*)((SwPtrItem*)pItem)->GetValue();
407 :
408 0 : if( nSlot == SID_STYLE_UPDATE_BY_EXAMPLE )
409 : {
410 0 : switch( nFamily )
411 : {
412 : case SFX_STYLE_FAMILY_PARA:
413 : {
414 0 : SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl();
415 0 : if(pColl)
416 0 : aParam = pColl->GetName();
417 : }
418 0 : break;
419 : case SFX_STYLE_FAMILY_FRAME:
420 : {
421 0 : SwFrmFmt* pFrm = pWrtShell->GetCurFrmFmt();
422 0 : if( pFrm )
423 0 : aParam = pFrm->GetName();
424 : }
425 0 : break;
426 : case SFX_STYLE_FAMILY_CHAR:
427 : {
428 0 : SwCharFmt* pChar = pWrtShell->GetCurCharFmt();
429 0 : if( pChar )
430 0 : aParam = pChar->GetName();
431 : }
432 0 : break;
433 : case SFX_STYLE_FAMILY_PSEUDO:
434 0 : if(SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, sal_False, &pItem))
435 : {
436 0 : aParam = ((const SfxStringItem*)pItem)->GetValue();
437 : }
438 0 : break;
439 : }
440 0 : rReq.AppendItem(SfxStringItem(nSlot, aParam));
441 : }
442 : }
443 0 : if (aParam.Len() || nSlot == SID_STYLE_WATERCAN )
444 : {
445 0 : switch(nSlot)
446 : {
447 : case SID_STYLE_EDIT:
448 0 : nRet = Edit(aParam, aEmptyStr, nFamily, nMask, sal_False, 0, pActShell );
449 0 : break;
450 : case SID_STYLE_DELETE:
451 0 : nRet = Delete(aParam, nFamily);
452 0 : break;
453 : case SID_STYLE_HIDE:
454 : case SID_STYLE_SHOW:
455 0 : nRet = Hide(aParam, nFamily, nSlot == SID_STYLE_HIDE);
456 0 : break;
457 : case SID_STYLE_APPLY:
458 : // Shell-switch in ApplyStyles
459 0 : nRet = ApplyStyles(aParam, nFamily, pActShell, rReq.GetModifier() );
460 0 : break;
461 : case SID_STYLE_WATERCAN:
462 0 : nRet = DoWaterCan(aParam, nFamily);
463 0 : break;
464 : case SID_STYLE_UPDATE_BY_EXAMPLE:
465 0 : nRet = UpdateStyle(aParam, nFamily, pActShell);
466 0 : break;
467 : case SID_STYLE_NEW_BY_EXAMPLE:
468 : {
469 0 : nRet = MakeByExample(aParam, nFamily, nMask, pActShell );
470 0 : SfxTemplateDialog* pDlg = SFX_APP()->GetTemplateDialog();
471 :
472 0 : if(pDlg && pDlg->IsVisible())
473 0 : pDlg->Update();
474 : }
475 0 : break;
476 :
477 : default:
478 : OSL_FAIL("Invalid SlotId");
479 : }
480 :
481 0 : rReq.Done();
482 : }
483 :
484 0 : break;
485 : }
486 : }
487 :
488 0 : if(rReq.IsAPI()) // Basic only gets TRUE or FALSE
489 0 : rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet !=0));
490 : else
491 0 : rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet));
492 :
493 0 : }
494 :
495 0 : class ApplyStyle
496 : {
497 : public:
498 0 : ApplyStyle(SwDocShell &rDocSh, bool bNew, SfxStyleSheetBase* pStyle,
499 : sal_uInt16 nRet, rtl::Reference< SwDocStyleSheet > xTmp,
500 : sal_uInt16 nFamily, SfxAbstractApplyTabDialog *pDlg,
501 : rtl::Reference< SfxStyleSheetBasePool > xBasePool,
502 : bool bModified)
503 : : m_rDocSh(rDocSh)
504 : , m_bNew(bNew)
505 : , m_pStyle(pStyle)
506 : , m_nRet(nRet)
507 : , m_xTmp(xTmp)
508 : , m_nFamily(nFamily)
509 : , m_pDlg(pDlg)
510 : , m_xBasePool(xBasePool)
511 0 : , m_bModified(bModified)
512 : {
513 0 : }
514 : DECL_LINK( ApplyHdl, void* );
515 0 : void apply()
516 : {
517 0 : ApplyHdl(NULL);
518 0 : }
519 0 : sal_uInt16 getRet() const { return m_nRet; }
520 : private:
521 : SwDocShell &m_rDocSh;
522 : bool m_bNew;
523 : SfxStyleSheetBase* m_pStyle;
524 : sal_uInt16 m_nRet;
525 : rtl::Reference< SwDocStyleSheet > m_xTmp;
526 : sal_uInt16 m_nFamily;
527 : SfxAbstractApplyTabDialog *m_pDlg;
528 : rtl::Reference< SfxStyleSheetBasePool > m_xBasePool;
529 : bool m_bModified;
530 : };
531 :
532 0 : IMPL_LINK_NOARG(ApplyStyle, ApplyHdl)
533 : {
534 0 : SwWrtShell* pWrtShell = m_rDocSh.GetWrtShell();
535 0 : SwDoc* pDoc = m_rDocSh.GetDoc();
536 0 : SwView* pView = m_rDocSh.GetView();
537 :
538 0 : pWrtShell->StartAllAction();
539 :
540 : // newly set the mask only with paragraph-templates
541 0 : if( m_bNew )
542 : {
543 0 : m_nRet = SFX_STYLE_FAMILY_PARA == m_pStyle->GetFamily()
544 0 : ? m_xTmp->GetMask()
545 0 : : SFXSTYLEBIT_USERDEF;
546 : }
547 0 : else if( m_pStyle->GetMask() != m_xTmp->GetMask() )
548 0 : m_nRet = m_xTmp->GetMask();
549 :
550 0 : if( SFX_STYLE_FAMILY_PARA == m_nFamily )
551 : {
552 0 : SfxItemSet aSet( *m_pDlg->GetOutputItemSet() );
553 0 : ::SfxToSwPageDescAttr( *pWrtShell, aSet );
554 : // reset indent attributes at paragraph style, if a list style
555 : // will be applied and no indent attributes will be applied.
556 0 : m_xTmp->SetItemSet( aSet, true );
557 : }
558 : else
559 : {
560 0 : if(SFX_STYLE_FAMILY_PAGE == m_nFamily)
561 : {
562 : static const sal_uInt16 aInval[] = {
563 : SID_IMAGE_ORIENTATION,
564 : SID_ATTR_CHAR_FONT,
565 : FN_INSERT_CTRL, FN_INSERT_OBJ_CTRL, 0};
566 0 : pView->GetViewFrame()->GetBindings().Invalidate(aInval);
567 : }
568 0 : SfxItemSet aTmpSet( *m_pDlg->GetOutputItemSet() );
569 0 : if( SFX_STYLE_FAMILY_CHAR == m_nFamily )
570 : {
571 : const SfxPoolItem *pTmpBrush;
572 0 : if( SFX_ITEM_SET == aTmpSet.GetItemState( RES_BACKGROUND,
573 0 : sal_False, &pTmpBrush ) )
574 : {
575 0 : SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
576 0 : aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
577 0 : aTmpSet.Put( aTmpBrush );
578 : }
579 0 : aTmpSet.ClearItem( RES_BACKGROUND );
580 : }
581 0 : m_xTmp->SetItemSet( aTmpSet );
582 :
583 0 : if( SFX_STYLE_FAMILY_PAGE == m_nFamily && SvtLanguageOptions().IsCTLFontEnabled() )
584 : {
585 0 : const SfxPoolItem *pItem = NULL;
586 0 : if( aTmpSet.GetItemState( m_rDocSh.GetPool().GetTrueWhich( SID_ATTR_FRAMEDIRECTION, sal_False ) , sal_True, &pItem ) == SFX_ITEM_SET )
587 0 : SwChartHelper::DoUpdateAllCharts( pDoc );
588 0 : }
589 : }
590 0 : if(SFX_STYLE_FAMILY_PAGE == m_nFamily)
591 0 : pView->InvalidateRulerPos();
592 :
593 0 : if( m_bNew )
594 0 : m_xBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *m_xTmp.get() ) );
595 :
596 0 : pDoc->SetModified();
597 0 : if( !m_bModified )
598 : {
599 0 : pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
600 : }
601 :
602 0 : pWrtShell->EndAllAction();
603 :
604 0 : return m_nRet;
605 : }
606 :
607 0 : sal_uInt16 SwDocShell::Edit(
608 : const String &rName,
609 : const String &rParent,
610 : const sal_uInt16 nFamily,
611 : sal_uInt16 nMask,
612 : const sal_Bool bNew,
613 : const sal_uInt16 nSlot,
614 : SwWrtShell* pActShell,
615 : const sal_Bool bBasic )
616 : {
617 : OSL_ENSURE(GetWrtShell(), "No Shell, no Styles");
618 0 : SfxStyleSheetBase *pStyle = 0;
619 :
620 0 : sal_uInt16 nRet = nMask;
621 0 : sal_Bool bModified = pDoc->IsModified();
622 :
623 0 : if( bNew )
624 : {
625 0 : if( SFXSTYLEBIT_ALL != nMask && SFXSTYLEBIT_USED != nMask )
626 0 : nMask |= SFXSTYLEBIT_USERDEF;
627 : else
628 0 : nMask = SFXSTYLEBIT_USERDEF;
629 :
630 0 : pStyle = &mxBasePool->Make( rName, (SfxStyleFamily)nFamily, nMask );
631 :
632 : // set the current one as Parent
633 0 : SwDocStyleSheet* pDStyle = (SwDocStyleSheet*)pStyle;
634 0 : switch( nFamily )
635 : {
636 : case SFX_STYLE_FAMILY_PARA:
637 : {
638 0 : if(rParent.Len())
639 : {
640 0 : SwTxtFmtColl* pColl = pWrtShell->FindTxtFmtCollByName( rParent );
641 0 : if(!pColl)
642 : {
643 0 : sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
644 0 : if(USHRT_MAX != nId)
645 0 : pColl = pWrtShell->GetTxtCollFromPool( nId );
646 : }
647 0 : pDStyle->GetCollection()->SetDerivedFrom( pColl );
648 0 : pDStyle->PresetParent( rParent );
649 :
650 : //#outline level,add by zhaojianwei
651 : /*When a new paragraph style is created based on a "to outline style
652 : assigned" paragraph style, the outline level attribute and the list
653 : style attribute of the new paragraph style have to be set to 0
654 : respectively "".*/
655 0 : if( pColl->IsAssignedToListLevelOfOutlineStyle())
656 : {
657 0 : SwNumRuleItem aItem(aEmptyStr);
658 0 : pDStyle->GetCollection()->SetFmtAttr( aItem );
659 0 : pDStyle->GetCollection()->SetAttrOutlineLevel( 0 );
660 : }
661 : //<-end,zhaojianwei
662 :
663 : }
664 : else
665 : {
666 0 : SwTxtFmtColl* pColl = pWrtShell->GetCurTxtFmtColl();
667 0 : pDStyle->GetCollection()->SetDerivedFrom( pColl );
668 0 : if( pColl )
669 0 : pDStyle->PresetParent( pColl->GetName() );
670 : }
671 : }
672 0 : break;
673 : case SFX_STYLE_FAMILY_CHAR:
674 : {
675 0 : if(rParent.Len())
676 : {
677 0 : SwCharFmt* pCFmt = pWrtShell->FindCharFmtByName( rParent );
678 0 : if(!pCFmt)
679 : {
680 0 : sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
681 0 : if(USHRT_MAX != nId)
682 0 : pCFmt = pWrtShell->GetCharFmtFromPool( nId );
683 : }
684 :
685 0 : pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt );
686 0 : pDStyle->PresetParent( rParent );
687 : }
688 : else
689 : {
690 0 : SwCharFmt* pCFmt = pWrtShell->GetCurCharFmt();
691 0 : pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt );
692 0 : if( pCFmt )
693 0 : pDStyle->PresetParent( pCFmt->GetName() );
694 : }
695 : }
696 0 : break;
697 : case SFX_STYLE_FAMILY_FRAME :
698 : {
699 0 : if(rParent.Len())
700 : {
701 0 : SwFrmFmt* pFFmt = pWrtShell->GetDoc()->FindFrmFmtByName( rParent );
702 0 : if(!pFFmt)
703 : {
704 0 : sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT);
705 0 : if(USHRT_MAX != nId)
706 0 : pFFmt = pWrtShell->GetFrmFmtFromPool( nId );
707 : }
708 0 : pDStyle->GetFrmFmt()->SetDerivedFrom( pFFmt );
709 0 : pDStyle->PresetParent( rParent );
710 : }
711 : }
712 0 : break;
713 : }
714 : }
715 : else
716 : {
717 0 : pStyle = mxBasePool->Find( rName, (SfxStyleFamily)nFamily );
718 : OSL_ENSURE(pStyle, "Vorlage nicht gefunden");
719 : }
720 :
721 0 : if(!pStyle)
722 0 : return sal_False;
723 :
724 : // put dialogues together
725 0 : rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
726 0 : if( SFX_STYLE_FAMILY_PARA == nFamily )
727 : {
728 0 : SfxItemSet& rSet = xTmp->GetItemSet();
729 0 : ::SwToSfxPageDescAttr( rSet );
730 : // firstly only a Zero
731 0 : rSet.Put(SwBackgroundDestinationItem(SID_PARA_BACKGRND_DESTINATION, 0));
732 : // merge list level indent attributes into the item set if needed
733 0 : xTmp->MergeIndentAttrsOfListStyle( rSet );
734 : }
735 0 : else if( SFX_STYLE_FAMILY_CHAR == nFamily )
736 : {
737 0 : SfxItemSet& rSet = xTmp->GetItemSet();
738 : const SfxPoolItem *pTmpBrush;
739 0 : if( SFX_ITEM_SET == rSet.GetItemState( RES_CHRATR_BACKGROUND,
740 0 : sal_True, &pTmpBrush ) )
741 : {
742 0 : SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
743 0 : aTmpBrush.SetWhich( RES_BACKGROUND );
744 0 : rSet.Put( aTmpBrush );
745 : }
746 : }
747 0 : if (!bBasic)
748 : {
749 : // prior to the dialog the HtmlMode at the DocShell is being sunk
750 0 : sal_uInt16 nHtmlMode = ::GetHtmlMode(this);
751 :
752 : // In HTML mode, we do not always have a printer. In order to show
753 : // the correct page size in the Format - Page dialog, we have to
754 : // get one here.
755 0 : SwWrtShell* pCurrShell = ( pActShell ? pActShell : pWrtShell );
756 0 : if( ( HTMLMODE_ON & nHtmlMode ) &&
757 0 : !pCurrShell->getIDocumentDeviceAccess()->getPrinter( false ) )
758 0 : pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess()->getPrinter( true ) );
759 :
760 0 : PutItem(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
761 0 : FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode));
762 0 : SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
763 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
764 : OSL_ENSURE(pFact, "Dialogdiet fail!");
765 : SfxAbstractApplyTabDialog* pDlg = pFact->CreateTemplateDialog(
766 0 : 0, *(xTmp.get()), nFamily, nSlot,
767 0 : pActShell ? pActShell : pWrtShell, bNew);
768 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
769 0 : ApplyStyle aApplyStyleHelper(*this, bNew, pStyle, nRet, xTmp, nFamily, pDlg, mxBasePool, bModified);
770 0 : pDlg->SetApplyHdl(LINK(&aApplyStyleHelper, ApplyStyle, ApplyHdl));
771 :
772 0 : if (RET_OK == pDlg->Execute())
773 : {
774 0 : aApplyStyleHelper.apply();
775 : }
776 : else
777 : {
778 0 : if( bNew )
779 : {
780 0 : GetWrtShell()->Undo(1);
781 0 : pDoc->GetIDocumentUndoRedo().ClearRedo();
782 : }
783 :
784 0 : if( !bModified )
785 0 : pDoc->ResetModified();
786 : }
787 :
788 0 : nRet = aApplyStyleHelper.getRet();
789 :
790 0 : delete pDlg;
791 : }
792 : else
793 : {
794 : // prior to the dialog the HtmlMode at the DocShell is being sunk
795 0 : PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
796 :
797 0 : GetWrtShell()->StartAllAction();
798 :
799 : // newly set the mask only with paragraph-templates
800 0 : if( bNew )
801 : {
802 0 : nRet = SFX_STYLE_FAMILY_PARA == pStyle->GetFamily()
803 0 : ? xTmp->GetMask()
804 0 : : SFXSTYLEBIT_USERDEF;
805 : }
806 0 : else if( pStyle->GetMask() != xTmp->GetMask() )
807 0 : nRet = xTmp->GetMask();
808 :
809 0 : if( SFX_STYLE_FAMILY_PARA == nFamily )
810 0 : ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp->GetItemSet() );
811 : else
812 : {
813 0 : SfxItemSet aTmpSet( xTmp->GetItemSet() );
814 0 : if( SFX_STYLE_FAMILY_CHAR == nFamily )
815 : {
816 : const SfxPoolItem *pTmpBrush;
817 0 : if( SFX_ITEM_SET == aTmpSet.GetItemState( RES_BACKGROUND,
818 0 : sal_False, &pTmpBrush ) )
819 : {
820 0 : SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
821 0 : aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
822 0 : aTmpSet.Put( aTmpBrush );
823 : }
824 0 : aTmpSet.ClearItem( RES_BACKGROUND );
825 : }
826 0 : xTmp->SetItemSet( aTmpSet );
827 : }
828 0 : if(SFX_STYLE_FAMILY_PAGE == nFamily)
829 0 : pView->InvalidateRulerPos();
830 :
831 0 : if( bNew )
832 0 : mxBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xTmp.get() ) );
833 :
834 0 : pDoc->SetModified();
835 0 : if( !bModified ) // Bug 57028
836 : {
837 0 : pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
838 : }
839 0 : GetWrtShell()->EndAllAction();
840 : }
841 :
842 0 : return nRet;
843 : }
844 :
845 : // Delete
846 0 : sal_uInt16 SwDocShell::Delete(const String &rName, sal_uInt16 nFamily)
847 : {
848 0 : SfxStyleSheetBase *pStyle = mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
849 :
850 0 : if(pStyle)
851 : {
852 : OSL_ENSURE(GetWrtShell(), "No Shell, no Styles");
853 :
854 0 : GetWrtShell()->StartAllAction();
855 0 : mxBasePool->Remove(pStyle);
856 0 : GetWrtShell()->EndAllAction();
857 :
858 0 : return sal_True;
859 : }
860 0 : return sal_False;
861 : }
862 :
863 0 : sal_uInt16 SwDocShell::Hide(const String &rName, sal_uInt16 nFamily, bool bHidden)
864 : {
865 0 : SfxStyleSheetBase *pStyle = mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
866 :
867 0 : if(pStyle)
868 : {
869 : OSL_ENSURE(GetWrtShell(), "No Shell, no Styles");
870 :
871 0 : GetWrtShell()->StartAllAction();
872 0 : rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
873 0 : xTmp->SetHidden( bHidden );
874 0 : GetWrtShell()->EndAllAction();
875 :
876 0 : return sal_True;
877 : }
878 0 : return sal_False;
879 : }
880 :
881 : // apply template
882 0 : sal_uInt16 SwDocShell::ApplyStyles(const String &rName, sal_uInt16 nFamily,
883 : SwWrtShell* pShell, sal_uInt16 nMode )
884 : {
885 : SwDocStyleSheet* pStyle =
886 0 : (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
887 :
888 : OSL_ENSURE(pStyle, "Where's the StyleSheet");
889 :
890 0 : if(!pStyle)
891 0 : return sal_False;
892 :
893 0 : SwWrtShell *pSh = pShell ? pShell : GetWrtShell();
894 :
895 : OSL_ENSURE( pSh, "No Shell, no Styles");
896 :
897 0 : pSh->StartAllAction();
898 :
899 0 : switch(nFamily)
900 : {
901 : case SFX_STYLE_FAMILY_CHAR:
902 : {
903 0 : SwFmtCharFmt aFmt(pStyle->GetCharFmt());
904 0 : pSh->SetAttr( aFmt, (nMode & KEY_SHIFT) ?
905 0 : nsSetAttrMode::SETATTR_DONTREPLACE : nsSetAttrMode::SETATTR_DEFAULT );
906 0 : break;
907 : }
908 : case SFX_STYLE_FAMILY_PARA:
909 : {
910 : // #i62675#
911 : // clear also list attributes at affected text nodes, if paragraph
912 : // style has the list style attribute set.
913 0 : pSh->SetTxtFmtColl( pStyle->GetCollection(), true );
914 0 : break;
915 : }
916 : case SFX_STYLE_FAMILY_FRAME:
917 : {
918 0 : if ( pSh->IsFrmSelected() )
919 0 : pSh->SetFrmFmt( pStyle->GetFrmFmt() );
920 0 : break;
921 : }
922 : case SFX_STYLE_FAMILY_PAGE:
923 : {
924 0 : pSh->SetPageStyle(pStyle->GetPageDesc()->GetName());
925 0 : break;
926 : }
927 : case SFX_STYLE_FAMILY_PSEUDO:
928 : {
929 : // reset indent attribute on applying list style
930 : // continue list of list style
931 0 : const SwNumRule* pNumRule = pStyle->GetNumRule();
932 0 : const String sListIdForStyle =pNumRule->GetDefaultListId();
933 0 : pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true );
934 0 : break;
935 : }
936 : default:
937 : OSL_FAIL("Unknown family");
938 : }
939 0 : pSh->EndAllAction();
940 :
941 0 : return nFamily;
942 : }
943 :
944 : // start watering-can
945 0 : sal_uInt16 SwDocShell::DoWaterCan(const String &rName, sal_uInt16 nFamily)
946 : {
947 : OSL_ENSURE(GetWrtShell(), "No Shell, no Styles");
948 :
949 0 : SwEditWin& rEdtWin = pView->GetEditWin();
950 0 : SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
951 0 : bool bWaterCan = !(pApply && pApply->eType != 0);
952 :
953 0 : if( !rName.Len() )
954 0 : bWaterCan = false;
955 :
956 0 : SwApplyTemplate aTemplate;
957 0 : aTemplate.eType = nFamily;
958 :
959 0 : if(bWaterCan)
960 : {
961 : SwDocStyleSheet* pStyle =
962 0 : (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
963 :
964 : OSL_ENSURE (pStyle, "Where's the StyleSheet");
965 :
966 0 : if(!pStyle) return nFamily;
967 :
968 0 : switch(nFamily)
969 : {
970 : case SFX_STYLE_FAMILY_CHAR:
971 0 : aTemplate.aColl.pCharFmt = pStyle->GetCharFmt();
972 0 : break;
973 : case SFX_STYLE_FAMILY_PARA:
974 0 : aTemplate.aColl.pTxtColl = pStyle->GetCollection();
975 0 : break;
976 : case SFX_STYLE_FAMILY_FRAME:
977 0 : aTemplate.aColl.pFrmFmt = pStyle->GetFrmFmt();
978 0 : break;
979 : case SFX_STYLE_FAMILY_PAGE:
980 0 : aTemplate.aColl.pPageDesc = (SwPageDesc*)pStyle->GetPageDesc();
981 0 : break;
982 : case SFX_STYLE_FAMILY_PSEUDO:
983 0 : aTemplate.aColl.pNumRule = (SwNumRule*)pStyle->GetNumRule();
984 0 : break;
985 :
986 : default:
987 : OSL_FAIL("Unknown family");
988 : }
989 : }
990 : else
991 0 : aTemplate.eType = 0;
992 :
993 0 : pView->GetEditWin().SetApplyTemplate(aTemplate);
994 :
995 0 : return nFamily;
996 : }
997 :
998 : // update template
999 0 : sal_uInt16 SwDocShell::UpdateStyle(const String &rName, sal_uInt16 nFamily, SwWrtShell* pShell)
1000 : {
1001 0 : SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1002 : OSL_ENSURE(GetWrtShell(), "No Shell, no Styles");
1003 :
1004 : SwDocStyleSheet* pStyle =
1005 0 : (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily);
1006 :
1007 0 : if(!pStyle)
1008 0 : return nFamily;
1009 :
1010 0 : switch(nFamily)
1011 : {
1012 : case SFX_STYLE_FAMILY_PARA:
1013 : {
1014 0 : SwTxtFmtColl* pColl = pStyle->GetCollection();
1015 0 : if(pColl && !pColl->IsDefault())
1016 : {
1017 0 : GetWrtShell()->StartAllAction();
1018 :
1019 0 : SwRewriter aRewriter;
1020 0 : aRewriter.AddRule(UndoArg1, pColl->GetName());
1021 :
1022 0 : GetWrtShell()->StartUndo(UNDO_INSFMTATTR, &aRewriter);
1023 0 : GetWrtShell()->FillByEx(pColl);
1024 : // also apply template to remove hard set attributes
1025 0 : GetWrtShell()->SetTxtFmtColl( pColl );
1026 0 : GetWrtShell()->EndUndo();
1027 0 : GetWrtShell()->EndAllAction();
1028 : }
1029 0 : break;
1030 : }
1031 : case SFX_STYLE_FAMILY_FRAME:
1032 : {
1033 0 : SwFrmFmt* pFrm = pStyle->GetFrmFmt();
1034 0 : if( pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault() )
1035 : {
1036 0 : SfxItemSet aSet( GetPool(), aFrmFmtSetRange );
1037 0 : pCurrWrtShell->StartAllAction();
1038 0 : pCurrWrtShell->GetFlyFrmAttr( aSet );
1039 :
1040 : // #i105535#
1041 : // no update of anchor attribute
1042 0 : aSet.ClearItem( RES_ANCHOR );
1043 :
1044 0 : pFrm->SetFmtAttr( aSet );
1045 :
1046 : // also apply template to remove hard set attributes
1047 0 : pCurrWrtShell->SetFrmFmt( pFrm, true );
1048 0 : pCurrWrtShell->EndAllAction();
1049 : }
1050 : }
1051 0 : break;
1052 : case SFX_STYLE_FAMILY_CHAR:
1053 : {
1054 0 : SwCharFmt* pChar = pStyle->GetCharFmt();
1055 0 : if( pChar && !pChar->IsDefault() )
1056 : {
1057 0 : pCurrWrtShell->StartAllAction();
1058 0 : pCurrWrtShell->FillByEx(pChar);
1059 : // also apply template to remove hard set attributes
1060 0 : pCurrWrtShell->EndAllAction();
1061 : }
1062 :
1063 : }
1064 0 : break;
1065 : case SFX_STYLE_FAMILY_PSEUDO:
1066 : {
1067 : const SwNumRule* pCurRule;
1068 0 : if( pStyle->GetNumRule() &&
1069 0 : 0 != ( pCurRule = pCurrWrtShell->GetCurNumRule() ))
1070 : {
1071 0 : SwNumRule aRule( *pCurRule );
1072 : // #i91400#
1073 0 : aRule.SetName( pStyle->GetNumRule()->GetName(),
1074 0 : *(pCurrWrtShell->GetDoc()) );
1075 0 : pCurrWrtShell->ChgNumRuleFmts( aRule );
1076 : }
1077 : }
1078 0 : break;
1079 : }
1080 0 : return nFamily;
1081 : }
1082 :
1083 : // NewByExample
1084 0 : sal_uInt16 SwDocShell::MakeByExample( const String &rName, sal_uInt16 nFamily,
1085 : sal_uInt16 nMask, SwWrtShell* pShell )
1086 : {
1087 0 : SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1088 0 : SwDocStyleSheet* pStyle = (SwDocStyleSheet*)mxBasePool->Find(
1089 0 : rName, (SfxStyleFamily)nFamily );
1090 0 : if(!pStyle)
1091 : {
1092 : // preserve the current mask of PI, then the new one is
1093 : // immediately merged with the viewable area
1094 0 : if( SFXSTYLEBIT_ALL == nMask || SFXSTYLEBIT_USED == nMask )
1095 0 : nMask = SFXSTYLEBIT_USERDEF;
1096 : else
1097 0 : nMask |= SFXSTYLEBIT_USERDEF;
1098 :
1099 0 : pStyle = (SwDocStyleSheet*)&mxBasePool->Make(rName,
1100 0 : (SfxStyleFamily)nFamily, nMask );
1101 : }
1102 :
1103 0 : switch(nFamily)
1104 : {
1105 : case SFX_STYLE_FAMILY_PARA:
1106 : {
1107 0 : SwTxtFmtColl* pColl = pStyle->GetCollection();
1108 0 : if(pColl && !pColl->IsDefault())
1109 : {
1110 0 : pCurrWrtShell->StartAllAction();
1111 0 : pCurrWrtShell->FillByEx(pColl);
1112 : // also apply template to remove hard set attributes
1113 0 : pColl->SetDerivedFrom(pCurrWrtShell->GetCurTxtFmtColl());
1114 :
1115 : // set the mask at the Collection:
1116 0 : sal_uInt16 nId = pColl->GetPoolFmtId() & 0x87ff;
1117 0 : switch( nMask & 0x0fff )
1118 : {
1119 : case SWSTYLEBIT_TEXT:
1120 0 : nId |= COLL_TEXT_BITS;
1121 0 : break;
1122 : case SWSTYLEBIT_CHAPTER:
1123 0 : nId |= COLL_DOC_BITS;
1124 0 : break;
1125 : case SWSTYLEBIT_LIST:
1126 0 : nId |= COLL_LISTS_BITS;
1127 0 : break;
1128 : case SWSTYLEBIT_IDX:
1129 0 : nId |= COLL_REGISTER_BITS;
1130 0 : break;
1131 : case SWSTYLEBIT_EXTRA:
1132 0 : nId |= COLL_EXTRA_BITS;
1133 0 : break;
1134 : case SWSTYLEBIT_HTML:
1135 0 : nId |= COLL_HTML_BITS;
1136 0 : break;
1137 : }
1138 0 : pColl->SetPoolFmtId(nId);
1139 :
1140 0 : pCurrWrtShell->SetTxtFmtColl(pColl);
1141 0 : pCurrWrtShell->EndAllAction();
1142 : }
1143 : }
1144 0 : break;
1145 : case SFX_STYLE_FAMILY_FRAME:
1146 : {
1147 0 : SwFrmFmt* pFrm = pStyle->GetFrmFmt();
1148 0 : if(pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault())
1149 : {
1150 0 : pCurrWrtShell->StartAllAction();
1151 :
1152 0 : SfxItemSet aSet(GetPool(), aFrmFmtSetRange );
1153 0 : pCurrWrtShell->GetFlyFrmAttr( aSet );
1154 :
1155 0 : SwFrmFmt* pFFmt = pCurrWrtShell->GetCurFrmFmt();
1156 0 : pFrm->SetDerivedFrom( pFFmt );
1157 :
1158 0 : pFrm->SetFmtAttr( aSet );
1159 : // also apply template to remove hard set attributes
1160 0 : pCurrWrtShell->SetFrmFmt( pFrm );
1161 0 : pCurrWrtShell->EndAllAction();
1162 : }
1163 : }
1164 0 : break;
1165 : case SFX_STYLE_FAMILY_CHAR:
1166 : {
1167 0 : SwCharFmt* pChar = pStyle->GetCharFmt();
1168 0 : if(pChar && !pChar->IsDefault())
1169 : {
1170 0 : pCurrWrtShell->StartAllAction();
1171 0 : pCurrWrtShell->FillByEx( pChar );
1172 0 : pChar->SetDerivedFrom( pCurrWrtShell->GetCurCharFmt() );
1173 0 : SwFmtCharFmt aFmt( pChar );
1174 0 : pCurrWrtShell->SetAttr( aFmt );
1175 0 : pCurrWrtShell->EndAllAction();
1176 : }
1177 : }
1178 0 : break;
1179 :
1180 : case SFX_STYLE_FAMILY_PAGE:
1181 : {
1182 0 : pCurrWrtShell->StartAllAction();
1183 0 : sal_uInt16 nPgDsc = pCurrWrtShell->GetCurPageDesc();
1184 0 : SwPageDesc& rSrc = (SwPageDesc&)pCurrWrtShell->GetPageDesc( nPgDsc );
1185 0 : SwPageDesc& rDest = *(SwPageDesc*)pStyle->GetPageDesc();
1186 :
1187 0 : sal_uInt16 nPoolId = rDest.GetPoolFmtId();
1188 0 : sal_uInt16 nHId = rDest.GetPoolHelpId();
1189 0 : sal_uInt8 nHFId = rDest.GetPoolHlpFileId();
1190 :
1191 0 : pCurrWrtShell->GetDoc()->CopyPageDesc( rSrc, rDest );
1192 :
1193 : // PoolId must NEVER be copied!
1194 0 : rDest.SetPoolFmtId( nPoolId );
1195 0 : rDest.SetPoolHelpId( nHId );
1196 0 : rDest.SetPoolHlpFileId( nHFId );
1197 :
1198 : // when Headers/Footers are created, there is no Undo anymore!
1199 0 : pCurrWrtShell->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
1200 :
1201 0 : pCurrWrtShell->EndAllAction();
1202 : }
1203 0 : break;
1204 :
1205 : case SFX_STYLE_FAMILY_PSEUDO:
1206 : {
1207 0 : pCurrWrtShell->StartAllAction();
1208 :
1209 0 : SwNumRule aRule( *pCurrWrtShell->GetCurNumRule() );
1210 0 : String sOrigRule( aRule.GetName() );
1211 : // #i91400#
1212 0 : aRule.SetName( pStyle->GetNumRule()->GetName(),
1213 0 : *(pCurrWrtShell->GetDoc()) );
1214 0 : pCurrWrtShell->ChgNumRuleFmts( aRule );
1215 :
1216 0 : pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() );
1217 :
1218 :
1219 0 : pCurrWrtShell->EndAllAction();
1220 : }
1221 0 : break;
1222 : }
1223 0 : return nFamily;
1224 : }
1225 :
1226 0 : void SwDocShell::LoadStyles( SfxObjectShell& rSource )
1227 : {
1228 0 : _LoadStyles(rSource, sal_False);
1229 0 : }
1230 : /* --------------------------------------------------
1231 : bPreserveCurrentDocument determines whether SetFixFields() is called
1232 : This call modifies the source document. This mustn't happen when the source
1233 : is a document the user is working on.
1234 : Calls of ::LoadStyles() normally use files especially loaded for the purpose
1235 : of importing styles.
1236 : --------------------------------------------------*/
1237 0 : void SwDocShell::_LoadStyles( SfxObjectShell& rSource, sal_Bool bPreserveCurrentDocument )
1238 : {
1239 : /* [Description]
1240 :
1241 : This method is called by SFx if Styles have to be reloaded from a
1242 : document-template. Existing Styles should be overwritten by that.
1243 : That's why the document has to be reformatted. Therefore applications
1244 : will usually overload this method and call the baseclass' implementation
1245 : in their implementation.
1246 : */
1247 : // When the source is our document, we do the checking ourselves
1248 : // (much quicker and doesn't use the crutch StxStylePool).
1249 0 : if( rSource.ISA( SwDocShell ))
1250 : {
1251 : // in order for the Headers/Footers not to get the fixed content
1252 : // of the template, update all the Source's
1253 : // FixFields once.
1254 0 : if(!bPreserveCurrentDocument)
1255 0 : ((SwDocShell&)rSource).pDoc->SetFixFields(false, NULL);
1256 0 : if( pWrtShell )
1257 : {
1258 : // rhbz#818557, fdo#58893: EndAllAction will call SelectShell(),
1259 : // which pushes a bunch of SfxShells that are not cleared
1260 : // (for unknown reasons) when closing the document, causing crash;
1261 : // setting bNoInterrupt appears to avoid the problem.
1262 0 : ::comphelper::FlagRestorationGuard g(bNoInterrupt, true);
1263 0 : pWrtShell->StartAllAction();
1264 0 : pDoc->ReplaceStyles( *((SwDocShell&)rSource).pDoc );
1265 0 : pWrtShell->EndAllAction();
1266 : }
1267 : else
1268 : {
1269 0 : sal_Bool bModified = pDoc->IsModified();
1270 0 : pDoc->ReplaceStyles( *((SwDocShell&)rSource).pDoc );
1271 0 : if( !bModified && pDoc->IsModified() && !pView )
1272 : {
1273 : // the View is created later, but overwrites the Modify-Flag.
1274 : // Undo doesn't work anymore anyways.
1275 0 : pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1276 : }
1277 : }
1278 : }
1279 : else
1280 0 : SfxObjectShell::LoadStyles( rSource );
1281 0 : }
1282 :
1283 :
1284 0 : void SwDocShell::FormatPage(
1285 : const String& rPage,
1286 : const sal_uInt16 nSlot,
1287 : SwWrtShell& rActShell )
1288 : {
1289 0 : Edit( rPage, aEmptyStr, SFX_STYLE_FAMILY_PAGE, 0, sal_False, nSlot, &rActShell);
1290 0 : }
1291 :
1292 0 : Bitmap SwDocShell::GetStyleFamilyBitmap( SfxStyleFamily eFamily )
1293 : {
1294 0 : if( SFX_STYLE_FAMILY_PSEUDO == eFamily )
1295 0 : return Bitmap( SW_RES( BMP_STYLES_FAMILY_NUM ));
1296 0 : return SfxObjectShell::GetStyleFamilyBitmap( eFamily );
1297 99 : }
1298 :
1299 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|