diff --git a/README.md b/README.md index 6f90fea5..8815ff6a 100644 --- a/README.md +++ b/README.md @@ -384,6 +384,7 @@ The following are new features not available in Borland's release of Turbo Visio * Many functions which originally had null-terminated string parameters now receive `TStringView` instead. `TStringView` is compatible with `std::string_view`, `std::string` and `const char *` (even `nullptr`). * New class `TSpan`, inspired by `std::span`. * New classes `TDrawSurface` and `TSurfaceView`, see ``. +* The system integration subsystems (`THardwareInfo`, `TScreen`, `TEventQueue`...) are now initialized when constructing a `TApplication` for the first time, rather than before `main`. They are still destroyed on exit from `main`. * New method `TVMemMgr::reallocateDiscardable()` which can be used along `allocateDiscardable` and `freeDiscardable`. * New method `TView::textEvent()` which allows receiving text in an efficient manner, see [Clipboard interaction](#clipboard). * New class `TClipboard`, see [Clipboard interaction](#clipboard). diff --git a/include/tvision/app.h b/include/tvision/app.h index 448385ff..cb2d40d3 100644 --- a/include/tvision/app.h +++ b/include/tvision/app.h @@ -310,7 +310,16 @@ class TProgram : public TGroup, public virtual TProgInit #if defined( Uses_TApplication ) && !defined( __TApplication ) #define __TApplication -class TApplication : public TProgram +class TSubsystemsInit +{ + +public: + + TSubsystemsInit() noexcept; + +}; + +class TApplication : public virtual TSubsystemsInit, public TProgram { protected: diff --git a/include/tvision/system.h b/include/tvision/system.h index b4952854..71a65bbe 100644 --- a/include/tvision/system.h +++ b/include/tvision/system.h @@ -274,7 +274,6 @@ class TEventQueue private: - static TMouse _NEAR mouse; static Boolean getMouseState( TEvent& ) noexcept; static Boolean getPasteEvent( TEvent& ) noexcept; static void getKeyOrPasteEvent( TEvent& ) noexcept; diff --git a/source/tvision/tapplica.cpp b/source/tvision/tapplica.cpp index f2ed71e3..aaa8696a 100644 --- a/source/tvision/tapplica.cpp +++ b/source/tvision/tapplica.cpp @@ -17,7 +17,6 @@ #define Uses_THardwareInfo #define Uses_TScreen #define Uses_TObject -#define Uses_TMouse #define Uses_TApplication #define Uses_TDeskTop #include @@ -26,15 +25,18 @@ #include #include -static THardwareInfo hwInfoManager; -TMouse _NEAR TEventQueue::mouse; -static TScreen tsc; -static TEventQueue teq; -static TSystemError sysErr; - void initHistory(); void doneHistory(); +TSubsystemsInit::TSubsystemsInit() noexcept +{ + static THardwareInfo hwInfoManager; + static TMouse tms; + static TScreen tsc; + static TEventQueue teq; + static TSystemError sysErr; +} + TApplication::TApplication() noexcept : TProgInit( &TApplication::initStatusLine, &TApplication::initMenuBar, diff --git a/source/tvision/tevent.cpp b/source/tvision/tevent.cpp index a9d54a34..b7f7a4bb 100644 --- a/source/tvision/tevent.cpp +++ b/source/tvision/tevent.cpp @@ -74,18 +74,18 @@ TEventQueue::TEventQueue() noexcept void TEventQueue::resume() noexcept { - if( mouse.present() == False ) - mouse.resume(); - if( mouse.present() == False ) + if( TMouse::present() == False ) + TMouse::resume(); + if( TMouse::present() == False ) return; - mouse.getEvent( curMouse ); + TMouse::getEvent( curMouse ); lastMouse = curMouse; #if defined( __FLAT__ ) THardwareInfo::clearPendingEvent(); #else - mouse.registerHandler( 0xFFFF, (void (_FAR *)()) mouseInt ); + TMouse::registerHandler( 0xFFFF, (void (_FAR *)()) mouseInt ); #endif mouseEvents = True; @@ -95,7 +95,7 @@ void TEventQueue::resume() noexcept void TEventQueue::suspend() noexcept { - mouse.suspend(); + TMouse::suspend(); } TEventQueue::~TEventQueue() diff --git a/source/tvision/tprogram.cpp b/source/tvision/tprogram.cpp index 830f3937..507ab71b 100644 --- a/source/tvision/tprogram.cpp +++ b/source/tvision/tprogram.cpp @@ -316,7 +316,7 @@ void TProgram::setScreenMode( ushort mode ) { TRect r; - TEventQueue::mouse.hide(); //HideMouse(); + TMouse::hide(); TScreen::setVideoMode( mode ); initScreen(); buffer = TScreen::screenBuffer; @@ -325,7 +325,7 @@ void TProgram::setScreenMode( ushort mode ) setState(sfExposed, False); setState(sfExposed, True); redraw(); - TEventQueue::mouse.show(); //ShowMouse(); + TMouse::show(); } TTimerId TProgram::setTimer( uint timeoutMs, int periodMs )