diff options
-rw-r--r-- | win32/PlatWin.cxx | 64 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 72 |
2 files changed, 85 insertions, 51 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index c1d1f7cd1..4d31e5af5 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -57,23 +57,10 @@ #define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800 #endif -static void *PointerFromWindow(HWND hWnd) { - return reinterpret_cast<void *>(::GetWindowLongPtr(hWnd, 0)); -} - -static void SetWindowPointer(HWND hWnd, void *ptr) { - ::SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(ptr)); -} - -extern UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage); - -static CRITICAL_SECTION crPlatformLock; -static HINSTANCE hinstPlatformRes = 0; - -static HCURSOR reverseArrowCursor = NULL; - namespace Scintilla { +UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage); + static RECT RectFromPRectangle(PRectangle prc) { RECT rc = {static_cast<LONG>(prc.left), static_cast<LONG>(prc.top), static_cast<LONG>(prc.right), static_cast<LONG>(prc.bottom)}; @@ -240,6 +227,19 @@ HFONT FormatAndMetrics::HFont() { namespace { +void *PointerFromWindow(HWND hWnd) { + return reinterpret_cast<void *>(::GetWindowLongPtr(hWnd, 0)); +} + +void SetWindowPointer(HWND hWnd, void *ptr) { + ::SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(ptr)); +} + +CRITICAL_SECTION crPlatformLock; +HINSTANCE hinstPlatformRes = 0; + +HCURSOR reverseArrowCursor = NULL; + FormatAndMetrics *FamFromFontID(void *fid) { return static_cast<FormatAndMetrics *>(fid); } @@ -280,9 +280,7 @@ D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) { } #endif -} - -static void SetLogFont(LOGFONTW &lf, const char *faceName, int characterSet, float size, int weight, bool italic, int extraFontFlag) { +void SetLogFont(LOGFONTW &lf, const char *faceName, int characterSet, float size, int weight, bool italic, int extraFontFlag) { lf = LOGFONTW(); // The negative is to allow for leading lf.lfHeight = -(abs(lround(size))); @@ -298,7 +296,7 @@ static void SetLogFont(LOGFONTW &lf, const char *faceName, int characterSet, flo * If one font is the same as another, its hash will be the same, but if the hash is the * same then they may still be different. */ -static int HashFont(const FontParameters &fp) noexcept { +int HashFont(const FontParameters &fp) noexcept { return static_cast<int>(fp.size) ^ (fp.characterSet << 10) ^ @@ -309,6 +307,8 @@ static int HashFont(const FontParameters &fp) noexcept { fp.faceName[0]; } +} + class FontCached : Font { FontCached *next; int usage; @@ -1284,7 +1284,7 @@ void SurfaceD2D::SetFont(Font &font_) { yInternalLeading = pfm->yInternalLeading; codePageText = codePage; if (pfm->characterSet) { - codePageText = CodePageFromCharSet(pfm->characterSet, codePage); + codePageText = Scintilla::CodePageFromCharSet(pfm->characterSet, codePage); } if (pRenderTarget) { D2D1_TEXT_ANTIALIAS_MODE aaMode; @@ -1806,6 +1806,8 @@ void Window::SetPosition(PRectangle rc) { static_cast<int>(rc.Width()), static_cast<int>(rc.Height()), SWP_NOZORDER | SWP_NOACTIVATE); } +namespace { + static RECT RectFromMonitor(HMONITOR hMonitor) { MONITORINFO mi = {}; mi.cbSize = sizeof(mi); @@ -1822,6 +1824,8 @@ static RECT RectFromMonitor(HMONITOR hMonitor) { return rc; } +} + void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { const LONG style = ::GetWindowLong(static_cast<HWND>(wid), GWL_STYLE); if (style & WS_POPUP) { @@ -1876,16 +1880,14 @@ void Window::InvalidateRectangle(PRectangle rc) { ::InvalidateRect(static_cast<HWND>(wid), &rcw, FALSE); } -static LRESULT Window_SendMessage(const Window *w, UINT msg, WPARAM wParam=0, LPARAM lParam=0) { - return ::SendMessage(static_cast<HWND>(w->GetID()), msg, wParam, lParam); -} - void Window::SetFont(Font &font) { - Window_SendMessage(this, WM_SETFONT, + ::SendMessage(static_cast<HWND>(wid), WM_SETFONT, reinterpret_cast<WPARAM>(font.GetID()), 0); } -static void FlipBitmap(HBITMAP bitmap, int width, int height) { +namespace { + +void FlipBitmap(HBITMAP bitmap, int width, int height) { HDC hdc = ::CreateCompatibleDC(NULL); if (hdc != NULL) { HGDIOBJ prevBmp = ::SelectObject(hdc, bitmap); @@ -1895,7 +1897,7 @@ static void FlipBitmap(HBITMAP bitmap, int width, int height) { } } -static HCURSOR GetReverseArrowCursor() { +HCURSOR GetReverseArrowCursor() { if (reverseArrowCursor != NULL) return reverseArrowCursor; @@ -1926,6 +1928,8 @@ static HCURSOR GetReverseArrowCursor() { return cursor; } +} + void Window::SetCursor(Cursor curs) { switch (curs) { case cursorText: @@ -2853,7 +2857,9 @@ LRESULT PASCAL ListBoxX::StaticWndProc( } } -static bool ListBoxX_Register() { +namespace { + +bool ListBoxX_Register() { WNDCLASSEX wndclassc; wndclassc.cbSize = sizeof(wndclassc); // We need CS_HREDRAW and CS_VREDRAW because of the ellipsis that might be drawn for @@ -2878,6 +2884,8 @@ bool ListBoxX_Unregister() { return ::UnregisterClass(ListBoxX_ClassName, hinstPlatformRes) != 0; } +} + Menu::Menu() : mid(0) { } diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index d060cd1c3..e8d4b36a4 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -136,32 +136,39 @@ typedef UINT_PTR (WINAPI *SetCoalescableTimerSig)(HWND hwnd, UINT_PTR nIDEvent, // GCC has trouble with the standard COM ABI so do it the old C way with explicit vtables. -const TCHAR callClassName[] = TEXT("CallTip"); - using namespace Scintilla; -static void *PointerFromWindow(HWND hWnd) { +namespace { + +const TCHAR callClassName[] = TEXT("CallTip"); + +void *PointerFromWindow(HWND hWnd) { return reinterpret_cast<void *>(::GetWindowLongPtr(hWnd, 0)); } -static void SetWindowPointer(HWND hWnd, void *ptr) { +void SetWindowPointer(HWND hWnd, void *ptr) { ::SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(ptr)); } -static void SetWindowID(HWND hWnd, int identifier) { +void SetWindowID(HWND hWnd, int identifier) { ::SetWindowLongPtr(hWnd, GWLP_ID, identifier); } -static Point PointFromPOINT(POINT pt) { +Point PointFromPOINT(POINT pt) { return Point::FromInts(pt.x, pt.y); } -static Point PointFromLParam(sptr_t lpoint) { +Point PointFromLParam(sptr_t lpoint) { return Point::FromInts(GET_X_LPARAM(lpoint), GET_Y_LPARAM(lpoint)); } -static bool KeyboardIsKeyDown(int key) { +POINT POINTFromPoint(Point pt) { + return POINT{ static_cast<LONG>(pt.x), static_cast<LONG>(pt.y) }; +} +bool KeyboardIsKeyDown(int key) { return (::GetKeyState(key) & 0x80000000) != 0; } +} + class ScintillaWin; // Forward declaration for COM interface subobjects typedef void VFunction(void); @@ -641,7 +648,10 @@ int ScintillaWin::MouseModifiers(uptr_t wParam) { (wParam & MK_CONTROL) != 0, KeyboardIsKeyDown(VK_MENU)); } -static int InputCodePage() { + +namespace { + +int InputCodePage() { HKL inputLocale = ::GetKeyboardLayout(0); const LANGID inputLang = LOWORD(inputLocale); char sCodePage[10]; @@ -653,7 +663,7 @@ static int InputCodePage() { } /** Map the key codes to their equivalent SCK_ form. */ -static int KeyTranslate(int keyIn) { +int KeyTranslate(int keyIn) { //PLATFORM_ASSERT(!keyIn); switch (keyIn) { case VK_DOWN: return SCK_DOWN; @@ -685,7 +695,7 @@ static int KeyTranslate(int keyIn) { } } -static bool BoundsContains(PRectangle rcBounds, HRGN hRgnBounds, PRectangle rcCheck) { +bool BoundsContains(PRectangle rcBounds, HRGN hRgnBounds, PRectangle rcCheck) { bool contains = true; if (!rcCheck.Empty()) { if (!rcBounds.Contains(rcCheck)) { @@ -710,7 +720,7 @@ static bool BoundsContains(PRectangle rcBounds, HRGN hRgnBounds, PRectangle rcCh return contains; } -static std::string StringEncode(const std::wstring &s, int codePage) { +std::string StringEncode(const std::wstring &s, int codePage) { const int cchMulti = s.length() ? ::WideCharToMultiByte(codePage, 0, s.c_str(), static_cast<int>(s.length()), NULL, 0, NULL, NULL) : 0; std::string sMulti(cchMulti, 0); if (cchMulti) { @@ -719,7 +729,7 @@ static std::string StringEncode(const std::wstring &s, int codePage) { return sMulti; } -static std::wstring StringDecode(const std::string &s, int codePage) { +std::wstring StringDecode(const std::string &s, int codePage) { const int cchWide = s.length() ? ::MultiByteToWideChar(codePage, 0, s.c_str(), static_cast<int>(s.length()), NULL, 0) : 0; std::wstring sWide(cchWide, 0); if (cchWide) { @@ -728,7 +738,7 @@ static std::wstring StringDecode(const std::string &s, int codePage) { return sWide; } -static std::wstring StringMapCase(const std::wstring &ws, DWORD mapFlags) { +std::wstring StringMapCase(const std::wstring &ws, DWORD mapFlags) { const int charsConverted = ::LCMapStringW(LOCALE_SYSTEM_DEFAULT, mapFlags, ws.c_str(), static_cast<int>(ws.length()), NULL, 0); std::wstring wsConverted(charsConverted, 0); @@ -739,6 +749,8 @@ static std::wstring StringMapCase(const std::wstring &ws, DWORD mapFlags) { return wsConverted; } +} + // Returns the target converted to UTF8. // Return the length in bytes. Sci::Position ScintillaWin::TargetAsUTF8(char *text) const { @@ -816,7 +828,7 @@ sptr_t ScintillaWin::WndPaint(uptr_t wParam) { PAINTSTRUCT *pps; const bool IsOcxCtrl = (wParam != 0); // if wParam != 0, it contains - // a PAINSTRUCT* from the OCX + // a PAINTSTRUCT* from the OCX // Removed since this interferes with reporting other assertions as it occurs repeatedly //PLATFORM_ASSERT(hRgnUpdate == NULL); hRgnUpdate = ::CreateRectRgn(0, 0, 0, 0); @@ -886,8 +898,7 @@ sptr_t ScintillaWin::HandleCompositionWindowed(uptr_t wParam, sptr_t lParam) { const Point pos = PointMainCaret(); COMPOSITIONFORM CompForm; CompForm.dwStyle = CFS_POINT; - CompForm.ptCurrentPos.x = static_cast<int>(pos.x); - CompForm.ptCurrentPos.y = static_cast<int>(pos.y); + CompForm.ptCurrentPos = POINTFromPoint(pos); ::ImmSetCompositionWindow(imc.hIMC, &CompForm); } return 0; @@ -1118,8 +1129,10 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) { return 0; } +namespace { + // Translate message IDs from WM_* and EM_* to SCI_* so can partly emulate Windows Edit control -static unsigned int SciMessageFromEM(unsigned int iMessage) { +unsigned int SciMessageFromEM(unsigned int iMessage) { switch (iMessage) { case EM_CANPASTE: return SCI_CANPASTE; case EM_CANUNDO: return SCI_CANUNDO; @@ -1146,6 +1159,10 @@ static unsigned int SciMessageFromEM(unsigned int iMessage) { return iMessage; } +} + +namespace Scintilla { + UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage) { if (documentCodePage == SC_CP_UTF8) { return SC_CP_UTF8; @@ -1177,6 +1194,8 @@ UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage) { return documentCodePage; } +} + UINT ScintillaWin::CodePageOfDocument() const { return CodePageFromCharSet(vs.styles[STYLE_DEFAULT].characterSet, pdoc->dbcsCodePage); } @@ -1577,7 +1596,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam if ((pt.x == -1) && (pt.y == -1)) { // Caused by keyboard so display menu near caret pt = PointMainCaret(); - POINT spt = {static_cast<int>(pt.x), static_cast<int>(pt.y)}; + POINT spt = POINTFromPoint(pt); ::ClientToScreen(MainHWND(), &spt); pt = PointFromPOINT(spt); } @@ -2147,6 +2166,8 @@ bool ScintillaWin::CanPaste() { return false; } +namespace { + class GlobalMemory { HGLOBAL hand; public: @@ -2196,7 +2217,7 @@ public: // OpenClipboard may fail if another application has opened the clipboard. // Try up to 8 times, with an initial delay of 1 ms and an exponential back off // for a maximum total delay of 127 ms (1+2+4+8+16+32+64). -static bool OpenClipboardRetry(HWND hwnd) { +bool OpenClipboardRetry(HWND hwnd) { for (int attempt=0; attempt<8; attempt++) { if (attempt > 0) { ::Sleep(1 << (attempt-1)); @@ -2208,6 +2229,8 @@ static bool OpenClipboardRetry(HWND hwnd) { return false; } +} + void ScintillaWin::Paste() { if (!::OpenClipboardRetry(MainHWND())) { return; @@ -2633,8 +2656,7 @@ void ScintillaWin::ImeStartComposition() { const Point pos = PointMainCaret(); COMPOSITIONFORM CompForm; CompForm.dwStyle = CFS_POINT; - CompForm.ptCurrentPos.x = static_cast<int>(pos.x); - CompForm.ptCurrentPos.y = static_cast<int>(pos.y); + CompForm.ptCurrentPos = POINTFromPoint(pos); ::ImmSetCompositionWindow(imc.hIMC, &CompForm); @@ -2943,10 +2965,14 @@ void ScintillaWin::FullPaintDC(HDC hdc) { paintState = notPainting; } -static bool CompareDevCap(HDC hdc, HDC hOtherDC, int nIndex) { +namespace { + +bool CompareDevCap(HDC hdc, HDC hOtherDC, int nIndex) { return ::GetDeviceCaps(hdc, nIndex) == ::GetDeviceCaps(hOtherDC, nIndex); } +} + bool ScintillaWin::IsCompatibleDC(HDC hOtherDC) { HDC hdc = ::GetDC(MainHWND()); const bool isCompatible = |