1*02c50d82SAndre Fischer /************************************************************** 2*02c50d82SAndre Fischer * 3*02c50d82SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4*02c50d82SAndre Fischer * or more contributor license agreements. See the NOTICE file 5*02c50d82SAndre Fischer * distributed with this work for additional information 6*02c50d82SAndre Fischer * regarding copyright ownership. The ASF licenses this file 7*02c50d82SAndre Fischer * to you under the Apache License, Version 2.0 (the 8*02c50d82SAndre Fischer * "License"); you may not use this file except in compliance 9*02c50d82SAndre Fischer * with the License. You may obtain a copy of the License at 10*02c50d82SAndre Fischer * 11*02c50d82SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12*02c50d82SAndre Fischer * 13*02c50d82SAndre Fischer * Unless required by applicable law or agreed to in writing, 14*02c50d82SAndre Fischer * software distributed under the License is distributed on an 15*02c50d82SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*02c50d82SAndre Fischer * KIND, either express or implied. See the License for the 17*02c50d82SAndre Fischer * specific language governing permissions and limitations 18*02c50d82SAndre Fischer * under the License. 19*02c50d82SAndre Fischer * 20*02c50d82SAndre Fischer *************************************************************/ 21*02c50d82SAndre Fischer 22*02c50d82SAndre Fischer #include "precompiled_sd.hxx" 23*02c50d82SAndre Fischer 24*02c50d82SAndre Fischer #include "RecentMasterPagesSelector.hxx" 25*02c50d82SAndre Fischer 26*02c50d82SAndre Fischer #include "ViewShellBase.hxx" 27*02c50d82SAndre Fischer #include "RecentlyUsedMasterPages.hxx" 28*02c50d82SAndre Fischer #include "MasterPageContainerProviders.hxx" 29*02c50d82SAndre Fischer #include "MasterPageObserver.hxx" 30*02c50d82SAndre Fischer #include "SidebarShellManager.hxx" 31*02c50d82SAndre Fischer #include "sdpage.hxx" 32*02c50d82SAndre Fischer #include "drawdoc.hxx" 33*02c50d82SAndre Fischer #include "app.hrc" 34*02c50d82SAndre Fischer #include "helpids.h" 35*02c50d82SAndre Fischer 36*02c50d82SAndre Fischer #include <vcl/bitmap.hxx> 37*02c50d82SAndre Fischer #include <tools/color.hxx> 38*02c50d82SAndre Fischer 39*02c50d82SAndre Fischer namespace sd { namespace sidebar { 40*02c50d82SAndre Fischer 41*02c50d82SAndre Fischer 42*02c50d82SAndre Fischer MasterPagesSelector* RecentMasterPagesSelector::Create ( 43*02c50d82SAndre Fischer ::Window* pParent, 44*02c50d82SAndre Fischer ViewShellBase& rViewShellBase, 45*02c50d82SAndre Fischer const cssu::Reference<css::ui::XSidebar>& rxSidebar) 46*02c50d82SAndre Fischer { 47*02c50d82SAndre Fischer SdDrawDocument* pDocument = rViewShellBase.GetDocument(); 48*02c50d82SAndre Fischer if (pDocument == NULL) 49*02c50d82SAndre Fischer return NULL; 50*02c50d82SAndre Fischer 51*02c50d82SAndre Fischer ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer()); 52*02c50d82SAndre Fischer 53*02c50d82SAndre Fischer MasterPagesSelector* pSelector( 54*02c50d82SAndre Fischer new RecentMasterPagesSelector ( 55*02c50d82SAndre Fischer pParent, 56*02c50d82SAndre Fischer *pDocument, 57*02c50d82SAndre Fischer rViewShellBase, 58*02c50d82SAndre Fischer pContainer, 59*02c50d82SAndre Fischer rxSidebar)); 60*02c50d82SAndre Fischer pSelector->LateInit(); 61*02c50d82SAndre Fischer pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_RECENT); 62*02c50d82SAndre Fischer 63*02c50d82SAndre Fischer return pSelector; 64*02c50d82SAndre Fischer } 65*02c50d82SAndre Fischer 66*02c50d82SAndre Fischer 67*02c50d82SAndre Fischer 68*02c50d82SAndre Fischer 69*02c50d82SAndre Fischer RecentMasterPagesSelector::RecentMasterPagesSelector ( 70*02c50d82SAndre Fischer ::Window* pParent, 71*02c50d82SAndre Fischer SdDrawDocument& rDocument, 72*02c50d82SAndre Fischer 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) 76*02c50d82SAndre Fischer { 77*02c50d82SAndre Fischer } 78*02c50d82SAndre Fischer 79*02c50d82SAndre Fischer 80*02c50d82SAndre Fischer 81*02c50d82SAndre Fischer 82*02c50d82SAndre Fischer RecentMasterPagesSelector::~RecentMasterPagesSelector (void) 83*02c50d82SAndre Fischer { 84*02c50d82SAndre Fischer RecentlyUsedMasterPages::Instance().RemoveEventListener ( 85*02c50d82SAndre Fischer LINK(this,RecentMasterPagesSelector,MasterPageListListener)); 86*02c50d82SAndre Fischer } 87*02c50d82SAndre Fischer 88*02c50d82SAndre Fischer 89*02c50d82SAndre Fischer 90*02c50d82SAndre Fischer 91*02c50d82SAndre Fischer void RecentMasterPagesSelector::LateInit (void) 92*02c50d82SAndre Fischer { 93*02c50d82SAndre Fischer MasterPagesSelector::LateInit(); 94*02c50d82SAndre Fischer 95*02c50d82SAndre Fischer MasterPagesSelector::Fill(); 96*02c50d82SAndre Fischer RecentlyUsedMasterPages::Instance().AddEventListener ( 97*02c50d82SAndre Fischer LINK(this,RecentMasterPagesSelector,MasterPageListListener)); 98*02c50d82SAndre Fischer } 99*02c50d82SAndre Fischer 100*02c50d82SAndre Fischer 101*02c50d82SAndre Fischer 102*02c50d82SAndre Fischer 103*02c50d82SAndre Fischer IMPL_LINK(RecentMasterPagesSelector,MasterPageListListener, void*, EMPTYARG) 104*02c50d82SAndre Fischer { 105*02c50d82SAndre Fischer MasterPagesSelector::Fill(); 106*02c50d82SAndre Fischer return 0; 107*02c50d82SAndre Fischer } 108*02c50d82SAndre Fischer 109*02c50d82SAndre Fischer 110*02c50d82SAndre Fischer 111*02c50d82SAndre Fischer 112*02c50d82SAndre Fischer void RecentMasterPagesSelector::Fill (ItemList& rItemList) 113*02c50d82SAndre Fischer { 114*02c50d82SAndre Fischer // Create a set of names of the master pages used by the document. 115*02c50d82SAndre Fischer MasterPageObserver::MasterPageNameSet aCurrentNames; 116*02c50d82SAndre Fischer sal_uInt16 nMasterPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD); 117*02c50d82SAndre Fischer sal_uInt16 nIndex; 118*02c50d82SAndre Fischer for (nIndex=0; nIndex<nMasterPageCount; nIndex++) 119*02c50d82SAndre Fischer { 120*02c50d82SAndre Fischer SdPage* pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD); 121*02c50d82SAndre Fischer if (pMasterPage != NULL) 122*02c50d82SAndre Fischer aCurrentNames.insert (pMasterPage->GetName()); 123*02c50d82SAndre Fischer } 124*02c50d82SAndre Fischer MasterPageObserver::MasterPageNameSet::iterator aI; 125*02c50d82SAndre Fischer 126*02c50d82SAndre Fischer // Insert the recently used master pages that are currently not used. 127*02c50d82SAndre Fischer RecentlyUsedMasterPages& rInstance (RecentlyUsedMasterPages::Instance()); 128*02c50d82SAndre Fischer int nPageCount = rInstance.GetMasterPageCount(); 129*02c50d82SAndre Fischer for (nIndex=0; nIndex<nPageCount; nIndex++) 130*02c50d82SAndre Fischer { 131*02c50d82SAndre Fischer // Add an entry when a) the page is already known to the 132*02c50d82SAndre Fischer // MasterPageContainer, b) the style name is empty, i.e. it has not yet 133*02c50d82SAndre Fischer // been loaded (and thus can not be in use) or otherwise c) the 134*02c50d82SAndre Fischer // style name is not currently in use. 135*02c50d82SAndre Fischer MasterPageContainer::Token aToken (rInstance.GetTokenForIndex(nIndex)); 136*02c50d82SAndre Fischer if (aToken != MasterPageContainer::NIL_TOKEN) 137*02c50d82SAndre Fischer { 138*02c50d82SAndre Fischer String sStyleName (mpContainer->GetStyleNameForToken(aToken)); 139*02c50d82SAndre Fischer if (sStyleName.Len()==0 140*02c50d82SAndre Fischer || aCurrentNames.find(sStyleName) == aCurrentNames.end()) 141*02c50d82SAndre Fischer { 142*02c50d82SAndre Fischer rItemList.push_back(aToken); 143*02c50d82SAndre Fischer } 144*02c50d82SAndre Fischer } 145*02c50d82SAndre Fischer } 146*02c50d82SAndre Fischer } 147*02c50d82SAndre Fischer 148*02c50d82SAndre Fischer 149*02c50d82SAndre Fischer 150*02c50d82SAndre Fischer 151*02c50d82SAndre Fischer void RecentMasterPagesSelector::AssignMasterPageToPageList ( 152*02c50d82SAndre Fischer SdPage* pMasterPage, 153*02c50d82SAndre Fischer const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList) 154*02c50d82SAndre Fischer { 155*02c50d82SAndre Fischer sal_uInt16 nSelectedItemId = PreviewValueSet::GetSelectItemId(); 156*02c50d82SAndre Fischer 157*02c50d82SAndre Fischer MasterPagesSelector::AssignMasterPageToPageList(pMasterPage, rpPageList); 158*02c50d82SAndre Fischer 159*02c50d82SAndre Fischer // Restore the selection. 160*02c50d82SAndre Fischer if (PreviewValueSet::GetItemCount() > 0) 161*02c50d82SAndre Fischer { 162*02c50d82SAndre Fischer if (PreviewValueSet::GetItemCount() >= nSelectedItemId) 163*02c50d82SAndre Fischer PreviewValueSet::SelectItem(nSelectedItemId); 164*02c50d82SAndre Fischer else 165*02c50d82SAndre Fischer PreviewValueSet::SelectItem(PreviewValueSet::GetItemCount()); 166*02c50d82SAndre Fischer } 167*02c50d82SAndre Fischer } 168*02c50d82SAndre Fischer 169*02c50d82SAndre Fischer 170*02c50d82SAndre Fischer 171*02c50d82SAndre Fischer 172*02c50d82SAndre Fischer void RecentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu) 173*02c50d82SAndre Fischer { 174*02c50d82SAndre Fischer if (rMenu.GetItemPos(SID_TP_EDIT_MASTER) != MENU_ITEM_NOTFOUND) 175*02c50d82SAndre Fischer rMenu.EnableItem(SID_TP_EDIT_MASTER, sal_False); 176*02c50d82SAndre Fischer } 177*02c50d82SAndre Fischer 178*02c50d82SAndre Fischer 179*02c50d82SAndre Fischer 180*02c50d82SAndre Fischer 181*02c50d82SAndre Fischer } } // end of namespace sd::sidebar 182