bump product version to 4.2.0.1
[LibreOffice.git] / include / vcl / svapp.hxx
blob385cedbca30535680e19e99674d55d12e2f08ff8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_SVAPP_HXX
21 #define INCLUDED_VCL_SVAPP_HXX
23 #include <config_features.h>
25 #include <sal/config.h>
27 #include <cassert>
28 #include <stdexcept>
29 #include <vector>
31 #include <comphelper/solarmutex.hxx>
32 #include <rtl/ustring.hxx>
33 #include <osl/thread.hxx>
34 #include <tools/link.hxx>
35 #include <tools/solar.h>
36 #include <vcl/dllapi.h>
37 #include <vcl/apptypes.hxx>
38 #include <vcl/settings.hxx>
39 #include <vcl/vclevent.hxx>
41 class BitmapEx;
42 class Link;
43 class AllSettings;
44 class DataChangedEvent;
45 class Accelerator;
46 class Help;
47 class OutputDevice;
48 class Window;
49 class WorkWindow;
50 class MenuBar;
51 class UnoWrapperBase;
52 class Reflection;
53 class KeyCode;
54 class NotifyEvent;
55 class KeyEvent;
56 class MouseEvent;
57 class ZoomEvent;
58 class ScrollEvent;
60 #include <com/sun/star/uno/Reference.h>
61 #include <com/sun/star/connection/XConnection.hpp>
63 namespace com {
64 namespace sun {
65 namespace star {
66 namespace uno {
67 class XComponentContext;
69 namespace ui {
70 namespace dialogs {
71 class XFilePicker2;
72 class XFolderPicker2;
75 namespace awt {
76 class XToolkit;
77 class XDisplayConnection;
79 } } }
81 // helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
82 VCL_DLLPUBLIC sal_UCS4 GetMirroredChar( sal_UCS4 );
83 VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar( sal_UCS4, LanguageType );
85 #define SYSTEMWINDOW_MODE_NOAUTOMODE ((sal_uInt16)0x0001)
86 #define SYSTEMWINDOW_MODE_DIALOG ((sal_uInt16)0x0002)
88 typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
90 // ATTENTION: ENUM duplicate in daemon.cxx under Unix!
92 #ifdef UNX
93 enum Service { SERVICE_OLE, SERVICE_APPEVENT, SERVICE_IPC };
94 #endif
96 class VCL_DLLPUBLIC ApplicationEvent
98 public:
99 enum Type {
100 TYPE_ACCEPT, TYPE_APPEAR, TYPE_HELP, TYPE_VERSION, TYPE_OPEN,
101 TYPE_OPENHELPURL, TYPE_PRINT, TYPE_PRIVATE_DOSHUTDOWN, TYPE_QUICKSTART,
102 TYPE_SHOWDIALOG, TYPE_UNACCEPT
105 explicit ApplicationEvent(Type type): aEvent(type) {
106 assert(
107 type == TYPE_APPEAR || type == TYPE_VERSION
108 || type == TYPE_PRIVATE_DOSHUTDOWN || type == TYPE_QUICKSTART);
111 ApplicationEvent(Type type, OUString const & data): aEvent(type) {
112 assert(
113 type == TYPE_ACCEPT || type == TYPE_HELP || type == TYPE_OPENHELPURL
114 || type == TYPE_SHOWDIALOG || type == TYPE_UNACCEPT);
115 aData.push_back(data);
118 ApplicationEvent(Type type, std::vector<OUString> const & data):
119 aEvent(type), aData(data)
120 { assert(type == TYPE_OPEN || type == TYPE_PRINT); }
122 Type GetEvent() const { return aEvent; }
124 OUString GetStringData() const {
125 assert(
126 aEvent == TYPE_ACCEPT || aEvent == TYPE_HELP
127 || aEvent == TYPE_OPENHELPURL || aEvent == TYPE_SHOWDIALOG
128 || aEvent == TYPE_UNACCEPT);
129 assert(aData.size() == 1);
130 return aData[0];
133 std::vector<OUString> const & GetStringsData() const {
134 assert(aEvent == TYPE_OPEN || aEvent == TYPE_PRINT);
135 return aData;
138 private:
139 Type aEvent;
140 std::vector<OUString> aData;
144 class VCL_DLLPUBLIC Application
146 public:
147 enum DialogCancelMode {
148 DIALOG_CANCEL_OFF, ///< do not automatically cancel dialogs
149 DIALOG_CANCEL_SILENT, ///< silently cancel any dialogs
150 DIALOG_CANCEL_FATAL
151 ///< cancel any dialogs by std::abort
154 Application();
155 virtual ~Application();
157 virtual int Main() = 0;
159 virtual sal_Bool QueryExit();
161 virtual void UserEvent( sal_uLong nEvent, void* pEventData );
163 virtual void FocusChanged();
164 virtual void DataChanged( const DataChangedEvent& rDCEvt );
166 virtual void Init();
167 virtual void InitFinished();
168 virtual void DeInit();
170 static sal_uInt16 GetCommandLineParamCount();
171 static OUString GetCommandLineParam( sal_uInt16 nParam );
172 static OUString GetAppFileName();
174 virtual sal_uInt16 Exception( sal_uInt16 nError );
175 static void Abort( const OUString& rErrorText );
177 static void Execute();
178 static void Quit();
179 static void Reschedule( bool bAllEvents = false );
180 static void Yield();
181 static void EndYield();
182 static comphelper::SolarMutex& GetSolarMutex();
183 static oslThreadIdentifier GetMainThreadIdentifier();
184 static sal_uLong ReleaseSolarMutex();
185 static void AcquireSolarMutex( sal_uLong nCount );
186 static void EnableNoYieldMode( bool i_bNoYield );
187 static void AddPostYieldListener( const Link& i_rListener );
188 static void RemovePostYieldListener( const Link& i_rListener );
190 static sal_Bool IsInMain();
191 static sal_Bool IsInExecute();
192 static sal_Bool IsInModalMode();
194 static sal_uInt16 GetDispatchLevel();
195 static bool AnyInput( sal_uInt16 nType = VCL_INPUT_ANY );
196 static sal_uLong GetLastInputInterval();
197 static sal_Bool IsUICaptured();
199 virtual void SystemSettingsChanging( AllSettings& rSettings,
200 Window* pFrame );
201 static void MergeSystemSettings( AllSettings& rSettings );
202 /** validate that the currently selected system UI font is suitable
203 to display the application's UI.
205 A localized test string will be checked if it can be displayed
206 in the currently selected system UI font. If no glyphs are
207 missing it can be assumed that the font is proper for display
208 of the application's UI.
210 @returns
211 <TRUE/> if the system font is suitable for our UI
212 <FALSE/> if the test string could not be displayed with the system font
214 static bool ValidateSystemFont();
216 static void SetSettings( const AllSettings& rSettings );
217 static const AllSettings& GetSettings();
218 static void NotifyAllWindows( DataChangedEvent& rDCEvt );
220 static void AddEventListener( const Link& rEventListener );
221 static void RemoveEventListener( const Link& rEventListener );
222 static void AddKeyListener( const Link& rKeyListener );
223 static void RemoveKeyListener( const Link& rKeyListener );
224 static void ImplCallEventListeners( sal_uLong nEvent, Window* pWin, void* pData );
225 static void ImplCallEventListeners( VclSimpleEvent* pEvent );
226 static sal_Bool HandleKey( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent );
228 static sal_uLong PostKeyEvent( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent );
229 static sal_uLong PostMouseEvent( sal_uLong nEvent, Window *pWin, MouseEvent* pMouseEvent );
230 #if !HAVE_FEATURE_DESKTOP
231 static sal_uLong PostZoomEvent( sal_uLong nEvent, Window *pWin, ZoomEvent* pZoomEvent );
232 static sal_uLong PostScrollEvent( sal_uLong nEvent, Window *pWin, ScrollEvent* pScrollEvent );
233 #endif
234 static void RemoveMouseAndKeyEvents( Window *pWin );
236 static sal_uLong PostUserEvent( const Link& rLink, void* pCaller = NULL );
237 static sal_Bool PostUserEvent( sal_uLong& rEventId, const Link& rLink, void* pCaller = NULL );
238 static void RemoveUserEvent( sal_uLong nUserEvent );
240 static sal_Bool InsertIdleHdl( const Link& rLink, sal_uInt16 nPriority );
241 static void RemoveIdleHdl( const Link& rLink );
243 virtual void AppEvent( const ApplicationEvent& rAppEvent );
245 static WorkWindow* GetAppWindow();
246 static Window* GetFocusWindow();
247 static OutputDevice* GetDefaultDevice();
249 static Window* GetFirstTopLevelWindow();
250 static Window* GetNextTopLevelWindow( Window* pWindow );
252 static long GetTopWindowCount();
253 static Window* GetTopWindow( long nIndex );
254 static Window* GetActiveTopWindow();
256 static void SetAppName( const OUString& rUniqueName );
257 static OUString GetAppName();
258 static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
260 // default name of the application for message dialogs and printing
261 static void SetDisplayName( const OUString& rDisplayName );
262 static OUString GetDisplayName();
265 static unsigned int GetScreenCount();
266 static Rectangle GetScreenPosSizePixel( unsigned int nScreen );
268 // IsUnifiedDisplay returns:
269 // true: screens form up one large display area
270 // windows can be moved between single screens
271 // (e.g. Xserver with Xinerama, Windows)
272 // false: different screens are separate and windows cannot be moved
273 // between them (e.g. Xserver with multiple screens)
274 static bool IsUnifiedDisplay();
275 // if IsUnifiedDisplay() == true the return value will be
276 // nearest screen of the target rectangle
277 // in case of IsUnifiedDisplay() == false the return value
278 // will always be GetDisplayDefaultScreen()
279 SAL_DLLPRIVATE static unsigned int GetBestScreen( const Rectangle& );
280 // This returns the LCD screen number for a laptop, or the primary
281 // external VGA display for a desktop machine - it is where a presenter
282 // console should be rendered if there are other (non-built-in) screens
283 // present.
284 static unsigned int GetDisplayBuiltInScreen();
285 // Practically, this means - Get the screen we should run a presentation on.
286 static unsigned int GetDisplayExternalScreen();
288 static const LocaleDataWrapper& GetAppLocaleDataWrapper();
290 static sal_Bool InsertAccel( Accelerator* pAccel );
291 static void RemoveAccel( Accelerator* pAccel );
293 static long CallEventHooks( NotifyEvent& rEvt );
295 static void SetHelp( Help* pHelp = NULL );
296 static Help* GetHelp();
298 static void EnableAutoHelpId( sal_Bool bEnabled = sal_True );
299 static sal_Bool IsAutoHelpIdEnabled();
301 static void EnableAutoMnemonic( sal_Bool bEnabled = sal_True );
302 static sal_Bool IsAutoMnemonicEnabled();
304 static sal_uLong GetReservedKeyCodeCount();
305 static const KeyCode* GetReservedKeyCode( sal_uLong i );
307 static void SetDefDialogParent( Window* pWindow );
308 static Window* GetDefDialogParent();
310 static DialogCancelMode GetDialogCancelMode();
311 static void SetDialogCancelMode( DialogCancelMode mode );
312 static sal_Bool IsDialogCancelEnabled();
314 static void SetSystemWindowMode( sal_uInt16 nMode );
315 static sal_uInt16 GetSystemWindowMode();
317 static void SetDialogScaleX( short nScale );
319 static ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayConnection > GetDisplayConnection();
321 // The global service manager has to be created before!
322 static ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > GetVCLToolkit();
323 static UnoWrapperBase* GetUnoWrapper( sal_Bool bCreateIfNotExists = sal_True );
324 static void SetUnoWrapper( UnoWrapperBase* pWrapper );
326 static void SetFilterHdl( const Link& rLink );
327 static const Link& GetFilterHdl();
329 static void EnableHeadlessMode( bool dialogsAreFatal );
330 static sal_Bool IsHeadlessModeEnabled();
331 /// check command line arguments for --headless
332 static bool IsHeadlessModeRequested();
333 /// used to disable Mac specific app init that requires an app bundle
334 static void EnableConsoleOnly();
335 /// used to see if Mac specific app init has been disabled
336 static bool IsConsoleOnly();
338 static void ShowNativeErrorBox(const OUString& sTitle ,
339 const OUString& sMessage);
341 // IME Status Window Control:
343 /** Return true if any IME status window can be toggled on and off
344 externally.
346 Must only be called with the Solar mutex locked.
348 static bool CanToggleImeStatusWindow();
350 /** Toggle any IME status window on and off.
352 This only works if CanToggleImeStatusWinodw returns true (otherwise,
353 any calls of this method are ignored).
355 Must only be called with the Solar mutex locked.
357 static void ShowImeStatusWindow(bool bShow);
359 /** Return true if any IME status window should be turned on by default
360 (this decision can be locale dependent, for example).
362 Can be called without the Solar mutex locked.
364 static bool GetShowImeStatusWindowDefault();
366 /** Returns a string representing the desktop environment
367 the process is currently running in.
369 static const OUString& GetDesktopEnvironment();
371 /** Add a file to the system shells recent document list if there is any.
372 This function may have no effect under Unix because there is no
373 standard API among the different desktop managers.
375 @param rFileUrl
376 The file url of the document.
378 @param rMimeType
379 The mime content type of the document specified by aFileUrl.
380 If an empty string will be provided "application/octet-stream"
381 will be used.
383 static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
385 /** Do we have a native / system file selector available ?
387 static bool hasNativeFileSelection();
389 /** Create a platform specific file picker, if one is available,
390 otherwise return an empty reference
392 static com::sun::star::uno::Reference< com::sun::star::ui::dialogs::XFilePicker2 >
393 createFilePicker( const com::sun::star::uno::Reference<
394 com::sun::star::uno::XComponentContext >& rServiceManager );
396 /** Create a platform specific folder picker, if one is available,
397 otherwise return an empty reference
399 static com::sun::star::uno::Reference< com::sun::star::ui::dialogs::XFolderPicker2 >
400 createFolderPicker( const com::sun::star::uno::Reference<
401 com::sun::star::uno::XComponentContext >& rServiceManager );
403 static bool IsEnableAccessInterface() {return true;}
405 private:
407 DECL_STATIC_LINK( Application, PostEventHandler, void* );
411 class VCL_DLLPUBLIC SolarMutexGuard
413 private:
414 SolarMutexGuard( const SolarMutexGuard& );
415 const SolarMutexGuard& operator = ( const SolarMutexGuard& );
416 comphelper::SolarMutex& m_solarMutex;
418 public:
420 /** Acquires the object specified as parameter.
422 SolarMutexGuard() :
423 m_solarMutex(Application::GetSolarMutex())
425 m_solarMutex.acquire();
428 /** Releases the mutex or interface. */
429 ~SolarMutexGuard()
431 m_solarMutex.release();
435 class VCL_DLLPUBLIC SolarMutexClearableGuard
437 SolarMutexClearableGuard( const SolarMutexClearableGuard& );
438 const SolarMutexClearableGuard& operator = ( const SolarMutexClearableGuard& );
439 bool m_bCleared;
440 public:
441 /** Acquires mutex
442 @param pMutex pointer to mutex which is to be acquired */
443 SolarMutexClearableGuard()
444 : m_bCleared(false)
445 , m_solarMutex( Application::GetSolarMutex() )
447 m_solarMutex.acquire();
450 /** Releases mutex. */
451 virtual ~SolarMutexClearableGuard()
453 if( !m_bCleared )
455 m_solarMutex.release();
459 /** Releases mutex. */
460 void SAL_CALL clear()
462 if( !m_bCleared )
464 m_solarMutex.release();
465 m_bCleared = true;
468 protected:
469 comphelper::SolarMutex& m_solarMutex;
472 class VCL_DLLPUBLIC SolarMutexResettableGuard
474 SolarMutexResettableGuard( const SolarMutexResettableGuard& );
475 const SolarMutexResettableGuard& operator = ( const SolarMutexResettableGuard& );
476 bool m_bCleared;
477 public:
478 /** Acquires mutex
479 @param pMutex pointer to mutex which is to be acquired */
480 SolarMutexResettableGuard()
481 : m_bCleared(false)
482 , m_solarMutex( Application::GetSolarMutex() )
484 m_solarMutex.acquire();
487 /** Releases mutex. */
488 virtual ~SolarMutexResettableGuard()
490 if( !m_bCleared )
492 m_solarMutex.release();
496 /** Releases mutex. */
497 void SAL_CALL clear()
499 if( !m_bCleared)
501 m_solarMutex.release();
502 m_bCleared = true;
505 /** Releases mutex. */
506 void SAL_CALL reset()
508 if( m_bCleared)
510 m_solarMutex.acquire();
511 m_bCleared = false;
514 protected:
515 comphelper::SolarMutex& m_solarMutex;
520 A helper class that calls Application::ReleaseSolarMutex() in its constructor
521 and restores the mutex in its destructor.
523 class SolarMutexReleaser
525 sal_uLong mnReleased;
527 public:
528 SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
530 ~SolarMutexReleaser()
532 Application::AcquireSolarMutex( mnReleased );
536 VCL_DLLPUBLIC Application* GetpApp();
538 VCL_DLLPUBLIC bool InitVCL();
539 VCL_DLLPUBLIC void DeInitVCL();
541 VCL_DLLPUBLIC bool InitAccessBridge( bool bAllowCancel, bool &rCancelled );
543 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
544 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
545 VCL_DLLPUBLIC void JoinMainLoopThread();
547 inline void Application::EndYield()
549 PostUserEvent( Link() );
552 #endif // _APP_HXX
554 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */