ListIconGadget - Multiline Entry

Just starting out? Need help? Post your questions and find answers here.
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

PB_AlwaysShowSelection Also works now ... only one to go! :)
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post 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
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post 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?
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post 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
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post 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!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

I discover your site. You've ideas! It's good! Thanks for your answers.

Ollivier
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Who do you mean?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Donald
User
User
Posts: 15
Joined: Fri Jan 07, 2005 1:29 am
Location: Germany

Post by Donald »

Hello,

has someone which for the 4,31 version ?


Donald


..
DONALD :D http://www.PureBasic-Donald.de
PureBasic - jaPBe - PureFORM - PureVisonXP - TailBite
GFABasic 16Bit 4.38 - GB32 2.30 B1160 - GFABasic DOS 4.51
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Donald, I have edited my code on page 1 to be PB 4.3x compatible.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I missed seeing this one along the way. Nice work, Sparkie! 8)
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Post by RASHAD »

You said PureBatman Forever
Be as you said do not cut it off
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply