Re: How to add to Edit Text default context menu

new topic     » goto parent     » topic index » view thread      » older message » newer message
penpal0andrew said...

Wow that is a great program. I like your library better than win32lib. I should try to port my program. But before that, one would need to completely replace all of the functionality of the context menu. I found this website - http://www.c-sharpcorner.com/UploadFile/deepak.sharma00/how-to-customize-default-contextmenu-of-a-textbox-control-in/ Specifically, menu items need to be disabled if they are not currently appropriate. Thanks. If I port my program and run into problems, we will probably be in touch again. Also, isn't it funny that the 3 of us share the same name - me (Andrew / Andy), you (Andreas), and Andrea whose project you based yours on.

Hi

I think win32lib has much more to offer for bigger projects.
What do you mean with 'completly replace the functionality of the context menu'? That's a real big task.
I added some of the functionality (based on the picture in your link) to the program (only using functions allready in tinewg). 'Paste' is still not handled
and there is no 'getColorDialog' like in win32lib.

But maybe it helps you to go on.

Andreas

include tinewg.exw 
include std/dll.e 
atom txtcol=CL_BLACK 
atom backcol=CL_WHITE 
sequence colors={CL_BLACK,CL_WHITE,CL_YELLOW,CL_BLUE,CL_RED} 
sequence colorstring={"Black","White","Yellow","Blue","Red"} 
 
-- create your own popup  
 
atom poptxt=CreatePopupMenu() 
AppendTextItem(poptxt,201,colorstring) 
 
atom popback=CreatePopupMenu() 
AppendTextItem(popback,301,colorstring) 
 
atom popup=CreatePopupMenu() 
AppendTextItem(popup,100,"Undo") 
AppendSeparator(popup) 
AppendTextItem(popup,101,"Copy") 
AppendTextItem(popup,102,"Paste") 
AppendTextItem(popup,103,"Cut") 
AppendTextItem(popup,104,"Delete") 
AppendTextItem(popup,105,"Select All") 
AppendSeparator(popup) 
AppendTextItem(popup,106,"Font") 
AppendPopup(popup,poptxt,"TextColor") 
AppendPopup(popup,popback,"BackColor") 
AppendSeparator(popup) 
AppendTextItem(popup,109,"CloseApp") 
 
 
Window("test") 
SetClientRect(WinHwnd,400,200) 
constant edit=Control(MultiEdit,"",50,0,350,200) 
SetColor(edit,txtcol,backcol) 
Activate(edit) 
-- SubClass the EditControl and handle the WM_RBUTTONDOWN yourself  
 
function EditWndProc(atom hwnd,atom msg,atom wParam,atom lParam) 
sequence rect,selec,newselec 
atom lengthselec 
    if equal(msg,WM_CONTEXTMENU) then 
		rect=GetWindowRect(edit) 
		if SendMessage(edit,EM_CANUNDO,0,0) then 
			EnableItem(popup,100,True) 
		else 
			EnableItem(popup,100,False) 
		end if 
		selec=GetSelection(edit) 
		lengthselec=selec[2]-selec[1] 
		if lengthselec then 
			EnableItem(popup,{101,103,104},True) 
		else 
			EnableItem(popup,{101,103,104},False) 
		end if 
		SetSelection(edit,-1,-1) 
		newselec=GetSelection(edit) 
		if newselec[2]>0 then 
			EnableItem(popup,105,True) 
		else 
			EnableItem(popup,105,False) 
		end if 
		SetSelection(edit,selec[1],selec[2]) 
		TrackPopupMenu(popup,LoWord(lParam),HiWord(lParam),WinHwnd) 
	return 0 -- WM_RBUTTONDOWN never reaches the original EditWindowProc  
		   -- so the default menu never appears 
    end if 
    return  CallWindowProc(OldWndProc,hwnd,msg,wParam,lParam) 
end function 
 
constant OldWndProc=GetWindowLong(edit,GWL_WNDPROC) 
SetWindowLong(edit,GWL_WNDPROC,call_back(routine_id("EditWndProc"))) 
 
-- Your handler for your menu 
 
procedure menuhandler() 
sequence f 
atom textfont 
	switch EventItem do 
		case 100 then 
			SendMessage(edit,EM_UNDO,0,0) 
		case 101 then  
			SendMessage(edit,WM_COPY,0,0) 
		case 102 then 
			SendMessage(edit,WM_PASTE,0,0) 
		case 103 then 
			SendMessage(edit,WM_CUT,0,0) 
		case 104 then 
			SendMessage(edit,WM_CLEAR,0,0) 
		case 105 then 
			SendMessage(edit,EM_SETSEL,0,-1) 
		case 106 then 
			f=ChooseFont() 
			if sequence(f[1]) then  
				textfont=NewFont(f[1],f[2],f[3],f[4],f[5]) 
				SetFont(edit,textfont)  
			end if 
		case 109 then 
			CloseApp() 
		case 201,202,203,204,205 then 
			EnableItem(popback,{301,302,303,304,305},True) 
			txtcol=colors[EventItem-200] 
			EnableItem(popback,EventItem-200+300,False) 
			SetColor(edit,txtcol,backcol) 
		case 301,302,303,304,305 then 
			EnableItem(poptxt,{201,202,203,204,205},True) 
			backcol=colors[EventItem-300] 
			EnableItem(poptxt,EventItem-300+200,False) 
			SetColor(edit,txtcol,backcol) 
		-- and so on ... 
	end switch 
end procedure 
SetHandler(WinHwnd,Menu,routine_id("menuhandler")) 
 
WinMain() 
 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu