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
15namespace 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
A fragment that caches its contents; a cached result is used if the same width is passed to the layou...
Definition fragment_cache.h:35
A fragment represents a logical unit of text.
Definition fragment.h:38
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition style.h:52
Definition ref_ptr.h:20
This class represents a push-button.
Definition button.h:24
button(const std::wstring &_label)
Instantiate a button.
Definition button.cc:24
static util::ref_ptr< button > create(fragment *label)
Instantiate a button.
Definition button.h:60
void paint(const style &st)
Display this widget.
Definition button.cc:68
bool handle_key(const config::key &k)
Handles a keypress in this widget.
Definition button.cc:130
int width_request()
Definition button.cc:144
int height_request(int width)
Calculate the desired height of the widget, given its width.
Definition button.cc:149
static util::ref_ptr< button > create(const std::string &label)
Instantiate a button.
Definition button.h:72
label widgets display some (possibly formatted) text statically.
Definition label.h:25
The basic widget interface.
Definition widget.h:107
The namespace containing everything defined by cwidget.
Definition columnify.cc:28
Represents a keystroke as seen by curses.
Definition keybindings.h:43
Definition widget.h:89