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 { class Window; }
62namespace vcl { class KeyCode; }
63class NotifyEvent;
64class KeyEvent;
65class MouseEvent;
66class GestureEventPan;
67struct ImplSVEvent;
68struct ConvertData;
69namespace basegfx { class SystemDependentDataManager; }
70
71namespace com::sun::star::uno {
72 class XComponentContext;
73}
75 class XFilePicker2;
76 class XFolderPicker2;
77}
78namespace com::sun::star::awt {
79 class XToolkit;
80 class XDisplayConnection;
81 class XWindow;
82}
83
85
87 NOAUTOMODE = 0x0001,
88 DIALOG = 0x0002
89};
90namespace o3tl
91{
92 template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
93}
94
95typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
96
115{
116public:
117 enum class Type {
118 Accept,
119 Appear,
120 Open,
121 OpenHelpUrl,
122 Print,
123 PrivateDoShutdown,
124 QuickStart,
125 ShowDialog,
126 Unaccept
127 };
128
137 {
138 assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
139 }
140
148 ApplicationEvent(Type type, OUString const & data): aEvent(type)
149 {
150 assert(
151 type == Type::Accept || type == Type::OpenHelpUrl
152 || type == Type::ShowDialog || type == Type::Unaccept);
153 aData.push_back(data);
154 }
155
163 ApplicationEvent(Type type, std::vector<OUString>&& data):
164 aEvent(type), aData(std::move(data))
165 {
166 assert(type == Type::Open || type == Type::Print);
167 }
168
174 {
175 return aEvent;
176 }
177
185 OUString const & GetStringData() const
186 {
187 assert(
188 aEvent == Type::Accept
189 || aEvent == Type::OpenHelpUrl || aEvent == Type::ShowDialog
190 || aEvent == Type::Unaccept);
191 assert(aData.size() == 1);
192 return aData[0];
193 }
194
200 std::vector<OUString> const & GetStringsData() const
201 {
202 assert(aEvent == Type::Open || aEvent == Type::Print);
203 return aData;
204 }
205
206private:
208 std::vector<OUString> aData;
209};
210
212 Off,
213 Silent,
214 LOKSilent,
215 Fatal
216};
217
232class VCL_DLLPUBLIC Application : public vcl::ILibreOfficeKitNotifier
233{
234public:
240
249 Application();
250
256 virtual ~Application();
257
265 virtual void Init();
266
271 virtual void InitFinished();
272
280 virtual void DeInit();
281
283
344 virtual int Main();
345
350 virtual bool QueryExit();
351
352 virtual void Shutdown();
353
359
366 static void NotifyAllWindows( DataChangedEvent& rDCEvt );
367
369
378
385 static sal_uInt16 GetCommandLineParamCount();
386
395 static OUString GetCommandLineParam( sal_uInt16 nParam );
396
403 static OUString GetAppFileName();
404
406
421 virtual void Exception( ExceptionCategory nCategory );
422
433 static void Abort( const OUString& rErrorText );
434
436
443
449 static void Execute();
450
456 static void Quit();
457
460 static bool IsQuit();
461
477 static bool Reschedule( bool bHandleAllCurrentEvents = false );
478
487 static void Yield();
488
494 static void EndYield();
495
506 static comphelper::SolarMutex& GetSolarMutex();
507
515 static bool IsMainThread();
516
527 static sal_uInt32 ReleaseSolarMutex();
528
537 static void AcquireSolarMutex( sal_uInt32 nCount );
538
546 static bool IsInMain();
547
554 static bool IsInExecute();
555
562 static bool IsInModalMode();
563
568 static sal_uInt16 GetDispatchLevel();
569
579 static bool AnyInput( VclInputFlags nType = VCL_INPUT_ANY );
580
587 static sal_uInt64 GetLastInputInterval();
588
590
591 /* Determines if the UI is captured.
592
593 The UI is considered captured if a system dialog is open (e.g. printer setup),
594 a floating window, menu or toolbox dropdown is open, or a window has been
595 captured by the mouse.
596
597 @returns true if UI is captured, false if not
598 */
599 static bool IsUICaptured();
600
608
623 virtual void OverrideSystemSettings( AllSettings& rSettings );
624
632 static void MergeSystemSettings( AllSettings& rSettings );
633
642 static void SetSettings( const AllSettings& rSettings );
643
652 static const AllSettings& GetSettings();
653
658 static const LocaleDataWrapper& GetAppLocaleDataWrapper();
659
661
668
669
678 static void AddEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
679
686 static void RemoveEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
687
696 static void AddKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
697
704 static void RemoveKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
705
713 static void ImplCallEventListenersApplicationDataChanged( void* pData );
714
721 static void ImplCallEventListeners( VclSimpleEvent& rEvent );
722
731 static bool HandleKey( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
732
741 static ImplSVEvent * PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, KeyEvent const * pKeyEvent );
742
743
744 static bool LOKHandleMouseEvent( VclEventId nEvent, vcl::Window *pWin, const MouseEvent* pEvent );
745
752 static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
753
754 static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin,
755 GestureEventPan const * pGestureEvent);
756
764 static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
765
780 static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
781 bool bReferenceLink = false );
782
787 static void RemoveUserEvent( ImplSVEvent * nUserEvent );
788
789 /*** Get the DisplayConnection.
790
791 It is a reference to XDisplayConnection, which allows toolkits to send display
792 events to the application.
793
794 @returns UNO reference to an object that implements the css:awt:XDisplayConnection
795 interface.
796 */
797 static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
798
805 virtual void AppEvent( const ApplicationEvent& rAppEvent );
806
808
814
821 static vcl::Window* GetFocusWindow();
822
830 static OutputDevice* GetDefaultDevice();
831
836 static basegfx::SystemDependentDataManager& GetSystemDependentDataManager();
837
845 static vcl::Window* GetFirstTopLevelWindow();
846
854 static vcl::Window* GetNextTopLevelWindow( vcl::Window const * pWindow );
855
864 static tools::Long GetTopWindowCount();
865
878 static vcl::Window* GetTopWindow( tools::Long nIndex );
879
890 static vcl::Window* GetActiveTopWindow();
891
893
900 static void SetAppName( const OUString& rUniqueName );
901
902
906
911 static OUString GetAppName();
912
918 static OUString GetOSVersion();
919
925 static OUString GetHWOSConfInfo(const int bSelection = 0, bool bLocalize = true);
926
934 static bool LoadBrandBitmap (std::u16string_view pName, BitmapEx &rBitmap);
935
937
941
948 static void SetDisplayName( const OUString& rDisplayName );
949
954 static OUString GetDisplayName();
955
960 static OUString GetToolkitName();
961
968 static unsigned int GetScreenCount();
969
978 static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
979
990 static bool IsUnifiedDisplay();
991
1002 SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
1003
1014 static unsigned int GetDisplayBuiltInScreen();
1015
1023 static unsigned int GetDisplayExternalScreen();
1024
1026
1036
1045 static bool InsertAccel( Accelerator* pAccel );
1046
1053 static void RemoveAccel( Accelerator const * pAccel );
1054
1061 static size_t GetReservedKeyCodeCount();
1062
1071 static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1072
1074
1081
1088 static void SetHelp( Help* pHelp = nullptr );
1089
1097 static Help* GetHelp();
1098
1100
1108
1124 static weld::Window* GetDefDialogParent();
1125
1126
1133 static DialogCancelMode GetDialogCancelMode();
1134
1145 static void SetDialogCancelMode( DialogCancelMode mode );
1146
1153 static bool IsDialogCancelEnabled();
1154
1155
1163 static void SetSystemWindowMode( SystemWindowFlags nMode );
1164
1171 static SystemWindowFlags GetSystemWindowMode();
1172
1174
1183
1190 static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1191
1193
1194
1195 /*** @name Graphic Filters
1196 */
1198
1205 static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1206
1208
1216 static void EnableHeadlessMode( bool dialogsAreFatal );
1217
1222 static bool IsHeadlessModeEnabled();
1223
1228 static void EnableConsoleOnly();
1229
1232 static void EnableBitmapRendering();
1233
1238 static bool IsBitmapRendering();
1239
1241
1248 static void EnableEventTestingMode();
1249
1254 static bool IsEventTestingModeEnabled();
1255
1257 static void EnableSafeMode();
1258
1260 static bool IsSafeModeEnabled();
1261
1263
1268 static const OUString& GetDesktopEnvironment();
1269
1270 /*** @name Platform Functionality
1271 */
1273
1287 static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1288
1289 /*** Show a native error messagebox
1290
1291 @param sTitle Title of error messagebox
1292
1293 @param sMessage Message displayed in messagebox
1294 */
1295 static void ShowNativeErrorBox(const OUString& sTitle ,
1296 const OUString& sMessage);
1297
1299 static void UpdateMainThread();
1300
1305 static bool hasNativeFileSelection();
1306
1314 static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1315 createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1316
1324 static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1325 createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1326
1329 static void EndAllDialogs();
1330
1333 static void EndAllPopups();
1334
1339 static bool IsOnSystemEventLoop();
1340
1342
1343 // For vclbootstrapprotector:
1344 static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1345
1346 static std::unique_ptr<weld::Builder> CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false, sal_uInt64 nLOKWindowId = 0);
1347 // For the duration of vcl parent windows
1348 static std::unique_ptr<weld::Builder> CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId = 0);
1349
1350 static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1351 VclButtonsType eButtonType, const OUString& rPrimaryMessage);
1352
1353 static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1354
1355 // ILibreOfficeKitNotifier
1357 LibreOfficeKitCallback m_pCallback;
1358
1359 virtual void notifyWindow(vcl::LOKWindowId nLOKWindowId,
1360 const OUString& rAction,
1361 const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>()) const override;
1362 virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) const override;
1363
1364private:
1365 DECL_DLLPRIVATE_STATIC_LINK( Application, PostEventHandler, void*, void );
1366};
1367
1369 : public osl::Guard<comphelper::SolarMutex>
1370{
1371public:
1373 : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1374};
1375
1377 : public osl::ClearableGuard<comphelper::SolarMutex>
1378{
1379public:
1381 : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1382};
1383
1385 : public osl::ResettableGuard<comphelper::SolarMutex>
1386{
1387public:
1389 : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1390};
1391
1392namespace vcl
1393{
1394
1398{
1399private:
1401#ifdef DBG_UTIL
1403#endif
1405
1408
1409public:
1410
1412 : m_isAcquired(false)
1413#ifdef DBG_UTIL
1414 , m_isChecked(false)
1415#endif
1416 , m_rSolarMutex(Application::GetSolarMutex())
1417
1418 {
1420 }
1421
1423 {
1424#ifdef DBG_UTIL
1425 assert(m_isChecked);
1426#endif
1427 if (m_isAcquired)
1429 }
1430
1432 {
1433#ifdef DBG_UTIL
1434 m_isChecked = true;
1435#endif
1436 return m_isAcquired;
1437 }
1438};
1439
1440} // namespace vcl
1441
1447{
1448 const sal_uInt32 mnReleased;
1449public:
1450 SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1452};
1453
1455
1456// returns true if vcl is already initialized
1458// returns true if vcl successfully initializes or was already initialized
1459VCL_DLLPUBLIC bool InitVCL();
1461
1463
1464// only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1465VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1467
1469struct ImplSVHelpData;
1473
1475struct ImplSVWinData;
1479
1481{
1483}
1484
1485#endif // _APP_HXX
1486
1487/* 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:115
std::vector< OUString > aData
Definition: svapp.hxx:208
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:163
OUString const & GetStringData() const
Gets the application event's data string.
Definition: svapp.hxx:185
Type GetEvent() const
Get the type of event.
Definition: svapp.hxx:173
ApplicationEvent(Type type)
Explicit constructor for ApplicationEvent.
Definition: svapp.hxx:136
std::vector< OUString > const & GetStringsData() const
Gets the event's array of strings.
Definition: svapp.hxx:200
ApplicationEvent(Type type, OUString const &data)
Constructor for ApplicationEvent, accepts a string for the data associated with the event.
Definition: svapp.hxx:148
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:233
LibreOfficeKitCallback m_pCallback
Definition: svapp.hxx:1357
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:1122
DECL_DLLPRIVATE_STATIC_LINK(Application, PostEventHandler, void *, void)
void * m_pCallbackData
Definition: svapp.hxx:1356
static void EndYield()
Definition: svapp.hxx:1480
static void AcquireSolarMutex(sal_uInt32 nCount)
Acquire Solar Mutex(es) for this thread.
Definition: svapp.cxx:591
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:1447
const sal_uInt32 mnReleased
Definition: svapp.hxx:1448
sal_uInt32 release(bool bUnlockAll=false)
virtual bool tryToAcquire()
guard class that uses tryToAcquire() and has isAcquired() to check
Definition: svapp.hxx:1398
SolarMutexTryAndBuyGuard & operator=(const SolarMutexTryAndBuyGuard &)=delete
SolarMutexTryAndBuyGuard(const SolarMutexTryAndBuyGuard &)=delete
comphelper::SolarMutex & m_rSolarMutex
Definition: svapp.hxx:1404
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
void EndAllDialogs(vcl::Window const *pParent)
Definition: dialog.cxx:1201
sal_uInt32 LOKWindowId
ConversionMode mode
QPRO_FUNC_TYPE nType
@ Quit
Definition: salsession.hxx:30
OUString sMessage
VCL_DLLPUBLIC ImplSVHelpData * CreateSVHelpData()
Definition: svdata.cxx:420
VCL_DLLPUBLIC bool InitVCL()
Definition: svmain.cxx:297
VCL_DLLPUBLIC Application * GetpApp()
Definition: svapp.cxx:152
DialogCancelMode
Definition: svapp.hxx:211
@ 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:439
long(* VCLEventHookProc)(NotifyEvent &rEvt, void *pData)
Definition: svapp.hxx:95
VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar(sal_UCS4, LanguageType)
Definition: sallayout.cxx:51
SystemWindowFlags
Definition: svapp.hxx:86
VCL_DLLPUBLIC void SetSVHelpData(ImplSVHelpData *)
Definition: svdata.cxx:457
VCL_DLLPUBLIC void CreateMainLoopThread(oslWorkerFunction pWorker, void *pThreadData)
Definition: svmain.cxx:662
VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData *)
Definition: svdata.cxx:390
VCL_DLLPUBLIC void DeInitVCL()
Definition: svmain.cxx:420
VCL_DLLPUBLIC void JoinMainLoopThread()
Definition: svmain.cxx:680
VCL_DLLPUBLIC bool InitAccessBridge()
Definition: svapp.cxx:1744
VCL_DLLPUBLIC bool IsVCLInit()
Definition: svmain.cxx:278
VCL_DLLPUBLIC ImplSVWinData * CreateSVWinData()
Definition: svdata.cxx:371
VCL_DLLPUBLIC void DestroySVWinData(ImplSVWinData *)
Definition: svdata.cxx:385
ResultType type
VclMessageType
Definition: vclenum.hxx:233
VclButtonsType
Definition: vclenum.hxx:223
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:172
VclEventId
Definition: vclevent.hxx:38