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 OUString& 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 OUString& 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 OUString& rId)
87{
88 OUString 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 OUString&, 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 // tdf#90496 - remember last used view in hyperlink dialog
153
154 m_xResetBtn->show();
155}
156
158{
160
161 DeactivateRC nRet = DeactivateRC::LeavePage;
162
163 if ( !pData )
164 return;
165
166 IconChoicePage * pPage = pData->xPage.get();
167
168 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
169 pExampleSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
170
171 if ( pSet )
172 {
173 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
174
175 if ( pPage->HasExchangeSupport() )
176 nRet = pPage->DeactivatePage( &aTmp );
177
178 if ( ( DeactivateRC::LeavePage & nRet ) &&
179 aTmp.Count() )
180 {
181 if (pExampleSet)
182 pExampleSet->Put(aTmp);
183 pOutSet->Put( aTmp );
184 }
185 }
186 else
187 {
188 if ( pPage->HasExchangeSupport() )
189 {
190 if ( !pExampleSet )
191 {
192 SfxItemPool* pPool = pPage->GetItemSet().GetPool();
193 pExampleSet.reset(
194 new SfxItemSet( *pPool, GetInputRanges( *pPool ) ) );
195 }
196 nRet = pPage->DeactivatePage( pExampleSet.get() );
197 }
198 else
199 nRet = pPage->DeactivatePage( nullptr );
200 }
201
202 if ( nRet & DeactivateRC::RefreshSet )
203 {
204 // TODO refresh input set
205 // flag all pages to be newly initialized
206 for (auto & pObj : maPageList)
207 {
208 if ( pObj->xPage.get() != pPage )
209 pObj->bRefresh = true;
210 else
211 pObj->bRefresh = false;
212 }
213 }
214}
215
216
218{
220
221 assert( pData && "ID not known " );
222
223 pData->xPage->Reset( *pSet );
224}
225
226/**********************************************************************
227|
228| handling itemsets
229|
230\**********************************************************************/
231
233{
234 if ( pSet )
235 {
236 SAL_WARN( "cui.dialogs", "Set does already exist!" );
237 return pSet->GetRanges();
238 }
239
240 if ( !pRanges.empty() )
241 return pRanges;
242
243 return WhichRangesContainer();
244}
245
246
248{
249 bool bSet = ( pSet != nullptr );
250
251 pSet = pInSet;
252
253 if ( !bSet && !pExampleSet && !pOutSet )
254 {
255 pExampleSet.reset(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
306void SvxHpLinkDlg::SwitchPage( const OUString& rId )
307{
308 m_xIconCtrl->set_current_page(rId);
309}
310
311/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
IconChoicePage(weld::Container *pParent, const OUString &rUIXMLDescription, const OUString &rID, const SfxItemSet *pItemSet)
Definition: iconcdlg.cxx:33
const SfxItemSet & GetItemSet() const
Definition: iconcdlg.hxx:54
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet)
Definition: iconcdlg.cxx:58
virtual ~IconChoicePage()
Definition: iconcdlg.cxx:43
bool HasExchangeSupport() const
Definition: iconcdlg.hxx:59
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
IconChoicePageData * GetPageData(std::u16string_view rId)
Definition: iconcdlg.cxx:286
OUString msCurrentPageId
Definition: cuihyperdlg.hxx:70
void ResetPageImpl()
Definition: iconcdlg.cxx:217
void PageCreated(IconChoicePage &rPage)
WhichRangesContainer pRanges
Definition: cuihyperdlg.hxx:77
void ActivatePageImpl()
Definition: iconcdlg.cxx:135
const OUString & GetCurPageId() const
void Start()
Definition: iconcdlg.cxx:274
void SwitchPage(const OUString &rId)
Definition: iconcdlg.cxx:306
std::vector< std::unique_ptr< IconChoicePageData > > maPageList
Definition: cuihyperdlg.hxx:68
std::unique_ptr< SfxItemSet > pOutSet
Definition: cuihyperdlg.hxx:75
std::unique_ptr< SfxItemSet > pExampleSet
Definition: cuihyperdlg.hxx:76
void AddTabPage(const OUString &rId, CreatePage pCreateFunc)
Definition: iconcdlg.cxx:73
static OUString msRememberedPageId
Definition: cuihyperdlg.hxx:72
std::unique_ptr< weld::Button > m_xResetBtn
Definition: cuihyperdlg.hxx:90
std::unique_ptr< weld::Notebook > m_xIconCtrl
Definition: cuihyperdlg.hxx:85
void SetInputSet(const SfxItemSet *pInSet)
Definition: iconcdlg.cxx:247
void SetCurPageId(const OUString &rId)
void ShowPage(const OUString &rId)
Definition: iconcdlg.cxx:86
WhichRangesContainer GetInputRanges(const SfxItemPool &)
gives via map converted local slots if applicable
Definition: iconcdlg.cxx:232
bool QueryClose()
Definition: iconcdlg.cxx:260
void DeActivatePageImpl()
Definition: iconcdlg.cxx:157
const SfxItemSet * pSet
Definition: cuihyperdlg.hxx:74
IMPL_LINK_NOARG(SvxHpLinkDlg, ResetHdl, weld::Button &, void)
Definition: iconcdlg.cxx:120
IMPL_LINK(SvxHpLinkDlg, ChosePageHdl_Impl, const OUString &, 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:69
std::unique_ptr< IconChoicePage > xPage
the TabPage itself
Definition: iconcdlg.hxx:71
bool empty() const noexcept
DeactivateRC