bump product version to 6.4.0.3
[LibreOffice.git] / cui / source / dialogs / iconcdlg.cxx
blob39864c3a3d3bfa60e0ba42c7d673ff6cc18968a1
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 <cuihyperdlg.hxx>
23 #include <sal/log.hxx>
24 #include <vcl/svapp.hxx>
26 /**********************************************************************
28 | Ctor / Dtor
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))
37 , pSet(pItemSet)
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()
64 return true;
67 /**********************************************************************
69 | add new page
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;
89 if (bInvalidate)
91 IconChoicePageData* pOldData = GetPageData(sOldPageId);
92 if (pOldData && pOldData->xPage)
94 DeActivatePageImpl();
97 SetCurPageId(rId);
98 ActivatePageImpl();
101 /**********************************************************************
103 | select a page
105 \**********************************************************************/
106 IMPL_LINK(SvxHpLinkDlg, ChosePageHdl_Impl, const OString&, rId, void)
108 if (rId != msCurrentPageId)
110 ShowPage(rId);
114 /**********************************************************************
116 | Button-handler
118 \**********************************************************************/
119 IMPL_LINK_NOARG(SvxHpLinkDlg, ResetHdl, weld::Button&, void)
121 ResetPageImpl ();
123 IconChoicePageData* pData = GetPageData ( msCurrentPageId );
124 DBG_ASSERT( pData, "ID not known" );
126 pData->xPage->Reset( *pSet );
129 /**********************************************************************
131 | call page
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" );
139 if ( pData )
141 if ( pData->bRefresh )
143 pData->xPage->Reset( *pSet );
144 pData->bRefresh = false;
147 if ( pExampleSet )
148 pData->xPage->ActivatePage( *pExampleSet );
149 m_xDialog->set_help_id(pData->xPage->GetHelpId());
152 m_xResetBtn->show();
155 void SvxHpLinkDlg::DeActivatePageImpl ()
157 IconChoicePageData *pData = GetPageData ( msCurrentPageId );
159 DeactivateRC nRet = DeactivateRC::LeavePage;
161 if ( pData )
163 IconChoicePage * pPage = pData->xPage.get();
165 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
166 pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
168 if ( pSet )
170 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
172 if ( pPage->HasExchangeSupport() )
173 nRet = pPage->DeactivatePage( &aTmp );
175 if ( ( DeactivateRC::LeavePage & nRet ) &&
176 aTmp.Count() )
178 if (pExampleSet)
179 pExampleSet->Put(aTmp);
180 pOutSet->Put( aTmp );
183 else
185 if ( pPage->HasExchangeSupport() ) //!!!
187 if ( !pExampleSet )
189 SfxItemPool* pPool = pPage->GetItemSet().GetPool();
190 pExampleSet =
191 new SfxItemSet( *pPool, GetInputRanges( *pPool ) );
193 nRet = pPage->DeactivatePage( pExampleSet );
195 else
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;
207 else
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 /**********************************************************************
226 | handling itemsets
228 \**********************************************************************/
230 const sal_uInt16* SvxHpLinkDlg::GetInputRanges( const SfxItemPool& )
232 if ( pSet )
234 SAL_WARN( "cui.dialogs", "Set does already exist!" );
235 return pSet->GetRanges();
238 if ( pRanges )
239 return pRanges.get();
241 pRanges.reset(new sal_uInt16[1]);
242 pRanges[0] = 0;
244 return pRanges.get();
248 void SvxHpLinkDlg::SetInputSet( const SfxItemSet* pInSet )
250 bool bSet = ( pSet != nullptr );
252 pSet = pInSet;
254 if ( !bSet && !pExampleSet && !pOutSet )
256 pExampleSet = new SfxItemSet( *pSet );
257 pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
261 void SvxHpLinkDlg::Start()
263 Start_Impl();
266 bool SvxHpLinkDlg::QueryClose()
268 bool bRet = true;
269 for (auto & pData : maPageList)
271 if ( pData->xPage && !pData->xPage->QueryClose() )
273 bRet = false;
274 break;
277 return bRet;
280 void SvxHpLinkDlg::Start_Impl()
282 SwitchPage(msCurrentPageId);
283 ActivatePageImpl();
286 /**********************************************************************
288 | tool-methods
290 \**********************************************************************/
292 IconChoicePageData* SvxHpLinkDlg::GetPageData ( const OString& rId )
294 IconChoicePageData *pRet = nullptr;
295 for (const auto & pData : maPageList)
297 if ( pData->sId == rId )
299 pRet = pData.get();
300 break;
303 return pRet;
306 /**********************************************************************
308 | OK-Status
310 \**********************************************************************/
312 void SvxHpLinkDlg::SwitchPage( const OString& rId )
314 m_xIconCtrl->set_current_page(rId);
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */