2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-02-26 20:50:04 +03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-05-24 17:32:20 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Widget.h>
|
2021-07-26 00:20:11 +03:00
|
|
|
#include <LibGfx/TextWrapping.h>
|
2019-05-24 23:54:37 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
namespace GUI {
|
2019-05-24 17:32:20 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
class AbstractButton : public Widget {
|
2020-12-28 15:18:10 +03:00
|
|
|
C_OBJECT_ABSTRACT(AbstractButton);
|
|
|
|
|
2019-05-24 17:32:20 +03:00
|
|
|
public:
|
2022-02-26 20:50:04 +03:00
|
|
|
virtual ~AbstractButton() override = default;
|
2019-05-24 17:32:20 +03:00
|
|
|
|
2019-05-24 18:11:42 +03:00
|
|
|
Function<void(bool)> on_checked;
|
|
|
|
|
2020-12-28 15:18:10 +03:00
|
|
|
void set_text(String);
|
2022-04-01 20:58:27 +03:00
|
|
|
String const& text() const { return m_text; }
|
2019-05-24 17:32:20 +03:00
|
|
|
|
2019-06-12 06:57:26 +03:00
|
|
|
bool is_exclusive() const { return m_exclusive; }
|
|
|
|
void set_exclusive(bool b) { m_exclusive = b; }
|
|
|
|
|
2019-05-24 17:32:20 +03:00
|
|
|
bool is_checked() const { return m_checked; }
|
2021-09-22 00:02:48 +03:00
|
|
|
void set_checked(bool, AllowCallback = AllowCallback::Yes);
|
2019-05-24 17:32:20 +03:00
|
|
|
|
|
|
|
bool is_checkable() const { return m_checkable; }
|
|
|
|
void set_checkable(bool);
|
|
|
|
|
|
|
|
bool is_hovered() const { return m_hovered; }
|
|
|
|
bool is_being_pressed() const { return m_being_pressed; }
|
|
|
|
|
2020-05-12 21:30:33 +03:00
|
|
|
virtual void click(unsigned modifiers = 0) = 0;
|
2019-07-09 23:10:03 +03:00
|
|
|
virtual bool is_uncheckable() const { return true; }
|
2019-05-24 17:32:20 +03:00
|
|
|
|
2019-07-13 11:27:19 +03:00
|
|
|
int auto_repeat_interval() const { return m_auto_repeat_interval; }
|
|
|
|
void set_auto_repeat_interval(int interval) { m_auto_repeat_interval = interval; }
|
|
|
|
|
2019-05-24 17:32:20 +03:00
|
|
|
protected:
|
2020-12-28 15:18:10 +03:00
|
|
|
explicit AbstractButton(String = {});
|
2019-05-24 17:32:20 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual void mousedown_event(MouseEvent&) override;
|
|
|
|
virtual void mousemove_event(MouseEvent&) override;
|
|
|
|
virtual void mouseup_event(MouseEvent&) override;
|
|
|
|
virtual void keydown_event(KeyEvent&) override;
|
2021-06-03 00:59:08 +03:00
|
|
|
virtual void keyup_event(KeyEvent&) override;
|
2020-02-02 14:34:39 +03:00
|
|
|
virtual void enter_event(Core::Event&) override;
|
|
|
|
virtual void leave_event(Core::Event&) override;
|
2021-09-15 18:36:49 +03:00
|
|
|
virtual void focusout_event(GUI::FocusEvent&) override;
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual void change_event(Event&) override;
|
2019-05-24 17:32:20 +03:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
void paint_text(Painter&, Gfx::IntRect const&, Gfx::Font const&, Gfx::TextAlignment, Gfx::TextWrapping = Gfx::TextWrapping::DontWrap);
|
2019-05-24 23:54:37 +03:00
|
|
|
|
2019-05-24 17:32:20 +03:00
|
|
|
private:
|
|
|
|
String m_text;
|
|
|
|
bool m_checked { false };
|
|
|
|
bool m_checkable { false };
|
|
|
|
bool m_hovered { false };
|
|
|
|
bool m_being_pressed { false };
|
2021-09-15 18:36:49 +03:00
|
|
|
bool m_being_keyboard_pressed { false };
|
2019-06-12 06:57:26 +03:00
|
|
|
bool m_exclusive { false };
|
2019-07-13 11:27:19 +03:00
|
|
|
|
|
|
|
int m_auto_repeat_interval { 0 };
|
2020-02-02 14:34:39 +03:00
|
|
|
RefPtr<Core::Timer> m_auto_repeat_timer;
|
2019-05-24 17:32:20 +03:00
|
|
|
};
|
2019-06-12 06:57:26 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
}
|