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 #include <tools/debug.hxx>
27
28 #include <vcl/window.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/wrkwin.hxx>
31 #include <vcl/msgbox.hxx>
32
33
34 #include <stardiv/uno/awt/window.hxx>
35 #include <stardiv/uno/awt/vclwin.hxx>
36 #include <stardiv/uno/awt/printer.hxx>
37 #include <stardiv/uno/repos/serinfo.hxx>
38 #include <stardiv/uno/lang/factory.hxx>
39
40
41 #include <unoctrl.hxx>
42 // #include <unoctrl2.hxx>
43
44 #include <svtools/unoiface.hxx> // InitExtToolkit
45
UsrAny_UINT16(UINT16 n)46 UsrAny UsrAny_UINT16( UINT16 n )
47 {
48 UsrAny aVal;
49 aVal.setUINT16( n );
50 return aVal;
51 }
52
53 // -----------------------------------------------------------------------
54
55 class MyApp : public Application
56 {
57 public:
58 void Main();
59 };
60
61 MyApp aMyApp;
62
63 // -----------------------------------------------------------------------
64
65 class MyWin : public WorkWindow
66 {
67 XControlRef xCtrl;
68 XPropertySetRef xCtrlModel;
69 XControlContainerRef xCont;
70 XPropertySetRef xContModel;
71 XControlRef xDrawCtrl;
72 XGraphicsRef xG;
73
74 public:
75 MyWin( Window* pParent, WinBits nWinStyle );
76 ~MyWin();
77
78 void MouseButtonDown( const MouseEvent& rMEvt );
79 void Resize();
80 void Paint( const Rectangle& r );
81 };
82
83 // -----------------------------------------------------------------------
84
Main()85 void MyApp::Main()
86 {
87 createAndSetDefaultServiceManager();
88
89 MyWin aMainWin( NULL, WB_APP | WB_STDWORK );
90 aMainWin.SetText( "Uno-Controls - Workbench" );
91 aMainWin.Show();
92 Execute();
93 }
94
95 // -----------------------------------------------------------------------
96
MyWin(Window * pParent,WinBits nWinStyle)97 MyWin::MyWin( Window* pParent, WinBits nWinStyle ) :
98 WorkWindow( pParent, nWinStyle )
99 {
100 }
101
102 // -----------------------------------------------------------------------
~MyWin()103 MyWin::~MyWin()
104 {
105 XComponentRef xC1( xCont, USR_QUERY );
106 xC1->dispose();
107 XComponentRef xC2( xContModel, USR_QUERY );
108 xC2->dispose();
109 }
110
111 // -----------------------------------------------------------------------
112
MouseButtonDown(const MouseEvent & rMEvt)113 void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
114 {
115 if( rMEvt.GetClicks() == 2 )
116 {
117 XViewRef xV( xDrawCtrl, USR_QUERY );
118 XWindowRef xC( xDrawCtrl, USR_QUERY );
119 xV->draw( xC->getPosSize().Left(), xC->getPosSize().Top() );
120
121 // Printer Testen...
122 /*
123 XServiceManagerRef xProv = getGlobalServiceManager();
124 XServiceProviderRef xSSI = xProv->queryServiceProvider( L"stardiv.vcl.PrinterServer" );
125 XPrinterServerRef xPrinterServer( xSSI->createInstance(), USR_QUERY );
126
127 Sequence< UString > aPrinterNames = xPrinterServer->getPrinterNames();
128 USHORT nPrinters = aPrinterNames.getLen();
129 String aInfo( "Printers: " );
130 aInfo += nPrinters;
131 if ( nPrinters )
132 {
133 for ( USHORT n = 0; n < nPrinters; n++ )
134 {
135 aInfo += '\n';
136 aInfo += OUStringToString( aPrinterNames.getConstArray()[n], CHARSET_SYSTEM );
137 }
138
139 XPrinterRef xPrinter = xPrinterServer->createPrinter( aPrinterNames.getConstArray()[0] );
140 xPrinter->start( L"UNOPrinterTest", 1, TRUE );
141 XDeviceRef xDev = xPrinter->startPage();
142 XGraphicsRef xGraphics = xDev->createGraphics();
143 xGraphics->drawText( 200, 200, L"Printed with UNO" );
144 xPrinter->endPage();
145 xPrinter->end();
146 }
147 InfoBox( this, aInfo ).Execute();
148 */
149 }
150 else if( rMEvt.GetClicks() == 1 )
151 {
152 if( xContModel )
153 {
154 static INT32 nColor = 0x001788ab;
155 xContModel->setPropertyValue( L"BackgroundColor", UsrAny( nColor ) );
156 nColor += 0x00111111;
157 nColor &= 0xFFFFFF;
158 }
159 else
160 {
161 XServiceManagerRef xProv = getGlobalServiceManager();
162
163 XMultiServiceFactoryRef xMSF = NAMESPACE_USR( getProcessServiceManager )();
164
165 XServiceProviderRef xSSI = xProv->queryServiceProvider( L"stardiv.vcl.VclToolkit" );
166 XToolkitRef xToolkit( xMSF->createInstance( L"stardiv.vcl.VclToolkit" ), USR_QUERY );
167 DBG_ASSERT( xToolkit, "No Toolkit!" );
168
169 // Uno Container + Model erzeugen
170 XServiceProviderRef xModelProv; // = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.ControlContainer" );
171 XInterfaceRef xCMRef( xMSF->createInstance(L"stardiv.vcl.controlmodel.ControlContainer") );
172 xCMRef->queryInterface( XPropertySet::getSmartUik(), xContModel );
173 xContModel->setPropertyValue( L"Border", UsrAny_UINT16( 1 ) );
174 xContModel->setPropertyValue( L"BackgroundColor", UsrAny( (UINT32)0x00CCCCCC) );
175
176 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.control.ControlContainer" );
177 XInterfaceRef xCCRef( xModelProv->createInstance(), USR_QUERY );
178 xCCRef->queryInterface( XControlContainer::getSmartUik(), xCont );
179
180 XControlModelRef xCM( xContModel, USR_QUERY );
181 XControlRef xContControl( xCont, USR_QUERY );
182 xContControl->setModel( xCM );
183 XWindowRef xContComp( xCont, USR_QUERY );
184 xContComp->setPosSize( 0, 0, 500, 600, PosSize_POSSIZE );
185
186 // Zwei EditControls auf einem Model...
187 // xModelProv = xProv->queryServiceProvider( L"stardiv.uno.awt.UnoControlEditModel" );
188 XInterfaceRef xModel( xMSF->createInstance(L"stardiv.uno.awt.UnoControlEditModel") );
189 DBG_ASSERT( xModel, "No Model!" );
190
191 XPropertySetRef xPSet( xModel, USR_QUERY );
192 xPSet->setPropertyValue( L"Text", UsrAny( UString( L"Hallo!" ) ) );
193 xPSet->setPropertyValue( L"FontName", UsrAny( UString( L"Times New Roman" ) ) );
194 // xPSet->setPropertyValue( L"FontWeight", UsrAny( 200 ) );
195
196 XServiceProviderRef xEditCtrlProv = xProv->queryServiceProvider( L"stardiv.uno.awt.UnoControlEdit" );
197 // Edit1
198 XControlRef xEdit1( xMSF->createInstance(L"stardiv.uno.awt.UnoControlEdit"), USR_QUERY );
199 xModel->queryInterface( XControlModel::getSmartUik(), xCM );
200 xEdit1->setModel( xCM );
201 XWindowRef xEditCmp1( xEdit1, USR_QUERY );
202 xEditCmp1->setPosSize( 50, 50, 100, 60, PosSize_POSSIZE );
203 xCont->addControl( L"", xEdit1 );
204 // Edit2
205 XControlRef xEdit2( xMSF->createInstance(L"stardiv.uno.awt.UnoControlEdit"), USR_QUERY );
206 xModel->queryInterface( XControlModel::getSmartUik(), xCM );
207 xEdit2->setModel( xCM );
208 XWindowRef xEditCmp2( xEdit2, USR_QUERY );
209 XLayoutConstrainsRef xL( xEdit2, USR_QUERY );
210 if ( xL.is() )
211 {
212 Size aSz = xL->getPreferredSize();
213 xEditCmp2->setPosSize( 100, 180, aSz.Width(), aSz.Height(), PosSize_POSSIZE );
214 }
215 else
216 xEditCmp2->setPosSize( 100, 180, 100, 40, PosSize_POSSIZE );
217 xCont->addControl( L"", xEdit2 );
218
219 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.NumericField" );
220 XInterfaceRef xNumModel( xModelProv->createInstance(), USR_QUERY );
221 DBG_ASSERT( xNumModel, "No Model!" );
222
223
224 XServiceProviderRef xNumFieldProv = xProv->queryServiceProvider( L"stardiv.vcl.control.NumericField" );
225 XControlRef xNumField( xNumFieldProv->createInstance(), USR_QUERY );
226 xNumModel->queryInterface( XControlModel::getSmartUik(), xCM );
227 xNumField->setModel( xCM );
228 XWindowRef xNumFieldWin( xNumField, USR_QUERY );
229 xNumFieldWin->setPosSize( 50, 250, 100, 60, PosSize_POSSIZE );
230 xCont->addControl( L"", xNumField );
231
232 XMultiPropertySetRef xPSet2( xNumModel, USR_QUERY );
233 Sequence<UString> Names( 2 );
234 Names.getArray()[0] = L"Value";
235 Names.getArray()[1] = L"ValueMin";
236 Sequence<UsrAny> Values( 2 );
237 Values.getArray()[0] = UsrAny( -2000000.0 );
238 Values.getArray()[1] = UsrAny( -2000000.0 );
239 xPSet2->setPropertyValues( Names, Values );
240
241
242 // Button...
243 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.Button" );
244 xModelProv->createInstance()->queryInterface( XInterface::getSmartUik(), xModel );
245 DBG_ASSERT( xModel, "No Model!" );
246
247 xModel->queryInterface( XPropertySet::getSmartUik(), xPSet );
248 xPSet->setPropertyValue( L"Label", UsrAny( L"Press!" ) );
249
250 XServiceProviderRef xButtonCtrlProv = xProv->queryServiceProvider( L"stardiv.vcl.control.Button" );
251 XControlRef xButton1( xButtonCtrlProv->createInstance(), USR_QUERY );
252 xModel->queryInterface( XControlModel::getSmartUik(), xCM );
253 xButton1->setModel( xCM );
254 XWindowRef xButtonCmp1( xButton1, USR_QUERY );
255 xButtonCmp1->setPosSize( 170, 80, 80, 80, PosSize_POSSIZE );
256 // Unsichtbar, nur im MBDown mit DrawRoutine bei Doppel-Klick...
257 xButtonCmp1->setVisible( FALSE );
258 xDrawCtrl = xButton1;
259
260 xCont->addControl( L"", xButton1 );
261
262 /*
263
264 // ListBox...
265 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.ListBox" );
266 xModel = (XInterface*)xModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
267
268 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
269 Sequence<UString> aSeq( 7 );
270 aSeq.getArray()[0] = L"Item1";
271 aSeq.getArray()[1] = L"Item2";
272 aSeq.getArray()[2] = L"Item3";
273 aSeq.getArray()[3] = L"Item4";
274 aSeq.getArray()[4] = L"Item5";
275 aSeq.getArray()[5] = L"Item6";
276 aSeq.getArray()[6] = L"Item7";
277 xPSet->setPropertyValue( L"StringItemList", UsrAny( &aSeq, Sequence<UString>::getReflection() ) );
278 xPSet->setPropertyValue( L"LineCount", UsrAny_UINT16( 4 ) );
279 xPSet->setPropertyValue( L"Dropdown", UsrAny( (BOOL)TRUE ) );
280
281 XServiceProviderRef xListBoxCtrlProv = xProv->queryServiceProvider( L"stardiv.vcl.control.ListBox" );
282 XControlRef xListBox1 = (XControl*)xListBoxCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
283 xListBox1->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
284 XWindowRef xListBoxCmp1 = (XWindow*)xListBox1->queryInterface( XWindow::getSmartUik() );
285 xListBoxCmp1->setPosSize( 20, 250, 200, 20, PosSize_POSSIZE );
286 xCont->addControl( L"", xListBox1 );
287
288 // FixedText...
289 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.FixedText" );
290 xModel = (XInterface*)xModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
291 DBG_ASSERT( xModel, "No Model!" );
292
293 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
294 xPSet->setPropertyValue( L"Label", UsrAny( L"Label:" ) );
295 xPSet->setPropertyValue( L"BackgroundColor", UsrAny( (UINT32)0x00888888) );
296
297 Font_Attribs aFontAttrs;
298 aFontAttrs.Italic = ITALIC_NORMAL;
299 xPSet->setPropertyValue( L"Font_Attribs", UsrAny( &aFontAttrs, Font_Attribs_getReflection() ) );
300
301 XPropertyStateRef xState = (XPropertyState*)xPSet->queryInterface( XPropertyState::getSmartUik() );
302 xState->getPropertyState( L"Font_Attribs" );
303 xState->getPropertyState( L"Font_Size" );
304
305 XServiceProviderRef xFixedTextCtrlProv = xProv->queryServiceProvider( L"stardiv.vcl.control.FixedText" );
306 XControlRef xFixedText1 = (XControl*)xFixedTextCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
307 DBG_ASSERT( xFixedText1, "No FixedText!" );
308 xFixedText1->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
309 XWindowRef xFixedTextCmp1 = (XWindow*)xFixedText1->queryInterface( XWindow::getSmartUik() );
310 xFixedTextCmp1->setPosSize( 20, 20, 120, 20, PosSize_POSSIZE );
311 xCont->addControl( L"", xFixedText1 );
312
313 // TabTest...
314 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.GroupBox" );
315 xModel = (XInterface*)xModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
316 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
317 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio-Test:" ) );
318 XServiceProviderRef xGroupBoxCtrlProv = xProv->queryServiceProvider( L"stardiv.vcl.control.GroupBox" );
319 XControlRef xGroupBox1 = (XControl*)xGroupBoxCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
320 xGroupBox1->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
321 XWindowRef xGroupBoxCmp1 = (XWindow*)xGroupBox1->queryInterface( XWindow::getSmartUik() );
322 xGroupBoxCmp1->setPosSize( 30, 410, 100, 130, PosSize_POSSIZE );
323 xCont->addControl( L"", xGroupBox1 );
324
325 XServiceProviderRef xRadioButtonModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.RadioButton" );
326 XServiceProviderRef xRadioButtonCtrlProv = xProv->queryServiceProvider( L"stardiv.vcl.control.RadioButton" );
327
328 xModel = (XInterface*)xRadioButtonModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
329 XControlRef xT1 = (XControl*)xRadioButtonCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
330 xT1->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
331 XWindowRef xTC1 = (XWindow*)xT1->queryInterface( XWindow::getSmartUik() );
332 xTC1->setPosSize( 40, 430, 80, 20, PosSize_POSSIZE );
333 xCont->addControl( L"", xT1 );
334 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
335 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio1" ) );
336 xPSet->setPropertyValue( L"State", UsrAny_UINT16( 1 ) );
337
338 xModel = (XInterface*)xRadioButtonModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
339 XControlRef xT2 = (XControl*)xRadioButtonCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
340 xT2->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
341 XWindowRef xTC2 = (XWindow*)xT2->queryInterface( XWindow::getSmartUik() );
342 xTC2->setPosSize( 40, 470, 80, 20, PosSize_POSSIZE );
343 xCont->addControl( L"", xT2 );
344 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
345 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio2" ) );
346
347 xModel = (XInterface*)xRadioButtonModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
348 XControlRef xT3 = (XControl*)xRadioButtonCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
349 xT3->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
350 XWindowRef xTC3 = (XWindow*)xT3->queryInterface( XWindow::getSmartUik() );
351 xTC3->setPosSize( 40, 510, 80, 20, PosSize_POSSIZE );
352 xCont->addControl( L"", xT3 );
353 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
354 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio3" ) );
355
356 xModel = (XInterface*)xRadioButtonModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
357 XControlRef xT4 = (XControl*)xRadioButtonCtrlProv->createInstance()->queryInterface( XControl::getSmartUik() );
358 xT4->setModel( (XControlModel*)xModel->queryInterface( XControlModel::getSmartUik() ) );
359 XWindowRef xTC4 = (XWindow*)xT4->queryInterface( XWindow::getSmartUik() );
360 xTC4->setPosSize( 40, 550, 80, 20, PosSize_POSSIZE );
361 xCont->addControl( L"", xT4 );
362 xPSet = (XPropertySet*)xModel->queryInterface( XPropertySet::getSmartUik() );
363 xPSet->setPropertyValue( L"Label", UsrAny( L"Radio4 - no" ) );
364 xPSet->setPropertyValue( L"Tabstop", UsrAny( (BOOL)TRUE ) );
365
366 // TabController:
367 xModelProv = xProv->queryServiceProvider( L"stardiv.vcl.controlmodel.TabController" );
368 xModel = (XInterface*)xModelProv->createInstance()->queryInterface( XInterface::getSmartUik() );
369 XTabControllerModelRef xTCModel = (XTabControllerModel*)xModel->queryInterface( XTabControllerModel::getSmartUik() );
370
371 XServiceProviderRef xTCProv = xProv->queryServiceProvider( L"stardiv.vcl.control.TabController" );
372 XTabControllerRef xTC = (XTabController*)xTCProv->createInstance()->queryInterface( XTabController::getSmartUik() );
373 xTC->setModel( (XTabControllerModel*)xModel->queryInterface( XTabControllerModel::getSmartUik() ) );
374 XUnoControlContainerRef xUCC = (XUnoControlContainer*)xCont->queryInterface( XUnoControlContainer::getSmartUik() );
375 xUCC->addTabController( xTC );
376
377 Sequence<XControlModelRef> aControls( 5 );
378 aControls.getArray()[0] = xGroupBox1->getModel();
379 aControls.getArray()[1] = xT1->getModel();
380 aControls.getArray()[2] = xT3->getModel();
381 aControls.getArray()[3] = xT2->getModel();
382 aControls.getArray()[4] = xT4->getModel();
383 xTCModel->setControls( aControls );
384
385 Sequence<XControlModelRef> aGroup( 3 );
386 aGroup.getArray()[0] = xT1->getModel();
387 aGroup.getArray()[1] = xT3->getModel();
388 aGroup.getArray()[2] = xT2->getModel();
389 xTCModel->setGroup( aGroup, L"test" );
390 */
391 // Container anzeigen...
392 // Als Child zu diesem Fenster
393 xContControl->createPeer( XToolkitRef(), GetComponentInterface( TRUE ) );
394
395 XDeviceRef xD( xContControl->getPeer(), USR_QUERY );
396 xG = xD->createGraphics();
397 XViewRef xV ( xDrawCtrl, USR_QUERY );
398 xV->setGraphics( xG );
399
400 // ((UnoControl*)(XControl*)xNumField))->updateFromModel();
401
402 /*
403 // TEST:
404 WindowDecriptor aDescr;
405 aDescr.ComponentServiceName = "window";
406 aDescr.Type = VCLCOMPONENTTYPE_CONTAINER;
407 aDescr.Parent = GetComponentInterface( TRUE );
408 aDescr.WindowAttributes = WA_SHOW|WA_BORDER;
409 aDescr.Bounds = Rectangle( Point( 500, 50 ), Size( 300, 200 ) );
410 XVclWindowPeerRef xSPWin = xToolkit->createComponent( aDescr );
411
412 WindowDecriptor aDescr2;
413 aDescr2.ComponentServiceName = "scrollbar";
414 aDescr2.Type = VCLCOMPONENTTYPE_SIMPLE;
415 aDescr2.Parent = xSPWin;
416 aDescr2.WindowAttributes = WA_SHOW|WA_BORDER|WA_VSCROLL;
417 aDescr2.Bounds = Rectangle( Point( 250, 0 ), Size( 50, 200 ) );
418 XVclWindowPeerRef xSB = xToolkit->createComponent( aDescr2 );
419 */
420 }
421 return;
422 }
423 WorkWindow::MouseButtonDown( rMEvt );
424 }
425
426
427 // -----------------------------------------------------------------------
428
Resize()429 void MyWin::Resize()
430 {
431 WorkWindow::Resize();
432 }
433
Paint(const Rectangle & r)434 void MyWin::Paint( const Rectangle& r )
435 {
436 // Muss ueber PaintListener geschehen...
437 if ( xDrawCtrl.is() )
438 {
439 XViewRef xV( xDrawCtrl, USR_QUERY );
440 XWindowRef xC( xDrawCtrl, USR_QUERY );
441 xV->draw( xC->getPosSize().Left(), xC->getPosSize().Top() );
442 }
443
444 }
445
446