Bump version to 21.06.18.1
[LibreOffice.git] / include / vcl / svapp.hxx
blob3746b09dcc6a5990cf80ed37bc13e3102c603ad6
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 <LibreOfficeKit/LibreOfficeKitTypes.h>
31 #include <osl/mutex.hxx>
32 #include <rtl/ustring.hxx>
33 #include <osl/thread.h>
34 #include <tools/gen.hxx>
35 #include <tools/link.hxx>
36 #include <vcl/dllapi.h>
37 #include <vcl/IDialogRenderable.hxx>
38 #include <vcl/inputtypes.hxx>
39 #include <vcl/exceptiontypes.hxx>
40 #include <vcl/vclevent.hxx>
41 #include <vcl/vclenum.hxx>
42 #include <i18nlangtag/lang.h>
43 #include <o3tl/typed_flags_set.hxx>
44 #include <com/sun/star/uno/Reference.h>
47 class BitmapEx;
48 namespace weld
50 class Builder;
51 class MessageDialog;
52 class Widget;
53 class Window;
55 class LocaleDataWrapper;
56 class AllSettings;
57 class DataChangedEvent;
58 class Accelerator;
59 class Help;
60 class OutputDevice;
61 namespace vcl { class Window; }
62 namespace vcl { class KeyCode; }
63 class NotifyEvent;
64 class KeyEvent;
65 class MouseEvent;
66 class GestureEvent;
67 struct ImplSVEvent;
68 struct ConvertData;
70 namespace com::sun::star::uno {
71 class XComponentContext;
73 namespace com::sun::star::ui::dialogs {
74 class XFilePicker2;
75 class XFolderPicker2;
77 namespace com::sun::star::awt {
78 class XToolkit;
79 class XDisplayConnection;
80 class XWindow;
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 Open, ///< Open a document
122 OpenHelpUrl, ///< Open a help URL
123 Print, ///< Print document
124 PrivateDoShutdown, ///< Shutdown application
125 QuickStart, ///< Start QuickStart
126 ShowDialog, ///< Show a dialog
127 Unaccept ///< Stop listening for connections
130 /** Explicit constructor for ApplicationEvent.
132 @attention Type::Appear, Type::PrivateDoShutdown and
133 Type::QuickStart are the \em only events that don't need to include
134 a data string with the event. No other events should use this
135 constructor!
137 explicit ApplicationEvent(Type type): aEvent(type)
139 assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
142 /** Constructor for ApplicationEvent, accepts a string for the data
143 associated with the event.
145 @attention Type::Accept, Type::OpenHelpUrl, Type::ShowDialog
146 and Type::Unaccept are the \em only events that accept a single
147 string as event data. No other events should use this constructor!
149 ApplicationEvent(Type type, OUString const & data): aEvent(type)
151 assert(
152 type == Type::Accept || type == Type::OpenHelpUrl
153 || type == Type::ShowDialog || type == Type::Unaccept);
154 aData.push_back(data);
157 /** Constructor for ApplicationEvent, accepts an array of strings for
158 the data associated with the event.
160 @attention Type::Open and Type::Print can apply to multiple documents,
161 and are the \em only events that accept an array of strings. No other
162 events should use this constructor.
164 ApplicationEvent(Type type, std::vector<OUString> const & data):
165 aEvent(type), aData(data)
167 assert(type == Type::Open || type == Type::Print);
170 /** Get the type of event.
172 @returns The type of event.
174 Type GetEvent() const
176 return aEvent;
179 /** Gets the application event's data string.
181 @attention The \em only events that need a single string Type::Accept,
182 Type::OpenHelpUrl, Type::ShowDialog and Type::Unaccept
184 @returns The event's data string.
186 OUString const & GetStringData() const
188 assert(
189 aEvent == Type::Accept
190 || aEvent == Type::OpenHelpUrl || aEvent == Type::ShowDialog
191 || aEvent == Type::Unaccept);
192 assert(aData.size() == 1);
193 return aData[0];
196 /** Gets the event's array of strings.
198 @attention The \em only events that need an array of strings
199 are Type::Open and Type::Print.
201 std::vector<OUString> const & GetStringsData() const
203 assert(aEvent == Type::Open || aEvent == Type::Print);
204 return aData;
207 private:
208 Type aEvent;
209 std::vector<OUString> aData;
212 enum class DialogCancelMode {
213 Off, ///< do not automatically cancel dialogs
214 Silent, ///< silently cancel any dialogs
215 LOKSilent, ///< silently cancel any dialogs (LOK case)
216 Fatal ///< cancel any dialogs by std::abort
220 @brief Base class used mainly for the LibreOffice Desktop class.
222 The Application class is a base class mainly used by the Desktop
223 class. It is really meant to be subclassed, and the Main() function
224 should be overridden. Many of the ImplSVData members should be
225 moved to this class.
227 The reason Application exists is because the VCL used to be a
228 standalone framework, long since abandoned by anything other than
229 our application.
231 @see Desktop, ImplSVData
233 class VCL_DLLPUBLIC Application : public vcl::ILibreOfficeKitNotifier
235 public:
236 /** @name Initialization
237 The following functions perform initialization and deinitialization
238 of the application.
240 ///@{
242 /** Default constructor for Application class.
244 Initializes the LibreOffice global instance data structure if needed,
245 and then sets itself to be the Application class. Also initializes any
246 platform specific data structures.
248 @attention The initialization of the application itself is done in Init()
250 Application();
252 /** Virtual destructor for Application class.
254 Deinitializes the LibreOffice global instance data structure, then
255 deinitializes any platform specific data structures.
257 virtual ~Application();
259 /** Initialize the application itself.
261 @attention Note that the global data structures and platform specific
262 initialization is done in the constructor.
264 @see InitFinished, DeInit
266 virtual void Init();
268 /** Finish initialization of the application.
270 @see Init, DeInit
272 virtual void InitFinished();
274 /** Deinitialized the application itself.
276 @attention Note that the global data structures and platform specific
277 deinitialization is done in the destructor.
279 @see Init, InitFinished
281 virtual void DeInit();
283 ///@}
285 /** @brief Pure virtual entrypoint to the application.
287 Main() is the pure virtual entrypoint to your application. You
288 inherit your class from Application and subclass this function to
289 implement an application.
291 The Main() function does not pass in command line parameters,
292 you must use the functions GetCommandLineParamCount() and
293 GetCommandLineParam() to get these values as these are platform
294 independent ways of getting the command line (use GetAppFileName()
295 to get the invoked executable filename).
297 Once in this function, you create windows, etc. then call on
298 Execute() to start the application's main event loop.
300 An example code snippet follows (it won't compile, this just gives the
301 general flavour of the framework and is adapted from an old HelloWorld
302 example program that Star Division used to provide as part of their
303 library).
305 \code{.cpp}
306 class TheApplication : public Application
308 public:
309 virtual void Main();
312 class TheWindow : public WorkWindow
314 public:
315 TheWindow(vcl::Window *parent, WinBits windowStyle) :
316 WorkWindow(parent, windowStyle) {}
318 virtual void Paint(const Rectangle &);
321 void TheWindow::Paint(const Rectangle&)
323 DrawText(Point(100,100), String("Hello World!"));
326 void TheApplication::Main()
328 TheWindow aWindow(NULL, WB_APP | WB_STDWORK);
329 aWindow.Show();
330 Execute();
333 TheApplication anApplication;
334 \endcode
336 Some examples in the source tree can be found here:
338 vcl/workben/svdem.cxx
340 This is an example of how to use the Application and WorkWindow. Unfortunately, it
341 no longer compiles.
343 vcl/fpicker/test/svdem.cxx
345 virtual int Main();
347 /** Exit from the application
349 @returns true if exited successfully, false if not able to fully exit
351 virtual bool QueryExit();
353 virtual void Shutdown();
355 /** @name Change Notification Functions
357 Functions that notify when changes occur in the application.
359 ///@{
361 /** Notify all windows that the application has changed data.
363 @param rDCEvt Reference to a DataChangedEvent object
365 @see DataChanged
367 static void NotifyAllWindows( DataChangedEvent& rDCEvt );
369 ///@}
371 /** @name Command Line Processing
373 Command line processing is done via the following functions. They
374 give the number of parameters, the parameters themselves and a way
375 to get the name of the invoking application.
378 ///@{
380 /** Gets the number of command line parameters passed to the application
382 @return sal_uInt16 - the number of parameters
384 @see GetCommandLineParam, GetAppFileName
386 static sal_uInt16 GetCommandLineParamCount();
388 /** Gets a particular command line parameter
390 @param nParam The index of the parameter to return.
392 @return The command line parameter as an OUString
394 @see GetCommandLineParamCount, GetAppFileName
396 static OUString GetCommandLineParam( sal_uInt16 nParam );
398 /** Get the name of the file used to start the application
400 @return The filename as an OUString
402 @see GetCommandLineParamCount, GetCommandLineParam
404 static OUString GetAppFileName();
406 ///@}
408 /** @name Error Handling
410 \em Very rudimentary error handling is done by these
411 functions.
416 /** Handles an error.
418 @param nCategory The error category, see include/vcl/exceptiontypes.hxx
420 @see Abort
422 virtual void Exception( ExceptionCategory nCategory );
424 /** Ends the program prematurely with an error message.
426 If the \code --norestore \endcode command line argument is given (assuming
427 this process is run by developers who are interested in cores,
428 vs. end users who are not) then it does a coredump.
430 @param rErrorText The error message to report.
432 @see Exception
434 static void Abort( const OUString& rErrorText );
436 ///@}
438 /** @name Event Loop Functions
440 Functions that handle the LibreOffice main event loop are here,
441 including a global lock called the Solar Mutex.
443 ///@{
445 /** Run the main event processing loop until it is quit by Quit().
447 @see Quit, Reschedule, Yield, EndYield, GetSolarMutex,
448 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
450 static void Execute();
452 /** Quit the program
454 @see Execute, Reschedule, Yield, EndYield, GetSolarMutex,
455 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
457 static void Quit();
459 /** Has Quit() been called?
461 static bool IsQuit();
463 /** Attempt to process current pending event(s)
465 It doesn't sleep if no events are available for processing.
466 This doesn't process any events generated after invoking the function.
467 So in contrast to Scheduler::ProcessEventsToIdle, this cannot become
468 busy-locked by an event-generating event in the event queue.
470 @param bHandleAllCurrentEvents If set to true, then try to process all
471 the current events. If set to false, then only process one event.
472 Defaults to false.
474 @returns true if any event was processed.
476 @see Yield, Scheduler::ProcessEventsToIdle
478 static bool Reschedule( bool bHandleAllCurrentEvents = false );
480 /** Process the next event.
482 It sleeps if no event is available for processing and just returns
483 if an event was processed.
485 @see Execute, Quit, Reschedule, EndYield, GetSolarMutex,
486 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
488 static void Yield();
492 @see Execute, Quit, Reschedule, Yield, GetSolarMutex,
493 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
495 static void EndYield();
497 /** @brief Get the Solar Mutex for this thread.
499 Get the Solar Mutex that prevents other threads from accessing VCL
500 concurrently.
502 @returns SolarMutex reference
504 @see Execute, Quit, Reschedule, Yield, EndYield,
505 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
507 static comphelper::SolarMutex& GetSolarMutex();
509 /** Queries whether we are in main thread.
511 @returns true if we are in main thread, false if not
513 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
514 ReleaseSolarMutex, AcquireSolarMutex,
516 static bool IsMainThread();
518 /** @brief Release Solar Mutex(es) for this thread
520 Release the Solar Mutex(es) that prevents other threads from accessing
521 VCL concurrently.
523 @returns The number of mutexes that were acquired by this thread.
525 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
526 IsMainThread, AcquireSolarMutex,
528 static sal_uInt32 ReleaseSolarMutex();
530 /** @brief Acquire Solar Mutex(es) for this thread.
532 Acquire the Solar Mutex(es) that prevents other threads from accessing
533 VCL concurrently.
535 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
536 IsMainThread, ReleaseSolarMutex,
538 static void AcquireSolarMutex( sal_uInt32 nCount );
540 /** Queries whether the application is in "main", i.e. not yet in
541 the event loop
543 @returns true if in main, false if not in main
545 @see IsInExecute, IsInModalMode
547 static bool IsInMain();
549 /** Queries whether the application is in the event loop
551 @returns true if in the event loop, false if not
553 @see IsInMain, IsInModalMode
555 static bool IsInExecute();
557 /** Queries whether application has a modal dialog active.
559 @returns true if a modal dialog is active, false if not
561 @see IsInMain, IsInExecute
563 static bool IsInModalMode();
565 /** Return how many events are being dispatched.
567 @returns the number of events currently being dispatched
569 static sal_uInt16 GetDispatchLevel();
571 /** Determine if there are any pending input events.
573 @param nType input identifier, defined in include/vcl/inputtypes.hxx
574 The default is VCL_INPUT_ANY.
576 @returns true if there are pending events, false if not.
578 @see GetLastInputInterval
580 static bool AnyInput( VclInputFlags nType = VCL_INPUT_ANY );
582 /** The interval from the last time that input was received.
584 @returns system ticks - last input time
586 @see AnyInput
588 static sal_uInt64 GetLastInputInterval();
590 ///@}
592 /* Determines if the UI is captured.
594 The UI is considered captured if a system dialog is open (e.g. printer setup),
595 a floating window, menu or toolbox dropdown is open, or a window has been
596 captured by the mouse.
598 @returns true if UI is captured, false if not
600 static bool IsUICaptured();
602 /** @name Settings
604 The following functions set system settings (e.g. tab color, etc.). There are functions
605 that set settings objects, and functions that set and get the actual system settings for
606 the application.
608 ///@{
610 /** Sets user settings in settings object to override system settings
612 The system settings that can be overridden are:
613 - window dragging options (on or off, including live scrolling!)
614 - style settings (e.g. checkbox color, border color, 3D colors,
615 button rollover colors, etc.)
616 - mouse settings
617 - menu options, including the mouse follows the menu and whether menu
618 icons are used
620 @param rSettings Reference to the settings object to change.
622 @see MergeSystemSettings, SetSettings, GetSettings
624 virtual void OverrideSystemSettings( AllSettings& rSettings );
626 /** Set the settings object to the platform/desktop environment system
627 settings.
629 @param rSettings Reference to the settings object to change.
631 @see OverrideSystemSettings, SetSettings, GetSettings
633 static void MergeSystemSettings( AllSettings& rSettings );
635 /** Sets the application's settings and notifies all windows of the
636 change.
638 @param rSettings const reference to settings object used to
639 change the application's settings.
641 @see OverrideSystemSettings, MergeSystemSettings, GetSettings
643 static void SetSettings( const AllSettings& rSettings );
645 /** Gets the application's settings. If the application hasn't initialized
646 it's settings, then it does so (lazy initialization).
648 @returns AllSettings instance that contains the current settings of the
649 application.
651 @see OverrideSystemSettings, MergeSystemSettings, SetSettings
653 static const AllSettings& GetSettings();
655 /** Get the application's locale data wrapper.
657 @returns reference to a LocaleDataWrapper object
659 static const LocaleDataWrapper& GetAppLocaleDataWrapper();
661 ///@}
663 /** @name Event Listeners/Handlers
665 A set of event listeners and callers. Note that in this code there is
666 platform specific functions - namely for zoom and scroll events.
668 ///@{
671 /** Add a VCL event listener to the application. If no event listener exists,
672 then initialize the application's event listener with a new one, then add
673 the event listener.
675 @param rEventListener Const reference to the event listener to add.
677 @see RemoveEventListener, AddKeyListener, RemoveKeyListener
679 static void AddEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
681 /** Remove a VCL event listener from the application.
683 @param rEventListener Const reference to the event listener to be removed
685 @see AddEventListener, AddKeyListener, RemoveKeyListener
687 static void RemoveEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
689 /** Add a keypress listener to the application. If keypress listener exists,
690 then initialize the application's keypress event listener with a new one, then
691 add the keypress listener.
693 @param rKeyListener Const reference to the keypress event listener to add
695 @see AddEventListener, RemoveEventListener, RemoveKeyListener
697 static void AddKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
699 /** Remove a keypress listener from the application.
701 @param rKeyListener Const reference to the keypress event listener to be removed
703 @see AddEventListener, RemoveEventListener, AddKeyListener
705 static void RemoveKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
707 /** Send event to all VCL application event listeners
709 @param pWin Pointer to window to send event
710 @param pData Pointer to data to send with event
712 @see ImplCallEventListeners(VclSimpleEvent* pEvent)
714 static void ImplCallEventListenersApplicationDataChanged( void* pData );
716 /** Send event to all VCL application event listeners
718 @param rEvent Reference to VclSimpleEvent
720 @see ImplCallEventListeners(sal_uLong nEvent, Windows* pWin, void* pData);
722 static void ImplCallEventListeners( VclSimpleEvent& rEvent );
724 /** Handle keypress event
726 @param nEvent Event ID for keypress
727 @param pWin Pointer to window that receives the event
728 @param pKeyEvent Received key event
730 @see PostKeyEvent
732 static bool HandleKey( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
734 /** Send keypress event
736 @param nEvent Event ID for keypress
737 @param pWin Pointer to window to which the event is sent
738 @param pKeyEvent Key event to send
740 @see HandleKey
742 static ImplSVEvent * PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, KeyEvent const * pKeyEvent );
745 static bool LOKHandleMouseEvent( VclEventId nEvent, vcl::Window *pWin, const MouseEvent* pEvent );
747 /** Send mouse event
749 @param nEvent Event ID for mouse event
750 @param pWin Pointer to window to which the event is sent
751 @param pMouseEvent Mouse event to send
753 static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
755 static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin, GestureEvent const * pGestureEvent);
757 /** Remove mouse and keypress events from a window... any also zoom and scroll events
758 if the platform supports it.
760 @param pWin Window to remove events from
762 @see HandleKey, PostKeyEvent, PostMouseEvent
764 static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
766 /** Post a user event to the default window.
768 User events allow for the deferral of work to later in the main-loop - at idle.
770 Execution of the deferred work is thread-safe which means all the tasks are executed
771 serially, so no thread-safety locks between tasks are necessary.
773 @param rLink Link to event callback function
774 @param pCaller Pointer to data sent to the event by the caller. Optional.
775 @param bReferenceLink If true - hold a VclPtr<> reference on the Link's instance.
776 Taking the reference is guarded by a SolarMutexGuard.
778 @return the event ID used to post the event.
780 static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
781 bool bReferenceLink = false );
783 /** Remove user event based on event ID
785 @param nUserEvent User event to remove
787 static void RemoveUserEvent( ImplSVEvent * nUserEvent );
789 /*** Get the DisplayConnection.
791 It is a reference to XDisplayConnection, which allows toolkits to send display
792 events to the application.
794 @returns UNO reference to an object that implements the css:awt:XDisplayConnection
795 interface.
797 static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
799 /** @deprecated AppEvent is used only in the Desktop class now. However, it is
800 intended to notify the application that an event has occurred. It was in oldsv.cxx,
801 but is still needed by a number of functions.
803 @param rAppEvent const reference to ApplicationEvent event
805 virtual void AppEvent( const ApplicationEvent& rAppEvent );
807 ///@}
809 /** @name Application Window Functions
811 Functions that deal with the application's windows
813 ///@{
815 /** Get the currently focused window.
817 @returns Pointer to focused window.
819 @see GetDefaultDevice
821 static vcl::Window* GetFocusWindow();
823 /** Get the default "device" (in this case the default window).
825 @returns Pointer to an OutputDevice. However, it is a Window object -
826 Window class subclasses OutputDevice.
828 @see GetFocusWindow
830 static OutputDevice* GetDefaultDevice();
832 /** Get the first top-level window of the application.
834 @returns Pointer to top-level window (a Window object)
836 @see GetNextTopLevelWindow, GetTopWindowCount, GetTopWindow,
837 GetActiveTopWindow
839 static vcl::Window* GetFirstTopLevelWindow();
841 /** Get the next top level window.
843 @param pWindow Pointer to Window object you wish to get the next
844 window from.
846 @returns Pointer to next top window.
848 static vcl::Window* GetNextTopLevelWindow( vcl::Window const * pWindow );
850 /** Return the number of top-level windows being used by the application
852 @returns the number of top-level windows
854 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindow,
855 GetActiveTopWindow
858 static tools::Long GetTopWindowCount();
860 /** Get the nth top window.
862 @remark Top windows are actually implemented in a one-way linked list.
863 This iterates through top level windows n times.
865 @param nIndex The index of the top-level window
867 @returns The nth top-level window of the application
869 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
870 GetActiveTopWindow
872 static vcl::Window* GetTopWindow( tools::Long nIndex );
874 /** Get the "active" top window.
876 An "active" top window is one that has a child window that has the
877 application's focus.
879 @returns the active top window
881 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
882 GetTopWindow
884 static vcl::Window* GetActiveTopWindow();
886 ///@}
888 /** Set the application's name.
890 @param rUniqueName What to set the application name to
892 @see GetAppName
894 static void SetAppName( const OUString& rUniqueName );
897 /** @name Application Name, Branding
899 ///@{
901 /** Get the application's name.
903 @returns The application name.
905 static OUString GetAppName();
907 /** Get useful OS, Hardware and configuration information,
908 * cf. Help->About, and User-Agent
909 * bSelection = 0 to return all info, 1 for environment only,
910 * and 2 for VCL/render related infos
912 static OUString GetHWOSConfInfo(const int bSelection = 0, bool bLocalize = true);
914 /** Load a localized branding PNG file as a bitmap.
916 @param pName Name of the bitmap to load.
917 @param rBitmap Reference to BitmapEx object to load PNG into
919 @returns true if the PNG could be loaded, otherwise returns false.
921 static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
923 ///@}
925 /** @name Display and Screen
927 ///@{
929 /** Set the default name of the application for message dialogs and printing.
931 @param rDisplayName const reference to string to set the Display name to.
933 @see GetDisplayName
935 static void SetDisplayName( const OUString& rDisplayName );
937 /** Get the default name of the application for message dialogs and printing.
939 @returns The display name of the application.
941 static OUString GetDisplayName();
943 /** Get the toolkit's name. e.g. gtk3
945 @returns The toolkit name.
947 static OUString GetToolkitName();
949 /** Get the number of screens available for the display.
951 @returns The number of screens available.
953 @see GetScreenPosSizePixel
955 static unsigned int GetScreenCount();
957 /** Get a screen's rectangular area.
959 @param nScreen The number of the screen requested.
961 @returns The area of the screen in a Rectangle object.
963 @see GetScreenCount
965 static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
967 /** Determines if the screens that make up a display are separate or
968 form one large display area.
970 @returns true when screens form up one large display area windows can be
971 moved between single screens (e.g. Xserver with Xinerama, Windows)
972 and false when different screens are separate and windows cannot be moved
973 between them (e.g. Xserver with multiple screens)
975 @see GetBestScreen, GetDisplayBuiltInScreen
977 static bool IsUnifiedDisplay();
979 /** Get the "best" screen.
981 @returns If IsUnifiedDisplay() == true the return value will be
982 nearest screen of the target rectangle.
984 In case of IsUnifiedDisplay() == false the return value
985 will always be GetDisplayDefaultScreen().
987 @see IsUnifiedDisplay, GetDisplayBuiltInScreen
989 SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
991 /** Get the built-in screen.
993 @return
994 This returns the LCD screen number for a laptop, or the primary
995 external VGA display for a desktop machine - it is where a presenter
996 console should be rendered if there are other (non-built-in) screens
997 present.
999 @see IsUnifiedDisplay, GetBestScreen
1001 static unsigned int GetDisplayBuiltInScreen();
1003 /** Get the display's external screen.
1005 Practically, this means - Get the screen we should run a presentation on.
1007 @returns 0 or 1 currently, will fallback to the first available screen if
1008 there are more than one external screens. May be changed in the future.
1010 static unsigned int GetDisplayExternalScreen();
1012 ///@}
1014 /** @name Accelerators and Mnemonics
1016 Accelerators allow a user to hold down Ctrl+key (or CMD+key on macOS)
1017 combination to gain quick access to functionality.
1019 Mnemonics are underline letters in things like menus and dialog boxes
1020 that allow a user to type in the letter to activate the menu or option.
1022 ///@{
1024 /** Insert accelerator
1026 @param pAccel Pointer to an Accelerator object to insert
1028 @returns true if successful, false if otherwise
1030 @see RemoveAccel
1032 static bool InsertAccel( Accelerator* pAccel );
1034 /** Remove accelerator
1036 @param pAccel Pointer to Accelerator object to remove
1038 @see InsertAccel
1040 static void RemoveAccel( Accelerator const * pAccel );
1042 /** Get the number of reserved key codes used by the application.
1044 @returns number of reserved key codes
1046 @see GetReservedKeyCode
1048 static size_t GetReservedKeyCodeCount();
1050 /** Get the reserved key code.
1052 @param i The keycode number to retrieve
1054 @returns Const pointer to a KeyCode object
1056 @see GetReservedKeyCodeCount
1058 static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1060 ///@}
1062 /** @name Application Help
1064 Deals with the help system, and "auto-help", where a user hovers a mouse above
1065 a UI element and a tooltip with an explanation pops up.
1067 ///@{
1069 /** Sets up help
1071 @param pHelp Pointer to a Help object (optional, can by NULL)
1073 @see GetHelp
1075 static void SetHelp( Help* pHelp = nullptr );
1077 /** Gets the application's help
1079 @returns Pointer to application's help object. Note that the application may
1080 not have a help object, so it might return NULL.
1082 @see SetHelp
1084 static Help* GetHelp();
1086 ///@}
1088 /** @name Dialogs
1090 @remark "Dialog cancel mode" tells a headless install whether to
1091 cancel dialogs when they appear. See the DialogCancelMode
1092 enumerator.
1094 ///@{
1096 /** Get the default parent window for dialog boxes.
1098 @remark GetDefDialogParent does all sorts of things find a useful parent
1099 window for dialogs. It first uses the topmost parent of the active
1100 window to avoid using floating windows or other dialog boxes. If
1101 there are no active windows, then it will take a random stab and
1102 choose the first visible top window. Otherwise, it defaults to
1103 the desktop.
1105 @returns Pointer to the default window.
1107 static vcl::Window* GetDefDialogParent();
1110 /** Gets the dialog cancel mode for headless environments.
1112 @return DialogCancelMode value
1114 @see SetDialogCancelMode, IsDialogCancelEnabled
1116 static DialogCancelMode GetDialogCancelMode();
1118 /** Sets the dialog cancel mode for headless environments.
1120 This should be private, but XFrameImpl needs to access it and current
1121 baseline gcc doesn't support forward definition of anonymous classes.
1122 You probably should use EnableHeadlessMode instead.
1124 @param mode DialogCancel mode value
1126 @see GetDialogCancelMode, IsDialogCancelEnabled, EnableHeadlessMode
1128 static void SetDialogCancelMode( DialogCancelMode mode );
1130 /** Determines if dialog cancel mode is enabled.
1132 @returns True if dialog cancel mode is enabled, false if disabled.
1134 @see GetDialogCancelMode, SetDialogCancelMode
1136 static bool IsDialogCancelEnabled();
1139 /** Make a dialog box a system window or not.
1141 @param nMode Can be either: SystemWindowFlags::NOAUTOMODE (0x0001) or
1142 SystemWindowFlags::DIALOG (0x0002)
1144 @see GetSystemWindowMode
1146 static void SetSystemWindowMode( SystemWindowFlags nMode );
1148 /** Get the system window mode of dialogs.
1150 @returns SystemWindowFlags::NOAUTOMODE (0x0001) or SystemWindowFlags::DIALOG (0x0002)
1152 @see SetSystemWindowMode
1154 static SystemWindowFlags GetSystemWindowMode();
1156 ///@}
1158 /** @name VCL Toolkit and UNO Wrapper
1160 The VCL Toolkit implements the UNO XToolkit interface, which specifies a
1161 factory interface for the window toolkit. It is similar to the abstract window
1162 toolkit (AWT) in Java.
1165 ///@{
1167 /** Gets the VCL toolkit.
1169 @attention The global service manager has to be created before getting the toolkit!
1171 @returns UNO reference to VCL toolkit
1173 static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1175 ///@}
1178 /*** @name Graphic Filters
1180 ///@{
1182 /** Setup a new graphics filter
1184 @param rLink Const reference to a Link object, which the filter calls upon.
1186 @see GetFilterHdl
1188 static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1190 ///@}
1192 /** @name Headless Mode
1195 /** Enables headless mode.
1197 @param dialogsAreFatal Set to true if a dialog ends the session, false if not.
1199 static void EnableHeadlessMode( bool dialogsAreFatal );
1201 /** Determines if headless mode is enabled
1203 @return True if headless mode is enabled, false if not.
1205 static bool IsHeadlessModeEnabled();
1207 /** Enable Console Only mode
1209 Convenience function to enable headless and bitmap rendering.
1211 static void EnableConsoleOnly();
1213 /** Enable software-only bitmap rendering
1215 static void EnableBitmapRendering();
1217 /** Determines if bitmap rendering is enabled
1219 @return True if bitmap rendering is enabled.
1221 static bool IsBitmapRendering();
1223 ///@}
1225 /** @name Event Testing Mode
1228 /** Enables event testing mode.
1231 static void EnableEventTestingMode();
1233 /** Determines if event testing mode is enabled
1235 @return True if event testing mode is enabled, false if not.
1237 static bool IsEventTestingModeEnabled();
1239 /** Set safe mode to enabled */
1240 static void EnableSafeMode();
1242 /** Determines if safe mode is enabled */
1243 static bool IsSafeModeEnabled();
1245 ///@}
1247 /** Get the desktop environment the process is currently running in
1249 @returns String representing the desktop environment
1251 static const OUString& GetDesktopEnvironment();
1253 /*** @name Platform Functionality
1255 ///@{
1257 /** Add a file to the system shells recent document list if there is any.
1258 This function may have no effect under Unix because there is no standard
1259 API among the different desktop managers.
1261 @param rFileUrl The file url of the document.
1263 @param rMimeType The mime content type of the document specified by aFileUrl.
1264 If an empty string will be provided "application/octet-stream"
1265 will be used.
1267 @param rDocumentService The app (or "document service") you will be adding the file to
1268 e.g. com.sun.star.text.TextDocument
1270 static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1272 /*** Show a native error messagebox
1274 @param sTitle Title of error messagebox
1276 @param sMessage Message displayed in messagebox
1278 static void ShowNativeErrorBox(const OUString& sTitle ,
1279 const OUString& sMessage);
1281 /** Update main thread identifier */
1282 static void UpdateMainThread();
1284 /** Do we have a native / system file selector available?
1286 @returns True if native file selector is available, false otherwise.
1288 static bool hasNativeFileSelection();
1290 /** Create a platform specific file 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 File picker if available, otherwise an empty reference.
1297 static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1298 createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1300 /** Create a platform specific folder picker, if one is available, otherwise return an
1301 empty reference
1303 @param rServiceManager Const reference to a UNO component context (service manager).
1305 @returns Folder picker if available, otherwise an empty reference.
1307 static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1308 createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1310 /** Cancel all open dialogs
1312 static void EndAllDialogs();
1314 /** Cancel all open popups
1316 static void EndAllPopups();
1318 ///@}
1320 // For vclbootstrapprotector:
1321 static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1323 static weld::Builder* CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false, sal_uInt64 nLOKWindowId = 0);
1324 // For the duration of vcl parent windows
1325 static weld::Builder* CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId = 0);
1327 static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1328 VclButtonsType eButtonType, const OUString& rPrimaryMessage,
1329 bool bMobile = false);
1331 static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1333 // ILibreOfficeKitNotifier
1334 void* m_pCallbackData;
1335 LibreOfficeKitCallback m_pCallback;
1337 virtual void notifyWindow(vcl::LOKWindowId nLOKWindowId,
1338 const OUString& rAction,
1339 const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>()) const override;
1340 virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) const override;
1342 private:
1343 DECL_STATIC_LINK( Application, PostEventHandler, void*, void );
1346 class SolarMutexGuard
1347 : public osl::Guard<comphelper::SolarMutex>
1349 public:
1350 SolarMutexGuard()
1351 : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1354 class SolarMutexClearableGuard
1355 : public osl::ClearableGuard<comphelper::SolarMutex>
1357 public:
1358 SolarMutexClearableGuard()
1359 : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1362 class SolarMutexResettableGuard
1363 : public osl::ResettableGuard<comphelper::SolarMutex>
1365 public:
1366 SolarMutexResettableGuard()
1367 : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1370 namespace vcl
1373 /** guard class that uses tryToAcquire() and has isAcquired() to check
1375 class SolarMutexTryAndBuyGuard
1377 private:
1378 bool m_isAcquired;
1379 #ifdef DBG_UTIL
1380 bool m_isChecked;
1381 #endif
1382 comphelper::SolarMutex& m_rSolarMutex;
1384 SolarMutexTryAndBuyGuard(const SolarMutexTryAndBuyGuard&) = delete;
1385 SolarMutexTryAndBuyGuard& operator=(const SolarMutexTryAndBuyGuard&) = delete;
1387 public:
1389 SolarMutexTryAndBuyGuard()
1390 : m_isAcquired(false)
1391 #ifdef DBG_UTIL
1392 , m_isChecked(false)
1393 #endif
1394 , m_rSolarMutex(Application::GetSolarMutex())
1397 m_isAcquired = m_rSolarMutex.tryToAcquire();
1400 ~SolarMutexTryAndBuyGuard()
1402 #ifdef DBG_UTIL
1403 assert(m_isChecked);
1404 #endif
1405 if (m_isAcquired)
1406 m_rSolarMutex.release();
1409 bool isAcquired()
1411 #ifdef DBG_UTIL
1412 m_isChecked = true;
1413 #endif
1414 return m_isAcquired;
1418 } // namespace vcl
1421 A helper class that calls Application::ReleaseSolarMutex() in its constructor
1422 and restores the mutex in its destructor.
1424 class SolarMutexReleaser
1426 const sal_uInt32 mnReleased;
1427 public:
1428 SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1429 ~SolarMutexReleaser() { Application::AcquireSolarMutex( mnReleased ); }
1432 VCL_DLLPUBLIC Application* GetpApp();
1434 // returns true if vcl is already initialized
1435 VCL_DLLPUBLIC bool IsVCLInit();
1436 // returns true if vcl successfully initializes or was already initialized
1437 VCL_DLLPUBLIC bool InitVCL();
1438 VCL_DLLPUBLIC void DeInitVCL();
1440 VCL_DLLPUBLIC bool InitAccessBridge();
1442 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1443 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1444 VCL_DLLPUBLIC void JoinMainLoopThread();
1446 /// The following are to manage per-view (frame) help data.
1447 struct ImplSVHelpData;
1448 VCL_DLLPUBLIC ImplSVHelpData* CreateSVHelpData();
1449 VCL_DLLPUBLIC void DestroySVHelpData(ImplSVHelpData*);
1450 VCL_DLLPUBLIC void SetSVHelpData(ImplSVHelpData*);
1452 /// The following are to manage per-view (frame) window data.
1453 struct ImplSVWinData;
1454 VCL_DLLPUBLIC ImplSVWinData* CreateSVWinData();
1455 VCL_DLLPUBLIC void DestroySVWinData(ImplSVWinData*);
1456 VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData*);
1458 inline void Application::EndYield()
1460 PostUserEvent( Link<void*,void>() );
1463 #endif // _APP_HXX
1465 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */