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