Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / vcl / svapp.hxx
blobc96335f1076fa9e36b8f07f870d707fa8b06304e
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 {
62 class KeyCode;
63 class ILibreOfficeKitNotifier;
64 class Window;
67 class NotifyEvent;
68 class KeyEvent;
69 class MouseEvent;
70 class GestureEventPan;
71 struct ImplSVEvent;
72 struct ConvertData;
73 namespace basegfx { class SystemDependentDataManager; }
75 namespace com::sun::star::uno {
76 class XComponentContext;
78 namespace com::sun::star::ui::dialogs {
79 class XFilePicker2;
80 class XFolderPicker2;
82 namespace com::sun::star::awt {
83 class XToolkit;
84 class XDisplayConnection;
85 class XWindow;
88 VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar( sal_UCS4, LanguageType );
90 enum class SystemWindowFlags {
91 NOAUTOMODE = 0x0001,
92 DIALOG = 0x0002
94 namespace o3tl
96 template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
99 typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
101 /** An application can be notified of a number of different events:
102 - Type::Accept - listen for connection to the application (a connection
103 string is passed via the event)
104 - Type::Unaccept - stops listening for a connection to the app (determined by
105 a connection string passed via the event)
106 - Type::Appear - brings the app to the front (i.e. makes it "appear")
107 - Type::Version - display the app version
108 - Type::Help - opens a help topic (help topic passed as string)
109 - Type::OpenHELP_URL - opens a help URL (URL passed as a string)
110 - Type::ShowDialog - shows a dialog (dialog passed as a string)
111 - Type::Open - opens a document or group of documents (documents passed
112 as an array of strings)
113 - Type::Print - print a document or group of documents (documents passed
114 as an array of strings
115 - Type::PrivateDoShutdown - shutdown the app
118 class VCL_DLLPUBLIC ApplicationEvent
120 public:
121 enum class Type {
122 Accept, ///< Listen for connections
123 Appear, ///< Make application appear
124 Open, ///< Open a document
125 OpenHelpUrl, ///< Open a help URL
126 Print, ///< Print document
127 PrivateDoShutdown, ///< Shutdown application
128 QuickStart, ///< Start QuickStart
129 ShowDialog, ///< Show a dialog
130 Unaccept ///< Stop listening for connections
133 /** Explicit constructor for ApplicationEvent.
135 @attention Type::Appear, Type::PrivateDoShutdown and
136 Type::QuickStart are the \em only events that don't need to include
137 a data string with the event. No other events should use this
138 constructor!
140 explicit ApplicationEvent(Type type): aEvent(type)
142 assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
145 /** Constructor for ApplicationEvent, accepts a string for the data
146 associated with the event.
148 @attention Type::Accept, Type::OpenHelpUrl, Type::ShowDialog
149 and Type::Unaccept are the \em only events that accept a single
150 string as event data. No other events should use this constructor!
152 ApplicationEvent(Type type, OUString const & data): aEvent(type)
154 assert(
155 type == Type::Accept || type == Type::OpenHelpUrl
156 || type == Type::ShowDialog || type == Type::Unaccept);
157 aData.push_back(data);
160 /** Constructor for ApplicationEvent, accepts an array of strings for
161 the data associated with the event.
163 @attention Type::Open and Type::Print can apply to multiple documents,
164 and are the \em only events that accept an array of strings. No other
165 events should use this constructor.
167 ApplicationEvent(Type type, std::vector<OUString>&& data):
168 aEvent(type), aData(std::move(data))
170 assert(type == Type::Open || type == Type::Print);
173 /** Get the type of event.
175 @returns The type of event.
177 Type GetEvent() const
179 return aEvent;
182 /** Gets the application event's data string.
184 @attention The \em only events that need a single string Type::Accept,
185 Type::OpenHelpUrl, Type::ShowDialog and Type::Unaccept
187 @returns The event's data string.
189 OUString const & GetStringData() const
191 assert(
192 aEvent == Type::Accept
193 || aEvent == Type::OpenHelpUrl || aEvent == Type::ShowDialog
194 || aEvent == Type::Unaccept);
195 assert(aData.size() == 1);
196 return aData[0];
199 /** Gets the event's array of strings.
201 @attention The \em only events that need an array of strings
202 are Type::Open and Type::Print.
204 std::vector<OUString> const & GetStringsData() const
206 assert(aEvent == Type::Open || aEvent == Type::Print);
207 return aData;
210 private:
211 Type aEvent;
212 std::vector<OUString> aData;
215 enum class DialogCancelMode {
216 Off, ///< do not automatically cancel dialogs
217 Silent, ///< silently cancel any dialogs
218 LOKSilent, ///< silently cancel any dialogs (LOK case)
219 Fatal ///< cancel any dialogs by std::abort
223 @brief Base class used mainly for the LibreOffice Desktop class.
225 The Application class is a base class mainly used by the Desktop
226 class. It is really meant to be subclassed, and the Main() function
227 should be overridden. Many of the ImplSVData members should be
228 moved to this class.
230 The reason Application exists is because the VCL used to be a
231 standalone framework, long since abandoned by anything other than
232 our application.
234 @see Desktop, ImplSVData
236 class VCL_DLLPUBLIC Application : public vcl::ILibreOfficeKitNotifier
238 public:
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 Application();
255 /** Virtual destructor for Application class.
257 Deinitializes the LibreOffice global instance data structure, then
258 deinitializes any platform specific data structures.
260 virtual ~Application();
262 /** Initialize the application itself.
264 @attention Note that the global data structures and platform specific
265 initialization is done in the constructor.
267 @see InitFinished, DeInit
269 virtual void Init();
271 /** Finish initialization of the application.
273 @see Init, DeInit
275 virtual void InitFinished();
277 /** Deinitialized the application itself.
279 @attention Note that the global data structures and platform specific
280 deinitialization is done in the destructor.
282 @see Init, InitFinished
284 virtual void DeInit();
286 ///@}
288 /** @brief Pure virtual entrypoint to the application.
290 Main() is the pure virtual entrypoint to your application. You
291 inherit your class from Application and subclass this function to
292 implement an application.
294 The Main() function does not pass in command line parameters,
295 you must use the functions GetCommandLineParamCount() and
296 GetCommandLineParam() to get these values as these are platform
297 independent ways of getting the command line (use GetAppFileName()
298 to get the invoked executable filename).
300 Once in this function, you create windows, etc. then call on
301 Execute() to start the application's main event loop.
303 An example code snippet follows (it won't compile, this just gives the
304 general flavour of the framework and is adapted from an old HelloWorld
305 example program that Star Division used to provide as part of their
306 library).
308 \code{.cpp}
309 class TheApplication : public Application
311 public:
312 virtual void Main();
315 class TheWindow : public WorkWindow
317 public:
318 TheWindow(vcl::Window *parent, WinBits windowStyle) :
319 WorkWindow(parent, windowStyle) {}
321 virtual void Paint(const Rectangle &);
324 void TheWindow::Paint(const Rectangle&)
326 DrawText(Point(100,100), String("Hello World!"));
329 void TheApplication::Main()
331 TheWindow aWindow(NULL, WB_APP | WB_STDWORK);
332 aWindow.Show();
333 Execute();
336 TheApplication anApplication;
337 \endcode
339 Some examples in the source tree can be found here:
341 vcl/workben/svdem.cxx
343 This is an example of how to use the Application and WorkWindow. Unfortunately, it
344 no longer compiles.
346 vcl/fpicker/test/svdem.cxx
348 virtual int Main();
350 /** Exit from the application
352 @returns true if exited successfully, false if not able to fully exit
354 virtual bool QueryExit();
356 virtual void Shutdown();
358 /** @name Change Notification Functions
360 Functions that notify when changes occur in the application.
362 ///@{
364 /** Notify all windows that the application has changed data.
366 @param rDCEvt Reference to a DataChangedEvent object
368 @see DataChanged
370 static void NotifyAllWindows( DataChangedEvent& rDCEvt );
372 ///@}
374 /** @name Command Line Processing
376 Command line processing is done via the following functions. They
377 give the number of parameters, the parameters themselves and a way
378 to get the name of the invoking application.
381 ///@{
383 /** Gets the number of command line parameters passed to the application
385 @return sal_uInt16 - the number of parameters
387 @see GetCommandLineParam, GetAppFileName
389 static sal_uInt16 GetCommandLineParamCount();
391 /** Gets a particular command line parameter
393 @param nParam The index of the parameter to return.
395 @return The command line parameter as an OUString
397 @see GetCommandLineParamCount, GetAppFileName
399 static OUString GetCommandLineParam( sal_uInt16 nParam );
401 /** Get the name of the file used to start the application
403 @return The filename as an OUString
405 @see GetCommandLineParamCount, GetCommandLineParam
407 static OUString GetAppFileName();
409 ///@}
411 /** @name Error Handling
413 \em Very rudimentary error handling is done by these
414 functions.
419 /** Handles an error.
421 @param nCategory The error category, see include/vcl/exceptiontypes.hxx
423 @see Abort
425 virtual void Exception( ExceptionCategory nCategory );
427 /** Ends the program prematurely with an error message.
429 If the \code --norestore \endcode command line argument is given (assuming
430 this process is run by developers who are interested in cores,
431 vs. end users who are not) then it does a coredump.
433 @param rErrorText The error message to report.
435 @see Exception
437 static void Abort( const OUString& rErrorText );
439 ///@}
441 /** @name Event Loop Functions
443 Functions that handle the LibreOffice main event loop are here,
444 including a global lock called the Solar Mutex.
446 ///@{
448 /** Run the main event processing loop until it is quit by Quit().
450 @see Quit, Reschedule, Yield, EndYield, GetSolarMutex,
451 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
453 static void Execute();
455 /** Quit the program
457 @see Execute, Reschedule, Yield, EndYield, GetSolarMutex,
458 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
460 static void Quit();
462 /** Has Quit() been called?
464 static bool IsQuit();
466 /** Attempt to process current pending event(s)
468 It doesn't sleep if no events are available for processing.
469 This doesn't process any events generated after invoking the function.
470 So in contrast to Scheduler::ProcessEventsToIdle, this cannot become
471 busy-locked by an event-generating event in the event queue.
473 @param bHandleAllCurrentEvents If set to true, then try to process all
474 the current events. If set to false, then only process one event.
475 Defaults to false.
477 @returns true if any event was processed.
479 @see Yield, Scheduler::ProcessEventsToIdle
481 static bool Reschedule( bool bHandleAllCurrentEvents = false );
483 /** Process the next event.
485 It sleeps if no event is available for processing and just returns
486 if an event was processed.
488 @see Execute, Quit, Reschedule, EndYield, GetSolarMutex,
489 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
491 static void Yield();
495 @see Execute, Quit, Reschedule, Yield, GetSolarMutex,
496 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
498 static void EndYield();
500 /** @brief Get the Solar Mutex for this thread.
502 Get the Solar Mutex that prevents other threads from accessing VCL
503 concurrently.
505 @returns SolarMutex reference
507 @see Execute, Quit, Reschedule, Yield, EndYield,
508 IsMainThread, ReleaseSolarMutex, AcquireSolarMutex,
510 static comphelper::SolarMutex& GetSolarMutex();
512 /** Queries whether we are in main thread.
514 @returns true if we are in main thread, false if not
516 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
517 ReleaseSolarMutex, AcquireSolarMutex,
519 static bool IsMainThread();
521 /** @brief Release Solar Mutex(es) for this thread
523 Release the Solar Mutex(es) that prevents other threads from accessing
524 VCL concurrently.
526 @returns The number of mutexes that were acquired by this thread.
528 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
529 IsMainThread, AcquireSolarMutex,
531 static sal_uInt32 ReleaseSolarMutex();
533 /** @brief Acquire Solar Mutex(es) for this thread.
535 Acquire the Solar Mutex(es) that prevents other threads from accessing
536 VCL concurrently.
538 @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
539 IsMainThread, ReleaseSolarMutex,
541 static void AcquireSolarMutex( sal_uInt32 nCount );
543 /** Queries whether the application is in "main", i.e. not yet in
544 the event loop
546 @returns true if in main, false if not in main
548 @see IsInExecute, IsInModalMode
550 static bool IsInMain();
552 /** Queries whether the application is in the event loop
554 @returns true if in the event loop, false if not
556 @see IsInMain, IsInModalMode
558 static bool IsInExecute();
560 /** Queries whether application has a modal dialog active.
562 @returns true if a modal dialog is active, false if not
564 @see IsInMain, IsInExecute
566 static bool IsInModalMode();
568 /** Return how many events are being dispatched.
570 @returns the number of events currently being dispatched
572 static sal_uInt16 GetDispatchLevel();
574 /** Determine if there are any pending input events.
576 @param nType input identifier, defined in include/vcl/inputtypes.hxx
577 The default is VCL_INPUT_ANY.
579 @returns true if there are pending events, false if not.
581 @see GetLastInputInterval
583 static bool AnyInput( VclInputFlags nType = VCL_INPUT_ANY );
585 /** The interval from the last time that input was received.
587 @returns system ticks - last input time
589 @see AnyInput
591 static sal_uInt64 GetLastInputInterval();
593 ///@}
595 /* Determines if the UI is captured.
597 The UI is considered captured if a system dialog is open (e.g. printer setup),
598 a floating window, menu or toolbox dropdown is open, or a window has been
599 captured by the mouse.
601 @returns true if UI is captured, false if not
603 static bool IsUICaptured();
605 /** @name Settings
607 The following functions set system settings (e.g. tab color, etc.). There are functions
608 that set settings objects, and functions that set and get the actual system settings for
609 the application.
611 ///@{
613 /** Sets user settings in settings object to override system settings
615 The system settings that can be overridden are:
616 - window dragging options (on or off, including live scrolling!)
617 - style settings (e.g. checkbox color, border color, 3D colors,
618 button rollover colors, etc.)
619 - mouse settings
620 - menu options, including the mouse follows the menu and whether menu
621 icons are used
623 @param rSettings Reference to the settings object to change.
625 @see MergeSystemSettings, SetSettings, GetSettings
627 virtual void OverrideSystemSettings( AllSettings& rSettings );
629 /** Set the settings object to the platform/desktop environment system
630 settings.
632 @param rSettings Reference to the settings object to change.
634 @see OverrideSystemSettings, SetSettings, GetSettings
636 static void MergeSystemSettings( AllSettings& rSettings );
638 /** Sets the application's settings and notifies all windows of the
639 change.
641 @param rSettings const reference to settings object used to
642 change the application's settings.
644 @see OverrideSystemSettings, MergeSystemSettings, GetSettings
646 static void SetSettings( const AllSettings& rSettings );
648 /** Gets the application's settings. If the application hasn't initialized
649 it's settings, then it does so (lazy initialization).
651 @returns AllSettings instance that contains the current settings of the
652 application.
654 @see OverrideSystemSettings, MergeSystemSettings, SetSettings
656 static const AllSettings& GetSettings();
658 /** Get the application's locale data wrapper.
660 @returns reference to a LocaleDataWrapper object
662 static const LocaleDataWrapper& GetAppLocaleDataWrapper();
664 ///@}
666 /** @name Event Listeners/Handlers
668 A set of event listeners and callers. Note that in this code there is
669 platform specific functions - namely for zoom and scroll events.
671 ///@{
674 /** Add a VCL event listener to the application. If no event listener exists,
675 then initialize the application's event listener with a new one, then add
676 the event listener.
678 @param rEventListener Const reference to the event listener to add.
680 @see RemoveEventListener, AddKeyListener, RemoveKeyListener
682 static void AddEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
684 /** Remove a VCL event listener from the application.
686 @param rEventListener Const reference to the event listener to be removed
688 @see AddEventListener, AddKeyListener, RemoveKeyListener
690 static void RemoveEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
692 /** Add a keypress listener to the application. If keypress listener exists,
693 then initialize the application's keypress event listener with a new one, then
694 add the keypress listener.
696 @param rKeyListener Const reference to the keypress event listener to add
698 @see AddEventListener, RemoveEventListener, RemoveKeyListener
700 static void AddKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
702 /** Remove a keypress listener from the application.
704 @param rKeyListener Const reference to the keypress event listener to be removed
706 @see AddEventListener, RemoveEventListener, AddKeyListener
708 static void RemoveKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
710 /** Send event to all VCL application event listeners
712 @param pWin Pointer to window to send event
713 @param pData Pointer to data to send with event
715 @see ImplCallEventListeners(VclSimpleEvent* pEvent)
717 static void ImplCallEventListenersApplicationDataChanged( void* pData );
719 /** Send event to all VCL application event listeners
721 @param rEvent Reference to VclSimpleEvent
723 @see ImplCallEventListeners(sal_uLong nEvent, Windows* pWin, void* pData);
725 static void ImplCallEventListeners( VclSimpleEvent& rEvent );
727 /** Handle keypress event
729 @param nEvent Event ID for keypress
730 @param pWin Pointer to window that receives the event
731 @param pKeyEvent Received key event
733 @see PostKeyEvent
735 static bool HandleKey( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
737 /** Send keypress event
739 @param nEvent Event ID for keypress
740 @param pWin Pointer to window to which the event is sent
741 @param pKeyEvent Key event to send
743 @see HandleKey
745 static ImplSVEvent * PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, KeyEvent const * pKeyEvent );
748 static bool LOKHandleMouseEvent( VclEventId nEvent, vcl::Window *pWin, const MouseEvent* pEvent );
750 /** Send mouse event
752 @param nEvent Event ID for mouse event
753 @param pWin Pointer to window to which the event is sent
754 @param pMouseEvent Mouse event to send
756 static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
758 static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin,
759 GestureEventPan const * pGestureEvent);
761 /** Remove mouse and keypress events from a window... any also zoom and scroll events
762 if the platform supports it.
764 @param pWin Window to remove events from
766 @see HandleKey, PostKeyEvent, PostMouseEvent
768 static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
770 /** Post a user event to the default window.
772 User events allow for the deferral of work to later in the main-loop - at idle.
774 Execution of the deferred work is thread-safe which means all the tasks are executed
775 serially, so no thread-safety locks between tasks are necessary.
777 @param rLink Link to event callback function
778 @param pCaller Pointer to data sent to the event by the caller. Optional.
779 @param bReferenceLink If true - hold a VclPtr<> reference on the Link's instance.
780 Taking the reference is guarded by a SolarMutexGuard.
782 @return the event ID used to post the event.
784 static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
785 bool bReferenceLink = false );
787 /** Remove user event based on event ID
789 @param nUserEvent User event to remove
791 static void RemoveUserEvent( ImplSVEvent * nUserEvent );
793 /*** Get the DisplayConnection.
795 It is a reference to XDisplayConnection, which allows toolkits to send display
796 events to the application.
798 @returns UNO reference to an object that implements the css:awt:XDisplayConnection
799 interface.
801 static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
803 /** @deprecated AppEvent is used only in the Desktop class now. However, it is
804 intended to notify the application that an event has occurred. It was in oldsv.cxx,
805 but is still needed by a number of functions.
807 @param rAppEvent const reference to ApplicationEvent event
809 virtual void AppEvent( const ApplicationEvent& rAppEvent );
811 ///@}
813 /** @name Application Window Functions
815 Functions that deal with the application's windows
817 ///@{
819 /** Get the currently focused window.
821 @returns Pointer to focused window.
823 @see GetDefaultDevice
825 static vcl::Window* GetFocusWindow();
827 /** Get the default "device" (in this case the default window).
829 @returns Pointer to an OutputDevice. However, it is a Window object -
830 Window class subclasses OutputDevice.
832 @see GetFocusWindow
834 static OutputDevice* GetDefaultDevice();
836 /** access the DataManager for buffering system-dependent data
838 @returns the global instance of the SystemDependentDataManager
840 static basegfx::SystemDependentDataManager& GetSystemDependentDataManager();
842 /** Get the first top-level window of the application.
844 @returns Pointer to top-level window (a Window object)
846 @see GetNextTopLevelWindow, GetTopWindowCount, GetTopWindow,
847 GetActiveTopWindow
849 static vcl::Window* GetFirstTopLevelWindow();
851 /** Get the next top level window.
853 @param pWindow Pointer to Window object you wish to get the next
854 window from.
856 @returns Pointer to next top window.
858 static vcl::Window* GetNextTopLevelWindow( vcl::Window const * pWindow );
860 /** Return the number of top-level windows being used by the application
862 @returns the number of top-level windows
864 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindow,
865 GetActiveTopWindow
868 static tools::Long GetTopWindowCount();
870 /** Get the nth top window.
872 @remark Top windows are actually implemented in a one-way linked list.
873 This iterates through top level windows n times.
875 @param nIndex The index of the top-level window
877 @returns The nth top-level window of the application
879 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
880 GetActiveTopWindow
882 static vcl::Window* GetTopWindow( tools::Long nIndex );
884 /** Get the "active" top window.
886 An "active" top window is one that has a child window that has the
887 application's focus.
889 @returns the active top window
891 @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
892 GetTopWindow
894 static vcl::Window* GetActiveTopWindow();
896 ///@}
898 /** Set the application's name.
900 @param rUniqueName What to set the application name to
902 @see GetAppName
904 static void SetAppName( const OUString& rUniqueName );
907 /** @name Application Name, Branding
909 ///@{
911 /** Get the application's name.
913 @returns The application name.
915 static OUString GetAppName();
918 * Get the OS version based on the OS specific implementation.
920 * @return OUString version string or "-" in case of problems
922 static OUString GetOSVersion();
924 /** Get useful OS, Hardware and configuration information,
925 * cf. Help->About, and User-Agent
926 * bSelection = 0 to return all info, 1 for environment only,
927 * and 2 for VCL/render related infos
929 static OUString GetHWOSConfInfo(const int bSelection = 0, bool bLocalize = true);
931 /** Load a localized branding PNG file as a bitmap.
933 @param pName Name of the bitmap to load.
934 @param rBitmap Reference to BitmapEx object to load PNG into
936 @returns true if the PNG could be loaded, otherwise returns false.
938 static bool LoadBrandBitmap (std::u16string_view pName, BitmapEx &rBitmap);
940 ///@}
942 /** @name Display and Screen
944 ///@{
946 /** Set the default name of the application for message dialogs and printing.
948 @param rDisplayName const reference to string to set the Display name to.
950 @see GetDisplayName
952 static void SetDisplayName( const OUString& rDisplayName );
954 /** Get the default name of the application for message dialogs and printing.
956 @returns The display name of the application.
958 static OUString GetDisplayName();
960 /** Get the toolkit's name. e.g. gtk3
962 @returns The toolkit name.
964 static OUString GetToolkitName();
966 /** Get the number of screens available for the display.
968 @returns The number of screens available.
970 @see GetScreenPosSizePixel
972 static unsigned int GetScreenCount();
974 /** Get a screen's rectangular area.
976 @param nScreen The number of the screen requested.
978 @returns The area of the screen in a Rectangle object.
980 @see GetScreenCount
982 static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
984 /** Determines if the screens that make up a display are separate or
985 form one large display area.
987 @returns true when screens form up one large display area windows can be
988 moved between single screens (e.g. Xserver with Xinerama, Windows)
989 and false when different screens are separate and windows cannot be moved
990 between them (e.g. Xserver with multiple screens)
992 @see GetBestScreen, GetDisplayBuiltInScreen
994 static bool IsUnifiedDisplay();
996 /** Get the "best" screen.
998 @returns If IsUnifiedDisplay() == true the return value will be
999 nearest screen of the target rectangle.
1001 In case of IsUnifiedDisplay() == false the return value
1002 will always be GetDisplayDefaultScreen().
1004 @see IsUnifiedDisplay, GetDisplayBuiltInScreen
1006 SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
1008 /** Get the built-in screen.
1010 @return
1011 This returns the LCD screen number for a laptop, or the primary
1012 external VGA display for a desktop machine - it is where a presenter
1013 console should be rendered if there are other (non-built-in) screens
1014 present.
1016 @see IsUnifiedDisplay, GetBestScreen
1018 static unsigned int GetDisplayBuiltInScreen();
1020 /** Get the display's external screen.
1022 Practically, this means - Get the screen we should run a presentation on.
1024 @returns 0 or 1 currently, will fallback to the first available screen if
1025 there are more than one external screens. May be changed in the future.
1027 static unsigned int GetDisplayExternalScreen();
1029 ///@}
1031 /** @name Accelerators and Mnemonics
1033 Accelerators allow a user to hold down Ctrl+key (or CMD+key on macOS)
1034 combination to gain quick access to functionality.
1036 Mnemonics are underline letters in things like menus and dialog boxes
1037 that allow a user to type in the letter to activate the menu or option.
1039 ///@{
1041 /** Insert accelerator
1043 @param pAccel Pointer to an Accelerator object to insert
1045 @returns true if successful, false if otherwise
1047 @see RemoveAccel
1049 static bool InsertAccel( Accelerator* pAccel );
1051 /** Remove accelerator
1053 @param pAccel Pointer to Accelerator object to remove
1055 @see InsertAccel
1057 static void RemoveAccel( Accelerator const * pAccel );
1059 /** Get the number of reserved key codes used by the application.
1061 @returns number of reserved key codes
1063 @see GetReservedKeyCode
1065 static size_t GetReservedKeyCodeCount();
1067 /** Get the reserved key code.
1069 @param i The keycode number to retrieve
1071 @returns Const pointer to a KeyCode object
1073 @see GetReservedKeyCodeCount
1075 static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1077 ///@}
1079 /** @name Application Help
1081 Deals with the help system, and "auto-help", where a user hovers a mouse above
1082 a UI element and a tooltip with an explanation pops up.
1084 ///@{
1086 /** Sets up help
1088 @param pHelp Pointer to a Help object (optional, can by NULL)
1090 @see GetHelp
1092 static void SetHelp( Help* pHelp = nullptr );
1094 /** Gets the application's help
1096 @returns Pointer to application's help object. Note that the application may
1097 not have a help object, so it might return NULL.
1099 @see SetHelp
1101 static Help* GetHelp();
1103 ///@}
1105 /** @name Dialogs
1107 @remark "Dialog cancel mode" tells a headless install whether to
1108 cancel dialogs when they appear. See the DialogCancelMode
1109 enumerator.
1111 ///@{
1113 /** Get the default parent window for dialog boxes.
1115 @remark This is almost always a terrible method to use to get a parent
1116 for a dialog, try hard to instead pass a specific parent window
1117 to dialogs.
1119 GetDefDialogParent does all sorts of things to try and find a useful
1120 parent window for dialogs. It first uses the topmost parent of the
1121 active window to avoid using floating windows or other dialog boxes.
1122 If there are no active windows, then it will take a random stab and
1123 choose the first visible top window. Otherwise, it defaults to
1124 the desktop.
1126 @returns Pointer to the default window.
1128 static weld::Window* GetDefDialogParent();
1131 /** Gets the dialog cancel mode for headless environments.
1133 @return DialogCancelMode value
1135 @see SetDialogCancelMode, IsDialogCancelEnabled
1137 static DialogCancelMode GetDialogCancelMode();
1139 /** Sets the dialog cancel mode for headless environments.
1141 This should be private, but XFrameImpl needs to access it and current
1142 baseline gcc doesn't support forward definition of anonymous classes.
1143 You probably should use EnableHeadlessMode instead.
1145 @param mode DialogCancel mode value
1147 @see GetDialogCancelMode, IsDialogCancelEnabled, EnableHeadlessMode
1149 static void SetDialogCancelMode( DialogCancelMode mode );
1151 /** Determines if dialog cancel mode is enabled.
1153 @returns True if dialog cancel mode is enabled, false if disabled.
1155 @see GetDialogCancelMode, SetDialogCancelMode
1157 static bool IsDialogCancelEnabled();
1160 /** Make a dialog box a system window or not.
1162 @param nMode Can be either: SystemWindowFlags::NOAUTOMODE (0x0001) or
1163 SystemWindowFlags::DIALOG (0x0002)
1165 @see GetSystemWindowMode
1167 static void SetSystemWindowMode( SystemWindowFlags nMode );
1169 /** Get the system window mode of dialogs.
1171 @returns SystemWindowFlags::NOAUTOMODE (0x0001) or SystemWindowFlags::DIALOG (0x0002)
1173 @see SetSystemWindowMode
1175 static SystemWindowFlags GetSystemWindowMode();
1177 ///@}
1179 /** @name VCL Toolkit and UNO Wrapper
1181 The VCL Toolkit implements the UNO XToolkit interface, which specifies a
1182 factory interface for the window toolkit. It is similar to the abstract window
1183 toolkit (AWT) in Java.
1186 ///@{
1188 /** Gets the VCL toolkit.
1190 @attention The global service manager has to be created before getting the toolkit!
1192 @returns UNO reference to VCL toolkit
1194 static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1196 ///@}
1199 /*** @name Graphic Filters
1201 ///@{
1203 /** Setup a new graphics filter
1205 @param rLink Const reference to a Link object, which the filter calls upon.
1207 @see GetFilterHdl
1209 static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1211 ///@}
1213 /** @name Headless Mode
1216 /** Enables headless mode.
1218 @param dialogsAreFatal Set to true if a dialog ends the session, false if not.
1220 static void EnableHeadlessMode( bool dialogsAreFatal );
1222 /** Determines if headless mode is enabled
1224 @return True if headless mode is enabled, false if not.
1226 static bool IsHeadlessModeEnabled();
1228 /** Enable Console Only mode
1230 Convenience function to enable headless and bitmap rendering.
1232 static void EnableConsoleOnly();
1234 /** Enable software-only bitmap rendering
1236 static void EnableBitmapRendering();
1238 /** Determines if bitmap rendering is enabled
1240 @return True if bitmap rendering is enabled.
1242 static bool IsBitmapRendering();
1244 ///@}
1246 /** Set safe mode to enabled */
1247 static void EnableSafeMode();
1249 /** Determines if safe mode is enabled */
1250 static bool IsSafeModeEnabled();
1252 ///@}
1254 /** Get the desktop environment the process is currently running in
1256 @returns String representing the desktop environment
1258 static const OUString& GetDesktopEnvironment();
1260 /*** @name Platform Functionality
1262 ///@{
1264 /** Add a file to the system shells recent document list if there is any.
1265 This function may have no effect under Unix because there is no standard
1266 API among the different desktop managers.
1268 @param rFileUrl The file url of the document.
1270 @param rMimeType The mime content type of the document specified by aFileUrl.
1271 If an empty string will be provided "application/octet-stream"
1272 will be used.
1274 @param rDocumentService The app (or "document service") you will be adding the file to
1275 e.g. com.sun.star.text.TextDocument
1277 static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1279 /*** Show a native error messagebox
1281 @param sTitle Title of error messagebox
1283 @param sMessage Message displayed in messagebox
1285 static void ShowNativeErrorBox(const OUString& sTitle ,
1286 const OUString& sMessage);
1288 /** Update main thread identifier */
1289 static void UpdateMainThread();
1291 /** Do we have a native / system file selector available?
1293 @returns True if native file selector is available, false otherwise.
1295 static bool hasNativeFileSelection();
1297 /** Create a platform specific file picker, if one is available, otherwise return an
1298 empty reference.
1300 @param rServiceManager Const reference to a UNO component context (service manager).
1302 @returns File picker if available, otherwise an empty reference.
1304 static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1305 createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1307 /** Create a platform specific folder picker, if one is available, otherwise return an
1308 empty reference
1310 @param rServiceManager Const reference to a UNO component context (service manager).
1312 @returns Folder picker if available, otherwise an empty reference.
1314 static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1315 createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1317 /** Cancel all open dialogs
1319 static void EndAllDialogs();
1321 /** Cancel all open popups
1323 static void EndAllPopups();
1325 /** Returns true, if the VCL plugin runs on the system event loop.
1327 * AKA the VCL plugin can't handle nested event loops, like WASM or mobile.
1329 static bool IsOnSystemEventLoop();
1331 ///@}
1333 // For vclbootstrapprotector:
1334 static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1336 static std::unique_ptr<weld::Builder> CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false, sal_uInt64 nLOKWindowId = 0);
1337 // For the duration of vcl parent windows
1338 static std::unique_ptr<weld::Builder> CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId = 0);
1340 static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1341 VclButtonsType eButtonType, const OUString& rPrimaryMessage,
1342 const ILibreOfficeKitNotifier* pNotifier = nullptr);
1344 static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1346 // ILibreOfficeKitNotifier
1347 void* m_pCallbackData;
1348 LibreOfficeKitCallback m_pCallback;
1350 virtual void notifyWindow(vcl::LOKWindowId nLOKWindowId,
1351 const OUString& rAction,
1352 const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>()) const override;
1353 virtual void libreOfficeKitViewCallback(int nType, const OString& pPayload) const override;
1354 virtual void notifyInvalidation(tools::Rectangle const *) const override;
1357 private:
1358 DECL_DLLPRIVATE_STATIC_LINK( Application, PostEventHandler, void*, void );
1361 class SolarMutexGuard
1362 : public osl::Guard<comphelper::SolarMutex>
1364 public:
1365 SolarMutexGuard()
1366 : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1369 class SolarMutexClearableGuard
1370 : public osl::ClearableGuard<comphelper::SolarMutex>
1372 public:
1373 SolarMutexClearableGuard()
1374 : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1377 class SolarMutexResettableGuard
1378 : public osl::ResettableGuard<comphelper::SolarMutex>
1380 public:
1381 SolarMutexResettableGuard()
1382 : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1385 namespace vcl
1388 /** guard class that uses tryToAcquire() and has isAcquired() to check
1390 class SolarMutexTryAndBuyGuard
1392 private:
1393 bool m_isAcquired;
1394 #ifdef DBG_UTIL
1395 bool m_isChecked;
1396 #endif
1397 comphelper::SolarMutex& m_rSolarMutex;
1399 SolarMutexTryAndBuyGuard(const SolarMutexTryAndBuyGuard&) = delete;
1400 SolarMutexTryAndBuyGuard& operator=(const SolarMutexTryAndBuyGuard&) = delete;
1402 public:
1404 SolarMutexTryAndBuyGuard()
1405 : m_isAcquired(false)
1406 #ifdef DBG_UTIL
1407 , m_isChecked(false)
1408 #endif
1409 , m_rSolarMutex(Application::GetSolarMutex())
1412 m_isAcquired = m_rSolarMutex.tryToAcquire();
1415 ~SolarMutexTryAndBuyGuard()
1417 #ifdef DBG_UTIL
1418 assert(m_isChecked);
1419 #endif
1420 if (m_isAcquired)
1421 m_rSolarMutex.release();
1424 bool isAcquired()
1426 #ifdef DBG_UTIL
1427 m_isChecked = true;
1428 #endif
1429 return m_isAcquired;
1433 } // namespace vcl
1436 A helper class that calls Application::ReleaseSolarMutex() in its constructor
1437 and restores the mutex in its destructor.
1439 class SolarMutexReleaser
1441 const sal_uInt32 mnReleased;
1442 public:
1443 SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1444 ~SolarMutexReleaser() { Application::AcquireSolarMutex( mnReleased ); }
1447 VCL_DLLPUBLIC Application* GetpApp();
1449 // returns true if vcl is already initialized
1450 VCL_DLLPUBLIC bool IsVCLInit();
1451 // returns true if vcl successfully initializes or was already initialized
1452 VCL_DLLPUBLIC bool InitVCL();
1453 VCL_DLLPUBLIC void DeInitVCL();
1455 VCL_DLLPUBLIC bool InitAccessBridge();
1457 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1458 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1459 VCL_DLLPUBLIC void JoinMainLoopThread();
1461 /// The following are to manage per-view (frame) help data.
1462 struct ImplSVHelpData;
1463 VCL_DLLPUBLIC ImplSVHelpData* CreateSVHelpData();
1464 VCL_DLLPUBLIC void DestroySVHelpData(ImplSVHelpData*);
1465 VCL_DLLPUBLIC void SetSVHelpData(ImplSVHelpData*);
1467 /// The following are to manage per-view (frame) window data.
1468 struct ImplSVWinData;
1469 VCL_DLLPUBLIC ImplSVWinData* CreateSVWinData();
1470 VCL_DLLPUBLIC void DestroySVWinData(ImplSVWinData*);
1471 VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData*);
1473 inline void Application::EndYield()
1475 PostUserEvent( Link<void*,void>() );
1478 #endif // _APP_HXX
1480 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */