eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CheckBox':



Class: CheckBox



rev: 1.98 date: 2019/07/31 15:38:09
user: cg
file: CheckBox.st directory: libwidg2
module: stx stc-classLibrary: libwidg2
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.)

Related information:


Class protocol:

o  updateStyleCache
extract values from the styleSheet and cache them in class variables

usage example(s):

     self updateStyleCache

instance creation
o  label: aStringOrImage model: aModel
create & return a new checkBox, on aModel (typically a ValueHolder),
with aStringOrImage as label.

Instance protocol:

o  action: aBlock
set the actionBlock; forwarded to the toggle

o  enabled
return true, if the checkBox is enabled.
forwarded to toggle

o  enabled: aBoolean
enable/diable the checkBox; forwarded to toggle & change labels color

o  pressAction: aBlock
set the pressAction; forwarded to the toggle

o  releaseAction: aBlock
set the releaseAction; forwarded to the toggle

o  backgroundChannel

o  backgroundChannel: aChannel

o  enableChannel
return a valueHolder for enable/disable

o  enableChannel: aChannel
set the enableChannel

o  foregroundChannel

o  foregroundChannel: aChannel

o  labelChannel

o  labelChannel: aChannel

accessing-color & font
o  backgroundColor
get backgroundColor of the label view

o  backgroundColor: aColor
set backgroundColor only for myself and the label view

o  disabledLabelEtchedForegroundColor
get the disabledLabelForegroundColor; forwarded to the toggle

o  disabledLabelForegroundColor
get the disabledLabelForegroundColor; forwarded to the toggle

o  foregroundColor
get foregroundColor of the label view

o  foregroundColor: foregroundColor
set foregroundColor only for the label view

o  labelForegroundColor
get the labels foregroundColor

o  viewBackground: backgroundColor
set backgroundColor

o  labelView
return the labelView; allows manipulation of the
labels attributes (colors etc.)

o  toggleView
return the toggleView; allows manipulation of the
toggles attributes (colors etc.)

o  activeLogo: anImageOrString
set the activeLogo; forwarded to the toggle

o  font
return the font. Forward from label

o  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.

o  label
return the label's logo

o  label: aStringOrImageOrForm
set the logo; forward to label & resize

o  passiveLogo: anImageOrString
set the passiveLogo; forwarded to the toggle

o  resizeForLabel

o  resizeForLabel: aBoolean

o  aspectMessage: aspectSymbol
set the aspectMessage; forward to label & toggle

o  changeMessage: aChangeSelector
set the changeMessage; forward to toggle

o  model: aModel
set the model; forward to label & toggle

o  isOn
return true, if the check is on; false otherwise

o  turnOff
turn the check off; forwarded to the toggle

o  turnOn
turn the check on; forwarded to the toggle

change & update
o  enableStateChanged
handle changes on the enableChannel or fg/bg color, change labels color.

o  update: something with: aParameter from: changedObject
changedObject == labelView labelChannel ifTrue:[

event handling
o  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.

o  keyPress: aKey x: x y: y
forward some key-events to my toggle-button

o  performShortcutAction

focus handling
o  showFocus: explicit
the button got the keyboard focus
(either explicit, via tabbing; or implicit, by pointer movement)
- change any display attributes as req'd.

o  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
o  defaultCheckToggleClass

o  defaultControllerClass
(comment from inherited method)

o  initStyle
setup viewStyle specifics

o  initialize
must be called if redefined

o  release
release dependencies

native widget support
o  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)

o  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)

o  resizeForChangedLabel

o  sendChangeMessageWith: aValue
redefined to have mimic changes being sent from the toggle
instead of myself

o  computePreferredExtent
compute & return the boxes preferredExtent from the components' sizes


no-op checkBox without a label:

   b := CheckBox new.
   b open
no-op checkBox:

   b := CheckBox new.
   b label:'foo'.
   b open
combined instance creation & label setup:

   b := CheckBox label:'foo'.
   b open
no-op checkBox, disabled:

   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 := 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
                      enableChannel value
                              box1 enable.
                              box2 enable.
                              box3 enable.
                              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.

ST/X; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Sat, 20 Apr 2024 21:01:14 GMT