source: Include/basic/prompt.sbp@ 269

Last change on this file since 269 was 269, checked in by イグトランス (egtra), 18 years ago

basicディレクトリの一部の_System関数をActiveBasic名前空間へ入れた

File size: 27.5 KB
Line 
1'prompt.sbp
2
3
4#ifndef _INC_PROMPT
5#define _INC_PROMPT
6
7#require <api_imm.sbp>
8#require <Classes/System/Math.ab>
9#require <Classes/System/Environment.ab>
10
11Namespace ActiveBasic
12Namespace Prompt
13Namespace Detail
14
15Function _PromptSys_GetTextExtentPoint32(hdc As HDC, psz As PCSTR, cb As Long, ByRef Size As SIZE) As Long
16 _PromptSys_GetTextExtentPoint32 = GetTextExtentPoint32A(hdc, psz, cb, Size)
17End Function
18
19Function _PromptSys_GetTextExtentPoint32(hdc As HDC, psz As PCWSTR, cb As Long, ByRef Size As SIZE) As Long
20 _PromptSys_GetTextExtentPoint32 = GetTextExtentPoint32W(hdc, psz, cb, Size)
21End Function
22
23Function _PromptSys_TextOut(hdc As HDC, x As Long, y As Long, psz As PCSTR, cb As Long) As Long
24 _PromptSys_TextOut = TextOutA(hdc, x, y, psz, cb)
25End Function
26
27Function _PromptSys_TextOut(hdc As HDC, x As Long, y As Long, psz As PCWSTR, cb As Long) As Long
28 _PromptSys_TextOut = TextOutW(hdc, x, y, psz, cb)
29End Function
30
31Function _PromptSys_ImmGetCompositionString(himc As HIMC, index As DWord, pBuf As PSTR, bufLen As DWord) As Long
32 _PromptSys_ImmGetCompositionString = ImmGetCompositionStringA(himc, index, pBuf, bufLen)
33End Function
34
35Function _PromptSys_ImmGetCompositionString(himc As HIMC, index As DWord, pBuf As PWSTR, bufLen As DWord) As Long
36 _PromptSys_ImmGetCompositionString = ImmGetCompositionStringW(himc, index, pBuf, bufLen)
37End Function
38
39Dim _PromptSys_hWnd As HWND
40Dim _PromptSys_dwThreadID As DWord
41Dim _PromptSys_hInitFinish As HANDLE
42
43'text
44Type _PromptSys_CharacterInformation
45 ForeColor As COLORREF
46 BackColor As COLORREF
47 StartPos As Long
48End Type
49
50Type _PromptSys_LineInformation
51 Length As Long
52 Text As *StrChar
53 CharInfo As *_PromptSys_CharacterInformation
54End Type
55
56Dim _PromptSys_hFont As HFONT
57Dim _PromptSys_FontSize As SIZE
58Dim _PromptSys_InputStr[255] As StrChar
59Dim _PromptSys_InputLen = -1 As Long
60Dim _PromptSys_KeyChar As Byte
61Dim _PromptSys_CurPos As POINTAPI
62Dim _PromptSys_TextLine[100] As _PromptSys_LineInformation
63Dim _PromptSys_NowTextColor As COLORREF
64Dim _PromptSys_NowBackColor As COLORREF
65Dim _PromptSys_SectionOfBufferAccess As CRITICAL_SECTION
66
67Dim _System_OSVersionInfo As OSVERSIONINFO
68
69
70'graphic
71Dim _PromptSys_hBitmap As HBITMAP
72Dim _PromptSys_hMemDC As HDC
73Dim _PromptSys_ScreenSize As SIZE
74Dim _PromptSys_GlobalPos As POINTAPI
75
76Sub _PromptSys_Initialize()
77_PromptSys_hInitFinish = CreateEvent(0, FALSE, FALSE, 0)
78Dim _PromptSys_hThread = CreateThread(0, 0, AddressOf(PromptMain), 0, 0, _PromptSys_dwThreadID)
79If _PromptSys_hThread = 0 Then
80 Debug
81 ExitProcess(1)
82End If
83WaitForSingleObject(_PromptSys_hInitFinish, INFINITE)
84End Sub
85
86Sub DrawPromptBuffer(hDC As HDC, StartLine As Long, EndLine As Long)
87 Dim i As Long, i2 As Long, i3 As Long
88
89 Dim hOldFont = SelectObject(hDC, _PromptSys_hFont) As HFONT
90
91 'Scroll
92 Dim rc As RECT
93 GetClientRect(_PromptSys_hWnd, rc)
94 While (_PromptSys_CurPos.y+1) * _PromptSys_FontSize.cy > rc.bottom and _PromptSys_CurPos.y > 0
95 _System_free(_PromptSys_TextLine[0].Text)
96 _System_free(_PromptSys_TextLine[0].CharInfo)
97 For i = 0 To 100 - 1
98 _PromptSys_TextLine[i].Length = _PromptSys_TextLine[i+1].Length
99 _PromptSys_TextLine[i].Text = _PromptSys_TextLine[i+1].Text
100 _PromptSys_TextLine[i].CharInfo = _PromptSys_TextLine[i+1].CharInfo
101 Next
102 _PromptSys_TextLine[100].Length = 0
103 _PromptSys_TextLine[100].Text = _System_calloc(SizeOf (StrChar) * 255)
104 _PromptSys_TextLine[100].CharInfo = _System_calloc(SizeOf (_PromptSys_CharacterInformation) * 255)
105 _PromptSys_CurPos.y--
106
107 'Redraw
108 StartLine = -1
109 Wend
110
111 i = 0' : Debug
112 While i * _PromptSys_FontSize.cy < rc.bottom and i <= 100
113 If StartLine=-1 or (StartLine<=i and i<=EndLine) Then
114 Dim currentLineCharInfo = _PromptSys_TextLine[i].CharInfo
115
116 Dim sz As SIZE
117 i3 = _PromptSys_TextLine[i].Length
118 _PromptSys_GetTextExtentPoint32(hDC, _PromptSys_TextLine[i].Text, i3, sz)
119
120 BitBlt(hDC,_
121 sz.cx, i * _PromptSys_FontSize.cy, _
122 rc.right, _PromptSys_FontSize.cy, _
123 _PromptSys_hMemDC, sz.cx, i * _PromptSys_FontSize.cy, SRCCOPY)
124
125 While i2 < i3
126 SetTextColor(hDC, currentLineCharInfo[i2].ForeColor)
127 If currentLineCharInfo[i2].BackColor = -1 Then
128 SetBkMode(hDC, TRANSPARENT)
129 Else
130 SetBkMode(hDC, OPAQUE)
131 SetBkColor(hDC, currentLineCharInfo[i2].BackColor)
132 End If
133
134 Dim tempLen As Long
135 If _System_IsDoubleUnitChar(_PromptSys_TextLine[i].Text[i2], _PromptSys_TextLine[i].Text[i2+1]) Then
136 tempLen = 2
137 Else
138 tempLen = 1
139 End If
140 With _PromptSys_FontSize
141 _PromptSys_TextOut(hDC, currentLineCharInfo[i2].StartPos, i * .cy, VarPtr(_PromptSys_TextLine[i].Text[i2]) As *StrChar, tempLen)
142 End With
143 i2 += tempLen
144 Wend
145 End If
146
147 i++
148 Wend
149
150 SelectObject(hDC, hOldFont)
151End Sub
152
153Sub PRINT_ToPrompt(buf As String)
154 EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
155 With _PromptSys_CurPos
156 Dim hdc = GetDC(_PromptSys_hWnd)
157 Dim hOldFont = SelectObject(hdc, _PromptSys_hFont)
158 Dim StartLine As Long : StartLine = .y
159 Dim bufLen = buf.Length
160 Dim doubleUnitChar = False As Boolean
161 'Addition
162 Dim i2 = 0 As Long, i3 As Long
163 For i2 = 0 To ELM(bufLen)
164 If buf[i2] = &h0d Then 'CR \r
165 _PromptSys_TextLine[.y].Length = .x
166 .x = 0
167 ElseIf buf[i2] = &h0a Then 'LF \n
168 _PromptSys_TextLine[.y].Length = System.Math.Max(_PromptSys_TextLine[.y].Length, .x)
169 .y++
170 Else
171 Dim currentLineCharInfo = _PromptSys_TextLine[.y].CharInfo
172 _PromptSys_TextLine[.y].Text[.x] = buf[i2]
173 currentLineCharInfo[.x].ForeColor = _PromptSys_NowTextColor
174 currentLineCharInfo[.x].BackColor = _PromptSys_NowBackColor
175
176 If buf[i2] = &h09 Then 'tab
177 Dim tabStop = _PromptSys_FontSize.cx * 8
178 currentLineCharInfo[.x + 1].StartPos = currentLineCharInfo[.x].StartPos + _
179 tabStop - currentLineCharInfo[.x].StartPos Mod tabStop
180 Else
181 If doubleUnitChar <> False Then
182 doubleUnitChar = False
183 currentLineCharInfo[.x + 1].StartPos = currentLineCharInfo[.x].StartPos
184 Else
185 Dim sz As SIZE
186 Dim charLen As Long
187 If _System_IsDoubleUnitChar(buf[i2], buf[i2 + 1]) Then
188 charLen = 2
189 doubleUnitChar = True
190 Else
191 charLen = 1
192 EndIf
193 _PromptSys_GetTextExtentPoint32(hdc, VarPtr(buf.Chars[i2]) As *StrChar, charLen, sz)
194 currentLineCharInfo[.x + 1].StartPos = currentLineCharInfo[.x].StartPos + sz.cx
195/*
196 Dim buf[1023] As Char
197 wsprintf(buf, Ex"%d %d\r\n", currentLineCharInfo[.x + 1].StartPos, currentLineCharInfo[.x].StartPos + sz.cx)
198 OutputDebugString(buf)
199*/
200 End If
201 End If
202 .x++
203 End If
204 Next
205 _PromptSys_TextLine[.y].Length = System.Math.Max(_PromptSys_TextLine[.y].Length, .x)
206
207 'Draw the text buffer added
208 DrawPromptBuffer(hdc, StartLine, .y)
209 SelectObject(hdc, hOldFont)
210 ReleaseDC(_PromptSys_hWnd, hdc)
211 End With
212 LeaveCriticalSection(_PromptSys_SectionOfBufferAccess)
213End Sub
214
215Function PromptProc(hWnd As HWND, message As DWord, wParam As WPARAM, lParam As LPARAM) As LRESULT
216 Select Case message
217 Case WM_CREATE
218 Return _PromptWnd_OnCreate(hWnd, ByVal lParam As *CREATESTRUCT)
219 Case WM_PAINT
220 _PromptWnd_OnPaint(hWnd)
221 Case WM_SETFOCUS
222 _PromptWnd_OnSetFocus(hWnd, wParam As HWND)
223 Case WM_KILLFOCUS
224 _PromptWnd_OnKillForcus(hWnd, wParam As HWND)
225 Case WM_KEYDOWN
226 _PromptWnd_OnKeyDown(wParam As DWord, LOWORD(lParam) As DWord, HIWORD(lParam) As DWord)
227 Case WM_CHAR
228 _PromptWnd_OnChar(hWnd, wParam, lParam)
229 Case WM_IME_COMPOSITION
230 Return _PromptWnd_OnImeCompostion(hWnd, wParam, lParam)
231 Case WM_DESTROY
232 _PromptWnd_OnDestroy(hWnd)
233 Case Else
234 PromptProc = DefWindowProc(hWnd, message, wParam, lParam)
235 Exit Function
236 End Select
237 PromptProc = 0
238End Function
239
240Function _PromptWnd_OnCreate(hwnd As HWND, ByRef cs As CREATESTRUCT) As LRESULT
241 Dim hdc = GetDC(hwnd)
242 With _PromptSys_ScreenSize
243 _PromptSys_hBitmap = CreateCompatibleBitmap(hdc, .cx, .cy)
244 End With
245 _PromptSys_hMemDC = CreateCompatibleDC(hdc)
246 SelectObject(_PromptSys_hMemDC, _PromptSys_hBitmap)
247
248 'Initialize for Win9x
249 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, GetStockObject(BLACK_BRUSH)) As HBRUSH
250 With _PromptSys_ScreenSize
251 PatBlt(_PromptSys_hMemDC, 0, 0, .cx, .cy, PATCOPY)
252 End With
253 SelectObject(_PromptSys_hMemDC, hOldBrush)
254
255 Dim tm As TEXTMETRIC
256 Dim hOldFont = SelectObject(_PromptSys_hMemDC, _PromptSys_hFont) As HFONT
257 GetTextMetrics(_PromptSys_hMemDC, tm)
258 SelectObject(_PromptSys_hMemDC, hOldFont)
259 With _PromptSys_FontSize
260 .cx = tm.tmAveCharWidth
261 .cy = tm.tmHeight
262 End With
263
264 ReleaseDC(hwnd, hdc)
265
266 _PromptWnd_OnCreate = 0
267End Function
268
269Sub _PromptWnd_OnPaint(hwnd As HWND)
270 Dim ps As PAINTSTRUCT
271 Dim hdc = BeginPaint(hwnd, ps)
272 With _PromptSys_ScreenSize
273 BitBlt(hdc, 0, 0, .cx, .cy, _PromptSys_hMemDC, 0, 0, SRCCOPY)
274' With ps.rcPaint
275' BitBlt(hdc, .left, .top, .right - .left, .bottom - .top, _PromptSys_hMemDC, .left, .top, SRCCOPY)
276 End With
277 DrawPromptBuffer(hdc, -1, 0)
278 EndPaint(hwnd, ps)
279End Sub
280
281Sub _PromptWnd_OnSetFocus(hwnd As HWND, hwndOldFocus As HWND)
282 If _PromptSys_InputLen <> -1 Then
283 Dim himc = ImmGetContext(hwnd)
284 If himc Then
285 Dim CompForm As COMPOSITIONFORM
286 With CompForm
287 .dwStyle = CFS_POINT
288 .ptCurrentPos.x = _PromptSys_CurPos.x * _PromptSys_FontSize.cx
289 .ptCurrentPos.y = _PromptSys_CurPos.y * _PromptSys_FontSize.cy
290 End With
291 ImmSetCompositionWindow(himc, CompForm)
292
293 Dim lf As LOGFONT
294 GetObject(_PromptSys_hFont, Len(lf), lf)
295 ImmSetCompositionFont(himc, lf)
296 End If
297 ImmReleaseContext(hwnd, himc)
298
299 CreateCaret(hwnd, 0, 9, 6)
300 With _PromptSys_CurPos
301 SetCaretPos(_PromptSys_TextLine[.y].CharInfo[.x].StartPos, (.y + 1) * _PromptSys_FontSize.cy - 7)
302 End With
303 ShowCaret(hwnd)
304 End If
305End Sub
306
307Sub _PromptWnd_OnKillForcus(hwnd As HWND, hwndNewFocus As HWND)
308 HideCaret(hwnd)
309 DestroyCaret()
310End Sub
311
312Sub _PromptWnd_OnKeyDown(vk As DWord, repeat As DWord, flags As DWord)
313 If _PromptSys_InputLen = -1 Then
314 _PromptSys_KeyChar = vk As Byte
315 End If
316End Sub
317
318Sub _PromptWnd_OnDestroy(hwnd As HWND)
319 DeleteDC(_PromptSys_hMemDC)
320 DeleteObject(_PromptSys_hBitmap)
321
322 PostQuitMessage(0)
323End Sub
324
325Sub _PromptWnd_OnChar(hwnd As HWND, wParam As WPARAM, lParam As LPARAM)
326 Dim TempStr As String
327 If _PromptSys_InputLen <> -1 Then
328 If wParam = VK_BACK Then
329 If _PromptSys_InputLen Then
330 _PromptSys_InputLen--
331 _PromptSys_InputStr[_PromptSys_InputLen] = 0
332
333 _PromptSys_CurPos.x--
334 With _PromptSys_CurPos
335 _PromptSys_TextLine[.y].Text[.x] = 0
336 End With
337 End If
338 ElseIf wParam = VK_RETURN Then
339 _PromptSys_InputStr[_PromptSys_InputLen] = 0
340 _PromptSys_InputLen = -1
341 TempStr = Ex"\r\n"
342 ElseIf wParam = &H16 Then
343/*
344 'Paste Command(Use Clippboard)
345 OpenClipboard(hwnd)
346 Dim hGlobal = GetClipboardData(CF_TEXT) As HGLOBAL
347 If hGlobal = 0 Then Exit Sub
348 Dim pTemp = GlobalLock(hGlobal) As PCSTR
349#ifdef UNICODE 'A版ウィンドウプロシージャ用
350 Dim tempSizeA = lstrlenA(pTemp)
351 Dim tempSizeW = MultiByteToWideChar(CP_ACP, 0, pTemp, tempSizeA, 0, 0) + 1
352 TempStr = ZeroString(tempSizeW)
353 MultiByteToWideChar(CP_ACP, 0, pTemp, tempSizeA, StrPtr(TempStr), tempSizeW)
354#else
355 TempStr = ZeroString(lstrlen(pTemp) + 1)
356 lstrcpy(StrPtr(TempStr), pTemp)
357#endif
358 memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), TempStr.Chars, SizeOf (Char) * TempStr.Length)
359 _PromptSys_InputLen += TempStr.Length
360
361 GlobalUnlock(hGlobal)
362 CloseClipboard()
363*/
364 Else
365 _PromptSys_InputStr[_PromptSys_InputLen] = wParam As Byte
366 _PromptSys_InputLen++
367
368 TempStr.ReSize(1)
369 TempStr[0] = wParam As Char
370 End If
371
372 SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
373 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(TempStr)
374 SendMessage(hwnd, WM_SETFOCUS, 0, 0)
375 End If
376End Sub
377
378Function _PromptWnd_GetCompositionStringW(himc As HIMC, ByRef rpsz As PWSTR) As Long
379 Dim size = ImmGetCompositionStringW(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
380 rpsz = _System_malloc(size) As PWSTR
381 If rpsz = 0 Then
382 'Debug
383 Return 0
384 End If
385 Return ImmGetCompositionStringW(himc, GCS_RESULTSTR, rpsz, size)
386End Function
387
388Function _PromptWnd_GetCompositionStringA(himc As HIMC, ByRef rpsz As PSTR) As Long
389 Dim size = ImmGetCompositionStringA(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
390 rpsz = _System_malloc(size) As PSTR
391 If rpsz = 0 Then
392 'Debug
393 Return 0
394 End If
395 Return ImmGetCompositionStringA(himc, GCS_RESULTSTR, rpsz, size)
396End Function
397
398Function _PromptWnd_OnImeCompostion(hwnd As HWND, wp As WPARAM, lp As LPARAM) As LRESULT
399 If (lp And GCS_RESULTSTR) <> 0 Then
400 Dim himc = ImmGetContext(hwnd)
401 If himc = 0 Then
402 'Debug
403 Return 0
404 End If
405 Dim tempStr As String
406 Dim str As *StrChar
407#ifdef __STRING_IS_NOT_UNICODE
408 Dim size = _PromptWnd_GetCompositionStringA(himc, str)
409 tempStr.Assign(str, size)
410#else
411 Dim osver = System.Environment.OSVersion
412 With osver
413 ' GetCompositionStringW is not implimented in Windows 95
414 If .Version.Major = 4 And .Version.Minor = 0 And .Platform = System.PlatformID.Win32Windows Then
415 Dim strA As PCSTR
416 Dim sizeA = _PromptWnd_GetCompositionStringA(himc, strA)
417 tempStr.AssignFromMultiByte(strA, sizeA)
418 Else
419 Dim size = _PromptWnd_GetCompositionStringW(himc, str)
420 tempStr.Assign(str, size \ SizeOf (WCHAR))
421 End If
422 End With
423#endif
424 ImmReleaseContext(hwnd, himc)
425 _System_free(str)
426
427 memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), tempStr.Chars, SizeOf (StrChar) * tempStr.Length)
428 _PromptSys_InputLen += tempStr.Length
429
430 SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
431 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(tempStr)
432 SendMessage(hwnd, WM_SETFOCUS, 0, 0)
433
434 _PromptWnd_OnImeCompostion = 0
435 Else
436 _PromptWnd_OnImeCompostion = DefWindowProc(hwnd, WM_IME_COMPOSITION, wp, lp)
437 End If
438End Function
439
440Function PromptMain(dwData As Long) As Long
441 GetVersionEx(_System_OSVersionInfo)
442
443 Dim i As Long
444 'Allocate
445 For i = 0 To 100
446 With _PromptSys_TextLine[i]
447 .Length = 0
448 .Text = _System_calloc(SizeOf (StrChar) * 255)
449 .CharInfo = _System_calloc(SizeOf (_PromptSys_CharacterInformation) * 255)
450 End With
451 Next
452
453 'Current Colors initialize
454 _PromptSys_NowTextColor = RGB(255, 255, 255)
455 _PromptSys_NowBackColor = RGB(0, 0, 0)
456
457 'Setup
458 With _PromptSys_ScreenSize
459 .cx = GetSystemMetrics(SM_CXSCREEN)
460 .cy = GetSystemMetrics(SM_CYSCREEN)
461 End With
462
463 '_PromptSys_hFont initialize
464 Dim lf As LOGFONT
465 With lf
466 .lfHeight = -16
467 .lfWidth = 0
468 .lfEscapement = 0
469 .lfOrientation = 0
470 .lfWeight = 0
471 .lfItalic = 0
472 .lfUnderline = 0
473 .lfStrikeOut = 0
474 .lfCharSet = SHIFTJIS_CHARSET
475 .lfOutPrecision = OUT_DEFAULT_PRECIS
476 .lfClipPrecision = CLIP_DEFAULT_PRECIS
477 .lfQuality = DEFAULT_QUALITY
478 .lfPitchAndFamily = FIXED_PITCH
479 lstrcpy(.lfFaceName, ToTCStr("MS 明朝"))
480 End With
481
482 _PromptSys_hFont = CreateFontIndirect(lf)
483
484 'Critical Section
485 InitializeCriticalSection(_PromptSys_SectionOfBufferAccess)
486
487 'Regist Prompt Class
488 Dim wcl As WNDCLASSEX
489 ZeroMemory(VarPtr(wcl), Len(wcl))
490 With wcl
491 .cbSize = Len(wcl)
492 .hInstance = GetModuleHandle(0)
493 .style = CS_HREDRAW Or CS_VREDRAW' or CS_DBLCLKS
494 .hIcon = LoadImage(0, MAKEINTRESOURCE(IDI_APPLICATION), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE Or LR_SHARED) As HICON
495 .hIconSm = LoadImage(0, MAKEINTRESOURCE(IDI_WINLOGO), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE Or LR_SHARED) As HICON
496 .hCursor = LoadImage(0, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE Or LR_SHARED) As HCURSOR
497 .lpszClassName = ToTCStr("PROMPT")
498 .lpfnWndProc = AddressOf(PromptProc)
499 .hbrBackground = GetStockObject(BLACK_BRUSH)
500 End With
501 Dim atom = RegisterClassEx(wcl)
502
503 'Create Prompt Window
504 _PromptSys_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, atom As ULONG_PTR As LPCTSTR, ToTCStr("BASIC PROMPT"), _
505 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _
506 0, 0, wcl.hInstance, 0)
507 ShowWindow(_PromptSys_hWnd, SW_SHOW)
508 UpdateWindow(_PromptSys_hWnd)
509 SetEvent(_PromptSys_hInitFinish)
510 Dim msg As MSG
511 Do
512 Dim iResult = GetMessage(msg, 0, 0, 0)
513 If iResult = 0 Then
514 System.Environment.ExitCode = msg.wParam As Long
515 Exit Do
516 ElseIf iResult = -1 Then
517 Exit Do
518 End If
519 TranslateMessage(msg)
520 DispatchMessage(msg)
521 Loop
522
523 '強制的に終了する
524 End
525
526 EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
527
528 For i = 0 to 100
529 _System_free(_PromptSys_TextLine[i].Text)
530 _System_free(_PromptSys_TextLine[i].CharInfo)
531 Next
532
533 LeaveCriticalSection(_PromptSys_SectionOfBufferAccess)
534
535 DeleteCriticalSection(_PromptSys_SectionOfBufferAccess)
536
537 End
538End Function
539
540'Prompt text command functoins
541
542Sub Cls(n As Long)
543 Dim i As Long
544
545 'When parameter was omitted, num is set to 1
546 If n = 0 Then n = 1
547
548 If n = 1 Or n = 3 Then
549 'Clear the text screen
550 For i = 0 To 100
551 With _PromptSys_TextLine[i]
552 .Text[0] = 0 '_System_FillChar(_PromptSys_TextLine[i].Text, -1 As StrChar, 0)
553 .Length = 0
554 End With
555 Next
556 With _PromptSys_CurPos
557 .x = 0
558 .y = 0
559 End With
560 End If
561
562 If n = 2 Or n = 3 Then
563 'Clear the graphics screen
564 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, GetStockObject(BLACK_BRUSH))
565 With _PromptSys_ScreenSize
566 PatBlt(_PromptSys_hMemDC, 0, 0, .cx, .cy, PATCOPY)
567 End With
568 SelectObject(_PromptSys_hMemDC, hOldBrush)
569 End If
570
571 'Redraw
572 InvalidateRect(_PromptSys_hWnd, ByVal 0, 0)
573End Sub
574
575Sub Color(textColorCode As Long, backColorCode As Long)
576 _PromptSys_NowTextColor = GetBasicColor(textColorCode)
577 If backColorCode = -1 Then
578 _PromptSys_NowBackColor = -1
579 Else
580 _PromptSys_NowBackColor = GetBasicColor(backColorCode)
581 End If
582End Sub
583
584Sub INPUT_FromPrompt(showStr As String)
585 Dim i As Long, i2 As Long, i3 As Long
586 Dim buf As String
587
588*InputReStart
589
590 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(showStr)
591
592 'Input by keyboard
593 _PromptSys_InputLen = 0
594 SendMessage(_PromptSys_hWnd, WM_SETFOCUS, 0, 0)
595 While _PromptSys_InputLen <> -1
596 Sleep(10)
597 Wend
598 SendMessage(_PromptSys_hWnd, WM_KILLFOCUS, 0, 0)
599
600 'Set value to variable
601 i = 0
602 i2 = 0
603 buf = ZeroString(lstrlen(_PromptSys_InputStr))
604 While 1
605 i3 = 0
606 While 1
607 If _PromptSys_InputStr[i2] = &h2c Then
608 buf.Chars[i3] = 0
609 Exit While
610 End If
611
612 buf.Chars[i3] = _PromptSys_InputStr[i2]
613
614 If _PromptSys_InputStr[i2] = 0 Then Exit While
615
616 i2++
617 i3++
618 Wend
619
620 _System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], buf, i3)
621
622 i++
623 If _System_InputDataPtr[i] = 0 and _PromptSys_InputStr[i2] = &h2c Then 'Asc(",")
624 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
625 Goto *InputReStart
626 ElseIf _PromptSys_InputStr[i2] = 0 Then
627 If _System_InputDataPtr[i]<>0 Then
628 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n")
629 Goto *InputReStart
630 Else
631 Exit While
632 End If
633 End If
634
635 i2++
636 Wend
637End Sub
638
639Sub Locate(x As Long, y As Long)
640 If x < 0 Then x = 0
641 If y < 0 Then y = 0
642 If y > 100 Then y = 100
643 With _PromptSys_CurPos
644 .x = x
645 .y = y
646 End With
647
648 Dim i = _PromptSys_TextLine[y].Length
649 If i < x Then
650 _System_FillChar(VarPtr(_PromptSys_TextLine[y].Text[i]), x - i, &h20 As StrChar) 'Asc(" ")
651 Dim i2 As Long
652 For i2 = i To ELM(x)
653 _PromptSys_TextLine[y].CharInfo[i2].BackColor = -1
654 Next
655 _PromptSys_TextLine[y].Length = x
656 End If
657End Sub
658
659'Prompt graphic command functions
660
661Sub Circle(x As Long , y As Long, radius As Long, ColorCode As Long, StartPos As Double, EndPos As Double, Aspect As Double, bFill As Long, BrushColor As Long)
662 Dim i1 As Long, i2 As Long, i3 As Long, i4 As Long
663
664 Dim hPen = CreatePen(PS_SOLID,1,GetBasicColor(ColorCode))
665 Dim hBrush As HBRUSH
666 If bFill Then
667 hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
668 Else
669 hBrush = GetStockObject(NULL_BRUSH)
670 End If
671
672 Dim hDC = GetDC(_PromptSys_hWnd)
673 Dim hOldPenDC = SelectObject(hDC, hPen)
674 Dim hOldBrushDC = SelectObject(hDC, hBrush)
675 Dim hOldPen = SelectObject(_PromptSys_hMemDC, hPen)
676 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
677
678 Dim radi2 As Long
679 If Aspect<1 Then
680 radi2=(CDbl(radius)*Aspect) As Long
681 Else
682 radi2=radius
683 radius=(CDbl(radius)/Aspect) As Long
684 End If
685
686 If StartPos=0 And EndPos=0 Then
687 Ellipse(hDC,x-radius,y-radi2,x+radius,y+radi2)
688 Ellipse(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2)
689 Else
690 Dim sw As Long
691 StartPos *=StartPos
692 EndPos *=EndPos
693
694 If StartPos<0 Or EndPos<0 Then
695 sw=1
696 Else
697 sw=0
698 End If
699
700 StartPos = Abs(StartPos)
701 EndPos = Abs(EndPos)
702
703 If StartPos<=78.5 Then
704 i1=78
705 i2=Int(StartPos)
706 ElseIf StartPos<=235.5 Then
707 StartPos -= 78.5
708 i1=78-Int(StartPos)
709 i2=78
710 ElseIf StartPos<=392.5 Then
711 StartPos -= 235.5
712 i1=-78
713 i2=78-Int(StartPos)
714 ElseIf StartPos<=549.5 Then
715 StartPos -= 392.5
716 i1=-78+Int(StartPos)
717 i2=-78
718 ElseIf StartPos<=628 Then
719 StartPos -= 549.5
720 i1=78
721 i2=-78+Int(StartPos)
722 End If
723
724 If EndPos<=78.5 Then
725 i3=78
726 i4=Int(EndPos)
727 ElseIf EndPos<=235.5 Then
728 EndPos -= 78.5
729 i3=78-Int(EndPos)
730 i4=78
731 ElseIf EndPos<=392.5 Then
732 EndPos -= 235.5
733 i3=-78
734 i4=78-Int(EndPos)
735 ElseIf EndPos<=549.5 Then
736 EndPos -= 392.5
737 i3=-78+Int(EndPos)
738 i4=-78
739 ElseIf EndPos<=628 Then
740 EndPos -= 549.5
741 i3=78
742 i4=-78+Int(EndPos)
743 End If
744
745 If sw Then
746 Pie(hDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
747 Pie(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
748 Else
749 Arc(hDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
750 Arc(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
751 End If
752 End If
753
754 SelectObject(hDC, hOldPenDC)
755 SelectObject(hDC, hOldBrushDC)
756 ReleaseDC(_PromptSys_hWnd, hDC)
757 SelectObject(_PromptSys_hMemDC, hOldPen)
758 SelectObject(_PromptSys_hMemDC, hOldBrush)
759 DeleteObject(hPen)
760 If bFill Then DeleteObject(hBrush)
761End Sub
762
763Sub Line(sx As Long, sy As Long, bStep As Long, ex As Long, ey As Long, ColorCode As Long, fType As Long, BrushColor As Long)
764 Dim temp As Long
765
766 If sx = &H80000000 And sy = &H80000000 Then
767 With _PromptSys_GlobalPos
768 sx = .x
769 sy = .y
770 End With
771 End If
772
773 If bStep Then
774 ex += sx
775 ey += sy
776 Else
777 If fType Then
778 'ラインの場合(四角形でない場合)
779 If sx>ex Then
780 temp=ex
781 ex=sx
782 sx=temp
783 End If
784 If sy>ey Then
785 temp=ey
786 ey=sy
787 sy=temp
788 End If
789 End If
790 End If
791
792 Dim hdc = GetDC(_PromptSys_hWnd)
793 Dim hPen = CreatePen(PS_SOLID, 1, GetBasicColor(ColorCode))
794 Dim hBrush As HBRUSH
795 If fType=2 Then
796 hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
797 Else
798 hBrush = GetStockObject(NULL_BRUSH)
799 End If
800
801 SelectObject(hdc, hPen)
802 SelectObject(hdc, hBrush)
803 Dim hOldPen = SelectObject(_PromptSys_hMemDC, hPen)
804 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
805
806 Select Case fType
807 Case 0
808 'line
809 MoveToEx(_PromptSys_hMemDC,sx,sy,ByVal NULL)
810 LineTo(_PromptSys_hMemDC,ex,ey)
811 SetPixel(_PromptSys_hMemDC,ex,ey,GetBasicColor(ColorCode))
812 MoveToEx(hdc,sx,sy,ByVal NULL)
813 LineTo(hdc,ex,ey)
814 SetPixel(hdc,ex,ey,GetBasicColor(ColorCode))
815 Case Else
816 'Rectangle
817 Rectangle(hdc,sx,sy,ex+1,ey+1)
818 Rectangle(_PromptSys_hMemDC,sx,sy,ex+1,ey+1)
819 End Select
820
821 ReleaseDC(_PromptSys_hWnd,hdc)
822 SelectObject(_PromptSys_hMemDC,hOldPen)
823 SelectObject(_PromptSys_hMemDC,hOldBrush)
824 DeleteObject(hPen)
825 If fType = 2 Then DeleteObject(hBrush)
826 With _PromptSys_GlobalPos
827 .x = ex
828 .y = ey
829 End With
830End Sub
831
832Sub PSet(x As Long, y As Long, ColorCode As Long)
833 Dim hdc = GetDC(_PromptSys_hWnd)
834 SetPixel(hdc, x, y, GetBasicColor(ColorCode))
835 SetPixel(_PromptSys_hMemDC, x, y, GetBasicColor(ColorCode))
836 ReleaseDC(_PromptSys_hWnd, hdc)
837 With _PromptSys_GlobalPos
838 .x = x
839 .y = y
840 End With
841End Sub
842
843Sub Paint(x As Long, y As Long, BrushColor As Long, LineColor As Long)
844 Dim hbr = CreateSolidBrush(GetBasicColor(BrushColor))
845
846 Dim hdc = GetDC(_PromptSys_hWnd)
847 Dim hbrOld = SelectObject(_PromptSys_hMemDC, hbr)
848 Dim hbrOldWndDC = SelectObject(hdc, hbr)
849
850 ExtFloodFill(hdc, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
851 ExtFloodFill(_PromptSys_hMemDC, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
852
853 ReleaseDC(_PromptSys_hWnd, hdc)
854 SelectObject(_PromptSys_hMemDC, hbrOld)
855 SelectObject(hdc, hbrOldWndDC)
856 DeleteObject(hbr)
857End Sub
858
859Function Inkey$() As String
860 If _PromptSys_KeyChar=0 Then
861 Inkey$=""
862 Else
863 Inkey$=Chr$(_PromptSys_KeyChar)
864 End If
865 _PromptSys_KeyChar=0
866End Function
867
868Function Input$(length As Long) As String
869 Dim i = 0 As Long
870
871 If length<=0 Then
872 Input$=""
873 Exit Function
874 End If
875
876 While 1
877 If _PromptSys_KeyChar Then
878 Input$=Input$+Chr$(_PromptSys_KeyChar)
879 _PromptSys_KeyChar=0
880 i++
881 If i >= length Then
882 Exit While
883 End If
884 End If
885 Sleep(1)
886 Wend
887End Function
888
889End Namespace 'Detail
890
891Function OwnerWnd() As HWND
892 Return Detail._PromptSys_hWnd
893End Function
894
895End Namespace 'Prompt
896End Namespace 'ActiveBasic
897
898'----------------------
899' Prompt text Commands
900'----------------------
901
902Sub PRINT_ToPrompt(s As String)
903 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(s)
904End Sub
905
906Macro CLS()(num As Long)
907 ActiveBasic.Prompt.Detail.Cls(num)
908End Macro
909
910Macro COLOR(TextColorCode As Long)(BackColorCode As Long)
911 ActiveBasic.Prompt.Detail.Color(TextColorCode, BackColorCode)
912End Macro
913
914'---------- Defined in "command.sbp" ----------
915'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr
916'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord
917'----------------------------------------------
918Sub INPUT_FromPrompt(ShowStr As String)
919 ActiveBasic.Prompt.Detail.INPUT_FromPrompt(ShowStr)
920End Sub
921
922Sub PRINTUSING_ToPrompt(UsingStr As String)
923 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(_System_GetUsingFormat(UsingStr))
924End Sub
925
926Macro LOCATE(x As Long, y As Long)
927 ActiveBasic.Prompt.Detail.Locate(x, y)
928End Macro
929
930
931'-------------------
932' Graphics Commands
933'-------------------
934
935Macro CIRCLE(x As Long , y As Long, radius As Long)(ColorCode As Long, StartPos As Double, EndPos As Double, Aspect As Double, bFill As Long, BrushColor As Long)
936 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
937 'Circle (x, y), radius [, color] [, start] [, end] [, aspect] [, f] [, color2]
938 ActiveBasic.Prompt.Detail.Circle(x, y, radius, ColorCode, StartPos, EndPos, Aspect, bFill, BrushColor)
939End Macro
940
941Macro LINE(sx As Long, sy As Long, bStep As Long, ex As Long, ey As Long)(ColorCode As Long, fType As Long, BrushColor As Long)
942 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
943 'Line (sx,sy)-[STEP](ex,ey),[ColorCode],[B/Bf],[BrushColor]
944 ActiveBasic.Prompt.Detail.Line(sx, sy, bStep, ex, ey, ColorCode, fType, BrushColor)
945End Macro
946
947Macro PSET(x As Long, y As Long)(ColorCode As Long)
948 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
949 'PSet (x,y),ColorCode
950 ActiveBasic.Prompt.Detail.PSet(x, y, ColorCode)
951End Macro
952
953Macro PAINT(x As Long, y As Long, BrushColor As Long)(ByVal LineColor As Long)
954 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
955 'Paint (x,y),BrushColor,LineColor
956 ActiveBasic.Prompt.Detail.Paint(x, y, BrushColor, LineColor)
957End Macro
958
959
960'-----------
961' Functions
962'-----------
963
964Function Inkey$() As String
965 Return ActiveBasic.Prompt.Detail.Inkey$()
966End Function
967
968Function Input$(length As Long) As String
969 Return ActiveBasic.Prompt.Detail.Input$(length)
970End Function
971
972ActiveBasic.Prompt.Detail._PromptSys_Initialize()
973
974#endif '_INC_PROMPT
Note: See TracBrowser for help on using the repository browser.