gtk grid/table close ish

BlitzMax Forums/BlitzMax GUI Programming/gtk grid/table close ish

I've been staring at this and its quite close I just cant get the scroll area to work correctly

I know I have gone wrong somewhere with a parenting issue but I cant see the wood for the trees

as gtkmaxgui works in windows now it cant be far off on the mac so I though this would make a good table view type component for viewing sql query results...

I have deliberately kept it separate from gtkmaxgui till everything is working and happy, then its up to Brucey if he wants to add none maxgui components to gtkmaxgui.

superstrict 
framework bah.gtkmaxgui
import brl.eventQueue

extern
'GtkWidget* gtk_table_new (gint rows, gint columns, gint homogeneous)
	function gtk_table_new:byte ptr(rows:int,columns:int,homo:int)
'void gtk_table_attach (GtkTable *table, GtkWidget *child, gint left_attach, gint right_attach, gint top_attach, gint bottom_attach, gint xoptions, gint yoptions, gint xpadding, gint ypadding)
	function gtk_table_attach(table:byte ptr,child:byte ptr,la:int,ra:int,ta:int,ba:int,xo:int,yo:int,xpad:int,ypad:int)
	function gtk_scrolled_window_add_with_viewport(c:byte ptr,p:byte ptr)
end extern

type gtkTable extends TgtkGadget
	Field scrollWindow:Byte Ptr
	Function createTable:gtkTable(x:Int, y:Int, w:Int, h:Int,r:int,c:int, group:TGadget)

		Local gadget:gtkTable=new gtkTable
		gadget.handle=gtk_table_new(r,c,false)
		gtk_widget_set_size_request(gadget.handle, 100*10, 24*10)


		gadget.scrollWindow = gtk_scrolled_window_new(null,null)

		gtk_container_set_resize_mode(gadget.scrollWindow, GTK_RESIZE_QUEUE)

'		gtk_scrolled_window_set_policy(gadget.scrollWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC)


'		gtk_container_add(gadget.scrollWindow, gadget.handle)
		gtk_scrolled_window_add_with_viewport(	gadget.scrollWindow, gadget.handle)
		gtk_layout_put(TGTKContainer(group).container, gadget.scrollwindow, x, y)
		gtk_widget_set_size_request(gadget.scrollwindow, w, Max(h,0))

		gtk_widget_show(gadget.scrollWindow)

		gtk_widget_show(gadget.handle)
		' map the new gadget - so we can find it later if required
		If gadget Then
			GadgetMap.Insert(TGTKInteger.Set(Int Ptr(gadget.handle)[0]),gadget)
		End If
		
		If group Then
			gadget._SetParent group
		End If
		gadget.SetShape x,y,w,h

		Return gadget
	End Function
endtype

' have to nick this code cause i need a parentless gadget
function initTextField(g:TGTKTextField,x:Int, y:Int, w:Int, h:Int, label:String, _style:Int)

		g.handle = gtk_entry_new()
'		init(GTK_TEXTFIELD, x, y, w, h, style)
		g.SetRect(x,y,w,h)
		g.class = GTK_TEXTFIELD
		g.kids = New TList
		g.style = _style

		If g.style Then
			g.isPassword = True
			gtk_entry_set_visibility(g.handle, False)
		End If

		' causes the default gadget to be activated when Enter is pressed inside this Text Field.
		g_object_set_int(g.handle, "activates-default", True)
		g.setShow(True)

'		gtk_layout_put(TGTKContainer(group).container, g.handle, x, y)
		gtk_widget_set_size_request(g.handle, w, Max(h,0))

		' add callbacks
		g_signal_cb2(g.handle, "changed", g.OnTextChanged, g, g.Destroy, 0)
		g_signal_cb3(g.handle, "key-press-event", g.OnKeyDown, g, g.Destroy, 0)
		g_signal_cb3(g.handle, "focus-out-event", g.OnFocusLost, g, g.Destroy, 0)
		' catch right-mouse buttons
		g_signal_cb3(g.handle, "button-press-event", g.OnMouseDown, g, g.Destroy, 0)

Endfunction
	

local win:TGadget=createwindow("table test",64,64,264,264,null,WINDOW_RESIZABLE|WINDOW_TITLEBAR|WINDOW_STATUS|WINDOW_CLIENTCOORDS)
local tab:gtkTable=gtkTable.createTable(32,32,200,200,20,20,win)
global txt:TGTKTextField[10,10]
const GTK_EXPAND:int=1
const GTK_FILL:int=4
for local y:int=0 until 10
	for local x:int=0 until 10
		txt[x,y]=new TGTKTextField'createtextfield(0,0,100,24,null)
		initTextField(txt[x,y],0,0,100, 24, "", 0)
		txt[x,y].settext(" "+x+" "+y)
		gtk_table_attach(tab.handle,TgtkGadget(txt[x,y]).handle,x,x+1,y,y+1,GTK_EXPAND | GTK_FILL,GTK_EXPAND | GTK_FILL,0,0)
	next
next


While True
	WaitEvent() 
'	Print CurrentEvent.ToString()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			print "window closed"
			End
	End Select
Wend