diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-16 19:25:35 +0200 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-16 19:25:35 +0200 |
| commit | 8b5755851611574fd4010d9fa4e1046b78a501b9 (patch) | |
| tree | 84817c8bea211c099d72967470a1f054ece707c6 /alf/alfcombobox.cpp | |
| parent | 536ea04c34ba761d7031eeabb6d50adab0f0f2bd (diff) | |
make it build with -Wconversion
Diffstat (limited to 'alf/alfcombobox.cpp')
| -rw-r--r-- | alf/alfcombobox.cpp | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/alf/alfcombobox.cpp b/alf/alfcombobox.cpp index 33a454c..6d3af5e 100644 --- a/alf/alfcombobox.cpp +++ b/alf/alfcombobox.cpp @@ -23,19 +23,17 @@ ALF__ComboItemHeight(HWND hwnd) int height = 0; HDC hDc = GetDC(hwnd); HFONT font = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); - if (font) { - HFONT oldfont = SelectFont(hDc, font); + HFONT oldfont = SelectFont(hDc, font); - TEXTMETRIC tm; - ZeroMemory(&tm, sizeof(tm)); + TEXTMETRIC tm; + ZeroMemory(&tm, sizeof(tm)); - if (GetTextMetrics(hDc, &tm)) { - height = tm.tmHeight; - } - - SelectFont(hDc, oldfont); + if (GetTextMetrics(hDc, &tm)) { + height = tm.tmHeight; } + SelectFont(hDc, oldfont); + if (!ALF_Compat_IsMinWindowsVersion(4, 0)) { // baseline alignment for NT3.x/Win32s // ideally, this would only be applied for the ODS_COMOBOXEDIT state, @@ -84,10 +82,7 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } if (uMsg == WM_SETFONT && hwndChild) { SendMessage(hwndChild, WM_SETFONT, wParam, lParam); - - int h = ALF__ComboItemHeight(hwnd); - if (h) - SendMessage(hwndChild, CB_SETITEMHEIGHT, (WPARAM)0, h); + SendMessage(hwndChild, CB_SETITEMHEIGHT, (WPARAM)0, (LPARAM)ALF__ComboItemHeight(hwnd)); ALF_InvalidateLayout(GetParent(hwnd)); @@ -153,7 +148,7 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (!ps->cy) { ps->cy = tm.tmHeight + 2*ALF_Compat_GetSystemMetricsForDpi( - SM_CYEDGE, ALF_CentipointsToPixels(GetParent(hwnd), 7200)) + SM_CYEDGE, (UINT)ALF_CentipointsToPixels(GetParent(hwnd), 7200)) + 4 /* padding internal to the edit control */; } } @@ -168,9 +163,7 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (uMsg == WM_MEASUREITEM) { PMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam; - int h = ALF__ComboItemHeight(hwnd); - if (h) - lpmis->itemHeight = h; + lpmis->itemHeight = (UINT)ALF__ComboItemHeight(hwnd); return TRUE; } @@ -208,14 +201,14 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // Get and display the text for the list item. int len = (int)SendMessage(lpdis->hwndItem, CB_GETLBTEXTLEN, (WPARAM)lpdis->itemID, 0); if (len != CB_ERR) { - TCHAR *buf = (TCHAR*)LocalAlloc(LPTR, (len+1) * sizeof(TCHAR)); + TCHAR *buf = (TCHAR*)LocalAlloc(LPTR, (SIZE_T)(len+1) * sizeof(TCHAR)); SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID, (LPARAM)buf); ExtTextOut(lpdis->hDC, x, y, ETO_CLIPPED | ETO_OPAQUE, &lpdis->rcItem, - buf, lstrlen(buf), NULL); + buf, (UINT)lstrlen(buf), NULL); LocalFree(buf); } @@ -238,25 +231,21 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // XXX: When resizing the combo box, it will improperly draw a selection. // this appears to be a well-known bug that is still not fixed, even in Win10. // workaround based on https://stackoverflow.com/questions/49603893/how-to-deal-with-invalidly-painted-combobox-control-in-win32-winapi - DWORD sel = SendMessage(hwndChild, CB_GETEDITSEL, 0, 0); + LRESULT sel = SendMessage(hwndChild, CB_GETEDITSEL, 0, 0); SendMessage(hwndChild, CB_SETEDITSEL, 0, -1); // SWP_NOCOPYBITS because NT 3.51 doesn't properly repaint the drop-down button SetWindowPos(hwndChild, NULL, 0, 0, pos->cx, 200, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS); SendMessage(hwndChild, CB_SETEDITSEL, 0, (LPARAM)sel); - DWORD heightOffset = 0; + int heightOffset = 0; if (ALF_Compat_IsMinWindowsVersion(4, 0)) { heightOffset = - 2*ALF_Compat_GetSystemMetricsForDpi( - SM_CYEDGE, ALF_CentipointsToPixels(GetParent(hwnd), 7200)) + SM_CYEDGE, (UINT)ALF_CentipointsToPixels(GetParent(hwnd), 7200)) - 2; } SendMessage(hwndChild, CB_SETITEMHEIGHT, (WPARAM)-1, pos->cy + heightOffset); - - int h = ALF__ComboItemHeight(hwnd); - if (h) - SendMessage(hwndChild, CB_SETITEMHEIGHT, (WPARAM)0, h); - + SendMessage(hwndChild, CB_SETITEMHEIGHT, (WPARAM)0, (LPARAM)ALF__ComboItemHeight(hwnd)); } } @@ -371,7 +360,7 @@ ALF_ComboBoxStringForIndex(HWND combo, int index) { int len = (int)SendMessage(combo, ALF_CB_GETLBTEXTLEN, (WPARAM)index, 0); if (len > 0) { - TCHAR* buf = ALF_New(TCHAR, len + 1); + TCHAR* buf = ALF_New(TCHAR, (SIZE_T)len + 1); if (SendMessage(combo, ALF_CB_GETLBTEXT, (WPARAM)index, (LPARAM)buf)) { return buf; } else { |
