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