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 QUARTZ) 58 #include "premac.h" 59 #include <Cocoa/Cocoa.h> 60 #include "postmac.h" 61 #endif 62 #include <vcl/sysdata.hxx> 63 64 #include <toolkit/awt/vclxwindows.hxx> 65 #include <toolkit/awt/vclxsystemdependentwindow.hxx> 66 #include <toolkit/awt/vclxregion.hxx> 67 #include <toolkit/awt/vclxtoolkit.hxx> 68 #include <toolkit/awt/vclxtabpagecontainer.hxx> 69 #include <toolkit/awt/vclxtabpagemodel.hxx> 70 71 #include <toolkit/awt/xsimpleanimation.hxx> 72 #include <toolkit/awt/xthrobber.hxx> 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 { "simpleanimation", WINDOW_CONTROL }, 317 { "animatedimages", WINDOW_CONTROL }, 318 { "spinbutton", WINDOW_SPINBUTTON }, 319 { "spinfield", WINDOW_SPINFIELD }, 320 { "throbber", WINDOW_CONTROL }, 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 ( aServiceName.EqualsAscii( "throbber" ) ) 1018 { 1019 pNewWindow = new Throbber( pParent, nWinBits, Throbber::IMAGES_NONE ); 1020 ((Throbber*)pNewWindow)->SetScaleMode( css::awt::ImageScaleMode::Anisotropic ); 1021 // (compatibility) 1022 *ppNewComp = new ::toolkit::XThrobber; 1023 } 1024 else if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase( 1025 ::rtl::OUString::createFromAscii("tabpagecontainer") ) ) 1026 { 1027 pNewWindow = new TabControl( pParent, nWinBits ); 1028 *ppNewComp = new VCLXTabPageContainer; 1029 } 1030 else if ( aServiceName.EqualsAscii( "animatedimages" ) ) 1031 { 1032 pNewWindow = new Throbber( pParent, nWinBits ); 1033 *ppNewComp = new ::toolkit::AnimatedImagesPeer; 1034 } 1035 break; 1036 default: 1037 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" ); 1038 break; 1039 } 1040 } 1041 1042 return pNewWindow; 1043 } 1044 1045 extern "C" { static void SAL_CALL thisModule() {} } 1046 1047 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow( 1048 const css::awt::WindowDescriptor& rDescriptor, 1049 WinBits nForceWinBits ) 1050 { 1051 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 1052 1053 osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() ); 1054 1055 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef; 1056 1057 Window* pParent = NULL; 1058 if ( rDescriptor.Parent.is() ) 1059 { 1060 VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( rDescriptor.Parent ); 1061 1062 // #103939# Don't through assertion, may be it's a system dependend window, used in ImplCreateWindow. 1063 // DBG_ASSERT( pParentComponent, "ParentComponent not valid" ); 1064 1065 if ( pParentComponent ) 1066 pParent = pParentComponent->GetWindow(); 1067 } 1068 1069 WinBits nWinBits = ImplGetWinBits( rDescriptor.WindowAttributes, 1070 ImplGetComponentType( rDescriptor.WindowServiceName ) ); 1071 nWinBits |= nForceWinBits; 1072 1073 VCLXWindow* pNewComp = NULL; 1074 1075 Window* pNewWindow = NULL; 1076 // Try to create the window with SvTools 1077 // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way, 1078 // and we need to stay compatible) 1079 // try to load the lib 1080 if ( !fnSvtCreateWindow && !hSvToolsLib ) 1081 { 1082 ::rtl::OUString aLibName = ::vcl::unohelper::CreateLibraryName( "svt", sal_True ); 1083 hSvToolsLib = osl_loadModuleRelative( 1084 &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT ); 1085 if ( hSvToolsLib ) 1086 { 1087 ::rtl::OUString aFunctionName( RTL_CONSTASCII_USTRINGPARAM( "CreateWindow" ) ); 1088 fnSvtCreateWindow = (FN_SvtCreateWindow)osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData ); 1089 } 1090 } 1091 // ask the SvTool creation function 1092 if ( fnSvtCreateWindow ) 1093 pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits ); 1094 1095 // if SvTools could not provide a window, create it ourself 1096 if ( !pNewWindow ) 1097 pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits ); 1098 1099 DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" ); 1100 DBG_ASSERTWARNING( pNewComp, "createWindow: No special Interface!" ); 1101 1102 if ( pNewWindow ) 1103 { 1104 pNewWindow->SetCreatedWithToolkit( sal_True ); 1105 //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead 1106 1107 if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::MINSIZE ) 1108 { 1109 pNewWindow->SetSizePixel( Size() ); 1110 } 1111 else if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::FULLSIZE ) 1112 { 1113 if ( pParent ) 1114 pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() ); 1115 } 1116 else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) ) 1117 { 1118 Rectangle aRect = VCLRectangle( rDescriptor.Bounds ); 1119 pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() ); 1120 } 1121 1122 if ( !pNewComp ) 1123 { 1124 // Default-Interface 1125 xRef = pNewWindow->GetComponentInterface( sal_True ); 1126 } 1127 else 1128 { 1129 pNewComp->SetCreatedWithToolkit( sal_True ); 1130 xRef = pNewComp; 1131 pNewWindow->SetComponentInterface( xRef ); 1132 } 1133 DBG_ASSERT( pNewWindow->GetComponentInterface( sal_False ) == xRef, 1134 "VCLXToolkit::createWindow: did #133706# resurge?" ); 1135 1136 if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::SHOW ) 1137 pNewWindow->Show(); 1138 } 1139 1140 return xRef; 1141 } 1142 1143 ::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) 1144 { 1145 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 1146 1147 sal_uInt32 nComponents = rDescriptors.getLength(); 1148 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > aSeq( nComponents ); 1149 for ( sal_uInt32 n = 0; n < nComponents; n++ ) 1150 { 1151 ::com::sun::star::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n]; 1152 1153 if ( aDescr.ParentIndex == (-1) ) 1154 aDescr.Parent = NULL; 1155 else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < (short)n ) ) 1156 aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex]; 1157 aSeq.getArray()[n] = createWindow( aDescr ); 1158 } 1159 return aSeq; 1160 } 1161 1162 // ::com::sun::star::awt::XSystemChildFactory 1163 ::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) 1164 { 1165 Window* pChildWindow = NULL; 1166 if ( nSystemType == SYSTEM_DEPENDENT_TYPE ) 1167 { 1168 // use sal_Int64 here to accomodate all int types 1169 // uno::Any shift operator whill upcast if necessary 1170 sal_Int64 nWindowHandle = 0; 1171 sal_Bool bXEmbed = sal_False; 1172 1173 bool bUseParentData = true; 1174 if( ! (Parent >>= nWindowHandle) ) 1175 { 1176 css::uno::Sequence< css::beans::NamedValue > aProps; 1177 if( Parent >>= aProps ) 1178 { 1179 const int nProps = aProps.getLength(); 1180 const css::beans::NamedValue* pProps = aProps.getConstArray(); 1181 for( int i = 0; i < nProps; i++ ) 1182 { 1183 if( pProps[i].Name.equalsAscii( "WINDOW" ) ) 1184 pProps[i].Value >>= nWindowHandle; 1185 else if( pProps[i].Name.equalsAscii( "XEMBED" ) ) 1186 pProps[i].Value >>= bXEmbed; 1187 } 1188 } 1189 else 1190 bUseParentData = false; 1191 } 1192 1193 if( bUseParentData ) 1194 { 1195 SystemParentData aParentData; 1196 aParentData.nSize = sizeof( aParentData ); 1197 #if defined QUARTZ 1198 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle); 1199 #elif defined UNX 1200 aParentData.aWindow = nWindowHandle; 1201 aParentData.bXEmbedSupport = bXEmbed; 1202 #elif defined WNT 1203 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle); 1204 #elif defined OS2 1205 aParentData.hWnd = (HWND)nWindowHandle; 1206 #endif 1207 osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() ); 1208 try 1209 { 1210 pChildWindow = new WorkWindow( &aParentData ); 1211 } 1212 catch ( ::com::sun::star::uno::RuntimeException & rEx ) 1213 { 1214 // system child window could not be created 1215 OSL_TRACE( 1216 "VCLXToolkit::createSystemChild: caught %s\n", 1217 ::rtl::OUStringToOString( 1218 rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); 1219 pChildWindow = NULL; 1220 } 1221 } 1222 } 1223 else if (nSystemType == com::sun::star::lang::SystemDependent::SYSTEM_JAVA) 1224 { 1225 osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex()); 1226 pChildWindow = new WorkWindow(0, Parent); 1227 } 1228 1229 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xPeer; 1230 if ( pChildWindow ) 1231 { 1232 VCLXTopWindow* pPeer = new VCLXTopWindow(true); 1233 osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() ); 1234 pPeer->SetWindow( pChildWindow ); 1235 xPeer = pPeer; 1236 } 1237 1238 return xPeer; 1239 } 1240 1241 // ::com::sun::star::awt::XMessageBoxFactory 1242 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox( 1243 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& aParent, 1244 const ::com::sun::star::awt::Rectangle& aPosSize, 1245 const ::rtl::OUString& aType, 1246 ::sal_Int32 aButtons, 1247 const ::rtl::OUString& aTitle, 1248 const ::rtl::OUString& aMessage ) throw (::com::sun::star::uno::RuntimeException) 1249 { 1250 ::com::sun::star::awt::WindowDescriptor aDescriptor; 1251 1252 sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE; 1253 1254 // Map button definitions to window attributes 1255 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK ) 1256 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK; 1257 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL ) 1258 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL; 1259 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO ) 1260 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO; 1261 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL ) 1262 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL; 1263 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL ) 1264 nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL; 1265 1266 // Map default button definitions to window attributes 1267 if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK ) 1268 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK; 1269 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL ) 1270 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL; 1271 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES ) 1272 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES; 1273 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO ) 1274 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO; 1275 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY ) 1276 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY; 1277 1278 // No more bits for VclWindowPeerAttribute possible. Mapping must be 1279 // done explicitly using VCL methods 1280 WinBits nAddWinBits( 0 ); 1281 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY ) 1282 nAddWinBits |= WB_ABORT_RETRY_IGNORE; 1283 if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE ) 1284 nAddWinBits |= WB_DEF_IGNORE; 1285 1286 aDescriptor.Type = css::awt::WindowClass_MODALTOP; 1287 aDescriptor.WindowServiceName = aType; 1288 aDescriptor.ParentIndex = -1; 1289 aDescriptor.Parent = aParent; 1290 aDescriptor.Bounds = aPosSize; 1291 aDescriptor.WindowAttributes = nWindowAttributes; 1292 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > xMsgBox( 1293 ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY ); 1294 css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY ); 1295 if ( xMsgBox.is() && xWindow.is() ) 1296 { 1297 Window * pWindow = VCLUnoHelper::GetWindow( xWindow ); 1298 if ( pWindow ) 1299 { 1300 osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex()); 1301 xMsgBox->setCaptionText( aTitle ); 1302 xMsgBox->setMessageText( aMessage ); 1303 } 1304 } 1305 1306 return xMsgBox; 1307 } 1308 1309 ::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) 1310 { 1311 Window * pWindow = VCLUnoHelper::GetWindow( window ); 1312 1313 if( pWindow ) 1314 return pWindow->GetDragGestureRecognizer(); 1315 1316 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer >(); 1317 } 1318 1319 ::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) 1320 { 1321 Window * pWindow = VCLUnoHelper::GetWindow( window ); 1322 1323 if( pWindow ) 1324 return pWindow->GetDragSource(); 1325 1326 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource >(); 1327 } 1328 1329 ::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) 1330 { 1331 Window * pWindow = VCLUnoHelper::GetWindow( window ); 1332 1333 if( pWindow ) 1334 return pWindow->GetDropTarget(); 1335 1336 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget >(); 1337 } 1338 1339 ::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) 1340 { 1341 if( clipboardName.getLength() == 0 ) 1342 { 1343 if( !mxClipboard.is() ) 1344 { 1345 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); 1346 if ( xFactory.is() ) 1347 { 1348 // remember clipboard here 1349 mxClipboard = ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > ( 1350 xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.SystemClipboard" ) ), ::com::sun::star::uno::UNO_QUERY ); 1351 } 1352 } 1353 1354 return mxClipboard; 1355 } 1356 1357 else if( clipboardName.equals( ::rtl::OUString::createFromAscii("Selection") ) ) 1358 { 1359 return mxSelection; 1360 } 1361 1362 return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >(); 1363 } 1364 1365 // XServiceInfo 1366 ::rtl::OUString VCLXToolkit::getImplementationName() throw(::com::sun::star::uno::RuntimeException) 1367 { 1368 return rtl::OUString::createFromAscii( "stardiv.Toolkit.VCLXToolkit" ); 1369 } 1370 1371 sal_Bool VCLXToolkit::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException) 1372 { 1373 ::osl::MutexGuard aGuard( GetMutex() ); 1374 1375 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames(); 1376 const ::rtl::OUString* pArray = aSNL.getConstArray(); 1377 const ::rtl::OUString* pArrayEnd = aSNL.getConstArray(); 1378 for (; pArray != pArrayEnd; ++pArray ) 1379 if( *pArray == rServiceName ) 1380 break; 1381 1382 return pArray != pArrayEnd; 1383 } 1384 1385 ::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXToolkit::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) 1386 { 1387 ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit ) ); 1388 return ::com::sun::star::uno::Sequence< ::rtl::OUString >( &aServiceName, 1); 1389 } 1390 1391 // css::awt::XExtendedToolkit: 1392 1393 // virtual 1394 ::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount() 1395 throw (::css::uno::RuntimeException) 1396 { 1397 return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount()); 1398 // XXX numeric overflow 1399 } 1400 1401 // virtual 1402 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL 1403 VCLXToolkit::getTopWindow(::sal_Int32 nIndex) 1404 throw (::css::uno::RuntimeException) 1405 { 1406 ::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex)); 1407 // XXX numeric overflow 1408 return ::css::uno::Reference< ::css::awt::XTopWindow >( 1409 p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()), 1410 ::css::uno::UNO_QUERY); 1411 } 1412 1413 // virtual 1414 ::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL 1415 VCLXToolkit::getActiveTopWindow() throw (::css::uno::RuntimeException) 1416 { 1417 ::Window * p = ::Application::GetActiveTopWindow(); 1418 return ::css::uno::Reference< ::css::awt::XTopWindow >( 1419 p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()), 1420 ::css::uno::UNO_QUERY); 1421 } 1422 1423 // virtual 1424 void SAL_CALL VCLXToolkit::addTopWindowListener( 1425 ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener) 1426 throw (::css::uno::RuntimeException) 1427 { 1428 OSL_ENSURE(rListener.is(), "Null rListener"); 1429 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); 1430 if (rBHelper.bDisposed || rBHelper.bInDispose) 1431 { 1432 aGuard.clear(); 1433 rListener->disposing( 1434 ::css::lang::EventObject( 1435 static_cast< ::cppu::OWeakObject * >(this))); 1436 } 1437 else if (m_aTopWindowListeners.addInterface(rListener) == 1 1438 && !m_bEventListener) 1439 { 1440 m_bEventListener = true; 1441 ::Application::AddEventListener(m_aEventListenerLink); 1442 } 1443 } 1444 1445 // virtual 1446 void SAL_CALL VCLXToolkit::removeTopWindowListener( 1447 ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener) 1448 throw (::css::uno::RuntimeException) 1449 { 1450 ::osl::MutexGuard aGuard(rBHelper.rMutex); 1451 if (!(rBHelper.bDisposed || rBHelper.bInDispose) 1452 && m_aTopWindowListeners.removeInterface(rListener) == 0 1453 && m_aFocusListeners.getLength() == 0 && m_bEventListener) 1454 { 1455 ::Application::RemoveEventListener(m_aEventListenerLink); 1456 m_bEventListener = false; 1457 } 1458 } 1459 1460 // virtual 1461 void SAL_CALL VCLXToolkit::addKeyHandler( 1462 ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler) 1463 throw (::css::uno::RuntimeException) 1464 { 1465 OSL_ENSURE(rHandler.is(), "Null rHandler"); 1466 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); 1467 if (rBHelper.bDisposed || rBHelper.bInDispose) 1468 { 1469 aGuard.clear(); 1470 rHandler->disposing( 1471 ::css::lang::EventObject( 1472 static_cast< ::cppu::OWeakObject * >(this))); 1473 } 1474 else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener) 1475 { 1476 m_bKeyListener = true; 1477 ::Application::AddKeyListener(m_aKeyListenerLink); 1478 } 1479 } 1480 1481 // virtual 1482 void SAL_CALL VCLXToolkit::removeKeyHandler( 1483 ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler) 1484 throw (::css::uno::RuntimeException) 1485 { 1486 ::osl::MutexGuard aGuard(rBHelper.rMutex); 1487 if (!(rBHelper.bDisposed || rBHelper.bInDispose) 1488 && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener) 1489 { 1490 ::Application::RemoveKeyListener(m_aKeyListenerLink); 1491 m_bKeyListener = false; 1492 } 1493 } 1494 1495 // virtual 1496 void SAL_CALL VCLXToolkit::addFocusListener( 1497 ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener) 1498 throw (::css::uno::RuntimeException) 1499 { 1500 OSL_ENSURE(rListener.is(), "Null rListener"); 1501 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); 1502 if (rBHelper.bDisposed || rBHelper.bInDispose) 1503 { 1504 aGuard.clear(); 1505 rListener->disposing( 1506 ::css::lang::EventObject( 1507 static_cast< ::cppu::OWeakObject * >(this))); 1508 } 1509 else if (m_aFocusListeners.addInterface(rListener) == 1 1510 && !m_bEventListener) 1511 { 1512 m_bEventListener = true; 1513 ::Application::AddEventListener(m_aEventListenerLink); 1514 } 1515 } 1516 1517 // virtual 1518 void SAL_CALL VCLXToolkit::removeFocusListener( 1519 ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener) 1520 throw (::css::uno::RuntimeException) 1521 { 1522 ::osl::MutexGuard aGuard(rBHelper.rMutex); 1523 if (!(rBHelper.bDisposed || rBHelper.bInDispose) 1524 && m_aFocusListeners.removeInterface(rListener) == 0 1525 && m_aTopWindowListeners.getLength() == 0 && m_bEventListener) 1526 { 1527 ::Application::RemoveEventListener(m_aEventListenerLink); 1528 m_bEventListener = false; 1529 } 1530 } 1531 1532 // virtual 1533 void SAL_CALL VCLXToolkit::fireFocusGained( 1534 ::com::sun::star::uno::Reference< 1535 ::com::sun::star::uno::XInterface > const &) 1536 throw (::com::sun::star::uno::RuntimeException) 1537 { 1538 } 1539 1540 // virtual 1541 void SAL_CALL VCLXToolkit::fireFocusLost( 1542 ::com::sun::star::uno::Reference< 1543 ::com::sun::star::uno::XInterface > const &) 1544 throw (::com::sun::star::uno::RuntimeException) 1545 { 1546 } 1547 1548 1549 IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent const *, pEvent) 1550 { 1551 switch (pEvent->GetId()) 1552 { 1553 case VCLEVENT_WINDOW_SHOW: 1554 callTopWindowListeners( 1555 pEvent, &::css::awt::XTopWindowListener::windowOpened); 1556 break; 1557 case VCLEVENT_WINDOW_HIDE: 1558 callTopWindowListeners( 1559 pEvent, &::css::awt::XTopWindowListener::windowClosed); 1560 break; 1561 case VCLEVENT_WINDOW_ACTIVATE: 1562 callTopWindowListeners( 1563 pEvent, &::css::awt::XTopWindowListener::windowActivated); 1564 break; 1565 case VCLEVENT_WINDOW_DEACTIVATE: 1566 callTopWindowListeners( 1567 pEvent, &::css::awt::XTopWindowListener::windowDeactivated); 1568 break; 1569 case VCLEVENT_WINDOW_CLOSE: 1570 callTopWindowListeners( 1571 pEvent, &::css::awt::XTopWindowListener::windowClosing); 1572 break; 1573 case VCLEVENT_WINDOW_GETFOCUS: 1574 callFocusListeners(pEvent, true); 1575 break; 1576 case VCLEVENT_WINDOW_LOSEFOCUS: 1577 callFocusListeners(pEvent, false); 1578 break; 1579 case VCLEVENT_WINDOW_MINIMIZE: 1580 callTopWindowListeners( 1581 pEvent, &::css::awt::XTopWindowListener::windowMinimized); 1582 break; 1583 case VCLEVENT_WINDOW_NORMALIZE: 1584 callTopWindowListeners( 1585 pEvent, &::css::awt::XTopWindowListener::windowNormalized); 1586 break; 1587 } 1588 return 0; 1589 } 1590 1591 IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclSimpleEvent const *, pEvent) 1592 { 1593 switch (pEvent->GetId()) 1594 { 1595 case VCLEVENT_WINDOW_KEYINPUT: 1596 return callKeyHandlers(pEvent, true); 1597 case VCLEVENT_WINDOW_KEYUP: 1598 return callKeyHandlers(pEvent, false); 1599 } 1600 return 0; 1601 } 1602 1603 void VCLXToolkit::callTopWindowListeners( 1604 ::VclSimpleEvent const * pEvent, 1605 void (SAL_CALL ::css::awt::XTopWindowListener::* pFn)( 1606 ::css::lang::EventObject const &)) 1607 { 1608 ::Window * pWindow 1609 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); 1610 if (pWindow->IsTopWindow()) 1611 { 1612 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > > 1613 aListeners(m_aTopWindowListeners.getElements()); 1614 if (aListeners.hasElements()) 1615 { 1616 ::css::lang::EventObject aAwtEvent( 1617 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer())); 1618 for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i) 1619 { 1620 ::css::uno::Reference< ::css::awt::XTopWindowListener > 1621 xListener(aListeners[i], ::css::uno::UNO_QUERY); 1622 try 1623 { 1624 (xListener.get()->*pFn)(aAwtEvent); 1625 } 1626 catch (::css::uno::RuntimeException & rEx) 1627 { 1628 OSL_TRACE( 1629 "VCLXToolkit::callTopWindowListeners: caught %s\n", 1630 ::rtl::OUStringToOString( 1631 rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); 1632 } 1633 } 1634 } 1635 } 1636 } 1637 1638 long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent, 1639 bool bPressed) 1640 { 1641 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > > 1642 aHandlers(m_aKeyHandlers.getElements()); 1643 1644 if (aHandlers.hasElements()) 1645 { 1646 ::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); 1647 1648 // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event 1649 ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >( 1650 static_cast< ::VclWindowEvent const * >(pEvent)->GetData()); 1651 ::css::awt::KeyEvent aAwtEvent( 1652 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()), 1653 (pKeyEvent->GetKeyCode().IsShift() 1654 ? ::css::awt::KeyModifier::SHIFT : 0) 1655 | (pKeyEvent->GetKeyCode().IsMod1() 1656 ? ::css::awt::KeyModifier::MOD1 : 0) 1657 | (pKeyEvent->GetKeyCode().IsMod2() 1658 ? ::css::awt::KeyModifier::MOD2 : 0) 1659 | (pKeyEvent->GetKeyCode().IsMod3() 1660 ? ::css::awt::KeyModifier::MOD3 : 0), 1661 pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(), 1662 sal::static_int_cast< sal_Int16 >( 1663 pKeyEvent->GetKeyCode().GetFunction())); 1664 for (::sal_Int32 i = 0; i < aHandlers.getLength(); ++i) 1665 { 1666 ::css::uno::Reference< ::css::awt::XKeyHandler > xHandler( 1667 aHandlers[i], ::css::uno::UNO_QUERY); 1668 try 1669 { 1670 if ((bPressed ? xHandler->keyPressed(aAwtEvent) 1671 : xHandler->keyReleased(aAwtEvent))) 1672 return 1; 1673 } 1674 catch (::css::uno::RuntimeException & rEx) 1675 { 1676 OSL_TRACE( 1677 "VCLXToolkit::callKeyHandlers: caught %s\n", 1678 ::rtl::OUStringToOString( 1679 rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); 1680 } 1681 } 1682 } 1683 return 0; 1684 } 1685 1686 void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent, 1687 bool bGained) 1688 { 1689 ::Window * pWindow 1690 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); 1691 if (pWindow->IsTopWindow()) 1692 { 1693 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > > 1694 aListeners(m_aFocusListeners.getElements()); 1695 if (aListeners.hasElements()) 1696 { 1697 // Ignore the interior of compound controls when determining the 1698 // window that gets the focus next (see implementation in 1699 // vclxwindow.cxx for mapping between VCL and UNO AWT event): 1700 ::css::uno::Reference< css::uno::XInterface > xNext; 1701 ::Window * pFocus = ::Application::GetFocusWindow(); 1702 for (::Window * p = pFocus; p != 0; p = p->GetParent()) 1703 if (!p->IsCompoundControl()) 1704 { 1705 pFocus = p; 1706 break; 1707 } 1708 if (pFocus != 0) 1709 xNext = pFocus->GetComponentInterface(true); 1710 ::css::awt::FocusEvent aAwtEvent( 1711 static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()), 1712 pWindow->GetGetFocusFlags(), xNext, false); 1713 for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i) 1714 { 1715 ::css::uno::Reference< ::css::awt::XFocusListener > xListener( 1716 aListeners[i], ::css::uno::UNO_QUERY); 1717 try 1718 { 1719 bGained ? xListener->focusGained(aAwtEvent) 1720 : xListener->focusLost(aAwtEvent); 1721 } 1722 catch (::css::uno::RuntimeException & rEx) 1723 { 1724 OSL_TRACE( 1725 "VCLXToolkit::callFocusListeners: caught %s\n", 1726 ::rtl::OUStringToOString( 1727 rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); 1728 } 1729 } 1730 } 1731 } 1732 } 1733 1734 // css::awt::XReschedule: 1735 1736 void SAL_CALL VCLXToolkit::reschedule() 1737 throw (::com::sun::star::uno::RuntimeException) 1738 { 1739 Application::Reschedule(true); 1740 } 1741 1742