Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / styleui / styledlg.cxx
blob1b738d35420781fae9e3068ac4118ecaf96c6048
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #undef SC_DLLIMPLEMENTATION
25 //------------------------------------------------------------------
27 #include "scitems.hxx"
28 #include <svx/numinf.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <svl/style.hxx>
31 #include <svl/cjkoptions.hxx>
33 #include "styledlg.hxx"
34 #include "tabpages.hxx"
35 #include "tphf.hxx"
36 #include "tptable.hxx"
37 #include "scresid.hxx"
38 #include "sc.hrc"
39 #include <svx/svxdlg.hxx>
40 #include <svx/svxids.hrc>
41 #include <svx/dialogs.hrc>
42 #include <svl/intitem.hxx>
43 #include <editeng/flstitem.hxx>
44 #include <svl/aeitem.hxx>
45 #include <svx/flagsdef.hxx>
46 //==================================================================
48 ScStyleDlg::ScStyleDlg( Window* pParent,
49 SfxStyleSheetBase& rStyleBase,
50 sal_uInt16 nRscId )
52 : SfxStyleDialog ( pParent,
53 nRscId == RID_SCDLG_STYLES_PAR ?
54 OString("ParaTemplateDialog") :
55 OString("PageTemplateDialog"),
56 nRscId == RID_SCDLG_STYLES_PAR ?
57 OUString("modules/scalc/ui/paratemplatedialog.ui") :
58 OUString("modules/scalc/ui/pagetemplatedialog.ui"),
59 rStyleBase )
60 , nDlgRsc ( nRscId )
61 , m_nNumberId(0)
62 , m_nFontId(0)
63 , m_nFontEffectId(0)
64 , m_nAlignmentId(0)
65 , m_nAsianId(0)
66 , m_nBorderId(0)
67 , m_nBackgroundId(0)
68 , m_nProtectId(0)
69 , m_nPageId(0)
70 , m_nHeaderId(0)
71 , m_nFooterId(0)
72 , m_nSheetId(0)
74 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
75 OSL_ENSURE(pFact, "Dialogdiet fail!");
76 switch ( nRscId )
78 case RID_SCDLG_STYLES_PAR: // Zellformatvorlagen
80 SvtCJKOptions aCJKOptions;
81 OSL_ENSURE(pFact->GetTabPageCreatorFunc( RID_SVXPAGE_NUMBERFORMAT ), "GetTabPageCreatorFunc fail!");
82 OSL_ENSURE(pFact->GetTabPageRangesFunc( RID_SVXPAGE_NUMBERFORMAT ), "GetTabPageRangesFunc fail!");
83 m_nNumberId = AddTabPage("numbers", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_NUMBERFORMAT ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_NUMBERFORMAT ));
84 OSL_ENSURE(pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_NAME ), "GetTabPageCreatorFunc fail!");
85 OSL_ENSURE(pFact->GetTabPageRangesFunc( RID_SVXPAGE_CHAR_NAME ), "GetTabPageRangesFunc fail!");
86 m_nFontId = AddTabPage("font", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_NAME ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_CHAR_NAME ));
87 OSL_ENSURE(pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_EFFECTS ), "GetTabPageCreatorFunc fail!");
88 OSL_ENSURE(pFact->GetTabPageRangesFunc( RID_SVXPAGE_CHAR_EFFECTS ), "GetTabPageRangesFunc fail!");
89 m_nFontEffectId = AddTabPage("fonteffects", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_EFFECTS ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_CHAR_EFFECTS ));
90 OSL_ENSURE(pFact->GetTabPageCreatorFunc( RID_SVXPAGE_ALIGNMENT ), "GetTabPageCreatorFunc fail!");
91 OSL_ENSURE( pFact->GetTabPageRangesFunc( RID_SVXPAGE_ALIGNMENT ), "GetTabPageRangesFunc fail!");
92 m_nAlignmentId = AddTabPage("alignment", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_ALIGNMENT ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_ALIGNMENT ));
93 if ( aCJKOptions.IsAsianTypographyEnabled() )
95 OSL_ENSURE(pFact->GetTabPageCreatorFunc(RID_SVXPAGE_PARA_ASIAN), "GetTabPageCreatorFunc fail!");
96 OSL_ENSURE(pFact->GetTabPageRangesFunc(RID_SVXPAGE_PARA_ASIAN), "GetTabPageRangesFunc fail!");
97 m_nAsianId = AddTabPage("asiantypo", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_PARA_ASIAN), pFact->GetTabPageRangesFunc(RID_SVXPAGE_PARA_ASIAN));
99 else
100 RemoveTabPage("asiantypo");
101 OSL_ENSURE(pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), "GetTabPageCreatorFunc fail!");
102 OSL_ENSURE(pFact->GetTabPageRangesFunc( RID_SVXPAGE_BORDER ), "GetTabPageRangesFunc fail!");
103 m_nBorderId = AddTabPage("borders", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_BORDER ));
104 OSL_ENSURE(pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), "GetTabPageCreatorFunc fail!");
105 OSL_ENSURE(pFact->GetTabPageRangesFunc( RID_SVXPAGE_BACKGROUND ), "GetTabPageRangesFunc fail!");
106 m_nBackgroundId = AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_BACKGROUND ));
107 m_nProtectId = AddTabPage("protection", &ScTabPageProtection::Create, &ScTabPageProtection::GetRanges);
109 break;
111 case RID_SCDLG_STYLES_PAGE: // Seitenvorlagen
113 OSL_ENSURE(pFact->GetTabPageCreatorFunc( RID_SVXPAGE_PAGE ), "GetTabPageCreatorFunc fail!");
114 OSL_ENSURE(pFact->GetTabPageRangesFunc( RID_SVXPAGE_PAGE ), "GetTabPageRangesFunc fail!");
115 m_nPageId = AddTabPage("page", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_PAGE ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_PAGE ) );
116 OSL_ENSURE(pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), "GetTabPageCreatorFunc fail!");
117 OSL_ENSURE(pFact->GetTabPageRangesFunc( RID_SVXPAGE_BORDER ), "GetTabPageRangesFunc fail!");
118 m_nBorderId = AddTabPage("borders", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_BORDER ) );
119 OSL_ENSURE(pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), "GetTabPageCreatorFunc fail!");
120 OSL_ENSURE(pFact->GetTabPageRangesFunc( RID_SVXPAGE_BACKGROUND ), "GetTabPageRangesFunc fail!");
121 m_nBackgroundId = AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_BACKGROUND ) );
122 m_nHeaderId = AddTabPage("header", &ScHeaderPage::Create, &ScHeaderPage::GetRanges );
123 m_nFooterId = AddTabPage("footer", &ScFooterPage::Create, &ScFooterPage::GetRanges );
124 m_nSheetId = AddTabPage("sheet", &ScTablePage::Create, &ScTablePage::GetRanges );
126 break;
128 default:
129 OSL_FAIL( "Family not supported" );
133 // -----------------------------------------------------------------------
135 void ScStyleDlg::PageCreated( sal_uInt16 nPageId, SfxTabPage& rTabPage )
137 if ( nDlgRsc == RID_SCDLG_STYLES_PAR )
139 SfxObjectShell* pDocSh = SfxObjectShell::Current();
140 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
141 if (nPageId == m_nNumberId)
143 const SfxPoolItem* pInfoItem
144 = pDocSh->GetItem( SID_ATTR_NUMBERFORMAT_INFO );
146 OSL_ENSURE( pInfoItem, "NumberInfoItem nicht gefunden!" );
148 aSet.Put (SvxNumberInfoItem( (const SvxNumberInfoItem&)*pInfoItem ) );
149 rTabPage.PageCreated(aSet);
151 else if (nPageId == m_nFontId)
153 const SfxPoolItem* pInfoItem
154 = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
156 OSL_ENSURE( pInfoItem, "FontListItem nicht gefunden!" );
158 aSet.Put (SvxFontListItem(((const SvxFontListItem&)*pInfoItem).GetFontList(), SID_ATTR_CHAR_FONTLIST));
159 rTabPage.PageCreated(aSet);
162 else if ( nDlgRsc == RID_SCDLG_STYLES_PAGE )
164 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
165 if (nPageId == m_nPageId)
167 aSet.Put (SfxAllEnumItem((const sal_uInt16)SID_ENUM_PAGE_MODE, SVX_PAGE_MODE_CENTER));
168 rTabPage.PageCreated(aSet);
170 else if (nPageId == m_nHeaderId || nPageId == m_nFooterId)
172 ((ScHFPage&)rTabPage).SetStyleDlg( this );
173 ((ScHFPage&)rTabPage).SetPageStyle( GetStyleSheet().GetName() );
174 ((ScHFPage&)rTabPage).DisableDeleteQueryBox();
176 else if (nPageId == m_nBackgroundId)
178 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, SVX_SHOW_SELECTOR));
179 rTabPage.PageCreated(aSet);
185 // -----------------------------------------------------------------------
187 const SfxItemSet* ScStyleDlg::GetRefreshedSet()
189 SfxItemSet* pItemSet = GetInputSetImpl();
190 pItemSet->ClearItem();
191 pItemSet->SetParent( GetStyleSheet().GetItemSet().GetParent() );
192 return pItemSet;
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */