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 : class MasterPageDescriptorOrder
52 : {
53 : public:
54 0 : bool operator() (
55 : const SharedMasterPageDescriptor& rp1,
56 : const SharedMasterPageDescriptor& rp2)
57 : {
58 0 : if (rp1->meOrigin == MasterPageContainer::DEFAULT)
59 0 : return true;
60 0 : else if (rp2->meOrigin == MasterPageContainer::DEFAULT)
61 0 : return false;
62 0 : else if (rp1->GetURLClassification() == rp2->GetURLClassification())
63 0 : return rp1->mnTemplateIndex < rp2->mnTemplateIndex;
64 : else
65 0 : return GetURLPriority(rp1) < GetURLPriority(rp2);
66 : }
67 : };
68 :
69 : } // end of anonymous namespace
70 :
71 : namespace sd { namespace sidebar {
72 :
73 0 : class AllMasterPagesSelector::SortedMasterPageDescriptorList
74 : : public ::std::set<SharedMasterPageDescriptor,MasterPageDescriptorOrder>
75 : {
76 : public:
77 0 : SortedMasterPageDescriptorList (void) {}
78 : };
79 :
80 0 : MasterPagesSelector* AllMasterPagesSelector::Create (
81 : vcl::Window* pParent,
82 : ViewShellBase& rViewShellBase,
83 : const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
84 : {
85 0 : SdDrawDocument* pDocument = rViewShellBase.GetDocument();
86 0 : if (pDocument == NULL)
87 0 : return NULL;
88 :
89 0 : ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer());
90 :
91 : MasterPagesSelector* pSelector(
92 : new AllMasterPagesSelector (
93 : pParent,
94 : *pDocument,
95 : rViewShellBase,
96 : pContainer,
97 0 : rxSidebar));
98 0 : pSelector->LateInit();
99 0 : pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_ALL);
100 :
101 0 : return pSelector;
102 : }
103 :
104 0 : AllMasterPagesSelector::AllMasterPagesSelector (
105 : vcl::Window* pParent,
106 : SdDrawDocument& rDocument,
107 : ViewShellBase& rBase,
108 : const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
109 : const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
110 : : MasterPagesSelector(pParent, rDocument, rBase, rpContainer, rxSidebar),
111 0 : mpSortedMasterPages(new SortedMasterPageDescriptorList())
112 : {
113 0 : MasterPagesSelector::Fill();
114 0 : }
115 :
116 0 : AllMasterPagesSelector::~AllMasterPagesSelector (void)
117 : {
118 0 : }
119 :
120 0 : void AllMasterPagesSelector::Fill (ItemList& rItemList)
121 : {
122 0 : if (mpSortedMasterPages->empty())
123 0 : UpdateMasterPageList();
124 0 : UpdatePageSet(rItemList);
125 0 : }
126 :
127 0 : void AllMasterPagesSelector::NotifyContainerChangeEvent (
128 : const MasterPageContainerChangeEvent& rEvent)
129 : {
130 0 : switch (rEvent.meEventType)
131 : {
132 : case MasterPageContainerChangeEvent::CHILD_ADDED:
133 0 : AddItem(rEvent.maChildToken);
134 0 : MasterPagesSelector::Fill();
135 0 : break;
136 :
137 : case MasterPageContainerChangeEvent::INDEX_CHANGED:
138 : case MasterPageContainerChangeEvent::INDEXES_CHANGED:
139 0 : mpSortedMasterPages->clear();
140 0 : MasterPagesSelector::Fill();
141 0 : break;
142 :
143 : default:
144 0 : MasterPagesSelector::NotifyContainerChangeEvent(rEvent);
145 0 : break;
146 : }
147 0 : }
148 :
149 0 : void AllMasterPagesSelector::UpdateMasterPageList (void)
150 : {
151 0 : mpSortedMasterPages->clear();
152 0 : int nTokenCount = mpContainer->GetTokenCount();
153 0 : for (int i=0; i<nTokenCount; i++)
154 0 : AddItem(mpContainer->GetTokenForIndex(i));
155 0 : }
156 :
157 0 : void AllMasterPagesSelector::AddItem (MasterPageContainer::Token aToken)
158 : {
159 0 : switch (mpContainer->GetOriginForToken(aToken))
160 : {
161 : case MasterPageContainer::DEFAULT:
162 : case MasterPageContainer::TEMPLATE:
163 : // Templates are added only when coming from the
164 : // MasterPageContainerFiller so that they have an id which
165 : // defines their place in the list. Templates (pre) loaded from
166 : // RecentlyUsedMasterPages are ignored (they will be loaded
167 : // later by the MasterPageContainerFiller.)
168 0 : if (mpContainer->GetTemplateIndexForToken(aToken) >= 0)
169 0 : mpSortedMasterPages->insert(mpContainer->GetDescriptorForToken(aToken));
170 0 : break;
171 :
172 : default:
173 0 : break;
174 : }
175 0 : }
176 :
177 0 : void AllMasterPagesSelector::UpdatePageSet (ItemList& rItemList)
178 : {
179 0 : SortedMasterPageDescriptorList::const_iterator iDescriptor;
180 0 : SortedMasterPageDescriptorList::const_iterator iEnd (mpSortedMasterPages->end());
181 0 : for (iDescriptor=mpSortedMasterPages->begin(); iDescriptor!=iEnd; ++iDescriptor)
182 0 : rItemList.push_back((*iDescriptor)->maToken);
183 0 : }
184 :
185 0 : void AllMasterPagesSelector::GetState (SfxItemSet& rItemSet)
186 : {
187 : // MasterPagesSelector::GetState(rItemSet);
188 :
189 0 : if (rItemSet.GetItemState(SID_TP_EDIT_MASTER) == SfxItemState::DEFAULT)
190 0 : rItemSet.DisableItem(SID_TP_EDIT_MASTER);
191 0 : }
192 :
193 114 : } } // end of namespace sd::sidebar
194 :
195 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|