GtkFileSelection, Signals and the GTK Reference



Hi,

I'm a new GTK programmer whose hit a bit of a problem...

I am writing a procedure, ask_for_file() which pops up a
GtkFileSelection dialog and sets its callbacks to the pointers
specified.  This is the prototype for my procedure:

void ask_for_file (const char *title, const char *ok_button,
GtkSignalFunc callback_ok, GtkSignalFunc callback_cancel, gpointer
*data)

title is the title of the window
ok_button is the caption of the Okay button (if null, use "Okay")
callback_ok is a pointer to the callback for the Okay button
callback_cancel is a pointer to the callback for the Cancel button
data is an optional pointer to user data

This is my procedure so far:

void
ask_for_file (const char *title, const char *ok_button, GtkSignalFunc
callback_ok,
GtkSignalFunc callback_cancel, gpointer *data)
{
  GtkWidget *file_selector;

  /* Sanity checks - we need a title and a callback for the okay button
*/
  g_return_if_fail(title != NULL);
  g_return_if_fail(callback_ok != NULL);
  
  /* Create the selector */
  file_selector = gtk_file_selection_new(title);

  /* TODO: set captions, default to "Okay" */

  /* Connect the user supplied callbacks */
  gtk_signal_connect_object (GTK_OBJECT
(GTK_FILE_SELECTION(file_selector)->ok_button),
                             "clicked", callback_ok,
GTK_OBJECT(file_selector));
  if (callback_cancel) {
    gtk_signal_connect_object (GTK_OBJECT
(GTK_FILE_SELECTION(file_selector)->cancel_button),
                               "clicked", callback_cancel,
GTK_OBJECT(file_selector));
  }
  
  /* Connect callbacks to destroy the dialog once the user has clicked a
button. */
  gtk_signal_connect_object (GTK_OBJECT
(GTK_FILE_SELECTION(file_selector)->ok_button),
                             "clicked", GTK_SIGNAL_FUNC
(gtk_widget_destroy),
                             (gpointer) file_selector);
  gtk_signal_connect_object (GTK_OBJECT
(GTK_FILE_SELECTION(file_selector)->cancel_button),
                             "clicked", GTK_SIGNAL_FUNC
(gtk_widget_destroy),
                             (gpointer) file_selector);
  
   /* Display the selector */
  gtk_widget_show (file_selector);
}


(some code was stolen from the GTK reference examples)

Now I come to my problem: if I use gtk_signal_connect to connect the
user's callbacks to the okay button I can pass the user data.  However,
as far as I can tell when I do this the first parameter given to the
callback is a pointer to the "Okay" GtkButton, not the GtkFileSelection
dialog. Thus I can't see a way of getting the filename. If I use
gtk_signal_connect_object I can set the "object" to be a pointer to the
GtkFileSelection, so the callbacks have a way to get the filename, but
the user data is not available. I am planning to use this code in Galeon
and the user data is used to pass around a pointer to a GaleonWindow
instance.

Is this correct so far?

I'm slightly confused about what can be done as the GTK reference
example for GtkFileSelection does not make sense
(http://developer.gnome.org/doc/API/gtk/gtkfileselection.html): the
function store_filename is being given a GtkFileSelection, but then uses
the global variable. The gtk_signal_connect call implies that the
arguments to that procedure should be the "Okay" GtkButton and the user
data (NULL). However, the signature actually is GtkFileSelection and the
user data.  What is correct?

I'm terribly confused...  :-(  Can anyone help me?

Thanks in advance,
Ross Burton

-- 
Ross Burton                     Software Engineer
OneEighty Software Ltd          Tel: +44 20 8263 2332
The Lansdowne Building          Fax: +44 20 8263 6314
2 Lansdowne Road                r burton 180sw com
Croydon, Surrey CR9 2ER, UK     http://www.180sw.com./
====================================================================
Under the Regulation of Investigatory Powers (RIP) Act 2000 together
with any and all Regulations in force pursuant to the Act OneEighty
Software Ltd reserves the right to monitor any or all incoming or
outgoing communications as provided for under the Act





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]