PopUpList.st
author Claus Gittinger <cg@exept.de>
Thu, 27 Feb 1997 15:48:03 +0100
changeset 1071 4bfcb90dd70c
parent 1070 df1b79d1abab
child 1075 662f7e5069fd
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
     1
"
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
59
450ce95a72a4 *** empty log message ***
claus
parents: 38
diff changeset
     3
	      All Rights Reserved
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
     4
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
    11
"
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
    12
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
    13
Button subclass:#PopUpList
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    14
	instanceVariableNames:'menu menuAction values useIndex listMsg defaultLabel listHolder'
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
    15
	classVariableNames:''
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
    16
	poolDictionaries:''
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
    17
	category:'Views-Interactors'
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
    18
!
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
    19
998
ab1890b4e157 specClass
ca
parents: 799
diff changeset
    20
!PopUpList class methodsFor:'documentation'!
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    21
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    22
copyright
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    23
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    24
 COPYRIGHT (c) 1994 by Claus Gittinger
59
450ce95a72a4 *** empty log message ***
claus
parents: 38
diff changeset
    25
	      All Rights Reserved
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    26
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    27
 This software is furnished under a license and may be used
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    28
 only in accordance with the terms of that license and with the
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    30
 be provided or otherwise made available to, or used by, any
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    31
 other person.  No title to or ownership of the software is
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    32
 hereby transferred.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    33
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    34
!
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    35
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    36
documentation
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    37
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    38
    a PopUpList is basically a button with a popup menu.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    39
    The PopUpLists label is showing the current selection from the
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    40
    list.
121
claus
parents: 120
diff changeset
    41
    When an entry is selected, an actionBlock (if nonNil) is evaluated
claus
parents: 120
diff changeset
    42
    and (if nonNil), the model is notified via the changeMessage.
