xref: /trunk/main/toolkit/source/layout/core/helper.cxx (revision b0724fc6)
1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b0724fc6SAndrew Rist  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19*b0724fc6SAndrew Rist  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "helper.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <assert.h>
27cdf0e10cSrcweir #include <list>
28cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
29cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
30cdf0e10cSrcweir #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
31cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "proplist.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #if TEST_LAYOUT && !defined( DBG_UTIL )
37cdf0e10cSrcweir #undef DBG_ERROR
38cdf0e10cSrcweir #define DBG_ERROR OSL_TRACE
39cdf0e10cSrcweir #undef DBG_ERROR1
40cdf0e10cSrcweir #define DBG_ERROR1 OSL_TRACE
41cdf0e10cSrcweir #undef DBG_ERROR2
42cdf0e10cSrcweir #define DBG_ERROR2 OSL_TRACE
43cdf0e10cSrcweir #endif /* TEST_LAYOUT && !DBG_UTIL */
44cdf0e10cSrcweir 
45cdf0e10cSrcweir namespace layoutimpl
46cdf0e10cSrcweir {
47cdf0e10cSrcweir using namespace com::sun::star;
48cdf0e10cSrcweir using rtl::OUString;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir uno::Reference< awt::XWindowPeer >
getParent(uno::Reference<uno::XInterface> xRef)51cdf0e10cSrcweir getParent( uno::Reference< uno::XInterface > xRef )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     do
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir         uno::Reference< awt::XWindowPeer > xPeer( xRef, uno::UNO_QUERY );
56cdf0e10cSrcweir         if ( xPeer.is() )
57cdf0e10cSrcweir             return xPeer;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         uno::Reference< awt::XLayoutContainer > xCont( xRef, uno::UNO_QUERY );
60cdf0e10cSrcweir         if ( xCont.is() )
61cdf0e10cSrcweir             xRef = xCont->getParent();
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir     while ( xRef.is() );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     return uno::Reference< awt::XWindowPeer >();
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #if 0
69cdf0e10cSrcweir static uno::Reference< awt::XWindowPeer >
70cdf0e10cSrcweir getToplevel( uno::Reference< uno::XInterface > xRef )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     uno::Reference< awt::XWindowPeer > xTop, i;
73cdf0e10cSrcweir     while ( ( i = uno::Reference< awt::XWindowPeer >( xRef, uno::UNO_QUERY ) ).is() )
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         xTop = i;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         uno::Reference< awt::XLayoutContainer > xCont( xRef, uno::UNO_QUERY );
78cdf0e10cSrcweir         if ( xCont.is() )
79cdf0e10cSrcweir             xRef = xCont->getParent();
80cdf0e10cSrcweir         else
81cdf0e10cSrcweir             xRef = uno::Reference< awt::XWindowPeer >();
82cdf0e10cSrcweir     }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     return xTop;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir #endif
87cdf0e10cSrcweir 
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir #include "bin.hxx"
91cdf0e10cSrcweir #include "box.hxx"
92cdf0e10cSrcweir #include "dialogbuttonhbox.hxx"
93cdf0e10cSrcweir #include "flow.hxx"
94cdf0e10cSrcweir #include "localized-string.hxx"
95cdf0e10cSrcweir #include "table.hxx"
96cdf0e10cSrcweir 
97cdf0e10cSrcweir namespace layoutimpl
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 
100cdf0e10cSrcweir oslModule WidgetFactory::mSfx2Library = 0;
101cdf0e10cSrcweir WindowCreator WidgetFactory::mSfx2CreateWidget = 0;
102cdf0e10cSrcweir 
createContainer(OUString const & name)103cdf0e10cSrcweir uno::Reference <awt::XLayoutContainer> WidgetFactory::createContainer (OUString const& name)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     uno::Reference< awt::XLayoutContainer > xPeer;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     if ( name.equalsAscii( "hbox" ) )
108cdf0e10cSrcweir         xPeer = uno::Reference< awt::XLayoutContainer >( new HBox() );
109cdf0e10cSrcweir     else if ( name.equalsAscii( "vbox" ) )
110cdf0e10cSrcweir         xPeer = uno::Reference< awt::XLayoutContainer >( new VBox() );
111cdf0e10cSrcweir     else if ( name.equalsAscii( "table" ) )
112cdf0e10cSrcweir         xPeer = uno::Reference< awt::XLayoutContainer >( new Table() );
113cdf0e10cSrcweir     else if ( name.equalsAscii( "flow" ) )
114cdf0e10cSrcweir         xPeer = uno::Reference< awt::XLayoutContainer >( new Flow() );
115cdf0e10cSrcweir     else if ( name.equalsAscii( "bin" ) )
116cdf0e10cSrcweir         xPeer = uno::Reference< awt::XLayoutContainer >( new Bin() );
117cdf0e10cSrcweir     else if ( name.equalsAscii( "min-size" ) )
118cdf0e10cSrcweir         xPeer = uno::Reference< awt::XLayoutContainer >( new MinSize() );
119cdf0e10cSrcweir     else if ( name.equalsAscii( "align" ) )
120cdf0e10cSrcweir         xPeer = uno::Reference< awt::XLayoutContainer >( new Align() );
121cdf0e10cSrcweir     else if ( name.equalsAscii( "dialogbuttonhbox" ) )
122cdf0e10cSrcweir         xPeer = uno::Reference< awt::XLayoutContainer >( new DialogButtonHBox() );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     return xPeer;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
toolkitCreateWidget(uno::Reference<awt::XToolkit> xToolkit,uno::Reference<uno::XInterface> xParent,OUString const & name,long properties)127cdf0e10cSrcweir uno::Reference <awt::XLayoutConstrains> WidgetFactory::toolkitCreateWidget (uno::Reference <awt::XToolkit> xToolkit, uno::Reference <uno::XInterface> xParent, OUString const& name, long properties)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xPeer;
130cdf0e10cSrcweir     bool bToplevel = !xParent.is();
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     // UNO Control Widget
133cdf0e10cSrcweir     awt::WindowDescriptor desc;
134cdf0e10cSrcweir     if ( bToplevel )
135cdf0e10cSrcweir         desc.Type = awt::WindowClass_TOP;
136cdf0e10cSrcweir     else
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         desc.Type = awt::WindowClass_SIMPLE;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir #if 0
141cdf0e10cSrcweir         // top container -- a wrapper for framewindow -- is de-coupled
142cdf0e10cSrcweir         // from awt::XWindowPeer. So, getParent() fails at it.
143cdf0e10cSrcweir         uno::Reference< awt::XWindowPeer > xWinParent = getParent( xParent );
144cdf0e10cSrcweir #else
145cdf0e10cSrcweir         uno::Reference< awt::XWindowPeer > xWinParent( xParent, uno::UNO_QUERY );
146cdf0e10cSrcweir #endif
147cdf0e10cSrcweir         assert( xParent.is() );
148cdf0e10cSrcweir         assert( xWinParent.is() );
149cdf0e10cSrcweir         /*
150cdf0e10cSrcweir           With the new three layer instarr/rpath feature, when
151cdf0e10cSrcweir           prepending toolkit/unxlngx6.pro/lib or $SOLARVER/lib to
152cdf0e10cSrcweir           LD_LIBRARY_PATH, VCLXWindow::GetImplementation returns 0x0
153cdf0e10cSrcweir           vclxtoolkit::ImplCreateWindow failing to create any widget;
154cdf0e10cSrcweir           although it succeeds here.
155cdf0e10cSrcweir 
156cdf0e10cSrcweir           While developing, one now must copy libtlx.so to
157cdf0e10cSrcweir           $OOO_INSTALL_PREFIX/openoffice.org/basis3.0/program/libtklx.so
158cdf0e10cSrcweir           each time.
159cdf0e10cSrcweir         */
160cdf0e10cSrcweir 		VCLXWindow* parentComponent = VCLXWindow::GetImplementation( xWinParent );
161cdf0e10cSrcweir         if ( !parentComponent )
162cdf0e10cSrcweir             throw uno::RuntimeException(
163cdf0e10cSrcweir                 OUString::createFromAscii( "parent has no implementation" ),
164cdf0e10cSrcweir                 uno::Reference< uno::XInterface >() );
165cdf0e10cSrcweir         desc.Parent = xWinParent;
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     desc.ParentIndex = 0;
169cdf0e10cSrcweir     // debugging help ...
170cdf0e10cSrcweir     desc.Bounds.X = 0;
171cdf0e10cSrcweir     desc.Bounds.Y = 0;
172cdf0e10cSrcweir     desc.Bounds.Width = 300;
173cdf0e10cSrcweir     desc.Bounds.Height = 200;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     desc.WindowAttributes = properties;
176cdf0e10cSrcweir     desc.WindowServiceName = name;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     uno::Reference< awt::XWindowPeer > xWinPeer;
179cdf0e10cSrcweir     try
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         OSL_TRACE("Asking toolkit: %s", OUSTRING_CSTR( desc.WindowServiceName ) );
182cdf0e10cSrcweir         xWinPeer = xToolkit->createWindow( desc );
183cdf0e10cSrcweir         if ( !xWinPeer.is() )
184cdf0e10cSrcweir             throw uno::RuntimeException(
185cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot create peer" ) ),
186cdf0e10cSrcweir                 uno::Reference< uno::XInterface >() );
187cdf0e10cSrcweir         xPeer = uno::Reference< awt::XLayoutConstrains >( xWinPeer, uno::UNO_QUERY );
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir     catch( uno::Exception & )
190cdf0e10cSrcweir     {
191cdf0e10cSrcweir         DBG_ERROR1( "Warning: %s is not a recognized type\n", OUSTRING_CSTR( name ) );
192cdf0e10cSrcweir         return uno::Reference< awt::XLayoutConstrains >();
193cdf0e10cSrcweir     }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir #if 0 // This shadows the show="false" property and seems otherwise
196cdf0e10cSrcweir       // unnecessary
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     // default to visible, let then people change it on properties
199cdf0e10cSrcweir     if ( ! bToplevel )
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         uno::Reference< awt::XWindow> xWindow( xPeer, uno::UNO_QUERY );
202cdf0e10cSrcweir         if ( xWindow.is() )
203cdf0e10cSrcweir             xWindow->setVisible( true );
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir #endif
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     return xPeer;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir uno::Reference< awt::XLayoutConstrains >
createWidget(uno::Reference<awt::XToolkit> xToolkit,uno::Reference<uno::XInterface> xParent,OUString const & name,long properties)211cdf0e10cSrcweir WidgetFactory::createWidget (uno::Reference< awt::XToolkit > xToolkit, uno::Reference< uno::XInterface > xParent, OUString const& name, long properties)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xPeer;
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     xPeer = uno::Reference <awt::XLayoutConstrains> (createContainer (name), uno::UNO_QUERY);
216cdf0e10cSrcweir     if ( xPeer.is() )
217cdf0e10cSrcweir         return xPeer;
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     xPeer = implCreateWidget (xParent, name, properties);
220cdf0e10cSrcweir     if (xPeer.is ())
221cdf0e10cSrcweir         return xPeer;
222cdf0e10cSrcweir 
223cdf0e10cSrcweir #define FIXED_INFO 1
224cdf0e10cSrcweir #if FIXED_INFO
225cdf0e10cSrcweir     OUString tName = name;
226cdf0e10cSrcweir     // FIXME
227cdf0e10cSrcweir     if ( name.equalsAscii( "fixedinfo" ) )
228cdf0e10cSrcweir         tName = OUString::createFromAscii( "fixedtext" );
229cdf0e10cSrcweir     xPeer = toolkitCreateWidget (xToolkit, xParent, tName, properties);
230cdf0e10cSrcweir #else
231cdf0e10cSrcweir     xPeer = toolkitCreateWidget (xToolkit, xParent, name, properties);
232cdf0e10cSrcweir #endif
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     return xPeer;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
PropHelper()237cdf0e10cSrcweir PropHelper::PropHelper() : LockHelper()
238cdf0e10cSrcweir                          , cppu::OPropertySetHelper( maBrdcstHelper )
239cdf0e10cSrcweir                          , pHelper( NULL )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir void
addProp(const char * pName,sal_Int32 nNameLen,rtl_TextEncoding e,uno::Type aType,void * pPtr)244cdf0e10cSrcweir PropHelper::addProp (const char *pName, sal_Int32 nNameLen, rtl_TextEncoding e,
245cdf0e10cSrcweir                      uno::Type aType, void *pPtr)
246cdf0e10cSrcweir {
247cdf0e10cSrcweir     // this sucks rocks for effiency ...
248cdf0e10cSrcweir     PropDetails aDetails;
249cdf0e10cSrcweir     aDetails.aName = rtl::OUString::intern( pName, nNameLen, e );
250cdf0e10cSrcweir     aDetails.aType = aType;
251cdf0e10cSrcweir     aDetails.pValue = pPtr;
252cdf0e10cSrcweir     maDetails.push_back( aDetails );
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir cppu::IPropertyArrayHelper & SAL_CALL
getInfoHelper()256cdf0e10cSrcweir PropHelper::getInfoHelper()
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     if ( ! pHelper )
259cdf0e10cSrcweir     {
260cdf0e10cSrcweir         uno::Sequence< beans::Property > aProps( maDetails.size() );
261cdf0e10cSrcweir         for ( unsigned int i = 0; i < maDetails.size(); i++)
262cdf0e10cSrcweir         {
263cdf0e10cSrcweir             aProps[i].Name = maDetails[i].aName;
264cdf0e10cSrcweir             aProps[i].Type = maDetails[i].aType;
265cdf0e10cSrcweir             aProps[i].Handle = i;
266cdf0e10cSrcweir             aProps[i].Attributes = 0;
267cdf0e10cSrcweir         }
268cdf0e10cSrcweir         pHelper = new cppu::OPropertyArrayHelper( aProps, false /* fixme: faster ? */ );
269cdf0e10cSrcweir 
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir     return *pHelper;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir sal_Bool SAL_CALL
convertFastPropertyValue(uno::Any & rConvertedValue,uno::Any & rOldValue,sal_Int32 nHandle,const uno::Any & rValue)275cdf0e10cSrcweir PropHelper::convertFastPropertyValue(
276cdf0e10cSrcweir     uno::Any & rConvertedValue,
277cdf0e10cSrcweir     uno::Any & rOldValue,
278cdf0e10cSrcweir     sal_Int32 nHandle,
279cdf0e10cSrcweir     const uno::Any& rValue )
280cdf0e10cSrcweir     throw (lang::IllegalArgumentException)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir     OSL_ASSERT( nHandle >= 0 && nHandle < (sal_Int32) maDetails.size() );
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     // FIXME: no Any::getValue ...
285cdf0e10cSrcweir     getFastPropertyValue( rOldValue, nHandle );
286cdf0e10cSrcweir     if ( rOldValue != rValue )
287cdf0e10cSrcweir     {
288cdf0e10cSrcweir         rConvertedValue = rValue;
289cdf0e10cSrcweir         return sal_True; // changed
290cdf0e10cSrcweir     }
291cdf0e10cSrcweir     else
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         rConvertedValue.clear();
294cdf0e10cSrcweir         rOldValue.clear();
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir     return sal_False;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 
300cdf0e10cSrcweir void SAL_CALL
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const uno::Any & rValue)301cdf0e10cSrcweir PropHelper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
302cdf0e10cSrcweir                                               const uno::Any& rValue )
303cdf0e10cSrcweir     throw (uno::Exception)
304cdf0e10cSrcweir {
305cdf0e10cSrcweir     OSL_ASSERT( nHandle >= 0 && nHandle < (sal_Int32) maDetails.size() );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     const PropDetails &rInfo = maDetails[ nHandle ];
308cdf0e10cSrcweir 
309cdf0e10cSrcweir     uno_type_assignData( rInfo.pValue, rInfo.aType.getTypeLibType(),
310cdf0e10cSrcweir                          rValue.pData, rValue.pType,
311cdf0e10cSrcweir                          0, 0, 0 );
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     if ( mpListener )
314cdf0e10cSrcweir         mpListener->propertiesChanged();
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir void SAL_CALL
getFastPropertyValue(uno::Any & rValue,sal_Int32 nHandle) const318cdf0e10cSrcweir PropHelper::getFastPropertyValue( uno::Any& rValue,
319cdf0e10cSrcweir                                   sal_Int32 nHandle ) const
320cdf0e10cSrcweir {
321cdf0e10cSrcweir     OSL_ASSERT( nHandle >= 0 && nHandle < (sal_Int32) maDetails.size() );
322cdf0e10cSrcweir     const PropDetails &rInfo = maDetails[ nHandle ];
323cdf0e10cSrcweir #if 0
324cdf0e10cSrcweir     switch ( rInfo.aType.getTypeClass() )
325cdf0e10cSrcweir     {
326cdf0e10cSrcweir #define MAP(classtype,ctype)                        \
327cdf0e10cSrcweir         case uno::TypeClass_##classtype:       \
328cdf0e10cSrcweir             rValue <<= *(ctype *)(rInfo.pValue);    \
329cdf0e10cSrcweir         break
330cdf0e10cSrcweir         MAP( DOUBLE, double );
331cdf0e10cSrcweir         MAP( SHORT, sal_Int16 );
332cdf0e10cSrcweir         MAP( LONG,  sal_Int32 );
333cdf0e10cSrcweir         MAP( UNSIGNED_SHORT, sal_uInt16 );
334cdf0e10cSrcweir         MAP( UNSIGNED_LONG, sal_uInt32 );
335cdf0e10cSrcweir         MAP( STRING, ::rtl::OUString );
336cdf0e10cSrcweir         default:
337cdf0e10cSrcweir             DBG_ERROR( "ERROR: unknown type to map!" );
338cdf0e10cSrcweir             break;
339cdf0e10cSrcweir     }
340cdf0e10cSrcweir #undef MAP
341cdf0e10cSrcweir #endif
342cdf0e10cSrcweir     rValue.setValue( rInfo.pValue, rInfo.aType );
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir ::com::sun::star::uno::Any
queryInterface(const::com::sun::star::uno::Type & rType)346cdf0e10cSrcweir PropHelper::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
347cdf0e10cSrcweir {
348cdf0e10cSrcweir     return OPropertySetHelper::queryInterface( rType );
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
getPropertySetInfo()351cdf0e10cSrcweir uno::Reference <beans::XPropertySetInfo> SAL_CALL PropHelper::getPropertySetInfo () throw (uno::RuntimeException)
352cdf0e10cSrcweir {
353cdf0e10cSrcweir     return css::uno::Reference <css::beans::XPropertySetInfo> (createPropertySetInfo (getInfoHelper ()));
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir } // namespace layoutimpl
357cdf0e10cSrcweir 
358cdf0e10cSrcweir #include <awt/vclxbutton.hxx>
359cdf0e10cSrcweir #include <awt/vclxdialog.hxx>
360cdf0e10cSrcweir #include <awt/vclxfixedline.hxx>
361cdf0e10cSrcweir #include <awt/vclxplugin.hxx>
362cdf0e10cSrcweir #include <awt/vclxscroller.hxx>
363cdf0e10cSrcweir #include <awt/vclxsplitter.hxx>
364cdf0e10cSrcweir #include <awt/vclxtabcontrol.hxx>
365cdf0e10cSrcweir #include <awt/vclxtabpage.hxx>
366cdf0e10cSrcweir #include <toolkit/awt/vclxtoolkit.hxx>
367cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
368cdf0e10cSrcweir #include <vcl/button.hxx>
369cdf0e10cSrcweir #include <vcl/dialog.hxx>
370cdf0e10cSrcweir #include <vcl/fixed.hxx>
371cdf0e10cSrcweir #include <vcl/tabctrl.hxx>
372cdf0e10cSrcweir #include <vcl/tabpage.hxx>
373cdf0e10cSrcweir #include <vcl/unohelp.hxx>
374cdf0e10cSrcweir 
375cdf0e10cSrcweir #include <layout/layout.hxx>
376cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx>
377cdf0e10cSrcweir #include <vcl/lstbox.hxx>
378cdf0e10cSrcweir #include <vcl.hxx>
379cdf0e10cSrcweir 
380cdf0e10cSrcweir #include <typeinfo>
381cdf0e10cSrcweir 
382cdf0e10cSrcweir namespace layoutimpl
383cdf0e10cSrcweir {
384cdf0e10cSrcweir 
implCreateWidget(uno::Reference<uno::XInterface> xParent,OUString name,long attributes)385cdf0e10cSrcweir uno::Reference <awt::XLayoutConstrains> WidgetFactory::implCreateWidget (uno::Reference <uno::XInterface> xParent, OUString name, long attributes)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir     Window* parent = 0;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir     if (VCLXWindow* parentComponent = VCLXWindow::GetImplementation (xParent))
390cdf0e10cSrcweir         parent = parentComponent->GetWindow ();
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     VCLXWindow* component = 0;
393cdf0e10cSrcweir     Window* window = 0; //sfx2CreateWindow (&component, parent, name, attributes);
394cdf0e10cSrcweir     if (!window)
395cdf0e10cSrcweir         window = layoutCreateWindow (&component, parent, name, attributes);
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     uno::Reference <awt::XLayoutConstrains> reference;
398cdf0e10cSrcweir     if (window)
399cdf0e10cSrcweir     {
400cdf0e10cSrcweir         window->SetCreatedWithToolkit( sal_True );
401cdf0e10cSrcweir         if ( component )
402cdf0e10cSrcweir             component->SetCreatedWithToolkit( true );
403cdf0e10cSrcweir         reference = component;
404cdf0e10cSrcweir         window->SetComponentInterface( component );
405cdf0e10cSrcweir         if ( attributes & awt::WindowAttribute::SHOW )
406cdf0e10cSrcweir             window->Show();
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir     return reference;
410cdf0e10cSrcweir }
411cdf0e10cSrcweir 
thisModule()412cdf0e10cSrcweir extern "C" { static void SAL_CALL thisModule() {} }
413cdf0e10cSrcweir 
sfx2CreateWindow(VCLXWindow ** component,Window * parent,OUString const & name,long & attributes)414cdf0e10cSrcweir Window* WidgetFactory::sfx2CreateWindow (VCLXWindow** component, Window* parent, OUString const& name, long& attributes)
415cdf0e10cSrcweir {
416cdf0e10cSrcweir     OSL_TRACE("Asking sfx2: %s", OUSTRING_CSTR (name));
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 	if (!mSfx2Library)
419cdf0e10cSrcweir 	{
420cdf0e10cSrcweir 		OUString libraryName = ::vcl::unohelper::CreateLibraryName ("sfx", sal_True);
421cdf0e10cSrcweir         mSfx2Library = osl_loadModuleRelative (&thisModule, libraryName.pData, SAL_LOADMODULE_DEFAULT);
422cdf0e10cSrcweir         if (mSfx2Library)
423cdf0e10cSrcweir         {
424cdf0e10cSrcweir             OUString functionName (RTL_CONSTASCII_USTRINGPARAM ("CreateWindow"));
425cdf0e10cSrcweir             mSfx2CreateWidget = (WindowCreator) osl_getFunctionSymbol (mSfx2Library, functionName.pData);
426cdf0e10cSrcweir         }
427cdf0e10cSrcweir     }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 	if (mSfx2CreateWidget)
430cdf0e10cSrcweir 		return mSfx2CreateWidget (component, name, parent, attributes);
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     return 0;
433cdf0e10cSrcweir }
434cdf0e10cSrcweir 
layoutCreateWindow(VCLXWindow ** component,Window * parent,OUString const & name,long & attributes)435cdf0e10cSrcweir Window* WidgetFactory::layoutCreateWindow (VCLXWindow** component, Window *parent, OUString const& name, long& attributes)
436cdf0e10cSrcweir {
437cdf0e10cSrcweir     Window* window = 0;
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     if (0)
440cdf0e10cSrcweir     {
441cdf0e10cSrcweir         ;
442cdf0e10cSrcweir     }
443cdf0e10cSrcweir     if ( name.equalsAscii( "dialog" ) )
444cdf0e10cSrcweir     {
445cdf0e10cSrcweir         if ( parent == NULL )
446cdf0e10cSrcweir             parent = DIALOG_NO_PARENT;
447cdf0e10cSrcweir         window = new Dialog( parent, ImplGetWinBits( attributes, 0 ) );
448cdf0e10cSrcweir         *component = new layoutimpl::VCLXDialog();
449cdf0e10cSrcweir 
450cdf0e10cSrcweir         attributes ^= awt::WindowAttribute::SHOW;
451cdf0e10cSrcweir     }
452cdf0e10cSrcweir     else if ( name.equalsAscii( "modaldialog" ) )
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir         if ( parent == NULL )
455cdf0e10cSrcweir             parent = DIALOG_NO_PARENT;
456cdf0e10cSrcweir         window = new ModalDialog( parent, ImplGetWinBits( attributes, 0 ) );
457cdf0e10cSrcweir         *component = new layoutimpl::VCLXDialog();
458cdf0e10cSrcweir 
459cdf0e10cSrcweir         attributes ^= awt::WindowAttribute::SHOW;
460cdf0e10cSrcweir     }
461cdf0e10cSrcweir     else if ( name.equalsAscii( "modelessdialog" ) )
462cdf0e10cSrcweir     {
463cdf0e10cSrcweir         if ( parent == NULL )
464cdf0e10cSrcweir             parent = DIALOG_NO_PARENT;
465cdf0e10cSrcweir         window = new ModelessDialog (parent, ImplGetWinBits (attributes, 0));
466cdf0e10cSrcweir         *component = new layoutimpl::VCLXDialog();
467cdf0e10cSrcweir 
468cdf0e10cSrcweir         attributes ^= awt::WindowAttribute::SHOW;
469cdf0e10cSrcweir     }
470cdf0e10cSrcweir     else if ( name.equalsAscii( "sfxdialog" ) )
471cdf0e10cSrcweir     {
472cdf0e10cSrcweir         if ( parent == NULL )
473cdf0e10cSrcweir             parent = DIALOG_NO_PARENT;
474cdf0e10cSrcweir         window = new ClosingDialog (parent, ImplGetWinBits (attributes, 0));
475cdf0e10cSrcweir         *component = new layoutimpl::VCLXDialog();
476cdf0e10cSrcweir 
477cdf0e10cSrcweir         attributes ^= awt::WindowAttribute::SHOW;
478cdf0e10cSrcweir     }
479cdf0e10cSrcweir     else if ( name.equalsAscii( "sfxmodaldialog" ) )
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         if ( parent == NULL )
482cdf0e10cSrcweir             parent = DIALOG_NO_PARENT;
483cdf0e10cSrcweir         window = new ClosingModalDialog( parent,
484cdf0e10cSrcweir                                          ImplGetWinBits( attributes, 0 ) );
485cdf0e10cSrcweir         *component = new layoutimpl::VCLXDialog();
486cdf0e10cSrcweir 
487cdf0e10cSrcweir         attributes ^= awt::WindowAttribute::SHOW;
488cdf0e10cSrcweir     }
489cdf0e10cSrcweir     else if ( name.equalsAscii( "sfxmodelessdialog" ) )
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         if ( parent == NULL )
492cdf0e10cSrcweir             parent = DIALOG_NO_PARENT;
493cdf0e10cSrcweir         window = new ClosingModelessDialog (parent, ImplGetWinBits (attributes, 0));
494cdf0e10cSrcweir         *component = new layoutimpl::VCLXDialog();
495cdf0e10cSrcweir 
496cdf0e10cSrcweir         attributes ^= awt::WindowAttribute::SHOW;
497cdf0e10cSrcweir     }
498cdf0e10cSrcweir     else if ( name.equalsAscii( "tabcontrol" ) )
499cdf0e10cSrcweir     {
500cdf0e10cSrcweir         window = new TabControl( parent, ImplGetWinBits( attributes, WINDOW_TABCONTROL ) );
501cdf0e10cSrcweir         *component = new layoutimpl::VCLXTabControl();
502cdf0e10cSrcweir     }
503cdf0e10cSrcweir     else if ( name.equalsAscii( "scroller" ) )
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         // used FixedImage because I just want some empty non-intrusive widget
506cdf0e10cSrcweir         window = new FixedImage( parent, ImplGetWinBits( attributes, 0 ) );
507cdf0e10cSrcweir         *component = new layoutimpl::VCLXScroller();
508cdf0e10cSrcweir     }
509cdf0e10cSrcweir     else if ( name.equalsAscii( "hsplitter" ) || name.equalsAscii( "vsplitter" ) )
510cdf0e10cSrcweir     {
511cdf0e10cSrcweir         window = new FixedImage( parent, ImplGetWinBits( attributes, 0 ) );
512cdf0e10cSrcweir         *component = new layoutimpl::VCLXSplitter( name.equalsAscii( "hsplitter" ) );
513cdf0e10cSrcweir     }
514cdf0e10cSrcweir     else if ( name.equalsAscii( "hfixedline" ) || name.equalsAscii( "vfixedline" ) )
515cdf0e10cSrcweir     {
516cdf0e10cSrcweir         WinBits nStyle = ImplGetWinBits( attributes, 0 );
517cdf0e10cSrcweir         nStyle ^= WB_HORZ;
518cdf0e10cSrcweir         if ( name.equalsAscii( "hfixedline" ) )
519cdf0e10cSrcweir             nStyle |= WB_HORZ;
520cdf0e10cSrcweir         else
521cdf0e10cSrcweir             nStyle |= WB_VERT;
522cdf0e10cSrcweir         window = new FixedLine( parent, nStyle );
523cdf0e10cSrcweir         *component = new layoutimpl::VCLXFixedLine();
524cdf0e10cSrcweir     }
525cdf0e10cSrcweir     else if ( name.equalsAscii( "okbutton" ) )
526cdf0e10cSrcweir     {
527cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
528cdf0e10cSrcweir         *component = new layoutimpl::VCLXOKButton( window );
529cdf0e10cSrcweir         window->SetType (WINDOW_OKBUTTON);
530cdf0e10cSrcweir     }
531cdf0e10cSrcweir     else if ( name.equalsAscii( "cancelbutton" ) )
532cdf0e10cSrcweir     {
533cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
534cdf0e10cSrcweir         *component = new layoutimpl::VCLXCancelButton( window );
535cdf0e10cSrcweir         window->SetType (WINDOW_CANCELBUTTON);
536cdf0e10cSrcweir     }
537cdf0e10cSrcweir     else if ( name.equalsAscii( "yesbutton" ) )
538cdf0e10cSrcweir     {
539cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
540cdf0e10cSrcweir         *component = new layoutimpl::VCLXYesButton( window );
541cdf0e10cSrcweir         window->SetType (WINDOW_OKBUTTON);
542cdf0e10cSrcweir     }
543cdf0e10cSrcweir     else if ( name.equalsAscii( "nobutton" ) )
544cdf0e10cSrcweir     {
545cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
546cdf0e10cSrcweir         window->SetType (WINDOW_CANCELBUTTON);
547cdf0e10cSrcweir         *component = new layoutimpl::VCLXNoButton( window );
548cdf0e10cSrcweir     }
549cdf0e10cSrcweir     else if ( name.equalsAscii( "retrybutton" ) )
550cdf0e10cSrcweir     {
551cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
552cdf0e10cSrcweir         *component = new layoutimpl::VCLXRetryButton( window );
553cdf0e10cSrcweir     }
554cdf0e10cSrcweir     else if ( name.equalsAscii( "ignorebutton" ) )
555cdf0e10cSrcweir     {
556cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
557cdf0e10cSrcweir         *component = new layoutimpl::VCLXIgnoreButton( window );
558cdf0e10cSrcweir     }
559cdf0e10cSrcweir     else if ( name.equalsAscii( "resetbutton" ) )
560cdf0e10cSrcweir     {
561cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
562cdf0e10cSrcweir         *component = new layoutimpl::VCLXResetButton( window );
563cdf0e10cSrcweir     }
564cdf0e10cSrcweir     else if ( name.equalsAscii( "applybutton" ) )
565cdf0e10cSrcweir     {
566cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
567cdf0e10cSrcweir         *component = new layoutimpl::VCLXApplyButton( window );
568cdf0e10cSrcweir     }
569cdf0e10cSrcweir     else if ( name.equalsAscii( "helpbutton" ) )
570cdf0e10cSrcweir     {
571cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
572cdf0e10cSrcweir         *component = new layoutimpl::VCLXHelpButton( window );
573cdf0e10cSrcweir         window->SetType (WINDOW_HELPBUTTON);
574cdf0e10cSrcweir     }
575cdf0e10cSrcweir     else if ( name.equalsAscii( "morebutton" ) )
576cdf0e10cSrcweir     {
577cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
578cdf0e10cSrcweir         *component = new layoutimpl::VCLXMoreButton( window );
579cdf0e10cSrcweir         window->SetType (WINDOW_MOREBUTTON);
580cdf0e10cSrcweir     }
581cdf0e10cSrcweir     else if ( name.equalsAscii( "advancedbutton" ) )
582cdf0e10cSrcweir     {
583cdf0e10cSrcweir         window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) );
584cdf0e10cSrcweir         *component = new layoutimpl::VCLXAdvancedButton( window );
585cdf0e10cSrcweir     }
586cdf0e10cSrcweir     else if ( name.equalsAscii( "plugin" ) )
587cdf0e10cSrcweir     {
588cdf0e10cSrcweir         window = new Control( parent, ImplGetWinBits( attributes, 0 ) );
589cdf0e10cSrcweir #ifndef __SUNPRO_CC
590cdf0e10cSrcweir         OSL_TRACE( "%s: parent=%p (%s)\n", __FUNCTION__, parent, typeid( *parent ).name() );
591cdf0e10cSrcweir #endif
592cdf0e10cSrcweir         *component = new layoutimpl::VCLXPlugin( window, ImplGetWinBits( attributes, 0 ) );
593cdf0e10cSrcweir     }
594cdf0e10cSrcweir     else if ( name.equalsAscii( "tabpage" ) )
595cdf0e10cSrcweir     {
596cdf0e10cSrcweir #if 0
597cdf0e10cSrcweir         if ( !parent )
598cdf0e10cSrcweir             parent = layout::TabPage::global_parent;
599cdf0e10cSrcweir #else
600cdf0e10cSrcweir         if (layout::TabPage::global_parent)
601cdf0e10cSrcweir             parent = layout::TabPage::global_parent;
602cdf0e10cSrcweir         layout::TabPage::global_parent = 0;
603cdf0e10cSrcweir #endif
604cdf0e10cSrcweir         //window = new TabPage( parent, ImplGetWinBits( attributes, 0 ) );
605cdf0e10cSrcweir         attributes ^= awt::WindowAttribute::SHOW;
606cdf0e10cSrcweir         WinBits nStyle = ImplGetWinBits( attributes, 0 );
607cdf0e10cSrcweir         nStyle |= WB_HIDE;
608cdf0e10cSrcweir 
609cdf0e10cSrcweir         if (!parent)
610cdf0e10cSrcweir         {
611cdf0e10cSrcweir             window = new Dialog( parent, nStyle );
612cdf0e10cSrcweir             *component = new VCLXDialog();
613cdf0e10cSrcweir         }
614cdf0e10cSrcweir         else
615cdf0e10cSrcweir         {
616cdf0e10cSrcweir             window = new TabPage( parent, nStyle );
617cdf0e10cSrcweir             *component = new VCLXTabPage( window );
618cdf0e10cSrcweir         }
619cdf0e10cSrcweir     }
620cdf0e10cSrcweir     else if ( name.equalsAscii( "string" ) )
621cdf0e10cSrcweir     {
622cdf0e10cSrcweir         // FIXME: move <string>s.text to simple map<string> in root?
623cdf0e10cSrcweir         attributes &= ~awt::WindowAttribute::SHOW;
624cdf0e10cSrcweir         window = new Window( parent, ImplGetWinBits( attributes, 0 ) );
625cdf0e10cSrcweir         *component = new layoutimpl::LocalizedString();
626cdf0e10cSrcweir     }
627cdf0e10cSrcweir #if 0 // parent paranoia
628cdf0e10cSrcweir     else if ( name.equalsAscii( "listbox" ) )
629cdf0e10cSrcweir     {
630cdf0e10cSrcweir         window = new ListBox (parent, ImplGetWinBits (attributes, 0));
631cdf0e10cSrcweir         *component = new VCLXListBox ();
632cdf0e10cSrcweir     }
633cdf0e10cSrcweir #endif
634cdf0e10cSrcweir     else if (name.equalsAscii ("svxfontlistbox")
635cdf0e10cSrcweir              || name.equalsAscii ("svxlanguagebox"))
636cdf0e10cSrcweir     {
637cdf0e10cSrcweir         window = new ListBox (parent, ImplGetWinBits (attributes, 0));
638cdf0e10cSrcweir         *component = new VCLXListBox ();
639cdf0e10cSrcweir     }
640cdf0e10cSrcweir     return window;
641cdf0e10cSrcweir }
642cdf0e10cSrcweir 
643cdf0e10cSrcweir } // namespace layoutimpl
644cdf0e10cSrcweir 
645cdf0e10cSrcweir // Avoid polluting the rest of the code with vcl linkage pieces ...
646cdf0e10cSrcweir 
647cdf0e10cSrcweir #include <vcl/imagerepository.hxx>
648cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
649cdf0e10cSrcweir #include <vcl/graph.hxx>
650cdf0e10cSrcweir 
651cdf0e10cSrcweir namespace layoutimpl
652cdf0e10cSrcweir {
653cdf0e10cSrcweir 
loadGraphic(const char * pName)654cdf0e10cSrcweir uno::Reference< graphic::XGraphic > loadGraphic( const char *pName )
655cdf0e10cSrcweir {
656cdf0e10cSrcweir     BitmapEx aBmp;
657cdf0e10cSrcweir 
658cdf0e10cSrcweir     OUString aStr( pName, strlen( pName ), RTL_TEXTENCODING_ASCII_US );
659cdf0e10cSrcweir     if ( aStr.compareToAscii( ".uno:" ) == 0 )
660cdf0e10cSrcweir         aStr = aStr.copy( 5 ).toAsciiLowerCase();
661cdf0e10cSrcweir 
662cdf0e10cSrcweir     if ( !vcl::ImageRepository::loadImage( OUString::createFromAscii( pName ), aBmp, true ) )
663cdf0e10cSrcweir         return uno::Reference< graphic::XGraphic >();
664cdf0e10cSrcweir 
665cdf0e10cSrcweir     return Graphic( aBmp ).GetXGraphic();
666cdf0e10cSrcweir }
667cdf0e10cSrcweir 
668cdf0e10cSrcweir } // namespace layoutimpl
669