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