android: Update app-specific/MIME type icons
[LibreOffice.git] / cui / source / dialogs / iconcdlg.cxx
blob4aacf0e2b50e99d40ceab1544c198897b2147643
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 <cassert>
24 #include <sal/log.hxx>
25 #include <vcl/svapp.hxx>
27 /**********************************************************************
29 | Ctor / Dtor
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))
38 , pSet(pItemSet)
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()
65 return true;
68 /**********************************************************************
70 | add new page
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;
90 if (bInvalidate)
92 IconChoicePageData* pOldData = GetPageData(sOldPageId);
93 if (pOldData && pOldData->xPage)
95 DeActivatePageImpl();
98 SetCurPageId(rId);
99 ActivatePageImpl();
102 /**********************************************************************
104 | select a page
106 \**********************************************************************/
107 IMPL_LINK(SvxHpLinkDlg, ChosePageHdl_Impl, const OUString&, rId, void)
109 if (rId != msCurrentPageId)
111 ShowPage(rId);
115 /**********************************************************************
117 | Button-handler
119 \**********************************************************************/
120 IMPL_LINK_NOARG(SvxHpLinkDlg, ResetHdl, weld::Button&, void)
122 ResetPageImpl ();
124 IconChoicePageData* pData = GetPageData ( msCurrentPageId );
125 assert( pData && "ID not known " );
127 pData->xPage->Reset( *pSet );
130 /**********************************************************************
132 | call page
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;
147 if ( pExampleSet )
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;
154 m_xResetBtn->show();
157 void SvxHpLinkDlg::DeActivatePageImpl ()
159 IconChoicePageData *pData = GetPageData ( msCurrentPageId );
161 DeactivateRC nRet = DeactivateRC::LeavePage;
163 if ( !pData )
164 return;
166 IconChoicePage * pPage = pData->xPage.get();
168 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
169 pExampleSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
171 if ( pSet )
173 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
175 if ( pPage->HasExchangeSupport() )
176 nRet = pPage->DeactivatePage( &aTmp );
178 if ( ( DeactivateRC::LeavePage & nRet ) &&
179 aTmp.Count() )
181 if (pExampleSet)
182 pExampleSet->Put(aTmp);
183 pOutSet->Put( aTmp );
186 else
188 if ( pPage->HasExchangeSupport() ) //!!!
190 if ( !pExampleSet )
192 SfxItemPool* pPool = pPage->GetItemSet().GetPool();
193 pExampleSet.reset(
194 new SfxItemSet( *pPool, GetInputRanges( *pPool ) ) );
196 nRet = pPage->DeactivatePage( pExampleSet.get() );
198 else
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;
210 else
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 /**********************************************************************
228 | handling itemsets
230 \**********************************************************************/
232 WhichRangesContainer SvxHpLinkDlg::GetInputRanges( const SfxItemPool& )
234 if ( pSet )
236 SAL_WARN( "cui.dialogs", "Set does already exist!" );
237 return pSet->GetRanges();
240 if ( !pRanges.empty() )
241 return pRanges;
243 return WhichRangesContainer();
247 void SvxHpLinkDlg::SetInputSet( const SfxItemSet* pInSet )
249 bool bSet = ( pSet != nullptr );
251 pSet = pInSet;
253 if ( !bSet && !pExampleSet && !pOutSet )
255 pExampleSet.reset(new SfxItemSet( *pSet ));
256 pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
260 bool SvxHpLinkDlg::QueryClose()
262 bool bRet = true;
263 for (auto & pData : maPageList)
265 if ( pData->xPage && !pData->xPage->QueryClose() )
267 bRet = false;
268 break;
271 return bRet;
274 void SvxHpLinkDlg::Start()
276 SwitchPage(msCurrentPageId);
277 ActivatePageImpl();
280 /**********************************************************************
282 | tool-methods
284 \**********************************************************************/
286 IconChoicePageData* SvxHpLinkDlg::GetPageData ( std::u16string_view rId )
288 IconChoicePageData *pRet = nullptr;
289 for (const auto & pData : maPageList)
291 if ( pData->sId == rId )
293 pRet = pData.get();
294 break;
297 return pRet;
300 /**********************************************************************
302 | OK-Status
304 \**********************************************************************/
306 void SvxHpLinkDlg::SwitchPage( const OUString& rId )
308 m_xIconCtrl->set_current_page(rId);
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */