Page 1 of 1

Owner draw issues with ListIconGadgets

Posted: Sat Nov 14, 2009 1:37 pm
by Michael Vogel
Hm,
I've some problems implementing a callback to show bars in the last four columns of a listicongadget -- additionally ther should be a color marker in one of the cells. But this (red) background color will be seen also within the last 4 columns :( and there's also another issue, because not all of the rows will show the bars :x

Here's the code - you may have a look at it:

Code: Select all

; Define
	EnableExplicit

	Global i
	Global MonthZ;					Höhe des Monatsreportfensters

	Global CallbackReturnValue;		Callback-Variablen
	Global CallbackX;					hauptsächlich für Balkengraphik des Monatsreports verwendet
	Global CallbackY;
	Global CallbackZ;
	Global CallbackM;
	Global CallbackN;
	Global CallbackO;
	Global CallbackDC;

	Global *CallbackMessage.NM_LISTVIEW
	Global *CallbackCustomdraw.NMLVCUSTOMDRAW
	Global *CallbackDrawItem.DRAWITEMSTRUCT
	Global CallbackText.s

	Global Rect.RECT;					in Callback und bei Initialisierung benötigt

	Enumeration
		#MonthTable
		#monthID;			Monatsreport
	EndEnumeration

	Global planecol,backcol;		Brushes für Bodenplatte
	Global linecol,rectcol;			Pen/Brush für Callback-Routine
	Global lineold,rectold;			Sicherung der alten Pen/Brush
	Global month,monthreportopen;	Handle und Status für Monats-Reportfenster

; EndDefine
Procedure WindowCallback(WindowID,Message,wParam,lParam)

	CallbackReturnValue=#PB_ProcessPureBasicEvents

	Select Message

	Case #WM_NOTIFY

		*CallbackMessage=lParam

		; nur im Monatsreportfenster spielt es sich ab...
		If *CallbackMessage\hdr\hwndFrom=GadgetID(#MonthTable);  [oder]  If GetDlgCtrlID_(*CallbackMessage\hdr\hwndFrom)=#MonthTable


			Select *CallbackMessage\hdr\code

				; Benutzerdefiniertes Malen der Balken (Zeit, Länge, Geschwindigkeit, Pace)...
			Case #NM_CUSTOMDRAW
				;		If MonthType>#MonthButtonAll

				*CallbackCustomdraw.NMLVCUSTOMDRAW=lParam

				CallbackX=*CallbackCustomdraw\nmcd\dwItemSpec;	Zeile
				CallbackY=*CallbackCustomdraw\iSubitem;				Spalte der jeweiligen Balkengraphik
				Debug Str(CallbackX)+":"+Str(Callbacky)


				If CallbackY>=5
					Select *CallbackCustomdraw\nmcd\dwDrawStage
						;Case #CDDS_PREPAINT;	Gitterlinien verschwinden :-(
						;CallbackReturnValue=#CDRF_NOTIFYITEMDRAW

					Case #CDDS_ITEMPREPAINT
						CallbackReturnValue=#CDRF_NOTIFYSUBITEMDRAW

					Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
						CallbackReturnValue=#CDRF_NOTIFYPOSTPAINT

					Case #CDDS_ITEMPOSTPAINT|#CDDS_SUBITEM

						Debug Str(CallbackX)+":"+Str(Callbacky)
						Rect\left=#LVIR_LABEL
						Rect\top=CallbackY;	sollte eigentlich die Spalte sein??? (=6)
						SendMessage_(*CallbackCustomdraw\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*CallbackCustomdraw\nmcd\dwItemSpec,@Rect)

						If Rect\left<Rect\right
							Rect\left+1
							Rect\top+3
							Rect\right-1
							Rect\bottom-3

							CallbackX=Random(1000)
							CallbackDC=*CallbackCustomdraw\nmcd\hdc


							Select CallbackX
							Case 0 To 300
								CallbackX/2;			50m
								CallbackY=2;			0.1km
								CallbackM=10;			0.5
								CallbackN=20;			1
								CallbackO=100;		5
								rectcol=$FF8080;	kobalt-blau
							Case 301 To 1000
								CallbackX/5;			125m
								CallbackY=2;			0.25km
								CallbackM=8;			1
								CallbackN=40;			5
								CallbackO=80;			10
								rectcol=$49D89E;	grasgrün
							Default
								CallbackX/20;			500m
								CallbackY=2;			1km
								CallbackM=2;			-
								CallbackN=10;			5
								CallbackO=20;			10km
								rectcol=$4A85FF;	orange
							EndSelect


							rectcol=CreateSolidBrush_(rectcol);
							rectold=SelectObject_(CallbackDC,rectcol);
							linecol=CreatePen_(#PS_SOLID,1,#Black);
							lineold=SelectObject_(CallbackDC,linecol);

							Rectangle_(CallbackDC,rect\left,rect\top,rect\left+CallbackX+1,rect\bottom)
							CallbackZ=CallbackY
							While CallbackZ<CallbackX
								MoveToEx_(CallbackDC,rect\left+CallbackZ,rect\top,#Null)
								If CallbackZ%CallbackM
									LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+2)
								ElseIf CallbackZ%CallbackN
									LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+4)
								ElseIf CallbackZ%CallbackO
									LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+7)
								Else
									LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+9)
								EndIf
								CallbackZ+CallbackY
							Wend
							SelectObject_(CallbackDC,lineold);
							DeleteObject_(linecol);
							SelectObject_(CallbackDC,rectold);
							DeleteObject_(rectcol);
						EndIf

						CallbackReturnValue=#CDRF_SKIPDEFAULT

					EndSelect

				EndIf
				;		EndIf

			EndSelect

		EndIf

	EndSelect

	ProcedureReturn CallbackReturnValue

