BlockValue.st
author Claus Gittinger <cg@exept.de>
Sat, 08 Dec 2001 01:36:32 +0100
changeset 1537 364eabac0aec
parent 1352 cd83d6348a36
child 1665 096ca1b11ce1
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
     3
	      All Rights Reserved
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
ValueModel subclass:#BlockValue
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'cachedValue arguments block'
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
    16
	classVariableNames:'NeverComputed'
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Interface-Support-Models'
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!BlockValue class methodsFor:'documentation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
 COPYRIGHT (c) 1995 by Claus Gittinger
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    26
	      All Rights Reserved
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
documentation
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    BlockValues depend on multiple other objects (typically valueHolders)
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    and recompute a value whenever one of them changes.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    If the new value is different, it triggers itself a change to its dependents.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    Example use is to base an enableChannels value on multiple other boolean values.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    (See example for how this is done)
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 158
diff changeset
    46
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    47
    Notice: 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    48
        this class was implemented using protocol information
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    49
        from alpha testers - it may not be complete or compatible to
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    50
        the corresponding ST-80 class. 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    51
        If you encounter any incompatibilities, please forward a note 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    52
        describing the incompatibility verbal (i.e. no code) to the ST/X team.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    53
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 158
diff changeset
    54
    [author:]
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 158
diff changeset
    55
        Claus Gittinger
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
examples
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    62
    checkToggle 3 shows the value of toggle1 AND toggle2
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    63
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    64
        |val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    65
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    66
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    67
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    68
        both := BlockValue 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    69
                    with:[:v1 :v2 | 
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
    70
                            Transcript showCR:'evaluating ...'.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    71
                            v1 value and:[v2 value]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    72
                         ] 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    73
                    arguments:(Array with:val1 with:val2).
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    74
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    75
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    76
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    77
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    78
        box addHorizontalLine.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    79
        box addCheckBox:'both' on:both.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
    80
        box addOkButton.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    81
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    82
                                                                        [exEnd]
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    83
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    84
    the same, using a convenient instance creation message:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    85
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    86
        |val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    87
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    88
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    89
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    90
        both := BlockValue forLogical:val1 and:val2.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    92
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    93
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    94
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    95
        box addHorizontalLine.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
    96
        (box addCheckBox:'both' on:both) disable.
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
    97
        box addOkButton.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    98
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    99
                                                                        [exEnd]
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   100
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   101
    logical or:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   102
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   103
        |val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   104
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   105
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   106
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   107
        both := BlockValue forLogical:val1 or:val2.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   109
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   110
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   111
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   112
        box addHorizontalLine.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   113
        box addCheckBox:'both' on:both.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   114
        box addOkButton.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   115
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   116
                                                                        [exEnd]
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   117
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   118
    example use: enabling an element depending on two others:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   119
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   120
        |val1 val2 enabler val3 box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   121
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   122
        val1 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   123
        val2 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   124
        val3 := false asValue.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   125
        enabler := BlockValue forLogical:val1 and:val2.
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   126
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   127
        box := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   128
        box addCheckBox:'one' on:val1.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   129
        box addCheckBox:'two' on:val2.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   130
        box addHorizontalLine.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   131
        (box addCheckBox:'three (both of the above)' on:val3) enableChannel:enabler.
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   132
        box addOkButton.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   133
        box open
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   134
                                                                        [exEnd]
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   135
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   136
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   137
    like above, using a logical-or block:
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   138
                                                                        [exBegin]
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   139
        |val1 val2 enabler val3 box|
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   140
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   141
        val1 := false asValue.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   142
        val2 := false asValue.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   143
        val3 := false asValue.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   144
        enabler := BlockValue forLogical:val1 or:val2.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   145
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   146
        box := Dialog new.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   147
        box addCheckBox:'one' on:val1.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   148
        box addCheckBox:'two' on:val2.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   149
        box addHorizontalLine.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   150
        (box addCheckBox:'three (any of the above)' on:val3) enableChannel:enabler.
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   151
        box addOkButton.
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   152
        box open
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   153
                                                                        [exEnd]
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   154
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   155
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   156
    like above, using a bunch of toggles:
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   157
                                                                        [exBegin]
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   158
        |values anyValue box|
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   159
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   160
        values := (1 to:10) collect:[:i | false asValue].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   161
        anyValue := BlockValue forLogicalOrAll:values.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   162
        anyValue onChangeSend:#value to:[Transcript showCR:'any is true'].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   163
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   164
        box := Dialog new.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   165
        values keysAndValuesDo:[:index :aValueHolder |
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   166
            box addCheckBox:index printString on:aValueHolder.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   167
        ].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   168
        box addHorizontalLine.
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   169
        (box addOkButton) enableChannel:anyValue.
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   170
        box open
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   171
                                                                        [exEnd]
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   175
!BlockValue class methodsFor:'initialization'!
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   176
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   177
initialize
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   178
    NeverComputed isNil ifTrue:[
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   179
	NeverComputed := Object new.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   180
    ]
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   181
! !
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   182
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
!BlockValue class methodsFor:'instance creation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
979
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   185
block:aBlock arguments:aCollectionOfArguments
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   186
    "return a new BlockValue computing aBlock.
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   187
     Same as #with:arguments: for ST80 compatibility"
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   188
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   189
    ^ self with:aBlock arguments:aCollectionOfArguments
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   190
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   191
    "Created: / 20.6.1998 / 14:00:16 / cg"
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   192
!
cd28a5d673c9 added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 911
diff changeset
   193
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   194
forLogical:arg1 and:arg2
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   195
    "return a new BlockValue computing the logical AND of its args
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   196
     (which are usually other valueHolders)"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   197
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   198
    ^ (super new) 
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   199
        setBlock:[:a :b | a value and:[b value]]
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   200
        arguments:(Array with:arg1 with:arg2)
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   201
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   202
    "Created: / 16.12.1995 / 19:20:14 / cg"
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   203
    "Modified: / 30.1.2000 / 23:24:50 / cg"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   204
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   205
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   206
forLogical:arg1 or:arg2
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   207
    "return a new BlockValue computing the logical OR of its args
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   208
     (which are usually other valueHolders)"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   209
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   210
    ^ (super new) 
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   211
        setBlock:[:a :b | a value or:[b value]]
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   212
        arguments:(Array with:arg1 with:arg2)
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   213
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   214
    "Created: / 16.12.1995 / 19:20:14 / cg"
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   215
    "Modified: / 30.1.2000 / 23:24:46 / cg"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   216
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   217
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   218
forLogicalAndAll:argArray
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   219
    "return a new BlockValue computing the logical OR of all elements
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   220
     in the passed argArray (which are usually other valueHolders)"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   221
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   222
    ^ (super new) 
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   223
        setBlock:[:a | (argArray findFirst:[:a | a value not]) == 0]
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   224
        argumentArray:argArray asArray
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   225
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   226
    "Created: / 22.1.1997 / 19:12:44 / cg"
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   227
    "Modified: / 28.4.1998 / 20:16:38 / ca"
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   228
    "Modified: / 30.1.2000 / 23:24:40 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   229
