Mercurial > dwindows
comparison win/dw.c @ 1663:a76fb5f1a6c8
Fixes for building in Unicode mode with MinGW on Windows.
Also fix incorrect calling conventions on signal handlers with MinGW.
AEROGLASS is still not supported with MinGW due to some missing items
in the uxtheme.h header.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 20 Apr 2012 19:44:16 +0000 |
parents | 620df4222086 |
children | 9dbd2984c1e5 |
comparison
equal
deleted
inserted
replaced
1662:620df4222086 | 1663:a76fb5f1a6c8 |
---|---|
4 * | 4 * |
5 * (C) 2000-2012 Brian Smith <brian@dbsoft.org> | 5 * (C) 2000-2012 Brian Smith <brian@dbsoft.org> |
6 * (C) 2003-2011 Mark Hessling <mark@rexx.org> | 6 * (C) 2003-2011 Mark Hessling <mark@rexx.org> |
7 * | 7 * |
8 */ | 8 */ |
9 | |
10 #ifdef AEROGLASS | |
11 #define _WIN32_IE 0x0501 | |
12 #define WINVER 0x501 | |
13 #else | |
9 #define _WIN32_IE 0x0500 | 14 #define _WIN32_IE 0x0500 |
10 #define WINVER 0x500 | 15 #define WINVER 0x500 |
16 #endif | |
11 #include <windows.h> | 17 #include <windows.h> |
12 #include <windowsx.h> | 18 #include <windowsx.h> |
13 #include <commctrl.h> | 19 #include <commctrl.h> |
14 #include <shlwapi.h> | 20 #include <shlwapi.h> |
15 #include <shlobj.h> | 21 #include <shlobj.h> |
219 * MinGW Is missing a bunch of definitions | 225 * MinGW Is missing a bunch of definitions |
220 * so #define them here... | 226 * so #define them here... |
221 */ | 227 */ |
222 | 228 |
223 #if !defined( _tstol ) | 229 #if !defined( _tstol ) |
230 #if defined(UNICODE) | |
231 # define _tstol _wtol | |
232 #else | |
224 # define _tstol atol | 233 # define _tstol atol |
234 #endif | |
225 #endif | 235 #endif |
226 #if !defined(PBS_MARQUEE) | 236 #if !defined(PBS_MARQUEE) |
227 # define PBS_MARQUEE 0x08 | 237 # define PBS_MARQUEE 0x08 |
228 #endif | 238 #endif |
229 #if !defined(PBM_SETMARQUEE) | 239 #if !defined(PBM_SETMARQUEE) |
1573 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 1583 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
1574 | 1584 |
1575 if(cinfo && cinfo->vcenter) | 1585 if(cinfo && cinfo->vcenter) |
1576 { | 1586 { |
1577 /* We are centered so calculate a new position */ | 1587 /* We are centered so calculate a new position */ |
1578 TCHAR tmpbuf[1024] = {0}; | 1588 TCHAR tmpbuf[1024] = {0}, *thisbuf = tmpbuf; |
1579 int textheight, diff, total = height; | 1589 int textheight, diff, total = height; |
1580 | 1590 |
1581 GetWindowText(handle, tmpbuf, 1023); | 1591 GetWindowText(handle, thisbuf, 1023); |
1582 | 1592 |
1583 /* Figure out how big the text is */ | 1593 /* Figure out how big the text is */ |
1584 dw_font_text_extents_get(handle, 0, WideToUTF8(tmpbuf), 0, &textheight); | 1594 dw_font_text_extents_get(handle, 0, WideToUTF8(thisbuf), 0, &textheight); |
1585 | 1595 |
1586 diff = (total - textheight) / 2; | 1596 diff = (total - textheight) / 2; |
1587 | 1597 |
1588 MoveWindow(handle, currentx + pad, currenty + pad + diff, | 1598 MoveWindow(handle, currentx + pad, currenty + pad + diff, |
1589 width, height - diff, FALSE); | 1599 width, height - diff, FALSE); |
2931 _wndproc(hWnd, msg, mp1, mp2); | 2941 _wndproc(hWnd, msg, mp1, mp2); |
2932 break; | 2942 break; |
2933 case WM_PAINT: | 2943 case WM_PAINT: |
2934 if(continfo->cinfo.pOldProc && (continfo->even != DW_RGB_TRANSPARENT || continfo->odd != DW_RGB_TRANSPARENT)) | 2944 if(continfo->cinfo.pOldProc && (continfo->even != DW_RGB_TRANSPARENT || continfo->odd != DW_RGB_TRANSPARENT)) |
2935 { | 2945 { |
2936 RECT rectUpd, rectDestin, rect; | 2946 RECT rectUpd, rectDestin, rectThis, *rect = &rectThis; |
2937 int iItems, iTop, i; | 2947 int iItems, iTop, i; |
2938 COLORREF c; | 2948 COLORREF c; |
2939 | 2949 |
2940 /* Load the default background color for the first pass */ | 2950 /* Load the default background color for the first pass */ |
2941 ListView_SetTextBkColor(hWnd, continfo->cinfo.back != -1 ? continfo->cinfo.back : ListView_GetBkColor(hWnd)); | 2951 ListView_SetTextBkColor(hWnd, continfo->cinfo.back != -1 ? continfo->cinfo.back : ListView_GetBkColor(hWnd)); |
2949 iTop = ListView_GetTopIndex(hWnd); | 2959 iTop = ListView_GetTopIndex(hWnd); |
2950 | 2960 |
2951 for(i=iTop; i<=(iTop+iItems+1); i++) | 2961 for(i=iTop; i<=(iTop+iItems+1); i++) |
2952 { | 2962 { |
2953 /* if row rectangle intersects update rectangle then it requires re-drawing */ | 2963 /* if row rectangle intersects update rectangle then it requires re-drawing */ |
2954 if(ListView_GetItemRect(hWnd, i, &rect, LVIR_BOUNDS) && IntersectRect(&rectDestin, &rectUpd, &rect)) | 2964 if(ListView_GetItemRect(hWnd, i, rect, LVIR_BOUNDS) && IntersectRect(&rectDestin, &rectUpd, rect)) |
2955 { | 2965 { |
2956 /* change text background colour accordingly */ | 2966 /* change text background colour accordingly */ |
2957 c = (i % 2) ? continfo->odd : continfo->even; | 2967 c = (i % 2) ? continfo->odd : continfo->even; |
2958 | 2968 |
2959 if(c != DW_RGB_TRANSPARENT) | 2969 if(c != DW_RGB_TRANSPARENT) |
4203 * ...: Additional variables for use in the format. | 4213 * ...: Additional variables for use in the format. |
4204 */ | 4214 */ |
4205 void API dw_debug(char *format, ...) | 4215 void API dw_debug(char *format, ...) |
4206 { | 4216 { |
4207 va_list args; | 4217 va_list args; |
4208 char outbuf[1025] = {0}; | 4218 char outbuf[1025] = {0}, *thisbuf = outbuf; |
4209 | 4219 |
4210 va_start(args, format); | 4220 va_start(args, format); |
4211 vsnprintf(outbuf, 1024, format, args); | 4221 vsnprintf(outbuf, 1024, format, args); |
4212 va_end(args); | 4222 va_end(args); |
4213 | 4223 |
4214 OutputDebugString(UTF8toWide(outbuf)); | 4224 OutputDebugString(UTF8toWide(thisbuf)); |
4215 } | 4225 } |
4216 | 4226 |
4217 /* | 4227 /* |
4218 * Displays a Message Box with given text and title.. | 4228 * Displays a Message Box with given text and title.. |
4219 * Parameters: | 4229 * Parameters: |
4222 * ...: Additional variables for use in the format. | 4232 * ...: Additional variables for use in the format. |
4223 */ | 4233 */ |
4224 int API dw_messagebox(char *title, int flags, char *format, ...) | 4234 int API dw_messagebox(char *title, int flags, char *format, ...) |
4225 { | 4235 { |
4226 va_list args; | 4236 va_list args; |
4227 char outbuf[1025] = { 0 }; | 4237 char outbuf[1025] = { 0 }, *thisbuf = outbuf; |
4228 int rc; | 4238 int rc; |
4229 | 4239 |
4230 va_start(args, format); | 4240 va_start(args, format); |
4231 vsnprintf(outbuf, 1024, format, args); | 4241 vsnprintf(outbuf, 1024, format, args); |
4232 va_end(args); | 4242 va_end(args); |
4233 | 4243 |
4234 rc = MessageBox(HWND_DESKTOP, UTF8toWide(outbuf), UTF8toWide(title), flags); | 4244 rc = MessageBox(HWND_DESKTOP, UTF8toWide(thisbuf), UTF8toWide(title), flags); |
4235 if(rc == IDOK) | 4245 if(rc == IDOK) |
4236 return DW_MB_RETURN_OK; | 4246 return DW_MB_RETURN_OK; |
4237 else if(rc == IDYES) | 4247 else if(rc == IDYES) |
4238 return DW_MB_RETURN_YES; | 4248 return DW_MB_RETURN_YES; |
4239 else if(rc == IDNO) | 4249 else if(rc == IDNO) |
11346 * | 11356 * |
11347 */ | 11357 */ |
11348 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) | 11358 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) |
11349 { | 11359 { |
11350 OPENFILENAME of = {0}; | 11360 OPENFILENAME of = {0}; |
11351 TCHAR filenamebuf[1001] = {0}; | 11361 TCHAR filenamebuf[1001] = {0}, *fbuf = filenamebuf; |
11352 TCHAR filterbuf[1001] = {0}; | 11362 TCHAR filterbuf[1001] = {0}; |
11353 TCHAR *exten = UTF8toWide(ext); | 11363 TCHAR *exten = UTF8toWide(ext); |
11354 TCHAR *dpath = UTF8toWide(defpath); | 11364 TCHAR *dpath = UTF8toWide(defpath); |
11355 int rc; | 11365 int rc; |
11356 | 11366 |
11393 (LPCTSTR)title, | 11403 (LPCTSTR)title, |
11394 (LPTSTR)filenamebuf, | 11404 (LPTSTR)filenamebuf, |
11395 1000, | 11405 1000, |
11396 FALSE ) ) | 11406 FALSE ) ) |
11397 { | 11407 { |
11398 return _strdup( WideToUTF8(filenamebuf) ); | 11408 return _strdup( WideToUTF8(fbuf) ); |
11399 } | 11409 } |
11400 #endif | 11410 #endif |
11401 } | 11411 } |
11402 else | 11412 else |
11403 { | 11413 { |
11648 * current user directory. Or the root directory (C:\ on | 11658 * current user directory. Or the root directory (C:\ on |
11649 * OS/2 and Windows). | 11659 * OS/2 and Windows). |
11650 */ | 11660 */ |
11651 char * API dw_user_dir(void) | 11661 char * API dw_user_dir(void) |
11652 { | 11662 { |
11653 static char _user_dir[1024] = ""; | 11663 static char _user_dir[1024] = {0}; |
11654 | 11664 |
11655 if(!_user_dir[0]) | 11665 if(!_user_dir[0]) |
11656 { | 11666 { |
11657 HANDLE hToken = 0; | 11667 HANDLE hToken = 0; |
11658 | 11668 |
11659 /* Use the Windows API to get the user's profile directory */ | 11669 /* Use the Windows API to get the user's profile directory */ |
11660 if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) | 11670 if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) |
11661 { | 11671 { |
11662 DWORD BufSize = 1024; | 11672 DWORD BufSize = 1024; |
11663 TCHAR Buf[1024]; | 11673 TCHAR TmpBuf[1024], *Buf = TmpBuf; |
11664 | 11674 |
11665 GetUserProfileDirectory(hToken, Buf, &BufSize); | 11675 GetUserProfileDirectory(hToken, Buf, &BufSize); |
11666 CloseHandle(hToken); | 11676 CloseHandle(hToken); |
11667 strncpy(_user_dir, WideToUTF8(Buf), 1023); | 11677 strncpy(_user_dir, WideToUTF8(Buf), 1023); |
11668 } | 11678 } |