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