Browse Source

Widget: implement destroy callback.

(dlg_destroy): remove. Use widget_destroy() to destroy any dialog.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 4 years ago
parent
commit
231c84caeb

+ 2 - 2
lib/widget/dialog-switch.c

@@ -268,7 +268,7 @@ dialog_switch_process_pending (void)
         ret = dlg_run (h);
         if (widget_get_state (wh, WST_CLOSED))
         {
-            dlg_destroy (h);
+            widget_destroy (wh);
 
             /* return to panels */
             if (mc_global.mc_run_mode == MC_RUN_FULL)
@@ -306,7 +306,7 @@ dialog_switch_shutdown (void)
         WDialog *dlg = DIALOG (mc_dialogs->data);
 
         dlg_run (dlg);
-        dlg_destroy (dlg);
+        widget_destroy (WIDGET (dlg));
     }
 }
 

+ 18 - 16
lib/widget/dialog.c

@@ -324,6 +324,23 @@ frontend_dlg_run (WDialog * h)
     }
 }
 
+/* --------------------------------------------------------------------------------------------- */
+
+static void
+dlg_default_destroy (Widget * w)
+{
+    WDialog *h = DIALOG (w);
+
+    /* if some widgets have history, save all histories at one moment here */
+    dlg_save_history (h);
+    group_default_callback (w, NULL, MSG_DESTROY, 0, NULL);
+    mc_event_group_del (h->event_group);
+    g_free (h->event_group);
+    g_free (h);
+
+    do_refresh ();
+}
+
 /* --------------------------------------------------------------------------------------------- */
 /*** public functions ****************************************************************************/
 /* --------------------------------------------------------------------------------------------- */
@@ -403,6 +420,7 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flag
     w->mouse_handler = dlg_handle_mouse_event;
     w->mouse.forced_capture = mouse_close_dialog && (w->pos_flags & WPOS_FULLSCREEN) == 0;
 
+    w->destroy = dlg_default_destroy;
     w->get_colors = dlg_default_get_colors;
 
     new_d->colors = colors;
@@ -586,22 +604,6 @@ dlg_run (WDialog * h)
 
 /* --------------------------------------------------------------------------------------------- */
 
-void
-dlg_destroy (WDialog * h)
-{
-    /* if some widgets have history, save all history at one moment here */
-    dlg_save_history (h);
-    group_default_callback (WIDGET (h), NULL, MSG_DESTROY, 0, NULL);
-    send_message (WIDGET (h), NULL, MSG_DESTROY, 0, NULL);
-    mc_event_group_del (h->event_group);
-    g_free (h->event_group);
-    g_free (h);
-
-    do_refresh ();
-}
-
-/* --------------------------------------------------------------------------------------------- */
-
 /**
   * Write history to the ${XDG_CACHE_HOME}/mc/history file
   */

+ 0 - 1
lib/widget/dialog.h

@@ -106,7 +106,6 @@ void dlg_set_default_colors (void);
 
 void dlg_init (WDialog * h);
 int dlg_run (WDialog * d);
-void dlg_destroy (WDialog * h);
 
 void dlg_run_done (WDialog * h);
 void dlg_save_history (WDialog * h);

+ 1 - 1
lib/widget/history.c

@@ -288,7 +288,7 @@ history_show (history_descriptor_t * hd)
     if (WIDGET (query_dlg)->y < hd->y)
         z = g_list_reverse (z);
 
-    dlg_destroy (query_dlg);
+    widget_destroy (WIDGET (query_dlg));
 
     hd->list = g_list_first (hd->list);
     g_list_free_full (hd->list, hd->free);

+ 1 - 1
lib/widget/input_complete.c

@@ -1282,7 +1282,7 @@ complete_engine (WInput * in, int what_to_do)
             }
             if (q != NULL || end != min_end)
                 input_complete_free (in);
-            dlg_destroy (complete_dlg);
+            widget_destroy (WIDGET (complete_dlg));
 
             /* B_USER if user wants to start over again */
             return (i == B_USER);

+ 2 - 2
lib/widget/listbox-window.c

@@ -132,7 +132,7 @@ run_listbox (Listbox * l)
 
     if (dlg_run (l->dlg) != B_CANCEL)
         val = l->list->pos;
-    dlg_destroy (l->dlg);
+    widget_destroy (WIDGET (l->dlg));
     g_free (l);
     return val;
 }
@@ -167,7 +167,7 @@ run_listbox_with_data (Listbox * l, const void *select)
         }
     }
 
-    dlg_destroy (l->dlg);
+    widget_destroy (WIDGET (l->dlg));
     g_free (l);
     return val;
 }

+ 1 - 1
lib/widget/quick.c

