PureLVSORT library : sorting ListIconGadgets (and more)

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

Moderator: gnozal

QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by QuimV »

:) Hi,
I'm testing the Filter Callback Function (in windows 7 and PB 4.41) using this code:

Code: Select all

Procedure MyFilterCallback(GadgetNumber.l, FilterString.s, ListIconColumn.l, EventCode.l) ; simple search example
  Protected itemNumber.l, I.l
  
  Debug FilterString 
  
  If FilterString 
    itemNumber = -1
    If IsGadget(GadgetNumber)
      ; Search for string
      For I = 0 To CountGadgetItems(GadgetNumber) - 1 
        If FilterString = GetGadgetItemText(GadgetNumber, I, ListIconColumn) 
          itemNumber = I
          Break
        EndIf 
      Next 
      ;
      If itemNumber <> -1 ; if string found, scroll to row
        PureLVSORT_ScrollToRow(GadgetNumber, itemNumber)
        SetGadgetItemState(GadgetNumber, itemNumber, GetGadgetItemState(GadgetNumber, itemNumber) | #PB_ListIcon_Selected)
      EndIf
    EndIf
  EndIf
EndProcedure
;
#Window_0 = 0 
#ListIcon_0 = 0 
;
Procedure Open_Window_0() 
  If OpenWindow(#Window_0, 216, 0, 602, 302, "PureLVSORT 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) 
      AddGadgetItem(#ListIcon_0, -1, "ABCDE" + Chr(10) + "514" + Chr(10) + "0.9" + Chr(10) + "31/12/2004" + Chr(10) + "12/31/2004") 
      AddGadgetItem(#ListIcon_0, -1, "ACDEF" + Chr(10) + "118" + Chr(10) + "1.9" + Chr(10) + "11/12/2004" + Chr(10) + "12/11/2004") 
      AddGadgetItem(#ListIcon_0, -1, "ZABCD" + Chr(10) + "-414" + Chr(10) + "7.0" + Chr(10) + "21/01/2003" + Chr(10) + "01/21/2003") 
      AddGadgetItem(#ListIcon_0, -1, "DEFGH" + Chr(10) + "524" + Chr(10) + "900" + Chr(10) + "10/06/2001" + Chr(10) + "06/10/2001") 
  EndIf 
EndProcedure 
;
Open_Window_0() 
;
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_SortListIconNow(#ListIcon_0, 3, 1)
  PureLVSORT_DefineFilterCallback(@MyFilterCallback())
  PureLVSORT_SetFilterTimeOut(100)
  PureLVSORT_SetFilter(#ListIcon_0)
EndIf 
; 
Repeat 
  Event = WaitWindowEvent() 
Until Event = #PB_Event_CloseWindow 
End

and I have found that when I erase a previous FilterString entered by keyboard, the callback function receive a FilterString strange (look at "Debug FilterString "), that is not "" (empty).

Thats only occurs in W7! in WXPSP3 all runs fine.

Thanks for your help
QuimV
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 »

QuimV wrote::) Hi,
I'm testing the Filter Callback Function (in windows 7 and PB 4.41) ... and I have found that when I erase a previous FilterString entered by keyboard, the callback function receive a FilterString strange (look at "Debug FilterString "), that is not "" (empty).
Thats only occurs in W7! in WXPSP3 all runs fine.
I don't have Se7en, so I can only imagine what's going wrong.
Anyway, I made a little change.
Could you test http://freenet-homepage.de/gnozal/PureLVSORT_TEST.zip (PB4.50 ANSI library version, copy to \PureBasic450\PureLibraries\UserLibraries\) ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by QuimV »

:( Hi gnozal,

The behaviour continue being wrong. I mean that when I erase the string entered by the keyboard, the gadget callback function receive a string different from "" (void string), in fact the string received by the callback function is garbage.

Thanks
QuimV
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 »

QuimV wrote::( Hi gnozal,

The behaviour continue being wrong. I mean that when I erase the string entered by the keyboard, the gadget callback function receive a string different from "" (void string), in fact the string received by the callback function is garbage.
Ok another try : I have updated http://freenet-homepage.de/gnozal/PureLVSORT_TEST.zip (PB4.50 ANSI library version, copy to \PureBasic450\PureLibraries\UserLibraries\).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by QuimV »

:( Nothing good. The same behaviour.
Thanks
QuimV
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 »

QuimV wrote::( Nothing good. The same behaviour.
Thanks
ye old code looks like this (ANSI PB4.xx version)

Code: Select all

...
        ElseIf *pNMHdr\hdr\code = #HDN_FILTERCHANGE Or *pNMHdr\hdr\code = #HDN_FILTERBTNCLICK ; filter string changed
          ; hHDItem.HDITEM, TFilter.HDTEXTFILTER
          TmpHeaderText = Space(#MAX_pszText + 1)
          TFilter\pszText = @TmpHeaderText
          TFilter\cchTextMax = #MAX_pszText
          hHDItem\mask = #HDI_FILTER 
          hHDItem\type = #HDFT_ISSTRING 
          hHDItem\pvFilter = @TFilter 
          hHeader = SendMessage_(WindowId, #LVM_GETHEADER, 0, 0) ; <--- get header handle
          If hHeader
            SendMessage_(hHeader,#HDM_GETITEM,*pNMHdr\iItem,@hHDItem) ; <--- get filter text
            If PureLVSORT_FilterCallBack
              CallFunctionFast(PureLVSORT_FilterCallBack, GetDlgCtrlID_(WindowId), TFilter\pszText, *pNMHdr\iItem, *pNMHdr\hdr\code) ; passes info to the user callback
...
I don't know where the problem might be...
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by QuimV »

Hi,

Would it be possible that you send a number to the callback filter function (TFilter\pszText) while the function should receive a string?

Code: Select all

Procedure MyFilterCallback(GadgetNumber.l, FilterString.s, ListIconColumn.l, EventCode.l)

   TFilter\pszText = @TmpHeaderText

CallFunctionFast(PureLVSORT_FilterCallBack, GetDlgCtrlID_(WindowId), TFilter\pszText, *pNMHdr\iItem, *pNMHdr\hdr\code) ; passes info to the user callback

The problem always appears when the string is zero lenght an only in this case,

:o I'm sorry, I don't know enough programming to be more efective helping you.

Thanks
QuimV
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 »

QuimV wrote:Would it be possible that you send a number to the callback filter function (TFilter\pszText) while the function should receive a string?
It is correct imho, it's a pointer to a zero terminated string.
But maybe it's an issue with CallFunctionFast() and Se7en.
I used a prototype instead in this new test lib : http://freenet-homepage.de/gnozal/PureLVSORT_TEST.zip (PB4.50 ANSI library version, copy to \PureBasic450\PureLibraries\UserLibraries\). Please test.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by QuimV »

:( Same behaviour. Garbage instead nullstring.
QuimV
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by QuimV »

gnozal,
Would it be possible to insert a debug message showing the text filter, at the place marked witn an *** in order to control the text filter that your library has received?

ElseIf *pNMHdr\hdr\code = #HDN_FILTERCHANGE Or *pNMHdr\hdr\code = #HDN_FILTERBTNCLICK ; filter string changed
; hHDItem.HDITEM, TFilter.HDTEXTFILTER
TmpHeaderText = Space(#MAX_pszText + 1)
TFilter\pszText = @TmpHeaderText
TFilter\cchTextMax = #MAX_pszText
hHDItem\mask = #HDI_FILTER
hHDItem\type = #HDFT_ISSTRING
hHDItem\pvFilter = @TFilter
hHeader = SendMessage_(WindowId, #LVM_GETHEADER, 0, 0) ; <--- get header handle
If hHeader
SendMessage_(hHeader,#HDM_GETITEM,*pNMHdr\iItem,@hHDItem) ; <--- get filter text

***
If PureLVSORT_FilterCallBack
CallFunctionFast(PureLVSORT_FilterCallBack, GetDlgCtrlID_(WindowId), TFilter\pszText, *pNMHdr\iItem, *pNMHdr\hdr\code) ; passes info to the user callback

Thank You
QuimV
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by QuimV »

Hi gnozal,

Testing EditCallback function (with W7_32 and PB4.50) I get the next error messages:

- Constant not Found: Case #PureLVSORT_EditStart
- Constant not Found: Case #PureLVSORT_EditText
- Constant not Found: Case #PureLVSORT_EditEnd
- Constant not Found: Case #PureLVSORT_EditEscape

Could you fix it?

Thanks in advanced
QuimV
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 »

Hi QuimV,
I have updated http://freenet-homepage.de/gnozal/PureLVSORT_TEST.zip.
It includes a fixed resident (for the missing constants) and a new library version, which shows the text filter that the library has received as a warning.

Code: Select all

Import "Debugger.lib" 
  DebugWarning(szError.s) As "_PB_DEBUGGER_SendWarning@4" 
EndImport 
...
            SendMessage_(hHeader,#HDM_GETITEM,*pNMHdr\iItem,@hHDItem)
            FilterText = PeekS(TFilter\pszText)
            ;
            DebugWarning("TFilter\pszText = '" + FilterText + "'")
            ;
            If PureLVSORT_FilterCallBack
              PureLVSORT_FilterCallBack(GetDlgCtrlID_(WindowId), FilterText, *pNMHdr\iItem, *pNMHdr\hdr\code)
...
You have to use this library only with debugger enabled and with warning level = 'Display warnings'.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by QuimV »

Hi @gnozal,

This is the debug output that I have received when I enter the string "DEFGH" and erase it letter by letter:

D
DE
DEF
DEFG
DEFGH
DEFG
DEF
DE
D
?/?/adgetStack_4194304
QuimV
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 »

QuimV wrote:...
?/?/adgetStack_4194304
Seems the memory is corrupted somehow, but I have no clue why.... the Purifier doesn't catch any problem.
Only with an empty string, and only with Se7en !?
Another try (I have updated http://freenet-homepage.de/gnozal/PureLVSORT_TEST.zip) : I check the TFilter\pszText pointer with IsBadStringPtr_().
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: PureLVSORT library : sorting ListIconGadgets (and more)

Post by QuimV »

This is the result in debug screen, with the word "test".

t
te
tes
test
tes
te
t
C
QuimV
Post Reply