@davido: Thank you.  
 
@Shardik: Thank you, and also for pointing out the compatibility issues with Mac OSX. I must admit that it was only tested on Windows; like the listing says, 
quick & dirty.  
 
Nevertheless, it might be worth putting a note to the documentation team, highlighting this incompatibility with the 
SetGadgetText() function when used with the 
TreeGadget() on Mac OSX.
@Rashad: Good approach 
habibi, although scanning for the highlight colour would not work when custom colour preferences or themes are applied. Also, the string gadget gets displaced if the list is scrolled during editing, and it gets clipped if the tree gadget width is smaller than the tree.  
 
I've taken a page from that approach, and modified my example to retrieve the currently applied highlight colour using the Windows 
GetSysColor() API function. To maintain cross-compatibility, I've added a compiler directive to implement the original method on Mac OSX and Linux.
Code: Select all
;========================================================
; A quick & dirty method for editable TreeGadget() items
;      
; a cross-platform (?) solution by TI-994A - version 1.3
;
; 26th September 2014 - free to use, improve, share...
;========================================================
Enumeration 
  #mainWindow   
  #tree1
  #text1
EndEnumeration
;=============================================================
; fully self-contained and ready to use - no changes required.
; just drop into your project and call ediTree(win#, tree#)
;=============================================================
Procedure ediTree(parentWindowNo, treeGadgetNo)
  DisableWindow(parentWindowNo, #True)
  treeText.s = GetGadgetText(treeGadgetNo)
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      StartDrawing(WindowOutput(parentWindowNo))
        teStrWidth = TextWidth(GetGadgetItemText(treeGadgetNo, GetGadgetState(treeGadgetNo)))
        teStrHeight = TextHeight(GetGadgetItemText(treeGadgetNo, GetGadgetState(treeGadgetNo)))
        If teStrWidth < 100
          teStrWidth = 100
        EndIf
        xScanStart = WindowMouseX(parentWindowNo) - teStrWidth
        If xScanStart < 0
          xScanStart = 0
        EndIf
        yScanStart = WindowMouseY(parentWindowNo) - teStrHeight
        If yScanStart < 0
          yScanStart = 0
        EndIf
        For selectedX = xScanStart To (xScanStart + teStrWidth)
          For selectedY = yScanStart To (yScanStart + teStrHeight)
            If Point(selectedX, selectedY) = GetSysColor_(#COLOR_HIGHLIGHT)
              Break 2
            EndIf
          Next
        Next
        selectedX + WindowX(parentWindowNo, #PB_Window_InnerCoordinate)
        selectedY + WindowY(parentWindowNo, #PB_Window_InnerCoordinate)
      StopDrawing()  
    CompilerDefault
      teStrWidth = 100
      teStrHeight = 20
      selectedX = DesktopMouseX()
      selectedY = DesktopMouseY()
  CompilerEndSelect
  
  treeEditor = OpenWindow(#PB_Any, selectedX, selectedY, teStrWidth, teStrHeight, "", 
                          #PB_Window_BorderLess, WindowID(parentWindowNo))
  AddKeyboardShortcut(treeEditor, #PB_Shortcut_Return, 1)
  AddKeyboardShortcut(treeEditor, #PB_Shortcut_Escape, 2)
  teString = StringGadget(#PB_Any, 0, 0, teStrWidth, teStrHeight, treeText, #PB_String_BorderLess)
  SetGadgetColor(teString, #PB_Gadget_BackColor, RGB(255, 255, 0))
  SetGadgetColor(teString, #PB_Gadget_FrontColor, RGB(100, 0, 0))
  SetActiveGadget(teString)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Menu
        Select EventMenu()
          Case 1
            If Trim(GetGadgetText(teString)) <> ""
              SetGadgetItemText(treeGadgetNo, GetGadgetState(treeGadgetNo), Trim(GetGadgetText(teString)))
            EndIf
            escaped = 1
          Case 2
            escaped = 1
        EndSelect
    EndSelect  
  Until escaped
  
  DisableWindow(parentWindowNo, #False)
  CloseWindow(treeEditor)
  
EndProcedure
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(#mainWindow, 0, 0, 220, 250, "TreeGadget", wFlags)
  TextGadget(#text1, 10, 10, 200, 30, "Double-click the tree item to edit," + 
                                      #CRLF$ + "ENTER to set, ESC to cancel.")
  TreeGadget(#tree1, 10, 45, 200, 200, #PB_Tree_CheckBoxes)
  For populate = 0 To 9
    Read.s dataStr$
    AddGadgetItem (#tree1, -1, dataStr$)
    Read.s dataStr$
    AddGadgetItem (#tree1, -1, dataStr$, 0, 1)
    AddGadgetItem (#tree1, -1, "one more...", 0, 2)  
  Next
  
  Repeat    
    Select WaitWindowEvent() 
      Case #PB_Event_CloseWindow
        appQuit = 1
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #tree1
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
                ;*****************************************************
                ; simply call this as a function for any TreeGadget()
                ;*****************************************************
                ediTree(#mainWindow, #tree1)
                ;*****************************************************
            EndSelect        
        EndSelect
    EndSelect
  Until appQuit = 1 
EndIf
DataSection
  Data.s "Albert Einstein", "e = mc2", "Isaac Newton", "Apple on the head?", "Charles Darwin", "Theory of evolution."
  Data.s "Guglielmo Marconi", "This is the BBC.", "Benjamin Franklin", "Flying kites in the rain?", "Galileo Galilei"
  Data.s "Starlight, star bright...", "Leonardo da Vinci", "Mona Lisa.", "René Descartes", "I think, therefore I am?"
  Data.s "Thomas Edison", "1% perspiration, 99% rip-off!", "Alexander Graham Bell", "Hello? Can you hear me?"
EndDataSection