Set alignment of ListIconGadget columns in PB 6

Mac OSX specific forum
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Set alignment of ListIconGadget columns in PB 6

Post by Lebostein »

so far I used this code:

Code: Select all

Procedure SetListIconColumnJustification(ListIconID.i, ColumnIndex.i, Alignment.i)
    Protected ColumnHeaderCell.i
    Protected ColumnObject.i
    Protected ColumnObjectArray.i
    CocoaMessage(@ColumnObjectArray, GadgetID(ListIconID), "tableColumns")
    CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", ColumnIndex)
    CocoaMessage(0, CocoaMessage(0, ColumnObject, "dataCell"), "setAlignment:", Alignment)
    CocoaMessage(@ColumnHeaderCell, ColumnObject, "headerCell")
    CocoaMessage(0, ColumnHeaderCell, "setAlignment:", Alignment)
EndProcedure
But with PB 6 it dont' work.
User avatar
mk-soft
Always Here
Always Here
Posts: 5333
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Set alignment of ListIconGadget columns in PB 6

Post by mk-soft »

This is due to "PBIconTextCell".
I wanted to start a bug discussion to see if Fred might return to the old NSTableView procedure for the Cell.

https://www.purebasic.fr/english/viewtopic.php?t=79156
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Set alignment of ListIconGadget columns in PB 6

Post by Lebostein »

How I could align the colums center an right with Mac OS API? Is it possible with the new "PBIconTextCell"? I wonder why such basic format functions are not implemented if the Gadget is rewritten anyway...
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Set alignment of ListIconGadget columns in PB 6

Post by deseven »

Code: Select all

EnableExplicit

#justifyLeft = 0
#justifyCenter = 1
#justifyRight = 2

Define app.i = CocoaMessage(0,0,"NSApplication sharedApplication")
Define appDelegate.i = CocoaMessage(0,app,"delegate")
Define delegateClass.i = CocoaMessage(0,appDelegate,"class")

ProcedureC CellDisplayCallback(Object.I,Selector.I,TableView.I,Cell.I,*Column,Row.I)
  Protected LineFrame.NSRect
  Protected RowFrame.NSRect
  Protected TextSize.NSSize
  Protected CellFrame.NSRect
  Protected BoldFontSize.CGFloat = 15.0
  Protected FontSize.CGFloat = 13.0
  Protected Column.i = CocoaMessage(0,CocoaMessage(0,TableView,"tableColumns"),"indexOfObject:",*Column)
  Protected Gadget.i = CocoaMessage(0,TableView,"tag")
  Protected CellText.s = GetGadgetItemText(Gadget,Row,Column)
  
  Select Column
    Case 0
      CocoaMessage(0,Cell,"setAlignment:",#justifyCenter)
    Case 1
      CocoaMessage(0,Cell,"setAlignment:",#justifyRight)
  EndSelect
  
  CocoaMessage(0,Cell,"setStringValue:$",@CellText)
  
EndProcedure

OpenWindow(0,0,0,400,300,"ListIconGadget - centered text",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(0,10,10,380,280,"Column A",100)
AddGadgetColumn(0,1,"Column B",100)

AddGadgetItem(0,-1,"Test 1" + Chr(10) + "Test 2")
AddGadgetItem(0,-1,"Test 3" + Chr(10) + "Test 4")

class_addMethod_(delegateClass,sel_registerName_("tableView:willDisplayCell:forTableColumn:row:"),@CellDisplayCallback(),"v@:@@@@")
CocoaMessage(0,GadgetID(0),"setDelegate:",appDelegate)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
mk-soft
Always Here
Always Here
Posts: 5333
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Set alignment of ListIconGadget columns in PB 6

Post by mk-soft »

And

Code: Select all

CocoaMessage(0, Cell, "_setVerticallyCentered:", #YES)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Set alignment of ListIconGadget columns in PB 6

Post by Lebostein »

It is possible to transform this in a function like:

SetListIconColumnAlignment(GadgetID, ColumnIndex, Alignment)
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Set alignment of ListIconGadget columns in PB 6

Post by deseven »

It's possible, as a module for example, but inside you'll still have the same callback that defines how things should look like when they are being displayed.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Set alignment of ListIconGadget columns in PB 6

Post by Lebostein »

deseven wrote: Wed Oct 26, 2022 8:52 pm It's possible, as a module for example, but inside you'll still have the same callback that defines how things should look like when they are being displayed.
OK, but I need a callback? With the old implementation von ListView no callback was needed to change the alignment (see code in the first posting).
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Set alignment of ListIconGadget columns in PB 6

Post by deseven »

Lebostein wrote: Thu Oct 27, 2022 10:00 am OK, but I need a callback? With the old implementation von ListView no callback was needed to change the alignment (see code in the first posting).
Yes, you do need a callback now. But you can create an abstraction layer that will allow you to set alignment and other types of styling using simple procedure calls.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Set alignment of ListIconGadget columns in PB 6

Post by Lebostein »

Hard to understand for me. At the moment your callback functions is called 4 to 6 times per click (!) on this gadet. Is that really necessary?
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Set alignment of ListIconGadget columns in PB 6

Post by deseven »

You should ask Apple whether it's necessary or not, we can't control how often a callback is being called.
Docs for the reference: https://developer.apple.com/documentati ... guage=objc
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Set alignment of ListIconGadget columns in PB 6

Post by Lebostein »

The code seems not combatible with icons. Add this two lines before the Forever-Loop:
Biggest problem: #PB_EventType_Change is not triggered if you click in the gadget (or press the arrow keys up/down if a line is selected)

Code: Select all

EnableExplicit

#justifyLeft = 0
#justifyCenter = 1
#justifyRight = 2

Define app.i = CocoaMessage(0,0,"NSApplication sharedApplication")
Define appDelegate.i = CocoaMessage(0,app,"delegate")
Define delegateClass.i = CocoaMessage(0,appDelegate,"class")

ProcedureC CellDisplayCallback(Object.I,Selector.I,TableView.I,Cell.I,*Column,Row.I)
  Protected LineFrame.NSRect
  Protected RowFrame.NSRect
  Protected TextSize.NSSize
  Protected CellFrame.NSRect
  Protected BoldFontSize.CGFloat = 15.0
  Protected FontSize.CGFloat = 13.0
  Protected Column.i = CocoaMessage(0,CocoaMessage(0,TableView,"tableColumns"),"indexOfObject:",*Column)
  Protected Gadget.i = CocoaMessage(0,TableView,"tag")
  Protected CellText.s = GetGadgetItemText(Gadget,Row,Column)
  
  Select Column
    Case 0
      CocoaMessage(0,Cell,"setAlignment:",#justifyCenter)
    Case 1
      CocoaMessage(0,Cell,"setAlignment:",#justifyRight)
  EndSelect
  
  CocoaMessage(0,Cell,"setStringValue:$",@CellText)
  
EndProcedure

OpenWindow(0,0,0,400,300,"ListIconGadget - centered text",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(0,10,10,380,280,"Column A",100)
AddGadgetColumn(0,1,"Column B",100)

AddGadgetItem(0,-1,"Test 1" + Chr(10) + "Test 2")
AddGadgetItem(0,-1,"Test 3" + Chr(10) + "Test 4")

class_addMethod_(delegateClass,sel_registerName_("tableView:willDisplayCell:forTableColumn:row:"),@CellDisplayCallback(),"v@:@@@@")
CocoaMessage(0,GadgetID(0),"setDelegate:",appDelegate)

LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/File.bmp")
SetGadgetItemImage(0, 0, ImageID(0))

Repeat
  Define Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Debug "Gadget"
          If EventType() = #PB_EventType_Change
            Debug "Changed"
          EndIf
      EndSelect
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
User avatar
mk-soft
Always Here
Always Here
Posts: 5333
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Set alignment of ListIconGadget columns in PB 6

Post by mk-soft »

The gadget no longer works as it did before. The delegate of gadget can no longer be redirected and there is no column for the image.

PB now also uses the class PBIconTextCell for the ListIconGadget. Search for it in the forum
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Set alignment of ListIconGadget columns in PB 6

Post by Lebostein »

mk-soft wrote: Thu Nov 17, 2022 6:24 pm The gadget no longer works as it did before. The delegate of gadget can no longer be redirected and there is no column for the image.

PB now also uses the class PBIconTextCell for the ListIconGadget. Search for it in the forum
Yes, I know. My question was referred to the code that deseven suggested. I wonder why #PB_EventType_Change is not riggered with this code...
User avatar
mk-soft
Always Here
Always Here
Posts: 5333
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Set alignment of ListIconGadget columns in PB 6

Post by mk-soft »

Is also destroyed with setDelegate.

I wish for the old ListIconGadget back. This way, all the standard NSTableView functions of Objective-C will work again. :cry:
The one size adjustment in the old NSTableView would be:

Code: Select all

CocoaMessage(0, Cell, "_setVerticallyCentered:", #YES)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply