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

Namespace ActiveBasic
Namespace Windows
Namespace UI

TypeDef Args = System.EventArgs
'TypeDef Handler = System.EventHandler
Delegate Sub Handler(sender As Object, e As Args)

Class MessageArgs
	Inherits Args
Public
	Sub MessageArgs(hwndSrc As HWND, message As DWord, wParam As WPARAM, lParam As LPARAM)
		msg = message
		hwnd = hwndSrc
		wp = wParam
		lp = lParam
		lr = 0
		handled = True
	End Sub

	Const Function Msg() As DWord
		Msg = msg
	End Function

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

	Const Function WParam() As WPARAM
		WParam = wp
	End Function

	Const Function LParam() As LPARAM
		LParam = lp
	End Function

	Const Function LResult() As LRESULT
		LResult = lr
	End Function

	Sub LResult(lResult As LRESULT)
		lr = lResult
	End Sub

	Const Function Handled() As Boolean
		Handled = handled
	End Function

	Sub Handled(h As Boolean)
		handled = h
	End Sub
Private
	msg As DWord
	hwnd As HWND
	wp As WPARAM
	lp As LPARAM
	lr As LRESULT
	handled As Boolean
End Class

Delegate Sub MessageHandler(sender As Object, e As MessageArgs)

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

	Const Function Handle() As HDC
		Handle = hdc
	End Function

	Const Function ClipRect() As RECT
		ClipRect = rc
	End Function

Private
	hdc As HDC
	rc As RECT
End Class

Delegate Sub PaintDCHandler(sender As Object, e As PaintDCArgs)

Class PaintDCHandledArgs
	Inherits PaintDCArgs
Public
	Sub PaintDCHandledArgs(hdcTarget As HDC, ByRef rect As RECT)
		PaintDCArgs(hdcTarget, rect)
	End Sub

	Const Function Handled() As Boolean
		Handled = h
	End Function

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

Private
	h As Boolean
End Class

TypeDef PaintDCBackGroundArgs = PaintDCHandledArgs

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 MouseArgs
	Inherits Args
Public
	Sub MouseArgs(button As MouseButtons, clicks As Long, x As Long, y As Long, delta As Long)
		This.button = button
		This.clicks = clicks
		This.pt.X = x
		This.pt.Y = y
		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 = pt
	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 MouseHandler(sender As Object, e As MouseArgs)

Class KeyPressArgs
	Inherits Args
Public
	Sub KeyPressArgs(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 KeyPressHandler(sender As Object, e As KeyPressArgs)

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 KeyArgs
	Inherits Args
Public
	Sub KeyArgs(keyData As Keys)
		key = keyData
	End Sub

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

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

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

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

	Const Function KeyData() As Keys
		KeyData = key
	End Function

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

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

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

	Const Function Handled() As Boolean
		Handled = h
	End Function

Private
	key As Keys
	h As Boolean
End Class

Delegate Sub KeyHandler(sender As Object, e As KeyArgs)

Class CreateArgs
	Inherits Args
Public
	Sub CreateArgs(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

	Const Function Cancel() As Boolean
		Cancel = cancel
	End Function

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

Delegate Sub CreateHandler(sender As Object, e As CreateArgs)

Class FormClosingArgs
	Inherits Args
Public
	Sub FormClosingArgs()
		c = False
	End Sub

	Const 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 FormClosingHandler(sender As Object, e As FormClosingArgs)

Class ResizeArgs
	Inherits Args
Public
	Sub ResizeArgs(resizeType As Long, X As Long, Y As Long)
		rt = resizeType
		x = X
		y = Y
	End Sub

	Sub ResizeArgs(wp As WPARAM, lp As LPARAM)
		rt = wp As Long
		x = GET_X_LPARAM(lp)
		y = GET_Y_LPARAM(lp)
	End Sub

	Function ResizeType() As Long
		ResizeType = rt
	End Function

	Function X() As Long
		X = x
	End Function

	Function Y() As Long
		Y = y
	End Function
Private
	rt As Long
	x As Long
	y As Long
End Class

Delegate Sub ResizeHandler(sender As Object, e As ResizeArgs)

Class PaintBackgroundArgs
	Inherits Args
Public
	Sub PaintBackgroundArgs(hdc As HDC)
		This.hdc = hdc
		This.painted = True
	End Sub

	Sub PaintBackgroundArgs(wp As WPARAM, lp As LPARAM)
		This.hdc = wp As HDC
	End Sub

	Const Function Handle() As HDC
		Handle = hdc
	End Function

	Const Function Painted() As Boolean
		Painted = painted
	End Function

	Sub Painted(p As Boolean)
		painted = p
	End Sub
Private
	hdc As HDC
	painted As Boolean
End Class

Delegate Sub PaintBackgroundHandler(sender As Object, e As PaintBackgroundArgs)

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