File: | home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx |
Warning: | line 284, column 13 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <comphelper/lok.hxx> | ||||||||
21 | #include <officecfg/Office/Common.hxx> | ||||||||
22 | #include <vcl/event.hxx> | ||||||||
23 | #include <tools/debug.hxx> | ||||||||
24 | #include <tools/diagnose_ex.h> | ||||||||
25 | #include <strings.hrc> | ||||||||
26 | #include <svdata.hxx> | ||||||||
27 | #include <wizdlg.hxx> | ||||||||
28 | #include <stack> | ||||||||
29 | #include "wizimpldata.hxx" | ||||||||
30 | |||||||||
31 | #define HID_WIZARD_NEXT"SVT_HID_WIZARD_NEXT" "SVT_HID_WIZARD_NEXT" | ||||||||
32 | #define HID_WIZARD_PREVIOUS"SVT_HID_WIZARD_PREVIOUS" "SVT_HID_WIZARD_PREVIOUS" | ||||||||
33 | |||||||||
34 | #define WIZARDDIALOG_BUTTON_OFFSET_Y6 6 | ||||||||
35 | #define WIZARDDIALOG_BUTTON_DLGOFFSET_X6 6 | ||||||||
36 | #define WIZARDDIALOG_VIEW_DLGOFFSET_X6 6 | ||||||||
37 | #define WIZARDDIALOG_VIEW_DLGOFFSET_Y6 6 | ||||||||
38 | |||||||||
39 | namespace vcl | ||||||||
40 | { | ||||||||
41 | //= WizardPageImplData | ||||||||
42 | OWizardPage::OWizardPage(weld::Container* pPage, weld::DialogController* pController, const OUString& rUIXMLDescription, const OString& rID) | ||||||||
43 | : BuilderPage(pPage, pController, rUIXMLDescription, rID) | ||||||||
44 | { | ||||||||
45 | } | ||||||||
46 | |||||||||
47 | OWizardPage::~OWizardPage() | ||||||||
48 | { | ||||||||
49 | } | ||||||||
50 | |||||||||
51 | void OWizardPage::initializePage() | ||||||||
52 | { | ||||||||
53 | } | ||||||||
54 | |||||||||
55 | void OWizardPage::Activate() | ||||||||
56 | { | ||||||||
57 | BuilderPage::Activate(); | ||||||||
58 | updateDialogTravelUI(); | ||||||||
59 | } | ||||||||
60 | |||||||||
61 | void OWizardPage::updateDialogTravelUI() | ||||||||
62 | { | ||||||||
63 | auto pWizardMachine = dynamic_cast<RoadmapWizardMachine*>(m_pDialogController); | ||||||||
64 | if (pWizardMachine) | ||||||||
65 | pWizardMachine->updateTravelUI(); | ||||||||
66 | } | ||||||||
67 | |||||||||
68 | bool OWizardPage::canAdvance() const | ||||||||
69 | { | ||||||||
70 | return true; | ||||||||
71 | } | ||||||||
72 | |||||||||
73 | bool OWizardPage::commitPage( WizardTypes::CommitPageReason ) | ||||||||
74 | { | ||||||||
75 | return true; | ||||||||
76 | } | ||||||||
77 | |||||||||
78 | void RoadmapWizard::SetLeftAlignedButtonCount( sal_Int16 _nCount ) | ||||||||
79 | { | ||||||||
80 | mnLeftAlignCount = _nCount; | ||||||||
81 | } | ||||||||
82 | |||||||||
83 | void RoadmapWizard::ImplCalcSize( Size& rSize ) | ||||||||
84 | { | ||||||||
85 | // calculate ButtonBar height and width | ||||||||
86 | long nMaxHeight = 0; | ||||||||
87 | long nBarWidth = WIZARDDIALOG_BUTTON_DLGOFFSET_X6 * 2 + LogicalCoordinateToPixel(6); | ||||||||
88 | ImplWizButtonData* pBtnData = mpFirstBtn; | ||||||||
89 | while (pBtnData) | ||||||||
90 | { | ||||||||
91 | auto nBtnHeight = pBtnData->mpButton->GetSizePixel().Height(); | ||||||||
92 | auto nBtnWidth = pBtnData->mpButton->GetSizePixel().Width(); | ||||||||
93 | if (pBtnData->mpButton->IsVisible()) | ||||||||
94 | { | ||||||||
95 | nBarWidth += nBtnWidth; | ||||||||
96 | nBarWidth += pBtnData->mnOffset; | ||||||||
97 | } | ||||||||
98 | if ( nBtnHeight > nMaxHeight ) | ||||||||
99 | nMaxHeight = nBtnHeight; | ||||||||
100 | pBtnData = pBtnData->mpNext; | ||||||||
101 | } | ||||||||
102 | if ( nMaxHeight ) | ||||||||
103 | nMaxHeight += WIZARDDIALOG_BUTTON_OFFSET_Y6*2; | ||||||||
104 | rSize.AdjustHeight(nMaxHeight); | ||||||||
105 | |||||||||
106 | // add in the view window size | ||||||||
107 | if ( mpViewWindow && mpViewWindow->IsVisible() ) | ||||||||
108 | { | ||||||||
109 | Size aViewSize = mpViewWindow->GetSizePixel(); | ||||||||
110 | // align left | ||||||||
111 | rSize.AdjustWidth(aViewSize.Width() ); | ||||||||
112 | } | ||||||||
113 | |||||||||
114 | if (nBarWidth > rSize.Width()) | ||||||||
115 | rSize.setWidth(nBarWidth); | ||||||||
116 | } | ||||||||
117 | |||||||||
118 | void RoadmapWizard::queue_resize(StateChangedType /*eReason*/) | ||||||||
119 | { | ||||||||
120 | if (maWizardLayoutIdle.IsActive()) | ||||||||
121 | return; | ||||||||
122 | if (IsInClose()) | ||||||||
123 | return; | ||||||||
124 | maWizardLayoutIdle.Start(); | ||||||||
125 | } | ||||||||
126 | |||||||||
127 | IMPL_LINK_NOARG(RoadmapWizard, ImplHandleWizardLayoutTimerHdl, Timer*, void)void RoadmapWizard::LinkStubImplHandleWizardLayoutTimerHdl(void * instance, Timer* data) { return static_cast<RoadmapWizard *>(instance)->ImplHandleWizardLayoutTimerHdl(data); } void RoadmapWizard::ImplHandleWizardLayoutTimerHdl(__attribute__ ( (unused)) Timer*) | ||||||||
128 | { | ||||||||
129 | ImplPosCtrls(); | ||||||||
130 | ImplPosTabPage(); | ||||||||
131 | } | ||||||||
132 | |||||||||
133 | void RoadmapWizard::ImplPosCtrls() | ||||||||
134 | { | ||||||||
135 | Size aDlgSize = GetOutputSizePixel(); | ||||||||
136 | long nBtnWidth = 0; | ||||||||
137 | long nMaxHeight = 0; | ||||||||
138 | long nOffY = aDlgSize.Height(); | ||||||||
139 | |||||||||
140 | ImplWizButtonData* pBtnData = mpFirstBtn; | ||||||||
141 | int j = 0; | ||||||||
142 | while ( pBtnData ) | ||||||||
143 | { | ||||||||
144 | if (j >= mnLeftAlignCount) | ||||||||
145 | { | ||||||||
146 | Size aBtnSize = pBtnData->mpButton->GetSizePixel(); | ||||||||
147 | long nBtnHeight = aBtnSize.Height(); | ||||||||
148 | if ( nBtnHeight > nMaxHeight ) | ||||||||
149 | nMaxHeight = nBtnHeight; | ||||||||
150 | nBtnWidth += aBtnSize.Width(); | ||||||||
151 | nBtnWidth += pBtnData->mnOffset; | ||||||||
152 | } | ||||||||
153 | pBtnData = pBtnData->mpNext; | ||||||||
154 | j++; | ||||||||
155 | } | ||||||||
156 | |||||||||
157 | if ( nMaxHeight ) | ||||||||
158 | { | ||||||||
159 | long nOffX = aDlgSize.Width()-nBtnWidth-WIZARDDIALOG_BUTTON_DLGOFFSET_X6; | ||||||||
160 | long nOffLeftAlignX = LogicalCoordinateToPixel(6); | ||||||||
161 | nOffY -= WIZARDDIALOG_BUTTON_OFFSET_Y6+nMaxHeight; | ||||||||
162 | |||||||||
163 | pBtnData = mpFirstBtn; | ||||||||
164 | int i = 0; | ||||||||
165 | while ( pBtnData ) | ||||||||
166 | { | ||||||||
167 | Size aBtnSize = pBtnData->mpButton->GetSizePixel(); | ||||||||
168 | if (i >= mnLeftAlignCount) | ||||||||
169 | { | ||||||||
170 | Point aPos( nOffX, nOffY+((nMaxHeight-aBtnSize.Height())/2) ); | ||||||||
171 | pBtnData->mpButton->SetPosPixel( aPos ); | ||||||||
172 | nOffX += aBtnSize.Width(); | ||||||||
173 | nOffX += pBtnData->mnOffset; | ||||||||
174 | } | ||||||||
175 | else | ||||||||
176 | { | ||||||||
177 | Point aPos( nOffLeftAlignX, nOffY+((nMaxHeight-aBtnSize.Height())/2) ); | ||||||||
178 | pBtnData->mpButton->SetPosPixel( aPos ); | ||||||||
179 | nOffLeftAlignX += aBtnSize.Width(); | ||||||||
180 | nOffLeftAlignX += pBtnData->mnOffset; | ||||||||
181 | } | ||||||||
182 | |||||||||
183 | pBtnData = pBtnData->mpNext; | ||||||||
184 | i++; | ||||||||
185 | } | ||||||||
186 | |||||||||
187 | nOffY -= WIZARDDIALOG_BUTTON_OFFSET_Y6; | ||||||||
188 | } | ||||||||
189 | |||||||||
190 | if ( !(mpViewWindow && mpViewWindow->IsVisible()) ) | ||||||||
191 | return; | ||||||||
192 | |||||||||
193 | long nViewOffX = 0; | ||||||||
194 | long nViewOffY = 0; | ||||||||
195 | long nViewWidth = 0; | ||||||||
196 | long nViewHeight = 0; | ||||||||
197 | long nDlgHeight = nOffY; | ||||||||
198 | PosSizeFlags nViewPosFlags = PosSizeFlags::Pos; | ||||||||
199 | // align left | ||||||||
200 | { | ||||||||
201 | if ( mbEmptyViewMargin ) | ||||||||
202 | { | ||||||||
203 | nViewOffX = 0; | ||||||||
204 | nViewOffY = 0; | ||||||||
205 | nViewHeight = nDlgHeight; | ||||||||
206 | } | ||||||||
207 | else | ||||||||
208 | { | ||||||||
209 | nViewOffX = WIZARDDIALOG_VIEW_DLGOFFSET_X6; | ||||||||
210 | nViewOffY = WIZARDDIALOG_VIEW_DLGOFFSET_Y6; | ||||||||
211 | nViewHeight = nDlgHeight-(WIZARDDIALOG_VIEW_DLGOFFSET_Y6*2); | ||||||||
212 | } | ||||||||
213 | nViewPosFlags |= PosSizeFlags::Height; | ||||||||
214 | } | ||||||||
215 | mpViewWindow->setPosSizePixel( nViewOffX, nViewOffY, | ||||||||
216 | nViewWidth, nViewHeight, | ||||||||
217 | nViewPosFlags ); | ||||||||
218 | } | ||||||||
219 | |||||||||
220 | long RoadmapWizard::LogicalCoordinateToPixel(int iCoordinate){ | ||||||||
221 | Size aLocSize = LogicToPixel(Size(iCoordinate, 0), MapMode(MapUnit::MapAppFont)); | ||||||||
222 | int iPixelCoordinate = aLocSize.Width(); | ||||||||
223 | return iPixelCoordinate; | ||||||||
224 | } | ||||||||
225 | |||||||||
226 | void RoadmapWizard::ImplPosTabPage() | ||||||||
227 | { | ||||||||
228 | if ( !mpCurTabPage ) | ||||||||
229 | return; | ||||||||
230 | |||||||||
231 | if ( !IsInInitShow() ) | ||||||||
232 | { | ||||||||
233 | // #100199# - On Unix initial size is equal to screen size, on Windows | ||||||||
234 | // it's 0,0. One cannot calculate the size unless dialog is visible. | ||||||||
235 | if ( !IsReallyVisible() ) | ||||||||
236 | return; | ||||||||
237 | } | ||||||||
238 | |||||||||
239 | // calculate height of ButtonBar | ||||||||
240 | long nMaxHeight = 0; | ||||||||
241 | ImplWizButtonData* pBtnData = mpFirstBtn; | ||||||||
242 | while ( pBtnData ) | ||||||||
243 | { | ||||||||
244 | long nBtnHeight = pBtnData->mpButton->GetSizePixel().Height(); | ||||||||
245 | if ( nBtnHeight > nMaxHeight ) | ||||||||
246 | nMaxHeight = nBtnHeight; | ||||||||
247 | pBtnData = pBtnData->mpNext; | ||||||||
248 | } | ||||||||
249 | if ( nMaxHeight ) | ||||||||
250 | nMaxHeight += WIZARDDIALOG_BUTTON_OFFSET_Y6*2; | ||||||||
251 | |||||||||
252 | // position TabPage | ||||||||
253 | Size aDlgSize = GetOutputSizePixel(); | ||||||||
254 | aDlgSize.AdjustHeight( -nMaxHeight ); | ||||||||
255 | long nOffX = 0; | ||||||||
256 | long nOffY = 0; | ||||||||
257 | if ( mpViewWindow && mpViewWindow->IsVisible() ) | ||||||||
258 | { | ||||||||
259 | Size aViewSize = mpViewWindow->GetSizePixel(); | ||||||||
260 | // align left | ||||||||
261 | long nViewOffset = mbEmptyViewMargin ? 0 : WIZARDDIALOG_VIEW_DLGOFFSET_X6; | ||||||||
262 | nOffX += aViewSize.Width() + nViewOffset; | ||||||||
263 | aDlgSize.AdjustWidth( -nOffX ); | ||||||||
264 | } | ||||||||
265 | Point aPos( nOffX, nOffY ); | ||||||||
266 | mpCurTabPage->SetPosSizePixel( aPos, aDlgSize ); | ||||||||
267 | } | ||||||||
268 | |||||||||
269 | void RoadmapWizard::ImplShowTabPage( TabPage* pTabPage ) | ||||||||
270 | { | ||||||||
271 | if ( mpCurTabPage == pTabPage ) | ||||||||
272 | return; | ||||||||
273 | |||||||||
274 | TabPage* pOldTabPage = mpCurTabPage; | ||||||||
275 | |||||||||
276 | mpCurTabPage = pTabPage; | ||||||||
277 | if ( pTabPage
| ||||||||
278 | { | ||||||||
279 | ImplPosTabPage(); | ||||||||
280 | pTabPage->Show(); | ||||||||
281 | } | ||||||||
282 | |||||||||
283 | if ( pOldTabPage
| ||||||||
284 | pOldTabPage->Hide(); | ||||||||
| |||||||||
285 | } | ||||||||
286 | |||||||||
287 | TabPage* RoadmapWizard::ImplGetPage( sal_uInt16 nLevel ) const | ||||||||
288 | { | ||||||||
289 | sal_uInt16 nTempLevel = 0; | ||||||||
290 | ImplWizPageData* pPageData = mpFirstPage; | ||||||||
291 | while ( pPageData ) | ||||||||
292 | { | ||||||||
293 | if ( (nTempLevel == nLevel) || !pPageData->mpNext ) | ||||||||
294 | break; | ||||||||
295 | |||||||||
296 | nTempLevel++; | ||||||||
297 | pPageData = pPageData->mpNext; | ||||||||
298 | } | ||||||||
299 | |||||||||
300 | if ( pPageData ) | ||||||||
301 | return pPageData->mpPage; | ||||||||
302 | return nullptr; | ||||||||
303 | } | ||||||||
304 | |||||||||
305 | void RoadmapWizard::implConstruct( const WizardButtonFlags _nButtonFlags ) | ||||||||
306 | { | ||||||||
307 | m_xWizardImpl->sTitleBase = GetText(); | ||||||||
308 | |||||||||
309 | // create the buttons according to the wizard button flags | ||||||||
310 | // the help button | ||||||||
311 | if (_nButtonFlags & WizardButtonFlags::HELP) | ||||||||
312 | { | ||||||||
313 | m_pHelp= VclPtr<HelpButton>::Create(this, WB_TABSTOP); | ||||||||
314 | m_pHelp->SetSizePixel(LogicToPixel(Size(50, 14), MapMode(MapUnit::MapAppFont))); | ||||||||
315 | m_pHelp->Show(); | ||||||||
316 | AddButton( m_pHelp, WIZARDDIALOG_BUTTON_STDOFFSET_X6); | ||||||||
317 | } | ||||||||
318 | |||||||||
319 | // the previous button | ||||||||
320 | if (_nButtonFlags & WizardButtonFlags::PREVIOUS) | ||||||||
321 | { | ||||||||
322 | m_pPrevPage = VclPtr<PushButton>::Create(this, WB_TABSTOP); | ||||||||
323 | m_pPrevPage->SetHelpId( HID_WIZARD_PREVIOUS"SVT_HID_WIZARD_PREVIOUS" ); | ||||||||
324 | m_pPrevPage->SetSizePixel(LogicToPixel(Size(50, 14), MapMode(MapUnit::MapAppFont))); | ||||||||
325 | m_pPrevPage->SetText(VclResId(STR_WIZDLG_PREVIOUSreinterpret_cast<char const *>("STR_WIZDLG_PREVIOUS" "\004" u8"< Bac~k"))); | ||||||||
326 | m_pPrevPage->Show(); | ||||||||
327 | m_pPrevPage->set_id("previous"); | ||||||||
328 | |||||||||
329 | if (_nButtonFlags & WizardButtonFlags::NEXT) | ||||||||
330 | AddButton( m_pPrevPage, ( WIZARDDIALOG_BUTTON_SMALLSTDOFFSET_X3) ); // half x-offset to the next button | ||||||||
331 | else | ||||||||
332 | AddButton( m_pPrevPage, WIZARDDIALOG_BUTTON_STDOFFSET_X6 ); | ||||||||
333 | mpPrevBtn = m_pPrevPage; | ||||||||
334 | m_pPrevPage->SetClickHdl( LINK( this, RoadmapWizard, OnPrevPage )::tools::detail::makeLink( ::tools::detail::castTo<RoadmapWizard *>(this), &RoadmapWizard::LinkStubOnPrevPage) ); | ||||||||
335 | } | ||||||||
336 | |||||||||
337 | // the next button | ||||||||
338 | if (_nButtonFlags & WizardButtonFlags::NEXT) | ||||||||
339 | { | ||||||||
340 | m_pNextPage = VclPtr<PushButton>::Create(this, WB_TABSTOP); | ||||||||
341 | m_pNextPage->SetHelpId( HID_WIZARD_NEXT"SVT_HID_WIZARD_NEXT" ); | ||||||||
342 | m_pNextPage->SetSizePixel(LogicToPixel(Size(50, 14), MapMode(MapUnit::MapAppFont))); | ||||||||
343 | m_pNextPage->SetText(VclResId(STR_WIZDLG_NEXTreinterpret_cast<char const *>("STR_WIZDLG_NEXT" "\004" u8"~Next >"))); | ||||||||
344 | m_pNextPage->Show(); | ||||||||
345 | m_pNextPage->set_id("next"); | ||||||||
346 | |||||||||
347 | AddButton( m_pNextPage, WIZARDDIALOG_BUTTON_STDOFFSET_X6 ); | ||||||||
348 | mpNextBtn = m_pNextPage; | ||||||||
349 | m_pNextPage->SetClickHdl( LINK( this, RoadmapWizard, OnNextPage )::tools::detail::makeLink( ::tools::detail::castTo<RoadmapWizard *>(this), &RoadmapWizard::LinkStubOnNextPage) ); | ||||||||
350 | } | ||||||||
351 | |||||||||
352 | // the finish button | ||||||||
353 | if (_nButtonFlags & WizardButtonFlags::FINISH) | ||||||||
354 | { | ||||||||
355 | m_pFinish = VclPtr<OKButton>::Create(this, WB_TABSTOP); | ||||||||
356 | m_pFinish->SetSizePixel(LogicToPixel(Size(50, 14), MapMode(MapUnit::MapAppFont))); | ||||||||
357 | m_pFinish->SetText(VclResId(STR_WIZDLG_FINISHreinterpret_cast<char const *>("STR_WIZDLG_FINISH" "\004" u8"~Finish"))); | ||||||||
358 | m_pFinish->Show(); | ||||||||
359 | m_pFinish->set_id("finish"); | ||||||||
360 | |||||||||
361 | AddButton( m_pFinish, WIZARDDIALOG_BUTTON_STDOFFSET_X6 ); | ||||||||
362 | m_pFinish->SetClickHdl( LINK( this, RoadmapWizard, OnFinish )::tools::detail::makeLink( ::tools::detail::castTo<RoadmapWizard *>(this), &RoadmapWizard::LinkStubOnFinish) ); | ||||||||
363 | } | ||||||||
364 | |||||||||
365 | // the cancel button | ||||||||
366 | if (_nButtonFlags & WizardButtonFlags::CANCEL) | ||||||||
367 | { | ||||||||
368 | m_pCancel = VclPtr<CancelButton>::Create(this, WB_TABSTOP); | ||||||||
369 | m_pCancel->SetSizePixel(LogicToPixel(Size(50, 14), MapMode(MapUnit::MapAppFont))); | ||||||||
370 | m_pCancel->Show(); | ||||||||
371 | |||||||||
372 | AddButton( m_pCancel, WIZARDDIALOG_BUTTON_STDOFFSET_X6 ); | ||||||||
373 | } | ||||||||
374 | } | ||||||||
375 | |||||||||
376 | void RoadmapWizard::Resize() | ||||||||
377 | { | ||||||||
378 | if ( IsReallyShown() && !IsInInitShow() ) | ||||||||
379 | { | ||||||||
380 | ImplPosCtrls(); | ||||||||
381 | ImplPosTabPage(); | ||||||||
382 | } | ||||||||
383 | |||||||||
384 | Dialog::Resize(); | ||||||||
385 | } | ||||||||
386 | |||||||||
387 | void RoadmapWizard::implUpdateTitle() | ||||||||
388 | { | ||||||||
389 | OUString sCompleteTitle(m_xWizardImpl->sTitleBase); | ||||||||
390 | |||||||||
391 | // append the page title | ||||||||
392 | TabPage* pCurrentPage = GetPage(getCurrentState()); | ||||||||
393 | if ( pCurrentPage && !pCurrentPage->GetText().isEmpty() ) | ||||||||
394 | { | ||||||||
395 | sCompleteTitle += " - " + pCurrentPage->GetText(); | ||||||||
396 | } | ||||||||
397 | |||||||||
398 | SetText(sCompleteTitle); | ||||||||
399 | } | ||||||||
400 | |||||||||
401 | void RoadmapWizard::CalcAndSetSize() | ||||||||
402 | { | ||||||||
403 | Size aDlgSize = GetPageSizePixel(); | ||||||||
404 | if ( !aDlgSize.Width() || !aDlgSize.Height() ) | ||||||||
405 | { | ||||||||
406 | ImplWizPageData* pPageData = mpFirstPage; | ||||||||
407 | while ( pPageData ) | ||||||||
408 | { | ||||||||
409 | if ( pPageData->mpPage ) | ||||||||
410 | { | ||||||||
411 | Size aPageSize = pPageData->mpPage->GetSizePixel(); | ||||||||
412 | if ( aPageSize.Width() > aDlgSize.Width() ) | ||||||||
413 | aDlgSize.setWidth( aPageSize.Width() ); | ||||||||
414 | if ( aPageSize.Height() > aDlgSize.Height() ) | ||||||||
415 | aDlgSize.setHeight( aPageSize.Height() ); | ||||||||
416 | } | ||||||||
417 | |||||||||
418 | pPageData = pPageData->mpNext; | ||||||||
419 | } | ||||||||
420 | } | ||||||||
421 | ImplCalcSize( aDlgSize ); | ||||||||
422 | SetMinOutputSizePixel( aDlgSize ); | ||||||||
423 | SetOutputSizePixel( aDlgSize ); | ||||||||
424 | } | ||||||||
425 | |||||||||
426 | void RoadmapWizard::StateChanged( StateChangedType nType ) | ||||||||
427 | { | ||||||||
428 | if ( nType == StateChangedType::InitShow ) | ||||||||
429 | { | ||||||||
430 | if ( IsDefaultSize() ) | ||||||||
431 | { | ||||||||
432 | CalcAndSetSize(); | ||||||||
433 | } | ||||||||
434 | |||||||||
435 | ImplPosCtrls(); | ||||||||
436 | ImplPosTabPage(); | ||||||||
437 | ImplShowTabPage( ImplGetPage( mnCurLevel ) ); | ||||||||
438 | } | ||||||||
439 | |||||||||
440 | Dialog::StateChanged( nType ); | ||||||||
441 | } | ||||||||
442 | |||||||||
443 | bool RoadmapWizard::EventNotify( NotifyEvent& rNEvt ) | ||||||||
444 | { | ||||||||
445 | if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && mpPrevBtn && mpNextBtn ) | ||||||||
446 | { | ||||||||
447 | const KeyEvent* pKEvt = rNEvt.GetKeyEvent(); | ||||||||
448 | vcl::KeyCode aKeyCode = pKEvt->GetKeyCode(); | ||||||||
449 | sal_uInt16 nKeyCode = aKeyCode.GetCode(); | ||||||||
450 | |||||||||
451 | if ( aKeyCode.IsMod1() ) | ||||||||
452 | { | ||||||||
453 | if ( aKeyCode.IsShift() || (nKeyCode == KEY_PAGEUP) ) | ||||||||
454 | { | ||||||||
455 | if ( (nKeyCode == KEY_TAB) || (nKeyCode == KEY_PAGEUP) ) | ||||||||
456 | { | ||||||||
457 | if ( mpPrevBtn->IsVisible() && | ||||||||
458 | mpPrevBtn->IsEnabled() && mpPrevBtn->IsInputEnabled() ) | ||||||||
459 | { | ||||||||
460 | mpPrevBtn->SetPressed( true ); | ||||||||
461 | mpPrevBtn->SetPressed( false ); | ||||||||
462 | mpPrevBtn->Click(); | ||||||||
463 | } | ||||||||
464 | return true; | ||||||||
465 | } | ||||||||
466 | } | ||||||||
467 | else | ||||||||
468 | { | ||||||||
469 | if ( (nKeyCode == KEY_TAB) || (nKeyCode == KEY_PAGEDOWN) ) | ||||||||
470 | { | ||||||||
471 | if ( mpNextBtn->IsVisible() && | ||||||||
472 | mpNextBtn->IsEnabled() && mpNextBtn->IsInputEnabled() ) | ||||||||
473 | { | ||||||||
474 | mpNextBtn->SetPressed( true ); | ||||||||
475 | mpNextBtn->SetPressed( false ); | ||||||||
476 | mpNextBtn->Click(); | ||||||||
477 | } | ||||||||
478 | return true; | ||||||||
479 | } | ||||||||
480 | } | ||||||||
481 | } | ||||||||
482 | } | ||||||||
483 | |||||||||
484 | return Dialog::EventNotify( rNEvt ); | ||||||||
485 | } | ||||||||
486 | |||||||||
487 | TabPage* RoadmapWizard::GetOrCreatePage( const WizardTypes::WizardState i_nState ) | ||||||||
488 | { | ||||||||
489 | if ( nullptr == GetPage( i_nState ) ) | ||||||||
490 | { | ||||||||
491 | VclPtr<TabPage> pNewPage = createPage( i_nState ); | ||||||||
492 | DBG_ASSERT( pNewPage, "RoadmapWizard::GetOrCreatePage: invalid new page (NULL)!" )do { if (true && (!(pNewPage))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "492" ": "), "%s", "RoadmapWizard::GetOrCreatePage: invalid new page (NULL)!" ); } } while (false); | ||||||||
493 | |||||||||
494 | // fill up the page sequence of our base class (with dummies) | ||||||||
495 | while ( m_xWizardImpl->nFirstUnknownPage < i_nState ) | ||||||||
496 | { | ||||||||
497 | AddPage( nullptr ); | ||||||||
498 | ++m_xWizardImpl->nFirstUnknownPage; | ||||||||
499 | } | ||||||||
500 | |||||||||
501 | if ( m_xWizardImpl->nFirstUnknownPage == i_nState ) | ||||||||
502 | { | ||||||||
503 | // encountered this page number the first time | ||||||||
504 | AddPage( pNewPage ); | ||||||||
505 | ++m_xWizardImpl->nFirstUnknownPage; | ||||||||
506 | } | ||||||||
507 | else | ||||||||
508 | // already had this page - just change it | ||||||||
509 | SetPage( i_nState, pNewPage ); | ||||||||
510 | } | ||||||||
511 | return GetPage( i_nState ); | ||||||||
512 | } | ||||||||
513 | |||||||||
514 | void RoadmapWizard::ActivatePage() | ||||||||
515 | { | ||||||||
516 | WizardTypes::WizardState nCurrentLevel = GetCurLevel(); | ||||||||
517 | GetOrCreatePage( nCurrentLevel ); | ||||||||
518 | |||||||||
519 | enterState( nCurrentLevel ); | ||||||||
520 | } | ||||||||
521 | |||||||||
522 | bool RoadmapWizard::ShowPage( sal_uInt16 nLevel ) | ||||||||
523 | { | ||||||||
524 | mnCurLevel = nLevel; | ||||||||
525 | ActivatePage(); | ||||||||
526 | ImplShowTabPage( ImplGetPage( mnCurLevel ) ); | ||||||||
527 | return true; | ||||||||
528 | } | ||||||||
529 | |||||||||
530 | bool RoadmapWizard::Finish( long nResult ) | ||||||||
531 | { | ||||||||
532 | if ( IsInExecute() ) | ||||||||
533 | EndDialog( nResult ); | ||||||||
534 | else if ( GetStyle() & WB_CLOSEABLE ) | ||||||||
535 | Close(); | ||||||||
536 | return true; | ||||||||
537 | } | ||||||||
538 | |||||||||
539 | void RoadmapWizard::AddPage( TabPage* pPage ) | ||||||||
540 | { | ||||||||
541 | ImplWizPageData* pNewPageData = new ImplWizPageData; | ||||||||
542 | pNewPageData->mpNext = nullptr; | ||||||||
543 | pNewPageData->mpPage = pPage; | ||||||||
544 | |||||||||
545 | if ( !mpFirstPage ) | ||||||||
546 | mpFirstPage = pNewPageData; | ||||||||
547 | else | ||||||||
548 | { | ||||||||
549 | ImplWizPageData* pPageData = mpFirstPage; | ||||||||
550 | while ( pPageData->mpNext ) | ||||||||
551 | pPageData = pPageData->mpNext; | ||||||||
552 | pPageData->mpNext = pNewPageData; | ||||||||
553 | } | ||||||||
554 | } | ||||||||
555 | |||||||||
556 | void RoadmapWizard::RemovePage( TabPage* pPage ) | ||||||||
557 | { | ||||||||
558 | ImplWizPageData* pPrevPageData = nullptr; | ||||||||
559 | ImplWizPageData* pPageData = mpFirstPage; | ||||||||
560 | while ( pPageData ) | ||||||||
561 | { | ||||||||
562 | if ( pPageData->mpPage == pPage ) | ||||||||
563 | { | ||||||||
564 | if ( pPrevPageData ) | ||||||||
565 | pPrevPageData->mpNext = pPageData->mpNext; | ||||||||
566 | else | ||||||||
567 | mpFirstPage = pPageData->mpNext; | ||||||||
568 | if ( pPage == mpCurTabPage ) | ||||||||
569 | mpCurTabPage = nullptr; | ||||||||
570 | delete pPageData; | ||||||||
571 | return; | ||||||||
572 | } | ||||||||
573 | |||||||||
574 | pPrevPageData = pPageData; | ||||||||
575 | pPageData = pPageData->mpNext; | ||||||||
576 | } | ||||||||
577 | |||||||||
578 | OSL_FAIL( "RoadmapWizard::RemovePage() - Page not in list" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "578" ": "), "%s", "RoadmapWizard::RemovePage() - Page not in list" ); } } while (false); | ||||||||
579 | } | ||||||||
580 | |||||||||
581 | void RoadmapWizard::SetPage( sal_uInt16 nLevel, TabPage* pPage ) | ||||||||
582 | { | ||||||||
583 | sal_uInt16 nTempLevel = 0; | ||||||||
584 | ImplWizPageData* pPageData = mpFirstPage; | ||||||||
585 | while ( pPageData ) | ||||||||
586 | { | ||||||||
587 | if ( (nTempLevel == nLevel) || !pPageData->mpNext ) | ||||||||
588 | break; | ||||||||
589 | |||||||||
590 | nTempLevel++; | ||||||||
591 | pPageData = pPageData->mpNext; | ||||||||
592 | } | ||||||||
593 | |||||||||
594 | if ( pPageData ) | ||||||||
595 | { | ||||||||
596 | if ( pPageData->mpPage == mpCurTabPage ) | ||||||||
597 | mpCurTabPage = nullptr; | ||||||||
598 | pPageData->mpPage = pPage; | ||||||||
599 | } | ||||||||
600 | } | ||||||||
601 | |||||||||
602 | TabPage* RoadmapWizard::GetPage( sal_uInt16 nLevel ) const | ||||||||
603 | { | ||||||||
604 | sal_uInt16 nTempLevel = 0; | ||||||||
605 | |||||||||
606 | for (ImplWizPageData* pPageData = mpFirstPage; pPageData; | ||||||||
607 | pPageData = pPageData->mpNext) | ||||||||
608 | { | ||||||||
609 | if ( nTempLevel == nLevel ) | ||||||||
610 | return pPageData->mpPage; | ||||||||
611 | nTempLevel++; | ||||||||
612 | } | ||||||||
613 | |||||||||
614 | return nullptr; | ||||||||
615 | } | ||||||||
616 | |||||||||
617 | void RoadmapWizard::AddButton( Button* pButton, long nOffset ) | ||||||||
618 | { | ||||||||
619 | ImplWizButtonData* pNewBtnData = new ImplWizButtonData; | ||||||||
620 | pNewBtnData->mpNext = nullptr; | ||||||||
621 | pNewBtnData->mpButton = pButton; | ||||||||
622 | pNewBtnData->mnOffset = nOffset; | ||||||||
623 | |||||||||
624 | if ( !mpFirstBtn ) | ||||||||
625 | mpFirstBtn = pNewBtnData; | ||||||||
626 | else | ||||||||
627 | { | ||||||||
628 | ImplWizButtonData* pBtnData = mpFirstBtn; | ||||||||
629 | while ( pBtnData->mpNext ) | ||||||||
630 | pBtnData = pBtnData->mpNext; | ||||||||
631 | pBtnData->mpNext = pNewBtnData; | ||||||||
632 | } | ||||||||
633 | } | ||||||||
634 | |||||||||
635 | void RoadmapWizard::RemoveButton( Button* pButton ) | ||||||||
636 | { | ||||||||
637 | ImplWizButtonData* pPrevBtnData = nullptr; | ||||||||
638 | ImplWizButtonData* pBtnData = mpFirstBtn; | ||||||||
639 | while ( pBtnData ) | ||||||||
640 | { | ||||||||
641 | if ( pBtnData->mpButton == pButton ) | ||||||||
642 | { | ||||||||
643 | if ( pPrevBtnData ) | ||||||||
644 | pPrevBtnData->mpNext = pBtnData->mpNext; | ||||||||
645 | else | ||||||||
646 | mpFirstBtn = pBtnData->mpNext; | ||||||||
647 | delete pBtnData; | ||||||||
648 | return; | ||||||||
649 | } | ||||||||
650 | |||||||||
651 | pPrevBtnData = pBtnData; | ||||||||
652 | pBtnData = pBtnData->mpNext; | ||||||||
653 | } | ||||||||
654 | |||||||||
655 | OSL_FAIL( "RoadmapWizard::RemoveButton() - Button not in list" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "655" ": "), "%s", "RoadmapWizard::RemoveButton() - Button not in list" ); } } while (false); | ||||||||
656 | } | ||||||||
657 | |||||||||
658 | void RoadmapWizard::enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable) | ||||||||
659 | { | ||||||||
660 | if (m_pFinish && (_nWizardButtonFlags & WizardButtonFlags::FINISH)) | ||||||||
661 | m_pFinish->Enable(_bEnable); | ||||||||
662 | if (m_pNextPage && (_nWizardButtonFlags & WizardButtonFlags::NEXT)) | ||||||||
663 | m_pNextPage->Enable(_bEnable); | ||||||||
664 | if (m_pPrevPage && (_nWizardButtonFlags & WizardButtonFlags::PREVIOUS)) | ||||||||
665 | m_pPrevPage->Enable(_bEnable); | ||||||||
666 | if (m_pHelp && (_nWizardButtonFlags & WizardButtonFlags::HELP)) | ||||||||
667 | m_pHelp->Enable(_bEnable); | ||||||||
668 | if (m_pCancel && (_nWizardButtonFlags & WizardButtonFlags::CANCEL)) | ||||||||
669 | m_pCancel->Enable(_bEnable); | ||||||||
670 | } | ||||||||
671 | |||||||||
672 | IMPL_LINK_NOARG(RoadmapWizard, OnFinish, Button*, void)void RoadmapWizard::LinkStubOnFinish(void * instance, Button* data) { return static_cast<RoadmapWizard *>(instance)-> OnFinish(data); } void RoadmapWizard::OnFinish(__attribute__ ( (unused)) Button*) | ||||||||
673 | { | ||||||||
674 | if ( isTravelingSuspended() ) | ||||||||
675 | return; | ||||||||
676 | RoadmapWizardTravelSuspension aTravelGuard( *this ); | ||||||||
677 | if (!prepareLeaveCurrentState(WizardTypes::eFinish)) | ||||||||
678 | { | ||||||||
679 | return; | ||||||||
680 | } | ||||||||
681 | Finish( RET_OK ); | ||||||||
682 | } | ||||||||
683 | |||||||||
684 | bool RoadmapWizard::prepareLeaveCurrentState( WizardTypes::CommitPageReason _eReason ) | ||||||||
685 | { | ||||||||
686 | IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) ); | ||||||||
687 | ENSURE_OR_RETURN( pController != nullptr, "RoadmapWizard::prepareLeaveCurrentState: no controller for the current page!", true )if( !(pController != nullptr) ) { do { if (true && (! (pController != nullptr))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "687" ": "), "%s", "RoadmapWizard::prepareLeaveCurrentState: no controller for the current page!" ); } } while (false); return true; }; | ||||||||
688 | return pController->commitPage( _eReason ); | ||||||||
689 | } | ||||||||
690 | |||||||||
691 | bool RoadmapWizard::skipBackwardUntil( WizardTypes::WizardState _nTargetState ) | ||||||||
692 | { | ||||||||
693 | // allowed to leave the current page? | ||||||||
694 | if (!prepareLeaveCurrentState(WizardTypes::eTravelBackward)) | ||||||||
| |||||||||
695 | return false; | ||||||||
696 | |||||||||
697 | // don't travel directly on m_xWizardImpl->aStateHistory, in case something goes wrong | ||||||||
698 | std::stack< WizardTypes::WizardState > aTravelVirtually = m_xWizardImpl->aStateHistory; | ||||||||
699 | std::stack< WizardTypes::WizardState > aOldStateHistory = m_xWizardImpl->aStateHistory; | ||||||||
700 | |||||||||
701 | WizardTypes::WizardState nCurrentRollbackState = getCurrentState(); | ||||||||
702 | while ( nCurrentRollbackState != _nTargetState ) | ||||||||
703 | { | ||||||||
704 | DBG_ASSERT( !aTravelVirtually.empty(), "RoadmapWizard::skipBackwardUntil: this target state does not exist in the history!" )do { if (true && (!(!aTravelVirtually.empty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "704" ": "), "%s", "RoadmapWizard::skipBackwardUntil: this target state does not exist in the history!" ); } } while (false); | ||||||||
705 | nCurrentRollbackState = aTravelVirtually.top(); | ||||||||
706 | aTravelVirtually.pop(); | ||||||||
707 | } | ||||||||
708 | m_xWizardImpl->aStateHistory = aTravelVirtually; | ||||||||
709 | if ( !ShowPage( _nTargetState ) ) | ||||||||
710 | { | ||||||||
711 | m_xWizardImpl->aStateHistory = aOldStateHistory; | ||||||||
712 | return false; | ||||||||
713 | } | ||||||||
714 | return true; | ||||||||
715 | } | ||||||||
716 | |||||||||
717 | bool RoadmapWizard::skipUntil( WizardTypes::WizardState _nTargetState ) | ||||||||
718 | { | ||||||||
719 | WizardTypes::WizardState nCurrentState = getCurrentState(); | ||||||||
720 | |||||||||
721 | // allowed to leave the current page? | ||||||||
722 | if ( !prepareLeaveCurrentState( nCurrentState < _nTargetState ? WizardTypes::eTravelForward : WizardTypes::eTravelBackward ) ) | ||||||||
723 | return false; | ||||||||
724 | |||||||||
725 | // don't travel directly on m_xWizardImpl->aStateHistory, in case something goes wrong | ||||||||
726 | std::stack< WizardTypes::WizardState > aTravelVirtually = m_xWizardImpl->aStateHistory; | ||||||||
727 | std::stack< WizardTypes::WizardState > aOldStateHistory = m_xWizardImpl->aStateHistory; | ||||||||
728 | while ( nCurrentState != _nTargetState ) | ||||||||
729 | { | ||||||||
730 | WizardTypes::WizardState nNextState = determineNextState( nCurrentState ); | ||||||||
731 | if ( WZS_INVALID_STATE(::vcl::WizardTypes::WizardState(-1)) == nNextState ) | ||||||||
732 | { | ||||||||
733 | OSL_FAIL( "RoadmapWizard::skipUntil: the given target state does not exist!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "733" ": "), "%s", "RoadmapWizard::skipUntil: the given target state does not exist!" ); } } while (false); | ||||||||
734 | return false; | ||||||||
735 | } | ||||||||
736 | |||||||||
737 | // remember the skipped state in the history | ||||||||
738 | aTravelVirtually.push( nCurrentState ); | ||||||||
739 | |||||||||
740 | // get the next state | ||||||||
741 | nCurrentState = nNextState; | ||||||||
742 | } | ||||||||
743 | m_xWizardImpl->aStateHistory = aTravelVirtually; | ||||||||
744 | // show the target page | ||||||||
745 | if ( !ShowPage( nCurrentState ) ) | ||||||||
746 | { | ||||||||
747 | // argh! prepareLeaveCurrentPage succeeded, determineNextState succeeded, | ||||||||
748 | // but ShowPage doesn't? Somebody behaves very strange here... | ||||||||
749 | OSL_FAIL( "RoadmapWizard::skipUntil: very unpolite..." )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "749" ": "), "%s", "RoadmapWizard::skipUntil: very unpolite..." ); } } while (false); | ||||||||
750 | m_xWizardImpl->aStateHistory = aOldStateHistory; | ||||||||
751 | return false; | ||||||||
752 | } | ||||||||
753 | return true; | ||||||||
754 | } | ||||||||
755 | |||||||||
756 | bool RoadmapWizard::travelNext() | ||||||||
757 | { | ||||||||
758 | // allowed to leave the current page? | ||||||||
759 | if ( !prepareLeaveCurrentState( WizardTypes::eTravelForward ) ) | ||||||||
760 | return false; | ||||||||
761 | |||||||||
762 | // determine the next state to travel to | ||||||||
763 | WizardTypes::WizardState nCurrentState = getCurrentState(); | ||||||||
764 | WizardTypes::WizardState nNextState = determineNextState(nCurrentState); | ||||||||
765 | if (WZS_INVALID_STATE(::vcl::WizardTypes::WizardState(-1)) == nNextState) | ||||||||
766 | return false; | ||||||||
767 | |||||||||
768 | // the state history is used by the enterState method | ||||||||
769 | // all fine | ||||||||
770 | m_xWizardImpl->aStateHistory.push(nCurrentState); | ||||||||
771 | if (!ShowPage(nNextState)) | ||||||||
772 | { | ||||||||
773 | m_xWizardImpl->aStateHistory.pop(); | ||||||||
774 | return false; | ||||||||
775 | } | ||||||||
776 | |||||||||
777 | return true; | ||||||||
778 | } | ||||||||
779 | |||||||||
780 | bool RoadmapWizard::travelPrevious() | ||||||||
781 | { | ||||||||
782 | DBG_ASSERT(!m_xWizardImpl->aStateHistory.empty(), "RoadmapWizard::travelPrevious: have no previous page!")do { if (true && (!(!m_xWizardImpl->aStateHistory. empty()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN) , ("legacy.tools"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "782" ": "), "%s", "RoadmapWizard::travelPrevious: have no previous page!" ); } } while (false); | ||||||||
783 | |||||||||
784 | // allowed to leave the current page? | ||||||||
785 | if ( !prepareLeaveCurrentState( WizardTypes::eTravelBackward ) ) | ||||||||
786 | return false; | ||||||||
787 | |||||||||
788 | // the next state to switch to | ||||||||
789 | WizardTypes::WizardState nPreviousState = m_xWizardImpl->aStateHistory.top(); | ||||||||
790 | |||||||||
791 | // the state history is used by the enterState method | ||||||||
792 | m_xWizardImpl->aStateHistory.pop(); | ||||||||
793 | // show this page | ||||||||
794 | if (!ShowPage(nPreviousState)) | ||||||||
795 | { | ||||||||
796 | m_xWizardImpl->aStateHistory.push(nPreviousState); | ||||||||
797 | return false; | ||||||||
798 | } | ||||||||
799 | |||||||||
800 | // all fine | ||||||||
801 | return true; | ||||||||
802 | } | ||||||||
803 | |||||||||
804 | void RoadmapWizard::removePageFromHistory( WizardTypes::WizardState nToRemove ) | ||||||||
805 | { | ||||||||
806 | |||||||||
807 | std::stack< WizardTypes::WizardState > aTemp; | ||||||||
808 | while(!m_xWizardImpl->aStateHistory.empty()) | ||||||||
809 | { | ||||||||
810 | WizardTypes::WizardState nPreviousState = m_xWizardImpl->aStateHistory.top(); | ||||||||
811 | m_xWizardImpl->aStateHistory.pop(); | ||||||||
812 | if(nPreviousState != nToRemove) | ||||||||
813 | aTemp.push( nPreviousState ); | ||||||||
814 | else | ||||||||
815 | break; | ||||||||
816 | } | ||||||||
817 | while(!aTemp.empty()) | ||||||||
818 | { | ||||||||
819 | m_xWizardImpl->aStateHistory.push( aTemp.top() ); | ||||||||
820 | aTemp.pop(); | ||||||||
821 | } | ||||||||
822 | } | ||||||||
823 | |||||||||
824 | bool RoadmapWizard::isAutomaticNextButtonStateEnabled() const | ||||||||
825 | { | ||||||||
826 | return m_xWizardImpl->m_bAutoNextButtonState; | ||||||||
827 | } | ||||||||
828 | |||||||||
829 | IMPL_LINK_NOARG(RoadmapWizard, OnPrevPage, Button*, void)void RoadmapWizard::LinkStubOnPrevPage(void * instance, Button * data) { return static_cast<RoadmapWizard *>(instance) ->OnPrevPage(data); } void RoadmapWizard::OnPrevPage(__attribute__ ((unused)) Button*) | ||||||||
830 | { | ||||||||
831 | if ( isTravelingSuspended() ) | ||||||||
832 | return; | ||||||||
833 | RoadmapWizardTravelSuspension aTravelGuard( *this ); | ||||||||
834 | travelPrevious(); | ||||||||
835 | } | ||||||||
836 | |||||||||
837 | IMPL_LINK_NOARG(RoadmapWizard, OnNextPage, Button*, void)void RoadmapWizard::LinkStubOnNextPage(void * instance, Button * data) { return static_cast<RoadmapWizard *>(instance) ->OnNextPage(data); } void RoadmapWizard::OnNextPage(__attribute__ ((unused)) Button*) | ||||||||
838 | { | ||||||||
839 | if ( isTravelingSuspended() ) | ||||||||
840 | return; | ||||||||
841 | RoadmapWizardTravelSuspension aTravelGuard( *this ); | ||||||||
842 | travelNext(); | ||||||||
843 | } | ||||||||
844 | |||||||||
845 | IWizardPageController* RoadmapWizard::getPageController( TabPage* _pCurrentPage ) | ||||||||
846 | { | ||||||||
847 | IWizardPageController* pController = dynamic_cast< IWizardPageController* >( _pCurrentPage ); | ||||||||
848 | return pController; | ||||||||
849 | } | ||||||||
850 | |||||||||
851 | bool RoadmapWizard::isTravelingSuspended() const | ||||||||
852 | { | ||||||||
853 | return m_xWizardImpl->m_bTravelingSuspended; | ||||||||
854 | } | ||||||||
855 | |||||||||
856 | void RoadmapWizard::suspendTraveling( AccessGuard ) | ||||||||
857 | { | ||||||||
858 | DBG_ASSERT( !m_xWizardImpl->m_bTravelingSuspended, "RoadmapWizard::suspendTraveling: already suspended!" )do { if (true && (!(!m_xWizardImpl->m_bTravelingSuspended ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "858" ": "), "%s", "RoadmapWizard::suspendTraveling: already suspended!" ); } } while (false); | ||||||||
859 | m_xWizardImpl->m_bTravelingSuspended = true; | ||||||||
860 | } | ||||||||
861 | |||||||||
862 | void RoadmapWizard::resumeTraveling( AccessGuard ) | ||||||||
863 | { | ||||||||
864 | DBG_ASSERT( m_xWizardImpl->m_bTravelingSuspended, "RoadmapWizard::resumeTraveling: nothing to resume!" )do { if (true && (!(m_xWizardImpl->m_bTravelingSuspended ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "864" ": "), "%s", "RoadmapWizard::resumeTraveling: nothing to resume!" ); } } while (false); | ||||||||
865 | m_xWizardImpl->m_bTravelingSuspended = false; | ||||||||
866 | } | ||||||||
867 | |||||||||
868 | WizardMachine::WizardMachine(weld::Window* pParent, WizardButtonFlags nButtonFlags) | ||||||||
869 | : AssistantController(pParent, "vcl/ui/wizard.ui", "Wizard") | ||||||||
870 | , m_pCurTabPage(nullptr) | ||||||||
871 | , m_nCurState(0) | ||||||||
872 | , m_pFirstPage(nullptr) | ||||||||
873 | , m_xFinish(m_xAssistant->weld_widget_for_response(RET_OK)) | ||||||||
874 | , m_xCancel(m_xAssistant->weld_widget_for_response(RET_CANCEL)) | ||||||||
875 | , m_xNextPage(m_xAssistant->weld_widget_for_response(RET_YES)) | ||||||||
876 | , m_xPrevPage(m_xAssistant->weld_widget_for_response(RET_NO)) | ||||||||
877 | , m_xHelp(m_xAssistant->weld_widget_for_response(RET_HELP)) | ||||||||
878 | , m_pImpl(new WizardMachineImplData) | ||||||||
879 | { | ||||||||
880 | implConstruct(nButtonFlags); | ||||||||
881 | } | ||||||||
882 | |||||||||
883 | void WizardMachine::implConstruct(const WizardButtonFlags nButtonFlags) | ||||||||
884 | { | ||||||||
885 | m_pImpl->sTitleBase = m_xAssistant->get_title(); | ||||||||
886 | |||||||||
887 | const bool bHideHelp = comphelper::LibreOfficeKit::isActive() && | ||||||||
888 | officecfg::Office::Common::Help::HelpRootURL::get().isEmpty(); | ||||||||
889 | // create the buttons according to the wizard button flags | ||||||||
890 | // the help button | ||||||||
891 | if (nButtonFlags & WizardButtonFlags::HELP && !bHideHelp) | ||||||||
892 | m_xHelp->show(); | ||||||||
893 | else | ||||||||
894 | m_xHelp->hide(); | ||||||||
895 | |||||||||
896 | // the previous button | ||||||||
897 | if (nButtonFlags & WizardButtonFlags::PREVIOUS) | ||||||||
898 | { | ||||||||
899 | m_xPrevPage->set_help_id( HID_WIZARD_PREVIOUS"SVT_HID_WIZARD_PREVIOUS" ); | ||||||||
900 | m_xPrevPage->show(); | ||||||||
901 | |||||||||
902 | m_xPrevPage->connect_clicked( LINK( this, WizardMachine, OnPrevPage )::tools::detail::makeLink( ::tools::detail::castTo<WizardMachine *>(this), &WizardMachine::LinkStubOnPrevPage) ); | ||||||||
903 | } | ||||||||
904 | else | ||||||||
905 | m_xPrevPage->hide(); | ||||||||
906 | |||||||||
907 | // the next button | ||||||||
908 | if (nButtonFlags & WizardButtonFlags::NEXT) | ||||||||
909 | { | ||||||||
910 | m_xNextPage->set_help_id( HID_WIZARD_NEXT"SVT_HID_WIZARD_NEXT" ); | ||||||||
911 | m_xNextPage->show(); | ||||||||
912 | |||||||||
913 | m_xNextPage->connect_clicked( LINK( this, WizardMachine, OnNextPage )::tools::detail::makeLink( ::tools::detail::castTo<WizardMachine *>(this), &WizardMachine::LinkStubOnNextPage) ); | ||||||||
914 | } | ||||||||
915 | else | ||||||||
916 | m_xNextPage->hide(); | ||||||||
917 | |||||||||
918 | // the finish button | ||||||||
919 | if (nButtonFlags & WizardButtonFlags::FINISH) | ||||||||
920 | { | ||||||||
921 | m_xFinish->show(); | ||||||||
922 | |||||||||
923 | m_xFinish->connect_clicked( LINK( this, WizardMachine, OnFinish )::tools::detail::makeLink( ::tools::detail::castTo<WizardMachine *>(this), &WizardMachine::LinkStubOnFinish) ); | ||||||||
924 | } | ||||||||
925 | else | ||||||||
926 | m_xFinish->hide(); | ||||||||
927 | |||||||||
928 | // the cancel button | ||||||||
929 | if (nButtonFlags & WizardButtonFlags::CANCEL) | ||||||||
930 | { | ||||||||
931 | m_xCancel->show(); | ||||||||
932 | m_xCancel->connect_clicked( LINK( this, WizardMachine, OnCancel )::tools::detail::makeLink( ::tools::detail::castTo<WizardMachine *>(this), &WizardMachine::LinkStubOnCancel) ); | ||||||||
933 | } | ||||||||
934 | else | ||||||||
935 | m_xCancel->hide(); | ||||||||
936 | } | ||||||||
937 | |||||||||
938 | WizardMachine::~WizardMachine() | ||||||||
939 | { | ||||||||
940 | if (m_pImpl) | ||||||||
941 | { | ||||||||
942 | while (m_pFirstPage) | ||||||||
943 | RemovePage(m_pFirstPage->mxPage.get()); | ||||||||
944 | m_pImpl.reset(); | ||||||||
945 | } | ||||||||
946 | } | ||||||||
947 | |||||||||
948 | void WizardMachine::implUpdateTitle() | ||||||||
949 | { | ||||||||
950 | OUString sCompleteTitle(m_pImpl->sTitleBase); | ||||||||
951 | |||||||||
952 | // append the page title | ||||||||
953 | BuilderPage* pCurrentPage = GetPage(getCurrentState()); | ||||||||
954 | if ( pCurrentPage && !pCurrentPage->GetPageTitle().isEmpty() ) | ||||||||
955 | { | ||||||||
956 | sCompleteTitle += " - " + pCurrentPage->GetPageTitle(); | ||||||||
957 | } | ||||||||
958 | |||||||||
959 | m_xAssistant->set_title(sCompleteTitle); | ||||||||
960 | } | ||||||||
961 | |||||||||
962 | void WizardMachine::setTitleBase(const OUString& _rTitleBase) | ||||||||
963 | { | ||||||||
964 | m_pImpl->sTitleBase = _rTitleBase; | ||||||||
965 | implUpdateTitle(); | ||||||||
966 | } | ||||||||
967 | |||||||||
968 | BuilderPage* WizardMachine::GetOrCreatePage( const WizardTypes::WizardState i_nState ) | ||||||||
969 | { | ||||||||
970 | if ( nullptr == GetPage( i_nState ) ) | ||||||||
971 | { | ||||||||
972 | std::unique_ptr<BuilderPage> xNewPage = createPage( i_nState ); | ||||||||
973 | DBG_ASSERT( xNewPage, "WizardMachine::GetOrCreatePage: invalid new page (NULL)!" )do { if (true && (!(xNewPage))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "973" ": "), "%s", "WizardMachine::GetOrCreatePage: invalid new page (NULL)!" ); } } while (false); | ||||||||
974 | |||||||||
975 | // fill up the page sequence of our base class (with dummies) | ||||||||
976 | while ( m_pImpl->nFirstUnknownPage < i_nState ) | ||||||||
977 | { | ||||||||
978 | AddPage( nullptr ); | ||||||||
979 | ++m_pImpl->nFirstUnknownPage; | ||||||||
980 | } | ||||||||
981 | |||||||||
982 | if ( m_pImpl->nFirstUnknownPage == i_nState ) | ||||||||
983 | { | ||||||||
984 | // encountered this page number the first time | ||||||||
985 | AddPage(std::move(xNewPage)); | ||||||||
986 | ++m_pImpl->nFirstUnknownPage; | ||||||||
987 | } | ||||||||
988 | else | ||||||||
989 | // already had this page - just change it | ||||||||
990 | SetPage(i_nState, std::move(xNewPage)); | ||||||||
991 | } | ||||||||
992 | return GetPage( i_nState ); | ||||||||
993 | } | ||||||||
994 | |||||||||
995 | void WizardMachine::ActivatePage() | ||||||||
996 | { | ||||||||
997 | WizardTypes::WizardState nCurrentLevel = m_nCurState; | ||||||||
998 | GetOrCreatePage( nCurrentLevel ); | ||||||||
999 | |||||||||
1000 | enterState( nCurrentLevel ); | ||||||||
1001 | } | ||||||||
1002 | |||||||||
1003 | bool WizardMachine::DeactivatePage() | ||||||||
1004 | { | ||||||||
1005 | WizardTypes::WizardState nCurrentState = getCurrentState(); | ||||||||
1006 | return leaveState(nCurrentState); | ||||||||
1007 | } | ||||||||
1008 | |||||||||
1009 | void WizardMachine::defaultButton(WizardButtonFlags _nWizardButtonFlags) | ||||||||
1010 | { | ||||||||
1011 | // the new default button | ||||||||
1012 | weld::Button* pNewDefButton = nullptr; | ||||||||
1013 | if (_nWizardButtonFlags & WizardButtonFlags::FINISH) | ||||||||
1014 | pNewDefButton = m_xFinish.get(); | ||||||||
1015 | if (_nWizardButtonFlags & WizardButtonFlags::NEXT) | ||||||||
1016 | pNewDefButton = m_xNextPage.get(); | ||||||||
1017 | if (_nWizardButtonFlags & WizardButtonFlags::PREVIOUS) | ||||||||
1018 | pNewDefButton = m_xPrevPage.get(); | ||||||||
1019 | if (_nWizardButtonFlags & WizardButtonFlags::HELP) | ||||||||
1020 | pNewDefButton = m_xHelp.get(); | ||||||||
1021 | if (_nWizardButtonFlags & WizardButtonFlags::CANCEL) | ||||||||
1022 | pNewDefButton = m_xCancel.get(); | ||||||||
1023 | |||||||||
1024 | if ( pNewDefButton ) | ||||||||
1025 | defaultButton( pNewDefButton ); | ||||||||
1026 | else | ||||||||
1027 | m_xAssistant->recursively_unset_default_buttons(); | ||||||||
1028 | } | ||||||||
1029 | |||||||||
1030 | void WizardMachine::defaultButton(weld::Button* _pNewDefButton) | ||||||||
1031 | { | ||||||||
1032 | // loop through all (direct and indirect) descendants which participate in our tabbing order, and | ||||||||
1033 | // reset the WB_DEFBUTTON for every window which is a button | ||||||||
1034 | m_xAssistant->recursively_unset_default_buttons(); | ||||||||
1035 | |||||||||
1036 | // set its new style | ||||||||
1037 | if (_pNewDefButton) | ||||||||
1038 | _pNewDefButton->set_has_default(true); | ||||||||
1039 | } | ||||||||
1040 | |||||||||
1041 | void WizardMachine::enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable) | ||||||||
1042 | { | ||||||||
1043 | if (_nWizardButtonFlags & WizardButtonFlags::FINISH) | ||||||||
1044 | m_xFinish->set_sensitive(_bEnable); | ||||||||
1045 | if (_nWizardButtonFlags & WizardButtonFlags::NEXT) | ||||||||
1046 | m_xNextPage->set_sensitive(_bEnable); | ||||||||
1047 | if (_nWizardButtonFlags & WizardButtonFlags::PREVIOUS) | ||||||||
1048 | m_xPrevPage->set_sensitive(_bEnable); | ||||||||
1049 | if (_nWizardButtonFlags & WizardButtonFlags::HELP) | ||||||||
1050 | m_xHelp->set_sensitive(_bEnable); | ||||||||
1051 | if (_nWizardButtonFlags & WizardButtonFlags::CANCEL) | ||||||||
1052 | m_xCancel->set_sensitive(_bEnable); | ||||||||
1053 | } | ||||||||
1054 | |||||||||
1055 | void WizardMachine::enterState(WizardTypes::WizardState _nState) | ||||||||
1056 | { | ||||||||
1057 | // tell the page | ||||||||
1058 | IWizardPageController* pController = getPageController( GetPage( _nState ) ); | ||||||||
1059 | OSL_ENSURE( pController, "WizardMachine::enterState: no controller for the given page!" )do { if (true && (!(pController))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1059" ": "), "%s", "WizardMachine::enterState: no controller for the given page!" ); } } while (false); | ||||||||
1060 | if ( pController ) | ||||||||
1061 | pController->initializePage(); | ||||||||
1062 | |||||||||
1063 | if ( isAutomaticNextButtonStateEnabled() ) | ||||||||
1064 | enableButtons( WizardButtonFlags::NEXT, canAdvance() ); | ||||||||
1065 | |||||||||
1066 | enableButtons( WizardButtonFlags::PREVIOUS, !m_pImpl->aStateHistory.empty() ); | ||||||||
1067 | |||||||||
1068 | // set the new title - it depends on the current page (i.e. state) | ||||||||
1069 | implUpdateTitle(); | ||||||||
1070 | } | ||||||||
1071 | |||||||||
1072 | bool WizardMachine::leaveState(WizardTypes::WizardState) | ||||||||
1073 | { | ||||||||
1074 | // no need to ask the page here. | ||||||||
1075 | // If we reach this point, we already gave the current page the chance to commit it's data, | ||||||||
1076 | // and it was allowed to commit it's data | ||||||||
1077 | |||||||||
1078 | return true; | ||||||||
1079 | } | ||||||||
1080 | |||||||||
1081 | bool WizardMachine::onFinish() | ||||||||
1082 | { | ||||||||
1083 | return Finish(RET_OK); | ||||||||
1084 | } | ||||||||
1085 | |||||||||
1086 | IMPL_LINK_NOARG(WizardMachine, OnFinish, weld::Button&, void)void WizardMachine::LinkStubOnFinish(void * instance, weld::Button & data) { return static_cast<WizardMachine *>(instance )->OnFinish(data); } void WizardMachine::OnFinish(__attribute__ ((unused)) weld::Button&) | ||||||||
1087 | { | ||||||||
1088 | if ( isTravelingSuspended() ) | ||||||||
1089 | return; | ||||||||
1090 | |||||||||
1091 | // prevent WizardTravelSuspension from using this instance | ||||||||
1092 | // after will be destructed due to onFinish and async response call | ||||||||
1093 | { | ||||||||
1094 | WizardTravelSuspension aTravelGuard( *this ); | ||||||||
1095 | if (!prepareLeaveCurrentState(WizardTypes::eFinish)) | ||||||||
1096 | { | ||||||||
1097 | return; | ||||||||
1098 | } | ||||||||
1099 | } | ||||||||
1100 | |||||||||
1101 | onFinish(); | ||||||||
1102 | } | ||||||||
1103 | |||||||||
1104 | IMPL_LINK_NOARG(WizardMachine, OnCancel, weld::Button&, void)void WizardMachine::LinkStubOnCancel(void * instance, weld::Button & data) { return static_cast<WizardMachine *>(instance )->OnCancel(data); } void WizardMachine::OnCancel(__attribute__ ((unused)) weld::Button&) | ||||||||
1105 | { | ||||||||
1106 | m_xAssistant->response(RET_CANCEL); | ||||||||
1107 | } | ||||||||
1108 | |||||||||
1109 | WizardTypes::WizardState WizardMachine::determineNextState(WizardTypes::WizardState _nCurrentState ) const | ||||||||
1110 | { | ||||||||
1111 | return _nCurrentState + 1; | ||||||||
1112 | } | ||||||||
1113 | |||||||||
1114 | bool WizardMachine::prepareLeaveCurrentState( WizardTypes::CommitPageReason _eReason ) | ||||||||
1115 | { | ||||||||
1116 | IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) ); | ||||||||
1117 | ENSURE_OR_RETURN( pController != nullptr, "WizardMachine::prepareLeaveCurrentState: no controller for the current page!", true )if( !(pController != nullptr) ) { do { if (true && (! (pController != nullptr))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1117" ": "), "%s", "WizardMachine::prepareLeaveCurrentState: no controller for the current page!" ); } } while (false); return true; }; | ||||||||
1118 | return pController->commitPage( _eReason ); | ||||||||
1119 | } | ||||||||
1120 | |||||||||
1121 | bool WizardMachine::skipBackwardUntil(WizardTypes::WizardState _nTargetState) | ||||||||
1122 | { | ||||||||
1123 | // allowed to leave the current page? | ||||||||
1124 | if ( !prepareLeaveCurrentState( WizardTypes::eTravelBackward ) ) | ||||||||
1125 | return false; | ||||||||
1126 | |||||||||
1127 | // don't travel directly on m_pImpl->aStateHistory, in case something goes wrong | ||||||||
1128 | std::stack< WizardTypes::WizardState > aTravelVirtually = m_pImpl->aStateHistory; | ||||||||
1129 | std::stack< WizardTypes::WizardState > aOldStateHistory = m_pImpl->aStateHistory; | ||||||||
1130 | |||||||||
1131 | WizardTypes::WizardState nCurrentRollbackState = getCurrentState(); | ||||||||
1132 | while ( nCurrentRollbackState != _nTargetState ) | ||||||||
1133 | { | ||||||||
1134 | DBG_ASSERT( !aTravelVirtually.empty(), "WizardMachine::skipBackwardUntil: this target state does not exist in the history!" )do { if (true && (!(!aTravelVirtually.empty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1134" ": "), "%s", "WizardMachine::skipBackwardUntil: this target state does not exist in the history!" ); } } while (false); | ||||||||
1135 | nCurrentRollbackState = aTravelVirtually.top(); | ||||||||
1136 | aTravelVirtually.pop(); | ||||||||
1137 | } | ||||||||
1138 | m_pImpl->aStateHistory = aTravelVirtually; | ||||||||
1139 | if ( !ShowPage( _nTargetState ) ) | ||||||||
1140 | { | ||||||||
1141 | m_pImpl->aStateHistory = aOldStateHistory; | ||||||||
1142 | return false; | ||||||||
1143 | } | ||||||||
1144 | return true; | ||||||||
1145 | } | ||||||||
1146 | |||||||||
1147 | bool WizardMachine::skipUntil( WizardTypes::WizardState _nTargetState ) | ||||||||
1148 | { | ||||||||
1149 | WizardTypes::WizardState nCurrentState = getCurrentState(); | ||||||||
1150 | |||||||||
1151 | // allowed to leave the current page? | ||||||||
1152 | if ( !prepareLeaveCurrentState( nCurrentState < _nTargetState ? WizardTypes::eTravelForward : WizardTypes::eTravelBackward ) ) | ||||||||
1153 | return false; | ||||||||
1154 | |||||||||
1155 | // don't travel directly on m_pImpl->aStateHistory, in case something goes wrong | ||||||||
1156 | std::stack< WizardTypes::WizardState > aTravelVirtually = m_pImpl->aStateHistory; | ||||||||
1157 | std::stack< WizardTypes::WizardState > aOldStateHistory = m_pImpl->aStateHistory; | ||||||||
1158 | while ( nCurrentState != _nTargetState ) | ||||||||
1159 | { | ||||||||
1160 | WizardTypes::WizardState nNextState = determineNextState( nCurrentState ); | ||||||||
1161 | if ( WZS_INVALID_STATE(::vcl::WizardTypes::WizardState(-1)) == nNextState ) | ||||||||
1162 | { | ||||||||
1163 | OSL_FAIL( "WizardMachine::skipUntil: the given target state does not exist!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1163" ": "), "%s", "WizardMachine::skipUntil: the given target state does not exist!" ); } } while (false); | ||||||||
1164 | return false; | ||||||||
1165 | } | ||||||||
1166 | |||||||||
1167 | // remember the skipped state in the history | ||||||||
1168 | aTravelVirtually.push( nCurrentState ); | ||||||||
1169 | |||||||||
1170 | // get the next state | ||||||||
1171 | nCurrentState = nNextState; | ||||||||
1172 | } | ||||||||
1173 | m_pImpl->aStateHistory = aTravelVirtually; | ||||||||
1174 | // show the target page | ||||||||
1175 | if ( !ShowPage( nCurrentState ) ) | ||||||||
1176 | { | ||||||||
1177 | // argh! prepareLeaveCurrentPage succeeded, determineNextState succeeded, | ||||||||
1178 | // but ShowPage doesn't? Somebody behaves very strange here... | ||||||||
1179 | OSL_FAIL( "WizardMachine::skipUntil: very unpolite..." )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1179" ": "), "%s", "WizardMachine::skipUntil: very unpolite..." ); } } while (false); | ||||||||
1180 | m_pImpl->aStateHistory = aOldStateHistory; | ||||||||
1181 | return false; | ||||||||
1182 | } | ||||||||
1183 | return true; | ||||||||
1184 | } | ||||||||
1185 | |||||||||
1186 | void WizardMachine::skip() | ||||||||
1187 | { | ||||||||
1188 | // allowed to leave the current page? | ||||||||
1189 | if ( !prepareLeaveCurrentState( WizardTypes::eTravelForward ) ) | ||||||||
1190 | return; | ||||||||
1191 | |||||||||
1192 | WizardTypes::WizardState nCurrentState = getCurrentState(); | ||||||||
1193 | WizardTypes::WizardState nNextState = determineNextState(nCurrentState); | ||||||||
1194 | |||||||||
1195 | if (WZS_INVALID_STATE(::vcl::WizardTypes::WizardState(-1)) == nNextState) | ||||||||
1196 | return; | ||||||||
1197 | |||||||||
1198 | // remember the skipped state in the history | ||||||||
1199 | m_pImpl->aStateHistory.push(nCurrentState); | ||||||||
1200 | |||||||||
1201 | // get the next state | ||||||||
1202 | nCurrentState = nNextState; | ||||||||
1203 | |||||||||
1204 | // show the (n+1)th page | ||||||||
1205 | if (!ShowPage(nCurrentState)) | ||||||||
1206 | { | ||||||||
1207 | // TODO: this leaves us in a state where we have no current page and an inconsistent state history. | ||||||||
1208 | // Perhaps we should rollback the skipping here... | ||||||||
1209 | OSL_FAIL("RoadmapWizard::skip: very unpolite...")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1209" ": "), "%s", "RoadmapWizard::skip: very unpolite..." ); } } while (false); | ||||||||
1210 | // if somebody does a skip and then does not allow to leave... | ||||||||
1211 | // (can't be a commit error, as we've already committed the current page. So if ShowPage fails here, | ||||||||
1212 | // somebody behaves really strange ...) | ||||||||
1213 | return; | ||||||||
1214 | } | ||||||||
1215 | |||||||||
1216 | // all fine | ||||||||
1217 | } | ||||||||
1218 | |||||||||
1219 | bool WizardMachine::travelNext() | ||||||||
1220 | { | ||||||||
1221 | // allowed to leave the current page? | ||||||||
1222 | if ( !prepareLeaveCurrentState( WizardTypes::eTravelForward ) ) | ||||||||
1223 | return false; | ||||||||
1224 | |||||||||
1225 | // determine the next state to travel to | ||||||||
1226 | WizardTypes::WizardState nCurrentState = getCurrentState(); | ||||||||
1227 | WizardTypes::WizardState nNextState = determineNextState(nCurrentState); | ||||||||
1228 | if (WZS_INVALID_STATE(::vcl::WizardTypes::WizardState(-1)) == nNextState) | ||||||||
1229 | return false; | ||||||||
1230 | |||||||||
1231 | // the state history is used by the enterState method | ||||||||
1232 | // all fine | ||||||||
1233 | m_pImpl->aStateHistory.push(nCurrentState); | ||||||||
1234 | if (!ShowPage(nNextState)) | ||||||||
1235 | { | ||||||||
1236 | m_pImpl->aStateHistory.pop(); | ||||||||
1237 | return false; | ||||||||
1238 | } | ||||||||
1239 | |||||||||
1240 | return true; | ||||||||
1241 | } | ||||||||
1242 | |||||||||
1243 | bool WizardMachine::ShowPage(WizardTypes::WizardState nState) | ||||||||
1244 | { | ||||||||
1245 | if (DeactivatePage()) | ||||||||
1246 | { | ||||||||
1247 | BuilderPage* pOldTabPage = m_pCurTabPage; | ||||||||
1248 | |||||||||
1249 | m_nCurState = nState; | ||||||||
1250 | ActivatePage(); | ||||||||
1251 | |||||||||
1252 | if (pOldTabPage) | ||||||||
1253 | pOldTabPage->Deactivate(); | ||||||||
1254 | |||||||||
1255 | m_xAssistant->set_current_page(OString::number(nState)); | ||||||||
1256 | |||||||||
1257 | m_pCurTabPage = GetPage(m_nCurState); | ||||||||
1258 | m_pCurTabPage->Activate(); | ||||||||
1259 | |||||||||
1260 | return true; | ||||||||
1261 | } | ||||||||
1262 | return false; | ||||||||
1263 | } | ||||||||
1264 | |||||||||
1265 | bool WizardMachine::ShowNextPage() | ||||||||
1266 | { | ||||||||
1267 | return ShowPage(m_nCurState + 1); | ||||||||
1268 | } | ||||||||
1269 | |||||||||
1270 | bool WizardMachine::ShowPrevPage() | ||||||||
1271 | { | ||||||||
1272 | if (!m_nCurState) | ||||||||
1273 | return false; | ||||||||
1274 | return ShowPage(m_nCurState - 1); | ||||||||
1275 | } | ||||||||
1276 | |||||||||
1277 | bool WizardMachine::travelPrevious() | ||||||||
1278 | { | ||||||||
1279 | DBG_ASSERT(!m_pImpl->aStateHistory.empty(), "WizardMachine::travelPrevious: have no previous page!")do { if (true && (!(!m_pImpl->aStateHistory.empty( )))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1279" ": "), "%s", "WizardMachine::travelPrevious: have no previous page!" ); } } while (false); | ||||||||
1280 | |||||||||
1281 | // allowed to leave the current page? | ||||||||
1282 | if ( !prepareLeaveCurrentState( WizardTypes::eTravelBackward ) ) | ||||||||
1283 | return false; | ||||||||
1284 | |||||||||
1285 | // the next state to switch to | ||||||||
1286 | WizardTypes::WizardState nPreviousState = m_pImpl->aStateHistory.top(); | ||||||||
1287 | |||||||||
1288 | // the state history is used by the enterState method | ||||||||
1289 | m_pImpl->aStateHistory.pop(); | ||||||||
1290 | // show this page | ||||||||
1291 | if (!ShowPage(nPreviousState)) | ||||||||
1292 | { | ||||||||
1293 | m_pImpl->aStateHistory.push(nPreviousState); | ||||||||
1294 | return false; | ||||||||
1295 | } | ||||||||
1296 | |||||||||
1297 | // all fine | ||||||||
1298 | return true; | ||||||||
1299 | } | ||||||||
1300 | |||||||||
1301 | |||||||||
1302 | void WizardMachine::removePageFromHistory( WizardTypes::WizardState nToRemove ) | ||||||||
1303 | { | ||||||||
1304 | |||||||||
1305 | std::stack< WizardTypes::WizardState > aTemp; | ||||||||
1306 | while(!m_pImpl->aStateHistory.empty()) | ||||||||
1307 | { | ||||||||
1308 | WizardTypes::WizardState nPreviousState = m_pImpl->aStateHistory.top(); | ||||||||
1309 | m_pImpl->aStateHistory.pop(); | ||||||||
1310 | if(nPreviousState != nToRemove) | ||||||||
1311 | aTemp.push( nPreviousState ); | ||||||||
1312 | else | ||||||||
1313 | break; | ||||||||
1314 | } | ||||||||
1315 | while(!aTemp.empty()) | ||||||||
1316 | { | ||||||||
1317 | m_pImpl->aStateHistory.push( aTemp.top() ); | ||||||||
1318 | aTemp.pop(); | ||||||||
1319 | } | ||||||||
1320 | } | ||||||||
1321 | |||||||||
1322 | |||||||||
1323 | void WizardMachine::enableAutomaticNextButtonState() | ||||||||
1324 | { | ||||||||
1325 | m_pImpl->m_bAutoNextButtonState = true; | ||||||||
1326 | } | ||||||||
1327 | |||||||||
1328 | |||||||||
1329 | bool WizardMachine::isAutomaticNextButtonStateEnabled() const | ||||||||
1330 | { | ||||||||
1331 | return m_pImpl->m_bAutoNextButtonState; | ||||||||
1332 | } | ||||||||
1333 | |||||||||
1334 | IMPL_LINK_NOARG(WizardMachine, OnPrevPage, weld::Button&, void)void WizardMachine::LinkStubOnPrevPage(void * instance, weld:: Button& data) { return static_cast<WizardMachine *> (instance)->OnPrevPage(data); } void WizardMachine::OnPrevPage (__attribute__ ((unused)) weld::Button&) | ||||||||
1335 | { | ||||||||
1336 | if ( isTravelingSuspended() ) | ||||||||
1337 | return; | ||||||||
1338 | WizardTravelSuspension aTravelGuard( *this ); | ||||||||
1339 | travelPrevious(); | ||||||||
1340 | } | ||||||||
1341 | |||||||||
1342 | IMPL_LINK_NOARG(WizardMachine, OnNextPage, weld::Button&, void)void WizardMachine::LinkStubOnNextPage(void * instance, weld:: Button& data) { return static_cast<WizardMachine *> (instance)->OnNextPage(data); } void WizardMachine::OnNextPage (__attribute__ ((unused)) weld::Button&) | ||||||||
1343 | { | ||||||||
1344 | if ( isTravelingSuspended() ) | ||||||||
1345 | return; | ||||||||
1346 | WizardTravelSuspension aTravelGuard( *this ); | ||||||||
1347 | travelNext(); | ||||||||
1348 | } | ||||||||
1349 | |||||||||
1350 | IWizardPageController* WizardMachine::getPageController(BuilderPage* pCurrentPage) const | ||||||||
1351 | { | ||||||||
1352 | IWizardPageController* pController = dynamic_cast<IWizardPageController*>(pCurrentPage); | ||||||||
1353 | return pController; | ||||||||
1354 | } | ||||||||
1355 | |||||||||
1356 | void WizardMachine::getStateHistory( std::vector< WizardTypes::WizardState >& _out_rHistory ) | ||||||||
1357 | { | ||||||||
1358 | std::stack< WizardTypes::WizardState > aHistoryCopy( m_pImpl->aStateHistory ); | ||||||||
1359 | while ( !aHistoryCopy.empty() ) | ||||||||
1360 | { | ||||||||
1361 | _out_rHistory.push_back( aHistoryCopy.top() ); | ||||||||
1362 | aHistoryCopy.pop(); | ||||||||
1363 | } | ||||||||
1364 | } | ||||||||
1365 | |||||||||
1366 | bool WizardMachine::canAdvance() const | ||||||||
1367 | { | ||||||||
1368 | return WZS_INVALID_STATE(::vcl::WizardTypes::WizardState(-1)) != determineNextState( getCurrentState() ); | ||||||||
1369 | } | ||||||||
1370 | |||||||||
1371 | void WizardMachine::updateTravelUI() | ||||||||
1372 | { | ||||||||
1373 | const IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) ); | ||||||||
1374 | OSL_ENSURE( pController != nullptr, "RoadmapWizard::updateTravelUI: no controller for the current page!" )do { if (true && (!(pController != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1374" ": "), "%s", "RoadmapWizard::updateTravelUI: no controller for the current page!" ); } } while (false); | ||||||||
1375 | |||||||||
1376 | bool bCanAdvance = | ||||||||
1377 | ( !pController || pController->canAdvance() ) // the current page allows to advance | ||||||||
1378 | && canAdvance(); // the dialog as a whole allows to advance | ||||||||
1379 | enableButtons( WizardButtonFlags::NEXT, bCanAdvance ); | ||||||||
1380 | } | ||||||||
1381 | |||||||||
1382 | bool WizardMachine::isTravelingSuspended() const | ||||||||
1383 | { | ||||||||
1384 | return m_pImpl->m_bTravelingSuspended; | ||||||||
1385 | } | ||||||||
1386 | |||||||||
1387 | void WizardMachine::suspendTraveling( AccessGuard ) | ||||||||
1388 | { | ||||||||
1389 | DBG_ASSERT( !m_pImpl->m_bTravelingSuspended, "WizardMachine::suspendTraveling: already suspended!" )do { if (true && (!(!m_pImpl->m_bTravelingSuspended ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1389" ": "), "%s", "WizardMachine::suspendTraveling: already suspended!" ); } } while (false); | ||||||||
1390 | m_pImpl->m_bTravelingSuspended = true; | ||||||||
1391 | } | ||||||||
1392 | |||||||||
1393 | void WizardMachine::resumeTraveling( AccessGuard ) | ||||||||
1394 | { | ||||||||
1395 | if (!m_pImpl) | ||||||||
1396 | return; | ||||||||
1397 | |||||||||
1398 | DBG_ASSERT( m_pImpl->m_bTravelingSuspended, "WizardMachine::resumeTraveling: nothing to resume!" )do { if (true && (!(m_pImpl->m_bTravelingSuspended ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1398" ": "), "%s", "WizardMachine::resumeTraveling: nothing to resume!" ); } } while (false); | ||||||||
1399 | m_pImpl->m_bTravelingSuspended = false; | ||||||||
1400 | } | ||||||||
1401 | |||||||||
1402 | bool WizardMachine::Finish(short nResult) | ||||||||
1403 | { | ||||||||
1404 | if ( DeactivatePage() ) | ||||||||
1405 | { | ||||||||
1406 | if (m_pCurTabPage) | ||||||||
1407 | m_pCurTabPage->Deactivate(); | ||||||||
1408 | |||||||||
1409 | m_xAssistant->response(nResult); | ||||||||
1410 | return true; | ||||||||
1411 | } | ||||||||
1412 | else | ||||||||
1413 | return false; | ||||||||
1414 | } | ||||||||
1415 | |||||||||
1416 | void WizardMachine::AddPage(std::unique_ptr<BuilderPage> xPage) | ||||||||
1417 | { | ||||||||
1418 | WizPageData* pNewPageData = new WizPageData; | ||||||||
1419 | pNewPageData->mpNext = nullptr; | ||||||||
1420 | pNewPageData->mxPage = std::move(xPage); | ||||||||
1421 | |||||||||
1422 | if ( !m_pFirstPage ) | ||||||||
1423 | m_pFirstPage = pNewPageData; | ||||||||
1424 | else | ||||||||
1425 | { | ||||||||
1426 | WizPageData* pPageData = m_pFirstPage; | ||||||||
1427 | while ( pPageData->mpNext ) | ||||||||
1428 | pPageData = pPageData->mpNext; | ||||||||
1429 | pPageData->mpNext = pNewPageData; | ||||||||
1430 | } | ||||||||
1431 | } | ||||||||
1432 | |||||||||
1433 | void WizardMachine::RemovePage(const BuilderPage* pPage) | ||||||||
1434 | { | ||||||||
1435 | WizPageData* pPrevPageData = nullptr; | ||||||||
1436 | WizPageData* pPageData = m_pFirstPage; | ||||||||
1437 | while ( pPageData ) | ||||||||
1438 | { | ||||||||
1439 | if (pPageData->mxPage.get() == pPage) | ||||||||
1440 | { | ||||||||
1441 | if (pPrevPageData) | ||||||||
1442 | pPrevPageData->mpNext = pPageData->mpNext; | ||||||||
1443 | else | ||||||||
1444 | m_pFirstPage = pPageData->mpNext; | ||||||||
1445 | if (pPage == m_pCurTabPage) | ||||||||
1446 | m_pCurTabPage = nullptr; | ||||||||
1447 | delete pPageData; | ||||||||
1448 | return; | ||||||||
1449 | } | ||||||||
1450 | |||||||||
1451 | pPrevPageData = pPageData; | ||||||||
1452 | pPageData = pPageData->mpNext; | ||||||||
1453 | } | ||||||||
1454 | |||||||||
1455 | OSL_FAIL( "WizardMachine::RemovePage() - Page not in list" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/control/wizardmachine.cxx" ":" "1455" ": "), "%s", "WizardMachine::RemovePage() - Page not in list" ); } } while (false); | ||||||||
1456 | } | ||||||||
1457 | |||||||||
1458 | void WizardMachine::SetPage(WizardTypes::WizardState nLevel, std::unique_ptr<BuilderPage> xPage) | ||||||||
1459 | { | ||||||||
1460 | sal_uInt16 nTempLevel = 0; | ||||||||
1461 | WizPageData* pPageData = m_pFirstPage; | ||||||||
1462 | while ( pPageData ) | ||||||||
1463 | { | ||||||||
1464 | if ( (nTempLevel == nLevel) || !pPageData->mpNext ) | ||||||||
1465 | break; | ||||||||
1466 | |||||||||
1467 | nTempLevel++; | ||||||||
1468 | pPageData = pPageData->mpNext; | ||||||||
1469 | } | ||||||||
1470 | |||||||||
1471 | if ( pPageData ) | ||||||||
1472 | { | ||||||||
1473 | if (pPageData->mxPage.get() == m_pCurTabPage) | ||||||||
1474 | m_pCurTabPage = nullptr; | ||||||||
1475 | pPageData->mxPage = std::move(xPage); | ||||||||
1476 | } | ||||||||
1477 | } | ||||||||
1478 | |||||||||
1479 | BuilderPage* WizardMachine::GetPage(WizardTypes::WizardState nLevel) const | ||||||||
1480 | { | ||||||||
1481 | sal_uInt16 nTempLevel = 0; | ||||||||
1482 | |||||||||
1483 | for (WizPageData* pPageData = m_pFirstPage; pPageData; | ||||||||
1484 | pPageData = pPageData->mpNext) | ||||||||
1485 | { | ||||||||
1486 | if ( nTempLevel == nLevel ) | ||||||||
1487 | return pPageData->mxPage.get(); | ||||||||
1488 | nTempLevel++; | ||||||||
1489 | } | ||||||||
1490 | |||||||||
1491 | return nullptr; | ||||||||
1492 | } | ||||||||
1493 | } // namespace svt | ||||||||
1494 | |||||||||
1495 | |||||||||
1496 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX |
21 | #define INCLUDED_RTL_REF_HXX |
22 | |
23 | #include "sal/config.h" |
24 | |
25 | #include <cassert> |
26 | #include <cstddef> |
27 | #include <functional> |
28 | #ifdef LIBO_INTERNAL_ONLY1 |
29 | #include <type_traits> |
30 | #endif |
31 | |
32 | #include "sal/types.h" |
33 | |
34 | namespace rtl |
35 | { |
36 | |
37 | /** Template reference class for reference type. |
38 | */ |
39 | template <class reference_type> |
40 | class Reference |
41 | { |
42 | /** The <b>reference_type</b> body pointer. |
43 | */ |
44 | reference_type * m_pBody; |
45 | |
46 | |
47 | public: |
48 | /** Constructor... |
49 | */ |
50 | Reference() |
51 | : m_pBody (NULL__null) |
52 | {} |
53 | |
54 | |
55 | /** Constructor... |
56 | */ |
57 | Reference (reference_type * pBody, __sal_NoAcquire) |
58 | : m_pBody (pBody) |
59 | { |
60 | } |
61 | |
62 | /** Constructor... |
63 | */ |
64 | Reference (reference_type * pBody) |
65 | : m_pBody (pBody) |
66 | { |
67 | if (m_pBody) |
68 | m_pBody->acquire(); |
69 | } |
70 | |
71 | /** Copy constructor... |
72 | */ |
73 | Reference (const Reference<reference_type> & handle) |
74 | : m_pBody (handle.m_pBody) |
75 | { |
76 | if (m_pBody) |
77 | m_pBody->acquire(); |
78 | } |
79 | |
80 | #ifdef LIBO_INTERNAL_ONLY1 |
81 | /** Move constructor... |
82 | */ |
83 | Reference (Reference<reference_type> && handle) noexcept |
84 | : m_pBody (handle.m_pBody) |
85 | { |
86 | handle.m_pBody = nullptr; |
87 | } |
88 | #endif |
89 | |
90 | #if defined LIBO_INTERNAL_ONLY1 |
91 | /** Up-casting conversion constructor: Copies interface reference. |
92 | |
93 | Does not work for up-casts to ambiguous bases. |
94 | |
95 | @param rRef another reference |
96 | */ |
97 | template< class derived_type > |
98 | inline Reference( |
99 | const Reference< derived_type > & rRef, |
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) |
101 | : m_pBody (rRef.get()) |
102 | { |
103 | if (m_pBody) |
104 | m_pBody->acquire(); |
105 | } |
106 | #endif |
107 | |
108 | /** Destructor... |
109 | */ |
110 | ~Reference() COVERITY_NOEXCEPT_FALSE |
111 | { |
112 | if (m_pBody) |
113 | m_pBody->release(); |
114 | } |
115 | |
116 | /** Set... |
117 | Similar to assignment. |
118 | */ |
119 | Reference<reference_type> & |
120 | SAL_CALL set (reference_type * pBody) |
121 | { |
122 | if (pBody) |
123 | pBody->acquire(); |
124 | reference_type * const pOld = m_pBody; |
125 | m_pBody = pBody; |
126 | if (pOld) |
127 | pOld->release(); |
128 | return *this; |
129 | } |
130 | |
131 | /** Assignment. |
132 | Unbinds this instance from its body (if bound) and |
133 | bind it to the body represented by the handle. |
134 | */ |
135 | Reference<reference_type> & |
136 | SAL_CALL operator= (const Reference<reference_type> & handle) |
137 | { |
138 | return set( handle.m_pBody ); |
139 | } |
140 | |
141 | #ifdef LIBO_INTERNAL_ONLY1 |
142 | /** Assignment. |
143 | * Unbinds this instance from its body (if bound), |
144 | * bind it to the body represented by the handle, and |
145 | * set the body represented by the handle to nullptr. |
146 | */ |
147 | Reference<reference_type> & |
148 | operator= (Reference<reference_type> && handle) |
149 | { |
150 | // self-movement guts ourself |
151 | if (m_pBody) |
152 | m_pBody->release(); |
153 | m_pBody = handle.m_pBody; |
154 | handle.m_pBody = nullptr; |
155 | return *this; |
156 | } |
157 | #endif |
158 | |
159 | /** Assignment... |
160 | */ |
161 | Reference<reference_type> & |
162 | SAL_CALL operator= (reference_type * pBody) |
163 | { |
164 | return set( pBody ); |
165 | } |
166 | |
167 | /** Unbind the body from this handle. |
168 | Note that for a handle representing a large body, |
169 | "handle.clear().set(new body());" _might_ |
170 | perform a little bit better than "handle.set(new body());", |
171 | since in the second case two large objects exist in memory |
172 | (the old body and the new body). |
173 | */ |
174 | Reference<reference_type> & SAL_CALL clear() |
175 | { |
176 | if (m_pBody) |
177 | { |
178 | reference_type * const pOld = m_pBody; |
179 | m_pBody = NULL__null; |
180 | pOld->release(); |
181 | } |
182 | return *this; |
183 | } |
184 | |
185 | |
186 | /** Get the body. Can be used instead of operator->(). |
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
188 | are the same. |
189 | */ |
190 | reference_type * SAL_CALL get() const |
191 | { |
192 | return m_pBody; |
193 | } |
194 | |
195 | |
196 | /** Probably most common used: handle->someBodyOp(). |
197 | */ |
198 | reference_type * SAL_CALL operator->() const |
199 | { |
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); |
201 | return m_pBody; |
202 | } |
203 | |
204 | |
205 | /** Allows (*handle).someBodyOp(). |
206 | */ |
207 | reference_type & SAL_CALL operator*() const |
208 | { |
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); |
210 | return *m_pBody; |
211 | } |
212 | |
213 | |
214 | /** Returns True if the handle does point to a valid body. |
215 | */ |
216 | bool SAL_CALL is() const |
217 | { |
218 | return (m_pBody != NULL__null); |
219 | } |
220 | |
221 | #if defined LIBO_INTERNAL_ONLY1 |
222 | /** Returns True if the handle does point to a valid body. |
223 | */ |
224 | explicit operator bool() const |
225 | { |
226 | return is(); |
227 | } |
228 | #endif |
229 | |
230 | /** Returns True if this points to pBody. |
231 | */ |
232 | bool SAL_CALL operator== (const reference_type * pBody) const |
233 | { |
234 | return (m_pBody == pBody); |
235 | } |
236 | |
237 | |
238 | /** Returns True if handle points to the same body. |
239 | */ |
240 | bool |
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const |
242 | { |
243 | return (m_pBody == handle.m_pBody); |
244 | } |
245 | |
246 | |
247 | /** Needed to place References into STL collection. |
248 | */ |
249 | bool |
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const |
251 | { |
252 | return (m_pBody != handle.m_pBody); |
253 | } |
254 | |
255 | |
256 | /** Needed to place References into STL collection. |
257 | */ |
258 | bool |
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const |
260 | { |
261 | return (m_pBody < handle.m_pBody); |
262 | } |
263 | |
264 | |
265 | /** Needed to place References into STL collection. |
266 | */ |
267 | bool |
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const |
269 | { |
270 | return (m_pBody > handle.m_pBody); |
271 | } |
272 | }; |
273 | |
274 | } // namespace rtl |
275 | |
276 | #if defined LIBO_INTERNAL_ONLY1 |
277 | namespace std |
278 | { |
279 | |
280 | /// @cond INTERNAL |
281 | /** |
282 | Make rtl::Reference hashable by default for use in STL containers. |
283 | |
284 | @since LibreOffice 6.3 |
285 | */ |
286 | template<typename T> |
287 | struct hash<::rtl::Reference<T>> |
288 | { |
289 | std::size_t operator()(::rtl::Reference<T> const & s) const |
290 | { return std::size_t(s.get()); } |
291 | }; |
292 | /// @endcond |
293 | |
294 | } |
295 | |
296 | #endif |
297 | |
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ |
299 | |
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |