1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/window.hxx>
21 #include <vcl/sysdata.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/syschild.hxx>
26 #include <salframe.hxx>
27 #include <salinst.hxx>
31 using namespace ::com::sun::star
;
33 static void ImplSysChildProc( SystemChildWindow
* pInst
, SalObjEvent nEvent
)
35 VclPtr
<SystemChildWindow
> pWindow
= pInst
;
39 case SalObjEvent::GetFocus
:
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() )
48 pWindow
->ImplGetFrameData()->mbInSysObjToTopHdl
= false;
49 pWindow
->ImplGetFrameData()->mbInSysObjFocusHdl
= true;
51 if( pWindow
->isDisposed() )
53 pWindow
->ImplGetFrameData()->mbInSysObjFocusHdl
= false;
56 case SalObjEvent::LoseFocus
:
57 // trigger a LoseFocus which matches the status
58 // of the window with matching Activate-Status
59 if (pWindow
->isDisposed())
61 pWindow
->ImplGetFrameData()->mbSysObjFocus
= false;
62 if ( !pWindow
->ImplGetFrameData()->mnFocusId
)
64 pWindow
->ImplGetFrameData()->mbStartFocusState
= true;
65 pWindow
->ImplGetFrameData()->mnFocusId
= Application::PostUserEvent( LINK( pWindow
->ImplGetFrameWindow(), vcl::Window
, ImplAsyncFocusHdl
), nullptr, true );
69 case SalObjEvent::ToTop
:
70 pWindow
->ImplGetFrameData()->mbInSysObjToTopHdl
= true;
71 if ( !Application::GetFocusWindow() || pWindow
->HasChildPathFocus() )
72 pWindow
->ToTop( ToTopFlags::NoGrabFocus
);
75 if( pWindow
->isDisposed() )
78 if( pWindow
->isDisposed() )
80 pWindow
->ImplGetFrameData()->mbInSysObjToTopHdl
= false;
87 void SystemChildWindow::ImplInitSysChild( vcl::Window
* pParent
, WinBits nStyle
, SystemWindowData
*pData
, bool bShow
)
89 mpWindowImpl
->mpSysObj
= ImplGetSVData()->mpDefInst
->CreateObject( pParent
->ImplGetFrame(), pData
, bShow
);
91 Window::ImplInit( pParent
, nStyle
, nullptr );
93 // we do not paint if it is the right SysChild
94 if ( GetSystemData() )
96 mpWindowImpl
->mpSysObj
->SetCallback( this, ImplSysChildProc
);
97 SetParentClipMode( ParentClipMode::Clip
);
102 SystemChildWindow::SystemChildWindow( vcl::Window
* pParent
, WinBits nStyle
) :
103 Window( WindowType::SYSTEMCHILDWINDOW
)
105 ImplInitSysChild( pParent
, nStyle
, nullptr );
108 SystemChildWindow::SystemChildWindow( vcl::Window
* pParent
, WinBits nStyle
, SystemWindowData
*pData
, bool bShow
) :
109 Window( WindowType::SYSTEMCHILDWINDOW
)
111 ImplInitSysChild( pParent
, nStyle
, pData
, bShow
);
114 SystemChildWindow::~SystemChildWindow()
119 void SystemChildWindow::dispose()
122 if ( mpWindowImpl
&& mpWindowImpl
->mpSysObj
)
124 ImplGetSVData()->mpDefInst
->DestroyObject( mpWindowImpl
->mpSysObj
);
125 mpWindowImpl
->mpSysObj
= nullptr;
130 const SystemEnvData
* SystemChildWindow::GetSystemData() const
132 if ( mpWindowImpl
->mpSysObj
)
133 return &mpWindowImpl
->mpSysObj
->GetSystemData();
138 void SystemChildWindow::EnableEraseBackground( bool bEnable
)
140 if ( mpWindowImpl
->mpSysObj
)
141 mpWindowImpl
->mpSysObj
->EnableEraseBackground( bEnable
);
144 Size
SystemChildWindow::GetOptimalSize() const
146 if (mpWindowImpl
->mpSysObj
)
147 return mpWindowImpl
->mpSysObj
->GetOptimalSize();
148 return vcl::Window::GetOptimalSize();
151 void SystemChildWindow::SetLeaveEnterBackgrounds(const css::uno::Sequence
<css::uno::Any
>& rLeaveArgs
, const css::uno::Sequence
<css::uno::Any
>& rEnterArgs
)
153 if (mpWindowImpl
->mpSysObj
)
154 mpWindowImpl
->mpSysObj
->SetLeaveEnterBackgrounds(rLeaveArgs
, rEnterArgs
);
157 void SystemChildWindow::SetForwardKey( bool bEnable
)
159 if ( mpWindowImpl
->mpSysObj
)
160 mpWindowImpl
->mpSysObj
->SetForwardKey( bEnable
);
163 sal_IntPtr
SystemChildWindow::GetParentWindowHandle() const
168 nRet
= reinterpret_cast< sal_IntPtr
>( GetSystemData()->hWnd
);
170 // FIXME: this is wrong
171 nRet
= reinterpret_cast< sal_IntPtr
>( GetSystemData()->mpNSView
);
172 #elif defined ANDROID
177 nRet
= GetSystemData()->GetWindowHandle(ImplGetFrame());
183 void* SystemChildWindow::CreateGStreamerSink()
185 return ImplGetSVData()->mpDefInst
->CreateGStreamerSink(this);
188 #if defined( MACOSX )
189 #elif defined( ANDROID )
192 sal_uIntPtr
SystemEnvData::GetWindowHandle(const SalFrame
* pReference
) const
194 if (!aWindow
&& pReference
)
195 pReference
->ResolveWindowHandle(const_cast<SystemEnvData
&>(*this));
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */