GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 23, 2014 10:25 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: appwindow.c g_object_new question
PostPosted: Tue Sep 11, 2012 7:21 pm 
Offline
Familiar Face

Joined: Wed Sep 05, 2012 2:02 am
Posts: 7
Hello Sir's
I have tried to follow appwindow.c code that comes in gtk2 and one line called my attention.
Code:
      open_action = g_object_new (tool_menu_action_get_type (),
              "name", "Open",
              "label", "_Open",
              "tooltip", "Open a file",
              "stock-id", GTK_STOCK_OPEN,
              NULL);

What is tool_menu_action_get_type() ? After searched in all my hard drive on windows and linux side, I was not able to find that.
So, I think that that function can be in one of the headers, and this give-me another question, where are "#include "demo-common.h""?
Well, maybe I was not searching in the right place, but, the question is:
Can you , please, create a simple example about how to use g_object_new () in the same context of appwindow.c? So, I can try it by my way, instead of debug the gtk-demo(.exe) to find this solution.
thanks a lot.


Top
 Profile  
 
 Post subject: Re: appwindow.c g_object_new question
PostPosted: Tue Sep 11, 2012 7:55 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

This function is part of the internal workings of custom GObject. Code that you're inspecting defines a custom action that derives from GtkAction. Relevant pieces of code that do this are definition of ToolMenuAction and ToolMenuActionClass structures and G_DEFINE_TYPE macro (along with some other init functions). And that macro (along other things) define that tool_menu_action_type() function.

Normally, you don't see these function, since they are wrapped using standard macros like GTK_TYPE_WIDGET, GDK_TYPE_PIXBUF ... and when constructing them, you use special _new() functions that wrap the call to g_object_new() for you.

If you're only starting to learn GTK+, you should just ignore those functions and write your code using higher-level API calls. Things will become much clearer when you start to learn how to create your own widgets. You'll get to now GType and GObject libraries in greater detail and see where all that stuff comes from.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: appwindow.c g_object_new question
PostPosted: Tue Sep 11, 2012 8:19 pm 
Offline
Familiar Face

Joined: Wed Sep 05, 2012 2:02 am
Posts: 7
Thank you Sir tadeboro for the light in the end of tunnel.
I'm in a learning process, but I have a fault that I cannot understand c or python language. So, I compile some programs, dump their assembly and study the output. I'm learning both, C language and gtk in this way.
So, what I have understood from your words is that that function are generally used if I will create my own class object. Is this? And I can have the same supposed effect if I use builded classes that do that.
So, now I'm forgetting that line (only for some time, I will be back to that again in a near future) and changing my eyes to gmenu example.
Thank you Sir tadeboro.


Top
 Profile  
 
 Post subject: Re: appwindow.c g_object_new question
PostPosted: Wed Sep 12, 2012 2:38 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

Yes, functions that you're interested in are usually only used when creating new class of object, deriving it from GObject. As I said, doing this stuff is not exactly trivial, since C knows nothing about objects, but GObject at least makes it possible;)

Cheers,
Tadej


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 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