/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
class BitmapEx; namespace weld
{ class Builder; class MessageDialog; class Widget; class Window;
} class LocaleDataWrapper; class AllSettings; class DataChangedEvent; class Accelerator; class Help; class OutputDevice; namespace vcl { class KeyCode; class Window;
}
class NotifyEvent; class KeyEvent; class MouseEvent; class GestureEventPan; struct ImplSVEvent; struct ConvertData; namespace basegfx { class SystemDependentDataManager; }
namespace com::sun::star::uno { class XComponentContext;
} namespace com::sun::star::ui::dialogs { class XFilePicker2; class XFolderPicker2;
} namespace com::sun::star::awt { class XToolkit; class XDisplayConnection; class XWindow;
}
/** An application can be notified of a number of different events: - Type::Accept - listen for connection to the application (a connection string is passed via the event) - Type::Unaccept - stops listening for a connection to the app (determined by a connection string passed via the event) - Type::Appear - brings the app to the front (i.e. makes it "appear") - Type::Version - display the app version - Type::Help - opens a help topic (help topic passed as string) - Type::OpenHELP_URL - opens a help URL (URL passed as a string) - Type::ShowDialog - shows a dialog (dialog passed as a string) - Type::Open - opens a document or group of documents (documents passed as an array of strings) - Type::Print - print a document or group of documents (documents passed as an array of strings - Type::PrivateDoShutdown - shutdown the app
*/
class VCL_DLLPUBLIC ApplicationEvent
{ public: enumclass Type {
Accept, ///< Listen for connections
Appear, ///< Make application appear
Open, ///< Open a document
OpenHelpUrl, ///< Open a help URL
Print, ///< Print document
PrivateDoShutdown, ///< Shutdown application
QuickStart, ///< Start QuickStart
ShowDialog, ///< Show a dialog
Unaccept ///< Stop listening for connections
};
/** Explicit constructor for ApplicationEvent.
@attention Type::Appear, Type::PrivateDoShutdown and Type::QuickStart are the \em only events that don't need to include a data string with the event. No other events should use this constructor!
*/ explicit ApplicationEvent(Type type): aEvent(type)
{
assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
}
/** Constructor for ApplicationEvent, accepts a string for the data associated with the event.
@attention Type::Accept, Type::OpenHelpUrl, Type::ShowDialog and Type::Unaccept are the \em only events that accept a single string as event data. No other events should use this constructor!
*/
ApplicationEvent(Type type, OUString const & data): aEvent(type)
{
assert(
type == Type::Accept || type == Type::OpenHelpUrl
|| type == Type::ShowDialog || type == Type::Unaccept);
aData.push_back(data);
}
/** Constructor for ApplicationEvent, accepts an array of strings for the data associated with the event.
@attention Type::Open and Type::Print can apply to multiple documents, and are the \em only events that accept an array of strings. No other events should use this constructor.
*/
ApplicationEvent(Type type, std::vector<OUString>&& data):
aEvent(type), aData(std::move(data))
{
assert(type == Type::Open || type == Type::Print);
}
/** Get the type of event.
@returns The type of event.
*/
Type GetEvent() const
{ return aEvent;
}
/** Gets the application event's data string.
@attention The \em only events that need a single string Type::Accept, Type::OpenHelpUrl, Type::ShowDialog and Type::Unaccept
@attention The \em only events that need an array of strings are Type::Open and Type::Print.
*/
std::vector<OUString> const & GetStringsData() const
{
assert(aEvent == Type::Open || aEvent == Type::Print); return aData;
}
private:
Type aEvent;
std::vector<OUString> aData;
};
enumclass DialogCancelMode {
Off, ///< do not automatically cancel dialogs
Silent, ///< silently cancel any dialogs
LOKSilent, ///< silently cancel any dialogs (LOK case)
Fatal ///< cancel any dialogs by std::abort
};
/** @brief Base class used mainly for the LibreOffice Desktop class.
The Application class is a base class mainly used by the Desktop class. It is really meant to be subclassed, and the Main() function should be overridden. Many of the ImplSVData members should be moved to this class.
The reason Application exists is because the VCL used to be a standalone framework, long since abandoned by anything other than our application.
@see Desktop, ImplSVData
*/ class VCL_DLLPUBLIC Application : public vcl::ILibreOfficeKitNotifier
{ public: /** @name Initialization The following functions perform initialization and deinitialization of the application.
*/ ///@{
/** Default constructor for Application class.
Initializes the LibreOffice global instance data structure if needed, and then sets itself to be the Application class. Also initializes any platform specific data structures.
@attention The initialization of the application itself is done in Init()
*/
Application();
/** Virtual destructor for Application class.
Deinitializes the LibreOffice global instance data structure, then deinitializes any platform specific data structures.
*/ virtual ~Application();
/** Initialize the application itself.
@attention Note that the global data structures and platform specific initialization is done in the constructor.
@see InitFinished, DeInit
*/ virtualvoid Init();
/** Finish initialization of the application.
@see Init, DeInit
*/ virtualvoid InitFinished();
/** Deinitialized the application itself.
@attention Note that the global data structures and platform specific deinitialization is done in the destructor.
@see Init, InitFinished
*/ virtualvoid DeInit();
///@}
/** @brief Pure virtual entrypoint to the application.
Main() is the pure virtual entrypoint to your application. You inherit your class from Application and subclass this function to implement an application.
The Main() function does not pass in command line parameters, you must use the functions GetCommandLineParamCount() and GetCommandLineParam() to get these values as these are platform independent ways of getting the command line (use GetAppFileName() to get the invoked executable filename).
Once in this function, you create windows, etc. then call on Execute() to start the application's main event loop.
An example code snippet follows (it won't compile, this just gives the general flavour of the framework and is adapted from an old HelloWorld example program that Star Division used to provide as part of their library).
\code{.cpp} class TheApplication : public Application { public: virtual void Main(); };
class TheWindow : public WorkWindow { public: TheWindow(vcl::Window *parent, WinBits windowStyle) : WorkWindow(parent, windowStyle) {}
Command line processing is done via the following functions. They give the number of parameters, the parameters themselves and a way to get the name of the invoking application.
*/
///@{
/** Gets the number of command line parameters passed to the application
/** Ends the program prematurely with an error message.
If the \code --norestore \endcode command line argument is given (assuming this process is run by developers who are interested in cores, vs. end users who are not) then it does a coredump.
/** Has Quit() been called?
*/ staticbool IsQuit();
/** Attempt to process current pending event(s)
It doesn't sleep if no events are available for processing. This doesn't process any events generated after invoking the function. So in contrast to Scheduler::ProcessEventsToIdle, this cannot become busy-locked by an event-generating event in the event queue.
@param bHandleAllCurrentEvents If set to true, then try to process all the current events. If set to false, then only process one event. Defaults to false.
The UI is considered captured if a system dialog is open (e.g. printer setup), a floating window, menu or toolbox dropdown is open, or a window has been captured by the mouse.
@returns true if UI is captured, false if not
*/ staticbool IsUICaptured();
/** @name Settings
The following functions set system settings (e.g. tab color, etc.). There are functions that set settings objects, and functions that set and get the actual system settings for the application.
*/ ///@{
/** Sets user settings in settings object to override system settings
The system settings that can be overridden are: - window dragging options (on or off, including live scrolling!) - style settings (e.g. checkbox color, border color, 3D colors, button rollover colors, etc.) - mouse settings - menu options, including the mouse follows the menu and whether menu icons are used
@param rSettings Reference to the settings object to change.
@returns reference to a LocaleDataWrapper object
*/
SAL_DLLPRIVATE staticconst LocaleDataWrapper& GetAppLocaleDataWrapper();
///@}
/** @name Event Listeners/Handlers
A set of event listeners and callers. Note that in this code there is platform specific functions - namely for zoom and scroll events.
*/ ///@{
/** Add a VCL event listener to the application. If no event listener exists, then initialize the application's event listener with a new one, then add the event listener.
@param rEventListener Const reference to the event listener to add.
/** Add a keypress listener to the application. If keypress listener exists, then initialize the application's keypress event listener with a new one, then add the keypress listener.
@param rKeyListener Const reference to the keypress event listener to add
@param nEvent Event ID for mouse event @param pWin Pointer to window to which the event is sent @param pMouseEvent Mouse event to send
*/ static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
User events allow for the deferral of work to later in the main-loop - at idle.
Execution of the deferred work is thread-safe which means all the tasks are executed serially, so no thread-safety locks between tasks are necessary.
@param rLink Link to event callback function @param pCaller Pointer to data sent to the event by the caller. Optional. @param bReferenceLink If true - hold a VclPtr<> reference on the Link's instance. Taking the reference is guarded by a SolarMutexGuard.
@return the event ID used to post the event.
*/ static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr, bool bReferenceLink = false );
/** Remove user event based on event ID
@param nUserEvent User event to remove
*/ staticvoid RemoveUserEvent( ImplSVEvent * nUserEvent );
/*** Get the DisplayConnection.
It is a reference to XDisplayConnection, which allows toolkits to send display events to the application.
@returns UNO reference to an object that implements the css:awt:XDisplayConnection interface.
*/ static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
/** @deprecated AppEvent is used only in the Desktop class now. However, it is intended to notify the application that an event has occurred. It was in oldsv.cxx, but is still needed by a number of functions.
@returns The application name.
*/ staticconst OUString & GetAppName();
/** * Get the OS version based on the OS specific implementation. * * @return OUString version string or "-" in case of problems
*/ static OUString GetOSVersion();
/** Get useful OS, Hardware and configuration information, * cf. Help->About, and User-Agent * bSelection = 0 to return all info, 1 for environment only, * and 2 for VCL/render related infos
*/ static OUString GetHWOSConfInfo(constint bSelection = 0, bool bLocalize = true);
/** Load a localized branding PNG file as a bitmap.
@param pName Name of the bitmap to load. @param rBitmap Reference to BitmapEx object to load PNG into
@returns true if the PNG could be loaded, otherwise returns false.
*/ staticbool LoadBrandBitmap (std::u16string_view pName, BitmapEx &rBitmap);
///@}
/** @name Display and Screen
*/ ///@{
/** Set the default name of the application for message dialogs and printing.
@param rDisplayName const reference to string to set the Display name to.
@returns the return value will be nearest screen of the target rectangle.
*/
SAL_DLLPRIVATE staticunsignedint GetBestScreen( const AbsoluteScreenPixelRectangle& );
/** Get the built-in screen.
@return This returns the LCD screen number for a laptop, or the primary external VGA display for a desktop machine - it is where a presenter console should be rendered if there are other (non-built-in) screens present.
Practically, this means - Get the screen we should run a presentation on.
@returns 0 or 1 currently, will fallback to the first available screen if there are more than one external screens. May be changed in the future.
*/ staticunsignedint GetDisplayExternalScreen();
///@}
/** @name Accelerators and Mnemonics
Accelerators allow a user to hold down Ctrl+key (or CMD+key on macOS) combination to gain quick access to functionality.
Mnemonics are underline letters in things like menus and dialog boxes that allow a user to type in the letter to activate the menu or option.
*/ ///@{
/** Insert accelerator
@param pAccel Pointer to an Accelerator object to insert
@returns Pointer to application's help object. Note that the application may not have a help object, so it might return NULL.
@see SetHelp
*/ static Help* GetHelp();
///@}
/** @name Dialogs
@remark "Dialog cancel mode" tells a headless install whether to cancel dialogs when they appear. See the DialogCancelMode enumerator.
*/ ///@{
/** Get the default parent window for dialog boxes.
@remark This is almost always a terrible method to use to get a parent for a dialog, try hard to instead pass a specific parent window to dialogs.
GetDefDialogParent does all sorts of things to try and find a useful parent window for dialogs. It first uses the topmost parent of the active window to avoid using floating windows or other dialog boxes. If there are no active windows, then it will take a random stab and choose the first visible top window. Otherwise, it defaults to the desktop.
@returns Pointer to the default window.
*/ static weld::Window* GetDefDialogParent();
/** Gets the dialog cancel mode for headless environments.
/** Sets the dialog cancel mode for headless environments.
This should be private, but XFrameImpl needs to access it and current baseline gcc doesn't support forward definition of anonymous classes. You probably should use EnableHeadlessMode instead.
The VCL Toolkit implements the UNO XToolkit interface, which specifies a factory interface for the window toolkit. It is similar to the abstract window toolkit (AWT) in Java.
*/ ///@{
/** Gets the VCL toolkit.
@attention The global service manager has to be created before getting the toolkit!
@returns UNO reference to VCL toolkit
*/ static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
///@}
/*** @name Graphic Filters
*/ ///@{
/** Setup a new graphics filter
@param rLink Const reference to a Link object, which the filter calls upon.
@return True if bitmap rendering is enabled.
*/ staticbool IsBitmapRendering();
///@}
/** Set safe mode to enabled */ staticvoid EnableSafeMode();
/** Determines if safe mode is enabled */ staticbool IsSafeModeEnabled();
///@}
/** Get the desktop environment the process is currently running in
@returns String representing the desktop environment
*/ staticconst OUString& GetDesktopEnvironment();
/*** @name Platform Functionality
*/ ///@{
/** Add a file to the system shells recent document list if there is any. This function may have no effect under Unix because there is no standard API among the different desktop managers.
@param rFileUrl The file url of the document.
@param rMimeType The mime content type of the document specified by aFileUrl. If an empty string will be provided "application/octet-stream" will be used.
@param rDocumentService The app (or "document service") you will be adding the file to e.g. com.sun.star.text.TextDocument
*/ staticvoid AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
/** Update main thread identifier */ staticvoid UpdateMainThread();
/** Do we have a native / system file selector available?
@returns True if native file selector is available, false otherwise.
*/ staticbool hasNativeFileSelection();
/** Create a platform specific file picker, if one is available, otherwise return an empty reference.
@param rServiceManager Const reference to a UNO component context (service manager).
@returns File picker if available, otherwise an empty reference.
*/ static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
/** Create a platform specific folder picker, if one is available, otherwise return an empty reference
@param rServiceManager Const reference to a UNO component context (service manager).
@returns Folder picker if available, otherwise an empty reference.
*/ static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
/** Returns true, if the VCL plugin should run on the system event loop. * * AKA the VCL plugin can't handle nested event loops, like WASM or mobile.
*/ staticbool IsUseSystemEventLoop();
///@}
// For vclbootstrapprotector: staticvoid setDeInitHook(Link<LinkParamNone*,void> const & hook);
static std::unique_ptr<weld::Builder> CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false, sal_uInt64 nLOKWindowId = 0); // For the duration of vcl parent windows static std::unique_ptr<weld::Builder> CreateInterimBuilder(vcl::Window* pParent, constOUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId = 0);
class SolarMutexGuard
: public osl::Guard<comphelper::SolarMutex>
{ public:
SolarMutexGuard()
: osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
};
class SolarMutexClearableGuard
: public osl::ClearableGuard<comphelper::SolarMutex>
{ public:
SolarMutexClearableGuard()
: osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
};
class SolarMutexResettableGuard
: public osl::ResettableGuard<comphelper::SolarMutex>
{ public:
SolarMutexResettableGuard()
: osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
};
namespace vcl
{
/** guard class that uses tryToAcquire() and has isAcquired() to check
*/ class SolarMutexTryAndBuyGuard
{ private: bool m_isAcquired; #ifdef DBG_UTIL bool m_isChecked; #endif
comphelper::SolarMutex& m_rSolarMutex;
/** A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex in its destructor.
*/ class SolarMutexReleaser
{ const sal_uInt32 mnReleased; public:
SolarMutexReleaser()
: mnReleased(
Application::GetSolarMutex().IsCurrentThread() ? Application::ReleaseSolarMutex() : 0)
{
}
~SolarMutexReleaser()
{ if (mnReleased)
Application::AcquireSolarMutex(mnReleased);
}
};
VCL_DLLPUBLIC Application* GetpApp();
// returns true if vcl is already initialized
VCL_DLLPUBLIC bool IsVCLInit(); // returns true if vcl successfully initializes or was already initialized
VCL_DLLPUBLIC bool InitVCL();
VCL_DLLPUBLIC void DeInitVCL();
// only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
VCL_DLLPUBLIC void JoinMainLoopThread();
/// The following are to manage per-view (frame) help data. struct ImplSVHelpData;
VCL_DLLPUBLIC ImplSVHelpData* CreateSVHelpData();
VCL_DLLPUBLIC void DestroySVHelpData(ImplSVHelpData*);
VCL_DLLPUBLIC void SetSVHelpData(ImplSVHelpData*);
/// The following are to manage per-view (frame) window data. struct ImplSVWinData;
VCL_DLLPUBLIC ImplSVWinData* CreateSVWinData();
VCL_DLLPUBLIC void DestroySVWinData(ImplSVWinData*);
VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData*);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.