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 "RecentMasterPagesSelector.hxx"
25cdf0e10cSrcweir 
267a32b0c8SAndre Fischer #include "ViewShellBase.hxx"
27cdf0e10cSrcweir #include "RecentlyUsedMasterPages.hxx"
28cdf0e10cSrcweir #include "MasterPageContainerProviders.hxx"
29cdf0e10cSrcweir #include "MasterPageObserver.hxx"
305d65efa0SAndre Fischer #include "SidebarShellManager.hxx"
31cdf0e10cSrcweir #include "sdpage.hxx"
32cdf0e10cSrcweir #include "drawdoc.hxx"
33cdf0e10cSrcweir #include "app.hrc"
347a32b0c8SAndre Fischer #include "helpids.h"
357a32b0c8SAndre Fischer 
36cdf0e10cSrcweir #include <vcl/bitmap.hxx>
37cdf0e10cSrcweir #include <tools/color.hxx>
38cdf0e10cSrcweir 
397a32b0c8SAndre Fischer namespace sd { namespace sidebar {
407a32b0c8SAndre Fischer 
417a32b0c8SAndre Fischer 
Create(::Window * pParent,ViewShellBase & rViewShellBase,const cssu::Reference<css::ui::XSidebar> & rxSidebar)427a32b0c8SAndre Fischer MasterPagesSelector* RecentMasterPagesSelector::Create (
437a32b0c8SAndre Fischer     ::Window* pParent,
447a32b0c8SAndre Fischer     ViewShellBase& rViewShellBase,
45*02c50d82SAndre Fischer     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
467a32b0c8SAndre Fischer {
477a32b0c8SAndre Fischer     SdDrawDocument* pDocument = rViewShellBase.GetDocument();
487a32b0c8SAndre Fischer     if (pDocument == NULL)
497a32b0c8SAndre Fischer         return NULL;
507a32b0c8SAndre Fischer 
517a32b0c8SAndre Fischer     ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer());
527a32b0c8SAndre Fischer 
537a32b0c8SAndre Fischer     MasterPagesSelector* pSelector(
547a32b0c8SAndre Fischer         new RecentMasterPagesSelector (
557a32b0c8SAndre Fischer             pParent,
567a32b0c8SAndre Fischer             *pDocument,
577a32b0c8SAndre Fischer             rViewShellBase,
58*02c50d82SAndre Fischer             pContainer,
59*02c50d82SAndre Fischer             rxSidebar));
607a32b0c8SAndre Fischer     pSelector->LateInit();
617a32b0c8SAndre Fischer     pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_RECENT);
627a32b0c8SAndre Fischer 
637a32b0c8SAndre Fischer     return pSelector;
647a32b0c8SAndre Fischer }
657a32b0c8SAndre Fischer 
667a32b0c8SAndre Fischer 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
RecentMasterPagesSelector(::Window * pParent,SdDrawDocument & rDocument,ViewShellBase & rBase,const::boost::shared_ptr<MasterPageContainer> & rpContainer,const cssu::Reference<css::ui::XSidebar> & rxSidebar)69cdf0e10cSrcweir RecentMasterPagesSelector::RecentMasterPagesSelector (
707a32b0c8SAndre Fischer     ::Window* pParent,
71cdf0e10cSrcweir     SdDrawDocument& rDocument,
72cdf0e10cSrcweir     ViewShellBase& rBase,
73*02c50d82SAndre Fischer     const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
74*02c50d82SAndre Fischer     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
75*02c50d82SAndre Fischer     : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
~RecentMasterPagesSelector(void)82cdf0e10cSrcweir RecentMasterPagesSelector::~RecentMasterPagesSelector (void)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     RecentlyUsedMasterPages::Instance().RemoveEventListener (
85cdf0e10cSrcweir         LINK(this,RecentMasterPagesSelector,MasterPageListListener));
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
LateInit(void)91cdf0e10cSrcweir void RecentMasterPagesSelector::LateInit (void)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     MasterPagesSelector::LateInit();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     MasterPagesSelector::Fill();
96cdf0e10cSrcweir     RecentlyUsedMasterPages::Instance().AddEventListener (
97cdf0e10cSrcweir         LINK(this,RecentMasterPagesSelector,MasterPageListListener));
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
IMPL_LINK(RecentMasterPagesSelector,MasterPageListListener,void *,EMPTYARG)103cdf0e10cSrcweir IMPL_LINK(RecentMasterPagesSelector,MasterPageListListener, void*, EMPTYARG)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     MasterPagesSelector::Fill();
106cdf0e10cSrcweir     return 0;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
Fill(ItemList & rItemList)112cdf0e10cSrcweir void RecentMasterPagesSelector::Fill (ItemList& rItemList)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     // Create a set of names of the master pages used by the document.
115cdf0e10cSrcweir     MasterPageObserver::MasterPageNameSet aCurrentNames;
116cdf0e10cSrcweir     sal_uInt16 nMasterPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD);
117cdf0e10cSrcweir     sal_uInt16 nIndex;
118cdf0e10cSrcweir     for (nIndex=0; nIndex<nMasterPageCount; nIndex++)
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         SdPage* pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD);
121cdf0e10cSrcweir         if (pMasterPage != NULL)
122cdf0e10cSrcweir             aCurrentNames.insert (pMasterPage->GetName());
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir     MasterPageObserver::MasterPageNameSet::iterator aI;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     // Insert the recently used master pages that are currently not used.
127cdf0e10cSrcweir     RecentlyUsedMasterPages& rInstance (RecentlyUsedMasterPages::Instance());
128cdf0e10cSrcweir     int nPageCount = rInstance.GetMasterPageCount();
129cdf0e10cSrcweir     for (nIndex=0; nIndex<nPageCount; nIndex++)
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         // Add an entry when a) the page is already known to the
132cdf0e10cSrcweir         // MasterPageContainer, b) the style name is empty, i.e. it has not yet
133cdf0e10cSrcweir         // been loaded (and thus can not be in use) or otherwise c) the
134cdf0e10cSrcweir         // style name is not currently in use.
135cdf0e10cSrcweir         MasterPageContainer::Token aToken (rInstance.GetTokenForIndex(nIndex));
136cdf0e10cSrcweir         if (aToken != MasterPageContainer::NIL_TOKEN)
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir             String sStyleName (mpContainer->GetStyleNameForToken(aToken));
139cdf0e10cSrcweir             if (sStyleName.Len()==0
140cdf0e10cSrcweir                 || aCurrentNames.find(sStyleName) == aCurrentNames.end())
141cdf0e10cSrcweir             {
142cdf0e10cSrcweir                 rItemList.push_back(aToken);
143cdf0e10cSrcweir             }
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir     }
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
AssignMasterPageToPageList(SdPage * pMasterPage,const::boost::shared_ptr<std::vector<SdPage * >> & rpPageList)151cdf0e10cSrcweir void RecentMasterPagesSelector::AssignMasterPageToPageList (
152cdf0e10cSrcweir     SdPage* pMasterPage,
153cdf0e10cSrcweir     const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList)
154cdf0e10cSrcweir {
1557a32b0c8SAndre Fischer 	sal_uInt16 nSelectedItemId = PreviewValueSet::GetSelectItemId();
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     MasterPagesSelector::AssignMasterPageToPageList(pMasterPage, rpPageList);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     // Restore the selection.
1607a32b0c8SAndre Fischer     if (PreviewValueSet::GetItemCount() > 0)
161cdf0e10cSrcweir     {
1627a32b0c8SAndre Fischer         if (PreviewValueSet::GetItemCount() >= nSelectedItemId)
1637a32b0c8SAndre Fischer             PreviewValueSet::SelectItem(nSelectedItemId);
164cdf0e10cSrcweir         else
1657a32b0c8SAndre Fischer             PreviewValueSet::SelectItem(PreviewValueSet::GetItemCount());
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
ProcessPopupMenu(Menu & rMenu)172*02c50d82SAndre Fischer void RecentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu)
173cdf0e10cSrcweir {
174*02c50d82SAndre Fischer     if (rMenu.GetItemPos(SID_TP_EDIT_MASTER) != MENU_ITEM_NOTFOUND)
175*02c50d82SAndre Fischer         rMenu.EnableItem(SID_TP_EDIT_MASTER, sal_False);
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
1817a32b0c8SAndre Fischer } } // end of namespace sd::sidebar
182