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>
24 #include <sal/log.hxx>
25 #include <vcl/svapp.hxx>
27 /**********************************************************************
31 \**********************************************************************/
33 IconChoicePage::IconChoicePage(weld::Container
* pParent
,
34 const OUString
& rUIXMLDescription
, const OUString
& rID
,
35 const SfxItemSet
* pItemSet
)
36 : xBuilder(Application::CreateBuilder(pParent
, rUIXMLDescription
))
37 , xContainer(xBuilder
->weld_container(rID
))
39 , bHasExchangeSupport(false)
43 IconChoicePage::~IconChoicePage()
47 /**********************************************************************
49 | Activate / Deactivate
51 \**********************************************************************/
53 void IconChoicePage::ActivatePage( const SfxItemSet
& )
58 DeactivateRC
IconChoicePage::DeactivatePage( SfxItemSet
* )
60 return DeactivateRC::LeavePage
;
63 bool IconChoicePage::QueryClose()
68 /**********************************************************************
72 \**********************************************************************/
73 void SvxHpLinkDlg::AddTabPage(const OUString
& rId
, CreatePage pCreateFunc
/* != 0 */)
75 weld::Container
* pPage
= m_xIconCtrl
->get_page(rId
);
76 maPageList
.emplace_back(new IconChoicePageData(rId
, pCreateFunc(pPage
, this, pSet
)));
77 maPageList
.back()->xPage
->Reset(*pSet
);
78 PageCreated(*maPageList
.back()->xPage
);
81 /**********************************************************************
83 | Show / Hide page or button
85 \**********************************************************************/
86 void SvxHpLinkDlg::ShowPage(const OUString
& rId
)
88 OUString sOldPageId
= GetCurPageId();
89 bool bInvalidate
= sOldPageId
!= rId
;
92 IconChoicePageData
* pOldData
= GetPageData(sOldPageId
);
93 if (pOldData
&& pOldData
->xPage
)
102 /**********************************************************************
106 \**********************************************************************/
107 IMPL_LINK(SvxHpLinkDlg
, ChosePageHdl_Impl
, const OUString
&, rId
, void)
109 if (rId
!= msCurrentPageId
)
115 /**********************************************************************
119 \**********************************************************************/
120 IMPL_LINK_NOARG(SvxHpLinkDlg
, ResetHdl
, weld::Button
&, void)
124 IconChoicePageData
* pData
= GetPageData ( msCurrentPageId
);
125 assert( pData
&& "ID not known " );
127 pData
->xPage
->Reset( *pSet
);
130 /**********************************************************************
134 \**********************************************************************/
135 void SvxHpLinkDlg::ActivatePageImpl()
137 assert( !maPageList
.empty() && "no Pages registered " );
138 IconChoicePageData
* pData
= GetPageData ( msCurrentPageId
);
139 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());
151 // tdf#90496 - remember last used view in hyperlink dialog
152 msRememberedPageId
= msCurrentPageId
;
157 void SvxHpLinkDlg::DeActivatePageImpl ()
159 IconChoicePageData
*pData
= GetPageData ( msCurrentPageId
);
161 DeactivateRC nRet
= DeactivateRC::LeavePage
;
166 IconChoicePage
* pPage
= pData
->xPage
.get();
168 if ( !pExampleSet
&& pPage
->HasExchangeSupport() && pSet
)
169 pExampleSet
.reset(new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() ));
173 SfxItemSet
aTmp( *pSet
->GetPool(), pSet
->GetRanges() );
175 if ( pPage
->HasExchangeSupport() )
176 nRet
= pPage
->DeactivatePage( &aTmp
);
178 if ( ( DeactivateRC::LeavePage
& nRet
) &&
182 pExampleSet
->Put(aTmp
);
183 pOutSet
->Put( aTmp
);
188 if ( pPage
->HasExchangeSupport() ) //!!!
192 SfxItemPool
* pPool
= pPage
->GetItemSet().GetPool();
194 new SfxItemSet( *pPool
, GetInputRanges( *pPool
) ) );
196 nRet
= pPage
->DeactivatePage( pExampleSet
.get() );
199 nRet
= pPage
->DeactivatePage( nullptr );
202 if ( nRet
& DeactivateRC::RefreshSet
)
204 // TODO refresh input set
205 // flag all pages to be newly initialized
206 for (auto & pObj
: maPageList
)
208 if ( pObj
->xPage
.get() != pPage
)
209 pObj
->bRefresh
= true;
211 pObj
->bRefresh
= false;
217 void SvxHpLinkDlg::ResetPageImpl ()
219 IconChoicePageData
*pData
= GetPageData ( msCurrentPageId
);
221 assert( pData
&& "ID not known " );
223 pData
->xPage
->Reset( *pSet
);
226 /**********************************************************************
230 \**********************************************************************/
232 WhichRangesContainer
SvxHpLinkDlg::GetInputRanges( const SfxItemPool
& )
236 SAL_WARN( "cui.dialogs", "Set does already exist!" );
237 return pSet
->GetRanges();
240 if ( !pRanges
.empty() )
243 return WhichRangesContainer();
247 void SvxHpLinkDlg::SetInputSet( const SfxItemSet
* pInSet
)
249 bool bSet
= ( pSet
!= nullptr );
253 if ( !bSet
&& !pExampleSet
&& !pOutSet
)
255 pExampleSet
.reset(new SfxItemSet( *pSet
));
256 pOutSet
.reset(new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() ));
260 bool SvxHpLinkDlg::QueryClose()
263 for (auto & pData
: maPageList
)
265 if ( pData
->xPage
&& !pData
->xPage
->QueryClose() )
274 void SvxHpLinkDlg::Start()
276 SwitchPage(msCurrentPageId
);
280 /**********************************************************************
284 \**********************************************************************/
286 IconChoicePageData
* SvxHpLinkDlg::GetPageData ( std::u16string_view rId
)
288 IconChoicePageData
*pRet
= nullptr;
289 for (const auto & pData
: maPageList
)
291 if ( pData
->sId
== rId
)
300 /**********************************************************************
304 \**********************************************************************/
306 void SvxHpLinkDlg::SwitchPage( const OUString
& rId
)
308 m_xIconCtrl
->set_current_page(rId
);
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */