Combobox in Listicongadget

Just starting out? Need help? Post your questions and find answers here.
Barbarossa
User
User
Posts: 47
Joined: Fri Oct 12, 2012 8:50 am

Combobox in Listicongadget

Post by Barbarossa »

Hi All,

I want to have an editable listicongadget. One column in that listicongadget needs to contain a combobox dropdown gadget. I took the 2008 code from Srod and modified this a bit to suits my needs (see code snippet). This part works perfectly as far as direct editing is concerned.
Then I tried to implement comboboxes into this code. I used the 2005 code from Srod.
http://www.purebasic.fr/english/viewtop ... n+listicon
The problem is that this code is too old for the current PureBasic version as a couple of the commands don't work anymore. Also I don't have much (very little) experience in API programming so I really don't know what things to change and where.

Maybe someone could point me in the right direction?

John

Code: Select all

#HDI_ORDER                  = $80
#EC_RIGHTMARGIN             = 2

Structure _LIEdit
  listOldProc.i
  editHwnd.i
  item.i
  subitem.i
  x.i
  y.i
  cx.i
  cy.i
EndStructure

;Returns zero if an error.
Procedure.i SetListIconEditable(listID)
	Protected result, parenthWnd, *mem._LIEdit, hWnd, dlv.DLLVERSIONINFO, func, lib
	;Check that listID references a valid listicon.
	If IsGadget(listID) And GadgetType(listID)=#PB_GadgetType_ListIcon
		hWnd = GadgetID(listID)
		;Is the listicon already registered?
		If GetProp_(hWnd, "_LIEdit")=0 ;No!
			;Allocate enough memory for a _LIEdit structure.
			*mem=AllocateMemory(SizeOf(_LIEdit))
			If *mem
				SetWindowLong_(hWnd, #GWL_STYLE, GetWindowLong_(hWnd, #GWL_STYLE)&~#LVS_EDITLABELS)
				;Set the fields of the _LIEedit structure.
				*mem\listOldProc = SetWindowLong_(hWnd, #GWL_WNDPROC, @_LIEListProc())
				;Store a pointer to this structure in a window property ofthe listicon.          
				SetProp_(hWnd, "_LIEdit", *mem)
				;Subclass the parent window if not already through another listicon.
				parenthWnd=GetParent_(hWnd)
				If GetProp_(parenthWnd, "_LIEditOldProc")=0 ;No!
					SetProp_(parenthWnd, "_LIEditOldProc", SetWindowLong_(parenthWnd, #GWL_WNDPROC, @_LIEwinProc()))
				EndIf
				result=1
			EndIf
		EndIf
	EndIf
	ProcedureReturn result
EndProcedure

;Sets the specified cell to be edited.
Procedure EditCell(listID, item, subitem)
	Protected hWnd, *liedit._LIEdit, numrows, numcols
	;Check that listID references a valid listicon.
	If IsGadget(listID) And GadgetType(listID)=#PB_GadgetType_ListIcon
		;Check that the listicon is registered as editable.
		hWnd = GadgetID(listID)
		*liedit = GetProp_(hWnd, "_LIEdit")
		If *liedit
			;Check parameters are in range.
			numrows = CountGadgetItems(listID)
			numcols = SendMessage_(SendMessage_(hWnd,#LVM_GETHEADER,0,0), #HDM_GETITEMCOUNT,0,0)
			If item>=0 And item < numrows And subitem>0 And subitem < numcols
				*liedit\item = item
				*liedit\subitem = subitem
				SetActiveGadget(listID)
				_LIEEditCell(*liedit, hWnd)
			EndIf
		EndIf
	EndIf
EndProcedure

Procedure _LIEEditCell(*liedit._LIEdit, hWnd)
	Protected rc.RECT, clientrc.RECT, numCols, headerWnd
	Protected Dim cols.l(0), i, blnFoundZeroColumn
	Protected hdi.HDITEM
	;Scroll the listicon if the clicked cell is not entirely visible
	;*****IF YOU WISH TO RESTRICT WHICH CELLS CAN BE EDITED, THEN PERFORM THE NECESSARY CHECKS HERE
	;*****ON THE VALUES OF *liedit\item and *liedit\subitem (WHICH INDICATE WHICH CELL IS ABOUT
	;*****TO BE EDITED) AND RUN THE FOLLOWING LINES FOR THOSE CELLS WHICH ARE TO BE EDITED.
	rc\top = *liedit\subitem
	rc\left = #LVIR_BOUNDS
	SendMessage_(hWnd, #LVM_GETSUBITEMRECT, *liedit\item, rc)
	GetClientRect_(hWnd, clientrc)
	If rc\left < 0 Or (rc\right-rc\left)>=clientrc\right
		SendMessage_(hWnd, #LVM_SCROLL,rc\left,0) 
	Else
		If rc\right > clientrc\right
			SendMessage_(hWnd, #LVM_SCROLL,rc\right-clientrc\right,0) 
		EndIf
	EndIf
	SetWindowLong_(hWnd, #GWL_STYLE, GetWindowLong_(hWnd, #GWL_STYLE)|#LVS_EDITLABELS)
	SendMessage_(hWnd, #LVM_EDITLABEL, *liedit\item, 0)
EndProcedure

;New Procedure to implement ComboBox functionality
Procedure _LIEComboCell(*liedit._LIEdit, hWnd)
	; need some help with this part
EndProcedure

;Window proc of the ListIcon parent window.
Procedure.i _LIEwinProc(hWnd, uMsg, wParam, lParam)
	Protected result, oldwinproc, *nmh. NMHDR, listhWnd, edithWnd, *liedit._LIEdit, *lvd.LV_DISPINFO, rc.RECT
	Protected hdi.HDITEM, headerWnd
	Static celltext$
	;Retrieve the address of the old proc.
	oldwinproc = GetProp_(hWnd, "_LIEditOldProc")
	Select uMsg
		Case #WM_NOTIFY
			*nmh=lParam
			Select *nmh\code
				Case #LVN_BEGINLABELEDIT
					listhWnd = *nmh\hwndFrom
					;Retrieve the address of the LIEdit structure.
					*liedit = GetProp_(listhWnd, "_LIEdit")
					If *liedit ;Good to go!
						*liedit\editHwnd=0
						;Get the handle of the edit control used to edit the label.
						edithWnd = SendMessage_(listhWnd, #LVM_GETEDITCONTROL,0,0)
						;Subclass the edit control.
						SetProp_(edithWnd, "_LIEditOldProc", SetWindowLong_(edithWnd, #GWL_WNDPROC, @_LIEeditProc()))
						;Set text.
						celltext$=GetGadgetItemText(*nmh\idFrom, *liedit\item, *liedit\subitem)
						SendMessage_(edithWnd, #WM_SETTEXT, 0, celltext$)
						SetGadgetItemText(*nmh\idFrom, *liedit\item, "",*liedit\subitem)
						;Get bounding rectangle.
						rc\top = *liedit\subitem
						rc\left = #LVIR_BOUNDS 
						SendMessage_(listhWnd, #LVM_GETSUBITEMRECT, *liedit\item, rc) 
						*liedit\x=rc\left
						*liedit\y=rc\top
						*liedit\cx=SendMessage_(listhWnd, #LVM_GETCOLUMNWIDTH, *liedit\subitem,0)
						*liedit\cy=rc\bottom-rc\top
					EndIf
				Case #LVN_ENDLABELEDIT
					listhWnd = *nmh\hwndFrom
					;Retrieve the address of the LIEdit structure.
					*liedit = GetProp_(listhWnd, "_LIEdit")
					If *liedit ;Good to go!
						*lvd = lParam
						If *lvd\item\pszText
							SetGadgetItemText(*nmh\idFrom, *liedit\item, PeekS(*lvd\item\pszText), *liedit\subitem)
						Else              
							SetGadgetItemText(*nmh\idFrom, *liedit\item, celltext$, *liedit\subitem)
						EndIf
						SetWindowLong_(listhWnd, #GWL_STYLE, GetWindowLong_(listhWnd, #GWL_STYLE)&~#LVS_EDITLABELS)
						headerWnd = SendMessage_(listhWnd,#LVM_GETHEADER,0,0)
						SendMessage_(headerWnd, #HDM_SETITEM, 0, hdi) 
					EndIf
						; Insert new blank line
						If *liedit\item=CountGadgetItems(*nmh\idFrom)-1
							If Trim(GetGadgetItemText(*nmh\idFrom, *liedit\item, 1))+Trim(GetGadgetItemText(*nmh\idFrom, *liedit\item, 2))+Trim(GetGadgetItemText(*nmh\idFrom, *liedit\item, 3))<>""
								AddGadgetItem(*nmh\idFrom, -1, "")
							EndIf
						EndIf
				Default
					result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
			EndSelect
		Case #WM_NCDESTROY
			result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
			RemoveProp_(hWnd, "_LIEditOldProc")
		Default
			result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
	EndSelect
	ProcedureReturn result
EndProcedure

;Window proc of the ListIcon.
Procedure.i _LIEListProc(hWnd, uMsg, wParam, lParam)
	Protected result, *liedit._LIEdit, PInfo.LVHITTESTINFO, *nmHEADER.HD_NOTIFY
	;Retrieve the address of the LIEdit structure.
	*liedit = GetProp_(hWnd, "_LIEdit")
	Select uMsg
		Case #WM_NOTIFY
			*nmHEADER = lParam 
			Select *nmHEADER\hdr\code
					;Case #HDN_BEGINTRACK, #HDN_BEGINTRACKW ;Prevent column 0 from being resized.
					;  If *nmHEADER\iItem=0
					;    result=1
					;  EndIf
				Case #HDN_ENDTRACK, #HDN_ENDTRACKW
					InvalidateRect_(hWnd,0,1)
				Default
					result=CallWindowProc_(*liedit\listOldProc, hWnd, uMsg, wParam, lParam)
			EndSelect
		Case #WM_LBUTTONDBLCLK
			;Identify the clicked item
			PInfo\pt\x = lParam&$ffff 
			PInfo\pt\y = (lParam>>16)&$ffff 
			SendMessage_(hwnd, #LVM_SUBITEMHITTEST, 0, PInfo) 
			If PInfo\iItem <> -1 ;A valid cell was clicked.
				*liedit\item = PInfo\iItem
				*liedit\subitem = PInfo\iSubItem
				If PInfo\iSubItem=2 ; column 2 should be combobox
					_LIEComboCell(*liedit, hWnd)
				Else
					_LIEEditCell(*liedit, hWnd) ; all other columns can be edited directly
				EndIf
			EndIf
		Case #WM_NCDESTROY
			result=CallWindowProc_(*liedit\listOldProc, hWnd, uMsg, wParam, lParam)
			RemoveProp_(hWnd, "_LIEdit")
			FreeMemory(*liedit)
		Default
			result=CallWindowProc_(*liedit\listOldProc, hWnd, uMsg, wParam, lParam)
	EndSelect
	ProcedureReturn result
EndProcedure

;Window proc of the edit control.
Procedure.i _LIEeditProc(hWnd, uMsg, wParam, lParam)
	Protected result, oldwinproc, *liedit._LIEdit, *wpos.WINDOWPOS
	;Retrieve the address of the old proc.
	oldwinproc = GetProp_(hWnd, "_LIEditOldProc")
	;Retrieve the address of the LIEdit structure.
	*liedit = GetProp_(GetParent_(hWnd), "_LIEdit")
	Select uMsg
		Case #WM_ERASEBKGND
			;A hack in order to clear the default selection of characters.
			result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
			If *liedit\editHwnd=0
				*liedit\editHwnd = hWnd
				;Set margins.
				SendMessage_(hWnd, #EM_SETMARGINS, #EC_LEFTMARGIN|#EC_RIGHTMARGIN, 4)
				SendMessage_(hWnd, #EM_SETSEL, -1,0)
			EndIf
		Case #WM_WINDOWPOSCHANGING
			*wpos=lParam
			*wpos\cx=*liedit\cx ;Comment this line to get an edit control which grows with the text.
			*wpos\x=*liedit\x
			*wpos\cy=*liedit\cy
			*wpos\y=*liedit\y
			result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
		Case #WM_NCDESTROY
			result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
			RemoveProp_(hWnd, "_LIEditOldProc")
		Default
			result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
	EndSelect
	ProcedureReturn result
EndProcedure
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: Combobox in Listicongadget

Post by JHPJHP »

Hi,

Three things I see:

- you didn't include your Declare's (see original post)

DeclareDLL.l SetListIconEditable(listID)
Declare.l _LIEwinProc(hWnd, uMsg, wParam, lParam)
Declare.l _LIEListProc(hWnd, uMsg, wParam, lParam)
Declare.l _LIEeditProc(hWnd, uMsg, wParam, lParam)


- once you include the Declare's make sure they match your procedures:

** Declare is a Long (.l) procedure currently is an integer (.i)
** DeclareDLL SetListIconEditable is DLL : SetListIconEditable Procedure is standard (without DLL)


- _LIEEditCell Procedure needs to be moved before EditCell Procedure or a add another Declare

** Declare _LIEEditCell(*liedit_LIEdit, hWnd) - after structure
Last edited by JHPJHP on Fri Aug 02, 2013 5:38 pm, edited 2 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Barbarossa
User
User
Posts: 47
Joined: Fri Oct 12, 2012 8:50 am

Re: Combobox in Listicongadget

Post by Barbarossa »

- you didn't include your Declare's (see original post)
They are included in my declaration section. I omitted them in my post because I thought those were selfexplanatory.
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: Combobox in Listicongadget

Post by JHPJHP »

I modified the script found at the URL you posted to at least comple, but it runs a little flakey without more work - clicking in column 2 does bring up a combobox though:

PureBasic Changes - as applied to this post:

- OpenWindow moved Title parameter
- usefont is now FontID
- ProcedureReturn WindowID() is now WindowID(#Window_hittest)
- EventMenuID() is now EventMenu()
- EventGadgetID() is now EventGadget()
- EventWindowID() is now EventWindow()
- CreateGadgetList has been depreciated
- Frame3DGadget has been depreciated
- CreateGadgetList has been depreciated

Code: Select all

;============================================================================================================================ 
; 
;============================================================================================================================ 

Global BubbleTipStyle.l, OldListProc


PInfo.LVHITTESTINFO 
temp.Point 
rc.rect 
#LVM_SUBITEMHITTEST = #LVM_FIRST+57 
#LVM_GETSUBITEMRECT = #LVM_FIRST+56 

LoadFont(1,"Arial", 9) 

;============================================================================================================================ 
; 
;============================================================================================================================ 

BubbleTipStyle  = 0 

Enumeration 1 
  #Window_hittest 
EndEnumeration 

#WindowIndex = #PB_Compiler_EnumerationValue 

Enumeration 1 
  #Gadget_hittest_fmain 
  #Gadget_hittest_ListIcon3 
  #Gadget_hittest_hitcombo 
EndEnumeration 

#GadgetIndex = #PB_Compiler_EnumerationValue 


;The following callback allows a listicon control to be subclassed.
Procedure.l ListIconCallBack(hWnd, uMsg, wParam, lParam) 
Protected result
  Select uMsg 
    Case #WM_COMMAND ;This is how the CBN_SELCHANGE message is sent.
      Select (wParam>>16) & $ffff ;This contains the notification code.
        Case #CBN_SELCHANGE
          Debug GetGadgetItemText(#Gadget_hittest_hitcombo,GetGadgetState(#Gadget_hittest_hitcombo),0)
        EndSelect
  
  EndSelect
  result = CallWindowProc_(OldListProc, hWnd, uMsg, wParam, lParam) 
  ProcedureReturn result
EndProcedure



Procedure.l Window_hittest() 
  If OpenWindow(#Window_hittest,64,73,640,480,"Column hit test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible) 
;    If CreateGadgetList(WindowID(#Window_hittest)) 
;      Frame3DGadget(#Gadget_hittest_fmain,5,0,630,475,"") 
      ListIconGadget(#Gadget_hittest_ListIcon3,15,15,610,450,"Column 1",292,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection) 
      AddGadgetColumn(#Gadget_hittest_ListIcon3,1,"Column 2",292) 

;Best to create the comboboxgadget as a child of the ListIconGadget. 
;      CreateGadgetList(GadgetID(#Gadget_hittest_ListIcon3)) 
      ComboBoxGadget(#Gadget_hittest_hitcombo,0,0,80,200,#PB_ComboBox_Editable) 

      UseGadgetList(WindowID(#Window_hittest)) 
      HideGadget(#Gadget_hittest_hitcombo,1) 
      HideWindow(#Window_hittest,0) 
      SetGadgetFont(#Gadget_hittest_ListIcon3,FontID(1)) 
 
 ;Subclass the ListIconGadget
      OldListProc = SetWindowLong_(GadgetID(#Gadget_hittest_ListIcon3), #GWL_WNDPROC, @ListIconCallBack()) 
      

      ProcedureReturn WindowID(#Window_hittest) 
;    EndIf 
  EndIf 
EndProcedure 

If Window_hittest() 

  For flooble = 0 To 10 
    AddGadgetItem(#Gadget_hittest_ListIcon3, -1, "column 1" + Chr(10) + "column 2", 0) 
  Next flooble 
  
  For flooble = 0 To 10 
    AddGadgetItem(#Gadget_hittest_hitcombo, -1, "Macaroni " + Str(flooble)) 
  Next flooble 

  quithittest = 0 
  
  Repeat 
    EventID  = WaitWindowEvent() 
    MenuID   = EventMenu() 
    GadgetID = EventGadget() 
    WindowID = EventWindow() 

    Select EventID 
      Case #PB_Event_CloseWindow 
        If WindowID = #Window_hittest 
          quithittest = 1 
        EndIf 

      Case #PB_Event_Gadget 
        Select GadgetID 
          Case #Gadget_hittest_ListIcon3 
            Select EventType() 
              Case #PB_EventType_LeftClick 
                GetCursorPos_(temp) 
                MapWindowPoints_(0, GadgetID(#Gadget_hittest_ListIcon3), temp, 1) 
                pInfo\pt\x = temp\x 
                pInfo\pt\y = temp\y 
                SendMessage_(GadgetID(#Gadget_hittest_ListIcon3), #LVM_SUBITEMHITTEST, 0, pInfo) 
;The 'pInfo\iSubItem = 1' in the following statement ensures that the combo only
;appears when the user clicks column 1.
                If pInfo\iItem <> -1 And pInfo\iSubItem = 1;A cell has been selected. 
                  rc\top = pInfo\iSubItem 
                  rc\left = #LVIR_BOUNDS 
                  SendMessage_(GadgetID(#Gadget_hittest_ListIcon3), #LVM_GETSUBITEMRECT, pInfo\iItem, rc) 
                  rc\right = rc\left+SendMessage_(GadgetID(#Gadget_hittest_ListIcon3), #LVM_GETCOLUMNWIDTH, pInfo\iSubItem, 0) 
                  ResizeGadget(#Gadget_hittest_hitcombo, rc\left, rc\top-2, rc\right-rc\left, rc\bottom-rc\top+2) 
                  SendMessage_(GadgetID(#Gadget_hittest_hitcombo), #CB_SETITEMHEIGHT, -1,rc\bottom-rc\top-2) 
                  HideGadget(#Gadget_hittest_hitcombo,0) 
                Else 
                  HideGadget(#Gadget_hittest_hitcombo,1) 
                 EndIf 
              Default 
            EndSelect 
        EndSelect 

    EndSelect 
  Until quithittest 
  CloseWindow(#Window_hittest) 
EndIf 
End 

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Barbarossa
User
User
Posts: 47
Joined: Fri Oct 12, 2012 8:50 am

Re: Combobox in Listicongadget

Post by Barbarossa »

Thanks for translating the script to current PB syntax for me. That will surely help (I don't understand why there must be so many command name changes in the language all the time - this is killing backwards compatability).

However commenting

Code: Select all

;CreateGadgetList(GadgetID(#Gadget_hittest_ListIcon3))
is not the solution, we need an alternative. This command is important (I think) because with it the combobox becomes a child of the the listicongadget parent. Not doing this could be the cause of the flackynes.

I will see if I can improve it from this point now I have something to work with.

John
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: Combobox in Listicongadget

Post by JHPJHP »

Hi Barbarossa,

Sorry, I should have done a better job translating, or at least read this complete post (the last comment had it): viewtopic.php?t=36073.

CreateGadgetList replaced with UseGadgetList
Frame3DGadget "can" be replaced with FrameGadget

- the code runs much better:

Code: Select all

;============================================================================================================================ 
; 
;============================================================================================================================ 

Global BubbleTipStyle.l, OldListProc


PInfo.LVHITTESTINFO 
temp.Point 
rc.rect 
#LVM_SUBITEMHITTEST = #LVM_FIRST+57 
#LVM_GETSUBITEMRECT = #LVM_FIRST+56 

LoadFont(1,"Arial", 9) 

;============================================================================================================================ 
; 
;============================================================================================================================ 

BubbleTipStyle  = 0 

Enumeration 1 
  #Window_hittest 
EndEnumeration 

#WindowIndex = #PB_Compiler_EnumerationValue 

Enumeration 1 
  #Gadget_hittest_fmain 
  #Gadget_hittest_ListIcon3 
  #Gadget_hittest_hitcombo 
EndEnumeration 

#GadgetIndex = #PB_Compiler_EnumerationValue 


;The following callback allows a listicon control to be subclassed.
Procedure.l ListIconCallBack(hWnd, uMsg, wParam, lParam) 
  Protected Result
  Select uMsg 
    Case #WM_COMMAND ;This is how the CBN_SELCHANGE message is sent.
      Select (wParam>>16) & $FFFF ;This contains the notification code.
        Case #CBN_SELCHANGE
          Debug GetGadgetItemText(#Gadget_hittest_hitcombo,GetGadgetState(#Gadget_hittest_hitcombo),0)
      EndSelect
      
  EndSelect
  Result = CallWindowProc_(OldListProc, hWnd, uMsg, wParam, lParam) 
  ProcedureReturn Result
EndProcedure



Procedure.l Window_hittest() 
  If OpenWindow(#Window_hittest,64,73,640,480,"Column hit test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible) 
    If UseGadgetList(WindowID(#Window_hittest)) 
      FrameGadget(#Gadget_hittest_fmain,5,0,630,475,"", #PB_Frame_Single)
      ListIconGadget(#Gadget_hittest_ListIcon3,15,15,610,450,"Column 1",292,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection) 
      AddGadgetColumn(#Gadget_hittest_ListIcon3,1,"Column 2",292) 
      
      ;Best to create the comboboxgadget as a child of the ListIconGadget. 
      UseGadgetList(GadgetID(#Gadget_hittest_ListIcon3)) 
      ComboBoxGadget(#Gadget_hittest_hitcombo,0,0,80,200,#PB_ComboBox_Editable) 
      
      UseGadgetList(WindowID(#Window_hittest)) 
      HideGadget(#Gadget_hittest_hitcombo,1) 
      HideWindow(#Window_hittest,0) 
      SetGadgetFont(#Gadget_hittest_ListIcon3,FontID(1)) 
      
      ;Subclass the ListIconGadget
      OldListProc = SetWindowLong_(GadgetID(#Gadget_hittest_ListIcon3), #GWL_WNDPROC, @ListIconCallBack()) 
      
      
      ProcedureReturn WindowID(#Window_hittest) 
    EndIf 
  EndIf 
EndProcedure 

If Window_hittest() 
  
  For flooble = 0 To 10 
    AddGadgetItem(#Gadget_hittest_ListIcon3, -1, "column 1" + Chr(10) + "column 2", 0) 
  Next flooble 
  
  For flooble = 0 To 10 
    AddGadgetItem(#Gadget_hittest_hitcombo, -1, "Macaroni " + Str(flooble)) 
  Next flooble 
  
  quithittest = 0 
  
  Repeat 
    EventID  = WaitWindowEvent() 
    MenuID   = EventMenu() 
    GadgetID = EventGadget() 
    WindowID = EventWindow() 
    
    Select EventID 
      Case #PB_Event_CloseWindow 
        If WindowID = #Window_hittest 
          quithittest = 1 
        EndIf 
        
      Case #PB_Event_Gadget 
        Select GadgetID 
          Case #Gadget_hittest_ListIcon3 
            Select EventType() 
              Case #PB_EventType_LeftClick 
                GetCursorPos_(temp) 
                MapWindowPoints_(0, GadgetID(#Gadget_hittest_ListIcon3), temp, 1) 
                PInfo\pt\x = temp\x 
                PInfo\pt\y = temp\y 
                SendMessage_(GadgetID(#Gadget_hittest_ListIcon3), #LVM_SUBITEMHITTEST, 0, PInfo) 
                ;The 'pInfo\iSubItem = 1' in the following statement ensures that the combo only
                ;appears when the user clicks column 1.
                If PInfo\iItem <> -1 And PInfo\iSubItem = 1;A cell has been selected. 
                  rc\top = PInfo\iSubItem 
                  rc\left = #LVIR_BOUNDS 
                  SendMessage_(GadgetID(#Gadget_hittest_ListIcon3), #LVM_GETSUBITEMRECT, PInfo\iItem, rc) 
                  rc\right = rc\left+SendMessage_(GadgetID(#Gadget_hittest_ListIcon3), #LVM_GETCOLUMNWIDTH, PInfo\iSubItem, 0) 
                  ResizeGadget(#Gadget_hittest_hitcombo, rc\left, rc\top-2, rc\right-rc\left, rc\bottom-rc\top+2) 
                  SendMessage_(GadgetID(#Gadget_hittest_hitcombo), #CB_SETITEMHEIGHT, -1,rc\bottom-rc\top-2) 
                  HideGadget(#Gadget_hittest_hitcombo,0) 
                Else 
                  HideGadget(#Gadget_hittest_hitcombo,1) 
                EndIf 
              Default 
            EndSelect 
        EndSelect 
        
    EndSelect 
  Until quithittest 
  CloseWindow(#Window_hittest) 
EndIf 
End 

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Barbarossa
User
User
Posts: 47
Joined: Fri Oct 12, 2012 8:50 am

Re: Combobox in Listicongadget

Post by Barbarossa »

Ok thanks, I can see that this works.

Now back to my orginal question. How to integrate the second piece of code (Combolistbox) into the first piece of code (Editable Listicongadget)? It should be able to do both things.

John
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: Combobox in Listicongadget

Post by JHPJHP »

I was browsing the other Boards (Tricks 'n' Tips)...

Looks like RASHAD has just done what you've been asking: viewtopic.php?f=12&t=55781&sid=30e56e82 ... 4f744e6895

A sleek bit of script, but some work is needed when resizing the columns.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Combobox in Listicongadget

Post by netmaestro »

BERESHEIT
Post Reply