It is currently Wed Aug 05, 2020 2:14 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: RemoveGadgetColumn() fails if ListIconGadget has Icons
PostPosted: Fri Dec 20, 2019 12:25 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 11, 2004 7:07 am
Posts: 635
If you have a ListIconGadget with icons (SetGadgetItemImage) then GetGadgetAttribute(gadget, #PB_ListIcon_ColumnCount) returns "1" after you remove all columns with RemoveGadgetColumn(gadget, #PB_All). In it seems there is a remaining column...

Edit: it seem RemoveGadgetColumn() uses a wrong column index

Code:
#listicon = 0
UsePNGImageDecoder()
LoadImage(0, #PB_Compiler_Home + "logo.png")
OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(#listicon, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#listicon, 1, "Address", 250)
AddGadgetItem(#listicon, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(#listicon, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
;SetGadgetItemImage(#listicon, 1, ImageID(0)) ; <---- try it
RemoveGadgetColumn(#listicon, #PB_All)

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow


Top
 Profile  
Reply with quote  
 Post subject: Re: RemoveGadgetColumn() fails if ListIconGadget has Icons
PostPosted: Thu Dec 26, 2019 11:17 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1750
Location: Germany
I can confirm that RemoveGadgetColumn(GadgetID, #PB_All) doesn't work with ListIconGadgets displaying an icon column.

Lebostein wrote:
In it seems there is a remaining column...
That's correct. I have written the following example which counts the columns and uses the Cocoa framework method identifier to display the identifier for each column. In ListIconGadgets without an icon column all identifiers are named like the column, i.e. "0", "1" and so on. After displaying an icon with SetGadgetItemImage(), a new column 0 will be inserted as the first column with the identifier "Image" and the old column 0 will be shifted to column 1 while the old identifier is kept as "0".

My example demonstrates the changes in column count and displays all column identifiers after adding an icon. And by calling the procedure RemoveAllColumns() it demonstrates how to circumvent the PureBasic bug by first testing whether column 0 contains an image and deleting that column using the Cocoa method removeTableColumn:. After having removed a potential image column, PureBasic's RemoveGadgetColumn() can safely be used... :wink:

I have tested my example successfully with MacOS 10.14.6 'Mojave' and PB 5.71 x64.
Code:
EnableExplicit

UsePNGImageDecoder()

Procedure DisplayColumnInfos()
  Protected ColumnCount.I
  Protected ColumnObject.I
  Protected ColumnObjectArray.I
  Protected i.I

  ColumnCount = GetGadgetAttribute(0, #PB_ListIcon_ColumnCount)
  Debug "Column infos:"
  Debug "Number of columns: " + ColumnCount

  CocoaMessage(@ColumnObjectArray, GadgetID(0), "tableColumns")

  For i = 0 To ColumnCount - 1
    CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", i)
    Debug "Column " + Str(i) + ": identifer = " + #DQUOTE$ +
      PeekS(CocoaMessage(0, CocoaMessage(0, ColumnObject, "identifier"),
      "UTF8String"), -1, #PB_UTF8) + #DQUOTE$
  Next i

  Debug ""
EndProcedure

Procedure RemoveAllColumns()
  Protected ColumnCount.I
  Protected ColumnObject.I
  Protected ColumnObjectArray.I
  Protected i.I

  CocoaMessage(@ColumnObjectArray, GadgetID(0), "tableColumns")
  CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", 0)

  If PeekS(CocoaMessage(0, CocoaMessage(0, ColumnObject, "identifier"),
    "UTF8String"), -1, #PB_UTF8) = "Image"
    CocoaMessage(0, GadgetID(0), "removeTableColumn:", ColumnObject)
  EndIf

  RemoveGadgetColumn(0, #PB_All)
  DisableGadget(1, #True)
  DisableGadget(2, #True)
EndProcedure

If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png") = 0
  MessageRequester("Error",
    "Unable to load image CdPlayer.ico",
    #PB_MessageRequester_Error)
  End
EndIf

OpenWindow(0, 100, 100, 425, 110, "ListIcon example",
  #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 415, 70, "Name", 100,
  #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Address", 280)
AddGadgetItem(0, -1, "Harry Rannit"+ #LF$ +
  "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+ #LF$ +
  "130 PureBasic Road, BigTown, CodeCity")
DisplayColumnInfos()
ButtonGadget(1, 80, WindowHeight(0) - 30, 80, 25, "Add icon")
ButtonGadget(2, 195, WindowHeight(0) - 30, 150, 25, "Remove all columns")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          SetGadgetItemImage(0, 1, ImageID(0))
          DisplayColumnInfos()
          DisableGadget(1, #True)
        Case 2
          RemoveAllColumns()
      EndSelect
  EndSelect
ForEver


Top
 Profile  
Reply with quote  
 Post subject: Re: RemoveGadgetColumn() fails if ListIconGadget has Icons
PostPosted: Wed Jan 08, 2020 11:16 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 11, 2004 7:07 am
Posts: 635
Thanks for the workaround...


Top
 Profile  
Reply with quote  
 Post subject: Re: RemoveGadgetColumn() fails if ListIconGadget has Icons
PostPosted: Wed Jan 08, 2020 2:53 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2604
Location: Germany
The same problem with the LisIconGadget when checkboxes are used.
It is a bit more complicated to delete all columns without losing the checkbox property.

I once implemented it as bugfix function and macro.

Update v1.02
- Bugfix gadget number
- Added OSX Bugfix - Get count of columns

Code:
;- TOP Fix MacOS RemoveGadgetColumn

EnableExplicit

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS

  Macro PB_Call(Function)
    Function
  EndMacro
 
  Macro RemoveGadgetColumn(Gadget, Column)
    OSX_RemoveGadgetColumn(Gadget, Column)
  EndMacro
 
  Macro GetGadgetAttribute(Gadget, Attribute)
    OSX_GetGadgetAttribute(Gadget, Attribute)
  EndMacro
 
  ; ----
 
  Procedure OSX_RemoveGadgetColumn(Gadget, Column)
    Protected ColumnObjectArray, ColumnObject, ColumnObject2
    Protected cnt, Ident.S
   
    If Column <> #PB_All
      PB_Call(RemoveGadgetColumn)(Gadget, Column)
      ProcedureReturn 0
    EndIf
   
    If GadgetType(Gadget) <> #PB_GadgetType_ListIcon
      PB_Call(RemoveGadgetColumn)(Gadget, Column)
      ProcedureReturn 0
    EndIf
   
    cnt = PB_Call(GetGadgetAttribute)(Gadget, #PB_ListIcon_ColumnCount)
    If cnt <= 0
      ProcedureReturn 0
    EndIf
   
    CocoaMessage(@ColumnObjectArray, GadgetID(Gadget), "tableColumns")
    CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", 0)
   
    Ident = PeekS(CocoaMessage(0, CocoaMessage(0, ColumnObject, "identifier"), "UTF8String"), -1, #PB_UTF8)
    If Ident = "Image"
      CocoaMessage(0, GadgetID(Gadget), "removeTableColumn:", ColumnObject)
      PB_Call(RemoveGadgetColumn)(Gadget, #PB_All)
    ElseIf Ident = "CheckBox"
      ; Check Second Column
      If cnt >= 2
        CocoaMessage(@ColumnObject2, ColumnObjectArray, "objectAtIndex:", 1)
        Ident = PeekS(CocoaMessage(0, CocoaMessage(0, ColumnObject2, "identifier"), "UTF8String"), -1, #PB_UTF8)
        If Ident = "Image"
          CocoaMessage(0, GadgetID(Gadget), "removeTableColumn:", ColumnObject2)
        EndIf
        ClearGadgetItems(Gadget)
        PB_Call(RemoveGadgetColumn)(Gadget, #PB_All)
      EndIf
    Else
      PB_Call(RemoveGadgetColumn)(Gadget, #PB_All)
    EndIf
   
  EndProcedure
 
  Procedure OSX_GetGadgetAttribute(Gadget, Attribute)
    Protected ColumnObject, ColumnObjectArray
    Protected cnt, Ident.S
   
    If Attribute <> #PB_ListIcon_ColumnCount
      PB_Call(GetGadgetAttribute)(Gadget, Attribute)
    EndIf
   
    If GadgetType(Gadget) <> #PB_GadgetType_ListIcon
      PB_Call(GetGadgetAttribute)(Gadget, Attribute)
    EndIf
   
    cnt = PB_Call(GetGadgetAttribute)(Gadget, #PB_ListIcon_ColumnCount)
    If cnt <= 0
      ProcedureReturn 0
    EndIf
   
    CocoaMessage(@ColumnObjectArray, GadgetID(Gadget), "tableColumns")
    CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", 0)
    Ident = PeekS(CocoaMessage(0, CocoaMessage(0, ColumnObject, "identifier"), "UTF8String"), -1, #PB_UTF8)
    If Ident = "Image" Or Ident = "CheckBox"
      cnt - 1
    EndIf
    If cnt >= 2
      CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", 1)
      Ident = PeekS(CocoaMessage(0, CocoaMessage(0, ColumnObject, "identifier"), "UTF8String"), -1, #PB_UTF8)
      If Ident = "Image"
        cnt - 1
      EndIf
    EndIf
   
    ProcedureReturn cnt
   
  EndProcedure
 
CompilerEndIf

; ****

UsePNGImageDecoder()

Procedure DisplayColumnInfos()
  Protected ColumnCount.I
  Protected ColumnObject.I
  Protected ColumnObjectArray.I
  Protected i.I

  CocoaMessage(@ColumnObjectArray, GadgetID(0), "tableColumns")
  ColumnCount = CocoaMessage(0, ColumnObjectArray, "count", i)
 
  Debug "Column infos:"
  Debug "Number of columns: " + ColumnCount
 
 
  For i = 0 To ColumnCount - 1
    CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", i)
    Debug "Column " + Str(i) + ": identifer = " + #DQUOTE$ +
      PeekS(CocoaMessage(0, CocoaMessage(0, ColumnObject, "identifier"),
      "UTF8String"), -1, #PB_UTF8) + #DQUOTE$
  Next i

  Debug ""
  Debug "PB Number of columns: " + GetGadgetAttribute(0, #PB_ListIcon_ColumnCount)
  Debug ""
 
EndProcedure


If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png") = 0
  MessageRequester("Error",
    "Unable to load image CdPlayer.ico",
    #PB_MessageRequester_Error)
  End
EndIf

OpenWindow(0, 100, 100, 425, 120, "ListIcon example",
  #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 415, 80, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_CheckBoxes)
AddGadgetColumn(0, 1, "Address", 280)
AddGadgetItem(0, -1, "Harry Rannit"+ #LF$ + "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+ #LF$ + "130 PureBasic Road, BigTown, CodeCity")
DisplayColumnInfos()
ButtonGadget(1, 80, WindowHeight(0) - 30, 80, 25, "Add icon")
ButtonGadget(2, 195, WindowHeight(0) - 30, 150, 25, "Remove all columns")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          If CountGadgetItems(0) = 0
            AddGadgetColumn(0, 1, "Name", 100)
            AddGadgetColumn(0, 1, "Address", 280)
            AddGadgetItem(0, -1, "Harry Rannit"+ #LF$ + "12 Parliament Way, Battle Street, By the Bay")
            AddGadgetItem(0, -1, "Ginger Brokeit"+ #LF$ + "130 PureBasic Road, BigTown, CodeCity")
          EndIf
          SetGadgetItemImage(0, 1, ImageID(0))
          DisplayColumnInfos()
        Case 2
          RemoveGadgetColumn(0, #PB_All)
      EndSelect
  EndSelect
ForEver

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: RemoveGadgetColumn() fails if ListIconGadget has Icons
PostPosted: Fri May 01, 2020 8:00 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1847
Location: Germany (Saxony, Deutscheinsiedel)
I just stumbled across this topic, when I noticed a difference in my cross-platform project between the Windows version and MacOS... different from Windows an icon in front of the items is counted as column too on MacOS, so I needed to use the following workaround to have get it working on both OS:
Code:
      ; Set a new header text to the 2nd column, or add a 2nd column if there is only one:
      CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
        a = 2   ; on MacOS the icon in front of the first (text) column count as column too!
      CompilerElse
        a = 1   ; on Windows there is only count the text column (regardless if there is an image in front or not)
      CompilerEndIf
      ;Debug "Actual columns in listicon = " + GetGadgetAttribute(gad, #PB_ListIcon_ColumnCount)
      If GetGadgetAttribute(gad, #PB_ListIcon_ColumnCount) = a
        AddGadgetColumn(gad, 1, a$, 80)     ; ...but regardless of the OS, we always add a second column with index 1!
      Else
        SetGadgetItemText(gad, -1, a$, a)
      EndIf


I think this different "column counting" shouldn't happen in PB.
Else some remarks would be needed in the PB manual...

Sorry for jumping on this topic, but I think it's related too ;-)

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: RemoveGadgetColumn() fails if ListIconGadget has Icons
PostPosted: Sun May 03, 2020 8:44 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 11, 2004 7:07 am
Posts: 635
There's no need to apologize. The problem is still not solved.


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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