Просмотр исходного кода

Drop old mouse API and use the new one.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 9 лет назад
Родитель
Сommit
8490ca7be4
10 измененных файлов с 53 добавлено и 87 удалено
  1. 0 3
      lib/tty/mouse.h
  2. 1 2
      lib/widget/button.c
  3. 1 2
      lib/widget/buttonbar.c
  4. 1 2
      lib/widget/check.c
  5. 26 11
      lib/widget/dialog.c
  6. 1 2
      lib/widget/dialog.h
  7. 1 2
      lib/widget/input.c
  8. 1 2
      lib/widget/listbox.c
  9. 2 3
      lib/widget/menu.c
  10. 19 58
      lib/widget/mouse.c

+ 0 - 3
lib/tty/mouse.h

@@ -89,9 +89,6 @@ typedef struct Gpm_Event
 } Gpm_Event;
 } Gpm_Event;
 #endif /* !HAVE_LIBGPM */
 #endif /* !HAVE_LIBGPM */
 
 
-/* Mouse callback */
-typedef int (*mouse_h) (Gpm_Event *, void *);
-
 /*** global variables defined in .c file *********************************************************/
 /*** global variables defined in .c file *********************************************************/
 
 
 /* Type of the currently used mouse */
 /* Type of the currently used mouse */

+ 1 - 2
lib/widget/button.c

@@ -210,8 +210,7 @@ button_new (int y, int x, int action, button_flags_t flags, const char *text, bc
     b->action = action;
     b->action = action;
     b->flags = flags;
     b->flags = flags;
     b->text = parse_hotkey (text);
     b->text = parse_hotkey (text);
-    widget_init (w, y, x, 1, button_get_len (b), button_callback, NULL);
+    widget_init (w, y, x, 1, button_get_len (b), button_callback, button_mouse_callback);
-    set_easy_mouse_callback (w, button_mouse_callback);
     b->selected = FALSE;
     b->selected = FALSE;
     b->callback = callback;
     b->callback = callback;
     widget_want_hotkey (w, TRUE);
     widget_want_hotkey (w, TRUE);

+ 1 - 2
lib/widget/buttonbar.c

@@ -248,8 +248,7 @@ buttonbar_new (gboolean visible)
 
 
     bb = g_new0 (WButtonBar, 1);
     bb = g_new0 (WButtonBar, 1);
     w = WIDGET (bb);
     w = WIDGET (bb);
-    widget_init (w, LINES - 1, 0, 1, COLS, buttonbar_callback, NULL);
+    widget_init (w, LINES - 1, 0, 1, COLS, buttonbar_callback, buttonbar_mouse_callback);
-    set_easy_mouse_callback (w, buttonbar_mouse_callback);
 
 
     w->pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM;
     w->pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM;
     bb->visible = visible;
     bb->visible = visible;

+ 1 - 2
lib/widget/check.c

@@ -138,8 +138,7 @@ check_new (int y, int x, int state, const char *text)
     w = WIDGET (c);
     w = WIDGET (c);
     c->text = parse_hotkey (text);
     c->text = parse_hotkey (text);
     /* 4 is width of "[X] " */
     /* 4 is width of "[X] " */
-    widget_init (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, NULL);
+    widget_init (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_mouse_callback);
-    set_easy_mouse_callback (w, check_mouse_callback);
     c->state = state ? C_BOOL : 0;
     c->state = state ? C_BOOL : 0;
     widget_want_hotkey (w, TRUE);
     widget_want_hotkey (w, TRUE);
 
 

+ 26 - 11
lib/widget/dialog.c

@@ -40,10 +40,12 @@
 #include "lib/skin.h"
 #include "lib/skin.h"
 #include "lib/tty/key.h"
 #include "lib/tty/key.h"
 #include "lib/strutil.h"
 #include "lib/strutil.h"
-#include "lib/widget.h"
 #include "lib/fileloc.h"        /* MC_HISTORY_FILE */
 #include "lib/fileloc.h"        /* MC_HISTORY_FILE */
 #include "lib/event.h"          /* mc_event_raise() */
 #include "lib/event.h"          /* mc_event_raise() */
 
 
+#include "lib/widget.h"
+#include "lib/widget/mouse.h"
+
 /*** global variables ****************************************************************************/
 /*** global variables ****************************************************************************/
 
 
 /* Color styles for normal and error dialogs */
 /* Color styles for normal and error dialogs */
@@ -355,6 +357,22 @@ dlg_handle_key (WDialog * h, int d_key)
     return MSG_NOT_HANDLED;
     return MSG_NOT_HANDLED;
 }
 }
 
 
