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 :
21 : #include "MasterPagesSelector.hxx"
22 :
23 : #include "MasterPageContainer.hxx"
24 : #include "DocumentHelper.hxx"
25 : #include "pres.hxx"
26 : #include "drawdoc.hxx"
27 : #include "DrawDocShell.hxx"
28 : #include "sdpage.hxx"
29 : #include "glob.hxx"
30 : #include "glob.hrc"
31 : #include "app.hrc"
32 : #include "res_bmp.hrc"
33 : #include "strings.hrc"
34 : #include "DrawViewShell.hxx"
35 : #include "DrawController.hxx"
36 : #include "SlideSorterViewShell.hxx"
37 : #include "PreviewValueSet.hxx"
38 : #include "ViewShellBase.hxx"
39 : #include "../TaskPaneShellManager.hxx"
40 : #include "taskpane/TitledControl.hxx"
41 : #include "taskpane/ControlContainer.hxx"
42 : #include "controller/SlideSorterController.hxx"
43 : #include "controller/SlsPageSelector.hxx"
44 : #include <sfx2/objface.hxx>
45 : #include "sdresid.hxx"
46 : #include "TemplateScanner.hxx"
47 : #include "drawview.hxx"
48 : #include <vcl/image.hxx>
49 : #include <svl/languageoptions.hxx>
50 : #include <sfx2/app.hxx>
51 : #include <sfx2/dispatch.hxx>
52 : #include <sfx2/mnumgr.hxx>
53 : #include <svl/itemset.hxx>
54 : #include <svl/eitem.hxx>
55 : #include <svx/dlgutil.hxx>
56 : #include <svx/svdpagv.hxx>
57 : #include <svx/svxids.hrc>
58 : #include "FrameView.hxx"
59 : #include "stlpool.hxx"
60 : #include "unmovss.hxx"
61 : #include <sfx2/request.hxx>
62 : #include <svl/itempool.hxx>
63 :
64 : using namespace ::sd::toolpanel::controls;
65 : #define MasterPagesSelector
66 : #include "sdslots.hxx"
67 :
68 : using namespace ::com::sun::star::text;
69 :
70 :
71 :
72 : namespace sd { namespace toolpanel { namespace controls {
73 :
74 :
75 44 : SFX_IMPL_INTERFACE(MasterPagesSelector, SfxShell,
76 : SdResId(STR_MASTERPAGESSELECTOR))
77 : {
78 11 : SFX_POPUPMENU_REGISTRATION( SdResId(RID_TASKPANE_MASTERPAGESSELECTOR_POPUP) );
79 11 : }
80 :
81 0 : TYPEINIT1(MasterPagesSelector, SfxShell);
82 :
83 :
84 :
85 0 : MasterPagesSelector::MasterPagesSelector (
86 : TreeNode* pParent,
87 : SdDrawDocument& rDocument,
88 : ViewShellBase& rBase,
89 : const ::boost::shared_ptr<MasterPageContainer>& rpContainer)
90 : : TreeNode (pParent),
91 : SfxShell(),
92 : maMutex(),
93 : mpContainer(rpContainer),
94 : mrDocument(rDocument),
95 0 : mpPageSet (new PreviewValueSet(pParent)),
96 : mrBase(rBase),
97 : mnDefaultClickAction(SID_TP_APPLY_TO_ALL_SLIDES),
98 : maPreviewUpdateQueue(),
99 : maCurrentItemList(),
100 : maTokenToValueSetIndex(),
101 0 : maLockedMasterPages()
102 : {
103 0 : SetPool (&rDocument.GetPool());
104 :
105 0 : mpPageSet->SetSelectHdl (
106 0 : LINK(this, MasterPagesSelector, ClickHandler));
107 : mpPageSet->SetRightMouseClickHandler (
108 0 : LINK(this, MasterPagesSelector, RightClickHandler));
109 : mpPageSet->SetContextMenuCallback (
110 0 : LINK(this, MasterPagesSelector, ContextMenuCallback));
111 0 : mpPageSet->SetStyle(mpPageSet->GetStyle() | WB_NO_DIRECTSELECT);
112 0 : mpPageSet->SetPreviewSize(mpContainer->GetPreviewSizePixel());
113 0 : mpPageSet->Show();
114 :
115 0 : Link aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
116 0 : mpContainer->AddChangeListener(aChangeListener);
117 0 : }
118 :
119 :
120 :
121 :
122 0 : MasterPagesSelector::~MasterPagesSelector (void)
123 : {
124 0 : Clear();
125 0 : mpPageSet.reset();
126 0 : UpdateLocks(ItemList());
127 :
128 0 : if (GetShellManager() != NULL)
129 0 : GetShellManager()->RemoveSubShell (this);
130 :
131 0 : Link aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
132 0 : mpContainer->RemoveChangeListener(aChangeListener);
133 0 : }
134 :
135 :
136 :
137 :
138 0 : void MasterPagesSelector::LateInit (void)
139 : {
140 0 : }
141 :
142 :
143 :
144 :
145 0 : sal_Int32 MasterPagesSelector::GetPreferredWidth (sal_Int32 nHeight)
146 : {
147 0 : const ::osl::MutexGuard aGuard (maMutex);
148 :
149 0 : return mpPageSet->GetPreferredWidth (nHeight);
150 : }
151 :
152 :
153 :
154 :
155 0 : sal_Int32 MasterPagesSelector::GetPreferredHeight (sal_Int32 nWidth)
156 : {
157 0 : const ::osl::MutexGuard aGuard (maMutex);
158 :
159 0 : return mpPageSet->GetPreferredHeight (nWidth);
160 : }
161 :
162 :
163 :
164 :
165 0 : Size MasterPagesSelector::GetPreferredSize (void)
166 : {
167 : int nPreferredWidth = GetPreferredWidth(
168 0 : mpPageSet->GetOutputSizePixel().Height());
169 0 : int nPreferredHeight = GetPreferredHeight(nPreferredWidth);
170 0 : return Size (nPreferredWidth, nPreferredHeight);
171 :
172 : }
173 :
174 :
175 :
176 :
177 0 : void MasterPagesSelector::UpdateLocks (const ItemList& rItemList)
178 : {
179 0 : ItemList aNewLockList;
180 :
181 : // In here we first lock the master pages in the given list and then
182 : // release the locks acquired in a previous call to this method. When
183 : // this were done the other way round the lock count of some master
184 : // pages might drop temporarily to 0 and would lead to unnecessary
185 : // deletion and re-creation of MasterPageDescriptor objects.
186 :
187 : // Lock the master pages in the given list.
188 0 : ItemList::const_iterator iItem;
189 0 : for (iItem=rItemList.begin(); iItem!=rItemList.end(); ++iItem)
190 : {
191 0 : mpContainer->AcquireToken(*iItem);
192 0 : aNewLockList.push_back(*iItem);
193 : }
194 :
195 : // Release the previously locked master pages.
196 0 : ItemList::const_iterator iPage;
197 0 : ItemList::const_iterator iEnd (maLockedMasterPages.end());
198 0 : for (iPage=maLockedMasterPages.begin(); iPage!=iEnd; ++iPage)
199 0 : mpContainer->ReleaseToken(*iPage);
200 :
201 0 : maLockedMasterPages.swap(aNewLockList);
202 0 : }
203 :
204 :
205 :
206 :
207 0 : void MasterPagesSelector::Fill (void)
208 : {
209 0 : ::std::auto_ptr<ItemList> pItemList (new ItemList());
210 :
211 0 : Fill(*pItemList);
212 :
213 0 : UpdateLocks(*pItemList);
214 0 : UpdateItemList(pItemList);
215 0 : }
216 :
217 :
218 :
219 :
220 0 : ResId MasterPagesSelector::GetContextMenuResId (void) const
221 : {
222 0 : return SdResId(RID_TASKPANE_MASTERPAGESSELECTOR_POPUP);
223 : }
224 :
225 :
226 :
227 :
228 0 : IMPL_LINK_NOARG(MasterPagesSelector, ClickHandler)
229 : {
230 : // We use the framework to assign the clicked-on master page because we
231 : // so use the same mechanism as the context menu does (where we do not
232 : // have the option to call the assignment method directly.)
233 0 : if (GetShellManager() != NULL)
234 0 : GetShellManager()->MoveToTop (this);
235 :
236 0 : SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
237 0 : if (pViewFrame != NULL)
238 : {
239 0 : SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
240 0 : if (pDispatcher != NULL)
241 0 : pDispatcher->Execute(mnDefaultClickAction);
242 : }
243 :
244 0 : return 0;
245 : }
246 :
247 :
248 :
249 :
250 0 : IMPL_LINK(MasterPagesSelector, RightClickHandler, MouseEvent*, pEvent)
251 : {
252 : // Here we only prepare the display of the context menu: the item under
253 : // the mouse is selected. The actual display of the context menu is
254 : // done in ContextMenuCallback which is called indirectly through
255 : // PreviewValueSet::Command().
256 0 : mpPageSet->GrabFocus ();
257 0 : mpPageSet->ReleaseMouse();
258 0 : if (GetDispatcher() != NULL && pEvent != NULL)
259 : {
260 0 : sal_uInt16 nIndex = mpPageSet->GetItemId (pEvent->GetPosPixel());
261 0 : if (nIndex > 0)
262 0 : mpPageSet->SelectItem (nIndex);
263 : }
264 0 : return 0;
265 : }
266 :
267 :
268 :
269 :
270 0 : IMPL_LINK(MasterPagesSelector, ContextMenuCallback, CommandEvent*, pEvent)
271 : {
272 : // Use the currently selected item and show the popup menu in its
273 : // center.
274 0 : if (GetShellManager() != NULL)
275 0 : GetShellManager()->MoveToTop (this);
276 0 : const sal_uInt16 nIndex = mpPageSet->GetSelectItemId();
277 0 : if (nIndex > 0 && pEvent!=NULL)
278 : {
279 : // The position of the upper left corner of the context menu is
280 : // taken either from the mouse position (when the command was sent
281 : // as reaction to a right click) or in the center of the selected
282 : // item (when the command was sent as reaction to Shift+F10.)
283 0 : Point aPosition (pEvent->GetMousePosPixel());
284 0 : if ( ! pEvent->IsMouseEvent())
285 : {
286 0 : Rectangle aBBox (mpPageSet->GetItemRect(nIndex));
287 0 : aPosition = aBBox.Center();
288 : }
289 :
290 0 : const ResId aPopupResId (GetContextMenuResId());
291 : mrBase.GetViewFrame()->GetDispatcher()->ExecutePopup(
292 : aPopupResId,
293 0 : mpPageSet.get(),
294 0 : &aPosition);
295 : }
296 :
297 0 : return 0;
298 : }
299 :
300 :
301 :
302 :
303 0 : IMPL_LINK(MasterPagesSelector, ContainerChangeListener, MasterPageContainerChangeEvent*, pEvent)
304 : {
305 0 : if (pEvent)
306 0 : NotifyContainerChangeEvent(*pEvent);
307 0 : return 0;
308 : }
309 :
310 :
311 :
312 :
313 0 : SdPage* MasterPagesSelector::GetSelectedMasterPage (void)
314 : {
315 0 : const ::osl::MutexGuard aGuard (maMutex);
316 :
317 0 : SdPage* pMasterPage = NULL;
318 0 : sal_uInt16 nIndex = mpPageSet->GetSelectItemId();
319 0 : UserData* pData = GetUserData(nIndex);
320 0 : if (pData != NULL)
321 : {
322 0 : pMasterPage = mpContainer->GetPageObjectForToken(pData->second);
323 : }
324 0 : return pMasterPage;
325 : }
326 :
327 :
328 :
329 :
330 : /** Assemble a list of all slides of the document and pass it to
331 : AssignMasterPageToPageList().
332 : */
333 0 : void MasterPagesSelector::AssignMasterPageToAllSlides (SdPage* pMasterPage)
334 : {
335 0 : if (pMasterPage == NULL)
336 0 : return;
337 :
338 0 : sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD);
339 0 : if (nPageCount == 0)
340 0 : return;
341 :
342 : // Get a list of all pages. As a little optimization we only
343 : // include pages that do not already have the given master page
344 : // assigned.
345 0 : OUString sFullLayoutName(pMasterPage->GetLayoutName());
346 : ::sd::slidesorter::SharedPageSelection pPageList (
347 0 : new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
348 0 : for (sal_uInt16 nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
349 : {
350 0 : SdPage* pPage = mrDocument.GetSdPage (nPageIndex, PK_STANDARD);
351 0 : if (pPage != NULL && pPage->GetLayoutName() != sFullLayoutName)
352 : {
353 0 : pPageList->push_back (pPage);
354 : }
355 : }
356 :
357 0 : AssignMasterPageToPageList(pMasterPage, pPageList);
358 : }
359 :
360 :
361 :
362 :
363 : /** Assemble a list of the currently selected slides (selected in a visible
364 : slide sorter) and pass it to AssignMasterPageToPageList().
365 : */
366 0 : void MasterPagesSelector::AssignMasterPageToSelectedSlides (
367 : SdPage* pMasterPage)
368 : {
369 : using namespace ::sd::slidesorter;
370 : using namespace ::sd::slidesorter::controller;
371 :
372 0 : if (pMasterPage == NULL)
373 0 : return;
374 :
375 : // Find a visible slide sorter.
376 0 : SlideSorterViewShell* pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
377 0 : if (pSlideSorter == NULL)
378 0 : return;
379 :
380 : // Get a list of selected pages.
381 0 : SharedPageSelection pPageSelection = pSlideSorter->GetPageSelection();
382 0 : if (pPageSelection->empty())
383 0 : return;
384 :
385 0 : AssignMasterPageToPageList(pMasterPage, pPageSelection);
386 :
387 : // Restore the previous selection.
388 0 : pSlideSorter->SetPageSelection(pPageSelection);
389 : }
390 :
391 :
392 :
393 :
394 0 : void MasterPagesSelector::AssignMasterPageToPageList (
395 : SdPage* pMasterPage,
396 : const ::sd::slidesorter::SharedPageSelection& rPageList)
397 : {
398 0 : DocumentHelper::AssignMasterPageToPageList(mrDocument, pMasterPage, rPageList);
399 0 : }
400 :
401 :
402 :
403 :
404 0 : void MasterPagesSelector::NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent)
405 : {
406 0 : const ::osl::MutexGuard aGuard (maMutex);
407 :
408 0 : switch (rEvent.meEventType)
409 : {
410 : case MasterPageContainerChangeEvent::SIZE_CHANGED:
411 0 : mpPageSet->SetPreviewSize(mpContainer->GetPreviewSizePixel());
412 0 : UpdateAllPreviews();
413 0 : break;
414 :
415 : case MasterPageContainerChangeEvent::PREVIEW_CHANGED:
416 : {
417 0 : int nIndex (GetIndexForToken(rEvent.maChildToken));
418 0 : if (nIndex >= 0)
419 : {
420 0 : mpPageSet->SetItemImage (
421 : (sal_uInt16)nIndex,
422 0 : mpContainer->GetPreviewForToken(rEvent.maChildToken));
423 0 : mpPageSet->Invalidate(mpPageSet->GetItemRect((sal_uInt16)nIndex));
424 : }
425 : }
426 0 : break;
427 :
428 : case MasterPageContainerChangeEvent::DATA_CHANGED:
429 : {
430 0 : InvalidateItem(rEvent.maChildToken);
431 0 : Fill();
432 : }
433 0 : break;
434 :
435 : case MasterPageContainerChangeEvent::CHILD_REMOVED:
436 : {
437 0 : int nIndex (GetIndexForToken(rEvent.maChildToken));
438 0 : SetItem(nIndex, MasterPageContainer::NIL_TOKEN);
439 : }
440 :
441 : default:
442 0 : break;
443 0 : }
444 0 : }
445 :
446 :
447 :
448 :
449 0 : MasterPagesSelector::UserData* MasterPagesSelector::CreateUserData (
450 : int nIndex,
451 : MasterPageContainer::Token aToken) const
452 : {
453 0 : return new UserData(nIndex,aToken);
454 : }
455 :
456 :
457 :
458 :
459 0 : MasterPagesSelector::UserData* MasterPagesSelector::GetUserData (int nIndex) const
460 : {
461 0 : const ::osl::MutexGuard aGuard (maMutex);
462 :
463 0 : if (nIndex>0 && static_cast<unsigned int>(nIndex)<=mpPageSet->GetItemCount())
464 0 : return reinterpret_cast<UserData*>(mpPageSet->GetItemData((sal_uInt16)nIndex));
465 : else
466 0 : return NULL;
467 : }
468 :
469 :
470 :
471 :
472 0 : void MasterPagesSelector::SetUserData (int nIndex, UserData* pData)
473 : {
474 0 : const ::osl::MutexGuard aGuard (maMutex);
475 :
476 0 : if (nIndex>0 && static_cast<unsigned int>(nIndex)<=mpPageSet->GetItemCount())
477 : {
478 0 : UserData* pOldData = GetUserData(nIndex);
479 0 : if (pOldData!=NULL && pOldData!=pData)
480 0 : delete pOldData;
481 0 : mpPageSet->SetItemData((sal_uInt16)nIndex, pData);
482 0 : }
483 0 : }
484 :
485 :
486 :
487 :
488 0 : bool MasterPagesSelector::IsResizable (void)
489 : {
490 0 : return false;
491 : }
492 :
493 :
494 :
495 :
496 0 : ::Window* MasterPagesSelector::GetWindow (void)
497 : {
498 0 : return mpPageSet.get();
499 : }
500 :
501 :
502 :
503 :
504 0 : sal_Int32 MasterPagesSelector::GetMinimumWidth (void)
505 : {
506 0 : return mpContainer->GetPreviewSizePixel().Width() + 2*3;
507 : }
508 :
509 :
510 :
511 :
512 0 : void MasterPagesSelector::UpdateSelection (void)
513 : {
514 0 : }
515 :
516 :
517 :
518 :
519 0 : void MasterPagesSelector::Execute (SfxRequest& rRequest)
520 : {
521 0 : switch (rRequest.GetSlot())
522 : {
523 : case SID_TP_APPLY_TO_ALL_SLIDES:
524 0 : mrBase.SetBusyState (true);
525 0 : AssignMasterPageToAllSlides (GetSelectedMasterPage());
526 0 : mrBase.SetBusyState (false);
527 0 : break;
528 :
529 : case SID_TP_APPLY_TO_SELECTED_SLIDES:
530 0 : mrBase.SetBusyState (true);
531 0 : AssignMasterPageToSelectedSlides (GetSelectedMasterPage());
532 0 : mrBase.SetBusyState (false);
533 0 : break;
534 :
535 : case SID_TP_USE_FOR_NEW_PRESENTATIONS:
536 : DBG_ASSERT (false,
537 : "Using slides as default for new presentations"
538 : " is not yet implemented");
539 0 : break;
540 :
541 : case SID_TP_SHOW_SMALL_PREVIEW:
542 : case SID_TP_SHOW_LARGE_PREVIEW:
543 : {
544 0 : mrBase.SetBusyState (true);
545 : mpContainer->SetPreviewSize(
546 0 : rRequest.GetSlot()==SID_TP_SHOW_SMALL_PREVIEW
547 : ? MasterPageContainer::SMALL
548 0 : : MasterPageContainer::LARGE);
549 0 : mrBase.SetBusyState (false);
550 0 : break;
551 : }
552 :
553 : case SID_TP_EDIT_MASTER:
554 : {
555 : using namespace ::com::sun::star;
556 0 : uno::Reference<drawing::XDrawPage> xSelectedMaster;
557 0 : SdPage* pMasterPage = GetSelectedMasterPage();
558 : assert(pMasterPage); //rhbz#902884
559 0 : if (pMasterPage)
560 0 : xSelectedMaster = uno::Reference<drawing::XDrawPage>(pMasterPage->getUnoPage(), uno::UNO_QUERY);
561 0 : SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
562 0 : if (pViewFrame != NULL && xSelectedMaster.is())
563 : {
564 0 : SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
565 0 : if (pDispatcher != NULL)
566 : {
567 0 : sal_uInt16 nIndex = mpPageSet->GetSelectItemId();
568 0 : pDispatcher->Execute(SID_MASTERPAGE, SFX_CALLMODE_SYNCHRON);
569 0 : mpPageSet->SelectItem (nIndex);
570 0 : mrBase.GetDrawController().setCurrentPage(xSelectedMaster);
571 : }
572 : }
573 0 : break;
574 : }
575 :
576 : case SID_CUT:
577 : case SID_COPY:
578 : case SID_PASTE:
579 : // Cut, copy, and paste are not supported and thus are ignored.
580 0 : break;
581 : }
582 0 : }
583 :
584 :
585 :
586 :
587 0 : void MasterPagesSelector::GetState (SfxItemSet& rItemSet)
588 : {
589 0 : if (mpContainer->GetPreviewSize() == MasterPageContainer::SMALL)
590 0 : rItemSet.DisableItem (SID_TP_SHOW_SMALL_PREVIEW);
591 : else
592 0 : rItemSet.DisableItem (SID_TP_SHOW_LARGE_PREVIEW);
593 :
594 : // Cut and paste is not supported so do not show the menu entries.
595 0 : rItemSet.DisableItem (SID_CUT);
596 0 : rItemSet.DisableItem (SID_COPY);
597 0 : rItemSet.DisableItem (SID_PASTE);
598 0 : }
599 :
600 :
601 :
602 :
603 0 : void MasterPagesSelector::SetItem (
604 : sal_uInt16 nIndex,
605 : MasterPageContainer::Token aToken)
606 : {
607 0 : const ::osl::MutexGuard aGuard (maMutex);
608 :
609 0 : RemoveTokenToIndexEntry(nIndex,aToken);
610 :
611 0 : if (nIndex > 0)
612 : {
613 0 : if (aToken != MasterPageContainer::NIL_TOKEN)
614 : {
615 0 : Image aPreview (mpContainer->GetPreviewForToken(aToken));
616 0 : MasterPageContainer::PreviewState eState (mpContainer->GetPreviewState(aToken));
617 :
618 0 : if (aPreview.GetSizePixel().Width()>0)
619 : {
620 0 : if (mpPageSet->GetItemPos(nIndex) != VALUESET_ITEM_NOTFOUND)
621 : {
622 0 : mpPageSet->SetItemImage(nIndex,aPreview);
623 0 : mpPageSet->SetItemText(nIndex, mpContainer->GetPageNameForToken(aToken));
624 : }
625 : else
626 : {
627 0 : mpPageSet->InsertItem (
628 : nIndex,
629 : aPreview,
630 : mpContainer->GetPageNameForToken(aToken),
631 0 : nIndex);
632 : }
633 0 : SetUserData(nIndex, CreateUserData(nIndex,aToken));
634 :
635 0 : AddTokenToIndexEntry(nIndex,aToken);
636 : }
637 :
638 0 : if (eState == MasterPageContainer::PS_CREATABLE)
639 0 : mpContainer->RequestPreview(aToken);
640 : }
641 : else
642 : {
643 0 : mpPageSet->RemoveItem(nIndex);
644 : }
645 0 : }
646 :
647 0 : }
648 :
649 :
650 :
651 :
652 0 : void MasterPagesSelector::AddTokenToIndexEntry (
653 : sal_uInt16 nIndex,
654 : MasterPageContainer::Token aToken)
655 : {
656 0 : const ::osl::MutexGuard aGuard (maMutex);
657 :
658 0 : maTokenToValueSetIndex[aToken] = nIndex;
659 0 : }
660 :
661 :
662 :
663 :
664 0 : void MasterPagesSelector::RemoveTokenToIndexEntry (
665 : sal_uInt16 nIndex,
666 : MasterPageContainer::Token aNewToken)
667 : {
668 0 : const ::osl::MutexGuard aGuard (maMutex);
669 :
670 0 : UserData* pData = GetUserData(nIndex);
671 0 : if (pData != NULL)
672 : {
673 : // Get the token that the index pointed to previously.
674 0 : MasterPageContainer::Token aOldToken (pData->second);
675 :
676 0 : if (aNewToken != aOldToken
677 0 : && nIndex == GetIndexForToken(aOldToken))
678 : {
679 0 : maTokenToValueSetIndex[aOldToken] = 0;
680 : }
681 0 : }
682 0 : }
683 :
684 :
685 :
686 :
687 0 : void MasterPagesSelector::InvalidatePreview (const SdPage* pPage)
688 : {
689 0 : const ::osl::MutexGuard aGuard (maMutex);
690 :
691 0 : for (sal_uInt16 nIndex=1; nIndex<=mpPageSet->GetItemCount(); nIndex++)
692 : {
693 0 : UserData* pData = GetUserData(nIndex);
694 0 : if (pData != NULL)
695 : {
696 0 : MasterPageContainer::Token aToken (pData->second);
697 0 : if (pPage == mpContainer->GetPageObjectForToken(aToken,false))
698 : {
699 0 : mpContainer->InvalidatePreview(aToken);
700 0 : mpContainer->RequestPreview(aToken);
701 0 : break;
702 : }
703 : }
704 0 : }
705 0 : }
706 :
707 0 : void MasterPagesSelector::UpdateAllPreviews (void)
708 : {
709 0 : const ::osl::MutexGuard aGuard (maMutex);
710 :
711 0 : for (sal_uInt16 nIndex=1; nIndex<=mpPageSet->GetItemCount(); nIndex++)
712 : {
713 0 : UserData* pData = GetUserData(nIndex);
714 0 : if (pData != NULL)
715 : {
716 0 : MasterPageContainer::Token aToken (pData->second);
717 0 : mpPageSet->SetItemImage(
718 : nIndex,
719 0 : mpContainer->GetPreviewForToken(aToken));
720 0 : if (mpContainer->GetPreviewState(aToken) == MasterPageContainer::PS_CREATABLE)
721 0 : mpContainer->RequestPreview(aToken);
722 : }
723 : }
724 0 : mpPageSet->Rearrange(true);
725 0 : }
726 :
727 :
728 :
729 :
730 0 : void MasterPagesSelector::ClearPageSet (void)
731 : {
732 0 : const ::osl::MutexGuard aGuard (maMutex);
733 :
734 0 : for (sal_uInt16 nIndex=1; nIndex<=mpPageSet->GetItemCount(); nIndex++)
735 : {
736 0 : UserData* pData = GetUserData(nIndex);
737 0 : if (pData != NULL)
738 0 : delete pData;
739 : }
740 0 : mpPageSet->Clear();
741 0 : }
742 :
743 :
744 :
745 :
746 0 : void MasterPagesSelector::SetHelpId( const OString& aId )
747 : {
748 0 : const ::osl::MutexGuard aGuard (maMutex);
749 :
750 0 : mpPageSet->SetHelpId( aId );
751 0 : }
752 :
753 :
754 :
755 :
756 0 : sal_Int32 MasterPagesSelector::GetIndexForToken (MasterPageContainer::Token aToken) const
757 : {
758 0 : const ::osl::MutexGuard aGuard (maMutex);
759 :
760 0 : TokenToValueSetIndex::const_iterator iIndex (maTokenToValueSetIndex.find(aToken));
761 0 : if (iIndex != maTokenToValueSetIndex.end())
762 0 : return iIndex->second;
763 : else
764 0 : return -1;
765 : }
766 :
767 :
768 :
769 :
770 0 : void MasterPagesSelector::Clear (void)
771 : {
772 0 : const ::osl::MutexGuard aGuard (maMutex);
773 :
774 0 : ClearPageSet();
775 0 : }
776 :
777 :
778 :
779 :
780 0 : void MasterPagesSelector::InvalidateItem (MasterPageContainer::Token aToken)
781 : {
782 0 : const ::osl::MutexGuard aGuard (maMutex);
783 :
784 0 : ItemList::iterator iItem;
785 0 : for (iItem=maCurrentItemList.begin(); iItem!=maCurrentItemList.end(); ++iItem)
786 : {
787 0 : if (*iItem == aToken)
788 : {
789 0 : *iItem = MasterPageContainer::NIL_TOKEN;
790 0 : break;
791 : }
792 0 : }
793 0 : }
794 :
795 :
796 :
797 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
798 0 : void MasterPagesSelector::UpdateItemList (::std::auto_ptr<ItemList> pNewItemList)
799 : {
800 0 : const ::osl::MutexGuard aGuard (maMutex);
801 :
802 0 : ItemList::const_iterator iNewItem (pNewItemList->begin());
803 0 : ItemList::const_iterator iCurrentItem (maCurrentItemList.begin());
804 0 : ItemList::const_iterator iNewEnd (pNewItemList->end());
805 0 : ItemList::const_iterator iCurrentEnd (maCurrentItemList.end());
806 0 : sal_uInt16 nIndex (1);
807 :
808 : // Update existing items.
809 0 : for ( ; iNewItem!=iNewEnd && iCurrentItem!=iCurrentEnd; ++iNewItem, ++iCurrentItem,++nIndex)
810 : {
811 0 : if (*iNewItem != *iCurrentItem)
812 : {
813 0 : SetItem(nIndex,*iNewItem);
814 : }
815 : }
816 :
817 : // Append new items.
818 0 : for ( ; iNewItem!=iNewEnd; ++iNewItem,++nIndex)
819 : {
820 0 : SetItem(nIndex,*iNewItem);
821 : }
822 :
823 : // Remove trailing items.
824 0 : for ( ; iCurrentItem!=iCurrentEnd; ++iCurrentItem,++nIndex)
825 : {
826 0 : SetItem(nIndex,MasterPageContainer::NIL_TOKEN);
827 : }
828 :
829 0 : maCurrentItemList.swap(*pNewItemList);
830 :
831 0 : mpPageSet->Rearrange();
832 0 : if (GetParentNode() != NULL)
833 0 : GetParentNode()->RequestResize();
834 0 : }
835 : SAL_WNODEPRECATED_DECLARATIONS_POP
836 :
837 :
838 :
839 :
840 33 : } } } // end of namespace ::sd::toolpanel::controls
841 :
842 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|