1998-10-20 00:46:58 +04:00
|
|
|
//
|
2002-04-11 14:46:19 +04:00
|
|
|
// "$Id: Fl_Choice.cxx,v 1.10.2.5.2.9 2002/04/11 10:46:19 easysw Exp $"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Choice widget for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2002-01-01 18:11:33 +03:00
|
|
|
// Copyright 1998-2002 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.
|
|
|
|
//
|
2000-06-06 01:21:24 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Choice.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
// Emulates the Forms choice widget. This is almost exactly the same
|
|
|
|
// as an Fl_Menu_Button. The only difference is the appearance of the
|
|
|
|
// button: it draws the text of the current pick and a down-arrow.
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
extern char fl_draw_shortcut;
|
|
|
|
|
|
|
|
void Fl_Choice::draw() {
|
2001-08-05 00:17:10 +04:00
|
|
|
int dx = Fl::box_dx(FL_DOWN_BOX);
|
|
|
|
int dy = Fl::box_dy(FL_DOWN_BOX);
|
|
|
|
int H = h() - 2 * dy;
|
2001-11-17 21:18:53 +03:00
|
|
|
int W = (H > 20) ? 20 : H;
|
|
|
|
int X = x() + w() - W - dx;
|
2001-08-05 00:17:10 +04:00
|
|
|
int Y = y() + dy;
|
2001-11-17 21:18:53 +03:00
|
|
|
int w1 = (W - 4) / 3; if (w1 < 1) w1 = 1;
|
|
|
|
int x1 = X + (W - 2 * w1 - 1) / 2;
|
2001-08-05 00:17:10 +04:00
|
|
|
int y1 = Y + (H - w1 - 1) / 2;
|
|
|
|
|
2002-03-26 03:50:16 +03:00
|
|
|
if (Fl::scheme()) {
|
|
|
|
draw_box(FL_UP_BOX, color());
|
2001-08-05 00:17:10 +04:00
|
|
|
|
2002-03-26 03:50:16 +03:00
|
|
|
fl_color(active_r() ? labelcolor() : fl_inactive(labelcolor()));
|
|
|
|
fl_polygon(x1, y1 + 3, x1 + w1, y1 + w1 + 3, x1 + 2 * w1, y1 + 3);
|
|
|
|
fl_polygon(x1, y1 + 1, x1 + w1, y1 - w1 + 1, x1 + 2 * w1, y1 + 1);
|
|
|
|
} else {
|
|
|
|
draw_box(FL_DOWN_BOX, color());
|
|
|
|
draw_box(FL_UP_BOX,X,Y,W,H,FL_GRAY);
|
|
|
|
|
|
|
|
fl_color(active_r() ? labelcolor() : fl_inactive(labelcolor()));
|
|
|
|
fl_polygon(x1, y1, x1 + w1, y1 + w1, x1 + 2 * w1, y1);
|
|
|
|
}
|
2001-08-05 00:17:10 +04:00
|
|
|
|
2002-03-26 01:11:52 +03:00
|
|
|
W += 2 * dx;
|
|
|
|
|
1999-03-07 11:51:44 +03:00
|
|
|
if (mvalue()) {
|
|
|
|
Fl_Menu_Item m = *mvalue();
|
|
|
|
if (active_r()) m.activate(); else m.deactivate();
|
2001-11-17 21:18:53 +03:00
|
|
|
fl_clip(x() + dx, y() + dy + 1, w() - W, H - 2);
|
1999-03-16 11:51:02 +03:00
|
|
|
fl_draw_shortcut = 2; // hack value to make '&' disappear
|
2001-11-17 21:18:53 +03:00
|
|
|
m.draw(x() + dx, y() + dy + 1, w() - W, H - 2, this,
|
2001-08-05 00:17:10 +04:00
|
|
|
Fl::focus() == this);
|
1999-03-07 11:51:44 +03:00
|
|
|
fl_draw_shortcut = 0;
|
1999-03-16 11:51:02 +03:00
|
|
|
fl_pop_clip();
|
1999-03-07 11:51:44 +03:00
|
|
|
}
|
2002-03-26 03:50:16 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
draw_label();
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Choice::Fl_Choice(int x,int y,int w,int h, const char *l)
|
|
|
|
: Fl_Menu_(x,y,w,h,l) {
|
|
|
|
align(FL_ALIGN_LEFT);
|
|
|
|
when(FL_WHEN_RELEASE);
|
|
|
|
textfont(FL_HELVETICA);
|
2001-08-05 00:17:10 +04:00
|
|
|
box(FL_FLAT_BOX);
|
|
|
|
down_box(FL_BORDER_BOX);
|
2002-04-11 14:46:19 +04:00
|
|
|
color(FL_BACKGROUND2_COLOR);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_Choice::value(int v) {
|
|
|
|
if (!Fl_Menu_::value(v)) return 0;
|
|
|
|
redraw();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_Choice::handle(int e) {
|
|
|
|
if (!menu() || !menu()->text) return 0;
|
|
|
|
const Fl_Menu_Item* v;
|
|
|
|
switch (e) {
|
2001-09-30 02:59:45 +04:00
|
|
|
case FL_ENTER:
|
|
|
|
case FL_LEAVE:
|
|
|
|
return 1;
|
|
|
|
|
2001-08-05 00:17:10 +04:00
|
|
|
case FL_KEYBOARD:
|
|
|
|
if (Fl::event_key() != ' ') return 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
case FL_PUSH:
|
2001-12-16 19:41:48 +03:00
|
|
|
if (Fl::visible_focus()) Fl::focus(this);
|
1999-01-19 22:12:51 +03:00
|
|
|
Fl::event_is_click(0);
|
1998-10-06 22:21:25 +04:00
|
|
|
J1:
|
|
|
|
v = menu()->pulldown(x(), y(), w(), h(), mvalue(), this);
|
|
|
|
if (!v || v->submenu()) return 1;
|
|
|
|
if (v != mvalue()) redraw();
|
|
|
|
picked(v);
|
|
|
|
return 1;
|
|
|
|
case FL_SHORTCUT:
|
|
|
|
if (Fl_Widget::test_shortcut()) goto J1;
|
|
|
|
v = menu()->test_shortcut();
|
|
|
|
if (!v) return 0;
|
|
|
|
if (v != mvalue()) redraw();
|
|
|
|
picked(v);
|
|
|
|
return 1;
|
2001-08-05 00:17:10 +04:00
|
|
|
case FL_FOCUS:
|
|
|
|
case FL_UNFOCUS:
|
2001-11-03 22:24:22 +03:00
|
|
|
if (Fl::visible_focus()) {
|
|
|
|
redraw();
|
|
|
|
return 1;
|
|
|
|
} else return 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2002-04-11 14:46:19 +04:00
|
|
|
// End of "$Id: Fl_Choice.cxx,v 1.10.2.5.2.9 2002/04/11 10:46:19 easysw Exp $".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|