Browse Source

Modified dialog callback function.

Added two parameters:
  * Widget *sender -- to recognize the wiget that have sent message;
  * void *data -- to pass any user-defined data to the dialog.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 15 years ago
parent
commit
11d21f1437
10 changed files with 101 additions and 86 deletions
  1. 7 7
      edit/editcmd_dialogs.c
  2. 5 4
      edit/editwidget.c
  3. 13 12
      src/achown.c
  4. 6 4
      src/boxes.c
  5. 3 2
      src/chmod.c
  6. 3 2
      src/chown.c
  7. 4 3
      src/complete.c
  8. 37 33
      src/dialog.c
  9. 17 15
      src/dialog.h
  10. 6 4
      src/find.c

+ 7 - 7
edit/editcmd_dialogs.c

@@ -34,10 +34,10 @@
 
 #include "../src/search/search.h"
 
-#include "../src/strutil.h"
+#include "../src/dialog.h"
 #include "../src/widget.h"
 #include "../src/wtools.h"
-#include "../src/dialog.h"      /* do_refresh() */
+#include "../src/strutil.h"
 #include "../src/main.h"
 #include "../src/history.h"
 #include "../src/charsets.h"
@@ -67,15 +67,16 @@
 /*** file scope functions **********************************************/
 
 static cb_ret_t
-editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, dlg_msg_t msg, int parm)
+editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget *sender,
+				    dlg_msg_t msg, int parm, void *data)
 {
     switch (msg) {
     case DLG_KEY:
-        dlg_stop (h);
         h->ret_value = parm;
+        dlg_stop (h);
         return MSG_HANDLED;
     default:
-        return default_dlg_callback (h, msg, parm);
+        return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 
@@ -283,8 +284,7 @@ editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel
     int w = str_term_width1 (query) + 7;
     struct Dlg_head *raw_dlg =
         create_dlg (0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb,
-                    NULL, heading,
-                    DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
+                    NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
     add_widget (raw_dlg,
                 input_new (3 - cancel, w - 5, INPUT_COLOR, 2, "", 0, INPUT_COMPLETE_DEFAULT));
     add_widget (raw_dlg, label_new (3 - cancel, 2, query));

+ 5 - 4
edit/editwidget.c

@@ -47,6 +47,7 @@
 #include "edit-impl.h"
 #include "edit-widget.h"
 
+#include "../src/dialog.h"
 #include "../src/widget.h"		/* ButtonBar */
 #include "../src/menu.h"		/* menubar_new() */
 #include "../src/cmddef.h"
@@ -177,7 +178,8 @@ edit_adjust_size (Dlg_head *h)
 
 /* Callback for the edit dialog */
 static cb_ret_t
-edit_dialog_callback (Dlg_head *h, dlg_msg_t msg, int parm)
+edit_dialog_callback (Dlg_head *h, Widget *sender,
+			dlg_msg_t msg, int parm, void *data)
 {
     WEdit *edit;
 
@@ -188,13 +190,12 @@ edit_dialog_callback (Dlg_head *h, dlg_msg_t msg, int parm)
 
     case DLG_VALIDATE:
 	edit = (WEdit *) find_widget_type (h, edit_callback);
-	if (!edit_ok_to_exit (edit)) {
+	if (!edit_ok_to_exit (edit))
 	    h->running = 1;
-	}
 	return MSG_HANDLED;
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 

+ 13 - 12
src/achown.c

@@ -225,7 +225,8 @@ static void update_mode (Dlg_head * h)
 }
 
 static cb_ret_t
-chl_callback (Dlg_head *h, dlg_msg_t msg, int parm)
+chl_callback (Dlg_head *h, Widget *sender,
+		dlg_msg_t msg, int parm, void *data)
 {
     switch (msg) {
     case DLG_KEY:
@@ -237,7 +238,7 @@ chl_callback (Dlg_head *h, dlg_msg_t msg, int parm)
 	}
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 
@@ -398,7 +399,8 @@ static void b_setpos (int f_pos) {
 }
 
 static cb_ret_t
-advanced_chown_callback (Dlg_head *h, dlg_msg_t msg, int parm)
+advanced_chown_callback (Dlg_head *h, Widget *sender,
+			    dlg_msg_t msg, int parm, void *data)
 {
     int i = 0, f_pos = BUTTONS - h->current->dlg_id - single_set - 1;
 
@@ -525,20 +527,19 @@ advanced_chown_callback (Dlg_head *h, dlg_msg_t msg, int parm)
 
 	case '=':
 	case '+':
-	    if (f_pos > 4)
-		break;
-	    ch_flags[flag_pos] = parm;
-	    update_mode (h);
-	    advanced_chown_callback (h, DLG_KEY, KEY_RIGHT);
-	    if (flag_pos > 8 || !(flag_pos % 3))
-		dlg_one_down (h);
-
+	    if (f_pos <= 4) {
+		ch_flags[flag_pos] = parm;
+		update_mode (h);
+		advanced_chown_callback (h, sender, DLG_KEY, KEY_RIGHT, NULL);
+		if (flag_pos > 8 || !(flag_pos % 3))
+		    dlg_one_down (h);
+	    }
 	    break;
 	}
 	return MSG_NOT_HANDLED;
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 

+ 6 - 4
src/boxes.c

@@ -78,7 +78,8 @@ static char **displays_status;
 static int display_user_hotkey = 'u';
 
 static cb_ret_t
-display_callback (Dlg_head *h, dlg_msg_t msg, int parm)
+display_callback (Dlg_head *h, Widget *sender,
+		    dlg_msg_t msg, int parm, void *data)
 {
     switch (msg) {
     case DLG_UNFOCUS:
@@ -119,7 +120,7 @@ display_callback (Dlg_head *h, dlg_msg_t msg, int parm)
 	return MSG_NOT_HANDLED;
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 
@@ -636,7 +637,8 @@ display_bits_box (void)
 #endif /* HAVE_CHARSET */
 
 static cb_ret_t
-tree_callback (Dlg_head *h, dlg_msg_t msg, int parm)
+tree_callback (Dlg_head *h, Widget *sender,
+		dlg_msg_t msg, int parm, void *data)
 {
     switch (msg) {
     case DLG_POST_KEY:
@@ -648,7 +650,7 @@ tree_callback (Dlg_head *h, dlg_msg_t msg, int parm)
 	return MSG_HANDLED;
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 

+ 3 - 2
src/chmod.c

@@ -160,7 +160,8 @@ static void chmod_refresh (Dlg_head *h)
 }
 
 static cb_ret_t
-chmod_callback (Dlg_head *h, dlg_msg_t msg, int parm)
+chmod_callback (Dlg_head *h, Widget *sender,
+		dlg_msg_t msg, int parm, void *data)
 {
     char buffer[BUF_TINY];
     int id = h->current->dlg_id - BUTTONS + single_set * 2;
@@ -190,7 +191,7 @@ chmod_callback (Dlg_head *h, dlg_msg_t msg, int parm)
 	return MSG_HANDLED;
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 

+ 3 - 2
src/chown.c

@@ -137,7 +137,8 @@ next_file (void)
 }
 
 static cb_ret_t
-chown_callback (Dlg_head *h, dlg_msg_t msg, int parm)
+chown_callback (Dlg_head *h, Widget *sender,
+		dlg_msg_t msg, int parm, void *data)
 {
     switch (msg) {
     case DLG_DRAW:
@@ -145,7 +146,7 @@ chown_callback (Dlg_head *h, dlg_msg_t msg, int parm)
 	return MSG_HANDLED;
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 

+ 4 - 3
src/complete.c

@@ -900,11 +900,12 @@ static int insert_text (WInput *in, char *text, ssize_t size)
 }
 
 static cb_ret_t
-query_callback (Dlg_head *h, dlg_msg_t msg, int parm)
+query_callback (Dlg_head *h, Widget *sender,
+		dlg_msg_t msg, int parm, void *data)
 {
     static char buff[MB_LEN_MAX] = "";
     static int bl = 0;
-    
+
     switch (msg) {
     case DLG_KEY:
 	switch (parm) {
@@ -1023,7 +1024,7 @@ query_callback (Dlg_head *h, dlg_msg_t msg, int parm)
 	break;
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 

+ 37 - 33
src/dialog.c

@@ -204,9 +204,13 @@ dlg_set_size (Dlg_head *h, int lines, int cols)
 }
 
 /* Default dialog callback */
-cb_ret_t default_dlg_callback (Dlg_head *h, dlg_msg_t msg, int parm)
+cb_ret_t
+default_dlg_callback (Dlg_head *h, Widget *sender,
+			dlg_msg_t msg, int parm, void *data)
 {
+    (void) sender;
     (void) parm;
+    (void) data;
 
     switch (msg) {
     case DLG_DRAW:
@@ -393,28 +397,25 @@ dlg_broadcast_msg (Dlg_head *h, widget_msg_t message, int reverse)
     dlg_broadcast_msg_to (h, message, reverse, 0);
 }
 
-int dlg_focus (Dlg_head *h)
+int
+dlg_focus (Dlg_head *h)
 {
-    if (!h->current)
-        return 0;
-
-    if (send_message (h->current, WIDGET_FOCUS, 0)){
-	(*h->callback) (h, DLG_FOCUS, 0);
-	return 1;
-    }
+    if ((h->current != NULL)
+	&& (send_message (h->current, WIDGET_FOCUS, 0) == MSG_HANDLED)) {
+	    h->callback (h, h->current, DLG_FOCUS, 0, NULL);
+	    return 1;
+	}
     return 0;
 }
 
 static int
 dlg_unfocus (Dlg_head *h)
 {
-    if (!h->current)
-        return 0;
-
-    if (send_message (h->current, WIDGET_UNFOCUS, 0)){
-	(*h->callback) (h, DLG_UNFOCUS, 0);
-	return 1;
-    }
+    if ((h->current != NULL)
+	&& (send_message (h->current, WIDGET_UNFOCUS, 0) == MSG_HANDLED)) {
+	    h->callback (h, h->current, DLG_UNFOCUS, 0, NULL);
+	    return 1;
+	}
     return 0;
 }
 
@@ -568,16 +569,16 @@ void update_cursor (Dlg_head *h)
 /* Redraw the widgets in reverse order, leaving the current widget
  * as the last one
  */
-void dlg_redraw (Dlg_head *h)
+void
+dlg_redraw (Dlg_head *h)
 {
-    (h->callback)(h, DLG_DRAW, 0);
-
+    h->callback (h, NULL, DLG_DRAW, 0, NULL);
     dlg_broadcast_msg (h, WIDGET_DRAW, 1);
-
     update_cursor (h);
 }
 
-void dlg_stop (Dlg_head *h)
+void
+dlg_stop (Dlg_head *h)
 {
     h->running = 0;
 }
@@ -705,26 +706,26 @@ dlg_key_event (Dlg_head *h, int d_key)
     }
 
     /* first can dlg_callback handle the key */
-    handled = (*h->callback) (h, DLG_KEY, d_key);
+    handled = h->callback (h, NULL, DLG_KEY, d_key, NULL);
 
     /* next try the hotkey */
     if (handled == MSG_NOT_HANDLED)
 	handled = dlg_try_hotkey (h, d_key);
 
     if (handled == MSG_HANDLED)
-	(*h->callback) (h, DLG_HOTKEY_HANDLED, 0);
+	h->callback (h, NULL, DLG_HOTKEY_HANDLED, 0, NULL);
     else
 	/* not used - then try widget_callback */
 	handled = send_message (h->current, WIDGET_KEY, d_key);
 
     /* not used- try to use the unhandled case */
     if (handled == MSG_NOT_HANDLED)
-	handled = (*h->callback) (h, DLG_UNHANDLED_KEY, d_key);
+	handled = h->callback (h, NULL, DLG_UNHANDLED_KEY, d_key, NULL);
 
     if (handled == MSG_NOT_HANDLED)
 	dialog_handle_key (h, d_key);
 
-    (*h->callback) (h, DLG_POST_KEY, d_key);
+    h->callback (h, NULL, DLG_POST_KEY, d_key, NULL);
 }
 
 static int
@@ -769,10 +770,11 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
 /* Run dialog routines */
 
 /* Init the process */
-void init_dlg (Dlg_head *h)
+void
+init_dlg (Dlg_head *h)
 {
     /* Initialize dialog manager and widgets */
-    (*h->callback) (h, DLG_INIT, 0);
+    h->callback (h, NULL, DLG_INIT, 0, NULL);
     dlg_broadcast_msg (h, WIDGET_INIT, 0);
 
     if (h->x == 0 && h->y == 0 && h->cols == COLS && h->lines == LINES)
@@ -796,15 +798,17 @@ void init_dlg (Dlg_head *h)
 }
 
 /* Shutdown the run_dlg */
-void dlg_run_done (Dlg_head *h)
+void
+dlg_run_done (Dlg_head *h)
 {
-    if (h->current)
-	(*h->callback) (h, DLG_END, 0);
+    if (h->current != NULL)
+	h->callback (h, h->current, DLG_END, 0, NULL);
 
     current_dlg = h->parent;
 }
 
-void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event)
+void
+dlg_process_event (Dlg_head *h, int key, Gpm_Event *event)
 {
     if (key == EV_NONE){
 	if (tty_got_interrupt ())
@@ -835,7 +839,7 @@ frontend_run_dlg (Dlg_head *h)
 		execute_hooks (idle_hook);
 
 	    while ((h->flags & DLG_WANT_IDLE) && is_idle ())
-		(*h->callback) (h, DLG_IDLE, 0);
+		h->callback (h, NULL, DLG_IDLE, 0, NULL);
 
 	    /* Allow terminating the dialog from the idle handler */
 	    if (!h->running)
@@ -851,7 +855,7 @@ frontend_run_dlg (Dlg_head *h)
 	dlg_process_event (h, d_key, &event);
 
 	if (!h->running)
-	    (*h->callback) (h, DLG_VALIDATE, 0);
+	    h->callback (h, NULL, DLG_VALIDATE, 0, NULL);
     }
 }
 

+ 17 - 15
src/dialog.h

@@ -65,26 +65,27 @@ typedef enum {
 
 /* Dialog messages */
 typedef enum {
-    DLG_KEY,			/* Key before sending to widget */
-    DLG_INIT,			/* Initialize dialog */
-    DLG_END,			/* Shut down dialog */
-    DLG_ACTION,			/* State of check- and radioboxes has changed
+    DLG_INIT		= 0,	/* Initialize dialog */
+    DLG_IDLE		= 1,	/* The idle state is active */
+    DLG_DRAW		= 2,	/* Draw dialog on screen */
+    DLG_FOCUS		= 3,	/* A widget has got focus */
+    DLG_UNFOCUS		= 4,	/* A widget has been unfocused */
+    DLG_RESIZE		= 5,	/* Window size has changed */
+    DLG_KEY		= 6,	/* Key before sending to widget */
+    DLG_HOTKEY_HANDLED	= 7,	/* A widget has got the hotkey */
+    DLG_POST_KEY	= 8,	/* The key has been handled */
+    DLG_UNHANDLED_KEY	= 9,	/* Key that no widget handled */
+    DLG_ACTION		= 10,	/* State of check- and radioboxes has changed
 				 * and listbox current entry has changed */
-    DLG_DRAW,			/* Draw dialog on screen */
-    DLG_FOCUS,			/* A widget has got focus */
-    DLG_UNFOCUS,		/* A widget has been unfocused */
-    DLG_RESIZE,			/* Window size has changed */
-    DLG_POST_KEY,		/* The key has been handled */
-    DLG_IDLE,			/* The idle state is active */
-    DLG_UNHANDLED_KEY,		/* Key that no widget handled */
-    DLG_HOTKEY_HANDLED,		/* A widget has got the hotkey */
-    DLG_VALIDATE		/* Dialog is to be closed */
+    DLG_VALIDATE	= 11,	/* Dialog is to be closed */
+    DLG_END		= 12	/* Shut down dialog */
 } dlg_msg_t;
 
 
 /* Dialog callback */
 typedef struct Dlg_head Dlg_head;
-typedef cb_ret_t (*dlg_cb_fn)(struct Dlg_head *h, dlg_msg_t msg, int parm);
+typedef cb_ret_t (*dlg_cb_fn)(struct Dlg_head *h, Widget *sender,
+				dlg_msg_t msg, int parm, void *data);
 
 /* keybinding commands execution
    sender: the widget that sent the command with data
@@ -227,7 +228,8 @@ void init_widget (Widget *w, int y, int x, int lines, int cols,
 		  callback_fn callback, mouse_h mouse_handler);
 
 /* Default callback for dialogs */
-cb_ret_t default_dlg_callback (Dlg_head *h, dlg_msg_t msg, int parm);
+cb_ret_t default_dlg_callback (Dlg_head *h, Widget *sender,
+				dlg_msg_t msg, int parm, void *data);
 
 /* Default paint routine for dialogs */
 void common_dialog_repaint (struct Dlg_head *h);

+ 6 - 4
src/find.c

@@ -222,7 +222,8 @@ find_check_regexp (const char *r)
  * Validate regex, prevent closing the dialog if it's invalid.
  */
 static cb_ret_t
-find_parm_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
+find_parm_callback (Dlg_head *h, Widget *sender,
+		    dlg_msg_t msg, int parm, void *data)
 {
     switch (msg) {
     case DLG_VALIDATE:
@@ -252,7 +253,7 @@ find_parm_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
 	return MSG_HANDLED;
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 
@@ -982,7 +983,8 @@ view_edit_currently_selected_file (int unparsed_view, int edit)
 }
 
 static cb_ret_t
-find_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
+find_callback (struct Dlg_head *h, Widget *sender,
+		dlg_msg_t msg, int parm, void *data)
 {
     switch (msg) {
     case DLG_KEY:
@@ -1000,7 +1002,7 @@ find_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
 	return MSG_HANDLED;
 
     default:
-	return default_dlg_callback (h, msg, parm);
+	return default_dlg_callback (h, sender, msg, parm, data);
     }
 }
 

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