Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
fltkcomplexbutton.cc
Go to the documentation of this file.
1// fltkcomplexbutton.cc is derived from src/Fl_Button.cxx from FLTK's 1.3
2// branch at http://fltk.org in early 2011.
3// src/Fl_Button.cxx is Copyright 1998-2010 by Bill Spitzak and others.
4
5/*
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <FL/Fl.H>
21#include <FL/Fl_Window.H>
22
23#include "fltkcomplexbutton.hh"
24
25using namespace dw::fltk::ui;
26
33 v = v ? 1 : 0;
34 oldval = v;
35 clear_changed();
36 if (value_ != v) {
37 value_ = v;
38 if (box()) redraw();
39 return 1;
40 } else {
41 return 0;
42 }
43}
44
46 Fl_Color col = value() ? selection_color() : color();
47 draw_box(value() ? (down_box()?down_box():fl_down(box())) : box(), col);
48
49 // ComplexButton is a Group; draw its children
50 for (int i = children () - 1; i >= 0; i--) {
51 // set absolute coordinates for fltk-1.3 --jcid
52 child (i)->position(x()+(w()-child(i)->w())/2,y()+(h()-child(i)->h())/2);
53 draw_child (*child (i));
54 }
55 if (Fl::focus() == this) draw_focus();
56}
57
58int ComplexButton::handle(int event) {
59 int newval;
60 switch (event) {
61 case FL_ENTER: /* FALLTHROUGH */
62 case FL_LEAVE:
63 return 1;
64 case FL_PUSH:
65 if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this);
66 /* fallthrough */
67 case FL_DRAG:
68 if (Fl::event_inside(this)) {
69 newval = !oldval;
70 } else
71 {
72 clear_changed();
73 newval = oldval;
74 }
75 if (newval != value_) {
76 value_ = newval;
77 set_changed();
78 redraw();
79 }
80 return 1;
81 case FL_RELEASE:
82 if (value_ == oldval) {
83 return 1;
84 }
85 set_changed();
87 set_changed();
88 if (when() & FL_WHEN_RELEASE) do_callback();
89 return 1;
90 case FL_FOCUS : /* FALLTHROUGH */
91 case FL_UNFOCUS :
92 if (Fl::visible_focus()) {
93 redraw();
94 return 1;
95 } else return 0;
96 case FL_KEYBOARD :
97 if (Fl::focus() == this &&
98 (Fl::event_key() == ' ' || Fl::event_key() == FL_Enter) &&
99 !(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) {
100 value(1);
101 set_changed();
102 if (when() & FL_WHEN_RELEASE) do_callback();
103 return 1;
104 } else return 0;
105 case FL_KEYUP:
106 if (Fl::focus() == this &&
107 (Fl::event_key() == ' ' || Fl::event_key() == FL_Enter)) {
108 value(0);
109 return 1;
110 }
111 /* fallthrough */
112 default:
113 return 0;
114 }
115}
116
122ComplexButton::ComplexButton(int X, int Y, int W, int H, const char *L)
123: Fl_Group(X,Y,W,H,L) {
124 Fl_Group::current(0);
125 box(FL_UP_BOX);
126 down_box(FL_NO_BOX);
127 value_ = oldval = 0;
128}
129
131 /*
132 * The Fl_Group destructor clear()s the children, but layout expects
133 * the flat view to be around until it deletes it.
134 */
135 remove(0);
136}
char value() const
Returns the current value of the button (0 or 1).
ComplexButton(int X, int Y, int W, int H, const char *L=0)
The constructor creates the button using the given position, size and label.
Fl_Boxtype down_box() const
Returns the current down box type, which is drawn when value() is non-zero.
#define H(x, y, z)
FLTK implementation of dw::core::ui.