# Policy for access to widget struct data

**URL:** <https://www.ruby-forum.com/t/policy-for-access-to-widget-struct-data/108874>\
**Category:** Ruby-Gnome 2\
**Created:** [July 8, 2007, 4:08pm UTC](https://www.ruby-forum.com/t/policy-for-access-to-widget-struct-data/108874 "2007-07-08T16:08:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [July 8, 2007, 4:08pm UTC](https://www.ruby-forum.com/t/policy-for-access-to-widget-struct-data/108874/1 "2007-07-08T16:08:39Z")

</div>

I need access to GtkButton-\>event\_window from my program. I see that  
it is not binded, but for example GtkWidget-\>window is equivalent  
problem, and binded.

Is there any policy regarding widget struct data? Can I simply add  
access to -\>event\_window since I need it?

–  
Guillaume C. - [http://zarb.org/~gc/](http://zarb.org/~gc/)

* * *

This [SF.net](http://SF.net) email is sponsored by DB2 Express  
Download DB2 Express C - the FREE version of DB2 express and take  
control of your XML. No limits. Just data. Click to get it now.  
[http://sourceforge.net/powerbar/db2/](http://sourceforge.net/powerbar/db2/)

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [July 8, 2007, 4:42pm UTC](https://www.ruby-forum.com/t/policy-for-access-to-widget-struct-data/108874/2 "2007-07-08T16:42:42Z")

</div>

Hi,

On Sun, 8 Jul 2007 16:07:48 +0200  
“Guillaume C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I need access to GtkButton-\>event\_window from my program. I see that  
> it is not binded, but for example GtkWidget-\>window is equivalent  
> problem, and binded.
> 
> Is there any policy regarding widget struct data? Can I simply add  
> access to -\>event\_window since I need it?

We implement public functions/data of GTK-2.0.  
“public” means it can be refer from API reference.  
And we don’t prefer to implement accessors to C Struct data directly.

For example, Gtk::Widget-\>window is in the API reference.  
[http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidgetClass](http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidgetClass)  
So we implemented them.

Are there any workaround ?  
If no, you can implement it.

–  
.:% Masao M.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

* * *

This [SF.net](http://SF.net) email is sponsored by DB2 Express  
Download DB2 Express C - the FREE version of DB2 express and take  
control of your XML. No limits. Just data. Click to get it now.  
[http://sourceforge.net/powerbar/db2/](http://sourceforge.net/powerbar/db2/)

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [July 8, 2007, 5:37pm UTC](https://www.ruby-forum.com/t/policy-for-access-to-widget-struct-data/108874/3 "2007-07-08T17:37:46Z")

</div>

> > Is there any policy regarding widget struct data? Can I simply add  
> > access to -\>event\_window since I need it?
> 
> We implement public functions/data of GTK-2.0.  
> “public” means it can be refer from API reference.  
> And we don’t prefer to implement accessors to C Struct data directly.

I see. And there is even this mention about the GtkButton struct:

“This should not be accessed directly. Use the accessor functions  
below.”

Though, I was misleaded because in the source code (headers of gtk)  
there seems to be no difference between struct for GtkWidget and  
GtkButton. I wonder why they don’t define the GtkButton as an opaque  
struct in the headers of gtk…

> Are there any workaround ?

I cannot find one for the moment ☹

I have a set of GtkButtons in a GtkHBox in a GtkScrolledWindow. I want  
to implement autoscrolling of the scrolled window when a non-visible  
button is focused with the keyboard. I cannot find another approach  
than looking at the coordinates of the -\>event\_window GdkWindow  
(GtkButton doesn’t have its own GdkWindow). But there is maybe a  
better one… but I don’t know it.

–  
Guillaume C. - [Guillaume Cottenceau](http://zarb.org/~gc/)

* * *

This [SF.net](http://SF.net) email is sponsored by DB2 Express  
Download DB2 Express C - the FREE version of DB2 express and take  
control of your XML. No limits. Just data. Click to get it now.  
[http://sourceforge.net/powerbar/db2/](http://sourceforge.net/powerbar/db2/)

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [July 8, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/policy-for-access-to-widget-struct-data/108874/4 "2007-07-08T18:10:52Z")

</div>

Hi,

this example is not perfect, but i think you will get it with it.

Cheers  
detlef

#!/usr/bin/ruby  
require ‘gtk2’

win = Gtk::Window.new  
scroll = Gtk::ScrolledWindow.new  
box = Gtk::HBox.new

win \<\< scroll  
scroll.add\_with\_viewport box  
adj = scroll.hadjustment

width = 0

10.times do |i|  
button = Gtk::Button.new(“button #{i}”)  
width += button.size\_request[0]  
button.signal\_connect(‘focus\_in\_event’) do |b, event|  
pos = b.allocation.x  
p pos  
adj.value = pos  
end  
box.pack\_start button  
end

adj.upper = width

win.show\_all  
Gtk.main

Am Sonntag, den 08.07.2007, 17:37 +0200 schrieb Guillaume C.:

> to implement autoscrolling of the scrolled window when a non-visible  
> button is focused with the keyboard. I cannot find another approach  
> than looking at the coordinates of the -\>event\_window GdkWindow  
> (GtkButton doesn’t have its own GdkWindow). But there is maybe a  
> better one… but I don’t know it.

* * *

This [SF.net](http://SF.net) email is sponsored by DB2 Express  
Download DB2 Express C - the FREE version of DB2 express and take  
control of your XML. No limits. Just data. Click to get it now.  
[http://sourceforge.net/powerbar/db2/](http://sourceforge.net/powerbar/db2/)

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [July 8, 2007, 7:19pm UTC](https://www.ruby-forum.com/t/policy-for-access-to-widget-struct-data/108874/5 "2007-07-08T19:19:59Z")

</div>

> this example is not perfect, but i think you will get it with it.

Doh! I just proved myself to be a gtk newbie 😕 Thanks a lot for your  
time!

–  
Guillaume C. - [Guillaume Cottenceau](http://zarb.org/~gc/)

* * *

This [SF.net](http://SF.net) email is sponsored by DB2 Express  
Download DB2 Express C - the FREE version of DB2 express and take  
control of your XML. No limits. Just data. Click to get it now.  
[http://sourceforge.net/powerbar/db2/](http://sourceforge.net/powerbar/db2/)
