/
Controls.hs
90 lines (67 loc) · 2.8 KB
/
Controls.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{-# LANGUAGE TemplateHaskell, DataKinds, MultiParamTypeClasses, FlexibleContexts,
OverlappingInstances, ConstraintKinds, FlexibleInstances #-}
module WinForms.Controls where
import WinForms.Types
import WinForms.Interface
import WinForms.Controls.Base
(#=) :: (Marshal a, Subclass a b) => Setter a -> b -> IO ()
(Setter setter) #= val = setter $ cast val
handle :: (Marshal a, Marshal b) => (a -> b -> IO ()) -> Event a b -> IO ()
handle = flip addHandler
makeShared "EventArgs"
makeShared "ControlCollection"
makeShared "Type"
makeShared "Graphics"
makeShared "Control"
makeShared "Image"
makeShared "Bitmap"
makeShared "Brush"
makeShared "SolidBrush"
makeInstantiable "Form"
makeInstantiable "Button"
makeInstantiable "PictureBox"
toString :: Shared a => a -> IO String
toString = invokeMarshal "ToString" []
getType :: Shared a => a -> IO Type
getType = invokeMarshal "GetType" []
class Shared a => ControlC a where
location :: FromGettableSettable p => a -> p Point
location = getSet . property "Location"
backColor :: FromGettableSettable p => a -> p Color
backColor = getSet . property "BackColor"
controls :: FromGettable p => a -> p ControlCollection
controls = get . property "Controls"
click :: a -> IO (Event a EventArgs)
click = event "Click"
backgroundImage :: FromGettableSettable p => a -> p Image
backgroundImage = getSet . property "BackgroundImage"
refresh :: a -> IO ()
refresh = invokeVoid "Refresh" []
text :: FromGettableSettable p => a -> p String
text = getSet . property "Text"
instance ControlC a => Subclass Control a
instance ControlC Form
instance ControlC Button
instance ControlC PictureBox
class Shared a => ImageC a
instance ImageC a => Subclass Image a
instance ImageC Bitmap
image :: FromGettableSettable p => PictureBox -> p Image
image = getSet . property "Image"
add :: ControlC a => a -> ControlCollection -> IO ()
add con = invokeVoid "Add" [toValue con]
graphicsFromImage :: ImageC i => i -> IO Graphics
graphicsFromImage img = invokeStaticMarshal "System.Drawing.Graphics" "FromImage" [toValue img]
newBitmap :: Int -> Int -> IO Bitmap
newBitmap width height = invokeStaticMarshal "System.Drawing.Bitmap" "new" [toValue width, toValue height]
class Shared a => GraphicsC a where
drawString :: BrushC b => String -> Font -> b -> PointF -> a -> IO ()
drawString str fnt br p = invokeVoid "DrawString" [toValue str, toValue fnt, toValue br, toValue p]
instance GraphicsC a => Subclass Graphics a
instance GraphicsC Graphics
class Shared a => BrushC a
instance BrushC a => Subclass Brush a
instance BrushC SolidBrush
newSolidBrush :: Color -> IO SolidBrush
newSolidBrush = invokeStaticMarshal "System.Drawing.SolidBrush" "new" . return . toValue
--TODO: Handle contructors that take parameters as static functions with the name "new"