From ba19cac8303b22ed415f246ea18dc334dd572343 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Fri, 18 Nov 2016 21:24:27 +1100 Subject: Moved Shortcut_Key type to FLTK.Enums, added function to remove key bindings from Text_Editors --- src/fltk_binding/c_fl_text_editor.cpp | 5 ++ src/fltk_binding/c_fl_text_editor.h | 1 + src/fltk_binding/fltk-enums.adb | 71 ++++++++++++++++++++++ src/fltk_binding/fltk-enums.ads | 47 ++++++++++++++ ...k-widgets-groups-text_displays-text_editors.adb | 21 +++++++ ...k-widgets-groups-text_displays-text_editors.ads | 8 +++ src/fltk_binding/fltk-widgets-menus.adb | 63 +------------------ src/fltk_binding/fltk-widgets-menus.ads | 34 +---------- to_do.txt | 1 + 9 files changed, 156 insertions(+), 95 deletions(-) create mode 100644 src/fltk_binding/fltk-enums.adb diff --git a/src/fltk_binding/c_fl_text_editor.cpp b/src/fltk_binding/c_fl_text_editor.cpp index 1290e7b..c28f6fa 100644 --- a/src/fltk_binding/c_fl_text_editor.cpp +++ b/src/fltk_binding/c_fl_text_editor.cpp @@ -41,3 +41,8 @@ void fl_text_editor_delete(TEXTEDITOR te) { Fl_Text_Editor::kf_delete(0, reinterpret_cast(te)); } + +void fl_text_editor_remove_key_binding(TEXTEDITOR te, unsigned int k, unsigned long m) { + reinterpret_cast(te)->remove_key_binding(k, m); +} + diff --git a/src/fltk_binding/c_fl_text_editor.h b/src/fltk_binding/c_fl_text_editor.h index 8c7dba0..ebaab0d 100644 --- a/src/fltk_binding/c_fl_text_editor.h +++ b/src/fltk_binding/c_fl_text_editor.h @@ -16,6 +16,7 @@ extern "C" void fl_text_editor_cut(TEXTEDITOR te); extern "C" void fl_text_editor_copy(TEXTEDITOR te); extern "C" void fl_text_editor_paste(TEXTEDITOR te); extern "C" void fl_text_editor_delete(TEXTEDITOR te); +extern "C" void fl_text_editor_remove_key_binding(TEXTEDITOR te, unsigned int k, unsigned long m); #endif diff --git a/src/fltk_binding/fltk-enums.adb b/src/fltk_binding/fltk-enums.adb new file mode 100644 index 0000000..292e5ff --- /dev/null +++ b/src/fltk_binding/fltk-enums.adb @@ -0,0 +1,71 @@ + + +with Interfaces.C; +use type Interfaces.C.unsigned_long; + + +package body FLTK.Enums is + + + function Shortcut + (Key : Pressable_Key) + return Shortcut_Key is + begin + return This : Shortcut_Key do + This.Modifier := Mod_None; + This.Keypress := Key; + end return; + end Shortcut; + + + + + function Key_To_C + (Key : Shortcut_Key) + return Interfaces.C.unsigned_long is + begin + return Interfaces.C.unsigned_long (Key.Modifier) * + 65536 + Character'Pos (Key.Keypress); + end Key_To_C; + + + + + function "+" + (Left, Right : in Modifier_Key) + return Modifier_Key is + begin + return Left or Right; + end "+"; + + + + + function "+" + (Left : in Modifier_Key; + Right : in Pressable_Key) + return Shortcut_Key is + begin + return This : Shortcut_Key do + This.Modifier := Left; + This.Keypress := Right; + end return; + end "+"; + + + + + function "+" + (Left : in Modifier_Key; + Right : in Shortcut_Key) + return Shortcut_Key is + begin + return This : Shortcut_Key do + This.Modifier := Left or Right.Modifier; + This.Keypress := Right.Keypress; + end return; + end "+"; + + +end FLTK.Enums; + diff --git a/src/fltk_binding/fltk-enums.ads b/src/fltk_binding/fltk-enums.ads index 00a56c2..91f7353 100644 --- a/src/fltk_binding/fltk-enums.ads +++ b/src/fltk_binding/fltk-enums.ads @@ -1,5 +1,9 @@ +with Interfaces.C; +private with FLTK.Enum_Values; + + package FLTK.Enums is @@ -95,5 +99,48 @@ package FLTK.Enums is Free_Label); + -- type Modifier_Key is private; + type Modifier_Key is new Interfaces.Unsigned_8; + + -- type Shortcut_Key is private; + type Shortcut_Key is + record + Modifier : Modifier_Key; + Keypress : Character; + end record; + + subtype Pressable_Key is Character range Character'Val (32) .. Character'Val (126); + function Shortcut (Key : Pressable_Key) return Shortcut_Key; + No_Key : constant Shortcut_Key; + + + function "+" (Left, Right : in Modifier_Key) return Modifier_Key; + function "+" (Left : in Modifier_Key; Right : in Pressable_Key) return Shortcut_Key; + function "+" (Left : in Modifier_Key; Right : in Shortcut_Key) return Shortcut_Key; + Mod_None : constant Modifier_Key; + Mod_Shift : constant Modifier_Key; + Mod_Ctrl : constant Modifier_Key; + Mod_Alt : constant Modifier_Key; + + + function Key_To_C + (Key : Shortcut_Key) + return Interfaces.C.unsigned_long; + + +private + + + -- these values designed to align with FLTK enumeration types + Mod_None : constant Modifier_Key := 2#00000000#; + Mod_Shift : constant Modifier_Key := 2#00000001#; + Mod_Ctrl : constant Modifier_Key := 2#00000100#; + Mod_Alt : constant Modifier_Key := 2#00001000#; + + + No_Key : constant Shortcut_Key := + (Modifier => Mod_None, Keypress => Character'Val (0)); + + end FLTK.Enums; diff --git a/src/fltk_binding/fltk-widgets-groups-text_displays-text_editors.adb b/src/fltk_binding/fltk-widgets-groups-text_displays-text_editors.adb index ce7684c..0172128 100644 --- a/src/fltk_binding/fltk-widgets-groups-text_displays-text_editors.adb +++ b/src/fltk_binding/fltk-widgets-groups-text_displays-text_editors.adb @@ -38,6 +38,12 @@ package body FLTK.Widgets.Groups.Text_Displays.Text_Editors is (TE : in System.Address); pragma Import (C, fl_text_editor_delete, "fl_text_editor_delete"); + procedure fl_text_editor_remove_key_binding + (TE : in System.Address; + K : in Interfaces.C.unsigned; + M : in Interfaces.C.unsigned_long); + pragma Import (C, fl_text_editor_remove_key_binding, "fl_text_editor_remove_key_binding"); + @@ -120,5 +126,20 @@ package body FLTK.Widgets.Groups.Text_Displays.Text_Editors is end Delete; + + + procedure Remove_Key_Binding + (This : in out Text_Editor; + Key : in Shortcut_Key) + is + use type Interfaces.C.unsigned_long; + begin + fl_text_editor_remove_key_binding + (This.Void_Ptr, + Character'Pos (Key.Keypress), + Interfaces.C.unsigned_long (Key.Modifier) * 65536); + end Remove_Key_Binding; + + end FLTK.Widgets.Groups.Text_Displays.Text_Editors; diff --git a/src/fltk_binding/fltk-widgets-groups-text_displays-text_editors.ads b/src/fltk_binding/fltk-widgets-groups-text_displays-text_editors.ads index 5e3ff01..d4c9b85 100644 --- a/src/fltk_binding/fltk-widgets-groups-text_displays-text_editors.ads +++ b/src/fltk_binding/fltk-widgets-groups-text_displays-text_editors.ads @@ -1,5 +1,8 @@ +with FLTK.Enums; use FLTK.Enums; + + package FLTK.Widgets.Groups.Text_Displays.Text_Editors is @@ -32,6 +35,11 @@ package FLTK.Widgets.Groups.Text_Displays.Text_Editors is (This : in out Text_Editor); + procedure Remove_Key_Binding + (This : in out Text_Editor; + Key : in Shortcut_Key); + + private diff --git a/src/fltk_binding/fltk-widgets-menus.adb b/src/fltk_binding/fltk-widgets-menus.adb index b1ffd9a..b92f0a1 100644 --- a/src/fltk_binding/fltk-widgets-menus.adb +++ b/src/fltk_binding/fltk-widgets-menus.adb @@ -1,5 +1,6 @@ +with FLTK.Enums; use FLTK.Enums; with Interfaces.C; with System; use type System.Address; @@ -10,68 +11,6 @@ use type Interfaces.C.unsigned_long; package body FLTK.Widgets.Menus is - function Shortcut - (Key : Pressable_Key) - return Shortcut_Key is - begin - return This : Shortcut_Key do - This.Modifier := Mod_None; - This.Keypress := Key; - end return; - end Shortcut; - - - - - function Key_To_C - (Key : Shortcut_Key) - return Interfaces.C.unsigned_long is - begin - return Interfaces.C.unsigned_long (Key.Modifier) * - 65536 + Character'Pos (Key.Keypress); - end Key_To_C; - - - - - function "+" - (Left, Right : in Modifier_Key) - return Modifier_Key is - begin - return Left or Right; - end "+"; - - - - - function "+" - (Left : in Modifier_Key; - Right : in Pressable_Key) - return Shortcut_Key is - begin - return This : Shortcut_Key do - This.Modifier := Left; - This.Keypress := Right; - end return; - end "+"; - - - - - function "+" - (Left : in Modifier_Key; - Right : in Shortcut_Key) - return Shortcut_Key is - begin - return This : Shortcut_Key do - This.Modifier := Left or Right.Modifier; - This.Keypress := Right.Keypress; - end return; - end "+"; - - - - function "+" (Left, Right : in Menu_Flag) return Menu_Flag is diff --git a/src/fltk_binding/fltk-widgets-menus.ads b/src/fltk_binding/fltk-widgets-menus.ads index 0346d2d..d01f02e 100644 --- a/src/fltk_binding/fltk-widgets-menus.ads +++ b/src/fltk_binding/fltk-widgets-menus.ads @@ -1,5 +1,6 @@ +with FLTK.Enums; use FLTK.Enums; private with Interfaces; private with System; @@ -18,22 +19,6 @@ package FLTK.Widgets.Menus is type Index is new Positive; - type Shortcut_Key is private; - subtype Pressable_Key is Character range Character'Val (32) .. Character'Val (126); - function Shortcut (Key : Pressable_Key) return Shortcut_Key; - No_Key : constant Shortcut_Key; - - - type Modifier_Key is private; - function "+" (Left, Right : in Modifier_Key) return Modifier_Key; - function "+" (Left : in Modifier_Key; Right : in Pressable_Key) return Shortcut_Key; - function "+" (Left : in Modifier_Key; Right : in Shortcut_Key) return Shortcut_Key; - Mod_None : constant Modifier_Key; - Mod_Shift : constant Modifier_Key; - Mod_Ctrl : constant Modifier_Key; - Mod_Alt : constant Modifier_Key; - - type Menu_Flag is private; function "+" (Left, Right : in Menu_Flag) return Menu_Flag; Flag_Normal : constant Menu_Flag; @@ -96,23 +81,6 @@ private end record; - -- these values designed to align with FLTK enumeration types - type Modifier_Key is new Interfaces.Unsigned_8; - Mod_None : constant Modifier_Key := 2#00000000#; - Mod_Shift : constant Modifier_Key := 2#00000001#; - Mod_Ctrl : constant Modifier_Key := 2#00000100#; - Mod_Alt : constant Modifier_Key := 2#00001000#; - - - type Shortcut_Key is - record - Modifier : Modifier_Key; - Keypress : Character; - end record; - No_Key : constant Shortcut_Key := - (Modifier => Mod_None, Keypress => Character'Val (0)); - - type Menu_Flag is new Interfaces.Unsigned_8; Flag_Normal : constant Menu_Flag := 2#00000000#; Flag_Inactive : constant Menu_Flag := 2#00000001#; diff --git a/to_do.txt b/to_do.txt index 64ce123..89c0ed0 100644 --- a/to_do.txt +++ b/to_do.txt @@ -6,6 +6,7 @@ To Do: - improve undo/redo - suppress unnecessary left/right scrollbar - clean up menu widget code, adapad menu and callback code +- make shortcut_key types private somehow - introduce maybe type to eliminate out parameters in search_forward/search_backward - eliminate image/text_buffer runtime warnings - separate fltk binding into its own repo -- cgit