xref: /aoo41x/main/toolkit/source/awt/vclxwindow1.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_toolkit.hxx"
30 
31 #include <tools/svwin.h>
32 #include <toolkit/awt/vclxwindow.hxx>
33 #include <com/sun/star/beans/NamedValue.hpp>
34 #ifndef _SV_WORKWIN
35 #include <vcl/wrkwin.hxx>
36 #endif
37 #include <vcl/window.hxx>
38 
39 #ifdef WNT
40 #include <tools/prewin.h>
41 #include <windows.h>
42 #include <tools/postwin.h>
43 #elif defined ( QUARTZ )
44 #include "premac.h"
45 #include <Cocoa/Cocoa.h>
46 #include "postmac.h"
47 #endif
48 #include <vcl/sysdata.hxx>
49 
50 /// helper method to set a window handle into a SystemParentData struct
51 void VCLXWindow::SetSystemParent_Impl( const com::sun::star::uno::Any& rHandle )
52 {
53 	// does only work for WorkWindows
54 	Window *pWindow = GetWindow();
55 	if ( pWindow->GetType() != WINDOW_WORKWINDOW )
56 	{
57 		::com::sun::star::uno::Exception *pException =
58 			new ::com::sun::star::uno::RuntimeException;
59 		pException->Message = ::rtl::OUString::createFromAscii( "not a work window" );
60 		throw pException;
61 	}
62 
63     // use sal_Int64 here to accomodate all int types
64     // uno::Any shift operator whill upcast if necessary
65     sal_Int64 nHandle = 0;
66     sal_Bool  bXEmbed = sal_False;
67     bool bThrow = false;
68     if( ! (rHandle >>= nHandle) )
69     {
70         com::sun::star::uno::Sequence< com::sun::star::beans::NamedValue > aProps;
71         if( rHandle >>= aProps )
72         {
73             const int nProps = aProps.getLength();
74             const com::sun::star::beans::NamedValue* pProps = aProps.getConstArray();
75             for( int i = 0; i < nProps; i++ )
76             {
77                 if( pProps[i].Name.equalsAscii( "WINDOW" ) )
78                     pProps[i].Value >>= nHandle;
79                 else if( pProps[i].Name.equalsAscii( "XEMBED" ) )
80                     pProps[i].Value >>= bXEmbed;
81             }
82         }
83         else
84             bThrow = true;
85     }
86     if( bThrow )
87     {
88         ::com::sun::star::uno::Exception *pException =
89             new ::com::sun::star::uno::RuntimeException;
90         pException->Message = ::rtl::OUString::createFromAscii( "incorrect window handle type" );
91         throw pException;
92     }
93     // create system parent data
94 	SystemParentData aSysParentData;
95 	aSysParentData.nSize = sizeof ( SystemParentData );
96 #if defined( WNT ) || defined ( OS2 )
97 	aSysParentData.hWnd = (HWND) nHandle;
98 #elif defined( QUARTZ )
99 	aSysParentData.pView = reinterpret_cast<NSView*>(nHandle);
100 #elif defined( UNX )
101 	aSysParentData.aWindow = (long)nHandle;
102     aSysParentData.bXEmbedSupport = bXEmbed;
103 #endif
104 
105 	// set system parent
106 	((WorkWindow*)pWindow)->SetPluginParent( &aSysParentData );
107 }
108 
109