Changeset 19

Show
Ignore:
Timestamp:
12/04/06 18:38:17 (2 years ago)
Author:
lindquist
Message:

Added new Windows functions. Improved GetTextExtentPoint?32X

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/minwin/mswindows.d

    r11 r19  
    3636export int LoadStringW(HINSTANCE inst, LPWSTR id, LPWSTR buf, int siz); 
    3737export int MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType); 
     38export int GetSystemMetrics(int nIndex); 
     39 
    3840/* 
    3941struct INITCOMMONCONTROLSEX { 
     
    488490export BOOL SwapBuffers(HDC); 
    489491 
     492const int SM_CXBORDER = 5; 
     493const int SM_CYBORDER = 5; 
     494const int SM_CXFIXEDFRAME = 7; 
     495const int SM_CYFIXEDFRAME = 8; 
     496const int SM_CXEDGE = 45; 
     497const int SM_CYEDGE= 46; 
     498const int SM_CXMENUCHECK = 71; 
     499const int SM_CYMENUCHECK = 72; 
     500 
    490501// 
    491502// these wrappers makes windows unicode look alot better and avoids excessive code duplication 
     
    529540    BOOL GetTextExtentPoint32X(HDC dc, char[] str, int len, SIZE* s) 
    530541    { 
    531         if (useWfuncs) 
    532         return GetTextExtentPoint32W(dc, toUTF16z(str), len, s); 
    533         else 
    534         return GetTextExtentPoint32A(dc, toMBSz(str), len, s); 
     542        if (useWfuncs) { 
     543            wchar[] wstr = toUTF16(str); 
     544            return GetTextExtentPoint32W(dc, wstr, wstr.length, s); 
     545        } else { 
     546            size_t al; 
     547            char* ansi = toMBSzl(str, al); 
     548            return GetTextExtentPoint32A(dc, ansi, al, s); 
     549        } 
    535550    } 
    536551 
     
    543558    } 
    544559} 
     560 
     561/****************************************** 
     562 * Converts the UTF-8 string s into a null-terminated string in a Windows 
     563 * 8-bit character set. 
     564 * 
     565 * Params: 
     566 * s = UTF-8 string to convert. 
     567 * reslen = the number of bytes in the resulting buffer 
     568 *   (not including the null terminator) will be place here. 
     569 * codePage = is the number of the target codepage, or 
     570 *   0 - ANSI, 
     571 *   1 - OEM, 
     572 *   2 - Mac 
     573 * 
     574 * Authors: 
     575 *  yaneurao, Walter Bright, Stewart Gordon 
     576 */ 
     577private import std.windows.syserror; 
     578char* toMBSzl(char[] s, out size_t reslen, uint codePage = 0) 
     579{ 
     580    // Only need to do this if any chars have the high bit set 
     581    foreach (char c; s) 
     582    { 
     583        if (c >= 0x80) 
     584        { 
     585            char[] result; 
     586            int readLen; 
     587            wchar* ws = std.utf.toUTF16z(s); 
     588            result.length = WideCharToMultiByte(codePage, 0, ws, -1, null, 0, 
     589            null, null); 
     590 
     591            if (result.length) 
     592            { 
     593            readLen = WideCharToMultiByte(codePage, 0, ws, -1, result.ptr, 
     594                result.length, null, null); 
     595            } 
     596 
     597            if (!readLen || readLen != result.length) 
     598            { 
     599            throw new Exception("Couldn't convert string: " ~ 
     600                sysErrorString(GetLastError())); 
     601            } 
     602 
     603            reslen = result.length ? result.length-1 : 0; 
     604            return result; 
     605        } 
     606    } 
     607    reslen = s.length; 
     608    return std.string.toStringz(s); 
     609}