sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.57k stars 268 forks source link

BehaviorEvent: type conversion sets the 16th bit #267

Closed mrg0lden closed 3 years ago

mrg0lden commented 3 years ago

Hi, I tried to attach a behavior event handler on an element. When I tried to check its type by comparing it to existing enums, It didn't match the supposed types. Doing some investigations, I found that the 16th bit is set, so instead of (binary) 100 it becomes 10000000000100.

Code Example input is a *sciter.Element ### This code doesn't work ```go //... input.AttachEventHandler(&sciter.EventHandler{ OnBehaviorEvent: func(target *sciter.Element, params *sciter.BehaviorEventParams) bool { cmd := uint32(params.Cmd()) if cmd == uint32(sciter.EDIT_VALUE_CHANGED) { fmt.Println("It works, it seems") } fmt.Printf("%d %X %b\n", cmd, cmd, cmd) return true }, }) //... ``` ```go input.AttachEventHandler(&sciter.EventHandler{ OnBehaviorEvent: func(target *sciter.Element, params *sciter.BehaviorEventParams) bool { cmd := uint32(params.Cmd()) leading := bits.LeadingZeros32(cmd) cmd ^= (1 << (31 - uint32(leading))) //remove leading set bit if cmd == uint32(sciter.EDIT_VALUE_CHANGED) { fmt.Println("It works, it seems") } fmt.Printf("%d %X %b\n", cmd, cmd, cmd) return true }, }) ````

Is this a normal behavior?

pravic commented 3 years ago

It's because of this: https://github.com/c-smile/sciter-sdk/blob/master/include/sciter-x-behavior.h#L73

mrg0lden commented 3 years ago

So I need to unmask it manually before checking its type, correct?

pravic commented 3 years ago

Correct.

Technically, we could introduce a separate params.Phase() and keep params.Cmd() clean: https://github.com/sciter-sdk/go-sciter/blob/ce0e920fd2fb79974c2cc202242fba2f774559c0/types.go#L588-L590

mrg0lden commented 3 years ago

I think that'd be better because it's quite confusing now.