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 <cassert>
24 #include <sal/log.hxx>
25 #include <vcl/svapp.hxx>
26 
27 /**********************************************************************
28 |
29 | Ctor / Dtor
30 |
31 \**********************************************************************/
32 
34  const OUString& rUIXMLDescription, const OString& rID,
35  const SfxItemSet* pItemSet)
36  : xBuilder(Application::CreateBuilder(pParent, rUIXMLDescription))
37  , xContainer(xBuilder->weld_container(rID))
38  , pSet(pItemSet)
39  , bHasExchangeSupport(false)
40 {
41 }
42 
44 {
45 }
46 
47 /**********************************************************************
48 |
49 | Activate / Deactivate
50 |
51 \**********************************************************************/
52 
54 {
55 }
56 
57 
59 {
60  return DeactivateRC::LeavePage;
61 }
62 
64 {
65  return true;
66 }
67 
68 /**********************************************************************
69 |
70 | add new page
71 |
72 \**********************************************************************/
73 void SvxHpLinkDlg::AddTabPage(const OString& rId, CreatePage pCreateFunc /* != 0 */)
74 {
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(rId, *maPageList.back()->xPage);
79 }
80 
81 /**********************************************************************
82 |
83 | Show / Hide page or button
84 |
85 \**********************************************************************/
86 void SvxHpLinkDlg::ShowPage(const OString& rId)
87 {
88  OString sOldPageId = GetCurPageId();
89  bool bInvalidate = sOldPageId != rId;
90  if (bInvalidate)
91  {
92  IconChoicePageData* pOldData = GetPageData(sOldPageId);
93  if (pOldData && pOldData->xPage)
94  {
96  }
97  }
98  SetCurPageId(rId);
100 }
101 
102 /**********************************************************************
103 |
104 | select a page
105 |
106 \**********************************************************************/
107 IMPL_LINK(SvxHpLinkDlg, ChosePageHdl_Impl, const OString&, rId, void)
108 {
109  if (rId != msCurrentPageId)
110  {
111  ShowPage(rId);
112  }
113 }
114 
115 /**********************************************************************
116 |
117 | Button-handler
118 |
119 \**********************************************************************/
121 {
122  ResetPageImpl ();
123 
124  IconChoicePageData* pData = GetPageData ( msCurrentPageId );
125  assert( pData && "ID not known " );
126 
127  pData->xPage->Reset( *pSet );
128 }
129 
130 /**********************************************************************
131 |
132 | call page
133 |
134 \**********************************************************************/
136 {
137  assert( !maPageList.empty() && "no Pages registered " );
139  assert( pData && "ID not known " );
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  m_xResetBtn->show();
152 }
153 
155 {
157 
158  DeactivateRC nRet = DeactivateRC::LeavePage;
159 
160  if ( !pData )
161  return;
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 
215 {
217 
218  assert( pData && "ID not known " );
219 
220  pData->xPage->Reset( *pSet );
221 }
222 
223 /**********************************************************************
224 |
225 | handling itemsets
226 |
227 \**********************************************************************/
228 
229 const sal_uInt16* SvxHpLinkDlg::GetInputRanges( const SfxItemPool& )
230 {
231  if ( pSet )
232  {
233  SAL_WARN( "cui.dialogs", "Set does already exist!" );
234  return pSet->GetRanges();
235  }
236 
237  if ( pRanges )
238  return pRanges.get();
239 
240  pRanges.reset(new sal_uInt16[1]);
241  pRanges[0] = 0;
242 
243  return pRanges.get();
244 }
245 
246 
248 {
249  bool bSet = ( pSet != nullptr );
250 
251  pSet = pInSet;
252 
253  if ( !bSet && !pExampleSet && !pOutSet )
254  {
255  pExampleSet = new SfxItemSet( *pSet );
256  pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
257  }
258 }
259 
261 {
262  bool bRet = true;
263  for (auto & pData : maPageList)
264  {
265  if ( pData->xPage && !pData->xPage->QueryClose() )
266  {
267  bRet = false;
268  break;
269  }
270  }
271  return bRet;
272 }
273 
275 {
278 }
279 
280 /**********************************************************************
281 |
282 | tool-methods
283 |
284 \**********************************************************************/
285 
287 {
288  IconChoicePageData *pRet = nullptr;
289  for (const auto & pData : maPageList)
290  {
291  if ( pData->sId == rId )
292  {
293  pRet = pData.get();
294  break;
295  }
296  }
297  return pRet;
298 }
299 
300 /**********************************************************************
301 |
302 | OK-Status
303 |
304 \**********************************************************************/
305 
306 void SvxHpLinkDlg::SwitchPage( const OString& rId )
307 {
308  m_xIconCtrl->set_current_page(rId);
309 }
310 
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet)
Definition: iconcdlg.cxx:58
void SetCurPageId(const OString &rId)
std::unique_ptr< ContentProperties > pData
IMPL_LINK(SvxHpLinkDlg, ChosePageHdl_Impl, const OString &, rId, void)
Definition: iconcdlg.cxx:107
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:274
SfxItemSet * pExampleSet
Definition: cuihyperdlg.hxx:74
void ActivatePageImpl()
Definition: iconcdlg.cxx:135
bool QueryClose()
Definition: iconcdlg.cxx:260
OString msCurrentPageId
Definition: cuihyperdlg.hxx:70
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void PageCreated(const OString &rId, IconChoicePage &rPage)
IconChoicePage(weld::Container *pParent, const OUString &rUIXMLDescription, const OString &rID, const SfxItemSet *pItemSet)
Definition: iconcdlg.cxx:33
virtual ~IconChoicePage()
Definition: iconcdlg.cxx:43
IMPL_LINK_NOARG(SvxHpLinkDlg, ResetHdl, weld::Button &, void)
Definition: iconcdlg.cxx:120
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:286
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:154
std::unique_ptr< sal_uInt16[]> pRanges
Definition: cuihyperdlg.hxx:75
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
Reference< XExecutableDialog > m_xDialog
virtual void ActivatePage(const SfxItemSet &)
Definition: iconcdlg.cxx:53
void ShowPage(const OString &rId)
Definition: iconcdlg.cxx:86
DeactivateRC
const sal_uInt16 * GetRanges() const
void ResetPageImpl()
Definition: iconcdlg.cxx:214
#define SAL_WARN(area, stream)
const sal_uInt16 * GetInputRanges(const SfxItemPool &)
gives via map converted local slots if applicable
Definition: iconcdlg.cxx:229
void SetInputSet(const SfxItemSet *pInSet)
Definition: iconcdlg.cxx:247
void AddTabPage(const OString &rId, CreatePage pCreateFunc)
Definition: iconcdlg.cxx:73
virtual bool QueryClose()
Definition: iconcdlg.cxx:63
void SwitchPage(const OString &rId)
Definition: iconcdlg.cxx:306
Data-structure for pages in dialog.
Definition: iconcdlg.hxx:36
std::unique_ptr< weld::Button > m_xResetBtn
Definition: cuihyperdlg.hxx:88