1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Menu button widget for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2009-01-02 00:28:26 +03:00
|
|
|
// Copyright 1998-2009 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Menu_Button.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
2006-01-15 05:21:19 +03:00
|
|
|
|
|
|
|
static Fl_Menu_Button *pressed_menu_button_ = 0;
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void Fl_Menu_Button::draw() {
|
|
|
|
if (!box() || type()) return;
|
2006-01-15 05:21:19 +03:00
|
|
|
draw_box(pressed_menu_button_ == this ? fl_down(box()) : box(), color());
|
1998-10-06 22:21:25 +04:00
|
|
|
draw_label();
|
2001-08-05 00:17:10 +04:00
|
|
|
if (Fl::focus() == this) draw_focus();
|
2009-02-08 20:50:22 +03:00
|
|
|
// ** if (box() == FL_FLAT_BOX) return; // for XForms compatibility
|
2008-09-11 03:56:49 +04:00
|
|
|
int H = (labelsize()-3)&-2;
|
1998-10-06 22:21:25 +04:00
|
|
|
int X = x()+w()-H*2;
|
|
|
|
int Y = y()+(h()-H)/2;
|
2001-08-05 00:17:10 +04:00
|
|
|
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);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
|
|
|
Act exactly as though the user clicked the button or typed the
|
|
|
|
shortcut key. The menu appears, it waits for the user to pick an item,
|
|
|
|
and if they pick one it sets value() and does the callback or
|
|
|
|
sets changed() as described above. The menu item is returned
|
|
|
|
or NULL if the user dismisses the menu.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
const Fl_Menu_Item* Fl_Menu_Button::popup() {
|
|
|
|
const Fl_Menu_Item* m;
|
2006-01-15 05:21:19 +03:00
|
|
|
pressed_menu_button_ = this;
|
|
|
|
redraw();
|
2009-02-08 17:44:15 +03:00
|
|
|
Fl_Watch mb(this);
|
1998-10-06 22:21:25 +04:00
|
|
|
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);
|
2006-01-15 05:21:19 +03:00
|
|
|
pressed_menu_button_ = 0;
|
2009-02-08 17:44:15 +03:00
|
|
|
if (mb.exists()) redraw();
|
1998-10-06 22:21:25 +04:00
|
|
|
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;
|
|
|
|
}
|
2001-12-16 19:41:48 +03:00
|
|
|
if (Fl::visible_focus()) Fl::focus(this);
|
1998-10-06 22:21:25 +04:00
|
|
|
popup();
|
|
|
|
return 1;
|
2001-08-05 00:17:10 +04:00
|
|
|
case FL_KEYBOARD:
|
2002-09-02 02:39:33 +04:00
|
|
|
if (!box()) return 0;
|
2002-11-11 23:22:21 +03:00
|
|
|
if (Fl::event_key() == ' ' &&
|
|
|
|
!(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) {
|
2001-08-05 00:17:10 +04:00
|
|
|
popup();
|
|
|
|
return 1;
|
|
|
|
} else return 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
case FL_SHORTCUT:
|
|
|
|
if (Fl_Widget::test_shortcut()) {popup(); return 1;}
|
|
|
|
return test_shortcut() != 0;
|
2001-08-05 00:17:10 +04:00
|
|
|
case FL_FOCUS:
|
|
|
|
case FL_UNFOCUS:
|
2001-11-03 22:24:22 +03:00
|
|
|
if (box() && Fl::visible_focus()) {
|
2001-08-05 00:17:10 +04:00
|
|
|
redraw();
|
|
|
|
return 1;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
|
|
|
Creates a new Fl_Menu_Button widget using the given position,
|
|
|
|
size, and label string. The default boxtype is FL_UP_BOX.
|
|
|
|
<P>The constructor sets menu() to NULL. See
|
|
|
|
Fl_Menu_ for the methods to set or change the menu.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|