source: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/MakeControlEventHandler.ab@ 559

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

UI_Sampleの追加。イベントのコメントアウト解除。Form.abからテスト部分を除去。Application.DoEventsを実装。MakeControlEventHandlerを静的メンバのイベント対応へ。WindowsExceptionの追加。

File size: 3.0 KB
RevLine 
[473]1/*
2注意:インクルードファイルではありません。
3イベント処理の実装コード生成プログラム。
4*/
5
6Imports System
7Imports System.IO
8Imports System.Text
9Imports ActiveBasic
10Imports ActiveBasic.CType
11
12Function EventNameToMemberVariableName(eventName As String) As String
13 '先頭1字を小文字化
14 Dim t = New StringBuilder(eventName)
15 t[0] = ToLower(t[0])
16 Return t.ToString
17End Function
18
[559]19Sub OutputEventHandlerCode(out As TextWriter, eventName As String, argBase As String, comment As String, isStatic As Boolean)
[473]20 Dim eventMember = EventNameToMemberVariableName(eventName)
21 Dim handlerType = argBase & "Handler"
22 Dim argsType = argBase & "Args"
[559]23 Dim staticKeyword = Nothing As String
24 If isStatic Then staticKeyword = "Static "
[473]25 out.WriteLine("Public")
[542]26' out.WriteLine(Ex"\t/*!")
27' out.WriteLine(Ex"\t@brief " & eventName & "イベントハンドラを追加する")
28' out.WriteLine(Ex"\t*/")
[559]29 out.WriteLine(Ex"\t" & staticKeyword & "Sub Add" & eventName & "(h As " & handlerType & ")")
[473]30 out.WriteLine(Ex"\t\tIf IsNothing(" & eventMember & ") Then")
[542]31 out.WriteLine(Ex"\t\t\t" & eventMember & " = h")
32 out.WriteLine(Ex"\t\tElse")
33 out.WriteLine(Ex"\t\t\t" & eventMember & " += h")
[473]34 out.WriteLine(Ex"\t\tEnd If")
35 out.WriteLine(Ex"\tEnd Sub")
[542]36' out.WriteLine(Ex"\t/*!")
37' out.WriteLine(Ex"\t@brief " & eventName & "イベントハンドラを削除する")
38' out.WriteLine(Ex"\t*/")
[559]39 out.WriteLine(Ex"\t" & staticKeyword & "Sub Remove" & eventName & "(h As " & handlerType & ")")
[473]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")
[551]44 out.WriteLine("Protected")
[542]45' out.WriteLine(Ex"\t/*!")
46' out.WriteLine(Ex"\t@brief " & comment)
47' out.WriteLine(Ex"\t*/")
[559]48 out.WriteLine(Ex"\t" & staticKeyword & "Sub On" & eventName & "(e As " & argsType & ")")
[473]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")
[559]54 out.WriteLine(Ex"\t" & staticKeyword & eventMember & " As " & handlerType)
[473]55 out.WriteLine()
56End Sub
57
[542]58'OutputEventHandlerCode("PaintDC", "PaintDCEventHandler",
[473]59' "ウィンドウの描画が必要なときに呼び出されます。")
60
[559]61Sub MakeControlEvent(t As String, isStatic = False As Boolean)
[473]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
[559]74 OutputEventHandlerCode(out, a[0], a[1], a[2], isStatic)
[473]75 End If
76 Loop
77 in.Close() 'End Using
78 out.Close() 'End Using
79End Sub
80
81MakeControlEvent("Control")
[545]82MakeControlEvent("Form")
[559]83MakeControlEvent("Application", True)
[473]84End
Note: See TracBrowser for help on using the repository browser.