mirror of
https://github.com/vim/vim.git
synced 2025-09-30 04:44:14 -04:00
patch 9.1.1347: small problems with gui_w32.c
Problem: small problems with gui_w32.c Solution: fix compile warnings and refactor code (John Marriott) Compiler (clang v20.1.3) warnings on `_OnMenuSelect()` and `_OnGetDpiScaledSize()`: ``` clang -c -I. -Iproto -DWIN32 -DWINVER=0x0601 -D_WIN32_WINNT=0x0601 -DHAVE_PATHDEF -DFEAT_HUGE -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO -pipe -Wall -Wno-deprecated-declarations -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -Wall -Wextra -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wno-deprecated-declarations -Wno-error=missing-field-initializers -Werror=uninitialized -Wunused-but-set-variable -DEXITFREE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD gui_w32.c -o gobjx86-64/gui_w32.o gui_w32.c:5038:55: warning: comparison of integers of different signs: 'UINT' (aka 'unsigned int') and 'int' [-Wsign-compare] 5038 | && GetMenuState(s_menuBar, pMenu->id, MF_BYCOMMAND) != -1) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~ gui_w32.c:5054:26: warning: unused parameter 'hwnd' [-Wunused-parameter] 5054 | _OnGetDpiScaledSize(HWND hwnd, UINT dpi, SIZE *size) | ^ 2 warnings generated. ``` This commit contains the following changes: - Fixes Warning 1: The prototype of `GetMenuState()` says that it returns a UINT, but returns -1 on failure. Huh?!? Also, Microsoft says that this function has been superseded (see https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmenustate) and replaced by `GetMenuItemInfo()`. Both of these functions have a minimum support of Windows 2000. Therefore in `_OnMenuSelect()`, replace the call to `GetMenuState()` with `GetMenuItemInfo()`. - Fixes Warning 2: Add `UNUSED` to the definition of `_OnGetDpiScaledSize()`. - Simplify `logfont2name()`. - Add small optimisations in `_OnNotify()` and `gui_mch_do_spawn()`. - Add out-of-memory check in `gui_mch_do_spawn()`. - Code cosmetics (see definitions of `process_message_usual_key_classic()` and `process_message()`). closes: #17208 Signed-off-by: John Marriott <basilisk@internode.on.net> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
ffc89e47d0
commit
411ae580a9
101
src/gui_w32.c
101
src/gui_w32.c
@@ -2157,7 +2157,8 @@ static void process_message_usual_key(UINT vk, const MSG *pmsg)
|
|||||||
* Experimental implementation, introduced in v8.2.4807
|
* Experimental implementation, introduced in v8.2.4807
|
||||||
* "processing key event in Win32 GUI is not ideal"
|
* "processing key event in Win32 GUI is not ideal"
|
||||||
*/
|
*/
|
||||||
static void process_message_usual_key_experimental(UINT vk, const MSG *pmsg)
|
static void
|
||||||
|
process_message_usual_key_experimental(UINT vk, const MSG *pmsg)
|
||||||
{
|
{
|
||||||
WCHAR ch[8];
|
WCHAR ch[8];
|
||||||
int len;
|
int len;
|
||||||
@@ -2237,7 +2238,8 @@ static void process_message_usual_key_experimental(UINT vk, const MSG *pmsg)
|
|||||||
/*
|
/*
|
||||||
* "Classic" implementation, existing prior to v8.2.4807
|
* "Classic" implementation, existing prior to v8.2.4807
|
||||||
*/
|
*/
|
||||||
static void process_message_usual_key_classic(UINT vk, const MSG *pmsg)
|
static void
|
||||||
|
process_message_usual_key_classic(UINT vk, const MSG *pmsg)
|
||||||
{
|
{
|
||||||
char_u string[40];
|
char_u string[40];
|
||||||
|
|
||||||
@@ -3673,12 +3675,11 @@ gui_mch_exit(int rc UNUSED)
|
|||||||
static char_u *
|
static char_u *
|
||||||
logfont2name(LOGFONTW lf)
|
logfont2name(LOGFONTW lf)
|
||||||
{
|
{
|
||||||
char *p;
|
|
||||||
char *res;
|
|
||||||
char *charset_name;
|
char *charset_name;
|
||||||
char *quality_name;
|
char *quality_name;
|
||||||
char *font_name;
|
char *font_name;
|
||||||
int points;
|
size_t res_size;
|
||||||
|
char *res;
|
||||||
|
|
||||||
font_name = (char *)utf16_to_enc(lf.lfFaceName, NULL);
|
font_name = (char *)utf16_to_enc(lf.lfFaceName, NULL);
|
||||||
if (font_name == NULL)
|
if (font_name == NULL)
|
||||||
@@ -3686,43 +3687,48 @@ logfont2name(LOGFONTW lf)
|
|||||||
charset_name = charset_id2name((int)lf.lfCharSet);
|
charset_name = charset_id2name((int)lf.lfCharSet);
|
||||||
quality_name = quality_id2name((int)lf.lfQuality);
|
quality_name = quality_id2name((int)lf.lfQuality);
|
||||||
|
|
||||||
res = alloc(strlen(font_name) + 30
|
res_size = STRLEN(font_name) + 30
|
||||||
+ (charset_name == NULL ? 0 : strlen(charset_name) + 2)
|
+ (charset_name == NULL ? 0 : STRLEN(charset_name) + 2)
|
||||||
+ (quality_name == NULL ? 0 : strlen(quality_name) + 2));
|
+ (quality_name == NULL ? 0 : STRLEN(quality_name) + 2);
|
||||||
|
res = alloc(res_size);
|
||||||
if (res != NULL)
|
if (res != NULL)
|
||||||
{
|
{
|
||||||
p = res;
|
char *p;
|
||||||
|
int points;
|
||||||
|
size_t res_len;
|
||||||
|
|
||||||
|
// replace spaces in font_name with underscores.
|
||||||
|
for (p = font_name; *p != NUL; ++p)
|
||||||
|
{
|
||||||
|
if (isspace(*p))
|
||||||
|
*p = '_';
|
||||||
|
}
|
||||||
|
|
||||||
// make a normal font string out of the lf thing:
|
// make a normal font string out of the lf thing:
|
||||||
points = pixels_to_points(
|
points = pixels_to_points(
|
||||||
lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE);
|
lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE);
|
||||||
if (lf.lfWeight == FW_NORMAL || lf.lfWeight == FW_BOLD)
|
if (lf.lfWeight == FW_NORMAL || lf.lfWeight == FW_BOLD)
|
||||||
sprintf((char *)p, "%s:h%d", font_name, points);
|
res_len = vim_snprintf_safelen(
|
||||||
|
(char *)res, res_size, "%s:h%d", font_name, points);
|
||||||
else
|
else
|
||||||
sprintf((char *)p, "%s:h%d:W%ld", font_name, points, lf.lfWeight);
|
res_len = vim_snprintf_safelen(
|
||||||
while (*p)
|
(char *)res, res_size, "%s:h%d:W%ld", font_name, points, lf.lfWeight);
|
||||||
{
|
|
||||||
if (*p == ' ')
|
res_len += vim_snprintf_safelen(
|
||||||
*p = '_';
|
(char *)res + res_len,
|
||||||
++p;
|
res_size - res_len,
|
||||||
}
|
"%s%s%s%s",
|
||||||
if (lf.lfItalic)
|
lf.lfItalic ? ":i" : "",
|
||||||
STRCAT(p, ":i");
|
lf.lfWeight ? ":b" : "",
|
||||||
if (lf.lfWeight == FW_BOLD)
|
lf.lfUnderline ? ":u" : "",
|
||||||
STRCAT(p, ":b");
|
lf.lfStrikeOut ? ":s" : "");
|
||||||
if (lf.lfUnderline)
|
|
||||||
STRCAT(p, ":u");
|
|
||||||
if (lf.lfStrikeOut)
|
|
||||||
STRCAT(p, ":s");
|
|
||||||
if (charset_name != NULL)
|
if (charset_name != NULL)
|
||||||
{
|
res_len += vim_snprintf_safelen((char *)res + res_len,
|
||||||
STRCAT(p, ":c");
|
res_size - res_len, ":c%s", charset_name);
|
||||||
STRCAT(p, charset_name);
|
|
||||||
}
|
|
||||||
if (quality_name != NULL)
|
if (quality_name != NULL)
|
||||||
{
|
vim_snprintf((char *)res + res_len,
|
||||||
STRCAT(p, ":q");
|
res_size - res_len, ":q%s", quality_name);
|
||||||
STRCAT(p, quality_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vim_free(font_name);
|
vim_free(font_name);
|
||||||
@@ -4975,9 +4981,10 @@ _OnNotify(HWND hwnd, UINT id, NMHDR *hdr)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LPNMTTDISPINFO lpdi = (LPNMTTDISPINFO)hdr;
|
LPNMTTDISPINFO lpdi = (LPNMTTDISPINFO)hdr;
|
||||||
|
size_t len = STRLEN(str);
|
||||||
|
|
||||||
if (STRLEN(str) < sizeof(lpdi->szText)
|
if (len < sizeof(lpdi->szText)
|
||||||
|| ((tt_text = vim_strsave(str)) == NULL))
|
|| ((tt_text = vim_strnsave(str, len)) == NULL))
|
||||||
vim_strncpy((char_u *)lpdi->szText, str,
|
vim_strncpy((char_u *)lpdi->szText, str,
|
||||||
sizeof(lpdi->szText) - 1);
|
sizeof(lpdi->szText) - 1);
|
||||||
else
|
else
|
||||||
@@ -5020,7 +5027,6 @@ _OnMenuSelect(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|||||||
== MF_HILITE
|
== MF_HILITE
|
||||||
&& (State & MODE_CMDLINE) == 0)
|
&& (State & MODE_CMDLINE) == 0)
|
||||||
{
|
{
|
||||||
UINT idButton;
|
|
||||||
vimmenu_T *pMenu;
|
vimmenu_T *pMenu;
|
||||||
static int did_menu_tip = FALSE;
|
static int did_menu_tip = FALSE;
|
||||||
|
|
||||||
@@ -5032,10 +5038,15 @@ _OnMenuSelect(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|||||||
did_menu_tip = FALSE;
|
did_menu_tip = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
idButton = (UINT)LOWORD(wParam);
|
pMenu = gui_mswin_find_menu(root_menu, (UINT)LOWORD(wParam));
|
||||||
pMenu = gui_mswin_find_menu(root_menu, idButton);
|
if (pMenu != NULL && pMenu->strings[MENU_INDEX_TIP] != NULL)
|
||||||
if (pMenu != NULL && pMenu->strings[MENU_INDEX_TIP] != 0
|
{
|
||||||
&& GetMenuState(s_menuBar, pMenu->id, MF_BYCOMMAND) != -1)
|
MENUITEMINFO menuinfo;
|
||||||
|
|
||||||
|
menuinfo.cbSize = sizeof(MENUITEMINFO);
|
||||||
|
menuinfo.fMask = MIIM_ID; // We only want to check if the menu item exists,
|
||||||
|
// so retrieve something simple.
|
||||||
|
if (GetMenuItemInfo(s_menuBar, pMenu->id, FALSE, &menuinfo))
|
||||||
{
|
{
|
||||||
++msg_hist_off;
|
++msg_hist_off;
|
||||||
msg((char *)pMenu->strings[MENU_INDEX_TIP]);
|
msg((char *)pMenu->strings[MENU_INDEX_TIP]);
|
||||||
@@ -5044,6 +5055,7 @@ _OnMenuSelect(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|||||||
out_flush();
|
out_flush();
|
||||||
did_menu_tip = TRUE;
|
did_menu_tip = TRUE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
return DefWindowProcW(hwnd, WM_MENUSELECT, wParam, lParam);
|
return DefWindowProcW(hwnd, WM_MENUSELECT, wParam, lParam);
|
||||||
@@ -5051,7 +5063,7 @@ _OnMenuSelect(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
_OnGetDpiScaledSize(HWND hwnd, UINT dpi, SIZE *size)
|
_OnGetDpiScaledSize(HWND hwnd UNUSED, UINT dpi, SIZE *size)
|
||||||
{
|
{
|
||||||
int old_width, old_height;
|
int old_width, old_height;
|
||||||
int new_width, new_height;
|
int new_width, new_height;
|
||||||
@@ -5394,7 +5406,12 @@ gui_mch_do_spawn(char_u *arg)
|
|||||||
if (session == NULL)
|
if (session == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
savebg = p_bg;
|
savebg = p_bg;
|
||||||
p_bg = vim_strsave((char_u *)"light"); // Set 'bg' to "light".
|
p_bg = vim_strnsave((char_u *)"light", 5); // Set 'bg' to "light".
|
||||||
|
if (p_bg == NULL)
|
||||||
|
{
|
||||||
|
p_bg = savebg;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
ret = write_session_file(session);
|
ret = write_session_file(session);
|
||||||
vim_free(p_bg);
|
vim_free(p_bg);
|
||||||
p_bg = savebg;
|
p_bg = savebg;
|
||||||
|
@@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1347,
|
||||||
/**/
|
/**/
|
||||||
1346,
|
1346,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user