themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / Fl_Menu_Button.cxx
blobbfd220779ab7f80033869d5dd68332f9b85e9b74
1 //
2 // "$Id: Fl_Menu_Button.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Menu button widget for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 #include <FL/Fl.H>
29 #include <FL/Fl_Menu_Button.H>
30 #include <FL/fl_draw.H>
33 static Fl_Menu_Button *pressed_menu_button_ = 0;
35 void Fl_Menu_Button::draw() {
36 if (!box() || type()) return;
37 draw_box(pressed_menu_button_ == this ? fl_down(box()) : box(), color());
38 draw_label();
39 if (Fl::focus() == this) draw_focus();
40 // ** if (box() == FL_FLAT_BOX) return; // for XForms compatibility
41 int H = (labelsize()-3)&-2;
42 int X = x()+w()-H*2;
43 int Y = y()+(h()-H)/2;
44 fl_color(active_r() ? FL_DARK3 : fl_inactive(FL_DARK3));
45 fl_line(X+H/2, Y+H, X, Y, X+H, Y);
46 fl_color(active_r() ? FL_LIGHT3 : fl_inactive(FL_LIGHT3));
47 fl_line(X+H, Y, X+H/2, Y+H);
50 /**
51 Act exactly as though the user clicked the button or typed the
52 shortcut key. The menu appears, it waits for the user to pick an item,
53 and if they pick one it sets value() and does the callback or
54 sets changed() as described above. The menu item is returned
55 or NULL if the user dismisses the menu.
57 const Fl_Menu_Item* Fl_Menu_Button::popup() {
58 const Fl_Menu_Item* m;
59 pressed_menu_button_ = this;
60 redraw();
61 Fl_Widget_Tracker mb(this);
62 if (!box() || type()) {
63 m = menu()->popup(Fl::event_x(), Fl::event_y(), label(), mvalue(), this);
64 } else {
65 m = menu()->pulldown(x(), y(), w(), h(), 0, this);
67 picked(m);
68 pressed_menu_button_ = 0;
69 if (mb.exists()) redraw();
70 return m;
73 int Fl_Menu_Button::handle(int e) {
74 if (!menu() || !menu()->text) return 0;
75 switch (e) {
76 case FL_ENTER: /* FALLTHROUGH */
77 case FL_LEAVE:
78 return (box() && !type()) ? 1 : 0;
79 case FL_PUSH:
80 if (!box()) {
81 if (Fl::event_button() != 3) return 0;
82 } else if (type()) {
83 if (!(type() & (1 << (Fl::event_button()-1)))) return 0;
85 if (Fl::visible_focus()) Fl::focus(this);
86 popup();
87 return 1;
88 case FL_KEYBOARD:
89 if (!box()) return 0;
90 if (Fl::event_key() == ' ' &&
91 !(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) {
92 popup();
93 return 1;
94 } else return 0;
95 case FL_SHORTCUT:
96 if (Fl_Widget::test_shortcut()) {popup(); return 1;}
97 return test_shortcut() != 0;
98 case FL_FOCUS: /* FALLTHROUGH */
99 case FL_UNFOCUS:
100 if (box() && Fl::visible_focus()) {
101 redraw();
102 return 1;
104 default:
105 return 0;
110 Creates a new Fl_Menu_Button widget using the given position,
111 size, and label string. The default boxtype is FL_UP_BOX.
112 <P>The constructor sets menu() to NULL. See
113 Fl_Menu_ for the methods to set or change the menu.
115 Fl_Menu_Button::Fl_Menu_Button(int X,int Y,int W,int H,const char *l)
116 : Fl_Menu_(X,Y,W,H,l) {
117 down_box(FL_NO_BOX);
121 // End of "$Id: Fl_Menu_Button.cxx 7903 2010-11-28 21:06:39Z matt $".