2025-02-01 11:42:31 -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 (
|
|
|
|
"go.wit.com/log"
|
2024-01-18 04:10:08 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:08:37 -06:00
|
|
|
)
|
|
|
|
|
2025-02-09 06:14:57 -06:00
|
|
|
func (tk *guiWidget) doButtonClick() {
|
|
|
|
if tk.node.IsEnabled() {
|
|
|
|
tk.dumpWidget("click()") // enable this to debug widget clicks
|
|
|
|
me.myTree.SendFromUser(tk.node)
|
|
|
|
} else {
|
2025-02-09 06:21:21 -06:00
|
|
|
log.Info("button is currently disabled by the application")
|
|
|
|
// tk.dumpWidget("disabled()") // enable this to debug widget clicks
|
2025-02-09 06:14:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-08 08:36:08 -06:00
|
|
|
// handles a mouse click
|
|
|
|
func doMouseClick(w int, h int) {
|
2025-02-08 10:00:12 -06:00
|
|
|
// Flag widgets (dropdown menus, etc) are the highest priority. ALWAYS SEND MOUSE CLICKS THERE FIRST
|
|
|
|
// handle an open dropdown menu or text entry window first
|
|
|
|
if me.dropdown.active || me.textbox.active {
|
|
|
|
// can't drag or do anything when dropdown or textbox are visible
|
2025-02-08 09:25:09 -06:00
|
|
|
for _, tk := range findByXY(w, h) {
|
2025-02-08 10:00:12 -06:00
|
|
|
if tk.node.WidgetId == me.dropdown.wId {
|
|
|
|
log.Info("got dropdwon click", w, h, tk.cuiName)
|
|
|
|
tk.dropdownClicked(w, h)
|
2025-02-08 15:01:36 -06:00
|
|
|
return
|
2025-02-08 09:25:09 -06:00
|
|
|
}
|
2025-02-08 10:30:19 -06:00
|
|
|
if tk.node.WidgetId == me.textbox.wId {
|
|
|
|
log.Info("got textbox click", w, h, tk.cuiName)
|
2025-02-08 16:23:03 -06:00
|
|
|
textboxClosed()
|
2025-02-08 15:01:36 -06:00
|
|
|
return
|
2025-02-08 10:30:19 -06:00
|
|
|
}
|
2025-02-01 15:48:28 -06:00
|
|
|
}
|
2025-02-08 15:01:36 -06:00
|
|
|
log.Info("a dropdown or textbox is active. you can't click anywhere else (otherwise hit ESC)", w, h)
|
2025-02-08 10:00:12 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-01 15:48:28 -06:00
|
|
|
|
2025-02-08 17:19:41 -06:00
|
|
|
win := findWindowUnderMouse()
|
2025-02-09 12:34:53 -06:00
|
|
|
if win == nil {
|
|
|
|
log.Log(GOCUI, "click() nothing was at:", w, h)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !win.isWindowActive() {
|
|
|
|
win.makeWindowActive()
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
// potentally the user is closing the window
|
2025-02-09 03:00:10 -06:00
|
|
|
if win.checkWindowClose(w, h) {
|
|
|
|
return
|
|
|
|
}
|
2025-02-03 18:50:17 -06:00
|
|
|
}
|
|
|
|
|
2025-02-09 12:34:53 -06:00
|
|
|
// look in this window for widgets
|
|
|
|
// widgets have priority. send the click here first
|
|
|
|
for _, tk := range win.findByXYreal(w, h) {
|
|
|
|
switch tk.node.WidgetType {
|
|
|
|
case widget.Checkbox:
|
|
|
|
if tk.node.State.Checked {
|
|
|
|
log.Log(WARN, "checkbox is being set to false")
|
|
|
|
tk.node.State.Checked = false
|
|
|
|
tk.setCheckbox()
|
|
|
|
} else {
|
|
|
|
log.Log(WARN, "checkbox is being set to true")
|
|
|
|
tk.node.State.Checked = true
|
|
|
|
tk.setCheckbox()
|
|
|
|
}
|
|
|
|
me.myTree.SendUserEvent(tk.node)
|
|
|
|
return
|
|
|
|
case widget.Button:
|
|
|
|
tk.doButtonClick()
|
|
|
|
return
|
|
|
|
case widget.Combobox:
|
|
|
|
tk.showDropdown()
|
|
|
|
return
|
|
|
|
case widget.Dropdown:
|
|
|
|
tk.showDropdown()
|
|
|
|
return
|
|
|
|
case widget.Textbox:
|
2025-02-09 17:31:32 -06:00
|
|
|
tk.prepTextbox()
|
2025-02-09 12:34:53 -06:00
|
|
|
return
|
|
|
|
default:
|
|
|
|
// TODO: enable the GUI debugger in gocui
|
|
|
|
// tk.dumpWidget("undef click()") // enable this to debug widget clicks
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2025-02-08 08:42:41 -06:00
|
|
|
|
|
|
|
func doMouseDoubleClick(w int, h int) {
|
|
|
|
me.mouse.double = false
|
2025-02-08 10:00:12 -06:00
|
|
|
// log.Printf("actually a double click (%d,%d)", w, h)
|
2025-02-08 08:55:26 -06:00
|
|
|
|
2025-02-08 15:01:36 -06:00
|
|
|
if me.dropdown.active || me.textbox.active {
|
|
|
|
// can't drag or do anything when dropdown or textbox are visible
|
|
|
|
log.Info("can't double click. dropdown or textbox is active")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-02-08 08:55:26 -06:00
|
|
|
for _, tk := range findByXY(w, h) {
|
2025-02-08 09:16:22 -06:00
|
|
|
if tk.node.WidgetType == widget.Window {
|
2025-02-09 12:21:43 -06:00
|
|
|
tk.makeWindowActive()
|
2025-02-08 09:16:22 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-02-08 08:55:26 -06:00
|
|
|
if tk.node.WidgetType == widget.Stdout {
|
|
|
|
if me.stdout.outputOnTop {
|
|
|
|
me.stdout.outputOnTop = false
|
|
|
|
setThingsOnTop()
|
|
|
|
} else {
|
|
|
|
me.stdout.outputOnTop = true
|
|
|
|
setThingsOnTop()
|
|
|
|
}
|
2025-02-08 09:16:22 -06:00
|
|
|
return
|
2025-02-08 08:55:26 -06:00
|
|
|
}
|
|
|
|
}
|
2025-02-08 08:42:41 -06:00
|
|
|
}
|