EndProcedure

MonthZ=400
#MonthY=500
month=OpenWindow(#monthID,10,10,#MonthY,MonthZ,"-",#PB_Window_Invisible|#PB_Window_Normal|#PB_Window_SystemMenu)
ListIconGadget(#MonthTable,10,10,#MonthY-20,340,"x",128,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)

For i=1 To 8
	AddGadgetColumn(#MonthTable,i,"x",40)
Next i

For i=0 To 9
	AddGadgetItem(#MonthTable,i,Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A'))
Next

SetGadgetItemColor(#MonthTable,5,#PB_Gadget_BackColor,#Red,4)

HideWindow(#monthid,0)
SetWindowCallback(@WindowCallback(),#monthID)

Repeat
Until WaitWindowEvent(100)=#WM_CHAR

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 7:54 am
by Michael Vogel
Made some additional experiments to get rid of the problems, but failed -- does anyone know what is wrong with the example above?

Thanks,
Michael

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 10:14 am
by RASHAD
Hi Michael
I hope it is what you asked for

Code: Select all


  EnableExplicit

   Global i
   Global MonthZ;               H?he des Monatsreportfensters

   Global CallbackReturnValue;      Callback-Variablen
   Global CallbackX;               haupts?chlich für Balkengraphik des Monatsreports verwendet
   Global CallbackY;
   Global CallbackZ;
   Global CallbackM;
   Global CallbackN;
   Global CallbackO;
   Global CallbackDC;

   Global *CallbackMessage.NM_LISTVIEW
   Global *CallbackCustomdraw.NMLVCUSTOMDRAW
   Global *CallbackDrawItem.DRAWITEMSTRUCT
   Global CallbackText.s

   Global Rect.RECT;               in Callback und bei Initialisierung ben?tigt

   Enumeration
      #MonthTable
      #monthID;         Monatsreport
   EndEnumeration

   Global planecol,backcol;      Brushes für Bodenplatte
   Global linecol,rectcol;         Pen/Brush für Callback-Routine
   Global lineold,rectold;         Sicherung der alten Pen/Brush
   Global month,monthreportopen;   Handle und Status für Monats-Reportfenster

; EndDefine
Procedure WindowCallback(WindowID,Message,wParam,lParam)

   CallbackReturnValue=#PB_ProcessPureBasicEvents

   Select Message

   Case #WM_NOTIFY,#WM_NCPAINT

      *CallbackMessage=lParam

      ; nur im Monatsreportfenster spielt es sich ab...
      If *CallbackMessage\hdr\hwndFrom=GadgetID(#MonthTable);  [oder]  If GetDlgCtrlID_(*CallbackMessage\hdr\hwndFrom)=#MonthTable


         Select *CallbackMessage\hdr\code

            ; Benutzerdefiniertes Malen der Balken (Zeit, L?nge, Geschwindigkeit, Pace)...
         Case #NM_CUSTOMDRAW
            ;      If MonthType>#MonthButtonAll

            *CallbackCustomdraw.NMLVCUSTOMDRAW=lParam

            CallbackX=*CallbackCustomdraw\nmcd\dwItemSpec;   Zeile
            CallbackY=*CallbackCustomdraw\iSubitem;            Spalte der jeweiligen Balkengraphik
            Debug Str(CallbackX)+":"+Str(Callbacky)


            If CallbackY>=5
               Select *CallbackCustomdraw\nmcd\dwDrawStage
               Case #CDDS_PREPAINT;   Gitterlinien verschwinden :-(
                  CallbackReturnValue=#CDRF_NOTIFYITEMDRAW

               Case #CDDS_ITEMPREPAINT
                  CallbackReturnValue=#CDRF_NOTIFYSUBITEMDRAW

               Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
                  CallbackReturnValue=#CDRF_NOTIFYPOSTPAINT

               Case #CDDS_ITEMPOSTPAINT|#CDDS_SUBITEM

                  Debug Str(CallbackX)+":"+Str(Callbacky)
                  Rect\left=#LVIR_LABEL
                  Rect\top=CallbackY;   sollte eigentlich die Spalte sein??? (=6)
                  SendMessage_(*CallbackCustomdraw\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*CallbackCustomdraw\nmcd\dwItemSpec,@Rect)

                  If Rect\left<Rect\right
                     Rect\left+1
                     Rect\top+3
                     Rect\right-1
                     Rect\bottom-3

                     CallbackX=Random(1000)
                     CallbackDC=*CallbackCustomdraw\nmcd\hdc


                     Select CallbackX
                     Case 0 To 300
                        CallbackX/2;         50m
                        CallbackY=2;         0.1km
                        CallbackM=10;         0.5
                        CallbackN=20;         1
                        CallbackO=100;      5
                        rectcol=$FF8080;   kobalt-blau
                     Case 301 To 1000
                        CallbackX/5;         125m
                        CallbackY=2;         0.25km
                        CallbackM=8;         1
                        CallbackN=40;         5
                        CallbackO=80;         10
                        rectcol=$49D89E;   grasgrün
                     Default
                        CallbackX/20;         500m
                        CallbackY=2;         1km
                        CallbackM=2;         -
                        CallbackN=10;         5
                        CallbackO=20;         10km
                        rectcol=$4A85FF;   orange
                     EndSelect


                     rectcol=CreateSolidBrush_(rectcol);
                     rectold=SelectObject_(CallbackDC,rectcol);
                     linecol=CreatePen_(#PS_SOLID,1,#Black);
                     lineold=SelectObject_(CallbackDC,linecol);

                     Rectangle_(CallbackDC,rect\left,rect\top,rect\left+CallbackX+1,rect\bottom)
                     CallbackZ=CallbackY
                     While CallbackZ<CallbackX
                        MoveToEx_(CallbackDC,rect\left+CallbackZ,rect\top,#Null)
                        If CallbackZ%CallbackM
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+2)
                        ElseIf CallbackZ%CallbackN
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+4)
                        ElseIf CallbackZ%CallbackO
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+7)
                        Else
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+9)
                        EndIf
                        CallbackZ+CallbackY
                     Wend
                     SelectObject_(CallbackDC,lineold);
                     DeleteObject_(linecol);
                     SelectObject_(CallbackDC,rectold);
                     DeleteObject_(rectcol);
                  EndIf

                  CallbackReturnValue=#CDRF_SKIPDEFAULT

               EndSelect

            EndIf
            
         Case #NM_CLICK
             InvalidateRect_(month,0,#True) 

         EndSelect

      EndIf

   EndSelect

   ProcedureReturn CallbackReturnValue

EndProcedure

MonthZ=400
#MonthY=500
month=OpenWindow(#monthID,10,10,#MonthY,MonthZ,"-",#PB_Window_Normal|#PB_Window_SystemMenu)
ListIconGadget(#MonthTable,10,10,#MonthY-20,340,"0",115,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)

For i=1 To 9
   AddGadgetColumn(#MonthTable,i,Str(i),40)
Next i

For i=0 To 8
   AddGadgetItem(#MonthTable,i,Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A'))
Next

SetGadgetItemColor(#MonthTable,5,#PB_Gadget_BackColor,#Red,4)

; HideWindow(#monthid,0)
SetWindowCallback(@WindowCallback(),#monthID)

Repeat
Until WaitWindowEvent(100)=#WM_CHAR
Have a good day

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 3:19 pm
by Michael Vogel
Rashad,

thanks for helping, but your code seems to bring up the same display here (testing on Win XP) as before :( (except the fact, that the grid lines are not shown anymore :wink:)

That means, the window does still ignore to draw the bars on the rightmost columns for the first five rows and the red background in the sixth row is also seen in the bar columns, even the color has only be given to one cell only

Michael

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 3:32 pm
by RASHAD
Michael
Sorry I did not test it on XP
Try the next it is ok on XP x32 PB x32 v 4.31

Code: Select all

EnableExplicit

   Global i
   Global MonthZ;               H?he des Monatsreportfensters

   Global CallbackReturnValue;      Callback-Variablen
   Global CallbackX;               haupts?chlich für Balkengraphik des Monatsreports verwendet
   Global CallbackY;
   Global CallbackZ;
   Global CallbackM;
   Global CallbackN;
   Global CallbackO;
   Global CallbackDC;

   Global *CallbackMessage.NM_LISTVIEW
   Global *CallbackCustomdraw.NMLVCUSTOMDRAW
   Global *CallbackDrawItem.DRAWITEMSTRUCT
   Global CallbackText.s

   Global Rect.RECT;               in Callback und bei Initialisierung ben?tigt

   Enumeration
      #MonthTable
      #monthID;         Monatsreport
   EndEnumeration

   Global planecol,backcol;      Brushes für Bodenplatte
   Global linecol,rectcol;         Pen/Brush für Callback-Routine
   Global lineold,rectold;         Sicherung der alten Pen/Brush
   Global month,monthreportopen;   Handle und Status für Monats-Reportfenster

; EndDefine
Procedure WindowCallback(WindowID,Message,wParam,lParam)

   CallbackReturnValue=#PB_ProcessPureBasicEvents

   Select Message

   Case #WM_NOTIFY,#WM_NCPAINT

      *CallbackMessage=lParam

      ; nur im Monatsreportfenster spielt es sich ab...
      If *CallbackMessage\hdr\hwndFrom=GadgetID(#MonthTable);  [oder]  If GetDlgCtrlID_(*CallbackMessage\hdr\hwndFrom)=#MonthTable


         Select *CallbackMessage\hdr\code

            ; Benutzerdefiniertes Malen der Balken (Zeit, L?nge, Geschwindigkeit, Pace)...
         Case #NM_CUSTOMDRAW
            ;      If MonthType>#MonthButtonAll

            *CallbackCustomdraw.NMLVCUSTOMDRAW=lParam

            CallbackX=*CallbackCustomdraw\nmcd\dwItemSpec;   Zeile
            CallbackY=*CallbackCustomdraw\iSubitem;            Spalte der jeweiligen Balkengraphik
            Debug Str(CallbackX)+":"+Str(Callbacky)


            If CallbackY>=5
               Select *CallbackCustomdraw\nmcd\dwDrawStage
               Case #CDDS_PREPAINT;   Gitterlinien verschwinden :-(
                  CallbackReturnValue=#CDRF_NOTIFYITEMDRAW

               Case #CDDS_ITEMPREPAINT
                  CallbackReturnValue=#CDRF_NOTIFYSUBITEMDRAW

               Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
                  CallbackReturnValue=#CDRF_NOTIFYPOSTPAINT

               Case #CDDS_ITEMPOSTPAINT|#CDDS_SUBITEM

                  Debug Str(CallbackX)+":"+Str(Callbacky)
                  Rect\left=#LVIR_LABEL
                  Rect\top=CallbackY;   sollte eigentlich die Spalte sein??? (=6)
                  SendMessage_(*CallbackCustomdraw\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*CallbackCustomdraw\nmcd\dwItemSpec,@Rect)

                  If Rect\left<Rect\right
                     Rect\left+1
                     Rect\top+3
                     Rect\right-1
                     Rect\bottom-3

                     CallbackX=Random(1000)
                     CallbackDC=*CallbackCustomdraw\nmcd\hdc


                     Select CallbackX
                     Case 0 To 300
                        CallbackX/2;         50m
                        CallbackY=2;         0.1km
                        CallbackM=10;         0.5
                        CallbackN=20;         1
                        CallbackO=100;      5
                        rectcol=$FF8080;   kobalt-blau
                     Case 301 To 1000
                        CallbackX/5;         125m
                        CallbackY=2;         0.25km
                        CallbackM=8;         1
                        CallbackN=40;         5
                        CallbackO=80;         10
                        rectcol=$49D89E;   grasgrün
                     Default
                        CallbackX/20;         500m
                        CallbackY=2;         1km
                        CallbackM=2;         -
                        CallbackN=10;         5
                        CallbackO=20;         10km
                        rectcol=$4A85FF;   orange
                     EndSelect


                     rectcol=CreateSolidBrush_(rectcol);
                     rectold=SelectObject_(CallbackDC,rectcol);
                     linecol=CreatePen_(#PS_SOLID,1,#Black);
                     lineold=SelectObject_(CallbackDC,linecol);

                     Rectangle_(CallbackDC,rect\left,rect\top,rect\left+CallbackX+1,rect\bottom)
                     CallbackZ=CallbackY
                     While CallbackZ<CallbackX
                        MoveToEx_(CallbackDC,rect\left+CallbackZ,rect\top,#Null)
                        If CallbackZ%CallbackM
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+2)
                        ElseIf CallbackZ%CallbackN
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+4)
                        ElseIf CallbackZ%CallbackO
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+7)
                        Else
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+9)
                        EndIf
                        CallbackZ+CallbackY
                     Wend
                     SelectObject_(CallbackDC,lineold);
                     DeleteObject_(linecol);
                     SelectObject_(CallbackDC,rectold);
                     DeleteObject_(rectcol);
                  EndIf

                  CallbackReturnValue=#CDRF_SKIPDEFAULT

               EndSelect

            EndIf
            
         Case #NM_CLICK,#NM_RCLICK
;             *lpnmitem.NMITEMACTIVATE = lParam             
;               Row.l = *lpnmitem\iItem
;               Column.l = *lpnmitem\iSubItem
;              SetGadgetItemColor(#MonthTable, -1, #PB_Gadget_BackColor, $FFFFFF)
;              SetGadgetItemColor(#MonthTable,Row,#PB_Gadget_BackColor,#Red,4)
             HideGadget(#MonthTable,1)             
             InvalidateRect_(month,0,#True)
             HideGadget(#MonthTable,0)



         EndSelect

      EndIf

   EndSelect

   ProcedureReturn CallbackReturnValue

EndProcedure

MonthZ=400
#MonthY=500
month=OpenWindow(#monthID,10,10,#MonthY,MonthZ,"-",#PB_Window_Normal|#PB_Window_SystemMenu)
ListIconGadget(#MonthTable,10,10,#MonthY-20,340,"0",115,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
SendMessage_(GadgetID(#MonthTable),#LVM_SETEXTENDEDLISTVIEWSTYLE,#LVS_EX_GRIDLINES,#LVS_EX_GRIDLINES)

For i=1 To 9
   AddGadgetColumn(#MonthTable,i,Str(i),40)
Next i

For i=0 To 8
   AddGadgetItem(#MonthTable,i,Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A'))
Next

SetGadgetItemColor(#MonthTable,5,#PB_Gadget_BackColor,#Red,4)

; HideWindow(#monthid,0)
SetWindowCallback(@WindowCallback(),#monthID)

Repeat
Until WaitWindowEvent(100)=#WM_CHAR
Keep going on we will beat it
But give me the errors one by one

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 3:45 pm
by PureLust
RASHAD wrote:But give me the errors one by one
Here is the first one: :wink:
If you change the with of a column the right area will not be redrawn correctly (set InvalidateRect_()?). Have fun with that. :mrgreen:

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 4:02 pm
by RASHAD
PureLust take it easy and let Michael handle the problem
Or if you have a solution that will be much appreciated right
Michael here it is a workaround try it

Code: Select all

EnableExplicit

   Global i
   Global MonthZ;               H?he des Monatsreportfensters

   Global CallbackReturnValue;      Callback-Variablen
   Global CallbackX;               haupts?chlich für Balkengraphik des Monatsreports verwendet
   Global CallbackY;
   Global CallbackZ;
   Global CallbackM;
   Global CallbackN;
   Global CallbackO;
   Global CallbackDC;

   Global *CallbackMessage.NM_LISTVIEW
   Global *CallbackCustomdraw.NMLVCUSTOMDRAW
   Global *CallbackDrawItem.DRAWITEMSTRUCT
   Global CallbackText.s

   Global Rect.RECT;               in Callback und bei Initialisierung ben?tigt

   Enumeration
      #MonthTable
      #monthID;         Monatsreport
   EndEnumeration

   Global planecol,backcol;      Brushes für Bodenplatte
   Global linecol,rectcol;         Pen/Brush für Callback-Routine
   Global lineold,rectold;         Sicherung der alten Pen/Brush
   Global month,monthreportopen;   Handle und Status für Monats-Reportfenster

; EndDefine
Procedure WindowCallback(WindowID,Message,wParam,lParam)

   CallbackReturnValue=#PB_ProcessPureBasicEvents

   Select Message

   Case #WM_NOTIFY

      *CallbackMessage=lParam

      ; nur im Monatsreportfenster spielt es sich ab...
      If *CallbackMessage\hdr\hwndFrom=GadgetID(#MonthTable);  [oder]  If GetDlgCtrlID_(*CallbackMessage\hdr\hwndFrom)=#MonthTable


         Select *CallbackMessage\hdr\code

            ; Benutzerdefiniertes Malen der Balken (Zeit, L?nge, Geschwindigkeit, Pace)...
         Case #NM_CUSTOMDRAW
            ;      If MonthType>#MonthButtonAll

            *CallbackCustomdraw.NMLVCUSTOMDRAW=lParam

            CallbackX=*CallbackCustomdraw\nmcd\dwItemSpec;   Zeile
            CallbackY=*CallbackCustomdraw\iSubitem;            Spalte der jeweiligen Balkengraphik
            Debug Str(CallbackX)+":"+Str(Callbacky)


            If CallbackY > 5
               Select *CallbackCustomdraw\nmcd\dwDrawStage
               Case #CDDS_PREPAINT;   Gitterlinien verschwinden :-(
               
                  CallbackReturnValue=#CDRF_NOTIFYITEMDRAW

               Case #CDDS_ITEMPREPAINT
                  CallbackReturnValue=#CDRF_NOTIFYSUBITEMDRAW

               Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
               
                  CallbackReturnValue=#CDRF_NOTIFYPOSTPAINT

               Case #CDDS_ITEMPOSTPAINT|#CDDS_SUBITEM

                  Debug Str(CallbackX)+":"+Str(Callbacky)
                  Rect\left=#LVIR_LABEL
                  Rect\top=CallbackY   ;sollte eigentlich die Spalte sein??? (=6)
                  SendMessage_(*CallbackCustomdraw\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*CallbackCustomdraw\nmcd\dwItemSpec,@Rect)

                  If Rect\left<Rect\right
                     Rect\left+1
                     Rect\top+3
                     Rect\right-1
                     Rect\bottom-3

                     CallbackX=Random(1000)
                     CallbackDC=*CallbackCustomdraw\nmcd\hdc


                     Select CallbackX
                     Case 0 To 300
                        CallbackX/2;         50m
                        CallbackY=2;         0.1km
                        CallbackM=10;         0.5
                        CallbackN=20;         1
                        CallbackO=100;      5
                        rectcol=$FF8080;   kobalt-blau
                     Case 301 To 1000
                        CallbackX/5;         125m
                        CallbackY=2;         0.25km
                        CallbackM=8;         1
                        CallbackN=40;         5
                        CallbackO=80;         10
                        rectcol=$49D89E;   grasgrün
                     Default
                        CallbackX/20;         500m
                        CallbackY=2;         1km
                        CallbackM=2;         -
                        CallbackN=10;         5
                        CallbackO=20;         10km
                        rectcol=$4A85FF;   orange
                     EndSelect


                     rectcol=CreateSolidBrush_(rectcol);
                     rectold=SelectObject_(CallbackDC,rectcol);
                     linecol=CreatePen_(#PS_SOLID,1,#Black);
                     lineold=SelectObject_(CallbackDC,linecol);

                     Rectangle_(CallbackDC,rect\left,rect\top,rect\left+CallbackX+1,rect\bottom)
                     CallbackZ=CallbackY
                     While CallbackZ<CallbackX
                        MoveToEx_(CallbackDC,rect\left+CallbackZ,rect\top,#Null)
                        If CallbackZ%CallbackM
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+2)
                        ElseIf CallbackZ%CallbackN
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+4)
                        ElseIf CallbackZ%CallbackO
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+7)
                        Else
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+9)
                        EndIf
                        CallbackZ+CallbackY
                     Wend
                     SelectObject_(CallbackDC,lineold);
                     DeleteObject_(linecol);
                     SelectObject_(CallbackDC,rectold);
                     DeleteObject_(rectcol);
                  EndIf

                  CallbackReturnValue=#CDRF_SKIPDEFAULT

               EndSelect

            EndIf
            
         Case #NM_CLICK,#NM_RCLICK,#HDN_ITEMCHANGING
;             *lpnmitem.NMITEMACTIVATE = lParam             
;               Row.l = *lpnmitem\iItem
;               Column.l = *lpnmitem\iSubItem
;              SetGadgetItemColor(#MonthTable, -1, #PB_Gadget_BackColor, $FFFFFF)
;              SetGadgetItemColor(#MonthTable,Row,#PB_Gadget_BackColor,#Red,4)
             HideGadget(#MonthTable,1)             
             InvalidateRect_(month,0,#True)
             HideGadget(#MonthTable,0)



         EndSelect

      EndIf

   EndSelect

   ProcedureReturn CallbackReturnValue

EndProcedure

MonthZ=400
#MonthY=500
month=OpenWindow(#monthID,10,10,#MonthY,MonthZ,"-",#PB_Window_Normal|#PB_Window_SystemMenu)
ListIconGadget(#MonthTable,10,10,#MonthY-20,340,"0",115,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
SendMessage_(GadgetID(#MonthTable),#LVM_SETEXTENDEDLISTVIEWSTYLE,#LVS_EX_GRIDLINES,#LVS_EX_GRIDLINES)

For i=1 To 10
   AddGadgetColumn(#MonthTable,i,Str(i),40)
Next i
SendMessage_(GadgetID(#MonthTable), #LVM_SETCOLUMNWIDTH, 5, 0)

For i=0 To 8
   AddGadgetItem(#MonthTable,i,Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A'))
Next

SetGadgetItemColor(#MonthTable,5,#PB_Gadget_BackColor,#Red,4)

; HideWindow(#monthid,0)
SetWindowCallback(@WindowCallback(),#monthID)

Repeat
Until WaitWindowEvent(100)=#WM_CHAR

Remember PB x32 v 4.31

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 4:54 pm
by Michael Vogel
Status Report:
• What a nasty trick - as I see, you've skipped a column to get rid of the red color... now I see what you mean by "workaround" (column 5 is gone)
• The issues with the oversized boxes are not a problem in fact - anyhow I added three lines that no one will get nervous :lol:
• Still wondering why the boxes are seen only beginning from line 6 :?

Michael

Code: Select all

EnableExplicit

Global i
Global MonthZ;               H?he des Monatsreportfensters

Global CallbackReturnValue;      Callback-Variablen
Global CallbackX;               haupts?chlich für Balkengraphik des Monatsreports verwendet
Global CallbackY;
Global CallbackZ;
Global CallbackM;
Global CallbackN;
Global CallbackO;
Global CallbackDC;

Global *CallbackMessage.NM_LISTVIEW
Global *CallbackCustomdraw.NMLVCUSTOMDRAW
Global *CallbackDrawItem.DRAWITEMSTRUCT
Global CallbackText.s

Global Rect.RECT;               in Callback und bei Initialisierung ben?tigt

Enumeration
	#MonthTable
	#monthID;         Monatsreport
EndEnumeration

Global planecol,backcol;      Brushes für Bodenplatte
Global linecol,rectcol;         Pen/Brush für Callback-Routine
Global lineold,rectold;         Sicherung der alten Pen/Brush
Global month,monthreportopen;   Handle und Status für Monats-Reportfenster

Procedure WindowCallback(WindowID,Message,wParam,lParam)

	CallbackReturnValue=#PB_ProcessPureBasicEvents

	Select Message

	Case #WM_NOTIFY

		*CallbackMessage=lParam

		; nur im Monatsreportfenster spielt es sich ab...
		If *CallbackMessage\hdr\hwndFrom=GadgetID(#MonthTable);  [oder]  If GetDlgCtrlID_(*CallbackMessage\hdr\hwndFrom)=#MonthTable


			Select *CallbackMessage\hdr\code

				; Benutzerdefiniertes Malen der Balken (Zeit, L?nge, Geschwindigkeit, Pace)...
			Case #NM_CUSTOMDRAW
				;      If MonthType>#MonthButtonAll

				*CallbackCustomdraw.NMLVCUSTOMDRAW=lParam

				CallbackX=*CallbackCustomdraw\nmcd\dwItemSpec;   Zeile
				CallbackY=*CallbackCustomdraw\iSubitem;            Spalte der jeweiligen Balkengraphik
				Debug Str(CallbackX)+":"+Str(Callbacky)


				If CallbackY > 5
					Select *CallbackCustomdraw\nmcd\dwDrawStage
					Case #CDDS_PREPAINT;   Gitterlinien verschwinden :-(

						CallbackReturnValue=#CDRF_NOTIFYITEMDRAW

					Case #CDDS_ITEMPREPAINT
						CallbackReturnValue=#CDRF_NOTIFYSUBITEMDRAW

					Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM

						CallbackReturnValue=#CDRF_NOTIFYPOSTPAINT

					Case #CDDS_ITEMPOSTPAINT|#CDDS_SUBITEM

						Debug Str(CallbackX)+":"+Str(Callbacky)
						Rect\left=#LVIR_LABEL
						Rect\top=CallbackY   ;sollte eigentlich die Spalte sein??? (=6)
						SendMessage_(*CallbackCustomdraw\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*CallbackCustomdraw\nmcd\dwItemSpec,@Rect)

						If Rect\left<Rect\right
							Rect\left+1
							Rect\top+3
							Rect\right-1
							Rect\bottom-3

							CallbackX=Random(1000)
							CallbackDC=*CallbackCustomdraw\nmcd\hdc


							Select CallbackX
							Case 0 To 300
								CallbackX/2;         50m
								CallbackY=2;         0.1km
								CallbackM=10;         0.5
								CallbackN=20;         1
								CallbackO=100;      5
								rectcol=$FF8080;   kobalt-blau
							Case 301 To 1000
								CallbackX/5;         125m
								CallbackY=2;         0.25km
								CallbackM=8;         1
								CallbackN=40;         5
								CallbackO=80;         10
								rectcol=$49D89E;   grasgrün
							Default
								CallbackX/20;         500m
								CallbackY=2;         1km
								CallbackM=2;         -
								CallbackN=10;         5
								CallbackO=20;         10km
								rectcol=$4A85FF;   orange
							EndSelect


							rectcol=CreateSolidBrush_(rectcol);
							rectold=SelectObject_(CallbackDC,rectcol);
							linecol=CreatePen_(#PS_SOLID,1,#Black);
							lineold=SelectObject_(CallbackDC,linecol);

							If CallbackX>rect\right-rect\left
								CallbackX=rect\right-rect\left
							EndIf

							Rectangle_(CallbackDC,rect\left,rect\top,rect\left+CallbackX+1,rect\bottom)
							CallbackZ=CallbackY
							While CallbackZ<CallbackX
								MoveToEx_(CallbackDC,rect\left+CallbackZ,rect\top,#Null)
								If CallbackZ%CallbackM
									LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+2)
								ElseIf CallbackZ%CallbackN
									LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+4)
								ElseIf CallbackZ%CallbackO
									LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+7)
								Else
									LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+9)
								EndIf
								CallbackZ+CallbackY
							Wend
							SelectObject_(CallbackDC,lineold);
							DeleteObject_(linecol);
							SelectObject_(CallbackDC,rectold);
							DeleteObject_(rectcol);
						EndIf

						CallbackReturnValue=#CDRF_SKIPDEFAULT

					EndSelect

				EndIf

			Case #NM_CLICK,#NM_RCLICK,#HDN_ITEMCHANGING
				;             *lpnmitem.NMITEMACTIVATE = lParam
				;               Row.l = *lpnmitem\iItem
				;               Column.l = *lpnmitem\iSubItem
				;              SetGadgetItemColor(#MonthTable, -1, #PB_Gadget_BackColor, $FFFFFF)
				;              SetGadgetItemColor(#MonthTable,Row,#PB_Gadget_BackColor,#Red,4)
				HideGadget(#MonthTable,1)
				InvalidateRect_(month,0,#True)
				HideGadget(#MonthTable,0)



			EndSelect

		EndIf

	EndSelect

	ProcedureReturn CallbackReturnValue

EndProcedure

MonthZ=400
#MonthY=500
month=OpenWindow(#monthID,10,10,#MonthY,MonthZ,"-",#PB_Window_Normal|#PB_Window_SystemMenu)
ListIconGadget(#MonthTable,10,10,#MonthY-20,340,"0",115,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
SendMessage_(GadgetID(#MonthTable),#LVM_SETEXTENDEDLISTVIEWSTYLE,#LVS_EX_GRIDLINES,#LVS_EX_GRIDLINES)

For i=1 To 10
	AddGadgetColumn(#MonthTable,i,Str(i),40)
Next i
SendMessage_(GadgetID(#MonthTable), #LVM_SETCOLUMNWIDTH, 5, 0)

For i=0 To 8
	AddGadgetItem(#MonthTable,i,Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A'))
Next

SetGadgetItemColor(#MonthTable,5,#PB_Gadget_BackColor,#Red,4)

; HideWindow(#monthid,0)
SetWindowCallback(@WindowCallback(),#monthID)

Repeat
Until WaitWindowEvent(100)=#WM_CHAR


Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 5:06 pm
by RASHAD
Progress
Good news
Try the next

Code: Select all

EnableExplicit

   Global i
   Global MonthZ;               H?he des Monatsreportfensters

   Global CallbackReturnValue;      Callback-Variablen
   Global CallbackX;               haupts?chlich für Balkengraphik des Monatsreports verwendet
   Global CallbackY;
   Global CallbackZ;
   Global CallbackM;
   Global CallbackN;
   Global CallbackO;
   Global CallbackDC;

   Global *CallbackMessage.NM_LISTVIEW
   Global *CallbackCustomdraw.NMLVCUSTOMDRAW
   Global *CallbackDrawItem.DRAWITEMSTRUCT
   Global CallbackText.s

   Global Rect.RECT;               in Callback und bei Initialisierung ben?tigt

   Enumeration
      #MonthTable
      #monthID;         Monatsreport
   EndEnumeration

   Global planecol,backcol;      Brushes für Bodenplatte
   Global linecol,rectcol;         Pen/Brush für Callback-Routine
   Global lineold,rectold;         Sicherung der alten Pen/Brush
   Global month,monthreportopen;   Handle und Status für Monats-Reportfenster

; EndDefine
Procedure WindowCallback(WindowID,Message,wParam,lParam)

   CallbackReturnValue=#PB_ProcessPureBasicEvents

   Select Message

   Case #WM_NOTIFY

      *CallbackMessage=lParam

      ; nur im Monatsreportfenster spielt es sich ab...
      If *CallbackMessage\hdr\hwndFrom=GadgetID(#MonthTable);  [oder]  If GetDlgCtrlID_(*CallbackMessage\hdr\hwndFrom)=#MonthTable


         Select *CallbackMessage\hdr\code

            ; Benutzerdefiniertes Malen der Balken (Zeit, L?nge, Geschwindigkeit, Pace)...
         Case #NM_CUSTOMDRAW
            ;      If MonthType>#MonthButtonAll

            *CallbackCustomdraw.NMLVCUSTOMDRAW=lParam

            CallbackX=*CallbackCustomdraw\nmcd\dwItemSpec;   Zeile
            CallbackY=*CallbackCustomdraw\iSubitem;            Spalte der jeweiligen Balkengraphik
            Debug Str(CallbackX)+":"+Str(Callbacky)


            If CallbackY > 5
               Select *CallbackCustomdraw\nmcd\dwDrawStage
               Case #CDDS_PREPAINT;   Gitterlinien verschwinden :-(
               
                  CallbackReturnValue=#CDRF_NOTIFYITEMDRAW

               Case #CDDS_ITEMPREPAINT
                  CallbackReturnValue=#CDRF_NOTIFYSUBITEMDRAW

               Case #CDDS_ITEMPREPAINT|#CDDS_SUBITEM
               
                  CallbackReturnValue=#CDRF_NOTIFYPOSTPAINT

               Case #CDDS_ITEMPOSTPAINT|#CDDS_SUBITEM

                  Debug Str(CallbackX)+":"+Str(Callbacky)
                  Rect\left=#LVIR_LABEL
                  Rect\top=CallbackY   ;sollte eigentlich die Spalte sein??? (=6)
                  SendMessage_(*CallbackCustomdraw\nmcd\hdr\hwndFrom,#LVM_GETSUBITEMRECT,*CallbackCustomdraw\nmcd\dwItemSpec,@Rect)

                  If Rect\left<Rect\right
                     Rect\left+1
                     Rect\top+3
                     Rect\right-1
                     Rect\bottom-3

                     CallbackX=Random(1000)
                     CallbackDC=*CallbackCustomdraw\nmcd\hdc


                     Select CallbackX
                     Case 0 To 300
                        CallbackX/2;         50m
                        CallbackY=2;         0.1km
                        CallbackM=10;         0.5
                        CallbackN=20;         1
                        CallbackO=100;      5
                        rectcol=$FF8080;   kobalt-blau
                     Case 301 To 1000
                        CallbackX/5;         125m
                        CallbackY=2;         0.25km
                        CallbackM=8;         1
                        CallbackN=40;         5
                        CallbackO=80;         10
                        rectcol=$49D89E;   grasgrün
                     Default
                        CallbackX/20;         500m
                        CallbackY=2;         1km
                        CallbackM=2;         -
                        CallbackN=10;         5
                        CallbackO=20;         10km
                        rectcol=$4A85FF;   orange
                     EndSelect


                     rectcol=CreateSolidBrush_(rectcol);
                     rectold=SelectObject_(CallbackDC,rectcol);
                     linecol=CreatePen_(#PS_SOLID,1,#Black);
                     lineold=SelectObject_(CallbackDC,linecol);

                     Rectangle_(CallbackDC,rect\left,rect\top,rect\left+CallbackX+1,rect\bottom)
                     CallbackZ=CallbackY
                     While CallbackZ<CallbackX
                        MoveToEx_(CallbackDC,rect\left+CallbackZ,rect\top,#Null)
                        If CallbackZ%CallbackM
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+2)
                        ElseIf CallbackZ%CallbackN
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+4)
                        ElseIf CallbackZ%CallbackO
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+7)
                        Else
                           LineTo_(CallbackDC,rect\left+CallbackZ,rect\top+9)
                        EndIf
                        CallbackZ+CallbackY
                     Wend
                     SelectObject_(CallbackDC,lineold);
                     DeleteObject_(linecol);
                     SelectObject_(CallbackDC,rectold);
                     DeleteObject_(rectcol);
                  EndIf

                  ;CallbackReturnValue=#CDRF_SKIPDEFAULT

               EndSelect

            EndIf
            
         Case #NM_CLICK,#NM_RCLICK,#HDN_ITEMCHANGING
;             *lpnmitem.NMITEMACTIVATE = lParam             
;               Row.l = *lpnmitem\iItem
;               Column.l = *lpnmitem\iSubItem
;              SetGadgetItemColor(#MonthTable, -1, #PB_Gadget_BackColor, $FFFFFF)
;              SetGadgetItemColor(#MonthTable,Row,#PB_Gadget_BackColor,#Red,4)
             HideGadget(#MonthTable,1)           
             InvalidateRect_(month,0,#True)
             HideGadget(#MonthTable,0)



         EndSelect

      EndIf

   EndSelect

   ProcedureReturn CallbackReturnValue

EndProcedure

MonthZ=400
#MonthY=500
month=OpenWindow(#monthID,10,10,#MonthY,MonthZ,"-",#PB_Window_Normal|#PB_Window_SystemMenu)
ListIconGadget(#MonthTable,10,10,#MonthY-20,340,"0",115,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
SendMessage_(GadgetID(#MonthTable),#LVM_SETEXTENDEDLISTVIEWSTYLE,#LVS_EX_GRIDLINES,#LVS_EX_GRIDLINES)

For i=1 To 10
   AddGadgetColumn(#MonthTable,i,Str(i),40)
Next i
SendMessage_(GadgetID(#MonthTable), #LVM_SETCOLUMNWIDTH, 5, 0)

For i=0 To 8
   AddGadgetItem(#MonthTable,i,Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A')+#LF$+Chr(Random(25)+'A'))
Next

SetGadgetItemColor(#MonthTable,0,#PB_Gadget_BackColor,#White,4)
SetGadgetItemColor(#MonthTable,5,#PB_Gadget_BackColor,#Red,4)

; HideWindow(#monthid,0)
SetWindowCallback(@WindowCallback(),#monthID)

Repeat
Until WaitWindowEvent(100)=#WM_CHAR
Have fun

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 5:14 pm
by Michael Vogel
Cool!
But I've to be careful and check the code, before being to enthusiastic :lol:
So the grid is here, and the boxes are seen in all rows and the red box seems also to be correct, 3 points for you...
...and one point subtracted for removing column 5 :wink:

Michael

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 5:21 pm
by RASHAD
Michael good
Yes check everything carefully
You can not remove Column 5 you have to resize it to 0 and it will be better to fix the size after that
Or you will face the same problem again

Have a good day mate


Edit:Michael have a mercy and give me that point ,please

have a good day my friend

Re: Owner draw issues with ListIconGadgets

Posted: Tue Nov 24, 2009 5:30 pm
by PureLust
Michael Vogel wrote:• Still wondering why the boxes are seen only beginning from line 6 :?
Seems to be a problem with the SetGadgetItemColor() you use to set the color of a field - if you change the Item from 5 to 2 you will see what I mean.
I think that PB initiates a Callback to enable the coloring if a field, which will conflict with your own callback.
So maybe you should do the coloring in your Callback as well on your own to prevent conflicts.

(As I can see in you last version - you've "fixed" this issue by using SetGadgetItemColor() on the first line - even though it's not the smartest way, it seems to be a functional workaround for that. ;) )