Update ooo320-m1
[ooovba.git] / sd / source / ui / toolpanel / controls / AllMasterPagesSelector.cxx
blobd43a348721a9ce421d123b058c141e6a7a4c98d6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AllMasterPagesSelector.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "AllMasterPagesSelector.hxx"
35 #include "PreviewValueSet.hxx"
36 #include "app.hrc"
37 #include "MasterPageContainer.hxx"
38 #include "MasterPageDescriptor.hxx"
39 #include <tools/link.hxx>
40 #include <set>
42 namespace {
44 using namespace sd::toolpanel::controls;
46 int GetURLPriority (const SharedMasterPageDescriptor& rpDescriptor)
48 int nPriority (0);
49 switch (rpDescriptor->GetURLClassification())
51 case MasterPageDescriptor::URLCLASS_USER: nPriority = 0; break;
52 case MasterPageDescriptor::URLCLASS_LAYOUT: nPriority = 1; break;
53 case MasterPageDescriptor::URLCLASS_PRESENTATION: nPriority = 2; break;
54 case MasterPageDescriptor::URLCLASS_OTHER: nPriority = 3; break;
55 case MasterPageDescriptor::URLCLASS_UNKNOWN: nPriority = 4; break;
56 default:
57 case MasterPageDescriptor::URLCLASS_UNDETERMINED: nPriority = 5; break;
59 return nPriority;
63 class MasterPageDescriptorOrder
65 public:
66 bool operator() (const sd::toolpanel::controls::SharedMasterPageDescriptor& rp1,
67 const sd::toolpanel::controls::SharedMasterPageDescriptor& rp2)
69 if (rp1->meOrigin == MasterPageContainer::DEFAULT)
70 return true;
71 else if (rp2->meOrigin == MasterPageContainer::DEFAULT)
72 return false;
73 else if (rp1->GetURLClassification() == rp2->GetURLClassification())
74 return rp1->mnTemplateIndex < rp2->mnTemplateIndex;
75 else
76 return GetURLPriority(rp1) < GetURLPriority(rp2);
80 } // end of anonymous namespace
84 namespace sd { namespace toolpanel { namespace controls {
86 class AllMasterPagesSelector::SortedMasterPageDescriptorList
87 : public ::std::set<SharedMasterPageDescriptor,MasterPageDescriptorOrder>
89 public:
90 SortedMasterPageDescriptorList (void) {}
96 AllMasterPagesSelector::AllMasterPagesSelector (
97 TreeNode* pParent,
98 SdDrawDocument& rDocument,
99 ViewShellBase& rBase,
100 DrawViewShell& rViewShell,
101 const ::boost::shared_ptr<MasterPageContainer>& rpContainer)
102 : MasterPagesSelector(pParent, rDocument, rBase, rpContainer),
103 mrViewShell(rViewShell),
104 mpSortedMasterPages(new SortedMasterPageDescriptorList())
106 SetName (String(RTL_CONSTASCII_USTRINGPARAM("AllMasterPagesSelector")));
107 MasterPagesSelector::Fill();
113 AllMasterPagesSelector::~AllMasterPagesSelector (void)
120 void AllMasterPagesSelector::Fill (ItemList& rItemList)
122 if (mpSortedMasterPages->empty())
123 UpdateMasterPageList();
124 UpdatePageSet(rItemList);
130 void AllMasterPagesSelector::NotifyContainerChangeEvent (
131 const MasterPageContainerChangeEvent& rEvent)
133 switch (rEvent.meEventType)
135 case MasterPageContainerChangeEvent::CHILD_ADDED:
136 AddItem(rEvent.maChildToken);
137 MasterPagesSelector::Fill();
138 break;
140 case MasterPageContainerChangeEvent::INDEX_CHANGED:
141 case MasterPageContainerChangeEvent::INDEXES_CHANGED:
142 mpSortedMasterPages->clear();
143 MasterPagesSelector::Fill();
144 break;
146 default:
147 MasterPagesSelector::NotifyContainerChangeEvent(rEvent);
148 break;
155 void AllMasterPagesSelector::UpdateMasterPageList (void)
157 mpSortedMasterPages->clear();
158 int nTokenCount = mpContainer->GetTokenCount();
159 for (int i=0; i<nTokenCount; i++)
160 AddItem(mpContainer->GetTokenForIndex(i));
166 void AllMasterPagesSelector::AddItem (MasterPageContainer::Token aToken)
168 switch (mpContainer->GetOriginForToken(aToken))
170 case MasterPageContainer::DEFAULT:
171 case MasterPageContainer::TEMPLATE:
172 // Templates are added only when coming from the
173 // MasterPageContainerFiller so that they have an id which
174 // defines their place in the list. Templates (pre) loaded from
175 // RecentlyUsedMasterPages are ignored (they will be loaded
176 // later by the MasterPageContainerFiller.)
177 if (mpContainer->GetTemplateIndexForToken(aToken) >= 0)
178 mpSortedMasterPages->insert(mpContainer->GetDescriptorForToken(aToken));
179 break;
181 default:
182 break;
189 void AllMasterPagesSelector::UpdatePageSet (ItemList& rItemList)
191 SortedMasterPageDescriptorList::const_iterator iDescriptor;
192 SortedMasterPageDescriptorList::const_iterator iEnd (mpSortedMasterPages->end());
193 for (iDescriptor=mpSortedMasterPages->begin(); iDescriptor!=iEnd; ++iDescriptor)
194 rItemList.push_back((*iDescriptor)->maToken);
200 void AllMasterPagesSelector::GetState (SfxItemSet& rItemSet)
202 MasterPagesSelector::GetState(rItemSet);
204 if (rItemSet.GetItemState(SID_TP_EDIT_MASTER) == SFX_ITEM_AVAILABLE)
205 rItemSet.DisableItem(SID_TP_EDIT_MASTER);
211 } } } // end of namespace ::sd::toolpanel::control