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 <salinst.hxx>
27 #include <salobj.hxx>
28 #include <svdata.hxx>
29 
30 using namespace ::com::sun::star;
31 
32 static void ImplSysChildProc( SystemChildWindow* pInst, SalObjEvent nEvent )
33 {
34  VclPtr<SystemChildWindow> pWindow = pInst;
35 
36  switch ( nEvent )
37  {
39  // get focus, such that all handlers are called,
40  // as if this window gets the focus assuring
41  // that the frame does not steal it
42  pWindow->ImplGetFrameData()->mbSysObjFocus = true;
43  pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = true;
44  pWindow->ToTop( ToTopFlags::NoGrabFocus );
45  if( pWindow->IsDisposed() )
46  break;
47  pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = false;
48  pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = true;
49  pWindow->GrabFocus();
50  if( pWindow->IsDisposed() )
51  break;
52  pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = false;
53  break;
54 
56  // trigger a LoseFocus which matches the status
57  // of the window with matching Activate-Status
58  if (pWindow->IsDisposed())
59  break;
60  pWindow->ImplGetFrameData()->mbSysObjFocus = false;
61  if ( !pWindow->ImplGetFrameData()->mnFocusId )
62  {
63  pWindow->ImplGetFrameData()->mbStartFocusState = true;
64  pWindow->ImplGetFrameData()->mnFocusId = Application::PostUserEvent( LINK( pWindow->ImplGetFrameWindow(), vcl::Window, ImplAsyncFocusHdl ), nullptr, true );
65  }
66  break;
67 
68  case SalObjEvent::ToTop:
69  pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = true;
70  if ( !Application::GetFocusWindow() || pWindow->HasChildPathFocus() )
71  pWindow->ToTop( ToTopFlags::NoGrabFocus );
72  else
73  pWindow->ToTop();
74  if( pWindow->IsDisposed() )
75  break;
76  pWindow->GrabFocus();
77  if( pWindow->IsDisposed() )
78  break;
79  pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = false;
80  break;
81 
82  default: break;
83  }
84 }
85 
86 void SystemChildWindow::ImplInitSysChild( vcl::Window* pParent, WinBits nStyle, SystemWindowData *pData, bool bShow )
87 {
88  mpWindowImpl->mpSysObj = ImplGetSVData()->mpDefInst->CreateObject( pParent->ImplGetFrame(), pData, bShow );
89 
90  Window::ImplInit( pParent, nStyle, nullptr );
91 
92  // we do not paint if it is the right SysChild
93  if ( GetSystemData() )
94  {
95  mpWindowImpl->mpSysObj->SetCallback( this, ImplSysChildProc );
97  SetBackground();
98  }
99 }
100 
103 {
104  ImplInitSysChild( pParent, nStyle, nullptr );
105 }
106 
109 {
110  ImplInitSysChild( pParent, nStyle, pData, bShow );
111 }
112 
114 {
115  disposeOnce();
116 }
117 
119 {
120  Hide();
121  if ( mpWindowImpl && mpWindowImpl->mpSysObj )
122  {
124  mpWindowImpl->mpSysObj = nullptr;
125  }
126  Window::dispose();
127 }
128 
130 {
131  if ( mpWindowImpl->mpSysObj )
132  return mpWindowImpl->mpSysObj->GetSystemData();
133  else
134  return nullptr;
135 }
136 
138 {
139  if ( mpWindowImpl->mpSysObj )
140  mpWindowImpl->mpSysObj->EnableEraseBackground( bEnable );
141 }
142 
143 void SystemChildWindow::SetLeaveEnterBackgrounds(const css::uno::Sequence<css::uno::Any>& rLeaveArgs, const css::uno::Sequence<css::uno::Any>& rEnterArgs)
144 {
145  if (mpWindowImpl->mpSysObj)
146  mpWindowImpl->mpSysObj->SetLeaveEnterBackgrounds(rLeaveArgs, rEnterArgs);
147 }
148 
150 {
151  if ( mpWindowImpl->mpSysObj )
152  mpWindowImpl->mpSysObj->SetForwardKey( bEnable );
153 }
154 
156 {
157  sal_IntPtr nRet = 0;
158 
159 #if defined(_WIN32)
160  nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->hWnd );
161 #elif defined MACOSX
162  // FIXME: this is wrong
163  nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->mpNSView );
164 #elif defined ANDROID
165  // Nothing
166 #elif defined IOS
167  // Nothing
168 #elif defined UNX
169  nRet = GetSystemData()->aWindow;
170 #endif
171 
172  return nRet;
173 }
174 
176 {
178 }
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbStartFocusState
Definition: window.h:163
SAL_DLLPRIVATE vcl::Window * ImplGetFrameWindow() const
Definition: window2.cxx:890
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:996
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
bool HasChildPathFocus(bool bSystemWindow=false) const
Definition: window.cxx:3008
bool mbInSysObjFocusHdl
Definition: window.h:164
sal_Int64 WinBits
void SetBackground()
unsigned long aWindow
Definition: sysdata.hxx:68
virtual const SystemEnvData * GetSystemData() const override
Definition: syschild.cxx:129
void Hide()
Definition: window.hxx:932
void SetLeaveEnterBackgrounds(const css::uno::Sequence< css::uno::Any > &rLeaveArgs, const css::uno::Sequence< css::uno::Any > &rEnterArgs)
Definition: syschild.cxx:143
SAL_DLLPRIVATE void ImplInitSysChild(vcl::Window *pParent, WinBits nStyle, SystemWindowData *pData, bool bShow=false)
Definition: syschild.cxx:86
void EnableEraseBackground(bool bEnable)
Definition: syschild.cxx:137
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:118
SalObjEvent
Definition: salwtype.hxx:221
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:67
bool mbInSysObjToTopHdl
Definition: window.h:165
void ToTop(ToTopFlags nFlags=ToTopFlags::NONE)
Definition: stacking.cxx:414
std::unique_ptr< WindowImpl > mpWindowImpl
Definition: window.hxx:511
bool mbSysObjFocus
Definition: window.h:166
void GrabFocus()
Definition: window.cxx:2980
void SetForwardKey(bool bEnable)
Definition: syschild.cxx:149
virtual void * CreateGStreamerSink(const SystemChildWindow *)
Definition: salinst.hxx:206
void * CreateGStreamerSink()
Definition: syschild.cxx:175
static void ImplSysChildProc(SystemChildWindow *pInst, SalObjEvent nEvent)
Definition: syschild.cxx:32
SalFrame * ImplGetFrame() const
Definition: window2.cxx:848
static vcl::Window * GetFocusWindow()
Get the currently focused window.
Definition: svapp.cxx:1049
WindowType
ImplSVEvent * mnFocusId
Definition: window.h:141
virtual ~SystemChildWindow() override
Definition: syschild.cxx:113
SystemChildWindow(const SystemChildWindow &)=delete
bool IsDisposed() const
Definition: window.cxx:136
SAL_DLLPRIVATE ImplFrameData * ImplGetFrameData()
Definition: window2.cxx:843
sal_IntPtr GetParentWindowHandle() const
Definition: syschild.cxx:155
SalInstance * mpDefInst
Definition: svdata.hxx:336
virtual SalObject * CreateObject(SalFrame *pParent, SystemWindowData *pWindowData, bool bShow)=0