cwidget  0.5.17
button.h
1 // button.h -*-c++-*-
2 //
3 // A button is just a widget which accepts keyboard focus and can be
4 // "pressed". I'm going to make a stab at sharing code between
5 // normal buttons, radio buttons, and checkbuttons..this may not be
6 // worth it..
7 
8 #ifndef BUTTON_H
9 #define BUTTON_H
10 
11 #include "widget.h"
12 
13 #include <string>
14 
15 namespace cwidget
16 {
17  class fragment;
18  class fragment_cache;
19 
20  namespace widgets
21  {
23  class button : public widget
24  {
26 
27  void accept_focus();
28  void lose_focus();
29 
30  protected:
31  bool handle_key(const config::key &k);
32  fragment_cache *get_label() const {return label;}
33 
39  button(const std::wstring &_label);
40  button(fragment *_label);
41  button(const std::string &_label);
42  public:
43 
44  ~button();
45 
47  create(const std::wstring &label)
48  {
49  util::ref_ptr<button> rval(new button(label));
50  // Remove the initial construction reference.
51  rval->decref();
52  return rval;
53  }
54 
61  {
62  util::ref_ptr<button> rval(new button(label));
63  rval->decref();
64  return rval;
65  }
66 
72  static util::ref_ptr<button> create(const std::string &label)
73  {
74  util::ref_ptr<button> rval(new button(label));
75  rval->decref();
76  return rval;
77  }
78 
79  void paint(const style &st);
80 
81  bool get_cursorvisible();
82  point get_cursorloc();
83  bool focus_me();
84 
85  int width_request();
86  int height_request(int width);
87  void dispatch_mouse(short id, int x, int y, int z, mmask_t bmask);
88 
89  void set_label(const fragment *_label);
90 
91  // Signals:
92 
93  // The button has been "pressed" (activated)
94  sigc::signal0<void> pressed;
95  };
96 
98  }
99 }
100 
101 #endif
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:51
Definition: widget.h:89
Definition: ref_ptr.h:19
int width_request()
Definition: button.cc:144
static util::ref_ptr< button > create(fragment *label)
Instantiate a button.
Definition: button.h:60
The namespace containing everything defined by cwidget.
Definition: columnify.cc:26
This class represents a push-button.
Definition: button.h:23
label widgets display some (possibly formatted) text statically.
Definition: label.h:24
A fragment that caches its contents; a cached result is used if the same width is passed to the layou...
Definition: fragment_cache.h:34
The basic widget interface.
Definition: widget.h:107
Represents a keystroke as seen by curses.
Definition: keybindings.h:42
bool handle_key(const config::key &k)
Handles a keypress in this widget.
Definition: button.cc:130
static util::ref_ptr< button > create(const std::string &label)
Instantiate a button.
Definition: button.h:72
A fragment represents a logical unit of text.
Definition: fragment.h:37
int height_request(int width)
Calculate the desired height of the widget, given its width.
Definition: button.cc:149
void paint(const style &st)
Display this widget.
Definition: button.cc:68
button(const std::wstring &_label)
Instantiate a button.
Definition: button.cc:24