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