Line data Source code
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 <com/sun/star/lang/SystemDependent.hpp>
21 : #include <com/sun/star/awt/SystemDependentXWindow.hpp>
22 :
23 : #if defined ( MACOSX )
24 : #include "premac.h"
25 : #include <Cocoa/Cocoa.h>
26 : #include "postmac.h"
27 : #endif
28 :
29 : #include <vcl/syschild.hxx>
30 : #include <vcl/sysdata.hxx>
31 : #include <cppuhelper/typeprovider.hxx>
32 : #include <comphelper/sequence.hxx>
33 :
34 : #include <toolkit/awt/vclxtopwindow.hxx>
35 : #include <toolkit/awt/vclxmenu.hxx>
36 : #include <toolkit/helper/macros.hxx>
37 :
38 : #include <vcl/wrkwin.hxx>
39 : #include <vcl/syswin.hxx>
40 : #include <vcl/menu.hxx>
41 : #include <vcl/svapp.hxx>
42 :
43 : using ::com::sun::star::uno::RuntimeException;
44 : using ::com::sun::star::uno::Sequence;
45 : using ::com::sun::star::uno::Type;
46 : using ::com::sun::star::uno::Any;
47 : using ::com::sun::star::lang::IndexOutOfBoundsException;
48 :
49 0 : VCLXTopWindow_Base::VCLXTopWindow_Base( const bool _bSupportSystemWindowPeer )
50 0 : :m_bWHWND( _bSupportSystemWindowPeer )
51 : {
52 0 : }
53 :
54 0 : VCLXTopWindow_Base::~VCLXTopWindow_Base()
55 : {
56 0 : }
57 :
58 0 : Any VCLXTopWindow_Base::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
59 : {
60 0 : ::com::sun::star::uno::Any aRet( VCLXTopWindow_XBase::queryInterface( rType ) );
61 :
62 : // do not expose XSystemDependentWindowPeer if we do not have a system window handle
63 0 : if ( !aRet.hasValue() && m_bWHWND )
64 0 : aRet = VCLXTopWindow_SBase::queryInterface( rType );
65 :
66 0 : return aRet;
67 : }
68 :
69 0 : Sequence< Type > VCLXTopWindow_Base::getTypes() throw(RuntimeException, std::exception)
70 : {
71 0 : Sequence< Type > aTypes( VCLXTopWindow_XBase::getTypes() );
72 0 : if ( m_bWHWND )
73 0 : aTypes = ::comphelper::concatSequences( aTypes, VCLXTopWindow_SBase::getTypes() );
74 0 : return aTypes;
75 : }
76 :
77 0 : ::com::sun::star::uno::Any VCLXTopWindow_Base::getWindowHandle( const ::com::sun::star::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 SystemType ) throw(::com::sun::star::uno::RuntimeException, std::exception)
78 : {
79 0 : SolarMutexGuard aGuard;
80 :
81 : // TODO, check the process id
82 0 : ::com::sun::star::uno::Any aRet;
83 0 : Window* pWindow = GetWindowImpl();
84 0 : if ( pWindow )
85 : {
86 0 : const SystemEnvData* pSysData = ((SystemWindow *)pWindow)->GetSystemData();
87 0 : if( pSysData )
88 : {
89 : #if (defined WNT)
90 : if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 )
91 : {
92 : aRet <<= (sal_IntPtr)pSysData->hWnd;
93 : }
94 : #elif (defined MACOSX)
95 : if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_MAC )
96 : {
97 : aRet <<= (sal_IntPtr)pSysData->mpNSView;
98 : }
99 : #elif (defined ANDROID)
100 : // Nothing
101 : (void) SystemType;
102 : #elif (defined IOS)
103 : // Nothing
104 : (void) SystemType;
105 : #elif (defined UNX)
106 0 : if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW )
107 : {
108 0 : ::com::sun::star::awt::SystemDependentXWindow aSD;
109 0 : aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay));
110 0 : aSD.WindowHandle = pSysData->aWindow;
111 0 : aRet <<= aSD;
112 : }
113 : #endif
114 : }
115 : }
116 0 : return aRet;
117 : }
118 :
119 0 : void VCLXTopWindow_Base::addTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException, std::exception)
120 : {
121 0 : SolarMutexGuard aGuard;
122 :
123 0 : GetTopWindowListenersImpl().addInterface( rxListener );
124 0 : }
125 :
126 0 : void VCLXTopWindow_Base::removeTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException, std::exception)
127 : {
128 0 : SolarMutexGuard aGuard;
129 :
130 0 : GetTopWindowListenersImpl().removeInterface( rxListener );
131 0 : }
132 :
133 0 : void VCLXTopWindow_Base::toFront( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
134 : {
135 0 : SolarMutexGuard aGuard;
136 :
137 0 : Window* pWindow = GetWindowImpl();
138 0 : if ( pWindow )
139 0 : ((WorkWindow*)pWindow)->ToTop( TOTOP_RESTOREWHENMIN );
140 0 : }
141 :
142 0 : void VCLXTopWindow_Base::toBack( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
143 : {
144 0 : }
145 :
146 0 : void VCLXTopWindow_Base::setMenuBar( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar >& rxMenu ) throw(::com::sun::star::uno::RuntimeException, std::exception)
147 : {
148 0 : SolarMutexGuard aGuard;
149 :
150 0 : SystemWindow* pWindow = (SystemWindow*) GetWindowImpl();
151 0 : if ( pWindow )
152 : {
153 0 : pWindow->SetMenuBar( NULL );
154 0 : if ( rxMenu.is() )
155 : {
156 0 : VCLXMenu* pMenu = VCLXMenu::GetImplementation( rxMenu );
157 0 : if ( pMenu && !pMenu->IsPopupMenu() )
158 0 : pWindow->SetMenuBar( (MenuBar*) pMenu->GetMenu() );
159 : }
160 : }
161 0 : mxMenuBar = rxMenu;
162 0 : }
163 :
164 :
165 0 : sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMaximized() throw (RuntimeException, std::exception)
166 : {
167 0 : SolarMutexGuard aGuard;
168 :
169 0 : const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() );
170 0 : if ( !pWindow )
171 0 : return sal_False;
172 :
173 0 : return pWindow->IsMaximized();
174 : }
175 :
176 :
177 0 : void SAL_CALL VCLXTopWindow_Base::setIsMaximized( sal_Bool _ismaximized ) throw (RuntimeException, std::exception)
178 : {
179 0 : SolarMutexGuard aGuard;
180 :
181 0 : WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() );
182 0 : if ( !pWindow )
183 0 : return;
184 :
185 0 : pWindow->Maximize( _ismaximized );
186 : }
187 :
188 :
189 0 : sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMinimized() throw (RuntimeException, std::exception)
190 : {
191 0 : SolarMutexGuard aGuard;
192 :
193 0 : const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() );
194 0 : if ( !pWindow )
195 0 : return sal_False;
196 :
197 0 : return pWindow->IsMinimized();
198 : }
199 :
200 :
201 0 : void SAL_CALL VCLXTopWindow_Base::setIsMinimized( sal_Bool _isMinimized ) throw (RuntimeException, std::exception)
202 : {
203 0 : SolarMutexGuard aGuard;
204 :
205 0 : WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() );
206 0 : if ( !pWindow )
207 0 : return;
208 :
209 0 : _isMinimized ? pWindow->Minimize() : pWindow->Restore();
210 : }
211 :
212 :
213 0 : ::sal_Int32 SAL_CALL VCLXTopWindow_Base::getDisplay() throw (RuntimeException, std::exception)
214 : {
215 0 : SolarMutexGuard aGuard;
216 :
217 0 : const SystemWindow* pWindow = dynamic_cast< const SystemWindow* >( GetWindowImpl() );
218 0 : if ( !pWindow )
219 0 : return 0;
220 :
221 0 : return pWindow->GetScreenNumber();
222 : }
223 :
224 :
225 0 : void SAL_CALL VCLXTopWindow_Base::setDisplay( ::sal_Int32 _display ) throw (RuntimeException, IndexOutOfBoundsException, std::exception)
226 : {
227 0 : SolarMutexGuard aGuard;
228 :
229 0 : if ( ( _display < 0 ) || ( _display >= (sal_Int32)Application::GetScreenCount() ) )
230 0 : throw IndexOutOfBoundsException();
231 :
232 0 : SystemWindow* pWindow = dynamic_cast< SystemWindow* >( GetWindowImpl() );
233 0 : if ( !pWindow )
234 0 : return;
235 :
236 0 : pWindow->SetScreenNumber( _display );
237 : }
238 :
239 :
240 : // class VCLXTopWindow
241 :
242 :
243 0 : void VCLXTopWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
244 : {
245 0 : VCLXContainer::ImplGetPropertyIds( rIds );
246 0 : }
247 :
248 0 : VCLXTopWindow::VCLXTopWindow(bool bWHWND)
249 0 : : VCLXTopWindow_Base( bWHWND )
250 : {
251 0 : }
252 :
253 0 : VCLXTopWindow::~VCLXTopWindow()
254 : {
255 0 : }
256 :
257 0 : Window* VCLXTopWindow::GetWindowImpl()
258 : {
259 0 : return VCLXContainer::GetWindow();
260 : }
261 :
262 0 : ::cppu::OInterfaceContainerHelper& VCLXTopWindow::GetTopWindowListenersImpl()
263 : {
264 0 : return GetTopWindowListeners();
265 : }
266 :
267 : // ::com::sun::star::uno::XInterface
268 0 : ::com::sun::star::uno::Any VCLXTopWindow::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception)
269 : {
270 0 : ::com::sun::star::uno::Any aRet( VCLXTopWindow_Base::queryInterface( rType ) );
271 :
272 0 : if ( !aRet.hasValue() )
273 0 : aRet = VCLXContainer::queryInterface( rType );
274 :
275 0 : return aRet;
276 : }
277 :
278 0 : ::com::sun::star::uno::Sequence< sal_Int8 > VCLXTopWindow::getImplementationId() throw(::com::sun::star::uno::RuntimeException, std::exception)
279 : {
280 0 : return css::uno::Sequence<sal_Int8>();
281 : }
282 :
283 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXTopWindow::getTypes() throw(::com::sun::star::uno::RuntimeException, std::exception)
284 : {
285 0 : return ::comphelper::concatSequences( VCLXTopWindow_Base::getTypes(), VCLXContainer::getTypes() );
286 : }
287 :
288 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|