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