1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
//
// "$Id: Fl_Menu_Button.cxx,v 1.4.2.3.2.8 2004/04/11 04:38:58 easysw Exp $"
//
// Menu button widget for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2004 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
#include <FL/Fl.H>
#include <FL/Fl_Menu_Button.H>
#include <FL/fl_draw.H>
void Fl_Menu_Button::draw() {
if (!box() || type()) return;
draw_box(box(), color());
draw_label();
if (Fl::focus() == this) draw_focus();
if (box() == FL_FLAT_BOX) return; // for XForms compatability
int H = (labelsize()-3)&-2;
int X = x()+w()-H*2;
int Y = y()+(h()-H)/2;
fl_color(active_r() ? FL_DARK3 : fl_inactive(FL_DARK3));
fl_line(X+H/2, Y+H, X, Y, X+H, Y);
fl_color(active_r() ? FL_LIGHT3 : fl_inactive(FL_LIGHT3));
fl_line(X+H, Y, X+H/2, Y+H);
}
const Fl_Menu_Item* Fl_Menu_Button::popup() {
const Fl_Menu_Item* m;
if (!box() || type()) {
m = menu()->popup(Fl::event_x(), Fl::event_y(), label(), mvalue(), this);
} else {
m = menu()->pulldown(x(), y(), w(), h(), 0, this);
}
picked(m);
return m;
}
int Fl_Menu_Button::handle(int e) {
if (!menu() || !menu()->text) return 0;
switch (e) {
case FL_ENTER:
case FL_LEAVE:
return (box() && !type()) ? 1 : 0;
case FL_PUSH:
if (!box()) {
if (Fl::event_button() != 3) return 0;
} else if (type()) {
if (!(type() & (1 << (Fl::event_button()-1)))) return 0;
}
if (Fl::visible_focus()) Fl::focus(this);
popup();
return 1;
case FL_KEYBOARD:
if (!box()) return 0;
if (Fl::event_key() == ' ' &&
!(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) {
popup();
return 1;
} else return 0;
case FL_SHORTCUT:
if (Fl_Widget::test_shortcut()) {popup(); return 1;}
return test_shortcut() != 0;
case FL_FOCUS:
case FL_UNFOCUS:
if (box() && Fl::visible_focus()) {
redraw();
return 1;
}
default:
return 0;
}
}
Fl_Menu_Button::Fl_Menu_Button(int X,int Y,int W,int H,const char *l)
: Fl_Menu_(X,Y,W,H,l) {
down_box(FL_NO_BOX);
}
//
// End of "$Id: Fl_Menu_Button.cxx,v 1.4.2.3.2.8 2004/04/11 04:38:58 easysw Exp $".
//
|