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 <com/sun/star/beans/PropertyAttribute.hpp> 27 28 #ifndef _SVWIN_HXX 29 #include <tools/svwin.h> 30 #endif 31 #include <stdio.h> 32 #include <com/sun/star/awt/ImageScaleMode.hpp> 33 #include <com/sun/star/awt/WindowAttribute.hpp> 34 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp> 35 #include <com/sun/star/awt/WindowClass.hpp> 36 #include <com/sun/star/awt/MessageBoxButtons.hpp> 37 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 38 #include <com/sun/star/lang/SystemDependent.hpp> 39 #include <com/sun/star/awt/FocusEvent.hpp> 40 #include <com/sun/star/awt/KeyEvent.hpp> 41 #include <com/sun/star/awt/KeyModifier.hpp> 42 #include <com/sun/star/lang/EventObject.hpp> 43 #include <com/sun/star/uno/Reference.hxx> 44 #include <com/sun/star/uno/Sequence.hxx> 45 #include <com/sun/star/uno/XInterface.hpp> 46 #include <com/sun/star/beans/NamedValue.hpp> 47 #include <cppuhelper/typeprovider.hxx> 48 #include <osl/conditn.hxx> 49 #include <rtl/memory.h> 50 #include <rtl/uuid.h> 51 #include <rtl/process.h> 52 53 #ifdef WNT 54 #include <tools/prewin.h> 55 #include <windows.h> 56 #include <tools/postwin.h> 57 #elif defined ( OS2 ) 58 #include <svpm.h> 59 #elif (defined QUARTZ) 60 #include "premac.h" 61 #include <Cocoa/Cocoa.h> 62 #include "postmac.h" 63 #endif 64 #include <vcl/sysdata.hxx> 65 66 #include <toolkit/awt/vclxwindows.hxx> 67 #include <toolkit/awt/vclxsystemdependentwindow.hxx> 68 #include <toolkit/awt/vclxregion.hxx> 69 #include <toolkit/awt/vclxtoolkit.hxx> 70 #include <toolkit/awt/vclxtabpagecontainer.hxx> 71 #include <toolkit/awt/vclxtabpagemodel.hxx> 72 73 #include <toolkit/awt/xsimpleanimation.hxx> 74 #include <toolkit/awt/animatedimagespeer.hxx> 75 #include <toolkit/awt/vclxtopwindow.hxx> 76 #include <toolkit/awt/vclxwindow.hxx> 77 #include <toolkit/helper/vclunohelper.hxx> 78 #include <toolkit/helper/unowrapper.hxx> 79 #include <toolkit/helper/servicenames.hxx> 80 81 82 #include <toolkit/helper/macros.hxx> 83 #include <toolkit/helper/convert.hxx> 84 #include <vcl/unohelp.hxx> 85 #include <vcl/btndlg.hxx> 86 #ifndef _SV_BUTTON_HXX 87 #include <vcl/button.hxx> 88 #endif 89 #include <vcl/combobox.hxx> 90 #include <vcl/ctrl.hxx> 91 #include <vcl/dialog.hxx> 92 #include <vcl/dockingarea.hxx> 93 #include <vcl/dockwin.hxx> 94 #include <vcl/edit.hxx> 95 #include <vcl/field.hxx> 96 #include <vcl/fixed.hxx> 97 #include <vcl/floatwin.hxx> 98 #include <vcl/group.hxx> 99 #include <vcl/imgctrl.hxx> 100 #include <vcl/longcurr.hxx> 101 #include <vcl/lstbox.hxx> 102 #include <vcl/menubtn.hxx> 103 #include <vcl/morebtn.hxx> 104 #include <vcl/msgbox.hxx> 105 #include <vcl/scrbar.hxx> 106 #include <vcl/spin.hxx> 107 #include <vcl/split.hxx> 108 #include <vcl/splitwin.hxx> 109 #include <vcl/status.hxx> 110 #include <vcl/svapp.hxx> 111 #include <vcl/syschild.hxx> 112 #include <vcl/tabctrl.hxx> 113 #include <vcl/tabdlg.hxx> 114 #include <vcl/tabpage.hxx> 115 #include <vcl/toolbox.hxx> 116 #include <vcl/virdev.hxx> 117 #include <vcl/window.hxx> 118 #include <vcl/wrkwin.hxx> 119 #include <vcl/throbber.hxx> 120 #include "toolkit/awt/vclxspinbutton.hxx" 121 122 #include <tools/debug.hxx> 123 #include <comphelper/processfactory.hxx> 124 125 namespace css = ::com::sun::star; 126 127 #define VCLWINDOW_FRAMEWINDOW 0x1000 128 #define VCLWINDOW_SYSTEMCHILDWINDOW 0x1001 129 130 #if (defined WNT) 131 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 132 #elif (defined OS2) 133 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_OS2 134 #elif (defined QUARTZ) 135 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_MAC 136 #elif (defined UNX) 137 #define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW 138 #endif 139 140 TOOLKIT_DLLPUBLIC WinBits ImplGetWinBits( sal_uInt32 nComponentAttribs, sal_uInt16 nCompType ) 141 { 142 WinBits nWinBits = 0; 143 144 sal_Bool bMessBox = sal_False; 145 if ( ( nCompType == WINDOW_INFOBOX ) || 146 ( nCompType == WINDOW_MESSBOX ) || 147 ( nCompType == WINDOW_QUERYBOX ) || 148 ( nCompType == WINDOW_WARNINGBOX ) || 149 ( nCompType == WINDOW_ERRORBOX ) ) 150 { 151 bMessBox = sal_True; 152 } 153 154 bool bDecoratedWindow = false; 155 if ( bMessBox 156 || ( nCompType == WINDOW_DIALOG ) 157 || ( nCompType == WINDOW_MODELESSDIALOG ) 158 || ( nCompType == WINDOW_MODALDIALOG ) 159 || ( nCompType == WINDOW_SYSTEMDIALOG ) 160 || ( nCompType == WINDOW_PATHDIALOG ) 161 || ( nCompType == WINDOW_FILEDIALOG ) 162 || ( nCompType == WINDOW_PRINTERSETUPDIALOG ) 163 || ( nCompType == WINDOW_PRINTDIALOG ) 164 || ( nCompType == WINDOW_COLORDIALOG ) 165 || ( nCompType == WINDOW_FONTDIALOG ) 166 || ( nCompType == WINDOW_DOCKINGWINDOW ) 167 || ( nCompType == WINDOW_TABDIALOG ) 168 || ( nCompType == WINDOW_BUTTONDIALOG ) 169 || ( nCompType == WINDOW_SYSTEMCHILDWINDOW ) 170 ) 171 { 172 bDecoratedWindow = true; 173 } 174 175 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::BORDER ) 176 nWinBits |= WB_BORDER; 177 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOBORDER ) 178 nWinBits |= WB_NOBORDER; 179 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::SIZEABLE ) 180 nWinBits |= WB_SIZEABLE; 181 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::MOVEABLE ) 182 nWinBits |= WB_MOVEABLE; 183 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::CLOSEABLE ) 184 nWinBits |= WB_CLOSEABLE; 185 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL ) 186 nWinBits |= WB_HSCROLL; 187 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL ) 188 nWinBits |= WB_VSCROLL; 189 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::LEFT ) 190 nWinBits |= WB_LEFT; 191 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CENTER ) 192 nWinBits |= WB_CENTER; 193 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RIGHT ) 194 nWinBits |= WB_RIGHT; 195 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SPIN ) 196 nWinBits |= WB_SPIN; 197 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SORT ) 198 nWinBits |= WB_SORT; 199 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DROPDOWN ) 200 nWinBits |= WB_DROPDOWN; 201 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEFBUTTON ) 202 nWinBits |= WB_DEFBUTTON; 203 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::READONLY ) 204 nWinBits |= WB_READONLY; 205 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CLIPCHILDREN ) 206 nWinBits |= WB_CLIPCHILDREN; 207 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::GROUP ) 208 nWinBits |= WB_GROUP; 209 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOLABEL ) //added for issue79712 210 nWinBits |= WB_NOLABEL; 211 212 // These bits are not uniqe 213 if ( bMessBox ) 214 { 215 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK ) 216 nWinBits |= WB_OK; 217 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK_CANCEL ) 218 nWinBits |= WB_OK_CANCEL; 219 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO ) 220 nWinBits |= WB_YES_NO; 221 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO_CANCEL ) 222 nWinBits |= WB_YES_NO_CANCEL; 223 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RETRY_CANCEL ) 224 nWinBits |= WB_RETRY_CANCEL; 225 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_OK ) 226 nWinBits |= WB_DEF_OK; 227 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_CANCEL ) 228 nWinBits |= WB_DEF_CANCEL; 229 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_RETRY ) 230 nWinBits |= WB_DEF_RETRY; 231 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_YES ) 232 nWinBits |= WB_DEF_YES; 233 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_NO ) 234 nWinBits |= WB_DEF_NO; 235 } 236 if ( nCompType == WINDOW_MULTILINEEDIT ) 237 { 238 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOHSCROLL ) 239 nWinBits |= WB_AUTOHSCROLL; 240 if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOVSCROLL ) 241 nWinBits |= WB_AUTOVSCROLL; 242 } 243 244 245 if ( bDecoratedWindow ) 246 { 247 if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::NODECORATION ) 248 { 249 // No decoration removes several window attributes and must 250 // set WB_NOBORDER! 251 nWinBits &= ~WB_BORDER; 252 nWinBits &= ~WB_SIZEABLE; 253 nWinBits &= ~WB_MOVEABLE; 254 nWinBits &= ~WB_CLOSEABLE; 255 nWinBits |= WB_NOBORDER; 256 } 257 } 258 259 return nWinBits; 260 } 261 262 struct ComponentInfo 263 { 264 const char* pName; 265 WindowType nWinType; 266 }; 267 268 static ComponentInfo __FAR_DATA aComponentInfos [] = 269 { 270 { "buttondialog", WINDOW_BUTTONDIALOG }, 271 { "cancelbutton", WINDOW_CANCELBUTTON }, 272 { "checkbox", WINDOW_CHECKBOX }, 273 { "combobox", WINDOW_COMBOBOX }, 274 { "control", WINDOW_CONTROL }, 275 { "currencybox", WINDOW_CURRENCYBOX }, 276 { "currencyfield", WINDOW_CURRENCYFIELD }, 277 { "datebox", WINDOW_DATEBOX }, 278 { "datefield", WINDOW_DATEFIELD }, 279 { "dialog", WINDOW_DIALOG }, 280 { "dockingarea", WINDOW_DOCKINGAREA }, 281 { "dockingwindow", WINDOW_DOCKINGWINDOW }, 282 { "edit", WINDOW_EDIT }, 283 { "errorbox", WINDOW_ERRORBOX }, 284 { "fixedbitmap", WINDOW_FIXEDBITMAP }, 285 { "fixedimage", WINDOW_FIXEDIMAGE }, 286 { "fixedline", WINDOW_FIXEDLINE }, 287 { "fixedtext", WINDOW_FIXEDTEXT }, 288 { "floatingwindow", WINDOW_FLOATINGWINDOW }, 289 { "framewindow", VCLWINDOW_FRAMEWINDOW }, 290 { "groupbox", WINDOW_GROUPBOX }, 291 { "helpbutton", WINDOW_HELPBUTTON }, 292 { "imagebutton", WINDOW_IMAGEBUTTON }, 293 { "imageradiobutton", WINDOW_IMAGERADIOBUTTON }, 294 { "infobox", WINDOW_INFOBOX }, 295 { "listbox", WINDOW_LISTBOX }, 296 { "longcurrencybox", WINDOW_LONGCURRENCYBOX }, 297 { "longcurrencyfield", WINDOW_LONGCURRENCYFIELD }, 298 { "menubutton", WINDOW_MENUBUTTON }, 299 { "messbox", WINDOW_MESSBOX }, 300 { "metricbox", WINDOW_METRICBOX }, 301 { "metricfield", WINDOW_METRICFIELD }, 302 { "modaldialog", WINDOW_MODALDIALOG }, 303 { "modelessdialog", WINDOW_MODELESSDIALOG }, 304 { "morebutton", WINDOW_MOREBUTTON }, 305 { "multilineedit", WINDOW_MULTILINEEDIT }, 306 { "multilistbox", WINDOW_MULTILISTBOX }, 307 { "numericbox", WINDOW_NUMERICBOX }, 308 { "numericfield", WINDOW_NUMERICFIELD }, 309 { "okbutton", WINDOW_OKBUTTON }, 310 { "patternbox", WINDOW_PATTERNBOX }, 311 { "patternfield", WINDOW_PATTERNFIELD }, 312 { "pushbutton", WINDOW_PUSHBUTTON }, 313 { "querybox", WINDOW_QUERYBOX }, 314 { "radiobutton", WINDOW_RADIOBUTTON }, 315 { "scrollbar", WINDOW_SCROLLBAR }, 316 { "scrollbarbox", WINDOW_SCROLLBARBOX }, 317 { "simpleanimation", WINDOW_CONTROL }, 318 { "animatedimages", WINDOW_CONTROL }, 319 { "spinbutton", WINDOW_SPINBUTTON }, 320 { "spinfield", WINDOW_SPINFIELD }, 321 { "splitter", WINDOW_SPLITTER }, 322 { "splitwindow", WINDOW_SPLITWINDOW }, 323 { "statusbar", WINDOW_STATUSBAR }, 324 { "systemchildwindow", VCLWINDOW_SYSTEMCHILDWINDOW }, 325 { "tabcontrol", WINDOW_TABCONTROL }, 326 { "tabdialog", WINDOW_TABDIALOG }, 327 { "tabpage", WINDOW_TABPAGE }, 328 { "timebox", WINDOW_TIMEBOX }, 329 { "timefield", WINDOW_TIMEFIELD }, 330 { "toolbox", WINDOW_TOOLBOX }, 331 { "tristatebox", WINDOW_TRISTATEBOX }, 332 { "warningbox", WINDOW_WARNINGBOX }, 333 { "window", WINDOW_WINDOW }, 334 { "workwindow", WINDOW_WORKWINDOW }, 335 { "tabpagecontainer", WINDOW_CONTROL }, 336 { "tabpagemodel", WINDOW_TABPAGE } 337 }; 338 339 extern "C" 340 { 341 static int 342 #if defined( WNT ) 343 __cdecl 344 #endif 345 #if defined( ICC ) && defined( OS2 ) 346 _Optlink 347 #endif 348 ComponentInfoCompare( const void* pFirst, const void* pSecond) 349 { 350 return( strcmp( ((ComponentInfo*)pFirst)->pName, 351 ((ComponentInfo*)pSecond)->pName ) ); 352 } 353 } 354 355 sal_uInt16 ImplGetComponentType( const String& rServiceName ) 356 { 357 static sal_Bool bSorted = sal_False; 358 if( !bSorted ) 359 { 360 qsort( (void*) aComponentInfos, 361 sizeof( aComponentInfos ) / sizeof( ComponentInfo ), 362 sizeof( ComponentInfo ), 363 ComponentInfoCompare ); 364 bSorted = sal_True; 365 } 366 367 368 ComponentInfo aSearch; 369 ByteString aServiceName( rServiceName, gsl_getSystemTextEncoding() ); 370 aServiceName.ToLowerAscii(); 371 if ( aServiceName.Len() ) 372 aSearch.pName = aServiceName.GetBuffer(); 373 else 374 aSearch.pName = "window"; 375 376 ComponentInfo* pInf = (ComponentInfo*) bsearch( &aSearch, 377 (void*) aComponentInfos, 378 sizeof( aComponentInfos ) / sizeof( ComponentInfo ), 379 sizeof( ComponentInfo ), 380 ComponentInfoCompare ); 381 382 return pInf ? pInf->nWinType : 0; 383 } 384 385 386 // ---------------------------------------------------- 387 // class VCLXToolkit 388 // ---------------------------------------------------- 389 390 static sal_Int32 nVCLToolkitInstanceCount = 0; 391 static sal_Bool bInitedByVCLToolkit = sal_False; 392 //static cppu::OInterfaceContainerHelper * pToolkits = 0; 393 394 static osl::Mutex & getInitMutex() 395 { 396 static osl::Mutex * pM; 397 if( !pM ) 398 { 399 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 400 if( !pM ) 401 { 402 static osl::Mutex aMutex; 403 pM = &aMutex; 404 } 405 } 406 return *pM; 407 } 408 409 static osl::Condition & getInitCondition() 410 { 411 static osl::Condition * pC = 0; 412 if( !pC ) 413 { 414 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 415 if( !pC ) 416 { 417 static osl::Condition aCondition; 418 pC = &aCondition; 419 } 420 } 421 return *pC; 422 } 423 424 struct ToolkitThreadData 425 { 426 VCLXToolkit * pTk; 427 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr; 428 429 ToolkitThreadData( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr, VCLXToolkit * pTk_ ) 430 : pTk( pTk_ ) 431 , xSMgr( rSMgr ) 432 { 433 } 434 }; 435 436 extern "C" 437 { 438 static void SAL_CALL ToolkitWorkerFunction( void* pArgs ) 439 { 440 ToolkitThreadData * pTTD = (ToolkitThreadData *)pArgs; 441 bInitedByVCLToolkit = InitVCL( pTTD->xSMgr ); 442 if( bInitedByVCLToolkit ) 443 { 444 UnoWrapper* pUnoWrapper = new UnoWrapper( pTTD->pTk ); 445 Application::SetUnoWrapper( pUnoWrapper ); 446 } 447 getInitCondition().set(); 448 if( bInitedByVCLToolkit ) 449 { 450 { 451 osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() ); 452 Application::Execute(); 453 } 454 try 455 { 456 pTTD->pTk->dispose(); 457 } 458 catch( com::sun::star::uno::Exception & ) 459 { 460 } 461 /* 462 if( pToolkits ) 463 { 464 cppu::OInterfaceIteratorHelper aIt( *pToolkits ); 465 ::com::sun::star::uno::XInterface * pI; 466 while( pI = aIt.next() ) 467 ((::com::sun::star::lang::XComponent *)pI)->dispose(); 468 469 // delete toolkit container 470 osl::Guard< osl::Mutex > aGuard( getInitMutex() ); 471 delete pToolkits; 472 pToolkits = 0; 473 } 474 */ 475 DeInitVCL(); 476 } 477 else 478 { 479 JoinMainLoopThread(); 480 } 481 delete pTTD; 482 } 483 } 484 485 // contructor, which might initialize VCL 486 VCLXToolkit::VCLXToolkit( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ): 487 cppu::WeakComponentImplHelper7< 488 ::com::sun::star::awt::XToolkit, 489 ::com::sun::star::lang::XServiceInfo, 490 ::com::sun::star::awt::XSystemChildFactory, 491 ::com::sun::star::awt::XMessageBoxFactory, 492 ::com::sun::star::awt::XDataTransferProviderAccess, 493 ::com::sun::star::awt::XExtendedToolkit, 494 ::com::sun::star::awt::XReschedule>( GetMutex() ), 495 m_aTopWindowListeners(rBHelper.rMutex), 496 m_aKeyHandlers(rBHelper.rMutex), 497 m_aFocusListeners(rBHelper.rMutex), 498 m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)), 499 m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)), 500 m_bEventListener(false), 501 m_bKeyListener(false) 502 { 503 hSvToolsLib = NULL; 504 fnSvtCreateWindow = NULL; 505 506 osl::Guard< osl::Mutex > aGuard( getInitMutex() ); 507 nVCLToolkitInstanceCount++; 508 if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) ) 509 { 510 // setup execute thread 511 CreateMainLoopThread( ToolkitWorkerFunction, new ToolkitThreadData( rSMgr, this ) ); 512 getInitCondition().wait(); 513 /* 514 if( bInitedByVCLToolkit ) 515 { 516 // insert in disposing list 517 if( !pToolkits ) 518 pToolkits = new cppu::OInterfaceContainerHelper( getInitMutex() ); 519 pToolkits->addInterface( (::com::sun::star::lang::XComponent *)this ); 520 } 521 */ 522 } 523 } 524 525 VCLXToolkit::~VCLXToolkit() 526 { 527 } 528 529 530 void SAL_CALL VCLXToolkit::disposing() 531 { 532 if ( hSvToolsLib ) 533 { 534 osl_unloadModule( hSvToolsLib ); 535 hSvToolsLib = NULL; 536 fnSvtCreateWindow = NULL; 537 } 538 539 { 540 osl::Guard< osl::Mutex > aGuard( getInitMutex() ); 541 if( --nVCLToolkitInstanceCount == 0 ) 542 { 543 if( bInitedByVCLToolkit ) 544 { 545 Application::Quit(); 546 JoinMainLoopThread(); 547 bInitedByVCLToolkit = sal_False; 548 } 549 } 550 } 551 552 if (m_bEventListener) 553 { 554 ::Application::RemoveEventListener(m_aEventListenerLink); 555 m_bEventListener = false; 556 } 557 if (m_bKeyListener) 558 { 559 ::Application::RemoveKeyListener(m_aKeyListenerLink); 560 m_bKeyListener = false; 561 } 562 ::css::lang::EventObject aEvent( 563 static_cast< ::cppu::OWeakObject * >(this)); 564 m_aTopWindowListeners.disposeAndClear(aEvent); 565 m_aKeyHandlers.disposeAndClear(aEvent); 566 m_aFocusListeners.disposeAndClear(aEvent); 567 568 /* 569 osl::Guard< osl::Mutex > aGuard( getInitMutex() ); 570 // insert in disposing list 571 if( pToolkits ) 572 { 573 // remove from the disposing list 574 pToolkits->removeInterface( (::com::sun::star::lang::XComponent *)this ); 575 } 576 */ 577 } 578 579 580 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::getDesktopWindow( ) throw(::com::sun::star::uno::RuntimeException) 581 { 582 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef; 583 // 07/00: AppWindow doesn't exist anymore... 584 return xRef; 585 } 586 587 ::com::sun::star::awt::Rectangle VCLXToolkit::getWorkArea( ) throw(::com::sun::star::uno::RuntimeException) 588 { 589 ::com::sun::star::awt::Rectangle aRect; 590 // 07/00: AppWindow doesn't exist anymore... 591 return aRect; 592 } 593 594 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::createWindow( const ::com::sun::star::awt::WindowDescriptor& rDescriptor ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 595 { 596 return ImplCreateWindow( rDescriptor, WinBits(0) ); 597 } 598 599 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) throw(::com::sun::star::uno::RuntimeException) 600 { 601 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 602 603 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > xRef; 604 VCLXVirtualDevice* pVDev = new VCLXVirtualDevice; 605 606 osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() ); 607 608 VirtualDevice* pV = new VirtualDevice; 609 pV->SetOutputSizePixel( Size( Width, Height ) ); 610 pVDev->SetVirtualDevice( pV ); 611 612 xRef = pVDev; 613 return xRef; 614 } 615 616 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > VCLXToolkit::createRegion( ) throw(::com::sun::star::uno::RuntimeException) 617 { 618 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 619 620 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > xRef = new VCLXRegion; 621 return xRef; 622 } 623 624 Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, 625 const ::com::sun::star::awt::WindowDescriptor& rDescriptor, 626 Window* pParent, WinBits nWinBits ) 627 { 628 String aServiceName( rDescriptor.WindowServiceName ); 629 aServiceName.ToLowerAscii(); 630 631 Window* pNewWindow = NULL; 632 sal_uInt16 nType = ImplGetComponentType( aServiceName ); 633 634 if ( !pParent ) 635 { 636 // Wenn die Component einen Parent braucht, dann NULL zurueckgeben, 637 // spaeter mal ::com::sun::star::uno::Exception... 638 sal_Bool bException = sal_True; 639 if ( ( nType == WINDOW_DIALOG ) 640 || ( nType == WINDOW_MODALDIALOG ) 641 || ( nType == WINDOW_MODELESSDIALOG ) 642 || ( nType == WINDOW_MESSBOX ) 643 || ( nType == WINDOW_INFOBOX ) 644 || ( nType == WINDOW_WARNINGBOX ) 645 || ( nType == WINDOW_ERRORBOX ) 646 || ( nType == WINDOW_QUERYBOX ) 647 ) 648 bException = sal_False; 649 else if ( ( nType == WINDOW_WINDOW ) || 650 ( nType == WINDOW_WORKWINDOW ) || 651 ( nType == VCLWINDOW_FRAMEWINDOW ) ) 652 { 653 if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP ) 654 bException = sal_False; 655 } 656 657 if ( bException ) 658 { 659 *ppNewComp = NULL; 660 return NULL; 661 } 662 } 663 664 if ( nType ) 665 { 666 vos::OGuard aVclGuard( Application::GetSolarMutex() ); 667 switch ( (WindowType)nType ) 668 { 669 case WINDOW_CANCELBUTTON: 670 pNewWindow = new CancelButton( pParent, nWinBits ); 671 *ppNewComp = new VCLXButton; 672 break; 673 case WINDOW_CHECKBOX: 674 pNewWindow = new CheckBox( pParent, nWinBits ); 675 *ppNewComp = new VCLXCheckBox; 676 break; 677 case WINDOW_COMBOBOX: 678 pNewWindow = new ComboBox( pParent, nWinBits|WB_AUTOHSCROLL ); 679 ((ComboBox*)pNewWindow)->EnableAutoSize( sal_False ); 680 *ppNewComp = new VCLXComboBox; 681 break; 682 case WINDOW_CURRENCYBOX: 683 pNewWindow = new CurrencyBox( pParent, nWinBits ); 684 break; 685 case WINDOW_CURRENCYFIELD: 686 pNewWindow = new CurrencyField( pParent, nWinBits ); 687 static_cast<CurrencyField*>(pNewWindow)->EnableEmptyFieldValue( sal_True ); 688 *ppNewComp = new VCLXNumericField; 689 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(CurrencyField*)pNewWindow ); 690 break; 691 case WINDOW_DATEBOX: 692 pNewWindow = new DateBox( pParent, nWinBits ); 693 break; 694 case WINDOW_DATEFIELD: 695 pNewWindow = new DateField( pParent, nWinBits ); 696 static_cast<DateField*>(pNewWindow)->EnableEmptyFieldValue( sal_True ); 697 *ppNewComp = new VCLXDateField; 698 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(DateField*)pNewWindow ); 699 break; 700 case WINDOW_DOCKINGAREA: 701 pNewWindow = new DockingAreaWindow( pParent ); 702 break; 703 case WINDOW_MULTILINEEDIT: 704 case WINDOW_EDIT: 705 pNewWindow = new Edit( pParent, nWinBits ); 706 *ppNewComp = new VCLXEdit; 707 break; 708 case WINDOW_ERRORBOX: 709 pNewWindow = new ErrorBox( pParent, nWinBits, String() ); 710 *ppNewComp = new VCLXMessageBox; 711 break; 712 case WINDOW_FIXEDBITMAP: 713 pNewWindow = new FixedBitmap( pParent, nWinBits ); 714 break; 715 case WINDOW_FIXEDIMAGE: 716 pNewWindow = new ImageControl( pParent, nWinBits ); 717 *ppNewComp = new VCLXImageControl; 718 break; 719 case WINDOW_FIXEDLINE: 720 pNewWindow = new FixedLine( pParent, nWinBits ); 721 break; 722 case WINDOW_FIXEDTEXT: 723 pNewWindow = new FixedText( pParent, nWinBits ); 724 *ppNewComp = new VCLXFixedText; 725 break; 726 case WINDOW_FLOATINGWINDOW: 727 pNewWindow = new FloatingWindow( pParent, nWinBits ); 728 break; 729 case WINDOW_GROUPBOX: 730 pNewWindow = new GroupBox( pParent, nWinBits ); 731 break; 732 case WINDOW_HELPBUTTON: 733 pNewWindow = new HelpButton( pParent, nWinBits ); 734 *ppNewComp = new VCLXButton; 735 break; 736 case WINDOW_IMAGEBUTTON: 737 pNewWindow = new ImageButton( pParent, nWinBits ); 738 *ppNewComp = new VCLXButton; 739 break; 740 case WINDOW_IMAGERADIOBUTTON: 741 pNewWindow = new ImageRadioButton( pParent, nWinBits ); 742 *ppNewComp = new VCLXButton; 743 break; 744 case WINDOW_INFOBOX: 745 pNewWindow = new InfoBox( pParent, String() ); 746 *ppNewComp = new VCLXMessageBox; 747 break; 748 case WINDOW_LISTBOX: 749 pNewWindow = new ListBox( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL ); 750 ((ListBox*)pNewWindow)->EnableAutoSize( sal_False ); 751 *ppNewComp = new VCLXListBox; 752 break; 753 case WINDOW_LONGCURRENCYBOX: 754 pNewWindow = new LongCurrencyBox( pParent, nWinBits ); 755 break; 756 case WINDOW_LONGCURRENCYFIELD: 757 pNewWindow = new LongCurrencyField( pParent, nWinBits ); 758 *ppNewComp = new VCLXCurrencyField; 759 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(LongCurrencyField*)pNewWindow ); 760 break; 761 case WINDOW_MENUBUTTON: 762 pNewWindow = new MenuButton( pParent, nWinBits ); 763 *ppNewComp = new VCLXButton; 764 break; 765 case WINDOW_MESSBOX: 766 pNewWindow = new MessBox( pParent, nWinBits, String(), String() ); 767 *ppNewComp = new VCLXMessageBox; 768 break; 769 case WINDOW_METRICBOX: 770 pNewWindow = new MetricBox( pParent, nWinBits ); 771 break; 772 case WINDOW_METRICFIELD: 773 pNewWindow = new MetricField( pParent, nWinBits ); 774 *ppNewComp = new VCLXMetricField; 775 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(MetricField*)pNewWindow ); 776 break; 777 case WINDOW_DIALOG: 778 case WINDOW_MODALDIALOG: 779 case WINDOW_MODELESSDIALOG: 780 { 781 // Modal/Modeless nur durch Show/Execute 782 if ( (pParent == NULL ) && ( rDescriptor.ParentIndex == -1 ) ) 783 pParent = DIALOG_NO_PARENT; 784 pNewWindow = new Dialog( pParent, nWinBits ); 785 // #i70217# Don't always create a new component object. It's possible that VCL has called 786 // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() ) 787 // which creates a component object. 788 css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( sal_False ); 789 if ( xWinPeer.is() ) 790 *ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() ); 791 else 792 *ppNewComp = new VCLXDialog; 793 } 794 break; 795 case WINDOW_MOREBUTTON: 796 pNewWindow = new MoreButton( pParent, nWinBits ); 797 *ppNewComp = new VCLXButton; 798 break; 799 case WINDOW_MULTILISTBOX: 800 pNewWindow = new MultiListBox( pParent, nWinBits ); 801 *ppNewComp = new VCLXListBox; 802 break; 803 case WINDOW_NUMERICBOX: 804 pNewWindow = new NumericBox( pParent, nWinBits ); 805 break; 806 case WINDOW_NUMERICFIELD: 807 pNewWindow = new NumericField( pParent, nWinBits ); 808 static_cast<NumericField*>(pNewWindow)->EnableEmptyFieldValue( sal_True ); 809 *ppNewComp = new VCLXNumericField; 810 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(NumericField*)pNewWindow ); 811 break; 812 case WINDOW_OKBUTTON: 813 pNewWindow = new OKButton( pParent, nWinBits ); 814 *ppNewComp = new VCLXButton; 815 break; 816 case WINDOW_PATTERNBOX: 817 pNewWindow = new PatternBox( pParent, nWinBits ); 818 break; 819 case WINDOW_PATTERNFIELD: 820 pNewWindow = new PatternField( pParent, nWinBits ); 821 *ppNewComp = new VCLXPatternField; 822 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(PatternField*)pNewWindow ); 823 break; 824 case WINDOW_PUSHBUTTON: 825 pNewWindow = new PushButton( pParent, nWinBits ); 826 *ppNewComp = new VCLXButton; 827 break; 828 case WINDOW_QUERYBOX: 829 pNewWindow = new QueryBox( pParent, nWinBits, String() ); 830 *ppNewComp = new VCLXMessageBox; 831 break; 832 case WINDOW_RADIOBUTTON: 833 pNewWindow = new RadioButton( pParent, nWinBits ); 834 *ppNewComp = new VCLXRadioButton; 835 836 // by default, disable RadioCheck 837 // Since the VCLXRadioButton really cares for it's RadioCheck settings, this is important: 838 // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState 839 // This leads to a strange behaviour if the control is newly created: when settings the initial 840 // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck 841 // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls 842 // is not really valid: the controls are grouped after they have been created, but we're still in 843 // the creation process, so the RadioButton::Check relies on invalid grouping information. 844 // 07.08.2001 - #87254# - frank.schoenheit@sun.com 845 static_cast<RadioButton*>(pNewWindow)->EnableRadioCheck( sal_False ); 846 break; 847 case WINDOW_SCROLLBAR: 848 pNewWindow = new ScrollBar( pParent, nWinBits ); 849 *ppNewComp = new VCLXScrollBar; 850 break; 851 case WINDOW_SCROLLBARBOX: 852 pNewWindow = new ScrollBarBox( pParent, nWinBits ); 853 break; 854 case WINDOW_SPINBUTTON: 855 pNewWindow = new SpinButton( pParent, nWinBits ); 856 *ppNewComp = new ::toolkit::VCLXSpinButton; 857 break; 858 case WINDOW_SPINFIELD: 859 pNewWindow = new SpinField( pParent, nWinBits ); 860 *ppNewComp = new VCLXNumericField; 861 break; 862 case WINDOW_SPLITTER: 863 pNewWindow = new Splitter( pParent, nWinBits ); 864 break; 865 case WINDOW_SPLITWINDOW: 866 pNewWindow = new SplitWindow( pParent, nWinBits ); 867 break; 868 case WINDOW_STATUSBAR: 869 pNewWindow = new StatusBar( pParent, nWinBits ); 870 break; 871 case VCLWINDOW_SYSTEMCHILDWINDOW: 872 pNewWindow = new SystemChildWindow( pParent, nWinBits ); 873 *ppNewComp = new VCLXSystemDependentWindow(); 874 break; 875 case WINDOW_TABCONTROL: 876 pNewWindow = new TabControl( pParent, nWinBits ); 877 *ppNewComp = new VCLXTabPageContainer; 878 break; 879 case WINDOW_TABDIALOG: 880 pNewWindow = new TabDialog( pParent, nWinBits ); 881 break; 882 case WINDOW_TABPAGE: 883 /* 884 if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase( 885 ::rtl::OUString::createFromAscii("tabpagemodel") ) ) 886 { 887 pNewWindow = new TabControl( pParent, nWinBits ); 888 *ppNewComp = new VCLXTabPageContainer; 889 } 890 else 891 */ 892 { 893 pNewWindow = new TabPage( pParent, nWinBits ); 894 *ppNewComp = new VCLXTabPage; 895 } 896 break; 897 case WINDOW_TIMEBOX: 898 pNewWindow = new TimeBox( pParent, nWinBits ); 899 break; 900 case WINDOW_TIMEFIELD: 901 pNewWindow = new TimeField( pParent, nWinBits ); 902 static_cast<TimeField*>(pNewWindow)->EnableEmptyFieldValue( sal_True ); 903 *ppNewComp = new VCLXTimeField; 904 ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(TimeField*)pNewWindow ); 905 break; 906 case WINDOW_TOOLBOX: 907 pNewWindow = new ToolBox( pParent, nWinBits ); 908 *ppNewComp = new VCLXToolBox; 909 break; 910 case WINDOW_TRISTATEBOX: 911 pNewWindow = new TriStateBox( pParent, nWinBits ); 912 break; 913 case WINDOW_WARNINGBOX: 914 pNewWindow = new WarningBox( pParent, nWinBits, String() ); 915 *ppNewComp = new VCLXMessageBox; 916 break; 917 case WINDOW_WORKWINDOW: 918 case WINDOW_WINDOW: 919 case VCLWINDOW_FRAMEWINDOW: 920 case WINDOW_DOCKINGWINDOW: 921 if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP ) 922 { 923 if (nType == WINDOW_DOCKINGWINDOW ) 924 pNewWindow = new DockingWindow( pParent, nWinBits ); 925 else 926 { 927 if ((pParent == NULL) && rDescriptor.Parent.is()) 928 { 929 // try to get a system dependent window handle 930 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, ::com::sun::star::uno::UNO_QUERY); 931 932 if (xSystemDepParent.is()) 933 { 934 sal_Int8 processID[16]; 935 936 rtl_getGlobalProcessId( (sal_uInt8*)processID ); 937 938 ::com::sun::star::uno::Sequence<sal_Int8> processIdSeq(processID, 16); 939 940 ::com::sun::star::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE); 941 942 // use sal_Int64 here to accomodate all int types 943 // uno::Any shift operator whill upcast if necessary 944 sal_Int64 nWindowHandle = 0; 945 sal_Bool bXEmbed = sal_False; 946 947 bool bUseParentData = true; 948 if( ! (anyHandle >>= nWindowHandle) ) 949 { 950 css::uno::Sequence< css::beans::NamedValue > aProps; 951 if( anyHandle >>= aProps ) 952 { 953 const int nProps = aProps.getLength(); 954 const css::beans::NamedValue* pProps = aProps.getConstArray(); 955 for( int i = 0; i < nProps; i++ ) 956 { 957 if( pProps[i].Name.equalsAscii( "WINDOW" ) ) 958 pProps[i].Value >>= nWindowHandle; 959 else if( pProps[i].Name.equalsAscii( "XEMBED" ) ) 960 pProps[i].Value >>= bXEmbed; 961 } 962 } 963 else 964 bUseParentData = false; 965 } 966 967 if( bUseParentData ) 968 { 969 SystemParentData aParentData; 970 aParentData.nSize = sizeof( aParentData ); 971 #if defined QUARTZ 972 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle); 973 #elif defined UNX 974 aParentData.aWindow = nWindowHandle; 975 aParentData.bXEmbedSupport = bXEmbed; 976 #elif defined WNT 977 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle); 978 #elif defined OS2 979 aParentData.hWnd = (HWND)nWindowHandle; 980 #endif 981 pNewWindow = new WorkWindow( &aParentData ); 982 } 983 } 984 } 985 986 if (!pNewWindow) 987 pNewWindow = new WorkWindow( pParent, nWinBits ); 988 } 989 990 *ppNewComp = new VCLXTopWindow( pNewWindow->GetType() == WINDOW_WORKWINDOW ); 991 } 992 else if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_CONTAINER ) 993 { 994 if (nType == WINDOW_DOCKINGWINDOW ) 995 pNewWindow = new DockingWindow( pParent, nWinBits ); 996 else 997 pNewWindow = new Window( pParent, nWinBits ); 998 *ppNewComp = new VCLXContainer; 999 } 1000 else 1001 { 1002 if (nType == WINDOW_DOCKINGWINDOW ) 1003 pNewWindow = new DockingWindow( pParent, nWinBits ); 1004 else 1005 pNewWindow = new Window( pParent, nWinBits ); 1006 *ppNewComp = new VCLXWindow; 1007 } 1008 break; 1009 case WINDOW_CONTROL: 1010 if ( aServiceName.EqualsAscii( "simpleanimation" ) ) 1011 { 1012 pNewWindow = new Throbber( pParent, nWinBits, Throbber::IMAGES_NONE ); 1013 ((Throbber*)pNewWindow)->SetScaleMode( css::awt::ImageScaleMode::Anisotropic ); 1014 // (compatibility) 1015 *ppNewComp = new ::toolkit::XSimpleAnimation; 1016 } 1017 else if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase( 1018 ::rtl::OUString::createFromAscii("tabpagecontainer") ) ) 1019 { 1020 pNewWindow = new TabControl( pParent, nWinBits ); 1021 *ppNewComp = new VCLXTabPageContainer; 1022 } 1023 else if ( aServiceName.EqualsAscii( "animatedimages" ) ) 1024 { 1025 pNewWindow = new Throbber( pParent, nWinBits ); 1026 *ppNewComp = new ::toolkit::AnimatedImagesPeer; 1027 } 1028 break; 1029 default: 1030 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" ); 1031 break; 1032 } 1033 } 1034 1035 return pNewWindow; 1036 } 1037 1038 extern "C" { static void SAL_CALL thisModule() {} } 1039 1040 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow( 1041 const css::awt::WindowDescriptor& rDescriptor, 1042 WinBits nForceWinBits ) 1043 { 1044 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 1045 1046 osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() ); 1047 1048 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef; 1049 1050 Window* pParent = NULL; 1051 if ( rDescriptor.Parent.is() ) 1052 { 1053 VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( rDescriptor.Parent ); 1054 1055 // #103939# Don't through assertion, may be it's a system dependend window, used in ImplCreateWindow. 1056 // DBG_ASSERT( pParentComponent, "ParentComponent not valid" ); 1057 1058 if ( pParentComponent ) 1059 pParent = pParentComponent->GetWindow(); 1060 } 1061 1062 WinBits nWinBits = ImplGetWinBits( rDescriptor.WindowAttributes, 1063 ImplGetComponentType( rDescriptor.WindowServiceName ) ); 1064 nWinBits |= nForceWinBits; 1065 1066 VCLXWindow* pNewComp = NULL; 1067 1068 Window* pNewWindow = NULL; 1069 // Try to create the window with SvTools 1070 // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way, 1071 // and we need to stay compatible) 1072 // try to load the lib 1073 if ( !fnSvtCreateWindow && !hSvToolsLib ) 1074 { 1075 ::rtl::OUString aLibName = ::vcl::unohelper::CreateLibraryName( "svt", sal_True ); 1076 hSvToolsLib = osl_loadModuleRelative( 1077 &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT ); 1078 if ( hSvToolsLib ) 1079 { 1080 ::rtl::OUString aFunctionName( RTL_CONSTASCII_USTRINGPARAM( "CreateWindow" ) ); 1081 fnSvtCreateWindow = (FN_SvtCreateWindow)osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData ); 1082 } 1083 } 1084 // ask the SvTool creation function 1085 if ( fnSvtCreateWindow ) 1086 pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits ); 1087 1088 // if SvTools could not provide a window, create it ourself 1089 if ( !pNewWindow ) 1090 pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits ); 1091 1092 DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" ); 1093 DBG_ASSERTWARNING( pNewComp, "createWindow: No special Interface!" ); 1094 1095 if ( pNewWindow ) 1096 { 1097 pNewWindow->SetCreatedWithToolkit( sal_True ); 1098 //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead 1099 1100 if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::MINSIZE ) 1101 { 1102 pNewWindow->SetSizePixel( Size() ); 1103 } 1104 else if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::FULLSIZE ) 1105 { 1106 if ( pParent ) 1107 pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() ); 1108 } 1109 else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) ) 1110 { 1111 Rectangle aRect = VCLRectangle( rDescriptor.Bounds ); 1112 pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() ); 1113 } 1114 1115 if ( !pNewComp ) 1116 { 1117 // Default-Interface 1118 xRef = pNewWindow->GetComponentInterface( sal_True ); 1119 } 1120 else 1121 { 1122 pNewComp->SetCreatedWithToolkit( sal_True ); 1123 xRef = pNewComp; 1124 pNewWindow->SetComponentInterface( xRef ); 1125 } 1126 DBG_ASSERT( pNewWindow->GetComponentInterface( sal_False ) == xRef, 1127 "VCLXToolkit::createWindow: did #133706# resurge?" ); 1128 1129 if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::SHOW ) 1130 pNewWindow->Show(); 1131 } 1132 1133 return xRef; 1134 } 1135 1136 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > VCLXToolkit::createWindows( const ::com::sun::star::uno::Sequence< ::com::sun::star::awt::WindowDescriptor >& rDescriptors ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1137 { 1138 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 1139 1140 sal_uInt32 nComponents = rDescriptors.getLength(); 1141 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > aSeq( nComponents ); 1142 for ( sal_uInt32 n = 0; n < nComponents; n++ ) 1143 { 1144 ::com::sun::star::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n]; 1145 1146 if ( aDescr.ParentIndex == (-1) ) 1147 aDescr.Parent = NULL; 1148 else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < (short)n ) ) 1149 aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex]; 1150 aSeq.getArray()[n] = createWindow( aDescr ); 1151 } 1152 return aSeq; 1153 } 1154 1155 // ::com::sun::star::awt::XSystemChildFactory 1156 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::createSystemChild( const ::com::sun::star::uno::Any& Parent, const ::com::sun::star::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 nSystemType ) throw(::com::sun::star::uno::RuntimeException) 1157 { 1158 Window* pChildWindow = NULL; 1159 if ( nSystemType == SYSTEM_DEPENDENT_TYPE ) 1160 { 1161 // use sal_Int64 here to accomodate all int types 1162 // uno::Any shift operator whill upcast if necessary 1163 sal_Int64 nWindowHandle = 0; 1164 sal_Bool bXEmbed = sal_False; 1165 1166 bool bUseParentData = true; 1167 if( ! (Parent >>= nWindowHandle) ) 1168 { 1169 css::uno::Sequence< css::beans::NamedValue > aProps; 1170 if( Parent >>= aProps ) 1171 { 1172 const int nProps = aProps.getLength(); 1173 const css::beans::NamedValue* pProps = aProps.getConstArray(); 1174 for( int i = 0; i < nProps; i++ ) 1175 { 1176 if( pProps[i].Name.equalsAscii( "WINDOW" ) ) 1177 pProps[i].Value >>= nWindowHandle; 1178 else if( pProps[i].Name.equalsAscii( "XEMBED" ) ) 1179 pProps[i].Value >>= bXEmbed; 1180 } 1181 } 1182 else 1183 bUseParentData = false; 1184 } 1185 1186 if( bUseParentData ) 1187 { 1188 SystemParentData aParentData; 1189 aParentData.nSize = sizeof( aParentData ); 1190 #if defined QUARTZ 1191 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle); 1192 #elif defined UNX 1193 aParentData.aWindow = nWindowHandle; 1194 aParentData.bXEmbedSupport = bXEmbed; 1195 #elif defined WNT 1196 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle); 1197 #elif defined OS2 1198 aParentData.hWnd = (HWND)nWindowHandle; 1199 #endif 1200 osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() ); 1201 try 1202 { 1203 pChildWindow = new WorkWindow( &aParentData ); 1204 } 1205 catch ( ::com::sun::star::uno::RuntimeException & rEx ) 1206 { 1207 // system child window could not be created 1208 OSL_TRACE( 1209 "VCLXToolkit::createSystemChild: caught %s\n", 1210 ::rtl::OUStringToOString( 1211 rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); 1212 pChildWindow = NULL; 1213 } 1214 } 1215 } 1216 else if (nSystemType == com::sun::star::lang::SystemDependent::SYSTEM_JAVA) 1217 { 1218 osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex()); 1219 pChildWindow = new WorkWindow(0, Parent); 1220 } 1221 1222 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xPeer; 1223 if ( pChildWindow ) 1224 { 1225 VCLXTopWindow* pPeer = new VCLXTopWindow(true); 1226 osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() ); 1227 pPeer->SetWindow( pChildWindow ); 1228 xPeer = pPeer; 1229 } 1230 1231 return xPeer; 1232 } 1233 1234 // ::com::sun::star::awt::XMessageBoxFactory 1235 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox( 1236 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& aParent, 1237 const ::com::sun::star::awt::Rectangle& aPosSize, 1238 const ::rtl::OUString& aType, 1239 ::sal_Int32 aButtons, 1240 const ::rtl::OUString& aTitle, 1241 const ::rtl::OUString& aMessage ) throw (::com::sun::star::uno::RuntimeException) 1242 { 1243 ::com::sun::star::awt::WindowDescriptor aDescriptor; 1244 1245 sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE; 1246 1247 // Map button definitions to window attributes 1248 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK ) 1249 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK; 1250 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL ) 1251 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL; 1252 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO ) 1253 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO; 1254 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL ) 1255 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL; 1256 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL ) 1257 nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL; 1258 1259 // Map default button definitions to window attributes 1260 if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK ) 1261 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK; 1262 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL ) 1263 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL; 1264 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES ) 1265 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES; 1266 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO ) 1267 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO; 1268 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY ) 1269 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY; 1270 1271 // No more bits for VclWindowPeerAttribute possible. Mapping must be 1272 // done explicitly using VCL methods 1273 WinBits nAddWinBits( 0 ); 1274 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY ) 1275 nAddWinBits |= WB_ABORT_RETRY_IGNORE; 1276 if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE ) 1277 nAddWinBits |= WB_DEF_IGNORE; 1278 1279 aDescriptor.Type = css::awt::WindowClass_MODALTOP; 1280 aDescriptor.WindowServiceName = aType; 1281 aDescriptor.ParentIndex = -1; 1282 aDescriptor.Parent = aParent; 1283 aDescriptor.Bounds = aPosSize; 1284 aDescriptor.WindowAttributes = nWindowAttributes; 1285 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > xMsgBox( 1286 ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY ); 1287 css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY ); 1288 if ( xMsgBox.is() && xWindow.is() ) 1289 { 1290 Window * pWindow = VCLUnoHelper::GetWindow( xWindow ); 1291 if ( pWindow ) 1292 { 1293 osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex()); 1294 xMsgBox->setCaptionText( aTitle ); 1295 xMsgBox->setMessageText( aMessage ); 1296 } 1297 } 1298 1299 return xMsgBox; 1300 } 1301 1302 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL VCLXToolkit::getDragGestureRecognizer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& window ) throw(::com::sun::star::uno::RuntimeException) 1303 { 1304 Window * pWindow = VCLUnoHelper::GetWindow( window ); 1305 1306 if( pWindow ) 1307 return pWindow->GetDragGestureRecognizer(); 1308 1309 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer >(); 1310 } 1311 1312 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource > SAL_CALL VCLXToolkit::getDragSource( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& window ) throw(::com::sun::star::uno::RuntimeException) 1313 { 1314 Window * pWindow = VCLUnoHelper::GetWindow( window ); 1315 1316 if( pWindow ) 1317 return pWindow->GetDragSource(); 1318 1319 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource >(); 1320 } 1321 1322 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget > SAL_CALL VCLXToolkit::getDropTarget( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& window ) throw(::com::sun::star::uno::RuntimeException) 1323 { 1324 Window * pWindow = VCLUnoHelper::GetWindow( window ); 1325 1326 if( pWindow ) 1327 return pWindow->GetDropTarget(); 1328 1329 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget >(); 1330 } 1331 1332 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > SAL_CALL VCLXToolkit::getClipboard( const ::rtl::OUString& clipboardName ) throw(::com::sun::star::uno::RuntimeException) 1333 { 1334 if( clipboardName.getLength() == 0 ) 1335 { 1336 if( !mxClipboard.is() ) 1337 { 1338 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); 1339 if ( xFactory.is() ) 1340 { 1341 // remember clipboard here 1342 mxClipboard = ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > ( 1343 xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.SystemClipboard" ) ), ::com::sun::star::uno::UNO_QUERY ); 1344 } 1345 } 1346 1347 return mxClipboard; 1348 } 1349 1350 else if( clipboardName.equals( ::rtl::OUString::createFromAscii("Selection") ) ) 1351 { 1352 return mxSelection; 1353 } 1354 1355 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >(); 1356 } 1357 1358 // XServiceInfo 1359 ::rtl::OUString VCLXToolkit::getImplementationName() throw(::com::sun::star::uno::RuntimeException) 1360 { 1361 return rtl::OUString::createFromAscii( "stardiv.Toolkit.VCLXToolkit" ); 1362 } 1363 1364 sal_Bool VCLXToolkit::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException) 1365 { 1366 ::osl::MutexGuard aGuard( GetMutex() ); 1367 1368 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames(); 1369 const ::rtl::OUString* pArray = aSNL.getConstArray(); 1370 const ::rtl::OUString* pArrayEnd = aSNL.getConstArray(); 1371 for (; pArray != pArrayEnd; ++pArray ) 1372 if( *pArray == rServiceName ) 1373 break; 1374 1375 return pArray != pArrayEnd; 1376 } 1377 1378 ::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXToolkit::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) 1379 { 1380 ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit ) ); 1381 return ::com::sun::star::uno::Sequence< ::rtl::OUString >( &aServiceName, 1); 1382 } 1383 1384 // css::awt::XExtendedToolkit: 1385 1386 // virtual 1387 ::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount() 1388 throw (::css::uno::RuntimeException) 1389 { 1390 return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount()); 1391 // XXX numeric overflow 1392 } 1393 1394 // virtual 1395 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL 1396 VCLXToolkit::getTopWindow(::sal_Int32 nIndex) 1397 throw (::css::uno::RuntimeException) 1398 { 1399 ::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex)); 1400 // XXX numeric overflow 1401 return ::css::uno::Reference< ::css::awt::XTopWindow >( 1402 p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()), 1403 ::css::uno::UNO_QUERY); 1404 } 1405 1406 // virtual 1407 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL 1408 VCLXToolkit::getActiveTopWindow() throw (::css::uno::RuntimeException) 1409 { 1410 ::Window * p = ::Application::GetActiveTopWindow(); 1411 return ::css::uno::Reference< ::css::awt::XTopWindow >( 1412 p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()), 1413 ::css::uno::UNO_QUERY); 1414 } 1415 1416 // virtual 1417 void SAL_CALL VCLXToolkit::addTopWindowListener( 1418 ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener) 1419 throw (::css::uno::RuntimeException) 1420 { 1421 OSL_ENSURE(rListener.is(), "Null rListener"); 1422 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); 1423 if (rBHelper.bDisposed || rBHelper.bInDispose) 1424 { 1425 aGuard.clear(); 1426 rListener->disposing( 1427 ::css::lang::EventObject( 1428 static_cast< ::cppu::OWeakObject * >(this))); 1429 } 1430 else if (m_aTopWindowListeners.addInterface(rListener) == 1 1431 && !m_bEventListener) 1432 { 1433 m_bEventListener = true; 1434 ::Application::AddEventListener(m_aEventListenerLink); 1435 } 1436 } 1437 1438 // virtual 1439 void SAL_CALL VCLXToolkit::removeTopWindowListener( 1440 ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener) 1441 throw (::css::uno::RuntimeException) 1442 { 1443 ::osl::MutexGuard aGuard(rBHelper.rMutex); 1444 if (!(rBHelper.bDisposed || rBHelper.bInDispose) 1445 && m_aTopWindowListeners.removeInterface(rListener) == 0 1446 && m_aFocusListeners.getLength() == 0 && m_bEventListener) 1447 { 1448 ::Application::RemoveEventListener(m_aEventListenerLink); 1449 m_bEventListener = false; 1450 } 1451 } 1452 1453 // virtual 1454 void SAL_CALL VCLXToolkit::addKeyHandler( 1455 ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler) 1456 throw (::css::uno::RuntimeException) 1457 { 1458 OSL_ENSURE(rHandler.is(), "Null rHandler"); 1459 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); 1460 if (rBHelper.bDisposed || rBHelper.bInDispose) 1461 { 1462 aGuard.clear(); 1463 rHandler->disposing( 1464 ::css::lang::EventObject( 1465 static_cast< ::cppu::OWeakObject * >(this))); 1466 } 1467 else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener) 1468 { 1469 m_bKeyListener = true; 1470 ::Application::AddKeyListener(m_aKeyListenerLink); 1471 } 1472 } 1473 1474 // virtual 1475 void SAL_CALL VCLXToolkit::removeKeyHandler( 1476 ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler) 1477 throw (::css::uno::RuntimeException) 1478 { 1479 ::osl::MutexGuard aGuard(rBHelper.rMutex); 1480 if (!(rBHelper.bDisposed || rBHelper.bInDispose) 1481 && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener) 1482 { 1483 ::Application::RemoveKeyListener(m_aKeyListenerLink); 1484 m_bKeyListener = false; 1485 } 1486 } 1487 1488 // virtual 1489 void SAL_CALL VCLXToolkit::addFocusListener( 1490 ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener) 1491 throw (::css::uno::RuntimeException) 1492 { 1493 OSL_ENSURE(rListener.is(), "Null rListener"); 1494 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); 1495 if (rBHelper.bDisposed || rBHelper.bInDispose) 1496 { 1497 aGuard.clear(); 1498 rListener->disposing( 1499 ::css::lang::EventObject( 1500 static_cast< ::cppu::OWeakObject * >(this))); 1501 } 1502 else if (m_aFocusListeners.addInterface(rListener) == 1 1503 && !m_bEventListener) 1504 { 1505 m_bEventListener = true; 1506 ::Application::AddEventListener(m_aEventListenerLink); 1507 } 1508 } 1509 1510 // virtual 1511 void SAL_CALL VCLXToolkit::removeFocusListener( 1512 ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener) 1513 throw (::css::uno::RuntimeException) 1514 { 1515 ::osl::MutexGuard aGuard(rBHelper.rMutex); 1516 if (!(rBHelper.bDisposed || rBHelper.bInDispose) 1517 && m_aFocusListeners.removeInterface(rListener) == 0 1518 && m_aTopWindowListeners.getLength() == 0 && m_bEventListener) 1519 { 1520 ::Application::RemoveEventListener(m_aEventListenerLink); 1521 m_bEventListener = false; 1522 } 1523 } 1524 1525 // virtual 1526 void SAL_CALL VCLXToolkit::fireFocusGained( 1527 ::com::sun::star::uno::Reference< 1528 ::com::sun::star::uno::XInterface > const &) 1529 throw (::com::sun::star::uno::RuntimeException) 1530 { 1531 } 1532 1533 // virtual 1534 void SAL_CALL VCLXToolkit::fireFocusLost( 1535 ::com::sun::star::uno::Reference< 1536 ::com::sun::star::uno::XInterface > const &) 1537 throw (::com::sun::star::uno::RuntimeException) 1538 { 1539 } 1540 1541 1542 IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent const *, pEvent) 1543 { 1544 switch (pEvent->GetId()) 1545 { 1546 case VCLEVENT_WINDOW_SHOW: 1547 callTopWindowListeners( 1548 pEvent, &::css::awt::XTopWindowListener::windowOpened); 1549 break; 1550 case VCLEVENT_WINDOW_HIDE: 1551 callTopWindowListeners( 1552 pEvent, &::css::awt::XTopWindowListener::windowClosed); 1553 break; 1554 case VCLEVENT_WINDOW_ACTIVATE: 1555 callTopWindowListeners( 1556 pEvent, &::css::awt::XTopWindowListener::windowActivated); 1557 break; 1558 case VCLEVENT_WINDOW_DEACTIVATE: 1559 callTopWindowListeners( 1560 pEvent, &::css::awt::XTopWindowListener::windowDeactivated); 1561 break; 1562 case VCLEVENT_WINDOW_CLOSE: 1563 callTopWindowListeners( 1564 pEvent, &::css::awt::XTopWindowListener::windowClosing); 1565 break; 1566 case VCLEVENT_WINDOW_GETFOCUS: 1567 callFocusListeners(pEvent, true); 1568 break; 1569 case VCLEVENT_WINDOW_LOSEFOCUS: 1570 callFocusListeners(pEvent, false); 1571 break; 1572 case VCLEVENT_WINDOW_MINIMIZE: 1573 callTopWindowListeners( 1574 pEvent, &::css::awt::XTopWindowListener::windowMinimized); 1575 break; 1576 case VCLEVENT_WINDOW_NORMALIZE: 1577 callTopWindowListeners( 1578 pEvent, &::css::awt::XTopWindowListener::windowNormalized); 1579 break; 1580 } 1581 return 0; 1582 } 1583 1584 IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclSimpleEvent const *, pEvent) 1585 { 1586 switch (pEvent->GetId()) 1587 { 1588 case VCLEVENT_WINDOW_KEYINPUT: 1589 return callKeyHandlers(pEvent, true); 1590 case VCLEVENT_WINDOW_KEYUP: 1591 return callKeyHandlers(pEvent, false); 1592 } 1593 return 0; 1594 } 1595 1596 void VCLXToolkit::callTopWindowListeners( 1597 ::VclSimpleEvent const * pEvent, 1598 void (SAL_CALL ::css::awt::XTopWindowListener::* pFn)( 1599 ::css::lang::EventObject const &)) 1600 { 1601 ::Window * pWindow 1602 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); 1603 if (pWindow->IsTopWindow()) 1604 { 1605 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > > 1606 aListeners(m_aTopWindowListeners.getElements()); 1607 if (aListeners.hasElements()) 1608 { 1609 ::css::lang::EventObject aAwtEvent( 1610 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer())); 1611 for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i) 1612 { 1613 ::css::uno::Reference< ::css::awt::XTopWindowListener > 1614 xListener(aListeners[i], ::css::uno::UNO_QUERY); 1615 try 1616 { 1617 (xListener.get()->*pFn)(aAwtEvent); 1618 } 1619 catch (::css::uno::RuntimeException & rEx) 1620 { 1621 OSL_TRACE( 1622 "VCLXToolkit::callTopWindowListeners: caught %s\n", 1623 ::rtl::OUStringToOString( 1624 rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); 1625 } 1626 } 1627 } 1628 } 1629 } 1630 1631 long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent, 1632 bool bPressed) 1633 { 1634 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > > 1635 aHandlers(m_aKeyHandlers.getElements()); 1636 1637 if (aHandlers.hasElements()) 1638 { 1639 ::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); 1640 1641 // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event 1642 ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >( 1643 static_cast< ::VclWindowEvent const * >(pEvent)->GetData()); 1644 ::css::awt::KeyEvent aAwtEvent( 1645 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()), 1646 (pKeyEvent->GetKeyCode().IsShift() 1647 ? ::css::awt::KeyModifier::SHIFT : 0) 1648 | (pKeyEvent->GetKeyCode().IsMod1() 1649 ? ::css::awt::KeyModifier::MOD1 : 0) 1650 | (pKeyEvent->GetKeyCode().IsMod2() 1651 ? ::css::awt::KeyModifier::MOD2 : 0) 1652 | (pKeyEvent->GetKeyCode().IsMod3() 1653 ? ::css::awt::KeyModifier::MOD3 : 0), 1654 pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(), 1655 sal::static_int_cast< sal_Int16 >( 1656 pKeyEvent->GetKeyCode().GetFunction())); 1657 for (::sal_Int32 i = 0; i < aHandlers.getLength(); ++i) 1658 { 1659 ::css::uno::Reference< ::css::awt::XKeyHandler > xHandler( 1660 aHandlers[i], ::css::uno::UNO_QUERY); 1661 try 1662 { 1663 if ((bPressed ? xHandler->keyPressed(aAwtEvent) 1664 : xHandler->keyReleased(aAwtEvent))) 1665 return 1; 1666 } 1667 catch (::css::uno::RuntimeException & rEx) 1668 { 1669 OSL_TRACE( 1670 "VCLXToolkit::callKeyHandlers: caught %s\n", 1671 ::rtl::OUStringToOString( 1672 rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); 1673 } 1674 } 1675 } 1676 return 0; 1677 } 1678 1679 void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent, 1680 bool bGained) 1681 { 1682 ::Window * pWindow 1683 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); 1684 if (pWindow->IsTopWindow()) 1685 { 1686 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > > 1687 aListeners(m_aFocusListeners.getElements()); 1688 if (aListeners.hasElements()) 1689 { 1690 // Ignore the interior of compound controls when determining the 1691 // window that gets the focus next (see implementation in 1692 // vclxwindow.cxx for mapping between VCL and UNO AWT event): 1693 ::css::uno::Reference< css::uno::XInterface > xNext; 1694 ::Window * pFocus = ::Application::GetFocusWindow(); 1695 for (::Window * p = pFocus; p != 0; p = p->GetParent()) 1696 if (!p->IsCompoundControl()) 1697 { 1698 pFocus = p; 1699 break; 1700 } 1701 if (pFocus != 0) 1702 xNext = pFocus->GetComponentInterface(true); 1703 ::css::awt::FocusEvent aAwtEvent( 1704 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()), 1705 pWindow->GetGetFocusFlags(), xNext, false); 1706 for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i) 1707 { 1708 ::css::uno::Reference< ::css::awt::XFocusListener > xListener( 1709 aListeners[i], ::css::uno::UNO_QUERY); 1710 try 1711 { 1712 bGained ? xListener->focusGained(aAwtEvent) 1713 : xListener->focusLost(aAwtEvent); 1714 } 1715 catch (::css::uno::RuntimeException & rEx) 1716 { 1717 OSL_TRACE( 1718 "VCLXToolkit::callFocusListeners: caught %s\n", 1719 ::rtl::OUStringToOString( 1720 rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); 1721 } 1722 } 1723 } 1724 } 1725 } 1726 1727 // css::awt::XReschedule: 1728 1729 void SAL_CALL VCLXToolkit::reschedule() 1730 throw (::com::sun::star::uno::RuntimeException) 1731 { 1732 Application::Reschedule(true); 1733 } 1734 1735