Page 1 of 1

Adding a widget to a PB WIndow?

Posted: Sun Aug 13, 2017 3:17 pm
by Justin
It is possible to add a widget to a PB window? I can't get the gtkFixed widget if it's what PB uses, i found this code on the forum but does not work, any ideas?

Code: Select all

EnableExplicit

Define.i win, fixedBox, widget

win = OpenWindow(#PB_Any, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
fixedBox = g_list_nth_data_(gtk_container_get_children_(gtk_bin_get_child_(WindowID(win))), 0)
Debug fixedBox
widget = gtk_drawing_area_new_()
Debug widget
gtk_fixed_put_(fixedBox, widget, 0, 0) ;ERROR NOT GTKFIXED

Repeat
Until	 WaitWindowEvent() = #PB_Event_CloseWindow

Re: Adding a widget to a PB WIndow?

Posted: Sun Aug 13, 2017 4:30 pm
by Oma
Hi Justin,

this only works on gtk2-subsystem and only for widgets like fixed backgrounds etc.

The hierarchy for a real PB-Gadget is on gtk2:
GtkWindow > GtkVBox > GtkFixed > GADGET

On gtk3-subsystem (to get it compatible as much as possible to gtk2-fixed-position-and-size system ):
GtkWindow > GtkVBox > GtkScrolledWindow > GtkViewport > GtkFixed > GADGET

I think you get a lot of work :wink:

Regards, Charly

ps: hierarchy corrected, Sun Aug 13, 2017 6:12 pm

Re: Adding a widget to a PB WIndow?

Posted: Sun Aug 13, 2017 4:47 pm
by Justin
Thanks for the info. I found a workaround, just put a container, is already a gtkFixed, you can use gtk_fixed_put_() directly on it.

Re: Adding a widget to a PB WIndow?

Posted: Sun Aug 13, 2017 5:27 pm
by Justin
My workaround did not work as expected, i needed the widget in the main window, it works in the first gtkFixed, going to the second gives errors, are you sure it is the correct hierarchy?

Code: Select all

EnableExplicit

Define.i win, FixedBox, widget

win = OpenWindow(#PB_Any, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
;GtkWindow > GtkVBox > GtkScrolledWindow > GtkViewport > GtkFixed > GtkScrolledWindow > GtkViewport > GtkFixed >

FixedBox = g_list_nth_data_(gtk_container_get_children_(WindowID(win)), 0) ;GtkVBox
FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkScrolledWindow
FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkViewport
FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkFixed WORKS
Debug FixedBox

; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkScrolledWindow
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkViewport
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkFixed ;ERROR
; Debug FixedBox

widget = gtk_button_new_with_label_("TEST")

gtk_fixed_put_(fixedBox, widget, 0, 0) 
gtk_widget_show_(widget)

Repeat
Until	 WaitWindowEvent() = #PB_Event_CloseWindow

Re: Adding a widget to a PB WIndow?

Posted: Sun Aug 13, 2017 6:11 pm
by Oma
Sorry! :oops:
Of course it was a mistake (taken from an older demo and forgot to remove the GtkScrolledWindow in which all Gadget-Types was placed to debug the structure)
The hierarchy above has been corrected!

Now the 1. button should be visible ...

Code: Select all

ImportC ""
	gtk_widget_get_name(*widget.GtkWidget)
EndImport

Define.i win, FixedBox, widget

win = OpenWindow(#PB_Any, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu)
;GtkWindow > GtkVBox > GtkScrolledWindow > GtkViewport > GtkFixed > GtkScrolledWindow > GtkViewport > GtkFixed >

;gtk3
; FixedBox = g_list_nth_data_(gtk_container_get_children_(WindowID(win)), 0) ;GtkVBox
; Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkScrolledWindow
; Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkViewport
; Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
; FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkFixed WORKS
; Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
; Debug FixedBox

;gtk2
FixedBox = g_list_nth_data_(gtk_container_get_children_(WindowID(win)), 0) ;GtkVBox
Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
FixedBox = g_list_nth_data_(gtk_container_get_children_(FixedBox), 0) ;GtkFixed ;ERROR
Debug PeekS(gtk_widget_get_name(FixedBox), -1, #PB_UTF8)
Debug FixedBox

widget = gtk_button_new_with_label_("TEST")

gtk_fixed_put_(fixedBox, widget, 0, 0)
gtk_widget_show_(widget)

Repeat
Until    WaitWindowEvent() = #PB_Event_CloseWindow
ps: To avoid problems in the future ...
For all API commands which uses parameters which are not of the type integer or long, you should use 'ImportC' with the proper types. Here ...

Code: Select all

ImportC ""
	gtk_button_new_with_label(text.p-utf8)
EndImport
Only a few non-integer-parameters was adapted correctly in the PB API calls.

Re: Adding a widget to a PB WIndow?

Posted: Sun Aug 13, 2017 6:47 pm
by Justin
Great. Thank you.