diff --git a/src/common/winlib.cpp b/src/common/winlib.cpp index d3e161c01..f4a6ff630 100644 --- a/src/common/winlib.cpp +++ b/src/common/winlib.cpp @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: 2023 Open Salamander Authors // SPDX-License-Identifier: GPL-2.0-or-later +// CommentsTranslationProject: TRANSLATED #include "precomp.h" @@ -8,7 +9,7 @@ #include #include #include -#include // potrebuju LPCOLORMAP +#include // LPCOLORMAP needed #include #if defined(_DEBUG) && defined(_MSC_VER) // without passing file+line to 'new' operator, list of memory leaks shows only 'crtdbg.h(552)' @@ -25,23 +26,23 @@ #include "winlib.h" -// opatreni proti runtime check failure v debug verzi: puvodni verze makra pretypovava rgb na WORD, -// takze hlasi ztratu dat (RED slozky) +// precaution against runtime check failure in debug version: original version of macro casts rgb to WORD, +// so it reports data loss (RED component) #undef GetGValue #define GetGValue(rgb) ((BYTE)(((rgb) >> 8) & 0xFF)) const TCHAR* CWINDOW_CLASSNAME = _T("WinLib Universal Window"); -const TCHAR* CWINDOW_CLASSNAME2 = _T("WinLib Universal Window2"); // nema CS_VREDRAW | CS_HREDRAW +const TCHAR* CWINDOW_CLASSNAME2 = _T("WinLib Universal Window2"); // doesn't have CS_VREDRAW | CS_HREDRAW #ifndef _UNICODE const WCHAR* CWINDOW_CLASSNAMEW = L"WinLib Universal Window Unicode"; -const WCHAR* CWINDOW_CLASSNAME2W = L"WinLib Universal Window Unicode2"; // nema CS_VREDRAW | CS_HREDRAW +const WCHAR* CWINDOW_CLASSNAME2W = L"WinLib Universal Window Unicode2"; // doesn't have CS_VREDRAW | CS_HREDRAW #endif // _UNICODE CWinLibHelp* WinLibHelp = NULL; CWindowsManager WindowsManager; HINSTANCE HInstance = NULL; -BOOL WinLibReleased = FALSE; // TRUE = uz se volalo ReleaseWinLib() +BOOL WinLibReleased = FALSE; // TRUE = ReleaseWinLib() was called TCHAR WinLibStrings[WLS_COUNT][101] = { _T("Invalid number!"), @@ -71,7 +72,7 @@ BOOL InitializeWinLib() void ReleaseWinLib() { - // musime odpojit otevrena okna od WinLibu, protoze WinLib konci ... + // the opened windows must be disconnected from WinLib because WinLib ends ... int c = WindowsManager.GetCount(); if (c > 0) TRACE_ET(_T("ReleaseWinLib(): WindowsManager still contains opened windows: ") << c); @@ -102,7 +103,7 @@ BOOL WinLibIsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WOR VER_MINORVERSION, VER_GREATER_EQUAL), VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); - SecureZeroMemory(&osvi, sizeof(osvi)); // nahrada za memset (nevyzaduje RTLko) + SecureZeroMemory(&osvi, sizeof(osvi)); // replacement for memset (does not require RTL) osvi.dwOSVersionInfoSize = sizeof(osvi); osvi.dwMajorVersion = wMajorVersion; osvi.dwMinorVersion = wMinorVersion; @@ -114,8 +115,8 @@ BOOL WinLibIsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WOR // **************************************************************************** // CWindow // -// lpvParam - v pripade, ze se pri CreateWindow zavola CWindow::CWindowProc -// (je v tride okna), musi obsahovat adresu objektu vytvareneho okna +// lpvParam - in case of CreateWindow calling CWindow::CWindowProc (it is in window class), +// it must contain address of object of created window HWND CWindow::CreateEx(DWORD dwExStyle, // extended window style LPCTSTR lpszClassName, // address of registered class name @@ -128,7 +129,7 @@ HWND CWindow::CreateEx(DWORD dwExStyle, // extended window style HWND hwndParent, // handle of parent or owner window HMENU hmenu, // handle of menu or child-window identifier HINSTANCE hinst, // handle of application instance - LPVOID lpvParam) // ukazatel na objekt vytvareneho okna + LPVOID lpvParam) // pointer to object of created window { HWND hWnd = CreateWindowEx(dwExStyle, lpszClassName, @@ -144,8 +145,8 @@ HWND CWindow::CreateEx(DWORD dwExStyle, // extended window style lpvParam); if (hWnd != 0) { - if (WindowsManager.GetWindowPtr(hWnd) == NULL) // pokud se jeste neni ve WindowsManageru - AttachToWindow(hWnd); // tak ho pridame -> subclassing + if (WindowsManager.GetWindowPtr(hWnd) == NULL) // if it is not in WindowsManager yet + AttachToWindow(hWnd); // then add it -> subclassing } return hWnd; } @@ -160,7 +161,7 @@ HWND CWindow::Create(LPCTSTR lpszClassName, // address of registered class name HWND hwndParent, // handle of parent or owner window HMENU hmenu, // handle of menu or child-window identifier HINSTANCE hinst, // handle of application instance - LPVOID lpvParam) // ukazatel na objekt vytvareneho okna + LPVOID lpvParam) // pointer to object of created window { return CreateEx(0, lpszClassName, @@ -189,7 +190,7 @@ HWND CWindow::CreateExW(DWORD dwExStyle, // extended window style HWND hwndParent, // handle of parent or owner window HMENU hmenu, // handle of menu or child-window identifier HINSTANCE hinst, // handle of application instance - LPVOID lpvParam) // ukazatel na objekt vytvareneho okna + LPVOID lpvParam) // pointer to object of created window { HWND hWnd = CreateWindowExW(dwExStyle, lpszClassName, @@ -205,8 +206,8 @@ HWND CWindow::CreateExW(DWORD dwExStyle, // extended window style lpvParam); if (hWnd != 0) { - if (WindowsManager.GetWindowPtr(hWnd) == NULL) // pokud se jeste neni ve WindowsManageru - AttachToWindow(hWnd); // tak ho pridame -> subclassing + if (WindowsManager.GetWindowPtr(hWnd) == NULL) // if it is not in WindowsManager yet + AttachToWindow(hWnd); // then add it -> subclassing } return hWnd; } @@ -221,7 +222,7 @@ HWND CWindow::CreateW(LPCWSTR lpszClassName, // address of registered class nam HWND hwndParent, // handle of parent or owner window HMENU hmenu, // handle of menu or child-window identifier HINSTANCE hinst, // handle of application instance - LPVOID lpvParam) // ukazatel na objekt vytvareneho okna + LPVOID lpvParam) // pointer to object of created window { return CreateExW(0, lpszClassName, @@ -275,7 +276,7 @@ void CWindow::AttachToWindow(HWND hWnd) #ifndef _UNICODE || DefWndProc == CWindow::CWindowProcW #endif // _UNICODE - ) // to by byla rekurze + ) // this would be recursion { TRACE_CT(_T("This should never happen.")); DefWndProc = GetDefWindowProc(); @@ -328,8 +329,8 @@ CWindow::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) return TRUE; } if (GetWindowLongPtr(HWindow, GWL_STYLE) & WS_CHILD) - break; // pokud F1 nezpracujeme a pokud je to child okno, nechame F1 propadnout do parenta - return TRUE; // pokud to neni child, ukoncime zpracovani F1 + break; // if F1 was not handled and it is child window, let F1 go to parent + return TRUE; // if it is not child, let's finish processing F1 } } #ifndef _UNICODE @@ -363,11 +364,11 @@ CWindow::CWindowProcInt(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL CWindow* wnd; switch (uMsg) { - case WM_CREATE: // prvni zprava - pripojeni objektu k oknu + case WM_CREATE: // the first message - attaching object to window { - // osetrim MDI_CHILD_WINDOW - if (((CREATESTRUCT*)lParam)->dwExStyle & WS_EX_MDICHILD) // CREATESTRUCTA a CREATESTRUCTW se pro dwExStyle ani lpCreateParams nelisi - wnd = (CWindow*)((MDICREATESTRUCT*)((CREATESTRUCT*)lParam)->lpCreateParams)->lParam; // MDICREATESTRUCTA a MDICREATESTRUCTW se pro lParam nelisi + // handling MDI_CHILD_WINDOW + if (((CREATESTRUCT*)lParam)->dwExStyle & WS_EX_MDICHILD) // CREATESTRUCTA and CREATESTRUCTW do not differ for dwExStyle and lpCreateParams + wnd = (CWindow*)((MDICREATESTRUCT*)((CREATESTRUCT*)lParam)->lpCreateParams)->lParam; // MDICREATESTRUCTA and MDICREATESTRUCTW do not differ for lParam else wnd = (CWindow*)((CREATESTRUCT*)lParam)->lpCreateParams; if (wnd == NULL) @@ -382,8 +383,8 @@ CWindow::CWindowProcInt(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL if (wnd->UnicodeWnd != unicode) TRACE_C("Incompatible windows procedure."); #endif // _UNICODE - //--- zarazeni okna podle hwnd do seznamu oken - if (!WindowsManager.AddWindow(hwnd, wnd)) // chyba + //--- adding window to the list of windows per hwnd + if (!WindowsManager.AddWindow(hwnd, wnd)) // error { TRACE_ET(_T("Unable to create window.")); return FALSE; @@ -392,7 +393,7 @@ CWindow::CWindowProcInt(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL break; } - case WM_DESTROY: // posledni zprava - odpojeni objektu od okna + case WM_DESTROY: // the last meesage - detaching object from window { wnd = (CWindow*)WindowsManager.GetWindowPtr(hwnd); #ifndef _UNICODE @@ -401,23 +402,23 @@ CWindow::CWindowProcInt(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL #endif // _UNICODE if (wnd != NULL && wnd->Is(otWindow)) { - // Petr: posunul jsem dolu pod wnd->WindowProc(), aby behem WM_DESTROY - // jeste dochazely zpravy (potreboval Lukas) + // Petr: I moved this down below wnd->WindowProc() so that during WM_DESTROY + // messages are still received (Lukas needed this) // WindowsManager.DetachWindow(hwnd); LRESULT res = wnd->WindowProc(uMsg, wParam, lParam); - // ted uz zase do stare procedury (kvuli subclassingu) + // and now into the old procedure again (because of subclassing) WindowsManager.DetachWindow(hwnd); - // pokud aktualni WndProc je jina nez nase, nebudeme ji menit, - // protoze nekdo v rade subclasseni uz vratil puvodni WndProc + // if the current WndProc is different than ours, we will not change it + // because someone in the subclassing chain has already returned the original WndProc #ifdef _UNICODE WNDPROC currentWndProc = (WNDPROC)GetWindowLongPtr(wnd->HWindow, GWLP_WNDPROC); if (currentWndProc == CWindow::CWindowProc) SetWindowLongPtr(wnd->HWindow, GWLP_WNDPROC, (LONG_PTR)wnd->DefWndProc); #else _UNICODE - if (wnd->UnicodeWnd) // je-li nase window procedura unicodova, musime pouzit "W" varianty API funkci + if (wnd->UnicodeWnd) // if our window procedure is unicode, we must use "W" variants of API functions { WNDPROC currentWndProc = (WNDPROC)GetWindowLongPtrW(wnd->HWindow, GWLP_WNDPROC); if (currentWndProc == CWindow::CWindowProcW || currentWndProc == CWindow::CWindowProc) @@ -434,9 +435,9 @@ CWindow::CWindowProcInt(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL if (wnd->IsAllocated()) delete wnd; else - wnd->HWindow = NULL; // uz neni pripojeny + wnd->HWindow = NULL; // is not attached anymore if (res == 0) - return 0; // aplikace ji zpracovala + return 0; // application has processed it wnd = NULL; } break; @@ -458,11 +459,11 @@ CWindow::CWindowProcInt(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL #endif // _UNICODE } } - //--- zavolani metody WindowProc(...) prislusneho objektu okna + //--- calling method WindowProc(...) of the object of window LRESULT lResult; if (wnd != NULL) lResult = wnd->WindowProc(uMsg, wParam, lParam); - else // chyba nebo message prisla pred WM_CREATE + else // error or message came before WM_CREATE { #ifndef _UNICODE lResult = unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) : DefWindowProcA(hwnd, uMsg, wParam, lParam); @@ -639,7 +640,7 @@ CDialog::DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG: { TransferData(ttDataToWindow); - return TRUE; // chci focus od DefDlgProc + return TRUE; // focus from DefDlgProc needed } case WM_HELP: @@ -650,7 +651,7 @@ CDialog::DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam) (GetKeyState(VK_CONTROL) & 0x8000) != 0, (GetKeyState(VK_SHIFT) & 0x8000) != 0); } - return TRUE; // F1 nenechame propadnout do parenta ani pokud nevolame WinLibHelp->OnHelp() + return TRUE; // let's not F1 be passed to parent, even if we don't call WinLibHelp->OnHelp() } case WM_CONTEXTMENU: @@ -672,7 +673,7 @@ CDialog::DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam) memset(&hi, 0, sizeof(hi)); hi.cbSize = sizeof(hi); hi.iContextType = HELPINFO_WINDOW; - hi.dwContextId = ResID; // ve WM_HELP taky chodi ResID a ne HelpID, tak at je to konzistentni + hi.dwContextId = ResID; // in WM_HELP ResID is used instead of HelpID, so let it be consistent GetCursorPos(&hi.MousePos); WinLibHelp->OnHelp(HWindow, HelpID, &hi, FALSE, FALSE); } @@ -706,7 +707,7 @@ CDialog::CDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) CDialog* dlg; switch (uMsg) { - case WM_INITDIALOG: // prvni zprava - pripojeni objektu k dialogu + case WM_INITDIALOG: // the first message - attaching object to dialog { dlg = (CDialog*)lParam; if (dlg == NULL) @@ -717,25 +718,25 @@ CDialog::CDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) else { dlg->HWindow = hwndDlg; - //--- zarazeni okna podle hwndDlg do seznamu oken - if (!WindowsManager.AddWindow(hwndDlg, dlg)) // chyba + //--- adding window to the list of windows per hwnd + if (!WindowsManager.AddWindow(hwndDlg, dlg)) // error { TRACE_ET(_T("Unable to create dialog.")); return TRUE; } - dlg->NotifDlgJustCreated(); // zavedeno jako misto pro upravu layoutu dialogu + dlg->NotifDlgJustCreated(); // loaded as a place for layout modification of the dialog } break; } - case WM_DESTROY: // posledni zprava - odpojeni objektu od dialogu + case WM_DESTROY: // the last message - detaching object from dialog { dlg = (CDialog*)WindowsManager.GetWindowPtr(hwndDlg); - INT_PTR ret = FALSE; // pro pripad, ze ji nezpracuje + INT_PTR ret = FALSE; // in case it is not processed if (dlg != NULL && dlg->Is(otDialog)) { - // Petr: posunul jsem dolu pod dlg->DialogProc(), aby behem WM_DESTROY - // jeste dochazely zpravy (potreboval Lukas) + // Petr: I moved this down below dlg->DialogProc() so that during WM_DESTROY + // messages are still received (Lukas needed this) // WindowsManager.DetachWindow(hwndDlg); ret = dlg->DialogProc(uMsg, wParam, lParam); @@ -744,7 +745,7 @@ CDialog::CDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) if (dlg->IsAllocated()) delete dlg; else - dlg->HWindow = NULL; // informace o odpojeni + dlg->HWindow = NULL; // information about disconnection } return ret; } @@ -761,12 +762,12 @@ CDialog::CDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) #endif } } - //--- zavolani metody DialogProc(...) prislusneho objektu dialogu + //--- calling method DialogProc(...) of the object of dialog INT_PTR dlgRes; if (dlg != NULL) dlgRes = dlg->DialogProc(uMsg, wParam, lParam); else - dlgRes = FALSE; // chyba nebo message neprisla mezi WM_INITDIALOG a WM_DESTROY + dlgRes = FALSE; // error or message did not come between WM_INITDIALOG and WM_DESTROY return dlgRes; } @@ -835,7 +836,7 @@ void CWindowsManager::DetachWindow(HWND hWnd) return; CS.Enter(); - if (LastHWnd[GetCacheIndex(hWnd)] == hWnd) // musime vycistit cache + if (LastHWnd[GetCacheIndex(hWnd)] == hWnd) // cache must be cleared { LastHWnd[GetCacheIndex(hWnd)] = NULL; LastWnd[GetCacheIndex(hWnd)] = NULL; @@ -849,7 +850,7 @@ void CWindowsManager::DetachWindow(HWND hWnd) { ResetState(); TRACE_ET(_T("Unable to detach window from WindowsManager. hwnd = ") << hWnd); - At(i).Wnd = NULL; // alespon takhle ... + At(i).Wnd = NULL; // at least this way ... } } else @@ -877,7 +878,7 @@ CWindowsManager::GetWindowPtr(HWND hWnd) search++; #endif int i; - if (GetIndex(hWnd, i)) // nalezeno + if (GetIndex(hWnd, i)) // found { LastHWnd[GetCacheIndex(hWnd)] = hWnd; LastWnd[GetCacheIndex(hWnd)] = At(i).Wnd; @@ -888,7 +889,7 @@ CWindowsManager::GetWindowPtr(HWND hWnd) else { CS.Leave(); - return NULL; // nenalezeno + return NULL; // not found } } @@ -911,9 +912,9 @@ int CWindowsManager::GetCount() CWindowQueue::~CWindowQueue() { if (!Empty()) - TRACE_ET(_T("Some window is still opened in ") << QueueName << _T(" queue!")); // nemelo by nastat... - // tady uz multi-threadovost nehrozi (konci soft, thready jsou/byly ukonceny) - // dealokujeme aspon nejakou pamet + TRACE_ET(_T("Some window is still opened in ") << QueueName << _T(" queue!")); // should not happen... + // multithreadness is not a problem here (soft is ending, threads are/were terminated) + // at least some memory should be deallocated CWindowQueueItem* last; CWindowQueueItem* item = Head; while (item != NULL) @@ -948,7 +949,7 @@ void CWindowQueue::Remove(HWND hWindow) CWindowQueueItem* item = Head; while (item != NULL) { - if (item->HWindow == hWindow) // nalezeno, odstranime + if (item->HWindow == hWindow) // found, removing { if (last != NULL) last->Next = item->Next; @@ -1001,7 +1002,7 @@ void CWindowQueue::BroadcastMessage(DWORD uMsg, WPARAM wParam, LPARAM lParam) BOOL CTransferInfo::GetControl(HWND& ctrlHWnd, int ctrlID, BOOL ignoreIsGood) { if (!ignoreIsGood && !IsGood()) - return FALSE; // dalsi nema cenu zpracovavat + return FALSE; // not worth to process further ctrlHWnd = GetDlgItem(HDialog, ctrlID); if (ctrlHWnd == NULL) { @@ -1021,8 +1022,8 @@ void CTransferInfo::EnsureControlIsFocused(int ctrlID) HWND wnd = GetFocus(); while (wnd != NULL && wnd != ctrl) wnd = ::GetParent(wnd); - if (wnd == NULL) // fokusime jen pokud neni ctrl predek GetFocusu - { // jako napr. edit-line v combo-boxu + if (wnd == NULL) // focus only if ctrl is not a child of GetFocus() + { // as e.g. edit-line in combo-box SendMessage(HDialog, WM_NEXTDLGCTL, (WPARAM)ctrl, TRUE); } } @@ -1107,8 +1108,8 @@ void CTransferInfo::EditLine(int ctrlID, double& value, TCHAR* format, BOOL sele BOOL decPoints = FALSE; BOOL expPart = FALSE; if (*s == _T('-') || *s == _T('+')) - s++; // preskok znamenka - while (*s != 0) // prevod carky na tecku + s++; // skipping sign + while (*s != 0) // converting comma to dot { if (!expPart && !decPoints && (*s == _T(',') || *s == _T('.'))) { @@ -1121,7 +1122,7 @@ void CTransferInfo::EditLine(int ctrlID, double& value, TCHAR* format, BOOL sele { expPart = TRUE; if (*(s + 1) == _T('+') || *(s + 1) == _T('-')) - s++; // preskok +- za E + s++; // skipping +- after exponent } else { @@ -1139,10 +1140,10 @@ void CTransferInfo::EditLine(int ctrlID, double& value, TCHAR* format, BOOL sele if (*s == 0) { TCHAR* stopString; // dummy - value = _tcstod(buff, &stopString); // jen pokud je cislo + value = _tcstod(buff, &stopString); // only if it's a number } else - value = 0; // pri chybe dame nulu + value = 0; // on error we give zero break; } } @@ -1173,8 +1174,8 @@ void CTransferInfo::EditLine(int ctrlID, int& value, BOOL select) TCHAR* s = buff; if (*s == _T('-') || *s == _T('+')) - s++; // preskok znamenka - while (*s != 0) // kontrola cisla + s++; // skipping sign + while (*s != 0) // checking the number { if (*s < _T('0') || *s > _T('9')) { @@ -1187,7 +1188,7 @@ void CTransferInfo::EditLine(int ctrlID, int& value, BOOL select) } TCHAR* endptr; - value = _tcstoul(buff, &endptr, 10); // nahrada za atoi / _ttoi, ktere misto 4000000000 vraci 2147483647 (protoze je to SIGNED INT) + value = _tcstoul(buff, &endptr, 10); // replacement for atoi / _ttoi, which returns 2147483647 instead of 4000000000 (because it's SIGNED INT) break; } } @@ -1227,10 +1228,10 @@ void CTransferInfo::EditLine(int ctrlID, __int64& value, BOOL select, BOOL unsig TCHAR* s = buff; BOOL minus = !unsignedNum && *s == _T('-'); if (!unsignedNum && *s == _T('-') || *s == _T('+')) - s++; // preskok znamenka + s++; // skipping sign unsigned __int64 num = 0; BOOL overflow = FALSE; - while (*s != 0) // kontrola cisla + while (*s != 0) // checking the number { if ((*s < _T('0') || *s > _T('9')) && (!hexMode || *s < _T('A') || *s > _T('F'))) { @@ -1245,7 +1246,7 @@ void CTransferInfo::EditLine(int ctrlID, __int64& value, BOOL select, BOOL unsig else { if (hexMode && num > 0x0fffffffffffffffui64 || - !hexMode && num > 1844674407370955161ui64 || // max. je 18446744073709551615ui64 + !hexMode && num > 1844674407370955161ui64 || // max. is 18446744073709551615ui64 !hexMode && num == 1844674407370955161ui64 && *s > _T('5')) { overflow = TRUE; // unsigned overflow @@ -1257,11 +1258,11 @@ void CTransferInfo::EditLine(int ctrlID, __int64& value, BOOL select, BOOL unsig } if (*s != 0) { - value = 0; // pri chybe dame nulu + value = 0; // zero when error break; } - // pri preteceni davame mezni hodnoty (inspirace: value = _ttoi64(buff)) + // when overflow, give boundary values (inspiration: value = _ttoi64(buff)) if (unsignedNum) { if (overflow) @@ -1294,7 +1295,7 @@ void CTransferInfo::EditLine(int ctrlID, __int64& value, BOOL select, BOOL unsig } if (overflow) { - if (ignoreOverflow) // ohlasime overflow jen pres TRACE_E + if (ignoreOverflow) // announce overflow only through TRACE_E { TRACE_ET(_T("CTransferInfo::EditLine(") << ctrlID << _T("): ") << (unsignedNum ? _T("unsigned ") : _T("")) << _T("int64 overflow has occured!")); } diff --git a/src/common/winlib.h b/src/common/winlib.h index fd7266822..0ca42338d 100644 --- a/src/common/winlib.h +++ b/src/common/winlib.h @@ -1,10 +1,12 @@ // SPDX-FileCopyrightText: 2023 Open Salamander Authors // SPDX-License-Identifier: GPL-2.0-or-later +// CommentsTranslationProject: TRANSLATED #pragma once -// makro __DEBUG_WINLIB zapina nekolik testu zaludnych chyb WinLibu +// __DEBUG_WINLIB macro enables some tests of tricky WinLib errors +// constants for WinLib strings (internal use in WinLib only) // konstanty pro stringy WinLibu (jen interni pouziti ve WinLibu) enum CWLS { @@ -14,26 +16,26 @@ enum CWLS WLS_COUNT }; -// nastaveni vlastnich textu do WinLibu -void SetWinLibStrings(const TCHAR* invalidNumber, // "neni cislo" (u transferbufferu cisel) - const TCHAR* error); // titulek "chyba" (u transferbufferu cisel) +// setting custom strings for WinLib +void SetWinLibStrings(const TCHAR* invalidNumber, // "not a number" (in transferbuffer of numbers) + const TCHAR* error); // "error" title (in transferbuffer of numbers) extern HINSTANCE HInstance; -extern const TCHAR* CWINDOW_CLASSNAME; // jmeno tridy universalniho okna -extern const TCHAR* CWINDOW_CLASSNAME2; // jmeno tridy universalniho okna - nema CS_VREDRAW | CS_HREDRAW +extern const TCHAR* CWINDOW_CLASSNAME; // universal window class name +extern const TCHAR* CWINDOW_CLASSNAME2; // universal window class name - does not have CS_VREDRAW | CS_HREDRAW #ifndef _UNICODE -extern const WCHAR* CWINDOW_CLASSNAMEW; // jmeno tridy unicodoveho universalniho okna -extern const WCHAR* CWINDOW_CLASSNAME2W; // jmeno tridy unicodoveho universalniho okna - nema CS_VREDRAW | CS_HREDRAW +extern const WCHAR* CWINDOW_CLASSNAMEW; // unicode universal window class name +extern const WCHAR* CWINDOW_CLASSNAME2W; // unicode universal window class name - does not have CS_VREDRAW | CS_HREDRAW #endif // _UNICODE class CWinLibHelp; -// je potreba zavolat pred pouzitim WinLibu +// needed to call before using WinLib BOOL InitializeWinLib(); -// je potreba zavolat po pouziti WinLibu +// needed to call after using WinLib void ReleaseWinLib(); -// je treba zavolat pred pouzivanim helpu +// needed to call before using help BOOL SetupWinLibHelp(CWinLibHelp* winLibHelp); class CWinLibHelp @@ -46,16 +48,16 @@ class CWinLibHelp // **************************************************************************** -enum CObjectOrigin // pouzito pri destrukci oken a dialogu +enum CObjectOrigin // used to destroy windows and dialogs { - ooAllocated, // pri WM_DESTROY se bude dealokovat - ooStatic, // pri WM_DESTROY se HWindow nastavi na NULL - ooStandard // pro modalni dlg =ooStatic, pro nemodalni dlg =ooAllocated + ooAllocated, // will be deallocated in WM_DESTROY + ooStatic, // HWindows will be set to NULL in WM_DESTROY + ooStandard // for modal dlg ==ooStatic, for non-modal dlg ==ooAllocated }; // **************************************************************************** -enum CObjectType // pro rozpoznani typu objektu +enum CObjectType // to recognize type of object { otBase, otWindow, @@ -66,7 +68,7 @@ enum CObjectType // pro rozpoznani typu objektu // **************************************************************************** -class CWindowsObject // predek vsech MS-Windows objektu +class CWindowsObject // parent of all MS-Windows objects { public: HWND HWindow; @@ -102,9 +104,9 @@ class CWindowsObject // predek vsech MS-Windows objektu SetHelpID(helpID); } - virtual ~CWindowsObject() {} // aby se u potomku volal jejich destruktor + virtual ~CWindowsObject() {} // so that destructor is called for derived objects - virtual BOOL Is(int) { return FALSE; } // identifikace objektu + virtual BOOL Is(int) { return FALSE; } // object identification virtual int GetObjectType() { return otBase; } virtual BOOL IsAllocated() { return ObjectOrigin == ooAllocated; } @@ -121,8 +123,8 @@ class CWindowsObject // predek vsech MS-Windows objektu protected: CObjectOrigin ObjectOrigin; #ifndef _UNICODE - // okna: create: TRUE = okno je unicodove, jinak je ANSI; attach: TRUE = nase window procedura - // je unicodova, jinak je ANSI; dialogy: TRUE = dialog je unicodovy, jinak je ANSI + // windows: create: TRUE = window is unicode, otherwise ANSI; attach: TRUE = our window procedure + // is unicode, otherwise ANSI; dialogs: TRUE = dialog is unicode, otherwise ANSI BOOL UnicodeWnd; #endif // _UNICODE }; @@ -201,7 +203,7 @@ class CWindow : public CWindowsObject HWND hwndParent, // handle of parent or owner window HMENU hmenu, // handle of menu or child-window identifier HINSTANCE hinst, // handle of application instance - LPVOID lpvParam); // ukazatel na objekt vytvareneho okna + LPVOID lpvParam); // pointer to object of the created window HWND CreateEx(DWORD dwExStyle, // extended window style LPCTSTR lpszClassName, // address of registered class name @@ -214,7 +216,7 @@ class CWindow : public CWindowsObject HWND hwndParent, // handle of parent or owner window HMENU hmenu, // handle of menu or child-window identifier HINSTANCE hinst, // handle of application instance - LPVOID lpvParam); // ukazatel na objekt vytvareneho okna + LPVOID lpvParam); // pointer to object of the created window #ifndef _UNICODE HWND CreateW(LPCWSTR lpszClassName, // address of registered class name @@ -227,7 +229,7 @@ class CWindow : public CWindowsObject HWND hwndParent, // handle of parent or owner window HMENU hmenu, // handle of menu or child-window identifier HINSTANCE hinst, // handle of application instance - LPVOID lpvParam); // ukazatel na objekt vytvareneho okna + LPVOID lpvParam); // pointer to object of the created window HWND CreateExW(DWORD dwExStyle, // extended window style LPCWSTR lpszClassName, // address of registered class name @@ -240,7 +242,7 @@ class CWindow : public CWindowsObject HWND hwndParent, // handle of parent or owner window HMENU hmenu, // handle of menu or child-window identifier HINSTANCE hinst, // handle of application instance - LPVOID lpvParam); // ukazatel na objekt vytvareneho okna + LPVOID lpvParam); // pointer to object of the created window #endif // _UNICODE void AttachToWindow(HWND hWnd); @@ -277,8 +279,8 @@ class CWindow : public CWindowsObject enum CTransferType { - ttDataToWindow, // data jdou do okna - ttDataFromWindow // data jdou z okna + ttDataToWindow, // data come to window + ttDataFromWindow // data come from window }; // **************************************************************************** @@ -286,7 +288,7 @@ enum CTransferType class CTransferInfo { public: - int FailCtrlID; // INT_MAX - vse v poradku, jinak ID controlu s chybou + int FailCtrlID; // INT_MAX - everything is OK, otherwise ID of control with error CTransferType Type; CTransferInfo(HWND hDialog, CTransferType type) @@ -302,7 +304,7 @@ class CTransferInfo void EnsureControlIsFocused(int ctrlID); void EditLine(int ctrlID, TCHAR* buffer, DWORD bufferSizeInChars, BOOL select = TRUE); - void EditLine(int ctrlID, double& value, TCHAR* format, BOOL select = TRUE); // format napr. _T("%.2lf") + void EditLine(int ctrlID, double& value, TCHAR* format, BOOL select = TRUE); // format e.g. _T("%.2lf") void EditLine(int ctrlID, int& value, BOOL select = TRUE); void EditLine(int ctrlID, __int64& value, BOOL select = TRUE, BOOL unsignedNum = FALSE /* signed number */, BOOL hexMode = FALSE /* decimal mode */, BOOL ignoreOverflow = FALSE, BOOL quiet = FALSE); @@ -315,7 +317,7 @@ class CTransferInfo #endif // _UNICODE protected: - HWND HDialog; // handle dialogu, pro ktery se provadi transfer + HWND HDialog; // handle of dialog for which the transfer is performed }; // **************************************************************************** @@ -323,8 +325,8 @@ class CTransferInfo class CDialog : public CWindowsObject { public: - CWindowsObject::SetObjectOrigin; // kvuli zkompilovatelnosti CPropSheetPage - CWindowsObject::HWindow; // kvuli zkompilovatelnosti CPropSheetPage + CWindowsObject::SetObjectOrigin; // for compilability CPropSheetPage + CWindowsObject::HWindow; // for compilability CPropSheetPage #ifdef _UNICODE CDialog(HINSTANCE modul, int resID, HWND parent, CObjectOrigin origin = ooStandard) : CWindowsObject(origin) @@ -366,8 +368,8 @@ class CDialog : public CWindowsObject void SetParent(HWND parent) { Parent = parent; } HWND GetParent() { return Parent; } - INT_PTR Execute(); // modalni dialog - HWND Create(); // nemodalni dialog + INT_PTR Execute(); // modal dialog + HWND Create(); // non-modal dialog static INT_PTR CALLBACK CDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -377,7 +379,7 @@ class CDialog : public CWindowsObject virtual void NotifDlgJustCreated() {} - BOOL Modal; // kvuli zpusobu destrukce dialogu + BOOL Modal; // due to the way of dialog destruction HINSTANCE Modul; int ResID; HWND Parent; @@ -388,14 +390,14 @@ class CDialog : public CWindowsObject struct CWindowData { - // pokud jsou objekty oken (Wnd) umistene na stacku (typicky modalni dialogy, napr. SalMessageBox()) - // a dojde k terminovani threadu, stack se zneplatni a tim jiz objekty oken nejsou pristupne, - // resime tak, ze na objekty (Wnd) sahame jen dokud jsou platne handly oken (HWnd) + // if all window objects (Wnd) are placed on stack (typically modal dialogs, e.g. SalMessageBox()) + // and thread is terminated, stack is invalidated and window objects are not accessible anymore, + // we solve this by accessing objects (Wnd) only while window handles (HWnd) are valid HWND HWnd; CWindowsObject* Wnd; }; -#define WNDMGR_CACHE_SIZE 256 // (2kB cache) musi byt v souladu s GetCacheIndex +#define WNDMGR_CACHE_SIZE 256 // (2kB cache) must be consistent with GetCacheIndex inline int GetCacheIndex(HWND hWnd) { @@ -420,7 +422,7 @@ class CWindowsManager : protected TDirectArray int search, cache, maxWndCount; #endif - CWinLibCS CS; // je public, aby slo lokalne zamezit zmenam ve Windows Manageru + CWinLibCS CS; // is public so that it can be used locally to prevent changes in Windows Manager public: CWindowsManager(); @@ -431,7 +433,7 @@ class CWindowsManager : protected TDirectArray int GetCount(); private: - HWND LastHWnd[WNDMGR_CACHE_SIZE]; // posledni pozadavek - cache + HWND LastHWnd[WNDMGR_CACHE_SIZE]; // the last request - cache CWindowsObject* LastWnd[WNDMGR_CACHE_SIZE]; inline BOOL GetIndex(HWND hWnd, int& index); @@ -456,7 +458,7 @@ BOOL CWindowsManager::GetIndex(HWND hWnd, int& index) { m = (l + r) / 2; HWND hw = At(m).HWnd; - if (hw == hWnd) // nalezeno + if (hw == hWnd) // found { index = m; CS.Leave(); @@ -464,9 +466,9 @@ BOOL CWindowsManager::GetIndex(HWND hWnd, int& index) } else if (hw > hWnd) { - if (l == r || l > m - 1) // nenalezeno + if (l == r || l > m - 1) // not found { - index = m; // mel by byt na teto pozici + index = m; // should be at this position CS.Leave(); return FALSE; } @@ -474,9 +476,9 @@ BOOL CWindowsManager::GetIndex(HWND hWnd, int& index) } else { - if (l == r) // nenalezeno + if (l == r) // not found { - index = m + 1; // mel by byt az za touto pozici + index = m + 1; // should be after this position CS.Leave(); return FALSE; } @@ -502,13 +504,13 @@ struct CWindowQueueItem class CWindowQueue { protected: - const TCHAR* QueueName; // jmeno fronty (jen pro debugovaci ucely) + const TCHAR* QueueName; // name of queue (for debug purposes only) CWindowQueueItem* Head; int Count; - CWinLibCS CS; // pristup z vice threadu -> nutna synchronizace + CWinLibCS CS; // access from more threads -> synchronization needed public: - CWindowQueue(const TCHAR* queueName /* napr. "Find Dialogs" */) + CWindowQueue(const TCHAR* queueName /* e.g. "Find Dialogs" */) { QueueName = queueName; Head = NULL; @@ -516,11 +518,12 @@ class CWindowQueue } ~CWindowQueue(); - BOOL Add(CWindowQueueItem* item); // prida polozku do fronty, vraci uspech - void Remove(HWND hWindow); // odstrani polozku z fronty - BOOL Empty(); // vraci TRUE pokud je fronta prazdna - int GetWindowCount(); // vraci pocet oken ve fronte + BOOL Add(CWindowQueueItem* item); // adds item into queue, returns success + void Remove(HWND hWindow); // removes item from queue + BOOL Empty(); // returns TRUE if queue is empty + int GetWindowCount(); // returns number of windows in queue + // sends (PostMessage - windows can be in different threads) message to all windows // posle (PostMessage - okna muzou byt v ruznych threadech) vsem oknum zpravu void BroadcastMessage(DWORD uMsg, WPARAM wParam, LPARAM lParam); };