Ignore:
Timestamp:
Mar 9, 2007, 10:15:34 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

Environment, OperatingSystem, Versionの追加、Unicode対応修正ほか

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/basic/prompt.sbp

    r137 r142  
    88#require <api_imm.sbp>
    99#require <Classes/System/Math.ab>
     10
     11Function _PromptSys_GetTextExtentPoint32(hdc As HDC, psz As PCSTR, cb As Long, ByRef Size As SIZE) As Long
     12    _PromptSys_GetTextExtentPoint32 = GetTextExtentPoint32A(hdc, psz, cb, Size)
     13End Function
     14
     15Function _PromptSys_GetTextExtentPoint32(hdc As HDC, psz As PCWSTR, cb As Long, ByRef Size As SIZE) As Long
     16    _PromptSys_GetTextExtentPoint32 = GetTextExtentPoint32W(hdc, psz, cb, Size)
     17End Function
     18
     19Function _PromptSys_TextOut(hdc As HDC, x As Long, y As Long, psz As PCSTR, cb As Long) As Long
     20    _PromptSys_TextOut = TextOutA(hdc, x, y, psz, cb)
     21End Function
     22
     23Function _PromptSys_TextOut(hdc As HDC, x As Long, y As Long, psz As PCWSTR, cb As Long) As Long
     24    _PromptSys_TextOut = TextOutW(hdc, x, y, psz, cb)
     25End Function
     26
     27Function _PromptSys_ImmGetCompositionString(himc As HIMC, index As DWord, pBuf As PSTR, bufLen As DWord) As Long
     28    _PromptSys_ImmGetCompositionString = ImmGetCompositionStringA(himc, index, pBuf, bufLen)
     29End Function
     30
     31Function _PromptSys_ImmGetCompositionString(himc As HIMC, index As DWord, pBuf As PWSTR, bufLen As DWord) As Long
     32    _PromptSys_ImmGetCompositionString = ImmGetCompositionStringW(himc, index, pBuf, bufLen)
     33End Function
    1034
    1135Dim _PromptSys_hWnd As HWND
     
    2246Type _PromptSys_LineInformation
    2347    Length As Long
    24     Text As *Char
     48    Text As *StrChar
    2549    CharInfo As *_PromptSys_CharacterInformation
    2650End Type
     
    2953Dim _PromptSys_hFont As HFONT
    3054Dim _PromptSys_FontSize As SIZE
    31 Dim _PromptSys_InputStr[255] As Char
     55Dim _PromptSys_InputStr[255] As StrChar
    3256Dim _PromptSys_InputLen As Long
    3357Dim _PromptSys_KeyChar As Byte
     
    3862Dim _PromptSys_SectionOfBufferAccess As CRITICAL_SECTION
    3963
     64Dim _System_OSVersionInfo As OSVERSIONINFO
    4065
    4166_PromptSys_InputLen = -1
     
    4873
    4974_PromptSys_hInitFinish = CreateEvent(0, FALSE, FALSE, 0)
    50 CreateThread(0, 0, AddressOf(PromptMain) As LPTHREAD_START_ROUTINE, 0, 0, _PromptSys_dwThreadID)
     75Dim _PromptSys_hThread As HANDLE
     76_PromptSys_hThread = CreateThread(0, 0, AddressOf(PromptMain) As LPTHREAD_START_ROUTINE, 0, 0, _PromptSys_dwThreadID)
     77If _PromptSys_hThread = 0 Then
     78    Debug
     79    ExitProcess(1)
     80End If
    5181WaitForSingleObject(_PromptSys_hInitFinish, INFINITE)
    5282
     
    6898        Next
    6999        _PromptSys_TextLine[100].Length = 0
    70         _PromptSys_TextLine[100].Text = _System_calloc(SizeOf (Char) * 255)
     100        _PromptSys_TextLine[100].Text = _System_calloc(SizeOf (StrChar) * 255)
    71101        _PromptSys_TextLine[100].CharInfo = _System_calloc(SizeOf (_PromptSys_CharacterInformation) * 255)
    72102        _PromptSys_CurPos.y--
     
    83113            Dim sz As SIZE
    84114            i3 = _PromptSys_TextLine[i].Length
    85             GetTextExtentPoint32(hDC, _PromptSys_TextLine[i].Text, i3, sz)
     115            _PromptSys_GetTextExtentPoint32(hDC, _PromptSys_TextLine[i].Text, i3, sz)
    86116
    87117            BitBlt(hDC,_
     
    106136                End If
    107137                With _PromptSys_FontSize
    108                     TextOut(hDC, currentLineCharInfo[i2].StartPos, i * .cy, VarPtr(_PromptSys_TextLine[i].Text[i2]), tempLen)
     138                    _PromptSys_TextOut(hDC, currentLineCharInfo[i2].StartPos, i * .cy, VarPtr(_PromptSys_TextLine[i].Text[i2]) As *StrChar, tempLen)
    109139                End With
    110140                i2 += tempLen
     
    127157        Dim doubleUnitChar = False As Boolean
    128158        'Addition
    129         Dim i2 = 0 As Long, i3 As Long' : Debug
     159        Dim i2 = 0 As Long, i3 As Long
    130160        For i2 = 0 To ELM(bufLen)
    131161            If buf[i2] = &h0d Then 'CR \r
     
    158188                            charLen = 1
    159189                        EndIf
    160                         GetTextExtentPoint32(hdc, VarPtr(buf.Chars[i2]), charLen, sz)
     190                        _PromptSys_GetTextExtentPoint32(hdc, VarPtr(buf.Chars[i2]) As *StrChar, charLen, sz)
    161191                        currentLineCharInfo[.x + 1].StartPos = currentLineCharInfo[.x].StartPos + sz.cx
    162192/*
     
    305335            TempStr = Ex"\r\n"
    306336        ElseIf wParam = &H16 Then
     337/*
    307338            'Paste Command(Use Clippboard)
    308339            OpenClipboard(hwnd)
     
    324355            GlobalUnlock(hGlobal)
    325356            CloseClipboard()
     357*/
    326358        Else
    327359            _PromptSys_InputStr[_PromptSys_InputLen] = wParam As Byte
     
    337369    End If
    338370End Sub
     371
     372Function _PromptWnd_GetCompositionStringW(himc As HIMC, ByRef rpsz As PWSTR) As Long
     373    Dim size = ImmGetCompositionStringW(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
     374    rpsz = _System_malloc(size) As PTSTR
     375    If rpsz = 0 Then
     376        'Debug
     377        Return 0
     378    End If
     379    Return ImmGetCompositionStringW(himc, GCS_RESULTSTR, rpsz, size)
     380End Function
     381
     382Function _PromptWnd_GetCompositionStringA(himc As HIMC, ByRef rpsz As PSTR) As Long
     383    Dim size = ImmGetCompositionStringA(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
     384    rpsz = _System_malloc(size) As PTSTR
     385    If rpsz = 0 Then
     386        'Debug
     387        Return 0
     388    End If
     389    Return ImmGetCompositionStringA(himc, GCS_RESULTSTR, rpsz, size)
     390End Function
    339391
    340392Function _PromptWnd_OnImeCompostion(hwnd As HWND, wp As WPARAM, lp As LPARAM) As LRESULT
     
    345397            Return 0
    346398        End If
    347         Dim size = ImmGetCompositionString(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
    348         Dim str = _System_malloc(size) As PTSTR
    349         If str = 0 Then
    350             'Debug
    351             Return 0
    352         End If
    353         ImmGetCompositionString(himc, GCS_RESULTSTR, str, size)
     399        Dim tempStr As String
     400        Dim str As *StrChar
     401#ifdef __STIRNG_IS_NOT_UNICODE
     402        Dim size = _PromptWnd_GetCompositionStringA(himc, str)
     403        tempStr.Assign(str, size)
     404#else
     405        With _System_OSVersionInfo
     406            ' GetCompositionStringW is not implimented in Windows 95
     407            If .dwMajorVersion = 4 And .dwMinorVersion = 0 And .dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
     408                Dim strA As PCSTR
     409                Dim sizeA = _PromptWnd_GetCompositionStringA(himc, strA)
     410                tempStr.AssignFromMultiByte(strA, sizeA)
     411            Else
     412                Dim size = _PromptWnd_GetCompositionStringW(himc, str)
     413                tempStr.Assign(str, size \ SizeOf (WCHAR))
     414            End If
     415        End With
     416#endif
    354417        ImmReleaseContext(hwnd, himc)
    355 
    356         memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), str, size)
    357         _PromptSys_InputLen += size \ SizeOf (Char)
    358 
    359         Dim tempStr As String(str, size \ SizeOf (Char))
    360418        _System_free(str)
    361419
    362         SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
     420        memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), tempStr.Chars, SizeOf (StrChar) * tempStr.Length)
     421        _PromptSys_InputLen += tempStr.Length
     422
     423        SendMessage(hwnd, WM_KILLFOCUS, 0, 0) : Debug
    363424        PRINT_ToPrompt(tempStr)
    364425        SendMessage(hwnd, WM_SETFOCUS, 0, 0)
     
    371432
    372433Function PromptMain(dwData As Long) As Long
     434    GetVersionEx(_System_OSVersionInfo)
     435
    373436    Dim i As Long
    374 
    375437    'Allocate
    376438    For i = 0 To 100
    377439        With _PromptSys_TextLine[i]
    378440            .Length = 0
    379             .Text = _System_calloc(SizeOf (Char) * 255)
     441            .Text = _System_calloc(SizeOf (StrChar) * 255)
    380442            .CharInfo = _System_calloc(SizeOf (_PromptSys_CharacterInformation) * 255)
    381443        End With
     
    515577'----------------------------------------------
    516578Sub INPUT_FromPrompt(ShowStr As String)
    517     Dim i As Long ,i2 As Long, i3 As Long
     579    Dim i As Long, i2 As Long, i3 As Long
    518580    Dim buf As String
    519581
Note: See TracChangeset for help on using the changeset viewer.