cwidget  0.5.18
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  {
50  // Remove the initial construction reference.
51  rval->decref();
52  return rval;
53  }
54 
61  {
63  rval->decref();
64  return rval;
65  }
66 
72  static util::ref_ptr<button> create(const std::string &label)
73  {
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
cwidget::util::ref_ptr< widget >
cwidget::config::key
Represents a keystroke as seen by curses.
Definition: keybindings.h:42
cwidget::widgets::button::handle_key
bool handle_key(const config::key &k)
Handles a keypress in this widget.
Definition: button.cc:130
cwidget::config::global_bindings
keybindings global_bindings
The global keybindings object.
Definition: keybindings.cc:43
cwidget::widgets::point
Definition: widget.h:88
cwidget::widgets::widget::apply_style
void apply_style(const style &st)
Set the display attributes of our associated window directly from the given style.
Definition: widget.cc:58
cwidget::widgets::button
This class represents a push-button.
Definition: button.h:23
cwidget::style_attrs_flip
style style_attrs_flip(attr_t attrs)
Definition: style.h:235
cwidget::fragment_cache
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
toplevel.h
Routines to manage the global cwidget state.
keybindings.h
Support for defining and remapping keybindings.
cwidget::widgets::button::height_request
int height_request(int width)
Calculate the desired height of the widget, given its width.
Definition: button.cc:149
cwidget::widgets::button::create
static util::ref_ptr< button > create(const std::string &label)
Instantiate a button.
Definition: button.h:72
cwidget::widgets::label
label widgets display some (possibly formatted) text statically.
Definition: label.h:24
cwidget::style
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:51
cwidget::fragment
A fragment represents a logical unit of text.
Definition: fragment.h:37
cwidget::widgets::widget::handle_key
virtual bool handle_key(const config::key &k)
Handles a keypress in this widget.
Definition: widget.cc:228
cwidget::widgets::button::paint
void paint(const style &st)
Display this widget.
Definition: button.cc:68
cwidget::widgets::button::button
button(const std::wstring &_label)
Instantiate a button.
Definition: button.cc:24
cwidget::widgets::size
Definition: widget.h:82
cwidget::wchstring
Definition: curses++.h:198
cwidget::wchstring::width
int width() const
Return the number of columns occupied by this string.
Definition: curses++.cc:95
cwidget::fragment_contents
This class represents the formatted contents of a fragment.
Definition: fragment_contents.h:30
cwidget::toplevel::update
void update()
Posts a request to redraw the screen; may be called from any thread.
Definition: toplevel.cc:1072
cwidget::widgets::button::width_request
int width_request()
Definition: button.cc:144
cwidget
The namespace containing everything defined by cwidget.
Definition: columnify.cc:27
cwidget::widgets::button::create
static util::ref_ptr< button > create(fragment *label)
Instantiate a button.
Definition: button.h:60
cwidget::widgets::widget
The basic widget interface.
Definition: widget.h:106