5. More Property list cell types
Boolean & Enable
Function PropList_AddBoolean(PropList, Caption$, Value)
Local MainGadgetData As DWORD
Local NewCell As DWORD
MainGadgetData = GetGadgetData(PropList)
CellPanel = Peek Integer(MainGadgetData+PROPLIST_CELLPANEL)
CW = GadgetWidth(CellPanel)
LW = Peek Integer(MainGadgetData+PROPLIST_LABELWIDTH)
ClH = Peek Integer(MainGadgetData+PROPLIST_CELLHEIGHT)
Y = GadgetHeight(CellPanel)
If Y Then Inc Y, 2
ResizeGadget CellPanel, GadgetWidth(CellPanel), Y+ClH
NewLabel = CreateLabel(0, Y+3, LW, ClH-3, Caption$, CellPanel)
Font = Peek Integer(MainGadgetData+PROPLIST_FONT): If Font Then ApplyFont NewLabel, Font
NewCheckBox = CreateCheckBox(LW, Y, CW-LW, ClH, "", CellPanel)
SetChecked NewCheckBox, Value
SetGadgetData NewCheckBox, Value
NewCell = _PropList_NewCell(MainGadgetData, 2)
Poke Integer NewCell+PROPLISTCELL_FUNCTION, Get Ptr To Function("_PropList_EnableFunction")
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET, NewCheckBox
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+4, NewLabel
EndFunction NewCell
Function PropList_AddEnable(PropList, Caption$, Value)
Local NewCell As DWORD
MainGadgetData = GetGadgetData(PropList)
CellPanel = Peek Integer(MainGadgetData+PROPLIST_CELLPANEL)
CW = GadgetWidth(CellPanel)
LW = Peek Integer(MainGadgetData+PROPLIST_LABELWIDTH)
ClH = Peek Integer(MainGadgetData+PROPLIST_CELLHEIGHT)
Y = GadgetHeight(CellPanel): If Y Then Inc Y, 2
ResizeGadget CellPanel, CW, Y+ClH, 1
NewCheckBox = CreateCheckBox(0, Y+3, CW, ClH-3, Caption$, CellPanel)
Font = Peek Integer(MainGadgetData+PROPLIST_FONT): If Font Then ApplyFont NewCheckBox, Font
SetChecked NewCheckBox, Value
SetGadgetData NewCheckBox, Value
NewCell = _PropList_NewCell(MainGadgetData, 1)
Poke Integer NewCell+PROPLISTCELL_FUNCTION, Get Ptr To Function("_PropList_EnableFunction")
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET, NewCheckBox
EndFunction NewCell
Function _PropList_EnableFunction(MainGadgetData As DWORD, Cell As DWORD)
CheckBox = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET)
Value = GetChecked(CheckBox)
Changed = (GetGadgetData(CheckBox) <> Value)
SetGadgetData CheckBox, Value
Poke Integer Cell+PROPLISTCELL_CHANGED, Changed
EndFunction Changed
ComboBox
Function PropList_AddComboBox(PropList, Caption$, ComboBoxText$)
Local MainGadgetData As DWORD
Local NewCell As DWORD
MainGadgetData = GetGadgetData(PropList)
CellPanel = Peek Integer(MainGadgetData+PROPLIST_CELLPANEL)
CW = GadgetWidth(CellPanel)
LW = Peek Integer(MainGadgetData+PROPLIST_LABELWIDTH)
ClH = Peek Integer(MainGadgetData+PROPLIST_CELLHEIGHT)
Y = GadgetHeight(CellPanel)
If Y Then Inc Y, 2
ResizeGadget CellPanel, GadgetWidth(CellPanel), Y+ClH
NewLabel = CreateLabel(0, Y+3, LW, ClH-3, Caption$, CellPanel)
Font = Peek Integer(MainGadgetData+PROPLIST_FONT): If Font Then ApplyFont NewLabel, Font
NewComboBox = CreateComboBox(LW, Y, CW-LW, ClH, CellPanel)
Split CSV String ComboBoxText$, ";", chr$(34)
Count = Split Count()
For i = 1 To Count: AddItem NewComboBox, Split Word$(i): Next i
SelectItem NewComboBox, 0
SetGadgetData NewComboBox, 0
Font = Peek Integer(MainGadgetData+PROPLIST_FONT): If Font Then ApplyFont NewComboBox, Font
NewCell = _PropList_NewCell(MainGadgetData, 2)
Poke Integer NewCell+PROPLISTCELL_FUNCTION, Get Ptr To Function("_PropList_ComboBoxFunction")
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET, NewComboBox
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+4, NewLabel
EndFunction NewCell
Function _PropList_ComboBoxFunction(MainGadgetData As DWORD, Cell As DWORD)
ComboBox = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET)
Label = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+4)
ValidatedGadget = Peek Integer(MainGadgetData+PROPLIST_VALIDATEGADGET)
If ActiveGadget() = Label Then ValidatedGadget = -1
NextValidatedGadget = ValidatedGadget
If ValidatedGadget = -1
ActivateGadget ComboBox
NextValidatedGadget = 0
EndIf
If ValidatedGadget = ComboBox
Changed = true
Poke Integer Cell+PROPLISTCELL_CHANGED, true
NextValidatedGadget = -1
EndIf
Poke Integer MainGadgetData+PROPLIST_VALIDATEGADGET, NextValidatedGadget
SelItem = SelectedItem(ComboBox)
Changed = (GetGadgetData(ComboBox) <> SelItem)
If Changed Then SetGadgetData ComboBox, SelItem
Poke Integer Cell+PROPLISTCELL_CHANGED, Changed
EndFunction Changed
Button
Function PropList_AddButton(PropList, Caption$)
Local MainGadgetData As DWORD
Local NewCell As DWORD
MainGadgetData = GetGadgetData(PropList)
CellPanel = Peek Integer(MainGadgetData+PROPLIST_CELLPANEL)
CW = GadgetWidth(CellPanel)
LW = Peek Integer(MainGadgetData+PROPLIST_LABELWIDTH)
ClH = Peek Integer(MainGadgetData+PROPLIST_CELLHEIGHT)
Y = GadgetHeight(CellPanel)
If Y Then Inc Y, 2
ResizeGadget CellPanel, GadgetWidth(CellPanel), Y+ClH
NewButton = CreateButton(0, Y, CW, ClH, Caption$, false, CellPanel)
Font = Peek Integer(MainGadgetData+PROPLIST_FONT): If Font Then ApplyFont NewButton, Font
NewCell = _PropList_NewCell(MainGadgetData, 1)
Poke Integer NewCell+PROPLISTCELL_FUNCTION, Get Ptr To Function("_PropList_ButtonFunction")
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET, NewButton
EndFunction NewCell
Function _PropList_ButtonFunction(MainGadgetData As DWORD, Cell As DWORD)
Button = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET)
Changed = (Peek Integer(MainGadgetData+PROPLIST_CLICKGADGET) = Button)
If GadgetUnderMouse() <> Button Then Changed = 0
SetGadgetData Button, Changed
Poke Integer Cell+PROPLISTCELL_CHANGED, Changed
EndFunction Changed
Vector
Function PropList_AddVector(PropList, Caption$, X#, Y#, Z#)
Local MainGadgetData As DWORD
Local NewCell As DWORD
MainGadgetData = GetGadgetData(PropList)
CellPanel = Peek Integer(MainGadgetData+PROPLIST_CELLPANEL)
LW = 12
CW = GadgetWidth(CellPanel)
EW = (CW - 4 - 3*LW) / 3
ClH = Peek Integer(MainGadgetData+PROPLIST_CELLHEIGHT)
Y = GadgetHeight(CellPanel)
If Y Then Inc Y, 2
ResizeGadget CellPanel, GadgetWidth(CellPanel), Y+2*ClH - 4
NewLabel = CreateLabel(0, Y+3, CW, ClH-7, Caption$, CellPanel)
Font = Peek Integer(MainGadgetData+PROPLIST_BOLDFONT): If Font Then ApplyFont NewLabel, Font
Font = Peek Integer(MainGadgetData+PROPLIST_FONT)
Y = Y + ClH - 4
NewLabelX = CreateLabel(0, Y+3, LW, ClH-3, "X", CellPanel)
If Font Then ApplyFont NewLabelX, Font
NewEditX = CreateEdit(LW, Y, EW, ClH, 0, CellPanel)
SetGadgetText NewEditX, Str$(X#)
If Font Then ApplyFont NewEditX, Font
X = LW + EW + 2
NewLabelY = CreateLabel(X, Y+3, LW, ClH-3, "Y", CellPanel)
If Font Then ApplyFont NewLabelY, Font
NewEditY = CreateEdit(X+LW, Y, EW, ClH, 0, CellPanel)
SetGadgetText NewEditY, Str$(Y#)
If Font Then ApplyFont NewEditY, Font
X = X + LW + EW + 2
NewLabelZ = CreateLabel(X, Y+3, LW, ClH-3, "Z", CellPanel)
If Font Then ApplyFont NewLabelZ, Font
NewEditZ = CreateEdit(X+LW, Y, CW-(X-LW), ClH, 0, CellPanel)
SetGadgetText NewEditZ, Str$(Z#)
If Font Then ApplyFont NewEditZ, Font
X = X + LW + EW + 2
NewCell = _PropList_NewCell(MainGadgetData, 7)
Poke Integer NewCell+PROPLISTCELL_FUNCTION, Get Ptr To Function("_PropList_VectorFunction")
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET, NewEditX
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+ 4, NewEditY
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+ 8, NewEditZ
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+12, NewLabel
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+16, NewLabelX
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+20, NewLabelY
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+24, NewLabelZ
EndFunction NewCell
Function _PropList_VectorFunction(MainGadgetData As DWORD, Cell As DWORD)
EditX = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET)
EditY = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+ 4)
EditZ = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+ 8)
Label = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+12)
LabelX = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+16)
LabelY = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+20)
LabelZ = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+24)
_ActiveGadget = ActiveGadget()
ValidatedGadget = Peek Integer(MainGadgetData+PROPLIST_VALIDATEGADGET)
NextValidatedGadget = ValidatedGadget
If ValidatedGadget = -1 Or _ActiveGadget = Label Or _ActiveGadget = Label
ActivateGadget EditX
SetSelStart EditX, 0
SetSelLen EditX, Fast Len(GetGadgetText(EditX))
NextValidatedGadget = 0
EndIf
If ValidatedGadget = EditX Or _ActiveGadget = LabelY
ActivateGadget EditY
SetSelStart EditY, 0
SetSelLen EditY, Fast Len(GetGadgetText(EditY))
NextValidatedGadget = 0
EndIf
If ValidatedGadget = EditY Or _ActiveGadget = LabelZ
ActivateGadget EditZ
SetSelStart EditZ, 0
SetSelLen EditZ, Fast Len(GetGadgetText(EditZ))
NextValidatedGadget = 0
EndIf
If ValidatedGadget = EditZ
NextValidatedGadget = -1
EndIf
Poke Integer MainGadgetData+PROPLIST_VALIDATEGADGET, NextValidatedGadget
Changed = (ValidatedGadget = EditX) Or (ValidatedGadget = EditY) Or (ValidatedGadget = EditZ)
Poke Integer Cell+PROPLISTCELL_CHANGED, Changed
EndFunction Changed
Resource Selector
Function PropList_AddResourceSelector(PropList, Caption$, ResourceName$)
MainGadgetData = GetGadgetData(PropList)
CellPanel = Peek Integer(MainGadgetData+PROPLIST_CELLPANEL)
CW = GadgetWidth(CellPanel)
LW = Peek Integer(MainGadgetData+PROPLIST_LABELWIDTH)
ClH = Peek Integer(MainGadgetData+PROPLIST_CELLHEIGHT)
Y = GadgetHeight(CellPanel)
If Y Then Inc Y, 2
ResizeGadget CellPanel, GadgetWidth(CellPanel), Y+ClH
NewLabel = CreateLabel(0, Y+3, LW, ClH-3, Caption$, CellPanel)
Font = Peek Integer(MainGadgetData+PROPLIST_FONT): If Font Then ApplyFont NewLabel, Font
NewPanel = CreatePanel(LW, Y, CW-LW-27, ClH, CellPanel)
SetPanelBorderStyle NewPanel, BORDER_FLAT
NewLabel2 = CreateLabel(2, 2, CW, ClH, ResourceName$, NewPanel)
If Font Then ApplyFont NewLabel2, Font
NewButton = CreateButton(CW-25, Y, 25, ClH, "...", false, CellPanel)
NewCell = _PropList_NewCell(MainGadgetData, 4)
Poke Integer NewCell+PROPLISTCELL_FUNCTION, Get Ptr To Function("_PropList_ResourceSelectorFunction")
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET, NewLabel2
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+4, NewLabel
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+8, NewButton
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+12, NewPanel
EndFunction NewCell
Function _PropList_ResourceSelectorFunction(MainGadgetData As DWORD, Cell As DWORD)
Label = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+4)
Button = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+8)
Changed = (Peek Integer(MainGadgetData+PROPLIST_CLICKGADGET) = Button)
If Changed Then Poke Integer MainGadgetData+PROPLIST_CLICKGADGET, 0
Changed = Changed && (GadgetUnderMouse() = Button)
SetGadgetData Button, Changed
Poke Integer Cell+PROPLISTCELL_CHANGED, Changed
ValidatedGadget = Peek Integer(MainGadgetData+PROPLIST_VALIDATEGADGET)
If ActiveGadget() = Label Then ValidatedGadget = -1
NextValidatedGadget = ValidatedGadget
If ValidatedGadget = -1
ActivateGadget Button
NextValidatedGadget = 0
EndIf
Poke Integer MainGadgetData+PROPLIST_VALIDATEGADGET, NextValidatedGadget
EndFunction Changed
Color Selector
Function PropList_AddColorRGB(PropList, Caption$, ColorRGB)
MainGadgetData = GetGadgetData(PropList)
CellPanel = Peek Integer(MainGadgetData+PROPLIST_CELLPANEL)
CW = GadgetWidth(CellPanel)
LW = Peek Integer(MainGadgetData+PROPLIST_LABELWIDTH)
ClH = Peek Integer(MainGadgetData+PROPLIST_CELLHEIGHT)
Y = GadgetHeight(CellPanel)
If Y Then Inc Y, 2
ResizeGadget CellPanel, GadgetWidth(CellPanel), Y+ClH
NewLabel = CreateLabel(0, Y+3, LW, ClH-3, Caption$, CellPanel)
Font = Peek Integer(MainGadgetData+PROPLIST_FONT): If Font Then ApplyFont NewLabel, Font
NewPanel = CreatePanel(LW, Y, CW-LW, ClH, CellPanel)
SetPanelBorderStyle NewPanel, BORDER_SUNKEN
SetGadgetColor NewPanel, ColorRGB, 0
NewCell = _PropList_NewCell(MainGadgetData, 2)
Poke Integer NewCell+PROPLISTCELL_FUNCTION, Get Ptr To Function("_PropList_ColorFunction")
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET, NewPanel
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET+4, NewLabel
EndFunction NewCell
Function _PropList_ColorFunction(MainGadgetData As DWORD, Cell As DWORD)
Panel = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET)
Label = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET+4)
If ActiveGadget() = Label Then Poke Integer MainGadgetData+PROPLIST_VALIDATEGADGET, -1
Changed = false
If Peek Integer(MainGadgetData+PROPLIST_EDITGADGET) = Panel
SetDialogOwner Panel
Color = ColorDialog()
If Color <> -1
SetGadgetColor Panel, Color, 0
SetGadgetData Panel, Color
Changed = true
EndIf
SetDialogOwner 0
EndIf
Poke Integer Cell+PROPLISTCELL_CHANGED, Changed
EndFunction Changed
ListBox
Function PropList_AddListBox(PropList, H)
Local NewCell As DWORD
MainGadgetData = GetGadgetData(PropList)
CellPanel = Peek Integer(MainGadgetData+PROPLIST_CELLPANEL)
CW = GadgetWidth(CellPanel)
LW = Peek Integer(MainGadgetData+PROPLIST_LABELWIDTH)
ClH = Peek Integer(MainGadgetData+PROPLIST_CELLHEIGHT)
Y = GadgetHeight(CellPanel): If Y Then Inc Y, 2
ResizeGadget CellPanel, CW, Y+H
NewListBox = CreateListBox(0, Y, CW, H, CellPanel)
Font = Peek Integer(MainGadgetData+PROPLIST_FONT): If Font Then ApplyFont NewListBox, Font
NewCell = _PropList_NewCell(MainGadgetData, 1)
Poke Integer NewCell+PROPLISTCELL_FUNCTION, Get Ptr To Function("_PropList_ListBoxFunction")
Poke Integer NewCell+PROPLISTCELL_FIRSTGADGET, NewListBox
EndFunction NewCell
Function _PropList_ListBoxFunction(MainGadgetData As DWORD, Cell As DWORD)
ListBox = Peek Integer(Cell+PROPLISTCELL_FIRSTGADGET)
SelItem = SelectedItem(ListBox)
Changed = false
ValidatedGadget = Peek Integer(MainGadgetData+PROPLIST_VALIDATEGADGET)
NextValidatedGadget = ValidatedGadget
If ActiveGadget() = ListBox Then Poke Integer MainGadgetData+PROPLIST_VALIDATEGADGET, -1
If ValidatedGadget = ListBox
If SelItem >= 0
Changed = true
Poke Integer Cell+PROPLISTCELL_CHANGED, true
EndIf
NextValidatedGadget = 0
EndIf
Poke Integer MainGadgetData+PROPLIST_VALIDATEGADGET, NextValidatedGadget
If Peek Integer(MainGadgetData+PROPLIST_SELECTGADGET) = ListBox
If SelItem >= 0
Changed = true
Poke Integer Cell+PROPLISTCELL_CHANGED, true
EndIf
EndIf
SetGadgetData ListBox, SelItem
EndFunction Changed
Code to add in the demo:
...
PropListCell_Enable = PropList_AddEnable(PropList, "Enabled", true)
PropListCell_Boolean = PropList_AddBoolean(PropList, "Boolean", true)
PropListCell_ComboBox = PropList_AddComboBox(PropList, "ComboBox", "Item 1;Item 2;Item 3;Item 4")
PropListCell_Button = PropList_AddButton(PropList, "Button")
PropListCell_Vector = PropList_AddVector(PropList, "Vector", 1.0, 2.0, 3.0)
PropListCell_Color = PropList_AddColorRGB(PropList, "Color", 0x0000ff)
PropListCell_ResSel = PropList_AddResourceSelector(PropList, "ResourceSelector", "My resource")
...
...
If PropListCell_IsChanged(PropListCell_Boolean) Then Print Console "Boolean changed: ", PropListCell_GetValue(PropListCell_Boolean, 0), CRLF$()
If PropListCell_IsChanged(PropListCell_Enable) Then Print Console "Enable changed: ", PropListCell_GetValue(PropListCell_Enable, 0), CRLF$()
If PropListCell_IsChanged(PropListCell_ComboBox) Then Print Console "Enable changed: ", PropListCell_GetValue(PropListCell_ComboBox, 0), CRLF$()
If PropListCell_IsChanged(PropListCell_Color) Then Print Console "Color clicked: "+Hex$(PropListCell_GetValue(PropListCell_Color, 0)), CRLF$()
If PropListCell_IsChanged(PropListCell_Button) Then Print Console "Button clicked: ", PropListCell_GetValue(PropListCell_Button, 0), CRLF$()
If PropListCell_IsChanged(PropListCell_ResSel) Then Print Console "ResSel clicked: ", PropListCell_GetValue(PropListCell_ResSel, 2), CRLF$()
If PropListCell_IsChanged(PropListCell_Vector)
v1# = Val(PropListCell_GetText(PropListCell_Vector, 0))
v2# = Val(PropListCell_GetText(PropListCell_Vector, 1))
v3# = Val(PropListCell_GetText(PropListCell_Vector, 2))
Print Console "Vector changed: ", v1#, " ", v2#, " ", v3#, CRLF$()
EndIf
...
The Property List Demo project file (Download)
All hail the new flesh