1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "RecentMasterPagesSelector.hxx"
22 #include "ViewShellBase.hxx"
23 #include "RecentlyUsedMasterPages.hxx"
24 #include "MasterPageContainerProviders.hxx"
25 #include "MasterPageObserver.hxx"
27 #include "drawdoc.hxx"
31 #include <vcl/bitmap.hxx>
33 namespace sd
{ namespace sidebar
{
35 VclPtr
<vcl::Window
> RecentMasterPagesSelector::Create (
37 ViewShellBase
& rViewShellBase
,
38 const css::uno::Reference
<css::ui::XSidebar
>& rxSidebar
)
40 SdDrawDocument
* pDocument
= rViewShellBase
.GetDocument();
41 if (pDocument
== NULL
)
44 ::boost::shared_ptr
<MasterPageContainer
> pContainer (new MasterPageContainer());
46 VclPtrInstance
<RecentMasterPagesSelector
> pSelector(
52 pSelector
->LateInit();
53 pSelector
->SetHelpId(HID_SD_TASK_PANE_PREVIEW_RECENT
);
58 RecentMasterPagesSelector::RecentMasterPagesSelector (
60 SdDrawDocument
& rDocument
,
62 const ::boost::shared_ptr
<MasterPageContainer
>& rpContainer
,
63 const css::uno::Reference
<css::ui::XSidebar
>& rxSidebar
)
64 : MasterPagesSelector (pParent
, rDocument
, rBase
, rpContainer
, rxSidebar
)
68 RecentMasterPagesSelector::~RecentMasterPagesSelector()
73 void RecentMasterPagesSelector::dispose()
75 RecentlyUsedMasterPages::Instance().RemoveEventListener (
76 LINK(this,RecentMasterPagesSelector
,MasterPageListListener
));
77 MasterPagesSelector::dispose();
80 void RecentMasterPagesSelector::LateInit()
82 MasterPagesSelector::LateInit();
84 MasterPagesSelector::Fill();
85 RecentlyUsedMasterPages::Instance().AddEventListener (
86 LINK(this,RecentMasterPagesSelector
,MasterPageListListener
));
89 IMPL_LINK_NOARG(RecentMasterPagesSelector
, MasterPageListListener
)
91 MasterPagesSelector::Fill();
95 void RecentMasterPagesSelector::Fill (ItemList
& rItemList
)
97 // Create a set of names of the master pages used by the document.
98 MasterPageObserver::MasterPageNameSet aCurrentNames
;
99 sal_uInt16 nMasterPageCount
= mrDocument
.GetMasterSdPageCount(PK_STANDARD
);
101 for (nIndex
=0; nIndex
<nMasterPageCount
; nIndex
++)
103 SdPage
* pMasterPage
= mrDocument
.GetMasterSdPage (nIndex
, PK_STANDARD
);
104 if (pMasterPage
!= NULL
)
105 aCurrentNames
.insert (pMasterPage
->GetName());
108 // Insert the recently used master pages that are currently not used.
109 RecentlyUsedMasterPages
& rInstance (RecentlyUsedMasterPages::Instance());
110 int nPageCount
= rInstance
.GetMasterPageCount();
111 for (nIndex
=0; nIndex
<nPageCount
; nIndex
++)
113 // Add an entry when a) the page is already known to the
114 // MasterPageContainer, b) the style name is empty, i.e. it has not yet
115 // been loaded (and thus can not be in use) or otherwise c) the
116 // style name is not currently in use.
117 MasterPageContainer::Token
aToken (rInstance
.GetTokenForIndex(nIndex
));
118 if (aToken
!= MasterPageContainer::NIL_TOKEN
)
120 OUString
sStyleName (mpContainer
->GetStyleNameForToken(aToken
));
121 if (sStyleName
.isEmpty()
122 || aCurrentNames
.find(sStyleName
) == aCurrentNames
.end())
124 rItemList
.push_back(aToken
);
130 void RecentMasterPagesSelector::AssignMasterPageToPageList (
132 const ::boost::shared_ptr
<std::vector
<SdPage
*> >& rpPageList
)
134 sal_uInt16 nSelectedItemId
= PreviewValueSet::GetSelectItemId();
136 MasterPagesSelector::AssignMasterPageToPageList(pMasterPage
, rpPageList
);
138 // Restore the selection.
139 if (PreviewValueSet::GetItemCount() > 0)
141 if (PreviewValueSet::GetItemCount() >= nSelectedItemId
)
142 PreviewValueSet::SelectItem(nSelectedItemId
);
144 PreviewValueSet::SelectItem(PreviewValueSet::GetItemCount());
148 void RecentMasterPagesSelector::ProcessPopupMenu (Menu
& rMenu
)
150 if (rMenu
.GetItemPos(SID_TP_EDIT_MASTER
) != MENU_ITEM_NOTFOUND
)
151 rMenu
.EnableItem(SID_TP_EDIT_MASTER
, false);
154 } } // end of namespace sd::sidebar
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */