1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svapp.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
37 #include <vcl/salinst.hxx>
38 #include <vcl/salframe.hxx>
39 #include <vcl/salsys.hxx>
40 #ifndef _VOS_PROCESS_HXX
41 #include <vos/process.hxx>
43 #ifndef _VOS_MUTEX_HXX
44 #include <vos/mutex.hxx>
46 #include <tools/tools.h>
47 #include <tools/debug.hxx>
48 #include <tools/time.hxx>
49 #include <i18npool/mslangid.hxx>
50 #include <vcl/svdata.hxx>
51 #include <vcl/settings.hxx>
53 #include <vcl/accmgr.hxx>
55 #ifndef _SV_KEYCOD_HXX
56 #include <vcl/keycod.hxx>
58 #include <vcl/event.hxx>
59 #include <vcl/virdev.hxx>
60 #include <vcl/windata.hxx>
61 #include <vcl/window.h>
62 #include <vcl/wrkwin.hxx>
63 #include <vcl/idlemgr.hxx>
64 #include <vcl/svapp.hxx>
65 #include <vcl/cvtgrf.hxx>
66 #include <vcl/unowrap.hxx>
67 #include <vcl/xconnection.hxx>
69 #include <vcl/svids.hrc>
71 #include <vcl/timer.hxx>
73 #include <vcl/unohelp.hxx>
75 #include <com/sun/star/uno/Reference.h>
76 #include <com/sun/star/awt/XToolkit.hpp>
77 #include <com/sun/star/uno/XNamingService.hpp>
78 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
79 #include <comphelper/processfactory.hxx>
81 #include <osl/module.h>
82 #include <osl/file.hxx>
84 #include "osl/thread.h"
85 #include "rtl/tencinfo.h"
86 #include <rtl/instance.hxx>
87 #include <vcl/salimestatus.hxx>
90 #include <vcl/lazydelete.hxx>
92 using namespace ::com::sun::star::uno
;
94 // keycodes handled internally by VCL
98 ImplReservedKey( KeyCode aKeyCode
, USHORT nResId
) :
99 mKeyCode(aKeyCode
), mnResId( nResId
)
106 typedef std::pair
<ImplReservedKey
*, size_t> ReservedKeys
;
109 struct ImplReservedKeysImpl
111 ReservedKeys
* operator()()
113 static ImplReservedKey ImplReservedKeys
[] =
115 ImplReservedKey(KeyCode(KEY_F1
,0), SV_SHORTCUT_HELP
),
116 ImplReservedKey(KeyCode(KEY_F1
,KEY_SHIFT
), SV_SHORTCUT_ACTIVEHELP
),
117 ImplReservedKey(KeyCode(KEY_F1
,KEY_MOD1
), SV_SHORTCUT_CONTEXTHELP
),
118 ImplReservedKey(KeyCode(KEY_F2
,KEY_SHIFT
), SV_SHORTCUT_CONTEXTHELP
),
119 ImplReservedKey(KeyCode(KEY_F4
,KEY_MOD1
), SV_SHORTCUT_DOCKUNDOCK
),
120 ImplReservedKey(KeyCode(KEY_F4
,KEY_MOD2
), SV_SHORTCUT_DOCKUNDOCK
),
121 ImplReservedKey(KeyCode(KEY_F4
,KEY_MOD1
|KEY_MOD2
), SV_SHORTCUT_DOCKUNDOCK
),
122 ImplReservedKey(KeyCode(KEY_F6
,0), SV_SHORTCUT_NEXTSUBWINDOW
),
123 ImplReservedKey(KeyCode(KEY_F6
,KEY_MOD1
), SV_SHORTCUT_TODOCUMENT
),
124 ImplReservedKey(KeyCode(KEY_F6
,KEY_SHIFT
), SV_SHORTCUT_PREVSUBWINDOW
),
125 ImplReservedKey(KeyCode(KEY_F6
,KEY_MOD1
|KEY_SHIFT
), SV_SHORTCUT_SPLITTER
),
126 ImplReservedKey(KeyCode(KEY_F10
,0), SV_SHORTCUT_MENUBAR
)
129 ImplReservedKey(KeyCode(KEY_1
,KEY_SHIFT
|KEY_MOD1
), 0),
130 ImplReservedKey(KeyCode(KEY_2
,KEY_SHIFT
|KEY_MOD1
), 0),
131 ImplReservedKey(KeyCode(KEY_3
,KEY_SHIFT
|KEY_MOD1
), 0),
132 ImplReservedKey(KeyCode(KEY_4
,KEY_SHIFT
|KEY_MOD1
), 0),
133 ImplReservedKey(KeyCode(KEY_5
,KEY_SHIFT
|KEY_MOD1
), 0),
134 ImplReservedKey(KeyCode(KEY_6
,KEY_SHIFT
|KEY_MOD1
), 0),
135 ImplReservedKey(KeyCode(KEY_7
,KEY_SHIFT
|KEY_MOD1
), 0),
136 ImplReservedKey(KeyCode(KEY_8
,KEY_SHIFT
|KEY_MOD1
), 0),
137 ImplReservedKey(KeyCode(KEY_9
,KEY_SHIFT
|KEY_MOD1
), 0),
138 ImplReservedKey(KeyCode(KEY_0
,KEY_SHIFT
|KEY_MOD1
), 0),
139 ImplReservedKey(KeyCode(KEY_ADD
,KEY_SHIFT
|KEY_MOD1
), 0)
142 static ReservedKeys aKeys
144 &ImplReservedKeys
[0],
145 sizeof(ImplReservedKeys
) / sizeof(ImplReservedKey
)
151 struct ImplReservedKeys
152 : public rtl::StaticAggregate
<ReservedKeys
, ImplReservedKeysImpl
> {};
156 // #include <usr/refl.hxx>
162 typedef UnoWrapperBase
* (SAL_CALL
*FN_TkCreateUnoWrapper
)();
165 // =======================================================================
179 // =======================================================================
187 ImplEventHook
* mpNext
;
189 VCLEventHookProc mpProc
;
192 // =======================================================================
194 // ---------------------
195 // - ImplPostEventData -
196 // ---------------------
198 struct ImplPostEventData
204 MouseEvent maMouseEvent
;
207 ImplPostEventData( ULONG nEvent
, const Window
* pWin
, const KeyEvent
& rKeyEvent
) :
208 mnEvent( nEvent
), mpWin( pWin
), mnEventId( 0 ), maKeyEvent( rKeyEvent
) {}
209 ImplPostEventData( ULONG nEvent
, const Window
* pWin
, const MouseEvent
& rMouseEvent
) :
210 mnEvent( nEvent
), mpWin( pWin
), mnEventId( 0 ), maMouseEvent( rMouseEvent
) {}
212 ~ImplPostEventData() {}
215 typedef ::std::pair
< Window
*, ImplPostEventData
* > ImplPostEventPair
;
217 static ::std::list
< ImplPostEventPair
> aPostedEventList
;
219 // =======================================================================
221 Application
* GetpApp()
223 ImplSVData
* pSVData
= ImplGetSVData();
226 return pSVData
->mpApp
;
229 // -----------------------------------------------------------------------
231 Application::Application()
233 if( ! ImplGetSVData() )
235 ImplGetSVData()->mpApp
= this;
239 // -----------------------------------------------------------------------
241 Application::~Application()
245 ImplGetSVData()->mpApp
= NULL
;
250 // -----------------------------------------------------------------------
252 void Application::InitAppRes( const ResId
& )
256 // -----------------------------------------------------------------------
258 BOOL
Application::QueryExit()
260 WorkWindow
* pAppWin
= ImplGetSVData()->maWinData
.mpAppWin
;
262 // Aufruf des Close-Handlers des Applikationsfensters
264 return pAppWin
->Close();
269 // -----------------------------------------------------------------------
271 void Application::UserEvent( ULONG
, void* )
275 // -----------------------------------------------------------------------
277 void Application::ShowStatusText( const XubString
& )
281 // -----------------------------------------------------------------------
283 void Application::ShowHelpStatusText( const XubString
& )
287 // -----------------------------------------------------------------------
289 void Application::ActivateExtHelp()
293 // -----------------------------------------------------------------------
295 void Application::DeactivateExtHelp()
299 // -----------------------------------------------------------------------
301 void Application::HideStatusText()
305 // -----------------------------------------------------------------------
307 void Application::HideHelpStatusText()
311 // -----------------------------------------------------------------------
313 void Application::FocusChanged()
317 // -----------------------------------------------------------------------
319 void Application::DataChanged( const DataChangedEvent
& )
323 // -----------------------------------------------------------------------
324 void Application::Init()
328 // -----------------------------------------------------------------------
329 void Application::InitFinished()
333 // -----------------------------------------------------------------------
335 void Application::DeInit()
339 // -----------------------------------------------------------------------
341 USHORT
Application::GetCommandLineParamCount()
343 vos::OStartupInfo aStartInfo
;
344 return (USHORT
)aStartInfo
.getCommandArgCount();
347 // -----------------------------------------------------------------------
349 XubString
Application::GetCommandLineParam( USHORT nParam
)
351 vos::OStartupInfo aStartInfo
;
352 rtl::OUString aParam
;
353 aStartInfo
.getCommandArg( nParam
, aParam
);
354 return XubString( aParam
);
357 // -----------------------------------------------------------------------
359 const XubString
& Application::GetAppFileName()
361 ImplSVData
* pSVData
= ImplGetSVData();
362 DBG_ASSERT( pSVData
->maAppData
.mpAppFileName
, "AppFileName vor SVMain ?!" );
363 if ( pSVData
->maAppData
.mpAppFileName
)
364 return *pSVData
->maAppData
.mpAppFileName
;
367 * #91147# provide a fallback for people without initialized
368 * vcl here (like setup in responsefile mode)
370 static String aAppFileName
;
371 if( !aAppFileName
.Len() )
373 vos::OStartupInfo aStartInfo
;
374 ::rtl::OUString aExeFileName
;
376 aStartInfo
.getExecutableFile( aExeFileName
);
378 // convert path to native file format
379 rtl::OUString aNativeFileName
;
380 osl::FileBase::getSystemPathFromFileURL( aExeFileName
, aNativeFileName
);
381 aAppFileName
= aNativeFileName
;
387 // -----------------------------------------------------------------------
389 USHORT
Application::Exception( USHORT nError
)
391 switch ( nError
& EXC_MAJORTYPE
)
393 // Bei System machen wir nichts und lassen dem System den
403 case EXC_RSCNOTLOADED
:
404 Abort( XubString( RTL_CONSTASCII_USTRINGPARAM( "Resource not loaded" ) ) );
406 case EXC_SYSOBJNOTCREATED
:
407 Abort( XubString( RTL_CONSTASCII_USTRINGPARAM( "System Object not created" ) ) );
410 Abort( XubString( RTL_CONSTASCII_USTRINGPARAM( "Unknown Error" ) ) );
414 Abort( ImplGetSVEmptyStr() );
422 // -----------------------------------------------------------------------
424 void Application::Abort( const XubString
& rErrorText
)
426 SalAbort( rErrorText
);
429 // -----------------------------------------------------------------------
431 ULONG
Application::GetReservedKeyCodeCount()
433 return ImplReservedKeys::get()->second
;
436 const KeyCode
* Application::GetReservedKeyCode( ULONG i
)
438 if( i
>= GetReservedKeyCodeCount() )
441 return &ImplReservedKeys::get()->first
[i
].mKeyCode
;
444 String
Application::GetReservedKeyCodeDescription( ULONG i
)
446 ResMgr
* pResMgr
= ImplGetResMgr();
449 ImplReservedKey
*pImplReservedKeys
= ImplReservedKeys::get()->first
;
450 if( i
>= GetReservedKeyCodeCount() || ! pImplReservedKeys
[i
].mnResId
)
453 return String( ResId( pImplReservedKeys
[i
].mnResId
, *pResMgr
) );
456 // -----------------------------------------------------------------------
458 void Application::Execute()
460 DBG_STARTAPPEXECUTE();
462 ImplSVData
* pSVData
= ImplGetSVData();
463 pSVData
->maAppData
.mbInAppExecute
= TRUE
;
465 while ( !pSVData
->maAppData
.mbAppQuit
)
466 Application::Yield();
468 pSVData
->maAppData
.mbInAppExecute
= FALSE
;
473 // -----------------------------------------------------------------------
475 void Application::Reschedule( bool bAllEvents
)
477 ImplSVData
* pSVData
= ImplGetSVData();
479 // run timers that have timed out
480 if ( !pSVData
->mbNoCallTimer
)
481 while ( pSVData
->mbNotAllTimerCalled
)
482 Timer::ImplTimerCallbackProc();
484 pSVData
->maAppData
.mnDispatchLevel
++;
485 pSVData
->mpDefInst
->Yield( false, bAllEvents
);
486 pSVData
->maAppData
.mnDispatchLevel
--;
488 // flush lazy deleted objects
489 if( pSVData
->maAppData
.mnDispatchLevel
== 0 )
490 vcl::LazyDelete::flush();
493 // -----------------------------------------------------------------------
495 void Application::Yield( bool bAllEvents
)
497 ImplSVData
* pSVData
= ImplGetSVData();
499 // run timers that have timed out
500 if ( !pSVData
->mbNoCallTimer
)
501 while ( pSVData
->mbNotAllTimerCalled
)
502 Timer::ImplTimerCallbackProc();
504 // do not wait for events if application was already quit; in that
505 // case only dispatch events already available
506 pSVData
->maAppData
.mnDispatchLevel
++;
507 pSVData
->mpDefInst
->Yield( !pSVData
->maAppData
.mbAppQuit
, bAllEvents
);
508 pSVData
->maAppData
.mnDispatchLevel
--;
510 // flush lazy deleted objects
511 if( pSVData
->maAppData
.mnDispatchLevel
== 0 )
512 vcl::LazyDelete::flush();
515 // -----------------------------------------------------------------------
517 IMPL_STATIC_LINK_NOINSTANCE( ImplSVAppData
, ImplQuitMsg
, void*, EMPTYARG
)
519 ImplGetSVData()->maAppData
.mbAppQuit
= TRUE
;
523 // -----------------------------------------------------------------------
525 void Application::Quit()
527 Application::PostUserEvent( STATIC_LINK( NULL
, ImplSVAppData
, ImplQuitMsg
) );
530 // -----------------------------------------------------------------------
532 vos::IMutex
& Application::GetSolarMutex()
534 ImplSVData
* pSVData
= ImplGetSVData();
535 return *(pSVData
->mpDefInst
->GetYieldMutex());
538 // -----------------------------------------------------------------------
540 vos::OThread::TThreadIdentifier
Application::GetMainThreadIdentifier()
542 return ImplGetSVData()->mnMainThreadId
;
545 // -----------------------------------------------------------------------
547 ULONG
Application::ReleaseSolarMutex()
549 ImplSVData
* pSVData
= ImplGetSVData();
550 return pSVData
->mpDefInst
->ReleaseYieldMutex();
553 // -----------------------------------------------------------------------
555 void Application::AcquireSolarMutex( ULONG nCount
)
557 ImplSVData
* pSVData
= ImplGetSVData();
558 pSVData
->mpDefInst
->AcquireYieldMutex( nCount
);
561 // -----------------------------------------------------------------------
563 BOOL
Application::IsInMain()
565 return ImplGetSVData()->maAppData
.mbInAppMain
;
568 // -----------------------------------------------------------------------
570 BOOL
Application::IsInExecute()
572 return ImplGetSVData()->maAppData
.mbInAppExecute
;
575 // -----------------------------------------------------------------------
577 BOOL
Application::IsShutDown()
579 return ImplGetSVData()->maAppData
.mbAppQuit
;
582 // -----------------------------------------------------------------------
584 BOOL
Application::IsInModalMode()
586 return (ImplGetSVData()->maAppData
.mnModalMode
!= 0);
589 // -----------------------------------------------------------------------
591 USHORT
Application::GetModalModeCount()
593 return ImplGetSVData()->maAppData
.mnModalMode
;
596 // -----------------------------------------------------------------------
598 USHORT
Application::GetDispatchLevel()
600 return ImplGetSVData()->maAppData
.mnDispatchLevel
;
603 // -----------------------------------------------------------------------
605 BOOL
Application::AnyInput( USHORT nType
)
607 return (BOOL
)ImplGetSVData()->mpDefInst
->AnyInput( nType
);
610 // -----------------------------------------------------------------------
612 ULONG
Application::GetLastInputInterval()
614 return (Time::GetSystemTicks()-ImplGetSVData()->maAppData
.mnLastInputTime
);
617 // -----------------------------------------------------------------------
619 extern int nImplSysDialog
;
621 BOOL
Application::IsUICaptured()
623 ImplSVData
* pSVData
= ImplGetSVData();
624 // Wenn Mouse gecaptured, oder im TrackingModus oder im Auswahlmodus
625 // eines FloatingWindows (wie Menus, Aufklapp-ToolBoxen) soll kein
626 // weiteres Fenster aufgezogen werden
628 if ( pSVData
->maWinData
.mpCaptureWin
|| pSVData
->maWinData
.mpTrackWin
||
629 pSVData
->maWinData
.mpFirstFloat
|| nImplSysDialog
)
635 // -----------------------------------------------------------------------
637 BOOL
Application::IsUserActive( USHORT nTest
)
639 if ( nTest
& (USERACTIVE_MOUSEDRAG
| USERACTIVE_INPUT
) )
641 if ( IsUICaptured() )
645 if ( nTest
& USERACTIVE_INPUT
)
647 if ( GetLastInputInterval() < 500 )
650 if ( AnyInput( INPUT_KEYBOARD
) )
654 if ( nTest
& USERACTIVE_MODALDIALOG
)
656 if ( ImplGetSVData()->maAppData
.mnModalDialog
)
663 // -----------------------------------------------------------------------
665 void Application::SystemSettingsChanging( AllSettings
& /*rSettings*/,
670 // -----------------------------------------------------------------------
672 void Application::MergeSystemSettings( AllSettings
& rSettings
)
674 Window
* pWindow
= ImplGetSVData()->maWinData
.mpFirstFrame
;
676 pWindow
= ImplGetDefaultWindow();
679 ImplSVData
* pSVData
= ImplGetSVData();
680 if ( !pSVData
->maAppData
.mbSettingsInit
)
682 // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
683 pWindow
->ImplUpdateGlobalSettings( *pSVData
->maAppData
.mpSettings
);
684 pSVData
->maAppData
.mbSettingsInit
= TRUE
;
686 // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
687 pWindow
->ImplUpdateGlobalSettings( rSettings
, FALSE
);
691 // -----------------------------------------------------------------------
693 bool Application::ValidateSystemFont()
695 Window
* pWindow
= ImplGetSVData()->maWinData
.mpFirstFrame
;
697 pWindow
= ImplGetDefaultWindow();
701 AllSettings aSettings
;
702 pWindow
->ImplGetFrame()->UpdateSettings( aSettings
);
703 return pWindow
->ImplCheckUIFont( aSettings
.GetStyleSettings().GetAppFont() );
708 // -----------------------------------------------------------------------
710 void Application::SetSettings( const AllSettings
& rSettings
)
712 MsLangId::setConfiguredSystemLanguage( rSettings
.GetLanguage());
713 MsLangId::setConfiguredSystemUILanguage( rSettings
.GetUILanguage());
714 ImplSVData
* pSVData
= ImplGetSVData();
715 if ( !pSVData
->maAppData
.mpSettings
)
717 pSVData
->maAppData
.mpSettings
= new AllSettings();
718 *pSVData
->maAppData
.mpSettings
= rSettings
;
719 ResMgr::SetDefaultLocale( rSettings
.GetUILocale() );
723 AllSettings aOldSettings
= *pSVData
->maAppData
.mpSettings
;
724 if( aOldSettings
.GetUILanguage() != rSettings
.GetUILanguage() && pSVData
->mpResMgr
)
726 delete pSVData
->mpResMgr
;
727 pSVData
->mpResMgr
= NULL
;
729 ResMgr::SetDefaultLocale( rSettings
.GetUILocale() );
730 *pSVData
->maAppData
.mpSettings
= rSettings
;
731 ULONG nChangeFlags
= aOldSettings
.GetChangeFlags( *pSVData
->maAppData
.mpSettings
);
734 DataChangedEvent
aDCEvt( DATACHANGED_SETTINGS
, &aOldSettings
, nChangeFlags
);
735 GetpApp()->DataChanged( aDCEvt
);
737 // notify data change handler
738 ImplCallEventListeners( VCLEVENT_APPLICATION_DATACHANGED
, NULL
, &aDCEvt
);
740 // Update all windows
741 Window
* pFirstFrame
= pSVData
->maWinData
.mpFirstFrame
;
742 // Daten, die neu berechnet werden muessen, zuruecksetzen
747 nOldDPIX
= pFirstFrame
->mnDPIX
;
748 nOldDPIY
= pFirstFrame
->mnDPIY
;
749 pSVData
->maGDIData
.mnAppFontX
= 0;
751 Window
* pFrame
= pFirstFrame
;
754 // AppFont-Cache-Daten zuruecksetzen
755 pFrame
->mpWindowImpl
->mpFrameData
->meMapUnit
= MAP_PIXEL
;
757 // UpdateSettings am ClientWindow aufrufen, damit
758 // die Daten nicht doppelt geupdatet werden
759 Window
* pClientWin
= pFrame
;
760 while ( pClientWin
->ImplGetClientWindow() )
761 pClientWin
= pClientWin
->ImplGetClientWindow();
762 pClientWin
->UpdateSettings( rSettings
, TRUE
);
764 Window
* pTempWin
= pFrame
->mpWindowImpl
->mpFrameData
->mpFirstOverlap
;
767 // UpdateSettings am ClientWindow aufrufen, damit
768 // die Daten nicht doppelt geupdatet werden
769 pClientWin
= pTempWin
;
770 while ( pClientWin
->ImplGetClientWindow() )
771 pClientWin
= pClientWin
->ImplGetClientWindow();
772 pClientWin
->UpdateSettings( rSettings
, TRUE
);
773 pTempWin
= pTempWin
->mpWindowImpl
->mpNextOverlap
;
776 pFrame
= pFrame
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
779 // Wenn sich die DPI-Aufloesung fuer Screen-Ausgaben
780 // geaendert hat, setzen wir auch bei allen
781 // Screen-Kompatiblen VirDev's die neue Aufloesung
782 pFirstFrame
= pSVData
->maWinData
.mpFirstFrame
;
785 if ( (pFirstFrame
->mnDPIX
!= nOldDPIX
) ||
786 (pFirstFrame
->mnDPIY
!= nOldDPIY
) )
788 VirtualDevice
* pVirDev
= pSVData
->maGDIData
.mpFirstVirDev
;
791 if ( pVirDev
->mbScreenComp
&&
792 (pVirDev
->mnDPIX
== nOldDPIX
) &&
793 (pVirDev
->mnDPIY
== nOldDPIY
) )
795 pVirDev
->mnDPIX
= pFirstFrame
->mnDPIX
;
796 pVirDev
->mnDPIY
= pFirstFrame
->mnDPIY
;
797 if ( pVirDev
->IsMapMode() )
799 MapMode aMapMode
= pVirDev
->GetMapMode();
800 pVirDev
->SetMapMode();
801 pVirDev
->SetMapMode( aMapMode
);
805 pVirDev
= pVirDev
->mpNext
;
813 // -----------------------------------------------------------------------
815 const AllSettings
& Application::GetSettings()
817 ImplSVData
* pSVData
= ImplGetSVData();
818 if ( !pSVData
->maAppData
.mpSettings
)
819 pSVData
->maAppData
.mpSettings
= new AllSettings();
820 return *(pSVData
->maAppData
.mpSettings
);
823 // -----------------------------------------------------------------------
825 void Application::NotifyAllWindows( DataChangedEvent
& rDCEvt
)
827 ImplSVData
* pSVData
= ImplGetSVData();
828 Window
* pFrame
= pSVData
->maWinData
.mpFirstFrame
;
831 pFrame
->NotifyAllChilds( rDCEvt
);
833 Window
* pSysWin
= pFrame
->mpWindowImpl
->mpFrameData
->mpFirstOverlap
;
836 pSysWin
->NotifyAllChilds( rDCEvt
);
837 pSysWin
= pSysWin
->mpWindowImpl
->mpNextOverlap
;
840 pFrame
= pFrame
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
844 // -----------------------------------------------------------------------
846 void Application::ImplCallEventListeners( ULONG nEvent
, Window
*pWin
, void* pData
)
848 ImplSVData
* pSVData
= ImplGetSVData();
849 VclWindowEvent
aEvent( pWin
, nEvent
, pData
);
851 if ( pSVData
->maAppData
.mpEventListeners
)
852 if ( !pSVData
->maAppData
.mpEventListeners
->empty() )
853 pSVData
->maAppData
.mpEventListeners
->Call( &aEvent
);
856 // -----------------------------------------------------------------------
858 void Application::ImplCallEventListeners( VclSimpleEvent
* pEvent
)
860 ImplSVData
* pSVData
= ImplGetSVData();
862 if ( pSVData
->maAppData
.mpEventListeners
)
863 if ( !pSVData
->maAppData
.mpEventListeners
->empty() )
864 pSVData
->maAppData
.mpEventListeners
->Call( pEvent
);
867 // -----------------------------------------------------------------------
869 void Application::AddEventListener( const Link
& rEventListener
)
871 ImplSVData
* pSVData
= ImplGetSVData();
872 if( !pSVData
->maAppData
.mpEventListeners
)
873 pSVData
->maAppData
.mpEventListeners
= new VclEventListeners
;
874 pSVData
->maAppData
.mpEventListeners
->push_back( rEventListener
);
877 // -----------------------------------------------------------------------
879 void Application::RemoveEventListener( const Link
& rEventListener
)
881 ImplSVData
* pSVData
= ImplGetSVData();
882 if( pSVData
->maAppData
.mpEventListeners
)
883 pSVData
->maAppData
.mpEventListeners
->remove( rEventListener
);
886 // -----------------------------------------------------------------------
887 void Application::AddKeyListener( const Link
& rKeyListener
)
889 ImplSVData
* pSVData
= ImplGetSVData();
890 if( !pSVData
->maAppData
.mpKeyListeners
)
891 pSVData
->maAppData
.mpKeyListeners
= new VclEventListeners
;
892 pSVData
->maAppData
.mpKeyListeners
->push_back( rKeyListener
);
895 // -----------------------------------------------------------------------
897 void Application::RemoveKeyListener( const Link
& rKeyListener
)
899 ImplSVData
* pSVData
= ImplGetSVData();
900 if( pSVData
->maAppData
.mpKeyListeners
)
901 pSVData
->maAppData
.mpKeyListeners
->remove( rKeyListener
);
904 // -----------------------------------------------------------------------
906 BOOL
Application::HandleKey( ULONG nEvent
, Window
*pWin
, KeyEvent
* pKeyEvent
)
908 // let listeners process the key event
909 VclWindowEvent
aEvent( pWin
, nEvent
, (void *) pKeyEvent
);
911 ImplSVData
* pSVData
= ImplGetSVData();
912 BOOL bProcessed
= FALSE
;
914 if ( pSVData
->maAppData
.mpKeyListeners
)
915 if ( !pSVData
->maAppData
.mpKeyListeners
->empty() )
916 bProcessed
= pSVData
->maAppData
.mpKeyListeners
->Process( &aEvent
);
921 // -----------------------------------------------------------------------------
923 ULONG
Application::PostKeyEvent( ULONG nEvent
, Window
*pWin
, KeyEvent
* pKeyEvent
)
925 const ::vos::OGuard
aGuard( GetSolarMutex() );
928 if( pWin
&& pKeyEvent
)
930 ImplPostEventData
* pPostEventData
= new ImplPostEventData( nEvent
, pWin
, *pKeyEvent
);
932 PostUserEvent( nEventId
,
933 STATIC_LINK( NULL
, Application
, PostEventHandler
),
938 pPostEventData
->mnEventId
= nEventId
;
939 aPostedEventList
.push_back( ImplPostEventPair( pWin
, pPostEventData
) );
942 delete pPostEventData
;
948 // -----------------------------------------------------------------------------
950 ULONG
Application::PostMouseEvent( ULONG nEvent
, Window
*pWin
, MouseEvent
* pMouseEvent
)
952 const ::vos::OGuard
aGuard( GetSolarMutex() );
955 if( pWin
&& pMouseEvent
)
957 Point
aTransformedPos( pMouseEvent
->GetPosPixel() );
959 aTransformedPos
.X() += pWin
->mnOutOffX
;
960 aTransformedPos
.Y() += pWin
->mnOutOffY
;
962 const MouseEvent
aTransformedEvent( aTransformedPos
, pMouseEvent
->GetClicks(), pMouseEvent
->GetMode(),
963 pMouseEvent
->GetButtons(), pMouseEvent
->GetModifier() );
965 ImplPostEventData
* pPostEventData
= new ImplPostEventData( nEvent
, pWin
, aTransformedEvent
);
967 PostUserEvent( nEventId
,
968 STATIC_LINK( NULL
, Application
, PostEventHandler
),
973 pPostEventData
->mnEventId
= nEventId
;
974 aPostedEventList
.push_back( ImplPostEventPair( pWin
, pPostEventData
) );
977 delete pPostEventData
;
983 // -----------------------------------------------------------------------------
985 IMPL_STATIC_LINK_NOINSTANCE( Application
, PostEventHandler
, void*, pCallData
)
987 const ::vos::OGuard
aGuard( GetSolarMutex() );
988 ImplPostEventData
* pData
= static_cast< ImplPostEventData
* >( pCallData
);
989 const void* pEventData
;
991 const ULONG nEventId
= pData
->mnEventId
;
993 switch( pData
->mnEvent
)
995 case VCLEVENT_WINDOW_MOUSEMOVE
:
996 nEvent
= SALEVENT_EXTERNALMOUSEMOVE
;
997 pEventData
= &pData
->maMouseEvent
;
1000 case VCLEVENT_WINDOW_MOUSEBUTTONDOWN
:
1001 nEvent
= SALEVENT_EXTERNALMOUSEBUTTONDOWN
;
1002 pEventData
= &pData
->maMouseEvent
;
1005 case VCLEVENT_WINDOW_MOUSEBUTTONUP
:
1006 nEvent
= SALEVENT_EXTERNALMOUSEBUTTONUP
;
1007 pEventData
= &pData
->maMouseEvent
;
1010 case VCLEVENT_WINDOW_KEYINPUT
:
1011 nEvent
= SALEVENT_EXTERNALKEYINPUT
;
1012 pEventData
= &pData
->maKeyEvent
;
1015 case VCLEVENT_WINDOW_KEYUP
:
1016 nEvent
= SALEVENT_EXTERNALKEYUP
;
1017 pEventData
= &pData
->maKeyEvent
;
1026 if( pData
->mpWin
&& pData
->mpWin
->mpWindowImpl
->mpFrameWindow
&& pEventData
)
1027 ImplWindowFrameProc( pData
->mpWin
->mpWindowImpl
->mpFrameWindow
, NULL
, (USHORT
) nEvent
, pEventData
);
1029 // remove this event from list of posted events, watch for destruction of internal data
1030 ::std::list
< ImplPostEventPair
>::iterator
aIter( aPostedEventList
.begin() );
1032 while( aIter
!= aPostedEventList
.end() )
1034 if( nEventId
== (*aIter
).second
->mnEventId
)
1036 delete (*aIter
).second
;
1037 aIter
= aPostedEventList
.erase( aIter
);
1046 // -----------------------------------------------------------------------
1048 void Application::RemoveMouseAndKeyEvents( Window
* pWin
)
1050 const ::vos::OGuard
aGuard( GetSolarMutex() );
1052 // remove all events for specific window, watch for destruction of internal data
1053 ::std::list
< ImplPostEventPair
>::iterator
aIter( aPostedEventList
.begin() );
1055 while( aIter
!= aPostedEventList
.end() )
1057 if( pWin
== (*aIter
).first
)
1059 if( (*aIter
).second
->mnEventId
)
1060 RemoveUserEvent( (*aIter
).second
->mnEventId
);
1062 delete (*aIter
).second
;
1063 aIter
= aPostedEventList
.erase( aIter
);
1070 // -----------------------------------------------------------------------
1072 BOOL
Application::IsProcessedMouseOrKeyEvent( ULONG nEventId
)
1074 const ::vos::OGuard
aGuard( GetSolarMutex() );
1077 ::std::list
< ImplPostEventPair
>::iterator
aIter( aPostedEventList
.begin() );
1079 while( aIter
!= aPostedEventList
.end() )
1081 if( (*aIter
).second
->mnEventId
== nEventId
)
1090 // -----------------------------------------------------------------------
1092 ULONG
Application::PostUserEvent( ULONG nEvent
, void* pEventData
)
1095 PostUserEvent( nEventId
, nEvent
, pEventData
);
1099 // -----------------------------------------------------------------------
1101 ULONG
Application::PostUserEvent( const Link
& rLink
, void* pCaller
)
1104 PostUserEvent( nEventId
, rLink
, pCaller
);
1108 // -----------------------------------------------------------------------
1110 BOOL
Application::PostUserEvent( ULONG
& rEventId
, ULONG nEvent
, void* pEventData
)
1112 ImplSVEvent
* pSVEvent
= new ImplSVEvent
;
1113 pSVEvent
->mnEvent
= nEvent
;
1114 pSVEvent
->mpData
= pEventData
;
1115 pSVEvent
->mpLink
= NULL
;
1116 pSVEvent
->mpWindow
= NULL
;
1117 pSVEvent
->mbCall
= TRUE
;
1118 rEventId
= (ULONG
)pSVEvent
;
1119 Window
* pDefWindow
= ImplGetDefaultWindow();
1120 if ( pDefWindow
&& pDefWindow
->ImplGetFrame()->PostEvent( pSVEvent
) )
1130 // -----------------------------------------------------------------------
1132 BOOL
Application::PostUserEvent( ULONG
& rEventId
, const Link
& rLink
, void* pCaller
)
1134 ImplSVEvent
* pSVEvent
= new ImplSVEvent
;
1135 pSVEvent
->mnEvent
= 0;
1136 pSVEvent
->mpData
= pCaller
;
1137 pSVEvent
->mpLink
= new Link( rLink
);
1138 pSVEvent
->mpWindow
= NULL
;
1139 pSVEvent
->mbCall
= TRUE
;
1140 rEventId
= (ULONG
)pSVEvent
;
1141 Window
* pDefWindow
= ImplGetDefaultWindow();
1142 if ( pDefWindow
&& pDefWindow
->ImplGetFrame()->PostEvent( pSVEvent
) )
1152 // -----------------------------------------------------------------------
1154 void Application::RemoveUserEvent( ULONG nUserEvent
)
1158 ImplSVEvent
* pSVEvent
= (ImplSVEvent
*)nUserEvent
;
1160 DBG_ASSERT( !pSVEvent
->mpWindow
,
1161 "Application::RemoveUserEvent(): Event is send to a window" );
1162 DBG_ASSERT( pSVEvent
->mbCall
,
1163 "Application::RemoveUserEvent(): Event is already removed" );
1165 if ( pSVEvent
->mpWindow
)
1167 if( ! pSVEvent
->maDelData
.IsDelete() )
1168 pSVEvent
->mpWindow
->ImplRemoveDel( &(pSVEvent
->maDelData
) );
1169 pSVEvent
->mpWindow
= NULL
;
1172 pSVEvent
->mbCall
= FALSE
;
1176 // -----------------------------------------------------------------------
1178 BOOL
Application::InsertIdleHdl( const Link
& rLink
, USHORT nPrio
)
1180 ImplSVData
* pSVData
= ImplGetSVData();
1182 // Falls er noch nicht existiert, dann anlegen
1183 if ( !pSVData
->maAppData
.mpIdleMgr
)
1184 pSVData
->maAppData
.mpIdleMgr
= new ImplIdleMgr
;
1186 return pSVData
->maAppData
.mpIdleMgr
->InsertIdleHdl( rLink
, nPrio
);
1189 // -----------------------------------------------------------------------
1191 void Application::RemoveIdleHdl( const Link
& rLink
)
1193 ImplSVData
* pSVData
= ImplGetSVData();
1195 if ( pSVData
->maAppData
.mpIdleMgr
)
1196 pSVData
->maAppData
.mpIdleMgr
->RemoveIdleHdl( rLink
);
1199 // -----------------------------------------------------------------------
1201 WorkWindow
* Application::GetAppWindow()
1203 return ImplGetSVData()->maWinData
.mpAppWin
;
1206 // -----------------------------------------------------------------------
1208 Window
* Application::GetFocusWindow()
1210 return ImplGetSVData()->maWinData
.mpFocusWin
;
1213 // -----------------------------------------------------------------------
1215 OutputDevice
* Application::GetDefaultDevice()
1217 return ImplGetDefaultWindow();
1220 // -----------------------------------------------------------------------
1222 Window
* Application::GetFirstTopLevelWindow()
1224 ImplSVData
* pSVData
= ImplGetSVData();
1225 return pSVData
->maWinData
.mpFirstFrame
;
1228 // -----------------------------------------------------------------------
1230 Window
* Application::GetNextTopLevelWindow( Window
* pWindow
)
1232 return pWindow
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
1235 // -----------------------------------------------------------------------
1237 long Application::GetTopWindowCount()
1240 ImplSVData
* pSVData
= ImplGetSVData();
1241 Window
*pWin
= pSVData
? pSVData
->maWinData
.mpFirstFrame
: NULL
;
1244 if( pWin
->ImplGetWindow()->IsTopWindow() )
1246 pWin
= pWin
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
1251 // -----------------------------------------------------------------------
1253 Window
* Application::GetTopWindow( long nIndex
)
1256 ImplSVData
* pSVData
= ImplGetSVData();
1257 Window
*pWin
= pSVData
? pSVData
->maWinData
.mpFirstFrame
: NULL
;
1260 if( pWin
->ImplGetWindow()->IsTopWindow() )
1262 if( nIdx
== nIndex
)
1263 return pWin
->ImplGetWindow();
1267 pWin
= pWin
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
1272 // -----------------------------------------------------------------------
1274 Window
* Application::GetActiveTopWindow()
1276 Window
*pWin
= ImplGetSVData()->maWinData
.mpFocusWin
;
1279 if( pWin
->IsTopWindow() )
1281 pWin
= pWin
->mpWindowImpl
->mpParent
;
1286 // -----------------------------------------------------------------------
1288 void Application::SetAppName( const XubString
& rUniqueName
)
1290 ImplSVData
* pSVData
= ImplGetSVData();
1292 // Falls er noch nicht existiert, dann anlegen
1293 if ( !pSVData
->maAppData
.mpAppName
)
1294 pSVData
->maAppData
.mpAppName
= new XubString( rUniqueName
);
1296 *(pSVData
->maAppData
.mpAppName
) = rUniqueName
;
1299 // -----------------------------------------------------------------------
1301 XubString
Application::GetAppName()
1303 ImplSVData
* pSVData
= ImplGetSVData();
1304 if ( pSVData
->maAppData
.mpAppName
)
1305 return *(pSVData
->maAppData
.mpAppName
);
1307 return ImplGetSVEmptyStr();
1310 // -----------------------------------------------------------------------
1312 void Application::SetDisplayName( const UniString
& rName
)
1314 ImplSVData
* pSVData
= ImplGetSVData();
1316 // Falls er noch nicht existiert, dann anlegen
1317 if ( !pSVData
->maAppData
.mpDisplayName
)
1318 pSVData
->maAppData
.mpDisplayName
= new UniString( rName
);
1320 *(pSVData
->maAppData
.mpDisplayName
) = rName
;
1323 // -----------------------------------------------------------------------
1325 UniString
Application::GetDisplayName()
1327 ImplSVData
* pSVData
= ImplGetSVData();
1328 if ( pSVData
->maAppData
.mpDisplayName
)
1329 return *(pSVData
->maAppData
.mpDisplayName
);
1330 else if ( pSVData
->maWinData
.mpAppWin
)
1331 return pSVData
->maWinData
.mpAppWin
->GetText();
1333 return ImplGetSVEmptyStr();
1336 // -----------------------------------------------------------------------
1338 unsigned int Application::GetScreenCount()
1340 SalSystem
* pSys
= ImplGetSalSystem();
1341 return pSys
? pSys
->GetDisplayScreenCount() : 0;
1344 rtl::OUString
Application::GetScreenName( unsigned int nScreen
)
1346 SalSystem
* pSys
= ImplGetSalSystem();
1347 return pSys
? pSys
->GetScreenName( nScreen
) : rtl::OUString();
1350 bool Application::IsMultiDisplay()
1352 SalSystem
* pSys
= ImplGetSalSystem();
1353 return pSys
? pSys
->IsMultiDisplay() : false;
1356 unsigned int Application::GetDefaultDisplayNumber()
1358 SalSystem
* pSys
= ImplGetSalSystem();
1359 return pSys
? pSys
->GetDefaultDisplayNumber() : 0;
1362 Rectangle
Application::GetScreenPosSizePixel( unsigned int nScreen
)
1364 SalSystem
* pSys
= ImplGetSalSystem();
1365 return pSys
? pSys
->GetDisplayScreenPosSizePixel( nScreen
) : Rectangle();
1368 Rectangle
Application::GetWorkAreaPosSizePixel( unsigned int nScreen
)
1370 SalSystem
* pSys
= ImplGetSalSystem();
1371 return pSys
? pSys
->GetDisplayWorkAreaPosSizePixel( nScreen
) : Rectangle();
1375 unsigned long calcDistSquare( const Point
& i_rPoint
, const Rectangle
& i_rRect
)
1377 const Point
aRectCenter( (i_rRect
.Left() + i_rRect
.Right())/2,
1378 (i_rRect
.Top() + i_rRect
.Bottom())/ 2 );
1379 const long nDX
= aRectCenter
.X() - i_rPoint
.X();
1380 const long nDY
= aRectCenter
.Y() - i_rPoint
.Y();
1381 return nDX
*nDX
+ nDY
*nDY
;
1385 unsigned int Application::GetBestScreen( const Rectangle
& i_rRect
)
1387 if( IsMultiDisplay() )
1388 return GetDefaultDisplayNumber();
1390 const unsigned int nScreens
= GetScreenCount();
1391 unsigned int nBestMatchScreen
= 0;
1392 unsigned long nOverlap
= 0;
1393 for( unsigned int i
= 0; i
< nScreens
; i
++ )
1395 const Rectangle
aCurScreenRect( GetScreenPosSizePixel( i
) );
1396 // if a screen contains the rectangle completely it is obviously the best screen
1397 if( aCurScreenRect
.IsInside( i_rRect
) )
1399 // next the screen which contains most of the area of the rect is the best
1400 Rectangle
aIntersection( aCurScreenRect
.GetIntersection( i_rRect
) );
1401 if( ! aIntersection
.IsEmpty() )
1403 const unsigned long nCurOverlap( aIntersection
.GetWidth() * aIntersection
.GetHeight() );
1404 if( nCurOverlap
> nOverlap
)
1406 nOverlap
= nCurOverlap
;
1407 nBestMatchScreen
= i
;
1412 return nBestMatchScreen
;
1414 // finally the screen which center is nearest to the rect is the best
1415 const Point
aCenter( (i_rRect
.Left() + i_rRect
.Right())/2,
1416 (i_rRect
.Top() + i_rRect
.Bottom())/2 );
1417 unsigned long nDist
= ULONG_MAX
;
1418 for( unsigned int i
= 0; i
< nScreens
; i
++ )
1420 const Rectangle
aCurScreenRect( GetScreenPosSizePixel( i
) );
1421 const unsigned long nCurDist( calcDistSquare( aCenter
, aCurScreenRect
) );
1422 if( nCurDist
< nDist
)
1424 nBestMatchScreen
= i
;
1428 return nBestMatchScreen
;
1431 // -----------------------------------------------------------------------
1433 BOOL
Application::InsertAccel( Accelerator
* pAccel
)
1435 ImplSVData
* pSVData
= ImplGetSVData();
1437 if ( !pSVData
->maAppData
.mpAccelMgr
)
1438 pSVData
->maAppData
.mpAccelMgr
= new ImplAccelManager();
1439 return pSVData
->maAppData
.mpAccelMgr
->InsertAccel( pAccel
);
1442 // -----------------------------------------------------------------------
1444 void Application::RemoveAccel( Accelerator
* pAccel
)
1446 ImplSVData
* pSVData
= ImplGetSVData();
1448 if ( pSVData
->maAppData
.mpAccelMgr
)
1449 pSVData
->maAppData
.mpAccelMgr
->RemoveAccel( pAccel
);
1452 // -----------------------------------------------------------------------
1454 void Application::FlushAccel()
1456 ImplSVData
* pSVData
= ImplGetSVData();
1458 if ( pSVData
->maAppData
.mpAccelMgr
)
1459 pSVData
->maAppData
.mpAccelMgr
->FlushAccel();
1462 // -----------------------------------------------------------------------
1464 BOOL
Application::CallAccel( const KeyCode
& rKeyCode
, USHORT nRepeat
)
1466 ImplSVData
* pSVData
= ImplGetSVData();
1468 if ( pSVData
->maAppData
.mpAccelMgr
)
1470 if ( pSVData
->maAppData
.mpAccelMgr
->IsAccelKey( rKeyCode
, nRepeat
) )
1477 // -----------------------------------------------------------------------
1479 void Application::SetHelp( Help
* pHelp
)
1481 ImplGetSVData()->maAppData
.mpHelp
= pHelp
;
1484 // -----------------------------------------------------------------------
1486 Help
* Application::GetHelp()
1488 return ImplGetSVData()->maAppData
.mpHelp
;
1491 // -----------------------------------------------------------------------
1493 void Application::EnableAutoHelpId( BOOL bEnabled
)
1495 ImplGetSVData()->maHelpData
.mbAutoHelpId
= bEnabled
;
1498 // -----------------------------------------------------------------------
1500 BOOL
Application::IsAutoHelpIdEnabled()
1502 return ImplGetSVData()->maHelpData
.mbAutoHelpId
;
1505 // -----------------------------------------------------------------------
1507 void Application::EnableAutoMnemonic( BOOL bEnabled
)
1509 AllSettings aSettings
= GetSettings();
1510 StyleSettings aStyle
= aSettings
.GetStyleSettings();
1511 aStyle
.SetAutoMnemonic( bEnabled
);
1512 aSettings
.SetStyleSettings( aStyle
);
1513 SetSettings( aSettings
);
1516 // -----------------------------------------------------------------------
1518 BOOL
Application::IsAutoMnemonicEnabled()
1520 return GetSettings().GetStyleSettings().GetAutoMnemonic();
1523 // -----------------------------------------------------------------------
1525 void Application::SetDialogScaleX( short nScale
)
1527 ImplSVData
* pSVData
= ImplGetSVData();
1528 pSVData
->maAppData
.mnDialogScaleX
= nScale
;
1529 pSVData
->maGDIData
.mnAppFontX
= pSVData
->maGDIData
.mnRealAppFontX
;
1531 pSVData
->maGDIData
.mnAppFontX
+= (pSVData
->maGDIData
.mnAppFontX
*nScale
)/100;
1534 // -----------------------------------------------------------------------
1536 short Application::GetDialogScaleX()
1538 return ImplGetSVData()->maAppData
.mnDialogScaleX
;
1541 // -----------------------------------------------------------------------
1543 void Application::SetDefDialogParent( Window
* pWindow
)
1545 ImplGetSVData()->maWinData
.mpDefDialogParent
= pWindow
;
1548 // -----------------------------------------------------------------------
1550 Window
* Application::GetDefDialogParent()
1552 ImplSVData
* pSVData
= ImplGetSVData();
1553 // #103442# find some useful dialog parent if there
1554 // was no default set
1555 // NOTE: currently even the default is not used
1556 if( FALSE
&& pSVData
->maWinData
.mpDefDialogParent
!= NULL
)
1557 return pSVData
->maWinData
.mpDefDialogParent
;
1560 // always use the topmost parent of the candidate
1561 // window to avoid using dialogs or floaters
1562 // as DefDialogParent
1564 // current focus frame
1565 Window
*pWin
= NULL
;
1566 if( (pWin
= pSVData
->maWinData
.mpFocusWin
) != NULL
)
1568 while( pWin
->mpWindowImpl
&& pWin
->mpWindowImpl
->mpParent
)
1569 pWin
= pWin
->mpWindowImpl
->mpParent
;
1571 if( (pWin
->mpWindowImpl
->mnStyle
& WB_INTROWIN
) == 0 )
1573 // check for corrupted window hierarchy, #122232#, may be we now crash somewhere else
1574 if( !pWin
->mpWindowImpl
)
1576 DBG_ERROR( "Window hierarchy corrupted!" );
1577 pSVData
->maWinData
.mpFocusWin
= NULL
; // avoid further access
1581 // MAV: before the implementation has used only decorated windows,
1582 // but it is not true in case of ActiveX or plugin scenario,
1583 // so this check is commented out
1584 // if( pWin->mpWindowImpl->mpFrameWindow->GetStyle() & (WB_MOVEABLE | WB_SIZEABLE) )
1585 return pWin
->mpWindowImpl
->mpFrameWindow
->ImplGetWindow();
1590 // last active application frame
1591 if( NULL
!= (pWin
= pSVData
->maWinData
.mpActiveApplicationFrame
) )
1593 return pWin
->mpWindowImpl
->mpFrameWindow
->ImplGetWindow();
1597 // first visible top window (may be totally wrong....)
1598 pWin
= pSVData
->maWinData
.mpFirstFrame
;
1601 if( pWin
->ImplGetWindow()->IsTopWindow() &&
1602 pWin
->mpWindowImpl
->mbReallyVisible
&&
1603 (pWin
->mpWindowImpl
->mnStyle
& WB_INTROWIN
) == 0
1606 while( pWin
->mpWindowImpl
->mpParent
)
1607 pWin
= pWin
->mpWindowImpl
->mpParent
;
1608 return pWin
->mpWindowImpl
->mpFrameWindow
->ImplGetWindow();
1610 pWin
= pWin
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
1618 // -----------------------------------------------------------------------
1620 void Application::EnableDialogCancel( BOOL bDialogCancel
)
1622 ImplGetSVData()->maAppData
.mbDialogCancel
= bDialogCancel
;
1625 // -----------------------------------------------------------------------
1627 BOOL
Application::IsDialogCancelEnabled()
1629 return ImplGetSVData()->maAppData
.mbDialogCancel
;
1632 // -----------------------------------------------------------------------
1634 void Application::SetSystemWindowMode( USHORT nMode
)
1636 ImplGetSVData()->maAppData
.mnSysWinMode
= nMode
;
1639 // -----------------------------------------------------------------------
1641 USHORT
Application::GetSystemWindowMode()
1643 return ImplGetSVData()->maAppData
.mnSysWinMode
;
1646 // -----------------------------------------------------------------------
1648 const String
& Application::GetFontPath()
1650 ImplSVData
* pSVData
= ImplGetSVData();
1651 if( !pSVData
->maAppData
.mpFontPath
)
1653 if( const char* pFontPath
= ::getenv( "SAL_FONTPATH_PRIVATE" ) )
1654 pSVData
->maAppData
.mpFontPath
= new String( String::CreateFromAscii( pFontPath
) );
1657 if( pSVData
->maAppData
.mpFontPath
)
1658 return *(pSVData
->maAppData
.mpFontPath
);
1659 return ImplGetSVEmptyStr();
1662 // -----------------------------------------------------------------------
1664 void Application::SetFontPath( const String
& rPath
)
1666 ImplSVData
* pSVData
= ImplGetSVData();
1668 // if it doesn't exist create a new one
1669 if( !pSVData
->maAppData
.mpFontPath
)
1670 pSVData
->maAppData
.mpFontPath
= new String( rPath
);
1672 *(pSVData
->maAppData
.mpFontPath
) = rPath
;
1675 // -----------------------------------------------------------------------
1677 UniqueItemId
Application::CreateUniqueId()
1679 ImplSVData
* pSVData
= ImplGetSVData();
1681 if ( !pSVData
->maAppData
.mpUniqueIdCont
)
1682 pSVData
->maAppData
.mpUniqueIdCont
= new UniqueIdContainer( UNIQUEID_SV_BEGIN
);
1683 return pSVData
->maAppData
.mpUniqueIdCont
->CreateId();
1686 // -----------------------------------------------------------------------
1688 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
> Application::GetVCLToolkit()
1690 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
> xT
;
1691 UnoWrapperBase
* pWrapper
= Application::GetUnoWrapper( TRUE
);
1693 xT
= pWrapper
->GetVCLToolkit();
1697 // -----------------------------------------------------------------------
1699 extern "C" { static void SAL_CALL
thisModule() {} }
1701 UnoWrapperBase
* Application::GetUnoWrapper( BOOL bCreateIfNotExist
)
1703 ImplSVData
* pSVData
= ImplGetSVData();
1704 static BOOL bAlreadyTriedToCreate
= FALSE
;
1705 if ( !pSVData
->mpUnoWrapper
&& bCreateIfNotExist
&& !bAlreadyTriedToCreate
)
1707 ::rtl::OUString aLibName
= ::vcl::unohelper::CreateLibraryName( "tk", TRUE
);
1708 oslModule hTkLib
= osl_loadModuleRelative(
1709 &thisModule
, aLibName
.pData
, SAL_LOADMODULE_DEFAULT
);
1712 ::rtl::OUString
aFunctionName( RTL_CONSTASCII_USTRINGPARAM( "CreateUnoWrapper" ) );
1713 FN_TkCreateUnoWrapper fnCreateWrapper
= (FN_TkCreateUnoWrapper
)osl_getFunctionSymbol( hTkLib
, aFunctionName
.pData
);
1714 if ( fnCreateWrapper
)
1716 pSVData
->mpUnoWrapper
= fnCreateWrapper();
1719 DBG_ASSERT( pSVData
->mpUnoWrapper
, "UnoWrapper could not be created!" );
1720 bAlreadyTriedToCreate
= TRUE
;
1722 return pSVData
->mpUnoWrapper
;
1725 // -----------------------------------------------------------------------
1727 void Application::SetUnoWrapper( UnoWrapperBase
* pWrapper
)
1729 ImplSVData
* pSVData
= ImplGetSVData();
1730 DBG_ASSERT( !pSVData
->mpUnoWrapper
, "SetUnoWrapper: Wrapper allready exists" );
1731 pSVData
->mpUnoWrapper
= pWrapper
;
1734 // -----------------------------------------------------------------------
1736 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XDisplayConnection
> Application::GetDisplayConnection()
1738 ImplSVData
* pSVData
= ImplGetSVData();
1740 if( !pSVData
->mxDisplayConnection
.is() )
1741 pSVData
->mxDisplayConnection
.set( new ::vcl::DisplayConnection
);
1743 return pSVData
->mxDisplayConnection
;
1746 // -----------------------------------------------------------------------
1748 void Application::SetFilterHdl( const Link
& rLink
)
1750 ImplGetSVData()->maGDIData
.mpGrfConverter
->SetFilterHdl( rLink
);
1753 // -----------------------------------------------------------------------
1755 const Link
& Application::GetFilterHdl()
1757 return ImplGetSVData()->maGDIData
.mpGrfConverter
->GetFilterHdl();
1760 // -----------------------------------------------------------------------
1762 BOOL
ImplCallHotKey( const KeyCode
& rKeyCode
)
1764 ImplSVData
* pSVData
= ImplGetSVData();
1765 ImplHotKey
* pHotKeyData
= pSVData
->maAppData
.mpFirstHotKey
;
1766 while ( pHotKeyData
)
1768 if ( pHotKeyData
->maKeyCode
.IsDefinedKeyCodeEqual( rKeyCode
) )
1770 pHotKeyData
->maLink
.Call( pHotKeyData
->mpUserData
);
1774 pHotKeyData
= pHotKeyData
->mpNext
;
1780 // -----------------------------------------------------------------------
1782 void ImplFreeHotKeyData()
1784 ImplSVData
* pSVData
= ImplGetSVData();
1785 ImplHotKey
* pTempHotKeyData
;
1786 ImplHotKey
* pHotKeyData
= pSVData
->maAppData
.mpFirstHotKey
;
1787 while ( pHotKeyData
)
1789 pTempHotKeyData
= pHotKeyData
->mpNext
;
1791 pHotKeyData
= pTempHotKeyData
;
1794 pSVData
->maAppData
.mpFirstHotKey
= NULL
;
1797 // -----------------------------------------------------------------------
1799 ULONG
Application::AddHotKey( const KeyCode
& rKeyCode
, const Link
& rLink
, void* pData
)
1801 ImplSVData
* pSVData
= ImplGetSVData();
1802 ImplHotKey
* pHotKeyData
= new ImplHotKey
;
1803 pHotKeyData
->mpUserData
= pData
;
1804 pHotKeyData
->maKeyCode
= rKeyCode
;
1805 pHotKeyData
->maLink
= rLink
;
1806 pHotKeyData
->mpNext
= pSVData
->maAppData
.mpFirstHotKey
;
1807 pSVData
->maAppData
.mpFirstHotKey
= pHotKeyData
;
1808 return (ULONG
)pHotKeyData
;
1811 // -----------------------------------------------------------------------
1813 void Application::RemoveHotKey( ULONG nId
)
1815 ImplSVData
* pSVData
= ImplGetSVData();
1816 ImplHotKey
* pFindHotKeyData
= (ImplHotKey
*)nId
;
1817 ImplHotKey
* pPrevHotKeyData
= NULL
;
1818 ImplHotKey
* pHotKeyData
= pSVData
->maAppData
.mpFirstHotKey
;
1819 while ( pHotKeyData
)
1821 if ( pHotKeyData
== pFindHotKeyData
)
1823 if ( pPrevHotKeyData
)
1824 pPrevHotKeyData
->mpNext
= pFindHotKeyData
->mpNext
;
1826 pSVData
->maAppData
.mpFirstHotKey
= pFindHotKeyData
->mpNext
;
1827 delete pFindHotKeyData
;
1831 pPrevHotKeyData
= pHotKeyData
;
1832 pHotKeyData
= pHotKeyData
->mpNext
;
1835 DBG_ASSERT( pHotKeyData
, "Application::RemoveHotKey() - HotKey is not added" );
1838 // -----------------------------------------------------------------------
1840 void ImplFreeEventHookData()
1842 ImplSVData
* pSVData
= ImplGetSVData();
1843 ImplEventHook
* pTempEventHookData
;
1844 ImplEventHook
* pEventHookData
= pSVData
->maAppData
.mpFirstEventHook
;
1845 while ( pEventHookData
)
1847 pTempEventHookData
= pEventHookData
->mpNext
;
1848 delete pEventHookData
;
1849 pEventHookData
= pTempEventHookData
;
1852 pSVData
->maAppData
.mpFirstEventHook
= NULL
;
1855 // -----------------------------------------------------------------------
1857 ULONG
Application::AddEventHook( VCLEventHookProc pProc
, void* pData
)
1859 ImplSVData
* pSVData
= ImplGetSVData();
1860 ImplEventHook
* pEventHookData
= new ImplEventHook
;
1861 pEventHookData
->mpUserData
= pData
;
1862 pEventHookData
->mpProc
= pProc
;
1863 pEventHookData
->mpNext
= pSVData
->maAppData
.mpFirstEventHook
;
1864 pSVData
->maAppData
.mpFirstEventHook
= pEventHookData
;
1865 return (ULONG
)pEventHookData
;
1868 // -----------------------------------------------------------------------
1870 void Application::RemoveEventHook( ULONG nId
)
1872 ImplSVData
* pSVData
= ImplGetSVData();
1873 ImplEventHook
* pFindEventHookData
= (ImplEventHook
*)nId
;
1874 ImplEventHook
* pPrevEventHookData
= NULL
;
1875 ImplEventHook
* pEventHookData
= pSVData
->maAppData
.mpFirstEventHook
;
1876 while ( pEventHookData
)
1878 if ( pEventHookData
== pFindEventHookData
)
1880 if ( pPrevEventHookData
)
1881 pPrevEventHookData
->mpNext
= pFindEventHookData
->mpNext
;
1883 pSVData
->maAppData
.mpFirstEventHook
= pFindEventHookData
->mpNext
;
1884 delete pFindEventHookData
;
1888 pPrevEventHookData
= pEventHookData
;
1889 pEventHookData
= pEventHookData
->mpNext
;
1892 DBG_ASSERT( pEventHookData
, "Application::RemoveEventHook() - EventHook is not added" );
1895 // -----------------------------------------------------------------------
1897 long Application::CallEventHooks( NotifyEvent
& rEvt
)
1899 ImplSVData
* pSVData
= ImplGetSVData();
1901 ImplEventHook
* pTempEventHookData
;
1902 ImplEventHook
* pEventHookData
= pSVData
->maAppData
.mpFirstEventHook
;
1903 while ( pEventHookData
)
1905 pTempEventHookData
= pEventHookData
->mpNext
;
1906 nRet
= pEventHookData
->mpProc( rEvt
, pEventHookData
->mpUserData
);
1909 pEventHookData
= pTempEventHookData
;
1915 // -----------------------------------------------------------------------
1917 long Application::CallPreNotify( NotifyEvent
& rEvt
)
1919 return ImplCallPreNotify( rEvt
);
1922 // -----------------------------------------------------------------------
1924 long Application::CallEvent( NotifyEvent
& rEvt
)
1926 return ImplCallEvent( rEvt
);
1929 // -----------------------------------------------------------------------
1931 const LocaleDataWrapper
& Application::GetAppLocaleDataWrapper()
1933 return GetSettings().GetLocaleDataWrapper();
1936 // -----------------------------------------------------------------------
1938 void Application::EnableHeadlessMode( BOOL bEnable
)
1940 EnableDialogCancel( bEnable
);
1943 // -----------------------------------------------------------------------
1945 BOOL
Application::IsHeadlessModeEnabled()
1947 return IsDialogCancelEnabled();
1950 // -----------------------------------------------------------------------
1952 void Application::ShowNativeErrorBox(const String
& sTitle
,
1953 const String
& sMessage
)
1955 ImplGetSalSystem()->ShowNativeMessageBox (
1958 SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK
,
1959 SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK
);
1962 // -----------------------------------------------------------------------
1964 bool Application::CanToggleImeStatusWindow()
1966 ImplSVData
* pSVData
= ImplGetSVData();
1967 if( ! pSVData
->mpImeStatus
)
1968 pSVData
->mpImeStatus
= pSVData
->mpDefInst
->CreateI18NImeStatus();
1969 return pSVData
->mpImeStatus
->canToggle();
1972 void Application::ShowImeStatusWindow(bool bShow
)
1974 ImplGetSVData()->maAppData
.meShowImeStatusWindow
= bShow
1975 ? ImplSVAppData::ImeStatusWindowMode_SHOW
1976 : ImplSVAppData::ImeStatusWindowMode_HIDE
;
1978 ImplSVData
* pSVData
= ImplGetSVData();
1979 if( ! pSVData
->mpImeStatus
)
1980 pSVData
->mpImeStatus
= pSVData
->mpDefInst
->CreateI18NImeStatus();
1981 pSVData
->mpImeStatus
->toggle();
1984 bool Application::GetShowImeStatusWindowDefault()
1986 rtl_TextEncodingInfo aInfo
;
1987 aInfo
.StructSize
= sizeof aInfo
;
1988 return rtl_getTextEncodingInfo(osl_getThreadTextEncoding(), &aInfo
)
1989 && aInfo
.MaximumCharSize
> 1;
1992 const ::rtl::OUString
& Application::GetDesktopEnvironment()
1994 return SalGetDesktopEnvironment();
1997 void Application::AddToRecentDocumentList(const rtl::OUString
& rFileUrl
, const rtl::OUString
& rMimeType
)
1999 ImplSVData
* pSVData
= ImplGetSVData();
2000 pSVData
->mpDefInst
->AddToRecentDocumentList(rFileUrl
, rMimeType
);
2003 BOOL
Application::IsAccessibilityEnabled()
2008 BOOL
InitAccessBridge( BOOL bShowCancel
, BOOL
&rCancelled
)
2012 // Disable Java bridge on UNIX
2014 (void) bShowCancel
; // unsued
2015 (void) rCancelled
; // unused
2017 bRet
= ImplInitAccessBridge( bShowCancel
, rCancelled
);
2019 if( !bRet
&& bShowCancel
&& !rCancelled
)
2021 // disable accessibility if the user chooses to continue
2022 AllSettings aSettings
= Application::GetSettings();
2023 MiscSettings aMisc
= aSettings
.GetMiscSettings();
2024 aMisc
.SetEnableATToolSupport( FALSE
);
2025 aSettings
.SetMiscSettings( aMisc
);
2026 Application::SetSettings( aSettings
);
2033 // MT: AppProperty, AppEvent was in oldsv.cxx, but is still needed...
2034 // ------------------------------------------------------------------------
2036 TYPEINIT0(ApplicationProperty
)
2038 // ------------------------------------------------------------------------
2040 static PropertyHandler
* pHandler
=NULL
;
2042 void Application::Property( ApplicationProperty
& rProp
)
2045 pHandler
->Property( rProp
);
2048 void Application::SetPropertyHandler( PropertyHandler
* p
)
2057 void Application::AppEvent( const ApplicationEvent
& /*rAppEvent*/ )