SetGadgetItemData & SetGadgetItemColor fuer Panel
Verfasst: 03.02.2008 21:30
Code: Alles auswählen
;{ pb intern struct
CompilerIf Defined(PB_GadgetVT, #PB_Structure) = #False
Structure PB_GadgetVT
GadgetType.l
SizeOf.l
GadgetCallback.l
FreeGadget.l
GetGadgetState.l
SetGadgetState.l
GetGadgetText.l
SetGadgetText.l
AddGadgetItem2.l
AddGadgetItem3.l
RemoveGadgetItem.l
ClearGadgetItemList.l
ResizeGadget.l
CountGadgetItems.l
GetGadgetItemState.l
SetGadgetItemState.l
GetGadgetItemText.l
SetGadgetItemText.l
OpenGadgetList2.l
GadgetX.l
GadgetY.l
GadgetWidth.l
GadgetHeight.l
HideGadget.l
AddGadgetColumn.l
RemoveGadgetColumn.l
GetGadgetAttribute.l
SetGadgetAttribute.l
GetGadgetItemAttribute2.l
SetGadgetItemAttribute2.l
SetGadgetColor.l
GetGadgetColor.l
SetGadgetItemColor2.l
GetGadgetItemColor2.l
SetGadgetItemData.l
GetGadgetItemData.l
EndStructure
CompilerEndIf
CompilerIf Defined(PB_Gadget, #PB_Structure) = #False
Structure PB_Gadget
Gadget.l
*VT.PB_GadgetVT
UserData.l
OldCallback.l
Daten.l[4]
EndStructure
Structure PB_Panel_User_Data
user_data.l
forecolor.l
backcolor.l
static_callback.l
EndStructure
CompilerEndIf ;}
Declare PB_GetPanelStaticItem(*gadget.PB_Gadget ,item)
Declare PB_GetGadgetItemData (*gadget.PB_Gadget ,item)
Declare PB_SetGadgetItemData (*gadget.PB_Gadget ,item,value)
Procedure PB_PanelStaticCB(hwnd,msg,wparam,lparam)
Protected *pud.PB_Panel_User_Data
Protected callback.l
*pud = GetWindowLong_(hwnd,#GWL_USERDATA)
callback = *pud\static_callback
If #WM_DESTROY = msg
FreeMemory(*pud)
EndIf
ProcedureReturn CallWindowProc_(callback,hwnd,msg,wparam,lparam)
EndProcedure
Procedure PB_PanelParentCB(hwnd,msg,wparam,lparam)
Protected *pud.PB_Panel_User_Data
Protected *dis.DRAWITEMSTRUCT
Protected shWnd.l
Protected callback.l = GetProp_(hWnd,"_oldCallback")
Protected fore.l,back.l,backbrush.l,text.s
If #WM_DESTROY = msg
SetWindowLong_(hwnd,#GWL_WNDPROC,callback)
RemoveProp_(hwnd,"_oldCallback")
EndIf
If #WM_DRAWITEM = msg
*dis = lParam
If *dis\CtlType = #ODT_TAB
shWnd = PB_GetPanelStaticItem(IsGadget(*dis\CtlID),*dis\itemID)
*pud = GetWindowLong_(shWnd,#GWL_USERDATA)
If *pud
fore = *pud\ForeColor
back = *pud\BackColor
If back = #PB_Default
back = GetSysColor_(#COLOR_BTNFACE)
EndIf
If fore = #PB_Default
fore = GetSysColor_(#COLOR_BTNTEXT)
EndIf
Else
fore = GetSysColor_(#COLOR_BTNTEXT)
back = GetSysColor_(#COLOR_BTNFACE)
EndIf
backbrush = CreateSolidBrush_(back)
fore = SetTextColor_(*dis\hdc, fore)
FillRect_(*dis\hdc, *dis\rcItem, backbrush)
SetBkMode_(*dis\hdc, #TRANSPARENT)
text = GetGadgetItemText(*dis\CtlID,*dis\ItemID)
DrawText_(*dis\hdc, text, Len(text), *dis\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER)
DeleteObject_(backbrush)
SetTextColor_(*dis\hdc, fore)
ProcedureReturn 0
EndIf
EndIf
ProcedureReturn CallWindowProc_(callback,hwnd,msg,wparam,lparam)
EndProcedure
Procedure PB_GetPanelStaticItem(*gadget.PB_Gadget ,item)
Protected tci.TC_ITEM\mask = #TCIF_PARAM
If SendMessage_(*gadget\gadget ,#TCM_GETITEM ,item ,@tci)
ProcedureReturn tci\lParam
EndIf
EndProcedure
Procedure PB_SetGadgetItemColor(*Gadget.PB_Gadget,item.l,ColorType.l,Color,col.l)
Protected hwnd = PB_GetPanelStaticItem(*gadget,item)
Protected *pud.PB_Panel_User_Data
Protected result.l,panel_callback.l
*pud = GetWindowLong_(hwnd ,#GWL_USERDATA)
If Not *pud
*pud = AllocateMemory(SizeOf(PB_Panel_User_Data))
If Not *pud ; no memory
ProcedureReturn 0
EndIf
SetWindowLong_(hwnd ,#GWL_USERDATA,*pud)
*pud\static_callback = SetWindowLong_(hwnd,#GWL_WNDPROC,@PB_PanelStaticCB())
*pud\ForeColor = -1
*pud\BackColor = -1
EndIf
panel_callback = GetProp_(GetParent_(*Gadget\gadget),"_oldCallback")
If Not panel_callback
panel_callback = SetWindowLong_(GetParent_(*Gadget\gadget),#GWL_WNDPROC,@PB_PanelParentCB())
EndIf
SetWindowLong_(*Gadget\gadget, #GWL_STYLE, GetWindowLong_(*Gadget\gadget, #GWL_STYLE) | #TCS_OWNERDRAWFIXED)
SetProp_(GetParent_(*Gadget\gadget),"_oldCallback",panel_callback)
Select ColorType
Case #PB_Gadget_FrontColor
*pud\ForeColor = color
Case #PB_Gadget_BackColor
*pud\BackColor = color
EndSelect
SetWindowPos_(*Gadget\gadget,0,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE|#SWP_NOZORDER|#SWP_FRAMECHANGED)
EndProcedure
Procedure PB_GetGadgetItemColor(*Gadget.PB_Gadget,item.l,ColorType.l,col.l)
Protected hwnd = PB_GetPanelStaticItem(*gadget,item)
Protected *pud.PB_Panel_User_Data
Protected result.l
*pud = GetWindowLong_(hwnd ,#GWL_USERDATA)
Select ColorType
Case #PB_Gadget_FrontColor
result = *pud\ForeColor
Case #PB_Gadget_BackColor
result = *pud\BackColor
EndSelect
ProcedureReturn result
EndProcedure
Procedure PB_GetGadgetItemData(*gadget.PB_Gadget ,item)
Protected hwnd = PB_GetPanelStaticItem(*gadget ,item)
Protected *pud.PB_Panel_User_Data
If hwnd
*pud = GetWindowLong_(hwnd ,#GWL_USERDATA)
If *pud
ProcedureReturn *pud\user_data
EndIf
EndIf
EndProcedure
Procedure PB_SetGadgetItemData(*gadget.PB_Gadget,item,value)
Protected hwnd = PB_GetPanelStaticItem(*gadget,item)
Protected *pud.PB_Panel_User_Data
Protected result.l
*pud = GetWindowLong_(hwnd,#GWL_USERDATA)
If Not *pud
*pud = AllocateMemory(SizeOf(PB_Panel_User_Data))
If Not *pud ; no memory
ProcedureReturn 0
EndIf
SetWindowLong_(hwnd ,#GWL_USERDATA,*pud)
*pud\static_callback = SetWindowLong_(hwnd,#GWL_WNDPROC,@PB_PanelStaticCB())
*pud\ForeColor = -1
*pud\BackColor = -1
EndIf
result = *pud\user_data
*pud\user_data = value
ProcedureReturn result
EndProcedure
Procedure PB_PanelGadget(id.l ,x.l ,y.l ,cx.l ,cy.l)
Protected value = PanelGadget(id,x,y,cx,cy)
Protected *gadget.PB_Gadget
If id = #PB_Any
id = value
EndIf
*gadget = IsGadget(id)
If *gadget
*gadget\vt\SetGadgetItemData = @PB_SetGadgetItemData()
*gadget\vt\GetGadgetItemData = @PB_GetGadgetItemData()
*gadget\vt\SetGadgetItemColor2 = @PB_SetGadgetItemColor()
*gadget\vt\GetGadgetItemColor2 = @PB_GetGadgetItemColor()
EndIf
ProcedureReturn value
EndProcedure
Macro PanelGadget
PB_PanelGadget
EndMacro
Test :
Code: Alles auswählen
Define hwnd
hwnd = OpenWindow(0,#PB_Ignore,#PB_Ignore,300,300,"Test")
CreateGadgetList(hwnd)
PanelGadget(0,0,0,300,300)
AddGadgetItem(0,0,"1")
AddGadgetItem(0,1,"2")
AddGadgetItem(0,2,"3")
SetGadgetItemColor(0,2,#PB_Gadget_FrontColor,$0D9FF2)
SetGadgetItemColor(0,2,#PB_Gadget_BackColor,$ff)
Repeat
Until WaitWindowEvent() = 16
SetGadgetItemData
GetGadgetItemData
SetGadgetItemColor
GetGadgetItemColor