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 <vcl/dllapi.h>
36 #include <vcl/inputtypes.hxx>
37 #include <vcl/exceptiontypes.hxx>
38 #include <vcl/vclevent.hxx>
39 #include <vcl/vclenum.hxx>
40 #include <i18nlangtag/lang.h>
41 #include <o3tl/typed_flags_set.hxx>
42 #include <com/sun/star/uno/Reference.h>
43 
44 
45 class BitmapEx;
46 namespace weld
47 {
48  class Builder;
49  class MessageDialog;
50  class Widget;
51  class Window;
52 }
53 class LocaleDataWrapper;
54 class AllSettings;
55 class DataChangedEvent;
56 class Accelerator;
57 class Help;
58 class OutputDevice;
59 namespace vcl { class Window; }
60 namespace vcl { class KeyCode; }
61 class NotifyEvent;
62 class KeyEvent;
63 class MouseEvent;
64 class GestureEvent;
65 struct ImplSVEvent;
66 struct ConvertData;
67 
68 namespace com::sun::star::uno {
69  class XComponentContext;
70 }
72  class XFilePicker2;
73  class XFolderPicker2;
74 }
75 namespace com::sun::star::awt {
76  class XToolkit;
77  class XDisplayConnection;
78  class XWindow;
79 }
80 
81 // helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
84 
85 enum class SystemWindowFlags {
86  NOAUTOMODE = 0x0001,
87  DIALOG = 0x0002
88 };
89 namespace o3tl
90 {
91  template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
92 }
93 
94 typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
95 
114 {
115 public:
116  enum class Type {
117  Accept,
118  Appear,
119  Open,
120  OpenHelpUrl,
121  Print,
122  PrivateDoShutdown,
123  QuickStart,
124  ShowDialog,
125  Unaccept
126  };
127 
135  explicit ApplicationEvent(Type type): aEvent(type)
136  {
137  assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
138  }
139 
147  ApplicationEvent(Type type, OUString const & data): aEvent(type)
148  {
149  assert(
150  type == Type::Accept || type == Type::OpenHelpUrl
151  || type == Type::ShowDialog || type == Type::Unaccept);
152  aData.push_back(data);
153  }
154 
162  ApplicationEvent(Type type, std::vector<OUString> const & data):
163  aEvent(type), aData(data)
164  {
165  assert(type == Type::Open || type == Type::Print);
166  }
167 
172  Type GetEvent() const
173  {
174  return aEvent;
175  }
176 
184  OUString const & GetStringData() const
185  {
186  assert(
187  aEvent == Type::Accept
188  || aEvent == Type::OpenHelpUrl || aEvent == Type::ShowDialog
189  || aEvent == Type::Unaccept);
190  assert(aData.size() == 1);
191  return aData[0];
192  }
193 
199  std::vector<OUString> const & GetStringsData() const
200  {
201  assert(aEvent == Type::Open || aEvent == Type::Print);
202  return aData;
203  }
204 
205 private:
207  std::vector<OUString> aData;
208 };
209 
210 enum class DialogCancelMode {
211  Off,
212  Silent,
213  Fatal
214 };
215 
231 {
232 public:
237 
247  Application();
248 
254  virtual ~Application();
255 
263  virtual void Init();
264 
269  virtual void InitFinished();
270 
278  virtual void DeInit();
279 
281 
342  virtual int Main();
343 
348  virtual bool QueryExit();
349 
350  virtual void Shutdown();
351 
356 
364  static void NotifyAllWindows( DataChangedEvent& rDCEvt );
365 
367 
375 
383  static sal_uInt16 GetCommandLineParamCount();
384 
393  static OUString GetCommandLineParam( sal_uInt16 nParam );
394 
401  static OUString GetAppFileName();
402 
404 
419  virtual void Exception( ExceptionCategory nCategory );
420 
431  static void Abort( const OUString& rErrorText );
432 
434 
440 
447  static void Execute();
448 
454  static void Quit();
455 
471  static bool Reschedule( bool bHandleAllCurrentEvents = false );
472 
481  static void Yield();
482 
488  static void EndYield();
489 
500  static comphelper::SolarMutex& GetSolarMutex();
501 
509  static bool IsMainThread();
510 
521  static sal_uInt32 ReleaseSolarMutex();
522 
531  static void AcquireSolarMutex( sal_uInt32 nCount );
532 
540  static bool IsInMain();
541 
548  static bool IsInExecute();
549 
556  static bool IsInModalMode();
557 
562  static sal_uInt16 GetDispatchLevel();
563 
573  static bool AnyInput( VclInputFlags nType = VCL_INPUT_ANY );
574 
581  static sal_uInt64 GetLastInputInterval();
582 
584 
585  /* Determines if the UI is captured.
586 
587  The UI is considered captured if a system dialog is open (e.g. printer setup),
588  a floating window, menu or toolbox dropdown is open, or a window has been
589  captured by the mouse.
590 
591  @returns true if UI is captured, false if not
592  */
593  static bool IsUICaptured();
594 
601 
617  virtual void OverrideSystemSettings( AllSettings& rSettings );
618 
626  static void MergeSystemSettings( AllSettings& rSettings );
627 
636  static void SetSettings( const AllSettings& rSettings );
637 
646  static const AllSettings& GetSettings();
647 
652  static const LocaleDataWrapper& GetAppLocaleDataWrapper();
653 
655 
661 
663 
672  static void AddEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
673 
680  static void RemoveEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
681 
690  static void AddKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
691 
698  static void RemoveKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
699 
707  static void ImplCallEventListenersApplicationDataChanged( void* pData );
708 
715  static void ImplCallEventListeners( VclSimpleEvent& rEvent );
716 
725  static bool HandleKey( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
726 
735  static ImplSVEvent * PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, KeyEvent const * pKeyEvent );
736 
743  static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
744 
745  static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin, GestureEvent const * pGestureEvent);
746 
754  static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
755 
770  static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
771  bool bReferenceLink = false );
772 
777  static void RemoveUserEvent( ImplSVEvent * nUserEvent );
778 
779  /*** Get the DisplayConnection.
780 
781  It is a reference to XDisplayConnection, which allows toolkits to send display
782  events to the application.
783 
784  @returns UNO reference to an object that implements the css:awt:XDisplayConnection
785  interface.
786  */
787  static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
788 
795  virtual void AppEvent( const ApplicationEvent& rAppEvent );
796 
798 
803 
811  static vcl::Window* GetFocusWindow();
812 
820  static OutputDevice* GetDefaultDevice();
821 
829  static vcl::Window* GetFirstTopLevelWindow();
830 
838  static vcl::Window* GetNextTopLevelWindow( vcl::Window const * pWindow );
839 
848  static long GetTopWindowCount();
849 
862  static vcl::Window* GetTopWindow( long nIndex );
863 
874  static vcl::Window* GetActiveTopWindow();
875 
877 
884  static void SetAppName( const OUString& rUniqueName );
885 
886 
889 
895  static OUString GetAppName();
896 
902  static OUString GetHWOSConfInfo(const int bSelection = 0, bool bLocalize = true);
903 
911  static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
912 
914 
917 
925  static void SetDisplayName( const OUString& rDisplayName );
926 
931  static OUString GetDisplayName();
932 
937  static OUString GetToolkitName();
938 
945  static unsigned int GetScreenCount();
946 
955  static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
956 
967  static bool IsUnifiedDisplay();
968 
979  SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
980 
991  static unsigned int GetDisplayBuiltInScreen();
992 
1000  static unsigned int GetDisplayExternalScreen();
1001 
1003 
1012 
1022  static bool InsertAccel( Accelerator* pAccel );
1023 
1030  static void RemoveAccel( Accelerator const * pAccel );
1031 
1038  static size_t GetReservedKeyCodeCount();
1039 
1048  static const vcl::KeyCode* GetReservedKeyCode( size_t i );
1049 
1051 
1057 
1065  static void SetHelp( Help* pHelp = nullptr );
1066 
1074  static Help* GetHelp();
1075 
1077 
1084 
1097  static vcl::Window* GetDefDialogParent();
1098 
1099 
1106  static DialogCancelMode GetDialogCancelMode();
1107 
1118  static void SetDialogCancelMode( DialogCancelMode mode );
1119 
1126  static bool IsDialogCancelEnabled();
1127 
1128 
1136  static void SetSystemWindowMode( SystemWindowFlags nMode );
1137 
1144  static SystemWindowFlags GetSystemWindowMode();
1145 
1147 
1155 
1163  static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1164 
1166 
1167 
1168  /*** @name Graphic Filters
1169  */
1171 
1178  static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1179 
1181 
1189  static void EnableHeadlessMode( bool dialogsAreFatal );
1190 
1195  static bool IsHeadlessModeEnabled();
1196 
1201  static void EnableConsoleOnly();
1202 
1205  static void EnableBitmapRendering();
1206 
1211  static bool IsBitmapRendering();
1212 
1214 
1221  static void EnableEventTestingMode();
1222 
1227  static bool IsEventTestingModeEnabled();
1228 
1230  static void EnableSafeMode();
1231 
1233  static bool IsSafeModeEnabled();
1234 
1236 
1241  static const OUString& GetDesktopEnvironment();
1242 
1243  /*** @name Platform Functionality
1244  */
1246 
1260  static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1261 
1262  /*** Show a native error messagebox
1263 
1264  @param sTitle Title of error messagebox
1265 
1266  @param sMessage Message displayed in messagebox
1267  */
1268  static void ShowNativeErrorBox(const OUString& sTitle ,
1269  const OUString& sMessage);
1270 
1272  static void UpdateMainThread();
1273 
1278  static bool hasNativeFileSelection();
1279 
1287  static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1288  createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1289 
1297  static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1298  createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1299 
1302  static void EndAllDialogs();
1303 
1306  static void EndAllPopups();
1307 
1309 
1319  static void LockFontUpdates(bool bLock);
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);
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 private:
1334  DECL_STATIC_LINK( Application, PostEventHandler, void*, void );
1335 };
1336 
1338  : public osl::Guard<comphelper::SolarMutex>
1339 {
1340 public:
1342  : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1343 };
1344 
1346  : public osl::ClearableGuard<comphelper::SolarMutex>
1347 {
1348 public:
1350  : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1351 };
1352 
1354  : public osl::ResettableGuard<comphelper::SolarMutex>
1355 {
1356 public:
1358  : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1359 };
1360 
1361 namespace vcl
1362 {
1363 
1367 {
1368 private:
1370 #ifdef DBG_UTIL
1372 #endif
1374 
1377 
1378 public:
1379 
1381  : m_isAcquired(false)
1382 #ifdef DBG_UTIL
1383  , m_isChecked(false)
1384 #endif
1385  , m_rSolarMutex(Application::GetSolarMutex())
1386 
1387  {
1388  m_isAcquired = m_rSolarMutex.tryToAcquire();
1389  }
1390 
1392  {
1393 #ifdef DBG_UTIL
1394  assert(m_isChecked);
1395 #endif
1396  if (m_isAcquired)
1397  m_rSolarMutex.release();
1398  }
1399 
1400  bool isAcquired()
1401  {
1402 #ifdef DBG_UTIL
1403  m_isChecked = true;
1404 #endif
1405  return m_isAcquired;
1406  }
1407 };
1408 
1409 } // namespace vcl
1410 
1416 {
1417  const sal_uInt32 mnReleased;
1418 public:
1419  SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1421 };
1422 
1424 
1425 // returns true if vcl is already initialized
1426 VCL_DLLPUBLIC bool IsVCLInit();
1427 // returns true if vcl successfully initializes or was already initialized
1428 VCL_DLLPUBLIC bool InitVCL();
1429 VCL_DLLPUBLIC void DeInitVCL();
1430 
1432 
1433 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1434 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1436 
1438 struct ImplSVHelpData;
1442 
1444 struct ImplSVWinData;
1448 
1450 {
1452 }
1453 
1454 #endif // _APP_HXX
1455 
1456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< OUString > const & GetStringsData() const
Gets the event's array of strings.
Definition: svapp.hxx:199
Type GetEvent() const
Get the type of event.
Definition: svapp.hxx:172
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:147
VCL_DLLPUBLIC bool IsVCLInit()
Definition: svmain.cxx:271
static void AcquireSolarMutex(sal_uInt32 nCount)
Acquire Solar Mutex(es) for this thread.
Definition: svapp.cxx:541
void Init()
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:196
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:1606
VCL_DLLPUBLIC void SetSVHelpData(ImplSVHelpData *)
Definition: svdata.cxx:450
std::vector< OUString > aData
Definition: svapp.hxx:207
VCL_DLLPUBLIC void JoinMainLoopThread()
Definition: svmain.cxx:668
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:998
An application can be notified of a number of different events:
Definition: svapp.hxx:113
VCL_DLLPUBLIC void DestroySVHelpData(ImplSVHelpData *)
Definition: svdata.cxx:432
VclInputFlags
Definition: inputtypes.hxx:25
ApplicationEvent(Type type)
Explicit constructor for ApplicationEvent.
Definition: svapp.hxx:135
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
Definition: svapp.hxx:1415
int nCount
VclEventId
Definition: vclevent.hxx:37
VclMessageType
Definition: vclenum.hxx:256
VCL_DLLPUBLIC void DestroySVWinData(ImplSVWinData *)
Definition: svdata.cxx:378
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:162
VCL_DLLPUBLIC bool InitVCL()
Definition: svmain.cxx:290
const sal_uInt32 mnReleased
Definition: svapp.hxx:1417
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:1159
VCL_DLLPUBLIC ImplSVHelpData * CreateSVHelpData()
Definition: svdata.cxx:413
SystemWindowFlags
Definition: svapp.hxx:85
sal_uInt16 & nParam
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
VCL_DLLPUBLIC void SetSVWinData(ImplSVWinData *)
Definition: svdata.cxx:383
VCL_DLLPUBLIC sal_UCS4 GetMirroredChar(sal_UCS4)
Definition: sallayout.cxx:131
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:230
VCL_DLLPUBLIC ImplSVWinData * CreateSVWinData()
Definition: svdata.cxx:364
ConversionMode mode
#define VCL_INPUT_ANY
Definition: inputtypes.hxx:39
VCL_DLLPUBLIC void CreateMainLoopThread(oslWorkerFunction pWorker, void *pThreadData)
Definition: svmain.cxx:650
VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar(sal_UCS4, LanguageType)
Definition: sallayout.cxx:137
long(* VCLEventHookProc)(NotifyEvent &rEvt, void *pData)
Definition: svapp.hxx:94
cancel any dialogs by std::abort
QPRO_FUNC_TYPE nType
virtual bool tryToAcquire()
VCL_DLLPUBLIC void DeInitVCL()
Definition: svmain.cxx:412
guard class that uses tryToAcquire() and has isAcquired() to check
Definition: svapp.hxx:1366
OUString const & GetStringData() const
Gets the application event's data string.
Definition: svapp.hxx:184
DialogCancelMode
Definition: svapp.hxx:210
comphelper::SolarMutex & m_rSolarMutex
Definition: svapp.hxx:1373
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
AnyEventRef aEvent
static void EndYield()
Definition: svapp.hxx:1449