-
Notifications
You must be signed in to change notification settings - Fork 30
/
mousecontrol.go
48 lines (40 loc) · 1.13 KB
/
mousecontrol.go
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
/*
* Copyright (C) 2019 The Winc Authors. All Rights Reserved.
*/
package winc
import (
"github.com/tadvi/winc/w32"
)
// MouseControl used for creating custom controls that need mouse hover or mouse leave events.
type MouseControl struct {
ControlBase
isMouseLeft bool
}
func (cc *MouseControl) Init(parent Controller, className string, exStyle, style uint) {
RegClassOnlyOnce(className)
cc.hwnd = CreateWindow(className, parent, exStyle, style)
cc.parent = parent
RegMsgHandler(cc)
cc.isMouseLeft = true
cc.SetFont(DefaultFont)
}
func (cc *MouseControl) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
sender := GetMsgHandler(cc.hwnd)
switch msg {
case w32.WM_CREATE:
internalTrackMouseEvent(cc.hwnd)
cc.onCreate.Fire(NewEvent(sender, nil))
case w32.WM_CLOSE:
cc.onClose.Fire(NewEvent(sender, nil))
case w32.WM_MOUSEMOVE:
//if cc.isMouseLeft {
cc.onMouseHover.Fire(NewEvent(sender, nil))
//internalTrackMouseEvent(cc.hwnd)
cc.isMouseLeft = false
//}
case w32.WM_MOUSELEAVE:
cc.onMouseLeave.Fire(NewEvent(sender, nil))
cc.isMouseLeft = true
}
return w32.DefWindowProc(cc.hwnd, msg, wparam, lparam)
}