Author: trilec
Date: 2007-06-10 14:04:52 -0400 (Sun, 10 Jun 2007)
New Revision: 5898
Log:
Menu is no longer a subclass of Group. This removes some casts but it reveals
that we need to move more functions to Widget such as the List (which will also
give us a lot of power).
Note: this work is by both Spitzak and Curtis
Modified:
widget_has_children/fltk/Menu.h
widget_has_children/ide/vcnet/fltk_static.sln
widget_has_children/src/Browser.cxx
widget_has_children/src/ComboBox.cxx
widget_has_children/src/FileBrowser.cxx
widget_has_children/src/Fl_Menu_Item.cxx
widget_has_children/src/Menu.cxx
widget_has_children/src/MenuBar.cxx
widget_has_children/src/Menu_add.cxx
widget_has_children/src/StringList.cxx
Modified: widget_has_children/fltk/Menu.h
===================================================================
--- widget_has_children/fltk/Menu.h 2007-06-10 17:03:52 UTC (rev 5897)
+++ widget_has_children/fltk/Menu.h 2007-06-10 18:04:52 UTC (rev 5898)
@@ -22,7 +22,7 @@
#ifndef fltk_Menu_h
#define fltk_Menu_h
-#include "Group.h"
+#include "Widget.h"
namespace fltk {
@@ -44,7 +44,8 @@
MENU_DIVIDER = 0x80
};
-class FL_API Menu : public Group {
+class FL_API Menu : public Widget {
+ int value_;
public:
@@ -66,7 +67,7 @@
bool set_item(const int* indexes, int level);
Widget* get_item();
- int value() const {return Group::focus_index();}
+ int value() const {return value_;}
bool value(int v);
int size() const {return children();}
@@ -87,21 +88,21 @@
Widget* replace(const char*, unsigned shortcut, Callback*, void* = 0, int =
0);
Widget* insert(int n, const char*, unsigned shortcut, Callback*, void* = 0,
int = 0);
Widget* add(const char*, void* = 0);
- Group* add_group(const char* label, Group* parent=0, void* data=0);
- Widget* add_leaf(const char* label, Group* parent=0, void* data=0);
+ Widget* add_group(const char* label, Widget* parent=0, void* data=0);
+ Widget* add_leaf(const char* label, Widget* parent=0, void* data=0);
Widget* add_many(const char*);
Widget* replace(const char*, void* = 0);
Widget* insert(int n, const char*, void* = 0);
- // Undo the overrides of stuff from Group:
- void add(Widget& o) {Group::add(o);}
+ // Undo the overrides of stuff from Widget:
+ void add(Widget& o) {Widget::add(o);}
void add(Widget* o) {add(*o);}
- void insert(Widget& o, int n) {Group::insert(o, n);}
- void replace(int index, Widget& o) {Group::replace(index, o);}
- void replace(Widget& old, Widget& o) {Group::replace(old,o);}
- void remove(int index) {Group::remove(index);}
- void remove(Widget& o) {Group::remove(o);}
- void remove(Widget* o) {Group::remove(o);}
+ void insert(Widget& o, int n) {Widget::insert(o, n);}
+ void replace(int index, Widget& o) {Widget::replace(index, o);}
+ void replace(Widget& old, Widget& o) {Widget::replace(old,o);}
+ void remove(int index) {Widget::remove(index);}
+ void remove(Widget& o) {Widget::remove(o);}
+ void remove(Widget* o) {Widget::remove(o);}
#ifdef Fl_Menu_Item_h
// Commented-out methods cannot be emulated.
Modified: widget_has_children/ide/vcnet/fltk_static.sln
===================================================================
--- widget_has_children/ide/vcnet/fltk_static.sln 2007-06-10 17:03:52 UTC
(rev 5897)
+++ widget_has_children/ide/vcnet/fltk_static.sln 2007-06-10 18:04:52 UTC
(rev 5898)
@@ -27,6 +27,10 @@
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "menu",
"..\..\..\fltk-2.0.x-r5810\ide\vcnet\test\menu.vcproj",
"{01F6F3FC-3574-4EAD-9F5D-EAA93ABEEE52}"
+ ProjectSection(ProjectDependencies) = postProject
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
@@ -61,6 +65,10 @@
{C1E5804B-938F-4DAD-84E7-5C162448E6DE}.Debug.Build.0 =
Debug|Win32
{C1E5804B-938F-4DAD-84E7-5C162448E6DE}.Release.ActiveCfg =
Release|Win32
{C1E5804B-938F-4DAD-84E7-5C162448E6DE}.Release.Build.0 =
Release|Win32
+ {01F6F3FC-3574-4EAD-9F5D-EAA93ABEEE52}.Debug.ActiveCfg =
Debug|Win32
+ {01F6F3FC-3574-4EAD-9F5D-EAA93ABEEE52}.Debug.Build.0 =
Debug|Win32
+ {01F6F3FC-3574-4EAD-9F5D-EAA93ABEEE52}.Release.ActiveCfg =
Release|Win32
+ {01F6F3FC-3574-4EAD-9F5D-EAA93ABEEE52}.Release.Build.0 =
Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
Modified: widget_has_children/src/Browser.cxx
===================================================================
--- widget_has_children/src/Browser.cxx 2007-06-10 17:03:52 UTC (rev 5897)
+++ widget_has_children/src/Browser.cxx 2007-06-10 18:04:52 UTC (rev 5898)
@@ -1745,8 +1745,8 @@
}
nHeader = 0; header_ = 0;
if (t) { // create new header_ widgets
- Group *g = Group::current();
- Group::current(0);
+ Widget *g = Widget::constructorAddsTo();
+ Widget::constructorAddsTo(0);
while (*t++) nHeader++;
header_ = new Widget*[nHeader];
for (i=0; i<nHeader; i++) {
@@ -1757,7 +1757,7 @@
header_[i]->parent(this);
header_[i]->callback(column_click_cb_, (void*)i);
}
- Group::current(g);
+ Widget::constructorAddsTo(g);
}
layout();
}
@@ -1845,7 +1845,7 @@
*/
NamedStyle* Browser::default_style = &::style;
-static int nogroup(int x) {Group::current(0); return x;}
+static int nogroup(int x) {Widget::constructorAddsTo(0); return x;}
/*! The constructor makes an empty browser. */
Browser::Browser(int X,int Y,int W,int H,const char* L)
@@ -1877,7 +1877,7 @@
}
/*! The destructor deletes all the list items (because they are child
- fltk::Widgets of an fltk::Group) and destroys the browser. */
+ fltk::Widgets) and destroys the browser. */
Browser::~Browser() {
delete[] column_widths_p;
delete[] column_widths_i;
Modified: widget_has_children/src/ComboBox.cxx
===================================================================
--- widget_has_children/src/ComboBox.cxx 2007-06-10 17:03:52 UTC (rev
5897)
+++ widget_has_children/src/ComboBox.cxx 2007-06-10 18:04:52 UTC (rev
5898)
@@ -53,13 +53,13 @@
{
style(default_style);
int w1 = h*4/5;
- Group *g = current();
- current(0);
+ Widget *g = constructorAddsTo();
+ constructorAddsTo(0);
input_ = new Input(x, y, w-w1, h);
input_->box(fltk::NO_BOX);
input_->parent(this);
input_->callback(input_cb);
- current(g);
+ constructorAddsTo(g);
}
ComboBox::~ComboBox() {
Modified: widget_has_children/src/FileBrowser.cxx
===================================================================
--- widget_has_children/src/FileBrowser.cxx 2007-06-10 17:03:52 UTC (rev
5897)
+++ widget_has_children/src/FileBrowser.cxx 2007-06-10 18:04:52 UTC (rev
5898)
@@ -353,7 +353,7 @@
}
void FileBrowser::insert(int n, const char *label, FileIcon*icon) {
- current(0);
+ constructorAddsTo(0);
FileItem * i = new FileItem(strdup(label),icon);
i->w((int) icon_size()); i->h(i->w());
Menu::insert(*i,n);
Modified: widget_has_children/src/Fl_Menu_Item.cxx
===================================================================
--- widget_has_children/src/Fl_Menu_Item.cxx 2007-06-10 17:03:52 UTC (rev
5897)
+++ widget_has_children/src/Fl_Menu_Item.cxx 2007-06-10 18:04:52 UTC (rev
5898)
@@ -114,7 +114,7 @@
const Fl_Menu_Item* picked,
const char* title) const
{
- Group::current(0);
+ Widget::constructorAddsTo(0);
PopupMenu menu(0,0,0,0);
add_to(&menu);
//menu.user_data(data);
@@ -129,7 +129,7 @@
const Fl_Menu_Item*
Fl_Menu_Item::test_shortcut() const
{
- Group::current(0);
+ Widget::constructorAddsTo(0);
Menu menu(0,0,0,0);
add_to(&menu);
//menu.user_data(data);
Modified: widget_has_children/src/Menu.cxx
===================================================================
--- widget_has_children/src/Menu.cxx 2007-06-10 17:03:52 UTC (rev 5897)
+++ widget_has_children/src/Menu.cxx 2007-06-10 18:04:52 UTC (rev 5898)
@@ -94,14 +94,14 @@
\endcode
*/
int List::children(const Menu* menu, const int* indexes, int level) {
- Group* group = (Group*)menu;
+ const Widget* group = menu;
while (level--) {
int i = *indexes++;
// browser can return indexes pointing on -1 values so we must check this :
if (i < 0) return -1; //if (i >= group->children()) return -1;
Widget* widget = group->child(i);
if (!widget->is_group()) return -1;
- group = (Group*)widget;
+ group = widget;
}
return group->children();
}
@@ -126,7 +126,7 @@
}
static fltk::Widget* widget;
if (!widget) {
- fltk::Group::current(0);
+ fltk::Widget::constructorAddsTo(0);
widget = new fltk::Item();
}
widget->label(node->text());
@@ -141,14 +141,14 @@
\endcode
*/
Widget* List::child(const Menu* menu, const int* indexes,int level) {
- Group* group = (Group*)menu;
+ const Widget* group = menu;
for (;;) {
int i = *indexes++;
- if (i < 0 || i >= group->children()) return 0;
+ if (i < 0 || unsigned(i) >= group->children()) return 0;
Widget* widget = group->child(i);
if (!level--) return widget;
if (!widget->is_group()) return 0;
- group = (Group*)widget;
+ group = widget;
}
}
@@ -192,7 +192,7 @@
/*! \class fltk::Menu
The Menu base class is used by Browser, Choice, MenuBar, PopupMenu,
- ComboBox, and other widgets. It is simply a Group and each item is
+ ComboBox, and other widgets. It is simply a Widget and each item is
a child Widget, but it provides functions to select and identify one
of the widgets in the hierarchy below it and do that widget's
callback directly, and functions to create and add Item and
@@ -243,8 +243,8 @@
NamedStyle* Menu::default_style = &::style;
Menu::Menu(int x,int y,int w, int h,const char* l, bool begin)
- : Group(x,y,w,h,l,begin), list_(&default_list), item_(0) {
- resizable(0);
+ : Widget(x,y,w,h,l), list_(&default_list), item_(0) {
+ if (begin) this->begin();
callback(default_callback);
style(default_style);
}
@@ -262,9 +262,9 @@
/*!
Returns the number of children at the top level. Same as children(0,0).
- <i>This Overrides the method of the same name on fltk::Group</i>. This is
+ <i>This Overrides the method of the same name on fltk::Widget</i>. This is
so that an fltk::List can be used. However if no fltk::List is
- specified the action is identical to fltk::Group::children().
+ specified the action is identical to fltk::Widget::children().
*/
int Menu::children() const {
return list_->children(this, 0, 0);
@@ -286,9 +286,9 @@
/*! Returns the given top-level child. Same as child(&index,0).
- <i>This Overrides the method of the same name on fltk::Group</i>. This is
+ <i>This Overrides the method of the same name on fltk::Widget</i>. This is
so that an fltk::List can be used. However if no fltk::List is
- specified the action is identical to fltk::Group::child(index).
+ specified the action is identical to fltk::Widget::child(index).
*/
Widget* Menu::child(int n) const {
return list_->child(this, &n, 0);
@@ -348,23 +348,23 @@
/*!
Remembers a currently selected item in a hierarchy by setting the
- focus_index() of each group to point to the next one. The widget
+ value() of each group to point to the next one. The widget
can then be recovered with get_item(). A redraw(DAMAGE_VALUE) is
done so pulldown menus redraw their display.
*/
bool Menu::set_item(const int* indexes, int level) {
int i = indexes[0];
bool ret = false;
- if (focus_index() != i) {focus_index(i); ret = true;}
+ if (value() != i) {value(i); ret = true;}
if (i < 0 || i >= children()) {
item(0);
} else {
item(child(i));
int j = 1;
while (item() && item()->is_group()) {
- Group* group = (Group*)item();
+ Menu* group = static_cast<Menu*>(item());
int i = (j > level) ? -1 : indexes[j++];
- if (group->focus_index() != i) {group->focus_index(i); ret = true;}
+ if (group->value() != i) {group->value(i); ret = true;}
if (i < 0 || i >= group->children()) break;
item(group->child(i));
}
@@ -374,23 +374,23 @@
}
/*!
- Sets and returns item() based on the focus_index() in this and each
+ Sets and returns item() based on the value() in this and each
child group, thus restoring the value saved with set_item().
This either returns a non-group node, or child group that has an
- illegal Group::focus_index(), or null if this focus_index() is
+ illegal Menu::value(), or null if this value() is
illegal.
If an fltk::List is used this will probably only go to the first
child and not descend any further.
*/
Widget* Menu::get_item() {
- int i = focus_index();
+ int i = value();
if (i < 0 || i >= children()) {item(0); return 0;}
item(child(i));
while (item()->is_group()) {
- Group* group = (Group*)item();
- int i = group->focus_index();
+ Menu* group = static_cast<Menu*>(item());
+ int i = group->value();
if (i < 0 || i >= group->children()) break;
item(group->child(i));
}
@@ -403,8 +403,8 @@
indexes starting at zero.
*/
bool Menu::value(int v) {
- if (v == focus_index()) return false;
- focus_index(v);
+ if (v == value()) return false;
+ value(v);
redraw(DAMAGE_VALUE);
return true;
}
@@ -412,21 +412,21 @@
////////////////////////////////////////////////////////////////
/*! Recursive innards of handle_shortcut. The recursive part only works
- for real children of a child Group, the hierarchy in a List is ignored.
+ for real children of a child Widget, the hierarchy in a List is ignored.
This is because generating every item in a list could take a very
long time, possibly forever. */
-static Widget* shortcut_search(Group* g) {
+static Widget* shortcut_search(Menu* g) {
for (int i = 0; i < g->children(); i++) {
Widget* item = g->child(i);
if (!item->active()) continue;
if (item->test_shortcut(false)) {
- g->focus_index(i);
+ g->value(i);
return item;
}
if (item->is_group()) {
- item = shortcut_search((Group*)item);
+ item = shortcut_search(static_cast<Menu*>(item));
if (item) {
- g->focus_index(i);
+ g->value(i);
return item;
}
}
@@ -465,7 +465,7 @@
return 1;
}
if (item->is_group()) {
- item = shortcut_search((Group*)item);
+ item = shortcut_search(static_cast<Menu*>(item));
if (item) {
value(i);
execute(item);
Modified: widget_has_children/src/MenuBar.cxx
===================================================================
--- widget_has_children/src/MenuBar.cxx 2007-06-10 17:03:52 UTC (rev 5897)
+++ widget_has_children/src/MenuBar.cxx 2007-06-10 18:04:52 UTC (rev 5898)
@@ -93,7 +93,7 @@
Widget* w = child(i);
if (w->active() && w->test_label_shortcut()) {
if (w->is_group()) {value(i); goto J1;} // menu title
- focus_index(Group::find(w)); // Set focus_index, so Menu::get_item()
works
+ value(Widget::find(w)); // Set focus_index, so Menu::get_item() works
if (checkmark(w)) { w->invert_flag(STATE); redraw(); }
execute(w); // button in the menu bar
return 1;
Modified: widget_has_children/src/Menu_add.cxx
===================================================================
--- widget_has_children/src/Menu_add.cxx 2007-06-10 17:03:52 UTC (rev
5897)
+++ widget_has_children/src/Menu_add.cxx 2007-06-10 18:04:52 UTC (rev
5898)
@@ -48,13 +48,13 @@
// Menu-style api:
static Widget* append(
- Group* g,
+ Widget* g,
const char *label,
int flags,
int insert_here
) {
- Group* saved = Group::current();
- Group::current(0);
+ Widget* saved = Widget::constructorAddsTo();
+ Widget::constructorAddsTo(0);
Widget* o;
if (flags & SUBMENU) {
o = new ItemGroup();
@@ -75,7 +75,7 @@
if (insert_here) g->insert(*d, insert_here);
else g->add(d);
}
- Group::current(saved);
+ Widget::constructorAddsTo(saved);
return o;
}
@@ -125,7 +125,7 @@
// Innards of Menu::add() and Menu::replace() methods:
static Widget* innards(
- Group* top,
+ Widget* top,
const char *label,
unsigned shortcut,
Callback *callback,
@@ -134,7 +134,7 @@
AddType what,
int insert_here
) {
- Group* group = top;
+ Widget* group = top;
int bufsize = strlen(label)+1;
ARRAY(char, buf, bufsize);
@@ -170,12 +170,12 @@
group = top;
goto BREAK1;
}
- group = (Group*)append(group, item_label, SUBMENU|flags1, 0);
+ group = append(group, item_label, SUBMENU|flags1, 0);
break;
}
Widget* w = group->child(--n);
if (w->is_group() && match_and_replace(w, item_label, flags, what)) {
- group = (Group*)w;
+ group = w;
break;
}
}
@@ -190,10 +190,10 @@
item = group;
// hack so "/_" adds a divider line
if (flags1 && what!=FIND) {
- Group* saved = Group::current();
- Group::current(0);
+ Widget* saved = Widget::constructorAddsTo();
+ Widget::constructorAddsTo(0);
group->add(new Divider());
- Group::current(saved);
+ Widget::constructorAddsTo(saved);
return item;
}
@@ -324,7 +324,7 @@
is returned.
*/
Widget* Menu::find(const char* label) const {
- return ::innards((Group*)this,label,0,0,0,0,FIND,0);
+ return ::innards(const_cast<Menu*>(this),label,0,0,0,0,FIND,0);
}
////////////////////////////////////////////////////////////////
@@ -334,7 +334,7 @@
// This is the same code except it does not do the splitting at '/'
// thus it is much simpler
static Widget* flat_innards(
- Group* group,
+ Widget* group,
const char *label,
void *data,
int flags,
@@ -404,8 +404,8 @@
Add a parent widget to a (possibly) lower level of the
hierarchy, such as returned by add_group().
*/
-Group* Menu::add_group(const char* label, Group* parent, void* data) {
- return (Group*)::flat_innards(parent?parent:this, label, data, SUBMENU, ADD,
0);
+Widget* Menu::add_group(const char* label, Widget* parent, void* data) {
+ return ::flat_innards(parent?parent:this, label, data, SUBMENU, ADD, 0);
}
/*!
@@ -413,7 +413,7 @@
hierarchy, such as returned by add_group(). If parent is null
or this then this is the same as add(label,data).
*/
-Widget* Menu::add_leaf(const char* label, Group* parent, void* data) {
+Widget* Menu::add_leaf(const char* label, Widget* parent, void* data) {
return ::flat_innards(parent?parent:this, label, data, 0, ADD, 0);
}
Modified: widget_has_children/src/StringList.cxx
===================================================================
--- widget_has_children/src/StringList.cxx 2007-06-10 17:03:52 UTC (rev
5897)
+++ widget_has_children/src/StringList.cxx 2007-06-10 18:04:52 UTC (rev
5898)
@@ -19,7 +19,7 @@
{
// Construct reusable widget:
if (!generated_item_) {
- Group::current(0);
+ Widget::constructorAddsTo(0);
generated_item_ = new Item();
}
// cause measure() to be called if width is needed:
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit