help ListIcon Justify Column Right

Linux specific forum
thierry94
User
User
Posts: 14
Joined: Mon Oct 08, 2007 12:37 pm
Location: france

help ListIcon Justify Column Right

Post by thierry94 »

hi,

this code is ok on purebasic 4.30 RHEL 5 (x86)

but on purebasic 5.10 RHEL 6.3 (x64)
[ERROR] line: 85 : g_object_set_double(g_list_nth_data_(*CellRenderers, i), "xalign", AlignmentFactor, #Null)
[ERROR] Invalid memory Access.

Code: Select all

EnableExplicit
CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    ImportC ""
      g_object_set_double(*Object, Property.P-ASCII, Value.D, Null) As "g_object_set"
    EndImport
  CompilerCase #PB_OS_MacOS
    #kControlUseJustMask = $0040
    #teCenter = 1
    #teFlushRight = -1
    #teFlushLeft = -2

    ImportC ""
      GetDataBrowserListViewHeaderDesc(DataBrowserRef, ColumnID, *HeaderDesc)
      GetDataBrowserTableViewColumnProperty(DataBrowserRef, Column, *ColumnID)
      HiliteControl(ControlRef, ControlPart)
      SetControlVisibility(ControlRef, IsVisible, DoDraw)
      SetDataBrowserListViewHeaderDesc(DataBrowserRef, ColumnID, *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
CompilerEndSelect

Enumeration
  #PB_ListIcon_JustifyColumnLeft
  #PB_ListIcon_JustifyColumnCenter
  #PB_ListIcon_JustifyColumnRight
EndEnumeration

Procedure SetListIconColumnJustification(ListIconID, Column, Alignment)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      Protected AlignmentFactor.D
      Protected *CellRenderers
      Protected *Column
      Protected Count
      Protected i

      Select Alignment
        Case #PB_ListIcon_JustifyColumnLeft
          AlignmentFactor = 0.0
        Case #PB_ListIcon_JustifyColumnCenter
          AlignmentFactor = 0.5
        Case #PB_ListIcon_JustifyColumnRight
          AlignmentFactor = 1.0
      EndSelect

      *Column = gtk_tree_view_get_column_(GadgetID(ListIconID), Column)

      If *Column
        gtk_tree_view_column_set_alignment_(*Column, AlignmentFactor)
        *CellRenderers = gtk_tree_view_column_get_cell_renderers_(*Column)

        If *CellRenderers
          Count = g_list_length_(*CellRenderers)

          For i = 0 To Count - 1
            g_object_set_double(g_list_nth_data_(*CellRenderers, i), "xalign", AlignmentFactor, #Null)
          Next i         

          g_list_free_(*CellRenderers)
        EndIf
      EndIf
    CompilerCase #PB_OS_MacOS
      Protected ColumnID.L
      Protected HeaderDesc.DataBrowserListViewHeaderDesc

      If GetDataBrowserTableViewColumnProperty(GadgetID(0), Column, @ColumnID) = 0
        If GetDataBrowserListViewHeaderDesc(GadgetID(0), ColumnID, @HeaderDesc) = 0
          HeaderDesc\FontStyle\Flags = #kControlUseJustMask
         
          Select Alignment
            Case #PB_ListIcon_JustifyColumnLeft
              HeaderDesc\FontStyle\Just = #teFlushLeft
            Case #PB_ListIcon_JustifyColumnCenter
              HeaderDesc\FontStyle\Just = #teCenter
            Case #PB_ListIcon_JustifyColumnRight
              HeaderDesc\FontStyle\Just = #teFlushRight
          EndSelect
         
          SetDataBrowserListViewHeaderDesc(GadgetID(0), ColumnID, @HeaderDesc)
        EndIf
      EndIf
    CompilerCase #PB_OS_Windows
      Protected ListIconColumn.LV_COLUMN

      ListIconColumn\mask = #LVCF_FMT

      Select Alignment
        Case #PB_ListIcon_JustifyColumnLeft
          ListIconColumn\fmt = #LVCFMT_LEFT
        Case #PB_ListIcon_JustifyColumnCenter
          ListIconColumn\fmt = #LVCFMT_CENTER
        Case #PB_ListIcon_JustifyColumnRight
          ListIconColumn\fmt = #LVCFMT_RIGHT
      EndSelect

      SendMessage_(GadgetID(ListIconID), #LVM_SETCOLUMN, Column, @ListIconColumn)
  CompilerEndSelect
EndProcedure

OpenWindow(0, 200, 100, 445, 90, "Right justify 1st column")
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")

SetListIconColumnJustification(0, 0, #PB_ListIcon_JustifyColumnRight)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

User avatar
idle
Always Here
Always Here
Posts: 5097
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: help ListIcon Justify Column Right

Post by idle »

testing it on ubuntu 12.04 x64 PB 5.10
compiles in ascii mode and justifies the text
compiles in unicode doesn't justify the text, even when changing the Property to p-utf8

Code: Select all

 g_object_set_double(*Object, Property.p-Ascii, Value.d, Null) As "g_object_set"
Windows 11, Manjaro, Raspberry Pi OS
Image
thierry94
User
User
Posts: 14
Joined: Mon Oct 08, 2007 12:37 pm
Location: france

Re: help ListIcon Justify Column Right

Post by thierry94 »

thx

please, how to get around this problem or how to use a different code

gtk2-devel-2.18.9-10.el6.x86_64
gtk2-2.18.9-10.el6.x86_64
User avatar
Shardik
Addict
Addict
Posts: 1991
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: help ListIcon Justify Column Right

Post by Shardik »

@thierry94,
it would have been nice if you had posted a link to the thread from which you have copied my entire example code:
http://www.purebasic.fr/english/viewtop ... 31&start=8

I have tested my example code with PB 5.10 x64 on Kubuntu 12.04 LTS x64 and Ubuntu 12.04 LTS x64 with file format "Plain text" and "Utf8" and with Compiler Option "Create unicode executable" enabled and disabled. With all settings my example code works as it should and right justifies the first column. So sorry, that I can't reproduce your problem and be of any help...

@idle,
I don't understand why the right justification of the first column doesn't work on your Ubuntu 12.04 x64 when testing with Unicode. I can't reproduce your finding on Ubuntu 12.04 x64 and PB 5.10 x64...
User avatar
idle
Always Here
Always Here
Posts: 5097
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: help ListIcon Justify Column Right

Post by idle »

Shardik wrote: @idle,
I don't understand why the right justification of the first column doesn't work on your Ubuntu 12.04 x64 when testing with Unicode. I can't reproduce your finding on Ubuntu 12.04 x64 and PB 5.10 x64...
I don't know why it's failing in unicode mode on my system.
The only way I can get it to work is changing the import to a *property.p-ascii
and poking the xalign

I'm using a clean install of PB 5.10 final

Code: Select all

 If *CellRenderers
          Count = g_list_length_(*CellRenderers)
          len = Len("xalign")
          *str = AllocateMemory(Len)
          PokeS(*str,"xalign",len,#PB_Ascii)
          For i = 0 To Count - 1
             g_object_set_double(g_list_nth_data_(*CellRenderers, i),*str, AlignmentFactor, #Null)
          Next i         
         FreeMemory(*str)
          g_list_free_(*CellRenderers)
        EndIf
Windows 11, Manjaro, Raspberry Pi OS
Image
thierry94
User
User
Posts: 14
Joined: Mon Oct 08, 2007 12:37 pm
Location: france

Re: help ListIcon Justify Column Right

Post by thierry94 »

i have found

i have replaced

Code: Select all

 g_object_set_double(g_list_nth_data_(*CellRenderers, i), "xalign", AlignmentFactor, #Null)
by

Code: Select all

        *Cellule.GtkCellRenderer = g_list_nth_data_(*CellRenderers, I)
        *Cellule\xalign=AlignmentFactor
 
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

Re: help ListIcon Justify Column Right

Post by mestnyi »

Who knows why is not aligned text in columns or how to do it? in linux.
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

Re: help ListIcon Justify Column Right

Post by mestnyi »

I found the cause of.

Code: Select all

ImportC ""
        gtk_tree_view_column_set_alignment(*tree_column, xalign.f);             replaced PureBasic's V5.* buggy: gtk_tree_view_column_set_alignment_(*Column, Alignment)
      EndImport
      
Now it is necessary to size an item avtosize
Post Reply