GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 01, 2014 4:00 am

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: callback function
PostPosted: Thu Sep 22, 2005 12:56 pm 
Offline
Familiar Face

Joined: Thu Sep 22, 2005 12:23 pm
Posts: 20
Hi folks!

I have been racking my brains trying to find informatio about writing a callback function that receives two parameters one that indicates the type of icon I want displayed and the other a character string variable that holds the different messages this callback function will pass to a a dialogbox.

This is what the callback function looks like, or I think it would look like:
typedef struct{
gchar* str; // Message
GtkWidget* obj; // Icon
}DATA;
void GeneralMsg(DATA&);
void GeneralMsg(DATA& d){
// Create and display a message box with the information in the DATA variable
.....
}

Is this possible?

TIA

_________________
* You cannot exercise your power to a point of humiliation.
- Jean Chretien

* It's amazing how the small seeds of distrust and misunderstanding
can yield a crop of hate and death...

Ma'assalama! Adiós! bye!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 4:00 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Are you trying to create a new signal/callback or use a specific one? If you are using an existing signal/callback, which one do you want to use?

You can reference them at http://www.gtk.org/api/2.6/gtk/index.html if you want...

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: Thanks Openldev.
PostPosted: Thu Sep 22, 2005 8:02 pm 
Offline
Familiar Face

Joined: Thu Sep 22, 2005 12:23 pm
Posts: 20
Well, firsto of all I'd like to thank you for your response, and second of all... No, I am not trying to create a new signal.
What I am trying to do, though, is to find out if it is possible to have a callback function, that will accept a number of parameters that will determin the look, and why not, the feel of the message box that this callback function will displayed.

This same methodology will be used when the user presses a button and to the callback function information would be passed, so that the new window do something with it.

Right now, all I can do is write a new callback function for each of the different messages that I want to displayed to the users, which is kind of a drag... you know what I mean.
It would be nice if I can write one callback function and pass to it the data I want to displayed, is this possible?

Thanks in advance

Reply with quote
New post
Are you trying to create a new signal/callback or use a specific one? If you are using an existing signal/callback, which one do you want to use?

You can reference them at http://www.gtk.org/api/2.6/gtk/index.html if you want..

_________________
* You cannot exercise your power to a point of humiliation.
- Jean Chretien

* It's amazing how the small seeds of distrust and misunderstanding
can yield a crop of hate and death...

Ma'assalama! Adiós! bye!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 8:11 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Ok, I think I know what you're trying to do.

Basically, first you want to connect the signal using:

g_signal_connect (G_OBJECT(button), "clicked", G_CALLBACK(on_button_pressed), (gpointer)data);

In this connection, "data" is your DATA structure you want to pass to your callback.

Then use for your callback:

void on_button_pressed (GtkButton *button, gpointer data)
{
DATA *ptr = (DATA*) data;
.....
}

This callback function casts the gpointer back to a DATA structure. Then you can use your "ptr->str" or whatever from the structure. I know there's other ways of doing this, but this is the most efficient way that I have found.

I hope this answers your question!

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 8:13 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Oh, and one more thing. I casted it because I was assuming DATA was a pointer. You can make it a non-pointer, but I always find sending data around that needs recasted constantly easier to use as pointers... :)

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: Wow!
PostPosted: Sat Sep 24, 2005 12:37 am 
Offline
Familiar Face

Joined: Thu Sep 22, 2005 12:23 pm
Posts: 20
You've come as a blessing from above.
I have not tried your suggestion, but I can tell that you understand my predicament.
One last question.
Thanks soooo much.

_________________
* You cannot exercise your power to a point of humiliation.
- Jean Chretien

* It's amazing how the small seeds of distrust and misunderstanding
can yield a crop of hate and death...

Ma'assalama! Adiós! bye!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 24, 2005 2:05 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Honesly, it's really no problem. I am so excited about this forum because when I was first learning Gtk I had so much trouble at first, but there were a ton of people that helped me out. Now I figure it is my turn to give back. The joys of Open Source... :)

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: thanks openldev
PostPosted: Sat Sep 24, 2005 2:15 am 
Offline
Familiar Face

Joined: Thu Sep 22, 2005 12:23 pm
Posts: 20
OK, I did as you suggested, but I get an error message saying that 'data of type DATA could not be converted to void*'

Any ideas?

TIA

_________________
* You cannot exercise your power to a point of humiliation.
- Jean Chretien

* It's amazing how the small seeds of distrust and misunderstanding
can yield a crop of hate and death...

Ma'assalama! Adiós! bye!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 24, 2005 2:19 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Can you post the code you are using?

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: Just an update
PostPosted: Sat Sep 24, 2005 2:48 am 
Offline
Familiar Face

Joined: Thu Sep 22, 2005 12:23 pm
Posts: 20
Instead of using the 'C' casting operator I use reinterpret_cast operator and it worked, I for got to mention that I am using GTK+ as the front end of an application that was written in C++.

OK, now let's see if I can get my GTK+ programming going.


Thanks!! :o

_________________
* You cannot exercise your power to a point of humiliation.
- Jean Chretien

* It's amazing how the small seeds of distrust and misunderstanding
can yield a crop of hate and death...

Ma'assalama! Adiós! bye!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 24, 2005 2:53 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Yes, that is actually what I do in OpenLDev. The only bump in the road I found with using c++ with Gtk+ is that you have to make callback functions private friends if you want them to have access to a specific class that you send to it with the gpointer. Good luck! :)

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: Tried it, did not work, HEEEEELLP
PostPosted: Sun Sep 25, 2005 4:22 pm 
Offline
Familiar Face

Joined: Thu Sep 22, 2005 12:23 pm
Posts: 20
I tried to provide as little code as possible, but to make what my intentions are clearer I had to add quite a bit, please bear with me…

This program runs, but when click on any button, with the exception of the “Exitâ€

_________________
* You cannot exercise your power to a point of humiliation.
- Jean Chretien

* It's amazing how the small seeds of distrust and misunderstanding
can yield a crop of hate and death...

Ma'assalama! Adiós! bye!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 25, 2005 4:42 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
I believe someone already answered your question on the Gtk-list...

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 4 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group