ListIconGadget With some Callback code(Window) problem

Everything else that doesn't fall into one of the other PB categories.
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

ListIconGadget With some Callback code(Window) problem

Post by GenRabbit »

Change Font types in and listicongadget. but for some reason its not working. I found some code and copied that but for some reasons It does not work as intended. Any idea whats going on?
Lines with the text "A Bold Statement" should be bold, the others not

Code: Select all

EnableExplicit
#PD_GROUP_LENGTH   = 6
#TOTALSIZE         = 60

Global.i Dim ViewSkillIndexValue(#PD_GROUP_LENGTH)
Global.i RegularFont = LoadFont(#PB_Any, "Arial", 9)
Global.i BoldFont = LoadFont(#PB_Any, "Arial", 9, #PB_Font_Bold)

Procedure lvwSkillCB(Window.i, Message.i, wParam.i, lParam.i)
	Protected.i i
	Protected *NMLVCustomDraw.NMLVCUSTOMDRAW
	Debug "Running"
	If Message = #WM_NOTIFY
			*NMLVCustomDraw = lParam
			If *NMLVCustomDraw\nmcd\hdr\code = #NM_CUSTOMDRAW
				;If *NMLVCustomDraw\nmcd\hdr\hWndFrom = GadgetID(GameListIconListViewSkill) And *NMLVCustomDraw\nmcd\hdr\code = #NM_CUSTOMDRAW
				Select *NMLVCustomDraw\nmcd\dwDrawStage
					Case #CDDS_PREPAINT
						ProcedureReturn #CDRF_NOTIFYITEMDRAW
					Case #CDDS_ITEMPREPAINT
						ProcedureReturn #CDRF_NOTIFYSUBITEMDRAW
					Case #CDDS_ITEMPREPAINT | #CDDS_SUBITEM
						Repeat
							If ViewSkillIndexValue(i) = *NMLVCustomDraw\nmcd\dwItemSpec  ; *NMLVCustomDraw\iSubItem       *NMLVCustomDraw\nmcd\dwItemSpec
								SelectObject_(*NMLVCustomDraw\nmcd\hDC, FontID(BoldFont))
								If i = #PD_GROUP_LENGTH
									SelectObject_(*NMLVCustomDraw\nmcd\hDC, FontID(RegularFont))
									Break
								EndIf
							EndIf
							i + 1
						ForEver
						ProcedureReturn #CDRF_NEWFONT
				EndSelect
			EndIf
		EndIf
	ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Global.i Event, x, Chapter, Tab_Container
Global.i Pnl1, panelgadget, WdwID, IconLvwAttr

	ViewSkillIndexValue(0) = 0
	ViewSkillIndexValue(1) = 10
	ViewSkillIndexValue(2) = 17
	viewSkillIndexValue(3) = 23
	ViewSkillIndexValue(4) = 35
	ViewSkillIndexValue(5) = 42
	ViewSkillIndexValue(6) = 55
	WdwID = OpenWindow(#PB_Any,0,0,420,650,"TEST")
	panelgadget = PanelGadget(#PB_Any, 8,8,404, 634)
	AddGadgetItem(panelgadget, -1,"Panel1")
		Tab_Container          = ContainerGadget(#PB_Any, 0, 0, 404, 634)
		IconLvwAttr             = ListIconGadget(#PB_Any, 10,30,380,550,"Column #1", 200)
		AddGadgetColumn(IconLvwAttr, 1, "Column #2",70)
		AddGadgetColumn(IconLvwAttr, 2, "Column #3",70)
		CloseGadgetList()
	AddGadgetItem(panelgadget, -1,"Panel2")
	CloseGadgetList()
	
	For x = 0 To #TOTALSIZE
		If x = ViewSkillIndexValue(Chapter)
			AddGadgetItem(IconLvwAttr,x,"A Bold Statement")
			If chapter < 6
				chapter + 1
			EndIf
		Else
			AddGadgetItem(IconLvwAttr,x,"Not A Bold Statement" + #LF$ + Str(x) + ":02" + #LF$ + Str(x) + ":03")
		EndIf
	Next x
	SetWindowCallback(@lvwSkillCB() ,IconLvwAttr) 
	Repeat
	Until WaitWindowEvent() = #PB_Event_CloseWindow
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ListIconGadget With some Callback code(Window) problem

Post by srod »

Not quite sure why you have posted in this section?

Anyhow, the PB Window callback should not be set for a ListIcon gadget - only a Window. As it turns out the #WM_NOTIFY messages are sent to the Window proc of the parent control/Window anyhow.

The following works; I had to fix a couple of bugs first.

Code: Select all

EnableExplicit
#PD_GROUP_LENGTH   = 6
#TOTALSIZE         = 60

Global.i Dim ViewSkillIndexValue(#PD_GROUP_LENGTH)
Global.i RegularFont = LoadFont(#PB_Any, "Arial", 9)
Global.i BoldFont = LoadFont(#PB_Any, "Arial", 9, #PB_Font_Bold)

Procedure lvwSkillCB(Window.i, Message.i, wParam.i, lParam.i)
   Protected.i i
   Protected *NMLVCustomDraw.NMLVCUSTOMDRAW
   If Message = #WM_NOTIFY
         *NMLVCustomDraw = lParam
         If *NMLVCustomDraw\nmcd\hdr\code = #NM_CUSTOMDRAW
            ;If *NMLVCustomDraw\nmcd\hdr\hWndFrom = GadgetID(GameListIconListViewSkill) And *NMLVCustomDraw\nmcd\hdr\code = #NM_CUSTOMDRAW
            Select *NMLVCustomDraw\nmcd\dwDrawStage
               Case #CDDS_PREPAINT
                  ProcedureReturn #CDRF_NOTIFYITEMDRAW
               Case #CDDS_ITEMPREPAINT
                  ProcedureReturn #CDRF_NOTIFYSUBITEMDRAW
               Case #CDDS_ITEMPREPAINT | #CDDS_SUBITEM
                  SelectObject_(*NMLVCustomDraw\nmcd\hDC, FontID(RegularFont))
                  For i = 0 To #PD_GROUP_LENGTH
                    If ViewSkillIndexValue(i) = *NMLVCustomDraw\nmcd\dwItemSpec 
                      SelectObject_(*NMLVCustomDraw\nmcd\hDC, FontID(BoldFont))
                      Break
                    EndIf
                  Next
                  ProcedureReturn #CDRF_NEWFONT
            EndSelect
         EndIf
      EndIf
   ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Global.i Event, x, Chapter, Tab_Container
Global.i Pnl1, panelgadget, WdwID, IconLvwAttr

   ViewSkillIndexValue(0) = 0
   ViewSkillIndexValue(1) = 10
   ViewSkillIndexValue(2) = 17
   viewSkillIndexValue(3) = 23
   ViewSkillIndexValue(4) = 35
   ViewSkillIndexValue(5) = 42
   ViewSkillIndexValue(6) = 55
   WdwID = OpenWindow(#PB_Any,0,0,420,650,"TEST")
   panelgadget = PanelGadget(#PB_Any, 8,8,404, 634)
   AddGadgetItem(panelgadget, -1,"Panel1")
      Tab_Container          = ContainerGadget(#PB_Any, 0, 0, 404, 634)
      IconLvwAttr             = ListIconGadget(#PB_Any, 10,30,380,550,"Column #1", 200)
      AddGadgetColumn(IconLvwAttr, 1, "Column #2",70)
      AddGadgetColumn(IconLvwAttr, 2, "Column #3",70)
      CloseGadgetList()
   AddGadgetItem(panelgadget, -1,"Panel2")
   CloseGadgetList()
   
   For x = 0 To #TOTALSIZE
      If x = ViewSkillIndexValue(Chapter)
         AddGadgetItem(IconLvwAttr,x,"A Bold Statement")
         If chapter < 6
            chapter + 1
         EndIf
      Else
         AddGadgetItem(IconLvwAttr,x,"Not A Bold Statement" + #LF$ + Str(x) + ":02" + #LF$ + Str(x) + ":03")
      EndIf
   Next x
   SetWindowCallback(@lvwSkillCB()) 
   Repeat
   Until WaitWindowEvent() = #PB_Event_CloseWindow
I may look like a mule, but I'm not a complete ass.
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: ListIconGadget With some Callback code(Window) problem

Post by GenRabbit »

Thanks for the help. I will have to study it, because I really need to learn more of the Winapi. And youre right, it put in the wrong place(OP). gah.. Fred can you move it where it belongs? :)

Btw by not setting the callback SetWindowCallback(@lvwSkillCB()) will that not mean that if I have two windows, then both windows will trigger this callback?

While SetWindowCallback(@lvwSkillCB(), WdwID) will only trigger this window?
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: ListIconGadget With some Callback code(Window) problem

Post by GenRabbit »

What keeps track of which Control? I moved the code into my project, and there the container has 3 listicongadgets. It runs on all of them
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1252
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: ListIconGadget With some Callback code(Window) problem

Post by Paul »

Just un-comment the line that srod left for you and adapt to your needs...

This example will only modify the ListIconView in the second Window.

Code: Select all

EnableExplicit
#PD_GROUP_LENGTH   = 6
#TOTALSIZE         = 60

Global.i Dim ViewSkillIndexValue(#PD_GROUP_LENGTH)
Global.i RegularFont = LoadFont(#PB_Any, "Arial", 9)
Global.i BoldFont = LoadFont(#PB_Any, "Arial", 9, #PB_Font_Bold)

Global.i Event, x, Chapter, Tab_Container
Global.i Pnl1, panelgadget, WdwID, IconLvwAttr
Global.i Tab_Container2, Pnl12, panelgadget2, WdwID2, IconLvwAttr2

Procedure lvwSkillCB(Window.i, Message.i, wParam.i, lParam.i)
  Protected.i i
  Protected *NMLVCustomDraw.NMLVCUSTOMDRAW
  If Message = #WM_NOTIFY
    *NMLVCustomDraw = lParam
    
    If *NMLVCustomDraw\nmcd\hdr\code = #NM_CUSTOMDRAW
      If IsGadget(IconLvwAttr2)
        If *NMLVCustomDraw\nmcd\hdr\hWndFrom = GadgetID(IconLvwAttr2)  ;<------- adapt
          Select *NMLVCustomDraw\nmcd\dwDrawStage
            Case #CDDS_PREPAINT
              ProcedureReturn #CDRF_NOTIFYITEMDRAW
            Case #CDDS_ITEMPREPAINT
              ProcedureReturn #CDRF_NOTIFYSUBITEMDRAW
            Case #CDDS_ITEMPREPAINT | #CDDS_SUBITEM
              SelectObject_(*NMLVCustomDraw\nmcd\hDC, FontID(RegularFont))
              For i = 0 To #PD_GROUP_LENGTH
                If ViewSkillIndexValue(i) = *NMLVCustomDraw\nmcd\dwItemSpec 
                  SelectObject_(*NMLVCustomDraw\nmcd\hDC, FontID(BoldFont))
                  Break
                EndIf
              Next
            ProcedureReturn #CDRF_NEWFONT
          EndSelect
        EndIf
      EndIf
    EndIf
      
  EndIf
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure



   ViewSkillIndexValue(0) = 0
   ViewSkillIndexValue(1) = 10
   ViewSkillIndexValue(2) = 17
   viewSkillIndexValue(3) = 23
   ViewSkillIndexValue(4) = 35
   ViewSkillIndexValue(5) = 42
   ViewSkillIndexValue(6) = 55
   WdwID = OpenWindow(#PB_Any,0,0,420,650,"TEST")
   panelgadget = PanelGadget(#PB_Any, 8,8,404, 634)
   AddGadgetItem(panelgadget, -1,"Panel1")
      Tab_Container          = ContainerGadget(#PB_Any, 0, 0, 404, 634)
      IconLvwAttr             = ListIconGadget(#PB_Any, 10,30,380,550,"Column #1", 200)
      AddGadgetColumn(IconLvwAttr, 1, "Column #2",70)
      AddGadgetColumn(IconLvwAttr, 2, "Column #3",70)
      CloseGadgetList()
   AddGadgetItem(panelgadget, -1,"Panel2")
   CloseGadgetList()

   WdwID2 = OpenWindow(#PB_Any,450,0,420,650,"TEST")
   panelgadget2 = PanelGadget(#PB_Any, 8,8,404, 634)
   AddGadgetItem(panelgadget2, -1,"Panel1")
      Tab_Container2          = ContainerGadget(#PB_Any, 0, 0, 404, 634)
      IconLvwAttr2             = ListIconGadget(#PB_Any, 10,30,380,550,"Column #1", 200)
      AddGadgetColumn(IconLvwAttr2, 1, "Column #2",70)
      AddGadgetColumn(IconLvwAttr2, 2, "Column #3",70)
      CloseGadgetList()
   AddGadgetItem(panelgadget2, -1,"Panel2")
   CloseGadgetList()
   
   For x = 0 To #TOTALSIZE
      If x = ViewSkillIndexValue(Chapter)
         AddGadgetItem(IconLvwAttr,x,"A Bold Statement")
         AddGadgetItem(IconLvwAttr2,x,"A Bold Statement")
         If chapter < 6
            chapter + 1
         EndIf
      Else
         AddGadgetItem(IconLvwAttr,x,"Not A Bold Statement" + #LF$ + Str(x) + ":02" + #LF$ + Str(x) + ":03")
         AddGadgetItem(IconLvwAttr2,x,"Not A Bold Statement" + #LF$ + Str(x) + ":02" + #LF$ + Str(x) + ":03")
      EndIf
   Next x
   SetWindowCallback(@lvwSkillCB()) 
   Repeat
   Until WaitWindowEvent() = #PB_Event_CloseWindow
Image Image
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: ListIconGadget With some Callback code(Window) problem

Post by GenRabbit »

I did find the info about NMHDR on the net. But I couldn't figure out how? as It didn't match up with the Purebasic NMLVCUSTOMDRAW. but after you wrote the upgrade I see its \nmcd\hdr. Gah...
Thanks for the code. Superb. :)
Post Reply