Modify text truncation in ListIconGadgets

Mac OSX specific forum
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Modify text truncation in ListIconGadgets

Post by Shardik »

In PB's ListIconGadget will text which doesn't fit completely into a column
be truncated in the middle and ellipsis will be displayed. But the underlying
DataBrowser API offers the feature to modify this truncation and let it happen
alternatively at the start, at the end or not at all. Unfortunately truncation at
the start seems to be broken since 2006 and seemingly has not been fixed
until now as this posting in the Apple Mailing Lists documents:
http://lists.apple.com/archives/Carbon- ... 00243.html

So don't blame me if you don't see any difference between "Truncate at the
start" and "Don't truncate": it's a still unfixed bug in MacOS X... :wink:

Code: Select all

ImportC ""
  GetDataBrowserTableViewColumnProperty(ControlRef.L, ColumnIndex.L, *ColumnPropertyID)
  SetDataBrowserPropertyFlags(ControlRef.L, ColumnPropertyID.L, PropertyFlags.L)
EndImport

#kDataBrowserPropertyFlagsOffset =   8
#kDataBrowserDoNotTruncateText   =   3 << #kDataBrowserPropertyFlagsOffset
#kDataBrowserTruncateTextAtEnd   =   2 << #kDataBrowserPropertyFlagsOffset
#kDataBrowserTruncateTextMiddle  =   0 << #kDataBrowserPropertyFlagsOffset
#kDataBrowserTruncateTextAtStart =   1 << #kDataBrowserPropertyFlagsOffset

Define TruncationMode.W

OpenWindow(0, 200, 100, 390, 190, "Modify text truncation in ListIconGadget")
ListIconGadget(0, 5, 5, WindowWidth(0) - 10, 95, "Name", 110)
AddGadgetColumn(0, 1, "Address", 249)
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")
AddGadgetItem(0, -1, "Didi Foundit"+ #LF$ + "321 Logo Drive, Mouse House, Downtown")
OptionGadget(1, 110, 105, 170, 20, "Don't truncate text")
OptionGadget(2, 110, 125, 170, 20, "Truncate text at start")
OptionGadget(3, 110, 145, 170, 20, "Truncate text in middle")
OptionGadget(4, 110, 165, 170, 20, "Truncate text at end")
SetGadgetState(3, #True)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If GetDataBrowserTableViewColumnProperty(GadgetID(0), 1, @ColumnID) = 0
        Select EventGadget()
          Case 1
            TruncationMode = #kDataBrowserDoNotTruncateText
          Case 2
            TruncationMode = #kDataBrowserTruncateTextAtStart
          Case 3
            TruncationMode = #kDataBrowserTruncateTextMiddle
          Case 4
            TruncationMode = #kDataBrowserTruncateTextAtEnd
        EndSelect

        SetDataBrowserPropertyFlags(GadgetID(0), ColumnID, TruncationMode)
      EndIf
  EndSelect
ForEver
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Modify text truncation in ListIconGadgets

Post by WilliamL »

Nice one, Shardik

I'd prefer the truncation at the end. :)
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Modify text truncation in ListIconGadgets

Post by jesperbrannmark »

Hi Shardik.
I see it only reacts to column 1 (and we are counting the first one as 0 so this is the right column).
Is this the proper way to get it going for all columns if i have 14 of them?

Code: Select all

For i=0 To 13
  If GetDataBrowserTableViewColumnProperty(GadgetID(#dayview_bookings), i, @ColumnID) = 0
    SetDataBrowserPropertyFlags(GadgetID(#dayview_bookings), ColumnID, #kDataBrowserDoNotTruncateText)
  EndIf
Next      
Or is there a better way?
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Modify text truncation in ListIconGadgets

Post by WilliamL »

I'm not sure how it is supposed to work...

[edit] Yeah, I gotta read the posts more carefully... a loop

but this works.

Code: Select all

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            TruncationMode = #kDataBrowserDoNotTruncateText
          Case 2
            TruncationMode = #kDataBrowserTruncateTextAtStart
          Case 3
            TruncationMode = #kDataBrowserTruncateTextMiddle
          Case 4
            TruncationMode = #kDataBrowserTruncateTextAtEnd
        EndSelect
        
        GetDataBrowserTableViewColumnProperty(GadgetID(0), 0, @ColumnID)
        SetDataBrowserPropertyFlags(GadgetID(0), ColumnID, TruncationMode)
        
        GetDataBrowserTableViewColumnProperty(GadgetID(0), 1, @ColumnID)
        SetDataBrowserPropertyFlags(GadgetID(0), ColumnID, TruncationMode)
  EndSelect
ForEver
Last edited by WilliamL on Wed Jun 22, 2011 4:51 pm, edited 1 time in total.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Modify text truncation in ListIconGadgets

Post by Shardik »

jesperbrannmark wrote:Hi Shardik.
I see it only reacts to column 1 (and we are counting the first one as 0 so this is the right column).
Is this the proper way to get it going for all columns if i have 14 of them?

Code: Select all

For i=0 To 13
  If GetDataBrowserTableViewColumnProperty(GadgetID(#dayview_bookings), i, @ColumnID) = 0
    SetDataBrowserPropertyFlags(GadgetID(#dayview_bookings), ColumnID, #kDataBrowserDoNotTruncateText)
  EndIf
Next      
Or is there a better way?
This would be the proper way if you define the gadget with the PB function ListIconGadget().
I assume that PB uses internally the API function CreateDataBrowserControl() to create the
ListIconGadget and internally the API function AddDataBrowserListViewColumn() to add a
new column. In one of the substructures (namely DataBrowserPropertyFlags) the default flag
kDataBrowserTruncateTextMiddle is set which causes text to be truncated in the middle.
Therefore you have to change the truncation for each column separately if you don't want
the default.

However if you would create your ListIcon with the API functions CreateDataBrowserControl()
and AddDataBrowserListViewColumn() you could define the truncation attribute directly but
that would be much more complicated, would require much more code and complicate callbacks
and you wouldn't be able to use any PB functions like GetGadgetText() but have to use the
appopriate API functions. So this would be an overkill.. :wink:


William,

your example would be indeed the right way to use for two columns but Jesper needed to
change the truncation behaviour for 14 columns... :wink:
Post Reply