LibreOffice Module vcl (master)  1
syschild.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <vcl/window.hxx>
21 #include <vcl/sysdata.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/syschild.hxx>
24 
25 #include <window.h>
26 #include <salframe.hxx>
27 #include <salinst.hxx>
28 #include <salobj.hxx>
29 #include <svdata.hxx>
30 
31 using namespace ::com::sun::star;
32 
33 static void ImplSysChildProc( SystemChildWindow* pInst, SalObjEvent nEvent )
34 {
35  VclPtr<SystemChildWindow> pWindow = pInst;
36 
37  switch ( nEvent )
38  {
40  // get focus, such that all handlers are called,
41  // as if this window gets the focus assuring
42  // that the frame does not steal it
43  pWindow->ImplGetFrameData()->mbSysObjFocus = true;
44  pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = true;
45  pWindow->ToTop( ToTopFlags::NoGrabFocus );
46  if( pWindow->IsDisposed() )
47  break;
48  pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = false;
49  pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = true;
50  pWindow->GrabFocus();
51  if( pWindow->IsDisposed() )
52  break;
53  pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = false;
54  break;
55 
57  // trigger a LoseFocus which matches the status
58  // of the window with matching Activate-Status
59  if (pWindow->IsDisposed())
60  break;
61  pWindow->ImplGetFrameData()->mbSysObjFocus = false;
62  if ( !pWindow->ImplGetFrameData()->mnFocusId )
63  {
64  pWindow->ImplGetFrameData()->mbStartFocusState = true;
65  pWindow->ImplGetFrameData()->mnFocusId = Application::PostUserEvent( LINK( pWindow->ImplGetFrameWindow(), vcl::Window, ImplAsyncFocusHdl ), nullptr, true );
66  }
67  break;
68 
69  case SalObjEvent::ToTop:
70  pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = true;
71  if ( !Application::GetFocusWindow() || pWindow->HasChildPathFocus() )
72  pWindow->ToTop( ToTopFlags::NoGrabFocus );
73  else
74  pWindow->ToTop();
75  if( pWindow->IsDisposed() )
76  break;
77  pWindow->GrabFocus();
78  if( pWindow->IsDisposed() )
79  break;
80  pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = false;
81  break;
82 
83  default: break;
84  }
85 }
86 
87 void SystemChildWindow::ImplInitSysChild( vcl::Window* pParent, WinBits nStyle, SystemWindowData *pData, bool bShow )
88 {
89  mpWindowImpl->mpSysObj = ImplGetSVData()->mpDefInst->CreateObject( pParent->ImplGetFrame(), pData, bShow );
90 
91  Window::ImplInit( pParent, nStyle, nullptr );
92 
93  // we do not paint if it is the right SysChild
94  if ( GetSystemData() )
95  {
96  mpWindowImpl->mpSysObj->SetCallback( this, ImplSysChildProc );
98  SetBackground();
99  }
100 }
101 
104 {
105  ImplInitSysChild( pParent, nStyle, nullptr );
106 }
107 
110 {
111  ImplInitSysChild( pParent, nStyle, pData, bShow );
112 }
113 
115 {
116  disposeOnce();
117 }
118 
120 {
121  Hide();
122  if ( mpWindowImpl && mpWindowImpl->mpSysObj )
123  {
125  mpWindowImpl->mpSysObj = nullptr;
126  }
127  Window::dispose();
128 }
129 
131 {
132  if ( mpWindowImpl->mpSysObj )
133  return mpWindowImpl->mpSysObj->GetSystemData();
134  else
135  return nullptr;
136 }
137 
139 {
140  if ( mpWindowImpl->mpSysObj )
141  mpWindowImpl->mpSysObj->EnableEraseBackground( bEnable );
142 }
143 
145 {
146  if (mpWindowImpl->mpSysObj)
147  return mpWindowImpl->mpSysObj->GetOptimalSize();
149 }
150 
151 void SystemChildWindow::SetLeaveEnterBackgrounds(const css::uno::Sequence<css::uno::Any>& rLeaveArgs, const css::uno::Sequence<css::uno::Any>& rEnterArgs)
152 {
153  if (mpWindowImpl->mpSysObj)
154  mpWindowImpl->mpSysObj->SetLeaveEnterBackgrounds(rLeaveArgs, rEnterArgs);
155 }
156 
158 {
159  if ( mpWindowImpl->mpSysObj )
160  mpWindowImpl->mpSysObj->SetForwardKey( bEnable );
161 }
162 
164 {
165  sal_IntPtr nRet = 0;
166 
167 #if defined(_WIN32)
168  nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->hWnd );
169 #elif defined MACOSX
170  // FIXME: this is wrong
171  nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->mpNSView );
172 #elif defined ANDROID
173  // Nothing
174 #elif defined IOS
175  // Nothing
176 #elif defined UNX
178 #endif
179 
180  return nRet;
181 }
182 
184 {
186 }
187 
188 #if defined( MACOSX )
189 #elif defined( ANDROID )
190 #elif defined( IOS )
191 #elif defined( UNX )
192 sal_uIntPtr SystemEnvData::GetWindowHandle(const SalFrame* pReference) const
193 {
194  if (!aWindow && pReference)
195  pReference->ResolveWindowHandle(const_cast<SystemEnvData&>(*this));
196  return aWindow;
197 }
198 #endif
199 
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Size GetOptimalSize() const override
Definition: syschild.cxx:144
virtual void ResolveWindowHandle(SystemEnvData &) const
Definition: salframe.hxx:220
bool mbStartFocusState
Definition: window.h:164
SAL_DLLPRIVATE vcl::Window * ImplGetFrameWindow() const
Definition: window2.cxx:900
virtual Size GetOptimalSize() const
Definition: window3.cxx:26
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
Post a user event to the default window.
Definition: svapp.cxx:1025
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
sal_uIntPtr GetWindowHandle(const SalFrame *pReference) const
Definition: syschild.cxx:192
bool HasChildPathFocus(bool bSystemWindow=false) const
Definition: window.cxx:2996
bool mbInSysObjFocusHdl
Definition: window.h:165
sal_Int64 WinBits
void SetBackground()
virtual const SystemEnvData * GetSystemData() const override
Definition: syschild.cxx:130
void Hide()
Definition: window.hxx:920
void SetLeaveEnterBackgrounds(const css::uno::Sequence< css::uno::Any > &rLeaveArgs, const css::uno::Sequence< css::uno::Any > &rEnterArgs)
Definition: syschild.cxx:151
SAL_DLLPRIVATE void ImplInitSysChild(vcl::Window *pParent, WinBits nStyle, SystemWindowData *pData, bool bShow=false)
Definition: syschild.cxx:87
void EnableEraseBackground(bool bEnable)
Definition: syschild.cxx:138
virtual void DestroyObject(SalObject *pObject)=0
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: syschild.cxx:119
SalObjEvent
Definition: salwtype.hxx:228
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:74
bool mbInSysObjToTopHdl
Definition: window.h:166
void ToTop(ToTopFlags nFlags=ToTopFlags::NONE)
Definition: stacking.cxx:418
std::unique_ptr< WindowImpl > mpWindowImpl
Definition: window.hxx:493
bool mbSysObjFocus
Definition: window.h:167
void GrabFocus()
Definition: window.cxx:2968
void SetForwardKey(bool bEnable)
Definition: syschild.cxx:157
virtual void * CreateGStreamerSink(const SystemChildWindow *)
Definition: salinst.hxx:207
void * CreateGStreamerSink()
Definition: syschild.cxx:183
static void ImplSysChildProc(SystemChildWindow *pInst, SalObjEvent nEvent)
Definition: syschild.cxx:33
SalFrame * ImplGetFrame() const
Definition: window2.cxx:847
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
static vcl::Window * GetFocusWindow()
Get the currently focused window.
Definition: svapp.cxx:1068
WindowType
ImplSVEvent * mnFocusId
Definition: window.h:142
virtual ~SystemChildWindow() override
Definition: syschild.cxx:114
SystemChildWindow(const SystemChildWindow &)=delete
bool IsDisposed() const
Definition: window.cxx:143
sal_uIntPtr aWindow
Definition: sysdata.hxx:77
SAL_DLLPRIVATE ImplFrameData * ImplGetFrameData()
Definition: window2.cxx:842
sal_IntPtr GetParentWindowHandle() const
Definition: syschild.cxx:163
SalInstance * mpDefInst
Definition: svdata.hxx:383
virtual SalObject * CreateObject(SalFrame *pParent, SystemWindowData *pWindowData, bool bShow)=0