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 »

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: 8452
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: 4996
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
Phantomas
User
User
Posts: 96
Joined: Wed Jul 01, 2009 12:59 pm

Re: ListIconGadget - Multiline Entry

Post by Phantomas »

How I can add multiline support in this code?

Code: Select all

Enumeration
  #window_jor
  #list_jor_errors
EndEnumeration

If OpenWindow(#window_jor, #PB_Any, #PB_Any, 420, 240, "PW Window", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_Invisible)
 
  ListIconGadget(#list_jor_errors, 5, 5, 410, 230, "Time", 60, #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(#list_jor_errors, 1, "Text", 340)
 
  imageList = ImageList_Create_(1, 30, #ILC_COLOR32, 0, 30)
  SendMessage_(GadgetID(#list_jor_errors), #LVM_SETIMAGELIST, #LVSIL_SMALL, imageList)
 
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
 
  HideWindow(#window_jor, 0)
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        CloseWindow(#window_jor)
        Break
    EndSelect
  ForEver
EndIf
And how to remove left indention (if selected):
Image
Phantomas
User
User
Posts: 96
Joined: Wed Jul 01, 2009 12:59 pm

Re: ListIconGadget - Multiline Entry

Post by Phantomas »

Anyone?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4996
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIconGadget - Multiline Entry

Post by RASHAD »

Hi
1- For MultiLine support search the forum for Sparkie code
2- For removing left indention next is a workaround

Code: Select all


Enumeration
  #window_jor
  #list_jor_errors
EndEnumeration

If OpenWindow(#window_jor, #PB_Any, #PB_Any, 420, 240, "PW Window", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_Invisible)

  ContainerGadget(0,5,5,410,230,#PB_Container_Single)
  LI = ListIconGadget(#list_jor_errors, -5, 0, 410, 230, "  Time", 60, #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(#list_jor_errors, 1, "Text 1", 345)
  CloseGadgetList()
  imageList = ImageList_Create_(1, 30, #ILC_COLOR32, 0, 30)
  SendMessage_(GadgetID(#list_jor_errors), #LVM_SETIMAGELIST, #LVSIL_SMALL, imageList)


  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")

  HideWindow(#window_jor, 0)

  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        CloseWindow(#window_jor)
        Break
    EndSelect
  ForEver
EndIf

Egypt my love
Post Reply