DISTRHO Plugin Framework
EventHandlers.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef DGL_EVENT_HANDLERS_HPP_INCLUDED
18 #define DGL_EVENT_HANDLERS_HPP_INCLUDED
19 
20 #include "Widget.hpp"
21 
22 START_NAMESPACE_DGL
23 
24 // --------------------------------------------------------------------------------------------------------------------
25 
27 {
28 public:
29  enum State {
30  kButtonStateDefault = 0x0,
31  kButtonStateHover = 0x1,
32  kButtonStateActive = 0x2,
33  kButtonStateActiveHover = kButtonStateActive|kButtonStateHover
34  };
35 
36  class Callback
37  {
38  public:
39  virtual ~Callback() {}
40  virtual void buttonClicked(SubWidget* widget, int button) = 0;
41  };
42 
43  explicit ButtonEventHandler(SubWidget* self);
45 
46  bool isActive() noexcept;
47  void setActive(bool active, bool sendCallback) noexcept;
48 
49  bool isChecked() const noexcept;
50  void setChecked(bool checked, bool sendCallback) noexcept;
51 
52  bool isCheckable() const noexcept;
53  void setCheckable(bool checkable) noexcept;
54 
55  void setCallback(Callback* callback) noexcept;
56 
57  bool mouseEvent(const Widget::MouseEvent& ev);
58  bool motionEvent(const Widget::MotionEvent& ev);
59 
60 protected:
61  State getState() const noexcept;
62  void clearState() noexcept;
63 
64  virtual void stateChanged(State state, State oldState);
65 
66 private:
67  struct PrivateData;
68  PrivateData* const pData;
69 
70  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ButtonEventHandler)
71 };
72 
73 // --------------------------------------------------------------------------------------------------------------------
74 
75 END_NAMESPACE_DGL
76 
77 #endif // DGL_EVENT_HANDLERS_HPP_INCLUDED
78 
ButtonEventHandler::Callback
Definition: EventHandlers.hpp:36
SubWidget
Definition: SubWidget.hpp:39
ButtonEventHandler
Definition: EventHandlers.hpp:26
Widget
Definition: Widget.hpp:53