wxMax context menu - getting started

BlitzMax Modules Forums/Brucey's Modules/wxMax context menu - getting started

Hi,

I want to create a wxGenericDirCtrl with a popmenu
if a file is right clicked.
In this thread, in the TestPopups.bmx,
the needed informations seem to be created by wxcodegen.
How do I setup the needed informations in formbuilder; or do I have
to do it myself like in samples/menu.bmx?
Hints appreciated.

Ideally the right-button down needs to be attached to the embedded treectrl.
Unfortunately, the default treectrl won't be available to the BlitzMax event system. I'll need to apply some changes which should fix that.

After that, you will be able to use GetTreeCtrl() to get a handle on the control, to which you connect the event you want.

Watch this space :-)

Watch this space :-)

I am not in hurry. *refresh* *refresh* *refresh* ...

Okay... it's looking better.

I've added a small "genericdirctrl" sample to show how to access the internal tree ctrl and adding your own event-processing to it.

Let me know if that's enough access to it.

:o)

Hi Brucey,

because I found no better solution I edited the codegen.bmx.
Is there a way around this?

I've tried to insert your code and see no really difference between mine
and your sample.
But your works, and mine not (no right mouseclick detected).

viewer.bmx

SuperStrict
Import wx.wxApp
Import wx.wxFrame
'Import wx.wxGenericDirCtrl

Import "viewercodegen.bmx"


New MyApp.Run()



Type MyApp Extends wxAppMain
	Field frame:frameBase
	Global shouldExit:Int = False
	'
	Method OnInit:Int()
		frame = Myworkframe(New Myworkframe.Create(,, "Viewer", 100, 100,,, wxDEFAULT_FRAME_STYLE | wxSTAY_ON_TOP))
		frame.Show()
	
		'# Connect exit event
		frame.Connect(, wxEVT_CLOSE, onQuit)
		Return True
	End Method
	
	Method MainLoop:Int()
		While True
			While Not Pending() And ProcessIdle() ; Wend
			While Pending()
				If Not Dispatch() Then
					shouldExit = True
					Exit
				End If
			Wend
			If shouldExit Then
				While pending() 
					dispatch() 
				Wend
				Return 0
			End If
		Wend
	End Method
	'
	Function OnQuit(event:wxEvent) 
		MyApp.shouldExit = True
	End Function

End Type
'
Type Myworkframe Extends FrameBase

	'
	Method Onrightclick(event:wxTreeEvent)
		
	End Method
	'
	Function _OnRightClick(event:wxEvent)
		Myworkframe(event.sink).OnRightClick(wxTreeEvent(event))
	End Function
	
	Method ExitSelected(event:wxCommandEvent)	 
		End
	End Method
End Type


Viewercodegen.bmx:
'
' BlitzMax code generated with wxCodeGen v1.03 : 16 Jan 2009 15:34:28
' 
' 
' PLEASE DO "NOT" EDIT THIS FILE!
' 
SuperStrict

Import wx.wxFrame
Import wx.wxGenericDirCtrl
Import wx.wxWindow


Type frameBase Extends wxFrame

	Field m_genericDirCtrl1:wxGenericDirCtrl


	Method Create:frameBase(parent:wxWindow = Null,id:Int = wxID_ANY, title:String = "", x:Int = -1, y:Int = -1, w:Int = 500, h:Int = 640, style:Int = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL)
		return frameBase(Super.Create(parent, id, title, x, y, w, h, style))
	End Method

	Method OnInit()

		Local gSizer1:wxGridSizer
		gSizer1 = new wxGridSizer.CreateRC(2, 2, 0, 0)
		
		m_genericDirCtrl1 = New wxGenericDirCtrl.Create(Self, wxID_ANY, CurrentDir(),, ,, , wxSUNKEN_BORDER, "", 0)
		m_genericDirCtrl1.ShowHidden(False)

		gSizer1.Add(m_genericDirCtrl1, 1, wxEXPAND | wxALL, 5)

		SetSizer(gSizer1)
		Layout()
		' changed code:
		Local tree:wxTreeCtrl = m_genericDirCtrl1.GetTreeCtrl()
		
		tree.Connect(tree.GetId(), wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, _OnRightClick, Null, Self)
		' end changed code
	End Method
	' added methods:
	Function _OnRightClick(event:wxEvent)
		frameBase(event.sink).OnRightClick(wxTreeEvent(event))
	End Function
	
	Method OnRightClick(event:wxTreeEvent)
		DebugLog "item : " + m_genericDirCtrl1.GetPath()
	End Method
	
End Type




In your Myworkframe type, you are overriding the Onrightclick method of Base, which means that is called, and not the one which outputs the text...

comment it out, and all should be well ;-)

because I found no better solution I edited the codegen.bmx.
Is there a way around this?


Yes, there should be. You can add the treectrl specific code in the OnInit() method of your subclassed type.
This bit :
		Local tree:wxTreeCtrl = m_genericDirCtrl1.GetTreeCtrl()
		
		tree.Connect(tree.GetId(), wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, _OnRightClick, Null, Self)

You should call Super.OnInit() first...
Method OnInit()
   Super.OnInit()

   Local tree:wxTreeCtrl = m_genericDirCtrl1.GetTreeCtrl()
	
   tree.Connect(tree.GetId(), wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, _OnRightClick, Null, Self)
End Method


Ah, super.OnInit(). Is there a smile for enlightment? *:-) perhaps?
Thanks a lot, finally got it working.