WxTreeCtrl Sorting

BlitzMax Forums/Brucey's Modules/WxTreeCtrl Sorting

Tommo(Posted 2009) [#1]
I use wxFormbuilder+wxCodeGen to generate code, it's a pleasure.
But there's a problem when I need a treeCtrl can do sorting, because you have to override a OnCompareItems method to implement it. Obviously, to modify the generated code is not a good way.

I added a callback function field to wxTreeCtrl class to solve this. It's handy to use, but a hack is still a hack, is there any "official" way?

Thanks. :)


Brucey(Posted 2009) [#2]
The best way to do this would be to subclass the wxTreeCtrl you are using, and implemented the sort callback in your subclass.


Tommo(Posted 2009) [#3]
I knew that I have to make a subclass to implement this.

Because WxCodeGen ignores the subclass fields from wxFormBuilder, so I always have to modify the generated source to replace wxTreeCtrl with new subclass once the form design changes.

It's not a problem, just a "laziness issue". :)


Brucey(Posted 2009) [#4]
Fair enough :-)

I already have some code which can use subclass/header field, but it is only implemented for a couple of the main "container" classes.

So, I think I've worked out a way for it to generate the following :

Having a wxTreeCtrl on a form, with the subclass property set to "MyTreeCtrl; mytree.bmx"

Will generate an : Import "mytree.bmx"
Will delcare the field as : Field m_treeCtrl1:wxTreeCtrl
Will instantiate with : m_treeCtrl1 = new MyTreeCtrl.Create(...

You would then need to implement the imported type, along the lines of :
SuperStrict

Import wx.wxTreeCtrl

Type MyTreeCtrl Extends wxTreeCtrl

End Type


Which all seems to compile, and removing the subclass info and re-generating also seems to work as it did before.
I should probably add this for all the widgets.

How's that sound?


Tommo(Posted 2009) [#5]
That sounds nice!
This can solve most of the custom control problems!

Here is what I'm playing with(a bunch of Bah.mod within)...


Thank you. :)


Brucey(Posted 2009) [#6]
Righty. I've committed the changes for wxCodeGen. You should (in theory) be able so subclass all of the main widgets now, in the way described above).

I've only tested it on a few random types, but it seems to be creating the code correctly.

See how you get on, and please let me know if I've broken anything in the mean time.


Nice looking editor :-)
What widget are you using for that context-menu tool ?


Tommo(Posted 2009) [#7]
They're just toolbar buttons... ;)

Checking out new codegen now. Thanks!


Tommo(Posted 2009) [#8]
It's working nicely so far.
And I can insert my own custom control with FormBuilder now. :)

Thanks again!


*EDIT:
I added some code to have it support mod import, like "mod:tommo.customwx".
It might be useful for some other case.

Method GetFullImport:String(name:String)
		If prop("subclass") Then
			Local s:String = prop("subclass").split(";")[1].Trim()
			If s Then
'start of added code---
				local m% = s.Find("mod:")
				
				if m >= 0 then
					return s[(m + 4)..s.length]
				End If
'end of added code--
....	



DavidDC(Posted 2009) [#9]
Looks great Tommo! Gives me hope, as my dialogs look pretty shabby.


Tommo(Posted 2009) [#10]
Thanks David!
I like the workflow with sizers, it's kind of like writing a webpage.
There are too many things you can do with wx. The more you play with it, the more you like it. :)