@@ -611,7 +611,7 @@ quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip)
             }
         }
 
-    dlg_destroy (dd);
+    widget_destroy (WIDGET (dd));
 
     g_list_free_full (input_labels, g_free);    /* destroy input labels created before */
     g_array_free (widgets, TRUE);

+ 15 - 9
lib/widget/widget-common.c

@@ -345,20 +345,12 @@ widget_init (Widget * w, int y, int x, int lines, int cols,
     w->find_by_id = widget_default_find_by_id;
 
     w->set_state = widget_default_set_state;
+    w->destroy = widget_default_destroy;
     w->get_colors = widget_default_get_colors;
 }
 
 /* --------------------------------------------------------------------------------------------- */
 
-void
-widget_destroy (Widget * w)
-{
-    send_message (w, NULL, MSG_DESTROY, 0, NULL);
-    g_free (w);
-}
-
-/* --------------------------------------------------------------------------------------------- */
-
 /* Default callback for widgets */
 cb_ret_t
 widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
@@ -879,6 +871,20 @@ widget_default_set_state (Widget * w, widget_state_t state, gboolean enable)
     return ret;
 }
 
+/* --------------------------------------------------------------------------------------------- */
+/**
+ * Default callback function to destroy widget.
+ *
+ * @param w widget
+ */
+
+void
+widget_default_destroy (Widget * w)
+{
+    send_message (w, NULL, MSG_DESTROY, 0, NULL);
+    g_free (w);
+}
+
 /* --------------------------------------------------------------------------------------------- */
 /* get mouse pointer location within widget */
 

+ 16 - 1
lib/widget/widget-common.h

@@ -168,6 +168,7 @@ struct Widget
     /* *INDENT-OFF* */
     cb_ret_t (*set_state) (Widget * w, widget_state_t state, gboolean enable);
     /* *INDENT-ON* */
+    void (*destroy) (Widget * w);
 
     const int *(*get_colors) (const Widget * w);
 };
@@ -203,7 +204,6 @@ char *hotkey_get_text (const hotkey_t hotkey);
 /* widget initialization */
 void widget_init (Widget * w, int y, int x, int lines, int cols,
                   widget_cb_fn callback, widget_mouse_cb_fn mouse_callback);
-void widget_destroy (Widget * w);
 /* Default callback for widgets */
 cb_ret_t widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
                                   void *data);
@@ -233,6 +233,8 @@ Widget *widget_default_find_by_id (const Widget * w, unsigned long id);
 
 cb_ret_t widget_default_set_state (Widget * w, widget_state_t state, gboolean enable);
 
+void widget_default_destroy (Widget * w);
+
 /* get mouse pointer location within widget */
 Gpm_Event mouse_get_local (const Gpm_Event * global, const Widget * w);
 gboolean mouse_global_in_widget (const Gpm_Event * event, const Widget * w);
@@ -380,6 +382,19 @@ widget_set_state (Widget * w, widget_state_t state, gboolean enable)
     return w->set_state (w, state, enable);
 }
 
+/* --------------------------------------------------------------------------------------------- */
+/**
+ * Destroy widget.
+ *
+ * @param w widget
+ */
+
+static inline void
+widget_destroy (Widget * w)
+{
+    w->destroy (w);
+}
+
 /* --------------------------------------------------------------------------------------------- */
 
 /**

+ 4 - 5
lib/widget/wtools.c

@@ -150,10 +150,9 @@ fg_message (int flags, const char *title, const char *text)
     d = do_create_message (flags, title, text);
     tty_getch ();
     dlg_run_done (d);
-    dlg_destroy (d);
+    widget_destroy (WIDGET (d));
 }
 
-
 /* --------------------------------------------------------------------------------------------- */
 /** Show message box from background */
 
@@ -356,7 +355,7 @@ query_dialog (const char *header, const char *text, int flags, int count, ...)
         }
 
         /* free used memory */
-        dlg_destroy (query_dlg);
+        widget_destroy (WIDGET (query_dlg));
     }
     else
     {
@@ -380,7 +379,7 @@ query_set_sel (int new_sel)
 /* --------------------------------------------------------------------------------------------- */
 /**
  * Create message dialog.  The caller must call dlg_run_done() and
- * dlg_destroy() to dismiss it.  Not safe to call from background.
+ * widget_destroy() to dismiss it.  Not safe to call from background.
  */
 
 WDialog *
@@ -628,7 +627,7 @@ status_msg_deinit (status_msg_t * sm)
 
     /* close and destroy dialog */
     dlg_run_done (sm->dlg);
-    dlg_destroy (sm->dlg);
+    widget_destroy (WIDGET (sm->dlg));
 }
 
 /* --------------------------------------------------------------------------------------------- */

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