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