summaryrefslogtreecommitdiff
path: root/src/Fl_Menu_.cxx
diff options
context:
space:
mode:
authorBill Spitzak <spitzak@gmail.com>1999-02-03 08:43:35 +0000
committerBill Spitzak <spitzak@gmail.com>1999-02-03 08:43:35 +0000
commit8009fef12cb88c5d4944bdad9a1e641c282df303 (patch)
tree9c3cacadf5121dba5ee5ab42327ba6a9ab79402a /src/Fl_Menu_.cxx
parent0434a826d57f5de3ef258532cc090717db574d4e (diff)
Put Fl::grab() into it's own source file. Rewritten as suggested so that
it takes a window pointer, and grab(0) releases. You can now call grab repeatedly with the same or different values without it failing. The old Fl::grab() and Fl::release() are emulated in inline functions in Fl.H Added Fl_Menu_::copy(Fl_Menu_Item*), which will be useful for fluid, although that use is nyi. Fixes and cleanup to the code for Fl_Menu_::add(...). git-svn-id: file:///fltk/svn/fltk/trunk@268 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Menu_.cxx')
-rw-r--r--src/Fl_Menu_.cxx34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/Fl_Menu_.cxx b/src/Fl_Menu_.cxx
index 8441212a1..fd2f1bcd4 100644
--- a/src/Fl_Menu_.cxx
+++ b/src/Fl_Menu_.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Menu_.cxx,v 1.5 1999/01/07 19:17:22 mike Exp $"
+// "$Id: Fl_Menu_.cxx,v 1.6 1999/02/03 08:43:32 bill Exp $"
//
// Common menu code for the Fast Light Tool Kit (FLTK).
//
@@ -32,9 +32,9 @@
#include <FL/Fl.H>
#include <FL/Fl_Menu_.H>
+#include <string.h>
#include <stdlib.h>
-
int Fl_Menu_::value(const Fl_Menu_Item* m) {
clear_changed();
if (value_ != m) {value_ = m; return 1;}
@@ -105,15 +105,37 @@ int Fl_Menu_::size() const {
}
void Fl_Menu_::menu(const Fl_Menu_Item* m) {
- // if (alloc) clear();
- alloc = 0;
+ clear();
value_ = menu_ = (Fl_Menu_Item*)m;
}
+void Fl_Menu_::copy(const Fl_Menu_Item* m, void* user_data) {
+ int n = m->size()+1;
+ Fl_Menu_Item* newMenu = new Fl_Menu_Item[n];
+ memcpy(newMenu, m, n*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 (; n--;) {
+ if (newMenu->callback_) newMenu->user_data_ = user_data;
+ newMenu++;
+ }
+}
+
Fl_Menu_::~Fl_Menu_() {
- // if (alloc) clear();
+ clear();
+}
+
+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_;
+ menu_ = 0;
+ alloc = 0;
+ }
}
//
-// End of "$Id: Fl_Menu_.cxx,v 1.5 1999/01/07 19:17:22 mike Exp $".
+// End of "$Id: Fl_Menu_.cxx,v 1.6 1999/02/03 08:43:32 bill Exp $".
//