|
Class: CheckBox
Object
|
+--GraphicsMedium
|
+--DisplaySurface
|
+--SimpleView
|
+--PanelView
|
+--HorizontalPanelView
|
+--CheckBox
|
+--TriggerBox
- Package:
- stx:libwidg2
- Category:
- Views-Interactors
- Version:
- rev:
1.98
date: 2019/07/31 15:38:09
- user: cg
- file: CheckBox.st directory: libwidg2
- module: stx stc-classLibrary: libwidg2
- Author:
- Claus Gittinger
CheckBoxes consist of a checkToggle and a label;
if used without a model, its action block is evaluated
when toggled (see Toggle for more information).
Otherwise, a valueHolder on a boolean is the preferred model
(other models are possible - this may required different aspect
and/or changeMessage settings; make certain to set those before
a model is assigned, since the toggle fetches the value when
a new model is assigned.)
Button
CheckToggle
DialogBox
ValueHolder
defaults
-
updateStyleCache
-
extract values from the styleSheet and cache them in class variables
usage example(s):
instance creation
-
label: aStringOrImage model: aModel
-
create & return a new checkBox, on aModel (typically a ValueHolder),
with aStringOrImage as label.
accessing-behavior
-
action: aBlock
-
set the actionBlock; forwarded to the toggle
-
enabled
-
return true, if the checkBox is enabled.
forwarded to toggle
-
enabled: aBoolean
-
enable/diable the checkBox; forwarded to toggle & change labels color
-
pressAction: aBlock
-
set the pressAction; forwarded to the toggle
-
releaseAction: aBlock
-
set the releaseAction; forwarded to the toggle
accessing-channels
-
backgroundChannel
-
-
backgroundChannel: aChannel
-
-
enableChannel
-
return a valueHolder for enable/disable
-
enableChannel: aChannel
-
set the enableChannel
-
foregroundChannel
-
-
foregroundChannel: aChannel
-
-
labelChannel
-
-
labelChannel: aChannel
-
accessing-color & font
-
backgroundColor
-
get backgroundColor of the label view
-
backgroundColor: aColor
-
set backgroundColor only for myself and the label view
-
disabledLabelEtchedForegroundColor
-
get the disabledLabelForegroundColor; forwarded to the toggle
-
disabledLabelForegroundColor
-
get the disabledLabelForegroundColor; forwarded to the toggle
-
foregroundColor
-
get foregroundColor of the label view
-
foregroundColor: foregroundColor
-
set foregroundColor only for the label view
-
labelForegroundColor
-
get the labels foregroundColor
-
viewBackground: backgroundColor
-
set backgroundColor
accessing-components
-
labelView
-
return the labelView; allows manipulation of the
labels attributes (colors etc.)
-
toggleView
-
return the toggleView; allows manipulation of the
toggles attributes (colors etc.)
accessing-look
-
activeLogo: anImageOrString
-
set the activeLogo; forwarded to the toggle
-
font
-
return the font. Forward from label
-
font: aFont
-
set the font. Forward to the label & resize myself.
CAVEAT: with the addition of Text objects,
this method is going to be obsoleted by a textStyle
method, which allows specific control over
normalFont/boldFont/italicFont parameters.
-
label
-
return the label's logo
-
label: aStringOrImageOrForm
-
set the logo; forward to label & resize
-
passiveLogo: anImageOrString
-
set the passiveLogo; forwarded to the toggle
-
resizeForLabel
-
-
resizeForLabel: aBoolean
-
accessing-mvc
-
aspectMessage: aspectSymbol
-
set the aspectMessage; forward to label & toggle
-
changeMessage: aChangeSelector
-
set the changeMessage; forward to toggle
-
model: aModel
-
set the model; forward to label & toggle
accessing-state
-
isOn
-
return true, if the check is on; false otherwise
-
turnOff
-
turn the check off; forwarded to the toggle
-
turnOn
-
turn the check on; forwarded to the toggle
change & update
-
enableStateChanged
-
handle changes on the enableChannel or fg/bg color, change labels color.
-
update: something with: aParameter from: changedObject
-
changedObject == labelView labelChannel ifTrue:[
event handling
-
invalidate
-
(comment from inherited method)
add a damage to redraw the receiver to its input event queue.
This is preferable to calling redraw directly, in that the drawing is done by
the view's process itself, and there is a possibilty to merge
multiple damage rectangles into single redraws.
However, be aware, that the redrawing may be delayed for some time,
until the receiver's windowGroupProcess gets rescheduled.
-
keyPress: aKey x: x y: y
-
forward some key-events to my toggle-button
-
performShortcutAction
-
focus handling
-
showFocus: explicit
-
the button got the keyboard focus
(either explicit, via tabbing; or implicit, by pointer movement)
- change any display attributes as req'd.
-
showNoFocus: explicit
-
the button lost the keyboard focus
(either explicit, via tabbing; or implicit, by pointer movement)
- change any display attributes as req'd.
initialization & release
-
defaultCheckToggleClass
-
-
defaultControllerClass
-
(comment from inherited method)
Controller
-
initStyle
-
setup viewStyle specifics
-
initialize
-
must be called if redefined
-
release
-
release dependencies
native widget support
-
makeElementsInvisible
-
when using native widget, my toggle is not visible.
(it is not destroyed, to keep a place for its attributes,
and to allow future dynamic switching and snapshot restore on
a non-native system)
-
nativeWindowType
-
return a symbol describing my native window type
(may be used internally by the device as a native window creation hint,
if the device supports native windows)
private
-
resizeForChangedLabel
-
-
sendChangeMessageWith: aValue
-
redefined to have mimic changes being sent from the toggle
instead of myself
queries
-
computePreferredExtent
-
compute & return the boxes preferredExtent from the components' sizes
no-op checkBox without a label:
|b|
b := CheckBox new.
b open
|
no-op checkBox:
|b|
b := CheckBox new.
b label:'foo'.
b open
|
combined instance creation & label setup:
|b|
b := CheckBox label:'foo'.
b open
|
no-op checkBox, disabled:
|b|
b := CheckBox label:'foo'.
b disable.
b open
|
changing colors
(a demo only: it is no good style to fight the styleSheet):
|panel b|
panel := VerticalPanelView new.
b := CheckBox label:'foo' in:panel.
b := CheckBox label:'bar' in:panel.
b labelView foregroundColor:Color red.
b := CheckBox label:'baz' in:panel.
b toggleView activeForegroundColor:Color blue.
panel open
|
using action-blocks:
|b|
b := CheckBox label:'check'.
b action:[:value | Transcript show:'set to: '; showCR:value].
b open.
|
with a model (default ST-80 behavior, sending #value: to the model):
(see changing value in the inspector)
|b model|
model := ValueHolder newBoolean.
b := CheckBox label:'check'.
b model:model.
b open.
model inspect.
|
combined instance creation & model setup:
|b model|
model := ValueHolder newBoolean.
b := CheckBox label:'check' model:model .
b open.
model inspect.
|
with a model and different aspect & changeSelector
setting the aspect to nil suppresses fetching the value from the model.
(using a plug here, for demonstration only):
|b model|
model := Plug new.
model respondTo:#changeCheck: with:[:arg | Transcript showCR:'change to ' , arg printString].
model respondTo:#value with:[false].
b := CheckBox label:'check'.
b aspectMessage:nil; model:model; changeMessage:#changeCheck:.
b open.
|
with an enableChannel
|b enaToggle enaHolder|
enaHolder := true asValue.
enaToggle := Toggle label:'enable'.
enaToggle model:enaHolder.
enaToggle open.
b := CheckBox label:'check'.
b action:[:value | Transcript show:'set to: '; showCR:value].
b enableChannel:enaHolder.
b open.
|
with models, one checkBox disabling the others:
|dialog translator enableChannel val1 val2 val3 eBox box1 box2 box3|
translator := Plug new.
translator respondTo:#enableDisable
with:[
enableChannel value
ifTrue:[
box1 enable.
box2 enable.
box3 enable.
]
ifFalse:[
box1 disable.
box2 disable.
box3 disable.
]
].
enableChannel := true asValue.
enableChannel onChangeSend:#enableDisable to:translator.
val1 := true asValue.
val2 := false asValue.
val3 := true asValue.
dialog := Dialog new.
dialog addCheckBox:'enable' on:enableChannel.
dialog addVerticalSpace.
dialog leftIndent:30.
box1 := dialog addCheckBox:'value1' on:val1.
dialog addVerticalSpace.
box2 := dialog addCheckBox:'value2' on:val2.
dialog addVerticalSpace.
box3 := dialog addCheckBox:'value3' on:val3.
dialog addVerticalSpace.
dialog addOkButton.
dialog open.
|
multiple checkBoxes on a single model (using different aspects)
|top panel b model value1 value2|
value1 := true.
value2 := false.
model := Plug new.
model respondTo:#value1 with:[value1].
model respondTo:#value1: with:[:val | value1 := val].
model respondTo:#value2 with:[value2].
model respondTo:#value2: with:[:val | value2 := val].
top := DialogBox new.
top extent:200@300.
panel := VerticalPanelView new.
b := CheckBox in:panel.
b label:'check1'.
b aspect:#value1; model:model; changeMessage:#value1:.
b := CheckBox in:panel.
b label:'check2'.
b aspect:#value2; model:model; changeMessage:#value2:.
top addComponent:panel.
top addAbortButton; addOkButton.
top openModal.
top accepted ifTrue:[
Transcript show:'value1: '; showCR:model value1.
Transcript show:'value2: '; showCR:model value2.
]
|
|