LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/vcl - svapp.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 39 50 78.0 %
Date: 2013-07-09 Functions: 10 18 55.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef _SV_SVAPP_HXX
      21             : #define _SV_SVAPP_HXX
      22             : 
      23             : #include <config_features.h>
      24             : 
      25             : #include <sal/config.h>
      26             : 
      27             : #include <stdexcept>
      28             : 
      29             : #include <comphelper/solarmutex.hxx>
      30             : #include <osl/thread.hxx>
      31             : #include <tools/string.hxx>
      32             : #include <tools/link.hxx>
      33             : #include <tools/solar.h>
      34             : #include <vcl/dllapi.h>
      35             : #include <vcl/apptypes.hxx>
      36             : #include <vcl/settings.hxx>
      37             : #include <vcl/vclevent.hxx>
      38             : 
      39             : class BitmapEx;
      40             : class Link;
      41             : class AllSettings;
      42             : class DataChangedEvent;
      43             : class Accelerator;
      44             : class Help;
      45             : class OutputDevice;
      46             : class Window;
      47             : class WorkWindow;
      48             : class MenuBar;
      49             : class UnoWrapperBase;
      50             : class Reflection;
      51             : class KeyCode;
      52             : class NotifyEvent;
      53             : class KeyEvent;
      54             : class MouseEvent;
      55             : class ZoomEvent;
      56             : class ScrollEvent;
      57             : 
      58             : #include <com/sun/star/uno/Reference.h>
      59             : #include <com/sun/star/connection/XConnection.hpp>
      60             : 
      61             : namespace com {
      62             : namespace sun {
      63             : namespace star {
      64             : namespace uno {
      65             :     class XComponentContext;
      66             : }
      67             : namespace ui {
      68             :     namespace dialogs {
      69             :         class XFilePicker2;
      70             :         class XFolderPicker2;
      71             :     }
      72             : }
      73             : namespace awt {
      74             :     class XToolkit;
      75             :     class XDisplayConnection;
      76             : }
      77             : } } }
      78             : 
      79             : // helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
      80             : VCL_DLLPUBLIC sal_UCS4 GetMirroredChar( sal_UCS4 );
      81             : VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar( sal_UCS4, LanguageType );
      82             : 
      83             : #define SYSTEMWINDOW_MODE_NOAUTOMODE    ((sal_uInt16)0x0001)
      84             : #define SYSTEMWINDOW_MODE_DIALOG        ((sal_uInt16)0x0002)
      85             : 
      86             : typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
      87             : 
      88             : // ATTENTION: ENUM duplicate in daemon.cxx under Unix!
      89             : 
      90             : #ifdef UNX
      91             : enum Service { SERVICE_OLE, SERVICE_APPEVENT, SERVICE_IPC };
      92             : #endif
      93             : 
      94           0 : class VCL_DLLPUBLIC ApplicationEvent
      95             : {
      96             : public:
      97             :     enum Type {
      98             :         TYPE_ACCEPT, TYPE_APPEAR, TYPE_HELP, TYPE_VERSION, TYPE_OPEN,
      99             :         TYPE_OPENHELPURL, TYPE_PRINT, TYPE_PRIVATE_DOSHUTDOWN, TYPE_QUICKSTART,
     100             :         TYPE_SHOWDIALOG, TYPE_UNACCEPT
     101             :     };
     102             : 
     103             :     ApplicationEvent() {}
     104             : 
     105           0 :     explicit ApplicationEvent(
     106             :         Type rEvent, const OUString& rData = OUString()):
     107             :         aEvent(rEvent),
     108           0 :         aData(rData)
     109           0 :     {}
     110             : 
     111           0 :     Type GetEvent() const { return aEvent; }
     112           0 :     const OUString& GetData() const { return aData; }
     113             : 
     114             : private:
     115             :     Type aEvent;
     116             :     OUString aData;
     117             : };
     118             : 
     119             : 
     120             : class VCL_DLLPUBLIC Application
     121             : {
     122             : public:
     123             :     enum DialogCancelMode {
     124             :         DIALOG_CANCEL_OFF, ///< do not automatically cancel dialogs
     125             :         DIALOG_CANCEL_SILENT, ///< silently cancel any dialogs
     126             :         DIALOG_CANCEL_FATAL
     127             :             ///< cancel any dialogs by std::abort
     128             :     };
     129             : 
     130             :                                 Application();
     131             :     virtual                     ~Application();
     132             : 
     133             :     virtual int                 Main() = 0;
     134             : 
     135             :     virtual sal_Bool                QueryExit();
     136             : 
     137             :     virtual void                UserEvent( sal_uLong nEvent, void* pEventData );
     138             : 
     139             :     virtual void                FocusChanged();
     140             :     virtual void                DataChanged( const DataChangedEvent& rDCEvt );
     141             : 
     142             :     virtual void                Init();
     143             :     virtual void                InitFinished();
     144             :     virtual void                DeInit();
     145             : 
     146             :     static sal_uInt16           GetCommandLineParamCount();
     147             :     static OUString             GetCommandLineParam( sal_uInt16 nParam );
     148             :     static OUString             GetAppFileName();
     149             : 
     150             :     virtual sal_uInt16          Exception( sal_uInt16 nError );
     151             :     static void                 Abort( const OUString& rErrorText );
     152             : 
     153             :     static void                 Execute();
     154             :     static void                 Quit();
     155             :     static void                 Reschedule( bool bAllEvents = false );
     156             :     static void                 Yield( bool bAllEvents = false );
     157             :     static void                 EndYield();
     158             :     static comphelper::SolarMutex& GetSolarMutex();
     159             :     static oslThreadIdentifier  GetMainThreadIdentifier();
     160             :     static sal_uLong                ReleaseSolarMutex();
     161             :     static void                 AcquireSolarMutex( sal_uLong nCount );
     162             :     static void                 EnableNoYieldMode( bool i_bNoYield );
     163             :     static void                 AddPostYieldListener( const Link& i_rListener );
     164             :     static void                 RemovePostYieldListener( const Link& i_rListener );
     165             : 
     166             :     static sal_Bool                 IsInMain();
     167             :     static sal_Bool                 IsInExecute();
     168             :     static sal_Bool                 IsInModalMode();
     169             : 
     170             :     static sal_uInt16               GetDispatchLevel();
     171             :     static bool                 AnyInput( sal_uInt16 nType = VCL_INPUT_ANY );
     172             :     static sal_uLong                GetLastInputInterval();
     173             :     static sal_Bool                 IsUICaptured();
     174             : 
     175             :     virtual void                SystemSettingsChanging( AllSettings& rSettings,
     176             :                                                         Window* pFrame );
     177             :     static void                 MergeSystemSettings( AllSettings& rSettings );
     178             :     /** validate that the currently selected system UI font is suitable
     179             :         to display the application's UI.
     180             : 
     181             :         A localized test string will be checked if it can be displayed
     182             :         in the currently selected system UI font. If no glyphs are
     183             :         missing it can be assumed that the font is proper for display
     184             :         of the application's UI.
     185             : 
     186             :         @returns
     187             :         <TRUE/> if the system font is suitable for our UI
     188             :         <FALSE/> if the test string could not be displayed with the system font
     189             :      */
     190             :     static bool                 ValidateSystemFont();
     191             : 
     192             :     static void                 SetSettings( const AllSettings& rSettings );
     193             :     static const AllSettings&   GetSettings();
     194             :     static void                 NotifyAllWindows( DataChangedEvent& rDCEvt );
     195             : 
     196             :     static void                 AddEventListener( const Link& rEventListener );
     197             :     static void                 RemoveEventListener( const Link& rEventListener );
     198             :     static void                 AddKeyListener( const Link& rKeyListener );
     199             :     static void                 RemoveKeyListener( const Link& rKeyListener );
     200             :     static void                 ImplCallEventListeners( sal_uLong nEvent, Window* pWin, void* pData );
     201             :     static void                 ImplCallEventListeners( VclSimpleEvent* pEvent );
     202             :     static sal_Bool                 HandleKey( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent );
     203             : 
     204             :     static sal_uLong                PostKeyEvent( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent );
     205             :     static sal_uLong                PostMouseEvent( sal_uLong nEvent, Window *pWin, MouseEvent* pMouseEvent );
     206             : #if !HAVE_FEATURE_DESKTOP
     207             :     static sal_uLong            PostZoomEvent( sal_uLong nEvent, Window *pWin, ZoomEvent* pZoomEvent );
     208             :     static sal_uLong            PostScrollEvent( sal_uLong nEvent, Window *pWin, ScrollEvent* pScrollEvent );
     209             : #endif
     210             :     static void                 RemoveMouseAndKeyEvents( Window *pWin );
     211             : 
     212             :     static sal_uLong                PostUserEvent( const Link& rLink, void* pCaller = NULL );
     213             :     static sal_Bool                 PostUserEvent( sal_uLong& rEventId, const Link& rLink, void* pCaller = NULL );
     214             :     static void                 RemoveUserEvent( sal_uLong nUserEvent );
     215             : 
     216             :     static sal_Bool                 InsertIdleHdl( const Link& rLink, sal_uInt16 nPriority );
     217             :     static void                 RemoveIdleHdl( const Link& rLink );
     218             : 
     219             :     virtual void                AppEvent( const ApplicationEvent& rAppEvent );
     220             : 
     221             : #ifndef NO_GETAPPWINDOW
     222             :     static WorkWindow*          GetAppWindow();
     223             : #endif
     224             : 
     225             :     static Window*              GetFocusWindow();
     226             :     static OutputDevice*        GetDefaultDevice();
     227             : 
     228             :     static Window*              GetFirstTopLevelWindow();
     229             :     static Window*              GetNextTopLevelWindow( Window* pWindow );
     230             : 
     231             :     static long                 GetTopWindowCount();
     232             :     static Window*              GetTopWindow( long nIndex );
     233             :     static Window*              GetActiveTopWindow();
     234             : 
     235             :     static void                 SetAppName( const String& rUniqueName );
     236             :     static String               GetAppName();
     237             :     static bool                 LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
     238             : 
     239             :     // default name of the application for message dialogs and printing
     240             :     static void                 SetDisplayName( const OUString& rDisplayName );
     241             :     static OUString             GetDisplayName();
     242             : 
     243             : 
     244             :     static unsigned int         GetScreenCount();
     245             :     static Rectangle            GetScreenPosSizePixel( unsigned int nScreen );
     246             : 
     247             :     // IsUnifiedDisplay returns:
     248             :     //        true:  screens form up one large display area
     249             :     //               windows can be moved between single screens
     250             :     //               (e.g. Xserver with Xinerama, Windows)
     251             :     //        false: different screens are separate and windows cannot be moved
     252             :     //               between them (e.g. Xserver with multiple screens)
     253             :     static bool          IsUnifiedDisplay();
     254             :     // if IsUnifiedDisplay() == true the return value will be
     255             :     // nearest screen of the target rectangle
     256             :     // in case of IsUnifiedDisplay() == false the return value
     257             :     // will always be GetDisplayDefaultScreen()
     258             :     SAL_DLLPRIVATE static unsigned int  GetBestScreen( const Rectangle& );
     259             :     static Rectangle     GetWorkAreaPosSizePixel( unsigned int nScreen );
     260             :     // This returns the LCD screen number for a laptop, or the primary
     261             :     // external VGA display for a desktop machine - it is where a presenter
     262             :     // console should be rendered if there are other (non-built-in) screens
     263             :     // present.
     264             :     static unsigned int  GetDisplayBuiltInScreen();
     265             :     // Practically, this means - Get the screen we should run a presentation on.
     266             :     static unsigned int  GetDisplayExternalScreen();
     267             : 
     268             :     static const LocaleDataWrapper& GetAppLocaleDataWrapper();
     269             : 
     270             :     static sal_Bool                 InsertAccel( Accelerator* pAccel );
     271             :     static void                 RemoveAccel( Accelerator* pAccel );
     272             : 
     273             :     static long                 CallEventHooks( NotifyEvent& rEvt );
     274             : 
     275             :     static void                 SetHelp( Help* pHelp = NULL );
     276             :     static Help*                GetHelp();
     277             : 
     278             :     static void                 EnableAutoHelpId( sal_Bool bEnabled = sal_True );
     279             :     static sal_Bool                 IsAutoHelpIdEnabled();
     280             : 
     281             :     static void                 EnableAutoMnemonic( sal_Bool bEnabled = sal_True );
     282             :     static sal_Bool                 IsAutoMnemonicEnabled();
     283             : 
     284             :     static sal_uLong                GetReservedKeyCodeCount();
     285             :     static const KeyCode*       GetReservedKeyCode( sal_uLong i );
     286             : 
     287             :     static void                 SetDefDialogParent( Window* pWindow );
     288             :     static Window*              GetDefDialogParent();
     289             : 
     290             :     static DialogCancelMode GetDialogCancelMode();
     291             :     static void SetDialogCancelMode( DialogCancelMode mode );
     292             :     static sal_Bool                 IsDialogCancelEnabled();
     293             : 
     294             :     static void                 SetSystemWindowMode( sal_uInt16 nMode );
     295             :     static sal_uInt16               GetSystemWindowMode();
     296             : 
     297             :     static void                 SetDialogScaleX( short nScale );
     298             : 
     299             :     static ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayConnection > GetDisplayConnection();
     300             : 
     301             :     // The global service manager has to be created before!
     302             :     static ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > GetVCLToolkit();
     303             :     static UnoWrapperBase*      GetUnoWrapper( sal_Bool bCreateIfNotExists = sal_True );
     304             :     static void                 SetUnoWrapper( UnoWrapperBase* pWrapper );
     305             : 
     306             :     static void                 SetFilterHdl( const Link& rLink );
     307             :     static const Link&          GetFilterHdl();
     308             : 
     309             :     static void                 EnableHeadlessMode( bool dialogsAreFatal );
     310             :     static sal_Bool             IsHeadlessModeEnabled();
     311             :     /// check command line arguments for --headless
     312             :     static bool                 IsHeadlessModeRequested();
     313             :     /// used to disable Mac specific app init that requires an app bundle
     314             :     static void                 EnableConsoleOnly();
     315             :     /// used to see if Mac specific app init has been disabled
     316             :     static bool                 IsConsoleOnly();
     317             : 
     318             :     static void                 ShowNativeErrorBox(const String& sTitle  ,
     319             :                                                    const String& sMessage);
     320             : 
     321             :     // IME Status Window Control:
     322             : 
     323             :     /** Return true if any IME status window can be toggled on and off
     324             :         externally.
     325             : 
     326             :         Must only be called with the Solar mutex locked.
     327             :      */
     328             :     static bool CanToggleImeStatusWindow();
     329             : 
     330             :     /** Toggle any IME status window on and off.
     331             : 
     332             :         This only works if CanToggleImeStatusWinodw returns true (otherwise,
     333             :         any calls of this method are ignored).
     334             : 
     335             :         Must only be called with the Solar mutex locked.
     336             :      */
     337             :     static void ShowImeStatusWindow(bool bShow);
     338             : 
     339             :     /** Return true if any IME status window should be turned on by default
     340             :         (this decision can be locale dependent, for example).
     341             : 
     342             :         Can be called without the Solar mutex locked.
     343             :      */
     344             :     static bool GetShowImeStatusWindowDefault();
     345             : 
     346             :     /** Returns a string representing the desktop environment
     347             :         the process is currently running in.
     348             :      */
     349             :     static const OUString& GetDesktopEnvironment();
     350             : 
     351             :     /** Add a file to the system shells recent document list if there is any.
     352             :           This function may have no effect under Unix because there is no
     353             :           standard API among the different desktop managers.
     354             : 
     355             :           @param rFileUrl
     356             :                     The file url of the document.
     357             : 
     358             :           @param rMimeType
     359             :           The mime content type of the document specified by aFileUrl.
     360             :           If an empty string will be provided "application/octet-stream"
     361             :           will be used.
     362             :     */
     363             :     static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType);
     364             : 
     365             :     /** Do we have a native / system file selector available ?
     366             :      */
     367             :     static bool hasNativeFileSelection();
     368             : 
     369             :     /** Create a platform specific file picker, if one is available,
     370             :         otherwise return an empty reference
     371             :     */
     372             :     static com::sun::star::uno::Reference< com::sun::star::ui::dialogs::XFilePicker2 >
     373             :         createFilePicker( const com::sun::star::uno::Reference<
     374             :                               com::sun::star::uno::XComponentContext >& rServiceManager );
     375             : 
     376             :     /** Create a platform specific folder picker, if one is available,
     377             :         otherwise return an empty reference
     378             :     */
     379             :     static com::sun::star::uno::Reference< com::sun::star::ui::dialogs::XFolderPicker2 >
     380             :         createFolderPicker( const com::sun::star::uno::Reference<
     381             :                               com::sun::star::uno::XComponentContext >& rServiceManager );
     382             : 
     383             : private:
     384             : 
     385             :     DECL_STATIC_LINK( Application, PostEventHandler, void* );
     386             : };
     387             : 
     388             : 
     389             : class VCL_DLLPUBLIC SolarMutexGuard
     390             : {
     391             :     private:
     392             :         SolarMutexGuard( const SolarMutexGuard& );
     393             :         const SolarMutexGuard& operator = ( const SolarMutexGuard& );
     394             :         comphelper::SolarMutex& m_solarMutex;
     395             : 
     396             :     public:
     397             : 
     398             :         /** Acquires the object specified as parameter.
     399             :          */
     400     4956842 :         SolarMutexGuard() :
     401     4956842 :         m_solarMutex(Application::GetSolarMutex())
     402             :     {
     403     4956842 :         m_solarMutex.acquire();
     404     4956842 :     }
     405             : 
     406             :     /** Releases the mutex or interface. */
     407     4956842 :     ~SolarMutexGuard()
     408             :     {
     409     4956842 :         m_solarMutex.release();
     410     4956842 :     }
     411             : };
     412             : 
     413             : class VCL_DLLPUBLIC SolarMutexClearableGuard
     414             : {
     415             :     SolarMutexClearableGuard( const SolarMutexClearableGuard& );
     416             :     const SolarMutexClearableGuard& operator = ( const SolarMutexClearableGuard& );
     417             :     bool m_bCleared;
     418             : public:
     419             :     /** Acquires mutex
     420             :         @param pMutex pointer to mutex which is to be acquired  */
     421        1215 :     SolarMutexClearableGuard()
     422             :         : m_bCleared(false)
     423        1215 :         , m_solarMutex( Application::GetSolarMutex() )
     424             :         {
     425        1215 :             m_solarMutex.acquire();
     426        1215 :         }
     427             : 
     428             :     /** Releases mutex. */
     429        1215 :     virtual ~SolarMutexClearableGuard()
     430        1215 :         {
     431        1215 :             if( !m_bCleared )
     432             :             {
     433          87 :                 m_solarMutex.release();
     434             :             }
     435        1215 :         }
     436             : 
     437             :     /** Releases mutex. */
     438        1128 :     void SAL_CALL clear()
     439             :         {
     440        1128 :             if( !m_bCleared )
     441             :             {
     442        1128 :                 m_solarMutex.release();
     443        1128 :                 m_bCleared = true;
     444             :             }
     445        1128 :         }
     446             : protected:
     447             :     comphelper::SolarMutex& m_solarMutex;
     448             : };
     449             : 
     450             : class VCL_DLLPUBLIC SolarMutexResettableGuard
     451             : {
     452             :     SolarMutexResettableGuard( const SolarMutexResettableGuard& );
     453             :     const SolarMutexResettableGuard& operator = ( const SolarMutexResettableGuard& );
     454             :     bool m_bCleared;
     455             : public:
     456             :     /** Acquires mutex
     457             :         @param pMutex pointer to mutex which is to be acquired  */
     458      342725 :     SolarMutexResettableGuard()
     459             :         : m_bCleared(false)
     460      342725 :         , m_solarMutex( Application::GetSolarMutex() )
     461             :         {
     462      342725 :             m_solarMutex.acquire();
     463      342725 :         }
     464             : 
     465             :     /** Releases mutex. */
     466      342725 :     virtual ~SolarMutexResettableGuard()
     467      342725 :         {
     468      342725 :             if( !m_bCleared )
     469             :             {
     470      342116 :                 m_solarMutex.release();
     471             :             }
     472      342725 :         }
     473             : 
     474             :     /** Releases mutex. */
     475         609 :     void SAL_CALL clear()
     476             :         {
     477         609 :             if( !m_bCleared)
     478             :             {
     479         609 :                 m_solarMutex.release();
     480         609 :                 m_bCleared = true;
     481             :             }
     482         609 :         }
     483             :     /** Releases mutex. */
     484           0 :     void SAL_CALL reset()
     485             :         {
     486           0 :             if( m_bCleared)
     487             :             {
     488           0 :                 m_solarMutex.acquire();
     489           0 :                 m_bCleared = false;
     490             :             }
     491           0 :         }
     492             : protected:
     493             :     comphelper::SolarMutex& m_solarMutex;
     494             : };
     495             : 
     496             : 
     497             : /**
     498             :  A helper class that calls Application::ReleaseSolarMutex() in its constructor
     499             :  and restores the mutex in its destructor.
     500             : */
     501             : class SolarMutexReleaser
     502             : {
     503             :     sal_uLong mnReleased;
     504             : 
     505             : public:
     506         126 :     SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
     507             : 
     508         126 :     ~SolarMutexReleaser()
     509             :     {
     510         126 :         Application::AcquireSolarMutex( mnReleased );
     511         126 :     }
     512             : };
     513             : 
     514             : VCL_DLLPUBLIC Application* GetpApp();
     515             : 
     516             : VCL_DLLPUBLIC bool InitVCL();
     517             : VCL_DLLPUBLIC void DeInitVCL();
     518             : 
     519             : VCL_DLLPUBLIC bool InitAccessBridge( bool bAllowCancel, bool &rCancelled );
     520             : 
     521             : // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
     522             : VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
     523             : VCL_DLLPUBLIC void JoinMainLoopThread();
     524             : 
     525             : inline void Application::EndYield()
     526             : {
     527             :     PostUserEvent( Link() );
     528             : }
     529             : 
     530             : #endif // _APP_HXX
     531             : 
     532             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10