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