tdf#164393 Change themes UI as per UX feedback
[LibreOffice.git] / vcl / source / window / syschild.cxx
blobc03df17ba1d53621a502cdd395d0ea71b10d2f74
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 <vcl/window.hxx>
21 #include <vcl/sysdata.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/syschild.hxx>
25 #include <window.h>
26 #include <salframe.hxx>
27 #include <salinst.hxx>
28 #include <salobj.hxx>
29 #include <svdata.hxx>
31 using namespace ::com::sun::star;
33 static void ImplSysChildProc( SystemChildWindow* pInst, SalObjEvent nEvent )
35 VclPtr<SystemChildWindow> pWindow = pInst;
37 switch ( nEvent )
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() )
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;
56 case SalObjEvent::LoseFocus:
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 )
64 pWindow->ImplGetFrameData()->mbStartFocusState = true;
65 pWindow->ImplGetFrameData()->mnFocusId = Application::PostUserEvent( LINK( pWindow->ImplGetFrameWindow(), vcl::Window, ImplAsyncFocusHdl ), nullptr, true );
67 break;
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;
83 default: break;
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 );
98 SetBackground();
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()
116 disposeOnce();
119 void SystemChildWindow::dispose()
121 Hide();
122 if ( mpWindowImpl && mpWindowImpl->mpSysObj )
124 ImplGetSVData()->mpDefInst->DestroyObject( mpWindowImpl->mpSysObj );
125 mpWindowImpl->mpSysObj = nullptr;
127 Window::dispose();
130 const SystemEnvData* SystemChildWindow::GetSystemData() const
132 if ( mpWindowImpl->mpSysObj )
133 return &mpWindowImpl->mpSysObj->GetSystemData();
134 else
135 return nullptr;
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
165 sal_IntPtr nRet = 0;
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
177 nRet = GetSystemData()->GetWindowHandle(ImplGetFrame());
178 #endif
180 return nRet;
183 void* SystemChildWindow::CreateGStreamerSink()
185 return ImplGetSVData()->mpDefInst->CreateGStreamerSink(this);
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
194 if (!aWindow && pReference)
195 pReference->ResolveWindowHandle(const_cast<SystemEnvData&>(*this));
196 return aWindow;
198 #endif
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */