1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CurrentMasterPagesSelector.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "CurrentMasterPagesSelector.hxx"
35 #include "PreviewValueSet.hxx"
36 #include "ViewShellBase.hxx"
37 #include "drawdoc.hxx"
39 #include "MasterPageContainer.hxx"
40 #include "MasterPageDescriptor.hxx"
41 #include "EventMultiplexer.hxx"
43 #include "DrawDocShell.hxx"
44 #include "DrawViewShell.hxx"
45 #include "res_bmp.hrc"
46 #include "sdresid.hxx"
48 #include <vcl/image.hxx>
49 #include <svx/svdmodel.hxx>
50 #include <sfx2/request.hxx>
55 using namespace ::com::sun::star
;
57 namespace sd
{ namespace toolpanel
{ namespace controls
{
60 CurrentMasterPagesSelector::CurrentMasterPagesSelector (
62 SdDrawDocument
& rDocument
,
64 const ::boost::shared_ptr
<MasterPageContainer
>& rpContainer
)
65 : MasterPagesSelector (pParent
, rDocument
, rBase
, rpContainer
)
67 SetName(String(RTL_CONSTASCII_USTRINGPARAM("CurrentMasterPagesSelector")));
69 // For this master page selector only we change the default action for
71 mnDefaultClickAction
= SID_TP_APPLY_TO_SELECTED_SLIDES
;
73 Link
aLink (LINK(this,CurrentMasterPagesSelector
,EventMultiplexerListener
));
74 rBase
.GetEventMultiplexer()->AddEventListener(aLink
,
75 sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
76 | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE
77 | sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER
78 | sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED
79 | sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED
80 | sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED
);
86 CurrentMasterPagesSelector::~CurrentMasterPagesSelector (void)
88 if (mrDocument
.GetDocSh() != NULL
)
90 EndListening(*mrDocument
.GetDocSh());
94 OSL_ASSERT(mrDocument
.GetDocSh() != NULL
);
97 Link
aLink (LINK(this,CurrentMasterPagesSelector
,EventMultiplexerListener
));
98 mrBase
.GetEventMultiplexer()->RemoveEventListener(aLink
);
104 void CurrentMasterPagesSelector::LateInit (void)
106 MasterPagesSelector::LateInit();
107 MasterPagesSelector::Fill();
108 if (mrDocument
.GetDocSh() != NULL
)
110 StartListening(*mrDocument
.GetDocSh());
114 OSL_ASSERT(mrDocument
.GetDocSh() != NULL
);
121 void CurrentMasterPagesSelector::Fill (ItemList
& rItemList
)
123 USHORT nPageCount
= mrDocument
.GetMasterSdPageCount(PK_STANDARD
);
125 // Remember the names of the master pages that have been inserted to
126 // avoid double insertion.
127 ::std::set
<String
> aMasterPageNames
;
128 for (USHORT nIndex
=0; nIndex
<nPageCount
; nIndex
++)
130 pMasterPage
= mrDocument
.GetMasterSdPage (nIndex
, PK_STANDARD
);
131 if (pMasterPage
== NULL
)
134 // Use the name of the master page to avoid duplicate entries.
135 String
sName (pMasterPage
->GetName());
136 if (aMasterPageNames
.find(sName
)!=aMasterPageNames
.end())
138 aMasterPageNames
.insert (sName
);
140 // Look up the master page in the container and, when it is not yet
142 MasterPageContainer::Token aToken
= mpContainer
->GetTokenForPageObject(pMasterPage
);
143 if (aToken
== MasterPageContainer::NIL_TOKEN
)
145 SharedMasterPageDescriptor
pDescriptor (new MasterPageDescriptor(
146 MasterPageContainer::MASTERPAGE
,
149 pMasterPage
->GetName(),
151 pMasterPage
->IsPrecious(),
152 ::boost::shared_ptr
<PageObjectProvider
>(new ExistingPageProvider(pMasterPage
)),
153 ::boost::shared_ptr
<PreviewProvider
>(new PagePreviewProvider())));
154 aToken
= mpContainer
->PutMasterPage(pDescriptor
);
157 rItemList
.push_back(aToken
);
164 ResId
CurrentMasterPagesSelector::GetContextMenuResId (void) const
166 return SdResId(RID_TASKPANE_CURRENT_MASTERPAGESSELECTOR_POPUP
);
172 void CurrentMasterPagesSelector::UpdateSelection (void)
174 // Iterate over all pages and for the selected ones put the name of
175 // their master page into a set.
176 USHORT nPageCount
= mrDocument
.GetSdPageCount(PK_STANDARD
);
178 ::std::set
<String
> aNames
;
181 for (nIndex
=0; nIndex
<nPageCount
&& bLoop
; nIndex
++)
183 pPage
= mrDocument
.GetSdPage (nIndex
, PK_STANDARD
);
184 if (pPage
!= NULL
&& pPage
->IsSelected())
186 if ( ! pPage
->TRG_HasMasterPage())
188 // One of the pages has no master page. This is an
189 // indicator for that this method is called in the middle of
190 // a document change and that the model is not in a valid
191 // state. Therefore we stop update the selection and wait
192 // for another call to UpdateSelection when the model is
198 SdrPage
& rMasterPage (pPage
->TRG_GetMasterPage());
199 SdPage
* pMasterPage
= static_cast<SdPage
*>(&rMasterPage
);
200 if (pMasterPage
!= NULL
)
201 aNames
.insert (pMasterPage
->GetName());
206 // Find the items for the master pages in the set.
207 USHORT
nItemCount (mpPageSet
->GetItemCount());
208 for (nIndex
=1; nIndex
<=nItemCount
&& bLoop
; nIndex
++)
210 String
sName (mpPageSet
->GetItemText (nIndex
));
211 if (aNames
.find(sName
) != aNames
.end())
213 mpPageSet
->SelectItem (nIndex
);
221 void CurrentMasterPagesSelector::Execute (SfxRequest
& rRequest
)
223 switch (rRequest
.GetSlot())
225 case SID_DELETE_MASTER_PAGE
:
227 // Check once again that the master page can safely be deleted,
229 SdPage
* pMasterPage
= GetSelectedMasterPage();
230 if (pMasterPage
!= NULL
231 && mrDocument
.GetMasterPageUserCount(pMasterPage
) > 0)
233 // Removing the precious flag so that the following call to
234 // RemoveUnnessesaryMasterPages() will remove this master page.
235 pMasterPage
->SetPrecious(false);
236 mrDocument
.RemoveUnnecessaryMasterPages(pMasterPage
, FALSE
, TRUE
);
242 MasterPagesSelector::Execute(rRequest
);
250 void CurrentMasterPagesSelector::GetState (SfxItemSet
& rItemSet
)
252 // Disable the SID_DELTE_MASTER slot when there is only one master page.
253 if (mrDocument
.GetMasterPageUserCount(GetSelectedMasterPage()) > 0)
255 rItemSet
.DisableItem(SID_DELETE_MASTER_PAGE
);
258 MasterPagesSelector::GetState(rItemSet
);
266 IMPL_LINK(CurrentMasterPagesSelector
,EventMultiplexerListener
,
267 sd::tools::EventMultiplexerEvent
*,pEvent
)
271 switch (pEvent
->meEventId
)
273 case sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
:
274 case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE
:
275 case sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
:
279 case sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER
:
280 // This is tricky. If a master page is removed, moved, or
281 // added we have to wait until both the notes master page
282 // and the standard master page have been removed, moved,
283 // or added. We do this by looking at the number of master
284 // pages which has to be odd in the consistent state (the
285 // handout master page is always present). If the number is
286 // even we ignore the hint.
287 if (mrBase
.GetDocument()->GetMasterPageCount()%2 == 1)
288 MasterPagesSelector::Fill();
291 case sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED
:
292 case sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED
:
293 case sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED
:
294 InvalidatePreview((const SdPage
*)pEvent
->mpUserData
);
305 void CurrentMasterPagesSelector::Notify (SfxBroadcaster
&, const SfxHint
& rHint
)
307 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
308 if (pSimpleHint
!= NULL
)
310 if (pSimpleHint
->GetId() == SFX_HINT_DOCCHANGED
)
312 // Is the edit view visible in the center pane?
313 ::boost::shared_ptr
<DrawViewShell
> pDrawViewShell (
314 ::boost::dynamic_pointer_cast
<DrawViewShell
>(mrBase
.GetMainViewShell()));
315 if (pDrawViewShell
.get() != NULL
)
317 // Is the edit view in master page mode?
318 if (pDrawViewShell
->GetEditMode() == EM_MASTERPAGE
)
320 // Mark the currently edited master page as precious.
321 SdPage
* pCurrentMasterPage
= pDrawViewShell
->getCurrentPage();
322 if (pCurrentMasterPage
!= NULL
)
323 pCurrentMasterPage
->SetPrecious(true);
333 } } } // end of namespace ::sd::toolpanel::controls