Request for wxGridBagSizer

BlitzMax Modules Forums/Brucey's Modules/Request for wxGridBagSizer

I need wxGridBagSizer and started to program it:
Type wxGridBagSizer Extends wxFlexGridSizer
	Function _create:wxGridBagSizer(wxSizerPtr:Byte Ptr)
		If wxSizerPtr Then
			Local this: wxGridBagSizer= New wxGridBagSizer
		
			this.wxSizerPtr = wxSizerPtr
		
			Return this
		End If
		
		Return Null
	End Function

	Function CreateGridBagSizer:wxGridBagSizer(vgap:Int=0, hgap:Int=0)
		Return New wxGridBagSizer.Create(vgap, hgap)
	End Function
	
	Method Create:wxBoxSizer(vgap:Int=0, hgap:Int=0)
		wxSizerPtr = bmx_wxgridbagsizer_create(Self, vgap, hgap)
		Return Self
	End Method
	
	Method Add:wxSizerItem(window:wxWindow, row:Int=0, col:Int=0, rowspan:Int=0, colspan:Int=0, flag:Int=0, border:Int=0)
		Return wxSizerItem._create(bmx_wxgridbagsizer_add(wxSizerPtr, window.wxObjectPtr, row, col, rowspan, colspan, flag, border))
	End Method

	Method AddSizer:wxSizerItem(sizer:wxSizer, row:Int=0, col:Int=0, rowspan:Int=0, colspan:Int=0, flag:Int=0, border:Int=0)
		Return wxSizerItem._create(bmx_wxgridbagsizer_addsizer(wxSizerPtr, sizer.wxSizerPtr, row, col, rowspan, colspan, flag, border))
	End Method

	Method AddWH:wxSizerItem(width:Int, height:Int, row:Int=0, col:Int=0, rowspan:Int=0, colspan:Int=0, flag:Int=0, border:Int=0)
		Return wxSizerItem._create(bmx_wxgridbagsizer_addwh(wxSizerPtr, width, height, row, col, rowspan, colspan, flag, border))
	End Method
	
	Method AddGBSizerItem:wxSizerItem(item:wxGBSizerItem, row:Int=0, col:Int=0, rowspan:Int=0, colspan:Int=0, flag:Int=0, border:Int=0)
		Return wxSizerItem._create(bmx_wxgridbagsizer_addgbsizeritem(wxSizerPtr, item.wxSizerItemPtr, row, col, rowspan, colspan, flag, border))
	End Method
	
	Method CheckForIntersection:Int(item:wxGBSizerItem, excludeItem:wxGBSizerItem=Null)
		If excludeItem Then
			Return bmx_wxgridbagsizer_checkforintersection(wxSizerPtr, item.wxSizerItemPtr, excludeItem.wxSizerItemPtr)
		Else
			Return bmx_wxgridbagsizer_checkforintersection(wxSizerPtr, item.wxSizerItemPtr, Null)
		EndIf
	End Method
	
	Method CheckForIntersection2:Int(row:Int, col:Int, rowspan:Int, colspan:Int, excludeItem:wxGBSizerItem=Null)
		If excludeItem Then
			Return bmx_wxgridbagsizer_checkforintersection2(wxSizerPtr, row, col, rowspan, colspan, excludeItem.wxSizerItemPtr)
		Else
			Return bmx_wxgridbagsizer_checkforintersection2(wxSizerPtr, row, col, rowspan, colspan, Null)
		EndIf
	End Method
	
	'Method FindItemWindow:wxGBSizerItem(window:wxWindow)
	'End Method

	'Method FindItemSizer:wxGBSizerItem(sizer:wxSizer)
	'End Method
	
	'Method FindItemAtPoint:wxGBSizerItem(x:Int, y:Int)
	'End Method

	'Method FindItemAtPosition:wxGBSizerItem(row:Int, col:Int)
	'End Method
	
	Method GetCellSize(row:Int, col:Int, width:Int Var, height:Int Var)
		bmx_wxgridbagsizer_getcellsize(wxSizerPtr, col, row, Varptr width, Varptr height)
	End Method
	
	Method GetEmptyCellSize(width:Int Var, height:Int Var)
		bmx_wxgridbagsizer_getemptycellsize(wxSizerPtr, Varptr width, Varptr height)
	End Method
	
	Method GetItemPositionWindow(window:wxWindow, row:Int Var, col:Int Var)
		bmx_wxgridbagsizer_getitempositionwindow(wxSizerPtr, window.wxObjectPtr, Varptr row, Varptr col)
	End Method
	
	Method GetItemPositionSizer(sizer:wxSizer, row:Int Var, col:Int Var)
		bmx_wxgridbagsizer_getitempositionsizer(wxSizerPtr, sizer.wxSizerPtr, Varptr row, Varptr col)
	End Method

	Method GetItemPositionWH(width:Int, height:Int, row:Int Var, col:Int Var)
		bmx_wxgridbagsizer_getitempositionwh(wxSizerPtr, width, height, Varptr row, Varptr col)
	End Method
	
	Method GetItemSpanWindow(window:wxWindow, rowspan:Int Var, colspan:Int Var)
		bmx_wxgridbagsizer_getitemspanwindow(wxSizerPtr, window.wxObjectPtr, Varptr rowspan, Varptr colspan)
	End Method
	
	Method GetItemSpanSizer(sizer:wxSizer, rowspan:Int Var, colspan:Int Var)
		bmx_wxgridbagsizer_getitemspansizer(wxSizerPtr, sizer.wxSizerPtr, Varptr rowspan, Varptr colspan)
	End Method

	Method GetItemSpanWH(width:Int, height:Int, rowspan:Int Var, colspan:Int Var)
		bmx_wxgridbagsizer_getitemspanwh(wxSizerPtr, width, height, Varptr rowspan, Varptr colspan)
	End Method
	
	Method RecalcSizes()
	End Method
	
	Method SetEmptyCellSize(width:Int, height:Int)
		bmx_gridbagsizer_setemptycellsize(wxSizerPtr, width, height)
	End Method
	
	Method SetItemPositionWindow:Int(window:wxWindow, row:Int, col:Int)
		Return bmx_wxgridbagsizer_setitempositionwindow(wxSizerPtr, window.wxObjectPtr, row, col)
	End Method
	
	Method SetItemPositionSizer:Int(sizer:wxSizer, row:Int, col:Int)
		Return bmx_wxgridbagsizer_setitempositionsizer(wxSizerPtr, sizer.wxSizerPtr, row, col)
	End Method

	Method SetItemPositionWH:Int(width:Int, height:Int, row:Int, col:Int)
		Return bmx_wxgridbagsizer_setitempositionwh(wxSizerPtr, width, height, row, col)
	End Method

	Method SetItemSpanWindow:Int(window:wxWindow, rowspan:Int, colspan:Int)
		Return bmx_wxgridbagsizer_setitemspanwindow(wxSizerPtr, window.wxObjectPtr, rowspan, colspan)
	End Method
	
	Method SetItemSpanSizer:Int(sizer:wxSizer, rowspan:Int, colspan:Int)
		Return bmx_wxgridbagsizer_setitemspansizer(wxSizerPtr, sizer.wxSizerPtr, rowspan, colspan)
	End Method

	Method SetItemSpanWH:Int(width:Int, height:Int, rowspan:Int, colspan:Int)
		Return bmx_wxgridbagsizer_setitemspanwh(wxSizerPtr, width, height, rowspan, colspan)
	End Method
