changeset 11224:e0db3f9e9267

Add more checks for uimeu
author Kai Habel <kai.habel@gmx.de>
date Wed, 10 Nov 2010 22:03:58 +0100
parents 64e7538db12a
children 8d8e10058df6
files src/ChangeLog src/DLD-FUNCTIONS/fltk_backend.cc
diffstat 2 files changed, 51 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2010-11-10  Kai Habel  <kai.habel@gmx.de>
+
+	* fltk-backend.cc (update_accelerator), (update_callback), (update_enable),
+	(update_foregroundcolor), (update_visible): Check if find_item
+	was succesful. (update_seperator): Make sure we don't write 
+	beyond limits of menubar structure.
+
 2010-11-10  John W. Eaton  <jwe@octave.org>
 
 	Bug #31491.
--- a/src/DLD-FUNCTIONS/fltk_backend.cc
+++ b/src/DLD-FUNCTIONS/fltk_backend.cc
@@ -377,11 +377,14 @@
       if (!fltk_label.empty ())
         {
           Fl_Menu_Item* item = const_cast<Fl_Menu_Item*>(menubar->find_item (fltk_label.c_str ()));
-          std::string acc = uimenup.get_accelerator ();
-          if (acc.length () > 0)
+          if (item != NULL)
             {
-              int key = FL_CTRL + acc[0];
-              item->shortcut (key);
+              std::string acc = uimenup.get_accelerator ();
+              if (acc.length () > 0)
+                {
+                  int key = FL_CTRL + acc[0];
+                  item->shortcut (key);
+                }
             }
         }
     }
@@ -392,11 +395,14 @@
       if (!fltk_label.empty ())
         {
           Fl_Menu_Item* item = const_cast<Fl_Menu_Item*>(menubar->find_item (fltk_label.c_str ()));
-          if (!uimenup.get_callback ().is_empty ())
-            item->callback(static_cast<Fl_Callback*>(script_cb), //callback
-                          static_cast<void*>(&uimenup));        //callback data
-          else
-            item->callback(NULL, static_cast<void*>(0));
+          if (item != NULL)
+            {
+              if (!uimenup.get_callback ().is_empty ())
+                item->callback(static_cast<Fl_Callback*>(script_cb), //callback
+                              static_cast<void*>(&uimenup));        //callback data
+              else
+                item->callback(NULL, static_cast<void*>(0));
+            }
         }
     }
             
@@ -406,10 +412,13 @@
       if (!fltk_label.empty ())
         {
           Fl_Menu_Item* item = const_cast<Fl_Menu_Item*>(menubar->find_item (fltk_label.c_str ()));
-          if (uimenup.is_enable ())
-            item->activate ();
-          else
-            item->deactivate ();
+          if (item != NULL)
+            {
+              if (uimenup.is_enable ())
+                item->activate ();
+              else
+                item->deactivate ();
+            }
         }
     }
 
@@ -419,10 +428,13 @@
       if (!fltk_label.empty ())
         {
           Fl_Menu_Item* item = const_cast<Fl_Menu_Item*>(menubar->find_item (fltk_label.c_str ()));
-          Matrix rgb = uimenup.get_foregroundcolor_rgb ();
-          item->labelcolor(fl_rgb_color(static_cast<uchar>(floor (rgb(0)*255)),
-                                        static_cast<uchar>(floor (rgb(1)*255)),
-                                        static_cast<uchar>(floor (rgb(2)*255))));
+          if (item != NULL)
+            {
+              Matrix rgb = uimenup.get_foregroundcolor_rgb ();
+              item->labelcolor(fl_rgb_color(static_cast<uchar>(floor (rgb(0)*255)),
+                                            static_cast<uchar>(floor (rgb(1)*255)),
+                                            static_cast<uchar>(floor (rgb(2)*255))));
+            }
         }
     }
 
@@ -445,13 +457,16 @@
                 break;
             }
 
-          if (uimenup.is_separator ())
+          if ((idx >= 0) && (idx < menubar->size ()))
             {
-              if (idx >= 0 && !(itemflags & FL_SUBMENU))
-                menubar->mode (idx, itemflags | FL_MENU_DIVIDER);
+              if (uimenup.is_separator ())
+                {
+                  if (idx >= 0 && !(itemflags & FL_SUBMENU))
+                    menubar->mode (idx, itemflags | FL_MENU_DIVIDER);
+                }
+              else
+                menubar->mode (idx, itemflags & (~FL_MENU_DIVIDER));
             }
-          else
-            menubar->mode (idx, itemflags & (~FL_MENU_DIVIDER));
         }
     }
 
@@ -461,10 +476,13 @@
       if (!fltk_label.empty ())
         {
           Fl_Menu_Item* item = const_cast<Fl_Menu_Item*>(menubar->find_item (fltk_label.c_str ()));
-          if (uimenup.is_visible ())
-            item->show ();
-          else
-            item->hide ();
+          if (item != NULL)
+            {
+              if (uimenup.is_visible ())
+                item->show ();
+              else
+                item->hide ();
+            }
         }
     }