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 .
21 #include "RecentMasterPagesSelector.hxx"
22 #include "PreviewValueSet.hxx"
24 #include "RecentlyUsedMasterPages.hxx"
25 #include "MasterPageContainerProviders.hxx"
26 #include "MasterPageObserver.hxx"
28 #include "drawdoc.hxx"
30 #include <vcl/bitmap.hxx>
32 namespace sd
{ namespace toolpanel
{ namespace controls
{
35 RecentMasterPagesSelector::RecentMasterPagesSelector (
37 SdDrawDocument
& rDocument
,
39 const ::boost::shared_ptr
<MasterPageContainer
>& rpContainer
)
40 : MasterPagesSelector (pParent
, rDocument
, rBase
, rpContainer
)
42 SetName (OUString("RecentMasterPagesSelector"));
48 RecentMasterPagesSelector::~RecentMasterPagesSelector (void)
50 RecentlyUsedMasterPages::Instance().RemoveEventListener (
51 LINK(this,RecentMasterPagesSelector
,MasterPageListListener
));
57 void RecentMasterPagesSelector::LateInit (void)
59 MasterPagesSelector::LateInit();
61 MasterPagesSelector::Fill();
62 RecentlyUsedMasterPages::Instance().AddEventListener (
63 LINK(this,RecentMasterPagesSelector
,MasterPageListListener
));
69 IMPL_LINK_NOARG(RecentMasterPagesSelector
, MasterPageListListener
)
71 MasterPagesSelector::Fill();
78 void RecentMasterPagesSelector::Fill (ItemList
& rItemList
)
80 // Create a set of names of the master pages used by the document.
81 MasterPageObserver::MasterPageNameSet aCurrentNames
;
82 sal_uInt16 nMasterPageCount
= mrDocument
.GetMasterSdPageCount(PK_STANDARD
);
84 for (nIndex
=0; nIndex
<nMasterPageCount
; nIndex
++)
86 SdPage
* pMasterPage
= mrDocument
.GetMasterSdPage (nIndex
, PK_STANDARD
);
87 if (pMasterPage
!= NULL
)
88 aCurrentNames
.insert (pMasterPage
->GetName());
90 MasterPageObserver::MasterPageNameSet::iterator aI
;
92 // Insert the recently used master pages that are currently not used.
93 RecentlyUsedMasterPages
& rInstance (RecentlyUsedMasterPages::Instance());
94 int nPageCount
= rInstance
.GetMasterPageCount();
95 for (nIndex
=0; nIndex
<nPageCount
; nIndex
++)
97 // Add an entry when a) the page is already known to the
98 // MasterPageContainer, b) the style name is empty, i.e. it has not yet
99 // been loaded (and thus can not be in use) or otherwise c) the
100 // style name is not currently in use.
101 MasterPageContainer::Token
aToken (rInstance
.GetTokenForIndex(nIndex
));
102 if (aToken
!= MasterPageContainer::NIL_TOKEN
)
104 String
sStyleName (mpContainer
->GetStyleNameForToken(aToken
));
105 if (sStyleName
.Len()==0
106 || aCurrentNames
.find(sStyleName
) == aCurrentNames
.end())
108 rItemList
.push_back(aToken
);
117 void RecentMasterPagesSelector::AssignMasterPageToPageList (
119 const ::boost::shared_ptr
<std::vector
<SdPage
*> >& rpPageList
)
121 sal_uInt16 nSelectedItemId
= mpPageSet
->GetSelectItemId();
123 MasterPagesSelector::AssignMasterPageToPageList(pMasterPage
, rpPageList
);
125 // Restore the selection.
126 if (mpPageSet
->GetItemCount() > 0)
128 if (mpPageSet
->GetItemCount() >= nSelectedItemId
)
129 mpPageSet
->SelectItem(nSelectedItemId
);
131 mpPageSet
->SelectItem(mpPageSet
->GetItemCount());
138 void RecentMasterPagesSelector::GetState (SfxItemSet
& rItemSet
)
140 MasterPagesSelector::GetState (rItemSet
);
141 if (rItemSet
.GetItemState(SID_TP_EDIT_MASTER
) == SFX_ITEM_AVAILABLE
)
142 rItemSet
.DisableItem (SID_TP_EDIT_MASTER
);
148 } } } // end of namespace ::sd::toolpanel::controls
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */