/**
@file Include/Classes/ActiveBasic/Windows/UI/EventArgs.ab
@brief イベントハンドラ関連
*/

Namespace ActiveBasic
Namespace Windows
Namespace UI

'TypeDef EventArgs = System.EventArgs
'TypeDef EventHandler = System.EventHandler
Class EventArgs
Public
	Static Empty = Nothing As EventArgs
End Class
Delegate Sub EventHandler(sender As Object, e As EventArgs)

Class MessageEventArgs
	Inherits EventArgs
Public
	Sub MessageEventArgs(hwndSrc As HWND, message As DWord, wParam As WPARAM, lParam As LPARAM)
		msg = message
'		hwnd = hwndSrc
		wp = wParam
		lp = lParam
		lr = 0
	End Sub

	Function Msg() As DWord
		Msg = msg
	End Function

'	Function HWnd() As HWND
'		HWnd = hwnd
'	End Function

	Function WParam() As WPARAM
		WParam = wp
	End Function

	Function LParam() As LPARAM
		LParam = lp
	End Function

	Function LResult() As LRESULT
		LResult = lr
	End Function

	Sub LResult(lResult As LRESULT)
		lr = lResult
	End Sub
Private
	msg As DWord
'	hwnd As HWND
	wp As WPARAM
	lp As LPARAM
	lr As LRESULT
End Class

Delegate Sub MessageEventHandler(sender As Object, e As MessageEventArgs)

Class PaintDCEventArgs
	Inherits EventArgs
Public
	Sub PaintDCEventArgs(hdcTarget As HDC, ByRef rect As RECT)
		hdc = hdcTarget
		rc = rect
	End Sub

	Function Handle() As HDC
		Handle = hdc
	End Function

	Function ClipRect() As RECT
		ClipRect = rc
	End Function

Private
	hdc As HDC
	rc As RECT
End Class

Delegate Sub PaintDCEventHandler(sender As Object, e As PaintDCEventArgs)

Class PaintDCHandledEventArgs
	Inherits PaintDCEventArgs
Public
	Sub PaintDCHandledEventArgs(hdcTarget As HDC, ByRef rect As RECT)
		PaintDCEventArgs(hdcTarget, rect)
	End Sub

	Function Handled() As Boolean
		Handled = h
	End Function

	Sub Handled(handled As Boolean)
		h = handled
	End Sub

Private
	h As Boolean
End Class

TypeDef PaintDCBackGroundEventArgs = PaintDCHandledEventArgs

Enum MouseButtons
	None = 0
	Left = MK_LBUTTON
	Right = MK_RBUTTON
	Middle = MK_MBUTTON
	XButton1 = MK_XBUTTON1
	XButton2 = MK_XBUTTON2

	Shift = MK_SHIFT
	Control = MK_CONTROL
End Enum

Class MouseEventArgs
	Inherits EventArgs
Public
	Sub MouseEventArgs(button As MouseButtons, clicks As Long, x As Long, y As Long, delta As Long)
		This.button = button
		This.clicks = clicks
		This.pt = New System.Drawing.Point(x, y)
		OutputDebugString(ToTCStr(Hex$(y) + " " + Hex$(pt.Y) + " " +  Ex" mea\r\n"))
		This.delta = delta
	End Sub

	Const Function Button() As MouseButtons
		Button = button
	End Function

	Const Function Clicks() As Long
		Clicks = clicks
	End Function

	Const Function Delta() As Long
		Delta = delta
	End Function

	Const Function Locale() As System.Drawing.Point
		Locale = New System.Drawing.Point(pt.X, pt.Y)
	End Function

	Const Function X() As Long
		X = pt.X
	End Function

	Const Function Y() As Long
		Y = pt.Y
	End Function

Private
	pt As System.Drawing.Point
	button As MouseButtons
	clicks As Long
	delta As Long
End Class

Delegate Sub MouseEventHandler(sender As Object, e As MouseEventArgs)

Class KeyPressEventArgs
	Inherits EventArgs
Public
	Sub KeyPressEventArgs(keyChar As Char)
		key = keyChar
	End Sub

	Sub KeyChar(keyChar As Char)
		key = keyChar
	End Sub

	Const Function KeyChar() As Char
		KeyChar = key
	End Function

	Sub Handled(handled As Boolean)
		h = handled
	End Sub

	Const Function Handled() As Boolean
		Handled = h
	End Function
Private
	key As Char
	h As Boolean
End Class

Delegate Sub KeyPressEventHandler(sender As Object, e As KeyPressEventArgs)

Enum Keys
	None = 0
	LButton = VK_LBUTTON
	RButton = VK_RBUTTON
	Cancel = VK_CANCEL
	MButton = VK_MBUTTON
	XButton1 = VK_XBUTTON1
	XButton2 = VK_XBUTTON2
	Back = VK_BACK
	Tab = VK_TAB
	LineFeed = &ha
	Clear = VK_CLEAR
	Enter = VK_RETURN
	Return_ = VK_RETURN
	ShiftKey = VK_SHIFT
	ControlKey = VK_CONTROL
	Menu = VK_MENU
	Pause = VK_PAUSE
	Capital = VK_CAPITAL
	KanaMode = VK_KANA
	HangulMode = VK_HANGUL
	JunjaMode = VK_JUNJA
	FinalMode = VK_FINAL
	KanjiMode = VK_KANJI
	HanjaMode = VK_HANJA
	Escape = VK_ESCAPE
	IMEConvert = VK_CONVERT
	IMENonconvert = VK_NONCONVERT
	IMEAccept = VK_ACCEPT
	IMEModeChange = VK_MODECHANGE
	Space = VK_SPACE
	Prior = VK_PRIOR
	PageUp = VK_PRIOR
	PageDown = VK_NEXT
	Next_ = VK_NEXT
	End_ = VK_END
	Home = VK_HOME
	Left = VK_LEFT
	Up = VK_UP
	Right = VK_RIGHT
	Down = VK_DOWN
	Select_ = VK_SELECT
	Print = VK_PRINT
	Execute = VK_EXECUTE
	Snapshot = VK_SNAPSHOT
	Insert = VK_INSERT
	Delete_ = VK_DELETE
	Help = VK_HELP
	D0 = &h30
	D1 = &h31
	D2 = &h32
	D3 = &h33
	D4 = &h34
	D5 = &h35
	D6 = &h36
	D7 = &h37
	D8 = &h38
	D9 = &h39
	A = &h41
	B = &h42
	C = &h43
	D = &h44
	E = &h45
	F = &h46
	G = &h47
	H = &h48
	I = &h49
	J = &h4a
	K = &h4b
	L = &h4c
	M = &h4d
	N = &h4e
	O = &h4f
	P = &h50
	Q = &h51
	R = &h52
	S = &h53
	T = &h54
	U = &h55
	V = &h56
	W = &h57
	X = &h58
	Y = &h59
	Z = &h5A
	LWin = VK_LWIN
	RWin = VK_RWIN
	Apps = VK_APPS
	Sleep = VK_SLEEP
	NumPad0 = VK_NUMPAD0
	NumPad1 = VK_NUMPAD1
	NumPad2 = VK_NUMPAD2
	NumPad3 = VK_NUMPAD3
	NumPad4 = VK_NUMPAD4
	NumPad5 = VK_NUMPAD5
	NumPad6 = VK_NUMPAD6
	NumPad7 = VK_NUMPAD7
	NumPad8 = VK_NUMPAD8
	NumPad9 = VK_NUMPAD9
	Multiply = VK_MULTIPLY
	Add = VK_ADD
	Separator = VK_SEPARATOR
	Substract = VK_SUBTRACT
	Decimal = VK_DECIMAL
	Divide = VK_DIVIDE
	F1 = VK_F1
	F2 = VK_F2
	F3 = VK_F3
	F4 = VK_F4
	F5 = VK_F5
	F6 = VK_F6
	F7 = VK_F7
	F8 = VK_F8
	F9 = VK_F9
	F10 = VK_F10
	F11 = VK_F11
	F12 = VK_F12
	F13 = VK_F13
	F14 = VK_F14
	F15 = VK_F15
	F16 = VK_F16
	F17 = VK_F17
	F18 = VK_F18
	F19 = VK_F19
	F20 = VK_F20
	F21 = VK_F21
	F22 = VK_F22
	F23 = VK_F23
	F24 = VK_F24
	NumLock = VK_NUMLOCK
	Scroll = VK_SCROLL
	LShiftKey = VK_LSHIFT
	RShiftKey = VK_RSHIFT
	LControlKey = VK_LCONTROL
	RControlKey = VK_RCONTROL
	LMenu = VK_LMENU
	RMenu = VK_RMENU
	BrowserBack = VK_BROWSER_BACK
	BrowserForward = VK_BROWSER_FORWARD
	BrowserRefresh = VK_BROWSER_REFRESH
	BrowserStop = VK_BROWSER_STOP
	BrowserSearch = VK_BROWSER_SEARCH
	BrowserFavorites = VK_BROWSER_FAVORITES
	BrowserHome = VK_BROWSER_HOME
	VolumeMute = VK_VOLUME_MUTE
	VolumeDown = VK_VOLUME_DOWN
	VolumeUp = VK_VOLUME_UP
	MediaNextTrack = VK_MEDIA_NEXT_TRACK
	MediaPreviousTrack = VK_MEDIA_PREV_TRACK
	MediaStop = VK_MEDIA_STOP
	MediaPlayPause = VK_MEDIA_PLAY_PAUSE
	LaunchMail = VK_LAUNCH_MAIL
	SelectMedia = VK_LAUNCH_MEDIA_SELECT
	LaunchApplication1 = VK_LAUNCH_APP1
	LaunchApplication2 = VK_LAUNCH_APP2
	Oem1 = VK_OEM_1
	Oemplus = VK_OEM_PLUS
	Oemcomma = VK_OEM_COMMA
	OemMinus = VK_OEM_MINUS
	OemPeriod = VK_OEM_PERIOD
	Oem2 = VK_OEM_2
	OemQuestion = VK_OEM_2
	Oem3 = VK_OEM_3
	Oemtilde = VK_OEM_3
	Oem4 = VK_OEM_4
	OemOpenBrackets = VK_OEM_4
	Oem5 = VK_OEM_5
	OemPipe = VK_OEM_5
	Oem6 = VK_OEM_6
	OemCloseBrackets = VK_OEM_6
	Oem7 = VK_OEM_7
	OemQuotes = VK_OEM_7
	Oem8 = VK_OEM_8
	Oem102 = VK_OEM_102
	OemBackslash = VK_OEM_102
	ProcessKey = VK_PROCESSKEY
	Packet = VK_PACKET
	Attn = VK_ATTN
	Crsel = VK_CRSEL
	Exsel = VK_EXSEL
	EraseEof = VK_EREOF
	Play = VK_PLAY
	NoName = VK_NONAME
	Zoom = VK_ZOOM
	Pa1 = VK_PA1
	OemClear = VK_OEM_CLEAR

	KeyCode = &hffff

	Shift = &h10000
	Control = &h20000
	Alt = &h40000

	Modifiers = &hffff
End Enum

Class KeyEventArgs
	Inherits EventArgs
Public
	Sub KeyEventArgs(keyData As Keys)
		key = keyData
	End Sub

	Function Alt() As Boolean
		Alt = key And Keys.Menu
	End Function

	Function Control() As Boolean
		Control = key And Keys.Control
	End Function

	Function Shift() As Boolean
		Shift = key And Keys.Shift
	End Function

	Function KeyCode() As Keys
		Dim k = key As DWord
		Dim mask = Keys.KeyCode As DWord
		KeyCode = (k And mask) As Keys
	End Function

	Function KeyData() As Keys
		KeyData = key
	End Function

	Function Modifiers() As Keys
		Dim k = key As DWord
		Dim mask = Keys.Modifiers As DWord
		Modifiers = (k And mask) As Keys
	End Function

	Function KeyValue() As Long
		KeyValue = key As Long
	End Function

	Sub Handled(handled As Boolean)
		h = handled
	End Sub

	Function Handled() As Boolean
		Handled = h
	End Function

Private
	key As Keys
	h As Boolean
End Class

Delegate Sub KeyEventHandler(sender As Object, e As KeyEventArgs)

Class CreateEventArgs
	Inherits EventArgs
Public
	Sub CreateEventArgs(pCreateStruct As *CREATESTRUCT)
		pcs = pCreateStruct
	End Sub

	Const Function HInstance() As HINSTANCE
		HInstance = pcs->hInstance
	End Function

	'Menu: pcs->hMenu

'	Const Function Parent() As Control
'		Parent = Control.FromHandle(pcs->hwndParent)
'	End Function

	Const Function Height() As Long
		Height = pcs->cy
	End Function

	Const Function Width() As Long
		Width = pcs->cx
	End Function

	Const Function Y() As Long
		Y = pcs->cy
	End Function

	Const Function X() As Long
		X = pcs->cx
	End Function

	Const Function Style() As DWord
		Style = pcs->style As DWord
	End Function

	Const Function Caption() As String
		Caption = New String(pcs->lpszName)
	End Function

	Const Function ClassName() As String
		ClassName = New String(pcs->lpszClass)
	End Function

	Const Function ExStyle() As DWord
		ExStyle = pcs->dwExStyle
	End Function

	Const Function CreateStruct() As *CREATESTRUCT
		CreateStruct = pcs
	End Function
Private
	pcs As *CREATESTRUCT
End Class

Delegate Sub CreateEventHandler(sender As Object, e As CreateEventArgs)

Class FormClosingEventArgs
	Inherits EventArgs
Public
	Sub FormClosingEventArgs()
		c = False
	End Sub

	Function Cancel() As Boolean
		Cancel = c
	End Function

	Sub Cancel(cancel As Boolean)
		c = cancel
	End Sub
Private
	c As Boolean
End Class

Delegate Sub FormClosingEventHandler(sender As Object, e As FormClosingEventArgs)

End Namespace 'UI
End Namespace 'Widnows
End Namespace 'ActiveBasic
