Page 2 of 3

Posted: Sun Dec 12, 2004 6:59 pm
by Christian
PB_AlwaysShowSelection Also works now ... only one to go! :)

Posted: Wed Aug 03, 2005 6:59 am
by Xombie
Howdy!

I have a similar question to Christian's original question. Except, I don't need all the fancy multi-line stuff. I just want to be able to change the text color of individual lines based on the value in one of the columns. So if I have an 11 column listicon, I want a line to be red if the value in column 2 is non-zero. Normal and black otherwise. And that's all I need. Nothing else fancy. Is it possible? I'm trying to make this as lightweight and optimized as possible since the bulk of my program relies on multiple listicons and the speed of switching between them and selecting lines.

Thanks! ^_^

[Edit] Scratch that! I think I have it going now :D

Posted: Wed Aug 03, 2005 4:13 pm
by Xombie
Actually, I'm still having problems. If I make a change to the logic in the callback that controls which listicon line gets what color, the lines do not update with the color. They have to be redrawn somehow. For example, minimizing and then maximizing the window or selecting the lines, etc...

So, how can I force a repaint of the lines in a listicon control to show the new colors?

Posted: Sun Aug 21, 2005 10:00 am
by Christian
Hi Xombie,

to colorize a single line it is easier to use this little callback:

Code: Select all

;-- SetLIGadgetItemColor
#NM_CUSTOMDRAW       = -12   ; $FFFFFFF4

#CDRF_DODEFAULT = $0
#CDDS_PREPAINT       = 1     ; $00000001
#CDRF_NOTIFYITEMDRAW = 32    ; $00000020
#CDRF_NEWFONT        = 2     ; $00000002
#CDDS_ITEM           = 65536 ; $00010000

#CDDS_ITEMPREPAINT   = #CDDS_ITEM | #CDDS_PREPAINT

;- Constants
#Window_Main_ID = 0
#Window_Main_Width = 500
#Window_Main_Height = 500

#Gadget_ListIcon_ID = 0

;- Variables
Global WMID.l ; - Handle of the main window

;- Procedures
Procedure SetLIGadgetItemColor(GadgetID.l, lParam.l) 
 *nml.NMLVCUSTOMDRAW = lParam
 ; - Copy CustomDraw Structure 

 Select *nml\nmcd\dwDrawStage
  Case #CDDS_PREPAINT                        ; - tell Windows that every line has to be painted seperatly
    Result = #CDRF_NOTIFYITEMDRAW

  Case #CDDS_ITEMPREPAINT                    ; - colorize lines
    If *nml\nmcd\hdr\idFrom = GadgetID
        For a = 0 To CountGadgetItems(GadgetID)
          If *nml\nmcd\dwItemSpec = a
              ; - paint text red if column 2 is non-zero
              If GetGadgetItemText(GadgetID, a, 1) <> "0"
                  *nml\clrTextBk = RGB(200,   0,   0) ; Background Color
                  *nml\clrText   = RGB(255, 255, 255) ; Text Color
              Else
                  *nml\clrTextBk = RGB(255, 255, 255) ; Background Color
                  *nml\clrText   = RGB(  0,   0,   0) ; Text Color
              EndIf

             Result = #CDRF_NEWFONT
          EndIf
        Next a
    EndIf
 EndSelect

ProcedureReturn Result
EndProcedure

Procedure ColorCallback(WindowID, Message, wParam, lParam)
 Result = #PB_ProcessPureBasicEvents 
    Select Message

      Case #WM_NOTIFY
        *hdr.NMHDR = lParam
        Select wParam
         Case #Gadget_ListIcon_ID ; - Your ListIconGadget
           If *hdr\code = #NM_CUSTOMDRAW
               Result = SetLIGadgetItemColor(#Gadget_ListIcon_ID, lParam)
           EndIf
        EndSelect

    EndSelect
 
 ProcedureReturn Result
EndProcedure

;- Program
WMID = OpenWindow(#Window_Main_ID, 0, 0, #Window_Main_Width, #Window_Main_Height, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListIcon with Colored Lines")
If WMID
    If CreateGadgetList(WMID)
        ListIconGadget(#Gadget_ListIcon_ID, 0, 0, WindowWidth(), WindowHeight(), "Column 1", 150, #PB_ListIcon_FullRowSelect)
         AddGadgetColumn(#Gadget_ListIcon_ID, 1, "Column 2", WindowWidth()-155)
         For a = 0 To 50
           AddGadgetItem(#Gadget_ListIcon_ID, -1, "Line "+Str(a)+Chr(10)+"0")
           AddGadgetItem(#Gadget_ListIcon_ID, -1, "Line "+Str(a)+Chr(10)+"Non-Zero")
         Next a
    EndIf
    SetWindowCallback(@ColorCallback())

Repeat
 Select WaitWindowEvent()

  Case #PB_Event_CloseWindow
    quit = #TRUE 

 EndSelect
Until quit = #TRUE
EndIf
Hope that is what you wanted to do!

Regards,
Christian

Posted: Tue Jun 17, 2008 11:27 am
by Ollivier
This code is good for multiline text : is there a way to change the height of one line only ? (ex : SetLineHeight() )
Or, do these settings above allow us to change ALL rows in one time ?

Thank you!

Posted: Tue Jun 17, 2008 11:45 am
by srod
No way of doing that with a ListIcon I'm afraid. The closest you would probably get (without a custom window class) would be to use an owner-drawn PB ListView gadget (Windows ListBox) and set the #LBS_OWNERDRAWVARIABLE style etc. A lot of work if you then try to use one of these to mimick a ListIcon.

Posted: Tue Jun 17, 2008 1:05 pm
by Ollivier
Thank you Srod. I remember you had a code using editorgagdet for each cell (Perhaps my memory is wrong! )

Do you think it's possible creating one little editorgadget per cell which the size is managed by splittergadgets ?

Ollivier

Posted: Tue Jun 17, 2008 1:22 pm
by srod
Ollivier wrote:Thank you Srod. I remember you had a code using editorgagdet for each cell (Perhaps my memory is wrong! )
Ah, a long long time ago, in a galaxy far far away... :) I once created a basic grid using an array of string gadgets. It was pretty crude, incomplete, inefficient.... a pile of garbage basically! :wink:
Do you think it's possible creating one little editorgadget per cell which the size is managed by splittergadgets ?
In short, no! The overhead would be horrendous, the flicker would send your monitor into orbit...... It just wouldn't be worth the hassle. You will need some kind of custom solution; either a 3rd party grid control allowing for variable row-heights (have a look at xgrid or csgrid) or proceed with an owner-drawn PB ListView gadget etc.

Posted: Tue Jun 17, 2008 3:00 pm
by Ollivier
I discover your site. You've ideas! It's good! Thanks for your answers.

Ollivier

Posted: Tue Oct 07, 2008 4:59 pm
by Fluid Byte
Who do you mean?

Posted: Sat Jul 25, 2009 1:41 pm
by Donald
Hello,

has someone which for the 4,31 version ?


Donald


..

Posted: Sun Jul 26, 2009 3:30 pm
by Sparkie
Donald, I have edited my code on page 1 to be PB 4.3x compatible.

Posted: Sun Jul 26, 2009 3:53 pm
by netmaestro
I missed seeing this one along the way. Nice work, Sparkie! 8)

Posted: Sun Jul 26, 2009 4:05 pm
by RASHAD
You said PureBatman Forever
Be as you said do not cut it off

Posted: Tue Jul 28, 2009 1:45 am
by Sparkie
Thanks netmaestro. I was still pretty new to PB at the time so I may have to take a look now and see if I can improve on it.

@RASHAD: I promise not to cut it off ;)