Page 1 of 1

Column select

Posted: Wed Jul 17, 2024 11:39 am
by epog10
I am an infrequent user of Purebasic. Thus apologies if this is a very basic question, the answer to which I should know.

In the ListIconGadget -

Is there an equivalent to GetGadgetState(0) that returns the column number?

Regards,
ep

Re: Column select

Posted: Wed Jul 17, 2024 11:53 am
by SMaag
Yes GetGateState() works for ListIconGadget too!

See PB help for GetGadgetState() there you will find a List with all Gadgets supporting GetGadgetState()

Re: Column select

Posted: Wed Jul 17, 2024 11:58 am
by mk-soft
New since PB v6.11

#PB_EventType_ColumnClick

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#Version = "v1.01.1"

Enumeration Windows
  #Main
EndEnumeration

Enumeration Menus
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuExitApplication
EndEnumeration

Enumeration Gadgets
  #MainList
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Global ExitApplication

; ----

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  ResizeGadget(#MainList, 0, 0, dx, dy)
  
EndProcedure

; ----

Procedure Main()
  Protected dx, dy

  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("File")
    MenuItem(#MainMenuExitApplication, "E&xit")
    ; For Mac
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      If Not IsMenu(#MainMenu)
        CreateMenu(#MainMenu, WindowID(#Main))
      EndIf
      MenuItem(#PB_Menu_About, "")
      MenuItem(#PB_Menu_Preferences, "")
    CompilerEndIf
    ; StatusBar  
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    StatusBarText(#MainStatusBar, 0, " " + #Version)
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    ListIconGadget(#MainList, 0, 0, dx, dy, "Column 0", 200)
    For i = 1 To 5
      AddGadgetColumn(#MainList, i, "Column " + i, 200)
    Next
    
    For i = 0 To 50
      AddGadgetItem(#MainList, -1, "Item " + i)
    Next
    
    ; Bind events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Main loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          ExitApplication = #True
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                MessageRequester("Info", #ProgramTitle + " " + #Version)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                ExitApplication = #True
                
            CompilerEndIf
              
            Case #MainMenuExitApplication
              ExitApplication = #True
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainList
              Select EventType()
                Case #PB_EventType_ColumnClick
                  Debug GetGadgetAttribute(#MainList, #PB_ListIcon_ClickedColumn)
                  
              EndSelect
              
          EndSelect
          
      EndSelect
      
    Until ExitApplication
    
  EndIf
  
EndProcedure : Main()

Re: Column select

Posted: Thu Jul 18, 2024 10:19 am
by epog10
Thank you for your responses.

Afraid that I see nothing called 'GetGateState' and the software example, does not run and I notice items (e.g. #PB_ListIcon_ClickedColum) that do not come up on Help.

I think the problem might be that I need to update my version (5.62) of Pb for those items to be available. So 6.11 it will be.

I shall do that later today and report back.

Thanks,
epog10

Re: Column select

Posted: Thu Jul 18, 2024 10:38 am
by RASHAD
For Windows
Or search the forum for Shardik cross platform solution

Code: Select all

Global Hit.LVHITTESTINFO

Procedure GetGadgetItemColumn(li)
  GetCursorPos_(@p.POINT)
  ScreenToClient_(GadgetID(li), p)
  hit\pt\x = p\x
  hit\pt\y = p\y
  SendMessage_(GadgetID(li),#LVM_SUBITEMHITTEST,0,@Hit)
  ProcedureReturn Hit\iSubItem
EndProcedure

OpenWindow(0,0,0,400,300,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ListIconGadget(0,10,10,380,280,"Column 0",100,#PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
AddGadgetColumn(0,1,"Column 1",100)
AddGadgetColumn(0,2,"Column 2",100)
For i=0 To 30
  AddGadgetItem(0,-1,"line "+Str(i)+Chr(10)+"line "+Str(i)+Chr(10)+"line "+Str(i))
Next

Repeat
  Select  WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Debug "Column : "+ Str(GetGadgetItemColumn(0))
      EndSelect
  EndSelect
Until Quit = 1

Re: Column select

Posted: Thu Jul 18, 2024 10:43 am
by mk-soft
Must be work with PB v5.x

Code: Select all

; =================================================================
;
;        Author:       Shardik  
;              :       Modified by mk-soft
;          Date:       January 27th, 2015
;       Explain:       Get ListIconGadget column
;           
; Typical Usage:
;
;     File Name:      Get Column Info.pb    
; =================================================================
Enumeration
  #MainForm
EndEnumeration

Enumeration Gadget 1
  #MyListIcon
EndEnumeration

Enumeration #PB_EventType_FirstCustomValue
  #MyEventType_ColumnClick
  #MyEventType_CellClick
EndEnumeration

Procedure OnListIconCLick(WindowID, message, wParam, lParam)
  Protected Result = #PB_ProcessPureBasicEvents 
  Protected Gadget
  Select message
    Case #WM_NOTIFY
      *nmITEM.NMITEMACTIVATE = lParam
      Select *nmITEM\hdr\code
          
        Case #LVN_COLUMNCLICK ;/ HeaderClick
          Gadget = GetProp_(*nmITEM\hdr\hwndFrom, "pb_id")
          If IsGadget(gadget) And GadgetType(Gadget) = #PB_GadgetType_ListIcon
            PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #MyEventType_ColumnClick, *nmITEM\iSubItem)
          EndIf
          
        Case #NM_CLICK ;/ CellClick (Your question)
          Gadget = GetProp_(*nmITEM\hdr\hwndFrom, "pb_id")
          If IsGadget(gadget) And GadgetType(Gadget) = #PB_GadgetType_ListIcon
            PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #MyEventType_CellClick, (*nmITEM\iSubItem << 16) | *nmITEM\iItem)
          EndIf
          
        Case #NM_DBLCLK 
          Debug "left doubleclick"
          ;Your code
          
        Case #NM_RCLICK
          Debug "right click"
          ;Your code
          
        Case #NM_RDBLCLK
          Debug "right doubleclick"
          ;Your code
          
      EndSelect
  EndSelect
  ProcedureReturn Result 
EndProcedure

Procedure Start()
  Protected n, Buffer.s
  
  OpenWindow(#MainForm, 0, 0, 500, 500, "Listicon gadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  SetWindowCallback(@OnListIconCLick(), #MainForm)
  
  ListIconGadget(#MyListIcon, 10, 10, 480, 400, "Col 0", 100, #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(#MyListIcon, 1, "Col 1", 100)
  AddGadgetColumn(#MyListIcon, 2, "Col 2", 100)
  
  For n=0 To 10
    Buffer = "Item " + Str(n) + Chr(10) + "Result Col 1=" + Str(n)  + Chr(10) + "Result Col 2=" + Str(n)
    AddGadgetItem(#MyListIcon, -1, Buffer)
  Next

  Repeat
    Select WaitWindowEvent(10)
      Case #PB_Event_CloseWindow
        Break
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #MyListIcon
            Select EventType()
              Case #MyEventType_ColumnClick
                Debug "#MyEventType_ColumnClick: Column " + EventData()
                
              Case #MyEventType_CellClick
                Debug "#MyEventType_CellClick: Column " + Str(EventData() >> 16) + " / Row " + Str(EventData() & $FFFF)
                
            EndSelect
              
        EndSelect
        
    EndSelect
  ForEver
  
EndProcedure

Start()

Re: Column select

Posted: Thu Jul 18, 2024 11:29 am
by boddhi
epog10 wrote: Afraid that I see nothing called 'GetGateState' [...]
SMaag wrote: Yes GetGateState() works for ListIconGadget too!
@SMaag, Error typing I suppose, This instruction doesn't exist... :wink:

Re: Column select

Posted: Thu Jul 18, 2024 11:52 am
by BarryG
epog10 wrote: Thu Jul 18, 2024 10:19 amI see nothing called 'GetGateState'
That was a typo. He meant GetGadgetState().

Re: Column select

Posted: Mon Jul 22, 2024 3:35 pm
by epog10
Sorry for the delay - I have been away.

Thank you all for your responses and clarifications.

mk-soft second example does work so I can do it in 5 although I did download 6 before I went away.

Can't pretend I understand the code - Have you declared (basically "invented") the "#MyEventType_ColumnClick" for Pb5 ???

The only column referenced event type I can see in Pb5 is the one that returns number of columns.

Regards,
epog10

Re: Column select

Posted: Tue Jul 23, 2024 6:32 am
by boddhi
epog10 wrote: Can't pretend I understand the code - Have you declared (basically "invented") the "#MyEventType_ColumnClick" for Pb5 ???
The only column referenced event type I can see in Pb5 is the one that returns number of columns.
Users can "define" their own events and invoke them via the PostEvent command. These events are not direct interactions (e.g. mouse, keyboard, etc.) with the user interface or provided by the system (e.g. timers).
These custom events are therefore differentiated in the event loop by values assigned to constants - by convention and because it's simpler - but they could also be simple variables, as long as their value does not correspond to the event constants used by PB.
This is the role played here by #MyEventType_ColumnClick and #MyEventType_CellClick

You can give them any name you like, usually explicit.

Note: As explained in the doc, PostEvent is mainly used with threads.