1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_toolkit.hxx"
30 #include <tools/debug.hxx>
32 #include <vcl/window.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/wrkwin.hxx>
35 #include <vcl/msgbox.hxx>
38 #include <stardiv/uno/awt/window.hxx>
39 #include <stardiv/uno/awt/vclwin.hxx>
40 #include <stardiv/uno/awt/printer.hxx>
41 #include <stardiv/uno/repos/serinfo.hxx>
42 #include <stardiv/uno/lang/factory.hxx>
45 #include <unoctrl.hxx>
46 // #include <unoctrl2.hxx>
48 #include <svtools/unoiface.hxx> // InitExtToolkit
50 UsrAny
UsrAny_UINT16( UINT16 n
)
57 // -----------------------------------------------------------------------
59 class MyApp
: public Application
67 // -----------------------------------------------------------------------
69 class MyWin
: public WorkWindow
72 XPropertySetRef xCtrlModel
;
73 XControlContainerRef xCont
;
74 XPropertySetRef xContModel
;
75 XControlRef xDrawCtrl
;
79 MyWin( Window
* pParent
, WinBits nWinStyle
);
82 void MouseButtonDown( const MouseEvent
& rMEvt
);
84 void Paint( const Rectangle
& r
);
87 // -----------------------------------------------------------------------
91 createAndSetDefaultServiceManager();
93 MyWin
aMainWin( NULL
, WB_APP
| WB_STDWORK
);
94 aMainWin
.SetText( "Uno-Controls - Workbench" );
99 // -----------------------------------------------------------------------
101 MyWin::MyWin( Window
* pParent
, WinBits nWinStyle
) :
102 WorkWindow( pParent
, nWinStyle
)
106 // -----------------------------------------------------------------------
109 XComponentRef
xC1( xCont
, USR_QUERY
);
111 XComponentRef
xC2( xContModel
, USR_QUERY
);
115 // -----------------------------------------------------------------------
117 void MyWin::MouseButtonDown( const MouseEvent
& rMEvt
)
119 if( rMEvt
.GetClicks() == 2 )
121 XViewRef
xV( xDrawCtrl
, USR_QUERY
);
122 XWindowRef
xC( xDrawCtrl
, USR_QUERY
);
123 xV
->draw( xC
->getPosSize().Left(), xC
->getPosSize().Top() );
127 XServiceManagerRef xProv = getGlobalServiceManager();
128 XServiceProviderRef xSSI = xProv->queryServiceProvider( L"stardiv.vcl.PrinterServer" );
129 XPrinterServerRef xPrinterServer( xSSI->createInstance(), USR_QUERY );
131 Sequence< UString > aPrinterNames = xPrinterServer->getPrinterNames();
132 USHORT nPrinters = aPrinterNames.getLen();
133 String aInfo( "Printers: " );
137 for ( USHORT n = 0; n < nPrinters; n++ )
140 aInfo += OUStringToString( aPrinterNames.getConstArray()[n], CHARSET_SYSTEM );
143 XPrinterRef xPrinter = xPrinterServer->createPrinter( aPrinterNames.getConstArray()[0] );
144 xPrinter->start( L"UNOPrinterTest", 1, TRUE );
145 XDeviceRef xDev = xPrinter->startPage();
146 XGraphicsRef xGraphics = xDev->createGraphics();
147 xGraphics->drawText( 200, 200, L"Printed with UNO" );
151 InfoBox( this, aInfo ).Execute();
154 else if( rMEvt
.GetClicks() == 1 )
158 static INT32 nColor
= 0x001788ab;
159 xContModel
->setPropertyValue( L
"BackgroundColor", UsrAny( nColor
) );
160 nColor
+= 0x00111111;
165 XServiceManagerRef xProv
= getGlobalServiceManager();
167 XMultiServiceFactoryRef xMSF
= NAMESPACE_USR( getProcessServiceManager
)();
169 XServiceProviderRef xSSI
= xProv
->queryServiceProvider( L
"stardiv.vcl.VclToolkit" );
170 XToolkitRef
xToolkit( xMSF
->createInstance( L
"stardiv.vcl.VclToolkit" ), USR_QUERY
);
171 DBG_ASSERT( xToolkit
, "No Toolkit!" );
173 // Uno Container + Model erzeugen
174 XServiceProviderRef xModelProv
; // = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.ControlContainer" );
175 XInterfaceRef
xCMRef( xMSF
->createInstance(L
"stardiv.vcl.controlmodel.ControlContainer") );
176 xCMRef
->queryInterface( XPropertySet::getSmartUik(), xContModel
);
177 xContModel
->setPropertyValue( L
"Border", UsrAny_UINT16( 1 ) );
178 xContModel
->setPropertyValue( L
"BackgroundColor", UsrAny( (UINT32
)0x00CCCCCC) );
180 xModelProv
= xProv
->queryServiceProvider( L
"stardiv.vcl.control.ControlContainer" );
181 XInterfaceRef
xCCRef( xModelProv
->createInstance(), USR_QUERY
);
182 xCCRef
->queryInterface( XControlContainer::getSmartUik(), xCont
);
184 XControlModelRef
xCM( xContModel
, USR_QUERY
);
185 XControlRef
xContControl( xCont
, USR_QUERY
);
186 xContControl
->setModel( xCM
);
187 XWindowRef
xContComp( xCont
, USR_QUERY
);
188 xContComp
->setPosSize( 0, 0, 500, 600, PosSize_POSSIZE
);
190 // Zwei EditControls auf einem Model...
191 // xModelProv = xProv->queryServiceProvider( L"stardiv.uno.awt.UnoControlEditModel" );
192 XInterfaceRef
xModel( xMSF
->createInstance(L
"stardiv.uno.awt.UnoControlEditModel") );
193 DBG_ASSERT( xModel
, "No Model!" );
195 XPropertySetRef
xPSet( xModel
, USR_QUERY
);
196 xPSet
->setPropertyValue( L
"Text", UsrAny( UString( L
"Hallo!" ) ) );
197 xPSet
->setPropertyValue( L
"FontName", UsrAny( UString( L
"Times New Roman" ) ) );
198 // xPSet->setPropertyValue( L"FontWeight", UsrAny( 200 ) );
200 XServiceProviderRef xEditCtrlProv
= xProv
->queryServiceProvider( L
"stardiv.uno.awt.UnoControlEdit" );
202 XControlRef
xEdit1( xMSF
->createInstance(L
"stardiv.uno.awt.UnoControlEdit"), USR_QUERY
);
203 xModel
->queryInterface( XControlModel::getSmartUik(), xCM
);
204 xEdit1
->setModel( xCM
);
205 XWindowRef
xEditCmp1( xEdit1
, USR_QUERY
);
206 xEditCmp1
->setPosSize( 50, 50, 100, 60, PosSize_POSSIZE
);
207 xCont
->addControl( L
"", xEdit1
);
209 XControlRef
xEdit2( xMSF
->createInstance(L
"stardiv.uno.awt.UnoControlEdit"), USR_QUERY
);
210 xModel
->queryInterface( XControlModel::getSmartUik(), xCM
);
211 xEdit2
->setModel( xCM
);
212 XWindowRef
xEditCmp2( xEdit2
, USR_QUERY
);
213 XLayoutConstrainsRef
xL( xEdit2
, USR_QUERY
);
216 Size aSz
= xL
->getPreferredSize();
217 xEditCmp2
->setPosSize( 100, 180, aSz
.Width(), aSz
.Height(), PosSize_POSSIZE
);
220 xEditCmp2
->setPosSize( 100, 180, 100, 40, PosSize_POSSIZE
);
221 xCont
->addControl( L
"", xEdit2
);
223 xModelProv
= xProv
->queryServiceProvider( L
"stardiv.vcl.controlmodel.NumericField" );
224 XInterfaceRef
xNumModel( xModelProv
->createInstance(), USR_QUERY
);
225 DBG_ASSERT( xNumModel
, "No Model!" );
228 XServiceProviderRef xNumFieldProv
= xProv
->queryServiceProvider( L
"stardiv.vcl.control.NumericField" );
229 XControlRef
xNumField( xNumFieldProv
->createInstance(), USR_QUERY
);
230 xNumModel
->queryInterface( XControlModel::getSmartUik(), xCM
);
231 xNumField
->setModel( xCM
);
232 XWindowRef
xNumFieldWin( xNumField
, USR_QUERY
);
233 xNumFieldWin
->setPosSize( 50, 250, 100, 60, PosSize_POSSIZE
);
234 xCont
->addControl( L
"", xNumField
);
236 XMultiPropertySetRef
xPSet2( xNumModel
, USR_QUERY
);
237 Sequence
<UString
> Names( 2 );
238 Names
.getArray()[0] = L
"Value";
239 Names
.getArray()[1] = L
"ValueMin";
240 Sequence
<UsrAny
> Values( 2 );
241 Values
.getArray()[0] = UsrAny( -2000000.0 );
242 Values
.getArray()[1] = UsrAny( -2000000.0 );
243 xPSet2
->setPropertyValues( Names
, Values
);
247 xModelProv
= xProv
->queryServiceProvider( L
"stardiv.vcl.controlmodel.Button" );
248 xModelProv
->createInstance()->queryInterface( XInterface::getSmartUik(), xModel
);
249 DBG_ASSERT( xModel
, "No Model!" );
251 xModel
->queryInterface( XPropertySet::getSmartUik(), xPSet
);
252 xPSet
->setPropertyValue( L
"Label", UsrAny( L
"Press!" ) );
254 XServiceProviderRef xButtonCtrlProv
= xProv
->queryServiceProvider( L
"stardiv.vcl.control.Button" );
255 XControlRef
xButton1( xButtonCtrlProv
->createInstance(), USR_QUERY
);
256 xModel
->queryInterface( XControlModel::getSmartUik(), xCM
);
257 xButton1
->setModel( xCM
);
258 XWindowRef
xButtonCmp1( xButton1
, USR_QUERY
);
259 xButtonCmp1
->setPosSize( 170, 80, 80, 80, PosSize_POSSIZE
);
260 // Unsichtbar, nur im MBDown mit DrawRoutine bei Doppel-Klick...
261 xButtonCmp1
->setVisible( FALSE
);
262 xDrawCtrl
= xButton1
;
264 xCont
->addControl( L
"", xButton1
);
269 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.ListBox" );
270 xModel = (XInterface*)xModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
272 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
273 Sequence<UString> aSeq( 7 );
274 aSeq.getArray()[0] = L"Item1";
275 aSeq.getArray()[1] = L"Item2";
276 aSeq.getArray()[2] = L"Item3";
277 aSeq.getArray()[3] = L"Item4";
278 aSeq.getArray()[4] = L"Item5";
279 aSeq.getArray()[5] = L"Item6";
280 aSeq.getArray()[6] = L"Item7";
281 xPSet->setPropertyValue( L"StringItemList", UsrAny( &aSeq, Sequence<UString>::getReflection() ) );
282 xPSet->setPropertyValue( L"LineCount", UsrAny_UINT16( 4 ) );
283 xPSet->setPropertyValue( L"Dropdown", UsrAny( (BOOL)TRUE ) );
285 XServiceProviderRef xListBoxCtrlProv = xProv->queryServiceProvider( L"stardiv.vcl.control.ListBox" );
286 XControlRef xListBox1 = (XControl*)xListBoxCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
287 xListBox1->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
288 XWindowRef xListBoxCmp1 = (XWindow*)xListBox1->queryInterface( XWindow::getSmartUik() );
289 xListBoxCmp1->setPosSize( 20, 250, 200, 20, PosSize_POSSIZE );
290 xCont->addControl( L"", xListBox1 );
293 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.FixedText" );
294 xModel = (XInterface*)xModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
295 DBG_ASSERT( xModel, "No Model!" );
297 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
298 xPSet->setPropertyValue( L"Label", UsrAny( L"Label:" ) );
299 xPSet->setPropertyValue( L"BackgroundColor", UsrAny( (UINT32)0x00888888) );
301 Font_Attribs aFontAttrs;
302 aFontAttrs.Italic = ITALIC_NORMAL;
303 xPSet->setPropertyValue( L"Font_Attribs", UsrAny( &aFontAttrs, Font_Attribs_getReflection() ) );
305 XPropertyStateRef xState = (XPropertyState*)xPSet->queryInterface( XPropertyState::getSmartUik() );
306 xState->getPropertyState( L"Font_Attribs" );
307 xState->getPropertyState( L"Font_Size" );
309 XServiceProviderRef xFixedTextCtrlProv = xProv->queryServiceProvider( L"stardiv.vcl.control.FixedText" );
310 XControlRef xFixedText1 = (XControl*)xFixedTextCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
311 DBG_ASSERT( xFixedText1, "No FixedText!" );
312 xFixedText1->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
313 XWindowRef xFixedTextCmp1 = (XWindow*)xFixedText1->queryInterface( XWindow::getSmartUik() );
314 xFixedTextCmp1->setPosSize( 20, 20, 120, 20, PosSize_POSSIZE );
315 xCont->addControl( L"", xFixedText1 );
318 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.GroupBox" );
319 xModel = (XInterface*)xModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
320 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
321 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio-Test:" ) );
322 XServiceProviderRef xGroupBoxCtrlProv = xProv->queryServiceProvider( L"stardiv.vcl.control.GroupBox" );
323 XControlRef xGroupBox1 = (XControl*)xGroupBoxCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
324 xGroupBox1->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
325 XWindowRef xGroupBoxCmp1 = (XWindow*)xGroupBox1->queryInterface( XWindow::getSmartUik() );
326 xGroupBoxCmp1->setPosSize( 30, 410, 100, 130, PosSize_POSSIZE );
327 xCont->addControl( L"", xGroupBox1 );
329 XServiceProviderRef xRadioButtonModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.RadioButton" );
330 XServiceProviderRef xRadioButtonCtrlProv = xProv->queryServiceProvider( L"stardiv.vcl.control.RadioButton" );
332 xModel = (XInterface*)xRadioButtonModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
333 XControlRef xT1 = (XControl*)xRadioButtonCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
334 xT1->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
335 XWindowRef xTC1 = (XWindow*)xT1->queryInterface( XWindow::getSmartUik() );
336 xTC1->setPosSize( 40, 430, 80, 20, PosSize_POSSIZE );
337 xCont->addControl( L"", xT1 );
338 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
339 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio1" ) );
340 xPSet->setPropertyValue( L"State", UsrAny_UINT16( 1 ) );
342 xModel = (XInterface*)xRadioButtonModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
343 XControlRef xT2 = (XControl*)xRadioButtonCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
344 xT2->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
345 XWindowRef xTC2 = (XWindow*)xT2->queryInterface( XWindow::getSmartUik() );
346 xTC2->setPosSize( 40, 470, 80, 20, PosSize_POSSIZE );
347 xCont->addControl( L"", xT2 );
348 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
349 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio2" ) );
351 xModel = (XInterface*)xRadioButtonModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
352 XControlRef xT3 = (XControl*)xRadioButtonCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
353 xT3->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
354 XWindowRef xTC3 = (XWindow*)xT3->queryInterface( XWindow::getSmartUik() );
355 xTC3->setPosSize( 40, 510, 80, 20, PosSize_POSSIZE );
356 xCont->addControl( L"", xT3 );
357 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
358 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio3" ) );
360 xModel = (XInterface*)xRadioButtonModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
361 XControlRef xT4 = (XControl*)xRadioButtonCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
362 xT4->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
363 XWindowRef xTC4 = (XWindow*)xT4->queryInterface( XWindow::getSmartUik() );
364 xTC4->setPosSize( 40, 550, 80, 20, PosSize_POSSIZE );
365 xCont->addControl( L"", xT4 );
366 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
367 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio4 - no" ) );
368 xPSet->setPropertyValue( L"Tabstop", UsrAny( (BOOL)TRUE ) );
371 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.TabController" );
372 xModel = (XInterface*)xModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
373 XTabControllerModelRef xTCModel = (XTabControllerModel*)xModel->queryInterface( XTabControllerModel::getSmartUik() );
375 XServiceProviderRef xTCProv = xProv->queryServiceProvider( L"stardiv.vcl.control.TabController" );
376 XTabControllerRef xTC = (XTabController*)xTCProv->createInstance()->queryInterface( XTabController::getSmartUik() );
377 xTC->setModel( (XTabControllerModel*)xModel->queryInterface( XTabControllerModel::getSmartUik() ) );
378 XUnoControlContainerRef xUCC = (XUnoControlContainer*)xCont->queryInterface( XUnoControlContainer::getSmartUik() );
379 xUCC->addTabController( xTC );
381 Sequence<XControlModelRef> aControls( 5 );
382 aControls.getArray()[0] = xGroupBox1->getModel();
383 aControls.getArray()[1] = xT1->getModel();
384 aControls.getArray()[2] = xT3->getModel();
385 aControls.getArray()[3] = xT2->getModel();
386 aControls.getArray()[4] = xT4->getModel();
387 xTCModel->setControls( aControls );
389 Sequence<XControlModelRef> aGroup( 3 );
390 aGroup.getArray()[0] = xT1->getModel();
391 aGroup.getArray()[1] = xT3->getModel();
392 aGroup.getArray()[2] = xT2->getModel();
393 xTCModel->setGroup( aGroup, L"test" );
395 // Container anzeigen...
396 // Als Child zu diesem Fenster
397 xContControl
->createPeer( XToolkitRef(), GetComponentInterface( TRUE
) );
399 XDeviceRef
xD( xContControl
->getPeer(), USR_QUERY
);
400 xG
= xD
->createGraphics();
401 XViewRef
xV ( xDrawCtrl
, USR_QUERY
);
402 xV
->setGraphics( xG
);
404 // ((UnoControl*)(XControl*)xNumField))->updateFromModel();
408 WindowDecriptor aDescr;
409 aDescr.ComponentServiceName = "window";
410 aDescr.Type = VCLCOMPONENTTYPE_CONTAINER;
411 aDescr.Parent = GetComponentInterface( TRUE );
412 aDescr.WindowAttributes = WA_SHOW|WA_BORDER;
413 aDescr.Bounds = Rectangle( Point( 500, 50 ), Size( 300, 200 ) );
414 XVclWindowPeerRef xSPWin = xToolkit->createComponent( aDescr );
416 WindowDecriptor aDescr2;
417 aDescr2.ComponentServiceName = "scrollbar";
418 aDescr2.Type = VCLCOMPONENTTYPE_SIMPLE;
419 aDescr2.Parent = xSPWin;
420 aDescr2.WindowAttributes = WA_SHOW|WA_BORDER|WA_VSCROLL;
421 aDescr2.Bounds = Rectangle( Point( 250, 0 ), Size( 50, 200 ) );
422 XVclWindowPeerRef xSB = xToolkit->createComponent( aDescr2 );
427 WorkWindow::MouseButtonDown( rMEvt
);
431 // -----------------------------------------------------------------------
435 WorkWindow::Resize();
438 void MyWin::Paint( const Rectangle
& r
)
440 // Muss ueber PaintListener geschehen...
441 if ( xDrawCtrl
.is() )
443 XViewRef
xV( xDrawCtrl
, USR_QUERY
);
444 XWindowRef
xC( xDrawCtrl
, USR_QUERY
);
445 xV
->draw( xC
->getPosSize().Left(), xC
->getPosSize().Top() );