File: | home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx |
Warning: | line 955, column 26 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 <memory> | ||||||||
21 | |||||||||
22 | #include <o3tl/safeint.hxx> | ||||||||
23 | #include <sal/config.h> | ||||||||
24 | #include <sal/log.hxx> | ||||||||
25 | |||||||||
26 | #include <vcl/accel.hxx> | ||||||||
27 | #include <vcl/layout.hxx> | ||||||||
28 | #include <vcl/settings.hxx> | ||||||||
29 | #include <vcl/svapp.hxx> | ||||||||
30 | #include <vcl/menu.hxx> | ||||||||
31 | #include <vcl/event.hxx> | ||||||||
32 | #include <vcl/syswin.hxx> | ||||||||
33 | #include <vcl/taskpanelist.hxx> | ||||||||
34 | #include <vcl/tabctrl.hxx> | ||||||||
35 | #include <vcl/tabpage.hxx> | ||||||||
36 | #include <vcl/virdev.hxx> | ||||||||
37 | |||||||||
38 | #include <rtl/strbuf.hxx> | ||||||||
39 | |||||||||
40 | #include <salframe.hxx> | ||||||||
41 | #include <svdata.hxx> | ||||||||
42 | #include <brdwin.hxx> | ||||||||
43 | #include <window.h> | ||||||||
44 | |||||||||
45 | using namespace ::com::sun::star::uno; | ||||||||
46 | using namespace ::com::sun::star::lang; | ||||||||
47 | |||||||||
48 | class SystemWindow::ImplData | ||||||||
49 | { | ||||||||
50 | public: | ||||||||
51 | ImplData(); | ||||||||
52 | |||||||||
53 | std::unique_ptr<TaskPaneList> | ||||||||
54 | mpTaskPaneList; | ||||||||
55 | Size maMaxOutSize; | ||||||||
56 | OUString maRepresentedURL; | ||||||||
57 | Link<SystemWindow&,void> maCloseHdl; | ||||||||
58 | }; | ||||||||
59 | |||||||||
60 | SystemWindow::ImplData::ImplData() | ||||||||
61 | { | ||||||||
62 | mpTaskPaneList = nullptr; | ||||||||
63 | maMaxOutSize = Size( SHRT_MAX32767, SHRT_MAX32767 ); | ||||||||
64 | } | ||||||||
65 | |||||||||
66 | SystemWindow::SystemWindow(WindowType nType) | ||||||||
67 | : Window(nType) | ||||||||
68 | , mbRollUp(false) | ||||||||
69 | , mbDockBtn(false) | ||||||||
70 | , mbHideBtn(false) | ||||||||
71 | , mbSysChild(false) | ||||||||
72 | , mbIsCalculatingInitialLayoutSize(false) | ||||||||
73 | , mbPaintComplete(false) | ||||||||
74 | , mnMenuBarMode(MenuBarMode::Normal) | ||||||||
75 | , mnIcon(0) | ||||||||
76 | , mpImplData(new ImplData) | ||||||||
77 | , mbIsDeferredInit(false) | ||||||||
78 | { | ||||||||
79 | mpWindowImpl->mbSysWin = true; | ||||||||
80 | mpWindowImpl->mnActivateMode = ActivateModeFlags::GrabFocus; | ||||||||
81 | |||||||||
82 | //To-Do, reuse maResizeTimer | ||||||||
83 | maLayoutIdle.SetPriority(TaskPriority::RESIZE); | ||||||||
84 | maLayoutIdle.SetInvokeHandler( LINK( this, SystemWindow, ImplHandleLayoutTimerHdl )::tools::detail::makeLink( ::tools::detail::castTo<SystemWindow *>(this), &SystemWindow::LinkStubImplHandleLayoutTimerHdl ) ); | ||||||||
85 | maLayoutIdle.SetDebugName( "vcl::SystemWindow maLayoutIdle" ); | ||||||||
86 | } | ||||||||
87 | |||||||||
88 | void SystemWindow::loadUI(vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription, | ||||||||
89 | const css::uno::Reference<css::frame::XFrame> &rFrame) | ||||||||
90 | { | ||||||||
91 | mbIsDeferredInit = true; | ||||||||
92 | mpDialogParent = pParent; //should be unset in doDeferredInit | ||||||||
93 | m_pUIBuilder.reset( new VclBuilder(this, AllSettings::GetUIRootDir(), rUIXMLDescription, rID, rFrame) ); | ||||||||
94 | } | ||||||||
95 | |||||||||
96 | SystemWindow::~SystemWindow() | ||||||||
97 | { | ||||||||
98 | disposeOnce(); | ||||||||
99 | } | ||||||||
100 | |||||||||
101 | void SystemWindow::dispose() | ||||||||
102 | { | ||||||||
103 | maLayoutIdle.Stop(); | ||||||||
104 | mpImplData.reset(); | ||||||||
105 | |||||||||
106 | // Hack to make sure code called from base ~Window does not interpret this | ||||||||
107 | // as a SystemWindow (which it no longer is by then): | ||||||||
108 | mpWindowImpl->mbSysWin = false; | ||||||||
109 | disposeBuilder(); | ||||||||
110 | mpDialogParent.clear(); | ||||||||
111 | mpMenuBar.clear(); | ||||||||
112 | Window::dispose(); | ||||||||
113 | } | ||||||||
114 | |||||||||
115 | static void ImplHandleControlAccelerator( const vcl::Window* pWindow, bool bShow ) | ||||||||
116 | { | ||||||||
117 | Control *pControl = dynamic_cast<Control*>(pWindow->ImplGetWindow()); | ||||||||
118 | if (pControl && pControl->GetText().indexOf('~') != -1) | ||||||||
119 | { | ||||||||
120 | pControl->SetShowAccelerator( bShow ); | ||||||||
121 | pControl->Invalidate(InvalidateFlags::Update); | ||||||||
122 | } | ||||||||
123 | } | ||||||||
124 | |||||||||
125 | namespace | ||||||||
126 | { | ||||||||
127 | void processChildren(const vcl::Window *pParent, bool bShowAccel) | ||||||||
128 | { | ||||||||
129 | // go through its children | ||||||||
130 | vcl::Window* pChild = firstLogicalChildOfParent(pParent); | ||||||||
131 | while (pChild) | ||||||||
132 | { | ||||||||
133 | if (pChild->GetType() == WindowType::TABCONTROL) | ||||||||
134 | { | ||||||||
135 | // find currently shown tab page | ||||||||
136 | TabControl* pTabControl = static_cast<TabControl*>(pChild); | ||||||||
137 | TabPage* pTabPage = pTabControl->GetTabPage( pTabControl->GetCurPageId() ); | ||||||||
138 | processChildren(pTabPage, bShowAccel); | ||||||||
139 | } | ||||||||
140 | else if (pChild->GetType() == WindowType::TABPAGE) | ||||||||
141 | { | ||||||||
142 | // bare tabpage without tabcontrol parent (options dialog) | ||||||||
143 | processChildren(pChild, bShowAccel); | ||||||||
144 | } | ||||||||
145 | else if ((pChild->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL) | ||||||||
146 | { | ||||||||
147 | // special controls that manage their children outside of widget layout | ||||||||
148 | processChildren(pChild, bShowAccel); | ||||||||
149 | } | ||||||||
150 | else | ||||||||
151 | { | ||||||||
152 | ImplHandleControlAccelerator(pChild, bShowAccel); | ||||||||
153 | } | ||||||||
154 | pChild = nextLogicalChildOfParent(pParent, pChild); | ||||||||
155 | } | ||||||||
156 | } | ||||||||
157 | } | ||||||||
158 | |||||||||
159 | bool Accelerator::ToggleMnemonicsOnHierarchy(const CommandEvent& rCEvent, const vcl::Window *pWindow) | ||||||||
160 | { | ||||||||
161 | if (rCEvent.GetCommand() == CommandEventId::ModKeyChange && ImplGetSVData()->maNWFData.mbAutoAccel) | ||||||||
162 | { | ||||||||
163 | const CommandModKeyData *pCData = rCEvent.GetModKeyData(); | ||||||||
164 | const bool bShowAccel = pCData && pCData->IsMod2() && pCData->IsDown(); | ||||||||
165 | processChildren(pWindow, bShowAccel); | ||||||||
166 | return true; | ||||||||
167 | } | ||||||||
168 | return false; | ||||||||
169 | } | ||||||||
170 | |||||||||
171 | bool SystemWindow::EventNotify( NotifyEvent& rNEvt ) | ||||||||
172 | { | ||||||||
173 | if (rNEvt.GetType() == MouseNotifyEvent::COMMAND) | ||||||||
174 | Accelerator::ToggleMnemonicsOnHierarchy(*rNEvt.GetCommandEvent(), this); | ||||||||
175 | |||||||||
176 | // capture KeyEvents for menu handling | ||||||||
177 | if (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT || | ||||||||
178 | rNEvt.GetType() == MouseNotifyEvent::COMMAND) | ||||||||
179 | { | ||||||||
180 | MenuBar* pMBar = mpMenuBar; | ||||||||
181 | if ( !pMBar && ( GetType() == WindowType::FLOATINGWINDOW ) ) | ||||||||
182 | { | ||||||||
183 | vcl::Window* pWin = ImplGetFrameWindow()->ImplGetWindow(); | ||||||||
184 | if( pWin && pWin->IsSystemWindow() ) | ||||||||
185 | pMBar = static_cast<SystemWindow*>(pWin)->GetMenuBar(); | ||||||||
186 | } | ||||||||
187 | bool bDone(false); | ||||||||
188 | if (pMBar) | ||||||||
189 | { | ||||||||
190 | if (rNEvt.GetType() == MouseNotifyEvent::COMMAND) | ||||||||
191 | bDone = pMBar->ImplHandleCmdEvent(*rNEvt.GetCommandEvent()); | ||||||||
192 | else | ||||||||
193 | bDone = pMBar->ImplHandleKeyEvent(*rNEvt.GetKeyEvent()); | ||||||||
194 | } | ||||||||
195 | if (bDone) | ||||||||
196 | return true; | ||||||||
197 | } | ||||||||
198 | |||||||||
199 | return Window::EventNotify( rNEvt ); | ||||||||
200 | } | ||||||||
201 | |||||||||
202 | bool SystemWindow::PreNotify( NotifyEvent& rNEvt ) | ||||||||
203 | { | ||||||||
204 | // capture KeyEvents for taskpane cycling | ||||||||
205 | if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT ) | ||||||||
206 | { | ||||||||
207 | if( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F6 && | ||||||||
208 | rNEvt.GetKeyEvent()->GetKeyCode().IsMod1() && | ||||||||
209 | !rNEvt.GetKeyEvent()->GetKeyCode().IsShift() ) | ||||||||
210 | { | ||||||||
211 | // Ctrl-F6 goes directly to the document | ||||||||
212 | GrabFocusToDocument(); | ||||||||
213 | return true; | ||||||||
214 | } | ||||||||
215 | else | ||||||||
216 | { | ||||||||
217 | TaskPaneList *pTList = mpImplData->mpTaskPaneList.get(); | ||||||||
218 | if( !pTList && ( GetType() == WindowType::FLOATINGWINDOW ) ) | ||||||||
219 | { | ||||||||
220 | vcl::Window* pWin = ImplGetFrameWindow()->ImplGetWindow(); | ||||||||
221 | if( pWin && pWin->IsSystemWindow() ) | ||||||||
222 | pTList = static_cast<SystemWindow*>(pWin)->mpImplData->mpTaskPaneList.get(); | ||||||||
223 | } | ||||||||
224 | if( !pTList ) | ||||||||
225 | { | ||||||||
226 | // search topmost system window which is the one to handle dialog/toolbar cycling | ||||||||
227 | SystemWindow *pSysWin = this; | ||||||||
228 | vcl::Window *pWin = this; | ||||||||
229 | while( pWin ) | ||||||||
230 | { | ||||||||
231 | pWin = pWin->GetParent(); | ||||||||
232 | if( pWin && pWin->IsSystemWindow() ) | ||||||||
233 | pSysWin = static_cast<SystemWindow*>(pWin); | ||||||||
234 | } | ||||||||
235 | pTList = pSysWin->mpImplData->mpTaskPaneList.get(); | ||||||||
236 | } | ||||||||
237 | if( pTList && pTList->HandleKeyEvent( *rNEvt.GetKeyEvent() ) ) | ||||||||
238 | return true; | ||||||||
239 | } | ||||||||
240 | } | ||||||||
241 | return Window::PreNotify( rNEvt ); | ||||||||
242 | } | ||||||||
243 | |||||||||
244 | TaskPaneList* SystemWindow::GetTaskPaneList() | ||||||||
245 | { | ||||||||
246 | if( !mpImplData ) | ||||||||
247 | return nullptr; | ||||||||
248 | if( mpImplData->mpTaskPaneList ) | ||||||||
249 | return mpImplData->mpTaskPaneList.get(); | ||||||||
250 | else | ||||||||
251 | { | ||||||||
252 | mpImplData->mpTaskPaneList.reset( new TaskPaneList ); | ||||||||
253 | MenuBar* pMBar = mpMenuBar; | ||||||||
254 | if ( !pMBar && ( GetType() == WindowType::FLOATINGWINDOW ) ) | ||||||||
255 | { | ||||||||
256 | vcl::Window* pWin = ImplGetFrameWindow()->ImplGetWindow(); | ||||||||
257 | if ( pWin && pWin->IsSystemWindow() ) | ||||||||
258 | pMBar = static_cast<SystemWindow*>(pWin)->GetMenuBar(); | ||||||||
259 | } | ||||||||
260 | if( pMBar ) | ||||||||
261 | mpImplData->mpTaskPaneList->AddWindow( pMBar->ImplGetWindow() ); | ||||||||
262 | return mpImplData->mpTaskPaneList.get(); | ||||||||
263 | } | ||||||||
264 | } | ||||||||
265 | |||||||||
266 | bool SystemWindow::Close() | ||||||||
267 | { | ||||||||
268 | VclPtr<vcl::Window> xWindow = this; | ||||||||
269 | CallEventListeners( VclEventId::WindowClose ); | ||||||||
270 | if ( xWindow->IsDisposed() ) | ||||||||
271 | return false; | ||||||||
272 | |||||||||
273 | if ( mpWindowImpl->mxWindowPeer.is() && IsCreatedWithToolkit() ) | ||||||||
274 | return false; | ||||||||
275 | |||||||||
276 | // Is Window not closeable, ignore close | ||||||||
277 | vcl::Window* pBorderWin = ImplGetBorderWindow(); | ||||||||
278 | WinBits nStyle; | ||||||||
279 | if ( pBorderWin ) | ||||||||
280 | nStyle = pBorderWin->GetStyle(); | ||||||||
281 | else | ||||||||
282 | nStyle = GetStyle(); | ||||||||
283 | if ( !(nStyle & WB_CLOSEABLE) ) | ||||||||
284 | return false; | ||||||||
285 | |||||||||
286 | Hide(); | ||||||||
287 | |||||||||
288 | return true; | ||||||||
289 | } | ||||||||
290 | |||||||||
291 | void SystemWindow::TitleButtonClick( TitleButton ) | ||||||||
292 | { | ||||||||
293 | } | ||||||||
294 | |||||||||
295 | void SystemWindow::Resizing( Size& ) | ||||||||
296 | { | ||||||||
297 | } | ||||||||
298 | |||||||||
299 | void SystemWindow::SetRepresentedURL( const OUString& i_rURL ) | ||||||||
300 | { | ||||||||
301 | bool bChanged = (i_rURL != mpImplData->maRepresentedURL); | ||||||||
302 | mpImplData->maRepresentedURL = i_rURL; | ||||||||
303 | if ( !mbSysChild && bChanged ) | ||||||||
304 | { | ||||||||
305 | const vcl::Window* pWindow = this; | ||||||||
306 | while ( pWindow->mpWindowImpl->mpBorderWindow ) | ||||||||
307 | pWindow = pWindow->mpWindowImpl->mpBorderWindow; | ||||||||
308 | |||||||||
309 | if ( pWindow->mpWindowImpl->mbFrame ) | ||||||||
310 | pWindow->mpWindowImpl->mpFrame->SetRepresentedURL( i_rURL ); | ||||||||
311 | } | ||||||||
312 | } | ||||||||
313 | |||||||||
314 | void SystemWindow::SetIcon( sal_uInt16 nIcon ) | ||||||||
315 | { | ||||||||
316 | if ( mnIcon == nIcon ) | ||||||||
317 | return; | ||||||||
318 | |||||||||
319 | mnIcon = nIcon; | ||||||||
320 | |||||||||
321 | if ( !mbSysChild ) | ||||||||
322 | { | ||||||||
323 | const vcl::Window* pWindow = this; | ||||||||
324 | while ( pWindow->mpWindowImpl->mpBorderWindow ) | ||||||||
325 | pWindow = pWindow->mpWindowImpl->mpBorderWindow; | ||||||||
326 | |||||||||
327 | if ( pWindow->mpWindowImpl->mbFrame ) | ||||||||
328 | pWindow->mpWindowImpl->mpFrame->SetIcon( nIcon ); | ||||||||
329 | } | ||||||||
330 | } | ||||||||
331 | |||||||||
332 | void SystemWindow::ShowTitleButton( TitleButton nButton, bool bVisible ) | ||||||||
333 | { | ||||||||
334 | if ( nButton == TitleButton::Docking ) | ||||||||
335 | { | ||||||||
336 | if ( mbDockBtn != bVisible ) | ||||||||
337 | { | ||||||||
338 | mbDockBtn = bVisible; | ||||||||
339 | if ( mpWindowImpl->mpBorderWindow ) | ||||||||
340 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetDockButton( bVisible ); | ||||||||
341 | } | ||||||||
342 | } | ||||||||
343 | else if ( nButton == TitleButton::Hide ) | ||||||||
344 | { | ||||||||
345 | if ( mbHideBtn != bVisible ) | ||||||||
346 | { | ||||||||
347 | mbHideBtn = bVisible; | ||||||||
348 | if ( mpWindowImpl->mpBorderWindow ) | ||||||||
349 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetHideButton( bVisible ); | ||||||||
350 | } | ||||||||
351 | } | ||||||||
352 | else if ( nButton == TitleButton::Menu ) | ||||||||
353 | { | ||||||||
354 | if ( mpWindowImpl->mpBorderWindow ) | ||||||||
355 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuButton( bVisible ); | ||||||||
356 | } | ||||||||
357 | else | ||||||||
358 | return; | ||||||||
359 | } | ||||||||
360 | |||||||||
361 | bool SystemWindow::IsTitleButtonVisible( TitleButton nButton ) const | ||||||||
362 | { | ||||||||
363 | if ( nButton == TitleButton::Docking ) | ||||||||
364 | return mbDockBtn; | ||||||||
365 | else /* if ( nButton == TitleButton::Hide ) */ | ||||||||
366 | return mbHideBtn; | ||||||||
367 | } | ||||||||
368 | |||||||||
369 | void SystemWindow::RollUp() | ||||||||
370 | { | ||||||||
371 | if ( !mbRollUp ) | ||||||||
372 | { | ||||||||
373 | maOrgSize = GetOutputSizePixel(); | ||||||||
374 | Size aSize = maRollUpOutSize; | ||||||||
375 | if ( !aSize.Width() ) | ||||||||
376 | aSize.setWidth( GetOutputSizePixel().Width() ); | ||||||||
377 | mbRollUp = true; | ||||||||
378 | if ( mpWindowImpl->mpBorderWindow ) | ||||||||
379 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetRollUp( true, aSize ); | ||||||||
380 | else | ||||||||
381 | SetOutputSizePixel( aSize ); | ||||||||
382 | } | ||||||||
383 | } | ||||||||
384 | |||||||||
385 | void SystemWindow::RollDown() | ||||||||
386 | { | ||||||||
387 | if ( mbRollUp ) | ||||||||
388 | { | ||||||||
389 | mbRollUp = false; | ||||||||
390 | if ( mpWindowImpl->mpBorderWindow ) | ||||||||
391 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetRollUp( false, maOrgSize ); | ||||||||
392 | else | ||||||||
393 | SetOutputSizePixel( maOrgSize ); | ||||||||
394 | } | ||||||||
395 | } | ||||||||
396 | |||||||||
397 | void SystemWindow::SetMinOutputSizePixel( const Size& rSize ) | ||||||||
398 | { | ||||||||
399 | maMinOutSize = rSize; | ||||||||
400 | if ( mpWindowImpl->mpBorderWindow ) | ||||||||
401 | { | ||||||||
402 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMinOutputSize( rSize.Width(), rSize.Height() ); | ||||||||
403 | if ( mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame ) | ||||||||
404 | mpWindowImpl->mpBorderWindow->mpWindowImpl->mpFrame->SetMinClientSize( rSize.Width(), rSize.Height() ); | ||||||||
405 | } | ||||||||
406 | else if ( mpWindowImpl->mbFrame ) | ||||||||
407 | mpWindowImpl->mpFrame->SetMinClientSize( rSize.Width(), rSize.Height() ); | ||||||||
408 | } | ||||||||
409 | |||||||||
410 | void SystemWindow::SetMaxOutputSizePixel( const Size& rSize ) | ||||||||
411 | { | ||||||||
412 | Size aSize( rSize ); | ||||||||
413 | if( aSize.Width() > SHRT_MAX32767 || aSize.Width() <= 0 ) | ||||||||
414 | aSize.setWidth( SHRT_MAX32767 ); | ||||||||
415 | if( aSize.Height() > SHRT_MAX32767 || aSize.Height() <= 0 ) | ||||||||
416 | aSize.setHeight( SHRT_MAX32767 ); | ||||||||
417 | |||||||||
418 | mpImplData->maMaxOutSize = aSize; | ||||||||
419 | if ( mpWindowImpl->mpBorderWindow ) | ||||||||
420 | { | ||||||||
421 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMaxOutputSize( aSize.Width(), aSize.Height() ); | ||||||||
422 | if ( mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame ) | ||||||||
423 | mpWindowImpl->mpBorderWindow->mpWindowImpl->mpFrame->SetMaxClientSize( aSize.Width(), aSize.Height() ); | ||||||||
424 | } | ||||||||
425 | else if ( mpWindowImpl->mbFrame ) | ||||||||
426 | mpWindowImpl->mpFrame->SetMaxClientSize( aSize.Width(), aSize.Height() ); | ||||||||
427 | } | ||||||||
428 | |||||||||
429 | const Size& SystemWindow::GetMaxOutputSizePixel() const | ||||||||
430 | { | ||||||||
431 | return mpImplData->maMaxOutSize; | ||||||||
432 | } | ||||||||
433 | |||||||||
434 | void ImplWindowStateFromStr(WindowStateData& rData, | ||||||||
435 | const OString& rStr) | ||||||||
436 | { | ||||||||
437 | WindowStateMask nValidMask = WindowStateMask::NONE; | ||||||||
438 | sal_Int32 nIndex = 0; | ||||||||
439 | |||||||||
440 | OString aTokenStr = rStr.getToken(0, ',', nIndex); | ||||||||
441 | if (!aTokenStr.isEmpty()) | ||||||||
442 | { | ||||||||
443 | rData.SetX(aTokenStr.toInt32()); | ||||||||
444 | if( rData.GetX() > -16384 && rData.GetX() < 16384 ) | ||||||||
445 | nValidMask |= WindowStateMask::X; | ||||||||
446 | else | ||||||||
447 | rData.SetX( 0 ); | ||||||||
448 | } | ||||||||
449 | else | ||||||||
450 | rData.SetX( 0 ); | ||||||||
451 | aTokenStr = rStr.getToken(0, ',', nIndex); | ||||||||
452 | if (!aTokenStr.isEmpty()) | ||||||||
453 | { | ||||||||
454 | rData.SetY(aTokenStr.toInt32()); | ||||||||
455 | if( rData.GetY() > -16384 && rData.GetY() < 16384 ) | ||||||||
456 | nValidMask |= WindowStateMask::Y; | ||||||||
457 | else | ||||||||
458 | rData.SetY( 0 ); | ||||||||
459 | } | ||||||||
460 | else | ||||||||
461 | rData.SetY( 0 ); | ||||||||
462 | aTokenStr = rStr.getToken(0, ',', nIndex); | ||||||||
463 | if (!aTokenStr.isEmpty()) | ||||||||
464 | { | ||||||||
465 | rData.SetWidth(aTokenStr.toInt32()); | ||||||||
466 | if( rData.GetWidth() > 0 && rData.GetWidth() < 16384 ) | ||||||||
467 | nValidMask |= WindowStateMask::Width; | ||||||||
468 | else | ||||||||
469 | rData.SetWidth( 0 ); | ||||||||
470 | } | ||||||||
471 | else | ||||||||
472 | rData.SetWidth( 0 ); | ||||||||
473 | aTokenStr = rStr.getToken(0, ';', nIndex); | ||||||||
474 | if (!aTokenStr.isEmpty()) | ||||||||
475 | { | ||||||||
476 | rData.SetHeight(aTokenStr.toInt32()); | ||||||||
477 | if( rData.GetHeight() > 0 && rData.GetHeight() < 16384 ) | ||||||||
478 | nValidMask |= WindowStateMask::Height; | ||||||||
479 | else | ||||||||
480 | rData.SetHeight( 0 ); | ||||||||
481 | } | ||||||||
482 | else | ||||||||
483 | rData.SetHeight( 0 ); | ||||||||
484 | aTokenStr = rStr.getToken(0, ';', nIndex); | ||||||||
485 | if (!aTokenStr.isEmpty()) | ||||||||
486 | { | ||||||||
487 | // #94144# allow Minimize again, should be masked out when read from configuration | ||||||||
488 | // 91625 - ignore Minimize | ||||||||
489 | WindowStateState nState = static_cast<WindowStateState>(aTokenStr.toInt32()); | ||||||||
490 | //nState &= ~(WindowStateState::Minimized); | ||||||||
491 | rData.SetState( nState ); | ||||||||
492 | nValidMask |= WindowStateMask::State; | ||||||||
493 | } | ||||||||
494 | else | ||||||||
495 | rData.SetState( WindowStateState::NONE ); | ||||||||
496 | |||||||||
497 | // read maximized pos/size | ||||||||
498 | aTokenStr = rStr.getToken(0, ',', nIndex); | ||||||||
499 | if (!aTokenStr.isEmpty()) | ||||||||
500 | { | ||||||||
501 | rData.SetMaximizedX(aTokenStr.toInt32()); | ||||||||
502 | if( rData.GetMaximizedX() > -16384 && rData.GetMaximizedX() < 16384 ) | ||||||||
503 | nValidMask |= WindowStateMask::MaximizedX; | ||||||||
504 | else | ||||||||
505 | rData.SetMaximizedX( 0 ); | ||||||||
506 | } | ||||||||
507 | else | ||||||||
508 | rData.SetMaximizedX( 0 ); | ||||||||
509 | aTokenStr = rStr.getToken(0, ',', nIndex); | ||||||||
510 | if (!aTokenStr.isEmpty()) | ||||||||
511 | { | ||||||||
512 | rData.SetMaximizedY(aTokenStr.toInt32()); | ||||||||
513 | if( rData.GetMaximizedY() > -16384 && rData.GetMaximizedY() < 16384 ) | ||||||||
514 | nValidMask |= WindowStateMask::MaximizedY; | ||||||||
515 | else | ||||||||
516 | rData.SetMaximizedY( 0 ); | ||||||||
517 | } | ||||||||
518 | else | ||||||||
519 | rData.SetMaximizedY( 0 ); | ||||||||
520 | aTokenStr = rStr.getToken(0, ',', nIndex); | ||||||||
521 | if (!aTokenStr.isEmpty()) | ||||||||
522 | { | ||||||||
523 | rData.SetMaximizedWidth(aTokenStr.toInt32()); | ||||||||
524 | if( rData.GetMaximizedWidth() > 0 && rData.GetMaximizedWidth() < 16384 ) | ||||||||
525 | nValidMask |= WindowStateMask::MaximizedWidth; | ||||||||
526 | else | ||||||||
527 | rData.SetMaximizedWidth( 0 ); | ||||||||
528 | } | ||||||||
529 | else | ||||||||
530 | rData.SetMaximizedWidth( 0 ); | ||||||||
531 | aTokenStr = rStr.getToken(0, ';', nIndex); | ||||||||
532 | if (!aTokenStr.isEmpty()) | ||||||||
533 | { | ||||||||
534 | rData.SetMaximizedHeight(aTokenStr.toInt32()); | ||||||||
535 | if( rData.GetMaximizedHeight() > 0 && rData.GetMaximizedHeight() < 16384 ) | ||||||||
536 | nValidMask |= WindowStateMask::MaximizedHeight; | ||||||||
537 | else | ||||||||
538 | rData.SetMaximizedHeight( 0 ); | ||||||||
539 | } | ||||||||
540 | else | ||||||||
541 | rData.SetMaximizedHeight( 0 ); | ||||||||
542 | |||||||||
543 | // mark valid fields | ||||||||
544 | rData.SetMask( nValidMask ); | ||||||||
545 | } | ||||||||
546 | |||||||||
547 | OString WindowStateData::ToStr() const | ||||||||
548 | { | ||||||||
549 | const WindowStateMask nValidMask = GetMask(); | ||||||||
550 | if ( nValidMask == WindowStateMask::NONE ) | ||||||||
551 | return OString(); | ||||||||
552 | |||||||||
553 | OStringBuffer rStrBuf(64); | ||||||||
554 | |||||||||
555 | if ( nValidMask & WindowStateMask::X ) | ||||||||
556 | rStrBuf.append(static_cast<sal_Int32>(GetX())); | ||||||||
557 | rStrBuf.append(','); | ||||||||
558 | if ( nValidMask & WindowStateMask::Y ) | ||||||||
559 | rStrBuf.append(static_cast<sal_Int32>(GetY())); | ||||||||
560 | rStrBuf.append(','); | ||||||||
561 | if ( nValidMask & WindowStateMask::Width ) | ||||||||
562 | rStrBuf.append(static_cast<sal_Int32>(GetWidth())); | ||||||||
563 | rStrBuf.append(','); | ||||||||
564 | if ( nValidMask & WindowStateMask::Height ) | ||||||||
565 | rStrBuf.append(static_cast<sal_Int32>(GetHeight())); | ||||||||
566 | rStrBuf.append( ';' ); | ||||||||
567 | if ( nValidMask & WindowStateMask::State ) | ||||||||
568 | { | ||||||||
569 | // #94144# allow Minimize again, should be masked out when read from configuration | ||||||||
570 | // 91625 - ignore Minimize | ||||||||
571 | WindowStateState nState = GetState(); | ||||||||
572 | rStrBuf.append(static_cast<sal_Int32>(nState)); | ||||||||
573 | } | ||||||||
574 | rStrBuf.append(';'); | ||||||||
575 | if ( nValidMask & WindowStateMask::MaximizedX ) | ||||||||
576 | rStrBuf.append(static_cast<sal_Int32>(GetMaximizedX())); | ||||||||
577 | rStrBuf.append(','); | ||||||||
578 | if ( nValidMask & WindowStateMask::MaximizedY ) | ||||||||
579 | rStrBuf.append(static_cast<sal_Int32>(GetMaximizedY())); | ||||||||
580 | rStrBuf.append( ',' ); | ||||||||
581 | if ( nValidMask & WindowStateMask::MaximizedWidth ) | ||||||||
582 | rStrBuf.append(static_cast<sal_Int32>(GetMaximizedWidth())); | ||||||||
583 | rStrBuf.append(','); | ||||||||
584 | if ( nValidMask & WindowStateMask::MaximizedHeight ) | ||||||||
585 | rStrBuf.append(static_cast<sal_Int32>(GetMaximizedHeight())); | ||||||||
586 | rStrBuf.append(';'); | ||||||||
587 | |||||||||
588 | return rStrBuf.makeStringAndClear(); | ||||||||
589 | } | ||||||||
590 | |||||||||
591 | void SystemWindow::ImplMoveToScreen( long& io_rX, long& io_rY, long i_nWidth, long i_nHeight, vcl::Window const * i_pConfigureWin ) | ||||||||
592 | { | ||||||||
593 | tools::Rectangle aScreenRect; | ||||||||
594 | if( !Application::IsUnifiedDisplay() ) | ||||||||
595 | aScreenRect = Application::GetScreenPosSizePixel( GetScreenNumber() ); | ||||||||
596 | else | ||||||||
597 | { | ||||||||
598 | aScreenRect = Application::GetScreenPosSizePixel( 0 ); | ||||||||
599 | for( unsigned int i = 1; i < Application::GetScreenCount(); i++ ) | ||||||||
600 | aScreenRect.Union( Application::GetScreenPosSizePixel( i ) ); | ||||||||
601 | } | ||||||||
602 | // unfortunately most of the time width and height are not really known | ||||||||
603 | if( i_nWidth < 1 ) | ||||||||
604 | i_nWidth = 50; | ||||||||
605 | if( i_nHeight < 1 ) | ||||||||
606 | i_nHeight = 50; | ||||||||
607 | |||||||||
608 | // check left border | ||||||||
609 | bool bMove = false; | ||||||||
610 | if( io_rX + i_nWidth < aScreenRect.Left() ) | ||||||||
611 | { | ||||||||
612 | bMove = true; | ||||||||
613 | io_rX = aScreenRect.Left(); | ||||||||
614 | } | ||||||||
615 | // check right border | ||||||||
616 | if( io_rX > aScreenRect.Right() - i_nWidth ) | ||||||||
617 | { | ||||||||
618 | bMove = true; | ||||||||
619 | io_rX = aScreenRect.Right() - i_nWidth; | ||||||||
620 | } | ||||||||
621 | // check top border | ||||||||
622 | if( io_rY + i_nHeight < aScreenRect.Top() ) | ||||||||
623 | { | ||||||||
624 | bMove = true; | ||||||||
625 | io_rY = aScreenRect.Top(); | ||||||||
626 | } | ||||||||
627 | // check bottom border | ||||||||
628 | if( io_rY > aScreenRect.Bottom() - i_nHeight ) | ||||||||
629 | { | ||||||||
630 | bMove = true; | ||||||||
631 | io_rY = aScreenRect.Bottom() - i_nHeight; | ||||||||
632 | } | ||||||||
633 | vcl::Window* pParent = i_pConfigureWin->GetParent(); | ||||||||
634 | if( bMove && pParent ) | ||||||||
635 | { | ||||||||
636 | // calculate absolute screen pos here, since that is what is contained in WindowState | ||||||||
637 | Point aParentAbsPos( pParent->OutputToAbsoluteScreenPixel( Point(0,0) ) ); | ||||||||
638 | Size aParentSizePixel( pParent->GetOutputSizePixel() ); | ||||||||
639 | Point aPos( (aParentSizePixel.Width() - i_nWidth) / 2, | ||||||||
640 | (aParentSizePixel.Height() - i_nHeight) / 2 ); | ||||||||
641 | io_rX = aParentAbsPos.X() + aPos.X(); | ||||||||
642 | io_rY = aParentAbsPos.Y() + aPos.Y(); | ||||||||
643 | } | ||||||||
644 | } | ||||||||
645 | |||||||||
646 | void SystemWindow::SetWindowStateData( const WindowStateData& rData ) | ||||||||
647 | { | ||||||||
648 | const WindowStateMask nValidMask = rData.GetMask(); | ||||||||
649 | if ( nValidMask == WindowStateMask::NONE ) | ||||||||
650 | return; | ||||||||
651 | |||||||||
652 | if ( mbSysChild ) | ||||||||
653 | return; | ||||||||
654 | |||||||||
655 | vcl::Window* pWindow = this; | ||||||||
656 | while ( pWindow->mpWindowImpl->mpBorderWindow ) | ||||||||
657 | pWindow = pWindow->mpWindowImpl->mpBorderWindow; | ||||||||
658 | |||||||||
659 | if ( pWindow->mpWindowImpl->mbFrame ) | ||||||||
660 | { | ||||||||
661 | const WindowStateState nState = rData.GetState(); | ||||||||
662 | SalFrameState aState; | ||||||||
663 | aState.mnMask = rData.GetMask(); | ||||||||
664 | aState.mnX = rData.GetX(); | ||||||||
665 | aState.mnY = rData.GetY(); | ||||||||
666 | aState.mnWidth = rData.GetWidth(); | ||||||||
667 | aState.mnHeight = rData.GetHeight(); | ||||||||
668 | |||||||||
669 | if( rData.GetMask() & (WindowStateMask::Width|WindowStateMask::Height) ) | ||||||||
670 | { | ||||||||
671 | // #i43799# adjust window state sizes if a minimal output size was set | ||||||||
672 | // otherwise the frame and the client might get different sizes | ||||||||
673 | if( maMinOutSize.Width() > aState.mnWidth ) | ||||||||
674 | aState.mnWidth = maMinOutSize.Width(); | ||||||||
675 | if( maMinOutSize.Height() > aState.mnHeight ) | ||||||||
676 | aState.mnHeight = maMinOutSize.Height(); | ||||||||
677 | } | ||||||||
678 | |||||||||
679 | aState.mnMaximizedX = rData.GetMaximizedX(); | ||||||||
680 | aState.mnMaximizedY = rData.GetMaximizedY(); | ||||||||
681 | aState.mnMaximizedWidth = rData.GetMaximizedWidth(); | ||||||||
682 | aState.mnMaximizedHeight = rData.GetMaximizedHeight(); | ||||||||
683 | // #94144# allow Minimize again, should be masked out when read from configuration | ||||||||
684 | // 91625 - ignore Minimize | ||||||||
685 | //nState &= ~(WindowStateState::Minimized); | ||||||||
686 | aState.mnState = nState & WindowStateState::SystemMask; | ||||||||
687 | |||||||||
688 | // normalize window positions onto screen | ||||||||
689 | ImplMoveToScreen( aState.mnX, aState.mnY, aState.mnWidth, aState.mnHeight, pWindow ); | ||||||||
690 | ImplMoveToScreen( aState.mnMaximizedX, aState.mnMaximizedY, aState.mnMaximizedWidth, aState.mnMaximizedHeight, pWindow ); | ||||||||
691 | |||||||||
692 | // #96568# avoid having multiple frames at the same screen location | ||||||||
693 | // do the check only if not maximized | ||||||||
694 | if( !((rData.GetMask() & WindowStateMask::State) && (nState & WindowStateState::Maximized)) ) | ||||||||
695 | if( rData.GetMask() & (WindowStateMask::Pos|WindowStateMask::Width|WindowStateMask::Height) ) | ||||||||
696 | { | ||||||||
697 | tools::Rectangle aDesktop = GetDesktopRectPixel(); | ||||||||
698 | ImplSVData *pSVData = ImplGetSVData(); | ||||||||
699 | vcl::Window *pWin = pSVData->maFrameData.mpFirstFrame; | ||||||||
700 | bool bWrapped = false; | ||||||||
701 | while( pWin ) | ||||||||
702 | { | ||||||||
703 | if( !pWin->ImplIsRealParentPath( this ) && ( pWin != this ) && | ||||||||
704 | pWin->ImplGetWindow()->IsTopWindow() && pWin->mpWindowImpl->mbReallyVisible ) | ||||||||
705 | { | ||||||||
706 | SalFrameGeometry g = pWin->mpWindowImpl->mpFrame->GetGeometry(); | ||||||||
707 | if( std::abs(g.nX-aState.mnX) < 2 && std::abs(g.nY-aState.mnY) < 5 ) | ||||||||
708 | { | ||||||||
709 | long displacement = g.nTopDecoration ? g.nTopDecoration : 20; | ||||||||
710 | if( aState.mnX + displacement + aState.mnWidth + g.nRightDecoration > o3tl::make_unsigned(aDesktop.Right()) || | ||||||||
711 | aState.mnY + displacement + aState.mnHeight + g.nBottomDecoration > o3tl::make_unsigned(aDesktop.Bottom()) ) | ||||||||
712 | { | ||||||||
713 | // displacing would leave screen | ||||||||
714 | aState.mnX = g.nLeftDecoration ? g.nLeftDecoration : 10; // should result in (0,0) | ||||||||
715 | aState.mnY = displacement; | ||||||||
716 | if( bWrapped || | ||||||||
717 | aState.mnX + displacement + aState.mnWidth + g.nRightDecoration > o3tl::make_unsigned(aDesktop.Right()) || | ||||||||
718 | aState.mnY + displacement + aState.mnHeight + g.nBottomDecoration > o3tl::make_unsigned(aDesktop.Bottom()) ) | ||||||||
719 | break; // further displacement not possible -> break | ||||||||
720 | // avoid endless testing | ||||||||
721 | bWrapped = true; | ||||||||
722 | } | ||||||||
723 | else | ||||||||
724 | { | ||||||||
725 | // displace | ||||||||
726 | aState.mnX += displacement; | ||||||||
727 | aState.mnY += displacement; | ||||||||
728 | } | ||||||||
729 | pWin = pSVData->maFrameData.mpFirstFrame; // check new pos again | ||||||||
730 | } | ||||||||
731 | } | ||||||||
732 | pWin = pWin->mpWindowImpl->mpFrameData->mpNextFrame; | ||||||||
733 | } | ||||||||
734 | } | ||||||||
735 | |||||||||
736 | mpWindowImpl->mpFrame->SetWindowState( &aState ); | ||||||||
737 | |||||||||
738 | // do a synchronous resize for layout reasons | ||||||||
739 | // but use rData only when the window is not to be maximized (#i38089#) | ||||||||
740 | // otherwise we have no useful size information | ||||||||
741 | if( (rData.GetMask() & WindowStateMask::State) && (nState & WindowStateState::Maximized) ) | ||||||||
742 | { | ||||||||
743 | // query maximized size from frame | ||||||||
744 | SalFrameGeometry aGeometry = mpWindowImpl->mpFrame->GetGeometry(); | ||||||||
745 | |||||||||
746 | // but use it only if it is different from the restore size (rData) | ||||||||
747 | // as currently only on windows the exact size of a maximized window | ||||||||
748 | // can be computed without actually showing the window | ||||||||
749 | if( aGeometry.nWidth != rData.GetWidth() || aGeometry.nHeight != rData.GetHeight() ) | ||||||||
750 | ImplHandleResize( pWindow, aGeometry.nWidth, aGeometry.nHeight ); | ||||||||
751 | } | ||||||||
752 | else | ||||||||
753 | if( rData.GetMask() & (WindowStateMask::Width|WindowStateMask::Height) ) | ||||||||
754 | ImplHandleResize( pWindow, aState.mnWidth, aState.mnHeight ); // #i43799# use aState and not rData, see above | ||||||||
755 | } | ||||||||
756 | else | ||||||||
757 | { | ||||||||
758 | PosSizeFlags nPosSize = PosSizeFlags::NONE; | ||||||||
759 | if ( nValidMask & WindowStateMask::X ) | ||||||||
760 | nPosSize |= PosSizeFlags::X; | ||||||||
761 | if ( nValidMask & WindowStateMask::Y ) | ||||||||
762 | nPosSize |= PosSizeFlags::Y; | ||||||||
763 | if ( nValidMask & WindowStateMask::Width ) | ||||||||
764 | nPosSize |= PosSizeFlags::Width; | ||||||||
765 | if ( nValidMask & WindowStateMask::Height ) | ||||||||
766 | nPosSize |= PosSizeFlags::Height; | ||||||||
767 | |||||||||
768 | if( IsRollUp() ) | ||||||||
769 | RollDown(); | ||||||||
770 | |||||||||
771 | long nX = rData.GetX(); | ||||||||
772 | long nY = rData.GetY(); | ||||||||
773 | long nWidth = rData.GetWidth(); | ||||||||
774 | long nHeight = rData.GetHeight(); | ||||||||
775 | const SalFrameGeometry& rGeom = pWindow->mpWindowImpl->mpFrame->GetGeometry(); | ||||||||
776 | if( nX < 0 ) | ||||||||
777 | nX = 0; | ||||||||
778 | if( nX + nWidth > static_cast<long>(rGeom.nWidth) ) | ||||||||
779 | nX = rGeom.nWidth - nWidth; | ||||||||
780 | if( nY < 0 ) | ||||||||
781 | nY = 0; | ||||||||
782 | if( nY + nHeight > static_cast<long>(rGeom.nHeight) ) | ||||||||
783 | nY = rGeom.nHeight - nHeight; | ||||||||
784 | setPosSizePixel( nX, nY, nWidth, nHeight, nPosSize ); | ||||||||
785 | maOrgSize = Size( nWidth, nHeight ); | ||||||||
786 | |||||||||
787 | // 91625 - ignore Minimize | ||||||||
788 | if ( nValidMask & WindowStateMask::State ) | ||||||||
789 | { | ||||||||
790 | const WindowStateState nState = rData.GetState(); | ||||||||
791 | if ( nState & WindowStateState::Rollup ) | ||||||||
792 | RollUp(); | ||||||||
793 | else | ||||||||
794 | RollDown(); | ||||||||
795 | } | ||||||||
796 | } | ||||||||
797 | } | ||||||||
798 | |||||||||
799 | void SystemWindow::GetWindowStateData( WindowStateData& rData ) const | ||||||||
800 | { | ||||||||
801 | WindowStateMask nValidMask = rData.GetMask(); | ||||||||
802 | if ( nValidMask == WindowStateMask::NONE ) | ||||||||
803 | return; | ||||||||
804 | |||||||||
805 | if ( mbSysChild ) | ||||||||
806 | return; | ||||||||
807 | |||||||||
808 | const vcl::Window* pWindow = this; | ||||||||
809 | while ( pWindow->mpWindowImpl->mpBorderWindow ) | ||||||||
810 | pWindow = pWindow->mpWindowImpl->mpBorderWindow; | ||||||||
811 | |||||||||
812 | if ( pWindow->mpWindowImpl->mbFrame ) | ||||||||
813 | { | ||||||||
814 | SalFrameState aState; | ||||||||
815 | aState.mnMask = WindowStateMask::All; | ||||||||
816 | if ( mpWindowImpl->mpFrame->GetWindowState( &aState ) ) | ||||||||
817 | { | ||||||||
818 | if ( nValidMask & WindowStateMask::X ) | ||||||||
819 | rData.SetX( aState.mnX ); | ||||||||
820 | if ( nValidMask & WindowStateMask::Y ) | ||||||||
821 | rData.SetY( aState.mnY ); | ||||||||
822 | if ( nValidMask & WindowStateMask::Width ) | ||||||||
823 | rData.SetWidth( aState.mnWidth ); | ||||||||
824 | if ( nValidMask & WindowStateMask::Height ) | ||||||||
825 | rData.SetHeight( aState.mnHeight ); | ||||||||
826 | if ( aState.mnMask & WindowStateMask::MaximizedX ) | ||||||||
827 | { | ||||||||
828 | rData.SetMaximizedX( aState.mnMaximizedX ); | ||||||||
829 | nValidMask |= WindowStateMask::MaximizedX; | ||||||||
830 | } | ||||||||
831 | if ( aState.mnMask & WindowStateMask::MaximizedY ) | ||||||||
832 | { | ||||||||
833 | rData.SetMaximizedY( aState.mnMaximizedY ); | ||||||||
834 | nValidMask |= WindowStateMask::MaximizedY; | ||||||||
835 | } | ||||||||
836 | if ( aState.mnMask & WindowStateMask::MaximizedWidth ) | ||||||||
837 | { | ||||||||
838 | rData.SetMaximizedWidth( aState.mnMaximizedWidth ); | ||||||||
839 | nValidMask |= WindowStateMask::MaximizedWidth; | ||||||||
840 | } | ||||||||
841 | if ( aState.mnMask & WindowStateMask::MaximizedHeight ) | ||||||||
842 | { | ||||||||
843 | rData.SetMaximizedHeight( aState.mnMaximizedHeight ); | ||||||||
844 | nValidMask |= WindowStateMask::MaximizedHeight; | ||||||||
845 | } | ||||||||
846 | if ( nValidMask & WindowStateMask::State ) | ||||||||
847 | { | ||||||||
848 | // #94144# allow Minimize again, should be masked out when read from configuration | ||||||||
849 | // 91625 - ignore Minimize | ||||||||
850 | if ( !(nValidMask&WindowStateMask::Minimized) ) | ||||||||
851 | aState.mnState &= ~WindowStateState::Minimized; | ||||||||
852 | rData.SetState( aState.mnState ); | ||||||||
853 | } | ||||||||
854 | rData.SetMask( nValidMask ); | ||||||||
855 | } | ||||||||
856 | else | ||||||||
857 | rData.SetMask( WindowStateMask::NONE ); | ||||||||
858 | } | ||||||||
859 | else | ||||||||
860 | { | ||||||||
861 | Point aPos = GetPosPixel(); | ||||||||
862 | Size aSize = GetSizePixel(); | ||||||||
863 | WindowStateState nState = WindowStateState::NONE; | ||||||||
864 | |||||||||
865 | if ( IsRollUp() ) | ||||||||
866 | { | ||||||||
867 | aSize.AdjustHeight(maOrgSize.Height() ); | ||||||||
868 | nState = WindowStateState::Rollup; | ||||||||
869 | } | ||||||||
870 | |||||||||
871 | if ( nValidMask & WindowStateMask::X ) | ||||||||
872 | rData.SetX( aPos.X() ); | ||||||||
873 | if ( nValidMask & WindowStateMask::Y ) | ||||||||
874 | rData.SetY( aPos.Y() ); | ||||||||
875 | if ( nValidMask & WindowStateMask::Width ) | ||||||||
876 | rData.SetWidth( aSize.Width() ); | ||||||||
877 | if ( nValidMask & WindowStateMask::Height ) | ||||||||
878 | rData.SetHeight( aSize.Height() ); | ||||||||
879 | if ( nValidMask & WindowStateMask::State ) | ||||||||
880 | rData.SetState( nState ); | ||||||||
881 | } | ||||||||
882 | } | ||||||||
883 | |||||||||
884 | void SystemWindow::SetWindowState(const OString& rStr) | ||||||||
885 | { | ||||||||
886 | if (rStr.isEmpty()) | ||||||||
887 | return; | ||||||||
888 | |||||||||
889 | WindowStateData aData; | ||||||||
890 | ImplWindowStateFromStr( aData, rStr ); | ||||||||
891 | SetWindowStateData( aData ); | ||||||||
892 | } | ||||||||
893 | |||||||||
894 | OString SystemWindow::GetWindowState( WindowStateMask nMask ) const | ||||||||
895 | { | ||||||||
896 | WindowStateData aData; | ||||||||
897 | aData.SetMask( nMask ); | ||||||||
898 | GetWindowStateData( aData ); | ||||||||
899 | |||||||||
900 | return aData.ToStr(); | ||||||||
901 | } | ||||||||
902 | |||||||||
903 | void SystemWindow::SetMenuBar(MenuBar* pMenuBar) | ||||||||
904 | { | ||||||||
905 | if ( mpMenuBar == pMenuBar ) | ||||||||
| |||||||||
906 | return; | ||||||||
907 | |||||||||
908 | MenuBar* pOldMenuBar = mpMenuBar; | ||||||||
909 | vcl::Window* pOldWindow = nullptr; | ||||||||
910 | VclPtr<vcl::Window> pNewWindow; | ||||||||
911 | mpMenuBar = pMenuBar; | ||||||||
912 | |||||||||
913 | if ( mpWindowImpl->mpBorderWindow && (mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW) ) | ||||||||
914 | { | ||||||||
915 | if ( pOldMenuBar ) | ||||||||
916 | pOldWindow = pOldMenuBar->ImplGetWindow(); | ||||||||
917 | else | ||||||||
918 | pOldWindow = nullptr; | ||||||||
919 | if ( pOldWindow ) | ||||||||
920 | { | ||||||||
921 | CallEventListeners( VclEventId::WindowMenubarRemoved, static_cast<void*>(pOldMenuBar) ); | ||||||||
922 | pOldWindow->SetAccessible( css::uno::Reference< css::accessibility::XAccessible >() ); | ||||||||
923 | } | ||||||||
924 | if ( pMenuBar ) | ||||||||
925 | { | ||||||||
926 | SAL_WARN_IF( pMenuBar->pWindow, "vcl", "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" )do { if (true && (pMenuBar->pWindow)) { switch (sal_detail_log_report (::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE : break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "926" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "926" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "926" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "926" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
927 | |||||||||
928 | pNewWindow = MenuBar::ImplCreate(mpWindowImpl->mpBorderWindow, pOldWindow, pMenuBar); | ||||||||
929 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuBarWindow(pNewWindow); | ||||||||
930 | |||||||||
931 | CallEventListeners( VclEventId::WindowMenubarAdded, static_cast<void*>(pMenuBar) ); | ||||||||
932 | } | ||||||||
933 | else | ||||||||
934 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuBarWindow( nullptr ); | ||||||||
935 | ImplToBottomChild(); | ||||||||
936 | if ( pOldMenuBar ) | ||||||||
937 | { | ||||||||
938 | bool bDelete = (pMenuBar == nullptr); | ||||||||
939 | if( bDelete && pOldWindow ) | ||||||||
940 | { | ||||||||
941 | if( mpImplData->mpTaskPaneList ) | ||||||||
942 | mpImplData->mpTaskPaneList->RemoveWindow( pOldWindow ); | ||||||||
943 | } | ||||||||
944 | MenuBar::ImplDestroy( pOldMenuBar, bDelete ); | ||||||||
945 | if( bDelete ) | ||||||||
946 | pOldWindow = nullptr; // will be deleted in MenuBar::ImplDestroy, | ||||||||
947 | } | ||||||||
948 | |||||||||
949 | } | ||||||||
950 | else | ||||||||
951 | { | ||||||||
952 | if( pMenuBar
| ||||||||
953 | pNewWindow = pMenuBar->ImplGetWindow(); | ||||||||
954 | if( pOldMenuBar
| ||||||||
955 | pOldWindow = pOldMenuBar->ImplGetWindow(); | ||||||||
| |||||||||
956 | } | ||||||||
957 | |||||||||
958 | // update taskpane list to make menubar accessible | ||||||||
959 | if( mpImplData->mpTaskPaneList ) | ||||||||
960 | { | ||||||||
961 | if( pOldWindow ) | ||||||||
962 | mpImplData->mpTaskPaneList->RemoveWindow( pOldWindow ); | ||||||||
963 | if( pNewWindow ) | ||||||||
964 | mpImplData->mpTaskPaneList->AddWindow( pNewWindow ); | ||||||||
965 | } | ||||||||
966 | } | ||||||||
967 | |||||||||
968 | void SystemWindow::SetNotebookBar(const OUString& rUIXMLDescription, | ||||||||
969 | const css::uno::Reference<css::frame::XFrame>& rFrame, | ||||||||
970 | const NotebookBarAddonsItem& aNotebookBarAddonsItem, | ||||||||
971 | bool bReloadNotebookbar) | ||||||||
972 | { | ||||||||
973 | if (rUIXMLDescription != maNotebookBarUIFile || bReloadNotebookbar) | ||||||||
974 | { | ||||||||
975 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get()) | ||||||||
976 | ->SetNotebookBar(rUIXMLDescription, rFrame, aNotebookBarAddonsItem); | ||||||||
977 | maNotebookBarUIFile = rUIXMLDescription; | ||||||||
978 | if(GetNotebookBar()) | ||||||||
979 | GetNotebookBar()->SetSystemWindow(this); | ||||||||
980 | } | ||||||||
981 | } | ||||||||
982 | |||||||||
983 | void SystemWindow::CloseNotebookBar() | ||||||||
984 | { | ||||||||
985 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->CloseNotebookBar(); | ||||||||
986 | maNotebookBarUIFile.clear(); | ||||||||
987 | } | ||||||||
988 | |||||||||
989 | VclPtr<NotebookBar> const & SystemWindow::GetNotebookBar() const | ||||||||
990 | { | ||||||||
991 | return static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->GetNotebookBar(); | ||||||||
992 | } | ||||||||
993 | |||||||||
994 | void SystemWindow::SetMenuBarMode( MenuBarMode nMode ) | ||||||||
995 | { | ||||||||
996 | if ( mnMenuBarMode != nMode ) | ||||||||
997 | { | ||||||||
998 | mnMenuBarMode = nMode; | ||||||||
999 | if ( mpWindowImpl->mpBorderWindow && (mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW) ) | ||||||||
1000 | { | ||||||||
1001 | if ( nMode == MenuBarMode::Hide ) | ||||||||
1002 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuBarMode( true ); | ||||||||
1003 | else | ||||||||
1004 | static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuBarMode( false ); | ||||||||
1005 | } | ||||||||
1006 | } | ||||||||
1007 | } | ||||||||
1008 | |||||||||
1009 | bool SystemWindow::ImplIsInTaskPaneList( vcl::Window* pWin ) | ||||||||
1010 | { | ||||||||
1011 | if( mpImplData && mpImplData->mpTaskPaneList ) | ||||||||
1012 | return mpImplData->mpTaskPaneList->IsInList( pWin ); | ||||||||
1013 | return false; | ||||||||
1014 | } | ||||||||
1015 | |||||||||
1016 | unsigned int SystemWindow::GetScreenNumber() const | ||||||||
1017 | { | ||||||||
1018 | return mpWindowImpl->mpFrame->maGeometry.nDisplayScreenNumber; | ||||||||
1019 | } | ||||||||
1020 | |||||||||
1021 | void SystemWindow::SetScreenNumber(unsigned int nDisplayScreen) | ||||||||
1022 | { | ||||||||
1023 | mpWindowImpl->mpFrame->SetScreenNumber( nDisplayScreen ); | ||||||||
1024 | } | ||||||||
1025 | |||||||||
1026 | void SystemWindow::SetApplicationID(const OUString &rApplicationID) | ||||||||
1027 | { | ||||||||
1028 | mpWindowImpl->mpFrame->SetApplicationID( rApplicationID ); | ||||||||
1029 | } | ||||||||
1030 | |||||||||
1031 | void SystemWindow::SetCloseHdl(const Link<SystemWindow&,void>& rLink) | ||||||||
1032 | { | ||||||||
1033 | mpImplData->maCloseHdl = rLink; | ||||||||
1034 | } | ||||||||
1035 | |||||||||
1036 | const Link<SystemWindow&,void>& SystemWindow::GetCloseHdl() const | ||||||||
1037 | { | ||||||||
1038 | return mpImplData->maCloseHdl; | ||||||||
1039 | } | ||||||||
1040 | |||||||||
1041 | void SystemWindow::queue_resize(StateChangedType /*eReason*/) | ||||||||
1042 | { | ||||||||
1043 | if (!isLayoutEnabled()) | ||||||||
1044 | return; | ||||||||
1045 | if (isCalculatingInitialLayoutSize()) | ||||||||
1046 | return; | ||||||||
1047 | InvalidateSizeCache(); | ||||||||
1048 | if (hasPendingLayout()) | ||||||||
1049 | return; | ||||||||
1050 | maLayoutIdle.Start(); | ||||||||
1051 | } | ||||||||
1052 | |||||||||
1053 | void SystemWindow::Resize() | ||||||||
1054 | { | ||||||||
1055 | queue_resize(); | ||||||||
1056 | } | ||||||||
1057 | |||||||||
1058 | bool SystemWindow::isLayoutEnabled() const | ||||||||
1059 | { | ||||||||
1060 | //pre dtor called, and single child is a container => we're layout enabled | ||||||||
1061 | return mpImplData && ::isLayoutEnabled(this); | ||||||||
1062 | } | ||||||||
1063 | |||||||||
1064 | Size SystemWindow::GetOptimalSize() const | ||||||||
1065 | { | ||||||||
1066 | if (!isLayoutEnabled()) | ||||||||
1067 | return Window::GetOptimalSize(); | ||||||||
1068 | |||||||||
1069 | Size aSize = VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild)); | ||||||||
1070 | |||||||||
1071 | sal_Int32 nBorderWidth = get_border_width(); | ||||||||
1072 | |||||||||
1073 | aSize.AdjustHeight(2 * nBorderWidth ); | ||||||||
1074 | aSize.AdjustWidth(2 * nBorderWidth ); | ||||||||
1075 | |||||||||
1076 | return Window::CalcWindowSize(aSize); | ||||||||
1077 | } | ||||||||
1078 | |||||||||
1079 | void SystemWindow::setPosSizeOnContainee(Size aSize, Window &rBox) | ||||||||
1080 | { | ||||||||
1081 | sal_Int32 nBorderWidth = get_border_width(); | ||||||||
1082 | |||||||||
1083 | aSize.AdjustWidth( -(2 * nBorderWidth) ); | ||||||||
1084 | aSize.AdjustHeight( -(2 * nBorderWidth) ); | ||||||||
1085 | |||||||||
1086 | Point aPos(nBorderWidth, nBorderWidth); | ||||||||
1087 | VclContainer::setLayoutAllocation(rBox, aPos, CalcOutputSize(aSize)); | ||||||||
1088 | } | ||||||||
1089 | |||||||||
1090 | IMPL_LINK_NOARG( SystemWindow, ImplHandleLayoutTimerHdl, Timer*, void )void SystemWindow::LinkStubImplHandleLayoutTimerHdl(void * instance , Timer* data) { return static_cast<SystemWindow *>(instance )->ImplHandleLayoutTimerHdl(data); } void SystemWindow::ImplHandleLayoutTimerHdl (__attribute__ ((unused)) Timer*) | ||||||||
1091 | { | ||||||||
1092 | if (!isLayoutEnabled()) | ||||||||
1093 | { | ||||||||
1094 | SAL_WARN("vcl.layout", "SystemWindow has become non-layout because extra children have been added directly to it.")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "vcl.layout")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "SystemWindow has become non-layout because extra children have been added directly to it." ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "1094" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "SystemWindow has become non-layout because extra children have been added directly to it." ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SystemWindow has become non-layout because extra children have been added directly to it." ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "1094" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "SystemWindow has become non-layout because extra children have been added directly to it." ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "1094" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "SystemWindow has become non-layout because extra children have been added directly to it." ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SystemWindow has become non-layout because extra children have been added directly to it." ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "1094" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
1095 | return; | ||||||||
1096 | } | ||||||||
1097 | |||||||||
1098 | Window *pBox = GetWindow(GetWindowType::FirstChild); | ||||||||
1099 | assert(pBox)(static_cast <bool> (pBox) ? void (0) : __assert_fail ( "pBox", "/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" , 1099, __extension__ __PRETTY_FUNCTION__)); | ||||||||
1100 | setPosSizeOnContainee(GetSizePixel(), *pBox); | ||||||||
1101 | } | ||||||||
1102 | |||||||||
1103 | void SystemWindow::SetText(const OUString& rStr) | ||||||||
1104 | { | ||||||||
1105 | setDeferredProperties(); | ||||||||
1106 | Window::SetText(rStr); | ||||||||
1107 | } | ||||||||
1108 | |||||||||
1109 | OUString SystemWindow::GetText() const | ||||||||
1110 | { | ||||||||
1111 | const_cast<SystemWindow*>(this)->setDeferredProperties(); | ||||||||
1112 | return Window::GetText(); | ||||||||
1113 | } | ||||||||
1114 | |||||||||
1115 | void SystemWindow::settingOptimalLayoutSize(Window* /*pBox*/) | ||||||||
1116 | { | ||||||||
1117 | } | ||||||||
1118 | |||||||||
1119 | void SystemWindow::setOptimalLayoutSize() | ||||||||
1120 | { | ||||||||
1121 | maLayoutIdle.Stop(); | ||||||||
1122 | |||||||||
1123 | //resize SystemWindow to fit requisition on initial show | ||||||||
1124 | Window *pBox = GetWindow(GetWindowType::FirstChild); | ||||||||
1125 | |||||||||
1126 | settingOptimalLayoutSize(pBox); | ||||||||
1127 | |||||||||
1128 | Size aSize = get_preferred_size(); | ||||||||
1129 | |||||||||
1130 | Size aMax(bestmaxFrameSizeForScreenSize(GetDesktopRectPixel().GetSize())); | ||||||||
1131 | |||||||||
1132 | aSize.setWidth( std::min(aMax.Width(), aSize.Width()) ); | ||||||||
1133 | aSize.setHeight( std::min(aMax.Height(), aSize.Height()) ); | ||||||||
1134 | |||||||||
1135 | SetMinOutputSizePixel(aSize); | ||||||||
1136 | SetSizePixel(aSize); | ||||||||
1137 | setPosSizeOnContainee(aSize, *pBox); | ||||||||
1138 | } | ||||||||
1139 | |||||||||
1140 | void SystemWindow::DoInitialLayout() | ||||||||
1141 | { | ||||||||
1142 | if (GetSettings().GetStyleSettings().GetAutoMnemonic()) | ||||||||
1143 | Accelerator::GenerateAutoMnemonicsOnHierarchy(this); | ||||||||
1144 | |||||||||
1145 | if (isLayoutEnabled()) | ||||||||
1146 | { | ||||||||
1147 | mbIsCalculatingInitialLayoutSize = true; | ||||||||
1148 | setDeferredProperties(); | ||||||||
1149 | setOptimalLayoutSize(); | ||||||||
1150 | mbIsCalculatingInitialLayoutSize = false; | ||||||||
1151 | } | ||||||||
1152 | } | ||||||||
1153 | |||||||||
1154 | void SystemWindow::doDeferredInit(WinBits /*nBits*/) | ||||||||
1155 | { | ||||||||
1156 | SAL_WARN("vcl.layout", "SystemWindow in layout without doDeferredInit impl")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "vcl.layout")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "SystemWindow in layout without doDeferredInit impl" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "1156" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "SystemWindow in layout without doDeferredInit impl" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SystemWindow in layout without doDeferredInit impl" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "1156" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "SystemWindow in layout without doDeferredInit impl" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "1156" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "SystemWindow in layout without doDeferredInit impl" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "SystemWindow in layout without doDeferredInit impl" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/syswin.cxx" ":" "1156" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
1157 | } | ||||||||
1158 | |||||||||
1159 | VclPtr<VirtualDevice> SystemWindow::createScreenshot() | ||||||||
1160 | { | ||||||||
1161 | // same prerequisites as in Execute() | ||||||||
1162 | setDeferredProperties(); | ||||||||
1163 | ImplAdjustNWFSizes(); | ||||||||
1164 | Show(); | ||||||||
1165 | ToTop(); | ||||||||
1166 | ensureRepaint(); | ||||||||
1167 | |||||||||
1168 | Size aSize(GetOutputSizePixel()); | ||||||||
1169 | |||||||||
1170 | VclPtr<VirtualDevice> xOutput(VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT)); | ||||||||
1171 | xOutput->SetOutputSizePixel(aSize); | ||||||||
1172 | |||||||||
1173 | Point aPos; | ||||||||
1174 | xOutput->DrawOutDev(aPos, aSize, aPos, aSize, *this); | ||||||||
1175 | |||||||||
1176 | return xOutput; | ||||||||
1177 | } | ||||||||
1178 | |||||||||
1179 | void SystemWindow::PrePaint(vcl::RenderContext& rRenderContext) | ||||||||
1180 | { | ||||||||
1181 | Window::PrePaint(rRenderContext); | ||||||||
1182 | mbPaintComplete = false; | ||||||||
1183 | } | ||||||||
1184 | |||||||||
1185 | void SystemWindow::PostPaint(vcl::RenderContext& rRenderContext) | ||||||||
1186 | { | ||||||||
1187 | Window::PostPaint(rRenderContext); | ||||||||
1188 | mbPaintComplete = true; | ||||||||
1189 | } | ||||||||
1190 | |||||||||
1191 | void SystemWindow::ensureRepaint() | ||||||||
1192 | { | ||||||||
1193 | // ensure repaint | ||||||||
1194 | Invalidate(); | ||||||||
1195 | mbPaintComplete = false; | ||||||||
1196 | |||||||||
1197 | while (!mbPaintComplete) | ||||||||
1198 | { | ||||||||
1199 | Application::Yield(); | ||||||||
1200 | } | ||||||||
1201 | } | ||||||||
1202 | |||||||||
1203 | /* 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 |