flat assembler
Message board for the users of flat assembler.

Index > Linux > I need a little help

Author
Thread Post new topic Reply to topic
devilsclaw



Joined: 30 Oct 2003
Posts: 8
devilsclaw 30 Oct 2003, 21:23
This is a C sample

void file_ok_sel( GtkWidget *w,
GtkFileSelection *fs )
{
g_print ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
}

int main( int argc,
char *argv[] )
{
GtkWidget *filew;

gtk_init (&argc, &argv);

/* Connect the ok_button to file_ok_sel function */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
"clicked", (GtkSignalFunc) file_ok_sel, filew );


gtk_widget_show(filew);
gtk_main ();
return 0;
}

i need to understand how to get the singal connect to be linked with the ok button but im not sure how to do that in this case
Post 30 Oct 2003, 21:23
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 30 Oct 2003, 22:33
It's C not C++ (the -> look's wrong to me, I know c++ rather well, but my c skills are under devlopment, but I don't think c has the -> operator).
Anyways, here is what I dug out from the gtk tutorial:
Quote:
Theory of Signals and Callbacks

In version 2.0, the signal system has been moved from GTK to GLib, therefore the functions and types explained in this section have a "g_" prefix rather than a "gtk_" prefix. We won't go into details about the extensions which the GLib 2.0 signal system has relative to the GTK 1.2 signal system.

Before we look in detail at helloworld, we'll discuss signals and callbacks. GTK is an event driven toolkit, which means it will sleep in gtk_main() until an event occurs and control is passed to the appropriate function.

This passing of control is done using the idea of "signals". (Note that these signals are not the same as the Unix system signals, and are not implemented using them, although the terminology is almost identical.) When an event occurs, such as the press of a mouse button, the appropriate signal will be "emitted" by the widget that was pressed. This is how GTK does most of its useful work. There are signals that all widgets inherit, such as "destroy", and there are signals that are widget specific, such as "toggled" on a toggle button.

To make a button perform an action, we set up a signal handler to catch these signals and call the appropriate function. This is done by using a function such as:

Code:
gulong g_signal_connect( gpointer      *object,
                         const gchar   *name,
                         GCallback     func,
                         gpointer      func_data );    


where the first argument is the widget which will be emitting the signal, and the second the name of the signal you wish to catch. The third is the function you wish to be called when it is caught, and the fourth, the data you wish to have passed to this function.

The function specified in the third argument is called a "callback function", and should generally be of the form

Code:
void callback_func( GtkWidget *widget,
                    gpointer   callback_data );    


where the first argument will be a pointer to the widget that emitted the signal, and the second a pointer to the data given as the last argument to the g_signal_connect() function as shown above.

Note that the above form for a signal callback function declaration is only a general guide, as some widget specific signals generate different calling parameters.

Another call used in the helloworld example, is:
Code:
gulong g_signal_connect_swapped( gpointer     *object,
                                 const gchar  *name,
                                 GCallback    func,
                                 gpointer     *slot_object );    


g_signal_connect_swapped() is the same as g_signal_connect() except that the callback function only uses one argument, a pointer to a GTK object. So when using this function to connect signals, the callback should be of the form
Code:
void callback_func( GtkObject *object );    


where the object is usually a widget. We usually don't setup callbacks for g_signal_connect_swapped() however. They are usually used to call a GTK function that accepts a single widget or object as an argument, as is the case in our helloworld example.

The purpose of having two functions to connect signals is simply to allow the callbacks to have a different number of arguments. Many functions in the GTK library accept only a single GtkWidget pointer as an argument, so you want to use the g_signal_connect_swapped() for these, whereas for your functions, you may need to have additional data supplied to the callbacks.


here is the signlar connection in one of the examples (buttons):
Code:
    /* Connect the "clicked" signal of the button to our callback */
    g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (callback), (gpointer) "cool button");    


So I guess your code should look like this:
Code:
/* Connect the ok_button to file_ok_sel function */
gtk_signal_connect ((G_OBJECT) ok_button, "clicked", (G_CALLBACK) file_ok_sel, filew );

// or (if I miss understood the -> operator)

/* Connect the ok_button to file_ok_sel function */
gtk_signal_connect ((G_OBJECT) ( (GTK_FILE_SELECTION)(filew).ok_button), "clicked", (G_CALLBACK) file_ok_sel, filew );    


I'd recoment downloading the gtk tutorials, as stated in the tutorial:
Quote:
Tutorial Availability

A copy of this tutorial in SGML and HTML is distributed with each source code release of GTK+. For binary distributions, please check with you vendor.

A copy is available online for reference at www.gtk.org/tutorial.

A packaged verion of this tutorial is available from ftp.gtk.org/pub/gtk/tutorial which contains the tutorial in various different formats. This package is primary for those people wanting to have the tutorial available for offline reference and for printing.

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 30 Oct 2003, 22:33
View user's profile Send private message Visit poster's website Reply with quote
devilsclaw



Joined: 30 Oct 2003
Posts: 8
devilsclaw 31 Oct 2003, 01:14
im using gcc and it compiles into a working sample so -> is in C other wise it would not compile and if it did it would give a warning
Post 31 Oct 2003, 01:14
View user's profile Send private message Reply with quote
devilsclaw



Joined: 30 Oct 2003
Posts: 8
devilsclaw 31 Oct 2003, 01:16
i have also already read that from the GTK website and the sample i posted is a stripped down version of the one they have at there site i only needed help with on section
Post 31 Oct 2003, 01:16
View user's profile Send private message Reply with quote
jInuQ



Joined: 26 Jun 2003
Posts: 48
Location: USA - NV
jInuQ 11 Nov 2003, 11:58
If i remember right the -> is used for accessing structure member thru a pointer.

http://www.phim.unibe.ch/comp_doc/c_manual/C/SYNTAX/struct.html#pointers

_________________
jInuQ

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away."
- Antoine de Saint Exupery
Post 11 Nov 2003, 11:58
View user's profile Send private message Visit poster's website AIM Address Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 11 Nov 2003, 12:25
ok, thanx for the link. My misstake, thougt -> was a class (thus c++) specific thing, but my memory failed me (long time since last c++ app)

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 11 Nov 2003, 12:25
View user's profile Send private message Visit poster's website Reply with quote
jInuQ



Joined: 26 Jun 2003
Posts: 48
Location: USA - NV
jInuQ 12 Nov 2003, 09:28
I think it was less a mistake and more just far too much stuff to remember. Very Happy

_________________
jInuQ

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away."
- Antoine de Saint Exupery
Post 12 Nov 2003, 09:28
View user's profile Send private message Visit poster's website AIM Address Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.