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 <osl/mutex.hxx>
31 #include <rtl/ustring.hxx>
32 #include <osl/thread.h>
33 #include <tools/gen.hxx>
34 #include <tools/link.hxx>
35 #include <tools/solar.h>
36 #include <vcl/dllapi.h>
37 #include <vcl/inputtypes.hxx>
38 #include <vcl/exceptiontypes.hxx>
39 #include <vcl/vclevent.hxx>
40 #include <vcl/vclenum.hxx>
41 #include <i18nlangtag/lang.h>
42 #include <o3tl/typed_flags_set.hxx>
43 #include <com/sun/star/uno/Reference.h>
44 
45 
46 class BitmapEx;
47 namespace weld
48 {
49  class Builder;
50  class MessageDialog;
51  class Widget;
52  class Window;
53 }
54 class LocaleDataWrapper;
55 class AllSettings;
56 class DataChangedEvent;
57 class Accelerator;
58 class Help;
59 class OutputDevice;
60 namespace vcl { class Window; }
61 namespace vcl { class KeyCode; }
62 class NotifyEvent;
63 class KeyEvent;
64 class MouseEvent;
65 class GestureEvent;
66 struct ImplSVEvent;
67 struct ConvertData;
68 
69 namespace com {
70 namespace sun {
71 namespace star {
72 namespace uno {
73  class XComponentContext;
74 }
75 namespace ui {
76  namespace dialogs {
77  class XFilePicker2;
78  class XFolderPicker2;
79  }
80 }
81 namespace awt {
82  class XToolkit;
83  class XDisplayConnection;
84  class XWindow;
85 }
86 } } }
87 
88 // helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
91 
92 enum class SystemWindowFlags {
93  NOAUTOMODE = 0x0001,
94  DIALOG = 0x0002
95 };
96 namespace o3tl
97 {
98  template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
99 }
100 
101 typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
102 
121 {
122 public:
123  enum class Type {
124  Accept,
125  Appear,
126  Open,
127  OpenHelpUrl,
128  Print,
129  PrivateDoShutdown,
130  QuickStart,
131  ShowDialog,
132  Unaccept
133  };
134 
142  explicit ApplicationEvent(Type type): aEvent(type)
143  {
144  assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
145  }
146 
154  ApplicationEvent(Type type, OUString const & data): aEvent(type)
155  {
156  assert(
157  type == Type::Accept || type == Type::OpenHelpUrl
158  || type == Type::ShowDialog || type == Type::Unaccept);
159  aData.push_back(data);
160  }
161 
169  ApplicationEvent(Type type, std::vector<OUString> const & data):
170  aEvent(type), aData(data)
171  {
172  assert(type == Type::Open || type == Type::Print);
173  }
174 
179  Type GetEvent() const
180  {
181  return aEvent;
182  }
183 
191  OUString const & GetStringData() const
192  {
193  assert(
194  aEvent == Type::Accept
195  || aEvent == Type::OpenHelpUrl || aEvent == Type::ShowDialog
196  || aEvent == Type::Unaccept);
197  assert(aData.size() == 1);
198  return aData[0];
199  }
200 
206  std::vector<OUString> const & GetStringsData() const
207  {
208  assert(aEvent == Type::Open || aEvent == Type::Print);
209  return aData;
210  }
211 
212 private:
214  std::vector<OUString> aData;
215 };
216 
217 enum class DialogCancelMode {
218  Off,
219  Silent,
220  Fatal
221 };
222 
238 {
239 public:
244 
254  Application();
255 
261  virtual ~Application();
262 
270  virtual void Init();
271 
276  virtual void InitFinished();
277 
285  virtual void DeInit();
286 
288 
349  virtual int Main();
350 
355  virtual bool QueryExit();
356 
357  virtual void Shutdown();
358 
363 
371  static void NotifyAllWindows( DataChangedEvent& rDCEvt );
372 
374 
382 
390  static sal_uInt16 GetCommandLineParamCount();
391 
400  static OUString GetCommandLineParam( sal_uInt16 nParam );
401 
408  static OUString GetAppFileName();
409 
411 
426  virtual void Exception( ExceptionCategory nCategory );
427 
438  static void Abort( const OUString& rErrorText );
439 
441 
447 
454  static void Execute();
455 
461  static void Quit();
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 long GetTopWindowCount();
856 
869  static vcl::Window* GetTopWindow( 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 
907  static OUString GetHWOSConfInfo();
908 
916  static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
917 
919 
922 
930  static void SetDisplayName( const OUString& rDisplayName );
931 
936  static OUString GetDisplayName();
937 
942  static OUString GetToolkitName();
943 
950  static unsigned int GetScreenCount();
951 
960  static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
961 
972  static bool IsUnifiedDisplay();
973 
984  SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
985 
996  static unsigned int GetDisplayBuiltInScreen();
997 
1005  static unsigned int GetDisplayExternalScreen();
1006 
1008 
1017 
1027  static bool InsertAccel( Accelerator* pAccel );
1028 
1035  static void RemoveAccel( Accelerator const * pAccel );
1036 
1043  static size_t GetReservedKeyCodeCount();
1044 
1053  static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1054 
1056 
1062 
1070  static void SetHelp( Help* pHelp = nullptr );
1071 
1079  static Help* GetHelp();
1080 
1082 
1089 
1102  static vcl::Window* GetDefDialogParent();
1103 
1104 
1111  static DialogCancelMode GetDialogCancelMode();
1112 
1123  static void SetDialogCancelMode( DialogCancelMode mode );
1124 
1131  static bool IsDialogCancelEnabled();
1132 
1133 
1141  static void SetSystemWindowMode( SystemWindowFlags nMode );
1142 
1149  static SystemWindowFlags GetSystemWindowMode();
1150 
1152 
1160 
1168  static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1169 
1171 
1172 
1173  /*** @name Graphic Filters
1174  */
1176 
1183  static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1184 
1186 
1194  static void EnableHeadlessMode( bool dialogsAreFatal );
1195 
1200  static bool IsHeadlessModeEnabled();
1201 
1206  static void EnableConsoleOnly();
1207 
1210  static void EnableBitmapRendering();
1211 
1216  static bool IsBitmapRendering();
1217 
1219 
1226  static void EnableEventTestingMode();
1227 
1232  static bool IsEventTestingModeEnabled();
1233 
1235  static void EnableSafeMode();
1236 
1238  static bool IsSafeModeEnabled();
1239 
1241 
1246  static const OUString& GetDesktopEnvironment();
1247 
1248  /*** @name Platform Functionality
1249  */
1251 
1265  static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1266 
1267  /*** Show a native error messagebox
1268 
1269  @param sTitle Title of error messagebox
1270 
1271  @param sMessage Message displayed in messagebox
1272  */
1273  static void ShowNativeErrorBox(const OUString& sTitle ,
1274  const OUString& sMessage);
1275 
1277  static void UpdateMainThread();
1278 
1283  static bool hasNativeFileSelection();
1284 
1292  static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1293  createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1294 
1302  static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1303  createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1304 
1307  static void EndAllDialogs();
1308 
1311  static void EndAllPopups();
1312 
1314 
1324  static void LockFontUpdates(bool bLock);
1325 
1326  // For vclbootstrapprotector:
1327  static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1328 
1329  static weld::Builder* CreateBuilder(weld::Widget* pParent, const OUString &rUIFile);
1330  static weld::Builder* CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile); //for the duration of vcl parent windows
1331 
1332  static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1333  VclButtonsType eButtonType, const OUString& rPrimaryMessage);
1334 
1335  static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1336 private:
1337  DECL_STATIC_LINK( Application, PostEventHandler, void*, void );
1338 };
1339 
1341  : public osl::Guard<comphelper::SolarMutex>
1342 {
1343 public:
1345  : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1346 };
1347 
1349  : public osl::ClearableGuard<comphelper::SolarMutex>
1350 {
1351 public:
1353  : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1354 };
1355 
1357  : public osl::ResettableGuard<comphelper::SolarMutex>
1358 {
1359 public:
1361  : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1362 };
1363 
1364 namespace vcl
1365 {
1366 
1370 {
1371 private:
1373 #ifdef DBG_UTIL
1375 #endif
1377 
1380 
1381 public:
1382 
1384  : m_isAcquired(false)
1385 #ifdef DBG_UTIL
1386  , m_isChecked(false)
1387 #endif
1388  , m_rSolarMutex(Application::GetSolarMutex())
1389 
1390  {
1391  m_isAcquired = m_rSolarMutex.tryToAcquire();
1392  }
1393 
1395  {
1396 #ifdef DBG_UTIL
1397  assert(m_isChecked);
1398 #endif
1399  if (m_isAcquired)
1400  m_rSolarMutex.release();
1401  }
1402 
1403  bool isAcquired()
1404  {
1405 #ifdef DBG_UTIL
1406  m_isChecked = true;
1407 #endif
1408  return m_isAcquired;
1409  }
1410 };
1411 
1412 } // namespace vcl
1413 
1419 {
1420  const sal_uInt32 mnReleased;
1421 public:
1422  SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1424 };
1425 
1427 
1428 // returns true if vcl is already initialized
1429 VCL_DLLPUBLIC bool IsVCLInit();
1430 // returns true if vcl successfully initializes or was already initialized
1431 VCL_DLLPUBLIC bool InitVCL();
1432 VCL_DLLPUBLIC void DeInitVCL();
1433 
1435 
1436 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1437 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1439 
1441 struct ImplSVHelpData;
1445 
1447 struct ImplSVWinData;
1451 
1453 {
1455 }
1456 
1457 #endif // _APP_HXX
1458 
1459 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< OUString > const & GetStringsData() const
Gets the event's array of strings.
Definition: svapp.hxx:206
Type GetEvent() const
Get the type of event.
Definition: svapp.hxx:179
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:154
VCL_DLLPUBLIC bool IsVCLInit()
Definition: svmain.cxx:271
static void AcquireSolarMutex(sal_uInt32 nCount)
Acquire Solar Mutex(es) for this thread.
Definition: svapp.cxx:549
void Init()
const char aData[]
VclButtonsType
Definition: vclenum.hxx:246
std::unique_ptr< ContentProperties > pData
Definition: help.hxx:60
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
VCL_DLLPUBLIC bool InitAccessBridge()
Definition: svapp.cxx:1600
VCL_DLLPUBLIC void SetSVHelpData(ImplSVHelpData *)
Definition: svdata.cxx:449
std::vector< OUString > aData
Definition: svapp.hxx:214
VCL_DLLPUBLIC void JoinMainLoopThread()
Definition: svmain.cxx:667
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:1006
An application can be notified of a number of different events:
Definition: svapp.hxx:120
VCL_DLLPUBLIC void DestroySVHelpData(ImplSVHelpData *)
Definition: svdata.cxx:431
VclInputFlags
Definition: inputtypes.hxx:25
ApplicationEvent(Type type)
Explicit constructor for ApplicationEvent.
Definition: svapp.hxx:142
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
Definition: svapp.hxx:1418
int nCount
VclEventId
Definition: vclevent.hxx:41
VclMessageType
Definition: vclenum.hxx:256
VCL_DLLPUBLIC void DestroySVWinData(ImplSVWinData *)
Definition: svdata.cxx:377
ExceptionCategory
sal_uInt32 release(bool bUnlockAll=false)
ApplicationEvent(Type type, std::vector< OUString > const &data)
Constructor for ApplicationEvent, accepts an array of strings for the data associated with the event...
Definition: svapp.hxx:169
VCL_DLLPUBLIC bool InitVCL()
Definition: svmain.cxx:290
const sal_uInt32 mnReleased
Definition: svapp.hxx:1420
sal_uInt16 char * pName
SolarMutexTryAndBuyGuard & operator=(const SolarMutexTryAndBuyGuard &)=delete
VCL_DLLPUBLIC Application * GetpApp()
Definition: svapp.cxx:149
silently cancel any dialogs
int i
void EndAllDialogs(vcl::Window const *pParent)
Definition: dialog.cxx:1161
VCL_DLLPUBLIC ImplSVHelpData * CreateSVHelpData()
Definition: svdata.cxx:412
SystemWindowFlags
Definition: svapp.hxx:92
sal_uInt16 & nParam
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData *)
Definition: svdata.cxx:382
VCL_DLLPUBLIC sal_UCS4 GetMirroredChar(sal_UCS4)
Definition: sallayout.cxx:131
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:237
VCL_DLLPUBLIC ImplSVWinData * CreateSVWinData()
Definition: svdata.cxx:363
ConversionMode mode
#define VCL_INPUT_ANY
Definition: inputtypes.hxx:39
VCL_DLLPUBLIC void CreateMainLoopThread(oslWorkerFunction pWorker, void *pThreadData)
Definition: svmain.cxx:649
VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar(sal_UCS4, LanguageType)
Definition: sallayout.cxx:137
long(* VCLEventHookProc)(NotifyEvent &rEvt, void *pData)
Definition: svapp.hxx:101
cancel any dialogs by std::abort
QPRO_FUNC_TYPE nType
virtual bool tryToAcquire()
sal_uInt32 sal_UCS4
Definition: fontcharmap.hxx:29
VCL_DLLPUBLIC void DeInitVCL()
Definition: svmain.cxx:412
guard class that uses tryToAcquire() and has isAcquired() to check
Definition: svapp.hxx:1369
OUString const & GetStringData() const
Gets the application event's data string.
Definition: svapp.hxx:191
DialogCancelMode
Definition: svapp.hxx:217
comphelper::SolarMutex & m_rSolarMutex
Definition: svapp.hxx:1376
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
AnyEventRef aEvent
static void EndYield()
Definition: svapp.hxx:1452