merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / toolpanel / controls / RecentMasterPagesSelector.cxx
blob71063e8df0281f71793c7a46c9c0ecbb9c6ed3d3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RecentMasterPagesSelector.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "RecentMasterPagesSelector.hxx"
35 #include "PreviewValueSet.hxx"
37 #include "RecentlyUsedMasterPages.hxx"
38 #include "MasterPageContainerProviders.hxx"
39 #include "MasterPageObserver.hxx"
40 #include "sdpage.hxx"
41 #include "drawdoc.hxx"
42 #include "app.hrc"
43 #include <vcl/bitmap.hxx>
44 #include <tools/color.hxx>
46 namespace sd { namespace toolpanel { namespace controls {
49 RecentMasterPagesSelector::RecentMasterPagesSelector (
50 TreeNode* pParent,
51 SdDrawDocument& rDocument,
52 ViewShellBase& rBase,
53 const ::boost::shared_ptr<MasterPageContainer>& rpContainer)
54 : MasterPagesSelector (pParent, rDocument, rBase, rpContainer)
56 SetName (String(RTL_CONSTASCII_USTRINGPARAM("RecentMasterPagesSelector")));
62 RecentMasterPagesSelector::~RecentMasterPagesSelector (void)
64 RecentlyUsedMasterPages::Instance().RemoveEventListener (
65 LINK(this,RecentMasterPagesSelector,MasterPageListListener));
71 void RecentMasterPagesSelector::LateInit (void)
73 MasterPagesSelector::LateInit();
75 MasterPagesSelector::Fill();
76 RecentlyUsedMasterPages::Instance().AddEventListener (
77 LINK(this,RecentMasterPagesSelector,MasterPageListListener));
83 IMPL_LINK(RecentMasterPagesSelector,MasterPageListListener, void*, EMPTYARG)
85 MasterPagesSelector::Fill();
86 return 0;
92 void RecentMasterPagesSelector::Fill (ItemList& rItemList)
94 // Create a set of names of the master pages used by the document.
95 MasterPageObserver::MasterPageNameSet aCurrentNames;
96 USHORT nMasterPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD);
97 USHORT nIndex;
98 for (nIndex=0; nIndex<nMasterPageCount; nIndex++)
100 SdPage* pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD);
101 if (pMasterPage != NULL)
102 aCurrentNames.insert (pMasterPage->GetName());
104 MasterPageObserver::MasterPageNameSet::iterator aI;
106 // Insert the recently used master pages that are currently not used.
107 RecentlyUsedMasterPages& rInstance (RecentlyUsedMasterPages::Instance());
108 int nPageCount = rInstance.GetMasterPageCount();
109 for (nIndex=0; nIndex<nPageCount; nIndex++)
111 // Add an entry when a) the page is already known to the
112 // MasterPageContainer, b) the style name is empty, i.e. it has not yet
113 // been loaded (and thus can not be in use) or otherwise c) the
114 // style name is not currently in use.
115 MasterPageContainer::Token aToken (rInstance.GetTokenForIndex(nIndex));
116 if (aToken != MasterPageContainer::NIL_TOKEN)
118 String sStyleName (mpContainer->GetStyleNameForToken(aToken));
119 if (sStyleName.Len()==0
120 || aCurrentNames.find(sStyleName) == aCurrentNames.end())
122 rItemList.push_back(aToken);
131 void RecentMasterPagesSelector::AssignMasterPageToPageList (
132 SdPage* pMasterPage,
133 const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList)
135 USHORT nSelectedItemId = mpPageSet->GetSelectItemId();
137 MasterPagesSelector::AssignMasterPageToPageList(pMasterPage, rpPageList);
139 // Restore the selection.
140 if (mpPageSet->GetItemCount() > 0)
142 if (mpPageSet->GetItemCount() >= nSelectedItemId)
143 mpPageSet->SelectItem(nSelectedItemId);
144 else
145 mpPageSet->SelectItem(mpPageSet->GetItemCount());
152 void RecentMasterPagesSelector::GetState (SfxItemSet& rItemSet)
154 MasterPagesSelector::GetState (rItemSet);
155 if (rItemSet.GetItemState(SID_TP_EDIT_MASTER) == SFX_ITEM_AVAILABLE)
156 rItemSet.DisableItem (SID_TP_EDIT_MASTER);
162 } } } // end of namespace ::sd::toolpanel::controls