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