1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <config_features.h>
22 #include "comphelper/processfactory.hxx"
24 #include "osl/module.h"
25 #include "osl/file.hxx"
26 #include "osl/thread.h"
28 #include "rtl/tencinfo.h"
29 #include "rtl/instance.hxx"
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/scheduler.hxx"
49 #include "vcl/unohelp.hxx"
50 #include "vcl/lazydelete.hxx"
52 #include "salinst.hxx"
53 #include "salframe.hxx"
56 #include "salimestatus.hxx"
57 #include "xconnection.hxx"
60 #include "idlemgr.hxx"
63 #include "com/sun/star/uno/Reference.h"
64 #include "com/sun/star/awt/XToolkit.hpp"
65 #include "com/sun/star/uno/XNamingService.hpp"
66 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
67 #include "comphelper/solarmutex.hxx"
68 #include "osl/process.h"
73 using namespace ::com::sun::star
;
74 using namespace ::com::sun::star::uno
;
76 // keycodes handled internally by VCL
80 ImplReservedKey( vcl::KeyCode aKeyCode
, sal_uInt16 nResId
) :
81 mKeyCode(aKeyCode
), mnResId( nResId
)
84 vcl::KeyCode mKeyCode
;
88 typedef std::pair
<ImplReservedKey
*, size_t> ReservedKeys
;
91 struct ImplReservedKeysImpl
93 ReservedKeys
* operator()()
95 static ImplReservedKey ImplReservedKeys
[] =
97 ImplReservedKey(vcl::KeyCode(KEY_F1
,0), SV_SHORTCUT_HELP
),
98 ImplReservedKey(vcl::KeyCode(KEY_F1
,KEY_SHIFT
), SV_SHORTCUT_ACTIVEHELP
),
99 ImplReservedKey(vcl::KeyCode(KEY_F1
,KEY_MOD1
), SV_SHORTCUT_CONTEXTHELP
),
100 ImplReservedKey(vcl::KeyCode(KEY_F2
,KEY_SHIFT
), SV_SHORTCUT_CONTEXTHELP
),
101 ImplReservedKey(vcl::KeyCode(KEY_F4
,KEY_MOD1
), SV_SHORTCUT_DOCKUNDOCK
),
102 ImplReservedKey(vcl::KeyCode(KEY_F4
,KEY_MOD2
), SV_SHORTCUT_DOCKUNDOCK
),
103 ImplReservedKey(vcl::KeyCode(KEY_F4
,KEY_MOD1
|KEY_MOD2
), SV_SHORTCUT_DOCKUNDOCK
),
104 ImplReservedKey(vcl::KeyCode(KEY_F6
,0), SV_SHORTCUT_NEXTSUBWINDOW
),
105 ImplReservedKey(vcl::KeyCode(KEY_F6
,KEY_MOD1
), SV_SHORTCUT_TODOCUMENT
),
106 ImplReservedKey(vcl::KeyCode(KEY_F6
,KEY_SHIFT
), SV_SHORTCUT_PREVSUBWINDOW
),
107 ImplReservedKey(vcl::KeyCode(KEY_F6
,KEY_MOD1
|KEY_SHIFT
), SV_SHORTCUT_SPLITTER
),
108 ImplReservedKey(vcl::KeyCode(KEY_F10
,0), SV_SHORTCUT_MENUBAR
)
111 ImplReservedKey(vcl::KeyCode(KEY_1
,KEY_SHIFT
|KEY_MOD1
), 0),
112 ImplReservedKey(vcl::KeyCode(KEY_2
,KEY_SHIFT
|KEY_MOD1
), 0),
113 ImplReservedKey(vcl::KeyCode(KEY_3
,KEY_SHIFT
|KEY_MOD1
), 0),
114 ImplReservedKey(vcl::KeyCode(KEY_4
,KEY_SHIFT
|KEY_MOD1
), 0),
115 ImplReservedKey(vcl::KeyCode(KEY_5
,KEY_SHIFT
|KEY_MOD1
), 0),
116 ImplReservedKey(vcl::KeyCode(KEY_6
,KEY_SHIFT
|KEY_MOD1
), 0),
117 ImplReservedKey(vcl::KeyCode(KEY_7
,KEY_SHIFT
|KEY_MOD1
), 0),
118 ImplReservedKey(vcl::KeyCode(KEY_8
,KEY_SHIFT
|KEY_MOD1
), 0),
119 ImplReservedKey(vcl::KeyCode(KEY_9
,KEY_SHIFT
|KEY_MOD1
), 0),
120 ImplReservedKey(vcl::KeyCode(KEY_0
,KEY_SHIFT
|KEY_MOD1
), 0),
121 ImplReservedKey(vcl::KeyCode(KEY_ADD
,KEY_SHIFT
|KEY_MOD1
), 0)
124 static ReservedKeys aKeys
126 &ImplReservedKeys
[0],
127 sizeof(ImplReservedKeys
) / sizeof(ImplReservedKey
)
133 struct ImplReservedKeys
134 : public rtl::StaticAggregate
<ReservedKeys
, ImplReservedKeysImpl
> {};
138 typedef UnoWrapperBase
* (SAL_CALL
*FN_TkCreateUnoWrapper
)();
145 vcl::KeyCode maKeyCode
;
151 ImplEventHook
* mpNext
;
153 VCLEventHookProc mpProc
;
156 struct ImplPostEventData
159 VclPtr
<vcl::Window
> mpWin
;
160 ImplSVEvent
* mnEventId
;
162 MouseEvent maMouseEvent
;
163 ZoomEvent maZoomEvent
;
164 ScrollEvent maScrollEvent
;
166 ImplPostEventData( sal_uLong nEvent
, vcl::Window
* pWin
, const KeyEvent
& rKeyEvent
) :
167 mnEvent( nEvent
), mpWin( pWin
), mnEventId( 0 ), maKeyEvent( rKeyEvent
) {}
168 ImplPostEventData( sal_uLong nEvent
, vcl::Window
* pWin
, const MouseEvent
& rMouseEvent
) :
169 mnEvent( nEvent
), mpWin( pWin
), mnEventId( 0 ), maMouseEvent( rMouseEvent
) {}
170 #if !HAVE_FEATURE_DESKTOP
171 ImplPostEventData( sal_uLong nEvent
, vcl::Window
* pWin
, const ZoomEvent
& rZoomEvent
) :
172 mnEvent( nEvent
), mpWin( pWin
), mnEventId( 0 ), maZoomEvent( rZoomEvent
) {}
173 ImplPostEventData( sal_uLong nEvent
, vcl::Window
* pWin
, const ScrollEvent
& rScrollEvent
) :
174 mnEvent( nEvent
), mpWin( pWin
), mnEventId( 0 ), maScrollEvent( rScrollEvent
) {}
177 ~ImplPostEventData() {}
180 typedef ::std::pair
< VclPtr
<vcl::Window
>, ImplPostEventData
* > ImplPostEventPair
;
182 static ::std::list
< ImplPostEventPair
> aPostedEventList
;
184 Application
* GetpApp()
186 ImplSVData
* pSVData
= ImplGetSVData();
189 return pSVData
->mpApp
;
192 Application::Application()
194 // useful for themes at least, perhaps extensions too
195 OUString
aVar("LIBO_VERSION"), aValue(LIBO_VERSION_DOTTED
);
196 osl_setEnvironment(aVar
.pData
, aValue
.pData
);
198 ImplGetSVData()->mpApp
= this;
202 Application::~Application()
206 ImplGetSVData()->mpApp
= NULL
;
209 int Application::Main()
211 SAL_WARN("vcl", "Application is a base class and should be overridden.");
215 bool Application::QueryExit()
217 WorkWindow
* pAppWin
= ImplGetSVData()->maWinData
.mpAppWin
;
219 // call the close handler of the application window
221 return pAppWin
->Close();
226 void Application::Init()
230 void Application::InitFinished()
234 void Application::DeInit()
238 sal_uInt16
Application::GetCommandLineParamCount()
240 return (sal_uInt16
)osl_getCommandArgCount();
243 OUString
Application::GetCommandLineParam( sal_uInt16 nParam
)
246 osl_getCommandArg( nParam
, &aParam
.pData
);
250 OUString
Application::GetAppFileName()
252 ImplSVData
* pSVData
= ImplGetSVData();
253 DBG_ASSERT( pSVData
->maAppData
.mpAppFileName
, "AppFileName should be set to something after SVMain!" );
254 if ( pSVData
->maAppData
.mpAppFileName
)
255 return *pSVData
->maAppData
.mpAppFileName
;
258 * provide a fallback for people without initialized vcl here (like setup
259 * in responsefile mode)
261 OUString aAppFileName
;
262 OUString aExeFileName
;
263 osl_getExecutableFile(&aExeFileName
.pData
);
265 // convert path to native file format
266 osl::FileBase::getSystemPathFromFileURL(aExeFileName
, aAppFileName
);
271 sal_uInt16
Application::Exception( sal_uInt16 nError
)
273 switch ( nError
& EXC_MAJORTYPE
)
275 // System has precedence (so do nothing)
284 case EXC_RSCNOTLOADED
:
285 Abort(OUString("Resource not loaded"));
288 Abort(OUString("Unknown Error"));
300 void Application::Abort( const OUString
& rErrorText
)
302 //HACK: Dump core iff --norestore command line argument is given (assuming
303 // this process is run by developers who are interested in cores, vs. end
304 // users who are not):
305 bool dumpCore
= false;
306 sal_uInt16 n
= GetCommandLineParamCount();
307 for (sal_uInt16 i
= 0; i
!= n
; ++i
) {
308 if (GetCommandLineParam(i
) == "--norestore") {
314 SalAbort( rErrorText
, dumpCore
);
317 sal_uLong
Application::GetReservedKeyCodeCount()
319 return ImplReservedKeys::get()->second
;
322 const vcl::KeyCode
* Application::GetReservedKeyCode( sal_uLong i
)
324 if( i
>= GetReservedKeyCodeCount() )
327 return &ImplReservedKeys::get()->first
[i
].mKeyCode
;
330 void Application::Execute()
332 ImplSVData
* pSVData
= ImplGetSVData();
333 pSVData
->maAppData
.mbInAppExecute
= true;
335 while ( !pSVData
->maAppData
.mbAppQuit
)
336 Application::Yield();
338 pSVData
->maAppData
.mbInAppExecute
= false;
341 inline void ImplYield( bool i_bWait
, bool i_bAllEvents
)
343 ImplSVData
* pSVData
= ImplGetSVData();
346 Scheduler::ProcessTaskScheduling(false);
348 pSVData
->maAppData
.mnDispatchLevel
++;
349 // do not wait for events if application was already quit; in that
350 // case only dispatch events already available
351 // do not wait for events either if the app decided that it is too busy for timers
352 // (feature added for the slideshow)
353 pSVData
->mpDefInst
->Yield( i_bWait
&& !pSVData
->maAppData
.mbAppQuit
&& !pSVData
->maAppData
.mbNoYield
, i_bAllEvents
);
354 pSVData
->maAppData
.mnDispatchLevel
--;
356 DBG_TESTSOLARMUTEX(); // must be locked on return from Yield
358 // flush lazy deleted objects
359 if( pSVData
->maAppData
.mnDispatchLevel
== 0 )
360 vcl::LazyDelete::flush();
362 // the system timer events will not necessarily come in non waiting mode
363 // e.g. on OS X; need to trigger timer checks manually
364 if( pSVData
->maAppData
.mbNoYield
)
367 Scheduler::ProcessTaskScheduling(true);
370 // call post yield listeners
371 if( pSVData
->maAppData
.mpPostYieldListeners
)
372 pSVData
->maAppData
.mpPostYieldListeners
->callListeners( NULL
);
375 void Application::Reschedule( bool i_bAllEvents
)
377 ImplYield( false, i_bAllEvents
);
380 void Application::Yield()
382 ImplYield( true, false );
385 IMPL_STATIC_LINK_NOARG( ImplSVAppData
, ImplQuitMsg
)
387 ImplGetSVData()->maAppData
.mbAppQuit
= true;
391 void Application::Quit()
393 Application::PostUserEvent( LINK( NULL
, ImplSVAppData
, ImplQuitMsg
) );
396 comphelper::SolarMutex
& Application::GetSolarMutex()
398 ImplSVData
* pSVData
= ImplGetSVData();
399 return *(pSVData
->mpDefInst
->GetYieldMutex());
402 oslThreadIdentifier
Application::GetMainThreadIdentifier()
404 return ImplGetSVData()->mnMainThreadId
;
407 sal_uLong
Application::ReleaseSolarMutex()
409 ImplSVData
* pSVData
= ImplGetSVData();
410 return pSVData
->mpDefInst
->ReleaseYieldMutex();
413 void Application::AcquireSolarMutex( sal_uLong nCount
)
415 ImplSVData
* pSVData
= ImplGetSVData();
416 pSVData
->mpDefInst
->AcquireYieldMutex( nCount
);
419 bool Application::IsInMain()
421 ImplSVData
* pSVData
= ImplGetSVData();
422 return pSVData
&& pSVData
->maAppData
.mbInAppMain
;
425 bool Application::IsInExecute()
427 return ImplGetSVData()->maAppData
.mbInAppExecute
;
430 bool Application::IsInModalMode()
432 return (ImplGetSVData()->maAppData
.mnModalMode
!= 0);
435 sal_uInt16
Application::GetDispatchLevel()
437 return ImplGetSVData()->maAppData
.mnDispatchLevel
;
440 bool Application::AnyInput( VclInputFlags nType
)
442 return ImplGetSVData()->mpDefInst
->AnyInput( nType
);
445 sal_uInt64
Application::GetLastInputInterval()
447 return (tools::Time::GetSystemTicks()-ImplGetSVData()->maAppData
.mnLastInputTime
);
450 extern int nImplSysDialog
;
452 bool Application::IsUICaptured()
454 ImplSVData
* pSVData
= ImplGetSVData();
456 // If mouse was captured, or if in tracking- or in select-mode of a floatingwindow (e.g. menus
457 // or pulldown toolboxes) another window should be created
459 if ( pSVData
->maWinData
.mpCaptureWin
|| pSVData
->maWinData
.mpTrackWin
||
460 pSVData
->maWinData
.mpFirstFloat
|| nImplSysDialog
)
466 void Application::OverrideSystemSettings( AllSettings
& /*rSettings*/ )
470 void Application::MergeSystemSettings( AllSettings
& rSettings
)
472 vcl::Window
* pWindow
= ImplGetSVData()->maWinData
.mpFirstFrame
;
474 pWindow
= ImplGetDefaultWindow();
477 ImplSVData
* pSVData
= ImplGetSVData();
478 if ( !pSVData
->maAppData
.mbSettingsInit
)
480 // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
481 pWindow
->ImplUpdateGlobalSettings( *pSVData
->maAppData
.mpSettings
);
482 pSVData
->maAppData
.mbSettingsInit
= true;
484 // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
485 pWindow
->ImplUpdateGlobalSettings( rSettings
, false );
489 void Application::SetSettings( const AllSettings
& rSettings
)
491 const SolarMutexGuard aGuard
;
493 ImplSVData
* pSVData
= ImplGetSVData();
494 if ( !pSVData
->maAppData
.mpSettings
)
496 InitSettings(pSVData
);
497 *pSVData
->maAppData
.mpSettings
= rSettings
;
498 ResMgr::SetDefaultLocale( rSettings
.GetUILanguageTag() );
502 AllSettings aOldSettings
= *pSVData
->maAppData
.mpSettings
;
503 if( aOldSettings
.GetUILanguageTag().getLanguageType() != rSettings
.GetUILanguageTag().getLanguageType() &&
506 delete pSVData
->mpResMgr
;
507 pSVData
->mpResMgr
= NULL
;
509 ResMgr::SetDefaultLocale( rSettings
.GetUILanguageTag() );
510 *pSVData
->maAppData
.mpSettings
= rSettings
;
511 AllSettingsFlags nChangeFlags
= aOldSettings
.GetChangeFlags( *pSVData
->maAppData
.mpSettings
);
512 if ( bool(nChangeFlags
) )
514 DataChangedEvent
aDCEvt( DataChangedEventType::SETTINGS
, &aOldSettings
, nChangeFlags
);
516 // notify data change handler
517 ImplCallEventListeners( VCLEVENT_APPLICATION_DATACHANGED
, NULL
, &aDCEvt
);
519 // Update all windows
520 vcl::Window
* pFirstFrame
= pSVData
->maWinData
.mpFirstFrame
;
521 // Reset data that needs to be re-calculated
526 nOldDPIX
= pFirstFrame
->GetDPIX();
527 nOldDPIY
= pFirstFrame
->GetDPIY();
528 vcl::Window::ImplInitAppFontData(pFirstFrame
);
530 vcl::Window
* pFrame
= pFirstFrame
;
533 // restore AppFont cache data
534 pFrame
->mpWindowImpl
->mpFrameData
->meMapUnit
= MAP_PIXEL
;
536 // call UpdateSettings from ClientWindow in order to prevent updating data twice
537 vcl::Window
* pClientWin
= pFrame
;
538 while ( pClientWin
->ImplGetClientWindow() )
539 pClientWin
= pClientWin
->ImplGetClientWindow();
540 pClientWin
->UpdateSettings( rSettings
, true );
542 vcl::Window
* pTempWin
= pFrame
->mpWindowImpl
->mpFrameData
->mpFirstOverlap
;
545 // call UpdateSettings from ClientWindow in order to prevent updating data twice
546 pClientWin
= pTempWin
;
547 while ( pClientWin
->ImplGetClientWindow() )
548 pClientWin
= pClientWin
->ImplGetClientWindow();
549 pClientWin
->UpdateSettings( rSettings
, true );
550 pTempWin
= pTempWin
->mpWindowImpl
->mpNextOverlap
;
553 pFrame
= pFrame
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
556 // if DPI resolution for screen output was changed set the new resolution for all
557 // screen compatible VirDev's
558 pFirstFrame
= pSVData
->maWinData
.mpFirstFrame
;
561 if ( (pFirstFrame
->GetDPIX() != nOldDPIX
) ||
562 (pFirstFrame
->GetDPIY() != nOldDPIY
) )
564 VirtualDevice
* pVirDev
= pSVData
->maGDIData
.mpFirstVirDev
;
567 if ( pVirDev
->mbScreenComp
&&
568 (pVirDev
->GetDPIX() == nOldDPIX
) &&
569 (pVirDev
->GetDPIY() == nOldDPIY
) )
571 pVirDev
->SetDPIX( pFirstFrame
->GetDPIX() );
572 pVirDev
->SetDPIY( pFirstFrame
->GetDPIY() );
573 if ( pVirDev
->IsMapModeEnabled() )
575 MapMode aMapMode
= pVirDev
->GetMapMode();
576 pVirDev
->SetMapMode();
577 pVirDev
->SetMapMode( aMapMode
);
581 pVirDev
= pVirDev
->mpNext
;
589 const AllSettings
& Application::GetSettings()
591 ImplSVData
* pSVData
= ImplGetSVData();
592 if ( !pSVData
->maAppData
.mpSettings
)
594 InitSettings(pSVData
);
597 return *(pSVData
->maAppData
.mpSettings
);
600 void Application::InitSettings(ImplSVData
* pSVData
)
602 assert(!pSVData
->maAppData
.mpSettings
&& "initialization should not happen twice!");
604 pSVData
->maAppData
.mpCfgListener
= new LocaleConfigurationListener
;
605 pSVData
->maAppData
.mpSettings
= new AllSettings();
606 pSVData
->maAppData
.mpSettings
->GetSysLocale().GetOptions().AddListener( pSVData
->maAppData
.mpCfgListener
);
609 void Application::NotifyAllWindows( DataChangedEvent
& rDCEvt
)
611 ImplSVData
* pSVData
= ImplGetSVData();
612 vcl::Window
* pFrame
= pSVData
->maWinData
.mpFirstFrame
;
615 pFrame
->NotifyAllChildren( rDCEvt
);
617 vcl::Window
* pSysWin
= pFrame
->mpWindowImpl
->mpFrameData
->mpFirstOverlap
;
620 pSysWin
->NotifyAllChildren( rDCEvt
);
621 pSysWin
= pSysWin
->mpWindowImpl
->mpNextOverlap
;
624 pFrame
= pFrame
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
628 void Application::ImplCallEventListeners( sal_uLong nEvent
, vcl::Window
*pWin
, void* pData
)
630 ImplSVData
* pSVData
= ImplGetSVData();
631 VclWindowEvent
aEvent( pWin
, nEvent
, pData
);
633 if ( pSVData
->maAppData
.mpEventListeners
)
634 pSVData
->maAppData
.mpEventListeners
->Call( &aEvent
);
637 void Application::ImplCallEventListeners( VclSimpleEvent
* pEvent
)
639 ImplSVData
* pSVData
= ImplGetSVData();
641 if ( pSVData
->maAppData
.mpEventListeners
)
642 pSVData
->maAppData
.mpEventListeners
->Call( pEvent
);
645 void Application::AddEventListener( const Link
<>& rEventListener
)
647 ImplSVData
* pSVData
= ImplGetSVData();
648 if( !pSVData
->maAppData
.mpEventListeners
)
649 pSVData
->maAppData
.mpEventListeners
= new VclEventListeners
;
650 pSVData
->maAppData
.mpEventListeners
->addListener( rEventListener
);
653 void Application::RemoveEventListener( const Link
<>& rEventListener
)
655 ImplSVData
* pSVData
= ImplGetSVData();
656 if( pSVData
->maAppData
.mpEventListeners
)
657 pSVData
->maAppData
.mpEventListeners
->removeListener( rEventListener
);
660 void Application::AddKeyListener( const Link
<>& rKeyListener
)
662 ImplSVData
* pSVData
= ImplGetSVData();
663 if( !pSVData
->maAppData
.mpKeyListeners
)
664 pSVData
->maAppData
.mpKeyListeners
= new VclEventListeners
;
665 pSVData
->maAppData
.mpKeyListeners
->addListener( rKeyListener
);
668 void Application::RemoveKeyListener( const Link
<>& rKeyListener
)
670 ImplSVData
* pSVData
= ImplGetSVData();
671 if( pSVData
->maAppData
.mpKeyListeners
)
672 pSVData
->maAppData
.mpKeyListeners
->removeListener( rKeyListener
);
675 bool Application::HandleKey( sal_uLong nEvent
, vcl::Window
*pWin
, KeyEvent
* pKeyEvent
)
677 // let listeners process the key event
678 VclWindowEvent
aEvent( pWin
, nEvent
, (void *) pKeyEvent
);
680 ImplSVData
* pSVData
= ImplGetSVData();
681 bool bProcessed
= false;
683 if ( pSVData
->maAppData
.mpKeyListeners
)
684 bProcessed
= pSVData
->maAppData
.mpKeyListeners
->Process( &aEvent
);
689 ImplSVEvent
* Application::PostKeyEvent( sal_uLong nEvent
, vcl::Window
*pWin
, KeyEvent
* pKeyEvent
)
691 const SolarMutexGuard aGuard
;
692 ImplSVEvent
* nEventId
= 0;
694 if( pWin
&& pKeyEvent
)
696 ImplPostEventData
* pPostEventData
= new ImplPostEventData( nEvent
, pWin
, *pKeyEvent
);
698 nEventId
= PostUserEvent(
699 LINK( NULL
, Application
, PostEventHandler
),
704 pPostEventData
->mnEventId
= nEventId
;
705 aPostedEventList
.push_back( ImplPostEventPair( pWin
, pPostEventData
) );
708 delete pPostEventData
;
714 ImplSVEvent
* Application::PostMouseEvent( sal_uLong nEvent
, vcl::Window
*pWin
, MouseEvent
* pMouseEvent
)
716 const SolarMutexGuard aGuard
;
717 ImplSVEvent
* nEventId
= 0;
719 if( pWin
&& pMouseEvent
)
721 Point
aTransformedPos( pMouseEvent
->GetPosPixel() );
723 aTransformedPos
.X() += pWin
->GetOutOffXPixel();
724 aTransformedPos
.Y() += pWin
->GetOutOffYPixel();
726 const MouseEvent
aTransformedEvent( aTransformedPos
, pMouseEvent
->GetClicks(), pMouseEvent
->GetMode(),
727 pMouseEvent
->GetButtons(), pMouseEvent
->GetModifier() );
729 ImplPostEventData
* pPostEventData
= new ImplPostEventData( nEvent
, pWin
, aTransformedEvent
);
731 nEventId
= PostUserEvent(
732 LINK( NULL
, Application
, PostEventHandler
),
737 pPostEventData
->mnEventId
= nEventId
;
738 aPostedEventList
.push_back( ImplPostEventPair( pWin
, pPostEventData
) );
741 delete pPostEventData
;
747 #if !HAVE_FEATURE_DESKTOP
749 ImplSVEvent
* Application::PostZoomEvent( sal_uLong nEvent
, vcl::Window
*pWin
, ZoomEvent
* pZoomEvent
)
751 const SolarMutexGuard aGuard
;
752 ImplSVEvent
* nEventId
= 0;
754 if( pWin
&& pZoomEvent
)
756 Point
aTransformedPos( pZoomEvent
->GetCenter() );
758 aTransformedPos
.X() += pWin
->GetOutOffXPixel();
759 aTransformedPos
.Y() += pWin
->GetOutOffYPixel();
761 const ZoomEvent
aTransformedEvent( aTransformedPos
, pZoomEvent
->GetScale() );
763 ImplPostEventData
* pPostEventData
= new ImplPostEventData( nEvent
, pWin
, aTransformedEvent
);
765 nEventId
= PostUserEvent(
766 LINK( NULL
, Application
, PostEventHandler
),
771 pPostEventData
->mnEventId
= nEventId
;
772 aPostedEventList
.push_back( ImplPostEventPair( pWin
, pPostEventData
) );
775 delete pPostEventData
;
781 ImplSVEvent
* Application::PostScrollEvent( sal_uLong nEvent
, vcl::Window
*pWin
, ScrollEvent
* pScrollEvent
)
783 const SolarMutexGuard aGuard
;
784 ImplSVEvent
* nEventId
= 0;
786 if( pWin
&& pScrollEvent
)
788 ImplPostEventData
* pPostEventData
= new ImplPostEventData( nEvent
, pWin
, *pScrollEvent
);
790 nEventId
= PostUserEvent(
791 LINK( NULL
, Application
, PostEventHandler
),
796 pPostEventData
->mnEventId
= nEventId
;
797 aPostedEventList
.push_back( ImplPostEventPair( pWin
, pPostEventData
) );
800 delete pPostEventData
;
806 #endif // !HAVE_FEATURE_DESKTOP
808 IMPL_STATIC_LINK( Application
, PostEventHandler
, void*, pCallData
)
810 const SolarMutexGuard aGuard
;
811 ImplPostEventData
* pData
= static_cast< ImplPostEventData
* >( pCallData
);
812 const void* pEventData
;
814 ImplSVEvent
* const nEventId
= pData
->mnEventId
;
816 switch( pData
->mnEvent
)
818 case VCLEVENT_WINDOW_MOUSEMOVE
:
819 nEvent
= SALEVENT_EXTERNALMOUSEMOVE
;
820 pEventData
= &pData
->maMouseEvent
;
823 case VCLEVENT_WINDOW_MOUSEBUTTONDOWN
:
824 nEvent
= SALEVENT_EXTERNALMOUSEBUTTONDOWN
;
825 pEventData
= &pData
->maMouseEvent
;
828 case VCLEVENT_WINDOW_MOUSEBUTTONUP
:
829 nEvent
= SALEVENT_EXTERNALMOUSEBUTTONUP
;
830 pEventData
= &pData
->maMouseEvent
;
833 case VCLEVENT_WINDOW_KEYINPUT
:
834 nEvent
= SALEVENT_EXTERNALKEYINPUT
;
835 pEventData
= &pData
->maKeyEvent
;
838 case VCLEVENT_WINDOW_KEYUP
:
839 nEvent
= SALEVENT_EXTERNALKEYUP
;
840 pEventData
= &pData
->maKeyEvent
;
843 case VCLEVENT_WINDOW_ZOOM
:
844 nEvent
= SALEVENT_EXTERNALZOOM
;
845 pEventData
= &pData
->maZoomEvent
;
848 case VCLEVENT_WINDOW_SCROLL
:
849 nEvent
= SALEVENT_EXTERNALSCROLL
;
850 pEventData
= &pData
->maScrollEvent
;
859 if( pData
->mpWin
&& pData
->mpWin
.get()->mpWindowImpl
->mpFrameWindow
.get() && pEventData
)
860 ImplWindowFrameProc( pData
->mpWin
.get()->mpWindowImpl
->mpFrameWindow
.get(), NULL
, (sal_uInt16
) nEvent
, pEventData
);
862 // remove this event from list of posted events, watch for destruction of internal data
863 ::std::list
< ImplPostEventPair
>::iterator
aIter( aPostedEventList
.begin() );
865 while( aIter
!= aPostedEventList
.end() )
867 if( nEventId
== (*aIter
).second
->mnEventId
)
869 delete (*aIter
).second
;
870 aIter
= aPostedEventList
.erase( aIter
);
879 void Application::RemoveMouseAndKeyEvents( vcl::Window
* pWin
)
881 const SolarMutexGuard aGuard
;
883 // remove all events for specific window, watch for destruction of internal data
884 ::std::list
< ImplPostEventPair
>::iterator
aIter( aPostedEventList
.begin() );
886 while( aIter
!= aPostedEventList
.end() )
888 if( pWin
== (*aIter
).first
)
890 if( (*aIter
).second
->mnEventId
)
891 RemoveUserEvent( (*aIter
).second
->mnEventId
);
893 delete (*aIter
).second
;
894 aIter
= aPostedEventList
.erase( aIter
);
901 ImplSVEvent
* Application::PostUserEvent( const Link
<>& rLink
, void* pCaller
,
902 bool bReferenceLink
)
904 ImplSVEvent
* pSVEvent
= new ImplSVEvent
;
905 pSVEvent
->mpData
= pCaller
;
906 pSVEvent
->mpLink
= new Link
<>( rLink
);
907 pSVEvent
->mpWindow
= NULL
;
908 pSVEvent
->mbCall
= true;
911 SolarMutexGuard aGuard
;
912 // Double check that this is indeed a vcl::Window instance.
913 assert(dynamic_cast<vcl::Window
*>(
914 static_cast<vcl::Window
*>(rLink
.GetInstance())) ==
915 static_cast<vcl::Window
*>(rLink
.GetInstance()));
916 pSVEvent
->mpInstanceRef
= static_cast<vcl::Window
*>(rLink
.GetInstance());
919 vcl::Window
* pDefWindow
= ImplGetDefaultWindow();
920 if ( pDefWindow
== 0 || !pDefWindow
->ImplGetFrame()->PostEvent( pSVEvent
) )
922 delete pSVEvent
->mpLink
;
929 void Application::RemoveUserEvent( ImplSVEvent
* nUserEvent
)
933 DBG_ASSERT( !nUserEvent
->mpWindow
,
934 "Application::RemoveUserEvent(): Event is send to a window" );
935 DBG_ASSERT( nUserEvent
->mbCall
,
936 "Application::RemoveUserEvent(): Event is already removed" );
938 if ( nUserEvent
->mpWindow
)
940 if( ! nUserEvent
->maDelData
.IsDead() )
941 nUserEvent
->mpWindow
->ImplRemoveDel( &(nUserEvent
->maDelData
) );
942 nUserEvent
->mpWindow
.clear();
944 nUserEvent
->mpInstanceRef
.clear();
945 nUserEvent
->mbCall
= false;
949 bool Application::InsertIdleHdl( const Link
<>& rLink
, sal_uInt16 nPrio
)
951 ImplSVData
* pSVData
= ImplGetSVData();
953 // create if does not exist
954 if ( !pSVData
->maAppData
.mpIdleMgr
)
955 pSVData
->maAppData
.mpIdleMgr
= new ImplIdleMgr
;
957 return pSVData
->maAppData
.mpIdleMgr
->InsertIdleHdl( rLink
, nPrio
);
960 void Application::RemoveIdleHdl( const Link
<>& rLink
)
962 ImplSVData
* pSVData
= ImplGetSVData();
964 if ( pSVData
->maAppData
.mpIdleMgr
)
965 pSVData
->maAppData
.mpIdleMgr
->RemoveIdleHdl( rLink
);
968 void Application::EnableNoYieldMode()
970 ImplSVData
* pSVData
= ImplGetSVData();
971 pSVData
->maAppData
.mbNoYield
= true;
974 void Application::DisableNoYieldMode()
976 ImplSVData
* pSVData
= ImplGetSVData();
977 pSVData
->maAppData
.mbNoYield
= false;
980 void Application::AddPostYieldListener( const Link
<>& i_rListener
)
982 ImplSVData
* pSVData
= ImplGetSVData();
983 if( ! pSVData
->maAppData
.mpPostYieldListeners
)
984 pSVData
->maAppData
.mpPostYieldListeners
= new VclEventListeners2();
985 pSVData
->maAppData
.mpPostYieldListeners
->addListener( i_rListener
);
988 void Application::RemovePostYieldListener( const Link
<>& i_rListener
)
990 ImplSVData
* pSVData
= ImplGetSVData();
991 if( pSVData
->maAppData
.mpPostYieldListeners
)
992 pSVData
->maAppData
.mpPostYieldListeners
->removeListener( i_rListener
);
995 WorkWindow
* Application::GetAppWindow()
997 return ImplGetSVData()->maWinData
.mpAppWin
;
1000 vcl::Window
* Application::GetFocusWindow()
1002 return ImplGetSVData()->maWinData
.mpFocusWin
;
1005 OutputDevice
* Application::GetDefaultDevice()
1007 return ImplGetDefaultWindow();
1010 vcl::Window
* Application::GetFirstTopLevelWindow()
1012 ImplSVData
* pSVData
= ImplGetSVData();
1013 return pSVData
->maWinData
.mpFirstFrame
;
1016 vcl::Window
* Application::GetNextTopLevelWindow( vcl::Window
* pWindow
)
1018 return pWindow
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
1021 long Application::GetTopWindowCount()
1024 ImplSVData
* pSVData
= ImplGetSVData();
1025 vcl::Window
*pWin
= pSVData
? pSVData
->maWinData
.mpFirstFrame
.get() : NULL
;
1028 if( pWin
->ImplGetWindow()->IsTopWindow() )
1030 pWin
= pWin
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
1035 vcl::Window
* Application::GetTopWindow( long nIndex
)
1038 ImplSVData
* pSVData
= ImplGetSVData();
1039 vcl::Window
*pWin
= pSVData
? pSVData
->maWinData
.mpFirstFrame
.get() : NULL
;
1042 if( pWin
->ImplGetWindow()->IsTopWindow() )
1044 if( nIdx
== nIndex
)
1045 return pWin
->ImplGetWindow();
1049 pWin
= pWin
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
1054 vcl::Window
* Application::GetActiveTopWindow()
1056 vcl::Window
*pWin
= ImplGetSVData()->maWinData
.mpFocusWin
;
1059 if( pWin
->IsTopWindow() )
1061 pWin
= pWin
->mpWindowImpl
->mpParent
;
1066 void Application::SetAppName( const OUString
& rUniqueName
)
1068 ImplSVData
* pSVData
= ImplGetSVData();
1070 // create if does not exist
1071 if ( !pSVData
->maAppData
.mpAppName
)
1072 pSVData
->maAppData
.mpAppName
= new OUString( rUniqueName
);
1074 *(pSVData
->maAppData
.mpAppName
) = rUniqueName
;
1077 OUString
Application::GetAppName()
1079 ImplSVData
* pSVData
= ImplGetSVData();
1080 if ( pSVData
->maAppData
.mpAppName
)
1081 return *(pSVData
->maAppData
.mpAppName
);
1086 void Application::SetDisplayName( const OUString
& rName
)
1088 ImplSVData
* pSVData
= ImplGetSVData();
1090 // create if does not exist
1091 if ( !pSVData
->maAppData
.mpDisplayName
)
1092 pSVData
->maAppData
.mpDisplayName
= new OUString( rName
);
1094 *(pSVData
->maAppData
.mpDisplayName
) = rName
;
1097 OUString
Application::GetDisplayName()
1099 ImplSVData
* pSVData
= ImplGetSVData();
1100 if ( pSVData
->maAppData
.mpDisplayName
)
1101 return *(pSVData
->maAppData
.mpDisplayName
);
1102 else if ( pSVData
->maWinData
.mpAppWin
)
1103 return pSVData
->maWinData
.mpAppWin
->GetText();
1105 return OUString("");
1108 unsigned int Application::GetScreenCount()
1110 SalSystem
* pSys
= ImplGetSalSystem();
1111 return pSys
? pSys
->GetDisplayScreenCount() : 0;
1114 bool Application::IsUnifiedDisplay()
1116 SalSystem
* pSys
= ImplGetSalSystem();
1117 return pSys
== nullptr || pSys
->IsUnifiedDisplay();
1120 unsigned int Application::GetDisplayBuiltInScreen()
1122 SalSystem
* pSys
= ImplGetSalSystem();
1123 return pSys
? pSys
->GetDisplayBuiltInScreen() : 0;
1126 unsigned int Application::GetDisplayExternalScreen()
1128 // This is really unpleasant, in theory we could have multiple
1129 // external displays etc.
1131 switch (GetDisplayBuiltInScreen())
1140 // When the built-in display is neither 0 nor 1
1141 // then place the full-screen presentation on the
1142 // first available screen.
1149 Rectangle
Application::GetScreenPosSizePixel( unsigned int nScreen
)
1151 SalSystem
* pSys
= ImplGetSalSystem();
1152 return pSys
? pSys
->GetDisplayScreenPosSizePixel( nScreen
) : Rectangle();
1156 unsigned long calcDistSquare( const Point
& i_rPoint
, const Rectangle
& i_rRect
)
1158 const Point
aRectCenter( (i_rRect
.Left() + i_rRect
.Right())/2,
1159 (i_rRect
.Top() + i_rRect
.Bottom())/ 2 );
1160 const long nDX
= aRectCenter
.X() - i_rPoint
.X();
1161 const long nDY
= aRectCenter
.Y() - i_rPoint
.Y();
1162 return nDX
*nDX
+ nDY
*nDY
;
1166 unsigned int Application::GetBestScreen( const Rectangle
& i_rRect
)
1168 if( !IsUnifiedDisplay() )
1169 return GetDisplayBuiltInScreen();
1171 const unsigned int nScreens
= GetScreenCount();
1172 unsigned int nBestMatchScreen
= 0;
1173 unsigned long nOverlap
= 0;
1174 for( unsigned int i
= 0; i
< nScreens
; i
++ )
1176 const Rectangle
aCurScreenRect( GetScreenPosSizePixel( i
) );
1177 // if a screen contains the rectangle completely it is obviously the best screen
1178 if( aCurScreenRect
.IsInside( i_rRect
) )
1180 // next the screen which contains most of the area of the rect is the best
1181 Rectangle
aIntersection( aCurScreenRect
.GetIntersection( i_rRect
) );
1182 if( ! aIntersection
.IsEmpty() )
1184 const unsigned long nCurOverlap( aIntersection
.GetWidth() * aIntersection
.GetHeight() );
1185 if( nCurOverlap
> nOverlap
)
1187 nOverlap
= nCurOverlap
;
1188 nBestMatchScreen
= i
;
1193 return nBestMatchScreen
;
1195 // finally the screen which center is nearest to the rect is the best
1196 const Point
aCenter( (i_rRect
.Left() + i_rRect
.Right())/2,
1197 (i_rRect
.Top() + i_rRect
.Bottom())/2 );
1198 unsigned long nDist
= ULONG_MAX
;
1199 for( unsigned int i
= 0; i
< nScreens
; i
++ )
1201 const Rectangle
aCurScreenRect( GetScreenPosSizePixel( i
) );
1202 const unsigned long nCurDist( calcDistSquare( aCenter
, aCurScreenRect
) );
1203 if( nCurDist
< nDist
)
1205 nBestMatchScreen
= i
;
1209 return nBestMatchScreen
;
1212 bool Application::InsertAccel( Accelerator
* pAccel
)
1214 ImplSVData
* pSVData
= ImplGetSVData();
1216 if ( !pSVData
->maAppData
.mpAccelMgr
)
1217 pSVData
->maAppData
.mpAccelMgr
= new ImplAccelManager();
1218 return pSVData
->maAppData
.mpAccelMgr
->InsertAccel( pAccel
);
1221 void Application::RemoveAccel( Accelerator
* pAccel
)
1223 ImplSVData
* pSVData
= ImplGetSVData();
1225 if ( pSVData
->maAppData
.mpAccelMgr
)
1226 pSVData
->maAppData
.mpAccelMgr
->RemoveAccel( pAccel
);
1229 void Application::SetHelp( Help
* pHelp
)
1231 ImplGetSVData()->maAppData
.mpHelp
= pHelp
;
1234 Help
* Application::GetHelp()
1236 return ImplGetSVData()->maAppData
.mpHelp
;
1239 void Application::EnableAutoHelpId( bool bEnabled
)
1241 ImplGetSVData()->maHelpData
.mbAutoHelpId
= bEnabled
;
1244 bool Application::IsAutoHelpIdEnabled()
1246 return ImplGetSVData()->maHelpData
.mbAutoHelpId
;
1249 void Application::EnableAutoMnemonic( bool bEnabled
)
1251 AllSettings aSettings
= GetSettings();
1252 StyleSettings aStyle
= aSettings
.GetStyleSettings();
1253 aStyle
.SetAutoMnemonic( bEnabled
);
1254 aSettings
.SetStyleSettings( aStyle
);
1255 SetSettings( aSettings
);
1258 bool Application::IsAutoMnemonicEnabled()
1260 return GetSettings().GetStyleSettings().GetAutoMnemonic();
1263 void Application::SetDialogScaleX( short nScale
)
1265 ImplSVData
* pSVData
= ImplGetSVData();
1266 pSVData
->maAppData
.mnDialogScaleX
= nScale
;
1267 pSVData
->maGDIData
.mnAppFontX
= pSVData
->maGDIData
.mnRealAppFontX
;
1269 pSVData
->maGDIData
.mnAppFontX
+= (pSVData
->maGDIData
.mnAppFontX
*nScale
)/100;
1272 void Application::SetDefDialogParent( vcl::Window
* pWindow
)
1274 ImplGetSVData()->maWinData
.mpDefDialogParent
= pWindow
;
1277 vcl::Window
* Application::GetDefDialogParent()
1279 ImplSVData
* pSVData
= ImplGetSVData();
1280 // #103442# find some useful dialog parent if there
1281 // was no default set
1282 // NOTE: currently even the default is not used
1283 if( false && pSVData
->maWinData
.mpDefDialogParent
.get() != NULL
)
1284 return pSVData
->maWinData
.mpDefDialogParent
;
1287 // always use the topmost parent of the candidate
1288 // window to avoid using dialogs or floaters
1289 // as DefDialogParent
1291 // current focus frame
1292 vcl::Window
*pWin
= NULL
;
1293 if( (pWin
= pSVData
->maWinData
.mpFocusWin
) != NULL
)
1295 while( pWin
->mpWindowImpl
&& pWin
->mpWindowImpl
->mpParent
)
1296 pWin
= pWin
->mpWindowImpl
->mpParent
;
1298 // check for corrupted window hierarchy, #122232#, may be we now crash somewhere else
1299 if( !pWin
->mpWindowImpl
)
1301 OSL_FAIL( "Window hierarchy corrupted!" );
1302 pSVData
->maWinData
.mpFocusWin
= NULL
; // avoid further access
1306 if( (pWin
->mpWindowImpl
->mnStyle
& WB_INTROWIN
) == 0 )
1308 return pWin
->mpWindowImpl
->mpFrameWindow
->ImplGetWindow();
1311 // last active application frame
1312 if( NULL
!= (pWin
= pSVData
->maWinData
.mpActiveApplicationFrame
) )
1314 return pWin
->mpWindowImpl
->mpFrameWindow
->ImplGetWindow();
1318 // first visible top window (may be totally wrong....)
1319 pWin
= pSVData
->maWinData
.mpFirstFrame
;
1322 if( pWin
->ImplGetWindow()->IsTopWindow() &&
1323 pWin
->mpWindowImpl
->mbReallyVisible
&&
1324 (pWin
->mpWindowImpl
->mnStyle
& WB_INTROWIN
) == 0
1327 while( pWin
->mpWindowImpl
->mpParent
)
1328 pWin
= pWin
->mpWindowImpl
->mpParent
;
1329 return pWin
->mpWindowImpl
->mpFrameWindow
->ImplGetWindow();
1331 pWin
= pWin
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
1339 Application::DialogCancelMode
Application::GetDialogCancelMode()
1341 return ImplGetSVData()->maAppData
.meDialogCancel
;
1344 void Application::SetDialogCancelMode( DialogCancelMode mode
)
1346 ImplGetSVData()->maAppData
.meDialogCancel
= mode
;
1349 bool Application::IsDialogCancelEnabled()
1351 return ImplGetSVData()->maAppData
.meDialogCancel
!= DIALOG_CANCEL_OFF
;
1354 void Application::SetSystemWindowMode( SystemWindowFlags nMode
)
1356 ImplGetSVData()->maAppData
.mnSysWinMode
= nMode
;
1359 SystemWindowFlags
Application::GetSystemWindowMode()
1361 return ImplGetSVData()->maAppData
.mnSysWinMode
;
1364 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
> Application::GetVCLToolkit()
1366 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
> xT
;
1367 UnoWrapperBase
* pWrapper
= Application::GetUnoWrapper( true );
1369 xT
= pWrapper
->GetVCLToolkit();
1373 #ifdef DISABLE_DYNLOADING
1375 extern "C" { UnoWrapperBase
* CreateUnoWrapper(); }
1379 extern "C" { static void SAL_CALL
thisModule() {} }
1383 UnoWrapperBase
* Application::GetUnoWrapper( bool bCreateIfNotExist
)
1385 ImplSVData
* pSVData
= ImplGetSVData();
1386 static bool bAlreadyTriedToCreate
= false;
1387 if ( !pSVData
->mpUnoWrapper
&& bCreateIfNotExist
&& !bAlreadyTriedToCreate
)
1389 #ifndef DISABLE_DYNLOADING
1391 OUString
aLibName(TK_DLL_NAME
);
1392 aTkLib
.loadRelative(&thisModule
, aLibName
, SAL_LOADMODULE_DEFAULT
);
1395 FN_TkCreateUnoWrapper fnCreateWrapper
= reinterpret_cast<FN_TkCreateUnoWrapper
>(aTkLib
.getFunctionSymbol("CreateUnoWrapper"));
1396 if ( fnCreateWrapper
)
1398 pSVData
->mpUnoWrapper
= fnCreateWrapper();
1402 DBG_ASSERT( pSVData
->mpUnoWrapper
, "UnoWrapper could not be created!" );
1404 pSVData
->mpUnoWrapper
= CreateUnoWrapper();
1406 bAlreadyTriedToCreate
= true;
1408 return pSVData
->mpUnoWrapper
;
1411 void Application::SetUnoWrapper( UnoWrapperBase
* pWrapper
)
1413 ImplSVData
* pSVData
= ImplGetSVData();
1414 DBG_ASSERT( !pSVData
->mpUnoWrapper
, "SetUnoWrapper: Wrapper already exists" );
1415 pSVData
->mpUnoWrapper
= pWrapper
;
1418 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDisplayConnection
> Application::GetDisplayConnection()
1420 ImplSVData
* pSVData
= ImplGetSVData();
1422 if( !pSVData
->mxDisplayConnection
.is() )
1424 pSVData
->mxDisplayConnection
.set( new vcl::DisplayConnection
);
1425 pSVData
->mxDisplayConnection
->start();
1428 return pSVData
->mxDisplayConnection
.get();
1431 void Application::SetFilterHdl( const Link
<>& rLink
)
1433 ImplGetSVData()->maGDIData
.mpGrfConverter
->SetFilterHdl( rLink
);
1436 bool ImplCallHotKey( const vcl::KeyCode
& rKeyCode
)
1438 ImplSVData
* pSVData
= ImplGetSVData();
1439 ImplHotKey
* pHotKeyData
= pSVData
->maAppData
.mpFirstHotKey
;
1440 while ( pHotKeyData
)
1442 if ( pHotKeyData
->maKeyCode
== rKeyCode
)
1444 pHotKeyData
->maLink
.Call( pHotKeyData
->mpUserData
);
1448 pHotKeyData
= pHotKeyData
->mpNext
;
1454 void ImplFreeHotKeyData()
1456 ImplSVData
* pSVData
= ImplGetSVData();
1457 ImplHotKey
* pTempHotKeyData
;
1458 ImplHotKey
* pHotKeyData
= pSVData
->maAppData
.mpFirstHotKey
;
1459 while ( pHotKeyData
)
1461 pTempHotKeyData
= pHotKeyData
->mpNext
;
1463 pHotKeyData
= pTempHotKeyData
;
1466 pSVData
->maAppData
.mpFirstHotKey
= NULL
;
1469 void ImplFreeEventHookData()
1471 ImplSVData
* pSVData
= ImplGetSVData();
1472 ImplEventHook
* pTempEventHookData
;
1473 ImplEventHook
* pEventHookData
= pSVData
->maAppData
.mpFirstEventHook
;
1474 while ( pEventHookData
)
1476 pTempEventHookData
= pEventHookData
->mpNext
;
1477 delete pEventHookData
;
1478 pEventHookData
= pTempEventHookData
;
1481 pSVData
->maAppData
.mpFirstEventHook
= NULL
;
1484 long Application::CallEventHooks( NotifyEvent
& rEvt
)
1486 ImplSVData
* pSVData
= ImplGetSVData();
1488 ImplEventHook
* pTempEventHookData
;
1489 ImplEventHook
* pEventHookData
= pSVData
->maAppData
.mpFirstEventHook
;
1490 while ( pEventHookData
)
1492 pTempEventHookData
= pEventHookData
->mpNext
;
1493 nRet
= pEventHookData
->mpProc( rEvt
, pEventHookData
->mpUserData
);
1496 pEventHookData
= pTempEventHookData
;
1502 const LocaleDataWrapper
& Application::GetAppLocaleDataWrapper()
1504 return GetSettings().GetLocaleDataWrapper();
1507 void Application::EnableHeadlessMode( bool dialogsAreFatal
)
1509 SetDialogCancelMode(
1510 dialogsAreFatal
? DIALOG_CANCEL_FATAL
: DIALOG_CANCEL_SILENT
);
1513 bool Application::IsHeadlessModeEnabled()
1515 return IsDialogCancelEnabled();
1518 static bool bConsoleOnly
= false;
1520 bool Application::IsConsoleOnly()
1522 return bConsoleOnly
;
1525 void Application::EnableConsoleOnly()
1527 EnableHeadlessMode(true);
1528 bConsoleOnly
= true;
1531 void Application::ShowNativeErrorBox(const OUString
& sTitle
,
1532 const OUString
& sMessage
)
1534 int btn
= ImplGetSalSystem()->ShowNativeMessageBox (
1537 SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK
,
1538 SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK
, false);
1539 if (btn
!= SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK
) {
1540 OSL_TRACE("ShowNativeMessageBox returned %d", btn
);
1544 bool Application::CanToggleImeStatusWindow()
1546 ImplSVData
* pSVData
= ImplGetSVData();
1547 if( ! pSVData
->mpImeStatus
)
1548 pSVData
->mpImeStatus
= pSVData
->mpDefInst
->CreateI18NImeStatus();
1549 return pSVData
->mpImeStatus
->canToggle();
1552 void Application::ShowImeStatusWindow(bool bShow
)
1554 ImplGetSVData()->maAppData
.meShowImeStatusWindow
= bShow
1555 ? ImplSVAppData::ImeStatusWindowMode_SHOW
1556 : ImplSVAppData::ImeStatusWindowMode_HIDE
;
1558 ImplSVData
* pSVData
= ImplGetSVData();
1559 if( ! pSVData
->mpImeStatus
)
1560 pSVData
->mpImeStatus
= pSVData
->mpDefInst
->CreateI18NImeStatus();
1561 pSVData
->mpImeStatus
->toggle();
1564 bool Application::GetShowImeStatusWindowDefault()
1566 rtl_TextEncodingInfo aInfo
;
1567 aInfo
.StructSize
= sizeof aInfo
;
1568 return rtl_getTextEncodingInfo(osl_getThreadTextEncoding(), &aInfo
)
1569 && aInfo
.MaximumCharSize
> 1;
1572 const OUString
& Application::GetDesktopEnvironment()
1574 if (IsHeadlessModeEnabled())
1576 static OUString
aNone("none");
1580 return SalGetDesktopEnvironment();
1583 void Application::AddToRecentDocumentList(const OUString
& rFileUrl
, const OUString
& rMimeType
, const OUString
& rDocumentService
)
1585 ImplSVData
* pSVData
= ImplGetSVData();
1586 pSVData
->mpDefInst
->AddToRecentDocumentList(rFileUrl
, rMimeType
, rDocumentService
);
1589 bool InitAccessBridge()
1591 // Disable MSAA bridge on UNIX
1595 bool bRet
= ImplInitAccessBridge();
1599 // disable accessibility if the user chooses to continue
1600 AllSettings aSettings
= Application::GetSettings();
1601 MiscSettings aMisc
= aSettings
.GetMiscSettings();
1602 aMisc
.SetEnableATToolSupport( false );
1603 aSettings
.SetMiscSettings( aMisc
);
1604 Application::SetSettings( aSettings
);
1610 // MT: AppEvent was in oldsv.cxx, but is still needed...
1611 void Application::AppEvent( const ApplicationEvent
& /*rAppEvent*/ )
1615 bool Application::hasNativeFileSelection()
1617 ImplSVData
* pSVData
= ImplGetSVData();
1618 return pSVData
->mpDefInst
->hasNativeFileSelection();
1621 Reference
< ui::dialogs::XFilePicker2
>
1622 Application::createFilePicker( const Reference
< uno::XComponentContext
>& xSM
)
1624 ImplSVData
* pSVData
= ImplGetSVData();
1625 return pSVData
->mpDefInst
->createFilePicker( xSM
);
1628 Reference
< ui::dialogs::XFolderPicker2
>
1629 Application::createFolderPicker( const Reference
< uno::XComponentContext
>& xSM
)
1631 ImplSVData
* pSVData
= ImplGetSVData();
1632 return pSVData
->mpDefInst
->createFolderPicker( xSM
);
1635 void Application::setDeInitHook(Link
<> const & hook
) {
1636 ImplSVData
* pSVData
= ImplGetSVData();
1637 assert(!pSVData
->maDeInitHook
.IsSet());
1638 pSVData
->maDeInitHook
= hook
;
1639 // Fake this for VCLXToolkit ctor instantiated from
1640 // postprocess/CppunitTest_services.mk:
1641 pSVData
->maAppData
.mbInAppMain
= true;
1644 ImplDelData::ImplDelData( vcl::Window
* pWindow
) :
1649 if( pWindow
) AttachToWindow( pWindow
);
1652 // helper method to allow inline constructor even for pWindow!=NULL case
1653 void ImplDelData::AttachToWindow( const vcl::Window
* pWindow
)
1657 if( pWindow
->IsDisposed() )
1660 const_cast<vcl::Window
*>(pWindow
)->ImplAddDel( this );
1664 // define dtor for ImplDelData
1665 ImplDelData::~ImplDelData()
1667 // #112873# auto remove of ImplDelData
1668 // due to this code actively calling ImplRemoveDel() is not mandatory anymore
1669 if( !mbDel
&& mpWindow
)
1671 // the window still exists but we were not removed
1672 const_cast<vcl::Window
*>(mpWindow
.get())->ImplRemoveDel( this );
1678 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */