---------------------------------------------
-- Demonstrates:
-- scrolled_window
-- tables
-- GTK stock
-- (Hover over buttons with mouse pointer
-- to see stockname of button
----------------------------------------------
include GtkEngine.e
-------------------------------------------------------------
-- following would be very seldom used, so it's a hard-coded
-- call to Eu's define_c_func, not part of EuGTK
-------------------------------------------------------------
constant gtk_list_ids = define_c_func(GTK,"gtk_stock_list_ids",{},C_POINTER)
-- retrieve stock ids from GTK
sequence ids = dealloc(c_func(gtk_list_ids,{}))
------------------------------------------
function build_table(integer r, integer c)
------------------------------------------
object tbl, btn
integer ct
-- create a table with r rows and c columns, homogeneous sizing
tbl = create(GtkTable,r,c,TRUE)
ct = 0
for col = 0 to c do
for row = 0 to r do
ct += 1
if ct > length(ids) then -- no more stock items
exit
else
-- create a new button from this stock id
btn = create(GtkButton,ids[ct])
-- attach an appropriate tooltip to the button
set(btn,"tooltip text",ids[ct])
-- attach new button to the table
-- col,col+1 means button starts in col, extends to col+1
-- so items can take up more than one row or one columns
-- if needed;
set(tbl,"attach defaults",btn,col,col+1,row,row+1)
end if
end for
end for
return tbl
end function
-- create an adustment object to handle h scrollbar
constant hadj = create(GtkAdjustment)
-- create an adjustment object to handle v scrollbar
constant vadj = create(GtkAdjustment)
-- create a main window
constant win = create(GtkWindow)
set(win,"default_size",1024,768)
set(win,"title","GTK Stock Buttons")
set(win,"position",GTK_WIN_POS_CENTER)
-- create a scrolled window (not really a window, just a scrolling container)
constant scroller = create(GtkScrolledWindow,hadj,vadj)
-- create a table to hold the buttons, with 10 rows and 10 columns, homogeneous
atom tbl = create(GtkTable,10,10,TRUE)
-- kill gtk main loop when main window gets closed
connect(win,"destroy",quit)
-- add scrolling container to main window
add(win,scroller)
-- fill the table full of buttons
tbl = build_table(floor(length(ids)/4)+1,4)
-- put the table into the scrolling container
set(scroller,"add_with_viewport",tbl)
-- show everything
show_all(win)
-- enter main GTK event handling loop
main()
---------------------------------------------------------------
-- copyright 2009 by Irv Mullins, code released under the LGPL
---------------------------------------------------------------