2025-01-31 08:57:32 -06:00
|
|
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the GPL 3.0
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2025-02-08 08:07:03 -06:00
|
|
|
"time"
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
2025-02-01 18:27:42 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:08:37 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
2025-01-31 12:36:46 -06:00
|
|
|
// useful to debug everything that is being clicked on
|
2025-01-31 16:15:41 -06:00
|
|
|
/*
|
|
|
|
for _, tk := range findByXY(w, h) {
|
2025-02-01 13:58:53 -06:00
|
|
|
tk.dumpWidget("mouseUp()")
|
2025-01-31 16:15:41 -06:00
|
|
|
}
|
|
|
|
*/
|
2025-01-31 11:01:47 -06:00
|
|
|
|
2025-02-08 08:07:03 -06:00
|
|
|
me.mouse.mouseUp = true
|
2025-02-08 08:47:55 -06:00
|
|
|
// me.mouse.globalMouseDown = false
|
2025-02-08 08:36:08 -06:00
|
|
|
me.mouse.currentDrag = nil
|
2025-01-31 08:50:00 -06:00
|
|
|
|
2025-02-08 08:42:41 -06:00
|
|
|
if me.mouse.double && (time.Since(me.mouse.down) < me.mouse.doubletime) {
|
|
|
|
me.mouse.double = false
|
|
|
|
doMouseDoubleClick(me.mouse.downW, me.mouse.downH)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
me.mouse.double = false
|
|
|
|
|
2025-02-08 08:36:08 -06:00
|
|
|
if time.Since(me.mouse.down) < me.mouse.clicktime {
|
|
|
|
doMouseClick(me.mouse.downW, me.mouse.downH)
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2025-01-31 08:50:00 -06:00
|
|
|
// this is where you have to figure out what
|
|
|
|
// widget was underneath so you can active
|
|
|
|
// the right response for the toolkit user's app
|
2024-01-18 00:08:37 -06:00
|
|
|
func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
2025-02-08 08:07:03 -06:00
|
|
|
if me.mouse.mouseUp {
|
2025-02-08 08:36:08 -06:00
|
|
|
if time.Since(me.mouse.down) < me.mouse.doubletime {
|
2025-02-08 08:42:41 -06:00
|
|
|
me.mouse.double = true
|
2025-02-08 08:36:08 -06:00
|
|
|
}
|
2025-02-08 08:47:55 -06:00
|
|
|
// me.mouse.globalMouseDown = true
|
2025-02-08 08:07:03 -06:00
|
|
|
me.mouse.mouseUp = false
|
|
|
|
me.mouse.down = time.Now()
|
|
|
|
w, h := g.MousePosition()
|
|
|
|
me.mouse.downW = w
|
|
|
|
me.mouse.downH = h
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if time.Since(me.mouse.down) < me.mouse.clicktime {
|
|
|
|
log.Info("not yet")
|
|
|
|
return nil
|
|
|
|
}
|
2025-01-31 08:50:00 -06:00
|
|
|
|
2025-02-06 09:30:54 -06:00
|
|
|
w, h := g.MousePosition()
|
|
|
|
|
|
|
|
// if the dropdown is active, never do anything else
|
2025-02-06 05:41:51 -06:00
|
|
|
if me.dropdown.active {
|
|
|
|
log.Info("mouseDown() stopping here. dropdwon menu is in effect")
|
|
|
|
for _, tk := range findByXY(w, h) {
|
2025-02-06 05:52:00 -06:00
|
|
|
if (tk.node.WidgetType == widget.Flag) && (tk == me.dropdown.tk) {
|
2025-02-07 03:51:23 -06:00
|
|
|
// log.Info("SENDING CLICK TO Flag (dropdown)")
|
2025-02-06 05:41:51 -06:00
|
|
|
tk.doWidgetClick(w, h)
|
2025-02-06 05:52:00 -06:00
|
|
|
me.dropdown.active = false
|
2025-02-06 05:41:51 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2025-02-06 05:52:00 -06:00
|
|
|
log.Info("never found dropdown at", w, h)
|
2025-02-07 00:35:08 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the textbox is active, never do anything else
|
|
|
|
if me.textbox.active {
|
|
|
|
log.Info("mouseDown() stopping here. textbox widget is open")
|
|
|
|
for _, tk := range findByXY(w, h) {
|
|
|
|
if (tk.node.WidgetType == widget.Flag) && (tk == me.textbox.tk) {
|
|
|
|
me.textbox.active = false
|
|
|
|
tk.textboxClosed()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Info("never found textbox at", w, h)
|
2025-02-06 05:41:51 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2025-02-06 09:30:54 -06:00
|
|
|
// figre out what window this is
|
|
|
|
tk := findWindowUnderMouse()
|
|
|
|
if tk == nil {
|
|
|
|
log.Info("mouseDown() nothing to click on at", w, h)
|
|
|
|
return nil
|
2025-02-06 07:39:31 -06:00
|
|
|
}
|
2025-02-06 13:47:19 -06:00
|
|
|
tk.makeWindowActive()
|
2025-02-06 14:13:31 -06:00
|
|
|
// log.Info("SENDING mouseDown() to findWindowUnderMouse()")
|
2025-02-06 09:30:54 -06:00
|
|
|
if tk.node.WidgetType == widget.Window {
|
|
|
|
// check to see if this is a direct click on a widget
|
|
|
|
for _, tk := range tk.findByXYreal(w, h) {
|
2025-02-06 14:13:31 -06:00
|
|
|
// tk.dumpWidget("mouseDown()")
|
2025-02-06 09:30:54 -06:00
|
|
|
if tk.node.WidgetType == widget.Button {
|
2025-02-07 03:51:23 -06:00
|
|
|
// log.Info("SENDING CLICK TO Button")
|
2025-02-06 09:30:54 -06:00
|
|
|
tk.doWidgetClick(w, h)
|
|
|
|
return nil
|
2025-02-06 04:15:36 -06:00
|
|
|
}
|
2025-02-06 09:30:54 -06:00
|
|
|
if tk.node.WidgetType == widget.Checkbox {
|
2025-02-07 03:51:23 -06:00
|
|
|
// log.Info("SENDING CLICK TO Checkbox")
|
2025-02-06 09:30:54 -06:00
|
|
|
tk.doWidgetClick(w, h)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if tk.node.WidgetType == widget.Dropdown {
|
2025-02-07 03:51:23 -06:00
|
|
|
// log.Info("SENDING CLICK TO Dropdown")
|
2025-02-06 09:30:54 -06:00
|
|
|
tk.doWidgetClick(w, h)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if tk.node.WidgetType == widget.Textbox {
|
2025-02-07 03:51:23 -06:00
|
|
|
// log.Info("SENDING CLICK TO Textbox")
|
2025-02-06 09:30:54 -06:00
|
|
|
tk.doWidgetClick(w, h)
|
2025-02-01 18:37:04 -06:00
|
|
|
return nil
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
2025-02-08 08:36:08 -06:00
|
|
|
me.mouse.currentDrag = tk
|
2025-02-01 19:42:04 -06:00
|
|
|
return nil
|
|
|
|
}
|