It is currently Thu Feb 25, 2021 4:59 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Treegadget editable (readable version & more functions)
PostPosted: Mon Nov 08, 2004 11:06 am 
Offline
Addict
Addict
User avatar

Joined: Mon May 26, 2003 3:07 pm
Posts: 1477
Location: Nantes
- I tried to make a PB event-like system for notify callback
- notify functions for treegadget

Code:
; ====================================
; some functions to make this code readable
; ====================================

;like eventGadgetID()
;     Procedure NEventGadgetID()
;       *hdr.NMHDR=EventlParam()
;       If *hdr
;         ProcedureReturn *hdr\idFrom
;         EndIf
;     EndProcedure

; -------------------------------

;like eventType()
;     Procedure NEventType()
;        *hdr.NMHDR=EventlParam()
;        ProcedureReturn *hdr\code
;     EndProcedure

; ====================================
; some TreeGadget-specific functions to make this code readable
; ====================================

#TREE_LABEL_EDITABLE=0
#TREE_LABEL_UNEDITABLE=1
#TREE_LABEL_SAVED=1
#TREE_LABEL_UNSAVED=0

; -------------------------------         

;make tree editable
Procedure TreeEditable(TreeID.l)             
  SetWindowLong_(GadgetID(TreeID),#GWL_STYLE,GetWindowLong_(GadgetID(TreeID),#GWL_STYLE) | #TVS_EDITLABELS)
EndProcedure

; -------------------------------

;set label text before modification
Procedure N_SetLabelText(txt.s)
  ctl=SendMessage_(GadgetID(GadgetID),#TVM_GETEDITCONTROL,0,0)
  SendMessage_(ctl,#WM_SETTEXT,0,@txt)
EndProcedure

; -------------------------------         

;get modified label
Procedure.s N_GetLabelText()
  *tvinfo.NMTVDISPINFO=EventlParam()
  *txt=*tvinfo\item\psztext
  If *txt=0
    newtxt.s=""
  Else
    newtxt.s=PeekS(*txt)
  EndIf
  ProcedureReturn newtxt
EndProcedure

; -------------------------------         

;save modified label
Procedure.s N_SaveLabelText(newtxt.s)
  *tvinfo.NMTVDISPINFO=EventlParam()
  *txt=*tvinfo\item\psztext
  CopyMemoryString(newtxt,@*txt)
EndProcedure

; -------------------------------

;if user cancels the label edition
Procedure N_LabelEditCanceled()
  *tvinfo.NMTVDISPINFO=EventlParam()
  *txt=*tvinfo\item\psztext
  If *txt=0
    ProcedureReturn #True
  EndIf
EndProcedure

; =======================
; code example
; =======================

Enumeration
  #WINDOW
  #TREE
EndEnumeration

; -------------------

Procedure WindowCallBack(Window,Message,wParam,lParam)
  ReturnValue = #PB_ProcessPureBasicEvents
 
  If Message=#WM_NOTIFY   
    ;          *hdr.NMHDR=EventlParam()
    ;           GadgetID=*hdr\idFrom
    If EventGadget()=#TREE
      If EventType()=#TVN_BEGINLABELEDIT
        ;start modification
        index=GetGadgetState(GadgetID)
        Select index
          Case 1
            ReturnValue=#TREE_LABEL_UNEDITABLE
          Case 3
            txt.s=GetGadgetText(GadgetID)
            txt=Left(txt,Len(txt)-Len(" : postfix text"))
            N_SetLabelText(txt)
            ReturnValue=#TREE_LABEL_EDITABLE
          Default
            ReturnValue=#TREE_LABEL_EDITABLE
        EndSelect
       
      ElseIf EventType()=#TVN_ENDLABELEDIT
        ;save modification
        If N_LabelEditCanceled()
          ReturnValue=#TREE_LABEL_UNSAVED               
        Else
          ReturnValue=#TREE_LABEL_SAVED     
          index=GetGadgetState(GadgetID)
          Select index
            Case 2
              If N_GetLabelText()=""
                N_SaveLabelText("You tried to save an empty string !")   
              EndIf
            Case 3
              N_SaveLabelText(N_GetLabelText()+" : postfix text")
          EndSelect
        EndIf
       
      EndIf
    EndIf
  EndIf
 
  ProcedureReturn ReturnValue
EndProcedure

; -------------------

If OpenWindow(#WINDOW ,300,300,200,150,"Tree Edit",#PB_Window_SystemMenu)
  TreeGadget(#TREE, 10,10,180,120)           
  TreeEditable(#TREE)
  AddGadgetItem (#TREE, 0, "Label ")
  AddGadgetItem (#TREE, 1, "Label (uneditable)")
  AddGadgetItem (#TREE, 2, "Label (can't save empty string)")
  AddGadgetItem (#TREE, 3, "Label : postfix text")
  SetWindowCallback(@WindowCallBack())
 
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf 

_________________
Imagewin8.1 x64 5.31 | IDE | PB plugin | Tools | Sprite | JSON | visual tool


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye