ListboxTV (MBS plugins)

Thomas did a great job creating a native NSTableView control for macOS (called ListboxTV in the MBS plugin examples).

The only thing missing is the ability to add custom cells.

Any luck/help how to implement this (with example) would be very highly appreciated. :slight_smile:

What kind of custom cells? You mean like a NSCell or NSView that contains other controls?

I believe the code (or one of the various versions) offers that ability, i.e. there’s code paths for NSCell-based vs NSView-based Tables (one cannot use both at the same time). See what you can find.

I did not find an example with NSView based tables. Also, the current examples found in the MBS example folder do not work correctly when compiled to 64bit. Some ‘Single’ properties needs to be replaced with ‘CGFloat’.

Maybe you can provide Christian the latest version (including example)? :slight_smile:

Try removing the code from the event ListBoxTV.willDisplayCell, and then return your custom NSView in the adjacent ListBoxTV.view() event. That’s standard NSTableView behavior and you can get help from MBS support about that, I’m sure. It’s not something that helps emulating the Xojo ListBox, so I won’t put extra work in that for you unless you’re willing to pay for that :wink:

In fact, if I insert this code into the ListBoxTV.view event, I get a button in every cell:

dim bc as new NSButtonMBS bc.title = "row "+Str(row,"#")+" col "+tableColumn.identifier return bc

You do not even have to remove the code from the ListBoxTV.willDisplayCell event for that.

So, this should be pretty easy to implement for you.

About the Single types for 64 bit:

My projects contain #if Target64bit clauses for that purpose in ListBoxTV_Support.ListDrawCellHandler.drawWithFrame. Do you not have them in your version, or are there other places where these are missing?

[quote=400585:@Thomas Tempelmann]In fact, if I insert this code into the ListBoxTV.view event, I get a button in every cell:

[/quote]

Ha, cool. I even could link a container to the NSView.

EDIT: It seems adding a Container doesn’t work very good. Only the last added row displays the Container view. :-/

[code]Function view(tableColumn as NSTableColumnMBS, row as Integer) Handles view as NSViewMBS
dim b as NSViewMBS

dim c as new ContainerControl1
ContainersArray.Append c

c.EmbedWithin(self, 10000, 10000)

b = c.NSViewMBS
return b
End Function[/code]

Xojo creates NSView only, if you put Container in window. And you need to keep array with containers to store them for later. Otherwise they get released too early.

I’ve updated the Hierarchical version of ListboxTV, adding the ability to remove rows and to drag-reorder them.

Find the new version here: http://ln111.myplesk.cc/files.tempel.org/RB/Listbox%20TableView

See the Notes in the ListboxTV class, or use my Arbed tool (Compare Projects) to see what’s changed.

File not found. Correct link is http://files.tempel.org/RB/Listbox%20TableView/ .

There’s a new version out, see http://files.tempel.org/RB/Listbox%20TableView

This includes:

  • A new demo that uses ContainerControls to make custom Listbox Cells. Very neat!
  • Fixes the wrong gap reserved for the vertical scrollbar on the right.

Great work Thomas!

Using containers as a NSCell is awesome and it now can fully replace the awful Xojo Listbox for macOS. It makes your macOS looks like it should and behave too.
The performance is very fast too - miles ahead of the Xojo Listbox.

Basically, if you have the MBS plugins and are making a macOS app, you definitely should use this instead of the Listbox.

New version 5 now available. This one fixes a flicker issue with the ContainerControl example, improves AddRow() to allow multiple column values to be passed and adds a IntercellSpacing property so that one can easily remove the gaps between cells.

I just updated several apps with the ListboxTV (read: NSTableView). They look, work and behave a lot better now.

Finally a native way to list your items instead of using the non-native Listbox control.

In short, ListboxTV is a must’ve for all Xojo macOS coders.

Working with the ListBoxTV OutlineView example from MBS, I found this in ListBoxTV.dataCell:

// We return a custom NSTextFieldCell, in order to perform some custom painting in its drawWithFrame event handler.
// We are lazy and re-use the same cell, because we keep getting this event called for each drawn cell, sequentially.
static cc As ListBoxTV_Support.ListDrawCellHandler

This works fine usually, but when collapsing or expanding a row in the outline view, all cells show the same value for a split second for as long as the collapse/expand animation is ongoing.
Changing to

dim cc As ListBoxTV_Support.ListDrawCellHandler

Solves the issue, and luckily (for me at least) the repeated allocation isn’t a huge performance hit.

This is most likely never an issue if the list is flat.

Thomas, thank you for this great work!

Okay, how about this:

I’ve published the code on github: https://github.com/tempelmann/XojoListboxTV

Do you have a github account? If you do, would you please add this as an issue there? If you do not, I’ll just add your text myself. Just want to give you credit for it. Then I’ll update the code as well there.

Submitted issue on GitHub. Thanks!

Fixed and closed. Thanks!