GetGadgetItemAttribute() returning wrong value

Windows specific forum
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

GetGadgetItemAttribute() returning wrong value

Post by RichardL »

Good morning,

GetGadgetItemAttribute should return '0' if I request information regarding an incorrect attribute or a non-existent column.
This does not seem to be the case in the following example... can someone please spot my silly mistake?
RichardL

Code: Select all

 
; PB5.3 W7 32bit
If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 290, 90, "Name", 100)
  
  ; Add columns
  For n = 1 To 6
    AddGadgetColumn(0, n, Str(n), 25)
  Next
  
  ; Get column widths
  ColCount  = 0       
  Attrib = #PB_ListIcon_ColumnWidth
  ColW = GetGadgetItemAttribute(0,0,Attrib,ColCount)         ; First column width
  Debug ColW
  While ColW < 5000                                          ; If a real column...
    ; Do things....
    ColCount + 1                                             ; count the columns
    ColW = GetGadgetItemAttribute(0,0,Attrib,ColCount)       ; get next width....
    Debug ColW
  Wend
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
  
EndIf

Edit: I chose the value of 5000 as being larger than any likely column width and smaller than any return value I observed.
Last edited by RichardL on Sun Aug 10, 2014 2:46 pm, edited 1 time in total.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: GetGadgetItemAttribute() returning wrong value

Post by RASHAD »

Change

Code: Select all

 While ColW < 5000
To

Code: Select all

While ColW <> 0  
Egypt my love
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: GetGadgetItemAttribute() returning wrong value

Post by RichardL »

Hi Rashad,
I never get a zero, the value returned for the non-existing column is very large... and not always the same.
These are the debug results I just obtained...

100
25
25
25
25
25
25
8399408

I chose the value of 5000 as being larger than any likely column width and smaller than any return value I observed.

RichardL
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: GetGadgetItemAttribute() returning wrong value

Post by RASHAD »

Hi Rich
Yes I got you now beside my logic not always right
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: GetGadgetItemAttribute() returning wrong value

Post by RASHAD »

Hi Rich
I just tried your snippet with 5.3 and win 8.1 x64
It gives me zeros as expected
I presume you want to Count the no. of columns
Taking into consideration that one of the interior columns has 0 width

Code: Select all

; PB5.3 W7 32bit
If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 290, 90, "Name", 100)
 
  ; Add columns
  For n = 1 To 3
    AddGadgetColumn(0, n, Str(n), 25)
  Next
 AddGadgetColumn(0, 4, Str(4), 0)
   For n = 5 To 8
    AddGadgetColumn(0, n, Str(n), 25)
  Next
  ; Get column widths
  ColCount  = 0       
  Attrib = #PB_ListIcon_ColumnWidth
  ColW = GetGadgetItemAttribute(0,0,Attrib,ColCount)         ; First column width
  Debug ColW
  AddGadgetColumn(0, 32000, "RichardL", 0) ; Add a column at the farest position as you can with any strange header text
  While GetGadgetItemText(0,-1,ColCount) <> "RichardL"
    ColCount + 1                                             ; count the columns
    ColW = GetGadgetItemAttribute(0,0,Attrib,ColCount)       ; get next width....
    Debug ColW
  Wend
  
  Debug ColCount - 1
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
 
EndIf
Egypt my love
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: GetGadgetItemAttribute() returning wrong value

Post by RichardL »

Hi Rashad,
I cannot assume anything about the contents of a cell or the title, I need to determine the number of columns of ANY ListIconGadget() I am given the Gadget number for.
The context of the problem is I am making my gadget re-sizing utility automatically scale the widths of columns when the Window() is resized...
Here is my un-finished code to do this:

Code: Select all

; First steps with BindEvent() and BindGadgetEvent()

