nss: upgrade to release 3.73
[LibreOffice.git] / include / vcl / svapp.hxx
blobb1d7759765c32d370f5c3bf1ebd091079a9d1702
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_SVAPP_HXX
21 #define INCLUDED_VCL_SVAPP_HXX
23 #include <sal/config.h>
24 #include <sal/types.h>
26 #include <cassert>
27 #include <vector>
29 #include <comphelper/solarmutex.hxx>
30 #include <osl/mutex.hxx>
31 #include <rtl/ustring.hxx>
32 #include <osl/thread.h>
33 #include <tools/gen.hxx>
34 #include <tools/link.hxx>
35 #include <vcl/dllapi.h>
36 #include <vcl/inputtypes.hxx>
37 #include <vcl/exceptiontypes.hxx>
38 #include <vcl/vclevent.hxx>
39 #include <vcl/vclenum.hxx>
40 #include <i18nlangtag/lang.h>
41 #include <o3tl/typed_flags_set.hxx>
42 #include <com/sun/star/uno/Reference.h>
45 class BitmapEx;
46 namespace weld
48 class Builder;
49 class MessageDialog;
50 class Widget;
51 class Window;
53 class LocaleDataWrapper;
54 class AllSettings;
55 class DataChangedEvent;
56 class Accelerator;
57 class Help;
58 class OutputDevice;
59 namespace vcl { class Window; }
60 namespace vcl { class KeyCode; }
61 class NotifyEvent;
62 class KeyEvent;
63 class MouseEvent;
64 class GestureEvent;
65 struct ImplSVEvent;
66 struct ConvertData;
68 namespace com::sun::star::uno {
69 class XComponentContext;
71 namespace com::sun::star::ui::dialogs {
72 class XFilePicker2;
73 class XFolderPicker2;
75 namespace com::sun::star::awt {
76 class XToolkit;
77 class XDisplayConnection;
78 class XWindow;
81 // helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
82 VCL_DLLPUBLIC sal_UCS4 GetMirroredChar( sal_UCS4 );
83 VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar( sal_UCS4, LanguageType );
85 enum class SystemWindowFlags {
86 NOAUTOMODE = 0x0001,
87 DIALOG = 0x0002
89 namespace o3tl
91 template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
94 typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
96 /** An application can be notified of a number of different events:
97 - Type::Accept - listen for connection to the application (a connection
98 string is passed via the event)
99 - Type::Unaccept - stops listening for a connection to the app (determined by
100 a connection string passed via the event)
101 - Type::Appear - brings the app to the front (i.e. makes it "appear")
102 - Type::Version - display the app version
103 - Type::Help - opens a help topic (help topic passed as string)
104 - Type::OpenHELP_URL - opens a help URL (URL passed as a string)
105 - Type::ShowDialog - shows a dialog (dialog passed as a string)
106 - Type::Open - opens a document or group of documents (documents passed
107 as an array of strings)
108 - Type::Print - print a document or group of documents (documents passed
109 as an array of strings
110 - Type::PrivateDoShutdown - shutdown the app
113 class VCL_DLLPUBLIC ApplicationEvent
115 public:
116 enum class Type {
117 Accept, ///< Listen for connections
118 Appear, ///< Make application appear
119 Open, ///< Open a document
120 OpenHelpUrl, ///< Open a help URL
121 Print, ///< Print document
122 PrivateDoShutdown, ///< Shutdown application
123 QuickStart, ///< Start QuickStart
124 ShowDialog, ///< Show a dialog
125 Unaccept ///< Stop listening for connections
128 /** Explicit constructor for ApplicationEvent.
130 @attention Type::Appear, Type::PrivateDoShutdown and
131 Type::QuickStart are the \em only events that don't need to include
132 a data string with the event. No other events should use this
133 constructor!
135 explicit ApplicationEvent(Type type): aEvent(type)
137 assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
140 /** Constructor for ApplicationEvent, accepts a string for the data
141 associated with the event.
143 @attention Type::Accept, Type::OpenHelpUrl, Type::ShowDialog
144 and Type::Unaccept are the \em only events that accept a single
145 string as event data. No other events should use this constructor!
147 ApplicationEvent(Type type, OUString const & data): aEvent(type)
149 assert(
150 type == Type::Accept || type == Type::OpenHelpUrl
151 || type == Type::ShowDialog || type == Type::Unaccept);
152 aData.push_back(data);
155 /** Constructor for ApplicationEvent, accepts an array of strings for
156 the data associated with the event.
158 @attention Type::Open and Type::Print can apply to multiple documents,
159 and are the \em only events that accept an array of strings. No other
160 events should use this constructor.
162 ApplicationEvent(Type type, std::vector<OUString> const & data):
163 aEvent(type), aData(data)
165 assert(type == Type::Open || type == Type::Print);
168 /** Get the type of event.
170 @returns The type of event.
172 Type GetEvent() const
174 return aEvent;
177 /** Gets the application event's data string.
179 @attention The \em only events that need a single string Type::Accept,
180 Type::OpenHelpUrl, Type::ShowDialog and Type::Unaccept
182 @returns The event's data string.
184 OUString const & GetStringData() const
186 assert(
187 aEvent == Type::Accept
188 || aEvent == Type::OpenHelpUrl || aEvent == Type::ShowDialog
189 || aEvent == Type::Unaccept);
190 assert(aData.size() == 1);
191 return aData[0];
194 /** Gets the event's array of strings.
196 @attention The \em only events that need an array of strings
197 are Type::Open and Type::Print.
199 std::vector<OUString> const & GetStringsData() const
201 assert(aEvent == Type::Open || aEvent == Type::Print);
202 return aData;
205 private:
206 Type aEvent;
207 std::vector<OUString> aData;
210 enum class DialogCancelMode {
211 Off, ///< do not automatically cancel dialogs
212 Silent, ///< silently cancel any dialogs
213 Fatal ///< cancel any dialogs by std::abort
217 @brief Base class used mainly for the LibreOffice Desktop class.
219 The Application class is a base class mainly used by the Desktop
220 class. It is really meant to be subclassed, and the Main() function
221 should be overridden. Many of the ImplSVData members should be
222 moved to this class.
224 The reason Application exists is because the VCL used to be a
225 standalone framework, long since abandoned by anything other than
226 our application.
228 @see Desktop, ImplSVData
230 class VCL_DLLPUBLIC Application
232 public:
233 /** @name Initialization
234 The following functions perform initialization and deinitialization
235 of the application.
237 ///@{
239 /** Default constructor for Application class.
241 Initializes the LibreOffice global instance data structure if needed,
242 and then sets itself to be the Application class. Also initializes any
243 platform specific data structures.
245 @attention The initialization of the application itself is done in Init()
247 Application();
249 /** Virtual destructor for Application class.
251 Deinitializes the LibreOffice global instance data structure, then
252 deinitializes any platform specific data structures.
254 virtual ~Application();
256 /** Initialize the application itself.
258 @attention Note that the global data structures and platform specific
259 initialization is done in the constructor.
261 @see InitFinished, DeInit
263 virtual void Init();
265 /** Finish initialization of the application.
267 @see Init, DeInit
269 virtual void InitFinished();
271 /** Deinitialized the application itself.
273 @attention Note that the global data structures and platform specific
274 deinitialization is done in the destructor.
276 @see Init, InitFinished
278 virtual void DeInit();
280 ///@}
282 /** @brief Pure virtual entrypoint to the application.
284 Main() is the pure virtual entrypoint to your application. You
285 inherit your class from Application and subclass this function to
286 implement an application.
288 The Main() function does not pass in command line parameters,
289 you must use the functions GetCommandLineParamCount() and
290 GetCommandLineParam() to get these values as these are platform
291 independent ways of getting the command line (use GetAppFileName()
292 to get the invoked executable filename).
294 Once in this function, you create windows, etc. then call on
295 Execute() to start the application's main event loop.
297 An example code snippet follows (it won't compile, this just gives the
298 general flavour of the framework and is adapted from an old HelloWorld
299 example program that Star Division used to provide as part of their
300 library).
302 \code{.cpp}
303 class TheApplication : public Application
305 public:
306 virtual void Main();
309 class TheWindow : public WorkWindow
311 public:
312 TheWindow(vcl::Window *parent, WinBits windowStyle) :
313 WorkWindow(parent, windowStyle) {}
315 virtual void Paint(const Rectangle &);
318 void TheWindow::Paint(const Rectangle&)
320 DrawText(Point(100,100), String("Hello World!"));
323 void TheApplication::Main()
325 TheWindow aWindow(NULL, WB_APP | WB_STDWORK);
326 aWindow.Show();
327 Execute();
330 TheApplication anApplication;
331 \endcode
333 Some examples in the source tree can be found here:
335 vcl/workben/svdem.cxx
337 This is an example of how to use the Application and WorkWindow. Unfortunately, it
338 no longer compiles.
340 vcl/fpicker/test/svdem.cxx
342 virtual int Main();
344 /** Exit from the application
346 @returns true if exited successfully, false if not able to fully exit
348 virtual bool QueryExit();
350 virtual void Shutdown();
352 /** @name Change Notification Functions
354 Functions that notify when changes occur in the application.
356 ///@{
358 /** Notify all windows that the application has changed data.
360 @param rDCEvt Reference to a DataChangedEvent object
362 @see DataChanged
364 static void NotifyAllWindows( DataChangedEvent& rDCEvt );
366 ///@}
368 /** @name Command Line Processing
370 Command line processing is done via the following functions. They
371 give the number of parameters, the parameters themselves and a way
372 to get the name of the invoking application.
375 ///@{
377 /** Gets the number of command line parameters passed to the application
379 @return sal_uInt16 - the number of parameters
381 @see GetCommandLineParam, GetAppFileName
383 static sal_uInt16 GetCommandLineParamCount();
385 /** Gets a particular command line parameter
387 @param nParam The index of the parameter to return.
389 @return The command line parameter as an OUString
391 @see GetCommandLineParamCount, GetAppFileName
393 static OUString GetCommandLineParam( sal_uInt16 nParam );
395 /** Get the name of the file used to start the application
397 @return The filename as an OUString
399 @see GetCommandLineParamCount, GetCommandLineParam
401 static OUString GetAppFileName();
403 ///@}
405 /** @name Error Handling
407 \em Very rudimentary error handling is done by these
408 functions.
413 /** Handles an error.
415 @param nCategory The error category, see include/vcl/exceptiontypes.hxx
417 @see Abort
419 virtual void Exception( ExceptionCategory nCategory );
421 /** Ends the program prematurely with an error message.
423 If the \code --norestore \endcode command line argument is given (assuming
424 this process is run by developers who are interested in cores,
425 vs. end users who are not) then it does a coredump.
427 @param rErrorText The error message to report.
429 @see Exception
431 static void Abort( const OUString& rErrorText );
433 ///@}
435 /** @name Event Loop Functions
437 Functions that handle the LibreOffice main event loop are here,
438 including a global lock called the Solar Mutex.
440 ///@{
442 /** Run the main event processing loop until it is quit by Quit().
444 @see Quit, Reschedule, Yield, EndYield, GetSolarMutex,
445 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
447 static void Execute();
449 /** Quit the program
451 @see Execute, Reschedule, Yield, EndYield, GetSolarMutex,
452 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
454 static void Quit();
456 /** Attempt to process current pending event(s)
458 It doesn't sleep if no events are available for processing.
459 This doesn't process any events generated after invoking the function.
460 So in contrast to Scheduler::ProcessEventsToIdle, this cannot become
461 busy-locked by an event-generating event in the event queue.
463 @param bHandleAllCurrentEvents If set to true, then try to process all
464 the current events. If set to false, then only process one event.
465 Defaults to false.
467 @returns true if any event was processed.
469 @see Yield, Scheduler::ProcessEventsToIdle
471 static bool Reschedule( bool bHandleAllCurrentEvents = false );
473 /** Process the next event.
475 It sleeps if no event is available for processing and just returns
476 if an event was processed.
478 @see Execute, Quit, Reschedule, EndYield, GetSolarMutex,
479 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
481 static void Yield();
485 @see Execute, Quit, Reschedule, Yield, GetSolarMutex,
486 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
488 static void EndYield();
490 /** @brief Get the Solar Mutex for this thread.
492 Get the Solar Mutex that prevents other threads from accessing VCL
493 concurrently.
495 @returns SolarMutex reference
497 @see Execute, Quit, Reschedule, Yield, EndYield,
498 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
500 static comphelper::SolarMutex& GetSolarMutex();
502 /** Queries whether we are in main thread.
504 @returns true if we are in main thread, false if not
506 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
507 ReleaseSolarMutex, AcquireSolarMutex,
509 static bool IsMainThread();
511 /** @brief Release Solar Mutex(es) for this thread
513 Release the Solar Mutex(es) that prevents other threads from accessing
514 VCL concurrently.
516 @returns The number of mutexes that were acquired by this thread.
518 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
519 IsMainThread, AcquireSolarMutex,
521 static sal_uInt32 ReleaseSolarMutex();
523 /** @brief Acquire Solar Mutex(es) for this thread.
525 Acquire the Solar Mutex(es) that prevents other threads from accessing
526 VCL concurrently.
528 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
529 IsMainThread, ReleaseSolarMutex,
531 static void AcquireSolarMutex( sal_uInt32 nCount );
533 /** Queries whether the application is in "main", i.e. not yet in
534 the event loop
536 @returns true if in main, false if not in main
538 @see IsInExecute, IsInModalMode
540 static bool IsInMain();
542 /** Queries whether the application is in the event loop
544 @returns true if in the event loop, false if not
546 @see IsInMain, IsInModalMode
548 static bool IsInExecute();
550 /** Queries whether application has a modal dialog active.
552 @returns true if a modal dialog is active, false if not
554 @see IsInMain, IsInExecute
556 static bool IsInModalMode();
558 /** Return how many events are being dispatched.
560 @returns the number of events currently being dispatched
562 static sal_uInt16 GetDispatchLevel();
564 /** Determine if there are any pending input events.
566 @param nType input identifier, defined in include/vcl/inputtypes.hxx
567 The default is VCL_INPUT_ANY.
569 @returns true if there are pending events, false if not.
571 @see GetLastInputInterval
573 static bool AnyInput( VclInputFlags nType = VCL_INPUT_ANY );
575 /** The interval from the last time that input was received.
577 @returns system ticks - last input time
579 @see AnyInput
581 static sal_uInt64 GetLastInputInterval();
583 ///@}
585 /* Determines if the UI is captured.
587 The UI is considered captured if a system dialog is open (e.g. printer setup),
588 a floating window, menu or toolbox dropdown is open, or a window has been
589 captured by the mouse.
591 @returns true if UI is captured, false if not
593 static bool IsUICaptured();
595 /** @name Settings
597 The following functions set system settings (e.g. tab color, etc.). There are functions
598 that set settings objects, and functions that set and get the actual system settings for
599 the application.
601 ///@{
603 /** Sets user settings in settings object to override system settings
605 The system settings that can be overridden are:
606 - window dragging options (on or off, including live scrolling!)
607 - style settings (e.g. checkbox color, border color, 3D colors,
608 button rollover colors, etc.)
609 - mouse settings
610 - menu options, including the mouse follows the menu and whether menu
611 icons are used
613 @param rSettings Reference to the settings object to change.
615 @see MergeSystemSettings, SetSettings, GetSettings
617 virtual void OverrideSystemSettings( AllSettings& rSettings );
619 /** Set the settings object to the platform/desktop environment system
620 settings.
622 @param rSettings Reference to the settings object to change.
624 @see OverrideSystemSettings, SetSettings, GetSettings
626 static void MergeSystemSettings( AllSettings& rSettings );
628 /** Sets the application's settings and notifies all windows of the
629 change.
631 @param rSettings const reference to settings object used to
632 change the application's settings.
634 @see OverrideSystemSettings, MergeSystemSettings, GetSettings
636 static void SetSettings( const AllSettings& rSettings );
638 /** Gets the application's settings. If the application hasn't initialized
639 it's settings, then it does so (lazy initialization).
641 @returns AllSettings instance that contains the current settings of the
642 application.
644 @see OverrideSystemSettings, MergeSystemSettings, SetSettings
646 static const AllSettings& GetSettings();
648 /** Get the application's locale data wrapper.
650 @returns reference to a LocaleDataWrapper object
652 static const LocaleDataWrapper& GetAppLocaleDataWrapper();
654 ///@}
656 /** @name Event Listeners/Handlers
658 A set of event listeners and callers. Note that in this code there is
659 platform specific functions - namely for zoom and scroll events.
661 ///@{
664 /** Add a VCL event listener to the application. If no event listener exists,
665 then initialize the application's event listener with a new one, then add
666 the event listener.
668 @param rEventListener Const reference to the event listener to add.
670 @see RemoveEventListener, AddKeyListener, RemoveKeyListener
672 static void AddEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
674 /** Remove a VCL event listener from the application.
676 @param rEventListener Const reference to the event listener to be removed
678 @see AddEventListener, AddKeyListener, RemoveKeyListener
680 static void RemoveEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
682 /** Add a keypress listener to the application. If keypress listener exists,
683 then initialize the application's keypress event listener with a new one, then
684 add the keypress listener.
686 @param rKeyListener Const reference to the keypress event listener to add
688 @see AddEventListener, RemoveEventListener, RemoveKeyListener
690 static void AddKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
692 /** Remove a keypress listener from the application.
694 @param rKeyListener Const reference to the keypress event listener to be removed
696 @see AddEventListener, RemoveEventListener, AddKeyListener
698 static void RemoveKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
700 /** Send event to all VCL application event listeners
702 @param pWin Pointer to window to send event
703 @param pData Pointer to data to send with event
705 @see ImplCallEventListeners(VclSimpleEvent* pEvent)
707 static void ImplCallEventListenersApplicationDataChanged( void* pData );
709 /** Send event to all VCL application event listeners
711 @param rEvent Reference to VclSimpleEvent
713 @see ImplCallEventListeners(sal_uLong nEvent, Windows* pWin, void* pData);
715 static void ImplCallEventListeners( VclSimpleEvent& rEvent );
717 /** Handle keypress event
719 @param nEvent Event ID for keypress
720 @param pWin Pointer to window that receives the event
721 @param pKeyEvent Received key event
723 @see PostKeyEvent
725 static bool HandleKey( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
727 /** Send keypress event
729 @param nEvent Event ID for keypress
730 @param pWin Pointer to window to which the event is sent
731 @param pKeyEvent Key event to send
733 @see HandleKey
735 static ImplSVEvent * PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, KeyEvent const * pKeyEvent );
737 /** Send mouse event
739 @param nEvent Event ID for mouse event
740 @param pWin Pointer to window to which the event is sent
741 @param pMouseEvent Mouse event to send
743 static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
745 static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin, GestureEvent const * pGestureEvent);
747 /** Remove mouse and keypress events from a window... any also zoom and scroll events
748 if the platform supports it.
750 @param pWin Window to remove events from
752 @see HandleKey, PostKeyEvent, PostMouseEvent
754 static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
756 /** Post a user event to the default window.
758 User events allow for the deferral of work to later in the main-loop - at idle.
760 Execution of the deferred work is thread-safe which means all the tasks are executed
761 serially, so no thread-safety locks between tasks are necessary.
763 @param rLink Link to event callback function
764 @param pCaller Pointer to data sent to the event by the caller. Optional.
765 @param bReferenceLink If true - hold a VclPtr<> reference on the Link's instance.
766 Taking the reference is guarded by a SolarMutexGuard.
768 @return the event ID used to post the event.
770 static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
771 bool bReferenceLink = false );
773 /** Remove user event based on event ID
775 @param nUserEvent User event to remove
777 static void RemoveUserEvent( ImplSVEvent * nUserEvent );
779 /*** Get the DisplayConnection.
781 It is a reference to XDisplayConnection, which allows toolkits to send display
782 events to the application.
784 @returns UNO reference to an object that implements the css:awt:XDisplayConnection
785 interface.
787 static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
789 /** @deprecated AppEvent is used only in the Desktop class now. However, it is
790 intended to notify the application that an event has occurred. It was in oldsv.cxx,
791 but is still needed by a number of functions.
793 @param rAppEvent const reference to ApplicationEvent event
795 virtual void AppEvent( const ApplicationEvent& rAppEvent );
797 ///@}
799 /** @name Application Window Functions
801 Functions that deal with the application's windows
803 ///@{
805 /** Get the currently focused window.
807 @returns Pointer to focused window.
809 @see GetDefaultDevice
811 static vcl::Window* GetFocusWindow();
813 /** Get the default "device" (in this case the default window).
815 @returns Pointer to an OutputDevice. However, it is a Window object -
816 Window class subclasses OutputDevice.
818 @see GetFocusWindow
820 static OutputDevice* GetDefaultDevice();
822 /** Get the first top-level window of the application.
824 @returns Pointer to top-level window (a Window object)
826 @see GetNextTopLevelWindow, GetTopWindowCount, GetTopWindow,
827 GetActiveTopWindow
829 static vcl::Window* GetFirstTopLevelWindow();
831 /** Get the next top level window.
833 @param pWindow Pointer to Window object you wish to get the next
834 window from.
836 @returns Pointer to next top window.
838 static vcl::Window* GetNextTopLevelWindow( vcl::Window const * pWindow );
840 /** Return the number of top-level windows being used by the application
842 @returns the number of top-level windows
844 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindow,
845 GetActiveTopWindow
848 static tools::Long GetTopWindowCount();
850 /** Get the nth top window.
852 @remark Top windows are actually implemented in a one-way linked list.
853 This iterates through top level windows n times.
855 @param nIndex The index of the top-level window
857 @returns The nth top-level window of the application
859 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
860 GetActiveTopWindow
862 static vcl::Window* GetTopWindow( tools::Long nIndex );
864 /** Get the "active" top window.
866 An "active" top window is one that has a child window that has the
867 application's focus.
869 @returns the active top window
871 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
872 GetTopWindow
874 static vcl::Window* GetActiveTopWindow();
876 ///@}
878 /** Set the application's name.
880 @param rUniqueName What to set the application name to
882 @see GetAppName
884 static void SetAppName( const OUString& rUniqueName );
887 /** @name Application Name, Branding
889 ///@{
891 /** Get the application's name.
893 @returns The application name.
895 static OUString GetAppName();
897 /** Get useful OS, Hardware and configuration information,
898 * cf. Help->About, and User-Agent
899 * bSelection = 0 to return all info, 1 for environment only,
900 * and 2 for VCL/render related infos
902 static OUString GetHWOSConfInfo(const int bSelection = 0, bool bLocalize = true);
904 /** Load a localized branding PNG file as a bitmap.
906 @param pName Name of the bitmap to load.
907 @param rBitmap Reference to BitmapEx object to load PNG into
909 @returns true if the PNG could be loaded, otherwise returns false.
911 static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
913 ///@}
915 /** @name Display and Screen
917 ///@{
919 /** Set the default name of the application for message dialogs and printing.
921 @param rDisplayName const reference to string to set the Display name to.
923 @see GetDisplayName
925 static void SetDisplayName( const OUString& rDisplayName );
927 /** Get the default name of the application for message dialogs and printing.
929 @returns The display name of the application.
931 static OUString GetDisplayName();
933 /** Get the toolkit's name. e.g. gtk3
935 @returns The toolkit name.
937 static OUString GetToolkitName();
939 /** Get the number of screens available for the display.
941 @returns The number of screens available.
943 @see GetScreenPosSizePixel
945 static unsigned int GetScreenCount();
947 /** Get a screen's rectangular area.
949 @param nScreen The number of the screen requested.
951 @returns The area of the screen in a Rectangle object.
953 @see GetScreenCount
955 static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
957 /** Determines if the screens that make up a display are separate or
958 form one large display area.
960 @returns true when screens form up one large display area windows can be
961 moved between single screens (e.g. Xserver with Xinerama, Windows)
962 and false when different screens are separate and windows cannot be moved
963 between them (e.g. Xserver with multiple screens)
965 @see GetBestScreen, GetDisplayBuiltInScreen
967 static bool IsUnifiedDisplay();
969 /** Get the "best" screen.
971 @returns If IsUnifiedDisplay() == true the return value will be
972 nearest screen of the target rectangle.
974 In case of IsUnifiedDisplay() == false the return value
975 will always be GetDisplayDefaultScreen().
977 @see IsUnifiedDisplay, GetDisplayBuiltInScreen
979 SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
981 /** Get the built-in screen.
983 @return
984 This returns the LCD screen number for a laptop, or the primary
985 external VGA display for a desktop machine - it is where a presenter
986 console should be rendered if there are other (non-built-in) screens
987 present.
989 @see IsUnifiedDisplay, GetBestScreen
991 static unsigned int GetDisplayBuiltInScreen();
993 /** Get the display's external screen.
995 Practically, this means - Get the screen we should run a presentation on.
997 @returns 0 or 1 currently, will fallback to the first available screen if
998 there are more than one external screens. May be changed in the future.
1000 static unsigned int GetDisplayExternalScreen();
1002 ///@}
1004 /** @name Accelerators and Mnemonics
1006 Accelerators allow a user to hold down Ctrl+key (or CMD+key on macOS)
1007 combination to gain quick access to functionality.
1009 Mnemonics are underline letters in things like menus and dialog boxes
1010 that allow a user to type in the letter to activate the menu or option.
1012 ///@{
1014 /** Insert accelerator
1016 @param pAccel Pointer to an Accelerator object to insert
1018 @returns true if successful, false if otherwise
1020 @see RemoveAccel
1022 static bool InsertAccel( Accelerator* pAccel );
1024 /** Remove accelerator
1026 @param pAccel Pointer to Accelerator object to remove
1028 @see InsertAccel
1030 static void RemoveAccel( Accelerator const * pAccel );
1032 /** Get the number of reserved key codes used by the application.
1034 @returns number of reserved key codes
1036 @see GetReservedKeyCode
1038 static size_t GetReservedKeyCodeCount();
1040 /** Get the reserved key code.
1042 @param i The keycode number to retrieve
1044 @returns Const pointer to a KeyCode object
1046 @see GetReservedKeyCodeCount
1048 static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1050 ///@}
1052 /** @name Application Help
1054 Deals with the help system, and "auto-help", where a user hovers a mouse above
1055 a UI element and a tooltip with an explanation pops up.
1057 ///@{
1059 /** Sets up help
1061 @param pHelp Pointer to a Help object (optional, can by NULL)
1063 @see GetHelp
1065 static void SetHelp( Help* pHelp = nullptr );
1067 /** Gets the application's help
1069 @returns Pointer to application's help object. Note that the application may
1070 not have a help object, so it might return NULL.
1072 @see SetHelp
1074 static Help* GetHelp();
1076 ///@}
1078 /** @name Dialogs
1080 @remark "Dialog cancel mode" tells a headless install whether to
1081 cancel dialogs when they appear. See the DialogCancelMode
1082 enumerator.
1084 ///@{
1086 /** Get the default parent window for dialog boxes.
1088 @remark GetDefDialogParent does all sorts of things find a useful parent
1089 window for dialogs. It first uses the topmost parent of the active
1090 window to avoid using floating windows or other dialog boxes. If
1091 there are no active windows, then it will take a random stab and
1092 choose the first visible top window. Otherwise, it defaults to
1093 the desktop.
1095 @returns Pointer to the default window.
1097 static vcl::Window* GetDefDialogParent();
1100 /** Gets the dialog cancel mode for headless environments.
1102 @return DialogCancelMode value
1104 @see SetDialogCancelMode, IsDialogCancelEnabled
1106 static DialogCancelMode GetDialogCancelMode();
1108 /** Sets the dialog cancel mode for headless environments.
1110 This should be private, but XFrameImpl needs to access it and current
1111 baseline gcc doesn't support forward definition of anonymous classes.
1112 You probably should use EnableHeadlessMode instead.
1114 @param mode DialogCancel mode value
1116 @see GetDialogCancelMode, IsDialogCancelEnabled, EnableHeadlessMode
1118 static void SetDialogCancelMode( DialogCancelMode mode );
1120 /** Determines if dialog cancel mode is enabled.
1122 @returns True if dialog cancel mode is enabled, false if disabled.
1124 @see GetDialogCancelMode, SetDialogCancelMode
1126 static bool IsDialogCancelEnabled();
1129 /** Make a dialog box a system window or not.
1131 @param nMode Can be either: SystemWindowFlags::NOAUTOMODE (0x0001) or
1132 SystemWindowFlags::DIALOG (0x0002)
1134 @see GetSystemWindowMode
1136 static void SetSystemWindowMode( SystemWindowFlags nMode );
1138 /** Get the system window mode of dialogs.
1140 @returns SystemWindowFlags::NOAUTOMODE (0x0001) or SystemWindowFlags::DIALOG (0x0002)
1142 @see SetSystemWindowMode
1144 static SystemWindowFlags GetSystemWindowMode();
1146 ///@}
1148 /** @name VCL Toolkit and UNO Wrapper
1150 The VCL Toolkit implements the UNO XToolkit interface, which specifies a
1151 factory interface for the window toolkit. It is similar to the abstract window
1152 toolkit (AWT) in Java.
1155 ///@{
1157 /** Gets the VCL toolkit.
1159 @attention The global service manager has to be created before getting the toolkit!
1161 @returns UNO reference to VCL toolkit
1163 static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1165 ///@}
1168 /*** @name Graphic Filters
1170 ///@{
1172 /** Setup a new graphics filter
1174 @param rLink Const reference to a Link object, which the filter calls upon.
1176 @see GetFilterHdl
1178 static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1180 ///@}
1182 /** @name Headless Mode
1185 /** Enables headless mode.
1187 @param dialogsAreFatal Set to true if a dialog ends the session, false if not.
1189 static void EnableHeadlessMode( bool dialogsAreFatal );
1191 /** Determines if headless mode is enabled
1193 @return True if headless mode is enabled, false if not.
1195 static bool IsHeadlessModeEnabled();
1197 /** Enable Console Only mode
1199 Convenience function to enable headless and bitmap rendering.
1201 static void EnableConsoleOnly();
1203 /** Enable software-only bitmap rendering
1205 static void EnableBitmapRendering();
1207 /** Determines if bitmap rendering is enabled
1209 @return True if bitmap rendering is enabled.
1211 static bool IsBitmapRendering();
1213 ///@}
1215 /** @name Event Testing Mode
1218 /** Enables event testing mode.
1221 static void EnableEventTestingMode();
1223 /** Determines if event testing mode is enabled
1225 @return True if event testing mode is enabled, false if not.
1227 static bool IsEventTestingModeEnabled();
1229 /** Set safe mode to enabled */
1230 static void EnableSafeMode();
1232 /** Determines if safe mode is enabled */
1233 static bool IsSafeModeEnabled();
1235 ///@}
1237 /** Get the desktop environment the process is currently running in
1239 @returns String representing the desktop environment
1241 static const OUString& GetDesktopEnvironment();
1243 /*** @name Platform Functionality
1245 ///@{
1247 /** Add a file to the system shells recent document list if there is any.
1248 This function may have no effect under Unix because there is no standard
1249 API among the different desktop managers.
1251 @param rFileUrl The file url of the document.
1253 @param rMimeType The mime content type of the document specified by aFileUrl.
1254 If an empty string will be provided "application/octet-stream"
1255 will be used.
1257 @param rDocumentService The app (or "document service") you will be adding the file to
1258 e.g. com.sun.star.text.TextDocument
1260 static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1262 /*** Show a native error messagebox
1264 @param sTitle Title of error messagebox
1266 @param sMessage Message displayed in messagebox
1268 static void ShowNativeErrorBox(const OUString& sTitle ,
1269 const OUString& sMessage);
1271 /** Update main thread identifier */
1272 static void UpdateMainThread();
1274 /** Do we have a native / system file selector available?
1276 @returns True if native file selector is available, false otherwise.
1278 static bool hasNativeFileSelection();
1280 /** Create a platform specific file picker, if one is available, otherwise return an
1281 empty reference.
1283 @param rServiceManager Const reference to a UNO component context (service manager).
1285 @returns File picker if available, otherwise an empty reference.
1287 static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1288 createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1290 /** Create a platform specific folder picker, if one is available, otherwise return an
1291 empty reference
1293 @param rServiceManager Const reference to a UNO component context (service manager).
1295 @returns Folder picker if available, otherwise an empty reference.
1297 static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1298 createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1300 /** Cancel all open dialogs
1302 static void EndAllDialogs();
1304 /** Cancel all open popups
1306 static void EndAllPopups();
1308 ///@}
1310 // For vclbootstrapprotector:
1311 static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1313 static weld::Builder* CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false);
1314 // For the duration of vcl parent windows
1315 static weld::Builder* CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId = 0);
1317 static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1318 VclButtonsType eButtonType, const OUString& rPrimaryMessage,
1319 bool bMobile = false);
1321 static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1322 private:
1323 DECL_STATIC_LINK( Application, PostEventHandler, void*, void );
1326 class SolarMutexGuard
1327 : public osl::Guard<comphelper::SolarMutex>
1329 public:
1330 SolarMutexGuard()
1331 : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1334 class SolarMutexClearableGuard
1335 : public osl::ClearableGuard<comphelper::SolarMutex>
1337 public:
1338 SolarMutexClearableGuard()
1339 : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1342 class SolarMutexResettableGuard
1343 : public osl::ResettableGuard<comphelper::SolarMutex>
1345 public:
1346 SolarMutexResettableGuard()
1347 : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1350 namespace vcl
1353 /** guard class that uses tryToAcquire() and has isAcquired() to check
1355 class SolarMutexTryAndBuyGuard
1357 private:
1358 bool m_isAcquired;
1359 #ifdef DBG_UTIL
1360 bool m_isChecked;
1361 #endif
1362 comphelper::SolarMutex& m_rSolarMutex;
1364 SolarMutexTryAndBuyGuard(const SolarMutexTryAndBuyGuard&) = delete;
1365 SolarMutexTryAndBuyGuard& operator=(const SolarMutexTryAndBuyGuard&) = delete;
1367 public:
1369 SolarMutexTryAndBuyGuard()
1370 : m_isAcquired(false)
1371 #ifdef DBG_UTIL
1372 , m_isChecked(false)
1373 #endif
1374 , m_rSolarMutex(Application::GetSolarMutex())
1377 m_isAcquired = m_rSolarMutex.tryToAcquire();
1380 ~SolarMutexTryAndBuyGuard()
1382 #ifdef DBG_UTIL
1383 assert(m_isChecked);
1384 #endif
1385 if (m_isAcquired)
1386 m_rSolarMutex.release();
1389 bool isAcquired()
1391 #ifdef DBG_UTIL
1392 m_isChecked = true;
1393 #endif
1394 return m_isAcquired;
1398 } // namespace vcl
1401 A helper class that calls Application::ReleaseSolarMutex() in its constructor
1402 and restores the mutex in its destructor.
1404 class SolarMutexReleaser
1406 const sal_uInt32 mnReleased;
1407 public:
1408 SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1409 ~SolarMutexReleaser() { Application::AcquireSolarMutex( mnReleased ); }
1412 VCL_DLLPUBLIC Application* GetpApp();
1414 // returns true if vcl is already initialized
1415 VCL_DLLPUBLIC bool IsVCLInit();
1416 // returns true if vcl successfully initializes or was already initialized
1417 VCL_DLLPUBLIC bool InitVCL();
1418 VCL_DLLPUBLIC void DeInitVCL();
1420 VCL_DLLPUBLIC bool InitAccessBridge();
1422 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1423 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1424 VCL_DLLPUBLIC void JoinMainLoopThread();
1426 /// The following are to manage per-view (frame) help data.
1427 struct ImplSVHelpData;
1428 VCL_DLLPUBLIC ImplSVHelpData* CreateSVHelpData();
1429 VCL_DLLPUBLIC void DestroySVHelpData(ImplSVHelpData*);
1430 VCL_DLLPUBLIC void SetSVHelpData(ImplSVHelpData*);
1432 /// The following are to manage per-view (frame) window data.
1433 struct ImplSVWinData;
1434 VCL_DLLPUBLIC ImplSVWinData* CreateSVWinData();
1435 VCL_DLLPUBLIC void DestroySVWinData(ImplSVWinData*);
1436 VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData*);
1438 inline void Application::EndYield()
1440 PostUserEvent( Link<void*,void>() );
1443 #endif // _APP_HXX
1445 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */