Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / source / app / svapp.cxx
blob987db604dce2ae76d38c9322917fdf5ac5f901fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "comphelper/processfactory.hxx"
22 #include "osl/module.h"
23 #include "osl/file.hxx"
24 #include "osl/thread.h"
26 #include "rtl/tencinfo.h"
27 #include "rtl/instance.hxx"
28 #include "rtl/process.h"
30 #include "tools/tools.h"
31 #include "tools/debug.hxx"
32 #include "tools/time.hxx"
34 #include "i18nlangtag/mslangid.hxx"
36 #include "unotools/syslocaleoptions.hxx"
38 #include "vcl/settings.hxx"
39 #include "vcl/keycod.hxx"
40 #include "vcl/event.hxx"
41 #include "vcl/vclevent.hxx"
42 #include "vcl/virdev.hxx"
43 #include "vcl/wrkwin.hxx"
44 #include "vcl/svapp.hxx"
45 #include "vcl/cvtgrf.hxx"
46 #include "vcl/unowrap.hxx"
47 #include "vcl/timer.hxx"
48 #include "vcl/unohelp.hxx"
49 #include "vcl/lazydelete.hxx"
51 #include "salinst.hxx"
52 #include "salframe.hxx"
53 #include "salsys.hxx"
54 #include "svdata.hxx"
55 #include "salimestatus.hxx"
56 #include "xconnection.hxx"
57 #include "window.h"
58 #include "accmgr.hxx"
59 #include "idlemgr.hxx"
60 #include "svids.hrc"
62 #include "com/sun/star/uno/Reference.h"
63 #include "com/sun/star/awt/XToolkit.hpp"
64 #include "com/sun/star/uno/XNamingService.hpp"
65 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
66 #include "comphelper/solarmutex.hxx"
67 #include "osl/process.h"
69 #include <utility>
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::uno;
74 // keycodes handled internally by VCL
75 class ImplReservedKey
77 public:
78 ImplReservedKey( KeyCode aKeyCode, sal_uInt16 nResId ) :
79 mKeyCode(aKeyCode), mnResId( nResId)
82 KeyCode mKeyCode;
83 sal_uInt16 mnResId;
86 typedef std::pair<ImplReservedKey*, size_t> ReservedKeys;
87 namespace
89 struct ImplReservedKeysImpl
91 ReservedKeys* operator()()
93 static ImplReservedKey ImplReservedKeys[] =
95 ImplReservedKey(KeyCode(KEY_F1,0), SV_SHORTCUT_HELP),
96 ImplReservedKey(KeyCode(KEY_F1,KEY_SHIFT), SV_SHORTCUT_ACTIVEHELP),
97 ImplReservedKey(KeyCode(KEY_F1,KEY_MOD1), SV_SHORTCUT_CONTEXTHELP),
98 ImplReservedKey(KeyCode(KEY_F2,KEY_SHIFT), SV_SHORTCUT_CONTEXTHELP),
99 ImplReservedKey(KeyCode(KEY_F4,KEY_MOD1), SV_SHORTCUT_DOCKUNDOCK),
100 ImplReservedKey(KeyCode(KEY_F4,KEY_MOD2), SV_SHORTCUT_DOCKUNDOCK),
101 ImplReservedKey(KeyCode(KEY_F4,KEY_MOD1|KEY_MOD2), SV_SHORTCUT_DOCKUNDOCK),
102 ImplReservedKey(KeyCode(KEY_F6,0), SV_SHORTCUT_NEXTSUBWINDOW),
103 ImplReservedKey(KeyCode(KEY_F6,KEY_MOD1), SV_SHORTCUT_TODOCUMENT),
104 ImplReservedKey(KeyCode(KEY_F6,KEY_SHIFT), SV_SHORTCUT_PREVSUBWINDOW),
105 ImplReservedKey(KeyCode(KEY_F6,KEY_MOD1|KEY_SHIFT), SV_SHORTCUT_SPLITTER),
106 ImplReservedKey(KeyCode(KEY_F10,0), SV_SHORTCUT_MENUBAR)
107 #ifdef UNX
109 ImplReservedKey(KeyCode(KEY_1,KEY_SHIFT|KEY_MOD1), 0),
110 ImplReservedKey(KeyCode(KEY_2,KEY_SHIFT|KEY_MOD1), 0),
111 ImplReservedKey(KeyCode(KEY_3,KEY_SHIFT|KEY_MOD1), 0),
112 ImplReservedKey(KeyCode(KEY_4,KEY_SHIFT|KEY_MOD1), 0),
113 ImplReservedKey(KeyCode(KEY_5,KEY_SHIFT|KEY_MOD1), 0),
114 ImplReservedKey(KeyCode(KEY_6,KEY_SHIFT|KEY_MOD1), 0),
115 ImplReservedKey(KeyCode(KEY_7,KEY_SHIFT|KEY_MOD1), 0),
116 ImplReservedKey(KeyCode(KEY_8,KEY_SHIFT|KEY_MOD1), 0),
117 ImplReservedKey(KeyCode(KEY_9,KEY_SHIFT|KEY_MOD1), 0),
118 ImplReservedKey(KeyCode(KEY_0,KEY_SHIFT|KEY_MOD1), 0),
119 ImplReservedKey(KeyCode(KEY_ADD,KEY_SHIFT|KEY_MOD1), 0)
120 #endif
122 static ReservedKeys aKeys
124 &ImplReservedKeys[0],
125 sizeof(ImplReservedKeys) / sizeof(ImplReservedKey)
127 return &aKeys;
131 struct ImplReservedKeys
132 : public rtl::StaticAggregate<ReservedKeys, ImplReservedKeysImpl> {};
135 extern "C" {
136 typedef UnoWrapperBase* (SAL_CALL *FN_TkCreateUnoWrapper)();
139 struct ImplHotKey
141 ImplHotKey* mpNext;
142 void* mpUserData;
143 KeyCode maKeyCode;
144 Link maLink;
147 struct ImplEventHook
149 ImplEventHook* mpNext;
150 void* mpUserData;
151 VCLEventHookProc mpProc;
154 struct ImplPostEventData
156 sal_uLong mnEvent;
157 const Window* mpWin;
158 sal_uLong mnEventId;
159 KeyEvent maKeyEvent;
160 MouseEvent maMouseEvent;
161 ZoomEvent maZoomEvent;
162 ScrollEvent maScrollEvent;
164 ImplPostEventData( sal_uLong nEvent, const Window* pWin, const KeyEvent& rKeyEvent ) :
165 mnEvent( nEvent ), mpWin( pWin ), mnEventId( 0 ), maKeyEvent( rKeyEvent ) {}
166 ImplPostEventData( sal_uLong nEvent, const Window* pWin, const MouseEvent& rMouseEvent ) :
167 mnEvent( nEvent ), mpWin( pWin ), mnEventId( 0 ), maMouseEvent( rMouseEvent ) {}
168 ImplPostEventData( sal_uLong nEvent, const Window* pWin, const ZoomEvent& rZoomEvent ) :
169 mnEvent( nEvent ), mpWin( pWin ), mnEventId( 0 ), maZoomEvent( rZoomEvent ) {}
170 ImplPostEventData( sal_uLong nEvent, const Window* pWin, const ScrollEvent& rScrollEvent ) :
171 mnEvent( nEvent ), mpWin( pWin ), mnEventId( 0 ), maScrollEvent( rScrollEvent ) {}
173 ~ImplPostEventData() {}
176 typedef ::std::pair< Window*, ImplPostEventData* > ImplPostEventPair;
178 static ::std::list< ImplPostEventPair > aPostedEventList;
180 Application* GetpApp()
182 ImplSVData* pSVData = ImplGetSVData();
183 if ( !pSVData )
184 return NULL;
185 return pSVData->mpApp;
188 Application::Application()
190 // useful for themes at least, perhaps extensions too
191 OUString aVar("LIBO_VERSION"), aValue(LIBO_VERSION_DOTTED);
192 osl_setEnvironment(aVar.pData, aValue.pData);
194 if( ! ImplGetSVData() )
195 ImplInitSVData();
196 ImplGetSVData()->mpApp = this;
197 InitSalData();
200 Application::~Application()
202 ImplDeInitSVData();
203 DeInitSalData();
204 ImplGetSVData()->mpApp = NULL;
205 ImplDestroySVData();
206 GlobalDeInitTools();
209 sal_Bool Application::QueryExit()
211 WorkWindow* pAppWin = ImplGetSVData()->maWinData.mpAppWin;
213 // call the close handler of the application window
214 if ( pAppWin )
215 return pAppWin->Close();
216 else
217 return sal_True;
220 void Application::UserEvent( sal_uLong, void* )
224 void Application::FocusChanged()
228 void Application::DataChanged( const DataChangedEvent& )
232 void Application::Init()
236 void Application::InitFinished()
240 void Application::DeInit()
244 sal_uInt16 Application::GetCommandLineParamCount()
246 return (sal_uInt16)osl_getCommandArgCount();
249 OUString Application::GetCommandLineParam( sal_uInt16 nParam )
251 OUString aParam;
252 osl_getCommandArg( nParam, &aParam.pData );
253 return aParam;
256 OUString Application::GetAppFileName()
258 ImplSVData* pSVData = ImplGetSVData();
259 DBG_ASSERT( pSVData->maAppData.mpAppFileName, "AppFileName should be set to something after SVMain!" );
260 if ( pSVData->maAppData.mpAppFileName )
261 return *pSVData->maAppData.mpAppFileName;
264 * provide a fallback for people without initialized vcl here (like setup
265 * in responsefile mode)
267 OUString aAppFileName;
268 OUString aExeFileName;
269 osl_getExecutableFile(&aExeFileName.pData);
271 // convert path to native file format
272 osl::FileBase::getSystemPathFromFileURL(aExeFileName, aAppFileName);
274 return aAppFileName;
277 sal_uInt16 Application::Exception( sal_uInt16 nError )
279 switch ( nError & EXC_MAJORTYPE )
281 // System has precedence (so do nothing)
282 case EXC_SYSTEM:
283 return 0;
285 case EXC_DISPLAY:
286 case EXC_REMOTE:
287 return 0;
289 #ifdef DBG_UTIL
290 case EXC_RSCNOTLOADED:
291 Abort(OUString("Resource not loaded"));
292 break;
293 case EXC_SYSOBJNOTCREATED:
294 Abort(OUString("System Object not created"));
295 break;
296 default:
297 Abort(OUString("Unknown Error"));
298 break;
299 #else
300 default:
301 Abort(OUString());
302 break;
303 #endif
306 return 0;
309 void Application::Abort( const OUString& rErrorText )
311 //HACK: Dump core iff --norestore command line argument is given (assuming
312 // this process is run by developers who are interested in cores, vs. end
313 // users who are not):
314 bool dumpCore = false;
315 sal_uInt16 n = GetCommandLineParamCount();
316 for (sal_uInt16 i = 0; i != n; ++i) {
317 if (GetCommandLineParam(i).equals("--norestore")) {
318 dumpCore = true;
319 break;
323 SalAbort( rErrorText, dumpCore );
326 sal_uLong Application::GetReservedKeyCodeCount()
328 return ImplReservedKeys::get()->second;
331 const KeyCode* Application::GetReservedKeyCode( sal_uLong i )
333 if( i >= GetReservedKeyCodeCount() )
334 return NULL;
335 else
336 return &ImplReservedKeys::get()->first[i].mKeyCode;
339 void Application::Execute()
341 ImplSVData* pSVData = ImplGetSVData();
342 pSVData->maAppData.mbInAppExecute = sal_True;
344 while ( !pSVData->maAppData.mbAppQuit )
345 Application::Yield();
347 pSVData->maAppData.mbInAppExecute = sal_False;
350 inline void ImplYield( bool i_bWait, bool i_bAllEvents )
352 ImplSVData* pSVData = ImplGetSVData();
354 // run timers that have timed out
355 if ( !pSVData->mbNoCallTimer )
356 while ( pSVData->mbNotAllTimerCalled )
357 Timer::ImplTimerCallbackProc();
359 pSVData->maAppData.mnDispatchLevel++;
360 // do not wait for events if application was already quit; in that
361 // case only dispatch events already available
362 // do not wait for events either if the app decided that it is too busy for timers
363 // (feature added for the slideshow)
364 pSVData->mpDefInst->Yield( i_bWait && !pSVData->maAppData.mbAppQuit && !pSVData->maAppData.mbNoYield, i_bAllEvents );
365 pSVData->maAppData.mnDispatchLevel--;
367 DBG_TESTSOLARMUTEX(); // must be locked on return from Yield
369 // flush lazy deleted objects
370 if( pSVData->maAppData.mnDispatchLevel == 0 )
371 vcl::LazyDelete::flush();
373 // the system timer events will not necessarily come in in non waiting mode
374 // e.g. on aqua; need to trigger timer checks manually
375 if( pSVData->maAppData.mbNoYield && !pSVData->mbNoCallTimer )
379 Timer::ImplTimerCallbackProc();
381 while( pSVData->mbNotAllTimerCalled );
384 // call post yield listeners
385 if( pSVData->maAppData.mpPostYieldListeners )
386 pSVData->maAppData.mpPostYieldListeners->callListeners( NULL );
389 void Application::Reschedule( bool i_bAllEvents )
391 ImplYield( false, i_bAllEvents );
394 void Application::Yield()
396 ImplYield( true, false );
399 IMPL_STATIC_LINK_NOINSTANCE( ImplSVAppData, ImplQuitMsg, void*, EMPTYARG )
401 ImplGetSVData()->maAppData.mbAppQuit = sal_True;
402 return 0;
405 void Application::Quit()
407 Application::PostUserEvent( STATIC_LINK( NULL, ImplSVAppData, ImplQuitMsg ) );
410 comphelper::SolarMutex& Application::GetSolarMutex()
412 ImplSVData* pSVData = ImplGetSVData();
413 return *(pSVData->mpDefInst->GetYieldMutex());
416 oslThreadIdentifier Application::GetMainThreadIdentifier()
418 return ImplGetSVData()->mnMainThreadId;
421 sal_uLong Application::ReleaseSolarMutex()
423 ImplSVData* pSVData = ImplGetSVData();
424 return pSVData->mpDefInst->ReleaseYieldMutex();
427 void Application::AcquireSolarMutex( sal_uLong nCount )
429 ImplSVData* pSVData = ImplGetSVData();
430 pSVData->mpDefInst->AcquireYieldMutex( nCount );
433 sal_Bool Application::IsInMain()
435 return ImplGetSVData()->maAppData.mbInAppMain;
438 sal_Bool Application::IsInExecute()
440 return ImplGetSVData()->maAppData.mbInAppExecute;
443 sal_Bool Application::IsInModalMode()
445 return (ImplGetSVData()->maAppData.mnModalMode != 0);
448 sal_uInt16 Application::GetDispatchLevel()
450 return ImplGetSVData()->maAppData.mnDispatchLevel;
453 bool Application::AnyInput( sal_uInt16 nType )
455 return ImplGetSVData()->mpDefInst->AnyInput( nType );
458 sal_uLong Application::GetLastInputInterval()
460 return (Time::GetSystemTicks()-ImplGetSVData()->maAppData.mnLastInputTime);
463 extern int nImplSysDialog;
465 sal_Bool Application::IsUICaptured()
467 ImplSVData* pSVData = ImplGetSVData();
469 // If mouse was captured, or if in tracking- or in select-mode of a floatingwindow (e.g. menus
470 // or pulldown toolboxes) another window should be created
471 // D&D active !!!
472 if ( pSVData->maWinData.mpCaptureWin || pSVData->maWinData.mpTrackWin ||
473 pSVData->maWinData.mpFirstFloat || nImplSysDialog )
474 return sal_True;
475 else
476 return sal_False;
479 void Application::SystemSettingsChanging( AllSettings& /*rSettings*/,
480 Window* /*pFrame*/ )
484 void Application::MergeSystemSettings( AllSettings& rSettings )
486 Window* pWindow = ImplGetSVData()->maWinData.mpFirstFrame;
487 if( ! pWindow )
488 pWindow = ImplGetDefaultWindow();
489 if( pWindow )
491 ImplSVData* pSVData = ImplGetSVData();
492 if ( !pSVData->maAppData.mbSettingsInit )
494 // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
495 pWindow->ImplUpdateGlobalSettings( *pSVData->maAppData.mpSettings );
496 pSVData->maAppData.mbSettingsInit = sal_True;
498 // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
499 pWindow->ImplUpdateGlobalSettings( rSettings, sal_False );
503 bool Application::ValidateSystemFont()
505 Window* pWindow = ImplGetSVData()->maWinData.mpFirstFrame;
506 if( ! pWindow )
507 pWindow = ImplGetDefaultWindow();
509 if( pWindow )
511 AllSettings aSettings;
512 pWindow->ImplGetFrame()->UpdateSettings( aSettings );
513 return pWindow->ImplCheckUIFont( aSettings.GetStyleSettings().GetAppFont() );
515 return false;
518 void Application::SetSettings( const AllSettings& rSettings )
520 ImplSVData* pSVData = ImplGetSVData();
521 if ( !pSVData->maAppData.mpSettings )
523 GetSettings();
524 *pSVData->maAppData.mpSettings = rSettings;
525 ResMgr::SetDefaultLocale( rSettings.GetUILanguageTag() );
527 else
529 AllSettings aOldSettings = *pSVData->maAppData.mpSettings;
530 if( aOldSettings.GetUILanguageTag().getLanguageType() != rSettings.GetUILanguageTag().getLanguageType() &&
531 pSVData->mpResMgr )
533 delete pSVData->mpResMgr;
534 pSVData->mpResMgr = NULL;
536 ResMgr::SetDefaultLocale( rSettings.GetUILanguageTag() );
537 *pSVData->maAppData.mpSettings = rSettings;
538 sal_uLong nChangeFlags = aOldSettings.GetChangeFlags( *pSVData->maAppData.mpSettings );
539 if ( nChangeFlags )
541 DataChangedEvent aDCEvt( DATACHANGED_SETTINGS, &aOldSettings, nChangeFlags );
542 GetpApp()->DataChanged( aDCEvt );
544 // notify data change handler
545 ImplCallEventListeners( VCLEVENT_APPLICATION_DATACHANGED, NULL, &aDCEvt);
547 // Update all windows
548 Window* pFirstFrame = pSVData->maWinData.mpFirstFrame;
549 // Reset data that needs to be re-calculated
550 long nOldDPIX = 0;
551 long nOldDPIY = 0;
552 if ( pFirstFrame )
554 nOldDPIX = pFirstFrame->mnDPIX;
555 nOldDPIY = pFirstFrame->mnDPIY;
556 pSVData->maGDIData.mnAppFontX = 0;
558 Window* pFrame = pFirstFrame;
559 while ( pFrame )
561 // restore AppFont cache data
562 pFrame->mpWindowImpl->mpFrameData->meMapUnit = MAP_PIXEL;
564 // call UpdateSettings from ClientWindow in order to prevent updating data twice
565 Window* pClientWin = pFrame;
566 while ( pClientWin->ImplGetClientWindow() )
567 pClientWin = pClientWin->ImplGetClientWindow();
568 pClientWin->UpdateSettings( rSettings, sal_True );
570 Window* pTempWin = pFrame->mpWindowImpl->mpFrameData->mpFirstOverlap;
571 while ( pTempWin )
573 // call UpdateSettings from ClientWindow in order to prevent updating data twice
574 pClientWin = pTempWin;
575 while ( pClientWin->ImplGetClientWindow() )
576 pClientWin = pClientWin->ImplGetClientWindow();
577 pClientWin->UpdateSettings( rSettings, sal_True );
578 pTempWin = pTempWin->mpWindowImpl->mpNextOverlap;
581 pFrame = pFrame->mpWindowImpl->mpFrameData->mpNextFrame;
584 // if DPI resolution for screen output was changed set the new resolution for all
585 // screen compatible VirDev's
586 pFirstFrame = pSVData->maWinData.mpFirstFrame;
587 if ( pFirstFrame )
589 if ( (pFirstFrame->mnDPIX != nOldDPIX) ||
590 (pFirstFrame->mnDPIY != nOldDPIY) )
592 VirtualDevice* pVirDev = pSVData->maGDIData.mpFirstVirDev;
593 while ( pVirDev )
595 if ( pVirDev->mbScreenComp &&
596 (pVirDev->mnDPIX == nOldDPIX) &&
597 (pVirDev->mnDPIY == nOldDPIY) )
599 pVirDev->mnDPIX = pFirstFrame->mnDPIX;
600 pVirDev->mnDPIY = pFirstFrame->mnDPIY;
601 if ( pVirDev->IsMapMode() )
603 MapMode aMapMode = pVirDev->GetMapMode();
604 pVirDev->SetMapMode();
605 pVirDev->SetMapMode( aMapMode );
609 pVirDev = pVirDev->mpNext;
617 const AllSettings& Application::GetSettings()
619 ImplSVData* pSVData = ImplGetSVData();
620 if ( !pSVData->maAppData.mpSettings )
622 pSVData->maAppData.mpCfgListener = new LocaleConfigurationListener;
623 pSVData->maAppData.mpSettings = new AllSettings();
624 pSVData->maAppData.mpSettings->GetSysLocale().GetOptions().AddListener( pSVData->maAppData.mpCfgListener );
627 return *(pSVData->maAppData.mpSettings);
630 void Application::NotifyAllWindows( DataChangedEvent& rDCEvt )
632 ImplSVData* pSVData = ImplGetSVData();
633 Window* pFrame = pSVData->maWinData.mpFirstFrame;
634 while ( pFrame )
636 pFrame->NotifyAllChildren( rDCEvt );
638 Window* pSysWin = pFrame->mpWindowImpl->mpFrameData->mpFirstOverlap;
639 while ( pSysWin )
641 pSysWin->NotifyAllChildren( rDCEvt );
642 pSysWin = pSysWin->mpWindowImpl->mpNextOverlap;
645 pFrame = pFrame->mpWindowImpl->mpFrameData->mpNextFrame;
649 void Application::ImplCallEventListeners( sal_uLong nEvent, Window *pWin, void* pData )
651 ImplSVData* pSVData = ImplGetSVData();
652 VclWindowEvent aEvent( pWin, nEvent, pData );
654 if ( pSVData->maAppData.mpEventListeners )
655 pSVData->maAppData.mpEventListeners->Call( &aEvent );
658 void Application::ImplCallEventListeners( VclSimpleEvent* pEvent )
660 ImplSVData* pSVData = ImplGetSVData();
662 if ( pSVData->maAppData.mpEventListeners )
663 pSVData->maAppData.mpEventListeners->Call( pEvent );
666 void Application::AddEventListener( const Link& rEventListener )
668 ImplSVData* pSVData = ImplGetSVData();
669 if( !pSVData->maAppData.mpEventListeners )
670 pSVData->maAppData.mpEventListeners = new VclEventListeners;
671 pSVData->maAppData.mpEventListeners->addListener( rEventListener );
674 void Application::RemoveEventListener( const Link& rEventListener )
676 ImplSVData* pSVData = ImplGetSVData();
677 if( pSVData->maAppData.mpEventListeners )
678 pSVData->maAppData.mpEventListeners->removeListener( rEventListener );
681 void Application::AddKeyListener( const Link& rKeyListener )
683 ImplSVData* pSVData = ImplGetSVData();
684 if( !pSVData->maAppData.mpKeyListeners )
685 pSVData->maAppData.mpKeyListeners = new VclEventListeners;
686 pSVData->maAppData.mpKeyListeners->addListener( rKeyListener );
689 void Application::RemoveKeyListener( const Link& rKeyListener )
691 ImplSVData* pSVData = ImplGetSVData();
692 if( pSVData->maAppData.mpKeyListeners )
693 pSVData->maAppData.mpKeyListeners->removeListener( rKeyListener );
696 sal_Bool Application::HandleKey( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent )
698 // let listeners process the key event
699 VclWindowEvent aEvent( pWin, nEvent, (void *) pKeyEvent );
701 ImplSVData* pSVData = ImplGetSVData();
702 sal_Bool bProcessed = sal_False;
704 if ( pSVData->maAppData.mpKeyListeners )
705 bProcessed = pSVData->maAppData.mpKeyListeners->Process( &aEvent );
707 return bProcessed;
710 sal_uLong Application::PostKeyEvent( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent )
712 const SolarMutexGuard aGuard;
713 sal_uLong nEventId = 0;
715 if( pWin && pKeyEvent )
717 ImplPostEventData* pPostEventData = new ImplPostEventData( nEvent, pWin, *pKeyEvent );
719 PostUserEvent( nEventId,
720 STATIC_LINK( NULL, Application, PostEventHandler ),
721 pPostEventData );
723 if( nEventId )
725 pPostEventData->mnEventId = nEventId;
726 aPostedEventList.push_back( ImplPostEventPair( pWin, pPostEventData ) );
728 else
729 delete pPostEventData;
732 return nEventId;
735 sal_uLong Application::PostMouseEvent( sal_uLong nEvent, Window *pWin, MouseEvent* pMouseEvent )
737 const SolarMutexGuard aGuard;
738 sal_uLong nEventId = 0;
740 if( pWin && pMouseEvent )
742 Point aTransformedPos( pMouseEvent->GetPosPixel() );
744 aTransformedPos.X() += pWin->mnOutOffX;
745 aTransformedPos.Y() += pWin->mnOutOffY;
747 const MouseEvent aTransformedEvent( aTransformedPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(),
748 pMouseEvent->GetButtons(), pMouseEvent->GetModifier() );
750 ImplPostEventData* pPostEventData = new ImplPostEventData( nEvent, pWin, aTransformedEvent );
752 PostUserEvent( nEventId,
753 STATIC_LINK( NULL, Application, PostEventHandler ),
754 pPostEventData );
756 if( nEventId )
758 pPostEventData->mnEventId = nEventId;
759 aPostedEventList.push_back( ImplPostEventPair( pWin, pPostEventData ) );
761 else
762 delete pPostEventData;
765 return nEventId;
768 #if !HAVE_FEATURE_DESKTOP
770 sal_uLong Application::PostZoomEvent( sal_uLong nEvent, Window *pWin, ZoomEvent* pZoomEvent )
772 const SolarMutexGuard aGuard;
773 sal_uLong nEventId = 0;
775 if( pWin && pZoomEvent )
777 Point aTransformedPos( pZoomEvent->GetCenter() );
779 aTransformedPos.X() += pWin->mnOutOffX;
780 aTransformedPos.Y() += pWin->mnOutOffY;
782 const ZoomEvent aTransformedEvent( aTransformedPos, pZoomEvent->GetScale() );
784 ImplPostEventData* pPostEventData = new ImplPostEventData( nEvent, pWin, aTransformedEvent );
786 PostUserEvent( nEventId,
787 STATIC_LINK( NULL, Application, PostEventHandler ),
788 pPostEventData );
790 if( nEventId )
792 pPostEventData->mnEventId = nEventId;
793 aPostedEventList.push_back( ImplPostEventPair( pWin, pPostEventData ) );
795 else
796 delete pPostEventData;
799 return nEventId;
802 sal_uLong Application::PostScrollEvent( sal_uLong nEvent, Window *pWin, ScrollEvent* pScrollEvent )
804 const SolarMutexGuard aGuard;
805 sal_uLong nEventId = 0;
807 if( pWin && pScrollEvent )
809 ImplPostEventData* pPostEventData = new ImplPostEventData( nEvent, pWin, *pScrollEvent );
811 PostUserEvent( nEventId,
812 STATIC_LINK( NULL, Application, PostEventHandler ),
813 pPostEventData );
815 if( nEventId )
817 pPostEventData->mnEventId = nEventId;
818 aPostedEventList.push_back( ImplPostEventPair( pWin, pPostEventData ) );
820 else
821 delete pPostEventData;
824 return nEventId;
827 #endif // !HAVE_FEATURE_DESKTOP
829 IMPL_STATIC_LINK_NOINSTANCE( Application, PostEventHandler, void*, pCallData )
831 const SolarMutexGuard aGuard;
832 ImplPostEventData* pData = static_cast< ImplPostEventData * >( pCallData );
833 const void* pEventData;
834 sal_uLong nEvent;
835 const sal_uLong nEventId = pData->mnEventId;
837 switch( pData->mnEvent )
839 case VCLEVENT_WINDOW_MOUSEMOVE:
840 nEvent = SALEVENT_EXTERNALMOUSEMOVE;
841 pEventData = &pData->maMouseEvent;
842 break;
844 case VCLEVENT_WINDOW_MOUSEBUTTONDOWN:
845 nEvent = SALEVENT_EXTERNALMOUSEBUTTONDOWN;
846 pEventData = &pData->maMouseEvent;
847 break;
849 case VCLEVENT_WINDOW_MOUSEBUTTONUP:
850 nEvent = SALEVENT_EXTERNALMOUSEBUTTONUP;
851 pEventData = &pData->maMouseEvent;
852 break;
854 case VCLEVENT_WINDOW_KEYINPUT:
855 nEvent = SALEVENT_EXTERNALKEYINPUT;
856 pEventData = &pData->maKeyEvent;
857 break;
859 case VCLEVENT_WINDOW_KEYUP:
860 nEvent = SALEVENT_EXTERNALKEYUP;
861 pEventData = &pData->maKeyEvent;
862 break;
864 case VCLEVENT_WINDOW_ZOOM:
865 nEvent = SALEVENT_EXTERNALZOOM;
866 pEventData = &pData->maZoomEvent;
867 break;
869 case VCLEVENT_WINDOW_SCROLL:
870 nEvent = SALEVENT_EXTERNALSCROLL;
871 pEventData = &pData->maScrollEvent;
872 break;
874 default:
875 nEvent = 0;
876 pEventData = NULL;
877 break;
880 if( pData->mpWin && pData->mpWin->mpWindowImpl->mpFrameWindow && pEventData )
881 ImplWindowFrameProc( pData->mpWin->mpWindowImpl->mpFrameWindow, NULL, (sal_uInt16) nEvent, pEventData );
883 // remove this event from list of posted events, watch for destruction of internal data
884 ::std::list< ImplPostEventPair >::iterator aIter( aPostedEventList.begin() );
886 while( aIter != aPostedEventList.end() )
888 if( nEventId == (*aIter).second->mnEventId )
890 delete (*aIter).second;
891 aIter = aPostedEventList.erase( aIter );
893 else
894 ++aIter;
897 return 0;
900 void Application::RemoveMouseAndKeyEvents( Window* pWin )
902 const SolarMutexGuard aGuard;
904 // remove all events for specific window, watch for destruction of internal data
905 ::std::list< ImplPostEventPair >::iterator aIter( aPostedEventList.begin() );
907 while( aIter != aPostedEventList.end() )
909 if( pWin == (*aIter).first )
911 if( (*aIter).second->mnEventId )
912 RemoveUserEvent( (*aIter).second->mnEventId );
914 delete (*aIter).second;
915 aIter = aPostedEventList.erase( aIter );
917 else
918 ++aIter;
922 sal_uLong Application::PostUserEvent( const Link& rLink, void* pCaller )
924 sal_uLong nEventId;
925 PostUserEvent( nEventId, rLink, pCaller );
926 return nEventId;
929 sal_Bool Application::PostUserEvent( sal_uLong& rEventId, const Link& rLink, void* pCaller )
931 ImplSVEvent* pSVEvent = new ImplSVEvent;
932 pSVEvent->mnEvent = 0;
933 pSVEvent->mpData = pCaller;
934 pSVEvent->mpLink = new Link( rLink );
935 pSVEvent->mpWindow = NULL;
936 pSVEvent->mbCall = sal_True;
937 rEventId = (sal_uLong)pSVEvent;
938 Window* pDefWindow = ImplGetDefaultWindow();
939 if ( pDefWindow && pDefWindow->ImplGetFrame()->PostEvent( pSVEvent ) )
940 return sal_True;
941 else
943 rEventId = 0;
944 delete pSVEvent;
945 return sal_False;
949 void Application::RemoveUserEvent( sal_uLong nUserEvent )
951 if(nUserEvent)
953 ImplSVEvent* pSVEvent = (ImplSVEvent*)nUserEvent;
955 DBG_ASSERT( !pSVEvent->mpWindow,
956 "Application::RemoveUserEvent(): Event is send to a window" );
957 DBG_ASSERT( pSVEvent->mbCall,
958 "Application::RemoveUserEvent(): Event is already removed" );
960 if ( pSVEvent->mpWindow )
962 if( ! pSVEvent->maDelData.IsDead() )
963 pSVEvent->mpWindow->ImplRemoveDel( &(pSVEvent->maDelData) );
964 pSVEvent->mpWindow = NULL;
967 pSVEvent->mbCall = sal_False;
971 sal_Bool Application::InsertIdleHdl( const Link& rLink, sal_uInt16 nPrio )
973 ImplSVData* pSVData = ImplGetSVData();
975 // create if does not exist
976 if ( !pSVData->maAppData.mpIdleMgr )
977 pSVData->maAppData.mpIdleMgr = new ImplIdleMgr;
979 return pSVData->maAppData.mpIdleMgr->InsertIdleHdl( rLink, nPrio );
982 void Application::RemoveIdleHdl( const Link& rLink )
984 ImplSVData* pSVData = ImplGetSVData();
986 if ( pSVData->maAppData.mpIdleMgr )
987 pSVData->maAppData.mpIdleMgr->RemoveIdleHdl( rLink );
990 void Application::EnableNoYieldMode( bool i_bNoYield )
992 ImplSVData* pSVData = ImplGetSVData();
993 pSVData->maAppData.mbNoYield = i_bNoYield;
996 void Application::AddPostYieldListener( const Link& i_rListener )
998 ImplSVData* pSVData = ImplGetSVData();
999 if( ! pSVData->maAppData.mpPostYieldListeners )
1000 pSVData->maAppData.mpPostYieldListeners = new VclEventListeners2();
1001 pSVData->maAppData.mpPostYieldListeners->addListener( i_rListener );
1004 void Application::RemovePostYieldListener( const Link& i_rListener )
1006 ImplSVData* pSVData = ImplGetSVData();
1007 if( pSVData->maAppData.mpPostYieldListeners )
1008 pSVData->maAppData.mpPostYieldListeners->removeListener( i_rListener );
1011 WorkWindow* Application::GetAppWindow()
1013 return ImplGetSVData()->maWinData.mpAppWin;
1016 Window* Application::GetFocusWindow()
1018 return ImplGetSVData()->maWinData.mpFocusWin;
1021 OutputDevice* Application::GetDefaultDevice()
1023 return ImplGetDefaultWindow();
1026 Window* Application::GetFirstTopLevelWindow()
1028 ImplSVData* pSVData = ImplGetSVData();
1029 return pSVData->maWinData.mpFirstFrame;
1032 Window* Application::GetNextTopLevelWindow( Window* pWindow )
1034 return pWindow->mpWindowImpl->mpFrameData->mpNextFrame;
1037 long Application::GetTopWindowCount()
1039 long nRet = 0;
1040 ImplSVData* pSVData = ImplGetSVData();
1041 Window *pWin = pSVData ? pSVData->maWinData.mpFirstFrame : NULL;
1042 while( pWin )
1044 if( pWin->ImplGetWindow()->IsTopWindow() )
1045 nRet++;
1046 pWin = pWin->mpWindowImpl->mpFrameData->mpNextFrame;
1048 return nRet;
1051 Window* Application::GetTopWindow( long nIndex )
1053 long nIdx = 0;
1054 ImplSVData* pSVData = ImplGetSVData();
1055 Window *pWin = pSVData ? pSVData->maWinData.mpFirstFrame : NULL;
1056 while( pWin )
1058 if( pWin->ImplGetWindow()->IsTopWindow() )
1060 if( nIdx == nIndex )
1061 return pWin->ImplGetWindow();
1062 else
1063 nIdx++;
1065 pWin = pWin->mpWindowImpl->mpFrameData->mpNextFrame;
1067 return NULL;
1070 Window* Application::GetActiveTopWindow()
1072 Window *pWin = ImplGetSVData()->maWinData.mpFocusWin;
1073 while( pWin )
1075 if( pWin->IsTopWindow() )
1076 return pWin;
1077 pWin = pWin->mpWindowImpl->mpParent;
1079 return NULL;
1082 void Application::SetAppName( const OUString& rUniqueName )
1084 ImplSVData* pSVData = ImplGetSVData();
1086 // create if does not exist
1087 if ( !pSVData->maAppData.mpAppName )
1088 pSVData->maAppData.mpAppName = new OUString( rUniqueName );
1089 else
1090 *(pSVData->maAppData.mpAppName) = rUniqueName;
1093 OUString Application::GetAppName()
1095 ImplSVData* pSVData = ImplGetSVData();
1096 if ( pSVData->maAppData.mpAppName )
1097 return *(pSVData->maAppData.mpAppName);
1098 else
1099 return OUString();
1102 void Application::SetDisplayName( const OUString& rName )
1104 ImplSVData* pSVData = ImplGetSVData();
1106 // create if does not exist
1107 if ( !pSVData->maAppData.mpDisplayName )
1108 pSVData->maAppData.mpDisplayName = new OUString( rName );
1109 else
1110 *(pSVData->maAppData.mpDisplayName) = rName;
1113 OUString Application::GetDisplayName()
1115 ImplSVData* pSVData = ImplGetSVData();
1116 if ( pSVData->maAppData.mpDisplayName )
1117 return *(pSVData->maAppData.mpDisplayName);
1118 else if ( pSVData->maWinData.mpAppWin )
1119 return pSVData->maWinData.mpAppWin->GetText();
1120 else
1121 return OUString("");
1124 unsigned int Application::GetScreenCount()
1126 SalSystem* pSys = ImplGetSalSystem();
1127 return pSys ? pSys->GetDisplayScreenCount() : 0;
1130 bool Application::IsUnifiedDisplay()
1132 SalSystem* pSys = ImplGetSalSystem();
1133 return pSys ? pSys->IsUnifiedDisplay() : true;
1136 unsigned int Application::GetDisplayBuiltInScreen()
1138 SalSystem* pSys = ImplGetSalSystem();
1139 return pSys ? pSys->GetDisplayBuiltInScreen() : 0;
1142 unsigned int Application::GetDisplayExternalScreen()
1144 // This is really unpleasant, in theory we could have multiple
1145 // external displays etc.
1146 int nExternal(0);
1147 switch (GetDisplayBuiltInScreen())
1149 case 0:
1150 nExternal = 1;
1151 break;
1152 case 1:
1153 nExternal = 0;
1154 break;
1155 default:
1156 // When the built-in display is neither 0 nor 1
1157 // then place the full-screen presentation on the
1158 // first available screen.
1159 nExternal = 0;
1160 break;
1162 return nExternal;
1165 Rectangle Application::GetScreenPosSizePixel( unsigned int nScreen )
1167 SalSystem* pSys = ImplGetSalSystem();
1168 return pSys ? pSys->GetDisplayScreenPosSizePixel( nScreen ) : Rectangle();
1171 namespace {
1172 unsigned long calcDistSquare( const Point& i_rPoint, const Rectangle& i_rRect )
1174 const Point aRectCenter( (i_rRect.Left() + i_rRect.Right())/2,
1175 (i_rRect.Top() + i_rRect.Bottom())/ 2 );
1176 const long nDX = aRectCenter.X() - i_rPoint.X();
1177 const long nDY = aRectCenter.Y() - i_rPoint.Y();
1178 return nDX*nDX + nDY*nDY;
1182 unsigned int Application::GetBestScreen( const Rectangle& i_rRect )
1184 if( !IsUnifiedDisplay() )
1185 return GetDisplayBuiltInScreen();
1187 const unsigned int nScreens = GetScreenCount();
1188 unsigned int nBestMatchScreen = 0;
1189 unsigned long nOverlap = 0;
1190 for( unsigned int i = 0; i < nScreens; i++ )
1192 const Rectangle aCurScreenRect( GetScreenPosSizePixel( i ) );
1193 // if a screen contains the rectangle completely it is obviously the best screen
1194 if( aCurScreenRect.IsInside( i_rRect ) )
1195 return i;
1196 // next the screen which contains most of the area of the rect is the best
1197 Rectangle aIntersection( aCurScreenRect.GetIntersection( i_rRect ) );
1198 if( ! aIntersection.IsEmpty() )
1200 const unsigned long nCurOverlap( aIntersection.GetWidth() * aIntersection.GetHeight() );
1201 if( nCurOverlap > nOverlap )
1203 nOverlap = nCurOverlap;
1204 nBestMatchScreen = i;
1208 if( nOverlap > 0 )
1209 return nBestMatchScreen;
1211 // finally the screen which center is nearest to the rect is the best
1212 const Point aCenter( (i_rRect.Left() + i_rRect.Right())/2,
1213 (i_rRect.Top() + i_rRect.Bottom())/2 );
1214 unsigned long nDist = ULONG_MAX;
1215 for( unsigned int i = 0; i < nScreens; i++ )
1217 const Rectangle aCurScreenRect( GetScreenPosSizePixel( i ) );
1218 const unsigned long nCurDist( calcDistSquare( aCenter, aCurScreenRect ) );
1219 if( nCurDist < nDist )
1221 nBestMatchScreen = i;
1222 nDist = nCurDist;
1225 return nBestMatchScreen;
1228 sal_Bool Application::InsertAccel( Accelerator* pAccel )
1230 ImplSVData* pSVData = ImplGetSVData();
1232 if ( !pSVData->maAppData.mpAccelMgr )
1233 pSVData->maAppData.mpAccelMgr = new ImplAccelManager();
1234 return pSVData->maAppData.mpAccelMgr->InsertAccel( pAccel );
1237 void Application::RemoveAccel( Accelerator* pAccel )
1239 ImplSVData* pSVData = ImplGetSVData();
1241 if ( pSVData->maAppData.mpAccelMgr )
1242 pSVData->maAppData.mpAccelMgr->RemoveAccel( pAccel );
1245 void Application::SetHelp( Help* pHelp )
1247 ImplGetSVData()->maAppData.mpHelp = pHelp;
1250 Help* Application::GetHelp()
1252 return ImplGetSVData()->maAppData.mpHelp;
1255 void Application::EnableAutoHelpId( sal_Bool bEnabled )
1257 ImplGetSVData()->maHelpData.mbAutoHelpId = bEnabled;
1260 sal_Bool Application::IsAutoHelpIdEnabled()
1262 return ImplGetSVData()->maHelpData.mbAutoHelpId;
1265 void Application::EnableAutoMnemonic( sal_Bool bEnabled )
1267 AllSettings aSettings = GetSettings();
1268 StyleSettings aStyle = aSettings.GetStyleSettings();
1269 aStyle.SetAutoMnemonic( bEnabled );
1270 aSettings.SetStyleSettings( aStyle );
1271 SetSettings( aSettings );
1274 sal_Bool Application::IsAutoMnemonicEnabled()
1276 return GetSettings().GetStyleSettings().GetAutoMnemonic();
1279 void Application::SetDialogScaleX( short nScale )
1281 ImplSVData* pSVData = ImplGetSVData();
1282 pSVData->maAppData.mnDialogScaleX = nScale;
1283 pSVData->maGDIData.mnAppFontX = pSVData->maGDIData.mnRealAppFontX;
1284 if ( nScale )
1285 pSVData->maGDIData.mnAppFontX += (pSVData->maGDIData.mnAppFontX*nScale)/100;
1288 void Application::SetDefDialogParent( Window* pWindow )
1290 ImplGetSVData()->maWinData.mpDefDialogParent = pWindow;
1293 Window* Application::GetDefDialogParent()
1295 ImplSVData* pSVData = ImplGetSVData();
1296 // #103442# find some useful dialog parent if there
1297 // was no default set
1298 // NOTE: currently even the default is not used
1299 if( sal_False && pSVData->maWinData.mpDefDialogParent != NULL )
1300 return pSVData->maWinData.mpDefDialogParent;
1301 else
1303 // always use the topmost parent of the candidate
1304 // window to avoid using dialogs or floaters
1305 // as DefDialogParent
1307 // current focus frame
1308 Window *pWin = NULL;
1309 if( (pWin = pSVData->maWinData.mpFocusWin) != NULL )
1311 while( pWin->mpWindowImpl && pWin->mpWindowImpl->mpParent )
1312 pWin = pWin->mpWindowImpl->mpParent;
1314 if( (pWin->mpWindowImpl->mnStyle & WB_INTROWIN) == 0 )
1316 // check for corrupted window hierarchy, #122232#, may be we now crash somewhere else
1317 if( !pWin->mpWindowImpl )
1319 OSL_FAIL( "Window hierarchy corrupted!" );
1320 pSVData->maWinData.mpFocusWin = NULL; // avoid further access
1321 return NULL;
1324 return pWin->mpWindowImpl->mpFrameWindow->ImplGetWindow();
1327 // last active application frame
1328 if( NULL != (pWin = pSVData->maWinData.mpActiveApplicationFrame) )
1330 return pWin->mpWindowImpl->mpFrameWindow->ImplGetWindow();
1332 else
1334 // first visible top window (may be totally wrong....)
1335 pWin = pSVData->maWinData.mpFirstFrame;
1336 while( pWin )
1338 if( pWin->ImplGetWindow()->IsTopWindow() &&
1339 pWin->mpWindowImpl->mbReallyVisible &&
1340 (pWin->mpWindowImpl->mnStyle & WB_INTROWIN) == 0
1343 while( pWin->mpWindowImpl->mpParent )
1344 pWin = pWin->mpWindowImpl->mpParent;
1345 return pWin->mpWindowImpl->mpFrameWindow->ImplGetWindow();
1347 pWin = pWin->mpWindowImpl->mpFrameData->mpNextFrame;
1349 // use the desktop
1350 return NULL;
1355 Application::DialogCancelMode Application::GetDialogCancelMode()
1357 return ImplGetSVData()->maAppData.meDialogCancel;
1360 void Application::SetDialogCancelMode( DialogCancelMode mode )
1362 ImplGetSVData()->maAppData.meDialogCancel = mode;
1365 sal_Bool Application::IsDialogCancelEnabled()
1367 return ImplGetSVData()->maAppData.meDialogCancel != DIALOG_CANCEL_OFF;
1370 void Application::SetSystemWindowMode( sal_uInt16 nMode )
1372 ImplGetSVData()->maAppData.mnSysWinMode = nMode;
1375 sal_uInt16 Application::GetSystemWindowMode()
1377 return ImplGetSVData()->maAppData.mnSysWinMode;
1380 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > Application::GetVCLToolkit()
1382 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > xT;
1383 UnoWrapperBase* pWrapper = Application::GetUnoWrapper( sal_True );
1384 if ( pWrapper )
1385 xT = pWrapper->GetVCLToolkit();
1386 return xT;
1389 #ifdef DISABLE_DYNLOADING
1391 extern "C" { UnoWrapperBase* CreateUnoWrapper(); }
1393 #else
1395 extern "C" { static void SAL_CALL thisModule() {} }
1397 #endif
1399 UnoWrapperBase* Application::GetUnoWrapper( sal_Bool bCreateIfNotExist )
1401 ImplSVData* pSVData = ImplGetSVData();
1402 static bool bAlreadyTriedToCreate = false;
1403 if ( !pSVData->mpUnoWrapper && bCreateIfNotExist && !bAlreadyTriedToCreate )
1405 #ifndef DISABLE_DYNLOADING
1406 OUString aLibName = ::vcl::unohelper::CreateLibraryName(
1407 #ifdef LIBO_MERGELIBS
1408 "merged",
1409 #else
1410 "tk",
1411 #endif
1412 sal_True );
1413 oslModule hTkLib = osl_loadModuleRelative(
1414 &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT );
1415 if ( hTkLib )
1417 OUString aFunctionName( "CreateUnoWrapper" );
1418 FN_TkCreateUnoWrapper fnCreateWrapper = (FN_TkCreateUnoWrapper)osl_getFunctionSymbol( hTkLib, aFunctionName.pData );
1419 if ( fnCreateWrapper )
1421 pSVData->mpUnoWrapper = fnCreateWrapper();
1424 DBG_ASSERT( pSVData->mpUnoWrapper, "UnoWrapper could not be created!" );
1425 #else
1426 pSVData->mpUnoWrapper = CreateUnoWrapper();
1427 #endif
1428 bAlreadyTriedToCreate = true;
1430 return pSVData->mpUnoWrapper;
1433 void Application::SetUnoWrapper( UnoWrapperBase* pWrapper )
1435 ImplSVData* pSVData = ImplGetSVData();
1436 DBG_ASSERT( !pSVData->mpUnoWrapper, "SetUnoWrapper: Wrapper already exists" );
1437 pSVData->mpUnoWrapper = pWrapper;
1440 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayConnection > Application::GetDisplayConnection()
1442 ImplSVData* pSVData = ImplGetSVData();
1444 if( !pSVData->mxDisplayConnection.is() )
1446 pSVData->mxDisplayConnection.set( new ::vcl::DisplayConnection );
1447 pSVData->mxDisplayConnection->start();
1450 return pSVData->mxDisplayConnection.get();
1453 void Application::SetFilterHdl( const Link& rLink )
1455 ImplGetSVData()->maGDIData.mpGrfConverter->SetFilterHdl( rLink );
1458 bool ImplCallHotKey( const KeyCode& rKeyCode )
1460 ImplSVData* pSVData = ImplGetSVData();
1461 ImplHotKey* pHotKeyData = pSVData->maAppData.mpFirstHotKey;
1462 while ( pHotKeyData )
1464 if ( pHotKeyData->maKeyCode.IsDefinedKeyCodeEqual( rKeyCode ) )
1466 pHotKeyData->maLink.Call( pHotKeyData->mpUserData );
1467 return true;
1470 pHotKeyData = pHotKeyData->mpNext;
1473 return false;
1476 void ImplFreeHotKeyData()
1478 ImplSVData* pSVData = ImplGetSVData();
1479 ImplHotKey* pTempHotKeyData;
1480 ImplHotKey* pHotKeyData = pSVData->maAppData.mpFirstHotKey;
1481 while ( pHotKeyData )
1483 pTempHotKeyData = pHotKeyData->mpNext;
1484 delete pHotKeyData;
1485 pHotKeyData = pTempHotKeyData;
1488 pSVData->maAppData.mpFirstHotKey = NULL;
1491 void ImplFreeEventHookData()
1493 ImplSVData* pSVData = ImplGetSVData();
1494 ImplEventHook* pTempEventHookData;
1495 ImplEventHook* pEventHookData = pSVData->maAppData.mpFirstEventHook;
1496 while ( pEventHookData )
1498 pTempEventHookData = pEventHookData->mpNext;
1499 delete pEventHookData;
1500 pEventHookData = pTempEventHookData;
1503 pSVData->maAppData.mpFirstEventHook = NULL;
1506 long Application::CallEventHooks( NotifyEvent& rEvt )
1508 ImplSVData* pSVData = ImplGetSVData();
1509 long nRet = 0;
1510 ImplEventHook* pTempEventHookData;
1511 ImplEventHook* pEventHookData = pSVData->maAppData.mpFirstEventHook;
1512 while ( pEventHookData )
1514 pTempEventHookData = pEventHookData->mpNext;
1515 nRet = pEventHookData->mpProc( rEvt, pEventHookData->mpUserData );
1516 if ( nRet )
1517 break;
1518 pEventHookData = pTempEventHookData;
1521 return nRet;
1524 const LocaleDataWrapper& Application::GetAppLocaleDataWrapper()
1526 return GetSettings().GetLocaleDataWrapper();
1529 void Application::EnableHeadlessMode( bool dialogsAreFatal )
1531 SetDialogCancelMode(
1532 dialogsAreFatal ? DIALOG_CANCEL_FATAL : DIALOG_CANCEL_SILENT );
1535 sal_Bool Application::IsHeadlessModeEnabled()
1537 return IsDialogCancelEnabled();
1540 bool Application::IsHeadlessModeRequested()
1542 sal_uInt32 n = rtl_getAppCommandArgCount();
1543 for (sal_uInt32 i = 0; i < n; ++i) {
1544 OUString arg;
1545 rtl_getAppCommandArg(i, &arg.pData);
1546 if ( arg == "--headless" || arg == "-headless" ) {
1547 return true;
1550 return false;
1553 static bool bConsoleOnly = false;
1555 bool Application::IsConsoleOnly()
1557 return bConsoleOnly;
1560 void Application::EnableConsoleOnly()
1562 bConsoleOnly = true;
1565 void Application::ShowNativeErrorBox(const OUString& sTitle ,
1566 const OUString& sMessage)
1568 int btn = ImplGetSalSystem()->ShowNativeMessageBox (
1569 sTitle,
1570 sMessage,
1571 SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK,
1572 SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK, false);
1573 if (btn != SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK) {
1574 OSL_TRACE("ShowNativeMessageBox returned %d", btn);
1578 bool Application::CanToggleImeStatusWindow()
1580 ImplSVData* pSVData = ImplGetSVData();
1581 if( ! pSVData->mpImeStatus )
1582 pSVData->mpImeStatus = pSVData->mpDefInst->CreateI18NImeStatus();
1583 return pSVData->mpImeStatus->canToggle();
1586 void Application::ShowImeStatusWindow(bool bShow)
1588 ImplGetSVData()->maAppData.meShowImeStatusWindow = bShow
1589 ? ImplSVAppData::ImeStatusWindowMode_SHOW
1590 : ImplSVAppData::ImeStatusWindowMode_HIDE;
1592 ImplSVData* pSVData = ImplGetSVData();
1593 if( ! pSVData->mpImeStatus )
1594 pSVData->mpImeStatus = pSVData->mpDefInst->CreateI18NImeStatus();
1595 pSVData->mpImeStatus->toggle();
1598 bool Application::GetShowImeStatusWindowDefault()
1600 rtl_TextEncodingInfo aInfo;
1601 aInfo.StructSize = sizeof aInfo;
1602 return rtl_getTextEncodingInfo(osl_getThreadTextEncoding(), &aInfo)
1603 && aInfo.MaximumCharSize > 1;
1606 const OUString& Application::GetDesktopEnvironment()
1608 return SalGetDesktopEnvironment();
1611 void Application::AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService)
1613 ImplSVData* pSVData = ImplGetSVData();
1614 pSVData->mpDefInst->AddToRecentDocumentList(rFileUrl, rMimeType, rDocumentService);
1617 bool InitAccessBridge( bool bShowCancel, bool &rCancelled )
1619 // Disable Java bridge on UNIX
1620 #if defined UNX
1621 (void) bShowCancel; // unused
1622 (void) rCancelled; // unused
1623 return true;
1624 #else
1625 bool bRet = ImplInitAccessBridge( bShowCancel, rCancelled );
1627 if( !bRet && bShowCancel && !rCancelled )
1629 // disable accessibility if the user chooses to continue
1630 AllSettings aSettings = Application::GetSettings();
1631 MiscSettings aMisc = aSettings.GetMiscSettings();
1632 aMisc.SetEnableATToolSupport( sal_False );
1633 aSettings.SetMiscSettings( aMisc );
1634 Application::SetSettings( aSettings );
1636 return bRet;
1637 #endif // !UNX
1640 // MT: AppEvent was in oldsv.cxx, but is still needed...
1641 void Application::AppEvent( const ApplicationEvent& /*rAppEvent*/ )
1645 bool Application::hasNativeFileSelection()
1647 ImplSVData* pSVData = ImplGetSVData();
1648 return pSVData->mpDefInst->hasNativeFileSelection();
1651 Reference< ui::dialogs::XFilePicker2 >
1652 Application::createFilePicker( const Reference< uno::XComponentContext >& xSM )
1654 ImplSVData* pSVData = ImplGetSVData();
1655 return pSVData->mpDefInst->createFilePicker( xSM );
1658 Reference< ui::dialogs::XFolderPicker2 >
1659 Application::createFolderPicker( const Reference< uno::XComponentContext >& xSM )
1661 ImplSVData* pSVData = ImplGetSVData();
1662 return pSVData->mpDefInst->createFolderPicker( xSM );
1665 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */