summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-12 20:30:33 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-12 20:31:16 +0200
commit977863ea078e829df10d351a2e9ac3097fb8f5d9 (patch)
tree5ea075feaa74d0ff74381399c85cae1bfbaaa6b0 /Libraries/LibGUI
parent3a905aed063e84331aec82826926cdb89d777892 (diff)
downloadserenity-977863ea078e829df10d351a2e9ac3097fb8f5d9.zip
LibGUI: Include keyboard modifier state with button on_click calls
This will allow you us to implement special behavior when Ctrl+clicking a button.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r--Libraries/LibGUI/AboutDialog.cpp2
-rw-r--r--Libraries/LibGUI/AbstractButton.cpp4
-rw-r--r--Libraries/LibGUI/AbstractButton.h2
-rw-r--r--Libraries/LibGUI/Button.cpp4
-rw-r--r--Libraries/LibGUI/Button.h4
-rw-r--r--Libraries/LibGUI/CheckBox.cpp2
-rw-r--r--Libraries/LibGUI/CheckBox.h2
-rw-r--r--Libraries/LibGUI/ColorPicker.cpp8
-rw-r--r--Libraries/LibGUI/ComboBox.cpp2
-rw-r--r--Libraries/LibGUI/FilePicker.cpp4
-rw-r--r--Libraries/LibGUI/InputBox.cpp4
-rw-r--r--Libraries/LibGUI/MessageBox.cpp2
-rw-r--r--Libraries/LibGUI/RadioButton.cpp2
-rw-r--r--Libraries/LibGUI/RadioButton.h2
-rw-r--r--Libraries/LibGUI/SpinBox.cpp4
15 files changed, 24 insertions, 24 deletions
diff --git a/Libraries/LibGUI/AboutDialog.cpp b/Libraries/LibGUI/AboutDialog.cpp
index f2a3ac4c4d..c6cf1337ef 100644
--- a/Libraries/LibGUI/AboutDialog.cpp
+++ b/Libraries/LibGUI/AboutDialog.cpp
@@ -85,7 +85,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window
auto& ok_button = button_container.add<Button>("OK");
ok_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
ok_button.set_preferred_size(80, 20);
- ok_button.on_click = [this] {
+ ok_button.on_click = [this](auto) {
done(Dialog::ExecOK);
};
}
diff --git a/Libraries/LibGUI/AbstractButton.cpp b/Libraries/LibGUI/AbstractButton.cpp
index b192fefacc..2677b9baa9 100644
--- a/Libraries/LibGUI/AbstractButton.cpp
+++ b/Libraries/LibGUI/AbstractButton.cpp
@@ -134,7 +134,7 @@ void AbstractButton::mouseup_event(MouseEvent& event)
m_being_pressed = false;
update();
if (was_being_pressed && !was_auto_repeating)
- click();
+ click(event.modifiers());
}
Widget::mouseup_event(event);
}
@@ -154,7 +154,7 @@ void AbstractButton::leave_event(Core::Event&)
void AbstractButton::keydown_event(KeyEvent& event)
{
if (event.key() == KeyCode::Key_Return) {
- click();
+ click(event.modifiers());
event.accept();
return;
}
diff --git a/Libraries/LibGUI/AbstractButton.h b/Libraries/LibGUI/AbstractButton.h
index b896a26a2a..d925a451e7 100644
--- a/Libraries/LibGUI/AbstractButton.h
+++ b/Libraries/LibGUI/AbstractButton.h
@@ -52,7 +52,7 @@ public:
bool is_hovered() const { return m_hovered; }
bool is_being_pressed() const { return m_being_pressed; }
- virtual void click() = 0;
+ virtual void click(unsigned modifiers = 0) = 0;
virtual bool accepts_focus() const override { return true; }
virtual bool is_uncheckable() const { return true; }
diff --git a/Libraries/LibGUI/Button.cpp b/Libraries/LibGUI/Button.cpp
index ace26362ec..f662c82de4 100644
--- a/Libraries/LibGUI/Button.cpp
+++ b/Libraries/LibGUI/Button.cpp
@@ -86,7 +86,7 @@ void Button::paint_event(PaintEvent& event)
paint_text(painter, text_rect, font, text_alignment());
}
-void Button::click()
+void Button::click(unsigned modifiers)
{
if (!is_enabled())
return;
@@ -96,7 +96,7 @@ void Button::click()
set_checked(!is_checked());
}
if (on_click)
- on_click();
+ on_click(modifiers);
if (m_action)
m_action->activate(this);
}
diff --git a/Libraries/LibGUI/Button.h b/Libraries/LibGUI/Button.h
index 7ab0d8a9d7..e28972ca4b 100644
--- a/Libraries/LibGUI/Button.h
+++ b/Libraries/LibGUI/Button.h
@@ -47,12 +47,12 @@ public:
void set_text_alignment(Gfx::TextAlignment text_alignment) { m_text_alignment = text_alignment; }
Gfx::TextAlignment text_alignment() const { return m_text_alignment; }
- Function<void()> on_click;
+ Function<void(unsigned modifiers)> on_click;
void set_button_style(Gfx::ButtonStyle style) { m_button_style = style; }
Gfx::ButtonStyle button_style() const { return m_button_style; }
- virtual void click() override;
+ virtual void click(unsigned modifiers = 0) override;
void set_action(Action&);
diff --git a/Libraries/LibGUI/CheckBox.cpp b/Libraries/LibGUI/CheckBox.cpp
index 4917be86d3..f2cdf40897 100644
--- a/Libraries/LibGUI/CheckBox.cpp
+++ b/Libraries/LibGUI/CheckBox.cpp
@@ -97,7 +97,7 @@ void CheckBox::paint_event(PaintEvent& event)
paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft);
}
-void CheckBox::click()
+void CheckBox::click(unsigned)
{
if (!is_enabled())
return;
diff --git a/Libraries/LibGUI/CheckBox.h b/Libraries/LibGUI/CheckBox.h
index 23367dfc96..86b21cfe2a 100644
--- a/Libraries/LibGUI/CheckBox.h
+++ b/Libraries/LibGUI/CheckBox.h
@@ -35,7 +35,7 @@ class CheckBox : public AbstractButton {
public:
virtual ~CheckBox() override;
- virtual void click() override;
+ virtual void click(unsigned modifiers = 0) override;
private:
explicit CheckBox(const StringView& = {});
diff --git a/Libraries/LibGUI/ColorPicker.cpp b/Libraries/LibGUI/ColorPicker.cpp
index c4fbea8c74..b897d9ed93 100644
--- a/Libraries/LibGUI/ColorPicker.cpp
+++ b/Libraries/LibGUI/ColorPicker.cpp
@@ -49,7 +49,7 @@ public:
Function<void(const Color)> on_click;
protected:
- virtual void click() override;
+ virtual void click(unsigned modifiers = 0) override;
virtual void doubleclick_event(GUI::MouseEvent&) override;
virtual void paint_event(PaintEvent&) override;
@@ -136,7 +136,7 @@ void ColorPicker::build_ui()
ok_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
ok_button.set_preferred_size(80, 0);
ok_button.set_text("OK");
- ok_button.on_click = [this] {
+ ok_button.on_click = [this](auto) {
done(ExecOK);
};
@@ -144,7 +144,7 @@ void ColorPicker::build_ui()
cancel_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
cancel_button.set_preferred_size(80, 0);
cancel_button.set_text("Cancel");
- cancel_button.on_click = [this] {
+ cancel_button.on_click = [this](auto) {
done(ExecCancel);
};
}
@@ -368,7 +368,7 @@ void ColorButton::paint_event(PaintEvent& event)
}
}
-void ColorButton::click()
+void ColorButton::click(unsigned)
{
if (on_click)
on_click(m_color);
diff --git a/Libraries/LibGUI/ComboBox.cpp b/Libraries/LibGUI/ComboBox.cpp
index 160994c8fa..75a5fb72e6 100644
--- a/Libraries/LibGUI/ComboBox.cpp
+++ b/Libraries/LibGUI/ComboBox.cpp
@@ -68,7 +68,7 @@ ComboBox::ComboBox()
m_open_button = add<Button>();
m_open_button->set_focusable(false);
m_open_button->set_text("\xc3\xb7");
- m_open_button->on_click = [this] {
+ m_open_button->on_click = [this](auto) {
if (m_list_window->is_visible())
close();
else
diff --git a/Libraries/LibGUI/FilePicker.cpp b/Libraries/LibGUI/FilePicker.cpp
index 019a47d590..f01b565aa0 100644
--- a/Libraries/LibGUI/FilePicker.cpp
+++ b/Libraries/LibGUI/FilePicker.cpp
@@ -216,7 +216,7 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
cancel_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
cancel_button.set_preferred_size(80, 0);
cancel_button.set_text("Cancel");
- cancel_button.on_click = [this] {
+ cancel_button.on_click = [this](auto) {
done(ExecCancel);
};
@@ -224,7 +224,7 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
ok_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
ok_button.set_preferred_size(80, 0);
ok_button.set_text(ok_button_name(m_mode));
- ok_button.on_click = [this] {
+ ok_button.on_click = [this](auto) {
on_file_return();
};
diff --git a/Libraries/LibGUI/InputBox.cpp b/Libraries/LibGUI/InputBox.cpp
index 9d6025f4e4..e8322a68cc 100644
--- a/Libraries/LibGUI/InputBox.cpp
+++ b/Libraries/LibGUI/InputBox.cpp
@@ -83,7 +83,7 @@ void InputBox::build()
m_ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_ok_button->set_preferred_size(0, 20);
m_ok_button->set_text("OK");
- m_ok_button->on_click = [this] {
+ m_ok_button->on_click = [this](auto) {
dbgprintf("GUI::InputBox: OK button clicked\n");
m_text_value = m_text_editor->text();
done(ExecOK);
@@ -93,7 +93,7 @@ void InputBox::build()
m_cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_cancel_button->set_preferred_size(0, 20);
m_cancel_button->set_text("Cancel");
- m_cancel_button->on_click = [this] {
+ m_cancel_button->on_click = [this](auto) {
dbgprintf("GUI::InputBox: Cancel button clicked\n");
done(ExecCancel);
};
diff --git a/Libraries/LibGUI/MessageBox.cpp b/Libraries/LibGUI/MessageBox.cpp
index 019b20d0a9..6ed26e12d2 100644
--- a/Libraries/LibGUI/MessageBox.cpp
+++ b/Libraries/LibGUI/MessageBox.cpp
@@ -134,7 +134,7 @@ void MessageBox::build()
button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
button.set_preferred_size(96, 0);
button.set_text(label);
- button.on_click = [this, label, result] {
+ button.on_click = [this, label, result](auto) {
done(result);
};
};
diff --git a/Libraries/LibGUI/RadioButton.cpp b/Libraries/LibGUI/RadioButton.cpp
index ce0ec5127c..422dadc9d4 100644
--- a/Libraries/LibGUI/RadioButton.cpp
+++ b/Libraries/LibGUI/RadioButton.cpp
@@ -78,7 +78,7 @@ void RadioButton::for_each_in_group(Callback callback)
});
}
-void RadioButton::click()
+void RadioButton::click(unsigned)
{
if (!is_enabled())
return;
diff --git a/Libraries/LibGUI/RadioButton.h b/Libraries/LibGUI/RadioButton.h
index 77c77ec426..ec5c7b8400 100644
--- a/Libraries/LibGUI/RadioButton.h
+++ b/Libraries/LibGUI/RadioButton.h
@@ -35,7 +35,7 @@ class RadioButton : public AbstractButton {
public:
virtual ~RadioButton() override;
- virtual void click() override;
+ virtual void click(unsigned modifiers = 0) override;
protected:
explicit RadioButton(const StringView& text = {});
diff --git a/Libraries/LibGUI/SpinBox.cpp b/Libraries/LibGUI/SpinBox.cpp
index 46bf956cb7..df179ad56b 100644
--- a/Libraries/LibGUI/SpinBox.cpp
+++ b/Libraries/LibGUI/SpinBox.cpp
@@ -45,12 +45,12 @@ SpinBox::SpinBox()
m_increment_button = add<Button>();
m_increment_button->set_focusable(false);
m_increment_button->set_text("\xc3\xb6");
- m_increment_button->on_click = [this] { set_value(m_value + 1); };
+ m_increment_button->on_click = [this](auto) { set_value(m_value + 1); };
m_increment_button->set_auto_repeat_interval(150);
m_decrement_button = add<Button>();
m_decrement_button->set_focusable(false);
m_decrement_button->set_text("\xc3\xb7");
- m_decrement_button->on_click = [this] { set_value(m_value - 1); };
+ m_decrement_button->on_click = [this](auto) { set_value(m_value - 1); };
m_decrement_button->set_auto_repeat_interval(150);
}