15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55b190011SAndrew Rist  * distributed with this work for additional information
65b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist  * "License"); you may not use this file except in compliance
95b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
105b190011SAndrew Rist  *
115b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125b190011SAndrew Rist  *
135b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist  * software distributed under the License is distributed on an
155b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
175b190011SAndrew Rist  * specific language governing permissions and limitations
185b190011SAndrew Rist  * under the License.
195b190011SAndrew Rist  *
205b190011SAndrew Rist  *************************************************************/
215b190011SAndrew Rist 
22cdf0e10cSrcweir #include "precompiled_sd.hxx"
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "MasterPagesSelector.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "MasterPageContainer.hxx"
27cdf0e10cSrcweir #include "DocumentHelper.hxx"
285d65efa0SAndre Fischer #include "SidebarShellManager.hxx"
29cdf0e10cSrcweir #include "pres.hxx"
30cdf0e10cSrcweir #include "drawdoc.hxx"
31cdf0e10cSrcweir #include "DrawDocShell.hxx"
32cdf0e10cSrcweir #include "sdpage.hxx"
33cdf0e10cSrcweir #include "glob.hxx"
34cdf0e10cSrcweir #include "glob.hrc"
35cdf0e10cSrcweir #include "app.hrc"
36cdf0e10cSrcweir #include "res_bmp.hrc"
37cdf0e10cSrcweir #include "strings.hrc"
38cdf0e10cSrcweir #include "DrawViewShell.hxx"
39cdf0e10cSrcweir #include "DrawController.hxx"
40cdf0e10cSrcweir #include "SlideSorterViewShell.hxx"
41cdf0e10cSrcweir #include "PreviewValueSet.hxx"
42cdf0e10cSrcweir #include "ViewShellBase.hxx"
43cdf0e10cSrcweir #include <sfx2/objface.hxx>
44cdf0e10cSrcweir #include "sdresid.hxx"
45cdf0e10cSrcweir #include "drawview.hxx"
46cdf0e10cSrcweir #include <vcl/image.hxx>
4702c50d82SAndre Fischer #include <vcl/floatwin.hxx>
48cdf0e10cSrcweir #include <svl/languageoptions.hxx>
49cdf0e10cSrcweir #include <sfx2/app.hxx>
50cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
51cdf0e10cSrcweir #include <sfx2/mnumgr.hxx>
52cdf0e10cSrcweir #include <svl/itemset.hxx>
53cdf0e10cSrcweir #include <svl/eitem.hxx>
54cdf0e10cSrcweir #include <svx/dlgutil.hxx>
55cdf0e10cSrcweir #include <svx/svdpagv.hxx>
56cdf0e10cSrcweir #include <svx/svxids.hrc>
57cdf0e10cSrcweir #include "FrameView.hxx"
58cdf0e10cSrcweir #include "sdpage.hxx"
59cdf0e10cSrcweir #include "stlpool.hxx"
60cdf0e10cSrcweir #include "unmovss.hxx"
61cdf0e10cSrcweir #include <sfx2/request.hxx>
62cdf0e10cSrcweir #include <svl/itempool.hxx>
63*37fee4fdSAndre Fischer #include <sfx2/sidebar/Theme.hxx>
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 
66cdf0e10cSrcweir using namespace ::com::sun::star::text;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
707a32b0c8SAndre Fischer namespace sd { namespace sidebar {
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
MasterPagesSelector(::Window * pParent,SdDrawDocument & rDocument,ViewShellBase & rBase,const::boost::shared_ptr<MasterPageContainer> & rpContainer,const cssu::Reference<css::ui::XSidebar> & rxSidebar)73cdf0e10cSrcweir MasterPagesSelector::MasterPagesSelector (
747a32b0c8SAndre Fischer     ::Window* pParent,
75cdf0e10cSrcweir     SdDrawDocument& rDocument,
76cdf0e10cSrcweir     ViewShellBase& rBase,
7702c50d82SAndre Fischer     const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
7802c50d82SAndre Fischer     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
7902c50d82SAndre Fischer     : PreviewValueSet(pParent),
80cdf0e10cSrcweir       maMutex(),
81cdf0e10cSrcweir       mpContainer(rpContainer),
82cdf0e10cSrcweir       mrDocument(rDocument),
83cdf0e10cSrcweir       mrBase(rBase),
84cdf0e10cSrcweir       mnDefaultClickAction(SID_TP_APPLY_TO_ALL_SLIDES),
85cdf0e10cSrcweir       maPreviewUpdateQueue(),
86cdf0e10cSrcweir       maCurrentItemList(),
87cdf0e10cSrcweir       maTokenToValueSetIndex(),
887a32b0c8SAndre Fischer       maLockedMasterPages(),
8902c50d82SAndre Fischer       mxSidebar(rxSidebar)
90cdf0e10cSrcweir {
917a32b0c8SAndre Fischer     PreviewValueSet::SetSelectHdl (
92cdf0e10cSrcweir         LINK(this, MasterPagesSelector, ClickHandler));
937a32b0c8SAndre Fischer 	PreviewValueSet::SetRightMouseClickHandler (
94cdf0e10cSrcweir         LINK(this, MasterPagesSelector, RightClickHandler));
957a32b0c8SAndre Fischer     PreviewValueSet::SetStyle(PreviewValueSet::GetStyle() | WB_NO_DIRECTSELECT);
967a32b0c8SAndre Fischer     PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel());
977a32b0c8SAndre Fischer     PreviewValueSet::Show();
98cdf0e10cSrcweir 
99*37fee4fdSAndre Fischer     SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
100*37fee4fdSAndre Fischer     SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
101*37fee4fdSAndre Fischer 
102cdf0e10cSrcweir     Link aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
103cdf0e10cSrcweir     mpContainer->AddChangeListener(aChangeListener);
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
~MasterPagesSelector(void)109cdf0e10cSrcweir MasterPagesSelector::~MasterPagesSelector (void)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     Clear();
112cdf0e10cSrcweir     UpdateLocks(ItemList());
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     Link aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
115cdf0e10cSrcweir     mpContainer->RemoveChangeListener(aChangeListener);
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
LateInit(void)121cdf0e10cSrcweir void MasterPagesSelector::LateInit (void)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
GetPreferredWidth(sal_Int32 nHeight)128cdf0e10cSrcweir sal_Int32 MasterPagesSelector::GetPreferredWidth (sal_Int32 nHeight)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
131cdf0e10cSrcweir 
1327a32b0c8SAndre Fischer     return PreviewValueSet::GetPreferredWidth (nHeight);
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
GetPreferredHeight(sal_Int32 nWidth)138cdf0e10cSrcweir sal_Int32 MasterPagesSelector::GetPreferredHeight (sal_Int32 nWidth)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
141cdf0e10cSrcweir 
1427a32b0c8SAndre Fischer     return PreviewValueSet::GetPreferredHeight (nWidth);
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 
GetPreferredSize(void)148cdf0e10cSrcweir Size MasterPagesSelector::GetPreferredSize (void)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     int nPreferredWidth = GetPreferredWidth(
1517a32b0c8SAndre Fischer         PreviewValueSet::GetOutputSizePixel().Height());
152cdf0e10cSrcweir     int nPreferredHeight = GetPreferredHeight(nPreferredWidth);
153cdf0e10cSrcweir     return Size (nPreferredWidth, nPreferredHeight);
154cdf0e10cSrcweir 
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 
UpdateLocks(const ItemList & rItemList)160cdf0e10cSrcweir void MasterPagesSelector::UpdateLocks (const ItemList& rItemList)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     ItemList aNewLockList;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     // In here we first lock the master pages in the given list and then
165cdf0e10cSrcweir     // release the locks acquired in a previous call to this method.  When
166cdf0e10cSrcweir     // this were done the other way round the lock count of some master
167cdf0e10cSrcweir     // pages might drop temporarily to 0 and would lead to unnecessary
168cdf0e10cSrcweir     // deletion and re-creation of MasterPageDescriptor objects.
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     // Lock the master pages in the given list.
171cdf0e10cSrcweir     ItemList::const_iterator iItem;
172cdf0e10cSrcweir     for (iItem=rItemList.begin(); iItem!=rItemList.end(); ++iItem)
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         mpContainer->AcquireToken(*iItem);
175cdf0e10cSrcweir         aNewLockList.push_back(*iItem);
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     // Release the previously locked master pages.
179cdf0e10cSrcweir     ItemList::const_iterator iPage;
180cdf0e10cSrcweir     ItemList::const_iterator iEnd (maLockedMasterPages.end());
181cdf0e10cSrcweir     for (iPage=maLockedMasterPages.begin(); iPage!=iEnd; ++iPage)
182cdf0e10cSrcweir         mpContainer->ReleaseToken(*iPage);
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     maLockedMasterPages.swap(aNewLockList);
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
Fill(void)190cdf0e10cSrcweir void MasterPagesSelector::Fill (void)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir     ::std::auto_ptr<ItemList> pItemList (new ItemList());
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     Fill(*pItemList);
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     UpdateLocks(*pItemList);
197cdf0e10cSrcweir     UpdateItemList(pItemList);
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 
GetContextMenuResId(void) const203cdf0e10cSrcweir ResId MasterPagesSelector::GetContextMenuResId (void) const
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     return SdResId(RID_TASKPANE_MASTERPAGESSELECTOR_POPUP);
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 
IMPL_LINK(MasterPagesSelector,ClickHandler,PreviewValueSet *,EMPTYARG)211cdf0e10cSrcweir IMPL_LINK(MasterPagesSelector, ClickHandler, PreviewValueSet*, EMPTYARG)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     // We use the framework to assign the clicked-on master page because we
214cdf0e10cSrcweir     // so use the same mechanism as the context menu does (where we do not
215cdf0e10cSrcweir     // have the option to call the assignment method directly.)
21602c50d82SAndre Fischer     ExecuteCommand(mnDefaultClickAction);
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     return 0;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 
IMPL_LINK(MasterPagesSelector,RightClickHandler,MouseEvent *,pEvent)224cdf0e10cSrcweir IMPL_LINK(MasterPagesSelector, RightClickHandler, MouseEvent*, pEvent)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     // Here we only prepare the display of the context menu: the item under
227cdf0e10cSrcweir     // the mouse is selected.  The actual display of the context menu is
228cdf0e10cSrcweir     // done in ContextMenuCallback which is called indirectly through
229cdf0e10cSrcweir     // PreviewValueSet::Command().
2307a32b0c8SAndre Fischer     PreviewValueSet::GrabFocus ();
2317a32b0c8SAndre Fischer     PreviewValueSet::ReleaseMouse();
23202c50d82SAndre Fischer     SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
23302c50d82SAndre Fischer     if (pViewFrame != NULL)
234cdf0e10cSrcweir     {
23502c50d82SAndre Fischer         SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
23602c50d82SAndre Fischer         if (pDispatcher != NULL &&  pEvent != NULL)
23702c50d82SAndre Fischer         {
23802c50d82SAndre Fischer             sal_uInt16 nIndex = PreviewValueSet::GetItemId (pEvent->GetPosPixel());
23902c50d82SAndre Fischer             if (nIndex > 0)
24002c50d82SAndre Fischer                 PreviewValueSet::SelectItem (nIndex);
24102c50d82SAndre Fischer         }
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir     return 0;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 
Command(const CommandEvent & rEvent)24902c50d82SAndre Fischer void MasterPagesSelector::Command (const CommandEvent& rEvent)
250cdf0e10cSrcweir {
25102c50d82SAndre Fischer     switch (rEvent.GetCommand())
252cdf0e10cSrcweir     {
25302c50d82SAndre Fischer         case COMMAND_CONTEXTMENU:
254cdf0e10cSrcweir         {
25502c50d82SAndre Fischer             // Use the currently selected item and show the popup menu in its
25602c50d82SAndre Fischer             // center.
25702c50d82SAndre Fischer             const sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
25802c50d82SAndre Fischer             if (nIndex > 0)
25902c50d82SAndre Fischer             {
26002c50d82SAndre Fischer                 // The position of the upper left corner of the context menu is
26102c50d82SAndre Fischer                 // taken either from the mouse position (when the command was sent
26202c50d82SAndre Fischer                 // as reaction to a right click) or in the center of the selected
26302c50d82SAndre Fischer                 // item (when the command was sent as reaction to Shift+F10.)
26402c50d82SAndre Fischer                 Point aPosition (rEvent.GetMousePosPixel());
26502c50d82SAndre Fischer                 if ( ! rEvent.IsMouseEvent())
26602c50d82SAndre Fischer                 {
26702c50d82SAndre Fischer                     Rectangle aBBox (PreviewValueSet::GetItemRect(nIndex));
26802c50d82SAndre Fischer                     aPosition = aBBox.Center();
26902c50d82SAndre Fischer                 }
27002c50d82SAndre Fischer 
27102c50d82SAndre Fischer                 // Setup the menu.
27202c50d82SAndre Fischer                 ::boost::scoped_ptr<PopupMenu> pMenu (new PopupMenu(GetContextMenuResId()));
27302c50d82SAndre Fischer                 FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
27402c50d82SAndre Fischer                 if (pMenuWindow != NULL)
27502c50d82SAndre Fischer                     pMenuWindow->SetPopupModeFlags(
27602c50d82SAndre Fischer                         pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE);
27702c50d82SAndre Fischer                 pMenu->SetSelectHdl(LINK(this, MasterPagesSelector, OnMenuItemSelected));
27802c50d82SAndre Fischer 
27902c50d82SAndre Fischer                 ProcessPopupMenu(*pMenu);
28002c50d82SAndre Fischer 
28102c50d82SAndre Fischer                 // Show the menu.
28202c50d82SAndre Fischer                 pMenu->Execute(this, Rectangle(aPosition,Size(1,1)), POPUPMENU_EXECUTE_DOWN);
28302c50d82SAndre Fischer             }
28402c50d82SAndre Fischer             break;
285cdf0e10cSrcweir         }
28602c50d82SAndre Fischer     }
28702c50d82SAndre Fischer }
28802c50d82SAndre Fischer 
28902c50d82SAndre Fischer 
29002c50d82SAndre Fischer 
29102c50d82SAndre Fischer 
ProcessPopupMenu(Menu & rMenu)29202c50d82SAndre Fischer void MasterPagesSelector::ProcessPopupMenu (Menu& rMenu)
29302c50d82SAndre Fischer {
29402c50d82SAndre Fischer     // Disable some entries.
29502c50d82SAndre Fischer     if (mpContainer->GetPreviewSize() == MasterPageContainer::SMALL)
29602c50d82SAndre Fischer         rMenu.EnableItem(SID_TP_SHOW_SMALL_PREVIEW, sal_False);
29702c50d82SAndre Fischer     else
29802c50d82SAndre Fischer         rMenu.EnableItem(SID_TP_SHOW_LARGE_PREVIEW, sal_False);
29902c50d82SAndre Fischer }
30002c50d82SAndre Fischer 
30102c50d82SAndre Fischer 
302cdf0e10cSrcweir 
30302c50d82SAndre Fischer 
IMPL_LINK(MasterPagesSelector,OnMenuItemSelected,Menu *,pMenu)30402c50d82SAndre Fischer IMPL_LINK(MasterPagesSelector, OnMenuItemSelected, Menu*, pMenu)
30502c50d82SAndre Fischer {
30602c50d82SAndre Fischer     if (pMenu == NULL)
30702c50d82SAndre Fischer     {
30802c50d82SAndre Fischer         OSL_ENSURE(pMenu!=NULL, "MasterPagesSelector::OnMenuItemSelected: illegal menu!");
30902c50d82SAndre Fischer         return 0;
310cdf0e10cSrcweir     }
31102c50d82SAndre Fischer 
31202c50d82SAndre Fischer     pMenu->Deactivate();
31302c50d82SAndre Fischer     ExecuteCommand(pMenu->GetCurItemId());
314cdf0e10cSrcweir     return 0;
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 
ExecuteCommand(const sal_Int32 nCommandId)32002c50d82SAndre Fischer void MasterPagesSelector::ExecuteCommand (const sal_Int32 nCommandId)
32102c50d82SAndre Fischer {
32202c50d82SAndre Fischer 	switch (nCommandId)
32302c50d82SAndre Fischer     {
32402c50d82SAndre Fischer         case SID_TP_APPLY_TO_ALL_SLIDES:
32502c50d82SAndre Fischer             mrBase.SetBusyState (true);
32602c50d82SAndre Fischer             AssignMasterPageToAllSlides (GetSelectedMasterPage());
32702c50d82SAndre Fischer             mrBase.SetBusyState (false);
32802c50d82SAndre Fischer             break;
32902c50d82SAndre Fischer 
33002c50d82SAndre Fischer         case SID_TP_APPLY_TO_SELECTED_SLIDES:
33102c50d82SAndre Fischer             mrBase.SetBusyState (true);
33202c50d82SAndre Fischer             AssignMasterPageToSelectedSlides (GetSelectedMasterPage());
33302c50d82SAndre Fischer             mrBase.SetBusyState (false);
33402c50d82SAndre Fischer             break;
33502c50d82SAndre Fischer 
33602c50d82SAndre Fischer         case SID_TP_USE_FOR_NEW_PRESENTATIONS:
33702c50d82SAndre Fischer             DBG_ASSERT (false,
33802c50d82SAndre Fischer                 "Using slides as default for new presentations"
33902c50d82SAndre Fischer                 " is not yet implemented");
34002c50d82SAndre Fischer             break;
34102c50d82SAndre Fischer 
34202c50d82SAndre Fischer         case SID_TP_SHOW_SMALL_PREVIEW:
34302c50d82SAndre Fischer         case SID_TP_SHOW_LARGE_PREVIEW:
34402c50d82SAndre Fischer         {
34502c50d82SAndre Fischer             mrBase.SetBusyState (true);
34602c50d82SAndre Fischer             mpContainer->SetPreviewSize(
34702c50d82SAndre Fischer                 nCommandId==SID_TP_SHOW_SMALL_PREVIEW
34802c50d82SAndre Fischer                 ? MasterPageContainer::SMALL
34902c50d82SAndre Fischer                 : MasterPageContainer::LARGE);
35002c50d82SAndre Fischer             mrBase.SetBusyState (false);
35102c50d82SAndre Fischer             if (mxSidebar.is())
35202c50d82SAndre Fischer                 mxSidebar->requestLayout();
35302c50d82SAndre Fischer             break;
35402c50d82SAndre Fischer         }
35502c50d82SAndre Fischer 
35602c50d82SAndre Fischer         case SID_TP_EDIT_MASTER:
35702c50d82SAndre Fischer         {
35802c50d82SAndre Fischer             using namespace ::com::sun::star;
35902c50d82SAndre Fischer             uno::Reference<drawing::XDrawPage> xSelectedMaster (
36002c50d82SAndre Fischer                 GetSelectedMasterPage()->getUnoPage(), uno::UNO_QUERY);
36102c50d82SAndre Fischer             SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
36202c50d82SAndre Fischer             if (pViewFrame != NULL && xSelectedMaster.is())
36302c50d82SAndre Fischer             {
36402c50d82SAndre Fischer                 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
36502c50d82SAndre Fischer                 if (pDispatcher != NULL)
36602c50d82SAndre Fischer                 {
36702c50d82SAndre Fischer                     sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
36802c50d82SAndre Fischer                     pDispatcher->Execute(SID_MASTERPAGE, SFX_CALLMODE_SYNCHRON);
36902c50d82SAndre Fischer                     PreviewValueSet::SelectItem (nIndex);
37002c50d82SAndre Fischer                     mrBase.GetDrawController().setCurrentPage(xSelectedMaster);
37102c50d82SAndre Fischer                 }
37202c50d82SAndre Fischer             }
37302c50d82SAndre Fischer             break;
37402c50d82SAndre Fischer         }
37502c50d82SAndre Fischer 
37602c50d82SAndre Fischer         case SID_CUT:
37702c50d82SAndre Fischer         case SID_COPY:
37802c50d82SAndre Fischer         case SID_PASTE:
37902c50d82SAndre Fischer             // Cut, copy, and paste are not supported and thus are ignored.
38002c50d82SAndre Fischer             break;
38102c50d82SAndre Fischer     }
38202c50d82SAndre Fischer }
38302c50d82SAndre Fischer 
38402c50d82SAndre Fischer 
38502c50d82SAndre Fischer 
38602c50d82SAndre Fischer 
IMPL_LINK(MasterPagesSelector,ContainerChangeListener,MasterPageContainerChangeEvent *,pEvent)387cdf0e10cSrcweir IMPL_LINK(MasterPagesSelector, ContainerChangeListener, MasterPageContainerChangeEvent*, pEvent)
388cdf0e10cSrcweir {
389cdf0e10cSrcweir     if (pEvent)
390cdf0e10cSrcweir         NotifyContainerChangeEvent(*pEvent);
391cdf0e10cSrcweir     return 0;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 
GetSelectedMasterPage(void)397cdf0e10cSrcweir SdPage* MasterPagesSelector::GetSelectedMasterPage (void)
398cdf0e10cSrcweir {
399cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
400cdf0e10cSrcweir 
401cdf0e10cSrcweir     SdPage* pMasterPage = NULL;
4027a32b0c8SAndre Fischer     sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
403cdf0e10cSrcweir     UserData* pData = GetUserData(nIndex);
404cdf0e10cSrcweir     if (pData != NULL)
405cdf0e10cSrcweir     {
406cdf0e10cSrcweir         pMasterPage = mpContainer->GetPageObjectForToken(pData->second);
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir     return pMasterPage;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 
414cdf0e10cSrcweir /** Assemble a list of all slides of the document and pass it to
415cdf0e10cSrcweir     AssignMasterPageToPageList().
416cdf0e10cSrcweir */
AssignMasterPageToAllSlides(SdPage * pMasterPage)417cdf0e10cSrcweir void MasterPagesSelector::AssignMasterPageToAllSlides (SdPage* pMasterPage)
418cdf0e10cSrcweir {
419cdf0e10cSrcweir     do
420cdf0e10cSrcweir     {
421cdf0e10cSrcweir         if (pMasterPage == NULL)
422cdf0e10cSrcweir             break;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir         sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD);
425cdf0e10cSrcweir         if (nPageCount == 0)
426cdf0e10cSrcweir             break;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         // Get a list of all pages.  As a little optimization we only
429cdf0e10cSrcweir         // include pages that do not already have the given master page
430cdf0e10cSrcweir         // assigned.
431cdf0e10cSrcweir         String sFullLayoutName (pMasterPage->GetLayoutName());
432cdf0e10cSrcweir         ::sd::slidesorter::SharedPageSelection pPageList (
433cdf0e10cSrcweir             new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
434cdf0e10cSrcweir         for (sal_uInt16 nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
435cdf0e10cSrcweir         {
436cdf0e10cSrcweir             SdPage* pPage = mrDocument.GetSdPage (nPageIndex, PK_STANDARD);
437cdf0e10cSrcweir             if (pPage != NULL
438cdf0e10cSrcweir                 && pPage->GetLayoutName().CompareTo(sFullLayoutName)!=0)
439cdf0e10cSrcweir             {
440cdf0e10cSrcweir                 pPageList->push_back (pPage);
441cdf0e10cSrcweir             }
442cdf0e10cSrcweir         }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir         AssignMasterPageToPageList(pMasterPage, pPageList);
445cdf0e10cSrcweir     }
446cdf0e10cSrcweir     while (false);
447cdf0e10cSrcweir }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 
452cdf0e10cSrcweir /** Assemble a list of the currently selected slides (selected in a visible
453cdf0e10cSrcweir     slide sorter) and pass it to AssignMasterPageToPageList().
454cdf0e10cSrcweir */
AssignMasterPageToSelectedSlides(SdPage * pMasterPage)455cdf0e10cSrcweir void MasterPagesSelector::AssignMasterPageToSelectedSlides (
456cdf0e10cSrcweir     SdPage* pMasterPage)
457cdf0e10cSrcweir {
458cdf0e10cSrcweir     do
459cdf0e10cSrcweir     {
460cdf0e10cSrcweir         using namespace ::std;
461cdf0e10cSrcweir         using namespace ::sd::slidesorter;
462cdf0e10cSrcweir         using namespace ::sd::slidesorter::controller;
463cdf0e10cSrcweir 
464cdf0e10cSrcweir         if (pMasterPage == NULL)
465cdf0e10cSrcweir             break;
466cdf0e10cSrcweir 
467cdf0e10cSrcweir         // Find a visible slide sorter.
468cdf0e10cSrcweir         SlideSorterViewShell* pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
469cdf0e10cSrcweir         if (pSlideSorter == NULL)
470cdf0e10cSrcweir             break;
471cdf0e10cSrcweir 
472cdf0e10cSrcweir         // Get a list of selected pages.
473cdf0e10cSrcweir         ::sd::slidesorter::SharedPageSelection pPageSelection = pSlideSorter->GetPageSelection();
474cdf0e10cSrcweir         if (pPageSelection->empty())
475cdf0e10cSrcweir             break;
476cdf0e10cSrcweir 
477cdf0e10cSrcweir         AssignMasterPageToPageList(pMasterPage, pPageSelection);
478cdf0e10cSrcweir 
479cdf0e10cSrcweir         // Restore the previous selection.
480cdf0e10cSrcweir         pSlideSorter->SetPageSelection(pPageSelection);
481cdf0e10cSrcweir     }
482cdf0e10cSrcweir     while (false);
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 
487cdf0e10cSrcweir 
AssignMasterPageToPageList(SdPage * pMasterPage,const::sd::slidesorter::SharedPageSelection & rPageList)488cdf0e10cSrcweir void MasterPagesSelector::AssignMasterPageToPageList (
489cdf0e10cSrcweir     SdPage* pMasterPage,
490cdf0e10cSrcweir     const ::sd::slidesorter::SharedPageSelection& rPageList)
491cdf0e10cSrcweir {
492cdf0e10cSrcweir     DocumentHelper::AssignMasterPageToPageList(mrDocument, pMasterPage, rPageList);
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 
NotifyContainerChangeEvent(const MasterPageContainerChangeEvent & rEvent)498cdf0e10cSrcweir void MasterPagesSelector::NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent)
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     switch (rEvent.meEventType)
503cdf0e10cSrcweir     {
504cdf0e10cSrcweir         case MasterPageContainerChangeEvent::SIZE_CHANGED:
5057a32b0c8SAndre Fischer             PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel());
506cdf0e10cSrcweir             UpdateAllPreviews();
507cdf0e10cSrcweir             break;
508cdf0e10cSrcweir 
509cdf0e10cSrcweir         case MasterPageContainerChangeEvent::PREVIEW_CHANGED:
510cdf0e10cSrcweir         {
511cdf0e10cSrcweir             int nIndex (GetIndexForToken(rEvent.maChildToken));
512cdf0e10cSrcweir             if (nIndex >= 0)
513cdf0e10cSrcweir             {
5147a32b0c8SAndre Fischer                 PreviewValueSet::SetItemImage (
515cdf0e10cSrcweir                     (sal_uInt16)nIndex,
516cdf0e10cSrcweir                     mpContainer->GetPreviewForToken(rEvent.maChildToken));
5177a32b0c8SAndre Fischer                 PreviewValueSet::Invalidate(PreviewValueSet::GetItemRect((sal_uInt16)nIndex));
518cdf0e10cSrcweir             }
519cdf0e10cSrcweir         }
520cdf0e10cSrcweir         break;
521cdf0e10cSrcweir 
522cdf0e10cSrcweir         case MasterPageContainerChangeEvent::DATA_CHANGED:
523cdf0e10cSrcweir         {
524cdf0e10cSrcweir             InvalidateItem(rEvent.maChildToken);
525cdf0e10cSrcweir             Fill();
526cdf0e10cSrcweir         }
527cdf0e10cSrcweir         break;
528cdf0e10cSrcweir 
529cdf0e10cSrcweir 		default:
530cdf0e10cSrcweir 			break;
531cdf0e10cSrcweir    }
532cdf0e10cSrcweir }
533cdf0e10cSrcweir 
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 
CreateUserData(int nIndex,MasterPageContainer::Token aToken) const537cdf0e10cSrcweir MasterPagesSelector::UserData* MasterPagesSelector::CreateUserData (
538cdf0e10cSrcweir     int nIndex,
539cdf0e10cSrcweir     MasterPageContainer::Token aToken) const
540cdf0e10cSrcweir {
541cdf0e10cSrcweir     return new UserData(nIndex,aToken);
542cdf0e10cSrcweir }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 
GetUserData(int nIndex) const547cdf0e10cSrcweir MasterPagesSelector::UserData* MasterPagesSelector::GetUserData (int nIndex) const
548cdf0e10cSrcweir {
549cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
550cdf0e10cSrcweir 
5517a32b0c8SAndre Fischer     if (nIndex>0 && nIndex<=PreviewValueSet::GetItemCount())
5527a32b0c8SAndre Fischer         return reinterpret_cast<UserData*>(PreviewValueSet::GetItemData((sal_uInt16)nIndex));
553cdf0e10cSrcweir     else
554cdf0e10cSrcweir         return NULL;
555cdf0e10cSrcweir }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 
SetUserData(int nIndex,UserData * pData)560cdf0e10cSrcweir void MasterPagesSelector::SetUserData (int nIndex, UserData* pData)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
563cdf0e10cSrcweir 
5647a32b0c8SAndre Fischer     if (nIndex>0 && nIndex<=PreviewValueSet::GetItemCount())
565cdf0e10cSrcweir     {
566cdf0e10cSrcweir         UserData* pOldData = GetUserData(nIndex);
567cdf0e10cSrcweir         if (pOldData!=NULL && pOldData!=pData)
568cdf0e10cSrcweir             delete pOldData;
5697a32b0c8SAndre Fischer         PreviewValueSet::SetItemData((sal_uInt16)nIndex, pData);
570cdf0e10cSrcweir     }
571cdf0e10cSrcweir }
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 
IsResizable(void)576cdf0e10cSrcweir bool MasterPagesSelector::IsResizable (void)
577cdf0e10cSrcweir {
578cdf0e10cSrcweir     return false;
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 
GetWindow(void)584cdf0e10cSrcweir ::Window* MasterPagesSelector::GetWindow (void)
585cdf0e10cSrcweir {
5867a32b0c8SAndre Fischer     return this;
587cdf0e10cSrcweir }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 
GetMinimumWidth(void)592cdf0e10cSrcweir sal_Int32 MasterPagesSelector::GetMinimumWidth (void)
593cdf0e10cSrcweir {
594cdf0e10cSrcweir     return mpContainer->GetPreviewSizePixel().Width() + 2*3;
595cdf0e10cSrcweir }
596cdf0e10cSrcweir 
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 
UpdateSelection(void)600cdf0e10cSrcweir void MasterPagesSelector::UpdateSelection (void)
601cdf0e10cSrcweir {
602cdf0e10cSrcweir }
603cdf0e10cSrcweir 
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 
SetItem(sal_uInt16 nIndex,MasterPageContainer::Token aToken)607cdf0e10cSrcweir void MasterPagesSelector::SetItem (
608cdf0e10cSrcweir     sal_uInt16 nIndex,
609cdf0e10cSrcweir     MasterPageContainer::Token aToken)
610cdf0e10cSrcweir {
611cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
612cdf0e10cSrcweir 
613cdf0e10cSrcweir     RemoveTokenToIndexEntry(nIndex,aToken);
614cdf0e10cSrcweir 
615cdf0e10cSrcweir     if (nIndex > 0)
616cdf0e10cSrcweir     {
617cdf0e10cSrcweir         if (aToken != MasterPageContainer::NIL_TOKEN)
618cdf0e10cSrcweir         {
619cdf0e10cSrcweir             Image aPreview (mpContainer->GetPreviewForToken(aToken));
620cdf0e10cSrcweir             MasterPageContainer::PreviewState eState (mpContainer->GetPreviewState(aToken));
621cdf0e10cSrcweir 
622cdf0e10cSrcweir             if (aPreview.GetSizePixel().Width()>0)
623cdf0e10cSrcweir             {
6247a32b0c8SAndre Fischer                 if (PreviewValueSet::GetItemPos(nIndex) != VALUESET_ITEM_NOTFOUND)
625cdf0e10cSrcweir                 {
6267a32b0c8SAndre Fischer                     PreviewValueSet::SetItemImage(nIndex,aPreview);
6277a32b0c8SAndre Fischer                     PreviewValueSet::SetItemText(nIndex, mpContainer->GetPageNameForToken(aToken));
628cdf0e10cSrcweir                 }
629cdf0e10cSrcweir                 else
630cdf0e10cSrcweir                 {
6317a32b0c8SAndre Fischer                     PreviewValueSet::InsertItem (
632cdf0e10cSrcweir                         nIndex,
633cdf0e10cSrcweir                         aPreview,
634cdf0e10cSrcweir                         mpContainer->GetPageNameForToken(aToken),
635cdf0e10cSrcweir                         nIndex);
636cdf0e10cSrcweir                 }
637cdf0e10cSrcweir                 SetUserData(nIndex, CreateUserData(nIndex,aToken));
638cdf0e10cSrcweir 
639cdf0e10cSrcweir                 AddTokenToIndexEntry(nIndex,aToken);
640cdf0e10cSrcweir             }
641cdf0e10cSrcweir 
642cdf0e10cSrcweir             if (eState == MasterPageContainer::PS_CREATABLE)
643cdf0e10cSrcweir                 mpContainer->RequestPreview(aToken);
644cdf0e10cSrcweir         }
645cdf0e10cSrcweir         else
646cdf0e10cSrcweir         {
6477a32b0c8SAndre Fischer             PreviewValueSet::RemoveItem(nIndex);
648cdf0e10cSrcweir         }
649cdf0e10cSrcweir     }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir }
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 
654cdf0e10cSrcweir 
655cdf0e10cSrcweir 
AddTokenToIndexEntry(sal_uInt16 nIndex,MasterPageContainer::Token aToken)656cdf0e10cSrcweir void MasterPagesSelector::AddTokenToIndexEntry (
657cdf0e10cSrcweir     sal_uInt16 nIndex,
658cdf0e10cSrcweir     MasterPageContainer::Token aToken)
659cdf0e10cSrcweir {
660cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
661cdf0e10cSrcweir 
662cdf0e10cSrcweir     maTokenToValueSetIndex[aToken] = nIndex;
663cdf0e10cSrcweir }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 
667cdf0e10cSrcweir 
RemoveTokenToIndexEntry(sal_uInt16 nIndex,MasterPageContainer::Token aNewToken)668cdf0e10cSrcweir void MasterPagesSelector::RemoveTokenToIndexEntry (
669cdf0e10cSrcweir     sal_uInt16 nIndex,
670cdf0e10cSrcweir     MasterPageContainer::Token aNewToken)
671cdf0e10cSrcweir {
672cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
673cdf0e10cSrcweir 
674cdf0e10cSrcweir     UserData* pData = GetUserData(nIndex);
675cdf0e10cSrcweir     if (pData != NULL)
676cdf0e10cSrcweir     {
677cdf0e10cSrcweir         // Get the token that the index pointed to previously.
678cdf0e10cSrcweir         MasterPageContainer::Token aOldToken (pData->second);
679cdf0e10cSrcweir 
680cdf0e10cSrcweir         if (aNewToken != aOldToken
681cdf0e10cSrcweir             && nIndex == GetIndexForToken(aOldToken))
682cdf0e10cSrcweir         {
683cdf0e10cSrcweir             maTokenToValueSetIndex[aOldToken] = 0;
684cdf0e10cSrcweir         }
685cdf0e10cSrcweir     }
686cdf0e10cSrcweir }
687cdf0e10cSrcweir 
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 
690cdf0e10cSrcweir 
InvalidatePreview(const SdPage * pPage)691cdf0e10cSrcweir void MasterPagesSelector::InvalidatePreview (const SdPage* pPage)
692cdf0e10cSrcweir {
693cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
694cdf0e10cSrcweir 
6957a32b0c8SAndre Fischer     for (sal_uInt16 nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
696cdf0e10cSrcweir     {
697cdf0e10cSrcweir         UserData* pData = GetUserData(nIndex);
698cdf0e10cSrcweir         if (pData != NULL)
699cdf0e10cSrcweir         {
700cdf0e10cSrcweir             MasterPageContainer::Token aToken (pData->second);
701cdf0e10cSrcweir             if (pPage == mpContainer->GetPageObjectForToken(aToken,false))
702cdf0e10cSrcweir             {
703cdf0e10cSrcweir                 mpContainer->InvalidatePreview(aToken);
704cdf0e10cSrcweir                 mpContainer->RequestPreview(aToken);
705cdf0e10cSrcweir                 break;
706cdf0e10cSrcweir             }
707cdf0e10cSrcweir         }
708cdf0e10cSrcweir     }
709cdf0e10cSrcweir }
710cdf0e10cSrcweir 
UpdateAllPreviews(void)711cdf0e10cSrcweir void MasterPagesSelector::UpdateAllPreviews (void)
712cdf0e10cSrcweir {
713cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
714cdf0e10cSrcweir 
7157a32b0c8SAndre Fischer     for (sal_uInt16 nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
716cdf0e10cSrcweir     {
717cdf0e10cSrcweir         UserData* pData = GetUserData(nIndex);
718cdf0e10cSrcweir         if (pData != NULL)
719cdf0e10cSrcweir         {
720cdf0e10cSrcweir             MasterPageContainer::Token aToken (pData->second);
7217a32b0c8SAndre Fischer             PreviewValueSet::SetItemImage(
722cdf0e10cSrcweir                 nIndex,
723cdf0e10cSrcweir                 mpContainer->GetPreviewForToken(aToken));
724cdf0e10cSrcweir             if (mpContainer->GetPreviewState(aToken) == MasterPageContainer::PS_CREATABLE)
725cdf0e10cSrcweir                 mpContainer->RequestPreview(aToken);
726cdf0e10cSrcweir         }
727cdf0e10cSrcweir     }
7287a32b0c8SAndre Fischer     PreviewValueSet::Rearrange(true);
729cdf0e10cSrcweir }
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 
732cdf0e10cSrcweir 
733cdf0e10cSrcweir 
ClearPageSet(void)734cdf0e10cSrcweir void MasterPagesSelector::ClearPageSet (void)
735cdf0e10cSrcweir {
736cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
737cdf0e10cSrcweir 
7387a32b0c8SAndre Fischer     for (sal_uInt16 nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
739cdf0e10cSrcweir     {
740cdf0e10cSrcweir         UserData* pData = GetUserData(nIndex);
741cdf0e10cSrcweir         if (pData != NULL)
742cdf0e10cSrcweir             delete pData;
743cdf0e10cSrcweir     }
7447a32b0c8SAndre Fischer     PreviewValueSet::Clear();
745cdf0e10cSrcweir }
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 
SetHelpId(const rtl::OString & aId)750cdf0e10cSrcweir void MasterPagesSelector::SetHelpId( const rtl::OString& aId )
751cdf0e10cSrcweir {
752cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
753cdf0e10cSrcweir 
7547a32b0c8SAndre Fischer 	PreviewValueSet::SetHelpId( aId );
755cdf0e10cSrcweir }
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 
GetIndexForToken(MasterPageContainer::Token aToken) const760cdf0e10cSrcweir sal_Int32 MasterPagesSelector::GetIndexForToken (MasterPageContainer::Token aToken) const
761cdf0e10cSrcweir {
762cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
763cdf0e10cSrcweir 
764cdf0e10cSrcweir     TokenToValueSetIndex::const_iterator iIndex (maTokenToValueSetIndex.find(aToken));
765cdf0e10cSrcweir     if (iIndex != maTokenToValueSetIndex.end())
766cdf0e10cSrcweir         return iIndex->second;
767cdf0e10cSrcweir     else
768cdf0e10cSrcweir         return -1;
769cdf0e10cSrcweir }
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 
Clear(void)774cdf0e10cSrcweir void MasterPagesSelector::Clear (void)
775cdf0e10cSrcweir {
776cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
777cdf0e10cSrcweir 
778cdf0e10cSrcweir     ClearPageSet();
779cdf0e10cSrcweir }
780cdf0e10cSrcweir 
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 
InvalidateItem(MasterPageContainer::Token aToken)784cdf0e10cSrcweir void MasterPagesSelector::InvalidateItem (MasterPageContainer::Token aToken)
785cdf0e10cSrcweir {
786cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
787cdf0e10cSrcweir 
788cdf0e10cSrcweir     ItemList::iterator iItem;
789cdf0e10cSrcweir     for (iItem=maCurrentItemList.begin(); iItem!=maCurrentItemList.end(); ++iItem)
790cdf0e10cSrcweir     {
791cdf0e10cSrcweir         if (*iItem == aToken)
792cdf0e10cSrcweir         {
793cdf0e10cSrcweir             *iItem = MasterPageContainer::NIL_TOKEN;
794cdf0e10cSrcweir             break;
795cdf0e10cSrcweir         }
796cdf0e10cSrcweir     }
797cdf0e10cSrcweir }
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 
801cdf0e10cSrcweir 
UpdateItemList(::std::auto_ptr<ItemList> pNewItemList)802cdf0e10cSrcweir void MasterPagesSelector::UpdateItemList (::std::auto_ptr<ItemList> pNewItemList)
803cdf0e10cSrcweir {
804cdf0e10cSrcweir     const ::osl::MutexGuard aGuard (maMutex);
805cdf0e10cSrcweir 
806cdf0e10cSrcweir     ItemList::const_iterator iNewItem (pNewItemList->begin());
807cdf0e10cSrcweir     ItemList::const_iterator iCurrentItem (maCurrentItemList.begin());
808cdf0e10cSrcweir     ItemList::const_iterator iNewEnd (pNewItemList->end());
809cdf0e10cSrcweir     ItemList::const_iterator iCurrentEnd (maCurrentItemList.end());
810cdf0e10cSrcweir     sal_uInt16 nIndex (1);
811cdf0e10cSrcweir 
812cdf0e10cSrcweir     // Update existing items.
813cdf0e10cSrcweir     for ( ; iNewItem!=iNewEnd && iCurrentItem!=iCurrentEnd; ++iNewItem, ++iCurrentItem,++nIndex)
814cdf0e10cSrcweir     {
815cdf0e10cSrcweir         if (*iNewItem != *iCurrentItem)
816cdf0e10cSrcweir         {
817cdf0e10cSrcweir             SetItem(nIndex,*iNewItem);
818cdf0e10cSrcweir         }
819cdf0e10cSrcweir     }
820cdf0e10cSrcweir 
821cdf0e10cSrcweir     // Append new items.
822cdf0e10cSrcweir     for ( ; iNewItem!=iNewEnd; ++iNewItem,++nIndex)
823cdf0e10cSrcweir     {
824cdf0e10cSrcweir         SetItem(nIndex,*iNewItem);
825cdf0e10cSrcweir     }
826cdf0e10cSrcweir 
827cdf0e10cSrcweir     // Remove trailing items.
828cdf0e10cSrcweir     for ( ; iCurrentItem!=iCurrentEnd; ++iCurrentItem,++nIndex)
829cdf0e10cSrcweir     {
830cdf0e10cSrcweir         SetItem(nIndex,MasterPageContainer::NIL_TOKEN);
831cdf0e10cSrcweir     }
832cdf0e10cSrcweir 
833cdf0e10cSrcweir     maCurrentItemList.swap(*pNewItemList);
834cdf0e10cSrcweir 
8357a32b0c8SAndre Fischer     PreviewValueSet::Rearrange();
8367a32b0c8SAndre Fischer     if (mxSidebar.is())
8377a32b0c8SAndre Fischer         mxSidebar->requestLayout();
838cdf0e10cSrcweir }
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 
GetHeightForWidth(const sal_Int32 nWidth)8437a32b0c8SAndre Fischer css::ui::LayoutSize MasterPagesSelector::GetHeightForWidth (const sal_Int32 nWidth)
8447a32b0c8SAndre Fischer {
8457a32b0c8SAndre Fischer     const sal_Int32 nHeight (GetPreferredHeight(nWidth));
8467a32b0c8SAndre Fischer     return css::ui::LayoutSize(nHeight,nHeight,nHeight);
8477a32b0c8SAndre Fischer }
848cdf0e10cSrcweir 
8497a32b0c8SAndre Fischer } } // end of namespace sd::sidebar
850