Ignore:
Timestamp:
Mar 2, 2007, 2:57:09 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

#51完了

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/basic/prompt.sbp

    r123 r125  
    1313
    1414'text
     15
    1516Dim _PromptSys_LogFont As LOGFONTA 'LOGFONT
    1617Dim _PromptSys_hFont As HFONT
     
    2324Dim _PromptSys_TextColor[100] As *COLORREF
    2425Dim _PromptSys_BackColor[100] As *COLORREF
     26Dim _PromptSys_TextWidth[100] As Long
    2527Dim _PromptSys_NowTextColor As COLORREF
    2628Dim _PromptSys_NowBackColor As COLORREF
     
    4547Sub DrawPromptBuffer(hDC As HDC, StartLine As Long, EndLine As Long)
    4648    Dim i As Long, i2 As Long, i3 As Long
    47     Dim sz As SIZE
    48     Dim temporary[2] As Char
    4949
    5050    Dim hOldFont = SelectObject(hDC, _PromptSys_hFont) As HFONT
     
    5353    Dim rc As RECT
    5454    GetClientRect(_PromptSys_hWnd, rc)
    55     While (_PromptSys_CurPos.y+1)*_PromptSys_FontSize.cy>rc.bottom and _PromptSys_CurPos.y>0
     55    While (_PromptSys_CurPos.y+1) * _PromptSys_FontSize.cy > rc.bottom and _PromptSys_CurPos.y > 0
    5656        _System_free(_PromptSys_Buffer[0])
    5757        _System_free(_PromptSys_TextColor[0])
    5858        _System_free(_PromptSys_BackColor[0])
    59         For i=0 To 100-1
     59        For i = 0 To 100 - 1
    6060            _PromptSys_Buffer[i] = _PromptSys_Buffer[i+1]
    6161            _PromptSys_TextColor[i] = _PromptSys_TextColor[i+1]
    6262            _PromptSys_BackColor[i] = _PromptSys_BackColor[i+1]
     63            _PromptSys_TextWidth[i] = _PromptSys_TextWidth[i+1]
    6364        Next
    6465        _PromptSys_Buffer[100] = _System_calloc(SizeOf (Char) * 255)
    6566        _PromptSys_TextColor[100] = _System_calloc(SizeOf(COLORREF) * 255)
    6667        _PromptSys_BackColor[100] = _System_calloc(SizeOf(COLORREF) * 255)
     68        _PromptSys_TextWidth[100] = 0
    6769
    6870        _PromptSys_CurPos.y--
    6971
    7072        'Redraw
    71         StartLine=-1
     73        StartLine = -1
    7274    Wend
    7375
    74     i=0
    75     While i*_PromptSys_FontSize.cy<rc.bottom and i<=100
     76    i = 0
     77    While i * _PromptSys_FontSize.cy < rc.bottom and i <= 100
    7678        If StartLine=-1 or (StartLine<=i and i<=EndLine) Then
     79            Dim sz As SIZE
    7780            i3 = lstrlen(_PromptSys_Buffer[i])
    7881            GetTextExtentPoint32(hDC, _PromptSys_Buffer[i], i3, sz)
    7982
    8083            BitBlt(hDC,_
    81                 sz.cx, i*_PromptSys_FontSize.cy, _
     84                sz.cx, i * _PromptSys_FontSize.cy, _
    8285                rc.right, _PromptSys_FontSize.cy, _
    83                 _PromptSys_hMemDC,sz.cx,i*_PromptSys_FontSize.cy,SRCCOPY)
    84 
     86                _PromptSys_hMemDC, sz.cx, i * _PromptSys_FontSize.cy, SRCCOPY)
     87
     88            Dim width = 0 As Long
    8589            For i2 = 0 To i3-1
    8690                SetTextColor(hDC, _PromptSys_TextColor[i][i2])
     
    9296                End If
    9397
     98                Dim temporary[2] As Char
    9499                Dim tempLen As Long
    95                 temporary[0]=_PromptSys_Buffer[i][i2]
     100                temporary[0] = _PromptSys_Buffer[i][i2]
    96101#ifdef UNICODE
    97102                If _System_IsSurrogatePair(_PromptSys_Buffer[i][i2], _PromptSys_Buffer[i][i2+1]) Then
     
    108113                End If
    109114                With _PromptSys_FontSize
    110                     TextOut(hDC, i2 * .cx, i * .cy, temporary, tempLen)
     115                    TextOut(hDC, width, i * .cy, temporary, tempLen)
    111116                End With
     117                GetTextExtentPoint32(hDC, temporary, i3, sz)
     118                width += sz.cx
    112119            Next
    113120        End If
     
    150157            .x++
    151158        Loop
     159
    152160        'Draw the text buffer added
    153161        Dim hDC = GetDC(_PromptSys_hWnd)
     
    182190
    183191            Dim tm As TEXTMETRIC
    184             Dim hOldFont=SelectObject(_PromptSys_hMemDC, _PromptSys_hFont) As HFONT
     192            Dim hOldFont = SelectObject(_PromptSys_hMemDC, _PromptSys_hFont) As HFONT
    185193            GetTextExtentPoint32(_PromptSys_hMemDC, " " As PCTSTR, 1, _PromptSys_FontSize)
    186194            GetTextMetrics(_PromptSys_hMemDC, tm)
     
    190198            ReleaseDC(hWnd,hDC)
    191199        Case WM_PAINT
    192             hDC = BeginPaint(hWnd,ps)
     200            hDC = BeginPaint(hWnd, ps)
     201/*
    193202            With _PromptSys_ScreenSize
    194203                BitBlt(hDC, 0, 0, .cx, .cy, _PromptSys_hMemDC, 0, 0, SRCCOPY)
     204*/
     205            With ps.rcPaint
     206                BitBlt(hDC, .left, .top, .right - .left, .bottom - .top, _PromptSys_hMemDC, .left, .top, SRCCOPY)
    195207            End With
    196208            DrawPromptBuffer(hDC, -1, 0)
     
    270282                SendMessage(hWnd, WM_SETFOCUS, 0, 0)
    271283            End If
     284        Case WM_IME_COMPOSITION
     285            Return _PromptSys_OnImeCompostion(hWnd, wParam, lParam)
    272286        Case WM_DESTROY
    273287            DeleteDC(_PromptSys_hMemDC)
     
    282296End Function
    283297
     298Function _PromptSys_OnImeCompostion(hwnd As HWND, wp As WPARAM, lp As LPARAM) As LRESULT
     299    If (lp And GCS_RESULTSTR) <> 0 Then
     300        Dim himc = ImmGetContext(hwnd)
     301        If himc = 0 Then
     302            'Debug
     303            Return 0
     304        End If
     305        Dim size = ImmGetCompositionString(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
     306        Dim str = _System_malloc(size) As PTSTR
     307        If str = 0 Then
     308            'Debug
     309            Return 0
     310        End If
     311        ImmGetCompositionString(himc, GCS_RESULTSTR, str, size)
     312        ImmReleaseContext(hwnd, himc)
     313
     314        memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), str, size)
     315        _PromptSys_InputLen += size
     316
     317        Dim tempStr As String(str, size \ SizeOf (Char))
     318        _System_free(str)
     319
     320        SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
     321        PRINT_ToPrompt(tempStr)
     322        SendMessage(hwnd, WM_SETFOCUS, 0, 0)
     323
     324        Return 0
     325    Else
     326        Return DefWindowProc(hwnd, WM_IME_COMPOSITION, wp, lp)
     327    End If
     328End Function
     329
    284330Function PromptMain(dwData As Long) As Long
    285331    Dim i As Long
     
    297343
    298344    'Setup
    299     _PromptSys_ScreenSize.cx=GetSystemMetrics(SM_CXSCREEN)
    300     _PromptSys_ScreenSize.cy=GetSystemMetrics(SM_CYSCREEN)
     345    With _PromptSys_ScreenSize
     346        .cx = GetSystemMetrics(SM_CXSCREEN)
     347        .cy = GetSystemMetrics(SM_CYSCREEN)
     348    End With
    301349
    302350    'LogFont initialize
     
    315363        .lfQuality = DEFAULT_QUALITY
    316364        .lfPitchAndFamily = FIXED_PITCH
     365#ifdef UNICODE
     366        WideCharToMultiByte(CP_ACP, 0, "MS 明朝", 5, .lfFaceName, LF_FACESIZE, 0, 0)
     367#else
    317368        lstrcpy(.lfFaceName, "MS 明朝")
     369#endif
    318370    End With
    319371
    320     _PromptSys_hFont = CreateFontIndirect(ByVal VarPtr(_PromptSys_LogFont))
     372    _PromptSys_hFont = CreateFontIndirectA(ByVal VarPtr(_PromptSys_LogFont))
    321373
    322374    'Critical Section
     
    340392
    341393    'Create Prompt Window
    342     _PromptSys_hWnd=CreateWindowEx(WS_EX_CLIENTEDGE,atom As ULONG_PTR As PCSTR,"BASIC PROMPT",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,GetModuleHandle(0),0)
     394    _PromptSys_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, atom As ULONG_PTR As PCSTR, "BASIC PROMPT",
     395        WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
     396        0, 0, wcl.hInstance, 0)
    343397    ShowWindow(_PromptSys_hWnd, SW_SHOW)
    344398    UpdateWindow(_PromptSys_hWnd)
Note: See TracChangeset for help on using the changeset viewer.