Checking in Guillaume Nodet's fix for Fl_Menu_::copy() again. I checked it

in on April 8, but it seems to have disappeared from the CVS.

-Carl


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@574 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Carl E. Thompson 1999-05-06 01:17:49 +00:00
parent 2f942e1c4a
commit 72a313292c

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Menu_.cxx,v 1.7.2.3 1999/04/19 07:01:23 bill Exp $"
// "$Id: Fl_Menu_.cxx,v 1.7.2.4 1999/05/06 01:17:49 carl Exp $"
//
// Common menu code for the Fast Light Tool Kit (FLTK).
//
@ -112,6 +112,7 @@ void Fl_Menu_::menu(const Fl_Menu_Item* m) {
value_ = menu_ = (Fl_Menu_Item*)m;
}
/* This version is broken
void Fl_Menu_::copy(const Fl_Menu_Item* m, void* user_data) {
int n = m->size();
Fl_Menu_Item* newMenu = new Fl_Menu_Item[n];
@ -124,6 +125,24 @@ void Fl_Menu_::copy(const Fl_Menu_Item* m, void* user_data) {
newMenu++;
}
}
*/
// This is Guillaume Nodet's fixed version
void Fl_Menu_::copy(const Fl_Menu_Item* m, void* user_data) {
int i, s = m->size(), n=s;
for (i=0; n; n>>=1, i++);
n = 1 << i;
Fl_Menu_Item* newMenu = new Fl_Menu_Item[n];
memcpy(newMenu, m, s*sizeof(Fl_Menu_Item));
memset(newMenu+s, 0, (n-s)*sizeof(Fl_Menu_Item));
menu(newMenu);
alloc = 1; // make destructor free it
// for convienence, provide way to change all the user data pointers:
if (user_data) for (; s--;) {
if (newMenu->callback_) newMenu->user_data_ = user_data;
newMenu++;
}
}
Fl_Menu_::~Fl_Menu_() {
clear();
@ -148,5 +167,5 @@ void Fl_Menu_::clear() {
}
//
// End of "$Id: Fl_Menu_.cxx,v 1.7.2.3 1999/04/19 07:01:23 bill Exp $".
// End of "$Id: Fl_Menu_.cxx,v 1.7.2.4 1999/05/06 01:17:49 carl Exp $".
//