Browse Source

Make keybind map a member of Widget.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 8 years ago
parent
commit
2e734e5618

+ 0 - 1
lib/widget/buttonbar.c

@@ -44,7 +44,6 @@
 #include "lib/skin.h"
 #include "lib/strutil.h"
 #include "lib/util.h"
-#include "lib/keybind.h"        /* global_keymap_t */
 #include "lib/widget.h"
 
 /*** global variables ****************************************************************************/

+ 3 - 1
lib/widget/dialog.c

@@ -198,7 +198,7 @@ dlg_handle_key (WDialog * h, int d_key)
 {
     long command;
 
-    command = keybind_lookup_keymap_command (dialog_map, d_key);
+    command = widget_lookup_key (WIDGET (h), d_key);
     if (command != CK_IgnoreKey)
         return dlg_execute_cmd (h, command);
 
@@ -463,6 +463,8 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flag
     /* Temporary hack: dialog doesn't have an owner, own itself. */
     w->owner = g;
 
+    w->keymap = dialog_map;
+
     w->mouse_handler = dlg_handle_mouse_event;
     w->mouse.forced_capture = mouse_close_dialog && (w->pos_flags & WPOS_FULLSCREEN) == 0;
 

+ 0 - 1
lib/widget/dialog.h

@@ -13,7 +13,6 @@
 
 #include "lib/global.h"
 #include "lib/hook.h"           /* hook_t */
-#include "lib/keybind.h"        /* global_keymap_t */
 
 /*** typedefs(not structures) and defined constants **********************************************/
 

+ 3 - 6
lib/widget/input.c

@@ -46,7 +46,6 @@
 #include "lib/skin.h"
 #include "lib/strutil.h"
 #include "lib/util.h"
-#include "lib/keybind.h"        /* global_keymap_t */
 #include "lib/widget.h"
 #include "lib/event.h"          /* mc_event_raise() */
 #include "lib/mcconfig.h"       /* mc_config_history_*() */
@@ -998,6 +997,7 @@ input_new (int y, int x, const int *colors, int width, const char *def_text,
     w = WIDGET (in);
     widget_init (w, y, x, 1, width, input_callback, input_mouse_callback);
     w->options |= WOP_SELECTABLE | WOP_IS_INPUT | WOP_WANT_CURSOR;
+    w->keymap = input_map;
 
     in->color = colors;
     in->first = TRUE;
@@ -1139,8 +1139,7 @@ input_handle_char (WInput * in, int key)
         return v;
     }
 
-    command = keybind_lookup_keymap_command (input_map, key);
-
+    command = widget_lookup_key (WIDGET (in), key);
     if (command == CK_IgnoreKey)
     {
         if (key > 255)
@@ -1174,9 +1173,7 @@ input_key_is_in_map (WInput * in, int key)
 {
     long command;
 
-    (void) in;
-
-    command = keybind_lookup_keymap_command (input_map, key);
+    command = widget_lookup_key (WIDGET (in), key);
     if (command == CK_IgnoreKey)
         return 0;
 

+ 0 - 2
lib/widget/input.h

@@ -8,8 +8,6 @@
 
 #include <limits.h>             /* MB_LEN_MAX */
 
-#include "lib/keybind.h"        /* global_keymap_t */
-
 /*** typedefs(not structures) and defined constants **********************************************/
 
 #define INPUT(x) ((WInput *)(x))

+ 2 - 2
lib/widget/listbox.c

@@ -42,7 +42,6 @@
 #include "lib/skin.h"
 #include "lib/strutil.h"
 #include "lib/util.h"           /* Q_() */
-#include "lib/keybind.h"        /* global_keymap_t */
 #include "lib/widget.h"
 
 /*** global variables ****************************************************************************/
@@ -355,7 +354,7 @@ listbox_key (WListbox * l, int key)
         return MSG_HANDLED;
     }
 
-    command = keybind_lookup_keymap_command (listbox_map, key);
+    command = widget_lookup_key (WIDGET (l), key);
     if (command == CK_IgnoreKey)
         return MSG_NOT_HANDLED;
     return listbox_execute_cmd (l, command);
@@ -559,6 +558,7 @@ listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn
     w = WIDGET (l);
     widget_init (w, y, x, height, width, listbox_callback, listbox_mouse_callback);
     w->options |= WOP_SELECTABLE | WOP_WANT_HOTKEY;
+    w->keymap = listbox_map;
 
     l->list = NULL;
     l->top = l->pos = 0;

+ 0 - 2
lib/widget/listbox.h

@@ -6,8 +6,6 @@
 #ifndef MC__WIDGET_LISTBOX_H
 #define MC__WIDGET_LISTBOX_H
 
-#include "lib/keybind.h"        /* global_keymap_t */
-
 /*** typedefs(not structures) and defined constants **********************************************/
 
 #define LISTBOX(x) ((WListbox *)(x))

+ 2 - 2
lib/widget/menu.c

@@ -39,7 +39,6 @@
 #include "lib/tty/tty.h"
 #include "lib/skin.h"
 #include "lib/tty/key.h"        /* key macros */
-#include "lib/keybind.h"        /* global_keymap_t */
 #include "lib/strutil.h"
 #include "lib/widget.h"
 #include "lib/event.h"          /* mc_event_raise() */
@@ -589,7 +588,7 @@ menubar_handle_key (WMenuBar * menubar, int key)
     unsigned long cmd;
     cb_ret_t ret = MSG_NOT_HANDLED;
 
-    cmd = keybind_lookup_keymap_command (menu_map, key);
+    cmd = widget_lookup_key (WIDGET (menubar), key);
 
     if (cmd != CK_IgnoreKey)
         ret = menubar_execute_cmd (menubar, cmd);
@@ -950,6 +949,7 @@ menubar_new (GList * menu, gboolean visible)
     /* initially, menubar is not selectable */
     widget_set_options (w, WOP_SELECTABLE, FALSE);
     w->options |= WOP_TOP_SELECT;
+    w->keymap = menu_map;
     menubar->is_visible = visible;
     menubar_set_menu (menubar, menu);
 

+ 26 - 0
lib/widget/widget-common.c

@@ -297,6 +297,11 @@ widget_init (Widget * w, int y, int x, int lines, int cols,
     w->lines = lines;
     w->pos_flags = WPOS_KEEP_DEFAULT;
     w->callback = callback;
+
+    w->keymap = NULL;
+    w->ext_keymap = NULL;
+    w->ext_mode = FALSE;
+
     w->mouse_callback = mouse_callback;
     w->owner = NULL;
     w->mouse_handler = mouse_handle_event;
@@ -697,6 +702,27 @@ widget_overlapped (const Widget * a, const Widget * b)
              || (a->x >= b->x + b->cols) || (b->y >= a->y + a->lines) || (a->y >= b->y + b->lines));
 }
 
+/* --------------------------------------------------------------------------------------------- */
+/**
+  * Look up key event of widget and translate it to command ID.
+  * @param w   widget
+  * @param key key event
+  *
+  * @return command ID binded with @key.
+  */
+
+long
+widget_lookup_key (Widget * w, int key)
+{
+    if (w->ext_mode)
+    {
+        w->ext_mode = FALSE;
+        return keybind_lookup_keymap_command (w->ext_keymap, key);
+    }
+
+    return keybind_lookup_keymap_command (w->keymap, key);
+}
+
 /* --------------------------------------------------------------------------------------------- */
 /**
  * Default callback function to find widget.

+ 8 - 0
lib/widget/widget-common.h

@@ -6,6 +6,7 @@
 #ifndef MC__WIDGET_INTERNAL_H
 #define MC__WIDGET_INTERNAL_H
 
+#include "lib/keybind.h"        /* global_keymap_t */
 #include "lib/tty/mouse.h"
 #include "lib/widget/mouse.h"   /* mouse_msg_t, mouse_event_t */
 
@@ -138,6 +139,11 @@ struct Widget
     widget_mouse_cb_fn mouse_callback;
     WGroup *owner;
 
+    /* Key-related fields */
+    const global_keymap_t *keymap;      /* main keymap */
+    const global_keymap_t *ext_keymap;  /* extended keymap */
+    gboolean ext_mode;          /* use keymap or ext_keymap */
+
     /* Mouse-related fields. */
     widget_mouse_handle_fn mouse_handler;
     struct
@@ -205,6 +211,8 @@ void widget_replace (Widget * old, Widget * new);
 void widget_select (Widget * w);
 void widget_set_bottom (Widget * w);
 
+long widget_lookup_key (Widget * w, int key);
+
 GList *widget_default_find (const Widget * w, const Widget * what);
 Widget *widget_default_find_by_type (const Widget * w, widget_cb_fn cb);
 Widget *widget_default_find_by_id (const Widget * w, unsigned long id);

Some files were not shown because too many files changed in this diff