125
claus
parents: 121
diff changeset
    43
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    44
    If no model is set, the list is assumed to be a static list, which
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    45
    is defined via #list:, and the popUpList evaluates the action block,
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    46
    as defined via #action:.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    47
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    48
    If a model is provided, it should return the current selected items index via the 
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    49
    aspectMessage (default is #selection or: #selectionIndex, depending on the setting 
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    50
    of useIndex) and the list via the listMessage (default is #list).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    51
    If the listMessage was set to nil, the list is not aquired from the model
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    52
    and can be set explicitely via #list:.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    53
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    54
    The defaults are set to allow a PopUpList to be used with a SelectionInList 
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    55
    as model without further setup.
121
claus
parents: 120
diff changeset
    56
    (if used with some other model, either use an adaptor, or set the
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    57
     change/aspect and/or listMessage to something else ..)
125
claus
parents: 121
diff changeset
    58
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    59
    If a listHolder is set, this one is always asked for the list instead of the
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    60
    model, via the #value message. 
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    61
    This allows the popUpListView to aquire the list and value from different places.
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    62
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    63
1070
df1b79d1abab commentary
Claus Gittinger <cg@exept.de>
parents: 1069
diff changeset
    64
    Notice: PopUpList and ComboListView provide a similar protocol and functionality.
df1b79d1abab commentary
Claus Gittinger <cg@exept.de>
parents: 1069
diff changeset
    65
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    66
585
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    67
    [Instance variables:]
125
claus
parents: 121
diff changeset
    68
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    69
        menu                            helpers for the popup menu
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    70
        menuAction 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    71
        values 
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    72
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    73
        useIndex             <Boolean>  if true, the index of the selected entry
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    74
                                        is passed to the action block and the
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    75
                                        model in a change-message.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    76
                                        If false (the default), the value is passed.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    77
                                        Notice that the default changeMessage is
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    78
                                        #selection:, which is not ok to be used
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    79
                                        with useIndex:true and a selectionInList model.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    80
                                        (set the changeMessage to #selectionIndex: then)
125
claus
parents: 121
diff changeset
    81
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    82
        listMsg              <Symbol>   message to aquire a new list from the
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    83
                                        model. Default is #list.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    84
125
claus
parents: 121
diff changeset
    85
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    86
        listHolder           <Object>   if non-nil, this object is assumed to return the
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    87
                                        list via the listMsg (instead of the model).
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    88
                                        Default is nil.
585
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    89
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    90
    [see also:]
1070
df1b79d1abab commentary
Claus Gittinger <cg@exept.de>
parents: 1069
diff changeset
    91
        SelectionInList ValueHolder
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    92
        SelectionInListView
1070
df1b79d1abab commentary
Claus Gittinger <cg@exept.de>
parents: 1069
diff changeset
    93
        ComboListView
585
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    94
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    95
    [author:]
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    96
        Claus Gittinger
63
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    97
"
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
    98
!
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    99
63
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
   100
examples
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
   101
"
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   102
  non-MVC use:
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   103
                                                                        [exBegin]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   104
     |p|
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   105
     p := PopUpList label:'healthy fruit'.
119
claus
parents: 105
diff changeset
   106
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   107
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   108
                                                                        [exEnd]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   109
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   110
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   111
    with an initial selection:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   112
                                                                        [exBegin]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   113
     |p|
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   114
     p := PopUpList label:'dummy'.
119
claus
parents: 105
diff changeset
   115
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   116
     p selection:'apples'.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   117
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   118
                                                                        [exEnd]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   119
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   120
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   121
    with separating lines:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   122
                                                                        [exBegin]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   123
     |p|
119
claus
parents: 105
diff changeset
   124
     p := PopUpList label:'fruit'.
claus
parents: 105
diff changeset
   125
     p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   126
     p selection:'apples'.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   127
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   128
                                                                        [exEnd]
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   129
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   130
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   131
    with an action:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   132
                                                                        [exBegin]
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   133
     |p|
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   134
     p := PopUpList label:'dummy'.
119
claus
parents: 105
diff changeset
   135
     p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   136
     p selection:'apples'.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   137
     p action:[:what | Transcript showCR:'you selected: ' , what].
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   138
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   139
                                                                        [exEnd]
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   140
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   141
119
claus
parents: 105
diff changeset
   142
    sometimes, you may like the index instead of the value:
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   143
    (notice, that the separating line counts, so you have to take care ...)
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   144
                                                                        [exBegin]
119
claus
parents: 105
diff changeset
   145
     |p|
claus
parents: 105
diff changeset
   146
     p := PopUpList label:'dummy'.
claus
parents: 105
diff changeset
   147
     p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
claus
parents: 105
diff changeset
   148
     p selection:'apples'.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   149
     p action:[:what | Transcript show:'you selected: '; showCR:what].
119
claus
parents: 105
diff changeset
   150
     p useIndex:true.
claus
parents: 105
diff changeset
   151
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   152
                                                                        [exEnd]
119
claus
parents: 105
diff changeset
   153
claus
parents: 105
diff changeset
   154
claus
parents: 105
diff changeset
   155
    since the list is actually a popupMenu, you can add double-separators:
1071
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   156
    also, here values are different from the labels
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   157
                                                                        [exBegin]
119
claus
parents: 105
diff changeset
   158
     |p|
claus
parents: 105
diff changeset
   159
     p := PopUpList label:'dummy'.
claus
parents: 105
diff changeset
   160
     p list:#('apples' 'bananas' 'grape' 'lemon' 
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   161
              '=' 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   162
              'margaritas' 'pina colada'
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   163
              '=' 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   164
              'smalltalk' 'c++' 'eiffel' 'java').
119
claus
parents: 105
diff changeset
   165
     p values:#(apples bananas grape lemon 
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   166
                nil 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   167
                'mhmh - so good' 'makes headache'
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   168
                nil
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   169
                'great' 'another headache' 'not bad' 'neat').
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   170
     p selection:'apples'.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   171
     p action:[:what | Transcript show:'you selected: '; showCR:what].
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   172
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   173
                                                                        [exEnd]
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   174
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   175
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   176
    since the list is actually represented by a menuView,
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   177
    which itself is inheriting from listView, which itself can display
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   178
    things different from strings, arbitrary lists can be constructed:
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   179
    (see ListEntry, LabelAndIcon and Text classes)
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   180
                                                                        [exBegin]
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   181
     |p l|
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   182
     p := PopUpList label:'dummy'.
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   183
     l := OrderedCollection new.
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   184
     l add:(Text string:'apples' color:Color red).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   185
     l add:(Text string:'bananas' color:Color red).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   186
     l add:(Text string:'grape' color:Color red).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   187
     l add:(Text string:'lemon' color:Color red).
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   188
     l add:'='.
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   189
     l add:(Text string:'margaritas' color:Color green darkened darkened).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   190
     l add:(Text string:'pina colada' color:Color green darkened darkened).
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   191
     l add:'='.
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   192
     l add:(Text string:'smalltalk' color:Color blue).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   193
     l add:(Text string:'c++' color:Color blue).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   194
     l add:(Text string:'eiffel' color:Color blue).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   195
     l add:(Text string:'java' color:Color blue).
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   196
     p list:l.
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   197
     p values:#(apples bananas grape lemon 
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   198
                nil 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   199
                'mhmh - so good' 'makes headache'
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   200
                nil
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   201
                'great' 'another headache' 'not bad' 'neat').
119
claus
parents: 105
diff changeset
   202
     p selection:'apples'.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   203
     p action:[:what | Transcript show:'you selected: '; showCR:what].
119
claus
parents: 105
diff changeset
   204
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   205
                                                                        [exEnd]
119
claus
parents: 105
diff changeset
   206
claus
parents: 105
diff changeset
   207
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   208
    with values different from the label strings:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   209
                                                                        [exBegin]
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   210
     |p|
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   211
     p := PopUpList label:'dummy'.
119
claus
parents: 105
diff changeset
   212
     p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   213
     p selection:'apples'.
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   214
     p values:#(10 20 30 40 nil 50).
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   215
     p action:[:what | Transcript show:'you selected: '; showCR:what].
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   216
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   217
                                                                        [exEnd]
119
claus
parents: 105
diff changeset
   218
121
claus
parents: 120
diff changeset
   219
1069
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   220
    with values different from the label strings:
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   221
                                                                        [exBegin]
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   222
     |p|
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   223
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   224
     p := PopUpList label:'language selection'.
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   225
     p list:( #(
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   226
                'usa'
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   227
                'uk'
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   228
                'france'
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   229
                'germany'       
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   230
                'italy'
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   231
               ) collect:[:country |
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   232
                            LabelAndIcon 
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   233
                                icon:(Image fromFile:'bitmaps/xpmBitmaps/countries/' , country , '.xpm')
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   234
                                string:country
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   235
                         ]
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   236
            ).
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   237
     p values:#(us england france germany italy).
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   238
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   239
     p action:[:what | Transcript show:'you selected: '; showCR:what].
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   240
     p open
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   241
                                                                        [exEnd]
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   242
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   243
1064
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   244
  with a model (see in the inspector, how the index-holders value changes)
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   245
  the defaults are setup to allow a SelectionInList directly as model:
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   246
                                                                        [exBegin]
119
claus
parents: 105
diff changeset
   247
     |p model|
claus
parents: 105
diff changeset
   248
claus
parents: 105
diff changeset
   249
     model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
claus
parents: 105
diff changeset
   250
claus
parents: 105
diff changeset
   251
     p := PopUpList label:'healthy fruit'.
claus
parents: 105
diff changeset
   252
     p model:model.
claus
parents: 105
diff changeset
   253
     p open.
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   254
     model inspect
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   255
                                                                        [exEnd]
121
claus
parents: 120
diff changeset
   256
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   257
1071
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   258
  model provides selection; list is explicit:
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   259
  must change the aspect, since the default setup is for a SelectionInList
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   260
                                                                [exBegin]
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   261
     |model top b|
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   262
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   263
     model := 'foo' asValue.
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   264
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   265
     top := StandardSystemView new.
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   266
     top extent:(300 @ 200).
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   267
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   268
     b := PopUpList in:top.
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   269
     b origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   270
     b bottomInset:(b preferredExtent y negated).
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   271
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   272
     b list:#('hello' 'world' 'this' 'is' 'st/x').
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   273
     b model:model; aspect:#value; change:#value:.
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   274
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   275
     top openModal.
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   276
     Transcript showCR:('comboBox''s value: ' , model value).
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   277
                                                                [exEnd]
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   278
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   279
125
claus
parents: 121
diff changeset
   280
    a popupList and a SelectionInListView on the same model:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   281
                                                                        [exBegin]
125
claus
parents: 121
diff changeset
   282
     |p slv model|
claus
parents: 121
diff changeset
   283
claus
parents: 121
diff changeset
   284
     model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
claus
parents: 121
diff changeset
   285
     model selection:'apples'.
claus
parents: 121
diff changeset
   286
claus
parents: 121
diff changeset
   287
     p := PopUpList on:model.
1064
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   288
     p open.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   289
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   290
     slv := SelectionInListView on:model.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   291
     slv open.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   292
                                                                        [exEnd]
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   293
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   294
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   295
    dynamically changing the list (click button(s) to change):
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   296
                                                                        [exBegin]
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   297
     |p slv model b|
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   298
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   299
     model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   300
     model selection:'apples'.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   301
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   302
     p := PopUpList on:model.
125
claus
parents: 121
diff changeset
   303
     p open.
claus
parents: 121
diff changeset
   304
