Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / svapp.hxx
blob0891859c79e18f556fc60873d1db22935dafd00e
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 <stdexcept>
28 #include <vector>
30 #include <comphelper/solarmutex.hxx>
31 #include <rtl/ustring.hxx>
32 #include <osl/thread.hxx>
33 #include <tools/gen.hxx>
34 #include <tools/link.hxx>
35 #include <tools/solar.h>
36 #include <vcl/dllapi.h>
37 #include <vcl/inputtypes.hxx>
38 #include <vcl/exceptiontypes.hxx>
39 #include <vcl/keycod.hxx>
40 #include <vcl/vclevent.hxx>
41 #include <vcl/metric.hxx>
42 #include <unotools/localedatawrapper.hxx>
43 #include <o3tl/typed_flags_set.hxx>
44 #include <com/sun/star/uno/Reference.h>
45 #include <com/sun/star/connection/XConnection.hpp>
48 class BitmapEx;
49 class AllSettings;
50 class DataChangedEvent;
51 class Accelerator;
52 class Help;
53 class OutputDevice;
54 namespace vcl { class Window; }
55 class WorkWindow;
56 class MenuBar;
57 class UnoWrapperBase;
58 class Reflection;
59 class NotifyEvent;
60 class KeyEvent;
61 class MouseEvent;
62 struct ImplSVEvent;
63 struct ConvertData;
65 namespace com {
66 namespace sun {
67 namespace star {
68 namespace uno {
69 class XComponentContext;
71 namespace ui {
72 namespace dialogs {
73 class XFilePicker2;
74 class XFolderPicker2;
77 namespace awt {
78 class XToolkit;
79 class XDisplayConnection;
81 } } }
83 // helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
84 VCL_DLLPUBLIC sal_UCS4 GetMirroredChar( sal_UCS4 );
85 VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar( sal_UCS4, LanguageType );
87 enum class SystemWindowFlags {
88 NOAUTOMODE = 0x0001,
89 DIALOG = 0x0002
91 namespace o3tl
93 template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
96 typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
98 /** An application can be notified of a number of different events:
99 - Type::Accept - listen for connection to the application (a connection
100 string is passed via the event)
101 - Type::Unaccept - stops listening for a connection to the app (determined by
102 a connection string passed via the event)
103 - Type::Appear - brings the app to the front (i.e. makes it "appear")
104 - Type::Version - display the app version
105 - Type::Help - opens a help topic (help topic passed as string)
106 - Type::OpenHELP_URL - opens a help URL (URL passed as a string)
107 - Type::ShowDialog - shows a dialog (dialog passed as a string)
108 - Type::Open - opens a document or group of documents (documents passed
109 as an array of strings)
110 - Type::Print - print a document or group of documents (documents passed
111 as an array of strings
112 - Type::PrivateDoShutdown - shutdown the app
115 class VCL_DLLPUBLIC ApplicationEvent
117 public:
118 enum class Type {
119 Accept, ///< Listen for connections
120 Appear, ///< Make application appear
121 Help, ///< Bring up help options (command-line help)
122 Version, ///< Display product version
123 Open, ///< Open a document
124 OpenHelpUrl, ///< Open a help URL
125 Print, ///< Print document
126 PrivateDoShutdown, ///< Shutdown application
127 QuickStart, ///< Start QuickStart
128 ShowDialog, ///< Show a dialog
129 Unaccept ///< Stop listening for connections
132 /** Explicit constructor for ApplicationEvent.
134 @attention Type::Appear, Type::Version, Type::PrivateDoShutdown and
135 Type::QuickStart are the \em only events that don't need to include
136 a data string with the event. No other events should use this
137 constructor!
139 explicit ApplicationEvent(Type type): aEvent(type)
141 assert(
142 type == Type::Appear || type == Type::Version
143 || type == Type::PrivateDoShutdown || type == Type::QuickStart);
146 /** Constructor for ApplicationEvent, accepts a string for the data
147 associated with the event.
149 @attention Type::Accept, Type::Help, Type::OpenHelpUrl, Type::ShowDialog
150 and Type::Unaccept are the \em only events that accept a single
151 string as event data. No other events should use this constructor!
153 ApplicationEvent(Type type, OUString const & data): aEvent(type)
155 assert(
156 type == Type::Accept || type == Type::Help || type == Type::OpenHelpUrl
157 || type == Type::ShowDialog || type == Type::Unaccept);
158 aData.push_back(data);
161 /** Constructor for ApplicationEvent, accepts an array of strings for
162 the data associated with the event.
164 @attention Type::Open and Type::Print can apply to multiple documents,
165 and are the \em only events that accept an array of strings. No other
166 events should use this constructor.
168 ApplicationEvent(Type type, std::vector<OUString> const & data):
169 aEvent(type), aData(data)
171 assert(type == Type::Open || type == Type::Print);
174 /** Get the type of event.
176 @returns The type of event.
178 Type GetEvent() const
180 return aEvent;
183 /** Gets the application event's data string.
185 @attention The \em only events that need a single string Type::Accept,
186 Type::Help, Type::OpenHelpUrl, Type::ShowDialog and Type::Unaccept
188 @returns The event's data string.
190 OUString GetStringData() const
192 assert(
193 aEvent == Type::Accept || aEvent == Type::Help
194 || aEvent == Type::OpenHelpUrl || aEvent == Type::ShowDialog
195 || aEvent == Type::Unaccept);
196 assert(aData.size() == 1);
197 return aData[0];
200 /** Gets the event's array of strings.
202 @attention The \em only events that need an array of strings
203 are Type::Open and Type::Print.
205 std::vector<OUString> const & GetStringsData() const
207 assert(aEvent == Type::Open || aEvent == Type::Print);
208 return aData;
211 private:
212 Type aEvent;
213 std::vector<OUString> aData;
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 enum class DialogCancelMode {
234 Off, ///< do not automatically cancel dialogs
235 Silent, ///< silently cancel any dialogs
236 Fatal ///< cancel any dialogs by std::abort
239 /** @name Initialization
240 The following functions perform initialization and deinitialization
241 of the application.
243 ///@{
245 /** Default constructor for Application class.
247 Initializes the LibreOffice global instance data structure if needed,
248 and then sets itself to be the Application class. Also initializes any
249 platform specific data structures.
251 @attention The initialization of the application itself is done in Init()
253 @see InitSalData is implemented by platform specific code.
255 Application();
257 /** Virtual destructor for Application class.
259 Deinitializes the LibreOffice global instance data structure, then
260 deinitializes any platform specific data structures.
262 @see ImplDeInitSVData deinitializes the global instance data,
263 DeInitSalData is implemented by platform specific code
265 virtual ~Application();
267 /** Initialize the application itself.
269 @attention Note that the global data structures and platform specific
270 initialization is done in the constructor.
272 @see InitFinished, DeInit
274 virtual void Init();
276 /** Finish initialization of the application.
278 @see Init, DeInit
280 virtual void InitFinished();
282 /** Deinitialized the application itself.
284 @attention Note that the global data structures and platform specific
285 deinitialization is done in the destructor.
287 @see Init, InitFinished
289 virtual void DeInit();
291 ///@}
293 /** @brief Pure virtual entrypoint to the application.
295 Main() is the pure virtual entrypoint to your application. You
296 inherit your class from Application and subclass this function to
297 implement an application.
299 The Main() function does not pass in command line parameters,
300 you must use the functions GetCommandLineParamCount() and
301 GetCommandLineParam() to get these values as these are platform
302 independent ways of getting the command line (use GetAppFileName()
303 to get the invoked executable filename).
305 Once in this function, you create windows, etc. then call on
306 Execute() to start the application's main event loop.
308 An example code snippet follows (it won't compile, this just gives the
309 general flavour of the framework and is adapted from an old HelloWorld
310 example program that Star Division used to provide as part of their
311 library).
313 \code{.cpp}
314 class TheApplication : public Application
316 public:
317 virtual void Main();
320 class TheWindow : public WorkWindow
322 public:
323 TheWindow(vcl::Window *parent, WinBits windowStyle) :
324 WorkWindow(parent, windowStyle) {}
326 virtual void Paint(const Rectangle &);
329 void TheWindow::Paint(const Rectangle&)
331 DrawText(Point(100,100), String("Hello World!"));
334 void TheApplication::Main()
336 TheWindow aWindow(NULL, WB_APP | WB_STDWORK);
337 aWindow.Show();
338 Execute();
341 TheApplication anApplication;
342 \endcode
344 Some examples in the source tree can be found here:
346 vcl/workben/svdem.cxx
348 This is an example of how to use the Application and WorkWindow. Unfortunately, it
349 no longer compiles.
351 vcl/fpicker/test/svdem.cxx
353 virtual int Main();
355 /** Exit from the application
357 @returns true if exited successfully, false if not able to fully exit
359 virtual bool QueryExit();
361 /** @name Change Notification Functions
363 Functions that notify when changes occur in the application.
365 ///@{
367 /** Notify all windows that the application has changed data.
369 @param rDCEvt Reference to a DataChangedEvent object
371 @see DataChanged
373 static void NotifyAllWindows( DataChangedEvent& rDCEvt );
375 ///@}
377 /** @name Command Line Processing
379 Command line processing is done via the following functions. They
380 give the number of parameters, the parameters themselves and a way
381 to get the name of the invoking application.
384 ///@{
386 /** Gets the number of command line parameters passed to the application
388 @return sal_uInt16 - the number of parameters
390 @see GetCommandLineParam, GetAppFileName
392 static sal_uInt16 GetCommandLineParamCount();
394 /** Gets a particular command line parameter
396 @param nParam The index of the parameter to return.
398 @return The command line parameter as an OUString
400 @see GetCommandLineParamCount, GetAppFileName
402 static OUString GetCommandLineParam( sal_uInt16 nParam );
404 /** Get the name of the file used to start the application
406 @return The filename as an OUString
408 @see GetCommandLineParamCount, GetCommandLineParam
410 static OUString GetAppFileName();
412 ///@}
414 /** @name Error Handling
416 \em Very rudimentary error handling is done by these
417 functions.
422 /** Handles an error.
424 @param nCategory The error category, see include/vcl/exceptiontypes.hxx
426 @see Abort
428 virtual void Exception( ExceptionCategory nCategory );
430 /** Ends the program prematurely with an error message.
432 If the \code --norestore \endcode command line argument is given (assuming
433 this process is run by developers who are interested in cores,
434 vs. end users who are not) then it does a coredump.
436 @param rErrorText The error message to report.
438 @see Exception
440 static void Abort( const OUString& rErrorText );
442 ///@}
444 /** @name Event Loop Functions
446 Functions that handle the LibreOffice main event loop are here,
447 including a global lock called the Solar Mutex.
449 ///@{
451 /** Run the main event processing loop until it is quit by Quit().
453 @see Quit, Reschedule, Yield, EndYield, GetSolarMutex,
454 GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
456 static void Execute();
458 /** Quit the program
460 @see Execute, Reschedule, Yield, EndYield, GetSolarMutex,
461 GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
463 static void Quit();
465 /** Attempt to reschedule in processing of current event(s)
467 @param bAllEvents If set to true, then try to process all the
468 events. If set to false, then only process the current
469 event. Defaults to false.
471 @see Execute, Quit, Yield, EndYield, GetSolarMutex,
472 GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
474 static void Reschedule( bool bAllEvents = false );
476 /** Allow processing of the next event.
478 @see Execute, Quit, Reschedule, EndYield, GetSolarMutex,
479 GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
481 static void Yield();
485 @see Execute, Quit, Reschedule, Yield, GetSolarMutex,
486 GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
488 static void EndYield();
490 /** Acquire SolarMutex after it has been temporarily dropped completely.
492 This will Reschedule() on WNT and just acquire on other platforms.
494 static void ReAcquireSolarMutex(sal_uLong nReleased);
496 /** @brief Get the Solar Mutex for this thread.
498 Get the Solar Mutex that prevents other threads from accessing VCL
499 concurrently.
501 @returns SolarMutex reference
503 @see Execute, Quit, Reschedule, Yield, EndYield,
504 GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
506 static comphelper::SolarMutex& GetSolarMutex();
508 /** Get the main thread ID.
510 @returns oslThreadIdentifier that contains the thread ID
512 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
513 ReleaseSolarMutex, AcquireSolarMutex,
515 static oslThreadIdentifier GetMainThreadIdentifier();
517 /** @brief Release Solar Mutex(es) for this thread
519 Release the Solar Mutex(es) that prevents other threads from accessing
520 VCL concurrently.
522 @returns The number of mutexes that were acquired by this thread.
524 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
525 GetMainThreadIdentifier, AcquireSolarMutex,
527 static sal_uLong ReleaseSolarMutex();
529 /** @brief Acquire Solar Mutex(es) for this thread.
531 Acquire the Solar Mutex(es) that prevents other threads from accessing
532 VCL concurrently.
534 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
535 GetMainThreadIdentifier, ReleaseSolarMutex,
537 static void AcquireSolarMutex( sal_uLong nCount );
539 /** Queries whether the application is in "main", i.e. not yet in
540 the event loop
542 @returns true if in main, false if not in main
544 @see IsInExecute, IsInModalMode
546 static bool IsInMain();
548 /** Queries whether the application is in the event loop
550 @returns true if in the event loop, false if not
552 @see IsInMain, IsInModalMode
554 static bool IsInExecute();
556 /** Queries whether application has a modal dialog active.
558 @returns true if a modal dialog is active, false if not
560 @see IsInMain, IsInExecute
562 static bool IsInModalMode();
564 /** Return how many events are being dispatched.
566 @returns the number of events currently being dispatched
568 static sal_uInt16 GetDispatchLevel();
570 /** Determine if there are any pending input events.
572 @param nType input identifier, defined in include/vcl/inputtypes.hxx
573 The default is VCL_INPUT_ANY.
575 @returns true if there are pending events, false if not.
577 @see GetLastInputInterval
579 static bool AnyInput( VclInputFlags nType = VCL_INPUT_ANY );
581 /** The interval from the last time that input was received.
583 @returns system ticks - last input time
585 @see AnyInput
587 static sal_uInt64 GetLastInputInterval();
589 ///@}
591 /* Determines if the UI is captured.
593 The UI is considered captured if a system dialog is open (e.g. printer setup),
594 a floating window, menu or toolbox dropdown is open, or a window has been
595 captured by the mouse.
597 @returns true if UI is captured, false if not
599 static bool IsUICaptured();
601 /** @name Settings
603 The following functions set system settings (e.g. tab color, etc.). There are functions
604 that set settings objects, and functions that set and get the actual system settings for
605 the application.
607 ///@{
609 /** Sets user settings in settings object to override system settings
611 The system settings that can be overridden are:
612 - window dragging options (on or off, including live scrolling!)
613 - style settings (e.g. checkbox color, border color, 3D colors,
614 button rollover colors, etc.)
615 - mouse settings
616 - menu options, including the mouse follows the menu and whether menu
617 icons are used
619 @param rSettings Reference to the settings object to change.
621 @see MergeSystemSettings, SetSettings, GetSettings
623 virtual void OverrideSystemSettings( AllSettings& rSettings );
625 /** Set the settings object to the platform/desktop environment system
626 settings.
628 @param rSettings Reference to the settings object to change.
630 @see OverrideSystemSettings, SetSettings, GetSettings
632 static void MergeSystemSettings( AllSettings& rSettings );
634 /** Sets the application's settings and notifies all windows of the
635 change.
637 @param rSettings const reference to settings object used to
638 change the application's settings.
640 @see OverrideSystemSettings, MergeSystemSettings, GetSettings
642 static void SetSettings( const AllSettings& rSettings );
644 /** Gets the application's settings. If the application hasn't initialized
645 it's settings, then it does so (lazy initialization).
647 @returns AllSettings instance that contains the current settings of the
648 application.
650 @see OverrideSystemSettings, MergeSystemSettings, SetSettings
652 static const AllSettings& GetSettings();
654 /** Get the application's locale data wrapper.
656 @returns reference to a LocaleDataWrapper object
658 static const LocaleDataWrapper& GetAppLocaleDataWrapper();
660 ///@}
662 /** @name Event Listeners/Handlers
664 A set of event listeners and callers. Note that in this code there is
665 platform specific functions - namely for zoom and scroll events.
667 ///@{
670 /** Call on all event hooks
672 @param rEvt Reference to the notification event to send
673 to the event hook.
675 @return If any of the event hooks called upon fail with a non-zero
676 status, then it stops processing any more event hooks and returns
677 the error code as a long.
680 static long CallEventHooks( NotifyEvent& rEvt );
682 /** Add a VCL event listener to the application. If no event listener exists,
683 then initialize the application's event listener with a new one, then add
684 the event listener.
686 @param rEventListener Const reference to the event listener to add.
688 @see RemoveEventListener, AddKeyListener, RemoveKeyListener
690 static void AddEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
692 /** Remove a VCL event listener from the application.
694 @param rEventListener Const refernece to the event listener to be removed
696 @see AddEventListener, AddKeyListener, RemoveKeyListener
698 static void RemoveEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
700 /** Add a keypress listener to the application. If keypress listener exists,
701 then initialize the application's keypress event listener with a new one, then
702 add the keypress listener.
704 @param rKeyListener Const reference to the keypress event listener to add
706 @see AddEventListener, RemoveEventListener, RemoveKeyListener
708 static void AddKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
710 /** Remove a keypress listener from the application.
712 @param rKeyListener Const reference to the keypress event listener to be removed
714 @see AddEventListener, RemoveEventListener, AddKeyListener
716 static void RemoveKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
718 /** Send event to all VCL application event listeners
720 @param nEvent Event ID
721 @param pWin Pointer to window to send event
722 @param pData Pointer to data to send with event
724 @see ImplCallEventListeners(VclSimpleEvent* pEvent)
726 static void ImplCallEventListeners( VclEventId nEvent, vcl::Window* pWin, void* pData );
728 /** Send event to all VCL application event listeners
730 @param rEvent Reference to VclSimpleEvent
732 @see ImplCallEventListeners(sal_uLong nEvent, Windows* pWin, void* pData);
734 static void ImplCallEventListeners( VclSimpleEvent& rEvent );
736 /** Handle keypress event
738 @param nEvent Event ID for keypress
739 @param pWin Pointer to window that receives the event
740 @param pKeyEvent Received key event
742 @see PostKeyEvent
744 static bool HandleKey( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
746 /** Send keypress event
748 @param nEvent Event ID for keypress
749 @param pWin Pointer to window to which the event is sent
750 @param pKeyEvent Key event to send
752 @see HandleKey
754 static ImplSVEvent * PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
756 /** Send mouse event
758 @param nEvent Event ID for mouse event
759 @param pWin Pointer to window to which the event is sent
760 @param pMouseEvent Mouse event to send
762 static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent* pMouseEvent );
764 /** Remove mouse and keypress events from a window... any also zoom and scroll events
765 if the platform supports it.
767 @param pWin Window to remove events from
769 @see HandleKey, PostKeyEvent, PostMouseEvent
771 static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
773 /** Post a user event to the default window.
775 User events allow for the deferral of work to later in the main-loop - at idle.
777 Execution of the deferred work is thread-safe which means all the tasks are executed
778 serially, so no thread-safety locks between tasks are necessary.
780 @param rLink Link to event callback function
781 @param pCaller Pointer to data sent to the event by the caller. Optional.
782 @param bReferenceLink If true - hold a VclPtr<> reference on the Link's instance.
783 Taking the reference is guarded by a SolarMutexGuard.
785 @return the event ID used to post the event.
787 static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
788 bool bReferenceLink = false );
790 /** Remove user event based on event ID
792 @param nUserEvent User event to remove
794 static void RemoveUserEvent( ImplSVEvent * nUserEvent );
796 /*** Get the DisplayConnection.
798 It is a reference to XDisplayConnection, which allows toolkits to send display
799 events to the application.
801 @returns UNO reference to an object that implements the css:awt:XDisplayConnection
802 interface.
804 static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
806 /** @deprecated AppEvent is used only in the Desktop class now. However, it is
807 intended to notify the application that an event has occurred. It was in oldsv.cxx,
808 but is still needed by a number of functions.
810 @param rAppEvent const reference to ApplicationEvent event
812 virtual void AppEvent( const ApplicationEvent& rAppEvent );
814 ///@}
816 /** @name Application Window Functions
818 Functions that deal with the application's windows
820 ///@{
822 /** Get the main application window.
824 @remark the main application window (or App window) has a style of WB_APP,
825 there can only be on WorkWindow with this style, if a dialog or floating
826 window cannot find a parent, then the parent becomes the app window.
828 It also becomes the "default window", is used for help, is a fallback if
829 the application has no name, and a number of other things.
831 returns Pointer to main application window.
833 @see GetFocusWindow, GetDefaultDevice
835 static WorkWindow* GetAppWindow();
837 /** Get the currently focussed window.
839 @returns Pointer to focused window.
841 @see GetAppWindow, GetDefaultDevice
843 static vcl::Window* GetFocusWindow();
845 /** Get the default "device" (in this case the default window).
847 @returns Pointer to an OutputDevice. However, it is a Window object -
848 Window class subclasses OutputDevice.
850 @see GetAppWindow, GetFocusWindow
852 static OutputDevice* GetDefaultDevice();
854 /** Get the first top-level window of the application.
856 @returns Pointer to top-level window (a Window object)
858 @see GetNextTopLevelWindow, GetTopWindowCount, GetTopWindow,
859 GetActiveTopWindow
861 static vcl::Window* GetFirstTopLevelWindow();
863 /** Get the next top level window.
865 @param pWindow Pointer to Window object you wish to get the next
866 window from.
868 @returns Pointer to next top window.
870 static vcl::Window* GetNextTopLevelWindow( vcl::Window* pWindow );
872 /** Return the number of top-level windows being used by the application
874 @returns the number of top-level windows
876 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindow,
877 GetActiveTopWindow
880 static long GetTopWindowCount();
882 /** Get the nth top window.
884 @remark Top windows are actually implemented in a one-way linked list.
885 This iterates through top level windows n times.
887 @param nIndex The index of the top-level window
889 @returns The nth top-level window of the application
891 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
892 GetActiveTopWindow
894 static vcl::Window* GetTopWindow( long nIndex );
896 /** Get the "active" top window.
898 An "active" top window is one that has a child window that has the
899 application's focus.
901 @returns the active top window
903 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
904 GetTopWindow
906 static vcl::Window* GetActiveTopWindow();
908 ///@}
910 /** Set the application's name.
912 @param rUniqueName What to set the application name to
914 @see GetAppName
916 static void SetAppName( const OUString& rUniqueName );
919 /** @name Application Name, Branding
921 ///@{
923 /** Get the application's name.
925 @returns The application name.
927 static OUString GetAppName();
929 /** Get useful OS, Hardware and configuration information,
930 * cf. Help->About, and User-Agent
932 static OUString GetHWOSConfInfo();
934 /** Load a localized branding PNG file as a bitmap.
936 @param pName Name of the bitmap to load.
937 @param rBitmap Reference to BitmapEx object to load PNG into
939 @returns true if the PNG could be loaded, otherwise returns false.
941 static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
943 ///@}
945 /** @name Display and Screen
947 ///@{
949 /** Set the default name of the application for message dialogs and printing.
951 @param rDisplayName const reference to string to set the Display name to.
953 @see GetDisplayName
955 static void SetDisplayName( const OUString& rDisplayName );
957 /** Get the default name of the application for message dialogs and printing.
959 @returns The display name of the application.
961 static OUString GetDisplayName();
963 /** Get the toolkit's name. e.g. gtk3
965 @returns The toolkit name.
967 static OUString GetToolkitName();
969 /** Get the number of screens available for the display.
971 @returns The number of screens available.
973 @see GetScreenPosSizePixel
975 static unsigned int GetScreenCount();
977 /** Get a screen's rectangular area.
979 @param nScreen The number of the screen requested.
981 @returns The area of the screen in a Rectangle object.
983 @see GetScreenCount
985 static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
987 /** Determines if the screens that make up a display are separate or
988 form one large display area.
990 @returns true when screens form up one large display area windows can be
991 moved between single screens (e.g. Xserver with Xinerama, Windows)
992 and false when different screens are separate and windows cannot be moved
993 between them (e.g. Xserver with multiple screens)
995 @see GetBestScreen, GetDisplayBuiltInScreen
997 static bool IsUnifiedDisplay();
999 /** Get the "best" screen.
1001 @returns If IsUnifiedDisplay() == true the return value will be
1002 nearest screen of the target rectangle.
1004 In case of IsUnifiedDisplay() == false the return value
1005 will always be GetDisplayDefaultScreen().
1007 @see IsUnifiedDisplay, GetDisplayBuiltInScreen
1009 SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
1011 /** Get the built-in screen.
1013 @return
1014 This returns the LCD screen number for a laptop, or the primary
1015 external VGA display for a desktop machine - it is where a presenter
1016 console should be rendered if there are other (non-built-in) screens
1017 present.
1019 @see IsUnifiedDisplay, GetBestScreen
1021 static unsigned int GetDisplayBuiltInScreen();
1023 /** Get the display's external screen.
1025 Practically, this means - Get the screen we should run a presentation on.
1027 @returns 0 or 1 currently, will fallback to the first available screen if
1028 there are more than one external screens. May be changed in the future.
1030 static unsigned int GetDisplayExternalScreen();
1032 ///@}
1034 /** @name Accelerators and Mnemonics
1036 Accelerators allow a user to hold down Ctrl+key (or CMD+key on OS X)
1037 combination to gain quick access to functionality.
1039 Mnemonics are underline letters in things like menus and dialog boxes
1040 that allow a user to type in the letter to activate the menu or option.
1042 ///@{
1044 /** Insert accelerator
1046 @param pAccel Pointer to an Accelerator object to insert
1048 @returns true if successful, false if otherwise
1050 @see RemoveAccel
1052 static bool InsertAccel( Accelerator* pAccel );
1054 /** Remove accelerator
1056 @param pAccel Pointer to Accelerator object to remove
1058 @see InsertAccel
1060 static void RemoveAccel( Accelerator* pAccel );
1062 /** Get the number of reserved key codes used by the application.
1064 @returns number of reserved key codes
1066 @see GetReservedKeyCode
1068 static sal_uLong GetReservedKeyCodeCount();
1070 /** Get the reserved key code.
1072 @param i The keycode number to retrieve
1074 @returns Const pointer to a KeyCode object
1076 @see GetReservedKeyCodeCount
1078 static const vcl::KeyCode* GetReservedKeyCode( sal_uLong i );
1080 ///@}
1082 /** @name Application Help
1084 Deals with the help system, and "auto-help", where a user hovers a mouse above
1085 a UI element and a tooltip with an explanation pops up.
1087 ///@{
1089 /** Sets up help
1091 @param pHelp Pointer to a Help object (optional, can by NULL)
1093 @see GetHelp
1095 static void SetHelp( Help* pHelp = nullptr );
1097 /** Gets the application's help
1099 @returns Pointer to application's help object. Note that the application may
1100 not have a help object, so it might return NULL.
1102 @see SetHelp
1104 static Help* GetHelp();
1106 ///@}
1108 /** @name Dialogs
1110 @remark "Dialog cancel mode" tells a headless install whether to
1111 cancel dialogs when they appear. See the DialogCancelMode
1112 enumerator.
1114 ///@{
1116 /** Get the default parent window for dialog boxes.
1118 @remark GetDefDialogParent does all sorts of things find a useful parent
1119 window for dialogs. It first uses the topmost parent of the active
1120 window to avoid using floating windows or other dialog boxes. If
1121 there are no active windows, then it will take a random stab and
1122 choose the first visible top window. Otherwise, it defaults to
1123 the desktop.
1125 @returns Pointer to the default window.
1127 static vcl::Window* GetDefDialogParent();
1130 /** Gets the dialog cancel mode for headless environments.
1132 @return DialogCancelMode value
1134 @see SetDialogCancelMode, IsDialogCancelEnabled
1136 static DialogCancelMode GetDialogCancelMode();
1138 /** Sets the dialog cancel mode for headless environments.
1140 @param mode DialogCancel mode value
1142 @see GetDialogCancelMode, IsDialogCancelEnabled
1144 static void SetDialogCancelMode( DialogCancelMode mode );
1146 /** Determines if dialog cancel mode is enabled.
1148 @returns True if dialog cancel mode is enabled, false if disabled.
1150 @see GetDialogCancelMode, SetDialogCancelMode
1152 static bool IsDialogCancelEnabled();
1155 /** Make a dialog box a system window or not.
1157 @param nMode Can be either: SystemWindowFlags::NOAUTOMODE (0x0001) or
1158 SystemWindowFlags::DIALOG (0x0002)
1160 @see GetSystemWindowMode
1162 static void SetSystemWindowMode( SystemWindowFlags nMode );
1164 /** Get the system window mode of dialogs.
1166 @returns SystemWindowFlags::NOAUTOMODE (0x0001) or SystemWindowFlags::DIALOG (0x0002)
1168 @see SetSystemWindowMode
1170 static SystemWindowFlags GetSystemWindowMode();
1172 ///@}
1174 /** @name VCL Toolkit and UNO Wrapper
1176 The VCL Toolkit implements the UNO XToolkit interface, which specifies a
1177 factory interface for the window toolkit. It is similar to the abstract window
1178 toolkit (AWT) in Java.
1181 ///@{
1183 /** Gets the VCL toolkit.
1185 @attention The global service manager has to be created before getting the toolkit!
1187 @returns UNO reference to VCL toolkit
1189 static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1191 /** Get the application's UNO wrapper object.
1193 Note that this static function will only ever try to create UNO wrapper object once, and
1194 if it fails then it will not ever try again, even if the function is called multiple times.
1196 @param bCreateIfNotExists Create the UNO wrapper object if it doesn't exist when true.
1198 @return UNO wrapper object.
1200 static UnoWrapperBase* GetUnoWrapper( bool bCreateIfNotExists = true );
1202 /** Sets the application's UNO Wrapper object.
1204 @param pWrapper Pointer to UNO wrapper object.
1206 static void SetUnoWrapper( UnoWrapperBase* pWrapper );
1208 ///@}
1211 /*** @name Graphic Filters
1213 ///@{
1215 /** Setup a new graphics filter
1217 @param rLink Const reference to a Link object, which the filter calls upon.
1219 @see GetFilterHdl
1221 static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1223 ///@}
1225 /** @name Headless Mode
1228 /** Enables headless mode.
1230 @param dialogsAreFatal Set to true if a dialog ends the session, false if not.
1232 static void EnableHeadlessMode( bool dialogsAreFatal );
1234 /** Determines if headless mode is enabled
1236 @return True if headless mode is enabled, false if not.
1238 static bool IsHeadlessModeEnabled();
1240 /** Enable Console Only mode
1242 Used to disable Mac specific app init that requires an app bundle.
1244 static void EnableConsoleOnly();
1246 /** Determines if console only mode is enabled.
1248 Used to see if Mac specific app init has been disabled.
1250 @returns True if console only mode is on, false if not.
1252 @see EnableConsoleOnly
1254 static bool IsConsoleOnly();
1256 ///@}
1258 /** @name Event Testing Mode
1261 /** Enables event testing mode.
1264 static void EnableEventTestingMode();
1266 /** Determines if event testing mode is enabled
1268 @return True if event testing mode is enabled, false if not.
1270 static bool IsEventTestingModeEnabled();
1272 /** Set safe mode to enabled */
1273 static void EnableSafeMode();
1275 /** Determines if safe mode is enabled */
1276 static bool IsSafeModeEnabled();
1278 ///@}
1280 /** @name IME Status Window Control
1282 ///@{
1284 /** Determine application can toggle the IME status window on and off.
1286 @attention Must only be called with the Solar mutex locked.
1288 @return true if any IME status window can be toggled on and off
1289 externally.
1291 @see ShowImeStatusWindow, GetShowImeStatusWindowDefault,
1292 GetShowImeStatusWindowDefault
1294 static bool CanToggleImeStatusWindow();
1296 /** Toggle any IME status window on and off.
1298 This only works if CanToggleImeStatusWindow returns true (otherwise,
1299 any calls of this method are ignored).
1301 @remark Can be called without the Solar mutex locked.
1303 @param bShow If true, then show the IME status window
1305 @see GetShowImeStatusWindowDefault, CanToggleImeStatusWindow,
1306 GetShowImeStatusWindow
1308 static void ShowImeStatusWindow(bool bShow);
1310 /** Determines if the IME status window should be turned of by default.
1312 @return true if any IME status window should be turned on by default
1313 (this decision can be locale dependent, for example).
1315 @see ShowImeStatusWindow, GetShowImeStatusWindowDefault,
1316 CanToggleImeStatusWindow
1318 static bool GetShowImeStatusWindowDefault();
1320 ///@}
1322 /** Get the desktop environment the process is currently running in
1324 @returns String representing the desktop environment
1326 static const OUString& GetDesktopEnvironment();
1328 /*** @name Platform Functionality
1330 ///@{
1332 /** Add a file to the system shells recent document list if there is any.
1333 This function may have no effect under Unix because there is no standard
1334 API among the different desktop managers.
1336 @param rFileUrl The file url of the document.
1338 @param rMimeType The mime content type of the document specified by aFileUrl.
1339 If an empty string will be provided "application/octet-stream"
1340 will be used.
1342 @param rDocumentService The app (or "document service") you will be adding the file to
1343 e.g. com.sun.star.text.TextDocument
1345 static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1347 /*** Show a native error messagebox
1349 @param sTitle Title of error messagebox
1351 @param sMessage Message displayed in messagebox
1353 static void ShowNativeErrorBox(const OUString& sTitle ,
1354 const OUString& sMessage);
1356 /** Do we have a native / system file selector available?
1358 @returns True if native file selector is available, false otherwise.
1360 static bool hasNativeFileSelection();
1362 /** Create a platform specific file picker, if one is available, otherwise return an
1363 empty reference.
1365 @param rServiceManager Const reference to a UNO component context (service manager).
1367 @returns File picker if available, otherwise an empty reference.
1369 static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1370 createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1372 /** Create a platform specific folder picker, if one is available, otherwise return an
1373 empty reference
1375 @param rServiceManager Const reference to a UNO component context (service manager).
1377 @returns Folder picker if available, otherwise an empty reference.
1379 static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1380 createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1382 /** Cancel all open dialogs
1384 static void EndAllDialogs();
1386 /** Cancel all open popups
1388 static void EndAllPopups();
1390 ///@}
1392 // For vclbootstrapprotector:
1393 static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1395 private:
1396 DECL_STATIC_LINK( Application, PostEventHandler, void*, void );
1400 class VCL_DLLPUBLIC SolarMutexGuard
1402 private:
1403 SolarMutexGuard( const SolarMutexGuard& ) = delete;
1404 const SolarMutexGuard& operator = ( const SolarMutexGuard& ) = delete;
1405 comphelper::SolarMutex& m_solarMutex;
1407 public:
1408 /** Acquires the object specified as parameter.
1410 SolarMutexGuard() :
1411 m_solarMutex(Application::GetSolarMutex())
1413 m_solarMutex.acquire();
1416 /** Releases the mutex or interface. */
1417 ~SolarMutexGuard()
1419 m_solarMutex.release();
1423 class VCL_DLLPUBLIC SolarMutexClearableGuard final
1425 SolarMutexClearableGuard( const SolarMutexClearableGuard& ) = delete;
1426 const SolarMutexClearableGuard& operator = ( const SolarMutexClearableGuard& ) = delete;
1427 bool m_bCleared;
1428 comphelper::SolarMutex& m_solarMutex;
1429 public:
1430 /** Acquires mutex
1432 SolarMutexClearableGuard()
1433 : m_bCleared(false)
1434 , m_solarMutex( Application::GetSolarMutex() )
1436 m_solarMutex.acquire();
1439 /** Releases mutex. */
1440 ~SolarMutexClearableGuard()
1442 if( !m_bCleared )
1444 m_solarMutex.release();
1448 /** Releases mutex. */
1449 void SAL_CALL clear()
1451 if( !m_bCleared )
1453 m_solarMutex.release();
1454 m_bCleared = true;
1459 class VCL_DLLPUBLIC SolarMutexResettableGuard final
1461 SolarMutexResettableGuard( const SolarMutexResettableGuard& ) = delete;
1462 const SolarMutexResettableGuard& operator = ( const SolarMutexResettableGuard& ) = delete;
1463 bool m_bCleared;
1464 comphelper::SolarMutex& m_solarMutex;
1465 public:
1466 /** Acquires mutex
1468 SolarMutexResettableGuard()
1469 : m_bCleared(false)
1470 , m_solarMutex( Application::GetSolarMutex() )
1472 m_solarMutex.acquire();
1475 /** Releases mutex. */
1476 ~SolarMutexResettableGuard()
1478 if( !m_bCleared )
1480 m_solarMutex.release();
1484 /** Releases mutex. */
1485 void SAL_CALL clear()
1487 if( !m_bCleared)
1489 m_solarMutex.release();
1490 m_bCleared = true;
1494 /** Re-acquires mutex. */
1495 void SAL_CALL reset()
1497 if( m_bCleared)
1499 m_solarMutex.acquire();
1500 m_bCleared = false;
1505 namespace vcl
1508 /** guard class that uses tryToAcquire() and has isAcquired() to check
1510 class SolarMutexTryAndBuyGuard
1512 private:
1513 bool m_isAcquired;
1514 #ifdef DBG_UTIL
1515 bool m_isChecked;
1516 #endif
1517 comphelper::SolarMutex& m_rSolarMutex;
1519 SolarMutexTryAndBuyGuard(const SolarMutexTryAndBuyGuard&) = delete;
1520 SolarMutexTryAndBuyGuard& operator=(const SolarMutexTryAndBuyGuard&) = delete;
1522 public:
1524 SolarMutexTryAndBuyGuard()
1525 : m_isAcquired(false)
1526 #ifdef DBG_UTIL
1527 , m_isChecked(false)
1528 #endif
1529 , m_rSolarMutex(Application::GetSolarMutex())
1532 m_isAcquired = m_rSolarMutex.tryToAcquire();
1535 ~SolarMutexTryAndBuyGuard()
1537 #ifdef DBG_UTIL
1538 assert(m_isChecked);
1539 #endif
1540 if (m_isAcquired)
1541 m_rSolarMutex.release();
1544 bool isAcquired()
1546 #ifdef DBG_UTIL
1547 m_isChecked = true;
1548 #endif
1549 return m_isAcquired;
1553 } // namespace vcl
1556 A helper class that calls Application::ReleaseSolarMutex() in its constructor
1557 and restores the mutex in its destructor.
1559 class SolarMutexReleaser
1561 sal_uLong mnReleased;
1563 public:
1564 SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1566 ~SolarMutexReleaser()
1568 Application::ReAcquireSolarMutex(mnReleased);
1572 VCL_DLLPUBLIC Application* GetpApp();
1574 VCL_DLLPUBLIC bool InitVCL();
1575 VCL_DLLPUBLIC void DeInitVCL();
1577 VCL_DLLPUBLIC bool InitAccessBridge();
1579 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1580 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1581 VCL_DLLPUBLIC void JoinMainLoopThread();
1583 inline void Application::EndYield()
1585 PostUserEvent( Link<void*,void>() );
1588 #endif // _APP_HXX
1590 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */