Changeset 125 for Include/basic


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

#51完了

Location:
Include/basic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Include/basic/function.sbp

    r123 r125  
    694694    Dim temp[255] As Char
    695695#ifdef _WIN64
    696     _sntprintf(temp, Len (temp) / SizeOf (Char), "%I64d", value)
     696    _sntprintf(temp, Len (temp) \ SizeOf (Char), "%I64d", value)
    697697#else
    698     _sntprintf(temp, Len (temp) / SizeOf (Char), "%d", value)
     698    _sntprintf(temp, Len (temp) \ SizeOf (Char), "%d", value)
    699699#endif
    700700    Str$ = temp
     
    10681068End Function
    10691069
    1070 Function _System_FillChar(p As *Char, n As SIZE_T, c As Char)
     1070Sub _System_FillChar(p As *Char, n As SIZE_T, c As Char)
    10711071    Dim i As SIZE_T
    10721072    For i = 0 To ELM(n)
    10731073        p[i] = c
    10741074    Next
     1075End Sub
     1076
     1077Function _System_ASCII_IsUpper(c As Char) As Boolean
     1078    Return c As DWord - &h41 < 26 ' &h41 = Asc("A")
     1079End Function
     1080
     1081Function _System_ASCII_IsLower(c As Char) As Boolean
     1082    Return c As DWord - &h61 < 26 ' &h61 = Asc("a")
     1083End Function
     1084
     1085Function _System_ASCII_ToLower(c As Char)
     1086    If _System_ASCII_IsUpper(c) Then
     1087        Return c Or &h20
     1088    Else
     1089        Return c
     1090    End If
     1091End Function
     1092
     1093Function _System_ASCII_ToUpper(c As Char)
     1094    If _System_ASCII_IsLower(c) Then
     1095        Return c And (Not &h20)
     1096    Else
     1097        Return c
     1098    End If
     1099End Function
     1100
     1101Function _System_WideCharToMultiByte(s As PCWSTR) As PSTR
     1102    Return _System_WideCharToMultiByte(s, lstrlenW(s) + 1, 0)
     1103End Function
     1104
     1105Function _System_WideCharToMultiByte(s As PCWSTR, size As Long) As PSTR
     1106    Return _System_WideCharToMultiByte(s, size, 0)
     1107End Function
     1108
     1109Function _System_WideCharToMultiByte(ws As PCWSTR, size As Long, flag As DWord) As PSTR
     1110    Dim sizeMBS = WideCharToMultiByte(CP_THREAD_ACP, flag, s, size, 0, 0, 0, 0)
     1111    Dim mbs = malloc(sizeMBS) As PSTR
     1112    WideCharToMultiByte(CP_THREAD_ACP, flag, s, size, mbs, sizeMBS, 0, 0)
     1113    Return mbs
     1114End Function
     1115
     1116Function _System_MultiByteToWideChar(s As PCSTR) As PWSTR
     1117    Return _System_MultiByteToWideChar(s, lstrlenA(s) + 1, 0)
     1118End Function
     1119
     1120Function _System_MultiByteToWideChar(s As PCSTR, size As Long) As PWSTR
     1121    Return _System_MultiByteToWideChar(s, size, 0)
     1122End Function
     1123
     1124Function _System_MultiByteToWideChar(s As PCSTR, size As Long, flag As DWord) As PWSTR
     1125    Dim sizeMBS = MultiByteToWideChar(CP_THREAD_ACP, flag, s, size, 0, 0)
     1126    Dim mbs = malloc(SizeOf (WCHAR) * sizeMBS) As PWSTR
     1127    MultiByteToWideChar(CP_THREAD_ACP, flag, s, size, mbs, sizeMBS)
     1128    Return mbs
    10751129End Function
    10761130
  • 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.