End Type

Type wxGBSizerItem Extends wxSizerItem

	Function _create:wxGBSizerItem(wxGBSizerItemPtr:Byte Ptr)
		Local this:wxGBSizerItem = New wxGBSizerItem
		
		this.wxSizerItemPtr = wxGBSizerItemPtr
		
		Return this
	End Function

End Type


	Function bmx_wxgridbagsizer_create:Byte Ptr(handle:Object, vgap:Int, hgap:Int)
	Function bmx_wxgridbagsizer_add:Byte Ptr(handle:Byte Ptr, window:Byte Ptr, row:Int, col:Int, rowspan:Int, colspan:Int, flag:Int, border:Int)
	Function bmx_wxgridbagsizer_addsizer:Byte Ptr(handle:Byte Ptr, sizer:Byte Ptr, row:Int, col:Int, rowspan:Int, colspan:Int, flag:Int, border:Int)
	Function bmx_wxgridbagsizer_addwh:Byte Ptr(handle:Byte Ptr, width:Int, height:Int, row:Int, col:Int, rowspan:Int, colspan:Int, flag:Int, border:Int)
	Function bmx_wxgridbagsizer_checkforintersection:Int(handle:Byte Ptr, item:Byte Ptr, excludeItem:Byte Ptr)
	Function bmx_wxgridbagsizer_checkforintersection2:Int(handle:Byte Ptr, row:Int, col:Int, rowspan:Int, colspan:Int, excludeItem:Byte Ptr)
	Function bmx_wxgridbagsizer_getcellsize(handle:Byte Ptr, row:Int, col:Int, width:Int Ptr, height:Int Ptr)
	Function bmx_wxgridbagsizer_getemptycellsize(handle:Byte Ptr, width:Int Ptr, height:Int Ptr)
	Function bmx_wxgridbagsizer_getitempositionwindow(handle:Byte Ptr, window:Byte Ptr, row:Int Ptr, col:Int Ptr)
	Function bmx_wxgridbagsizer_getitempositionsizer(handle:Byte Ptr, sizer:Byte Ptr, row:Int Ptr, col:Int Ptr)
	Function bmx_wxgridbagsizer_getitempositionwh(handle:Byte Ptr, width:Int, height:Int, row:Int Ptr, col:Int Ptr)
	Function bmx_wxgridbagsizer_getitemspanwindow(handle:Byte Ptr, window:Byte Ptr, rowspan:Int Ptr, colspan:Int Ptr)
	Function bmx_wxgridbagsizer_getitemspansizer(handle:Byte Ptr, sizer:Byte Ptr, rowspan:Int Ptr, colspan:Int Ptr)
	Function bmx_wxgridbagsizer_getitemspanwh(handle:Byte Ptr, width:Int, height:Int, rowspan:Int Ptr, colspan:Int Ptr)
	Function bmx_gridbagsizer_setemptycellsize(handle:Byte Ptr, width:Int, height:Int)
	Function bmx_wxgridbagsizer_setitempositionwindow:Int(handle:Byte Ptr, window:Byte Ptr, row:Int, col:Int)
	Function bmx_wxgridbagsizer_setitempositionsizer:Int(handle:Byte Ptr, sizer:Byte Ptr, row:Int, col:Int)
	Function bmx_wxgridbagsizer_setitempositionwh:Int(handle:Byte Ptr, width:Int, height:Int, row:Int, col:Int)
	Function bmx_wxgridbagsizer_setitemspanwindow:Int(handle:Byte Ptr, window:Byte Ptr, rowspan:Int, colspan:Int)
	Function bmx_wxgridbagsizer_setitemspansizer:Int(handle:Byte Ptr, sizer:Byte Ptr, rowspan:Int, colspan:Int)
	Function bmx_wxgridbagsizer_setitemspanwh:Int(handle:Byte Ptr, width:Int, height:Int, rowspan:Int, colspan:Int)


