Hierarchical pop-up Combo Gadget

Windows specific forum
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Hierarchical pop-up Combo Gadget

Post by TomS »

zapman* wrote:I've updated my code
Less (no) work for me :lol:

Why did add the second parameter to your open/close-submenu-procedure?
You could add the submenu after you added all the 'toplevel' entries, but who does this?
At least make it optional ;)

Code: Select all

Procedure OpenSubMenu_CBM(iGadgetID,ItemIndex = -1)
	;- Added these 3 lines
	If ItemIndex = -1
		ItemIndex = CountGadgetItems(iGadgetID)-1
	EndIf 
	;.....
	vReturn = 0
  actualValue = SendMessage_(GadgetID(iGadgetID),#CB_GETITEMDATA,ItemIndex,0)
  If actualValue<>#CB_ERR
    actualValue|1
    If SendMessage_(GadgetID(iGadgetID),#CB_SETITEMDATA,ItemIndex,actualValue)<>#CB_ERR
      vReturn = 1
    EndIf
  EndIf
  ProcedureReturn vReturn
EndProcedure
zapman*
Enthusiast
Enthusiast
Posts: 115
Joined: Wed Jun 02, 2004 10:17 pm
Location: New Caledonia (South Pacific)
Contact:

Re: Hierarchical pop-up Combo Gadget

Post by zapman* »

Excellent!

Go one step beyond offering an "OpenSubMenu" similare to the one used with classical popup menu:

Code: Select all

Procedure OpenSubMenu_CBM(iGadgetID,ItemIndex=-1,Text$="_NoText_")
  ;
  If Text$<>"_NoText_"
    AddGadgetItem(iGadgetID, ItemIndex,Text$)
  EndIf
  ;
  If ItemIndex = -1
    ItemIndex = CountGadgetItems(iGadgetID)-1
  EndIf
  ;
  vReturn = 0
  actualValue = SendMessage_(GadgetID(iGadgetID),#CB_GETITEMDATA,ItemIndex,0)
  If actualValue<>#CB_ERR
    actualValue|1
    If SendMessage_(GadgetID(iGadgetID),#CB_SETITEMDATA,ItemIndex,actualValue)<>#CB_ERR
      vReturn = 1
    EndIf
  EndIf
  ProcedureReturn vReturn
EndProcedure
OpenSubMenu_CBM(GadgetID,-1,"Line")
  • Add the line "Line" in the list as a submenu title
OpenSubMenu_CBM(GadgetID)
  • Transform the last added line to a submenu title
OpenSubMenu_CBM(GadgetID,5)
  • Transform the line indexed "5" to a submenu title
OpenSubMenu_CBM(GadgetID,5,"Line")
  • Insert "Line" at position "5" in the list and transform it to a submenu title
Don't try - DO it !
Post Reply