tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / cui / source / dialogs / iconcdlg.cxx
blob9bda9d215dcfd3f1cb5ca5089d4ab5d44b4aede6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <cassert>
25 #include <sal/log.hxx>
26 #include <vcl/svapp.hxx>
28 /**********************************************************************
30 | Ctor / Dtor
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))
39 , pSet(pItemSet)
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()
66 return true;
69 /**********************************************************************
71 | add new page
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;
91 if (bInvalidate)
93 IconChoicePageData* pOldData = GetPageData(sOldPageId);
94 if (pOldData && pOldData->xPage)
96 DeActivatePageImpl();
99 SetCurPageId(rId);
100 ActivatePageImpl();
103 /**********************************************************************
105 | select a page
107 \**********************************************************************/
108 IMPL_LINK(SvxHpLinkDlg, ChosePageHdl_Impl, const OUString&, rId, void)
110 if (rId != msCurrentPageId)
112 ShowPage(rId);
116 /**********************************************************************
118 | Button-handler
120 \**********************************************************************/
121 IMPL_LINK_NOARG(SvxHpLinkDlg, ResetHdl, weld::Button&, void)
123 ResetPageImpl ();
125 IconChoicePageData* pData = GetPageData ( msCurrentPageId );
126 assert( pData && "ID not known " );
128 pData->xPage->Reset( *pSet );
131 /**********************************************************************
133 | call page
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;
148 if ( pExampleSet )
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())
156 m_xResetBtn->show();
159 void SvxHpLinkDlg::DeActivatePageImpl ()
161 IconChoicePageData *pData = GetPageData ( msCurrentPageId );
163 DeactivateRC nRet = DeactivateRC::LeavePage;
165 if ( !pData )
166 return;
168 IconChoicePage * pPage = pData->xPage.get();
170 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
171 pExampleSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
173 if ( pSet )
175 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
177 if ( pPage->HasExchangeSupport() )
178 nRet = pPage->DeactivatePage( &aTmp );
180 if ( ( DeactivateRC::LeavePage & nRet ) &&
181 aTmp.Count() )
183 if (pExampleSet)
184 pExampleSet->Put(aTmp);
185 pOutSet->Put( aTmp );
188 else
190 if ( pPage->HasExchangeSupport() ) //!!!
192 if ( !pExampleSet )
194 SfxItemPool* pPool = pPage->GetItemSet().GetPool();
195 pExampleSet.reset(
196 new SfxItemSet( *pPool, GetInputRanges( *pPool ) ) );
198 nRet = pPage->DeactivatePage( pExampleSet.get() );
200 else
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;
212 else
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 /**********************************************************************
230 | handling itemsets
232 \**********************************************************************/
234 WhichRangesContainer SvxHpLinkDlg::GetInputRanges( const SfxItemPool& )
236 if ( pSet )
238 SAL_WARN( "cui.dialogs", "Set does already exist!" );
239 return pSet->GetRanges();
242 if ( !pRanges.empty() )
243 return pRanges;
245 return WhichRangesContainer();
249 void SvxHpLinkDlg::SetInputSet( const SfxItemSet* pInSet )
251 bool bSet = ( pSet != nullptr );
253 pSet = pInSet;
255 if ( !bSet && !pExampleSet && !pOutSet )
257 pExampleSet.reset(new SfxItemSet( *pSet ));
258 pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
262 bool SvxHpLinkDlg::QueryClose()
264 bool bRet = true;
265 for (auto & pData : maPageList)
267 if ( pData->xPage && !pData->xPage->QueryClose() )
269 bRet = false;
270 break;
273 return bRet;
276 void SvxHpLinkDlg::Start()
278 SwitchPage(msCurrentPageId);
279 ActivatePageImpl();
282 /**********************************************************************
284 | tool-methods
286 \**********************************************************************/
288 IconChoicePageData* SvxHpLinkDlg::GetPageData ( std::u16string_view rId )
290 IconChoicePageData *pRet = nullptr;
291 for (const auto & pData : maPageList)
293 if ( pData->sId == rId )
295 pRet = pData.get();
296 break;
299 return pRet;
302 /**********************************************************************
304 | OK-Status
306 \**********************************************************************/
308 void SvxHpLinkDlg::SwitchPage( const OUString& rId )
310 m_xIconCtrl->set_current_page(rId);
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */