summaryrefslogtreecommitdiff
path: root/eventMouseClick.go
blob: 0d462164351dd467dc28d610f3f85996ebc8861e (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"github.com/awesome-gocui/gocui"
	"go.wit.com/log"
	"go.wit.com/widget"
)

func (tk *guiWidget) doButtonClick() {
	if tk.IsEnabled() {
		tk.dumpWidget("click()") // enable this to debug widget clicks
		me.myTree.SendFromUser(tk.node)
	} else {
		log.Info("button is currently disabled by the application")
		// tk.dumpWidget("disabled()") // enable this to debug widget clicks
	}
}

// handles a mouse click
func doMouseClick(w int, h int) {
	// 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
		for _, tk := range findByXY(w, h) {
			if tk.WidgetId() == me.dropdown.wId {
				log.Info("got dropdwon click", w, h, tk.cuiName)
				tk.dropdownClicked(w, h)
				return
			}
			if tk.WidgetId() == me.textbox.wId {
				log.Info("got textbox click", w, h, tk.cuiName)
				textboxClosed()
				return
			}
		}
		log.Info("a dropdown or textbox is active. you can't click anywhere else (otherwise hit ESC)", w, h)
		return
	}

	win := findWindowUnderMouse()
	if win == nil {
		log.Log(INFO, "click() nothing was at:", w, h)
		log.Log(INFO, "click() check if", w, h, "is the libnotify icon")
		if me.notify.icon.tk != nil && me.notify.icon.tk.gocuiSize.inRect(w, h) {
			log.Log(GOCUI, "click() is libnotify.icon!")
			if me.notify.icon.active {
				log.Info("show notify.icon here")
				setNotifyIconText("[X]")
				me.notify.icon.active = false
			} else {
				log.Info("hide notify.icon here")
				setNotifyIconText("[ ]")
				me.notify.icon.active = true
			}
			return
		}
		if me.notify.clock.tk != nil && me.notify.clock.tk.gocuiSize.inRect(w, h) {
			log.Log(GOCUI, "click() is the clock!")
			if me.showHelp {
				log.Info("show help")
				showHelp()
			} else {
				log.Info("hide help")
				hideHelp()
			}
			return
		}
		return
	}
	if !win.isWindowActive() {
		win.makeWindowActive()
		return
	} else {
		// potentally the user is closing the window
		if win.checkWindowClose(w, h) {
			return
		}
	}

	// look in this window for widgets
	// widgets have priority. send the click here first
	for _, tk := range win.findByXYreal(w, h) {
		switch tk.WidgetType() {
		case widget.Checkbox:
			if tk.Checked() {
				log.Log(WARN, "checkbox is being set to false")
				tk.SetChecked(false)
				tk.setCheckbox()
			} else {
				log.Log(WARN, "checkbox is being set to true")
				tk.SetChecked(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:
			tk.prepTextbox()
			return
		case widget.Label:
			if tk.node.InTable() {
				if tk.node.State.AtH == 0 {
					log.Log(NOW, "todo: sort by column here")
					tk.dumpWidget("sort")
				}
			}
			return
		default:
			// TODO: enable the GUI debugger in gocui
			// tk.dumpWidget("undef click()") // enable this to debug widget clicks
		}
	}
}

// todo: use this?
func ctrlDown(g *gocui.Gui, v *gocui.View) error {
	log.Info("todo: clicked with ctrlDown")
	return nil
}

func doMouseDoubleClick(w int, h int) {
	me.mouse.double = false
	// log.Printf("actually a double click (%d,%d)", w, h)

	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
	}

	for _, tk := range findByXY(w, h) {
		if tk.WidgetType() == widget.Window {
			tk.makeWindowActive()
			return
		}

		if tk.WidgetType() == widget.Stdout {
			if me.stdout.outputOnTop {
				me.stdout.outputOnTop = false
				setThingsOnTop()
			} else {
				me.stdout.outputOnTop = true
				setThingsOnTop()
			}
			return
		}
	}
}