Context Menu

BlitzMax Forums/BlitzMax GUI Programming/Context Menu

How do I create a context menu for a textarea gadget? And how do I do a cut, copy, and paste call for the same textarea from the context menu?

I can highly recommend Assari's MaxGUI tutorials for any budding MaxGUI coders - this one in particular, should be of interest to you:

Tutorial 14: Menus and Popup Menus

You'll need to scroll down to about half way down the page to get to the Popup Menu stuff.

Here is a small example with copy and paste working.
Write something, select it, right click to get the popup menu, choose copy...
Paste will add it to the end of the text
Hope that gets you started.

'Source Code created on 25 Apr 2008 00:02:40 with Logic Gui Version 3.1 Build 333
'LogicZone
'Start of external Header File
SuperStrict

Global Text:String

'End Of external Header File

Global	TextArea1:TGadget

Local Window2:TGadget = CreateWindow:TGadget("Window2",281,118,262,149,Null,WINDOW_TITLEBAR|WINDOW_RESIZABLE |WINDOW_STATUS |WINDOW_CLIENTCOORDS )
	TextArea1:TGadget = CreateTextArea:TGadget(0,0,262,149,Window2:TGadget,Null)
		SetGadgetLayout( TextArea1:TGadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED )
		SetTextAreaText( TextArea1:TGadget , "TextArea1" )
		Local TextArea1_PopUpMenu:TGadget = CreateMenu( "" , 0 , Null ) 
			Local TextArea1_PopUpMenu_Cut:TGadget = CreateMenu( "Cut" , 100 , TextArea1_PopUpMenu:TGadget  )
			Local TextArea1_PopUpMenu_Copy:TGadget = CreateMenu( "Copy" , 200 , TextArea1_PopUpMenu:TGadget  )
			Local TextArea1_PopUpMenu_Paste:TGadget = CreateMenu( "Paste" , 300 , TextArea1_PopUpMenu:TGadget  )

Repeat
	WaitEvent()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			Select EventSource()
				Case Window2	Window2_WC( Window2:TGadget )
			End Select

		Case EVENT_GADGETACTION
			Select EventSource()
				Case TextArea1	TextArea1_GA( TextArea1:TGadget )
			End Select

		Case EVENT_GADGETMENU
			Select EventSource()
				Case TextArea1	TextArea1_GM( TextArea1:TGadget , Window2:TGadget , TextArea1_PopUpMenu:TGadget )
			End Select

		Case EVENT_MENUACTION
			Select EventData()
				'Menu_Events for Gadget = TextArea1_PopUpMenu
				Case 100	TextArea1_PopUpMenu_Cut_MA( TextArea1_PopUpMenu:TGadget , TextArea1_PopUpMenu:TGadget , TextArea1_PopUpMenu_Cut:TGadget )
				Case 200	TextArea1_PopUpMenu_Copy_MA( TextArea1_PopUpMenu:TGadget , TextArea1_PopUpMenu:TGadget , TextArea1_PopUpMenu_Copy:TGadget )
				Case 300	TextArea1_PopUpMenu_Paste_MA( TextArea1_PopUpMenu:TGadget , TextArea1_PopUpMenu:TGadget , TextArea1_PopUpMenu_Paste:TGadget )
			End Select

	End Select
Forever

Function Window2_WC( Window:TGadget )
	DebugLog "Window Window2 wants to be closed"
'	HideGadget( Window:TGadget )

	End
End Function

Function TextArea1_GA( TextArea:TGadget )
	DebugLog "TextArea TextArea1 was modified"
	
End Function

Function TextArea1_GM( TextArea:TGadget , Window:TGadget=Null , PopUpMenu:TGadget=Null )
	DebugLog "TextArea TextArea1 was right clicked"
    PopupWindowMenu( Window:TGadget,PopUpMenu:TGadget )
	
End Function

Function TextArea1_PopUpMenu_Cut_MA( Window:TGadget , Parent:TGadget , Menu:TGadget )
	DebugLog "Menu Cut was selected from Window TextArea1_PopUpMenu"
	
End Function

Function TextArea1_PopUpMenu_Copy_MA( Window:TGadget , Parent:TGadget , Menu:TGadget )
	DebugLog "Menu Copy was selected from Window TextArea1_PopUpMenu"
	Local cursorpos:Int = TextAreaCursor(TextArea1:TGadget)
Local SelectedLength:Int = TextAreaSelLen(TextArea1:TGadget) 

Text:String = TextAreaText(TextArea1:TGadget,cursorpos,SelectedLength)
End Function

Function TextArea1_PopUpMenu_Paste_MA( Window:TGadget , Parent:TGadget , Menu:TGadget )
	DebugLog "Menu Paste was selected from Window TextArea1_PopUpMenu"
	AddTextAreaText( TextArea1:TGadget,text$ )


End Function



I feel a little stupid that i did not look for a popup menu command enough to actually find that command. I looked for workarounds more than for a native command. Thank you very much for your help.