claus
parents: 121
diff changeset
   305
     slv := SelectionInListView on:model.
claus
parents: 121
diff changeset
   306
     slv open.
claus
parents: 121
diff changeset
   307
1064
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   308
     b := Button label:'long list' action:[model list:#('1' '2' '3' '4' '5' '6')].
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   309
     b open.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   310
     b := Button label:'short list' action:[model list:#('1' '2' '3')].
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   311
     b open.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   312
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   313
                                                                        [exEnd]
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   314
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   315
125
claus
parents: 121
diff changeset
   316
127
claus
parents: 126
diff changeset
   317
    two PopUpLists on the same model, different aspects:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   318
                                                                        [exBegin]
121
claus
parents: 120
diff changeset
   319
     |top panel p model|
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   320
121
claus
parents: 120
diff changeset
   321
     model := Plug new.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   322
     model respondTo:#eat: with:[:val | Transcript showCR:'eat: ' , val].
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   323
     model respondTo:#drink: with:[:val | Transcript showCR:'drink: ' , val].
121
claus
parents: 120
diff changeset
   324
     model respondTo:#meals with:[#(taco burrito enchilada)].
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   325
     model respondTo:#drinks with:[#(margarita water corona)].
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   326
121
claus
parents: 120
diff changeset
   327
     top := StandardSystemView new.
claus
parents: 120
diff changeset
   328
     top extent:(100@100).
claus
parents: 120
diff changeset
   329
     panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
claus
parents: 120
diff changeset
   330
     panel horizontalLayout:#fitSpace.
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   331
121
claus
parents: 120
diff changeset
   332
     p := PopUpList label:'meals'.
126
claus
parents: 125
diff changeset
   333
     p model:model; listMessage:#meals; aspect:nil; change:#eat:.
121
claus
parents: 120
diff changeset
   334
     panel add:p.
119
claus
parents: 105
diff changeset
   335
121
claus
parents: 120
diff changeset
   336
     p := PopUpList label:'drinks'.
126
claus
parents: 125
diff changeset
   337
     p model:model; listMessage:#drinks; aspect:nil; change:#drink:.
121
claus
parents: 120
diff changeset
   338
     panel add:p.
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   339
121
claus
parents: 120
diff changeset
   340
     top open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   341
                                                                        [exEnd]
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   342
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   343
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   344
    with separate list- and indexHolders:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   345
                                                                        [exBegin]
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   346
     |p selectionHolder listHolder|
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   347
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   348
     listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   349
     selectionHolder := 'apples' asValue.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   350
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   351
     p := PopUpList label:'healthy fruit'.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   352
     p listHolder:listHolder.
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   353
     p model:selectionHolder; aspect:#value; change:#value:.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   354
     p open.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   355
     selectionHolder inspect
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   356
                                                                        [exEnd]
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   357
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   358
    same, using index:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   359
                                                                        [exBegin]
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   360
     |p selectionIndexHolder listHolder|
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   361
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   362
     listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   363
     selectionIndexHolder := 3 asValue.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   364
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   365
     p := PopUpList new.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   366
     p listHolder:listHolder.
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   367
     p model:selectionIndexHolder; aspect:#value; change:#value:.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   368
     p useIndex:true.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   369
     p open.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   370
     selectionIndexHolder inspect
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   371
                                                                        [exEnd]
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   372
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   373
    using different values:
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   374
                                                                        [exBegin]
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   375
     |p selectionHolder listHolder values|
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   376
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   377
     listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   378
     values := #(apples bananas grape lemon alcohol).
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   379
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   380
     selectionHolder := #alcohol asValue.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   381
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   382
     p := PopUpList label:'healthy fruit'.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   383
     p listHolder:listHolder.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   384
     p model:selectionHolder; aspect:#value; change:#value:.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   385
     p values:values.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   386
     p open.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   387
     selectionHolder inspect
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   388
                                                                        [exEnd]
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   389
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   390
121
claus
parents: 120
diff changeset
   391
"
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   392
! !
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   393
998
ab1890b4e157 specClass
ca
parents: 799
diff changeset
   394
!PopUpList class methodsFor:'defaults'!
125
claus
parents: 121
diff changeset
   395
claus
parents: 121
diff changeset
   396
defaultAspectMessage
claus
parents: 121
diff changeset
   397
    ^ #selection
claus
parents: 121
diff changeset
   398
!
claus
parents: 121
diff changeset
   399
claus
parents: 121
diff changeset
   400
defaultChangeMessage
claus
parents: 121
diff changeset
   401
    ^ #selection:
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   402
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   403
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   404
defaultListMessage
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   405
    ^ #list 
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   406
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   407
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   408
!PopUpList methodsFor:'accessing'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   409
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   410
contents
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   411
    ^ self label
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   412
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   413
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   414
contents:con
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   415
    ^ self selection:con
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   416
684
015c23130d7b selection: / setSelection:
Claus Gittinger <cg@exept.de>
parents: 655
diff changeset
   417
    "Modified: 25.5.1996 / 14:20:57 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   418
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   419
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   420
defaultLabel:aString
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   421
    "set the defaultLabel, to be shown if nothing is selected"
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   422
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   423
    defaultLabel := aString
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   424
!
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   425
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   426
list
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   427
    "return the list - i.e. the values shown in the pop-up list"
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   428
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   429
    ^ menu labels
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   430
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   431
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   432
list:aList
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   433
    "set the list - i.e. the values shown in the pop-up list"
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   434
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   435
    self createMenuFor:aList.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   436
    realized ifTrue:[
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   437
	self computeLabelSize
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   438
    ]
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   439
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   440
    "
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   441
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   442
     p := PopUpList label:'fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   443
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   444
     p action:[:val | Transcript showCR:'selected: ' , val printString].   
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   445
     p open
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   446
    "
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   447
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   448
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   449
selection:indexOrString
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   450
    "set (force) a selection - usually done to set
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   451
     an initial selection without updating others"
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   452
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   453
    |index wasFix|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   454
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   455
    menu isNil ifTrue:[
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   456
        self getListFromModel.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   457
    ].
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   458
    menu isNil ifTrue:[^ self].
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   459
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   460
    (useIndex not and:[values notNil]) ifTrue:[
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   461
        index := values indexOf:indexOrString
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   462
    ] ifFalse:[
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   463
        index := menu indexOf:indexOrString.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   464
    ].
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   465
    index == 0 ifTrue:[
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   466
        self label:defaultLabel.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   467
        ^ self
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   468
    ].
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   469
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   470
    "kludge: dont want label to resize ..."
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   471
    wasFix := fixSize. fixSize := true.
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   472
    self label:(menu labels at:index) printString.
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   473
    fixSize := wasFix
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   474
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   475
    "
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   476
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   477
     p := PopUpList label:'what fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   478
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   479
     p selection:'grape'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   480
     p open 
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   481
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   482
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   483
     p := PopUpList label:'what fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   484
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   485
     p selection:'blabla'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   486
     p open
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   487
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   488
     |p|
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   489
     p := PopUpList label:'what fruit ?'.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   490
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   491
     p defaultLabel:'nothing selected'.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   492
     p selection:'blabla'.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   493
     p open
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   494
    "
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   495
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   496
    "Modified: 27.2.1997 / 10:38:23 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   497
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   498
593
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   499
values:aList
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   500
    "set a value list - these are reported via the action or changeSymbol instead of
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   501
     the label strings."
593
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   502
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   503
    values := aList.
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   504
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   505
    "
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   506
     |p|
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   507
     p := PopUpList label:'fruit ?'.
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   508
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   509
     p values:#(1 2 3 4 'mhmh - good').
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   510
     p action:[:val | Transcript showCR:'selected: ' , val printString].   
593
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   511
     p open.
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   512
    "
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   513
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   514
    "Modified: 27.2.1997 / 10:24:12 / cg"
593
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   515
! !
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   516
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   517
!PopUpList methodsFor:'accessing-behavior'!
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   518
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   519
action:aOneArgBlock
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   520
    "set the action to be performed on selection changes;
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   521
     the argument, aOneArgBlock will be evaluated with the
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   522
     selection-value as argument"
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   523
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   524
    menuAction := aOneArgBlock
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   525
!
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   526
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   527
useIndex:aBoolean 
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   528
    "tell the popuplist to pass the index (instead of the value)
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   529
     to both the actionBlock and model. Notice, that if you use a model,
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   530
     the default changeSelector is not ok for using index and a SelectionInList"
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   531
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   532
    useIndex := aBoolean
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   533
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   534
    "
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   535
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   536
     p := PopUpList label:'fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   537
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   538
     p action:[:val | Transcript showCR:'selected: ' , val printString].   
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   539
     p open.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   540
    "
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   541
    "
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   542
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   543
     p := PopUpList label:'fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   544
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   545
     p action:[:val | Transcript showCR:'selected: ' , val printString].   
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   546
     p useIndex:true.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   547
     p open.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   548
    "
125
claus
parents: 121
diff changeset
   549
! !
claus
parents: 121
diff changeset
   550
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   551
!PopUpList methodsFor:'accessing-mvc'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   552
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   553
addModelInterfaceTo:aDictionary
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   554
    "see comment in View>>modelInterface"
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   555
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   556
    super addModelInterfaceTo:aDictionary.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   557
    aDictionary at:#listMessage put:listMsg
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   558
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   559
    "Modified: 26.2.1997 / 19:08:04 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   560
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   561
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   562
listHolder
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   563
    "return the listHolder if any"
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   564
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   565
    ^ listHolder
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   566
!
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   567
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   568
listHolder:aValueHolder
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   569
    "set the listHolder - if non nil, that one is assumed to provide the
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   570
     list via #value.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   571
     If a listHolder was defined, the model is never asked for the list."
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   572
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   573
    listHolder notNil ifTrue:[
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   574
        listHolder removeDependent:self.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   575
    ].
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   576
    listHolder := aValueHolder.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   577
    listHolder notNil ifTrue:[
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   578
        listHolder addDependent:self.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   579
    ].
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   580
    shown ifTrue:[
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   581
        self getListFromModel
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   582
    ]
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   583
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   584
    "Modified: 26.2.1997 / 19:06:01 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   585
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   586
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   587
listMessage
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   588
    "return the selector by which we ask the model or listHolder for the list.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   589
     The default is #list. 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   590
     If a listHolder was defined, the model is never asked for the list."
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   591
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   592
    ^ listMsg
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   593
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   594
    "Modified: 26.2.1997 / 19:05:27 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   595
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   596
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   597
listMessage:aSelector
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   598
    "set the selector by which we ask the model for the list.
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   599
     The default is #list. 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   600
     If a listHolder was defined, the model is never asked for the list."
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   601
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   602
    listMsg := aSelector
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   603
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   604
    "Modified: 26.2.1997 / 19:05:18 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   605
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   606
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   607
!PopUpList methodsFor:'change & update'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   608
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   609
update:something with:aParameter from:changedObject
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   610
    changedObject == listHolder ifTrue:[
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   611
        self getListFromModel.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   612
        ^ self
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   613
    ].
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   614
    changedObject == model ifTrue:[
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   615
        (something == aspectMsg 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   616
        or:[something == #selectionIndex]) ifTrue:[
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   617
            self getSelectionFromModel.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   618
            ^ self
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   619
        ].
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   620
        something == listMsg ifTrue:[
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   621
            self getListFromModel.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   622
        ].
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   623
        ^ self
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   624
    ].
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   625
    super update:something with:aParameter from:changedObject
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   626
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   627
    "Modified: 26.2.1997 / 18:23:27 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   628
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   629
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   630
!PopUpList methodsFor:'drawing'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   631
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   632
drawWith:fgColor and:bgColor
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   633
    |mmH mmV mW mH|
136
claus
parents: 135
diff changeset
   634
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   635
    controller pressed ifTrue:[
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   636
	super drawWith:enteredFgColor and:enteredBgColor
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   637
    ] ifFalse:[
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   638
	super drawWith:fgColor and:bgColor.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   639
    ].
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   640
    mmH := device horizontalPixelPerMillimeter rounded.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   641
    mmV := device verticalPixelPerMillimeter rounded.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   642
    mW := (device horizontalPixelPerMillimeter * 2.5) rounded.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   643
    mH := (device verticalPixelPerMillimeter * 1.5) rounded.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   644
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   645
    self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2)
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   646
		 width:mW height:mH level:2
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   647
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   648
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   649
showActive
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   650
    "no need to redraw - will pop menu ontop of me anyway ..."
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   651
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   652
    ^ self
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   653
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   654
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   655
showPassive
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   656
    "no need to redraw - will redraw from unpopped menu anyway ..."
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   657
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   658
    ^ self
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   659
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   660
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   661
!PopUpList methodsFor:'event handling'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   662
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   663
popMenu
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   664
    |org mv w|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   665
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   666
    menu notNil ifTrue:[
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   667
	self turnOffWithoutRedraw. 
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   668
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   669
	menu labels size == 0 ifTrue:[
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   670
	    ^ self
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   671
	].
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   672
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   673
	menu font:font.
136
claus
parents: 135
diff changeset
   674
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   675
	"
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   676
	 adjust the menus width to my current width
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   677
	"
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   678
	mv := menu menuView.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   679
	mv create.      "/ stupid: it resizes itself upon first create
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   680
	w := mv width.  "/ to its preferred size.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   681
	w := w max:(self width - (2 * menu margin) - (menu borderWidth*2)).
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   682
	mv width:w.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   683
	mv level:0; borderWidth:0.
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   684
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   685
	"
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   686
	 the popupMenu wants Display coordinates in its showAt: method
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   687
	"
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   688
	org := device translatePoint:0@0 
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   689
				from:(self id)
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   690
				  to:(device rootView id).
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   691
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   692
	menu showAt:org "resizing:false"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   693
    ].
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   694
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   695
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   696
!PopUpList methodsFor:'initialization'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   697
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   698
defaultControllerClass
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   699
    ^ PopUpListController
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   700
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   701
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   702
initialize
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   703
    super initialize.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   704
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   705
    controller beTriggerOnDown.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   706
    controller action:[self popMenu].
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   707
    self adjust:#left.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   708
    useIndex := false.
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   709
    defaultLabel := 'popup'.
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   710
    self label:defaultLabel.
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   711
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   712
    listMsg := self class defaultListMessage.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   713
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   714
    onLevel := offLevel.
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   715
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   716
    "Modified: 26.2.1997 / 18:23:43 / cg"
136
claus
parents: 135
diff changeset
   717
! !
claus
parents: 135
diff changeset
   718
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   719
!PopUpList methodsFor:'private'!
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   720
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   721
computeLabelSize
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   722
    "compute the extent needed to hold the label plus the mark"
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   723
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   724
    |mmH mmV savedLogo longest longestWidth labels|
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   725
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   726
    menu isNil ifTrue:[
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   727
	super computeLabelSize
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   728
    ] ifFalse:[
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   729
	"hack: simulate logo change to longest menu entry"
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   730
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   731
	font := font on:device.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   732
	longest := logo.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   733
	logo isNil ifTrue:[
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   734
	    longestWidth := 0
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   735
	] ifFalse:[
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   736
	    longestWidth := font widthOf:logo.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   737
	].
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   738
	labels := menu labels.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   739
	labels notNil ifTrue:[
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   740
	    labels do:[:entry |
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   741
		|this|
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   742
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   743
		this := font widthOf:entry printString.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   744
		this > longestWidth ifTrue:[
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   745
		    longest := entry.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   746
		    longestWidth := this
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   747
		].
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   748
	    ].
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   749
	].
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   750
	savedLogo := logo.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   751
	logo := longest printString.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   752
	super computeLabelSize.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   753
	logo := savedLogo.
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   754
    ].
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   755
    mmH := device horizontalPixelPerMillimeter.
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   756
    mmV := device verticalPixelPerMillimeter.
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   757
    labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace.
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   758
    labelHeight := labelHeight max: (mmV * 2) rounded
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   759
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   760
    "Modified: 8.2.1996 / 13:00:33 / cg"
121
claus
parents: 120
diff changeset
   761
!
claus
parents: 120
diff changeset
   762
claus
parents: 120
diff changeset
   763
createMenuFor:aList
claus
parents: 120
diff changeset
   764
    menu := PopUpMenu
claus
parents: 120
diff changeset
   765
		  labels:aList
claus
parents: 120
diff changeset
   766
	       selectors:#select:
claus
parents: 120
diff changeset
   767
		    args:(1 to:aList size) 
claus
parents: 120
diff changeset
   768
		receiver:self
claus
parents: 120
diff changeset
   769
		     for:self.
128
claus
parents: 127
diff changeset
   770
!
claus
parents: 127
diff changeset
   771
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   772
getListFromModel
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   773
    "if I have a listHolder, ask it for the list;
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   774
     otherwise, if I have a model and a listMsg, get my list from there"
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   775
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   776
    listHolder notNil ifTrue:[
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   777
        self list:listHolder value
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   778
    ] ifFalse:[
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   779
        (listMsg notNil and:[model notNil]) ifTrue:[
1067
1933c253b537 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   780
            (model respondsTo:listMsg) ifTrue:[
1933c253b537 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   781
                self list:(model perform:listMsg).
1933c253b537 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   782
            ]
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   783
        ].
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   784
    ]
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   785
1067
1933c253b537 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   786
    "Modified: 27.2.1997 / 14:05:52 / cg"
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   787
!
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   788
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   789
getSelectionFromModel
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   790
    "if I have a model and an aspectMsg, get my current value from it"
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   791
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   792
    (model notNil and:[aspectMsg notNil]) ifTrue:[
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   793
        self selection:(model perform:aspectMsg)
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   794
    ].
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   795
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   796
    "Modified: 26.2.1997 / 18:21:59 / cg"
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   797
!
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   798
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   799
realize
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   800
    super realize.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   801
    (model notNil or:[listHolder notNil]) ifTrue:[
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   802
        self getListFromModel.
121
claus
parents: 120
diff changeset
   803
    ].
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   804
    model notNil ifTrue:[
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   805
        self getSelectionFromModel.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   806
    ]
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   807
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   808
    "Modified: 26.2.1997 / 18:23:58 / cg"
121
claus
parents: 120
diff changeset
   809
! !
claus
parents: 120
diff changeset
   810
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   811
!PopUpList methodsFor:'private-controller access'!
121
claus
parents: 120
diff changeset
   812
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   813
menu
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   814
    "return the menu component"
125
claus
parents: 121
diff changeset
   815
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   816
    ^ menu
126
claus
parents: 125
diff changeset
   817
! !
claus
parents: 125
diff changeset
   818
136
claus
parents: 135
diff changeset
   819
!PopUpList methodsFor:'queries'!
claus
parents: 135
diff changeset
   820
claus
parents: 135
diff changeset
   821
preferredExtent
claus
parents: 135
diff changeset
   822
    "redefined to make certain that the menu is fully defined"
claus
parents: 135
diff changeset
   823
799
64f8700489a4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   824
    "/ If I have an explicit preferredExtent ..
64f8700489a4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   825
714
5ff02d2d9fa7 care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   826
    preferredExtent notNil ifTrue:[
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   827
	^ preferredExtent
714
5ff02d2d9fa7 care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   828
    ].
5ff02d2d9fa7 care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   829
136
claus
parents: 135
diff changeset
   830
    menu isNil ifTrue:[
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   831
	self getListFromModel
136
claus
parents: 135
diff changeset
   832
    ].
claus
parents: 135
diff changeset
   833
    self computeLabelSize.
claus
parents: 135
diff changeset
   834
    ^ super preferredExtent.
714
5ff02d2d9fa7 care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   835
799
64f8700489a4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   836
    "Modified: 19.7.1996 / 20:45:16 / cg"
155
claus
parents: 136
diff changeset
   837
!
claus
parents: 136
diff changeset
   838
claus
parents: 136
diff changeset
   839
specClass
claus
parents: 136
diff changeset
   840
    self class == PopUpList ifTrue:[^ PopUpListSpec].
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   841
    ^ super specClass
136
claus
parents: 135
diff changeset
   842
! !
claus
parents: 135
diff changeset
   843
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   844
!PopUpList methodsFor:'user actions'!
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   845
1069
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   846
select:anIndex
119
claus
parents: 105
diff changeset
   847
    "this is sent from the popupmenu when an entry was selected"
claus
parents: 105
diff changeset
   848
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   849
    |value label|
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   850
1069
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   851
    values isNil ifTrue:[
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   852
        value := anIndex.
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   853
        useIndex ifFalse:[
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   854
            value := menu labels at:anIndex.
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   855
        ]
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   856
    ] ifFalse:[
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   857
        value := values at:anIndex
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   858
    ].
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   859
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   860
    model isNil ifTrue:[
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   861
        "/ if there is a model,
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   862
        "/ the update will change my logo ...
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   863
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   864
        self sizeFixed:true.
1069
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   865
        label := menu labels at:anIndex.
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   866
        self label:label printString.
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   867
    ].
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   868
1012
36f7cb7862b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 998
diff changeset
   869
    "/
36f7cb7862b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 998
diff changeset
   870
    "/ ST-80 way of doing it
36f7cb7862b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 998
diff changeset
   871
    "/ tell my model - if any
36f7cb7862b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 998
diff changeset
   872
    "/
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   873
    self sendChangeMessageWith:value.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   874
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   875
    "/
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   876
    "/ ST/X action blocks
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   877
    "/
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   878
    menuAction notNil ifTrue:[
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   879
        menuAction value:value.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   880
    ].
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   881
1069
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   882
    "Modified: 27.2.1997 / 15:03:02 / cg"
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   883
! !
121
claus
parents: 120
diff changeset
   884
998
ab1890b4e157 specClass
ca
parents: 799
diff changeset
   885
!PopUpList class methodsFor:'documentation'!
121
claus
parents: 120
diff changeset
   886
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   887
version
1071
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   888
    ^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.40 1997-02-27 14:48:03 cg Exp $'
121
claus
parents: 120
diff changeset
   889
! !