!
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   230
1045
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   231
forLogicalNot:arg
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   232
    "return a new BlockValue computing the logical NOT of its arg 
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   233
     (which is usually another valueHolder)"
1045
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   234
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   235
    ^ (super new) 
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   236
        setBlock:[:a | a value not]
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   237
        arguments:(Array with:arg)
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   238
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   239
    "Created: / 17.8.1998 / 10:06:41 / cg"
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   240
    "Modified: / 30.1.2000 / 23:24:18 / cg"
1045
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   241
!
c501e3553048 added #forLogicalNot:
Claus Gittinger <cg@exept.de>
parents: 979
diff changeset
   242
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   243
forLogicalOrAll:argArray
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   244
    "return a new BlockValue computing the logical OR of all elements
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   245
     in the passed argArray (which are usually other valueHolders)"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   246
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   247
    ^ (super new) 
606
8a8b36a9e67d removed debugHalt
Claus Gittinger <cg@exept.de>
parents: 491
diff changeset
   248
        setBlock:[:arg | (arg findFirst:[:el | el value]) ~~ 0]
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   249
        argumentArray:argArray asArray
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   250
911
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   251
    "Created: / 22.1.1997 / 19:13:01 / cg"
97b17322f0fb fixed logicalOrAll / locicalAndAll:
ca
parents: 606
diff changeset
   252
    "Modified: / 28.4.1998 / 20:20:09 / ca"
