1*02c50d82SAndre Fischer /**************************************************************
2*02c50d82SAndre Fischer *
3*02c50d82SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
4*02c50d82SAndre Fischer * or more contributor license agreements. See the NOTICE file
5*02c50d82SAndre Fischer * distributed with this work for additional information
6*02c50d82SAndre Fischer * regarding copyright ownership. The ASF licenses this file
7*02c50d82SAndre Fischer * to you under the Apache License, Version 2.0 (the
8*02c50d82SAndre Fischer * "License"); you may not use this file except in compliance
9*02c50d82SAndre Fischer * with the License. You may obtain a copy of the License at
10*02c50d82SAndre Fischer *
11*02c50d82SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
12*02c50d82SAndre Fischer *
13*02c50d82SAndre Fischer * Unless required by applicable law or agreed to in writing,
14*02c50d82SAndre Fischer * software distributed under the License is distributed on an
15*02c50d82SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*02c50d82SAndre Fischer * KIND, either express or implied. See the License for the
17*02c50d82SAndre Fischer * specific language governing permissions and limitations
18*02c50d82SAndre Fischer * under the License.
19*02c50d82SAndre Fischer *
20*02c50d82SAndre Fischer *************************************************************/
21*02c50d82SAndre Fischer
22*02c50d82SAndre Fischer #include "precompiled_sd.hxx"
23*02c50d82SAndre Fischer
24*02c50d82SAndre Fischer #include "AllMasterPagesSelector.hxx"
25*02c50d82SAndre Fischer #include "PreviewValueSet.hxx"
26*02c50d82SAndre Fischer #include "ViewShellBase.hxx"
27*02c50d82SAndre Fischer #include "SidebarShellManager.hxx"
28*02c50d82SAndre Fischer #include "MasterPageContainer.hxx"
29*02c50d82SAndre Fischer #include "MasterPageDescriptor.hxx"
30*02c50d82SAndre Fischer #include "app.hrc"
31*02c50d82SAndre Fischer #include "helpids.h"
32*02c50d82SAndre Fischer
33*02c50d82SAndre Fischer #include <tools/link.hxx>
34*02c50d82SAndre Fischer #include <set>
35*02c50d82SAndre Fischer
36*02c50d82SAndre Fischer namespace {
37*02c50d82SAndre Fischer
38*02c50d82SAndre Fischer using namespace sd::sidebar;
39*02c50d82SAndre Fischer
GetURLPriority(const SharedMasterPageDescriptor & rpDescriptor)40*02c50d82SAndre Fischer int GetURLPriority (const SharedMasterPageDescriptor& rpDescriptor)
41*02c50d82SAndre Fischer {
42*02c50d82SAndre Fischer int nPriority (0);
43*02c50d82SAndre Fischer switch (rpDescriptor->GetURLClassification())
44*02c50d82SAndre Fischer {
45*02c50d82SAndre Fischer case MasterPageDescriptor::URLCLASS_USER: nPriority = 0; break;
46*02c50d82SAndre Fischer case MasterPageDescriptor::URLCLASS_LAYOUT: nPriority = 1; break;
47*02c50d82SAndre Fischer case MasterPageDescriptor::URLCLASS_PRESENTATION: nPriority = 2; break;
48*02c50d82SAndre Fischer case MasterPageDescriptor::URLCLASS_OTHER: nPriority = 3; break;
49*02c50d82SAndre Fischer case MasterPageDescriptor::URLCLASS_UNKNOWN: nPriority = 4; break;
50*02c50d82SAndre Fischer default:
51*02c50d82SAndre Fischer case MasterPageDescriptor::URLCLASS_UNDETERMINED: nPriority = 5; break;
52*02c50d82SAndre Fischer }
53*02c50d82SAndre Fischer return nPriority;
54*02c50d82SAndre Fischer }
55*02c50d82SAndre Fischer
56*02c50d82SAndre Fischer
57*02c50d82SAndre Fischer class MasterPageDescriptorOrder
58*02c50d82SAndre Fischer {
59*02c50d82SAndre Fischer public:
operator ()(const SharedMasterPageDescriptor & rp1,const SharedMasterPageDescriptor & rp2)60*02c50d82SAndre Fischer bool operator() (
61*02c50d82SAndre Fischer const SharedMasterPageDescriptor& rp1,
62*02c50d82SAndre Fischer const SharedMasterPageDescriptor& rp2)
63*02c50d82SAndre Fischer {
64*02c50d82SAndre Fischer if (rp1->meOrigin == MasterPageContainer::DEFAULT)
65*02c50d82SAndre Fischer return true;
66*02c50d82SAndre Fischer else if (rp2->meOrigin == MasterPageContainer::DEFAULT)
67*02c50d82SAndre Fischer return false;
68*02c50d82SAndre Fischer else if (rp1->GetURLClassification() == rp2->GetURLClassification())
69*02c50d82SAndre Fischer return rp1->mnTemplateIndex < rp2->mnTemplateIndex;
70*02c50d82SAndre Fischer else
71*02c50d82SAndre Fischer return GetURLPriority(rp1) < GetURLPriority(rp2);
72*02c50d82SAndre Fischer }
73*02c50d82SAndre Fischer };
74*02c50d82SAndre Fischer
75*02c50d82SAndre Fischer } // end of anonymous namespace
76*02c50d82SAndre Fischer
77*02c50d82SAndre Fischer
78*02c50d82SAndre Fischer
79*02c50d82SAndre Fischer namespace sd { namespace sidebar {
80*02c50d82SAndre Fischer
81*02c50d82SAndre Fischer class AllMasterPagesSelector::SortedMasterPageDescriptorList
82*02c50d82SAndre Fischer : public ::std::set<SharedMasterPageDescriptor,MasterPageDescriptorOrder>
83*02c50d82SAndre Fischer {
84*02c50d82SAndre Fischer public:
SortedMasterPageDescriptorList(void)85*02c50d82SAndre Fischer SortedMasterPageDescriptorList (void) {}
86*02c50d82SAndre Fischer };
87*02c50d82SAndre Fischer
88*02c50d82SAndre Fischer
89*02c50d82SAndre Fischer
90*02c50d82SAndre Fischer
Create(::Window * pParent,ViewShellBase & rViewShellBase,const cssu::Reference<css::ui::XSidebar> & rxSidebar)91*02c50d82SAndre Fischer MasterPagesSelector* AllMasterPagesSelector::Create (
92*02c50d82SAndre Fischer ::Window* pParent,
93*02c50d82SAndre Fischer ViewShellBase& rViewShellBase,
94*02c50d82SAndre Fischer const cssu::Reference<css::ui::XSidebar>& rxSidebar)
95*02c50d82SAndre Fischer {
96*02c50d82SAndre Fischer SdDrawDocument* pDocument = rViewShellBase.GetDocument();
97*02c50d82SAndre Fischer if (pDocument == NULL)
98*02c50d82SAndre Fischer return NULL;
99*02c50d82SAndre Fischer
100*02c50d82SAndre Fischer ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer());
101*02c50d82SAndre Fischer
102*02c50d82SAndre Fischer MasterPagesSelector* pSelector(
103*02c50d82SAndre Fischer new AllMasterPagesSelector (
104*02c50d82SAndre Fischer pParent,
105*02c50d82SAndre Fischer *pDocument,
106*02c50d82SAndre Fischer rViewShellBase,
107*02c50d82SAndre Fischer pContainer,
108*02c50d82SAndre Fischer rxSidebar));
109*02c50d82SAndre Fischer pSelector->LateInit();
110*02c50d82SAndre Fischer pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_ALL);
111*02c50d82SAndre Fischer
112*02c50d82SAndre Fischer return pSelector;
113*02c50d82SAndre Fischer }
114*02c50d82SAndre Fischer
115*02c50d82SAndre Fischer
116*02c50d82SAndre Fischer
117*02c50d82SAndre Fischer
AllMasterPagesSelector(::Window * pParent,SdDrawDocument & rDocument,ViewShellBase & rBase,const::boost::shared_ptr<MasterPageContainer> & rpContainer,const cssu::Reference<css::ui::XSidebar> & rxSidebar)118*02c50d82SAndre Fischer AllMasterPagesSelector::AllMasterPagesSelector (
119*02c50d82SAndre Fischer ::Window* pParent,
120*02c50d82SAndre Fischer SdDrawDocument& rDocument,
121*02c50d82SAndre Fischer ViewShellBase& rBase,
122*02c50d82SAndre Fischer const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
123*02c50d82SAndre Fischer const cssu::Reference<css::ui::XSidebar>& rxSidebar)
124*02c50d82SAndre Fischer : MasterPagesSelector(pParent, rDocument, rBase, rpContainer, rxSidebar),
125*02c50d82SAndre Fischer mpSortedMasterPages(new SortedMasterPageDescriptorList())
126*02c50d82SAndre Fischer {
127*02c50d82SAndre Fischer MasterPagesSelector::Fill();
128*02c50d82SAndre Fischer }
129*02c50d82SAndre Fischer
130*02c50d82SAndre Fischer
131*02c50d82SAndre Fischer
132*02c50d82SAndre Fischer
~AllMasterPagesSelector(void)133*02c50d82SAndre Fischer AllMasterPagesSelector::~AllMasterPagesSelector (void)
134*02c50d82SAndre Fischer {
135*02c50d82SAndre Fischer }
136*02c50d82SAndre Fischer
137*02c50d82SAndre Fischer
138*02c50d82SAndre Fischer
139*02c50d82SAndre Fischer
Fill(ItemList & rItemList)140*02c50d82SAndre Fischer void AllMasterPagesSelector::Fill (ItemList& rItemList)
141*02c50d82SAndre Fischer {
142*02c50d82SAndre Fischer if (mpSortedMasterPages->empty())
143*02c50d82SAndre Fischer UpdateMasterPageList();
144*02c50d82SAndre Fischer UpdatePageSet(rItemList);
145*02c50d82SAndre Fischer }
146*02c50d82SAndre Fischer
147*02c50d82SAndre Fischer
148*02c50d82SAndre Fischer
149*02c50d82SAndre Fischer
NotifyContainerChangeEvent(const MasterPageContainerChangeEvent & rEvent)150*02c50d82SAndre Fischer void AllMasterPagesSelector::NotifyContainerChangeEvent (
151*02c50d82SAndre Fischer const MasterPageContainerChangeEvent& rEvent)
152*02c50d82SAndre Fischer {
153*02c50d82SAndre Fischer switch (rEvent.meEventType)
154*02c50d82SAndre Fischer {
155*02c50d82SAndre Fischer case MasterPageContainerChangeEvent::CHILD_ADDED:
156*02c50d82SAndre Fischer AddItem(rEvent.maChildToken);
157*02c50d82SAndre Fischer MasterPagesSelector::Fill();
158*02c50d82SAndre Fischer break;
159*02c50d82SAndre Fischer
160*02c50d82SAndre Fischer case MasterPageContainerChangeEvent::INDEX_CHANGED:
161*02c50d82SAndre Fischer case MasterPageContainerChangeEvent::INDEXES_CHANGED:
162*02c50d82SAndre Fischer mpSortedMasterPages->clear();
163*02c50d82SAndre Fischer MasterPagesSelector::Fill();
164*02c50d82SAndre Fischer break;
165*02c50d82SAndre Fischer
166*02c50d82SAndre Fischer default:
167*02c50d82SAndre Fischer MasterPagesSelector::NotifyContainerChangeEvent(rEvent);
168*02c50d82SAndre Fischer break;
169*02c50d82SAndre Fischer }
170*02c50d82SAndre Fischer }
171*02c50d82SAndre Fischer
172*02c50d82SAndre Fischer
173*02c50d82SAndre Fischer
174*02c50d82SAndre Fischer
UpdateMasterPageList(void)175*02c50d82SAndre Fischer void AllMasterPagesSelector::UpdateMasterPageList (void)
176*02c50d82SAndre Fischer {
177*02c50d82SAndre Fischer mpSortedMasterPages->clear();
178*02c50d82SAndre Fischer int nTokenCount = mpContainer->GetTokenCount();
179*02c50d82SAndre Fischer for (int i=0; i<nTokenCount; i++)
180*02c50d82SAndre Fischer AddItem(mpContainer->GetTokenForIndex(i));
181*02c50d82SAndre Fischer }
182*02c50d82SAndre Fischer
183*02c50d82SAndre Fischer
184*02c50d82SAndre Fischer
185*02c50d82SAndre Fischer
AddItem(MasterPageContainer::Token aToken)186*02c50d82SAndre Fischer void AllMasterPagesSelector::AddItem (MasterPageContainer::Token aToken)
187*02c50d82SAndre Fischer {
188*02c50d82SAndre Fischer switch (mpContainer->GetOriginForToken(aToken))
189*02c50d82SAndre Fischer {
190*02c50d82SAndre Fischer case MasterPageContainer::DEFAULT:
191*02c50d82SAndre Fischer case MasterPageContainer::TEMPLATE:
192*02c50d82SAndre Fischer // Templates are added only when coming from the
193*02c50d82SAndre Fischer // MasterPageContainerFiller so that they have an id which
194*02c50d82SAndre Fischer // defines their place in the list. Templates (pre) loaded from
195*02c50d82SAndre Fischer // RecentlyUsedMasterPages are ignored (they will be loaded
196*02c50d82SAndre Fischer // later by the MasterPageContainerFiller.)
197*02c50d82SAndre Fischer if (mpContainer->GetTemplateIndexForToken(aToken) >= 0)
198*02c50d82SAndre Fischer mpSortedMasterPages->insert(mpContainer->GetDescriptorForToken(aToken));
199*02c50d82SAndre Fischer break;
200*02c50d82SAndre Fischer
201*02c50d82SAndre Fischer default:
202*02c50d82SAndre Fischer break;
203*02c50d82SAndre Fischer }
204*02c50d82SAndre Fischer }
205*02c50d82SAndre Fischer
206*02c50d82SAndre Fischer
207*02c50d82SAndre Fischer
208*02c50d82SAndre Fischer
UpdatePageSet(ItemList & rItemList)209*02c50d82SAndre Fischer void AllMasterPagesSelector::UpdatePageSet (ItemList& rItemList)
210*02c50d82SAndre Fischer {
211*02c50d82SAndre Fischer SortedMasterPageDescriptorList::const_iterator iDescriptor;
212*02c50d82SAndre Fischer SortedMasterPageDescriptorList::const_iterator iEnd (mpSortedMasterPages->end());
213*02c50d82SAndre Fischer for (iDescriptor=mpSortedMasterPages->begin(); iDescriptor!=iEnd; ++iDescriptor)
214*02c50d82SAndre Fischer rItemList.push_back((*iDescriptor)->maToken);
215*02c50d82SAndre Fischer }
216*02c50d82SAndre Fischer
217*02c50d82SAndre Fischer
218*02c50d82SAndre Fischer
219*02c50d82SAndre Fischer
GetState(SfxItemSet & rItemSet)220*02c50d82SAndre Fischer void AllMasterPagesSelector::GetState (SfxItemSet& rItemSet)
221*02c50d82SAndre Fischer {
222*02c50d82SAndre Fischer // MasterPagesSelector::GetState(rItemSet);
223*02c50d82SAndre Fischer
224*02c50d82SAndre Fischer if (rItemSet.GetItemState(SID_TP_EDIT_MASTER) == SFX_ITEM_AVAILABLE)
225*02c50d82SAndre Fischer rItemSet.DisableItem(SID_TP_EDIT_MASTER);
226*02c50d82SAndre Fischer }
227*02c50d82SAndre Fischer
228*02c50d82SAndre Fischer
229*02c50d82SAndre Fischer
230*02c50d82SAndre Fischer
231*02c50d82SAndre Fischer } } // end of namespace sd::sidebar
232