+/* --------------------------------------------------------------------------------------------- */
+/**
+ * This is the low-level mouse handler.
+ * It receives a Gpm_Event event and translates it into a higher level protocol.
+ */
+static int
+dlg_mouse_translator (Gpm_Event * event, Widget * w)
+{
+    gboolean run_click;
+    mouse_event_t me;
+
+    me = mouse_translate_event (w, event, &run_click);
+
+    return mouse_process_event (w, &me, run_click);
+}
+
 /* --------------------------------------------------------------------------------------------- */
 /* --------------------------------------------------------------------------------------------- */
 
 
 static int
 static int
@@ -373,11 +391,11 @@ dlg_mouse_event (WDialog * h, Gpm_Event * event)
         return MOU_NORMAL;
         return MOU_NORMAL;
     }
     }
 
 
-    if (wh->mouse != NULL)
+    if (wh->mouse_callback != NULL)
     {
     {
         int mou;
         int mou;
 
 
-        mou = wh->mouse (event, wh);
+        mou = dlg_mouse_translator (event, wh);
         if (mou != MOU_UNHANDLED)
         if (mou != MOU_UNHANDLED)
             return mou;
             return mou;
     }
     }
@@ -388,12 +406,12 @@ dlg_mouse_event (WDialog * h, Gpm_Event * event)
     {
     {
         Widget *w = WIDGET (p->data);
         Widget *w = WIDGET (p->data);
 
 
-        if ((w->options & W_DISABLED) == 0 && w->mouse != NULL)
+        if ((w->options & W_DISABLED) == 0 && w->mouse_callback != NULL)
         {
         {
             /* put global cursor position to the widget */
             /* put global cursor position to the widget */
             int ret;
             int ret;
 
 
-            ret = w->mouse (event, w);
+            ret = dlg_mouse_translator (event, w);
             if (ret != MOU_UNHANDLED)
             if (ret != MOU_UNHANDLED)
                 return ret;
                 return ret;
         }
         }
@@ -771,7 +789,7 @@ dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v
 
 
 WDialog *
 WDialog *
 dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
 dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
-            const int *colors, widget_cb_fn callback, mouse_h mouse_handler,
+            const int *colors, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback,
             const char *help_ctx, const char *title, dlg_flags_t flags)
             const char *help_ctx, const char *title, dlg_flags_t flags)
 {
 {
     WDialog *new_d;
     WDialog *new_d;
@@ -780,7 +798,7 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
     new_d = g_new0 (WDialog, 1);
     new_d = g_new0 (WDialog, 1);
     w = WIDGET (new_d);
     w = WIDGET (new_d);
     widget_init (w, y1, x1, lines, cols, (callback != NULL) ? callback : dlg_default_callback,
     widget_init (w, y1, x1, lines, cols, (callback != NULL) ? callback : dlg_default_callback,
-                 mouse_handler);
+                 mouse_callback);
     widget_want_cursor (w, FALSE);
     widget_want_cursor (w, FALSE);
 
 
     new_d->state = DLG_CONSTRUCT;
     new_d->state = DLG_CONSTRUCT;
@@ -1245,11 +1263,8 @@ dlg_process_event (WDialog * h, int key, Gpm_Event * event)
         if (tty_got_interrupt ())
         if (tty_got_interrupt ())
             if (send_message (h, NULL, MSG_ACTION, CK_Cancel, NULL) != MSG_HANDLED)
             if (send_message (h, NULL, MSG_ACTION, CK_Cancel, NULL) != MSG_HANDLED)
                 dlg_execute_cmd (h, CK_Cancel);
                 dlg_execute_cmd (h, CK_Cancel);
-
-        return;
     }
     }
