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 "DrawViewShell.hxx"
38 #include "drawdoc.hxx"
40 #include "MasterPageContainer.hxx"
41 #include "MasterPageDescriptor.hxx"
42 #include "EventMultiplexer.hxx"
44 #include "DrawDocShell.hxx"
45 #include "DrawViewShell.hxx"
46 #include "res_bmp.hrc"
47 #include "sdresid.hxx"
49 #include <vcl/image.hxx>
50 #include <svx/svdmodel.hxx>
51 #include <sfx2/request.hxx>
56 using namespace ::com::sun::star
;
58 namespace sd
{ namespace toolpanel
{ namespace controls
{
61 CurrentMasterPagesSelector::CurrentMasterPagesSelector (
63 SdDrawDocument
& rDocument
,
65 const ::boost::shared_ptr
<MasterPageContainer
>& rpContainer
)
66 : MasterPagesSelector (pParent
, rDocument
, rBase
, rpContainer
)
68 SetName(String(RTL_CONSTASCII_USTRINGPARAM("CurrentMasterPagesSelector")));
70 // For this master page selector only we change the default action for
72 mnDefaultClickAction
= SID_TP_APPLY_TO_SELECTED_SLIDES
;
74 Link
aLink (LINK(this,CurrentMasterPagesSelector
,EventMultiplexerListener
));
75 rBase
.GetEventMultiplexer()->AddEventListener(aLink
,
76 sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
77 | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
78 | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
79 | sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER
80 | sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED
81 | sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED
82 | sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED
);
88 CurrentMasterPagesSelector::~CurrentMasterPagesSelector (void)
90 if (mrDocument
.GetDocSh() != NULL
)
92 EndListening(*mrDocument
.GetDocSh());
96 OSL_ASSERT(mrDocument
.GetDocSh() != NULL
);
99 Link
aLink (LINK(this,CurrentMasterPagesSelector
,EventMultiplexerListener
));
100 mrBase
.GetEventMultiplexer()->RemoveEventListener(aLink
);
106 void CurrentMasterPagesSelector::LateInit (void)
108 MasterPagesSelector::LateInit();
109 MasterPagesSelector::Fill();
110 if (mrDocument
.GetDocSh() != NULL
)
112 StartListening(*mrDocument
.GetDocSh());
116 OSL_ASSERT(mrDocument
.GetDocSh() != NULL
);
123 void CurrentMasterPagesSelector::Fill (ItemList
& rItemList
)
125 USHORT nPageCount
= mrDocument
.GetMasterSdPageCount(PK_STANDARD
);
127 // Remember the names of the master pages that have been inserted to
128 // avoid double insertion.
129 ::std::set
<String
> aMasterPageNames
;
130 for (USHORT nIndex
=0; nIndex
<nPageCount
; nIndex
++)
132 pMasterPage
= mrDocument
.GetMasterSdPage (nIndex
, PK_STANDARD
);
133 if (pMasterPage
== NULL
)
136 // Use the name of the master page to avoid duplicate entries.
137 String
sName (pMasterPage
->GetName());
138 if (aMasterPageNames
.find(sName
)!=aMasterPageNames
.end())
140 aMasterPageNames
.insert (sName
);
142 // Look up the master page in the container and, when it is not yet
144 MasterPageContainer::Token aToken
= mpContainer
->GetTokenForPageObject(pMasterPage
);
145 if (aToken
== MasterPageContainer::NIL_TOKEN
)
147 SharedMasterPageDescriptor
pDescriptor (new MasterPageDescriptor(
148 MasterPageContainer::MASTERPAGE
,
151 pMasterPage
->GetName(),
153 pMasterPage
->IsPrecious(),
154 ::boost::shared_ptr
<PageObjectProvider
>(new ExistingPageProvider(pMasterPage
)),
155 ::boost::shared_ptr
<PreviewProvider
>(new PagePreviewProvider())));
156 aToken
= mpContainer
->PutMasterPage(pDescriptor
);
159 rItemList
.push_back(aToken
);
166 ResId
CurrentMasterPagesSelector::GetContextMenuResId (void) const
168 return SdResId(RID_TASKPANE_CURRENT_MASTERPAGESSELECTOR_POPUP
);
174 void CurrentMasterPagesSelector::UpdateSelection (void)
176 // Iterate over all pages and for the selected ones put the name of
177 // their master page into a set.
178 USHORT nPageCount
= mrDocument
.GetSdPageCount(PK_STANDARD
);
180 ::std::set
<String
> aNames
;
183 for (nIndex
=0; nIndex
<nPageCount
&& bLoop
; nIndex
++)
185 pPage
= mrDocument
.GetSdPage (nIndex
, PK_STANDARD
);
186 if (pPage
!= NULL
&& pPage
->IsSelected())
188 if ( ! pPage
->TRG_HasMasterPage())
190 // One of the pages has no master page. This is an
191 // indicator for that this method is called in the middle of
192 // a document change and that the model is not in a valid
193 // state. Therefore we stop update the selection and wait
194 // for another call to UpdateSelection when the model is
200 SdrPage
& rMasterPage (pPage
->TRG_GetMasterPage());
201 SdPage
* pMasterPage
= static_cast<SdPage
*>(&rMasterPage
);
202 if (pMasterPage
!= NULL
)
203 aNames
.insert (pMasterPage
->GetName());
208 // Find the items for the master pages in the set.
209 USHORT
nItemCount (mpPageSet
->GetItemCount());
210 for (nIndex
=1; nIndex
<=nItemCount
&& bLoop
; nIndex
++)
212 String
sName (mpPageSet
->GetItemText (nIndex
));
213 if (aNames
.find(sName
) != aNames
.end())
215 mpPageSet
->SelectItem (nIndex
);
223 void CurrentMasterPagesSelector::Execute (SfxRequest
& rRequest
)
225 switch (rRequest
.GetSlot())
227 case SID_DELETE_MASTER_PAGE
:
229 // Check once again that the master page can safely be deleted,
231 SdPage
* pMasterPage
= GetSelectedMasterPage();
232 if (pMasterPage
!= NULL
233 && mrDocument
.GetMasterPageUserCount(pMasterPage
) > 0)
235 // Removing the precious flag so that the following call to
236 // RemoveUnnessesaryMasterPages() will remove this master page.
237 pMasterPage
->SetPrecious(false);
238 mrDocument
.RemoveUnnecessaryMasterPages(pMasterPage
, FALSE
, TRUE
);
244 MasterPagesSelector::Execute(rRequest
);
252 void CurrentMasterPagesSelector::GetState (SfxItemSet
& rItemSet
)
254 // Disable the SID_DELTE_MASTER slot when there is only one master page.
255 if (rItemSet
.GetItemState(SID_DELETE_MASTER_PAGE
) == SFX_ITEM_AVAILABLE
256 && mrDocument
.GetMasterPageUserCount(GetSelectedMasterPage()) > 0)
258 rItemSet
.DisableItem(SID_DELETE_MASTER_PAGE
);
261 ::boost::shared_ptr
<DrawViewShell
> pDrawViewShell (
262 ::boost::dynamic_pointer_cast
<DrawViewShell
>(mrBase
.GetMainViewShell()));
263 if (rItemSet
.GetItemState(SID_TP_EDIT_MASTER
) == SFX_ITEM_AVAILABLE
265 && pDrawViewShell
->GetEditMode() == EM_MASTERPAGE
)
267 rItemSet
.DisableItem (SID_TP_EDIT_MASTER
);
270 MasterPagesSelector::GetState(rItemSet
);
278 IMPL_LINK(CurrentMasterPagesSelector
,EventMultiplexerListener
,
279 sd::tools::EventMultiplexerEvent
*,pEvent
)
283 switch (pEvent
->meEventId
)
285 case sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
:
286 case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
:
287 case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
:
288 case sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
:
292 case sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER
:
293 // This is tricky. If a master page is removed, moved, or
294 // added we have to wait until both the notes master page
295 // and the standard master page have been removed, moved,
296 // or added. We do this by looking at the number of master
297 // pages which has to be odd in the consistent state (the
298 // handout master page is always present). If the number is
299 // even we ignore the hint.
300 if (mrBase
.GetDocument()->GetMasterPageCount()%2 == 1)
301 MasterPagesSelector::Fill();
304 case sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED
:
305 case sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED
:
306 case sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED
:
307 InvalidatePreview((const SdPage
*)pEvent
->mpUserData
);
318 void CurrentMasterPagesSelector::Notify (SfxBroadcaster
&, const SfxHint
& rHint
)
320 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
321 if (pSimpleHint
!= NULL
)
323 if (pSimpleHint
->GetId() == SFX_HINT_DOCCHANGED
)
325 // Is the edit view visible in the center pane?
326 ::boost::shared_ptr
<DrawViewShell
> pDrawViewShell (
327 ::boost::dynamic_pointer_cast
<DrawViewShell
>(mrBase
.GetMainViewShell()));
328 if (pDrawViewShell
.get() != NULL
)
330 // Is the edit view in master page mode?
331 if (pDrawViewShell
->GetEditMode() == EM_MASTERPAGE
)
333 // Mark the currently edited master page as precious.
334 SdPage
* pCurrentMasterPage
= pDrawViewShell
->getCurrentPage();
335 if (pCurrentMasterPage
!= NULL
)
336 pCurrentMasterPage
->SetPrecious(true);
346 } } } // end of namespace ::sd::toolpanel::controls