Howto make a physical copy of a wxToolBar

BlitzMax Forums/Brucey's Modules/Howto make a physical copy of a wxToolBar

MOBii(Posted 2016) [#1]
I try set a copy of the Toolbar, but TToolbar_tmp is only a pointer to TToolbar

The Objects:
Global TToolbar:wxToolBar
Global TToolbar_tmp:wxToolBar
I try store a copy of the toolbar:
TToolbar_tmp = TToolbar
When I try restore the toolbar:
TToolbar.ClearTools()
TToolbar = TToolbar_tmp		' TToolbar = TToolbar = empty
TToolbar.Realize()
When I TToolbar.ClearTools() the TToolbar_tmp is empty too!

Is there a way to make a physical copy of TToolbar to TToolbar_tmp?


MOBii(Posted 2016) [#2]
I realize that I can't have a pure toolbar copy (with same id)
I only want a copy of the children if that's possible?

to do that I need to create a toolbar that is parentless, and somehow copy the children as I did for the menu:
	Repeat
		If MBar.GetMenuCount() > 0 Then MBar.Remove(0)
	Until Not MBar.GetMenuCount()
	MBar = MFrame.GetMenuBar()
	For Local m:wxMenu = EachIn MMenu
		MBar.append(m, m.GetTitle())
	Next
The best would be that I load the original toolbar as a Original copy

The menu was easier because it's 1 object type: wxMenu


The only option in my mind now is that I reload the toolbar from the scriptfile every time I want to restore the toolbar!


MOBii(Posted 2016) [#3]
I could Not make a toolbar copy so,
I cheat as usual: I load the scriptfile to a String and keep sting in memory, So I don't need to load from file every time I restore the toolbar from the scriptfile..

For educational use, I still like know if I can copy the children from the toolbar from a copy toolbar?


Henri(Posted 2016) [#4]
Hi,

in order to make a copy of an object you would create a new object with 'New' operator and go through every field in the source object and assign it's value to newly created objects similar field. There isn't any easy way to do it(now that I say this somebody comes up with an easy way :-)).

As for getting the tools from a wxToolbar (if that is what you meant):

- Get tools count with 'GetToolsCount()' and iterate every tool (for local i:Int = 0 Until toolsCount) and use probably 'GetToolByPos(i)' to retrieve the actual tool reference.

Not tested, but sounds good!

-Henri