vaccinewars

be a doctor and try to vaccinate the world
git clone git://src.adamsgaard.dk/vaccinewars # fast
git clone https://src.adamsgaard.dk/vaccinewars.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit f2e240bee60a4e6ae9f6e50630f6979d6f06740c
parent a3c8385f36c8dd6818f88166fd70b10c605bb7b5
Author: Ben Webb <ben@salilab.org>
Date:   Mon, 28 Dec 2020 22:38:27 -0800

Drop non-Unicode Windows code path

All supported Windows versions should now support
Unicode - we don't support building on Windows 98
any more - so we no longer need both a Unicode and
an ANSI code path.

Diffstat:
Msrc/gtkport/gtkport.c | 16+---------------
Msrc/gtkport/gtkport.h | 1-
Msrc/gtkport/unicodewrap.c | 297+++++++++++++++++++++++--------------------------------------------------------
Msrc/gtkport/unicodewrap.h | 2--
Msrc/gui_client/gtk_client.c | 15+++++++--------
Msrc/serverside.c | 16+++++++---------
6 files changed, 101 insertions(+), 246 deletions(-)

diff --git a/src/gtkport/gtkport.c b/src/gtkport/gtkport.c @@ -72,7 +72,7 @@ const gchar *GTK_STOCK_HELP = N_("_Help"); HICON mainIcon = NULL; static WNDPROC customWndProc = NULL; static gboolean HaveRichEdit = FALSE; -static gchar *RichEditClass = NULL; +static const gchar *RichEditClass = "RichEdit20W"; static gboolean HaveXPControls = FALSE; static guint RecurseLevel = 0; @@ -1181,7 +1181,6 @@ void win32_init(HINSTANCE hInstance, HINSTANCE hPrevInstance, WNDCLASS wc; hInst = hInstance; - InitUnicodeSupport(); defFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT); urlFont = CreateFont(14, 0, 0, 0, FW_SEMIBOLD, FALSE, TRUE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, @@ -1198,14 +1197,6 @@ void win32_init(HINSTANCE hInstance, HINSTANCE hPrevInstance, InitCommonControls(); LoadLibrary("RICHED20.DLL"); - - /* Rich Edit controls have two different class names, depending on whether - * we want ANSI or Unicode - argh! */ - if (HaveUnicodeSupport()) { - RichEditClass = "RichEdit20W"; - } else { - RichEditClass = "RichEdit20A"; - } HaveRichEdit = GetClassInfo(hInstance, RichEditClass, &wc); HaveXPControls = CheckForXPControls(); @@ -5514,11 +5505,6 @@ gchar *GtkGetFile(const GtkWidget *parent, const gchar *oldname, return ret; } -gboolean HaveUnicodeSupport(void) -{ - return TRUE; -} - #endif /* CYGWIN */ #if CYGWIN diff --git a/src/gtkport/gtkport.h b/src/gtkport/gtkport.h @@ -647,7 +647,6 @@ GtkWidget *NewStockButton(const gchar *label, GtkAccelGroup *accel_group); gchar *GtkGetFile(const GtkWidget *parent, const gchar *oldname, const gchar *title); void DisplayHTML(GtkWidget *parent, const gchar *bin, const gchar *target); -gboolean HaveUnicodeSupport(void); GtkWidget *gtk_scrolled_tree_view_new(GtkWidget **pack_widg); #endif /* __GTKPORT_H__ */ diff --git a/src/gtkport/unicodewrap.c b/src/gtkport/unicodewrap.c @@ -31,30 +31,6 @@ #include "unicodewrap.h" -static gboolean unicode_support = FALSE; - -/* - * Sets the global variable unicode_support to reflect whether this version - * of Windows understands Unicode. (WinNT/2000/XP do, 95/98/ME do not.) - * This is done by calling the Unicode version of GetVersionEx, which should - * have no undesirable side effects. On non-Unicode systems, this is just - * a stub function that returns an error. - */ -void InitUnicodeSupport(void) -{ - OSVERSIONINFOW verinfo; - - verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); - - unicode_support = - (GetVersionExW(&verinfo) || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED); -} - -gboolean HaveUnicodeSupport(void) -{ - return unicode_support; -} - /* * Converts a string from our internal representation (UTF-8) to a form * suitable for Windows Unicode-aware functions (i.e. UTF-16). This @@ -89,16 +65,10 @@ gchar *w32tostr(const gunichar2 *instr, int len) BOOL mySetWindowText(HWND hWnd, LPCTSTR lpString) { BOOL retval; - - if (unicode_support) { - gunichar2 *text; - text = strtow32(lpString, -1); - retval = SetWindowTextW(hWnd, text); - g_free(text); - } else { - retval = SetWindowTextA(hWnd, lpString); - } - + gunichar2 *text; + text = strtow32(lpString, -1); + retval = SetWindowTextW(hWnd, text); + g_free(text); return retval; } @@ -117,63 +87,42 @@ HWND myCreateWindowEx(DWORD dwExStyle, LPCTSTR lpClassName, HANDLE hInstance, LPVOID lpParam) { HWND retval; - - if (unicode_support) { - gunichar2 *classname, *winname; - classname = strtow32(lpClassName, -1); - winname = strtow32(lpWindowName, -1); - retval = CreateWindowExW(dwExStyle, classname, winname, dwStyle, x, y, - nWidth, nHeight, hwndParent, hMenu, hInstance, - lpParam); - g_free(classname); - g_free(winname); - } else { - retval = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, - x, y, nWidth, nHeight, hwndParent, hMenu, - hInstance, lpParam); - } + gunichar2 *classname, *winname; + classname = strtow32(lpClassName, -1); + winname = strtow32(lpWindowName, -1); + retval = CreateWindowExW(dwExStyle, classname, winname, dwStyle, x, y, + nWidth, nHeight, hwndParent, hMenu, hInstance, + lpParam); + g_free(classname); + g_free(winname); return retval; } gchar *myGetWindowText(HWND hWnd) { gint textlen; + gunichar2 *buffer; + gchar *retstr; textlen = SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0); - if (unicode_support) { - gunichar2 *buffer; - gchar *retstr; - - buffer = g_new0(gunichar2, textlen + 1); - GetWindowTextW(hWnd, buffer, textlen + 1); - buffer[textlen] = '\0'; - retstr = w32tostr(buffer, textlen); - g_free(buffer); - return retstr; - } else { - gchar *buffer; - buffer = g_new0(gchar, textlen + 1); - GetWindowTextA(hWnd, buffer, textlen + 1); - buffer[textlen] = '\0'; - return buffer; - } + buffer = g_new0(gunichar2, textlen + 1); + GetWindowTextW(hWnd, buffer, textlen + 1); + buffer[textlen] = '\0'; + retstr = w32tostr(buffer, textlen); + g_free(buffer); + return retstr; } int myDrawText(HDC hDC, LPCTSTR lpString, int nCount, LPRECT lpRect, UINT uFormat) { int retval; + gunichar2 *text; - if (unicode_support) { - gunichar2 *text; - - text = strtow32(lpString, nCount); - retval = DrawTextW(hDC, text, -1, lpRect, uFormat); - g_free(text); - } else { - retval = DrawTextA(hDC, lpString, nCount, lpRect, uFormat); - } + text = strtow32(lpString, nCount); + retval = DrawTextW(hDC, text, -1, lpRect, uFormat); + g_free(text); return retval; } @@ -202,18 +151,13 @@ BOOL WINAPI mySetMenuItemInfo(HMENU hMenu, UINT uItem, BOOL fByPosition, LPMENUITEMINFO lpmii) { BOOL retval; + MENUITEMINFOW miiw; + BOOL strdata; - if (unicode_support) { - MENUITEMINFOW miiw; - BOOL strdata; - - strdata = makeMenuItemInfoW(&miiw, lpmii); - retval = SetMenuItemInfoW(hMenu, uItem, fByPosition, &miiw); - if (strdata) { - g_free(miiw.dwTypeData); - } - } else { - retval = SetMenuItemInfoA(hMenu, uItem, fByPosition, lpmii); + strdata = makeMenuItemInfoW(&miiw, lpmii); + retval = SetMenuItemInfoW(hMenu, uItem, fByPosition, &miiw); + if (strdata) { + g_free(miiw.dwTypeData); } return retval; } @@ -222,18 +166,13 @@ BOOL WINAPI myInsertMenuItem(HMENU hMenu, UINT uItem, BOOL fByPosition, LPMENUITEMINFO lpmii) { BOOL retval; + MENUITEMINFOW miiw; + BOOL strdata; - if (unicode_support) { - MENUITEMINFOW miiw; - BOOL strdata; - - strdata = makeMenuItemInfoW(&miiw, lpmii); - retval = InsertMenuItemW(hMenu, uItem, fByPosition, &miiw); - if (strdata) { - g_free(miiw.dwTypeData); - } - } else { - retval = InsertMenuItemA(hMenu, uItem, fByPosition, lpmii); + strdata = makeMenuItemInfoW(&miiw, lpmii); + retval = InsertMenuItemW(hMenu, uItem, fByPosition, &miiw); + if (strdata) { + g_free(miiw.dwTypeData); } return retval; } @@ -272,7 +211,7 @@ static BOOL makeTabItemW(TC_ITEMW *tiew, const TC_ITEM *tie) int myHeader_InsertItem(HWND hWnd, int index, const HD_ITEM *phdi) { int retval; - if (unicode_support && IsWindowUnicode(hWnd)) { + if (IsWindowUnicode(hWnd)) { HD_ITEMW hdiw; BOOL strdata; @@ -292,18 +231,13 @@ int myHeader_InsertItem(HWND hWnd, int index, const HD_ITEM *phdi) int myTabCtrl_InsertItem(HWND hWnd, int index, const TC_ITEM *pitem) { int retval; - if (unicode_support) { - TC_ITEMW tiew; - BOOL strdata; - strdata = makeTabItemW(&tiew, pitem); - retval = (int)SendMessageW(hWnd, TCM_INSERTITEMW, (WPARAM)index, - (LPARAM)&tiew); - if (strdata) { - g_free(tiew.pszText); - } - } else { - retval = (int)SendMessageA(hWnd, TCM_INSERTITEMA, (WPARAM)index, - (LPARAM)pitem); + TC_ITEMW tiew; + BOOL strdata; + strdata = makeTabItemW(&tiew, pitem); + retval = (int)SendMessageW(hWnd, TCM_INSERTITEMW, (WPARAM)index, + (LPARAM)&tiew); + if (strdata) { + g_free(tiew.pszText); } return retval; } @@ -311,26 +245,21 @@ int myTabCtrl_InsertItem(HWND hWnd, int index, const TC_ITEM *pitem) ATOM myRegisterClass(CONST WNDCLASS *lpWndClass) { ATOM retval; - - if (unicode_support) { - WNDCLASSW wcw; - - wcw.style = lpWndClass->style; - wcw.lpfnWndProc = lpWndClass->lpfnWndProc; - wcw.cbClsExtra = lpWndClass->cbClsExtra; - wcw.cbWndExtra = lpWndClass->cbWndExtra; - wcw.hInstance = lpWndClass->hInstance; - wcw.hIcon = lpWndClass->hIcon; - wcw.hCursor = lpWndClass->hCursor; - wcw.hbrBackground = lpWndClass->hbrBackground; - wcw.lpszMenuName = strtow32(lpWndClass->lpszMenuName, -1); - wcw.lpszClassName = strtow32(lpWndClass->lpszClassName, -1); - retval = RegisterClassW(&wcw); - g_free((LPWSTR)wcw.lpszMenuName); - g_free((LPWSTR)wcw.lpszClassName); - } else { - retval = RegisterClassA(lpWndClass); - } + WNDCLASSW wcw; + + wcw.style = lpWndClass->style; + wcw.lpfnWndProc = lpWndClass->lpfnWndProc; + wcw.cbClsExtra = lpWndClass->cbClsExtra; + wcw.cbWndExtra = lpWndClass->cbWndExtra; + wcw.hInstance = lpWndClass->hInstance; + wcw.hIcon = lpWndClass->hIcon; + wcw.hCursor = lpWndClass->hCursor; + wcw.hbrBackground = lpWndClass->hbrBackground; + wcw.lpszMenuName = strtow32(lpWndClass->lpszMenuName, -1); + wcw.lpszClassName = strtow32(lpWndClass->lpszClassName, -1); + retval = RegisterClassW(&wcw); + g_free((LPWSTR)wcw.lpszMenuName); + g_free((LPWSTR)wcw.lpszClassName); return retval; } @@ -338,141 +267,87 @@ HWND myCreateDialog(HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc) { HWND retval; - - if (unicode_support) { - gunichar2 *text; - text = strtow32(lpTemplate, -1); - retval = CreateDialogW(hInstance, text, hWndParent, lpDialogFunc); - g_free(text); - } else { - retval = CreateDialogA(hInstance, lpTemplate, hWndParent, lpDialogFunc); - } + gunichar2 *text; + text = strtow32(lpTemplate, -1); + retval = CreateDialogW(hInstance, text, hWndParent, lpDialogFunc); + g_free(text); return retval; } LRESULT mySendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { - if (unicode_support) { - return SendMessageW(hWnd, Msg, wParam, lParam); - } else { - return SendMessageA(hWnd, Msg, wParam, lParam); - } + return SendMessageW(hWnd, Msg, wParam, lParam); } void myEditReplaceSel(HWND hWnd, BOOL fCanUndo, LPCSTR lParam) { - if (unicode_support) { - gunichar2 *text; - text = strtow32(lParam, -1); - SendMessageW(hWnd, EM_REPLACESEL, (WPARAM)fCanUndo, (LPARAM)text); - g_free(text); - } else { - SendMessageA(hWnd, EM_REPLACESEL, (WPARAM)fCanUndo, (LPARAM)lParam); - } + gunichar2 *text; + text = strtow32(lParam, -1); + SendMessageW(hWnd, EM_REPLACESEL, (WPARAM)fCanUndo, (LPARAM)text); + g_free(text); } LONG_PTR mySetWindowLong(HWND hWnd, int nIndex, LONG_PTR dwNewLong) { - if (unicode_support) { - return SetWindowLongPtrW(hWnd, nIndex, dwNewLong); - } else { - return SetWindowLongPtrA(hWnd, nIndex, dwNewLong); - } + return SetWindowLongPtrW(hWnd, nIndex, dwNewLong); } LONG_PTR myGetWindowLong(HWND hWnd, int nIndex) { - if (unicode_support) { - return GetWindowLongPtrW(hWnd, nIndex); - } else { - return GetWindowLongPtrA(hWnd, nIndex); - } + return GetWindowLongPtrW(hWnd, nIndex); } LRESULT myCallWindowProc(WNDPROC lpPrevWndProc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { - if (unicode_support) { - return CallWindowProcW(lpPrevWndProc, hWnd, Msg, wParam, lParam); - } else { - return CallWindowProcA(lpPrevWndProc, hWnd, Msg, wParam, lParam); - } + return CallWindowProcW(lpPrevWndProc, hWnd, Msg, wParam, lParam); } LRESULT myDefWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { - if (unicode_support) { - return DefWindowProcW(hWnd, Msg, wParam, lParam); - } else { - return DefWindowProcA(hWnd, Msg, wParam, lParam); - } + return DefWindowProcW(hWnd, Msg, wParam, lParam); } int myMessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) { int retval; - - if (unicode_support) { - gunichar2 *text, *caption; - text = strtow32(lpText, -1); - caption = strtow32(lpCaption, -1); - retval = MessageBoxW(hWnd, text, caption, uType); - g_free(text); - g_free(caption); - } else { - retval = MessageBoxA(hWnd, lpText, lpCaption, uType); - } + gunichar2 *text, *caption; + text = strtow32(lpText, -1); + caption = strtow32(lpCaption, -1); + retval = MessageBoxW(hWnd, text, caption, uType); + g_free(text); + g_free(caption); return retval; } BOOL myGetMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax) { - if (unicode_support) { - return GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); - } else { - return GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); - } + return GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); } LONG myDispatchMessage(CONST MSG *lpmsg) { - if (unicode_support) { - return DispatchMessageW(lpmsg); - } else { - return DispatchMessageA(lpmsg); - } + return DispatchMessageW(lpmsg); } BOOL myIsDialogMessage(HWND hDlg, LPMSG lpMsg) { - if (unicode_support) { - return IsDialogMessageW(hDlg, lpMsg); - } else { - return IsDialogMessageA(hDlg, lpMsg); - } + return IsDialogMessageW(hDlg, lpMsg); } size_t myw32strlen(const char *str) { - if (unicode_support) { - return g_utf8_strlen(str, -1); - } else { - return strlen(str); - } + return g_utf8_strlen(str, -1); } LRESULT myComboBox_AddString(HWND hWnd, LPCTSTR text) { LRESULT retval; - if (unicode_support) { - gunichar2 *w32text; - w32text = strtow32(text, -1); - retval = SendMessageW(hWnd, CB_ADDSTRING, 0, (LPARAM)w32text); - g_free(w32text); - } else { - retval = SendMessageA(hWnd, CB_ADDSTRING, 0, (LPARAM)text); - } + gunichar2 *w32text; + w32text = strtow32(text, -1); + retval = SendMessageW(hWnd, CB_ADDSTRING, 0, (LPARAM)w32text); + g_free(w32text); return retval; } diff --git a/src/gtkport/unicodewrap.h b/src/gtkport/unicodewrap.h @@ -32,8 +32,6 @@ #include <windows.h> #include <commctrl.h> -void InitUnicodeSupport(void); - BOOL mySetWindowText(HWND hWnd, LPCTSTR lpString); HWND myCreateWindow(LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hwndParent, diff --git a/src/gui_client/gtk_client.c b/src/gui_client/gtk_client.c @@ -2222,15 +2222,14 @@ gboolean GtkLoop(int *argc, char **argv[], gtk_init(argc, argv); #endif - if (HaveUnicodeSupport()) { - /* GTK+2 (and the GTK emulation code on WinNT systems) expects all - * strings to be UTF-8, so we force gettext to return all translations - * in this encoding here. */ - bind_textdomain_codeset(PACKAGE, "UTF-8"); + /* GTK+2 (and the GTK emulation code on WinNT systems) expects all + * strings to be UTF-8, so we force gettext to return all translations + * in this encoding here. */ + bind_textdomain_codeset(PACKAGE, "UTF-8"); + + Conv_SetInternalCodeset("UTF-8"); + WantUTF8Errors(TRUE); - Conv_SetInternalCodeset("UTF-8"); - WantUTF8Errors(TRUE); - } InitConfiguration(cmdline); ClientData.cmdline = cmdline; diff --git a/src/serverside.c b/src/serverside.c @@ -1445,7 +1445,7 @@ static void GuiDoCommand(GtkWidget *widget, gpointer data) text = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1); gtk_editable_delete_text(GTK_EDITABLE(widget), 0, -1); - HandleServerCommand(text, NULL, HaveUnicodeSupport()); + HandleServerCommand(text, NULL, TRUE); g_free(text); if (IsServerShutdown()) GuiQuitServer(); @@ -1649,15 +1649,13 @@ void GuiServerLoop(struct CMDLINE *cmdline, gboolean is_service) GtkWidget *window, *text, *hbox, *vbox, *entry, *label; GIOChannel *listench; - if (HaveUnicodeSupport()) { - /* GTK+2 (and the GTK emulation code on WinNT systems) expects all - * strings to be UTF-8, so we force gettext to return all translations - * in this encoding here. */ - bind_textdomain_codeset(PACKAGE, "UTF-8"); + /* GTK+2 (and the GTK emulation code on WinNT systems) expects all + * strings to be UTF-8, so we force gettext to return all translations + * in this encoding here. */ + bind_textdomain_codeset(PACKAGE, "UTF-8"); - Conv_SetInternalCodeset("UTF-8"); - WantUTF8Errors(TRUE); - } + Conv_SetInternalCodeset("UTF-8"); + WantUTF8Errors(TRUE); if (cmdline) { InitConfiguration(cmdline);