"Fossies" - the Fresh Open Source Software Archive

Member "xzgv-0.9.2/src/confirm.c" (3 Sep 2017, 3184 Bytes) of package /linux/misc/old/xzgv-0.9.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "confirm.c" see the Fossies "Dox" file reference documentation.

    1 /* xzgv v0.2 - picture viewer for X, with file selector.
    2  * Copyright (C) 1999 Russell Marks. See main.c for license details.
    3  *
    4  * confirm.c - a generic yes/no confirmation dialog.
    5  */
    6 
    7 #include <stdio.h>
    8 #include <sys/types.h>
    9 #include <gtk/gtk.h>
   10 #include <gdk/gdkkeysyms.h>
   11 #include "backend.h"
   12 #include "main.h"
   13 
   14 #include "confirm.h"
   15 
   16 
   17 static GtkWidget *yesno_win;
   18 
   19 
   20 
   21 static void cb_yes_button(GtkWidget *button,void (*callback)(void))
   22 {
   23 gtk_widget_destroy(yesno_win);
   24 (*callback)();
   25 }
   26 
   27 
   28 /* a yes/no confirmation dialog. You specify the title, message text,
   29  * and the main callback for the `yes' button (the `no' does nothing
   30  * other than removing the yes/no dialog).
   31  *
   32  * Note that this returns `immediately'; the callback should do
   33  * any work required.
   34  */
   35 void confirmation_dialog(char *title,char *msg,void (*main_callback)(void))
   36 {
   37 GtkWidget *vbox;
   38 GtkWidget *action_tbl,*yes_button,*no_button;
   39 GtkWidget *label;
   40 
   41 yesno_win=gtk_dialog_new();
   42 
   43 gtk_window_set_title(GTK_WINDOW(yesno_win),title);
   44 gtk_window_set_policy(GTK_WINDOW(yesno_win),FALSE,TRUE,FALSE);
   45 gtk_window_set_position(GTK_WINDOW(yesno_win),GTK_WIN_POS_CENTER);
   46 /* seems reasonable to have this as modal */
   47 gtk_window_set_modal(GTK_WINDOW(yesno_win),TRUE);
   48 
   49 /* make a new vbox for the top part so we can get spacing more sane */
   50 vbox=gtk_vbox_new(FALSE,10);
   51 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(yesno_win)->vbox),
   52                    vbox,TRUE,TRUE,0);
   53 gtk_widget_show(vbox);
   54 
   55 gtk_container_set_border_width(GTK_CONTAINER(vbox),5);
   56 gtk_container_set_border_width(
   57   GTK_CONTAINER(GTK_DIALOG(yesno_win)->action_area),5);
   58 
   59 /* add yes/no buttons */
   60 action_tbl=gtk_table_new(1,5,TRUE);
   61 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(yesno_win)->action_area),
   62                    action_tbl,TRUE,TRUE,0);
   63 gtk_widget_show(action_tbl);
   64 
   65 yes_button=gtk_button_new_with_label("Yes");
   66 gtk_table_attach_defaults(GTK_TABLE(action_tbl),yes_button, 1,2, 0,1);
   67 gtk_signal_connect(GTK_OBJECT(yes_button),"clicked",
   68                    GTK_SIGNAL_FUNC(cb_yes_button),main_callback);
   69 gtk_widget_show(yes_button);
   70 
   71 no_button=gtk_button_new_with_label("No");
   72 gtk_table_attach_defaults(GTK_TABLE(action_tbl),no_button, 3,4, 0,1);
   73 gtk_signal_connect_object(GTK_OBJECT(no_button),"clicked",
   74                           GTK_SIGNAL_FUNC(gtk_widget_destroy),
   75                           GTK_OBJECT(yesno_win));
   76 gtk_widget_show(no_button);
   77 
   78 
   79 label=gtk_label_new(msg);
   80 gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,2);
   81 gtk_widget_show(label);
   82 
   83 
   84 /* esc/n = no */
   85 gtk_widget_add_accelerator(no_button,"clicked",
   86                            mainwin_accel_group,
   87                            GDK_Escape,0,0);
   88 gtk_widget_add_accelerator(no_button,"clicked",
   89                            mainwin_accel_group,
   90                            GDK_n,0,0);
   91 
   92 /* enter/y = yes */
   93 gtk_widget_add_accelerator(yes_button,"clicked",
   94                            mainwin_accel_group,
   95                            GDK_Return,0,0);
   96 gtk_widget_add_accelerator(yes_button,"clicked",
   97                            mainwin_accel_group,
   98                            GDK_y,0,0);
   99 
  100 
  101 gtk_widget_show(yesno_win);
  102 
  103 /* that's it then; it's modal so we can just leave GTK+ to deal with things. */
  104 }