1 | /*
|
---|
2 | 注意:インクルードファイルではありません。
|
---|
3 | イベント処理の実装コード生成プログラム。
|
---|
4 | */
|
---|
5 |
|
---|
6 | Imports System
|
---|
7 | Imports System.IO
|
---|
8 | Imports System.Text
|
---|
9 | Imports ActiveBasic
|
---|
10 | Imports ActiveBasic.CType
|
---|
11 |
|
---|
12 | Function EventNameToMemberVariableName(eventName As String) As String
|
---|
13 | '先頭1字を小文字化
|
---|
14 | Dim t = New StringBuilder(eventName)
|
---|
15 | t[0] = ToLower(t[0])
|
---|
16 | Return t.ToString
|
---|
17 | End Function
|
---|
18 |
|
---|
19 | Sub OutputEventHandlerCode(out As TextWriter, eventName As String, argBase As String, comment As String, isStatic As Boolean)
|
---|
20 | Dim eventMember = EventNameToMemberVariableName(eventName)
|
---|
21 | Dim handlerType = argBase & "Handler"
|
---|
22 | Dim argsType = argBase & "Args"
|
---|
23 | Dim staticKeyword = Nothing As String
|
---|
24 | If isStatic Then staticKeyword = "Static "
|
---|
25 | out.WriteLine("Public")
|
---|
26 | ' out.WriteLine(Ex"\t/*!")
|
---|
27 | ' out.WriteLine(Ex"\t@brief " & eventName & "イベントハンドラを追加する")
|
---|
28 | ' out.WriteLine(Ex"\t*/")
|
---|
29 | out.WriteLine(Ex"\t" & staticKeyword & "Sub Add" & eventName & "(h As " & handlerType & ")")
|
---|
30 | out.WriteLine(Ex"\t\tIf IsNothing(" & eventMember & ") Then")
|
---|
31 | out.WriteLine(Ex"\t\t\t" & eventMember & " = h")
|
---|
32 | out.WriteLine(Ex"\t\tElse")
|
---|
33 | out.WriteLine(Ex"\t\t\t" & eventMember & " += h")
|
---|
34 | out.WriteLine(Ex"\t\tEnd If")
|
---|
35 | out.WriteLine(Ex"\tEnd Sub")
|
---|
36 | ' out.WriteLine(Ex"\t/*!")
|
---|
37 | ' out.WriteLine(Ex"\t@brief " & eventName & "イベントハンドラを削除する")
|
---|
38 | ' out.WriteLine(Ex"\t*/")
|
---|
39 | out.WriteLine(Ex"\t" & staticKeyword & "Sub Remove" & eventName & "(h As " & handlerType & ")")
|
---|
40 | out.WriteLine(Ex"\t\tIf Not IsNothing(" & eventMember & ") Then")
|
---|
41 | out.WriteLine(Ex"\t\t\t" & eventMember & " -= h")
|
---|
42 | out.WriteLine(Ex"\t\tEnd If")
|
---|
43 | out.WriteLine(Ex"\tEnd Sub")
|
---|
44 | out.WriteLine("Protected")
|
---|
45 | ' out.WriteLine(Ex"\t/*!")
|
---|
46 | ' out.WriteLine(Ex"\t@brief " & comment)
|
---|
47 | ' out.WriteLine(Ex"\t*/")
|
---|
48 | out.WriteLine(Ex"\t" & staticKeyword & "Sub On" & eventName & "(e As " & argsType & ")")
|
---|
49 | out.WriteLine(Ex"\t\tIf Not IsNothing(" & eventMember & ") Then")
|
---|
50 | out.WriteLine(Ex"\t\t\t" & eventMember & "(This, e)")
|
---|
51 | out.WriteLine(Ex"\t\tEnd If")
|
---|
52 | out.WriteLine(Ex"\tEnd Sub")
|
---|
53 | out.WriteLine("Private")
|
---|
54 | out.WriteLine(Ex"\t" & staticKeyword & eventMember & " As " & handlerType)
|
---|
55 | out.WriteLine()
|
---|
56 | End Sub
|
---|
57 |
|
---|
58 | 'OutputEventHandlerCode("PaintDC", "PaintDCEventHandler",
|
---|
59 | ' "ウィンドウの描画が必要なときに呼び出されます。")
|
---|
60 |
|
---|
61 | Sub MakeControlEvent(t As String, isStatic = False As Boolean)
|
---|
62 | Dim event As String, handler As String, comment As String
|
---|
63 | Dim n As DWord, i As DWord
|
---|
64 | /*Using*/ Dim in = New StreamReader(t + "EventList.txt")
|
---|
65 | /*Using*/ Dim out = New StreamWriter(t + "Event.sbp")
|
---|
66 | Do
|
---|
67 | Dim s = in.ReadLine
|
---|
68 | If IsNothing(s) Then
|
---|
69 | Exit Do
|
---|
70 | End If
|
---|
71 | If s[0] = Asc("'") Then Continue
|
---|
72 | Dim a = ActiveBasic.Strings.Detail.Split(s, 9) 'Tab
|
---|
73 | If a.Count >= 3 Then
|
---|
74 | OutputEventHandlerCode(out, a[0], a[1], a[2], isStatic)
|
---|
75 | End If
|
---|
76 | Loop
|
---|
77 | in.Close() 'End Using
|
---|
78 | out.Close() 'End Using
|
---|
79 | End Sub
|
---|
80 |
|
---|
81 | MakeControlEvent("Control")
|
---|
82 | MakeControlEvent("Form")
|
---|
83 | MakeControlEvent("Application", True)
|
---|
84 | End
|
---|