4#include "Stroika/Frameworks/StroikaPreComp.h"
8#include "Stroika/Frameworks/Led/IdleManager.h"
16namespace Stroika::Frameworks::Led::Platform {
19 IdleMangerLinkerSupport::IdleMangerLinkerSupport ()
31 class IdleManagerOSImpl_Win32 :
public IdleManager::IdleManagerOSImpl {
33 IdleManagerOSImpl_Win32 ();
34 ~IdleManagerOSImpl_Win32 ();
37 virtual void StartSpendTimeCalls ()
override;
38 virtual void TerminateSpendTimeCalls ()
override;
43 nonvirtual
void OnTimer_Msg (UINT_PTR nEventID, TIMERPROC* proc);
46 nonvirtual
void CheckAndCreateIdleWnd ();
49 static LRESULT CALLBACK StaticWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
64 struct IdleMangerSetter {
67 IdleManager::SetIdleManagerOSImpl (&fIdleManagerOSImpl);
71 IdleManager::SetIdleManagerOSImpl (NULL);
73 IdleManagerOSImpl_Win32 fIdleManagerOSImpl;
75 struct IdleMangerSetter sIdleMangerSetter;
83 FunnyMSPageUpDownAdjustSelectionHelper::FunnyMSPageUpDownAdjustSelectionHelper ()
88 void FunnyMSPageUpDownAdjustSelectionHelper::CaptureInfo (TextInteractor& ti)
90 size_t pinPoint = ti.GetSelectionStart ();
91 ptrdiff_t rowNum = ti.CalculateRowDeltaFromCharDeltaFromTopOfWindow (
long (pinPoint) -
long (ti.GetMarkerPositionOfStartOfWindow ()));
92 fRowNum = ::abs (rowNum);
95 void FunnyMSPageUpDownAdjustSelectionHelper::CompleteAdjustment (TextInteractor& ti)
98 size_t totalRowsInWindow = ti.GetTotalRowsInWindow ();
99 Assert (totalRowsInWindow >= 1);
100 fRowNum = min (fRowNum, totalRowsInWindow - 1);
102 size_t newRowStart = ti.CalculateCharDeltaFromRowDeltaFromTopOfWindow (fRowNum) + ti.GetMarkerPositionOfStartOfWindow ();
103 size_t newRowEnd = ti.GetEndOfRowContainingPosition (newRowStart);
104 Assert (newRowEnd >= newRowStart);
106 TextImager::GoalColumnRecomputerControlContext skipRecompute (ti,
true);
108 size_t newSelStart = ti.GetRowRelativeCharAtLoc (TextImager::Tablet_Acquirer (&ti)->CvtFromTWIPSH (ti.GetSelectionGoalColumn ()), newRowStart);
110 newSelStart = min (newSelStart, newRowEnd);
113 ti.SetSelection (newSelStart, newSelStart);
126 void SimpleWin32WndProcHelper::Create (DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle,
int x,
int y,
127 int nWidth,
int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance)
130 if (lpClassName == NULL) {
131 tmpClassName = Characters::CString::Format (_T(
"LED_SimpleWin32WndProcHelper-%d-%p"), ::GetCurrentProcessId (), &StaticWndProc);
132 lpClassName = tmpClassName.c_str ();
134 static bool sRegistered =
false;
135 if (not sRegistered) {
137 memset (&wcex, 0,
sizeof (wcex));
138 wcex.cbSize =
sizeof (WNDCLASSEX);
139 wcex.lpfnWndProc = (WNDPROC)StaticWndProc;
140 wcex.lpszClassName = lpClassName;
141 ATOM regResult = ::RegisterClassEx (&wcex);
142 if (regResult == 0) {
143 DWORD laserErr = ::GetLastError ();
144 if (laserErr == ERROR_CLASS_ALREADY_EXISTS) {
155 [[maybe_unused]] HWND hWnd =
156 ::CreateWindowEx (dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance,
this);
157 Assert (hWnd == GetValidatedHWND ());
160 LRESULT CALLBACK SimpleWin32WndProcHelper::StaticWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
162 if (message == WM_CREATE) {
163 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
165 SimpleWin32WndProcHelper* pThis =
reinterpret_cast<SimpleWin32WndProcHelper*
> (lpcs->lpCreateParams);
166 Assert (pThis->GetHWND () == NULL);
167 pThis->SetHWND (hWnd);
170 SimpleWin32WndProcHelper* pThis =
reinterpret_cast<SimpleWin32WndProcHelper*
> (::GetWindowLongPtr (hWnd, GWLP_USERDATA));
177 Assert (message == WM_GETMINMAXINFO or message == WM_NCCREATE or message == WM_NCCALCSIZE);
178 return ::DefWindowProc (hWnd, message, wParam, lParam);
181 Assert (pThis != NULL);
182 Assert (pThis->GetHWND () == hWnd);
183 return pThis->WndProc (message, wParam, lParam);
191 IdleManagerOSImpl_Win32::IdleManagerOSImpl_Win32 ()
193 , fSuggestedFrequency (0)
198 IdleManagerOSImpl_Win32::~IdleManagerOSImpl_Win32 ()
200 if (fIdleWnd != NULL) {
201 ::DestroyWindow (fIdleWnd);
205 void IdleManagerOSImpl_Win32::StartSpendTimeCalls ()
207 CheckAndCreateIdleWnd ();
211 int timeout =
static_cast<int> (fSuggestedFrequency.count () * 1000);
212 Verify ((fTimerID = ::SetTimer (fIdleWnd, eTimerEventID, timeout, NULL)) != 0);
216 void IdleManagerOSImpl_Win32::TerminateSpendTimeCalls ()
220 Verify (::KillTimer (fIdleWnd, eTimerEventID));
227 return fSuggestedFrequency;
232 if (fSuggestedFrequency != suggestedFrequency) {
233 fSuggestedFrequency = suggestedFrequency;
235 TerminateSpendTimeCalls ();
236 StartSpendTimeCalls ();
241 LRESULT CALLBACK IdleManagerOSImpl_Win32::StaticWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
243 if (message == WM_CREATE) {
244 LPCREATESTRUCT lpcs =
reinterpret_cast<LPCREATESTRUCT
> (lParam);
246 IdleManagerOSImpl_Win32* pThis =
reinterpret_cast<IdleManagerOSImpl_Win32*
> (lpcs->lpCreateParams);
247 ::SetWindowLongPtr (hWnd, GWLP_USERDATA,
reinterpret_cast<DWORD_PTR
> (pThis));
250 IdleManagerOSImpl_Win32* pThis =
reinterpret_cast<IdleManagerOSImpl_Win32*
> (::GetWindowLongPtr (hWnd, GWLP_USERDATA));
253 return ::DefWindowProc (hWnd, message, wParam, lParam);
256 Assert (pThis != NULL);
259 pThis->OnTimer_Msg (wParam,
reinterpret_cast<TIMERPROC*
> (lParam));
262 return ::DefWindowProc (hWnd, message, wParam, lParam);
265 void IdleManagerOSImpl_Win32::OnTimer_Msg (UINT_PTR , TIMERPROC* )
272 if (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE | PM_QS_INPUT | PM_QS_PAINT) == 0) {
277 void IdleManagerOSImpl_Win32::CheckAndCreateIdleWnd ()
279 if (fIdleWnd == NULL) {
281 SDKString className = Characters::CString::Format (Led_SDK_TCHAROF (
"Led::IdleManagerOSImpl_Win32 (%p)"), &StaticWndProc);
283 if (sRegisteredClassName != className) {
285 memset (&wcex, 0,
sizeof (wcex));
286 wcex.cbSize =
sizeof (WNDCLASSEX);
287 wcex.lpfnWndProc = (WNDPROC)StaticWndProc;
288 wcex.lpszClassName = className.c_str ();
289 ATOM regResult = ::RegisterClassEx (&wcex);
290 if (regResult == 0) {
291 DWORD x = ::GetLastError ();
292 if (x == ERROR_CLASS_ALREADY_EXISTS) {
299 sRegisteredClassName = className;
301 fIdleWnd = ::CreateWindowEx (0, className.c_str (), _T(
""), 0, 0, 0, 1, 1, NULL, NULL, NULL,
this);
#define CompileTimeFlagChecker_SOURCE(NS_PREFIX, NAME, VALUE)
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
basic_string< SDKChar > SDKString