PureLVSORT library : sorting ListIconGadgets (and more)

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

X wrote:Sorry, im talking about ListIconGadgets as I couldnt find a pure listbox in pb :(
It's the ListViewGadget (Windows class name = 'ListBox').
X wrote:As for the code, I was able to replicate the problem on this userlib's example. Modified example (from the help file for setcolumnType))below:
Ts-soft is right.
If you want case insensitive, why do you use #PureLVSORT_String_CaseSensitive ?
And as I said before, #PureLVSORT_String type (case insensitive) is default.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Cugel
New User
New User
Posts: 1
Joined: Fri May 15, 2009 4:13 am

Post by Cugel »

Is there a way to set the default sort order to descending?

Or, more specifically, I have a an unsorted column upon startup, set to sort numerically. When the user sorts this column, it's low->high, when I'd prefer it to be high->low on first sort.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Cugel wrote:I have a an unsorted column upon startup, set to sort numerically. When the user sorts this column, it's low->high, when I'd prefer it to be high->low on first sort.
1. You could use PureLVSORT_SortListIconNow() to set an initial sorting order after the listicon has been populated.
2. You could also set a custom sorting callback with PureLVSORT_DefineUserCallback() and define your own sorting order.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
rotacak
User
User
Posts: 77
Joined: Tue Feb 14, 2006 2:00 pm

Post by rotacak »

Is possible to use two different user callbacks?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

rotacak wrote:Is possible to use two different user callbacks?
No.
There is no need to, as the callback receives the listicon gadget id as parameter : you can use the same callback for several listicons.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

New version compiled with PB4.40 BETA 1 : http://freenet-homepage.de/gnozal/PureLVSORT_440.zip
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
ThoPie
User
User
Posts: 47
Joined: Sat Aug 22, 2009 6:49 pm

Sorting problem of german umlauts

Post by ThoPie »

I have a sorting problem with the german umlauts.

Now the sorting is:
aa
ab
oa
za
zb
öb

Is it possible to get the sorting result:
aa
ab
oa
öb
za
zb

Thank You.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

The sorting of special characters, like the german umlauts, are not supported by standard PB commands.

You will need to do it manually:
1) Including a special "abc" field in your structured linkedlist, where the ä is converted to ae, the ö to oe, etc.
2) Sort the list by this "abs" field.
3) Display the regular "name" with umlauts/special characters.

I think if Fred/Timo will include additional code into the sort commands to reflect the special characters automatically, this would be nice to have, but it will slow down the sorting process in general..... so don't think they will change anything.


PS: I've deleted your double post!
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Hi ThoPie, if you are talking about sorting with PureLVSORT, you may use :
  - PureLVSORT_DefineAlphabeticOrder(*UserArray)
  - PureLVSORT_DefineUserCallback(*UserCallbackAddress)
  to define your own custom sorting order.
If not, I guess your post is in the wrong thread ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Re: Sorting problem of german umlauts

Post by AND51 »

ThoPie wrote:Is it possible to get the sorting result:
aa
ab
oa
öb
za
zb
Yes, it is. A fantastic idea would be to implement a native possibility to set a custom sorting callback. You may add your idea to the linked feature request as well.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Polly
User
User
Posts: 29
Joined: Sat Jan 19, 2008 10:31 pm

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by Polly »

Hi, gnozal, PureLVSORT_GetFilterString is not working properly under Win7, as it seems to me. For columns where the user hasn't entered anything it returns garbage instead of empty string, with Pb 4.31 and 4.40b5.
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by dige »

Since Beta 5 a lot of bugs are fixed. may be gnozal could recompile the sources again?
thank you in advance!
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by gnozal »

Polly wrote:Hi, gnozal, PureLVSORT_GetFilterString is not working properly under Win7, as it seems to me. For columns where the user hasn't entered anything it returns garbage instead of empty string, with Pb 4.31 and 4.40b5.
I don't have Se7en, sorry.
dige wrote:Since Beta 5 a lot of bugs are fixed. may be gnozal could recompile the sources again?
Will do.
[EDIT]Done : recompiled PureLVSORT with PB4.40b5
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by dige »

Would be nice to have an additional parameter for PureLVSORT_SortListIconNow:

PureLVSORT_SortListIconNow(ListIconGadget.l, ListIconColumn.l, SortDirection.l, flags.b = #True)
flags = #True : Simulate click
flags = #True : Set Icon only

to reinitalise the gui after refill an listicon
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by gnozal »

dige wrote:Would be nice to have an additional parameter for PureLVSORT_SortListIconNow:
PureLVSORT_SortListIconNow(ListIconGadget.l, ListIconColumn.l, SortDirection.l, flags.b = #True)
flags = #True : Simulate click
flags = #True : Set Icon only
to reinitalise the gui after refill an listicon
I am not sure to understand what you are asking for ?
Set an icon without actually sorting ?
Try the example below :

Code: Select all

#MAX_pszText = 255
#HDI_TEXT = 2
#HDI_IMAGE = 32
#HDI_FORMAT = 4
#HDF_BITMAP_ON_LEFT = 0
#HDF_BITMAP_ON_RIGHT = 4096
#HDF_IMAGE = 2048
#HDF_STRING = 16384

Procedure SetHeaderImage(GadgetHandle.l, ImageIndex.l, Column.l, Align.l)
  ; ImageIndex : (using the lib's default images) 0 = first image [up], 1 = 2nd image [down]
  ; Align      : #HDF_BITMAP_ON_LEFT, #HDF_BITMAP_ON_RIGHT
  Protected Var.LVCOLUMN, VarHeader.HDITEM, TextColumn.s, HwndHeader.l, GadgetNumber.l
  ;
  Debug " Set Image ; Index = " + Str(ImageIndex.l)
  HwndHeader = SendMessage_(GadgetHandle, #LVM_GETHEADER, 0, 0)
  TextColumn = Space(#MAX_pszText + 1)
  Var\mask = #LVCF_TEXT | #LVCF_FMT
  Var\pszText = @TextColumn
  Var\cchTextMax = #MAX_pszText
  SendMessage_(GadgetHandle, #LVM_GETCOLUMN, Column, @Var)
  VarHeader\mask = #HDI_IMAGE | #HDI_FORMAT | #HDI_TEXT
  VarHeader\fmt = #HDF_IMAGE | Align | #HDF_STRING  | Var\fmt
  VarHeader\iImage = ImageIndex
  VarHeader\pszText = @TextColumn
  VarHeader\cchTextMax = Len(TextColumn)
  SendMessage_(HwndHeader, #HDM_SETITEM, Column, @VarHeader)
  ;
EndProcedure

#Window_0 = 0
#ListIcon_0 = 0
Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 602, 302, "PureLVSORT V2 Test", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
    ListIconGadget(#ListIcon_0, 5, 5, 590, 285, "String", 110)
    AddGadgetColumn(#ListIcon_0, 1, "Numeric", 110)
    AddGadgetColumn(#ListIcon_0, 2, "Float", 110)
    AddGadgetColumn(#ListIcon_0, 3, "DateDDMMYYYY", 120)
    AddGadgetColumn(#ListIcon_0, 4, "DateMMDDYYYY", 120)
    AddGadgetColumn(#ListIcon_0, 5, "FileSize", 120)
    AddGadgetColumn(#ListIcon_0, 6, "NoSorting", 120)
    AddGadgetItem(#ListIcon_0, -1, "ABCDE" + Chr(10) + "514" + Chr(10) + "0.9" + Chr(10) + "31/12/2004" + Chr(10) + "12/31/2004" + Chr(10) + "15.02 MB" + Chr(10) + "0")
    AddGadgetItem(#ListIcon_0, -1, "ACDEF" + Chr(10) + "118" + Chr(10) + "1.9" + Chr(10) + "11/12/2004" + Chr(10) + "12/11/2004"  + Chr(10) + "65 B" + Chr(10) + "1")
    AddGadgetItem(#ListIcon_0, -1, "ZABCD" + Chr(10) + "-414" + Chr(10) + "7.0" + Chr(10) + "21/01/2003" + Chr(10) + "01/21/2003" + Chr(10) + "5.98 GB" + Chr(10) + "3")
    AddGadgetItem(#ListIcon_0, -1, "DEFGH" + Chr(10) + "524" + Chr(10) + "900" + Chr(10) + "10/06/2001" + Chr(10) + "06/10/2001" + Chr(10) + "100 KB" + Chr(10) + "A")
  EndIf
EndProcedure
Open_Window_0()
; ListIcon Sort Setup
If PureLVSORT_SelectGadgetToSort(#ListIcon_0, #PureLVSORT_ShowClickedHeader_IconLeft) = #PureLVSORT_Ok
  PureLVSORT_SetColumnType(#ListIcon_0, 0, #PureLVSORT_String) ; default, not necessary
  PureLVSORT_SetColumnType(#ListIcon_0, 1, #PureLVSORT_Numeric)
  PureLVSORT_SetColumnType(#ListIcon_0, 2, #PureLVSORT_Float)
  PureLVSORT_SetColumnType(#ListIcon_0, 3, #PureLVSORT_DateDDMMYYYY)
  PureLVSORT_SetColumnType(#ListIcon_0, 4, #PureLVSORT_DateMMDDYYYY)
  PureLVSORT_SetColumnType(#ListIcon_0, 5, #PureLVSORT_FileSize)
  PureLVSORT_SetColumnType(#ListIcon_0, 6, #PureLVSORT_NoSorting)
EndIf
; Try with and without this line
SetHeaderImage(GadgetID(#ListIcon_0), 1, 0, #HDF_BITMAP_ON_LEFT)
;
Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply