Re: [gtk-list] Main Window References Dialog Window(or vica versa)?



George Deprez wrote:
> I have a window which creates and pops up a dialog with an entry.
> When the OK button is pressed the callback obtains the entry
> data and MUST update data in the main window.
> 
> What is the best way to exchange information between windows.

Hi George, I do this using the client pointer in signals. Make a struct
representing an instance of your dialog, something like:

	typedef struct {
		MyMainWindow *main;	/* Main window we pop up from */

		GtkWidget *entry;	/* Your entry widget */
		GtkWidget *window;	/* The main dialog window */
	} MyDialog;

So it's got links to your dialog widgets, and back to the struct for
your main window. Build one of these when you pop up an instance of your
dialog, and free it in a destroy signal handler on the window.

When you attach a signal to OK, pass in a pointer to the MyDialog
instance. In the OK signal handler, read the contents of the entry
widget, and pass it back to your main window. Something like:

	void
	my_signal_handler( GtkWidget *ok, MyDialog *dia )
	{
		char *txt;

		txt = gtk_entry_get_text( dia->entry );
		my_main_update( dia->main, txt );
	}

> How can I disable the destroy button on a dialog window?
> I want to force the users to use the OK and CANCEL buttons.

This is probably a bad idea, users expect to be able to use the kill
button. Why not make the destroy button the same as cancel?

To do this, you need to catch the "delete-event" signal, I think this is
covered in the tutorial.

Hope this helps,

John
--
John Cupitt, john.cupitt@ng-london.org.uk, +44 (0)171 747 2570
VASARI Lab, The National Gallery, Trafalgar Square, London, WC2N 5DN



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