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 #undef SC_DLLIMPLEMENTATION
21 
22 #include <svx/numinf.hxx>
23 #include <sfx2/objsh.hxx>
24 #include <sfx2/sfxdlg.hxx>
25 #include <svl/style.hxx>
26 #include <svl/cjkoptions.hxx>
27 #include <osl/diagnose.h>
28 
29 #include <styledlg.hxx>
30 #include <tabpages.hxx>
31 #include <tphf.hxx>
32 #include <tptable.hxx>
33 #include <svx/svxids.hrc>
34 #include <svx/dialogs.hrc>
35 #include <svl/intitem.hxx>
36 #include <editeng/flstitem.hxx>
37 #include <svx/flagsdef.hxx>
38 
ScStyleDlg(weld::Window * pParent,SfxStyleSheetBase & rStyleBase,bool bPage)39 ScStyleDlg::ScStyleDlg(weld::Window* pParent,
40                        SfxStyleSheetBase& rStyleBase,
41                        bool bPage)
42     : SfxStyleDialogController(pParent,
43                         bPage ?
44                           OUString("modules/scalc/ui/pagetemplatedialog.ui") :
45                           OUString("modules/scalc/ui/paratemplatedialog.ui"),
46                         bPage ?
47                           OString("PageTemplateDialog") :
48                           OString("ParaTemplateDialog"),
49                         rStyleBase )
50     , m_bPage(bPage)
51 {
52     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
53     if (m_bPage) // page styles
54     {
55         AddTabPage("page", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_PAGE ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_PAGE ) );
56         AddTabPage("borders", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_BORDER ) );
57         AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BKG ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_BKG ) );
58         AddTabPage("header", &ScHeaderPage::Create,      &ScHeaderPage::GetRanges );
59         AddTabPage("footer", &ScFooterPage::Create,      &ScFooterPage::GetRanges );
60         AddTabPage("sheet", &ScTablePage::Create,     &ScTablePage::GetRanges );
61     }
62     else // cell format styles
63     {
64         SvtCJKOptions aCJKOptions;
65         AddTabPage("numbers", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_NUMBERFORMAT ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_NUMBERFORMAT ));
66         AddTabPage("font", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_NAME ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_CHAR_NAME ));
67         AddTabPage("fonteffects", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_EFFECTS ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_CHAR_EFFECTS ));
68         AddTabPage("alignment", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_ALIGNMENT ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_ALIGNMENT ));
69         if ( aCJKOptions.IsAsianTypographyEnabled() )
70         {
71             AddTabPage("asiantypo", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_PARA_ASIAN),       pFact->GetTabPageRangesFunc(RID_SVXPAGE_PARA_ASIAN));
72         }
73         else
74             RemoveTabPage("asiantypo");
75         AddTabPage("borders", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_BORDER ));
76         AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BKG ), pFact->GetTabPageRangesFunc( RID_SVXPAGE_BKG ));
77         AddTabPage("protection", &ScTabPageProtection::Create,    &ScTabPageProtection::GetRanges);
78     }
79 }
80 
PageCreated(const OString & rPageId,SfxTabPage & rTabPage)81 void ScStyleDlg::PageCreated(const OString& rPageId, SfxTabPage& rTabPage)
82 {
83     if (m_bPage)
84     {
85         SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
86         if (rPageId == "page")
87         {
88             aSet.Put (SfxUInt16Item(sal_uInt16(SID_ENUM_PAGE_MODE), SVX_PAGE_MODE_CENTER));
89             rTabPage.PageCreated(aSet);
90         }
91         else if (rPageId == "header" || rPageId == "footer")
92         {
93             static_cast<ScHFPage&>(rTabPage).SetStyleDlg( this );
94             static_cast<ScHFPage&>(rTabPage).SetPageStyle( GetStyleSheet().GetName() );
95             static_cast<ScHFPage&>(rTabPage).DisableDeleteQueryBox();
96         }
97         else if (rPageId == "background")
98         {
99             aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_SELECTOR)));
100             rTabPage.PageCreated(aSet);
101         }
102     }
103     else
104     {
105         SfxObjectShell* pDocSh = SfxObjectShell::Current();
106         SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
107         if (rPageId == "numbers")
108         {
109             const SfxPoolItem* pInfoItem
110                 = pDocSh->GetItem( SID_ATTR_NUMBERFORMAT_INFO );
111 
112             OSL_ENSURE( pInfoItem, "NumberInfoItem not found!" );
113 
114             aSet.Put ( static_cast<const SvxNumberInfoItem&>(*pInfoItem) );
115             rTabPage.PageCreated(aSet);
116         }
117         else if (rPageId == "font")
118         {
119             const SfxPoolItem* pInfoItem
120                 = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
121 
122             OSL_ENSURE( pInfoItem, "FontListItem not found!" );
123 
124             aSet.Put (SvxFontListItem(static_cast<const SvxFontListItem&>(*pInfoItem).GetFontList(), SID_ATTR_CHAR_FONTLIST));
125             rTabPage.PageCreated(aSet);
126         }
127         else if (rPageId == "background")
128         {
129             rTabPage.PageCreated(aSet);
130         }
131     }
132 }
133 
RefreshInputSet()134 void ScStyleDlg::RefreshInputSet()
135 {
136     SfxItemSet* pItemSet = GetInputSetImpl();
137     pItemSet->ClearItem();
138     pItemSet->SetParent( GetStyleSheet().GetItemSet().GetParent() );
139 }
140 
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
142