Skip to content

Commit

Permalink
Configuration GUI toolkit: Fix checkbox behavior to only toggle on mo…
Browse files Browse the repository at this point in the history
…use click within the button region. Pressing within and releasing outside must not toggle it. Add code to dim to 3D background gray when check box is pressed, to match Windows 3.1 GUI behavior (specifically the 3D Common Controls that later became the default of Windows 95)
  • Loading branch information
joncampbell123 committed Mar 29, 2024
1 parent 935149a commit 1911605
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 37 deletions.
34 changes: 18 additions & 16 deletions src/libs/gui_tk/gui_tk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,27 +987,27 @@ bool Window::mouseDownOutside(MouseButton button) {
bool Window::mouseDown(int x, int y, MouseButton button)
{
std::list<Window *>::reverse_iterator i = children.rbegin();
bool handled = false;
bool doraise = !(button == GUI::WheelUp || button == GUI::WheelDown); /* do not raise if the scroll wheel */
bool handled = false;
bool doraise = !(button == GUI::WheelUp || button == GUI::WheelDown); /* do not raise if the scroll wheel */
Window *last = NULL;

while (i != children.rend()) {
Window *w = *i;

if (w->visible && x >= w->x && x < (w->x+w->width) && y >= w->y && y < (w->y+w->height)) {
if (handled) {
mouseChild = NULL;
return true;
}
if (handled) {
mouseChild = NULL;
return true;
}
mouseChild = last = w;
if (w->mouseDown(x-w->x, y-w->y, button)) {
if (doraise) w->raise();
if (doraise) w->raise();
return true;
}
}
else if (w->transient) {
handled |= w->mouseDownOutside(button);
}
else if (w->transient) {
handled |= w->mouseDownOutside(button);
}

++i;
}
Expand Down Expand Up @@ -1440,17 +1440,19 @@ void Checkbox::paint(Drawable &d) const
d.drawLine(2,(height/2)+5,14,(height/2)+5);
d.drawLine(14,(height/2)-7,14,(height/2)+5);

d.setColor(Color::EditableBackground);
d.fillRect(4,(height/2)-5,9,9);
if (!pressed) {
d.setColor(Color::EditableBackground);
d.fillRect(4,(height/2)-5,9,9);
}

d.setColor(Color::Border);
d.drawLine(3,(height/2)-6,12,(height/2)-6);
d.drawLine(3,(height/2)-6,3,(height/2)+4);

if (hasFocus()) {
d.setColor(Color::Black);
d.drawDotRect(1,(height/2)-8,14,14);
}
if (hasFocus()) {
d.setColor(Color::Black);
d.drawDotRect(1,(height/2)-8,14,14);
}

if (checked) {
d.setColor(Color::Text);
Expand Down
67 changes: 46 additions & 21 deletions src/libs/gui_tk/gui_tk.h
Original file line number Diff line number Diff line change
Expand Up @@ -2331,10 +2331,10 @@ class Button : public BorderedWindow, public ActionEventSource {

/// Press button.
bool mouseDown(int x, int y, MouseButton button) override {
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED

if (button == Left) {
border_left = 7; border_right = 5; border_top = 7; border_bottom = 3;
pressed = true;
Expand All @@ -2344,10 +2344,10 @@ class Button : public BorderedWindow, public ActionEventSource {

/// Release button.
bool mouseUp(int x, int y, MouseButton button) override {
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED

if (button == Left) {
border_left = 6; border_right = 6; border_top = 5; border_bottom = 5;
pressed = false;
Expand All @@ -2357,10 +2357,10 @@ class Button : public BorderedWindow, public ActionEventSource {

/// Handle mouse activation.
bool mouseClicked(int x, int y, MouseButton button) override {
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED

if (button == Left) {
executeAction();
return true;
Expand Down Expand Up @@ -2466,10 +2466,11 @@ class Checkbox : public BorderedWindow, public ActionEventSource {
protected:
/// \c true, if checkbox is currently selected.
bool checked;
bool pressed;

public:
/// Create a checkbox with given position and size
Checkbox(Window *parent, int x, int y, int w, int h) : BorderedWindow(parent,x,y,w,h,16,0,0,0), ActionEventSource("GUI::Checkbox"), checked(0) {}
Checkbox(Window *parent, int x, int y, int w, int h) : BorderedWindow(parent,x,y,w,h,16,0,0,0), ActionEventSource("GUI::Checkbox"), checked(0), pressed(0) {}

/// Create a checkbox with text label.
/** If a size is specified, text is centered. Otherwise, checkbox size is adjusted for the text. */
Expand All @@ -2486,22 +2487,46 @@ class Checkbox : public BorderedWindow, public ActionEventSource {

/// Press checkbox.
bool mouseDown(int x, int y, MouseButton button) override {
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED
checked = !checked;
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED

if (button == Left) {
pressed = true;
}

return true;
}

/// Release checkbox.
bool mouseUp(int x, int y, MouseButton button) override {
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED

if (button == Left) {
pressed = false;
}

execute();
return true;
}

/// Handle mouse activation.
bool mouseClicked(int x, int y, MouseButton button) override {
(void)button;//UNUSED
(void)x;//UNUSED
(void)y;//UNUSED

if (button == Left) {
checked = !checked;
executeAction();
return true;
}

return false;
}

/// Handle keyboard input.
bool keyDown(const Key &key) override;

Expand Down Expand Up @@ -2784,7 +2809,7 @@ template <typename STR> Button::Button(Window *parent, int x, int y, const STR t
}

template <typename STR> Checkbox::Checkbox(Window *parent, int x, int y, const STR text, int w, int h) :
BorderedWindow(parent,x,y,w,h,16,0,0,0), ActionEventSource(text), checked(0)
BorderedWindow(parent,x,y,w,h,16,0,0,0), ActionEventSource(text), checked(0), pressed(0)
{
Label *l = new Label(this,0,0,text);
if (width < 0) resize(l->getWidth()+border_left+border_right+4,height);
Expand Down

0 comments on commit 1911605

Please sign in to comment.