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\**********************************************************************/
73void 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(*maPageList.back()->xPage);
79}
80
81/**********************************************************************
82|
83| Show / Hide page or button
84|
85\**********************************************************************/
86void 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\**********************************************************************/
107IMPL_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.reset(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.reset(
191 new SfxItemSet( *pPool, GetInputRanges( *pPool ) ) );
192 }
193 nRet = pPage->DeactivatePage( pExampleSet.get() );
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
230{
231 if ( pSet )
232 {
233 SAL_WARN( "cui.dialogs", "Set does already exist!" );
234 return pSet->GetRanges();
235 }
236
237 if ( !pRanges.empty() )
238 return pRanges;
239
240 return WhichRangesContainer();
241}
242
243
245{
246 bool bSet = ( pSet != nullptr );
247
248 pSet = pInSet;
249
250 if ( !bSet && !pExampleSet && !pOutSet )
251 {
252 pExampleSet.reset(new SfxItemSet( *pSet ));
253 pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
254 }
255}
256
258{
259 bool bRet = true;
260 for (auto & pData : maPageList)
261 {
262 if ( pData->xPage && !pData->xPage->QueryClose() )
263 {
264 bRet = false;
265 break;
266 }
267 }
268 return bRet;
269}
270
272{
275}
276
277/**********************************************************************
278|
279| tool-methods
280|
281\**********************************************************************/
282
284{
285 IconChoicePageData *pRet = nullptr;
286 for (const auto & pData : maPageList)
287 {
288 if ( pData->sId == rId )
289 {
290 pRet = pData.get();
291 break;
292 }
293 }
294 return pRet;
295}
296
297/**********************************************************************
298|
299| OK-Status
300|
301\**********************************************************************/
302
303void SvxHpLinkDlg::SwitchPage( const OString& rId )
304{
305 m_xIconCtrl->set_current_page(rId);
306}
307
308/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
const SfxItemSet & GetItemSet() const
Definition: iconcdlg.hxx:69
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet)
Definition: iconcdlg.cxx:58
IconChoicePage(weld::Container *pParent, const OUString &rUIXMLDescription, const OString &rID, const SfxItemSet *pItemSet)
Definition: iconcdlg.cxx:33
virtual ~IconChoicePage()
Definition: iconcdlg.cxx:43
bool HasExchangeSupport() const
Definition: iconcdlg.hxx:74
virtual bool QueryClose()
Definition: iconcdlg.cxx:63
virtual void ActivatePage(const SfxItemSet &)
Definition: iconcdlg.cxx:53
const WhichRangesContainer & GetRanges() const
SfxItemPool * GetPool() const
sal_uInt16 Count() const
void AddTabPage(const OString &rId, CreatePage pCreateFunc)
Definition: iconcdlg.cxx:73
void ResetPageImpl()
Definition: iconcdlg.cxx:214
void PageCreated(IconChoicePage &rPage)
WhichRangesContainer pRanges
Definition: cuihyperdlg.hxx:75
const OString & GetCurPageId() const
IconChoicePageData * GetPageData(std::string_view rId)
Definition: iconcdlg.cxx:283
void ActivatePageImpl()
Definition: iconcdlg.cxx:135
OString msCurrentPageId
Definition: cuihyperdlg.hxx:70
void Start()
Definition: iconcdlg.cxx:271
void ShowPage(const OString &rId)
Definition: iconcdlg.cxx:86
std::vector< std::unique_ptr< IconChoicePageData > > maPageList
Definition: cuihyperdlg.hxx:68
std::unique_ptr< SfxItemSet > pOutSet
Definition: cuihyperdlg.hxx:73
std::unique_ptr< SfxItemSet > pExampleSet
Definition: cuihyperdlg.hxx:74
void SetCurPageId(const OString &rId)
std::unique_ptr< weld::Button > m_xResetBtn
Definition: cuihyperdlg.hxx:88
std::unique_ptr< weld::Notebook > m_xIconCtrl
Definition: cuihyperdlg.hxx:83
void SetInputSet(const SfxItemSet *pInSet)
Definition: iconcdlg.cxx:244
WhichRangesContainer GetInputRanges(const SfxItemPool &)
gives via map converted local slots if applicable
Definition: iconcdlg.cxx:229
bool QueryClose()
Definition: iconcdlg.cxx:257
void DeActivatePageImpl()
Definition: iconcdlg.cxx:154
const SfxItemSet * pSet
Definition: cuihyperdlg.hxx:72
void SwitchPage(const OString &rId)
Definition: iconcdlg.cxx:303
IMPL_LINK_NOARG(SvxHpLinkDlg, ResetHdl, weld::Button &, void)
Definition: iconcdlg.cxx:120
IMPL_LINK(SvxHpLinkDlg, ChosePageHdl_Impl, const OString &, rId, void)
Definition: iconcdlg.cxx:107
std::unique_ptr< IconChoicePage >(* CreatePage)(weld::Container *pParent, SvxHpLinkDlg *pDlg, const SfxItemSet *pAttrSet)
Definition: iconcdlg.hxx:33
#define SAL_WARN(area, stream)
std::unique_ptr< sal_Int32[]> pData
Data-structure for pages in dialog.
Definition: iconcdlg.hxx:37
std::unique_ptr< IconChoicePage > xPage
the TabPage itself
Definition: iconcdlg.hxx:39
bool empty() const noexcept
DeactivateRC