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 WorkWindow;
63 class NotifyEvent;
64 class KeyEvent;
65 class MouseEvent;
66 class GestureEvent;
67 struct ImplSVEvent;
68 struct ConvertData;
69 
70 namespace com {
71 namespace sun {
72 namespace star {
73 namespace uno {
74  class XComponentContext;
75 }
76 namespace ui {
77  namespace dialogs {
78  class XFilePicker2;
79  class XFolderPicker2;
80  }
81 }
82 namespace awt {
83  class XToolkit;
84  class XDisplayConnection;
85  class XWindow;
86 }
87 } } }
88 
89 // helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
92 
93 enum class SystemWindowFlags {
94  NOAUTOMODE = 0x0001,
95  DIALOG = 0x0002
96 };
97 namespace o3tl
98 {
99  template<> struct typed_flags<SystemWindowFlags> : is_typed_flags<SystemWindowFlags, 0x03> {};
100 }
101 
102 typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
103 
122 {
123 public:
124  enum class Type {
125  Accept,
126  Appear,
127  Open,
128  OpenHelpUrl,
129  Print,
130  PrivateDoShutdown,
131  QuickStart,
132  ShowDialog,
133  Unaccept
134  };
135 
143  explicit ApplicationEvent(Type type): aEvent(type)
144  {
145  assert(type == Type::Appear || type == Type::PrivateDoShutdown || type == Type::QuickStart);
146  }
147 
155  ApplicationEvent(Type type, OUString const & data): aEvent(type)
156  {
157  assert(
158  type == Type::Accept || type == Type::OpenHelpUrl
159  || type == Type::ShowDialog || type == Type::Unaccept);
160  aData.push_back(data);
161  }
162 
170  ApplicationEvent(Type type, std::vector<OUString> const & data):
171  aEvent(type), aData(data)
172  {
173  assert(type == Type::Open || type == Type::Print);
174  }
175 
180  Type GetEvent() const
181  {
182  return aEvent;
183  }
184 
192  OUString const & GetStringData() const
193  {
194  assert(
195  aEvent == Type::Accept
196  || aEvent == Type::OpenHelpUrl || aEvent == Type::ShowDialog
197  || aEvent == Type::Unaccept);
198  assert(aData.size() == 1);
199  return aData[0];
200  }
201 
207  std::vector<OUString> const & GetStringsData() const
208  {
209  assert(aEvent == Type::Open || aEvent == Type::Print);
210  return aData;
211  }
212 
213 private:
214  Type const aEvent;
215  std::vector<OUString> aData;
216 };
217 
218 enum class DialogCancelMode {
219  Off,
220  Silent,
221  Fatal
222 };
223 
239 {
240 public:
245 
255  Application();
256 
262  virtual ~Application();
263 
271  virtual void Init();
272 
277  virtual void InitFinished();
278 
286  virtual void DeInit();
287 
289 
350  virtual int Main();
351 
356  virtual bool QueryExit();
357 
362 
370  static void NotifyAllWindows( DataChangedEvent& rDCEvt );
371 
373 
381 
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 
446 
453  static void Execute();
454 
460  static void Quit();
461 
477  static bool Reschedule( bool bHandleAllCurrentEvents = false );
478 
487  static void Yield();
488 
494  static void EndYield();
495 
506  static comphelper::SolarMutex& GetSolarMutex();
507 
515  static bool IsMainThread();
516 
527  static sal_uInt32 ReleaseSolarMutex();
528 
537  static void AcquireSolarMutex( sal_uInt32 nCount );
538 
546  static bool IsInMain();
547 
554  static bool IsInExecute();
555 
562  static bool IsInModalMode();
563 
568  static sal_uInt16 GetDispatchLevel();
569 
579  static bool AnyInput( VclInputFlags nType = VCL_INPUT_ANY );
580 
587  static sal_uInt64 GetLastInputInterval();
588 
590 
591  /* Determines if the UI is captured.
592 
593  The UI is considered captured if a system dialog is open (e.g. printer setup),
594  a floating window, menu or toolbox dropdown is open, or a window has been
595  captured by the mouse.
596 
597  @returns true if UI is captured, false if not
598  */
599  static bool IsUICaptured();
600 
607 
623  virtual void OverrideSystemSettings( AllSettings& rSettings );
624 
632  static void MergeSystemSettings( AllSettings& rSettings );
633 
642  static void SetSettings( const AllSettings& rSettings );
643 
652  static const AllSettings& GetSettings();
653 
658  static const LocaleDataWrapper& GetAppLocaleDataWrapper();
659 
661 
667 
669 
678  static void AddEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
679 
686  static void RemoveEventListener( const Link<VclSimpleEvent&,void>& rEventListener );
687 
696  static void AddKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
697 
704  static void RemoveKeyListener( const Link<VclWindowEvent&,bool>& rKeyListener );
705 
713  static void ImplCallEventListenersApplicationDataChanged( void* pData );
714 
721  static void ImplCallEventListeners( VclSimpleEvent& rEvent );
722 
731  static bool HandleKey( VclEventId nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
732 
741  static ImplSVEvent * PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, KeyEvent const * pKeyEvent );
742 
749  static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
750 
751  static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin, GestureEvent const * pGestureEvent);
752 
760  static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
761 
776  static ImplSVEvent * PostUserEvent( const Link<void*,void>& rLink, void* pCaller = nullptr,
777  bool bReferenceLink = false );
778 
783  static void RemoveUserEvent( ImplSVEvent * nUserEvent );
784 
785  /*** Get the DisplayConnection.
786 
787  It is a reference to XDisplayConnection, which allows toolkits to send display
788  events to the application.
789 
790  @returns UNO reference to an object that implements the css:awt:XDisplayConnection
791  interface.
792  */
793  static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
794 
801  virtual void AppEvent( const ApplicationEvent& rAppEvent );
802 
804 
809 
824  static WorkWindow* GetAppWindow();
825 
832  static vcl::Window* GetFocusWindow();
833 
841  static OutputDevice* GetDefaultDevice();
842 
850  static vcl::Window* GetFirstTopLevelWindow();
851 
859  static vcl::Window* GetNextTopLevelWindow( vcl::Window const * pWindow );
860 
869  static long GetTopWindowCount();
870 
883  static vcl::Window* GetTopWindow( long nIndex );
884 
895  static vcl::Window* GetActiveTopWindow();
896 
898 
905  static void SetAppName( const OUString& rUniqueName );
906 
907 
910 
916  static OUString GetAppName();
917 
921  static OUString GetHWOSConfInfo();
922 
930  static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
931 
933 
936 
944  static void SetDisplayName( const OUString& rDisplayName );
945 
950  static OUString GetDisplayName();
951 
956  static OUString GetToolkitName();
957 
964  static unsigned int GetScreenCount();
965 
974  static tools::Rectangle GetScreenPosSizePixel( unsigned int nScreen );
975 
986  static bool IsUnifiedDisplay();
987 
998  SAL_DLLPRIVATE static unsigned int GetBestScreen( const tools::Rectangle& );
999 
1010  static unsigned int GetDisplayBuiltInScreen();
1011 
1019  static unsigned int GetDisplayExternalScreen();
1020 
1022 
1031 
1041  static bool InsertAccel( Accelerator* pAccel );
1042 
1049  static void RemoveAccel( Accelerator const * pAccel );
1050 
1057  static sal_uLong GetReservedKeyCodeCount();
1058 
1067  static const vcl::KeyCode* GetReservedKeyCode( sal_uLong i );
1068 
1070 
1076 
1084  static void SetHelp( Help* pHelp = nullptr );
1085 
1093  static Help* GetHelp();
1094 
1096 
1103 
1116  static vcl::Window* GetDefDialogParent();
1117 
1118 
1125  static DialogCancelMode GetDialogCancelMode();
1126 
1137  static void SetDialogCancelMode( DialogCancelMode mode );
1138 
1145  static bool IsDialogCancelEnabled();
1146 
1147 
1155  static void SetSystemWindowMode( SystemWindowFlags nMode );
1156 
1163  static SystemWindowFlags GetSystemWindowMode();
1164 
1166 
1174 
1182  static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1183 
1185 
1186 
1187  /*** @name Graphic Filters
1188  */
1190 
1197  static void SetFilterHdl( const Link<ConvertData&,bool>& rLink );
1198 
1200 
1208  static void EnableHeadlessMode( bool dialogsAreFatal );
1209 
1214  static bool IsHeadlessModeEnabled();
1215 
1220  static void EnableConsoleOnly();
1221 
1224  static void EnableBitmapRendering();
1225 
1230  static bool IsBitmapRendering();
1231 
1233 
1240  static void EnableEventTestingMode();
1241 
1246  static bool IsEventTestingModeEnabled();
1247 
1249  static void EnableSafeMode();
1250 
1252  static bool IsSafeModeEnabled();
1253 
1255 
1260  static const OUString& GetDesktopEnvironment();
1261 
1262  /*** @name Platform Functionality
1263  */
1265 
1279  static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1280 
1281  /*** Show a native error messagebox
1282 
1283  @param sTitle Title of error messagebox
1284 
1285  @param sMessage Message displayed in messagebox
1286  */
1287  static void ShowNativeErrorBox(const OUString& sTitle ,
1288  const OUString& sMessage);
1289 
1291  static void UpdateMainThread();
1292 
1297  static bool hasNativeFileSelection();
1298 
1306  static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1307  createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1308 
1316  static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1317  createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1318 
1321  static void EndAllDialogs();
1322 
1325  static void EndAllPopups();
1326 
1328 
1338  static void LockFontUpdates(bool bLock);
1339 
1340  // For vclbootstrapprotector:
1341  static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
1342 
1343  static weld::Builder* CreateBuilder(weld::Widget* pParent, const OUString &rUIFile);
1344  static weld::Builder* CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile); //for the duration of same SfxTabPages in mixed parent types
1345  static weld::Builder* CreateInterimBuilder(weld::Widget* pParent, const OUString &rUIFile); //for the duration of same SfxTabPages in mixed parent types
1346 
1347  static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1348  VclButtonsType eButtonType, const OUString& rPrimaryMessage);
1349 
1350  static weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
1351 private:
1352  DECL_STATIC_LINK( Application, PostEventHandler, void*, void );
1353 };
1354 
1356  : public osl::Guard<comphelper::SolarMutex>
1357 {
1358 public:
1360  : osl::Guard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1361 };
1362 
1364  : public osl::ClearableGuard<comphelper::SolarMutex>
1365 {
1366 public:
1368  : osl::ClearableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1369 };
1370 
1372  : public osl::ResettableGuard<comphelper::SolarMutex>
1373 {
1374 public:
1376  : osl::ResettableGuard<comphelper::SolarMutex>( Application::GetSolarMutex() ) {}
1377 };
1378 
1379 namespace vcl
1380 {
1381 
1385 {
1386 private:
1388 #ifdef DBG_UTIL
1390 #endif
1392 
1395 
1396 public:
1397 
1399  : m_isAcquired(false)
1400 #ifdef DBG_UTIL
1401  , m_isChecked(false)
1402 #endif
1403  , m_rSolarMutex(Application::GetSolarMutex())
1404 
1405  {
1406  m_isAcquired = m_rSolarMutex.tryToAcquire();
1407  }
1408 
1410  {
1411 #ifdef DBG_UTIL
1412  assert(m_isChecked);
1413 #endif
1414  if (m_isAcquired)
1415  m_rSolarMutex.release();
1416  }
1417 
1418  bool isAcquired()
1419  {
1420 #ifdef DBG_UTIL
1421  m_isChecked = true;
1422 #endif
1423  return m_isAcquired;
1424  }
1425 };
1426 
1427 } // namespace vcl
1428 
1434 {
1435  const sal_uInt32 mnReleased;
1436 public:
1437  SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1439 };
1440 
1442 
1443 // returns true if vcl is already initialized
1444 VCL_DLLPUBLIC bool IsVCLInit();
1445 // returns true if vcl successfully initializes or was already initialized
1446 VCL_DLLPUBLIC bool InitVCL();
1447 VCL_DLLPUBLIC void DeInitVCL();
1448 
1450 
1451 // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1452 VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1454 
1456 {
1458 }
1459 
1460 #endif // _APP_HXX
1461 
1462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< OUString > const & GetStringsData() const
Gets the event's array of strings.
Definition: svapp.hxx:207
Type GetEvent() const
Get the type of event.
Definition: svapp.hxx:180
def Print(s)
OUString sMessage
ApplicationEvent(Type type, OUString const &data)
Constructor for ApplicationEvent, accepts a string for the data associated with the event...
Definition: svapp.hxx:155
VCL_DLLPUBLIC bool IsVCLInit()
Definition: svmain.cxx:264
static void AcquireSolarMutex(sal_uInt32 nCount)
Acquire Solar Mutex(es) for this thread.
Definition: svapp.cxx:539
void Init()
const char aData[]
VclButtonsType
Definition: vclenum.hxx:243
Definition: help.hxx:60
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
VCL_DLLPUBLIC bool InitAccessBridge()
Definition: svapp.cxx:1571
sal_uIntPtr sal_uLong
std::vector< OUString > aData
Definition: svapp.hxx:215
VCL_DLLPUBLIC void JoinMainLoopThread()
Definition: svmain.cxx:643
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:996
An application can be notified of a number of different events:
Definition: svapp.hxx:121
VclInputFlags
Definition: inputtypes.hxx:25
ApplicationEvent(Type type)
Explicit constructor for ApplicationEvent.
Definition: svapp.hxx:143
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
Definition: svapp.hxx:1433
VclEventId
Definition: vclevent.hxx:41
VclMessageType
Definition: vclenum.hxx:253
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:170
VCL_DLLPUBLIC bool InitVCL()
Definition: svmain.cxx:283
const sal_uInt32 mnReleased
Definition: svapp.hxx:1435
SolarMutexTryAndBuyGuard & operator=(const SolarMutexTryAndBuyGuard &)=delete
VCL_DLLPUBLIC Application * GetpApp()
Definition: svapp.cxx:147
silently cancel any dialogs
SystemWindowFlags
Definition: svapp.hxx:93
int i
QPRO_FUNC_TYPE const nType
sal_uInt16 & nParam
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
VCL_DLLPUBLIC sal_UCS4 GetMirroredChar(sal_UCS4)
Definition: sallayout.cxx:131
sal_uInt16 sal_Char * pName
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:238
#define VCL_INPUT_ANY
Definition: inputtypes.hxx:39
VCL_DLLPUBLIC void CreateMainLoopThread(oslWorkerFunction pWorker, void *pThreadData)
Definition: svmain.cxx:625
VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar(sal_UCS4, LanguageType)
Definition: sallayout.cxx:137
Type const aEvent
Definition: svapp.hxx:214
long(* VCLEventHookProc)(NotifyEvent &rEvt, void *pData)
Definition: svapp.hxx:102
cancel any dialogs by std::abort
virtual bool tryToAcquire()
sal_uInt32 sal_UCS4
Definition: fontcharmap.hxx:29
VCL_DLLPUBLIC void DeInitVCL()
Definition: svmain.cxx:405
guard class that uses tryToAcquire() and has isAcquired() to check
Definition: svapp.hxx:1384
OUString const & GetStringData() const
Gets the application event's data string.
Definition: svapp.hxx:192
DialogCancelMode
Definition: svapp.hxx:218
comphelper::SolarMutex & m_rSolarMutex
Definition: svapp.hxx:1391
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
static void EndYield()
Definition: svapp.hxx:1455