Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

dialog.c

Go to the documentation of this file.
00001 /*
00002  * Yattm 
00003  *
00004  * Copyright (C) 1999, Torrey Searle <tsearle@uci.edu>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #  include <config.h>
00024 #endif
00025 
00026 #include "intl.h"
00027 #include <string.h>
00028 #include <gtk/gtk.h>
00029 #include <gdk/gdkprivate.h>
00030 #include <stdlib.h>
00031 #include "dialog.h"
00032 #include "util.h"
00033 #include "status.h"
00034 #include "pixmaps/yattm.xpm"
00035 #include "pixmaps/tb_yes.xpm"
00036 #include "pixmaps/tb_no.xpm"
00037 #include "pixmaps/ok.xpm"
00038 
00039 #include "libproxy/libproxy.h"
00040 #include "gtk_globals.h"
00041 
00042 static GdkPixmap *icon_pm = NULL;
00043 static GdkBitmap *icon_bm = NULL;
00044 
00045 /*------------------------------------------------------------------------*/
00046 /* Function for making buttons                                            */
00047 /*------------------------------------------------------------------------*/
00048 
00049 static void set_option(GtkWidget * w, int * data )
00050 {
00051     *data = !(*data);   
00052 }
00053 
00054 GtkWidget *eb_button(const char *text, int *value, GtkWidget *page)
00055 {
00056     GtkWidget *button;
00057     button = gtk_check_button_new_with_label(text);
00058     gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), *value);
00059     gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0);
00060     gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_option), value);
00061     gtk_widget_show(button);
00062     return button;
00063 }
00064 
00065 GtkWidget *eb_push_button(const char *text, GtkWidget *page)
00066 {
00067     GtkWidget *button;
00068     button = gtk_button_new_with_label(text);
00069     gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0);
00070     gtk_widget_show(button);
00071     return button;
00072 }
00073 
00074 /*
00075   eb_radio function
00076 */
00077 
00078 GSList * eb_radio (GSList * group, const char * text, int curr_val,
00079            int set_val, GtkWidget *page, void * set_element)
00080 {
00081   GtkWidget * radio;
00082 
00083   /* Create Button w/ or w/out text, as requested */
00084   if (text == NULL)
00085     {
00086       radio = gtk_radio_button_new (group);
00087     }
00088   else
00089     {
00090       radio = gtk_radio_button_new_with_label (group, text);
00091     }
00092 
00093   /* select this button if it should be */
00094   gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(radio),
00095                    (curr_val == set_val));
00096 
00097   /* add this button to whatever box given */
00098   gtk_box_pack_start (GTK_BOX(page), radio, FALSE, FALSE, 0);
00099 
00100   /* Set the callback that we're told to set and the argument */
00101   gtk_signal_connect(GTK_OBJECT(radio), "clicked",
00102              GTK_SIGNAL_FUNC(set_element), (void *) set_val);
00103 
00104   /* Make this visible */
00105   gtk_widget_show (radio);
00106 
00107   /* Return the group */
00108   return (gtk_radio_button_group (GTK_RADIO_BUTTON(radio)));
00109 }
00110 
00111 /*
00112  * Generalized menu functions ;)
00113  */
00114 
00115 GtkWidget * eb_menu_button (GtkMenu * menu, gchar * label,
00116                 GtkSignalFunc callback_func,
00117                 gpointer callback_arg)
00118 {
00119   GtkWidget * button;
00120   if (label == NULL)
00121       button = gtk_menu_item_new();
00122   else
00123       button = gtk_menu_item_new_with_label(label);
00124   if(callback_func != NULL)
00125       gtk_signal_connect(GTK_OBJECT(button), "activate",
00126             callback_func, callback_arg);
00127   gtk_menu_append(menu, button);
00128   gtk_widget_show(button);
00129 
00130   return (button);
00131 }
00132 
00133 GtkWidget * eb_menu_submenu (GtkMenu * menu, gchar * label,
00134                  GtkWidget *submenu)
00135 {
00136   GtkWidget * button;
00137   
00138   button = gtk_menu_item_new_with_label(label);
00139   gtk_menu_append(GTK_MENU(menu), button);
00140 
00141   gtk_menu_item_set_submenu (GTK_MENU_ITEM (button), submenu);
00142   gtk_widget_show(button);
00143 
00144   return (button);
00145 }
00146 
00147 /*
00148  * End generalized menu functions
00149  */
00150 
00151 
00152 
00153 /*------------------------------------------------------------------------*/
00154 /* Function for creating Yattm Icon on Windows                       */
00155 /*------------------------------------------------------------------------*/
00156 
00157 void eb_icon(GdkWindow *w)
00158 {
00159     GdkAtom icon_atom;
00160     glong data[2];
00161         if (icon_pm == NULL) {
00162                 icon_pm = gdk_pixmap_create_from_xpm_d(w, &icon_bm,
00163                           NULL, (gchar **)yattm_xpm);
00164         }
00165 
00166 #ifndef __MINGW32__
00167         data[0] = ((GdkPixmapPrivate *)icon_pm)->xwindow;
00168         data[1] = ((GdkPixmapPrivate *)icon_bm)->xwindow;
00169 
00170         icon_atom = gdk_atom_intern( "KWM_WIN_ICON", FALSE);
00171         gdk_property_change (w, icon_atom, icon_atom,
00172                 32, GDK_PROP_MODE_REPLACE,
00173                 (guchar *)data, 2);
00174 #endif
00175         gdk_window_set_icon(w, NULL, icon_pm, icon_bm);
00176 //      gdk_window_set_back_pixmap(w, icon_pm, 0 );
00177  //       gdk_window_set_group(w, statuswindow->window);
00178 }
00179 
00180 void list_dialog_callback(GtkWidget *widget,
00181             gint row,
00182             gint column,
00183             GdkEventButton *event,
00184             gpointer data)
00185 {
00186     gchar *text;
00187     list_dialog_data *ldd = data;
00188 
00189     gtk_clist_get_text(GTK_CLIST(widget), row, column, &text);
00190     ldd->callback(strdup(text), ldd->data);
00191     free(ldd);
00192 }
00193 
00194 void do_list_dialog( gchar * message, gchar * title, char **list, void (*action)(char * text, gpointer data), gpointer data )
00195 {
00196     GtkWidget * dialog_window;
00197     GtkWidget * label;
00198     GtkWidget * clist;
00199     /*  UNUSED GtkWidget * button_box; */
00200     char *Row[2]={NULL, NULL};
00201     list_dialog_data *ldata;
00202     char **ptr=list;
00203 
00204     eb_debug(DBG_CORE, ">Entering\n");
00205     if(list[0]==NULL) {
00206         eb_debug(DBG_CORE, ">Leaving as list[0]==NULL\n");
00207         return;
00208     }
00209     dialog_window = gtk_dialog_new();
00210 
00211     gtk_widget_realize(dialog_window);
00212     gtk_window_set_title(GTK_WINDOW(dialog_window), title );
00213 
00214     label = gtk_label_new(message);
00215     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
00216     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->vbox),
00217         label, FALSE, FALSE, 5);
00218 
00219     /* Convert the **list to a GList */
00220     clist = gtk_clist_new(1);   /* Only 1 column */
00221     gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_SINGLE);
00222     gtk_clist_set_column_width (GTK_CLIST(clist), 0, 200);
00223     /* Array of pointers to elements, one per column */
00224     while(*ptr) {
00225         Row[0]=*ptr;
00226         ptr++;
00227         gtk_clist_append(GTK_CLIST(clist), Row);
00228         free(Row[0]);
00229     }
00230     free(list);
00231 
00232     ldata=calloc(1, sizeof(list_dialog_data));
00233     ldata->callback=action;
00234     ldata->data=data;
00235     gtk_signal_connect(GTK_OBJECT(clist),
00236         "select_row",
00237         GTK_SIGNAL_FUNC(list_dialog_callback),
00238         ldata);
00239     gtk_signal_connect_object(GTK_OBJECT(clist),
00240         "select_row",
00241         GTK_SIGNAL_FUNC(gtk_widget_destroy),
00242         (gpointer)dialog_window);
00243     gtk_widget_show(clist);
00244     /* End list construction */
00245 /*
00246     button_box = gtk_hbox_new(FALSE, 5);
00247 
00248     gtk_box_pack_start(GTK_BOX(button_box), label, FALSE, FALSE, 2 );
00249 
00250     gtk_container_add(GTK_CONTAINER(button_box), button_box);
00251     gtk_widget_show(button_box);
00252 */  
00253     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), 
00254                         clist, FALSE, FALSE, 5 );
00255 
00256     gtk_widget_show_all(dialog_window);
00257     eb_debug(DBG_CORE, ">Leaving, all done\n");
00258 }
00259 
00260 void do_dialog( gchar * message, gchar * title, void (*action)(GtkWidget * widget, gpointer data), gpointer data )
00261 {
00262     GtkWidget * dialog_window;
00263     GtkWidget * button;
00264     GtkWidget * label;
00265     GdkPixmap *pm;
00266     GdkBitmap *bm;
00267     GtkWidget * button_box;
00268 
00269     dialog_window = gtk_dialog_new();
00270     gtk_window_set_position(GTK_WINDOW(dialog_window), GTK_WIN_POS_MOUSE);
00271     gtk_widget_realize(dialog_window);
00272     gtk_window_set_title(GTK_WINDOW(dialog_window), title );
00273 
00274 
00275 
00276     label = gtk_label_new(message);
00277     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
00278     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->vbox),
00279         label, FALSE, FALSE, 5);
00280 
00281     button_box = gtk_hbox_new(FALSE, 5);
00282     pm = gdk_pixmap_create_from_xpm_d(statuswindow->window, &bm, NULL, tb_yes_xpm);
00283     label = gtk_pixmap_new(pm, bm);
00284 
00285     gtk_box_pack_start(GTK_BOX(button_box), label, FALSE, FALSE, 2 );
00286 
00287     label = gtk_label_new(_("Yes"));
00288     gtk_box_pack_start(GTK_BOX(button_box), label, FALSE, FALSE, 2 );
00289 
00290 
00291     button = gtk_button_new();
00292     gtk_container_add(GTK_CONTAINER(button), button_box);
00293     gtk_widget_show(button_box);
00294     gtk_signal_connect(GTK_OBJECT(button), "clicked",
00295                        GTK_SIGNAL_FUNC(action), data );
00296     gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
00297                               GTK_SIGNAL_FUNC(gtk_widget_destroy),
00298                               (gpointer)dialog_window);
00299     gtk_object_set_user_data(GTK_OBJECT(button), (gpointer)1);
00300     
00301     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), 
00302                         button, FALSE, FALSE, 5 );
00303 
00304     button_box = gtk_hbox_new(FALSE, 5);
00305     pm = gdk_pixmap_create_from_xpm_d(statuswindow->window, &bm, NULL, tb_no_xpm);
00306     label = gtk_pixmap_new(pm, bm);
00307 
00308     gtk_box_pack_start(GTK_BOX(button_box), label, FALSE, FALSE, 2 );
00309 
00310     label = gtk_label_new(_("No"));
00311     gtk_box_pack_start(GTK_BOX(button_box), label, FALSE, FALSE, 2 );
00312 
00313 
00314     button = gtk_button_new();
00315     gtk_container_add(GTK_CONTAINER(button), button_box);
00316 
00317     gtk_signal_connect(GTK_OBJECT(button), "clicked",
00318                        GTK_SIGNAL_FUNC(action), data);
00319     gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
00320                               GTK_SIGNAL_FUNC(gtk_widget_destroy),
00321                               (gpointer)dialog_window);
00322     gtk_object_set_user_data(GTK_OBJECT(button), (gpointer)0 );
00323 
00324     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_window)->action_area), 
00325                         button, FALSE, FALSE, 5 );
00326 
00327     gtk_widget_show_all(dialog_window);
00328 }
00329 
00330     
00331     
00332 
00333 /*------------------------------------------------------------------------*/
00334 /*  The dialog for getting an error                                       */
00335 /*------------------------------------------------------------------------*/
00336 
00337 GtkWidget*
00338 do_error_dialog(char *message, char *title)
00339 {
00340     GtkWidget *d;
00341     GtkWidget *label;
00342     GtkWidget *close;
00343 
00344 
00345     d = gtk_dialog_new();
00346     /* if parent is not main window, set it.
00347      * This prevents this dialog from popping up 'underneath' another
00348      * dialog to which it applies
00349      */
00350     /*if(current_parent_widget)
00351     {
00352     gtk_window_set_transient_for(GTK_WINDOW(d),
00353                      GTK_WINDOW(current_parent_widget));
00354     }*/
00355     label = gtk_label_new(message);
00356     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
00357     gtk_widget_show(label);
00358     close = gtk_button_new_with_label(_("OK"));
00359     gtk_widget_show(close);
00360     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox),
00361         label, FALSE, FALSE, 5);
00362     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area),
00363         close, FALSE, FALSE, 5);
00364     /* so text isn't up against the border */
00365     gtk_container_set_border_width(GTK_CONTAINER(d), 5);
00366     gtk_widget_realize(d);
00367     gtk_window_set_title(GTK_WINDOW(d), title);
00368     gtk_window_set_position(GTK_WINDOW(d), GTK_WIN_POS_MOUSE);
00369     gtk_signal_connect_object(GTK_OBJECT(close), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(d));
00370     gtk_window_set_modal(GTK_WINDOW(d), TRUE);
00371 
00372     gtk_widget_show(d);
00373     return d;
00374 }
00375 
00376 
00377 /*
00378  * The following methods are for the text input window
00379  */
00380 
00381 static void input_window_destroy(GtkWidget * widget, gpointer data)
00382 {
00383     g_free(data);
00384 }
00385 
00386 static void input_window_ok(GtkWidget * widget, gpointer data)
00387 {
00388     text_input_window * window = (text_input_window*)data;
00389     char * text = gtk_editable_get_chars(GTK_EDITABLE(window->text), 0, -1);
00390     window->callback(text, window->data);
00391 }
00392 
00393 void do_text_input_window(gchar * title, gchar * value, 
00394         void (*action)(char * text, gpointer data), 
00395         gpointer data )
00396 {
00397     GtkWidget * vbox = gtk_vbox_new(FALSE, 5);
00398     GtkWidget * frame = gtk_frame_new(NULL); 
00399     GtkWidget * hbox;
00400     GtkWidget * hbox2;
00401     GtkWidget * separator;
00402     GtkWidget * iconwid;
00403     GdkPixmap * icon;
00404     GdkBitmap * mask;
00405     GtkWidget * label;
00406     GtkWidget * button;
00407 
00408     text_input_window * input_window = g_new0(text_input_window, 1);
00409     input_window->callback = action;
00410     input_window->data = data;
00411 
00412     input_window->window = gtk_window_new(GTK_WINDOW_DIALOG);
00413     gtk_window_set_position(GTK_WINDOW(input_window->window), GTK_WIN_POS_MOUSE);
00414         gtk_widget_realize(input_window->window);
00415 
00416     gtk_container_set_border_width(GTK_CONTAINER(input_window->window), 5);
00417     gtk_frame_set_label(GTK_FRAME(frame), title);
00418 
00419     input_window->text = gtk_text_new(NULL, NULL);
00420     gtk_widget_set_usize(input_window->text, 400, 200);
00421     gtk_text_insert(GTK_TEXT(input_window->text),
00422             NULL, NULL, NULL, value, strlen(value));
00423     gtk_text_set_editable(GTK_TEXT(input_window->text),
00424             TRUE);
00425 
00426     gtk_container_add(GTK_CONTAINER(frame), input_window->text);
00427     gtk_widget_show(input_window->text);
00428 
00429     gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
00430     gtk_widget_show(frame);
00431 
00432 
00433     separator = gtk_hseparator_new();
00434     gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 5);
00435     gtk_widget_show(separator);
00436 
00437     hbox = gtk_hbox_new(FALSE, 5);
00438     hbox2 = gtk_hbox_new(TRUE, 5);
00439 
00440     gtk_widget_set_usize(hbox2, 100,25);
00441 
00442     icon = gdk_pixmap_create_from_xpm_d(input_window->window->window, &mask, NULL, ok_xpm);
00443     iconwid = gtk_pixmap_new(icon, mask);
00444     label = gtk_label_new(_("OK"));
00445          
00446     gtk_box_pack_start(GTK_BOX(hbox), iconwid, FALSE, FALSE, 2);
00447     gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
00448          
00449     gtk_widget_show(iconwid);
00450     gtk_widget_show(label);
00451          
00452     button = gtk_button_new();
00453          
00454     gtk_signal_connect(GTK_OBJECT(button), "clicked", input_window_ok,
00455             input_window);
00456 
00457     gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
00458                   GTK_SIGNAL_FUNC(gtk_widget_destroy),
00459                   GTK_OBJECT(input_window->window));
00460          
00461     gtk_container_add(GTK_CONTAINER (button), hbox);        
00462     gtk_widget_show(hbox);     
00463          
00464     gtk_box_pack_start(GTK_BOX(hbox2), button, TRUE, TRUE, 0);
00465     gtk_widget_show(button);
00466 
00467     hbox = gtk_hbox_new(FALSE, 0);
00468         
00469     gtk_box_pack_end(GTK_BOX(hbox),hbox2, FALSE, FALSE, 0);
00470     gtk_widget_show(hbox2);      
00471       
00472     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00473     gtk_widget_show(hbox);
00474 
00475     gtk_container_add(GTK_CONTAINER(input_window->window), vbox);
00476     gtk_widget_show(vbox);
00477 
00478         gtk_window_set_title(GTK_WINDOW(input_window->window), title);
00479     eb_icon(input_window->window->window);
00480 
00481     gtk_signal_connect(GTK_OBJECT(input_window->window), "destroy",
00482             GTK_SIGNAL_FUNC(input_window_destroy), input_window);
00483 
00484     gtk_widget_show(input_window->window);
00485         
00486 
00487 }
00488 

Contact: Andy Maloney     [Documentation generated by doxygen]