LibreOffice Module vcl (master) 1
svapp.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_VCL_SVAPP_HXX
21#define INCLUDED_VCL_SVAPP_HXX
22
23#include <sal/config.h>
24#include <sal/types.h>
25
26#include <cassert>
27#include <vector>
28
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>
38#include <vcl/inputtypes.hxx>
40#include <vcl/vclevent.hxx>
41#include <vcl/vclenum.hxx>
42#include <i18nlangtag/lang.h>
44#include <com/sun/star/uno/Reference.h>
45
46
47class BitmapEx;
48namespace weld
49{
50 class Builder;
51 class MessageDialog;
52 class Widget;
53 class Window;
54}
56class AllSettings;
58class Accelerator;
59class Help;
60class OutputDevice;
61namespace vcl {
62 class KeyCode;
63 class ILibreOfficeKitNotifier;
64 class Window;
65}
66
67class NotifyEvent;
68class KeyEvent;
69class MouseEvent;
70class GestureEventPan;
71struct ImplSVEvent;
72struct ConvertData;
73namespace basegfx { class SystemDependentDataManager; }
74
75namespace com::sun::star::uno {
76 class XComponentContext;
77}
79 class XFilePicker2;
80 class XFolderPicker2;
81}
82namespace com::sun::star::awt {
83 class XToolkit;
84 class XDisplayConnection;
85 class XWindow;
86}
87
89
91 NOAUTOMODE = 0x0001,
92 DIALOG = 0x0002
93};
94namespace o3tl
95{
96 template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
97}
98
99typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
100
119{
120public:
121 enum class Type {
122 Accept,
123 Appear,
124 Open,
125 OpenHelpUrl,
126 Print,
127 PrivateDoShutdown,
128 QuickStart,
129 ShowDialog,
130 Unaccept
131 };
132
141 {
142 assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
143 }
144
152 ApplicationEvent(Type type, OUString const & data): aEvent(type)
153 {
154 assert(
155 type == Type::Accept || type == Type::OpenHelpUrl
156 || type == Type::ShowDialog || type == Type::Unaccept);
157 aData.push_back(data);
158 }
159
167 ApplicationEvent(Type type, std::vector<OUString>&& data):
168 aEvent(type), aData(std::move(data))
169 {
170 assert(type == Type::Open || type == Type::Print);
171 }
172
178 {
179 return aEvent;
180 }
181
189 OUString const & GetStringData() const
190 {
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];
197 }
198
204 std::vector<OUString> const & GetStringsData() const
205 {
206 assert(aEvent == Type::Open || aEvent == Type::Print);
207 return aData;
208 }
209
210private:
212 std::vector<OUString> aData;
213};
214
216 Off,
217 Silent,
218 LOKSilent,
219 Fatal
220};
221
237{
238public:
244
253 Application();
254
260 virtual ~Application();
261
269 virtual void Init();
270
275 virtual void InitFinished();
276
284 virtual void DeInit();
285
287
348 virtual int Main();
349
354 virtual bool QueryExit();
355
356 virtual void Shutdown();
357
363
370 static void NotifyAllWindows( DataChangedEvent& rDCEvt );
371
373
382
389 static sal_uInt16 GetCommandLineParamCount();
390
399 static OUString GetCommandLineParam( sal_uInt16 nParam );
400
407 static OUString GetAppFileName();
408
410
425 virtual void Exception( ExceptionCategory nCategory );
426
437 static void Abort( const OUString& rErrorText );
438
440
447
453 static void Execute();
454
460 static void Quit();
461
464 static bool IsQuit();
465
481 static bool Reschedule( bool bHandleAllCurrentEvents = false );
482
491 static void Yield();
492
498 static void EndYield();
499
510 static comphelper::SolarMutex& GetSolarMutex();
511
519 static bool IsMainThread();
520
531 static sal_uInt32 ReleaseSolarMutex();
532
541 static void AcquireSolarMutex( sal_uInt32 nCount );
542
550 static bool IsInMain();
551
558 static bool IsInExecute();
559
566 static bool IsInModalMode();
567
572 static sal_uInt16 GetDispatchLevel();
573
583 static bool AnyInput( VclInputFlags nType = VCL_INPUT_ANY );
584
591 static sal_uInt64 GetLastInputInterval();
592
594
595 /* Determines if the UI is captured.
596
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.
600
601 @returns true if UI is captured, false if not
602 */
603 static bool IsUICaptured();
604
612
627 virtual void OverrideSystemSettings( AllSettings& rSettings );
628
636 static void MergeSystemSettings( AllSettings& rSettings );
637
646 static void SetSettings( const AllSettings& rSettings );
647
656 static const AllSettings& GetSettings();
657
662 static const LocaleDataWrapper& GetAppLocaleDataWrapper();
663
665
672
673
682 static void AddEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
683
690 static void RemoveEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
691
700 static void AddKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
701
708 static void RemoveKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
709
717 static void ImplCallEventListenersApplicationDataChanged( void* pData );
718
725 static void ImplCallEventListeners( VclSimpleEvent& rEvent );
726
735 static bool HandleKey( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
736
745 static ImplSVEvent * PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, KeyEvent const * pKeyEvent );
746
747
748 static bool LOKHandleMouseEvent( VclEventId nEvent, vcl::Window *pWin, const MouseEvent* pEvent );
749
756 static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
757
758 static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin,
759 GestureEventPan const * pGestureEvent);
760
768 static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
769
784 static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
785 bool bReferenceLink = false );
786
791 static void RemoveUserEvent( ImplSVEvent * nUserEvent );
792
793 /*** Get the DisplayConnection.
794
795 It is a reference to XDisplayConnection, which allows toolkits to send display
796 events to the application.
797
798 @returns UNO reference to an object that implements the css:awt:XDisplayConnection
799 interface.
800 */
801 static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
802
809 virtual void AppEvent( const ApplicationEvent& rAppEvent );
810
812
818
825 static vcl::Window* GetFocusWindow();
826
834 static OutputDevice* GetDefaultDevice();
835
840 static basegfx::SystemDependentDataManager& GetSystemDependentDataManager();
841
849 static vcl::Window* GetFirstTopLevelWindow();
850
858 static vcl::Window* GetNextTopLevelWindow( vcl::Window const * pWindow );
859
868 static tools::Long GetTopWindowCount();
869
882 static vcl::Window* GetTopWindow( tools::Long nIndex );
883
894 static vcl::Window* GetActiveTopWindow();
895
897
904 static void SetAppName( const OUString& rUniqueName );
905
906
910
915 static OUString GetAppName();
916
922 static OUString GetOSVersion();
923
929 static OUString GetHWOSConfInfo(const int bSelection = 0, bool bLocalize = true);
930
938 static bool LoadBrandBitmap (std::u16string_view pName, BitmapEx &rBitmap);
939
941
945
952 static void SetDisplayName( const OUString& rDisplayName );
953
958 static OUString GetDisplayName();
959
964 static OUString GetToolkitName();
965
972 static unsigned int GetScreenCount();
973
982 static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
983
988 SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
989
1000 static unsigned int GetDisplayBuiltInScreen();
1001
1009 static unsigned int GetDisplayExternalScreen();
1010
1012
1022
1031 static bool InsertAccel( Accelerator* pAccel );
1032
1039 static void RemoveAccel( Accelerator const * pAccel );
1040
1047 static size_t GetReservedKeyCodeCount();
1048
1057 static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1058
1060
1067
1074 static void SetHelp( Help* pHelp = nullptr );
1075
1083 static Help* GetHelp();
1084
1086
1094
1110 static weld::Window* GetDefDialogParent();
1111
1112
1119 static DialogCancelMode GetDialogCancelMode();
1120
1131 static void SetDialogCancelMode( DialogCancelMode mode );
1132
1139 static bool IsDialogCancelEnabled();
1140
1141
1149 static void SetSystemWindowMode( SystemWindowFlags nMode );
1150
1157 static SystemWindowFlags GetSystemWindowMode();
1158
1160
1169
1176 static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1177
1179
1180
1181 /*** @name Graphic Filters
1182 */
1184
1191 static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1192
1194
1202 static void EnableHeadlessMode( bool dialogsAreFatal );
1203
1208 static bool IsHeadlessModeEnabled();
1209
1214 static void EnableConsoleOnly();
1215
1218 static void EnableBitmapRendering();
1219
1224 static bool IsBitmapRendering();
1225
1227
1229 static void EnableSafeMode();
1230
1232 static bool IsSafeModeEnabled();
1233
1235
1240 static const OUString& GetDesktopEnvironment();
1241
1242 /*** @name Platform Functionality
1243 */
1245
1259 static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1260
1261 /*** Show a native error messagebox
1262
1263 @param sTitle Title of error messagebox
1264
1265 @param sMessage Message displayed in messagebox
1266 */
1267 static void ShowNativeErrorBox(const OUString& sTitle ,
1268 const OUString& sMessage);
1269
1271 static void UpdateMainThread();
1272
1277 static bool hasNativeFileSelection();
1278
1286 static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1287 createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1288
1296 static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1297 createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1298
1303 static bool IsOnSystemEventLoop();
1304
1306
1307 // For vclbootstrapprotector:
1308 static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1309
1310 static std::unique_ptr<weld::Builder> CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false, sal_uInt64 nLOKWindowId = 0);
1311 // For the duration of vcl parent windows
1312 static std::unique_ptr<weld::Builder> CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId = 0);
1313
1314 static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1315 VclButtonsType eButtonType, const OUString& rPrimaryMessage,
1316 const ILibreOfficeKitNotifier* pNotifier = nullptr);
1317
1318 static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1319
1320 // ILibreOfficeKitNotifier
1322 LibreOfficeKitCallback m_pCallback;
1323
1324 virtual void notifyWindow(vcl::LOKWindowId nLOKWindowId,
1325 const OUString& rAction,
1326 const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>()) const override;
1327 virtual void libreOfficeKitViewCallback(int nType, const OString& pPayload) const override;
1328 virtual void notifyInvalidation(tools::Rectangle const *) const override;
1329
1330
1331private:
1332 DECL_DLLPRIVATE_STATIC_LINK( Application, PostEventHandler, void*, void );
1333};
1334
1336 : public osl::Guard<comphelper::SolarMutex>
1337{
1338public:
1340 : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1341};
1342
1344 : public osl::ClearableGuard<comphelper::SolarMutex>
1345{
1346public:
1348 : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1349};
1350
1352 : public osl::ResettableGuard<comphelper::SolarMutex>
1353{
1354public:
1356 : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1357};
1358
1359namespace vcl
1360{
1361
1365{
1366private:
1368#ifdef DBG_UTIL
1370#endif
1372
1375
1376public:
1377
1379 : m_isAcquired(false)
1380#ifdef DBG_UTIL
1381 , m_isChecked(false)
1382#endif
1383 , m_rSolarMutex(Application::GetSolarMutex())
1384
1385 {
1387 }
1388
1390 {
1391#ifdef DBG_UTIL
1392 assert(m_isChecked);
1393#endif
1394 if (m_isAcquired)
1396 }
1397
1399 {
1400#ifdef DBG_UTIL
1401 m_isChecked = true;
1402#endif
1403 return m_isAcquired;
1404 }
1405};
1406
1407} // namespace vcl
1408
1414{
1415 const sal_uInt32 mnReleased;
1416public:
1417 SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1419};
1420
1422
1423// returns true if vcl is already initialized
1425// returns true if vcl successfully initializes or was already initialized
1426VCL_DLLPUBLIC bool InitVCL();
1428
1430
1431// only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1432VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1434
1436struct ImplSVHelpData;
1440
1442struct ImplSVWinData;
1446
1448{
1450}
1451
1452#endif // _APP_HXX
1453
1454/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
AnyEventRef aEvent
An application can be notified of a number of different events:
Definition: svapp.hxx:119
std::vector< OUString > aData
Definition: svapp.hxx:212
ApplicationEvent(Type type, std::vector< OUString > &&data)
Constructor for ApplicationEvent, accepts an array of strings for the data associated with the event.
Definition: svapp.hxx:167
OUString const & GetStringData() const
Gets the application event's data string.
Definition: svapp.hxx:189
Type GetEvent() const
Get the type of event.
Definition: svapp.hxx:177
ApplicationEvent(Type type)
Explicit constructor for ApplicationEvent.
Definition: svapp.hxx:140
std::vector< OUString > const & GetStringsData() const
Gets the event's array of strings.
Definition: svapp.hxx:204
ApplicationEvent(Type type, OUString const &data)
Constructor for ApplicationEvent, accepts a string for the data associated with the event.
Definition: svapp.hxx:152
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:237
LibreOfficeKitCallback m_pCallback
Definition: svapp.hxx:1322
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
Post a user event to the default window.
Definition: svapp.cxx:999
DECL_DLLPRIVATE_STATIC_LINK(Application, PostEventHandler, void *, void)
void * m_pCallbackData
Definition: svapp.hxx:1321
static void EndYield()
Definition: svapp.hxx:1447
static void AcquireSolarMutex(sal_uInt32 nCount)
Acquire Solar Mutex(es) for this thread.
Definition: svapp.cxx:468
Definition: help.hxx:61
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
Definition: svapp.hxx:1414
const sal_uInt32 mnReleased
Definition: svapp.hxx:1415
sal_uInt32 release(bool bUnlockAll=false)
virtual bool tryToAcquire()
guard class that uses tryToAcquire() and has isAcquired() to check
Definition: svapp.hxx:1365
SolarMutexTryAndBuyGuard & operator=(const SolarMutexTryAndBuyGuard &)=delete
SolarMutexTryAndBuyGuard(const SolarMutexTryAndBuyGuard &)=delete
comphelper::SolarMutex & m_rSolarMutex
Definition: svapp.hxx:1371
void Init()
int nCount
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
ExceptionCategory
VclInputFlags
Definition: inputtypes.hxx:25
#define VCL_INPUT_ANY
Definition: inputtypes.hxx:39
sal_Int32 nIndex
std::unique_ptr< sal_Int32[]> pData
def Print(s)
constexpr OUStringLiteral aData
@ Exception
int i
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
const ::avmedia::MediaItem * Execute(const SdrMarkView *pSdrView, SfxRequest const &rReq)
long Long
sal_uInt32 LOKWindowId
ConversionMode mode
QPRO_FUNC_TYPE nType
@ Quit
Definition: salsession.hxx:30
OUString sMessage
VCL_DLLPUBLIC ImplSVHelpData * CreateSVHelpData()
Definition: svdata.cxx:448
VCL_DLLPUBLIC bool InitVCL()
Definition: svmain.cxx:298
VCL_DLLPUBLIC Application * GetpApp()
Definition: svapp.cxx:154
DialogCancelMode
Definition: svapp.hxx:215
@ Silent
silently cancel any dialogs
@ Fatal
cancel any dialogs by std::abort
@ LOKSilent
silently cancel any dialogs (LOK case)
VCL_DLLPUBLIC void DestroySVHelpData(ImplSVHelpData *)
Definition: svdata.cxx:467
long(* VCLEventHookProc)(NotifyEvent &rEvt, void *pData)
Definition: svapp.hxx:99
VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar(sal_UCS4, LanguageType)
Definition: sallayout.cxx:51
SystemWindowFlags
Definition: svapp.hxx:90
VCL_DLLPUBLIC void SetSVHelpData(ImplSVHelpData *)
Definition: svdata.cxx:485
VCL_DLLPUBLIC void CreateMainLoopThread(oslWorkerFunction pWorker, void *pThreadData)
Definition: svmain.cxx:659
VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData *)
Definition: svdata.cxx:391
VCL_DLLPUBLIC void DeInitVCL()
Definition: svmain.cxx:421
VCL_DLLPUBLIC void JoinMainLoopThread()
Definition: svmain.cxx:677
VCL_DLLPUBLIC bool InitAccessBridge()
Definition: svapp.cxx:1600
VCL_DLLPUBLIC bool IsVCLInit()
Definition: svmain.cxx:279
VCL_DLLPUBLIC ImplSVWinData * CreateSVWinData()
Definition: svdata.cxx:372
VCL_DLLPUBLIC void DestroySVWinData(ImplSVWinData *)
Definition: svdata.cxx:386
ResultType type
VclMessageType
Definition: vclenum.hxx:226
VclButtonsType
Definition: vclenum.hxx:216
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:160
VclEventId
Definition: vclevent.hxx:38