comparison dw/fltkcomplexbutton.cc @ 2035:5625ee0230ad

clean out fltkcomplexbutton a bit
author corvid <corvid@lavabit.com>
date Wed, 18 May 2011 16:19:58 +0000
parents f542084fa707
children 6a8f4de33240
comparison
equal deleted inserted replaced
2034:7cad4651d972 2035:5625ee0230ad
27 27
28 /** 28 /**
29 Sets the current value of the button. 29 Sets the current value of the button.
30 A non-zero value sets the button to 1 (ON), and zero sets it to 0 (OFF). 30 A non-zero value sets the button to 1 (ON), and zero sets it to 0 (OFF).
31 \param[in] v button value. 31 \param[in] v button value.
32 \see set(), clear()
33 */ 32 */
34 int ComplexButton::value(int v) { 33 int ComplexButton::value(int v) {
35 v = v ? 1 : 0; 34 v = v ? 1 : 0;
36 oldval = v; 35 oldval = v;
37 clear_changed(); 36 clear_changed();
43 } else { 42 } else {
44 return 0; 43 return 0;
45 } 44 }
46 } 45 }
47 46
48 /**
49 Turns on this button and turns off all other radio buttons in the group
50 (calling \c value(1) or \c set() does not do this).
51 */
52 void ComplexButton::setonly() { // set this radio button on, turn others off
53 value(1);
54 Fl_Group* g = parent();
55 Fl_Widget*const* a = g->array();
56 for (int i = g->children(); i--;) {
57 Fl_Widget* o = *a++;
58 if (o != this && o->type()==FL_RADIO_BUTTON) ((Fl_Button*)o)->value(0);
59 }
60 }
61
62 void ComplexButton::draw() { 47 void ComplexButton::draw() {
63 if (type() == FL_HIDDEN_BUTTON) return;
64 Fl_Color col = value() ? selection_color() : color(); 48 Fl_Color col = value() ? selection_color() : color();
65 draw_box(value() ? (down_box()?down_box():fl_down(box())) : box(), col); 49 draw_box(value() ? (down_box()?down_box():fl_down(box())) : box(), col);
66 draw_backdrop(); 50 draw_backdrop();
67 if (labeltype() == FL_NORMAL_LABEL && value()) { 51 if (labeltype() == FL_NORMAL_LABEL && value()) {
68 Fl_Color c = labelcolor(); 52 Fl_Color c = labelcolor();
83 int ComplexButton::handle(int event) { 67 int ComplexButton::handle(int event) {
84 int newval; 68 int newval;
85 switch (event) { 69 switch (event) {
86 case FL_ENTER: /* FALLTHROUGH */ 70 case FL_ENTER: /* FALLTHROUGH */
87 case FL_LEAVE: 71 case FL_LEAVE:
88 // if ((value_?selection_color():color())==FL_GRAY) redraw();
89 return 1; 72 return 1;
90 case FL_PUSH: 73 case FL_PUSH:
91 if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this); 74 if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this);
92 case FL_DRAG: 75 case FL_DRAG:
93 if (Fl::event_inside(this)) { 76 if (Fl::event_inside(this)) {
94 if (type() == FL_RADIO_BUTTON) newval = 1; 77 newval = !oldval;
95 else newval = !oldval;
96 } else 78 } else
97 { 79 {
98 clear_changed(); 80 clear_changed();
99 newval = oldval; 81 newval = oldval;
100 } 82 }
109 if (value_ == oldval) { 91 if (value_ == oldval) {
110 if (when() & FL_WHEN_NOT_CHANGED) do_callback(); 92 if (when() & FL_WHEN_NOT_CHANGED) do_callback();
111 return 1; 93 return 1;
112 } 94 }
113 set_changed(); 95 set_changed();
114 if (type() == FL_RADIO_BUTTON) setonly(); 96 value(oldval);
115 else if (type() == FL_TOGGLE_BUTTON) oldval = value_; 97 set_changed();
116 else { 98 if (when() & FL_WHEN_CHANGED) {
117 value(oldval); 99 Fl_Widget_Tracker wp(this);
118 set_changed(); 100 do_callback();
119 if (when() & FL_WHEN_CHANGED) { 101 if (wp.deleted()) return 1;
120 Fl_Widget_Tracker wp(this);
121 do_callback();
122 if (wp.deleted()) return 1;
123 }
124 } 102 }
125 if (when() & FL_WHEN_RELEASE) do_callback(); 103 if (when() & FL_WHEN_RELEASE) do_callback();
126 return 1; 104 return 1;
127 case FL_SHORTCUT:
128 if (!(shortcut() ?
129 Fl::test_shortcut(shortcut()) : test_shortcut())) return 0;
130 if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this);
131 goto triggered_by_keyboard;
132 case FL_FOCUS : /* FALLTHROUGH */ 105 case FL_FOCUS : /* FALLTHROUGH */
133 case FL_UNFOCUS : 106 case FL_UNFOCUS :
134 if (Fl::visible_focus()) { 107 if (Fl::visible_focus()) {
135 if (box() == FL_NO_BOX) { 108 if (box() == FL_NO_BOX) {
136 // Widgets with the FL_NO_BOX boxtype need a parent to 109 // Widgets with the FL_NO_BOX boxtype need a parent to
144 } else return 0; 117 } else return 0;
145 case FL_KEYBOARD : 118 case FL_KEYBOARD :
146 if (Fl::focus() == this && Fl::event_key() == ' ' && 119 if (Fl::focus() == this && Fl::event_key() == ' ' &&
147 !(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) { 120 !(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) {
148 set_changed(); 121 set_changed();
149 triggered_by_keyboard:
150 Fl_Widget_Tracker wp(this); 122 Fl_Widget_Tracker wp(this);
151 if (type() == FL_RADIO_BUTTON && !value_) {
152 setonly();
153 if (when() & FL_WHEN_CHANGED) do_callback();
154 } else if (type() == FL_TOGGLE_BUTTON) {
155 value(!value());
156 if (when() & FL_WHEN_CHANGED) do_callback();
157 }
158 if (wp.deleted()) return 1; 123 if (wp.deleted()) return 1;
159 if (when() & FL_WHEN_RELEASE) do_callback(); 124 if (when() & FL_WHEN_RELEASE) do_callback();
160 return 1; 125 return 1;
161 } 126 }
162 default: 127 default:
173 : Fl_Group(X,Y,W,H,L) { 138 : Fl_Group(X,Y,W,H,L) {
174 Fl_Group::current(0); 139 Fl_Group::current(0);
175 box(FL_UP_BOX); 140 box(FL_UP_BOX);
176 down_box(FL_NO_BOX); 141 down_box(FL_NO_BOX);
177 value_ = oldval = 0; 142 value_ = oldval = 0;
178 shortcut_ = 0;
179 } 143 }
180 144
181 ComplexButton::~ComplexButton() { 145 ComplexButton::~ComplexButton() {
182 /* 146 /*
183 * The Fl_Group destructor clear()s the children, but layout expects 147 * The Fl_Group destructor clear()s the children, but layout expects