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 <comphelper/lok.hxx>
22 #include <cuihyperdlg.hxx>
25 #include <sal/log.hxx>
26 #include <vcl/svapp.hxx>
28 /**********************************************************************
32 \**********************************************************************/
34 IconChoicePage::IconChoicePage(weld::Container
* pParent
,
35 const OUString
& rUIXMLDescription
, const OUString
& rID
,
36 const SfxItemSet
* pItemSet
)
37 : xBuilder(Application::CreateBuilder(pParent
, rUIXMLDescription
))
38 , xContainer(xBuilder
->weld_container(rID
))
40 , bHasExchangeSupport(false)
44 IconChoicePage::~IconChoicePage()
48 /**********************************************************************
50 | Activate / Deactivate
52 \**********************************************************************/
54 void IconChoicePage::ActivatePage( const SfxItemSet
& )
59 DeactivateRC
IconChoicePage::DeactivatePage( SfxItemSet
* )
61 return DeactivateRC::LeavePage
;
64 bool IconChoicePage::QueryClose()
69 /**********************************************************************
73 \**********************************************************************/
74 void SvxHpLinkDlg::AddTabPage(const OUString
& rId
, CreatePage pCreateFunc
/* != 0 */)
76 weld::Container
* pPage
= m_xIconCtrl
->get_page(rId
);
77 maPageList
.emplace_back(new IconChoicePageData(rId
, pCreateFunc(pPage
, this, pSet
)));
78 maPageList
.back()->xPage
->Reset(*pSet
);
79 PageCreated(*maPageList
.back()->xPage
);
82 /**********************************************************************
84 | Show / Hide page or button
86 \**********************************************************************/
87 void SvxHpLinkDlg::ShowPage(const OUString
& rId
)
89 OUString sOldPageId
= GetCurPageId();
90 bool bInvalidate
= sOldPageId
!= rId
;
93 IconChoicePageData
* pOldData
= GetPageData(sOldPageId
);
94 if (pOldData
&& pOldData
->xPage
)
103 /**********************************************************************
107 \**********************************************************************/
108 IMPL_LINK(SvxHpLinkDlg
, ChosePageHdl_Impl
, const OUString
&, rId
, void)
110 if (rId
!= msCurrentPageId
)
116 /**********************************************************************
120 \**********************************************************************/
121 IMPL_LINK_NOARG(SvxHpLinkDlg
, ResetHdl
, weld::Button
&, void)
125 IconChoicePageData
* pData
= GetPageData ( msCurrentPageId
);
126 assert( pData
&& "ID not known " );
128 pData
->xPage
->Reset( *pSet
);
131 /**********************************************************************
135 \**********************************************************************/
136 void SvxHpLinkDlg::ActivatePageImpl()
138 assert( !maPageList
.empty() && "no Pages registered " );
139 IconChoicePageData
* pData
= GetPageData ( msCurrentPageId
);
140 assert( pData
&& "ID not known " );
142 if ( pData
->bRefresh
)
144 pData
->xPage
->Reset( *pSet
);
145 pData
->bRefresh
= false;
149 pData
->xPage
->ActivatePage( *pExampleSet
);
150 m_xDialog
->set_help_id(pData
->xPage
->GetHelpId());
152 // tdf#90496 - remember last used view in hyperlink dialog
153 msRememberedPageId
= msCurrentPageId
;
155 if (!comphelper::LibreOfficeKit::isActive())
159 void SvxHpLinkDlg::DeActivatePageImpl ()
161 IconChoicePageData
*pData
= GetPageData ( msCurrentPageId
);
163 DeactivateRC nRet
= DeactivateRC::LeavePage
;
168 IconChoicePage
* pPage
= pData
->xPage
.get();
170 if ( !pExampleSet
&& pPage
->HasExchangeSupport() && pSet
)
171 pExampleSet
.reset(new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() ));
175 SfxItemSet
aTmp( *pSet
->GetPool(), pSet
->GetRanges() );
177 if ( pPage
->HasExchangeSupport() )
178 nRet
= pPage
->DeactivatePage( &aTmp
);
180 if ( ( DeactivateRC::LeavePage
& nRet
) &&
184 pExampleSet
->Put(aTmp
);
185 pOutSet
->Put( aTmp
);
190 if ( pPage
->HasExchangeSupport() ) //!!!
194 SfxItemPool
* pPool
= pPage
->GetItemSet().GetPool();
196 new SfxItemSet( *pPool
, GetInputRanges( *pPool
) ) );
198 nRet
= pPage
->DeactivatePage( pExampleSet
.get() );
201 nRet
= pPage
->DeactivatePage( nullptr );
204 if ( nRet
& DeactivateRC::RefreshSet
)
206 // TODO refresh input set
207 // flag all pages to be newly initialized
208 for (auto & pObj
: maPageList
)
210 if ( pObj
->xPage
.get() != pPage
)
211 pObj
->bRefresh
= true;
213 pObj
->bRefresh
= false;
219 void SvxHpLinkDlg::ResetPageImpl ()
221 IconChoicePageData
*pData
= GetPageData ( msCurrentPageId
);
223 assert( pData
&& "ID not known " );
225 pData
->xPage
->Reset( *pSet
);
228 /**********************************************************************
232 \**********************************************************************/
234 WhichRangesContainer
SvxHpLinkDlg::GetInputRanges( const SfxItemPool
& )
238 SAL_WARN( "cui.dialogs", "Set does already exist!" );
239 return pSet
->GetRanges();
242 if ( !pRanges
.empty() )
245 return WhichRangesContainer();
249 void SvxHpLinkDlg::SetInputSet( const SfxItemSet
* pInSet
)
251 bool bSet
= ( pSet
!= nullptr );
255 if ( !bSet
&& !pExampleSet
&& !pOutSet
)
257 pExampleSet
.reset(new SfxItemSet( *pSet
));
258 pOutSet
.reset(new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() ));
262 bool SvxHpLinkDlg::QueryClose()
265 for (auto & pData
: maPageList
)
267 if ( pData
->xPage
&& !pData
->xPage
->QueryClose() )
276 void SvxHpLinkDlg::Start()
278 SwitchPage(msCurrentPageId
);
282 /**********************************************************************
286 \**********************************************************************/
288 IconChoicePageData
* SvxHpLinkDlg::GetPageData ( std::u16string_view rId
)
290 IconChoicePageData
*pRet
= nullptr;
291 for (const auto & pData
: maPageList
)
293 if ( pData
->sId
== rId
)
302 /**********************************************************************
306 \**********************************************************************/
308 void SvxHpLinkDlg::SwitchPage( const OUString
& rId
)
310 m_xIconCtrl
->set_current_page(rId
);
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */