Page 2 of 2

Re: How to automatically resize the last column of a ListIco

Posted: Tue Jul 06, 2010 2:35 am
by Jihugen
GeBonet wrote:Hi,
I thing you can try the "PureLVSORT_SetLastColumnAutoResize(GadgetNumber.l, TrueOrFalse.l)"
of Gnozal Library... ? :?:
Hi, I explained in 1st post why I didn't want to use this lib.
Jihugen wrote:It would be the equivalent of PureLVSORT_SetLastColumnAutoResize() in one of the excellent Gnozal's libs (PureLVSORT).
But I don't want to be dependent of this lib, because I don't need sorting features, and I'm using Set/GetGadgetItemData().
Well, lately I tried a lot of ways, subclasssing listicon gadget or modifying window callback, intercepting listiscon messages or header messages, etc etc.
I think the best I have achieved for now is by intercepting CDDS_PREPAINT message of the listicon header:

Code: Select all

Enumeration
  #Window
EndEnumeration

Enumeration
  #ListIcon
  #Button
EndEnumeration

Procedure CallBack_MainWin (iWindowID, iMessage, wParam, lParam)
  result = #PB_ProcessPureBasicEvents 
  
  Select iMessage
    Case #WM_NOTIFY
      *pnmh.NMHDR = lParam
      If *pnmh\code = #NM_CUSTOMDRAW
        *lpNMCustomDraw.NMLVCUSTOMDRAW = lParam
        *pnmcd.NMCUSTOMDRAW = *lpNMCustomDraw\nmcd
        Select *pnmcd\dwDrawStage
          Case #CDDS_PREPAINT
            Static a : Debug a : a+1 ; Display counter
            SendMessage_(*pnmh\hwndFrom, #LVM_SETCOLUMNWIDTH, 1, #LVSCW_AUTOSIZE_USEHEADER)
        EndSelect
      EndIf
  EndSelect
  
  ProcedureReturn result
EndProcedure

If OpenWindow(#Window, 450, 200, 400, 185, "test", #PB_Window_SystemMenu|#PB_Window_TitleBar)
  ListIconGadget(#ListIcon, 15, 20, 200, 150, "1", 150, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
  
  AddGadgetColumn(#ListIcon, 1, "2", 50)
  ButtonGadget(#Button, 240, 20, 140, 30, "Add items", #PB_Button_Toggle)
  
  SetWindowCallback(@CallBack_MainWin())
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Button
            ClearGadgetItems(#ListIcon)
            If GetGadgetState(#Button)
              For i = 0 To 20
                AddGadgetItem(#ListIcon, -1, Str(i))
              Next
            EndIf           
        EndSelect
      Case #PB_Event_CloseWindow
        CloseWindow(#Window)
        Break
    EndSelect
  ForEver
EndIf
Unfortunately, a #LVM_SETCOLUMNWIDTH message is still constantly fired when using the horizontal or the vertical scrollbars.

I'm getting quite bored not being able to get a better result after all my attempts, and trying to modify some code blindly with hope it will magically works is not very fun...
For now, I think I can't do better, so I'll probably stick with the code above, or just use LVSCW_AUTOSIZE_USEHEADER each time I modify the content of my list, or maybe simply the PB's tip.

Re: How to automatically resize the last column of a ListIco

Posted: Tue Jul 06, 2010 9:08 am
by GeBonet
Excuse me,
I have Not really Read the first message.
But i think that even without using all the functions PureLVSORT, there are enough opportunities other than just sort!

Now without using other, just PB, it is possible to have all columns ListIconGadget or other with a width in agreement with its contents with a form of code as below ...

If i add a line and i have a wider column, so i change the header and refresh the display !
Thus all the columns are always adjusted to the content and also the last.
No other function are used than those of PB, or even To call API ...

In this code i have one array with the name "TableFichier(i,j)" and one array with with each max width !
When i create the ListIconGadget, if it is the first ligne (0) i create the width with the Lg_Table(j).

Table TableFichier (i, j) contains the data and Lg_Table (j) contains the maximum width of each column
and depending TableFichier (i, j) and (i, j = row and column) !

Code: Select all

;-------------------------- La grille des données ------------------------------------
; PART 1                
For j=1 To Nb_Column      ;    Firts row and first column
      Mot$=TableFichier(0,j)
      If j=1
           Caract=0
           Caract | #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes
           Caract | #PB_ListView_ClickSelect|#PB_ListIcon_FullRowSelect ; ,#PB_ListIcon_FullRowSelect
           Caract | #PB_ListIcon_AlwaysShowSelection:Mot$=Right(Mot$,Lg_Table(1)+2) 
           ListIconGadget(#Liste   ,10,20,ww-10 , wh-70  , Mot$+":",25+Lg_Table(j)*6,Caract)
      Else
            AddGadgetColumn(#Liste, j ,Mot$+":",20+Lg_Table(j)*4) ;
            SetGadgetItemData(#Liste, j, j)
      EndIf
 Next j
 ;  * * * * * * * * * * * * * * * * * * * * * Display the content of the file * * * * * * * * * * * * * * * * * * *        
 ; PART 2
 For i=1 To line-1              ; Other Line and Column 
       Verifie$=""
       For j=1 To Nb_Column
            Verifie$+TableFichier(i,j)+Chr(10) 
       Next j
      ; Passage Data of the table to ListeGadget... 
       Verifie$+TableFichier(ligne,Nb_Colonne)
      AddGadgetItem (#Liste ,-1,Verifie$)
 Next i
It's just a way of doing things, but there are others! :wink: