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>
39 #include <vcl/exceptiontypes.hxx>
40 #include <vcl/vclevent.hxx>
41 #include <vcl/vclenum.hxx>
42 #include <i18nlangtag/lang.h>
43 #include <o3tl/typed_flags_set.hxx>
44 #include <com/sun/star/uno/Reference.h>
45 
46 
47 class BitmapEx;
48 namespace weld
49 {
50  class Builder;
51  class MessageDialog;
52  class Widget;
53  class Window;
54 }
55 class LocaleDataWrapper;
56 class AllSettings;
57 class DataChangedEvent;
58 class Accelerator;
59 class Help;
60 class OutputDevice;
61 namespace vcl { class Window; }
62 namespace vcl { class KeyCode; }
63 class NotifyEvent;
64 class KeyEvent;
65 class MouseEvent;
66 class GestureEvent;
67 struct ImplSVEvent;
68 struct ConvertData;
69 
70 namespace com::sun::star::uno {
71  class XComponentContext;
72 }
74  class XFilePicker2;
75  class XFolderPicker2;
76 }
77 namespace 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 
87 enum class SystemWindowFlags {
88  NOAUTOMODE = 0x0001,
89  DIALOG = 0x0002
90 };
91 namespace o3tl
92 {
93  template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
94 }
95 
96 typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
97 
116 {
117 public:
118  enum class Type {
119  Accept,
120  Appear,
121  Open,
122  OpenHelpUrl,
123  Print,
124  PrivateDoShutdown,
125  QuickStart,
126  ShowDialog,
127  Unaccept
128  };
129 
137  explicit ApplicationEvent(Type type): aEvent(type)
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 
174  Type GetEvent() const
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 
207 private:
209  std::vector<OUString> aData;
210 };
211 
212 enum class DialogCancelMode {
213  Off,
214  Silent,
215  LOKSilent,
216  Fatal
217 };
218 
233 class VCL_DLLPUBLIC Application : public vcl::ILibreOfficeKitNotifier
234 {
235 public:
240 
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 
359 
367  static void NotifyAllWindows( DataChangedEvent& rDCEvt );
368 
370 
378 
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 
443 
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 
608 
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 
668 
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 
750  static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
751 
752  static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin, GestureEvent const * pGestureEvent);
753 
761  static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
762 
777  static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
778  bool bReferenceLink = false );
779 
784  static void RemoveUserEvent( ImplSVEvent * nUserEvent );
785 
786  /*** Get the DisplayConnection.
787 
788  It is a reference to XDisplayConnection, which allows toolkits to send display
789  events to the application.
790 
791  @returns UNO reference to an object that implements the css:awt:XDisplayConnection
792  interface.
793  */
794  static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
795 
802  virtual void AppEvent( const ApplicationEvent& rAppEvent );
803 
805 
810 
818  static vcl::Window* GetFocusWindow();
819 
827  static OutputDevice* GetDefaultDevice();
828 
836  static vcl::Window* GetFirstTopLevelWindow();
837 
845  static vcl::Window* GetNextTopLevelWindow( vcl::Window const * pWindow );
846 
855  static tools::Long GetTopWindowCount();
856 
869  static vcl::Window* GetTopWindow( tools::Long nIndex );
870 
881  static vcl::Window* GetActiveTopWindow();
882 
884 
891  static void SetAppName( const OUString& rUniqueName );
892 
893 
896 
902  static OUString GetAppName();
903 
909  static OUString GetHWOSConfInfo(const int bSelection = 0, bool bLocalize = true);
910 
918  static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
919 
921 
924 
932  static void SetDisplayName( const OUString& rDisplayName );
933 
938  static OUString GetDisplayName();
939 
944  static OUString GetToolkitName();
945 
952  static unsigned int GetScreenCount();
953 
962  static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
963 
974  static bool IsUnifiedDisplay();
975 
986  SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
987 
998  static unsigned int GetDisplayBuiltInScreen();
999 
1007  static unsigned int GetDisplayExternalScreen();
1008 
1010 
1019 
1029  static bool InsertAccel( Accelerator* pAccel );
1030 
1037  static void RemoveAccel( Accelerator const * pAccel );
1038 
1045  static size_t GetReservedKeyCodeCount();
1046 
1055  static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1056 
1058 
1064 
1072  static void SetHelp( Help* pHelp = nullptr );
1073 
1081  static Help* GetHelp();
1082 
1084 
1091 
1108  static weld::Window* GetDefDialogParent();
1109 
1110 
1117  static DialogCancelMode GetDialogCancelMode();
1118 
1129  static void SetDialogCancelMode( DialogCancelMode mode );
1130 
1137  static bool IsDialogCancelEnabled();
1138 
1139 
1147  static void SetSystemWindowMode( SystemWindowFlags nMode );
1148 
1155  static SystemWindowFlags GetSystemWindowMode();
1156 
1158 
1166 
1174  static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1175 
1177 
1178 
1179  /*** @name Graphic Filters
1180  */
1182 
1189  static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1190 
1192 
1200  static void EnableHeadlessMode( bool dialogsAreFatal );
1201 
1206  static bool IsHeadlessModeEnabled();
1207 
1212  static void EnableConsoleOnly();
1213 
1216  static void EnableBitmapRendering();
1217 
1222  static bool IsBitmapRendering();
1223 
1225 
1232  static void EnableEventTestingMode();
1233 
1238  static bool IsEventTestingModeEnabled();
1239 
1241  static void EnableSafeMode();
1242 
1244  static bool IsSafeModeEnabled();
1245 
1247 
1252  static const OUString& GetDesktopEnvironment();
1253 
1254  /*** @name Platform Functionality
1255  */
1257 
1271  static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1272 
1273  /*** Show a native error messagebox
1274 
1275  @param sTitle Title of error messagebox
1276 
1277  @param sMessage Message displayed in messagebox
1278  */
1279  static void ShowNativeErrorBox(const OUString& sTitle ,
1280  const OUString& sMessage);
1281 
1283  static void UpdateMainThread();
1284 
1289  static bool hasNativeFileSelection();
1290 
1298  static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1299  createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1300 
1308  static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1309  createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1310 
1313  static void EndAllDialogs();
1314 
1317  static void EndAllPopups();
1318 
1320 
1321  // For vclbootstrapprotector:
1322  static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1323 
1324  static weld::Builder* CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false, sal_uInt64 nLOKWindowId = 0);
1325  // For the duration of vcl parent windows
1326  static weld::Builder* CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId = 0);
1327 
1328  static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1329  VclButtonsType eButtonType, const OUString& rPrimaryMessage,
1330  bool bMobile = false);
1331 
1332  static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1333 
1334  // ILibreOfficeKitNotifier
1336  LibreOfficeKitCallback m_pCallback;
1337 
1338  virtual void notifyWindow(vcl::LOKWindowId nLOKWindowId,
1339  const OUString& rAction,
1340  const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>()) const override;
1341  virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) const override;
1342 
1343 private:
1344  DECL_STATIC_LINK( Application, PostEventHandler, void*, void );
1345 };
1346 
1348  : public osl::Guard<comphelper::SolarMutex>
1349 {
1350 public:
1352  : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1353 };
1354 
1356  : public osl::ClearableGuard<comphelper::SolarMutex>
1357 {
1358 public:
1360  : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1361 };
1362 
1364  : public osl::ResettableGuard<comphelper::SolarMutex>
1365 {
1366 public:
1368  : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1369 };
1370 
1371 namespace vcl
1372 {
1373 
1377 {
1378 private:
1380 #ifdef DBG_UTIL
1382 #endif
1384 
1387 
1388 public:
1389 
1391  : m_isAcquired(false)
1392 #ifdef DBG_UTIL
1393  , m_isChecked(false)
1394 #endif
1395  , m_rSolarMutex(Application::GetSolarMutex())
1396 
1397  {
1398  m_isAcquired = m_rSolarMutex.tryToAcquire();
1399  }
1400 
1402  {
1403 #ifdef DBG_UTIL
1404  assert(m_isChecked);
1405 #endif
1406  if (m_isAcquired)
1407  m_rSolarMutex.release();
1408  }
1409 
1410  bool isAcquired()
1411  {
1412 #ifdef DBG_UTIL
1413  m_isChecked = true;
1414 #endif
1415  return m_isAcquired;
1416  }
1417 };
1418 
1419 } // namespace vcl
1420 
1426 {
1427  const sal_uInt32 mnReleased;
1428 public:
1429  SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1431 };
1432 
1434 
1435 // returns true if vcl is already initialized
1436 VCL_DLLPUBLIC bool IsVCLInit();
1437 // returns true if vcl successfully initializes or was already initialized
1438 VCL_DLLPUBLIC bool InitVCL();
1439 VCL_DLLPUBLIC void DeInitVCL();
1440 
1442 
1443 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1444 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1446 
1448 struct ImplSVHelpData;
1452 
1454 struct ImplSVWinData;
1458 
1460 {
1462 }
1463 
1464 #endif // _APP_HXX
1465 
1466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< OUString > const & GetStringsData() const
Gets the event's array of strings.
Definition: svapp.hxx:201
Type GetEvent() const
Get the type of event.
Definition: svapp.hxx:174
def Print(s)
OUString sMessage
sal_Int32 nIndex
ApplicationEvent(Type type, OUString const &data)
Constructor for ApplicationEvent, accepts a string for the data associated with the event...
Definition: svapp.hxx:149
VCL_DLLPUBLIC bool IsVCLInit()
Definition: svmain.cxx:274
static void AcquireSolarMutex(sal_uInt32 nCount)
Acquire Solar Mutex(es) for this thread.
Definition: svapp.cxx:563
void Init()
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:192
VclButtonsType
Definition: vclenum.hxx:242
std::unique_ptr< ContentProperties > pData
Definition: help.hxx:60
silently cancel any dialogs (LOK case)
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
VCL_DLLPUBLIC bool InitAccessBridge()
Definition: svapp.cxx:1628
long Long
VCL_DLLPUBLIC void SetSVHelpData(ImplSVHelpData *)
Definition: svdata.cxx:441
std::vector< OUString > aData
Definition: svapp.hxx:209
const ::avmedia::MediaItem * Execute(const SdrMarkView *pSdrView, SfxRequest const &rReq)
VCL_DLLPUBLIC void JoinMainLoopThread()
Definition: svmain.cxx:672
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:1025
An application can be notified of a number of different events:
Definition: svapp.hxx:115
VCL_DLLPUBLIC void DestroySVHelpData(ImplSVHelpData *)
Definition: svdata.cxx:423
VclInputFlags
Definition: inputtypes.hxx:25
ApplicationEvent(Type type)
Explicit constructor for ApplicationEvent.
Definition: svapp.hxx:137
void * m_pCallbackData
Definition: svapp.hxx:1335
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
Definition: svapp.hxx:1425
int nCount
VclEventId
Definition: vclevent.hxx:37
VclMessageType
Definition: vclenum.hxx:252
VCL_DLLPUBLIC void DestroySVWinData(ImplSVWinData *)
Definition: svdata.cxx:369
ExceptionCategory
sal_uInt32 release(bool bUnlockAll=false)
constexpr OUStringLiteral aData
VCL_DLLPUBLIC bool InitVCL()
Definition: svmain.cxx:293
const sal_uInt32 mnReleased
Definition: svapp.hxx:1427
sal_uInt16 char * pName
SolarMutexTryAndBuyGuard & operator=(const SolarMutexTryAndBuyGuard &)=delete
VCL_DLLPUBLIC Application * GetpApp()
Definition: svapp.cxx:151
silently cancel any dialogs
int i
void EndAllDialogs(vcl::Window const *pParent)
Definition: dialog.cxx:1181
VCL_DLLPUBLIC ImplSVHelpData * CreateSVHelpData()
Definition: svdata.cxx:404
SystemWindowFlags
Definition: svapp.hxx:87
sal_uInt16 & nParam
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:168
VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData *)
Definition: svdata.cxx:374
VCL_DLLPUBLIC sal_UCS4 GetMirroredChar(sal_UCS4)
Definition: sallayout.cxx:54
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
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:233
VCL_DLLPUBLIC ImplSVWinData * CreateSVWinData()
Definition: svdata.cxx:355
exports com.sun.star.chart2. data
sal_uInt32 LOKWindowId
ConversionMode mode
#define VCL_INPUT_ANY
Definition: inputtypes.hxx:39
VCL_DLLPUBLIC void CreateMainLoopThread(oslWorkerFunction pWorker, void *pThreadData)
Definition: svmain.cxx:654
LibreOfficeKitCallback m_pCallback
Definition: svapp.hxx:1336
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar(sal_UCS4, LanguageType)
Definition: sallayout.cxx:60
long(* VCLEventHookProc)(NotifyEvent &rEvt, void *pData)
Definition: svapp.hxx:96
cancel any dialogs by std::abort
QPRO_FUNC_TYPE nType
virtual bool tryToAcquire()
VCL_DLLPUBLIC void DeInitVCL()
Definition: svmain.cxx:415
guard class that uses tryToAcquire() and has isAcquired() to check
Definition: svapp.hxx:1376
OUString const & GetStringData() const
Gets the application event's data string.
Definition: svapp.hxx:186
DialogCancelMode
Definition: svapp.hxx:212
comphelper::SolarMutex & m_rSolarMutex
Definition: svapp.hxx:1383
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
AnyEventRef aEvent
static void EndYield()
Definition: svapp.hxx:1459