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 <iconcdlg.hxx>
21 #include <cuihyperdlg.hxx>
23 #include <sal/log.hxx>
24 #include <vcl/svapp.hxx>
26 /**********************************************************************
30 \**********************************************************************/
32 IconChoicePage::IconChoicePage(weld::Container
* pParent
,
33 const OUString
& rUIXMLDescription
, const OString
& rID
,
34 const SfxItemSet
* pItemSet
)
35 : xBuilder(Application::CreateBuilder(pParent
, rUIXMLDescription
))
36 , xContainer(xBuilder
->weld_container(rID
))
38 , bHasExchangeSupport(false)
42 IconChoicePage::~IconChoicePage()
46 /**********************************************************************
48 | Activate / Deactivate
50 \**********************************************************************/
52 void IconChoicePage::ActivatePage( const SfxItemSet
& )
57 DeactivateRC
IconChoicePage::DeactivatePage( SfxItemSet
* )
59 return DeactivateRC::LeavePage
;
62 bool IconChoicePage::QueryClose()
67 /**********************************************************************
71 \**********************************************************************/
72 void SvxHpLinkDlg::AddTabPage(const OString
& rId
, CreatePage pCreateFunc
/* != 0 */)
74 weld::Container
* pPage
= m_xIconCtrl
->get_page(rId
);
75 maPageList
.emplace_back(new IconChoicePageData(rId
, pCreateFunc(pPage
, this, pSet
)));
76 maPageList
.back()->xPage
->Reset(*pSet
);
77 PageCreated(rId
, *maPageList
.back()->xPage
);
80 /**********************************************************************
82 | Show / Hide page or button
84 \**********************************************************************/
85 void SvxHpLinkDlg::ShowPage(const OString
& rId
)
87 OString sOldPageId
= GetCurPageId();
88 bool bInvalidate
= sOldPageId
!= rId
;
91 IconChoicePageData
* pOldData
= GetPageData(sOldPageId
);
92 if (pOldData
&& pOldData
->xPage
)
101 /**********************************************************************
105 \**********************************************************************/
106 IMPL_LINK(SvxHpLinkDlg
, ChosePageHdl_Impl
, const OString
&, rId
, void)
108 if (rId
!= msCurrentPageId
)
114 /**********************************************************************
118 \**********************************************************************/
119 IMPL_LINK_NOARG(SvxHpLinkDlg
, ResetHdl
, weld::Button
&, void)
123 IconChoicePageData
* pData
= GetPageData ( msCurrentPageId
);
124 DBG_ASSERT( pData
, "ID not known" );
126 pData
->xPage
->Reset( *pSet
);
129 /**********************************************************************
133 \**********************************************************************/
134 void SvxHpLinkDlg::ActivatePageImpl()
136 DBG_ASSERT( !maPageList
.empty(), "no Pages registered" );
137 IconChoicePageData
* pData
= GetPageData ( msCurrentPageId
);
138 DBG_ASSERT( pData
, "ID not known" );
141 if ( pData
->bRefresh
)
143 pData
->xPage
->Reset( *pSet
);
144 pData
->bRefresh
= false;
148 pData
->xPage
->ActivatePage( *pExampleSet
);
149 m_xDialog
->set_help_id(pData
->xPage
->GetHelpId());
155 void SvxHpLinkDlg::DeActivatePageImpl ()
157 IconChoicePageData
*pData
= GetPageData ( msCurrentPageId
);
159 DeactivateRC nRet
= DeactivateRC::LeavePage
;
163 IconChoicePage
* pPage
= pData
->xPage
.get();
165 if ( !pExampleSet
&& pPage
->HasExchangeSupport() && pSet
)
166 pExampleSet
= new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() );
170 SfxItemSet
aTmp( *pSet
->GetPool(), pSet
->GetRanges() );
172 if ( pPage
->HasExchangeSupport() )
173 nRet
= pPage
->DeactivatePage( &aTmp
);
175 if ( ( DeactivateRC::LeavePage
& nRet
) &&
179 pExampleSet
->Put(aTmp
);
180 pOutSet
->Put( aTmp
);
185 if ( pPage
->HasExchangeSupport() ) //!!!
189 SfxItemPool
* pPool
= pPage
->GetItemSet().GetPool();
191 new SfxItemSet( *pPool
, GetInputRanges( *pPool
) );
193 nRet
= pPage
->DeactivatePage( pExampleSet
);
196 nRet
= pPage
->DeactivatePage( nullptr );
199 if ( nRet
& DeactivateRC::RefreshSet
)
201 // TODO refresh input set
202 // flag all pages to be newly initialized
203 for (auto & pObj
: maPageList
)
205 if ( pObj
->xPage
.get() != pPage
)
206 pObj
->bRefresh
= true;
208 pObj
->bRefresh
= false;
215 void SvxHpLinkDlg::ResetPageImpl ()
217 IconChoicePageData
*pData
= GetPageData ( msCurrentPageId
);
219 DBG_ASSERT( pData
, "ID not known" );
221 pData
->xPage
->Reset( *pSet
);
224 /**********************************************************************
228 \**********************************************************************/
230 const sal_uInt16
* SvxHpLinkDlg::GetInputRanges( const SfxItemPool
& )
234 SAL_WARN( "cui.dialogs", "Set does already exist!" );
235 return pSet
->GetRanges();
239 return pRanges
.get();
241 pRanges
.reset(new sal_uInt16
[1]);
244 return pRanges
.get();
248 void SvxHpLinkDlg::SetInputSet( const SfxItemSet
* pInSet
)
250 bool bSet
= ( pSet
!= nullptr );
254 if ( !bSet
&& !pExampleSet
&& !pOutSet
)
256 pExampleSet
= new SfxItemSet( *pSet
);
257 pOutSet
.reset(new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() ));
261 void SvxHpLinkDlg::Start()
266 bool SvxHpLinkDlg::QueryClose()
269 for (auto & pData
: maPageList
)
271 if ( pData
->xPage
&& !pData
->xPage
->QueryClose() )
280 void SvxHpLinkDlg::Start_Impl()
282 SwitchPage(msCurrentPageId
);
286 /**********************************************************************
290 \**********************************************************************/
292 IconChoicePageData
* SvxHpLinkDlg::GetPageData ( const OString
& rId
)
294 IconChoicePageData
*pRet
= nullptr;
295 for (const auto & pData
: maPageList
)
297 if ( pData
->sId
== rId
)
306 /**********************************************************************
310 \**********************************************************************/
312 void SvxHpLinkDlg::SwitchPage( const OString
& rId
)
314 m_xIconCtrl
->set_current_page(rId
);
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */