1998-10-20 00:46:58 +04:00
|
|
|
//
|
1999-01-07 22:18:01 +03:00
|
|
|
// "$Id: Fl_Menu_.cxx,v 1.5 1999/01/07 19:17:22 mike Exp $"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Common menu code for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
1999-01-07 22:18:01 +03:00
|
|
|
// Copyright 1998-1999 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.
|
|
|
|
//
|
|
|
|
// Please report all bugs and problems to "fltk-bugs@easysw.com".
|
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// This is a base class for all items that have a menu:
|
|
|
|
// Fl_Menu_Bar, Fl_Menu_Button, Fl_Choice
|
|
|
|
// This provides storage for a menu item, functions to add/modify/delete
|
|
|
|
// items, and a call for when the user picks a menu item.
|
|
|
|
|
|
|
|
// More code in Fl_Menu_add.C
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Menu_.H>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
int Fl_Menu_::value(const Fl_Menu_Item* m) {
|
|
|
|
clear_changed();
|
|
|
|
if (value_ != m) {value_ = m; return 1;}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When user picks a menu item, call this. It will do the callback.
|
|
|
|
// Unfortunatly this also casts away const for the checkboxes, but this
|
|
|
|
// was necessary so non-checkbox menus can really be declared const...
|
|
|
|
const Fl_Menu_Item* Fl_Menu_::picked(const Fl_Menu_Item* v) {
|
|
|
|
if (v) {
|
|
|
|
if (v->radio()) {
|
|
|
|
if (!v->value()) { // they are turning on a radio item
|
|
|
|
set_changed();
|
|
|
|
((Fl_Menu_Item*)v)->setonly();
|
|
|
|
}
|
|
|
|
} else if (v->flags & FL_MENU_TOGGLE) {
|
|
|
|
set_changed();
|
|
|
|
((Fl_Menu_Item*)v)->flags ^= FL_MENU_VALUE;
|
|
|
|
} else if (v != value_) { // normal item
|
|
|
|
set_changed();
|
|
|
|
}
|
|
|
|
value_ = v;
|
|
|
|
if (when()&(FL_WHEN_CHANGED|FL_WHEN_RELEASE)) {
|
|
|
|
if (changed() || when()&FL_WHEN_NOT_CHANGED) {
|
|
|
|
clear_changed();
|
|
|
|
if (value_ && value_->callback_) value_->do_callback((Fl_Widget*)this);
|
|
|
|
else do_callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
// turn on one of a set of radio buttons
|
|
|
|
void Fl_Menu_Item::setonly() {
|
|
|
|
flags |= FL_MENU_RADIO | FL_MENU_VALUE;
|
|
|
|
Fl_Menu_Item* j;
|
|
|
|
for (j = this; ; ) { // go down
|
|
|
|
if (j->flags & FL_MENU_DIVIDER) break; // stop on divider lines
|
|
|
|
j++;
|
|
|
|
if (!j->text || !j->radio()) break; // stop after group
|
|
|
|
j->clear();
|
|
|
|
}
|
|
|
|
for (j = this-1; ; j--) { // go up
|
|
|
|
if (!j->text || (j->flags&FL_MENU_DIVIDER) || !j->radio()) break;
|
|
|
|
j->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Menu_::Fl_Menu_(int X,int Y,int W,int H,const char* l)
|
|
|
|
: Fl_Widget(X,Y,W,H,l) {
|
|
|
|
set_flag(SHORTCUT_LABEL);
|
|
|
|
box(FL_UP_BOX);
|
|
|
|
when(FL_WHEN_RELEASE_ALWAYS);
|
|
|
|
value_ = menu_ = 0;
|
|
|
|
alloc = 0;
|
|
|
|
selection_color(FL_SELECTION_COLOR);
|
|
|
|
textfont(FL_HELVETICA);
|
|
|
|
textsize(FL_NORMAL_SIZE);
|
|
|
|
textcolor(FL_BLACK);
|
|
|
|
down_box(FL_NO_BOX);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_Menu_::size() const {
|
|
|
|
if (!menu_) return 0;
|
|
|
|
return menu_->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Menu_::menu(const Fl_Menu_Item* m) {
|
|
|
|
// if (alloc) clear();
|
|
|
|
alloc = 0;
|
|
|
|
value_ = menu_ = (Fl_Menu_Item*)m;
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Menu_::~Fl_Menu_() {
|
|
|
|
// if (alloc) clear();
|
|
|
|
}
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1999-01-07 22:18:01 +03:00
|
|
|
// End of "$Id: Fl_Menu_.cxx,v 1.5 1999/01/07 19:17:22 mike Exp $".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|