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
994 static bool IsUnifiedDisplay();
995
1006 SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
1007
1018 static unsigned int GetDisplayBuiltInScreen();
1019
1027 static unsigned int GetDisplayExternalScreen();
1028
1030
1040
1049 static bool InsertAccel( Accelerator* pAccel );
1050
1057 static void RemoveAccel( Accelerator const * pAccel );
1058
1065 static size_t GetReservedKeyCodeCount();
1066
1075 static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1076
1078
1085
1092 static void SetHelp( Help* pHelp = nullptr );
1093
1101 static Help* GetHelp();
1102
1104
1112
1128 static weld::Window* GetDefDialogParent();
1129
1130
1137 static DialogCancelMode GetDialogCancelMode();
1138
1149 static void SetDialogCancelMode( DialogCancelMode mode );
1150
1157 static bool IsDialogCancelEnabled();
1158
1159
1167 static void SetSystemWindowMode( SystemWindowFlags nMode );
1168
1175 static SystemWindowFlags GetSystemWindowMode();
1176
1178
1187
1194 static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1195
1197
1198
1199 /*** @name Graphic Filters
1200 */
1202
1209 static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1210
1212
1220 static void EnableHeadlessMode( bool dialogsAreFatal );
1221
1226 static bool IsHeadlessModeEnabled();
1227
1232 static void EnableConsoleOnly();
1233
1236 static void EnableBitmapRendering();
1237
1242 static bool IsBitmapRendering();
1243
1245
1247 static void EnableSafeMode();
1248
1250 static bool IsSafeModeEnabled();
1251
1253
1258 static const OUString& GetDesktopEnvironment();
1259
1260 /*** @name Platform Functionality
1261 */
1263
1277 static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1278
1279 /*** Show a native error messagebox
1280
1281 @param sTitle Title of error messagebox
1282
1283 @param sMessage Message displayed in messagebox
1284 */
1285 static void ShowNativeErrorBox(const OUString& sTitle ,
1286 const OUString& sMessage);
1287
1289 static void UpdateMainThread();
1290
1295 static bool hasNativeFileSelection();
1296
1304 static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1305 createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1306
1314 static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1315 createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1316
1321 static bool IsOnSystemEventLoop();
1322
1324
1325 // For vclbootstrapprotector:
1326 static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1327
1328 static std::unique_ptr<weld::Builder> CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false, sal_uInt64 nLOKWindowId = 0);
1329 // For the duration of vcl parent windows
1330 static std::unique_ptr<weld::Builder> CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId = 0);
1331
1332 static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1333 VclButtonsType eButtonType, const OUString& rPrimaryMessage,
1334 const ILibreOfficeKitNotifier* pNotifier = nullptr);
1335
1336 static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1337
1338 // ILibreOfficeKitNotifier
1340 LibreOfficeKitCallback m_pCallback;
1341
1342 virtual void notifyWindow(vcl::LOKWindowId nLOKWindowId,
1343 const OUString& rAction,
1344 const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>()) const override;
1345 virtual void libreOfficeKitViewCallback(int nType, const OString& pPayload) const override;
1346 virtual void notifyInvalidation(tools::Rectangle const *) const override;
1347
1348
1349private:
1350 DECL_DLLPRIVATE_STATIC_LINK( Application, PostEventHandler, void*, void );
1351};
1352
1354 : public osl::Guard<comphelper::SolarMutex>
1355{
1356public:
1358 : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1359};
1360
1362 : public osl::ClearableGuard<comphelper::SolarMutex>
1363{
1364public:
1366 : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1367};
1368
1370 : public osl::ResettableGuard<comphelper::SolarMutex>
1371{
1372public:
1374 : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1375};
1376
1377namespace vcl
1378{
1379
1383{
1384private:
1386#ifdef DBG_UTIL
1388#endif
1390
1393
1394public:
1395
1397 : m_isAcquired(false)
1398#ifdef DBG_UTIL
1399 , m_isChecked(false)
1400#endif
1401 , m_rSolarMutex(Application::GetSolarMutex())
1402
1403 {
1405 }
1406
1408 {
1409#ifdef DBG_UTIL
1410 assert(m_isChecked);
1411#endif
1412 if (m_isAcquired)
1414 }
1415
1417 {
1418#ifdef DBG_UTIL
1419 m_isChecked = true;
1420#endif
1421 return m_isAcquired;
1422 }
1423};
1424
1425} // namespace vcl
1426
1432{
1433 const sal_uInt32 mnReleased;
1434public:
1435 SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1437};
1438
1440
1441// returns true if vcl is already initialized
1443// returns true if vcl successfully initializes or was already initialized
1444VCL_DLLPUBLIC bool InitVCL();
1446
1448
1449// only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1450VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1452
1454struct ImplSVHelpData;
1458
1460struct ImplSVWinData;
1464
1466{
1468}
1469
1470#endif // _APP_HXX
1471
1472/* 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:1340
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:1016
DECL_DLLPRIVATE_STATIC_LINK(Application, PostEventHandler, void *, void)
void * m_pCallbackData
Definition: svapp.hxx:1339
static void EndYield()
Definition: svapp.hxx:1465
static void AcquireSolarMutex(sal_uInt32 nCount)
Acquire Solar Mutex(es) for this thread.
Definition: svapp.cxx:485
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:1432
const sal_uInt32 mnReleased
Definition: svapp.hxx:1433
sal_uInt32 release(bool bUnlockAll=false)
virtual bool tryToAcquire()
guard class that uses tryToAcquire() and has isAcquired() to check
Definition: svapp.hxx:1383
SolarMutexTryAndBuyGuard & operator=(const SolarMutexTryAndBuyGuard &)=delete
SolarMutexTryAndBuyGuard(const SolarMutexTryAndBuyGuard &)=delete
comphelper::SolarMutex & m_rSolarMutex
Definition: svapp.hxx:1389
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:444
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:463
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:481
VCL_DLLPUBLIC void CreateMainLoopThread(oslWorkerFunction pWorker, void *pThreadData)
Definition: svmain.cxx:665
VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData *)
Definition: svdata.cxx:391
VCL_DLLPUBLIC void DeInitVCL()
Definition: svmain.cxx:421
VCL_DLLPUBLIC void JoinMainLoopThread()
Definition: svmain.cxx:683
VCL_DLLPUBLIC bool InitAccessBridge()
Definition: svapp.cxx:1626
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:221
VclButtonsType
Definition: vclenum.hxx:211
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:160
VclEventId
Definition: vclevent.hxx:38