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;
69
70namespace com::sun::star::uno {
71 class XComponentContext;
72}
74 class XFilePicker2;
75 class XFolderPicker2;
76}
77namespace com::sun::star::awt {
78 class XToolkit;
79 class XDisplayConnection;
80 class XWindow;
81}
82
83// helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
86
88 NOAUTOMODE = 0x0001,
89 DIALOG = 0x0002
90};
91namespace o3tl
92{
93 template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
94}
95
96typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
97
116{
117public:
118 enum class Type {
119 Accept,
120 Appear,
121 Open,
122 OpenHelpUrl,
123 Print,
124 PrivateDoShutdown,
125 QuickStart,
126 ShowDialog,
127 Unaccept
128 };
129
138 {
139 assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
140 }
141
149 ApplicationEvent(Type type, OUString const & data): aEvent(type)
150 {
151 assert(
152 type == Type::Accept || type == Type::OpenHelpUrl
153 || type == Type::ShowDialog || type == Type::Unaccept);
154 aData.push_back(data);
155 }
156
164 ApplicationEvent(Type type, std::vector<OUString>&& data):
165 aEvent(type), aData(std::move(data))
166 {
167 assert(type == Type::Open || type == Type::Print);
168 }
169
175 {
176 return aEvent;
177 }
178
186 OUString const & GetStringData() const
187 {
188 assert(
189 aEvent == Type::Accept
190 || aEvent == Type::OpenHelpUrl || aEvent == Type::ShowDialog
191 || aEvent == Type::Unaccept);
192 assert(aData.size() == 1);
193 return aData[0];
194 }
195
201 std::vector<OUString> const & GetStringsData() const
202 {
203 assert(aEvent == Type::Open || aEvent == Type::Print);
204 return aData;
205 }
206
207private:
209 std::vector<OUString> aData;
210};
211
213 Off,
214 Silent,
215 LOKSilent,
216 Fatal
217};
218
233class VCL_DLLPUBLIC Application : public vcl::ILibreOfficeKitNotifier
234{
235public:
241
250 Application();
251
257 virtual ~Application();
258
266 virtual void Init();
267
272 virtual void InitFinished();
273
281 virtual void DeInit();
282
284
345 virtual int Main();
346
351 virtual bool QueryExit();
352
353 virtual void Shutdown();
354
360
367 static void NotifyAllWindows( DataChangedEvent& rDCEvt );
368
370
379
386 static sal_uInt16 GetCommandLineParamCount();
387
396 static OUString GetCommandLineParam( sal_uInt16 nParam );
397
404 static OUString GetAppFileName();
405
407
422 virtual void Exception( ExceptionCategory nCategory );
423
434 static void Abort( const OUString& rErrorText );
435
437
444
450 static void Execute();
451
457 static void Quit();
458
461 static bool IsQuit();
462
478 static bool Reschedule( bool bHandleAllCurrentEvents = false );
479
488 static void Yield();
489
495 static void EndYield();
496
507 static comphelper::SolarMutex& GetSolarMutex();
508
516 static bool IsMainThread();
517
528 static sal_uInt32 ReleaseSolarMutex();
529
538 static void AcquireSolarMutex( sal_uInt32 nCount );
539
547 static bool IsInMain();
548
555 static bool IsInExecute();
556
563 static bool IsInModalMode();
564
569 static sal_uInt16 GetDispatchLevel();
570
580 static bool AnyInput( VclInputFlags nType = VCL_INPUT_ANY );
581
588 static sal_uInt64 GetLastInputInterval();
589
591
592 /* Determines if the UI is captured.
593
594 The UI is considered captured if a system dialog is open (e.g. printer setup),
595 a floating window, menu or toolbox dropdown is open, or a window has been
596 captured by the mouse.
597
598 @returns true if UI is captured, false if not
599 */
600 static bool IsUICaptured();
601
609
624 virtual void OverrideSystemSettings( AllSettings& rSettings );
625
633 static void MergeSystemSettings( AllSettings& rSettings );
634
643 static void SetSettings( const AllSettings& rSettings );
644
653 static const AllSettings& GetSettings();
654
659 static const LocaleDataWrapper& GetAppLocaleDataWrapper();
660
662
669
670
679 static void AddEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
680
687 static void RemoveEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
688
697 static void AddKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
698
705 static void RemoveKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
706
714 static void ImplCallEventListenersApplicationDataChanged( void* pData );
715
722 static void ImplCallEventListeners( VclSimpleEvent& rEvent );
723
732 static bool HandleKey( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
733
742 static ImplSVEvent * PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, KeyEvent const * pKeyEvent );
743
744
745 static bool LOKHandleMouseEvent( VclEventId nEvent, vcl::Window *pWin, const MouseEvent* pEvent );
746
753 static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
754
755 static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin,
756 GestureEventPan const * pGestureEvent);
757
765 static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
766
781 static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
782 bool bReferenceLink = false );
783
788 static void RemoveUserEvent( ImplSVEvent * nUserEvent );
789
790 /*** Get the DisplayConnection.
791
792 It is a reference to XDisplayConnection, which allows toolkits to send display
793 events to the application.
794
795 @returns UNO reference to an object that implements the css:awt:XDisplayConnection
796 interface.
797 */
798 static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
799
806 virtual void AppEvent( const ApplicationEvent& rAppEvent );
807
809
815
822 static vcl::Window* GetFocusWindow();
823
831 static OutputDevice* GetDefaultDevice();
832
840 static vcl::Window* GetFirstTopLevelWindow();
841
849 static vcl::Window* GetNextTopLevelWindow( vcl::Window const * pWindow );
850
859 static tools::Long GetTopWindowCount();
860
873 static vcl::Window* GetTopWindow( tools::Long nIndex );
874
885 static vcl::Window* GetActiveTopWindow();
886
888
895 static void SetAppName( const OUString& rUniqueName );
896
897
901
906 static OUString GetAppName();
907
913 static OUString GetOSVersion();
914
920 static OUString GetHWOSConfInfo(const int bSelection = 0, bool bLocalize = true);
921
929 static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
930
932
936
943 static void SetDisplayName( const OUString& rDisplayName );
944
949 static OUString GetDisplayName();
950
955 static OUString GetToolkitName();
956
963 static unsigned int GetScreenCount();
964
973 static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
974
985 static bool IsUnifiedDisplay();
986
997 SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
998
1009 static unsigned int GetDisplayBuiltInScreen();
1010
1018 static unsigned int GetDisplayExternalScreen();
1019
1021
1031
1040 static bool InsertAccel( Accelerator* pAccel );
1041
1048 static void RemoveAccel( Accelerator const * pAccel );
1049
1056 static size_t GetReservedKeyCodeCount();
1057
1066 static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1067
1069
1076
1083 static void SetHelp( Help* pHelp = nullptr );
1084
1092 static Help* GetHelp();
1093
1095
1103
1119 static weld::Window* GetDefDialogParent();
1120
1121
1128 static DialogCancelMode GetDialogCancelMode();
1129
1140 static void SetDialogCancelMode( DialogCancelMode mode );
1141
1148 static bool IsDialogCancelEnabled();
1149
1150
1158 static void SetSystemWindowMode( SystemWindowFlags nMode );
1159
1166 static SystemWindowFlags GetSystemWindowMode();
1167
1169
1178
1185 static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1186
1188
1189
1190 /*** @name Graphic Filters
1191 */
1193
1200 static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1201
1203
1211 static void EnableHeadlessMode( bool dialogsAreFatal );
1212
1217 static bool IsHeadlessModeEnabled();
1218
1223 static void EnableConsoleOnly();
1224
1227 static void EnableBitmapRendering();
1228
1233 static bool IsBitmapRendering();
1234
1236
1243 static void EnableEventTestingMode();
1244
1249 static bool IsEventTestingModeEnabled();
1250
1252 static void EnableSafeMode();
1253
1255 static bool IsSafeModeEnabled();
1256
1258
1263 static const OUString& GetDesktopEnvironment();
1264
1265 /*** @name Platform Functionality
1266 */
1268
1282 static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1283
1284 /*** Show a native error messagebox
1285
1286 @param sTitle Title of error messagebox
1287
1288 @param sMessage Message displayed in messagebox
1289 */
1290 static void ShowNativeErrorBox(const OUString& sTitle ,
1291 const OUString& sMessage);
1292
1294 static void UpdateMainThread();
1295
1300 static bool hasNativeFileSelection();
1301
1309 static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1310 createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1311
1319 static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1320 createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1321
1324 static void EndAllDialogs();
1325
1328 static void EndAllPopups();
1329
1334 static bool IsOnSystemEventLoop();
1335
1337
1338 // For vclbootstrapprotector:
1339 static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1340
1341 static std::unique_ptr<weld::Builder> CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false, sal_uInt64 nLOKWindowId = 0);
1342 // For the duration of vcl parent windows
1343 static std::unique_ptr<weld::Builder> CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId = 0);
1344
1345 static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1346 VclButtonsType eButtonType, const OUString& rPrimaryMessage,
1347 bool bMobile = false);
1348
1349 static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1350
1351 // ILibreOfficeKitNotifier
1353 LibreOfficeKitCallback m_pCallback;
1354
1355 virtual void notifyWindow(vcl::LOKWindowId nLOKWindowId,
1356 const OUString& rAction,
1357 const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>()) const override;
1358 virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) const override;
1359
1360private:
1361 DECL_DLLPRIVATE_STATIC_LINK( Application, PostEventHandler, void*, void );
1362};
1363
1365 : public osl::Guard<comphelper::SolarMutex>
1366{
1367public:
1369 : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1370};
1371
1373 : public osl::ClearableGuard<comphelper::SolarMutex>
1374{
1375public:
1377 : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1378};
1379
1381 : public osl::ResettableGuard<comphelper::SolarMutex>
1382{
1383public:
1385 : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1386};
1387
1388namespace vcl
1389{
1390
1394{
1395private:
1397#ifdef DBG_UTIL
1399#endif
1401
1404
1405public:
1406
1408 : m_isAcquired(false)
1409#ifdef DBG_UTIL
1410 , m_isChecked(false)
1411#endif
1412 , m_rSolarMutex(Application::GetSolarMutex())
1413
1414 {
1416 }
1417
1419 {
1420#ifdef DBG_UTIL
1421 assert(m_isChecked);
1422#endif
1423 if (m_isAcquired)
1425 }
1426
1428 {
1429#ifdef DBG_UTIL
1430 m_isChecked = true;
1431#endif
1432 return m_isAcquired;
1433 }
1434};
1435
1436} // namespace vcl
1437
1443{
1444 const sal_uInt32 mnReleased;
1445public:
1446 SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1448};
1449
1451
1452// returns true if vcl is already initialized
1454// returns true if vcl successfully initializes or was already initialized
1455VCL_DLLPUBLIC bool InitVCL();
1457
1459
1460// only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1461VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1463
1465struct ImplSVHelpData;
1469
1471struct ImplSVWinData;
1475
1477{
1479}
1480
1481#endif // _APP_HXX
1482
1483/* 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:116
std::vector< OUString > aData
Definition: svapp.hxx:209
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:164
OUString const & GetStringData() const
Gets the application event's data string.
Definition: svapp.hxx:186
Type GetEvent() const
Get the type of event.
Definition: svapp.hxx:174
ApplicationEvent(Type type)
Explicit constructor for ApplicationEvent.
Definition: svapp.hxx:137
std::vector< OUString > const & GetStringsData() const
Gets the event's array of strings.
Definition: svapp.hxx:201
ApplicationEvent(Type type, OUString const &data)
Constructor for ApplicationEvent, accepts a string for the data associated with the event.
Definition: svapp.hxx:149
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:234
LibreOfficeKitCallback m_pCallback
Definition: svapp.hxx:1353
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:1352
static void EndYield()
Definition: svapp.hxx:1476
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:171
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
Definition: svapp.hxx:1443
const sal_uInt32 mnReleased
Definition: svapp.hxx:1444
sal_uInt32 release(bool bUnlockAll=false)
virtual bool tryToAcquire()
guard class that uses tryToAcquire() and has isAcquired() to check
Definition: svapp.hxx:1394
SolarMutexTryAndBuyGuard & operator=(const SolarMutexTryAndBuyGuard &)=delete
SolarMutexTryAndBuyGuard(const SolarMutexTryAndBuyGuard &)=delete
comphelper::SolarMutex & m_rSolarMutex
Definition: svapp.hxx:1400
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:1199
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:212
@ 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:96
VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar(sal_UCS4, LanguageType)
Definition: sallayout.cxx:60
SystemWindowFlags
Definition: svapp.hxx:87
VCL_DLLPUBLIC sal_UCS4 GetMirroredChar(sal_UCS4)
Definition: sallayout.cxx:54
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:1731
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