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