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