But I've get some barriers to implement the c++ code. So I hope for implementation for the next update :)

cu olli

Someone's been busy ;-)

Yep. I'll see about finishing it off later. Thanks.

sweetie, thank you! :)

Yeah, thanks for the new module!

Please take a look on bmx_wxgridbagsizer_create in glue.cpp and change it to:
wxGridBagSizer * bmx_wxgridbagsizer_create(BBObject * maxHandle, int vgap, int hgap) {
	return new MaxGridBagSizer(maxHandle, vgap, hgap);
}

(in original there wars an empty line)

Can you change the default values of rowspan and colspan from 0 to 1 for the methods AddGB, AddGBSizer, AddGBSpacer?

Is there a need for to use the method name CreateGB as Create?

Can you put wxGridBagSizer into wx.wxWindow(becouse wxFlexGridSizer, wxBoxSizer and so on lies in this module)?

So I have a little example to work with this sizer:
SuperStrict

Framework wx.wxApp
Import wx.wxFrame
Import wx.wxPanel
Import wx.wxGridBagSizer
Import wx.wxTextCtrl
Import wx.wxButton

Global myApplication : TMyApplication

myApplication = New TMyApplication
myApplication.Run()
End

Type TMyApplication Extends wxApp
	Field myFrame : TMyFrame

	Method OnInit:Int()
		myFrame = New TMyFrame
		myFrame.Create()
		myFrame.Show()
		
		Return True
	End Method