EnableExplicit
Declare SetGadgetResize(WinNum,GadNum,FlagX,FlagY,FlagWidth,FlagHeight,AdjustCol=#False)
Declare EventHandler_WinResize()
Declare EventHandler_ScrollBar()

Global NumReSizeGads.l
Procedure SetGadgetResize(WinNum,GadNum,FlagX,FlagY,FlagWidth,FlagHeight,AdjustCol=#False)
  
  Protected Attrib.l,ColW.l,ColCount.w,Win.i
  Static *P,*M,ColTableSize.l = 1024
  
  ; Memory to hold number of columns and original sizes.
  ; NumCol.w,Wid0.w,Wid1.w,Wid2.w,Wid3.w,....
  If *P = 0 : *M =  AllocateMemory(ColTableSize) : *P = *M : EndIf
  
  Structure RESIZER
    WinNum.l
    OldWindowHeight.w
    OldWindowWidth.w  
    
    GadNum.l
    OriginalGadgetWidth.w
    OriginalGadgetHeight.w
    FlagX.w
    FlagY.w
    FlagW.w
    FlagH.w
    
    SpecGadData.i
  EndStructure
  
  ; Create structure to hold gadget data
  If NumReSizeGads = 0
    NumReSizeGads = 1
    Global Dim ReSize.RESIZER(1)
  Else
    NumReSizeGads + 1
    Redim ReSize(NumReSizeGads)
  EndIf
  
  ; Add a gadget to the list of gadgets that are to be re-sized.
  With ReSize(NumReSizeGads)
    \WinNum          = WinNum
    \OldWindowHeight = WindowHeight(WinNum)
    \OldWindowWidth  = WindowWidth(WinNum)
    
    \GadNum = GadNum
    \OriginalGadgetWidth = GadgetWidth(\GadNum)
    \OriginalGadgetHeight = GadgetHeight(\GadNum)
    \FlagX  = FlagX & 1
    \FlagY  = FlagY & 1
    \FlagW  = FlagWidth & 1
    \FlagH  = FlagHeight & 1
    
    ; Flag gadgets with columns that will need width adjustment
    
    Attrib = 0
    If AdjustCol & 1
      Select GadgetType(GadNum)
        Case #PB_GadgetType_ListIcon     :  Attrib = #PB_ListIcon_ColumnWidth
        Case #PB_GadgetType_ExplorerList :  Attrib = #PB_Explorer_ColumnWidth
      EndSelect
    EndIf
    
    If Attrib
      \SpecGadData = *P                    ; Start of data area for this gadget.
      ColCount  = 0       
      ColW = GetGadgetItemAttribute(\GadNum,0,Attrib,ColCount) ; First column width
      While ColW < 5000                    ; If a real column...
        PokeW((*P+2) + (ColCount*2),ColW)  ; keep it's width
        ColCount + 1                       ; count the columns
        ColW = GetGadgetItemAttribute(\GadNum,0,Attrib,ColCount) ; get next width.
      Wend
      PokeW(\SpecGadData,ColCount)         ; Keep the number of columns.
      *P + ((ColCount+1)*2)                ; Update data area pointer for next gadget
      ColTableSize + ((ColCount+1)*2)
      *M = ReAllocateMemory(*M,ColTableSize)
      Debug ColTableSize
      
    Else
      \SpecGadData = 0
    EndIf
   
  EndWith
  
EndProcedure
Procedure EventHandler_WinResize() 
  Protected dx.w,dy.w,n.w,NewX.w,NewY.w,NewW.w,NewH.w,Win.i,DoOnce.l,f.f,Col.w,ColCount.w,*P
  
  Win = EventWindow()
  DoOnce = #False
  For n = 1 To NumReSizeGads 
    If ReSize(n)\WinNum = Win ; A window is being resized, is it one we are monitoring?
      With ReSize(n)
        
        If DoOnce = #False
          ; How much has window size changed?
          dy = WindowHeight(ReSize(n)\WinNum) - ReSize(n)\OldWindowHeight   
          dx = WindowWidth(ReSize(n)\WinNum)  - ReSize(n)\OldWindowWidth           
          
          ; Save the new window size.
          \OldWindowHeight = WindowHeight(ReSize(n)\WinNum)
          \OldWindowWidth  = WindowWidth(ReSize(n)\WinNum)    
          DoOnce = #True
        EndIf
        
        ; Adjust gadget sizes and positions
        NewX = (dx * \FlagX) + GadgetX(\GadNum)
        NewY = (dy * \FlagY) + GadgetY(\GadNum)
        NewW = (dx * \FlagW) + GadgetWidth(\GadNum)
        NewH = (dy * \FlagH) + GadgetHeight(\GadNum)
        ResizeGadget(\GadNum,NewX,NewY,NewW,NewH)
       
        ; Adjust column widths of ListIconGadget() and ExplorerListGadget()
        If \SpecGadData And dx<>0
          f.f = GadgetWidth(\GadNum) / \OriginalGadgetWidth
          ColCount = PeekW(\SpecGadData)
          *P = \SpecGadData + 2
          For Col = 0 To ColCount-1
            SetGadgetItemAttribute(\GadNum,0,#PB_ListIcon_ColumnWidth,PeekW(*P)*f,Col)
            *P + 2  
          Next
        EndIf
        
        ; For WINDOWS
        CompilerIf #PB_OS_Windows 
          InvalidateRect_(WindowID(\WinNum),0,0) ; ***** Fixes broken gadgets
          While WindowEvent() : Wend             ; ***** Improves rendering of EditorGadget()
        CompilerEndIf
        
      EndWith
    EndIf
  Next

EndProcedure
Procedure EventHandler_ScrollBar()
  Select EventGadget()
    Case 7
      SetGadgetText(6,Str(GetGadgetState(7)))
    Case 8
      SetGadgetText(9,Str(GetGadgetState(8)))
  EndSelect
EndProcedure
DisableExplicit

; Test code
; Window 1
OpenWindow(1,100,100,200,90,"Re-Size my height",#PB_Window_SystemMenu|#PB_Window_SizeGadget) 
SmartWindowRefresh(1,1)
SetWindowColor(1,RGB(255,255,0))
WindowBounds(1,200,90,200,400)
EditorGadget(1,5,5,190,20)               : SetGadgetResize(1,1,0,0,0,1) 
ButtonGadget(2,5,40,190,20,"Button 2")   : SetGadgetResize(1,2,0,1,0,0)

; Window 2
OpenWindow(2,420,120,425,110,"Re-Size Me 2 ways",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
SetWindowColor(2,RGB(0,255,255))
WindowBounds(2,425,110,800,400)
EditorGadget(3,5,5,190,20)               : SetGadgetResize(2,3,0,0,0,1)
For n = 1 To 50
  AddGadgetItem(3,-1,Str(Random(1000000)))
Next

ListIconGadget(4,200,5,195,50,"Title",60,#PB_ListIcon_GridLines) ; Create the LIG()
For x = 0 To 9                                                   ; Add some columns
  AddGadgetColumn(4,60+(x*20),Str(x),20+x)
Next
SetGadgetResize(2,4,0,0,1,1,#True)                               ; Specify resizing AFTER adding the columns!

For y = 0 To 9
  AddGadgetItem(4,-1,"")
  For x = 0 To 10
    SetGadgetItemText(4,y,"X"+Str(x)+"  Y"+Str(y),x)
  Next
Next

ButtonGadget(5,5,40,190,40,"Button 4")   : SetGadgetResize(2,5,0,1,0,0)
StringGadget(6,340,85,50,20,"---")       : SetGadgetResize(2,6,1,1,0,0)
ScrollBarGadget(7,400,5,21,80,0,1023,1, #PB_ScrollBar_Vertical) :  SetGadgetResize(2,7,1,0,0,1)
SetGadgetState(7,512)
ScrollBarGadget(8,200,60,195,20,0,2048,1): SetGadgetResize(2,8,0,1,1,0)
SetGadgetState(8,1024)
StringGadget(9,200,85,50,20,"---")       : SetGadgetResize(2,9,0,1,0,0)

; Bind various items to specific event handlers
BindEvent(#PB_Event_SizeWindow,@EventHandler_WinResize())
BindGadgetEvent(7,@EventHandler_ScrollBar())
BindGadgetEvent(8,@EventHandler_ScrollBar())

Repeat 
  ; Your event management here
Until WaitWindowEvent() = #PB_Event_CloseWindow 

RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: GetGadgetItemAttribute() returning wrong value

Post by RASHAD »

Hi Rich
Try

Code: Select all

Procedure SetGadgetResize(WinNum,GadNum,FlagX,FlagY,FlagWidth,FlagHeight,AdjustCol=#False)
 
  Protected Attrib.l,ColW.l,ColW2.l,ColCount.w,Win.i,x
  Static *P,*M,ColTableSize.l = 1024
   
  ; Memory to hold number of columns and original sizes.
  ; NumCol.w,Wid0.w,Wid1.w,Wid2.w,Wid3.w,....
  If *P = 0 : *M =  AllocateMemory(ColTableSize) : *P = *M : EndIf
 
  Structure RESIZER
    WinNum.l
    OldWindowHeight.w
    OldWindowWidth.w 
   
    GadNum.l
    OriginalGadgetWidth.w
    OriginalGadgetHeight.w
    FlagX.w
    FlagY.w
    FlagW.w
    FlagH.w
   
    SpecGadData.i
  EndStructure
 
  ; Create structure to hold gadget data
  If NumReSizeGads = 0
    NumReSizeGads = 1
    Global Dim ReSize.RESIZER(1)
  Else
    NumReSizeGads + 1
    ReDim ReSize(NumReSizeGads)
  EndIf
 
  ; Add a gadget to the list of gadgets that are to be re-sized.
  With ReSize(NumReSizeGads)
    \WinNum          = WinNum
    \OldWindowHeight = WindowHeight(WinNum)
    \OldWindowWidth  = WindowWidth(WinNum)
   
    \GadNum = GadNum
    \OriginalGadgetWidth = GadgetWidth(\GadNum)
    \OriginalGadgetHeight = GadgetHeight(\GadNum)
    \FlagX  = FlagX & 1
    \FlagY  = FlagY & 1
    \FlagW  = FlagWidth & 1
    \FlagH  = FlagHeight & 1
   
    ; Flag gadgets with columns that will need width adjustment
   
    Attrib = 0
    If AdjustCol & 1
      Select GadgetType(GadNum)
        Case #PB_GadgetType_ListIcon     :  Attrib = #PB_ListIcon_ColumnWidth
        Case #PB_GadgetType_ExplorerList :  Attrib = #PB_Explorer_ColumnWidth
      EndSelect
    EndIf
   
    If Attrib
      \SpecGadData = *P                    ; Start of data area for this gadget.
      ColCount  = 0       
      ColW = GetGadgetItemAttribute(\GadNum,0,Attrib,ColCount) ; First column width
      For x = 0 To 1000
          If GetGadgetItemAttribute(\GadNum,0,Attrib,x) > ColW2
              ColW2 = GetGadgetItemAttribute(\GadNum,0,Attrib,x)
          EndIf
      Next
      While ColW < ColW2               ; If a real column...
        PokeW((*P+2) + (ColCount*2),ColW)  ; keep it's width
        ColCount + 1                       ; count the columns
        ColW = GetGadgetItemAttribute(\GadNum,0,Attrib,ColCount) ; get next width.
      Wend
      PokeW(\SpecGadData,ColCount)         ; Keep the number of columns.
      *P + ((ColCount+1)*2)                ; Update data area pointer for next gadget
      ColTableSize + ((ColCount+1)*2)
      *M = ReAllocateMemory(*M,ColTableSize)     
    Else
      \SpecGadData = 0
    EndIf
   
  EndWith
 
EndProcedure
Egypt my love
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: GetGadgetItemAttribute() returning wrong value

Post by RichardL »

@Rashad,
I cannot see what your introduction of ColW2 does that is any different to my fixed value of '5000', which was chosen based on my observation of the apparently wrong returned value from GetGadgetItemAttribute().

My original question stands... have I done something silly that provokes the erroneous value?
Is there a PB bug?
Can someone with Windows 7 32bit and PB5.3 please tell me what they see?

In the meanwhile I'm going to finish development of the function and use the following test that should work with anomalous installations, such as mine, and with those installations that work correctly.

Code: Select all

 While (ColW > 0) And (ColW < 5000)       ; If a real column...
Thanks,
RichardL
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: GetGadgetItemAttribute() returning wrong value

Post by RASHAD »

Sorry Rich :)
I just realized that before you post
My problem I can not reproduce your problem with win 8.1
I will try again with windows 7
By the way with windows it is easy to count the real column no.

Code: Select all

hHwnd  = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
ColumnCount = SendMessage_(hHwnd,  #HDM_GETITEMCOUNT, 0, 0)
Keep tuning
Egypt my love
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: GetGadgetItemAttribute() returning wrong value

Post by RichardL »

@Rashad,
Agreed, but I'm really trying to be platform portable whenever I can!
It would be good if PB could have a read only attribute to return the Column Count.
RichardL
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: GetGadgetItemAttribute() returning wrong value

Post by RASHAD »

Yes I agree about a ColumnCount Function
For time being try the next it is Cross Platform

Code: Select all

; First steps with BindEvent() and BindGadgetEvent()

EnableExplicit
Declare CountListiconColumn(GadNum, maxcolumn, keyword.s)
Declare SetGadgetResize(WinNum,GadNum,FlagX,FlagY,FlagWidth,FlagHeight,AdjustCol=#False)
Declare EventHandler_WinResize()
Declare EventHandler_ScrollBar()

Global NumReSizeGads.l,no.l

Procedure CountListiconColumn(GadNum, maxcolumn, keyword.s)
If IsGadget(GadNum)
  AddGadgetColumn(GadNum, maxcolumn, keyword, 0)
    For no=0 To maxcolumn
      If GetGadgetItemText(GadNum, -1, no)=keyword
        Break
      EndIf    
    Next
  RemoveGadgetColumn(GadNum, no)
  ProcedureReturn no
EndIf
EndProcedure

Procedure SetGadgetResize(WinNum,GadNum,FlagX,FlagY,FlagWidth,FlagHeight,AdjustCol=#False)
 
  Protected Attrib.l,ColW.l,ColCount.w,Win.i
  Static *P,*M,ColTableSize.l = 1024
 
  ; Memory to hold number of columns and original sizes.
  ; NumCol.w,Wid0.w,Wid1.w,Wid2.w,Wid3.w,....
  If *P = 0 : *M =  AllocateMemory(ColTableSize) : *P = *M : EndIf
 
  Structure RESIZER
    WinNum.l
    OldWindowHeight.w
    OldWindowWidth.w 
   
    GadNum.l
    OriginalGadgetWidth.w
    OriginalGadgetHeight.w
    FlagX.w
    FlagY.w
    FlagW.w
    FlagH.w
   
    SpecGadData.i
  EndStructure
 
  ; Create structure to hold gadget data
  If NumReSizeGads = 0
    NumReSizeGads = 1
    Global Dim ReSize.RESIZER(1)
  Else
    NumReSizeGads + 1
    ReDim ReSize(NumReSizeGads)
  EndIf
 
  ; Add a gadget to the list of gadgets that are to be re-sized.
  With ReSize(NumReSizeGads)
    \WinNum          = WinNum
    \OldWindowHeight = WindowHeight(WinNum)
    \OldWindowWidth  = WindowWidth(WinNum)
   
    \GadNum = GadNum
    \OriginalGadgetWidth = GadgetWidth(\GadNum)
    \OriginalGadgetHeight = GadgetHeight(\GadNum)
    \FlagX  = FlagX & 1
    \FlagY  = FlagY & 1
    \FlagW  = FlagWidth & 1
    \FlagH  = FlagHeight & 1
   
    ; Flag gadgets with columns that will need width adjustment
   
    Attrib = 0
    If AdjustCol & 1
      Select GadgetType(GadNum)
        Case #PB_GadgetType_ListIcon     :  Attrib = #PB_ListIcon_ColumnWidth
        Case #PB_GadgetType_ExplorerList :  Attrib = #PB_Explorer_ColumnWidth
      EndSelect
    EndIf
   
    If Attrib
      \SpecGadData = *P                    ; Start of data area for this gadget.
      ColCount  = 0       
      ColW = GetGadgetItemAttribute(\GadNum,0,Attrib,ColCount) ; First column width 
      CountListiconColumn(\GadNum, 32000, "RichardL Column No")
      While ColCount < no                   ; If a real column...      
        PokeW((*P+2) + (ColCount*2),ColW)  ; keep it's width
        ColCount + 1                       ; count the columns
        ColW = GetGadgetItemAttribute(\GadNum,0,Attrib,ColCount) ; get next width.        
      Wend
      PokeW(\SpecGadData,ColCount)         ; Keep the number of columns.
      *P + ((ColCount+1)*2)                ; Update data area pointer for next gadget
      ColTableSize + ((ColCount+1)*2)
      *M = ReAllocateMemory(*M,ColTableSize)
      Debug ColTableSize
     
    Else
      \SpecGadData = 0
    EndIf
   
  EndWith
 
EndProcedure
Procedure EventHandler_WinResize()
  Protected dx.w,dy.w,n.w,NewX.w,NewY.w,NewW.w,NewH.w,Win.i,DoOnce.l,f.f,Col.w,ColCount.w,*P
 
  Win = EventWindow()
  DoOnce = #False
  For n = 1 To NumReSizeGads
    If ReSize(n)\WinNum = Win ; A window is being resized, is it one we are monitoring?
      With ReSize(n)
       
        If DoOnce = #False
          ; How much has window size changed?
          dy = WindowHeight(ReSize(n)\WinNum) - ReSize(n)\OldWindowHeight   
          dx = WindowWidth(ReSize(n)\WinNum)  - ReSize(n)\OldWindowWidth           
         
          ; Save the new window size.
          \OldWindowHeight = WindowHeight(ReSize(n)\WinNum)
          \OldWindowWidth  = WindowWidth(ReSize(n)\WinNum)   
          DoOnce = #True
        EndIf
       
        ; Adjust gadget sizes and positions
        NewX = (dx * \FlagX) + GadgetX(\GadNum)
        NewY = (dy * \FlagY) + GadgetY(\GadNum)
        NewW = (dx * \FlagW) + GadgetWidth(\GadNum)
        NewH = (dy * \FlagH) + GadgetHeight(\GadNum)
        ResizeGadget(\GadNum,NewX,NewY,NewW,NewH)
       
        ; Adjust column widths of ListIconGadget() and ExplorerListGadget()
        If \SpecGadData And dx<>0
          f.f = GadgetWidth(\GadNum) / \OriginalGadgetWidth
          ColCount = PeekW(\SpecGadData)
          *P = \SpecGadData + 2
          For Col = 0 To ColCount-1
            SetGadgetItemAttribute(\GadNum,0,#PB_ListIcon_ColumnWidth,PeekW(*P)*f,Col)
            *P + 2 
          Next
        EndIf
       
        ; For WINDOWS
        CompilerIf #PB_OS_Windows
          InvalidateRect_(WindowID(\WinNum),0,0) ; ***** Fixes broken gadgets
          While WindowEvent() : Wend             ; ***** Improves rendering of EditorGadget()
        CompilerEndIf
       
      EndWith
    EndIf
  Next

EndProcedure
Procedure EventHandler_ScrollBar()
  Select EventGadget()
    Case 7
      SetGadgetText(6,Str(GetGadgetState(7)))
    Case 8
      SetGadgetText(9,Str(GetGadgetState(8)))
  EndSelect
EndProcedure
DisableExplicit

; Test code
; Window 1
OpenWindow(1,100,100,200,90,"Re-Size my height",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
SmartWindowRefresh(1,1)
SetWindowColor(1,RGB(255,255,0))
WindowBounds(1,200,90,200,400)
EditorGadget(1,5,5,190,20)               : SetGadgetResize(1,1,0,0,0,1)
ButtonGadget(2,5,40,190,20,"Button 2")   : SetGadgetResize(1,2,0,1,0,0)

; Window 2
OpenWindow(2,420,120,425,110,"Re-Size Me 2 ways",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
SetWindowColor(2,RGB(0,255,255))
WindowBounds(2,425,110,800,400)
EditorGadget(3,5,5,190,20)               : SetGadgetResize(2,3,0,0,0,1)
For n = 1 To 50
  AddGadgetItem(3,-1,Str(Random(1000000)))
Next

ListIconGadget(4,200,5,195,50,"Title",60,#PB_ListIcon_GridLines) ; Create the LIG()
For x = 0 To 9                                                   ; Add some columns
  AddGadgetColumn(4,60+(x*20),Str(x),20+x)
Next
SetGadgetResize(2,4,0,0,1,1,#True)                               ; Specify resizing AFTER adding the columns!

For y = 0 To 9
  AddGadgetItem(4,-1,"")
  For x = 0 To 10
    SetGadgetItemText(4,y,"X"+Str(x)+"  Y"+Str(y),x)
  Next
Next

ButtonGadget(5,5,40,190,40,"Button 4")   : SetGadgetResize(2,5,0,1,0,0)
StringGadget(6,340,85,50,20,"---")       : SetGadgetResize(2,6,1,1,0,0)
ScrollBarGadget(7,400,5,21,80,0,1023,1, #PB_ScrollBar_Vertical) :  SetGadgetResize(2,7,1,0,0,1)
SetGadgetState(7,512)
ScrollBarGadget(8,200,60,195,20,0,2048,1): SetGadgetResize(2,8,0,1,1,0)
SetGadgetState(8,1024)
StringGadget(9,200,85,50,20,"---")       : SetGadgetResize(2,9,0,1,0,0)

; Bind various items to specific event handlers
BindEvent(#PB_Event_SizeWindow,@EventHandler_WinResize())
BindGadgetEvent(7,@EventHandler_ScrollBar())
BindGadgetEvent(8,@EventHandler_ScrollBar())

Repeat
  ; Your event management here
Until WaitWindowEvent() = #PB_Event_CloseWindow 

Egypt my love
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: GetGadgetItemAttribute() returning wrong value

Post by Shardik »

Rashad,

you have a small error in your interesting last code example. You have to change

Code: Select all

CompilerIf #PB_OS_Windows
to

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
This is a short cross-platform example using platform-specific API functions to count all columns of a ListIconGadget:

Code: Select all

Procedure.I GetNumberOfColumns(ListIconGadgetID.I)
  Protected NumberOfColumns.I

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      Protected *ListStore.GtkListStore
      *ListStore = gtk_tree_view_get_model_(GadgetID(ListIconGadgetID))
      NumberOfColumns = (*ListStore\n_columns - 3) / 3
    CompilerCase #PB_OS_MacOS
      NumberOfColumns = CocoaMessage(0, GadgetID(ListIconGadgetID),
        "numberOfColumns")
    CompilerCase #PB_OS_Windows
      NumberOfColumns = SendMessage_(SendMessage_(GadgetID(ListIconGadgetID),
        #LVM_GETHEADER, 0, 0), #HDM_GETITEMCOUNT, 0, 0)
  CompilerEndSelect

  ProcedureReturn NumberOfColumns
EndProcedure

OpenWindow(0, 270, 100, 270, 60, "ListIconGadget")
ListIconGadget(0, 5, 5, WindowWidth(0) - 10, WindowHeight(0) - 10, "Column 1", 80)
AddGadgetColumn(0, 1, "Column 2", 80)
AddGadgetColumn(0, 2, "Column 3", 80)

MessageRequester("Info", "Number of columns: " + Str(GetNumberOfColumns(0)))
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: GetGadgetItemAttribute() returning wrong value

Post by RichardL »

Gentlemen,
Thank you for your kind assistance
Richard
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: GetGadgetItemAttribute() returning wrong value

Post by collectordave »

Counting Columns in listicon

Can you use

Code: Select all

  ColCount = 0
  While GetGadgetItemText(0,-1,ColCount) <> ""  ;Checks header text assumes all headers have some text
    ColCount + 1                                             ; count the columns
  Wend
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: GetGadgetItemAttribute() returning wrong value

Post by collectordave »

Just noticed a funny thing while removing columns I was using

Code: Select all

  For iloop = 1 To ColCount   ;Do not remove column 0
    RemoveGadgetColumn(lstResult, iloop)
  Next
Which left a couple of columns each time changed to

Code: Select all

  For iloop = ColCount To 1 Step -1  ;Do not remove column 0
    RemoveGadgetColumn(lstResult, iloop)
  Next
And it works removing all columns except the first column.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply