diff -ur src.0/tools.h src/tools.h --- src.0/tools.h 2004-11-27 07:33:40.000000000 +0900 +++ src/tools.h 2006-03-27 13:12:00.738425600 +0900 @@ -69,9 +69,9 @@ /* Redo */ gettext_noop("Redo!"), /* Eraser */ gettext_noop("Eraser!"), /* New */ gettext_noop("You now have a blank sheet to draw on!"), - /* Open */ gettext_noop("Open…"), + /* Open */ gettext_noop("Open..."), /* Save */ gettext_noop("Your image has been saved!"), - /* Print */ gettext_noop("Printing…"), + /* Print */ gettext_noop("Printing..."), /* Quit */ gettext_noop("Bye bye!") }; diff -ur src.0/tuxpaint.c src/tuxpaint.c --- src.0/tuxpaint.c 2005-11-27 15:43:00.000000000 +0900 +++ src/tuxpaint.c 2006-03-29 13:15:05.583156800 +0900 @@ -220,10 +220,11 @@ #endif #else -#include -#include +//#include +//#include #include #include "win32_print.h" +#include "win32_dirent.h" #include #include @@ -357,6 +358,7 @@ #endif #ifdef WIN32 +typedef __int64 ssize_t; /* The SDL stderr redirection trick doesn't seem to work for perror(). This does pretty much the same thing. @@ -376,7 +378,21 @@ */ #define NOMINMAX #include "Shlwapi.h" -#define strcasestr StrStrI +#include + +#define snprintf _snprintf +#define strcasestr StrStrI +#define strncasecmp strnicmp +#define strcasecmp stricmp + +#define S_ISDIR(i) ((i&_S_IFDIR)!=0) +#define S_ISREG(i) ((i&_S_IFREG)!=0) + +#ifdef ENABLE_IM_EVENT +int unicode_to_utf8(char *buf, Uint32 c); +int utf8_remove_last_char(char *utf8, int len); +#endif + #endif /* WIN32 */ @@ -414,7 +430,7 @@ #if __GNUC__ > 2 || __GNUC_MINOR__ >= 92 #define restrict __restrict__ #else -#warning No restrict keyword? +#pragma message("#warning No restrict keyword?") #define restrict #endif #endif @@ -2535,7 +2551,7 @@ #define CLOCK_ASM(tbl) asm volatile("mftb %0" : "=r" (tbl)) #define CLOCK_TYPE unsigned long #ifndef CLOCK_SPEED -#warning Benchmark times are based on a 99.63 MHz memory bus. +#pragma message("#warning Benchmark times are based on a 99.63 MHz memory bus.") #define CLOCK_SPEED 24907667.0 #endif #endif @@ -2544,13 +2560,13 @@ #define CLOCK_ASM(tbl) asm volatile("rdtsc" : "=A" (tbl)) #define CLOCK_TYPE unsigned long long #ifndef CLOCK_SPEED -#warning Benchmark times are based on a 450 MHz CPU. +#pragma message("#warning Benchmark times are based on a 450 MHz CPU.") #define CLOCK_SPEED 450000000.0 #endif #endif #ifndef CLOCK_ASM -#warning No idea how to read CPU cycles for you, sorry. +#pragma message("#warning No idea how to read CPU cycles for you, sorry.") #define CLOCK_ASM(tbl) #define CLOCK_TYPE unsigned long #define CLOCK_SPEED 1000000000.0 @@ -2777,6 +2793,10 @@ Uint32 last_cursor_blink, cur_cursor_blink, pre_event_time, current_event_time; +#ifdef ENABLE_IM_EVENT + wchar_t wbuf[256]; + int buf_len = 0; +#endif num_things = num_brushes; thing_scroll = &brush_scroll; @@ -2838,7 +2858,14 @@ { key = event.key.keysym.sym; mod = event.key.keysym.mod; - + +#ifdef ENABLE_IM_EVENT + SDL_SetIMPosition(cursor_x - 2, cursor_y - 2 + TTF_FontHeight(getfonthandle(cur_font))); + if (buf_len = SDL_FlushIMString(wbuf)) + SDL_FlushIMString(wbuf); + wbuf[buf_len] = 0; +#endif + handle_keymouse(key, SDL_KEYDOWN); if (key == SDLK_ESCAPE && !disable_quit) @@ -2991,6 +3018,10 @@ if (cur_tool == TOOL_TEXT && cursor_x != -1 && cursor_y != -1) { +#ifdef ENABLE_IM_EVENT + if (buf_len > 0) + event.key.keysym.unicode = wbuf[0]; +#endif key_down = key; key_unicode = event.key.keysym.unicode; @@ -3004,8 +3035,13 @@ if (texttool_len > 0) { +#ifdef ENABLE_IM_EVENT + texttool_len = utf8_remove_last_char(texttool_str, texttool_len); + texttool_str[texttool_len] = '\0'; +#else texttool_len--; texttool_str[texttool_len] = '\0'; +#endif playsound(0, SND_KEYCLICK, 0); do_render_cur_text(0); @@ -3040,8 +3076,12 @@ cursor_textwidth = 0; } } +#ifdef ENABLE_IM_EVENT + else //if (isprint(key_unicode)) +#else else if (isprint(key_unicode)) - { +#endif + { if (texttool_len < sizeof(texttool_str) - MAX_UTF8_CHAR_LENGTH) { int old_cursor_textwidth = cursor_textwidth; @@ -3050,9 +3090,18 @@ "unicode = %c (%d)\n\n", key_down, key_unicode, key_unicode); #endif - + +#ifdef ENABLE_IM_EVENT + if (buf_len > 0) { + texttool_len += unicode_to_utf8(&texttool_str[texttool_len], key_unicode); + } else if (key_unicode != 0) { texttool_str[texttool_len++] = key_unicode; - + } +#else + if (key_unicode != 0) { + texttool_str[texttool_len++] = key_unicode; + } +#endif texttool_str[texttool_len] = '\0'; do_render_cur_text(0); @@ -3437,12 +3486,14 @@ if (cur_tool == TOOL_STAMP) { if(!disable_stamp_controls) - gd_controls = (grid_dims){2,2}; + //gd_controls = (grid_dims){2,2}; + gd_controls.cols = gd_controls.rows = 2; } else if (cur_tool == TOOL_TEXT) { if(!disable_stamp_controls) - gd_controls = (grid_dims){2,2}; + //gd_controls = (grid_dims){2,2}; + gd_controls.cols = gd_controls.rows = 2; } // number of whole or partial rows that will be needed @@ -4017,12 +4068,14 @@ if (cur_tool == TOOL_STAMP) { if(!disable_stamp_controls) - gd_controls = (grid_dims){2,2}; + //gd_controls = (grid_dims){2,2}; + gd_controls.cols = gd_controls.rows = 2; } else if (cur_tool == TOOL_TEXT) { if(!disable_stamp_controls) - gd_controls = (grid_dims){2,2}; + //gd_controls = (grid_dims){2,2}; + gd_controls.cols = gd_controls.rows = 2; } // number of whole or partial rows that will be needed @@ -6685,7 +6738,7 @@ ; } #else -#warning Failed to see DT_UNKNOWN +#pragma message("#warning Failed to see DT_UNKNOWN") #endif #if defined(_DIRENT_HAVE_D_NAMLEN) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) @@ -11713,7 +11766,9 @@ // For the 3rd arg, pass either NondefectiveBlit or SDL_BlitSurface. -static void autoscale_copy_smear_free(SDL_Surface *src, SDL_Surface *dst, int SDLCALL (*blit)(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)) +typedef int SDLCALL blit_func(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); + +static void autoscale_copy_smear_free(SDL_Surface *src, SDL_Surface *dst, blit_func *blit) { SDL_Surface *src1; SDL_Rect dest; @@ -12017,7 +12072,7 @@ } else { - fprintf(fi, "%s\n", file_id); + if (file_id[0]) fprintf(fi, "%s\n", file_id); fclose(fi); } @@ -16158,3 +16213,96 @@ else return(0); } + +#ifdef ENABLE_IM_EVENT + +int unicode_to_utf8(char *buf, Uint32 c) +{ + char *q; + + q = buf; + if (c < 0x80) { + *q++ = (char)c; + } else { + if (c < 0x800) { + *q++ = (c >> 6) | 0xc0; + } else { + if (c < 0x10000) { + *q++ = (c >> 12) | 0xe0; + } else { + if (c < 0x00200000) { + *q++ = (c >> 18) | 0xf0; + } else { + if (c < 0x04000000) { + *q++ = (c >> 24) | 0xf8; + } else { + *q++ = (c >> 30) | 0xfc; + *q++ = ((c >> 24) & 0x3f) | 0x80; + } + *q++ = ((c >> 18) & 0x3f) | 0x80; + } + *q++ = ((c >> 12) & 0x3f) | 0x80; + } + *q++ = ((c >> 6) & 0x3f) | 0x80; + } + *q++ = (c & 0x3f) | 0x80; + } + *q = '\0'; + return q - buf; +} + +// from SDL_ttf.c +int UTF8_to_UNICODE(Uint16 *unicode, const char *utf8, int len) +{ + int i, j; + Uint16 ch; + + for ( i=0, j=0; i < len; ++i, ++j ) { + ch = ((const unsigned char *)utf8)[i]; + if ( ch >= 0xF0 ) { + ch = (Uint16)(utf8[i]&0x07) << 18; + ch |= (Uint16)(utf8[++i]&0x3F) << 12; + ch |= (Uint16)(utf8[++i]&0x3F) << 6; + ch |= (Uint16)(utf8[++i]&0x3F); + } else + if ( ch >= 0xE0 ) { + ch = (Uint16)(utf8[i]&0x0F) << 12; + ch |= (Uint16)(utf8[++i]&0x3F) << 6; + ch |= (Uint16)(utf8[++i]&0x3F); + } else + if ( ch >= 0xC0 ) { + ch = (Uint16)(utf8[i]&0x1F) << 6; + ch |= (Uint16)(utf8[++i]&0x3F); + } + unicode[j] = ch; + } + unicode[j] = 0; + + return j; +} + +int utf8_remove_last_char(char *utf8, int len) +{ + int unicode_len, utf8_len; + int i; + Uint16 unicode[256]; + char *bf; + Uint16 *tf; + unicode_len = UTF8_to_UNICODE(unicode, utf8, len); + unicode_len--; + unicode[unicode_len] = 0; + + bf = utf8; + tf = unicode; + while (*tf) { + utf8_len = unicode_to_utf8(bf, *tf); + tf++; + bf += utf8_len; + }; + utf8_len = bf - utf8; + utf8[utf8_len] = 0; + + return utf8_len; +} + +#endif Only in src: tuxpaint.c~ diff -ur src.0/win32_dirent.c src/win32_dirent.c --- src.0/win32_dirent.c 2003-12-21 09:35:12.000000000 +0900 +++ src/win32_dirent.c 2006-03-27 12:25:28.222985600 +0900 @@ -58,7 +58,7 @@ } -struct dirent *readdir(struct DIR *pDir) +struct dirent *readdir(DIR *pDir) { assert(pDir != NULL); if (pDir->hFind) diff -ur src.0/win32_dirent.h src/win32_dirent.h --- src.0/win32_dirent.h 2003-02-24 10:48:04.000000000 +0900 +++ src/win32_dirent.h 2006-03-27 13:34:07.956872000 +0900 @@ -7,6 +7,7 @@ /* john@johnnypops.demon.co.uk */ /* */ /****************************************************/ +#if 0 typedef long BOOL; typedef unsigned int DWORD; typedef wchar_t TCHAR; @@ -53,7 +54,10 @@ #ifdef __cplusplus }; #endif - +#else +#define WIN32_LEAN_AND_MEAN +#include +#endif struct dirent { @@ -71,7 +75,7 @@ extern DIR *opendir(const char *pSpec); extern void closedir(DIR *pDir); -extern struct dirent *readdir(struct DIR *pDir); +extern struct dirent *readdir(DIR *pDir); typedef int (*selectCB)(const struct dirent *); typedef int (*comparCB)(const void*, const void*); diff -ur src.0/win32_print.c src/win32_print.c --- src.0/win32_print.c 2005-07-26 16:41:50.000000000 +0900 +++ src/win32_print.c 2006-03-27 14:09:41.975440000 +0900 @@ -525,7 +525,7 @@ if (SUCCEEDED(hr = ReadRegistry(key, option, prefix, sizeof(prefix)))) { remove_slash(prefix); - snprintf(path, sizeof(path), "%s/%s", prefix, suffix); + _snprintf(path, sizeof(path), "%s/%s", prefix, suffix); _mkdir(path); return strdup(path); }