-
+    else if (key == EV_MOUSE)
-    if (key == EV_MOUSE)
         h->mouse_status = dlg_mouse_event (h, event);
         h->mouse_status = dlg_mouse_event (h, event);
     else
     else
         dlg_key_event (h, key);
         dlg_key_event (h, key);

+ 1 - 2
lib/widget/dialog.h

@@ -14,7 +14,6 @@
 #include "lib/global.h"
 #include "lib/global.h"
 #include "lib/hook.h"           /* hook_t */
 #include "lib/hook.h"           /* hook_t */
 #include "lib/keybind.h"        /* global_keymap_t */
 #include "lib/keybind.h"        /* global_keymap_t */
-#include "lib/tty/mouse.h"      /* mouse_h */
 
 
 /*** typedefs(not structures) and defined constants **********************************************/
 /*** typedefs(not structures) and defined constants **********************************************/
 
 
@@ -128,7 +127,7 @@ extern const global_keymap_t *dialog_map;
 
 
 /* Creates a dialog head  */
 /* Creates a dialog head  */
 WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
 WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
-                     const int *colors, widget_cb_fn callback, mouse_h mouse_handler,
+                     const int *colors, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback,
                      const char *help_ctx, const char *title, dlg_flags_t flags);
                      const char *help_ctx, const char *title, dlg_flags_t flags);
 
 
 void dlg_set_default_colors (void);
 void dlg_set_default_colors (void);

+ 1 - 2
lib/widget/input.c

@@ -1009,8 +1009,7 @@ input_new (int y, int x, const int *colors, int width, const char *def_text,
 
 
     in = g_new (WInput, 1);
     in = g_new (WInput, 1);
     w = WIDGET (in);
     w = WIDGET (in);
-    widget_init (w, y, x, 1, width, input_callback, NULL);
+    widget_init (w, y, x, 1, width, input_callback, input_mouse_callback);
-    set_easy_mouse_callback (w, input_mouse_callback);
     w->options |= W_IS_INPUT;
     w->options |= W_IS_INPUT;
     w->set_options = input_set_options_callback;
     w->set_options = input_set_options_callback;
 
 

+ 1 - 2
lib/widget/listbox.c

@@ -551,8 +551,7 @@ listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn
 
 
     l = g_new (WListbox, 1);
     l = g_new (WListbox, 1);
     w = WIDGET (l);
     w = WIDGET (l);
-    widget_init (w, y, x, height, width, listbox_callback, NULL);
+    widget_init (w, y, x, height, width, listbox_callback, listbox_mouse_callback);
-    set_easy_mouse_callback (w, listbox_mouse_callback);
 
 
     l->list = NULL;
     l->list = NULL;
     l->top = l->pos = 0;
     l->top = l->pos = 0;

+ 2 - 3
lib/widget/menu.c

@@ -743,7 +743,7 @@ menubar_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
              * touched by us. We should think of some other way of communicating
              * touched by us. We should think of some other way of communicating
              * this to the system.
              * this to the system.
              */
              */
-            w->Mouse.capture = FALSE;
+            w->mouse.capture = FALSE;
         }
         }
         break;
         break;
 
 
@@ -891,8 +891,7 @@ menubar_new (int y, int x, int cols, GList * menu, gboolean visible)
 
 
     menubar = g_new0 (WMenuBar, 1);
     menubar = g_new0 (WMenuBar, 1);
     w = WIDGET (menubar);
     w = WIDGET (menubar);
