xref: /trunk/main/vcl/inc/vcl/svapp.hxx (revision 4d7c9de0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_SVAPP_HXX
25 #define _SV_SVAPP_HXX
26 
27 #ifndef _VOS_THREAD_HXX
28 #include <vos/thread.hxx>
29 #endif
30 #include <tools/string.hxx>
31 #include <tools/link.hxx>
32 #include <tools/unqid.hxx>
33 #include <vcl/sv.h>
34 #include <vcl/dllapi.h>
35 #include <vcl/apptypes.hxx>
36 #ifndef _VCL_SETTINGS_HXX
37 #include <vcl/settings.hxx>
38 #endif
39 #include <vcl/vclevent.hxx>
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 
56 namespace vos { class IMutex; }
57 #include <com/sun/star/uno/Reference.h>
58 #include <com/sun/star/connection/XConnection.hpp>
59 
60 namespace com {
61 namespace sun {
62 namespace star {
63 namespace lang {
64     class XMultiServiceFactory;
65 }
66 namespace awt {
67     class XToolkit;
68     class XDisplayConnection;
69 }
70 } } }
71 
72 // helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
73 VCL_DLLPUBLIC sal_UCS4 GetMirroredChar( sal_UCS4 );
74 
75 // --------------------
76 // - SystemWindowMode -
77 // --------------------
78 
79 #define SYSTEMWINDOW_MODE_NOAUTOMODE    ((sal_uInt16)0x0001)
80 #define SYSTEMWINDOW_MODE_DIALOG        ((sal_uInt16)0x0002)
81 
82 // -------------
83 // - EventHook -
84 // -------------
85 
86 typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
87 
88 // --------------------
89 // - ApplicationEvent -
90 // --------------------
91 
92 // Erstmal wieder eingebaut, damit AppEvents auf dem MAC funktionieren
93 #ifdef UNX
94 // enum Doppelt in daemon.cxx unter unix Achtung !!!
95 enum Service { SERVICE_OLE, SERVICE_APPEVENT, SERVICE_IPC };
96 #endif
97 
98 class VCL_DLLPUBLIC ApplicationAddress
99 {
100 friend class Application;
101 protected:
102     UniString           aHostName;
103     UniString           aDisplayName;
104     UniString           aDomainName;
105     int                 nPID;
106 
107 public:
108                         ApplicationAddress();
109                         ApplicationAddress( const UniString& rDomain );
110                         ApplicationAddress( const UniString& rHost,
111                                             const UniString& rDisp,
112                                             const UniString& rDomain );
113                         ApplicationAddress( const UniString& rHost, int nPID );
114 
GetHost() const115     const UniString&    GetHost() const     { return aHostName; }
GetDisplay() const116     const UniString&    GetDisplay() const  { return aDisplayName; }
GetDomain() const117     const UniString&    GetDomain() const   { return aDomainName; }
GetPID() const118     int                 GetPID() const      { return nPID; }
119 
120     sal_Bool                IsConnectToSame( const ApplicationAddress& rAdr ) const;
121 };
122 
ApplicationAddress()123 inline ApplicationAddress::ApplicationAddress()
124 {
125     nPID = 0;
126 }
127 
ApplicationAddress(const UniString & rDomain)128 inline ApplicationAddress::ApplicationAddress( const UniString& rDomain )
129 {
130     aDomainName     = rDomain;
131     nPID            = 0;
132 }
133 
ApplicationAddress(const UniString & rHost,const UniString & rDisp,const UniString & rDomain)134 inline ApplicationAddress::ApplicationAddress( const UniString& rHost,
135                                                const UniString& rDisp,
136                                                const UniString& rDomain )
137 {
138     aHostName       = rHost;
139     aDisplayName    = rDisp;
140     aDomainName     = rDomain;
141     nPID            = 0;
142 }
143 
ApplicationAddress(const UniString & rHost,int nPIDPar)144 inline ApplicationAddress::ApplicationAddress( const UniString& rHost, int nPIDPar )
145 {
146     aHostName       = rHost;
147     nPID            = nPIDPar;
148 }
149 
IsConnectToSame(const ApplicationAddress & rAdr) const150 inline sal_Bool ApplicationAddress::IsConnectToSame( const ApplicationAddress& rAdr ) const
151 {
152     if ( nPID && ((nPID == rAdr.nPID) && (aHostName.Equals( rAdr.aHostName))) )
153         return sal_True;
154     else
155         return sal_False;
156 }
157 
158 #define APPEVENT_PARAM_DELIMITER    	'\n'
159 
160 #define APPEVENT_OPEN_STRING        	"Open"
161 #define APPEVENT_PRINT_STRING       	"Print"
162 #define APPEVENT_DISKINSERT_STRING  	"DiskInsert"
163 #define APPEVENT_SAVEDOCUMENTS_STRING	"SaveDocuments"
164 
165 class VCL_DLLPUBLIC ApplicationEvent
166 {
167 private:
168     UniString           aSenderAppName; // Absender Applikationsname
169     ByteString          aEvent;         // Event
170     UniString           aData;          // Uebertragene Daten
171     ApplicationAddress  aAppAddr;       // Absender Addresse
172 
173 public:
ApplicationEvent()174                         ApplicationEvent() {}
175                         ApplicationEvent( const UniString& rSenderAppName,
176                                           const ApplicationAddress& rAppAddr,
177                                           const ByteString& rEvent,
178                                           const UniString& rData );
179 
GetSenderAppName() const180     const UniString&    GetSenderAppName() const { return aSenderAppName; }
GetEvent() const181     const ByteString&   GetEvent() const { return aEvent; }
GetData() const182     const UniString&    GetData() const { return aData; }
GetAppAddress() const183     const ApplicationAddress& GetAppAddress() const { return aAppAddr; }
184 
185     sal_Bool                IsOpenEvent() const;
186     sal_Bool                IsPrintEvent() const;
187     sal_Bool                IsDiskInsertEvent() const;
188 
GetParamCount() const189     sal_uInt16              GetParamCount() const { return aData.GetTokenCount( APPEVENT_PARAM_DELIMITER ); }
GetParam(sal_uInt16 nParam) const190     UniString           GetParam( sal_uInt16 nParam ) const { return aData.GetToken( nParam, APPEVENT_PARAM_DELIMITER ); }
191 };
192 
ApplicationEvent(const UniString & rSenderAppName,const ApplicationAddress & rAppAddr,const ByteString & rEvent,const UniString & rData)193 inline ApplicationEvent::ApplicationEvent( const UniString& rSenderAppName,
194                                            const ApplicationAddress& rAppAddr,
195                                            const ByteString& rEvent,
196                                            const UniString& rData ) :
197     aSenderAppName( rSenderAppName ),
198     aEvent( rEvent ),
199     aData( rData ),
200     aAppAddr( rAppAddr )
201 {
202 }
203 
IsOpenEvent() const204 inline sal_Bool ApplicationEvent::IsOpenEvent() const
205 {
206     if ( aEvent.Equals( APPEVENT_OPEN_STRING ))
207         return sal_True;
208     else
209         return sal_False;
210 }
211 
IsPrintEvent() const212 inline sal_Bool ApplicationEvent::IsPrintEvent() const
213 {
214     if ( aEvent.Equals( APPEVENT_PRINT_STRING ))
215         return sal_True;
216     else
217         return sal_False;
218 }
219 
IsDiskInsertEvent() const220 inline sal_Bool ApplicationEvent::IsDiskInsertEvent() const
221 {
222     if ( aEvent.Equals( APPEVENT_DISKINSERT_STRING ))
223         return sal_True;
224     else
225         return sal_False;
226 }
227 
228 class VCL_DLLPUBLIC PropertyHandler
229 {
230 public:
231     virtual void                Property( ApplicationProperty& ) = 0;
232 };
233 
234 // ---------------
235 // - Application -
236 // ---------------
237 
238 class VCL_DLLPUBLIC Application
239 {
240 public:
241                                 Application();
242     virtual                     ~Application();
243 
244     virtual void                Main() = 0;
245 
246     virtual sal_Bool            QueryExit();
247 
248     virtual void                UserEvent( sal_uLong nEvent, void* pEventData );
249 
250     virtual void                ActivateExtHelp();
251     virtual void                DeactivateExtHelp();
252 
253     virtual void                ShowStatusText( const XubString& rText );
254     virtual void                HideStatusText();
255 
256     virtual void                ShowHelpStatusText( const XubString& rText );
257     virtual void                HideHelpStatusText();
258 
259     virtual void                FocusChanged();
260     virtual void                DataChanged( const DataChangedEvent& rDCEvt );
261 
262     virtual void                Init();
263     virtual void                DeInit();
264 
265     static void                 InitAppRes( const ResId& rResId );
266 
267     static sal_uInt16           GetCommandLineParamCount();
268     static XubString            GetCommandLineParam( sal_uInt16 nParam );
269     static const XubString&     GetAppFileName();
270 
271     virtual sal_uInt16          Exception( sal_uInt16 nError );
272     static void                 Abort( const XubString& rErrorText );
273 
274     static void                 Execute();
275     static void                 Quit();
276     static void                 Reschedule( bool bAllEvents = false );
277     static void                 Yield( bool bAllEvents = false );
278     static void                 EndYield();
279     static vos::IMutex&                     GetSolarMutex();
280     static vos::OThread::TThreadIdentifier  GetMainThreadIdentifier();
281     static sal_uLong            ReleaseSolarMutex();
282     static void                 AcquireSolarMutex( sal_uLong nCount );
283     static void                 EnableNoYieldMode( bool i_bNoYield );
284     static void                 AddPostYieldListener( const Link& i_rListener );
285     static void                 RemovePostYieldListener( const Link& i_rListener );
286 
287     static sal_Bool             IsInMain();
288     static sal_Bool             IsInExecute();
289     static sal_Bool             IsShutDown();
290     static sal_Bool             IsInModalMode();
291     static sal_uInt16           GetModalModeCount();
292 
293     static sal_uInt16           GetDispatchLevel();
294     static sal_Bool             AnyInput( sal_uInt16 nType = INPUT_ANY );
295     static sal_uLong            GetLastInputInterval();
296     static sal_Bool             IsUICaptured();
297     static sal_Bool             IsUserActive( sal_uInt16 nTest = USERACTIVE_ALL );
298 
299     virtual void                SystemSettingsChanging( AllSettings& rSettings,
300                                                         Window* pFrame );
301     static void                 MergeSystemSettings( AllSettings& rSettings );
302     /** validate that the currently selected system UI font is suitable
303         to display the application's UI.
304 
305         A localized test string will be checked if it can be displayed
306         in the currently selected system UI font. If no glyphs are
307         missing it can be assumed that the font is proper for display
308         of the application's UI.
309 
310         @returns
311         <TRUE/> if the system font is suitable for our UI
312         <FALSE/> if the test string could not be displayed with the system font
313      */
314     static bool					ValidateSystemFont();
315 
316     static void                 SetSettings( const AllSettings& rSettings );
317     static const AllSettings&   GetSettings();
318     static void                 NotifyAllWindows( DataChangedEvent& rDCEvt );
319 
320     static void                 AddEventListener( const Link& rEventListener );
321     static void                 RemoveEventListener( const Link& rEventListener );
322     static void                 AddKeyListener( const Link& rKeyListener );
323     static void                 RemoveKeyListener( const Link& rKeyListener );
324     static void                 ImplCallEventListeners( sal_uLong nEvent, Window* pWin, void* pData );
325     static void                 ImplCallEventListeners( VclSimpleEvent* pEvent );
326     static sal_Bool             HandleKey( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent );
327 
328 	static sal_uLong            PostKeyEvent( sal_uLong nEvent, Window *pWin, KeyEvent* pKeyEvent );
329     static sal_uLong            PostMouseEvent( sal_uLong nEvent, Window *pWin, MouseEvent* pMouseEvent );
330 	static void					RemoveMouseAndKeyEvents( Window *pWin );
331     static sal_Bool				IsProcessedMouseOrKeyEvent( sal_uLong nEventId );
332 
333     static sal_uLong            PostUserEvent( sal_uLong nEvent, void* pEventData = NULL );
334     static sal_uLong            PostUserEvent( const Link& rLink, void* pCaller = NULL );
335     static sal_Bool             PostUserEvent( sal_uLong& rEventId, sal_uLong nEvent, void* pEventData = NULL );
336     static sal_Bool             PostUserEvent( sal_uLong& rEventId, const Link& rLink, void* pCaller = NULL );
337     static void                 RemoveUserEvent( sal_uLong nUserEvent );
338 
339     static sal_Bool             InsertIdleHdl( const Link& rLink, sal_uInt16 nPriority );
340     static void                 RemoveIdleHdl( const Link& rLink );
341 
342     virtual void                AppEvent( const ApplicationEvent& rAppEvent );
343 
344     virtual void                Property( ApplicationProperty& );
345     void                        SetPropertyHandler( PropertyHandler* pHandler );
346 
347 #ifndef NO_GETAPPWINDOW
348     static WorkWindow*          GetAppWindow();
349 #endif
350 
351 	static Window*              GetFocusWindow();
352     static OutputDevice*        GetDefaultDevice();
353 
354     static Window*              GetFirstTopLevelWindow();
355     static Window*              GetNextTopLevelWindow( Window* pWindow );
356 
357     static long                 GetTopWindowCount();
358     static Window*              GetTopWindow( long nIndex );
359     static Window*              GetActiveTopWindow();
360 
361     static void                 SetAppName( const String& rUniqueName );
362     static String               GetAppName();
363 
364     static void                 SetDisplayName( const UniString& rDisplayName );
365     static UniString            GetDisplayName();
366 
367     static unsigned int         GetScreenCount();
368     // IsMultiDisplay returns:
369     //        true:  different screens are separate and windows cannot be moved
370     //               between them (e.g. Xserver with multiple screens)
371     //        false: screens form up one large display area
372     //               windows can be moved between single screens
373     //               (e.g. Xserver with Xinerama, Windows)
374     static bool                 IsMultiDisplay();
375     static Rectangle            GetScreenPosSizePixel( unsigned int nScreen );
376     static Rectangle            GetWorkAreaPosSizePixel( unsigned int nScreen );
377 	static rtl::OUString		GetScreenName( unsigned int nScreen );
378     static unsigned int         GetDefaultDisplayNumber();
379     // if IsMultiDisplay() == false the return value will be
380     // nearest screen of the target rectangle
381     // in case of IsMultiDisplay() == true the return value
382     // will always be GetDefaultDisplayNumber()
383     static unsigned int         GetBestScreen( const Rectangle& );
384 
385 	static const LocaleDataWrapper& GetAppLocaleDataWrapper();
386 
387     static sal_Bool             InsertAccel( Accelerator* pAccel );
388     static void                 RemoveAccel( Accelerator* pAccel );
389     static void                 FlushAccel();
390     static sal_Bool             CallAccel( const KeyCode& rKeyCode, sal_uInt16 nRepeat = 0 );
391 
392     static sal_uLong            AddHotKey( const KeyCode& rKeyCode, const Link& rLink, void* pData = NULL );
393     static void                 RemoveHotKey( sal_uLong nId );
394     static sal_uLong            AddEventHook( VCLEventHookProc pProc, void* pData = NULL );
395     static void                 RemoveEventHook( sal_uLong nId );
396     static long                 CallEventHooks( NotifyEvent& rEvt );
397     static long                 CallPreNotify( NotifyEvent& rEvt );
398     static long                 CallEvent( NotifyEvent& rEvt );
399 
400     static void                 SetHelp( Help* pHelp = NULL );
401     static Help*                GetHelp();
402 
403     static void                 EnableAutoHelpId( sal_Bool bEnabled = sal_True );
404     static sal_Bool             IsAutoHelpIdEnabled();
405 
406     static void                 EnableAutoMnemonic( sal_Bool bEnabled = sal_True );
407     static sal_Bool             IsAutoMnemonicEnabled();
408 
409     static sal_uLong            GetReservedKeyCodeCount();
410     static const KeyCode*       GetReservedKeyCode( sal_uLong i );
411     static String               GetReservedKeyCodeDescription( sal_uLong i );
412 
413     static void                 SetDefDialogParent( Window* pWindow );
414     static Window*              GetDefDialogParent();
415 
416     static void                 EnableDialogCancel( sal_Bool bDialogCancel = sal_True );
417     static sal_Bool             IsDialogCancelEnabled();
418 
419     static void                 SetSystemWindowMode( sal_uInt16 nMode );
420     static sal_uInt16           GetSystemWindowMode();
421 
422     static void                 SetDialogScaleX( short nScale );
423     static short                GetDialogScaleX();
424 
425     static void                 SetFontPath( const String& rPath );
426     static const String&        GetFontPath();
427 
428     static UniqueItemId         CreateUniqueId();
429 
430     static ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayConnection > GetDisplayConnection();
431 
432 	// The global service manager has to be created before!
433     static ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > GetVCLToolkit();
434     static UnoWrapperBase*      GetUnoWrapper( sal_Bool bCreateIfNotExists = sal_True );
435     static void                 SetUnoWrapper( UnoWrapperBase* pWrapper );
436 
437     static void                 SetFilterHdl( const Link& rLink );
438     static const Link&          GetFilterHdl();
439 
440     static sal_Bool             IsAccessibilityEnabled();
441 
442     static void                 EnableHeadlessMode( sal_Bool bEnable = sal_True );
443     static sal_Bool             IsHeadlessModeEnabled();
444 
445     static void                 EnableConversionMode( bool bEnableConv = true );
446     static bool                 IsConversionModeEnabled();
447 
448 
449     static void                 ShowNativeErrorBox(const String& sTitle  ,
450                                                    const String& sMessage);
451 	static bool					EnableAccessInterface(bool bEnable);
452 	static bool					IsEnableAccessInterface();
453 
454     // IME Status Window Control:
455 
456     /** Return true if any IME status window can be toggled on and off
457         externally.
458 
459         Must only be called with the Solar mutex locked.
460      */
461     static bool CanToggleImeStatusWindow();
462 
463     /** Toggle any IME status window on and off.
464 
465         This only works if CanToggleImeStatusWinodw returns true (otherwise,
466         any calls of this method are ignored).
467 
468         Must only be called with the Solar mutex locked.
469      */
470     static void ShowImeStatusWindow(bool bShow);
471 
472     /** Return true if any IME status window should be turned on by default
473         (this decision can be locale dependent, for example).
474 
475         Can be called without the Solar mutex locked.
476      */
477     static bool GetShowImeStatusWindowDefault();
478 
479     /** Returns a string representing the desktop environment
480         the process is currently running in.
481      */
482     static const ::rtl::OUString& GetDesktopEnvironment();
483 
484     /** Add a file to the system shells recent document list if there is any.
485           This function may have no effect under Unix because there is no
486           standard API among the different desktop managers.
487 
488           @param rFileUrl
489                     The file url of the document.
490 
491           @param rMimeType
492           The mime content type of the document specified by aFileUrl.
493           If an empty string will be provided "application/octet-stream"
494           will be used.
495     */
496     static void AddToRecentDocumentList(const rtl::OUString& rFileUrl, const rtl::OUString& rMimeType);
497 
498 private:
499 
500     DECL_STATIC_LINK( Application, PostEventHandler, void* );
501 };
502 
503 VCL_DLLPUBLIC Application* GetpApp();
504 
505 VCL_DLLPUBLIC sal_Bool InitVCL( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & );
506 VCL_DLLPUBLIC void DeInitVCL();
507 
508 VCL_DLLPUBLIC sal_Bool InitAccessBridge( sal_Bool bAllowCancel, sal_Bool &rCancelled );
509 
510 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
511 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
512 VCL_DLLPUBLIC void JoinMainLoopThread();
513 
EndYield()514 inline void Application::EndYield()
515 {
516     PostUserEvent( Link() );
517 }
518 
519 #ifdef WNT
520 VCL_DLLPUBLIC sal_Bool HasAtHook();
521 VCL_DLLPUBLIC bool IsWNTInitAccessBridge();
522 bool WNTEnableAccessInterface(bool bEnable);
523 
524 class VCL_DLLPUBLIC CEnableAccessInterface
525 {
526 public:
CEnableAccessInterface(bool bEnable=false)527 	CEnableAccessInterface(bool bEnable = false)
528 	{
529 		m_bIsEnableAccessInterface = Application::IsEnableAccessInterface();
530 		Application::EnableAccessInterface(bEnable);
531 	}
~CEnableAccessInterface()532 	~CEnableAccessInterface()
533 	{
534 		Application::EnableAccessInterface(m_bIsEnableAccessInterface);
535 	}
536 private:
537 	bool m_bIsEnableAccessInterface;
538 };
539 #endif
540 #endif // _APP_HXX
541