diff options
| author | Bill Spitzak <spitzak@gmail.com> | 1999-04-19 07:01:24 +0000 |
|---|---|---|
| committer | Bill Spitzak <spitzak@gmail.com> | 1999-04-19 07:01:24 +0000 |
| commit | add808d7c28d572090846322575f0a85a1f70ff4 (patch) | |
| tree | 0b582cc4ffc05e68c7c214b2d1f51bc52c0db9b9 /src/Fl_Menu_.cxx | |
| parent | 405f8fba3a14a50bd0340be93eb39e1ede938112 (diff) | |
Changes to Fl_Menu_::add() so that you should be able to add to any menu,
including one that was set with menu(). It copies the static menu if
necessary and keeps track of the size of the menu so it can reallocate
the array exactly when necessary.
This should make modifying the items in a menu much more predictable and
usefule.
I don't know if these changes will go cleanly into 2.0. Probably not.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@550 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Menu_.cxx')
| -rw-r--r-- | src/Fl_Menu_.cxx | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/Fl_Menu_.cxx b/src/Fl_Menu_.cxx index 875eef964..0a608e07e 100644 --- a/src/Fl_Menu_.cxx +++ b/src/Fl_Menu_.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Menu_.cxx,v 1.7.2.2 1999/04/08 19:13:02 carl Exp $" +// "$Id: Fl_Menu_.cxx,v 1.7.2.3 1999/04/19 07:01:23 bill Exp $" // // Common menu code for the Fast Light Tool Kit (FLTK). // @@ -113,16 +113,13 @@ void Fl_Menu_::menu(const Fl_Menu_Item* m) { } 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; + int n = m->size(); 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)); + memcpy(newMenu, m, n*sizeof(Fl_Menu_Item)); menu(newMenu); - alloc = 1; // make destructor free it + alloc = 1; // make destructor free array, but not strings // for convienence, provide way to change all the user data pointers: - if (user_data) for (; s--;) { + if (user_data) for (; n--;) { if (newMenu->callback_) newMenu->user_data_ = user_data; newMenu++; } @@ -132,11 +129,18 @@ Fl_Menu_::~Fl_Menu_() { clear(); } +// Fl_Menu::add() uses this to indicate the owner of the dynamically- +// expanding array. We must not free this array: +Fl_Menu_* fl_menu_array_owner = 0; + void Fl_Menu_::clear() { if (alloc) { if (alloc>1) for (int i = size(); i--;) if (menu_[i].text) free((void*)menu_[i].text); - delete[] menu_; + if (this == fl_menu_array_owner) + fl_menu_array_owner = 0; + else + delete[] menu_; menu_ = 0; value_ = 0; alloc = 0; @@ -144,5 +148,5 @@ void Fl_Menu_::clear() { } // -// End of "$Id: Fl_Menu_.cxx,v 1.7.2.2 1999/04/08 19:13:02 carl Exp $". +// End of "$Id: Fl_Menu_.cxx,v 1.7.2.3 1999/04/19 07:01:23 bill Exp $". // |
