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 "CurrentMasterPagesSelector.hxx"
21 : #include "PreviewValueSet.hxx"
22 : #include "ViewShellBase.hxx"
23 : #include "DrawViewShell.hxx"
24 : #include "drawdoc.hxx"
25 : #include "sdpage.hxx"
26 : #include "MasterPageContainer.hxx"
27 : #include "MasterPageDescriptor.hxx"
28 : #include "EventMultiplexer.hxx"
29 : #include "app.hrc"
30 : #include "DrawDocShell.hxx"
31 : #include "res_bmp.hrc"
32 : #include "sdresid.hxx"
33 : #include "helpids.h"
34 :
35 : #include <vcl/image.hxx>
36 : #include <svx/svdmodel.hxx>
37 : #include <sfx2/request.hxx>
38 :
39 : #include <set>
40 :
41 :
42 : using namespace ::com::sun::star;
43 :
44 : namespace sd { namespace sidebar {
45 :
46 0 : MasterPagesSelector* CurrentMasterPagesSelector::Create (
47 : ::Window* pParent,
48 : ViewShellBase& rViewShellBase,
49 : const cssu::Reference<css::ui::XSidebar>& rxSidebar)
50 : {
51 0 : SdDrawDocument* pDocument = rViewShellBase.GetDocument();
52 0 : if (pDocument == NULL)
53 0 : return NULL;
54 :
55 0 : ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer());
56 :
57 : MasterPagesSelector* pSelector(
58 : new CurrentMasterPagesSelector (
59 : pParent,
60 : *pDocument,
61 : rViewShellBase,
62 : pContainer,
63 0 : rxSidebar));
64 0 : pSelector->LateInit();
65 0 : pSelector->SetHelpId( HID_SD_TASK_PANE_PREVIEW_CURRENT );
66 :
67 0 : return pSelector;
68 : }
69 :
70 :
71 :
72 :
73 0 : CurrentMasterPagesSelector::CurrentMasterPagesSelector (
74 : ::Window* pParent,
75 : SdDrawDocument& rDocument,
76 : ViewShellBase& rBase,
77 : const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
78 : const cssu::Reference<css::ui::XSidebar>& rxSidebar)
79 0 : : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar)
80 : {
81 : // For this master page selector only we change the default action for
82 : // left clicks.
83 0 : mnDefaultClickAction = SID_TP_APPLY_TO_SELECTED_SLIDES;
84 :
85 0 : Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener));
86 : rBase.GetEventMultiplexer()->AddEventListener(aLink,
87 : sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
88 : | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
89 : | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
90 : | sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER
91 : | sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED
92 : | sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED
93 0 : | sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED);
94 0 : }
95 :
96 :
97 :
98 :
99 0 : CurrentMasterPagesSelector::~CurrentMasterPagesSelector (void)
100 : {
101 0 : if (mrDocument.GetDocSh() != NULL)
102 : {
103 0 : EndListening(*mrDocument.GetDocSh());
104 : }
105 : else
106 : {
107 : OSL_ASSERT(mrDocument.GetDocSh() != NULL);
108 : }
109 :
110 0 : Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener));
111 0 : mrBase.GetEventMultiplexer()->RemoveEventListener(aLink);
112 0 : }
113 :
114 :
115 :
116 :
117 0 : void CurrentMasterPagesSelector::LateInit (void)
118 : {
119 0 : MasterPagesSelector::LateInit();
120 0 : MasterPagesSelector::Fill();
121 0 : if (mrDocument.GetDocSh() != NULL)
122 : {
123 0 : StartListening(*mrDocument.GetDocSh());
124 : }
125 : else
126 : {
127 : OSL_ASSERT(mrDocument.GetDocSh() != NULL);
128 : }
129 0 : }
130 :
131 :
132 :
133 :
134 0 : void CurrentMasterPagesSelector::Fill (ItemList& rItemList)
135 : {
136 0 : sal_uInt16 nPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD);
137 : SdPage* pMasterPage;
138 : // Remember the names of the master pages that have been inserted to
139 : // avoid double insertion.
140 0 : ::std::set<OUString> aMasterPageNames;
141 0 : for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++)
142 : {
143 0 : pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD);
144 0 : if (pMasterPage == NULL)
145 0 : continue;
146 :
147 : // Use the name of the master page to avoid duplicate entries.
148 0 : OUString sName (pMasterPage->GetName());
149 0 : if (aMasterPageNames.find(sName)!=aMasterPageNames.end())
150 0 : continue;
151 0 : aMasterPageNames.insert (sName);
152 :
153 : // Look up the master page in the container and, when it is not yet
154 : // in it, insert it.
155 0 : MasterPageContainer::Token aToken = mpContainer->GetTokenForPageObject(pMasterPage);
156 0 : if (aToken == MasterPageContainer::NIL_TOKEN)
157 : {
158 : SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
159 : MasterPageContainer::MASTERPAGE,
160 : nIndex,
161 : OUString(),
162 : pMasterPage->GetName(),
163 : OUString(),
164 0 : pMasterPage->IsPrecious(),
165 0 : ::boost::shared_ptr<PageObjectProvider>(new ExistingPageProvider(pMasterPage)),
166 0 : ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider())));
167 0 : aToken = mpContainer->PutMasterPage(pDescriptor);
168 : }
169 :
170 0 : rItemList.push_back(aToken);
171 0 : }
172 0 : }
173 :
174 :
175 :
176 :
177 0 : ResId CurrentMasterPagesSelector::GetContextMenuResId (void) const
178 : {
179 0 : return SdResId(RID_TASKPANE_CURRENT_MASTERPAGESSELECTOR_POPUP);
180 : }
181 :
182 :
183 :
184 :
185 0 : void CurrentMasterPagesSelector::UpdateSelection (void)
186 : {
187 : // Iterate over all pages and for the selected ones put the name of
188 : // their master page into a set.
189 0 : sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD);
190 : SdPage* pPage;
191 0 : ::std::set<OUString> aNames;
192 : sal_uInt16 nIndex;
193 0 : bool bLoop (true);
194 0 : for (nIndex=0; nIndex<nPageCount && bLoop; nIndex++)
195 : {
196 0 : pPage = mrDocument.GetSdPage (nIndex, PK_STANDARD);
197 0 : if (pPage != NULL && pPage->IsSelected())
198 : {
199 0 : if ( ! pPage->TRG_HasMasterPage())
200 : {
201 : // One of the pages has no master page. This is an
202 : // indicator for that this method is called in the middle of
203 : // a document change and that the model is not in a valid
204 : // state. Therefore we stop update the selection and wait
205 : // for another call to UpdateSelection when the model is
206 : // valid again.
207 0 : bLoop = false;
208 : }
209 : else
210 : {
211 0 : SdrPage& rMasterPage (pPage->TRG_GetMasterPage());
212 0 : SdPage* pMasterPage = static_cast<SdPage*>(&rMasterPage);
213 0 : if (pMasterPage != NULL)
214 0 : aNames.insert (pMasterPage->GetName());
215 : }
216 : }
217 : }
218 :
219 : // Find the items for the master pages in the set.
220 0 : sal_uInt16 nItemCount (PreviewValueSet::GetItemCount());
221 0 : for (nIndex=1; nIndex<=nItemCount && bLoop; nIndex++)
222 : {
223 0 : OUString sName (PreviewValueSet::GetItemText (nIndex));
224 0 : if (aNames.find(sName) != aNames.end())
225 : {
226 0 : PreviewValueSet::SelectItem (nIndex);
227 : }
228 0 : }
229 0 : }
230 :
231 :
232 :
233 :
234 0 : void CurrentMasterPagesSelector::ExecuteCommand (const sal_Int32 nCommandId)
235 : {
236 0 : if (nCommandId == SID_DELETE_MASTER_PAGE)
237 : {
238 : // Check once again that the master page can safely be deleted,
239 : // i.e. is not used.
240 0 : SdPage* pMasterPage = GetSelectedMasterPage();
241 0 : if (pMasterPage != NULL
242 0 : && mrDocument.GetMasterPageUserCount(pMasterPage) == 0)
243 : {
244 : // Removing the precious flag so that the following call to
245 : // RemoveUnnessesaryMasterPages() will remove this master page.
246 0 : pMasterPage->SetPrecious(false);
247 0 : mrDocument.RemoveUnnecessaryMasterPages(pMasterPage, sal_False, sal_True);
248 : }
249 : }
250 : else
251 0 : MasterPagesSelector::ExecuteCommand(nCommandId);
252 0 : }
253 :
254 :
255 :
256 :
257 0 : void CurrentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu)
258 : {
259 : // Disable the SID_DELTE_MASTER slot when there is only one master page.
260 0 : if (mrDocument.GetMasterPageUserCount(GetSelectedMasterPage()) > 0)
261 : {
262 0 : if (rMenu.GetItemPos(SID_DELETE_MASTER_PAGE) != MENU_ITEM_NOTFOUND)
263 0 : rMenu.EnableItem(SID_DELETE_MASTER_PAGE, false);
264 : }
265 :
266 : ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
267 0 : ::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
268 0 : if (pDrawViewShell
269 0 : && pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
270 : {
271 0 : if (rMenu.GetItemPos(SID_TP_EDIT_MASTER) != MENU_ITEM_NOTFOUND)
272 0 : rMenu.EnableItem(SID_TP_EDIT_MASTER, false);
273 : }
274 :
275 0 : MasterPagesSelector::ProcessPopupMenu(rMenu);
276 0 : }
277 :
278 :
279 :
280 :
281 :
282 :
283 0 : IMPL_LINK(CurrentMasterPagesSelector,EventMultiplexerListener,
284 : sd::tools::EventMultiplexerEvent*,pEvent)
285 : {
286 0 : if (pEvent != NULL)
287 : {
288 0 : switch (pEvent->meEventId)
289 : {
290 : case sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
291 : case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL:
292 : case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER:
293 : case sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
294 0 : UpdateSelection();
295 0 : break;
296 :
297 : case sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER:
298 : // This is tricky. If a master page is removed, moved, or
299 : // added we have to wait until both the notes master page
300 : // and the standard master page have been removed, moved,
301 : // or added. We do this by looking at the number of master
302 : // pages which has to be odd in the consistent state (the
303 : // handout master page is always present). If the number is
304 : // even we ignore the hint.
305 0 : if (mrBase.GetDocument()->GetMasterPageCount()%2 == 1)
306 0 : MasterPagesSelector::Fill();
307 0 : break;
308 :
309 : case sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED:
310 : case sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED:
311 : case sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED:
312 0 : InvalidatePreview((const SdPage*)pEvent->mpUserData);
313 0 : break;
314 : }
315 : }
316 :
317 0 : return 0;
318 : }
319 :
320 : } } // end of namespace sd::sidebar
321 :
322 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|