1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <iconcdlg.hxx>
21 #include <cuihyperdlg.hxx>
22
23 #include <sal/log.hxx>
24 #include <vcl/svapp.hxx>
25
26 /**********************************************************************
27 |
28 | Ctor / Dtor
29 |
30 \**********************************************************************/
31
IconChoicePage(weld::Container * pParent,const OUString & rUIXMLDescription,const OString & rID,const SfxItemSet * pItemSet)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)
39 {
40 }
41
~IconChoicePage()42 IconChoicePage::~IconChoicePage()
43 {
44 }
45
46 /**********************************************************************
47 |
48 | Activate / Deactivate
49 |
50 \**********************************************************************/
51
ActivatePage(const SfxItemSet &)52 void IconChoicePage::ActivatePage( const SfxItemSet& )
53 {
54 }
55
56
DeactivatePage(SfxItemSet *)57 DeactivateRC IconChoicePage::DeactivatePage( SfxItemSet* )
58 {
59 return DeactivateRC::LeavePage;
60 }
61
QueryClose()62 bool IconChoicePage::QueryClose()
63 {
64 return true;
65 }
66
67 /**********************************************************************
68 |
69 | add new page
70 |
71 \**********************************************************************/
AddTabPage(const OString & rId,CreatePage pCreateFunc)72 void SvxHpLinkDlg::AddTabPage(const OString& rId, CreatePage pCreateFunc /* != 0 */)
73 {
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);
78 }
79
80 /**********************************************************************
81 |
82 | Show / Hide page or button
83 |
84 \**********************************************************************/
ShowPage(const OString & rId)85 void SvxHpLinkDlg::ShowPage(const OString& rId)
86 {
87 OString sOldPageId = GetCurPageId();
88 bool bInvalidate = sOldPageId != rId;
89 if (bInvalidate)
90 {
91 IconChoicePageData* pOldData = GetPageData(sOldPageId);
92 if (pOldData && pOldData->xPage)
93 {
94 DeActivatePageImpl();
95 }
96 }
97 SetCurPageId(rId);
98 ActivatePageImpl();
99 }
100
101 /**********************************************************************
102 |
103 | select a page
104 |
105 \**********************************************************************/
IMPL_LINK(SvxHpLinkDlg,ChosePageHdl_Impl,const OString &,rId,void)106 IMPL_LINK(SvxHpLinkDlg, ChosePageHdl_Impl, const OString&, rId, void)
107 {
108 if (rId != msCurrentPageId)
109 {
110 ShowPage(rId);
111 }
112 }
113
114 /**********************************************************************
115 |
116 | Button-handler
117 |
118 \**********************************************************************/
IMPL_LINK_NOARG(SvxHpLinkDlg,ResetHdl,weld::Button &,void)119 IMPL_LINK_NOARG(SvxHpLinkDlg, ResetHdl, weld::Button&, void)
120 {
121 ResetPageImpl ();
122
123 IconChoicePageData* pData = GetPageData ( msCurrentPageId );
124 DBG_ASSERT( pData, "ID not known" );
125
126 pData->xPage->Reset( *pSet );
127 }
128
129 /**********************************************************************
130 |
131 | call page
132 |
133 \**********************************************************************/
ActivatePageImpl()134 void SvxHpLinkDlg::ActivatePageImpl()
135 {
136 DBG_ASSERT( !maPageList.empty(), "no Pages registered" );
137 IconChoicePageData* pData = GetPageData ( msCurrentPageId );
138 DBG_ASSERT( pData, "ID not known" );
139 if ( pData )
140 {
141 if ( pData->bRefresh )
142 {
143 pData->xPage->Reset( *pSet );
144 pData->bRefresh = false;
145 }
146
147 if ( pExampleSet )
148 pData->xPage->ActivatePage( *pExampleSet );
149 m_xDialog->set_help_id(pData->xPage->GetHelpId());
150 }
151
152 m_xResetBtn->show();
153 }
154
DeActivatePageImpl()155 void SvxHpLinkDlg::DeActivatePageImpl ()
156 {
157 IconChoicePageData *pData = GetPageData ( msCurrentPageId );
158
159 DeactivateRC nRet = DeactivateRC::LeavePage;
160
161 if ( pData )
162 {
163 IconChoicePage * pPage = pData->xPage.get();
164
165 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
166 pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
167
168 if ( pSet )
169 {
170 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
171
172 if ( pPage->HasExchangeSupport() )
173 nRet = pPage->DeactivatePage( &aTmp );
174
175 if ( ( DeactivateRC::LeavePage & nRet ) &&
176 aTmp.Count() )
177 {
178 if (pExampleSet)
179 pExampleSet->Put(aTmp);
180 pOutSet->Put( aTmp );
181 }
182 }
183 else
184 {
185 if ( pPage->HasExchangeSupport() ) //!!!
186 {
187 if ( !pExampleSet )
188 {
189 SfxItemPool* pPool = pPage->GetItemSet().GetPool();
190 pExampleSet =
191 new SfxItemSet( *pPool, GetInputRanges( *pPool ) );
192 }
193 nRet = pPage->DeactivatePage( pExampleSet );
194 }
195 else
196 nRet = pPage->DeactivatePage( nullptr );
197 }
198
199 if ( nRet & DeactivateRC::RefreshSet )
200 {
201 // TODO refresh input set
202 // flag all pages to be newly initialized
203 for (auto & pObj : maPageList)
204 {
205 if ( pObj->xPage.get() != pPage )
206 pObj->bRefresh = true;
207 else
208 pObj->bRefresh = false;
209 }
210 }
211 }
212 }
213
214
ResetPageImpl()215 void SvxHpLinkDlg::ResetPageImpl ()
216 {
217 IconChoicePageData *pData = GetPageData ( msCurrentPageId );
218
219 DBG_ASSERT( pData, "ID not known" );
220
221 pData->xPage->Reset( *pSet );
222 }
223
224 /**********************************************************************
225 |
226 | handling itemsets
227 |
228 \**********************************************************************/
229
GetInputRanges(const SfxItemPool &)230 const sal_uInt16* SvxHpLinkDlg::GetInputRanges( const SfxItemPool& )
231 {
232 if ( pSet )
233 {
234 SAL_WARN( "cui.dialogs", "Set does already exist!" );
235 return pSet->GetRanges();
236 }
237
238 if ( pRanges )
239 return pRanges.get();
240
241 pRanges.reset(new sal_uInt16[1]);
242 pRanges[0] = 0;
243
244 return pRanges.get();
245 }
246
247
SetInputSet(const SfxItemSet * pInSet)248 void SvxHpLinkDlg::SetInputSet( const SfxItemSet* pInSet )
249 {
250 bool bSet = ( pSet != nullptr );
251
252 pSet = pInSet;
253
254 if ( !bSet && !pExampleSet && !pOutSet )
255 {
256 pExampleSet = new SfxItemSet( *pSet );
257 pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
258 }
259 }
260
Start()261 void SvxHpLinkDlg::Start()
262 {
263 Start_Impl();
264 }
265
QueryClose()266 bool SvxHpLinkDlg::QueryClose()
267 {
268 bool bRet = true;
269 for (auto & pData : maPageList)
270 {
271 if ( pData->xPage && !pData->xPage->QueryClose() )
272 {
273 bRet = false;
274 break;
275 }
276 }
277 return bRet;
278 }
279
Start_Impl()280 void SvxHpLinkDlg::Start_Impl()
281 {
282 SwitchPage(msCurrentPageId);
283 ActivatePageImpl();
284 }
285
286 /**********************************************************************
287 |
288 | tool-methods
289 |
290 \**********************************************************************/
291
GetPageData(const OString & rId)292 IconChoicePageData* SvxHpLinkDlg::GetPageData ( const OString& rId )
293 {
294 IconChoicePageData *pRet = nullptr;
295 for (const auto & pData : maPageList)
296 {
297 if ( pData->sId == rId )
298 {
299 pRet = pData.get();
300 break;
301 }
302 }
303 return pRet;
304 }
305
306 /**********************************************************************
307 |
308 | OK-Status
309 |
310 \**********************************************************************/
311
SwitchPage(const OString & rId)312 void SvxHpLinkDlg::SwitchPage( const OString& rId )
313 {
314 m_xIconCtrl->set_current_page(rId);
315 }
316
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
318