Fl_Input_Choice.H
//
// "$Id: Fl_Input_Choice.H 9740 2012-12-09 17:45:24Z manolo $"
//
// An input/chooser widget.
// ______________ ____
// | || __ |
// | input area || \/ |
// |______________||____|
//
// Copyright 1998-2010 by Bill Spitzak and others.
// Copyright 2004 by Greg Ercolano.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
/* \file
Fl_Input_Choice widget . */
#ifndef Fl_Input_Choice_H
#define Fl_Input_Choice_H
#include <FL/Fl.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Menu_Button.H>
#include <FL/fl_draw.H>
#include <string.h>
class FL_EXPORT Fl_Input_Choice : public Fl_Group {
// Private class to handle slightly 'special' behavior of menu button
class InputMenuButton : public Fl_Menu_Button {
void draw() {
draw_box(FL_UP_BOX, color());
fl_color(active_r() ? labelcolor() : fl_inactive(labelcolor()));
int xc = x()+w()/2, yc=y()+h()/2;
fl_polygon(xc-5,yc-3,xc+5,yc-3,xc,yc+3);
if (Fl::focus() == this) draw_focus();
}
public:
InputMenuButton(int X,int Y,int W,int H,const char*L=0) :
Fl_Menu_Button(X, Y, W, H, L) { box(FL_UP_BOX); }
};
Fl_Input *inp_;
InputMenuButton *menu_;
static void menu_cb(Fl_Widget*, void *data) {
Fl_Input_Choice *o=(Fl_Input_Choice *)data;
Fl_Widget_Tracker wp(o);
const Fl_Menu_Item *item = o->menubutton()->mvalue();
if (item && item->flags & (FL_SUBMENU|FL_SUBMENU_POINTER)) return; // ignore submenus
if (!strcmp(o->inp_->value(), o->menu_->text()))
{
o->Fl_Widget::clear_changed();
if (o->when() & FL_WHEN_NOT_CHANGED)
o->do_callback();
}
else
{
o->inp_->value(o->menu_->text());
o->inp_->set_changed();
o->Fl_Widget::set_changed();
if (o->when() & (FL_WHEN_CHANGED|FL_WHEN_RELEASE))
o->do_callback();
}
if (wp.deleted()) return;
if (o->callback() != default_callback)
{
o->Fl_Widget::clear_changed();
o->inp_->clear_changed();
}
}
static void inp_cb(Fl_Widget*, void *data) {
Fl_Input_Choice *o=(Fl_Input_Choice *)data;
Fl_Widget_Tracker wp(o);
if (o->inp_->changed()) {
o->Fl_Widget::set_changed();
if (o->when() & (FL_WHEN_CHANGED|FL_WHEN_RELEASE))
o->do_callback();
} else {
o->Fl_Widget::clear_changed();
if (o->when() & FL_WHEN_NOT_CHANGED)
o->do_callback();
}
if (wp.deleted()) return;
if (o->callback() != default_callback)
o->Fl_Widget::clear_changed();
}
// Custom resize behavior -- input stretches, menu button doesn't
inline int inp_x() { return(x() + Fl::box_dx(box())); }
inline int inp_y() { return(y() + Fl::box_dy(box())); }
inline int inp_w() { return(w() - Fl::box_dw(box()) - 20); }
inline int inp_h() { return(h() - Fl::box_dh(box())); }
inline int menu_x() { return(x() + w() - 20 - Fl::box_dx(box())); }
inline int menu_y() { return(y() + Fl::box_dy(box())); }
inline int menu_w() { return(20); }
inline int menu_h() { return(h() - Fl::box_dh(box())); }
public:
Fl_Input_Choice(int X,int Y,int W,int H,const char*L=0);
void add(const char *s) { menu_->add(s); }
int changed() const { return inp_->changed() | Fl_Widget::changed(); }
void clear_changed() {
inp_->clear_changed();
Fl_Widget::clear_changed();
}
void set_changed() {
inp_->set_changed();
// no need to call Fl_Widget::set_changed()
}
void clear() { menu_->clear(); }
Fl_Boxtype down_box() const { return (menu_->down_box()); }
void down_box(Fl_Boxtype b) { menu_->down_box(b); }
const Fl_Menu_Item *menu() { return (menu_->menu()); }
void menu(const Fl_Menu_Item *m) { menu_->menu(m); }
void resize(int X, int Y, int W, int H) {
Fl_Group::resize(X,Y,W,H);
inp_->resize(inp_x(), inp_y(), inp_w(), inp_h());
menu_->resize(menu_x(), menu_y(), menu_w(), menu_h());
}
Fl_Color textcolor() const { return (inp_->textcolor());}
void textcolor(Fl_Color c) { inp_->textcolor(c);}
Fl_Font textfont() const { return (inp_->textfont());}
void textfont(Fl_Font f) { inp_->textfont(f);}
Fl_Fontsize textsize() const { return (inp_->textsize()); }
void textsize(Fl_Fontsize s) { inp_->textsize(s); }
const char* value() const { return (inp_->value()); }
void value(const char *val) { inp_->value(val); }
void value(int val) {
menu_->value(val);
inp_->value(menu_->text(val));
}
Fl_Menu_Button *menubutton() { return menu_; }
Fl_Input *input() { return inp_; }
};
#endif // !Fl_Input_Choice_H
//
// End of "$Id: Fl_Input_Choice.H 9740 2012-12-09 17:45:24Z manolo $".
//
- © 1998-2012 by Bill Spitzak and others.