1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_toolkit.hxx"
26 
27 #include <tools/svwin.h>
28 #include <toolkit/awt/vclxwindow.hxx>
29 #include <com/sun/star/beans/NamedValue.hpp>
30 #ifndef _SV_WORKWIN
31 #include <vcl/wrkwin.hxx>
32 #endif
33 #include <vcl/window.hxx>
34 
35 #ifdef WNT
36 #include <tools/prewin.h>
37 #include <windows.h>
38 #include <tools/postwin.h>
39 #elif defined ( OS2 )
40 #include <svpm.h>
41 #elif defined ( QUARTZ )
42 #include "premac.h"
43 #include <Cocoa/Cocoa.h>
44 #include "postmac.h"
45 #endif
46 #include <vcl/sysdata.hxx>
47 
48 /// helper method to set a window handle into a SystemParentData struct
SetSystemParent_Impl(const com::sun::star::uno::Any & rHandle)49 void VCLXWindow::SetSystemParent_Impl( const com::sun::star::uno::Any& rHandle )
50 {
51 	// does only work for WorkWindows
52 	Window *pWindow = GetWindow();
53 	if ( pWindow->GetType() != WINDOW_WORKWINDOW )
54 	{
55 		::com::sun::star::uno::Exception *pException =
56 			new ::com::sun::star::uno::RuntimeException;
57 		pException->Message = ::rtl::OUString::createFromAscii( "not a work window" );
58 		throw pException;
59 	}
60 
61     // use sal_Int64 here to accomodate all int types
62     // uno::Any shift operator whill upcast if necessary
63     sal_Int64 nHandle = 0;
64     sal_Bool  bXEmbed = sal_False;
65     bool bThrow = false;
66     if( ! (rHandle >>= nHandle) )
67     {
68         com::sun::star::uno::Sequence< com::sun::star::beans::NamedValue > aProps;
69         if( rHandle >>= aProps )
70         {
71             const int nProps = aProps.getLength();
72             const com::sun::star::beans::NamedValue* pProps = aProps.getConstArray();
73             for( int i = 0; i < nProps; i++ )
74             {
75                 if( pProps[i].Name.equalsAscii( "WINDOW" ) )
76                     pProps[i].Value >>= nHandle;
77                 else if( pProps[i].Name.equalsAscii( "XEMBED" ) )
78                     pProps[i].Value >>= bXEmbed;
79             }
80         }
81         else
82             bThrow = true;
83     }
84     if( bThrow )
85     {
86         ::com::sun::star::uno::Exception *pException =
87             new ::com::sun::star::uno::RuntimeException;
88         pException->Message = ::rtl::OUString::createFromAscii( "incorrect window handle type" );
89         throw pException;
90     }
91     // create system parent data
92 	SystemParentData aSysParentData;
93 	aSysParentData.nSize = sizeof ( SystemParentData );
94 #if defined( WNT ) || defined ( OS2 )
95 	aSysParentData.hWnd = (HWND) nHandle;
96 #elif defined( QUARTZ )
97 	aSysParentData.pView = reinterpret_cast<NSView*>(nHandle);
98 #elif defined( UNX )
99 	aSysParentData.aWindow = (long)nHandle;
100     aSysParentData.bXEmbedSupport = bXEmbed;
101 #endif
102 
103 	// set system parent
104 	((WorkWindow*)pWindow)->SetPluginParent( &aSysParentData );
105 }
106 
107