From c477cd9b9879692a03178e67e71448fc97033b66 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Sat, 10 Dec 2022 02:02:35 +1300 Subject: Reworked menu popup and pulldown subprograms to no longer need exceptions --- doc/fl_menu_.html | 4 ++-- doc/fl_menu_button.html | 2 +- src/fltk-widgets-menus-menu_buttons.adb | 15 +++++++++++---- src/fltk-widgets-menus-menu_buttons.ads | 2 +- src/fltk-widgets-menus.adb | 18 ++++-------------- src/fltk-widgets-menus.ads | 4 ++-- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/doc/fl_menu_.html b/doc/fl_menu_.html index 731c16e..522c6e7 100644 --- a/doc/fl_menu_.html +++ b/doc/fl_menu_.html @@ -401,7 +401,7 @@ function Popup X, Y : in Integer; Title : in String := ""; Initial : in Extended_Index := No_Index) - return FLTK.Menu_Items.Menu_Item_Reference; + return Extended_Index; @@ -412,7 +412,7 @@ function Pulldown (This : in Menu; X, Y, W, H : in Integer; Initial : in Extended_Index := No_Index) - return FLTK.Menu_Items.Menu_Item_Reference; + return Extended_Index; diff --git a/doc/fl_menu_button.html b/doc/fl_menu_button.html index 55b9e57..0cc1a9d 100644 --- a/doc/fl_menu_button.html +++ b/doc/fl_menu_button.html @@ -92,7 +92,7 @@ const Fl_Menu_Item * popup();
 function Popup
        (This : in out Menu_Button)
-    return FLTK.Menu_Items.Menu_Item;
+    return Extended_Index;
 
diff --git a/src/fltk-widgets-menus-menu_buttons.adb b/src/fltk-widgets-menus-menu_buttons.adb index babf75f..890d847 100644 --- a/src/fltk-widgets-menus-menu_buttons.adb +++ b/src/fltk-widgets-menus-menu_buttons.adb @@ -53,6 +53,12 @@ package body FLTK.Widgets.Menus.Menu_Buttons is pragma Import (C, fl_menu_button_popup, "fl_menu_button_popup"); pragma Inline (fl_menu_button_popup); + function fl_menu_find_index2 + (M, I : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_menu_find_index2, "fl_menu_find_index2"); + pragma Inline (fl_menu_find_index2); + @@ -126,11 +132,12 @@ package body FLTK.Widgets.Menus.Menu_Buttons is function Popup (This : in out Menu_Button) - return FLTK.Menu_Items.Menu_Item is + return Extended_Index + is + use type Interfaces.C.int; + Ptr : System.Address := fl_menu_button_popup (This.Void_Ptr); begin - return Item : FLTK.Menu_Items.Menu_Item do - Wrapper (Item).Void_Ptr := fl_menu_button_popup (This.Void_Ptr); - end return; + return Extended_Index (fl_menu_find_index2 (This.Void_Ptr, Ptr) + 1); end Popup; diff --git a/src/fltk-widgets-menus-menu_buttons.ads b/src/fltk-widgets-menus-menu_buttons.ads index 31e4347..bccb8f7 100644 --- a/src/fltk-widgets-menus-menu_buttons.ads +++ b/src/fltk-widgets-menus-menu_buttons.ads @@ -37,7 +37,7 @@ package FLTK.Widgets.Menus.Menu_Buttons is function Popup (This : in out Menu_Button) - return FLTK.Menu_Items.Menu_Item; + return Extended_Index; diff --git a/src/fltk-widgets-menus.adb b/src/fltk-widgets-menus.adb index 4ff0f94..817776e 100644 --- a/src/fltk-widgets-menus.adb +++ b/src/fltk-widgets-menus.adb @@ -731,7 +731,7 @@ package body FLTK.Widgets.Menus is X, Y : in Integer; Title : in String := ""; Initial : in Extended_Index := No_Index) - return FLTK.Menu_Items.Menu_Item_Reference + return Extended_Index is Ptr : System.Address := fl_menu_popup (This.Void_Ptr, @@ -739,13 +739,8 @@ package body FLTK.Widgets.Menus is Interfaces.C.int (Y), Interfaces.C.To_C (Title), Interfaces.C.int (Initial) - 1); - Place : Extended_Index := Extended_Index (fl_menu_find_index2 (This.Void_Ptr, Ptr) + 1); begin - if Place = No_Index then - raise No_Reference; - end if; - Wrapper (This.My_Items (Place).all).Void_Ptr := Ptr; - return (Data => This.My_Items (Place)); + return Extended_Index (fl_menu_find_index2 (This.Void_Ptr, Ptr) + 1); end Popup; @@ -753,7 +748,7 @@ package body FLTK.Widgets.Menus is (This : in Menu; X, Y, W, H : in Integer; Initial : in Extended_Index := No_Index) - return FLTK.Menu_Items.Menu_Item_Reference + return Extended_Index is Ptr : System.Address := fl_menu_pulldown (This.Void_Ptr, @@ -762,13 +757,8 @@ package body FLTK.Widgets.Menus is Interfaces.C.int (W), Interfaces.C.int (H), Interfaces.C.int (Initial) - 1); - Place : Extended_Index := Extended_Index (fl_menu_find_index2 (This.Void_Ptr, Ptr) + 1); begin - if Place = No_Index then - raise No_Reference; - end if; - Wrapper (This.My_Items (Place).all).Void_Ptr := Ptr; - return (Data => This.My_Items (Place)); + return Extended_Index (fl_menu_find_index2 (This.Void_Ptr, Ptr) + 1); end Pulldown; diff --git a/src/fltk-widgets-menus.ads b/src/fltk-widgets-menus.ads index eb2d17a..7eb56d2 100644 --- a/src/fltk-widgets-menus.ads +++ b/src/fltk-widgets-menus.ads @@ -206,13 +206,13 @@ package FLTK.Widgets.Menus is X, Y : in Integer; Title : in String := ""; Initial : in Extended_Index := No_Index) - return FLTK.Menu_Items.Menu_Item_Reference; + return Extended_Index; function Pulldown (This : in Menu; X, Y, W, H : in Integer; Initial : in Extended_Index := No_Index) - return FLTK.Menu_Items.Menu_Item_Reference; + return Extended_Index; -- cgit