15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
55b190011SAndrew Rist * distributed with this work for additional information
65b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
75b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist * "License"); you may not use this file except in compliance
95b190011SAndrew Rist * with the License. You may obtain a copy of the License at
105b190011SAndrew Rist *
115b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
125b190011SAndrew Rist *
135b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist * software distributed under the License is distributed on an
155b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist * KIND, either express or implied. See the License for the
175b190011SAndrew Rist * specific language governing permissions and limitations
185b190011SAndrew Rist * under the License.
195b190011SAndrew Rist *
205b190011SAndrew Rist *************************************************************/
215b190011SAndrew Rist
22cdf0e10cSrcweir #include "precompiled_sd.hxx"
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "CurrentMasterPagesSelector.hxx"
25cdf0e10cSrcweir #include "PreviewValueSet.hxx"
26cdf0e10cSrcweir #include "ViewShellBase.hxx"
275d65efa0SAndre Fischer #include "SidebarShellManager.hxx"
28cdf0e10cSrcweir #include "DrawViewShell.hxx"
29cdf0e10cSrcweir #include "drawdoc.hxx"
30cdf0e10cSrcweir #include "sdpage.hxx"
31cdf0e10cSrcweir #include "MasterPageContainer.hxx"
32cdf0e10cSrcweir #include "MasterPageDescriptor.hxx"
33cdf0e10cSrcweir #include "EventMultiplexer.hxx"
34cdf0e10cSrcweir #include "app.hrc"
35cdf0e10cSrcweir #include "DrawDocShell.hxx"
36cdf0e10cSrcweir #include "DrawViewShell.hxx"
37cdf0e10cSrcweir #include "res_bmp.hrc"
38cdf0e10cSrcweir #include "sdresid.hxx"
397a32b0c8SAndre Fischer #include "helpids.h"
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <vcl/image.hxx>
42cdf0e10cSrcweir #include <svx/svdmodel.hxx>
43cdf0e10cSrcweir #include <sfx2/request.hxx>
44cdf0e10cSrcweir
45cdf0e10cSrcweir #include <set>
46cdf0e10cSrcweir
47cdf0e10cSrcweir
48cdf0e10cSrcweir using namespace ::com::sun::star;
49cdf0e10cSrcweir
507a32b0c8SAndre Fischer namespace sd { namespace sidebar {
517a32b0c8SAndre Fischer
Create(::Window * pParent,ViewShellBase & rViewShellBase,const cssu::Reference<css::ui::XSidebar> & rxSidebar)527a32b0c8SAndre Fischer MasterPagesSelector* CurrentMasterPagesSelector::Create (
537a32b0c8SAndre Fischer ::Window* pParent,
547a32b0c8SAndre Fischer ViewShellBase& rViewShellBase,
55*02c50d82SAndre Fischer const cssu::Reference<css::ui::XSidebar>& rxSidebar)
567a32b0c8SAndre Fischer {
577a32b0c8SAndre Fischer SdDrawDocument* pDocument = rViewShellBase.GetDocument();
587a32b0c8SAndre Fischer if (pDocument == NULL)
597a32b0c8SAndre Fischer return NULL;
607a32b0c8SAndre Fischer
617a32b0c8SAndre Fischer ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer());
627a32b0c8SAndre Fischer
637a32b0c8SAndre Fischer MasterPagesSelector* pSelector(
647a32b0c8SAndre Fischer new CurrentMasterPagesSelector (
657a32b0c8SAndre Fischer pParent,
667a32b0c8SAndre Fischer *pDocument,
677a32b0c8SAndre Fischer rViewShellBase,
68*02c50d82SAndre Fischer pContainer,
69*02c50d82SAndre Fischer rxSidebar));
707a32b0c8SAndre Fischer pSelector->LateInit();
717a32b0c8SAndre Fischer pSelector->SetHelpId( HID_SD_TASK_PANE_PREVIEW_CURRENT );
727a32b0c8SAndre Fischer
737a32b0c8SAndre Fischer return pSelector;
747a32b0c8SAndre Fischer }
757a32b0c8SAndre Fischer
767a32b0c8SAndre Fischer
77cdf0e10cSrcweir
78cdf0e10cSrcweir
CurrentMasterPagesSelector(::Window * pParent,SdDrawDocument & rDocument,ViewShellBase & rBase,const::boost::shared_ptr<MasterPageContainer> & rpContainer,const cssu::Reference<css::ui::XSidebar> & rxSidebar)79cdf0e10cSrcweir CurrentMasterPagesSelector::CurrentMasterPagesSelector (
807a32b0c8SAndre Fischer ::Window* pParent,
81cdf0e10cSrcweir SdDrawDocument& rDocument,
82cdf0e10cSrcweir ViewShellBase& rBase,
83*02c50d82SAndre Fischer const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
84*02c50d82SAndre Fischer const cssu::Reference<css::ui::XSidebar>& rxSidebar)
85*02c50d82SAndre Fischer : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir // For this master page selector only we change the default action for
88cdf0e10cSrcweir // left clicks.
89cdf0e10cSrcweir mnDefaultClickAction = SID_TP_APPLY_TO_SELECTED_SLIDES;
90cdf0e10cSrcweir
91cdf0e10cSrcweir Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener));
92cdf0e10cSrcweir rBase.GetEventMultiplexer()->AddEventListener(aLink,
93cdf0e10cSrcweir sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
94cdf0e10cSrcweir | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
95cdf0e10cSrcweir | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
96cdf0e10cSrcweir | sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER
97cdf0e10cSrcweir | sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED
98cdf0e10cSrcweir | sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED
99cdf0e10cSrcweir | sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED);
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir
103cdf0e10cSrcweir
104cdf0e10cSrcweir
~CurrentMasterPagesSelector(void)105cdf0e10cSrcweir CurrentMasterPagesSelector::~CurrentMasterPagesSelector (void)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir if (mrDocument.GetDocSh() != NULL)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir EndListening(*mrDocument.GetDocSh());
110cdf0e10cSrcweir }
111cdf0e10cSrcweir else
112cdf0e10cSrcweir {
113cdf0e10cSrcweir OSL_ASSERT(mrDocument.GetDocSh() != NULL);
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener));
117cdf0e10cSrcweir mrBase.GetEventMultiplexer()->RemoveEventListener(aLink);
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir
121cdf0e10cSrcweir
122cdf0e10cSrcweir
LateInit(void)123cdf0e10cSrcweir void CurrentMasterPagesSelector::LateInit (void)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir MasterPagesSelector::LateInit();
126cdf0e10cSrcweir MasterPagesSelector::Fill();
127cdf0e10cSrcweir if (mrDocument.GetDocSh() != NULL)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir StartListening(*mrDocument.GetDocSh());
130cdf0e10cSrcweir }
131cdf0e10cSrcweir else
132cdf0e10cSrcweir {
133cdf0e10cSrcweir OSL_ASSERT(mrDocument.GetDocSh() != NULL);
134cdf0e10cSrcweir }
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir
138cdf0e10cSrcweir
139cdf0e10cSrcweir
Fill(ItemList & rItemList)140cdf0e10cSrcweir void CurrentMasterPagesSelector::Fill (ItemList& rItemList)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir sal_uInt16 nPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD);
143cdf0e10cSrcweir SdPage* pMasterPage;
144cdf0e10cSrcweir // Remember the names of the master pages that have been inserted to
145cdf0e10cSrcweir // avoid double insertion.
146cdf0e10cSrcweir ::std::set<String> aMasterPageNames;
147cdf0e10cSrcweir for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD);
150cdf0e10cSrcweir if (pMasterPage == NULL)
151cdf0e10cSrcweir continue;
152cdf0e10cSrcweir
153cdf0e10cSrcweir // Use the name of the master page to avoid duplicate entries.
154cdf0e10cSrcweir String sName (pMasterPage->GetName());
155cdf0e10cSrcweir if (aMasterPageNames.find(sName)!=aMasterPageNames.end())
156cdf0e10cSrcweir continue;
157cdf0e10cSrcweir aMasterPageNames.insert (sName);
158cdf0e10cSrcweir
159cdf0e10cSrcweir // Look up the master page in the container and, when it is not yet
160cdf0e10cSrcweir // in it, insert it.
161cdf0e10cSrcweir MasterPageContainer::Token aToken = mpContainer->GetTokenForPageObject(pMasterPage);
162cdf0e10cSrcweir if (aToken == MasterPageContainer::NIL_TOKEN)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
165cdf0e10cSrcweir MasterPageContainer::MASTERPAGE,
166cdf0e10cSrcweir nIndex,
167cdf0e10cSrcweir String(),
168cdf0e10cSrcweir pMasterPage->GetName(),
169cdf0e10cSrcweir String(),
170cdf0e10cSrcweir pMasterPage->IsPrecious(),
171cdf0e10cSrcweir ::boost::shared_ptr<PageObjectProvider>(new ExistingPageProvider(pMasterPage)),
172cdf0e10cSrcweir ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider())));
173cdf0e10cSrcweir aToken = mpContainer->PutMasterPage(pDescriptor);
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir rItemList.push_back(aToken);
177cdf0e10cSrcweir }
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir
181cdf0e10cSrcweir
182cdf0e10cSrcweir
GetContextMenuResId(void) const183cdf0e10cSrcweir ResId CurrentMasterPagesSelector::GetContextMenuResId (void) const
184cdf0e10cSrcweir {
185cdf0e10cSrcweir return SdResId(RID_TASKPANE_CURRENT_MASTERPAGESSELECTOR_POPUP);
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir
189cdf0e10cSrcweir
190cdf0e10cSrcweir
UpdateSelection(void)191cdf0e10cSrcweir void CurrentMasterPagesSelector::UpdateSelection (void)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir // Iterate over all pages and for the selected ones put the name of
194cdf0e10cSrcweir // their master page into a set.
195cdf0e10cSrcweir sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD);
196cdf0e10cSrcweir SdPage* pPage;
197cdf0e10cSrcweir ::std::set<String> aNames;
198cdf0e10cSrcweir sal_uInt16 nIndex;
199cdf0e10cSrcweir bool bLoop (true);
200cdf0e10cSrcweir for (nIndex=0; nIndex<nPageCount && bLoop; nIndex++)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir pPage = mrDocument.GetSdPage (nIndex, PK_STANDARD);
203cdf0e10cSrcweir if (pPage != NULL && pPage->IsSelected())
204cdf0e10cSrcweir {
205cdf0e10cSrcweir if ( ! pPage->TRG_HasMasterPage())
206cdf0e10cSrcweir {
207cdf0e10cSrcweir // One of the pages has no master page. This is an
208cdf0e10cSrcweir // indicator for that this method is called in the middle of
209cdf0e10cSrcweir // a document change and that the model is not in a valid
210cdf0e10cSrcweir // state. Therefore we stop update the selection and wait
211cdf0e10cSrcweir // for another call to UpdateSelection when the model is
212cdf0e10cSrcweir // valid again.
213cdf0e10cSrcweir bLoop = false;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir else
216cdf0e10cSrcweir {
217cdf0e10cSrcweir SdrPage& rMasterPage (pPage->TRG_GetMasterPage());
218cdf0e10cSrcweir SdPage* pMasterPage = static_cast<SdPage*>(&rMasterPage);
219cdf0e10cSrcweir if (pMasterPage != NULL)
220cdf0e10cSrcweir aNames.insert (pMasterPage->GetName());
221cdf0e10cSrcweir }
222cdf0e10cSrcweir }
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
225cdf0e10cSrcweir // Find the items for the master pages in the set.
2267a32b0c8SAndre Fischer sal_uInt16 nItemCount (PreviewValueSet::GetItemCount());
227cdf0e10cSrcweir for (nIndex=1; nIndex<=nItemCount && bLoop; nIndex++)
228cdf0e10cSrcweir {
2297a32b0c8SAndre Fischer String sName (PreviewValueSet::GetItemText (nIndex));
230cdf0e10cSrcweir if (aNames.find(sName) != aNames.end())
231cdf0e10cSrcweir {
2327a32b0c8SAndre Fischer PreviewValueSet::SelectItem (nIndex);
233cdf0e10cSrcweir }
234cdf0e10cSrcweir }
235cdf0e10cSrcweir }
236cdf0e10cSrcweir
237cdf0e10cSrcweir
238cdf0e10cSrcweir
239cdf0e10cSrcweir
ExecuteCommand(const sal_Int32 nCommandId)240*02c50d82SAndre Fischer void CurrentMasterPagesSelector::ExecuteCommand (const sal_Int32 nCommandId)
241cdf0e10cSrcweir {
242*02c50d82SAndre Fischer if (nCommandId == SID_DELETE_MASTER_PAGE)
243cdf0e10cSrcweir {
244*02c50d82SAndre Fischer // Check once again that the master page can safely be deleted,
245*02c50d82SAndre Fischer // i.e. is not used.
246*02c50d82SAndre Fischer SdPage* pMasterPage = GetSelectedMasterPage();
247*02c50d82SAndre Fischer if (pMasterPage != NULL
248*02c50d82SAndre Fischer && mrDocument.GetMasterPageUserCount(pMasterPage) == 0)
249cdf0e10cSrcweir {
250*02c50d82SAndre Fischer // Removing the precious flag so that the following call to
251*02c50d82SAndre Fischer // RemoveUnnessesaryMasterPages() will remove this master page.
252*02c50d82SAndre Fischer pMasterPage->SetPrecious(false);
253*02c50d82SAndre Fischer mrDocument.RemoveUnnecessaryMasterPages(pMasterPage, sal_False, sal_True);
254cdf0e10cSrcweir }
255cdf0e10cSrcweir }
256*02c50d82SAndre Fischer else
257*02c50d82SAndre Fischer MasterPagesSelector::ExecuteCommand(nCommandId);
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir
261cdf0e10cSrcweir
262cdf0e10cSrcweir
ProcessPopupMenu(Menu & rMenu)263*02c50d82SAndre Fischer void CurrentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu)
264cdf0e10cSrcweir {
265cdf0e10cSrcweir // Disable the SID_DELTE_MASTER slot when there is only one master page.
266*02c50d82SAndre Fischer if (mrDocument.GetMasterPageUserCount(GetSelectedMasterPage()) > 0)
267cdf0e10cSrcweir {
268*02c50d82SAndre Fischer if (rMenu.GetItemPos(SID_DELETE_MASTER_PAGE) != MENU_ITEM_NOTFOUND)
269*02c50d82SAndre Fischer rMenu.EnableItem(SID_DELETE_MASTER_PAGE, sal_False);
270cdf0e10cSrcweir }
271cdf0e10cSrcweir
272cdf0e10cSrcweir ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
273cdf0e10cSrcweir ::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
274*02c50d82SAndre Fischer if (pDrawViewShell
275cdf0e10cSrcweir && pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
276cdf0e10cSrcweir {
277*02c50d82SAndre Fischer if (rMenu.GetItemPos(SID_TP_EDIT_MASTER) != MENU_ITEM_NOTFOUND)
278*02c50d82SAndre Fischer rMenu.EnableItem(SID_TP_EDIT_MASTER, sal_False);
279cdf0e10cSrcweir }
280cdf0e10cSrcweir
281*02c50d82SAndre Fischer MasterPagesSelector::ProcessPopupMenu(rMenu);
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir
285cdf0e10cSrcweir
286cdf0e10cSrcweir
287cdf0e10cSrcweir
288cdf0e10cSrcweir
IMPL_LINK(CurrentMasterPagesSelector,EventMultiplexerListener,sd::tools::EventMultiplexerEvent *,pEvent)289cdf0e10cSrcweir IMPL_LINK(CurrentMasterPagesSelector,EventMultiplexerListener,
290cdf0e10cSrcweir sd::tools::EventMultiplexerEvent*,pEvent)
291cdf0e10cSrcweir {
292cdf0e10cSrcweir if (pEvent != NULL)
293cdf0e10cSrcweir {
294cdf0e10cSrcweir switch (pEvent->meEventId)
295cdf0e10cSrcweir {
296cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
297cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL:
298cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER:
299cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
300cdf0e10cSrcweir UpdateSelection();
301cdf0e10cSrcweir break;
302cdf0e10cSrcweir
303cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER:
304cdf0e10cSrcweir // This is tricky. If a master page is removed, moved, or
305cdf0e10cSrcweir // added we have to wait until both the notes master page
306cdf0e10cSrcweir // and the standard master page have been removed, moved,
307cdf0e10cSrcweir // or added. We do this by looking at the number of master
308cdf0e10cSrcweir // pages which has to be odd in the consistent state (the
309cdf0e10cSrcweir // handout master page is always present). If the number is
310cdf0e10cSrcweir // even we ignore the hint.
311cdf0e10cSrcweir if (mrBase.GetDocument()->GetMasterPageCount()%2 == 1)
312cdf0e10cSrcweir MasterPagesSelector::Fill();
313cdf0e10cSrcweir break;
314cdf0e10cSrcweir
315cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED:
316cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED:
317cdf0e10cSrcweir case sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED:
318cdf0e10cSrcweir InvalidatePreview((const SdPage*)pEvent->mpUserData);
319cdf0e10cSrcweir break;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir }
322cdf0e10cSrcweir
323cdf0e10cSrcweir return 0;
324cdf0e10cSrcweir }
325cdf0e10cSrcweir
326cdf0e10cSrcweir
327cdf0e10cSrcweir
328cdf0e10cSrcweir
Notify(SfxBroadcaster &,const SfxHint & rHint)329cdf0e10cSrcweir void CurrentMasterPagesSelector::Notify (SfxBroadcaster&, const SfxHint& rHint)
330cdf0e10cSrcweir {
331cdf0e10cSrcweir const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
332cdf0e10cSrcweir if (pSimpleHint != NULL)
333cdf0e10cSrcweir {
334cdf0e10cSrcweir if (pSimpleHint->GetId() == SFX_HINT_DOCCHANGED)
335cdf0e10cSrcweir {
336cdf0e10cSrcweir // Is the edit view visible in the center pane?
337cdf0e10cSrcweir ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
338cdf0e10cSrcweir ::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
339cdf0e10cSrcweir if (pDrawViewShell.get() != NULL)
340cdf0e10cSrcweir {
341cdf0e10cSrcweir // Is the edit view in master page mode?
342cdf0e10cSrcweir if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
343cdf0e10cSrcweir {
344cdf0e10cSrcweir // Mark the currently edited master page as precious.
345cdf0e10cSrcweir SdPage* pCurrentMasterPage = pDrawViewShell->getCurrentPage();
346cdf0e10cSrcweir if (pCurrentMasterPage != NULL)
347cdf0e10cSrcweir pCurrentMasterPage->SetPrecious(true);
348cdf0e10cSrcweir }
349cdf0e10cSrcweir }
350cdf0e10cSrcweir }
351cdf0e10cSrcweir }
352cdf0e10cSrcweir }
353cdf0e10cSrcweir
354cdf0e10cSrcweir
3557a32b0c8SAndre Fischer } } // end of namespace sd::sidebar
356