-    widget_init (w, y, x, 1, cols, menubar_callback, NULL);
+    widget_init (w, y, x, 1, cols, menubar_callback, menubar_mouse_callback);
-    set_easy_mouse_callback (w, menubar_mouse_callback);
 
 
     menubar->is_visible = visible;
     menubar->is_visible = visible;
     widget_want_cursor (w, FALSE);
     widget_want_cursor (w, FALSE);

+ 19 - 58
lib/widget/mouse.c

@@ -42,16 +42,19 @@
 
 
 /*** file scope variables ************************************************************************/
 /*** file scope variables ************************************************************************/
 
 
-static int last_buttons_down;
-static gboolean was_drag = FALSE;
-
 /* --------------------------------------------------------------------------------------------- */
 /* --------------------------------------------------------------------------------------------- */
 /*** file scope functions ************************************************************************/
 /*** file scope functions ************************************************************************/
 /* --------------------------------------------------------------------------------------------- */
 /* --------------------------------------------------------------------------------------------- */
 
 
 /**
 /**
- * Constructs a mouse event structure. The is the high-level type used
+ * Constructs a mouse event structure.
- * with "easy callbacks".
+ *
+ * It receives a Gpm_Event event and translates it into a higher level protocol.
+ *
+ * Tip: for details on the C mouse API, see MC's lib/tty/mouse.h,
+ * or GPM's excellent 'info' manual:
+ *
+ *    http://www.fifi.org/cgi-bin/info2www?(gpm)Event+Types
  */
  */
 static void
 static void
 init_mouse_event (mouse_event_t * event, mouse_msg_t msg, const Gpm_Event * global_gpm,
 init_mouse_event (mouse_event_t * event, mouse_msg_t msg, const Gpm_Event * global_gpm,
@@ -66,52 +69,10 @@ init_mouse_event (mouse_event_t * event, mouse_msg_t msg, const Gpm_Event * glob
     event->result.repeat = FALSE;
     event->result.repeat = FALSE;
 }
 }
 
 
-/* --------------------------------------------------------------------------------------------- */
-
-/**
- * This is the low-level mouse handler that's in use when you install
- * an "easy callback".
- *
- * It receives a Gpm_Event event and translates it into a higher level
- * protocol with which it feeds your "easy callback".
- *
- * Tip: for details on the C mouse API, see MC's lib/tty/mouse.h,
- * or GPM's excellent 'info' manual:
- *
- *    http://www.fifi.org/cgi-bin/info2www?(gpm)Event+Types
- */
-static int
-easy_mouse_translator (Gpm_Event * event, void *data)
-{
-    Widget *w = WIDGET (data);
-    gboolean run_click;
-    mouse_event_t me;
-
-    me = mouse_translate_event (w, event, &run_click);
-
-    return mouse_process_event (w, &me, run_click);
-}
-
 /* --------------------------------------------------------------------------------------------- */
 /* --------------------------------------------------------------------------------------------- */
 /*** public functions ****************************************************************************/
 /*** public functions ****************************************************************************/
 /* --------------------------------------------------------------------------------------------- */
 /* --------------------------------------------------------------------------------------------- */
 
 
-/**
- * Use this to install an "easy mouse callback".
- *
- * (The mouse callback widget_init() accepts is a low-level one; you can
- * pass NULL to it. In the future we'll probably do the opposite: have
- * widget_init() accept the "easy" callback.)
- */
-void
-set_easy_mouse_callback (Widget * w, easy_mouse_callback cb)
-{
-    w->mouse = easy_mouse_translator;
-    w->Mouse.callback = cb;
-}
-
-/* --------------------------------------------------------------------------------------------- */
-
 /**
 /**
  * Translate GPM event to high-level event,
  * Translate GPM event to high-level event,
  *
  *
@@ -134,7 +95,7 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
      * You'll also need, in your mouse handler, to inform the system of
      * You'll also need, in your mouse handler, to inform the system of
      * events you want to pass on by setting 'event->result.abort' to TRUE.
      * events you want to pass on by setting 'event->result.abort' to TRUE.
      */
      */
-    in_widget = w->Mouse.forced_capture || mouse_global_in_widget (event, w);
+    in_widget = w->mouse.forced_capture || mouse_global_in_widget (event, w);
 
 
     *click = FALSE;
     *click = FALSE;
 
 
@@ -154,10 +115,10 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
                  * buttons doesn't make sense as they don't generate a
                  * buttons doesn't make sense as they don't generate a
                  * mouse_up event, which means we'd never get uncaptured.)
                  * mouse_up event, which means we'd never get uncaptured.)
                  */
                  */
-                w->Mouse.capture = TRUE;
+                w->mouse.capture = TRUE;
                 msg = MSG_MOUSE_DOWN;
                 msg = MSG_MOUSE_DOWN;
 
 
-                last_buttons_down = event->buttons;
+                w->mouse.last_buttons_down = event->buttons;
             }
             }
         }
         }
     }
     }
