Line data Source code
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 : #include "AllMasterPagesSelector.hxx"
21 : #include "PreviewValueSet.hxx"
22 : #include "ViewShellBase.hxx"
23 : #include "SidebarShellManager.hxx"
24 : #include "MasterPageContainer.hxx"
25 : #include "MasterPageDescriptor.hxx"
26 : #include "app.hrc"
27 : #include "helpids.h"
28 :
29 : #include <tools/link.hxx>
30 : #include <set>
31 :
32 : namespace {
33 :
34 : using namespace sd::sidebar;
35 :
36 0 : int GetURLPriority (const SharedMasterPageDescriptor& rpDescriptor)
37 : {
38 0 : int nPriority (0);
39 0 : switch (rpDescriptor->GetURLClassification())
40 : {
41 0 : case MasterPageDescriptor::URLCLASS_USER: nPriority = 0; break;
42 0 : case MasterPageDescriptor::URLCLASS_LAYOUT: nPriority = 1; break;
43 0 : case MasterPageDescriptor::URLCLASS_PRESENTATION: nPriority = 2; break;
44 0 : case MasterPageDescriptor::URLCLASS_OTHER: nPriority = 3; break;
45 0 : case MasterPageDescriptor::URLCLASS_UNKNOWN: nPriority = 4; break;
46 : default:
47 0 : case MasterPageDescriptor::URLCLASS_UNDETERMINED: nPriority = 5; break;
48 : }
49 0 : return nPriority;
50 : }
51 :
52 :
53 : class MasterPageDescriptorOrder
54 : {
55 : public:
56 0 : bool operator() (
57 : const SharedMasterPageDescriptor& rp1,
58 : const SharedMasterPageDescriptor& rp2)
59 : {
60 0 : if (rp1->meOrigin == MasterPageContainer::DEFAULT)
61 0 : return true;
62 0 : else if (rp2->meOrigin == MasterPageContainer::DEFAULT)
63 0 : return false;
64 0 : else if (rp1->GetURLClassification() == rp2->GetURLClassification())
65 0 : return rp1->mnTemplateIndex < rp2->mnTemplateIndex;
66 : else
67 0 : return GetURLPriority(rp1) < GetURLPriority(rp2);
68 : }
69 : };
70 :
71 : } // end of anonymous namespace
72 :
73 :
74 :
75 : namespace sd { namespace sidebar {
76 :
77 0 : class AllMasterPagesSelector::SortedMasterPageDescriptorList
78 : : public ::std::set<SharedMasterPageDescriptor,MasterPageDescriptorOrder>
79 : {
80 : public:
81 0 : SortedMasterPageDescriptorList (void) {}
82 : };
83 :
84 :
85 :
86 :
87 0 : MasterPagesSelector* AllMasterPagesSelector::Create (
88 : ::Window* pParent,
89 : ViewShellBase& rViewShellBase,
90 : const cssu::Reference<css::ui::XSidebar>& rxSidebar)
91 : {
92 0 : SdDrawDocument* pDocument = rViewShellBase.GetDocument();
93 0 : if (pDocument == NULL)
94 0 : return NULL;
95 :
96 0 : ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer());
97 :
98 : MasterPagesSelector* pSelector(
99 : new AllMasterPagesSelector (
100 : pParent,
101 : *pDocument,
102 : rViewShellBase,
103 : pContainer,
104 0 : rxSidebar));
105 0 : pSelector->LateInit();
106 0 : pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_ALL);
107 :
108 0 : return pSelector;
109 : }
110 :
111 :
112 :
113 :
114 0 : AllMasterPagesSelector::AllMasterPagesSelector (
115 : ::Window* pParent,
116 : SdDrawDocument& rDocument,
117 : ViewShellBase& rBase,
118 : const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
119 : const cssu::Reference<css::ui::XSidebar>& rxSidebar)
120 : : MasterPagesSelector(pParent, rDocument, rBase, rpContainer, rxSidebar),
121 0 : mpSortedMasterPages(new SortedMasterPageDescriptorList())
122 : {
123 0 : MasterPagesSelector::Fill();
124 0 : }
125 :
126 :
127 :
128 :
129 0 : AllMasterPagesSelector::~AllMasterPagesSelector (void)
130 : {
131 0 : }
132 :
133 :
134 :
135 :
136 0 : void AllMasterPagesSelector::Fill (ItemList& rItemList)
137 : {
138 0 : if (mpSortedMasterPages->empty())
139 0 : UpdateMasterPageList();
140 0 : UpdatePageSet(rItemList);
141 0 : }
142 :
143 :
144 :
145 :
146 0 : void AllMasterPagesSelector::NotifyContainerChangeEvent (
147 : const MasterPageContainerChangeEvent& rEvent)
148 : {
149 0 : switch (rEvent.meEventType)
150 : {
151 : case MasterPageContainerChangeEvent::CHILD_ADDED:
152 0 : AddItem(rEvent.maChildToken);
153 0 : MasterPagesSelector::Fill();
154 0 : break;
155 :
156 : case MasterPageContainerChangeEvent::INDEX_CHANGED:
157 : case MasterPageContainerChangeEvent::INDEXES_CHANGED:
158 0 : mpSortedMasterPages->clear();
159 0 : MasterPagesSelector::Fill();
160 0 : break;
161 :
162 : default:
163 0 : MasterPagesSelector::NotifyContainerChangeEvent(rEvent);
164 0 : break;
165 : }
166 0 : }
167 :
168 :
169 :
170 :
171 0 : void AllMasterPagesSelector::UpdateMasterPageList (void)
172 : {
173 0 : mpSortedMasterPages->clear();
174 0 : int nTokenCount = mpContainer->GetTokenCount();
175 0 : for (int i=0; i<nTokenCount; i++)
176 0 : AddItem(mpContainer->GetTokenForIndex(i));
177 0 : }
178 :
179 :
180 :
181 :
182 0 : void AllMasterPagesSelector::AddItem (MasterPageContainer::Token aToken)
183 : {
184 0 : switch (mpContainer->GetOriginForToken(aToken))
185 : {
186 : case MasterPageContainer::DEFAULT:
187 : case MasterPageContainer::TEMPLATE:
188 : // Templates are added only when coming from the
189 : // MasterPageContainerFiller so that they have an id which
190 : // defines their place in the list. Templates (pre) loaded from
191 : // RecentlyUsedMasterPages are ignored (they will be loaded
192 : // later by the MasterPageContainerFiller.)
193 0 : if (mpContainer->GetTemplateIndexForToken(aToken) >= 0)
194 0 : mpSortedMasterPages->insert(mpContainer->GetDescriptorForToken(aToken));
195 0 : break;
196 :
197 : default:
198 0 : break;
199 : }
200 0 : }
201 :
202 :
203 :
204 :
205 0 : void AllMasterPagesSelector::UpdatePageSet (ItemList& rItemList)
206 : {
207 0 : SortedMasterPageDescriptorList::const_iterator iDescriptor;
208 0 : SortedMasterPageDescriptorList::const_iterator iEnd (mpSortedMasterPages->end());
209 0 : for (iDescriptor=mpSortedMasterPages->begin(); iDescriptor!=iEnd; ++iDescriptor)
210 0 : rItemList.push_back((*iDescriptor)->maToken);
211 0 : }
212 :
213 :
214 :
215 :
216 0 : void AllMasterPagesSelector::GetState (SfxItemSet& rItemSet)
217 : {
218 : // MasterPagesSelector::GetState(rItemSet);
219 :
220 0 : if (rItemSet.GetItemState(SID_TP_EDIT_MASTER) == SFX_ITEM_AVAILABLE)
221 0 : rItemSet.DisableItem(SID_TP_EDIT_MASTER);
222 0 : }
223 :
224 :
225 :
226 :
227 33 : } } // end of namespace sd::sidebar
228 :
229 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|