tUnicode support is now detected automatically on both GTK+ and Win32 systems. - vaccinewars - be a doctor and try to vaccinate the world
(HTM) git clone git://src.adamsgaard.dk/vaccinewars
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit b64e60e800462e30a3669e8bbd65f351204acd67
(DIR) parent 941fff842010d3c75fd552e0686ec2f7b8f4f9a2
(HTM) Author: Ben Webb <ben@salilab.org>
Date: Thu, 22 Aug 2002 17:59:27 +0000
Unicode support is now detected automatically on both GTK+ and Win32 systems.
Diffstat:
M src/gtkport/gtkport.c | 10 ++++++++++
M src/gtkport/gtkport.h | 2 ++
M src/gtkport/unicodewrap.c | 84 +++++++++++++++++++++++--------
M src/gtkport/unicodewrap.h | 3 +++
M src/gui_client/gtk_client.c | 15 ++++++++-------
5 files changed, 85 insertions(+), 29 deletions(-)
---
(DIR) diff --git a/src/gtkport/gtkport.c b/src/gtkport/gtkport.c
t@@ -1117,6 +1117,7 @@ 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,
t@@ -5466,6 +5467,15 @@ gchar *GtkGetFile(const GtkWidget *parent, const gchar *oldname,
return filename;
}
+gboolean HaveUnicodeSupport(void)
+{
+#ifdef HAVE_GLIB2
+ return TRUE;
+#else
+ return FALSE;
+#endif
+}
+
#endif /* CYGWIN */
#if CYGWIN || !HAVE_GLIB2
(DIR) diff --git a/src/gtkport/gtkport.h b/src/gtkport/gtkport.h
t@@ -751,6 +751,8 @@ struct _GtkUrl {
gchar *target, *bin;
};
+gboolean HaveUnicodeSupport(void);
+
#endif /* CYGWIN */
#if CYGWIN || !HAVE_GLIB2
(DIR) diff --git a/src/gtkport/unicodewrap.c b/src/gtkport/unicodewrap.c
t@@ -30,17 +30,57 @@
#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
+ * returned string must be g_free'd when no longer needed.
+ */
+static gunichar2 *strtow32(const char *instr)
+{
+ gunichar2 *outstr;
+ outstr = g_utf8_to_utf16(instr, -1, NULL, NULL, NULL);
+ if (!outstr) {
+ outstr = g_utf8_to_utf16("[?]", -1, NULL, NULL, NULL);
+ }
+}
+
BOOL mySetWindowText(HWND hWnd, LPCTSTR lpString)
{
- gunichar2 *text;
BOOL retval;
- if (!(text = g_utf8_to_utf16(lpString, -1, NULL, NULL, NULL))) {
- retval = SetWindowTextA(hWnd, lpString);
- } else {
+ if (unicode_support) {
+ gunichar2 *text;
+ text = strtow32(lpString);
retval = SetWindowTextW(hWnd, text);
g_free(text);
+ } else {
+ retval = SetWindowTextA(hWnd, lpString);
}
+
return retval;
}
t@@ -48,20 +88,20 @@ HWND myCreateWindow(LPCTSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle,
int x, int y, int nWidth, int nHeight, HWND hwndParent,
HMENU hMenu, HANDLE hInstance, LPVOID lpParam)
{
- gunichar2 *classname, *winname;
HWND retval;
- classname = g_utf8_to_utf16(lpClassName, -1, NULL, NULL, NULL);
- winname = g_utf8_to_utf16(lpWindowName, -1, NULL, NULL, NULL);
- if (!classname || !winname) {
- retval = CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y, nWidth,
+ if (unicode_support) {
+ gunichar2 *classname, *winname;
+ classname = strtow32(lpClassName);
+ winname = strtow32(lpWindowName);
+ retval = CreateWindowW(classname, winname, dwStyle, x, y, nWidth,
nHeight, hwndParent, hMenu, hInstance, lpParam);
+ g_free(classname);
+ g_free(winname);
} else {
- retval = CreateWindowW(classname, winname, dwStyle, x, y, nWidth,
+ retval = CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y, nWidth,
nHeight, hwndParent, hMenu, hInstance, lpParam);
}
- g_free(classname);
- g_free(winname);
return retval;
}
t@@ -70,22 +110,22 @@ HWND myCreateWindowEx(DWORD dwExStyle, LPCTSTR lpClassName,
int nWidth, int nHeight, HWND hwndParent, HMENU hMenu,
HANDLE hInstance, LPVOID lpParam)
{
- gunichar2 *classname, *winname;
HWND retval;
- classname = g_utf8_to_utf16(lpClassName, -1, NULL, NULL, NULL);
- winname = g_utf8_to_utf16(lpWindowName, -1, NULL, NULL, NULL);
- if (!classname || !winname) {
- retval = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle,
- x, y, nWidth, nHeight, hwndParent, hMenu,
- hInstance, lpParam);
- } else {
+ if (unicode_support) {
+ gunichar2 *classname, *winname;
+ classname = strtow32(lpClassName);
+ winname = strtow32(lpWindowName);
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);
}
- g_free(classname);
- g_free(winname);
return retval;
}
(DIR) diff --git a/src/gtkport/unicodewrap.h b/src/gtkport/unicodewrap.h
t@@ -30,6 +30,9 @@
#ifdef CYGWIN
#include <windows.h>
+void InitUnicodeSupport(void);
+void HaveUnicodeSupport(void);
+
BOOL mySetWindowText(HWND hWnd, LPCTSTR lpString);
HWND myCreateWindow(LPCTSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle,
int x, int y, int nWidth, int nHeight, HWND hwndParent,
(DIR) diff --git a/src/gui_client/gtk_client.c b/src/gui_client/gtk_client.c
t@@ -2179,14 +2179,15 @@ gboolean GtkLoop(int *argc, char **argv[],
gtk_init(argc, argv);
#endif
-#if HAVE_GLIB2
- /* GTK+2 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");
+ 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");
- Conv_SetInternalCodeset("UTF-8");
- WantUTF8Errors(TRUE);
-#endif
+ Conv_SetInternalCodeset("UTF-8");
+ WantUTF8Errors(TRUE);
+ }
InitConfiguration(cmdline);
ClientData.cmdline = cmdline;