GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting widget geometry, ie where and how big?

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
wjgiddings
GTK+ Geek


Joined: 06 Feb 2009
Posts: 71
Location: The Midlands, England

PostPosted: Sun Apr 12, 2009 10:38 am    Post subject: Getting widget geometry, ie where and how big? Reply with quote

Gtk gives no simple, single command to return the geometry of a widget; ie its screen coordinates, width and height.
I recently implemented a script option in Gnocl and I thought that I'd like to share relevent code snippet to do the job. Adapt the context to suite your own apps.

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
        case GeometryIdx:
           
{
                char buffer[128];

                GtkWidget *widget;
                GtkRequisition req;
                gint x, y, w, h;

                widget = gnoclGetWidgetFromName (  Tcl_GetString ( objv[2] ), interp );

                gdk_window_get_origin ( widget->window, &x, &y );


                x += widget->allocation.x;
                x -= widget->style->xthickness;
                y += widget->allocation.y;
                y -= widget->style->ythickness;

                gtk_widget_size_request ( widget, &req );

                w = req.width;
                h = req.height;

                sprintf ( buffer, "%d %d %d %d", x, y, w, h );

                Tcl_SetObjResult ( interp, Tcl_NewStringObj ( buffer, -1 ) );
            }
added codeBB -dreblen
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP