Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "CurrentMasterPagesSelector.hxx"
31 : : #include "PreviewValueSet.hxx"
32 : : #include "ViewShellBase.hxx"
33 : : #include "DrawViewShell.hxx"
34 : : #include "drawdoc.hxx"
35 : : #include "sdpage.hxx"
36 : : #include "MasterPageContainer.hxx"
37 : : #include "MasterPageDescriptor.hxx"
38 : : #include "EventMultiplexer.hxx"
39 : : #include "app.hrc"
40 : : #include "DrawDocShell.hxx"
41 : : #include "res_bmp.hrc"
42 : : #include "sdresid.hxx"
43 : :
44 : : #include <vcl/image.hxx>
45 : : #include <svx/svdmodel.hxx>
46 : : #include <sfx2/request.hxx>
47 : :
48 : : #include <set>
49 : :
50 : :
51 : : using namespace ::com::sun::star;
52 : :
53 : : namespace sd { namespace toolpanel { namespace controls {
54 : :
55 : :
56 : 0 : CurrentMasterPagesSelector::CurrentMasterPagesSelector (
57 : : TreeNode* pParent,
58 : : SdDrawDocument& rDocument,
59 : : ViewShellBase& rBase,
60 : : const ::boost::shared_ptr<MasterPageContainer>& rpContainer)
61 [ # # ]: 0 : : MasterPagesSelector (pParent, rDocument, rBase, rpContainer)
62 : : {
63 [ # # ][ # # ]: 0 : SetName(rtl::OUString("CurrentMasterPagesSelector"));
[ # # ]
64 : :
65 : : // For this master page selector only we change the default action for
66 : : // left clicks.
67 : 0 : mnDefaultClickAction = SID_TP_APPLY_TO_SELECTED_SLIDES;
68 : :
69 [ # # ]: 0 : Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener));
70 : : rBase.GetEventMultiplexer()->AddEventListener(aLink,
71 : : sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
72 : : | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
73 : : | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
74 : : | sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER
75 : : | sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED
76 : : | sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED
77 [ # # ][ # # ]: 0 : | sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED);
[ # # ]
78 : 0 : }
79 : :
80 : :
81 : :
82 : :
83 [ # # ]: 0 : CurrentMasterPagesSelector::~CurrentMasterPagesSelector (void)
84 : : {
85 [ # # ]: 0 : if (mrDocument.GetDocSh() != NULL)
86 : : {
87 [ # # ]: 0 : EndListening(*mrDocument.GetDocSh());
88 : : }
89 : : else
90 : : {
91 : : OSL_ASSERT(mrDocument.GetDocSh() != NULL);
92 : : }
93 : :
94 [ # # ]: 0 : Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener));
95 [ # # ][ # # ]: 0 : mrBase.GetEventMultiplexer()->RemoveEventListener(aLink);
[ # # ]
96 [ # # ]: 0 : }
97 : :
98 : :
99 : :
100 : :
101 : 0 : void CurrentMasterPagesSelector::LateInit (void)
102 : : {
103 : 0 : MasterPagesSelector::LateInit();
104 : 0 : MasterPagesSelector::Fill();
105 [ # # ]: 0 : if (mrDocument.GetDocSh() != NULL)
106 : : {
107 : 0 : StartListening(*mrDocument.GetDocSh());
108 : : }
109 : : else
110 : : {
111 : : OSL_ASSERT(mrDocument.GetDocSh() != NULL);
112 : : }
113 : 0 : }
114 : :
115 : :
116 : :
117 : :
118 : 0 : void CurrentMasterPagesSelector::Fill (ItemList& rItemList)
119 : : {
120 [ # # ]: 0 : sal_uInt16 nPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD);
121 : : SdPage* pMasterPage;
122 : : // Remember the names of the master pages that have been inserted to
123 : : // avoid double insertion.
124 [ # # ]: 0 : ::std::set<String> aMasterPageNames;
125 [ # # ]: 0 : for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++)
126 : : {
127 [ # # ]: 0 : pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD);
128 [ # # ]: 0 : if (pMasterPage == NULL)
129 : 0 : continue;
130 : :
131 : : // Use the name of the master page to avoid duplicate entries.
132 [ # # ][ # # ]: 0 : String sName (pMasterPage->GetName());
133 [ # # ][ # # ]: 0 : if (aMasterPageNames.find(sName)!=aMasterPageNames.end())
[ # # ]
134 : 0 : continue;
135 [ # # ]: 0 : aMasterPageNames.insert (sName);
136 : :
137 : : // Look up the master page in the container and, when it is not yet
138 : : // in it, insert it.
139 [ # # ]: 0 : MasterPageContainer::Token aToken = mpContainer->GetTokenForPageObject(pMasterPage);
140 [ # # ]: 0 : if (aToken == MasterPageContainer::NIL_TOKEN)
141 : : {
142 : : SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
143 : : MasterPageContainer::MASTERPAGE,
144 : : nIndex,
145 : : String(),
146 : : pMasterPage->GetName(),
147 : : String(),
148 [ # # ]: 0 : pMasterPage->IsPrecious(),
149 [ # # ]: 0 : ::boost::shared_ptr<PageObjectProvider>(new ExistingPageProvider(pMasterPage)),
150 [ # # ][ # # ]: 0 : ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider())));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
151 [ # # ][ # # ]: 0 : aToken = mpContainer->PutMasterPage(pDescriptor);
152 : : }
153 : :
154 [ # # ][ # # ]: 0 : rItemList.push_back(aToken);
155 [ # # ]: 0 : }
156 : 0 : }
157 : :
158 : :
159 : :
160 : :
161 : 0 : ResId CurrentMasterPagesSelector::GetContextMenuResId (void) const
162 : : {
163 : 0 : return SdResId(RID_TASKPANE_CURRENT_MASTERPAGESSELECTOR_POPUP);
164 : : }
165 : :
166 : :
167 : :
168 : :
169 : 0 : void CurrentMasterPagesSelector::UpdateSelection (void)
170 : : {
171 : : // Iterate over all pages and for the selected ones put the name of
172 : : // their master page into a set.
173 [ # # ]: 0 : sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD);
174 : : SdPage* pPage;
175 [ # # ]: 0 : ::std::set<String> aNames;
176 : : sal_uInt16 nIndex;
177 : 0 : bool bLoop (true);
178 [ # # ][ # # ]: 0 : for (nIndex=0; nIndex<nPageCount && bLoop; nIndex++)
[ # # ]
179 : : {
180 [ # # ]: 0 : pPage = mrDocument.GetSdPage (nIndex, PK_STANDARD);
181 [ # # ][ # # ]: 0 : if (pPage != NULL && pPage->IsSelected())
[ # # ]
182 : : {
183 [ # # ]: 0 : if ( ! pPage->TRG_HasMasterPage())
184 : : {
185 : : // One of the pages has no master page. This is an
186 : : // indicator for that this method is called in the middle of
187 : : // a document change and that the model is not in a valid
188 : : // state. Therefore we stop update the selection and wait
189 : : // for another call to UpdateSelection when the model is
190 : : // valid again.
191 : 0 : bLoop = false;
192 : : }
193 : : else
194 : : {
195 [ # # ]: 0 : SdrPage& rMasterPage (pPage->TRG_GetMasterPage());
196 : 0 : SdPage* pMasterPage = static_cast<SdPage*>(&rMasterPage);
197 [ # # ]: 0 : if (pMasterPage != NULL)
198 [ # # ][ # # ]: 0 : aNames.insert (pMasterPage->GetName());
199 : : }
200 : : }
201 : : }
202 : :
203 : : // Find the items for the master pages in the set.
204 [ # # ]: 0 : sal_uInt16 nItemCount (mpPageSet->GetItemCount());
205 [ # # ][ # # ]: 0 : for (nIndex=1; nIndex<=nItemCount && bLoop; nIndex++)
[ # # ]
206 : : {
207 [ # # ]: 0 : String sName (mpPageSet->GetItemText (nIndex));
208 [ # # ][ # # ]: 0 : if (aNames.find(sName) != aNames.end())
[ # # ]
209 : : {
210 [ # # ]: 0 : mpPageSet->SelectItem (nIndex);
211 : : }
212 [ # # ]: 0 : }
213 : 0 : }
214 : :
215 : :
216 : :
217 : :
218 : 0 : void CurrentMasterPagesSelector::Execute (SfxRequest& rRequest)
219 : : {
220 [ # # ]: 0 : switch (rRequest.GetSlot())
221 : : {
222 : : case SID_DELETE_MASTER_PAGE:
223 : : {
224 : : // Check once again that the master page can safely be deleted,
225 : : // i.e. is not used.
226 : 0 : SdPage* pMasterPage = GetSelectedMasterPage();
227 [ # # ]: 0 : if (pMasterPage != NULL
[ # # # # ]
228 : 0 : && mrDocument.GetMasterPageUserCount(pMasterPage) == 0)
229 : : {
230 : : // Removing the precious flag so that the following call to
231 : : // RemoveUnnessesaryMasterPages() will remove this master page.
232 : 0 : pMasterPage->SetPrecious(false);
233 : 0 : mrDocument.RemoveUnnecessaryMasterPages(pMasterPage, sal_False, sal_True);
234 : : }
235 : : }
236 : 0 : break;
237 : :
238 : : default:
239 : 0 : MasterPagesSelector::Execute(rRequest);
240 : 0 : break;
241 : : }
242 : 0 : }
243 : :
244 : :
245 : :
246 : :
247 : 0 : void CurrentMasterPagesSelector::GetState (SfxItemSet& rItemSet)
248 : : {
249 : : // Disable the SID_DELTE_MASTER slot when there is only one master page.
250 [ # # ][ # # ]: 0 : if (rItemSet.GetItemState(SID_DELETE_MASTER_PAGE) == SFX_ITEM_AVAILABLE
[ # # ][ # # ]
251 [ # # ][ # # ]: 0 : && mrDocument.GetMasterPageUserCount(GetSelectedMasterPage()) > 0)
252 : : {
253 [ # # ]: 0 : rItemSet.DisableItem(SID_DELETE_MASTER_PAGE);
254 : : }
255 : :
256 : : ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
257 [ # # ][ # # ]: 0 : ::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
[ # # ]
258 [ # # ][ # # : 0 : if (rItemSet.GetItemState(SID_TP_EDIT_MASTER) == SFX_ITEM_AVAILABLE
# # # # ]
[ # # ]
259 : 0 : && pDrawViewShell
260 : 0 : && pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
261 : : {
262 [ # # ]: 0 : rItemSet.DisableItem (SID_TP_EDIT_MASTER);
263 : : }
264 : :
265 [ # # ][ # # ]: 0 : MasterPagesSelector::GetState(rItemSet);
266 : 0 : }
267 : :
268 : :
269 : :
270 : :
271 : :
272 : :
273 : 0 : IMPL_LINK(CurrentMasterPagesSelector,EventMultiplexerListener,
274 : : sd::tools::EventMultiplexerEvent*,pEvent)
275 : : {
276 [ # # ]: 0 : if (pEvent != NULL)
277 : : {
278 [ # # # # ]: 0 : switch (pEvent->meEventId)
279 : : {
280 : : case sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
281 : : case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL:
282 : : case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER:
283 : : case sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
284 : 0 : UpdateSelection();
285 : 0 : break;
286 : :
287 : : case sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER:
288 : : // This is tricky. If a master page is removed, moved, or
289 : : // added we have to wait until both the notes master page
290 : : // and the standard master page have been removed, moved,
291 : : // or added. We do this by looking at the number of master
292 : : // pages which has to be odd in the consistent state (the
293 : : // handout master page is always present). If the number is
294 : : // even we ignore the hint.
295 [ # # ]: 0 : if (mrBase.GetDocument()->GetMasterPageCount()%2 == 1)
296 : 0 : MasterPagesSelector::Fill();
297 : 0 : break;
298 : :
299 : : case sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED:
300 : : case sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED:
301 : : case sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED:
302 : 0 : InvalidatePreview((const SdPage*)pEvent->mpUserData);
303 : 0 : break;
304 : : }
305 : : }
306 : :
307 : 0 : return 0;
308 : : }
309 : :
310 : :
311 : :
312 : :
313 : 0 : void CurrentMasterPagesSelector::Notify (SfxBroadcaster&, const SfxHint& rHint)
314 : : {
315 [ # # ]: 0 : const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
316 [ # # ]: 0 : if (pSimpleHint != NULL)
317 : : {
318 [ # # ]: 0 : if (pSimpleHint->GetId() == SFX_HINT_DOCCHANGED)
319 : : {
320 : : // Is the edit view visible in the center pane?
321 : : ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
322 [ # # ][ # # ]: 0 : ::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
[ # # ]
323 [ # # ]: 0 : if (pDrawViewShell.get() != NULL)
324 : : {
325 : : // Is the edit view in master page mode?
326 [ # # ]: 0 : if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
327 : : {
328 : : // Mark the currently edited master page as precious.
329 [ # # ]: 0 : SdPage* pCurrentMasterPage = pDrawViewShell->getCurrentPage();
330 [ # # ]: 0 : if (pCurrentMasterPage != NULL)
331 [ # # ]: 0 : pCurrentMasterPage->SetPrecious(true);
332 : : }
333 [ # # ]: 0 : }
334 : : }
335 : : }
336 : 0 : }
337 : :
338 : :
339 : :
340 : :
341 : : } } } // end of namespace ::sd::toolpanel::controls
342 : :
343 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|