RE: Treeview w/Edit-Labels
- Posted by Derek Parnell <Derek.Parnell at SYD.RABOBANK.COM> Jun 20, 2002
- 410 views
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C21837.C06F9040 charset=iso-8859-1 > even still, this problem is alot easier solved if done in API... > atleast I dont have to travel around the world to party with > my next door neighbor. Look, if you think Win32lib is overkill for your system then use something else and get over it. I have consistantly said that Win32lib is not the fastest way of executing Windows code. But it isn't trying to be. I hope that people find it easier than raw API to code with, that's all. > Windows creates the Edit control and I retrieve the handle to > this edit control > now I must process the edit control via subclassing. I dont > suppose you have a > one word command for this do ya Derek? Firstly, you don't *HAVE TO* subclass the edit control if you don't want to. That is your choice. Windows doesn't force you to. Secondly, yes I do have a one word command for this. I've just added this bit of code the library... --------------------- global function subClassControl(object pId, atom phWnd) integer lNewId integer lParent integer lControlType if phWnd = 0 then return 0 end if if sequence(pId) then lControlType = pId[1] lParent = pId[2] if getId(phWnd) != 0 or -- hWnd already has an ID phWnd = getHandle(lParent) or -- is its own parent lControlType < 1 or -- invalid control class lControlType > NumClasses then return 0 end if lNewId = NewControl(lControlType, lParent) else lNewId = pId end if setId( phWnd, lNewId ) -- Set up data for child control window_handle[lNewId] = phWnd window_handle_type[lNewId] = kht_Window window_func[lNewId] = w32Func( xSetWindowLong, { phWnd, GWL_WndProc, SubProcAddress } ) return lNewId end function ---------------- and with this one can write ... tvEditor = subClassControl( {EditText, myWindow}, tvhWnd) and then all the win32lib functionality comes into existance for this new control. Also, to make live a bit easier than having to make global the library's varaibles, you can replace the existing routine "getId" with... global function getId( object hWnd ) if sequence(hWnd) then return find( hWnd[2], tvitem_handle ) else return w32Func( xGetWindowLong, { hWnd, GWL_USERDATA } ) end if end function and now you can get a TV Item's ID if you know its handle. TVI = getId ( {hWndTVI} ) --------------- Now with these small mods to the library, here is your example reworked... -------------------------------------- -- tvedit.exw Version 1.0 -- Author: Euman 20/June/2002 -- This demonstrates how to edit the text of a treeview item. include win32lib.ew object VOID integer MainWin, HelpText, TV, TVPopup, MI_AddItem, MI_Rename, MI_AddChild, Edit_Id atom closefolder, openfolder sequence folders integer vEditSource vEditSource = -1 integer vNewCount vNewCount = 0 -------------------------------- function TVBeginEdit(integer id, atom hWnd, atom wParam, atom lParam) -------------------------------- atom hWnd_Edit hWnd_Edit = w32Func( xSendMessage, {getHandle(TV), TVM_GETEDITCONTROL, 0, 0 } ) Edit_Id = subClassControl({EditText, MainWin}, hWnd_Edit) if vEditSource = 1 then setWindowBackColor(Edit_Id, BrightCyan) vNewCount += 1 setText(Edit_Id, sprintf("New Item Text %d", vNewCount)) elsif vEditSource = 0 then setWindowBackColor(Edit_Id, Yellow) elsif vEditSource = 2 then setWindowBackColor(Edit_Id, BrightGreen) elsif vEditSource = 3 then setWindowBackColor(Edit_Id, Parchment) vNewCount += 1 setText(Edit_Id, sprintf("New Child Text %d", vNewCount)) end if setFocus(Edit_Id) return {kReturnNow} end function -------------------------------- function TVEndEdit(integer id, atom hWnd, atom wParam, atom lParam) -------------------------------- object lNewText integer lRC integer lTVI lNewText = fetch(lParam, TVDISPINFO_TVITEMpszText) if sequence(lNewText) then lRC = True lTVI = getId( {TV, fetch( lParam, TVDISPINFO_TVITEMhItem )} ) setTVText(lTVI, lNewText) else lRC = False end if vEditSource = -1 return {kReturnNow, lRC} end function -------------------------------- procedure Mouse_TV(integer self, integer event, sequence parms) -------------------------------- integer index if parms[1] = WM_RBUTTONDOWN then popup(TVPopup, parms[2]-10, parms[3] ) end if end procedure -------------------------------- procedure Click_MI_AddItem(integer self, integer event, sequence parms ) -------------------------------- integer index integer lParent lParent = getTVParent( getIndex(TV) ) folders &= addTVItem( TV, closefolder, openfolder, "", lParent ) index = folders[length(folders)] vEditSource = 1 VOID = w32Func( xSendMessage, {getHandle(TV), TVM_EDITLABEL, 0, getHandle({TV,index}) } ) end procedure -------------------------------- procedure Click_MI_AddChild(integer self, integer event, sequence parms ) -------------------------------- integer index integer lParent lParent = getIndex(TV) folders &= addTVItem( TV, closefolder, openfolder, "", lParent ) index = folders[length(folders)] expandItem( lParent ) vEditSource = 3 VOID = w32Func( xSendMessage, {getHandle(TV), TVM_EDITLABEL, 0, getHandle({TV,index}) } ) end procedure -------------------------------- procedure Click_MI_Rename(integer self, integer event, sequence parms ) -------------------------------- integer index index = getIndex(TV) vEditSource = 2 VOID = w32Func( xSendMessage, {getHandle(TV), TVM_EDITLABEL, 0, getHandle({TV,index}) } ) end procedure -------------------------------- procedure KeyDown_TV(integer self, integer event, sequence parms ) -------------------------------- integer index if find(parms[1],{VK_RETURN,VK_F2}) = 0 or parms[2] != 0 then return end if index = getIndex(TV) vEditSource = 0 VOID = w32Func( xSendMessage, {getHandle(TV), TVM_EDITLABEL, 0, getHandle({TV,index}) } ) end procedure ------------------------------------------------ procedure Activate_MainWin(integer self, integer event, sequence parms) ------------------------------------------------ expandItem( folders[1] ) end procedure ------------------------------------------------ -- Application Initiation ------------------------------------------------ function AppInit() integer lRC lRC = 0 Edit_Id = -1 closefolder = addIcon( extractIcon( "clsdfold.ico" )) openfolder = addIcon( extractIcon( "openfold.ico" )) MainWin = create( Window, "Treeview Edit Label Demo", 0, 1, 1, 492, 380, { WS_DLGFRAME, WS_SYSMENU}) HelpText = create( LText, "", MainWin, 5, 5, 400, 50, 0) setText(HelpText, "You can edit an item by pressing RETURN or F2\n" & "Press the Right Mouse Button for extra options") TV = create(TreeView, "TreeView", MainWin, 10, 55, 464, 260, or_all({TVS_HASLINES,TVS_LINESATROOT,TVS_HASBUTTONS,TVS_EDITLABELS, TVS_SHOWSELALWAYS}) ) folders = {} folders &= addTVItem( TV, closefolder, openfolder, "Root Item" , 0 ) folders &= addTVItem( TV, closefolder, openfolder, "Item One" , folders[1] ) TVPopup = create( Popup, "", TV, 0, 0, 0, 0, 0 ) MI_AddItem = create( MenuItem, "New Item", TVPopup, 0, 0, 0, 0, 0 ) MI_AddChild = create( MenuItem, "New Child", TVPopup, 0, 0, 0, 0, 0 ) MI_Rename = create( MenuItem, "Rename", TVPopup, 0, 0, 0, 0, 0 ) setHandler(MainWin, w32HActivate, routine_id("Activate_MainWin")) setHandler(TV, w32HMouse, routine_id("Mouse_TV")) setHandler(MI_AddItem, w32HClick, routine_id("Click_MI_AddItem")) setHandler(MI_AddChild, w32HClick, routine_id("Click_MI_AddChild")) setHandler(MI_Rename, w32HClick, routine_id("Click_MI_Rename")) setHandler(TV, w32HKeyDown,routine_id("KeyDown_TV")) VOID = setNotifyHandler( TVN_BEGINLABELEDIT, routine_id("TVBeginEdit")) VOID = setNotifyHandler( TVN_ENDLABELEDIT, routine_id("TVEndEdit")) return lRC end function if AppInit() = 0 then WinMain( MainWin, Normal) end if -------------------- anyhow, have fun with this. cheers, Derek. ================================================================== De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht ontvangt wordt u verzocht de inhoud niet te gebruiken en de afzender direct te informeren door het bericht te retourneren. ================================================================== The information contained in this message may be confidential and is intended to be exclusively for the addressee. Should you receive this message unintentionally, please do not use the contents herein and notify the sender immediately by return e-mail. ================================================================== ------_=_NextPart_000_01C21837.C06F9040 Content-Type: application/ms-tnef