xref: /AOO41X/main/vcl/inc/vcl/svapp.hxx (revision 05236b1a0a8122ee73deabdbaef6d40a9b9d7792)
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 
115     const UniString&    GetHost() const     { return aHostName; }
116     const UniString&    GetDisplay() const  { return aDisplayName; }
117     const UniString&    GetDomain() const   { return aDomainName; }
118     int                 GetPID() const      { return nPID; }
119 
120     sal_Bool                IsConnectToSame( const ApplicationAddress& rAdr ) const;
121 };
122 
123 inline ApplicationAddress::ApplicationAddress()
124 {
125     nPID = 0;
126 }
127 
128 inline ApplicationAddress::ApplicationAddress( const UniString& rDomain )
129 {
130     aDomainName     = rDomain;
131     nPID            = 0;
132 }
133 
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 
144 inline ApplicationAddress::ApplicationAddress( const UniString& rHost, int nPIDPar )
145 {
146     aHostName       = rHost;
147     nPID            = nPIDPar;
148 }
149 
150 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:
174                         ApplicationEvent() {}
175                         ApplicationEvent( const UniString& rSenderAppName,
176                                           const ApplicationAddress& rAppAddr,
177                                           const ByteString& rEvent,
178                                           const UniString& rData );
179 
180     const UniString&    GetSenderAppName() const { return aSenderAppName; }
181     const ByteString&   GetEvent() const { return aEvent; }
182     const UniString&    GetData() const { return aData; }
183     const ApplicationAddress& GetAppAddress() const { return aAppAddr; }
184 
185     sal_Bool                IsOpenEvent() const;
186     sal_Bool                IsPrintEvent() const;
187     sal_Bool                IsDiskInsertEvent() const;
188 
189     sal_uInt16              GetParamCount() const { return aData.GetTokenCount( APPEVENT_PARAM_DELIMITER ); }
190     UniString           GetParam( sal_uInt16 nParam ) const { return aData.GetToken( nParam, APPEVENT_PARAM_DELIMITER ); }
191 };
192 
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 
204 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 
212 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 
220 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                 ShowNativeErrorBox(const String& sTitle  ,
446                                                    const String& sMessage);
447 
448     // IME Status Window Control:
449 
450     /** Return true if any IME status window can be toggled on and off
451         externally.
452 
453         Must only be called with the Solar mutex locked.
454      */
455     static bool CanToggleImeStatusWindow();
456 
457     /** Toggle any IME status window on and off.
458 
459         This only works if CanToggleImeStatusWinodw returns true (otherwise,
460         any calls of this method are ignored).
461 
462         Must only be called with the Solar mutex locked.
463      */
464     static void ShowImeStatusWindow(bool bShow);
465 
466     /** Return true if any IME status window should be turned on by default
467         (this decision can be locale dependent, for example).
468 
469         Can be called without the Solar mutex locked.
470      */
471     static bool GetShowImeStatusWindowDefault();
472 
473     /** Returns a string representing the desktop environment
474         the process is currently running in.
475      */
476     static const ::rtl::OUString& GetDesktopEnvironment();
477 
478     /** Add a file to the system shells recent document list if there is any.
479           This function may have no effect under Unix because there is no
480           standard API among the different desktop managers.
481 
482           @param rFileUrl
483                     The file url of the document.
484 
485           @param rMimeType
486           The mime content type of the document specified by aFileUrl.
487           If an empty string will be provided "application/octet-stream"
488           will be used.
489     */
490     static void AddToRecentDocumentList(const rtl::OUString& rFileUrl, const rtl::OUString& rMimeType);
491 
492 private:
493 
494     DECL_STATIC_LINK( Application, PostEventHandler, void* );
495 };
496 
497 VCL_DLLPUBLIC Application* GetpApp();
498 
499 VCL_DLLPUBLIC sal_Bool InitVCL( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & );
500 VCL_DLLPUBLIC void DeInitVCL();
501 
502 VCL_DLLPUBLIC sal_Bool InitAccessBridge( sal_Bool bAllowCancel, sal_Bool &rCancelled );
503 
504 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
505 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
506 VCL_DLLPUBLIC void JoinMainLoopThread();
507 
508 inline void Application::EndYield()
509 {
510     PostUserEvent( Link() );
511 }
512 
513 #endif // _APP_HXX
514