1326
1ee8b02dd6ab comments
Claus Gittinger <cg@exept.de>
parents: 1255
diff changeset
   253
    "Modified: / 30.1.2000 / 23:24:34 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   254
!
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   255
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
with:aBlock
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
    "return a new BlockValue computing aBlock"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
    ^ (super new) setBlock:aBlock
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    "Created: 16.12.1995 / 19:16:33 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   264
with:aBlock argument:anArgument
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   265
    "return a new BlockValue computing aBlock"
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   266
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   267
    ^ (super new) 
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   268
        setBlock:aBlock 
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   269
        arguments:(Array with:anArgument)
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   270
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   271
    "Created: 16.12.1995 / 19:20:14 / cg"
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   272
!
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   273
1255
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   274
with:aBlock argument:anArgument1 argument:anArgument2
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   275
    "return a new BlockValue computing aBlock"
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   276
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   277
    ^ (super new) 
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   278
        setBlock:aBlock 
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   279
        arguments:(Array with:anArgument1 with:anArgument2)
1255
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   280
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   281
    "Created: 16.12.1995 / 19:20:14 / cg"
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   282
!
39081e9cddf1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
   283
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   284
with:aBlock argument:anArgument1 argument:anArgument2 argument:anArgument3
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   285
    "return a new BlockValue computing aBlock"
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   286
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   287
    ^ (super new) 
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   288
        setBlock:aBlock 
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   289
        arguments:(Array with:anArgument1 with:anArgument2 with:anArgument3)
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   290
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   291
!
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   292
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
with:aBlock arguments:aCollectionOfArguments
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
    "return a new BlockValue computing aBlock"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   296
    ^ (super new) 
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   297
        setBlock:aBlock 
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   298
        arguments:aCollectionOfArguments
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
    "Created: 16.12.1995 / 19:20:14 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
!BlockValue methodsFor:'accessing'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
491
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   305
computeValue
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   306
    "evaluate the receivers action block"
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   307
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   308
    |sz|
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   309
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   310
    arguments isNil ifTrue:[
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   311
        ^ block value
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   312
    ].
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   313
    sz := arguments size.
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   314
    sz == 0 ifTrue:[
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   315
        ^ block value
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   316
    ].
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   317
    sz == 1 ifTrue:[
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   318
        ^ block value:(arguments at:1) value
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   319
    ].
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   320
    sz == 2 ifTrue:[
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   321
        ^ block value:(arguments at:1) value
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   322
                value:(arguments at:2) value
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   323
    ].
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   324
    sz == 3 ifTrue:[
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   325
        ^ block value:(arguments at:1) value
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   326
                value:(arguments at:2) value
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   327
                value:(arguments at:3) value
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   328
    ].
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   329
    ^ block 
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   330
        valueWithArguments:(arguments collect:[:arg | arg value]) asArray
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   331
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   332
    "Created: 16.12.1995 / 19:27:40 / cg"
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   333
    "Modified: 22.1.1997 / 19:05:57 / cg"
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   334
!
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   335
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
dependOn:someObject
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   337
    "arrange for the blockValue to be reevaluated, whenever someObject
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   338
     changes (i.e. sends a change notification)"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   339
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    arguments isNil ifTrue:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   341
        arguments := Array with:someObject
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
    ] ifFalse:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   343
        arguments := arguments copyWith:someObject
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
    someObject addDependent:self
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   347
    "Modified: 22.1.1997 / 19:05:26 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
evaluate
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   351
    "evaluate the receivers action block"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   352
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
    arguments isNil ifTrue:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   354
        ^ block value
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
    ^ block valueWithArguments:(arguments asArray)
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
    "Created: 16.12.1995 / 19:27:40 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   359
    "Modified: 22.1.1997 / 19:05:57 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
setBlock:aBlock
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   363
    "set the receivers action block"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   364
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    block := aBlock.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
    arguments notNil ifTrue:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   367
        self release
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
    arguments := nil.
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   370
    cachedValue := NeverComputed.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
    "Created: 16.12.1995 / 19:16:59 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   373
    "Modified: 22.1.1997 / 19:05:54 / cg"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   374
!
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   375
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   376
setBlock:aBlock argumentArray:anArgumentCollection
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   377
    "set the receivers action block, and define an arguments collection
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   378
     to be passed to it.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   379
     A change in any element of the collection will force reevaluation of the 
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   380
     action block (passing the collection as a single argument)
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   381
     - possibly generating another change from myself"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   383
    block := aBlock.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   384
    arguments notNil ifTrue:[
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   385
        self release
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   386
    ].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   387
    arguments := Array with:anArgumentCollection.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   388
    anArgumentCollection do:[:arg |
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   389
        arg addDependent:self
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   390
    ].
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   391
    cachedValue := NeverComputed.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   392
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   393
    "Modified: 22.1.1997 / 19:08:51 / cg"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   394
    "Created: 22.1.1997 / 19:22:13 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
setBlock:aBlock arguments:aCollectionOfArguments
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   398
    "set the receivers action block, and define arguments to be passed to it.
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   399
     A change in any of the arguments will force reevaluation of the action
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   400
     block - possibly generating another change from myself"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   401
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
    block := aBlock.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
    arguments notNil ifTrue:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   404
        self release
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
    arguments := aCollectionOfArguments.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
    arguments do:[:arg |
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   408
        arg addDependent:self
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
    ].
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   410
    cachedValue := NeverComputed.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
    "Created: 16.12.1995 / 19:21:41 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   413
    "Modified: 22.1.1997 / 19:08:51 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   416
setValue:newValue 
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   417
    "physically set my value, without change notifications.
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   418
     This is a noop here, since my value is computed."
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   419
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   420
    ^ self
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   421
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   422
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   423
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   424
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
value
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   426
    "retrieve my value - this does not always evaluate the action block,
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   427
     since the returned value is cached internally"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   428
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   429
    cachedValue == NeverComputed ifTrue:[
491
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   430
        cachedValue := self computeValue
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   431
    ].
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
    ^ cachedValue
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
    "Created: 16.12.1995 / 19:23:26 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   435
    "Modified: 22.1.1997 / 19:06:59 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
347
2a795646e985 category rename
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
   438
!BlockValue methodsFor:'change & update'!
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
update:something with:aParameter from:someone
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   441
    "the one I depend on has changed - reevaluate may actionBlock,
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   442
     and possibly send a change notification to my dependents"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   443
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
    |oldValue|
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
    oldValue := cachedValue.
491
c5174fe6f09c allow valueHolder(s) as arg(s)
ca
parents: 382
diff changeset
   447
    cachedValue := self computeValue.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
    oldValue ~~ cachedValue ifTrue:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   449
        self changed:#value
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
    "Created: 16.12.1995 / 19:22:54 / cg"
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   453
    "Modified: 22.1.1997 / 19:07:39 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
!BlockValue methodsFor:'release'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
release
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   459
    "release any dependencies upon the arguments"
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   460
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
    arguments notNil ifTrue:[
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   462
        arguments do:[:arg | arg removeDependent:self].
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
382
d64197ef1c9b commentary
Claus Gittinger <cg@exept.de>
parents: 347
diff changeset
   465
    "Modified: 22.1.1997 / 19:08:06 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
!BlockValue class methodsFor:'documentation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
version
1352
cd83d6348a36 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1326
diff changeset
   471
    ^ '$Header: /cvs/stx/stx/libview2/BlockValue.st,v 1.17 2000-02-17 15:00:56 cg Exp $'
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
! !
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   473
BlockValue initialize!