End Type

Type TMyFrame Extends wxFrame
	Field panel       : wxPanel
	Field grid        : wxGridBagSizer
	Field display     : wxTextCtrl
	Field buttonMC    : wxButton
	Field buttonMP    : wxButton
	Field buttonMM    : wxButton
	Field buttonMR    : wxButton
	Field buttonC     : wxButton
	Field buttonAC    : wxButton
	Field buttonDiv   : wxButton
	Field buttonMul   : wxButton
	Field button7     : wxButton
	Field button8     : wxButton
	Field button9     : wxButton
	Field buttonPlus  : wxButton
	Field button4     : wxButton
	Field button5     : wxButton
	Field button6     : wxButton
	Field buttonMinus : wxButton
	Field button1     : wxButton
	Field button2     : wxButton
	Field button3     : wxButton
	Field buttonEqual : wxButton
	Field button0     : wxButton
	Field buttonPoint : wxButton
	
	Method OnInit()
		Local sizer : wxBoxSizer
		sizer = New wxBoxSizer.Create(wxVERTICAL)
		
		panel = New wxPanel.Create(Self)
		
		Local sizer2 : wxBoxSizer
		sizer2 = New wxBoxSizer.Create(wxVERTICAL)
		
		grid = New wxGridBagSizer.CreateGB(5, 5)
		grid.SetFlexibleDirection(wxBOTH)
		grid.SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED)
		grid.AddGrowableRow(0)
		grid.AddGrowableRow(1)
		grid.AddGrowableRow(2)
		grid.AddGrowableRow(3)
		grid.AddGrowableRow(4)
		grid.AddGrowableRow(5)
		grid.AddGrowableRow(6)
		grid.AddGrowableCol(0)
		grid.AddGrowableCol(1)
		grid.AddGrowableCol(2)
		grid.AddGrowableCol(3)
		
		display     = New wxTextCtrl.Create(panel, wxID_ANY, "0123456789")
		buttonMC    = New wxButton.Create(panel, wxID_ANY, "MC")
		buttonMP    = New wxButton.Create(panel, wxID_ANY, "M+")
		buttonMM    = New wxButton.Create(panel, wxID_ANY, "M-")
		buttonMR    = New wxButton.Create(panel, wxID_ANY, "MR")
		buttonC     = New wxButton.Create(panel, wxID_ANY, "C")
		buttonAC    = New wxButton.Create(panel, wxID_ANY, "AC")
		buttonDiv   = New wxButton.Create(panel, wxID_ANY, "÷")
		buttonMul   = New wxButton.Create(panel, wxID_ANY, "x")
		button7     = New wxButton.Create(panel, wxID_ANY, "7")
		button8     = New wxButton.Create(panel, wxID_ANY, "8")
		button9     = New wxButton.Create(panel, wxID_ANY, "9")
		buttonPlus  = New wxButton.Create(panel, wxID_ANY, "+")
		button4     = New wxButton.Create(panel, wxID_ANY, "4")
		button5     = New wxButton.Create(panel, wxID_ANY, "5")
		button6     = New wxButton.Create(panel, wxID_ANY, "6")
		buttonMinus = New wxButton.Create(panel, wxID_ANY, "-")
		button1     = New wxButton.Create(panel, wxID_ANY, "1")
		button2     = New wxButton.Create(panel, wxID_ANY, "2")
		button3     = New wxButton.Create(panel, wxID_ANY, "3")
		buttonEqual = New wxButton.Create(panel, wxID_ANY, "=")
		button0     = New wxButton.Create(panel, wxID_ANY, "0")
		buttonPoint = New wxButton.Create(panel, wxID_ANY, ".")
		
		grid.AddGB(display,     0, 0, 1, 4, wxEXPAND) ' display spanning over 4 columns
		grid.AddGB(buttonMC,    1, 0, 1, 1, wxEXPAND)
		grid.AddGB(buttonMP,    1, 1, 1, 1, wxEXPAND)
		grid.AddGB(buttonMM,    1, 2, 1, 1, wxEXPAND)
		grid.AddGB(buttonMR,    1, 3, 1, 1, wxEXPAND)
		grid.AddGB(buttonC,     2, 0, 1, 1, wxEXPAND)
		grid.AddGB(buttonAC,    2, 1, 1, 1, wxEXPAND)
		grid.AddGB(buttonDiv,   2, 2, 1, 1, wxEXPAND)
		grid.AddGB(buttonMul,   2, 3, 1, 1, wxEXPAND)
		grid.AddGB(button7,     3, 0, 1, 1, wxEXPAND)
		grid.AddGB(button8,     3, 1, 1, 1, wxEXPAND)
		grid.AddGB(button9,     3, 2, 1, 1, wxEXPAND)
		grid.AddGB(buttonPlus,  3, 3, 1, 1, wxEXPAND)
		grid.AddGB(button4,     4, 0, 1, 1, wxEXPAND)
		grid.AddGB(button5,     4, 1, 1, 1, wxEXPAND)
		grid.AddGB(button6,     4, 2, 1, 1, wxEXPAND)
		grid.AddGB(buttonMinus, 4, 3, 1, 1, wxEXPAND)
		grid.AddGB(button1,     5, 0, 1, 1, wxEXPAND)
		grid.AddGB(button2,     5, 1, 1, 1, wxEXPAND)
		grid.AddGB(button3,     5, 2, 1, 1, wxEXPAND)
		grid.AddGB(buttonEqual, 5, 3, 2, 1, wxEXPAND) ' equal spanning over 2 rows
		grid.AddGB(button0,     6, 0, 1, 2, wxEXPAND) ' zero spanning over 2 columns
		grid.AddGB(buttonPoint, 6, 2, 1, 1, wxEXPAND)
		
		sizer2.AddSizer(grid, 1, wxEXPAND, 5)
		
		panel.SetSizer(sizer2)
		panel.Layout()
		sizer2.Fit(panel)
		
		sizer.Add(panel, 1, wxALL|wxEXPAND, 0)
		
		SetSizer(sizer)
		Layout()
	End Method
End Type


It is a calculater layout similar to


cu olli

take a look on bmx_wxgridbagsizer_create

Oops. That's what happens when ya do it right before bedtime!

Is there a need for to use the method name CreateGB as Create?

Unfortunately yes, as the parent FlexGridSizer has a different set of parameters, and as you know you can't overload methods in BlitzMax :-(

The other option would be to add ghost params, which are only there to align the two methods properly - but I think that's really messy.

Can you put wxGridBagSizer into wx.wxWindow

I'm trying hard not to add anything more to wx.wxWindow if I can help it. If BlitzMax could handle cyclic imports, there'd only be wxWindow in there :-)
Perhaps I should move those other sizers into their own mods...

Now having a look at implementing it in wxCodeGen....

... wxCodeGen now building code for wxGridSizer :-)

Nice :)