@@ -166,13 +127,13 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
         /* We trigger the mouse_up event even when !in_widget. That's
         /* We trigger the mouse_up event even when !in_widget. That's
          * because, for example, a paint application should stop drawing
          * because, for example, a paint application should stop drawing
          * lines when the button is released even outside the canvas. */
          * lines when the button is released even outside the canvas. */
-        if (w->Mouse.capture)
+        if (w->mouse.capture)
         {
         {
-            w->Mouse.capture = FALSE;
+            w->mouse.capture = FALSE;
             msg = MSG_MOUSE_UP;
             msg = MSG_MOUSE_UP;
 
 
             if (in_widget)
             if (in_widget)
-                *click = !was_drag;
+                *click = !w->mouse.was_drag;
 
 
             /*
             /*
              * When using xterm, event->buttons reports the buttons' state
              * When using xterm, event->buttons reports the buttons' state
@@ -183,12 +144,12 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
              * The following makes xterm behave effectively like GPM:
              * The following makes xterm behave effectively like GPM:
              */
              */
             if (event->buttons == 0)
             if (event->buttons == 0)
-                event->buttons = last_buttons_down;
+                event->buttons = w->mouse.last_buttons_down;
         }
         }
     }
     }
     else if ((event->type & GPM_DRAG) != 0)
     else if ((event->type & GPM_DRAG) != 0)
     {
     {
-        if (w->Mouse.capture)
+        if (w->mouse.capture)
             msg = MSG_MOUSE_DRAG;
             msg = MSG_MOUSE_DRAG;
     }
     }
     else if ((event->type & GPM_MOVE) != 0)
     else if ((event->type & GPM_MOVE) != 0)
@@ -199,7 +160,7 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
 
 
     if (msg != MSG_MOUSE_NONE)
     if (msg != MSG_MOUSE_NONE)
         /* Remember the current state for next event. */
         /* Remember the current state for next event. */
-        was_drag = ((event->type & GPM_DRAG) != 0);
+        w->mouse.was_drag = ((event->type & GPM_DRAG) != 0);
 
 
     init_mouse_event (&local, msg, event, w);
     init_mouse_event (&local, msg, event, w);
 
 
@@ -224,9 +185,9 @@ mouse_process_event (Widget * w, mouse_event_t * event, gboolean click)
 
 
     if (event->msg != MSG_MOUSE_NONE)
     if (event->msg != MSG_MOUSE_NONE)
     {
     {
-        w->Mouse.callback (w, event->msg, event);
+        w->mouse_callback (w, event->msg, event);
         if (click)
         if (click)
-            w->Mouse.callback (w, MSG_MOUSE_CLICK, event);
+            w->mouse_callback (w, MSG_MOUSE_CLICK, event);
 
 
         if (!event->result.abort)
         if (!event->result.abort)
             ret = event->result.repeat ? MOU_REPEAT : MOU_NORMAL;
             ret = event->result.repeat ? MOU_REPEAT : MOU_NORMAL;

Некоторые файлы не были показаны из-за большого количества измененных файлов