Mercurial > vim
comparison src/gui_w32.c @ 27322:574cd25f0962 v8.2.4189
patch 8.2.4189: MS-Windows: code for "old look" is obsolete
Commit: https://github.com/vim/vim/commit/d1c58999c82afbdcbbe01548c1dea06d4d086f3e
Author: K.Takata <kentkt@csc.jp>
Date: Sun Jan 23 12:31:57 2022 +0000
patch 8.2.4189: MS-Windows: code for "old look" is obsolete
Problem: MS-Windows: code for "old look" is obsolete.
Solution: Delete obsolete code. Use "MS Shell Dlg" font. (Ken Takata,
closes #9596)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 23 Jan 2022 13:45:03 +0100 |
parents | e91b577be192 |
children | 251cae25bb49 |
comparison
equal
deleted
inserted
replaced
27321:3649b5a6b1b6 | 27322:574cd25f0962 |
---|---|
204 #endif | 204 #endif |
205 | 205 |
206 // Some parameters for dialog boxes. All in pixels. | 206 // Some parameters for dialog boxes. All in pixels. |
207 #define DLG_PADDING_X 10 | 207 #define DLG_PADDING_X 10 |
208 #define DLG_PADDING_Y 10 | 208 #define DLG_PADDING_Y 10 |
209 #define DLG_OLD_STYLE_PADDING_X 5 | |
210 #define DLG_OLD_STYLE_PADDING_Y 5 | |
211 #define DLG_VERT_PADDING_X 4 // For vertical buttons | 209 #define DLG_VERT_PADDING_X 4 // For vertical buttons |
212 #define DLG_VERT_PADDING_Y 4 | 210 #define DLG_VERT_PADDING_Y 4 |
213 #define DLG_ICON_WIDTH 34 | 211 #define DLG_ICON_WIDTH 34 |
214 #define DLG_ICON_HEIGHT 34 | 212 #define DLG_ICON_HEIGHT 34 |
215 #define DLG_MIN_WIDTH 150 | 213 #define DLG_MIN_WIDTH 150 |
216 #define DLG_FONT_NAME "MS Sans Serif" | 214 #define DLG_FONT_NAME "MS Shell Dlg" |
217 #define DLG_FONT_POINT_SIZE 8 | 215 #define DLG_FONT_POINT_SIZE 8 |
218 #define DLG_MIN_MAX_WIDTH 400 | 216 #define DLG_MIN_MAX_WIDTH 400 |
219 #define DLG_MIN_MAX_HEIGHT 400 | 217 #define DLG_MIN_MAX_HEIGHT 400 |
220 | 218 |
221 #define DLG_NONBUTTON_CONTROL 5000 // First ID of non-button controls | 219 #define DLG_NONBUTTON_CONTROL 5000 // First ID of non-button controls |
4158 static int dialog_default_button = -1; | 4156 static int dialog_default_button = -1; |
4159 | 4157 |
4160 // Intellimouse support | 4158 // Intellimouse support |
4161 static int mouse_scroll_lines = 0; | 4159 static int mouse_scroll_lines = 0; |
4162 | 4160 |
4163 static int s_usenewlook; // emulate W95/NT4 non-bold dialogs | |
4164 #ifdef FEAT_TOOLBAR | 4161 #ifdef FEAT_TOOLBAR |
4165 static void initialise_toolbar(void); | 4162 static void initialise_toolbar(void); |
4166 static void update_toolbar_size(void); | 4163 static void update_toolbar_size(void); |
4167 static LRESULT CALLBACK toolbar_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); | 4164 static LRESULT CALLBACK toolbar_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); |
4168 static int get_toolbar_bitmap(vimmenu_T *menu); | 4165 static int get_toolbar_bitmap(vimmenu_T *menu); |
6972 font = CreateFontIndirectW(&lfSysmenu); | 6969 font = CreateFontIndirectW(&lfSysmenu); |
6973 use_lfSysmenu = TRUE; | 6970 use_lfSysmenu = TRUE; |
6974 } | 6971 } |
6975 else | 6972 else |
6976 # endif | 6973 # endif |
6977 font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 6974 font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, |
6978 VARIABLE_PITCH, DLG_FONT_NAME); | 6975 0, 0, 0, 0, VARIABLE_PITCH, DLG_FONT_NAME); |
6979 if (s_usenewlook) | 6976 |
6980 { | 6977 oldFont = SelectFont(hdc, font); |
6981 oldFont = SelectFont(hdc, font); | 6978 dlgPaddingX = DLG_PADDING_X; |
6982 dlgPaddingX = DLG_PADDING_X; | 6979 dlgPaddingY = DLG_PADDING_Y; |
6983 dlgPaddingY = DLG_PADDING_Y; | 6980 |
6984 } | |
6985 else | |
6986 { | |
6987 oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT)); | |
6988 dlgPaddingX = DLG_OLD_STYLE_PADDING_X; | |
6989 dlgPaddingY = DLG_OLD_STYLE_PADDING_Y; | |
6990 } | |
6991 GetTextMetrics(hdc, &fontInfo); | 6981 GetTextMetrics(hdc, &fontInfo); |
6992 fontHeight = fontInfo.tmHeight; | 6982 fontHeight = fontInfo.tmHeight; |
6993 | 6983 |
6994 // Minimum width for horizontal button | 6984 // Minimum width for horizontal button |
6995 minButtonWidth = GetTextWidth(hdc, (char_u *)"Cancel", 6); | 6985 minButtonWidth = GetTextWidth(hdc, (char_u *)"Cancel", 6); |
7146 | 7136 |
7147 if (dlgwidth < DLG_MIN_WIDTH) | 7137 if (dlgwidth < DLG_MIN_WIDTH) |
7148 dlgwidth = DLG_MIN_WIDTH; // Don't allow a really thin dialog! | 7138 dlgwidth = DLG_MIN_WIDTH; // Don't allow a really thin dialog! |
7149 | 7139 |
7150 // start to fill in the dlgtemplate information. addressing by WORDs | 7140 // start to fill in the dlgtemplate information. addressing by WORDs |
7151 if (s_usenewlook) | 7141 lStyle = DS_MODALFRAME | WS_CAPTION | DS_3DLOOK | WS_VISIBLE | DS_SETFONT; |
7152 lStyle = DS_MODALFRAME | WS_CAPTION |DS_3DLOOK| WS_VISIBLE |DS_SETFONT; | |
7153 else | |
7154 lStyle = DS_MODALFRAME | WS_CAPTION |DS_3DLOOK| WS_VISIBLE; | |
7155 | 7142 |
7156 add_long(lStyle); | 7143 add_long(lStyle); |
7157 add_long(0); // (lExtendedStyle) | 7144 add_long(0); // (lExtendedStyle) |
7158 pnumitems = p; //save where the number of items must be stored | 7145 pnumitems = p; //save where the number of items must be stored |
7159 add_word(0); // NumberOfItems(will change later) | 7146 add_word(0); // NumberOfItems(will change later) |
7191 // copy the title of the dialog | 7178 // copy the title of the dialog |
7192 nchar = nCopyAnsiToWideChar(p, (title ? (LPSTR)title | 7179 nchar = nCopyAnsiToWideChar(p, (title ? (LPSTR)title |
7193 : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE); | 7180 : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE); |
7194 p += nchar; | 7181 p += nchar; |
7195 | 7182 |
7196 if (s_usenewlook) | 7183 // do the font, since DS_3DLOOK doesn't work properly |
7197 { | |
7198 // do the font, since DS_3DLOOK doesn't work properly | |
7199 # ifdef USE_SYSMENU_FONT | 7184 # ifdef USE_SYSMENU_FONT |
7200 if (use_lfSysmenu) | 7185 if (use_lfSysmenu) |
7201 { | 7186 { |
7202 // point size | 7187 // point size |
7203 *p++ = -MulDiv(lfSysmenu.lfHeight, 72, | 7188 *p++ = -MulDiv(lfSysmenu.lfHeight, 72, |
7204 GetDeviceCaps(hdc, LOGPIXELSY)); | 7189 GetDeviceCaps(hdc, LOGPIXELSY)); |
7205 wcscpy(p, lfSysmenu.lfFaceName); | 7190 wcscpy(p, lfSysmenu.lfFaceName); |
7206 nchar = (int)wcslen(lfSysmenu.lfFaceName) + 1; | 7191 nchar = (int)wcslen(lfSysmenu.lfFaceName) + 1; |
7207 } | 7192 } |
7208 else | 7193 else |
7209 # endif | 7194 # endif |
7210 { | 7195 { |
7211 *p++ = DLG_FONT_POINT_SIZE; // point size | 7196 *p++ = DLG_FONT_POINT_SIZE; // point size |
7212 nchar = nCopyAnsiToWideChar(p, DLG_FONT_NAME, FALSE); | 7197 nchar = nCopyAnsiToWideChar(p, DLG_FONT_NAME, FALSE); |
7213 } | 7198 } |
7214 p += nchar; | 7199 p += nchar; |
7215 } | |
7216 | 7200 |
7217 buttonYpos = msgheight + 2 * dlgPaddingY; | 7201 buttonYpos = msgheight + 2 * dlgPaddingY; |
7218 | 7202 |
7219 if (textfield != NULL) | 7203 if (textfield != NULL) |
7220 buttonYpos += editboxheight; | 7204 buttonYpos += editboxheight; |
7553 } | 7537 } |
7554 #endif | 7538 #endif |
7555 | 7539 |
7556 | 7540 |
7557 /* | 7541 /* |
7558 * Decide whether to use the "new look" (small, non-bold font) or the "old | 7542 * Computes the dialog base units based on the current dialog font. |
7559 * look" (big, clanky font) for dialogs, and work out a few values for use | 7543 * We don't use the GetDialogBaseUnits() API, because we don't use the |
7560 * later accordingly. | 7544 * (old-style) system font. |
7561 */ | 7545 */ |
7562 static void | 7546 static void |
7563 get_dialog_font_metrics(void) | 7547 get_dialog_font_metrics(void) |
7564 { | 7548 { |
7565 HDC hdc; | 7549 HDC hdc; |
7566 HFONT hfontTools = 0; | 7550 HFONT hfontTools = 0; |
7567 DWORD dlgFontSize; | |
7568 SIZE size; | 7551 SIZE size; |
7569 #ifdef USE_SYSMENU_FONT | 7552 #ifdef USE_SYSMENU_FONT |
7570 LOGFONTW lfSysmenu; | 7553 LOGFONTW lfSysmenu; |
7571 #endif | 7554 #endif |
7572 | |
7573 s_usenewlook = FALSE; | |
7574 | 7555 |
7575 #ifdef USE_SYSMENU_FONT | 7556 #ifdef USE_SYSMENU_FONT |
7576 if (gui_w32_get_menu_font(&lfSysmenu) == OK) | 7557 if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
7577 hfontTools = CreateFontIndirectW(&lfSysmenu); | 7558 hfontTools = CreateFontIndirectW(&lfSysmenu); |
7578 else | 7559 else |
7579 #endif | 7560 #endif |
7580 hfontTools = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, | 7561 hfontTools = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, |
7581 0, 0, 0, 0, VARIABLE_PITCH, DLG_FONT_NAME); | 7562 0, 0, 0, 0, VARIABLE_PITCH, DLG_FONT_NAME); |
7582 | 7563 |
7583 if (hfontTools) | 7564 hdc = GetDC(s_hwnd); |
7584 { | 7565 SelectObject(hdc, hfontTools); |
7585 hdc = GetDC(s_hwnd); | 7566 /* |
7586 SelectObject(hdc, hfontTools); | 7567 * GetTextMetrics() doesn't return the right value in |
7587 /* | 7568 * tmAveCharWidth, so we have to figure out the dialog base units |
7588 * GetTextMetrics() doesn't return the right value in | 7569 * ourselves. |
7589 * tmAveCharWidth, so we have to figure out the dialog base units | 7570 */ |
7590 * ourselves. | 7571 GetTextExtentPoint(hdc, |
7591 */ | 7572 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", |
7592 GetTextExtentPoint(hdc, | 7573 52, &size); |
7593 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", | 7574 ReleaseDC(s_hwnd, hdc); |
7594 52, &size); | 7575 |
7595 ReleaseDC(s_hwnd, hdc); | 7576 s_dlgfntwidth = (WORD)((size.cx / 26 + 1) / 2); |
7596 | 7577 s_dlgfntheight = (WORD)size.cy; |
7597 s_dlgfntwidth = (WORD)((size.cx / 26 + 1) / 2); | |
7598 s_dlgfntheight = (WORD)size.cy; | |
7599 s_usenewlook = TRUE; | |
7600 } | |
7601 | |
7602 if (!s_usenewlook) | |
7603 { | |
7604 dlgFontSize = GetDialogBaseUnits(); // fall back to big old system | |
7605 s_dlgfntwidth = LOWORD(dlgFontSize); | |
7606 s_dlgfntheight = HIWORD(dlgFontSize); | |
7607 } | |
7608 } | 7578 } |
7609 | 7579 |
7610 #if defined(FEAT_MENU) && defined(FEAT_TEAROFF) | 7580 #if defined(FEAT_MENU) && defined(FEAT_TEAROFF) |
7611 /* | 7581 /* |
7612 * Create a pseudo-"tearoff menu" based on the child | 7582 * Create a pseudo-"tearoff menu" based on the child |
7681 font = CreateFontIndirectW(&lfSysmenu); | 7651 font = CreateFontIndirectW(&lfSysmenu); |
7682 use_lfSysmenu = TRUE; | 7652 use_lfSysmenu = TRUE; |
7683 } | 7653 } |
7684 else | 7654 else |
7685 # endif | 7655 # endif |
7686 font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 7656 font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, |
7687 VARIABLE_PITCH, DLG_FONT_NAME); | 7657 0, 0, 0, 0, VARIABLE_PITCH, DLG_FONT_NAME); |
7688 if (s_usenewlook) | 7658 |
7689 oldFont = SelectFont(hdc, font); | 7659 oldFont = SelectFont(hdc, font); |
7690 else | |
7691 oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT)); | |
7692 | 7660 |
7693 // Calculate width of a single space. Used for padding columns to the | 7661 // Calculate width of a single space. Used for padding columns to the |
7694 // right width. | 7662 // right width. |
7695 spaceWidth = GetTextWidth(hdc, (char_u *)" ", 1); | 7663 spaceWidth = GetTextWidth(hdc, (char_u *)" ", 1); |
7696 | 7664 |
7743 if (textWidth > dlgwidth) | 7711 if (textWidth > dlgwidth) |
7744 dlgwidth = textWidth; | 7712 dlgwidth = textWidth; |
7745 dlgwidth += 2 * TEAROFF_PADDING_X + TEAROFF_BUTTON_PAD_X; | 7713 dlgwidth += 2 * TEAROFF_PADDING_X + TEAROFF_BUTTON_PAD_X; |
7746 | 7714 |
7747 // start to fill in the dlgtemplate information. addressing by WORDs | 7715 // start to fill in the dlgtemplate information. addressing by WORDs |
7748 if (s_usenewlook) | 7716 lStyle = DS_MODALFRAME | WS_CAPTION | WS_SYSMENU | DS_SETFONT | WS_VISIBLE; |
7749 lStyle = DS_MODALFRAME | WS_CAPTION| WS_SYSMENU |DS_SETFONT| WS_VISIBLE; | |
7750 else | |
7751 lStyle = DS_MODALFRAME | WS_CAPTION| WS_SYSMENU | WS_VISIBLE; | |
7752 | 7717 |
7753 lExtendedStyle = WS_EX_TOOLWINDOW|WS_EX_STATICEDGE; | 7718 lExtendedStyle = WS_EX_TOOLWINDOW|WS_EX_STATICEDGE; |
7754 *p++ = LOWORD(lStyle); | 7719 *p++ = LOWORD(lStyle); |
7755 *p++ = HIWORD(lStyle); | 7720 *p++ = HIWORD(lStyle); |
7756 *p++ = LOWORD(lExtendedStyle); | 7721 *p++ = LOWORD(lExtendedStyle); |
7776 nchar = nCopyAnsiToWideChar(p, ((*title) | 7741 nchar = nCopyAnsiToWideChar(p, ((*title) |
7777 ? (LPSTR)title | 7742 ? (LPSTR)title |
7778 : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE); | 7743 : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE); |
7779 p += nchar; | 7744 p += nchar; |
7780 | 7745 |
7781 if (s_usenewlook) | 7746 // do the font, since DS_3DLOOK doesn't work properly |
7782 { | |
7783 // do the font, since DS_3DLOOK doesn't work properly | |
7784 # ifdef USE_SYSMENU_FONT | 7747 # ifdef USE_SYSMENU_FONT |
7785 if (use_lfSysmenu) | 7748 if (use_lfSysmenu) |
7786 { | 7749 { |
7787 // point size | 7750 // point size |
7788 *p++ = -MulDiv(lfSysmenu.lfHeight, 72, | 7751 *p++ = -MulDiv(lfSysmenu.lfHeight, 72, |
7789 GetDeviceCaps(hdc, LOGPIXELSY)); | 7752 GetDeviceCaps(hdc, LOGPIXELSY)); |
7790 wcscpy(p, lfSysmenu.lfFaceName); | 7753 wcscpy(p, lfSysmenu.lfFaceName); |
7791 nchar = (int)wcslen(lfSysmenu.lfFaceName) + 1; | 7754 nchar = (int)wcslen(lfSysmenu.lfFaceName) + 1; |
7792 } | 7755 } |
7793 else | 7756 else |
7794 # endif | 7757 # endif |
7795 { | 7758 { |
7796 *p++ = DLG_FONT_POINT_SIZE; // point size | 7759 *p++ = DLG_FONT_POINT_SIZE; // point size |
7797 nchar = nCopyAnsiToWideChar(p, DLG_FONT_NAME, FALSE); | 7760 nchar = nCopyAnsiToWideChar(p, DLG_FONT_NAME, FALSE); |
7798 } | 7761 } |
7799 p += nchar; | 7762 p += nchar; |
7800 } | |
7801 | 7763 |
7802 /* | 7764 /* |
7803 * Loop over all the items in the menu. | 7765 * Loop over all the items in the menu. |
7804 * But skip over the tearbar. | 7766 * But skip over the tearbar. |
7805 */ | 7767 */ |