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 MasterPagesSelector* RecentMasterPagesSelector::Create ( 42 ::Window* pParent, 43 ViewShellBase& rViewShellBase, 44 const cssu::Reference<css::ui::XSidebar>& rxSidebar) 45 { 46 SdDrawDocument* pDocument = rViewShellBase.GetDocument(); 47 if (pDocument == NULL) 48 return NULL; 49 50 ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer()); 51 52 MasterPagesSelector* pSelector( 53 new RecentMasterPagesSelector ( 54 pParent, 55 *pDocument, 56 rViewShellBase, 57 pContainer, 58 rxSidebar)); 59 pSelector->LateInit(); 60 pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_RECENT); 61 62 return pSelector; 63 } 64 65 66 67 RecentMasterPagesSelector::RecentMasterPagesSelector ( 68 ::Window* pParent, 69 SdDrawDocument& rDocument, 70 ViewShellBase& rBase, 71 const ::boost::shared_ptr<MasterPageContainer>& rpContainer, 72 const cssu::Reference<css::ui::XSidebar>& rxSidebar) 73 : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar) 74 { 75 } 76 77 78 79 RecentMasterPagesSelector::~RecentMasterPagesSelector (void) 80 { 81 RecentlyUsedMasterPages::Instance().RemoveEventListener ( 82 LINK(this,RecentMasterPagesSelector,MasterPageListListener)); 83 } 84 85 86 87 void RecentMasterPagesSelector::LateInit (void) 88 { 89 MasterPagesSelector::LateInit(); 90 91 MasterPagesSelector::Fill(); 92 RecentlyUsedMasterPages::Instance().AddEventListener ( 93 LINK(this,RecentMasterPagesSelector,MasterPageListListener)); 94 } 95 96 97 98 IMPL_LINK(RecentMasterPagesSelector,MasterPageListListener, void*, EMPTYARG) 99 { 100 MasterPagesSelector::Fill(); 101 return 0; 102 } 103 104 105 106 void RecentMasterPagesSelector::Fill (ItemList& rItemList) 107 { 108 // Create a set of names of the master pages used by the document. 109 MasterPageObserver::MasterPageNameSet aCurrentNames; 110 sal_uInt16 nMasterPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD); 111 sal_uInt16 nIndex; 112 for (nIndex=0; nIndex<nMasterPageCount; nIndex++) 113 { 114 SdPage* pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD); 115 if (pMasterPage != NULL) 116 aCurrentNames.insert (pMasterPage->GetName()); 117 } 118 MasterPageObserver::MasterPageNameSet::iterator aI; 119 120 // Insert the recently used master pages that are currently not used. 121 RecentlyUsedMasterPages& rInstance (RecentlyUsedMasterPages::Instance()); 122 int nPageCount = rInstance.GetMasterPageCount(); 123 for (nIndex=0; nIndex<nPageCount; nIndex++) 124 { 125 // Add an entry when a) the page is already known to the 126 // MasterPageContainer, b) the style name is empty, i.e. it has not yet 127 // been loaded (and thus can not be in use) or otherwise c) the 128 // style name is not currently in use. 129 MasterPageContainer::Token aToken (rInstance.GetTokenForIndex(nIndex)); 130 if (aToken != MasterPageContainer::NIL_TOKEN) 131 { 132 String sStyleName (mpContainer->GetStyleNameForToken(aToken)); 133 if (sStyleName.Len()==0 134 || aCurrentNames.find(sStyleName) == aCurrentNames.end()) 135 { 136 rItemList.push_back(aToken); 137 } 138 } 139 } 140 } 141 142 143 144 void RecentMasterPagesSelector::AssignMasterPageToPageList ( 145 SdPage* pMasterPage, 146 const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList) 147 { 148 sal_uInt16 nSelectedItemId = PreviewValueSet::GetSelectItemId(); 149 150 MasterPagesSelector::AssignMasterPageToPageList(pMasterPage, rpPageList); 151 152 // Restore the selection. 153 if (PreviewValueSet::GetItemCount() > 0) 154 { 155 if (PreviewValueSet::GetItemCount() >= nSelectedItemId) 156 PreviewValueSet::SelectItem(nSelectedItemId); 157 else 158 PreviewValueSet::SelectItem(PreviewValueSet::GetItemCount()); 159 } 160 } 161 162 163 164 void RecentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu) 165 { 166 if (rMenu.GetItemPos(SID_TP_EDIT_MASTER) != MENU_ITEM_NOTFOUND) 167 rMenu.EnableItem(SID_TP_EDIT_MASTER, sal_False); 168 // Disable some entries 169 if (mpContainer->GetPreviewSize() == MasterPageContainer::SMALL) 170 rMenu.EnableItem(SID_TP_SHOW_SMALL_PREVIEW, sal_False); 171 else 172 rMenu.EnableItem(SID_TP_SHOW_LARGE_PREVIEW, sal_False); 173 } 174 175 } } // end of namespace sd::sidebar 176 177 /* vim: set noet sw=4 ts=4: */ 178