LibreOffice Module cui (master)  1
iconcdlg.cxx
Go to the documentation of this file.
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 
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 
43 {
44 }
45 
46 /**********************************************************************
47 |
48 | Activate / Deactivate
49 |
50 \**********************************************************************/
51 
53 {
54 }
55 
56 
58 {
59  return DeactivateRC::LeavePage;
60 }
61 
63 {
64  return true;
65 }
66 
67 /**********************************************************************
68 |
69 | add new page
70 |
71 \**********************************************************************/
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 \**********************************************************************/
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  {
95  }
96  }
97  SetCurPageId(rId);
99 }
100 
101 /**********************************************************************
102 |
103 | select a page
104 |
105 \**********************************************************************/
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 \**********************************************************************/
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 \**********************************************************************/
135 {
136  DBG_ASSERT( !maPageList.empty(), "no Pages registered" );
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 
156 {
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 
216 {
218 
219  DBG_ASSERT( pData, "ID not known" );
220 
221  pData->xPage->Reset( *pSet );
222 }
223 
224 /**********************************************************************
225 |
226 | handling itemsets
227 |
228 \**********************************************************************/
229 
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 
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 
262 {
263  Start_Impl();
264 }
265 
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 
281 {
284 }
285 
286 /**********************************************************************
287 |
288 | tool-methods
289 |
290 \**********************************************************************/
291 
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 
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: */
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet)
Definition: iconcdlg.cxx:57
void Start_Impl()
Definition: iconcdlg.cxx:280
void SetCurPageId(const OString &rId)
IMPL_LINK(SvxHpLinkDlg, ChosePageHdl_Impl, const OString &, rId, void)
Definition: iconcdlg.cxx:106
OString GetCurPageId() const
std::unique_ptr< IconChoicePage >(* CreatePage)(weld::Container *pParent, SvxHpLinkDlg *pDlg, const SfxItemSet *pAttrSet)
Definition: iconcdlg.hxx:33
void Start()
Definition: iconcdlg.cxx:261
SfxItemSet * pExampleSet
Definition: cuihyperdlg.hxx:74
void ActivatePageImpl()
Definition: iconcdlg.cxx:134
bool QueryClose()
Definition: iconcdlg.cxx:266
OString msCurrentPageId
Definition: cuihyperdlg.hxx:70
void PageCreated(const OString &rId, IconChoicePage &rPage)
IconChoicePage(weld::Container *pParent, const OUString &rUIXMLDescription, const OString &rID, const SfxItemSet *pItemSet)
Definition: iconcdlg.cxx:32
virtual ~IconChoicePage()
Definition: iconcdlg.cxx:42
IMPL_LINK_NOARG(SvxHpLinkDlg, ResetHdl, weld::Button &, void)
Definition: iconcdlg.cxx:119
#define DBG_ASSERT(sCon, aError)
std::unique_ptr< weld::Notebook > m_xIconCtrl
Definition: cuihyperdlg.hxx:83
std::vector< std::unique_ptr< IconChoicePageData > > maPageList
Definition: cuihyperdlg.hxx:68
const SfxItemSet * pSet
Definition: cuihyperdlg.hxx:72
bool HasExchangeSupport() const
Definition: iconcdlg.hxx:74
std::unique_ptr< SfxItemSet > pOutSet
Definition: cuihyperdlg.hxx:73
SfxItemPool * GetPool() const
IconChoicePageData * GetPageData(const OString &rId)
Definition: iconcdlg.cxx:292
const SfxItemSet & GetItemSet() const
Definition: iconcdlg.hxx:69
std::unique_ptr< IconChoicePage > xPage
the TabPage itself
Definition: iconcdlg.hxx:39
void DeActivatePageImpl()
Definition: iconcdlg.cxx:155
std::unique_ptr< sal_uInt16[]> pRanges
Definition: cuihyperdlg.hxx:75
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual void ActivatePage(const SfxItemSet &)
Definition: iconcdlg.cxx:52
void ShowPage(const OString &rId)
Definition: iconcdlg.cxx:85
DeactivateRC
const sal_uInt16 * GetRanges() const
void ResetPageImpl()
Definition: iconcdlg.cxx:215
#define SAL_WARN(area, stream)
const sal_uInt16 * GetInputRanges(const SfxItemPool &)
gives via map converted local slots if applicable
Definition: iconcdlg.cxx:230
void SetInputSet(const SfxItemSet *pInSet)
Definition: iconcdlg.cxx:248
void AddTabPage(const OString &rId, CreatePage pCreateFunc)
Definition: iconcdlg.cxx:72
virtual bool QueryClose()
Definition: iconcdlg.cxx:62
void SwitchPage(const OString &rId)
Definition: iconcdlg.cxx:312
Data-structure for pages in dialog.
Definition: iconcdlg.hxx:36
std::unique_ptr< weld::Button > m_xResetBtn
Definition: cuihyperdlg.hxx:88