Page 1 of 1

Change column justification in ListIconGadget

Posted: Tue Feb 21, 2012 9:43 pm
by Shardik
This code example demonstrates how to change the justification
of ListIconGadget columns during runtime. For a cross-platform
solution take a look into this posting.

Code: Select all

EnableExplicit

#kControlUseJustMask = $0040
#teCenter = 1
#teFlushRight = -1
#teFlushLeft = -2

ImportC ""
  GetDataBrowserListViewHeaderDesc(DataBrowserRef.L, ColumnID.L, *HeaderDesc)
  GetDataBrowserTableViewColumnProperty(DataBrowserRef.L, Column.L, *ColumnID)
  SetDataBrowserListViewHeaderDesc(DataBrowserRef.L, ColumnID.L, *HeaderDesc)
EndImport

Structure RGBColor
  Red.U
  Green.U
  Blue.U
EndStructure

Structure ControlFontStyleRec
  Flags.W
  Font.W
  Size.W
  Style.W
  Mode.W
  Just.W
  ForeColor.RGBColor
  BackColor.RGBColor
EndStructure

Structure DataBrowserListViewHeaderDesc
  Version.L
  MinimumColumnWidth.U
  MaximumColumnWidth.U
  TitleOffset.W
  CFTitleString.L
  InitialSortOrder.U
  FontStyle.ControlFontStyleRec
  IconInfo.L
EndStructure

Procedure SetListIconColumnJustification(ListIconID.L, Column.L, OptionGadgetID.L)
  Protected ColumnID.L
  Protected FontStyle.ControlFontStyleRec
  Protected HeaderDesc.DataBrowserListViewHeaderDesc
  
  If GetDataBrowserTableViewColumnProperty(GadgetID(0), Column, @ColumnID) = 0
    If GetDataBrowserListViewHeaderDesc(GadgetID(0), ColumnID, @HeaderDesc) = 0
      HeaderDesc\FontStyle\Flags = #kControlUseJustMask
      
      Select OptionGadgetID
        Case 2
          HeaderDesc\FontStyle\Just = #teFlushLeft
        Case 3
          HeaderDesc\FontStyle\Just = #teCenter
        Case 4
          HeaderDesc\FontStyle\Just = #teFlushRight
      EndSelect
      
      SetDataBrowserListViewHeaderDesc(GadgetID(0), ColumnID, @HeaderDesc)
    EndIf
  EndIf
EndProcedure

Define GadgetID.L

OpenWindow(0, 200, 100, 445, 160, "Change column justification")
ListIconGadget(0, 5, 5, 435, 80, "Name", 110)
AddGadgetColumn(0, 1, "Address", 300)
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")
Frame3DGadget(1, 10, 100, WindowWidth(0) - 20, 50, "Justification of 2nd column:")
OptionGadget(2, 20, 120, 70, 20, "Left")
OptionGadget(3, 180, 120, 70, 20, "Center")
OptionGadget(4, 330, 120, 70, 20, "Right")
SetGadgetState(2, #True)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      GadgetID = EventGadget()

      Select GadgetID
        Case 2 To 4
          SetListIconColumnJustification(0, 1, GadgetID)
      EndSelect
  EndSelect
ForEver

Re: Change column justification in ListIconGadget

Posted: Tue Feb 21, 2012 9:49 pm
by Polo
You should not us Carbon API anymore as Fred & Freak are to release a Cocoa gadget library in one of the next PB releases :)

Re: Change column justification in ListIconGadget

Posted: Tue Feb 21, 2012 10:00 pm
by WilliamL
Hey Shardik! Thanks for the code! Nice addition to my columns. :)

@Polo
I'm looking forward to Cocoa. I hope that the gadgets in Cocoa have more options like color, justification, etc. :wink:

Re: Change column justification in ListIconGadget

Posted: Tue Feb 21, 2012 10:05 pm
by Shardik
Polo wrote:You should not us Carbon API anymore as Fred & Freak are to release a Cocoa gadget library in one of the next PB releases :)
I have of course read Fred's blog announcement of the release of
a Cocoa framework based MacOS X version of PB. But I assume
that it will take several releases until a workable cocoaified PB
version with most bugs eliminated will be released. Until this
point is reached I will still develop using Carbon... :wink:

And I hope that it will be still possible to select Carbon as a
subsystem in PB 4.70.

Re: Change column justification in ListIconGadget

Posted: Tue Feb 21, 2012 10:07 pm
by Polo
WilliamL wrote: @Polo
I'm looking forward to Cocoa. I hope that the gadgets in Cocoa have more options like color, justification, etc. :wink:
Me too!
What's for sure is it should include Lion's new scrollbars for most gadgets, rounded bottom window without the white resize box, the height resize limit (which forbid the user to go under the dock) etc etc :)

Re: Change column justification in ListIconGadget

Posted: Tue Feb 21, 2012 10:13 pm
by Shardik
WilliamL wrote:Hey Shardik! Thanks for the code! Nice addition to my columns. :)
I am glad that my code example is useful for you, William. It
cost me a lot of time because of a simple beginner's mistake
and it lets me believe that I might have become too old for
programming... :evil:
WilliamL wrote:I'm looking forward to Cocoa. I hope that the gadgets in Cocoa have more options like color, justification, etc. :wink:
I am working on a Carbon solution for coloring Gadgets now for
more than half a year... 8)

Re: Change column justification in ListIconGadget

Posted: Tue Feb 21, 2012 10:35 pm
by Shardik
Polo wrote:What's for sure is it should include Lion's new scrollbars for most gadgets, rounded bottom window without the white resize box, the height resize limit (which forbid the user to go under the dock) etc etc :)
Some features like the rounded bottom of a window and a
transparent resize box (for which I already posted this example
code
for you) is perfectly possible with Carbon (although not
easy to achieve, I am still working on it... :twisted: ). Here is a demo
of a Carbon window:

Image

Re: Change column justification in ListIconGadget

Posted: Tue Feb 21, 2012 11:48 pm
by Polo
True, just can't wait to have it right out of the box and minus the Carbon bugs on Lion :)