build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / window / syschild.cxx
blobbdeebf118dfcda15d49c62c0192f556a6324dc35
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <config_features.h>
22 #include <rtl/process.h>
23 #include <rtl/ref.hxx>
25 #include <tools/rc.h>
27 #include <vcl/window.hxx>
28 #include <vcl/sysdata.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/syschild.hxx>
32 #include <window.h>
33 #include <salinst.hxx>
34 #include <salframe.hxx>
35 #include <salobj.hxx>
36 #include <svdata.hxx>
38 #if HAVE_FEATURE_JAVA
39 #include <jni.h>
40 #endif
42 #include <comphelper/processfactory.hxx>
44 #if HAVE_FEATURE_JAVA
45 #include <jvmaccess/virtualmachine.hxx>
46 #include <com/sun/star/java/JavaVirtualMachine.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #endif
50 using namespace ::com::sun::star;
52 long ImplSysChildProc( void* pInst, SalObject* /* pObject */,
53 SalObjEvent nEvent, const void* /* pEvent */ )
55 VclPtr<SystemChildWindow> pWindow = static_cast<SystemChildWindow*>(pInst);
56 long nRet = 0;
58 switch ( nEvent )
60 case SalObjEvent::GetFocus:
61 // get focus, such that all handlers are called,
62 // as if this window gets the focus assuring
63 // that the frame does not steal it
64 pWindow->ImplGetFrameData()->mbSysObjFocus = true;
65 pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = true;
66 pWindow->ToTop( ToTopFlags::NoGrabFocus );
67 if( pWindow->IsDisposed() )
68 break;
69 pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = false;
70 pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = true;
71 pWindow->GrabFocus();
72 if( pWindow->IsDisposed() )
73 break;
74 pWindow->ImplGetFrameData()->mbInSysObjFocusHdl = false;
75 break;
77 case SalObjEvent::LoseFocus:
78 // trigger a LoseFocus which matches the status
79 // of the window with matching Activate-Status
80 pWindow->ImplGetFrameData()->mbSysObjFocus = false;
81 if ( !pWindow->ImplGetFrameData()->mnFocusId )
83 pWindow->ImplGetFrameData()->mbStartFocusState = true;
84 pWindow->ImplGetFrameData()->mnFocusId = Application::PostUserEvent( LINK( pWindow->ImplGetFrameWindow(), vcl::Window, ImplAsyncFocusHdl ), nullptr, true );
86 break;
88 case SalObjEvent::ToTop:
89 pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = true;
90 if ( !Application::GetFocusWindow() || pWindow->HasChildPathFocus() )
91 pWindow->ToTop( ToTopFlags::NoGrabFocus );
92 else
93 pWindow->ToTop();
94 if( pWindow->IsDisposed() )
95 break;
96 pWindow->GrabFocus();
97 if( pWindow->IsDisposed() )
98 break;
99 pWindow->ImplGetFrameData()->mbInSysObjToTopHdl = false;
100 break;
102 default: break;
105 return nRet;
108 void SystemChildWindow::ImplInitSysChild( vcl::Window* pParent, WinBits nStyle, SystemWindowData *pData, bool bShow )
110 mpWindowImpl->mpSysObj = ImplGetSVData()->mpDefInst->CreateObject( pParent->ImplGetFrame(), pData, bShow );
112 Window::ImplInit( pParent, nStyle, nullptr );
114 // we do not paint if it is the right SysChild
115 if ( GetSystemData() )
117 mpWindowImpl->mpSysObj->SetCallback( this, ImplSysChildProc );
118 SetParentClipMode( ParentClipMode::Clip );
119 SetBackground();
123 SystemChildWindow::SystemChildWindow( vcl::Window* pParent, WinBits nStyle ) :
124 Window( WINDOW_SYSTEMCHILDWINDOW )
126 ImplInitSysChild( pParent, nStyle, nullptr );
129 SystemChildWindow::SystemChildWindow( vcl::Window* pParent, WinBits nStyle, SystemWindowData *pData, bool bShow ) :
130 Window( WINDOW_SYSTEMCHILDWINDOW )
132 ImplInitSysChild( pParent, nStyle, pData, bShow );
135 SystemChildWindow::~SystemChildWindow()
137 disposeOnce();
140 void SystemChildWindow::dispose()
142 Hide();
143 if ( mpWindowImpl && mpWindowImpl->mpSysObj )
145 ImplGetSVData()->mpDefInst->DestroyObject( mpWindowImpl->mpSysObj );
146 mpWindowImpl->mpSysObj = nullptr;
148 Window::dispose();
151 const SystemEnvData* SystemChildWindow::GetSystemData() const
153 if ( mpWindowImpl->mpSysObj )
154 return mpWindowImpl->mpSysObj->GetSystemData();
155 else
156 return nullptr;
159 void SystemChildWindow::EnableEraseBackground( bool bEnable )
161 if ( mpWindowImpl->mpSysObj )
162 mpWindowImpl->mpSysObj->EnableEraseBackground( bEnable );
165 void SystemChildWindow::SetLeaveEnterBackgrounds(const css::uno::Sequence<css::uno::Any>& rLeaveArgs, const css::uno::Sequence<css::uno::Any>& rEnterArgs)
167 if (mpWindowImpl->mpSysObj)
168 mpWindowImpl->mpSysObj->SetLeaveEnterBackgrounds(rLeaveArgs, rEnterArgs);
171 void SystemChildWindow::SetForwardKey( bool bEnable )
173 if ( mpWindowImpl->mpSysObj )
174 mpWindowImpl->mpSysObj->SetForwardKey( bEnable );
177 sal_IntPtr SystemChildWindow::GetParentWindowHandle()
179 sal_IntPtr nRet = 0;
181 #if defined(_WIN32)
182 nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->hWnd );
183 #elif defined MACOSX
184 // FIXME: this is wrong
185 nRet = reinterpret_cast< sal_IntPtr >( GetSystemData()->mpNSView );
186 #elif defined ANDROID
187 // Nothing
188 #elif defined IOS
189 // Nothing
190 #elif defined UNX
191 nRet = (sal_IntPtr) GetSystemData()->aWindow;
192 #endif
194 return nRet;
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */