PopUpList.st
author Claus Gittinger <cg@exept.de>
Thu, 10 Aug 2000 00:18:02 +0200
changeset 2208 a37459b4dffa
parent 2174 1245fc1a0654
child 2262 2d42623317f0
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
2172
411ac4dcf8b4 action invocation for VW compatibility.
Claus Gittinger <cg@exept.de>
parents: 1988
diff changeset
    13
"{ Package: 'stx:libwidg' }"
411ac4dcf8b4 action invocation for VW compatibility.
Claus Gittinger <cg@exept.de>
parents: 1988
diff changeset
    14
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
    15
Button subclass:#PopUpList
1758
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
    16
	instanceVariableNames:'menu menuAction values useIndex listMsg defaultLabel listHolder
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
    17
		showHandle'
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
    18
	classVariableNames:''
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
    19
	poolDictionaries:''
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
    20
	category:'Views-Interactors'
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
    21
!
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
    22
998
ab1890b4e157 specClass
ca
parents: 799
diff changeset
    23
!PopUpList class methodsFor:'documentation'!
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    24
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    25
copyright
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
 COPYRIGHT (c) 1994 by Claus Gittinger
59
450ce95a72a4 *** empty log message ***
claus
parents: 38
diff changeset
    28
	      All Rights Reserved
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    29
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    30
 This software is furnished under a license and may be used
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    31
 only in accordance with the terms of that license and with the
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    33
 be provided or otherwise made available to, or used by, any
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    34
 other person.  No title to or ownership of the software is
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    35
 hereby transferred.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    36
"
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
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    39
documentation
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    40
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    41
    a PopUpList is basically a button with a popup menu.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    42
    The PopUpLists label is showing the current selection from the
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
    43
    list.
121
claus
parents: 120
diff changeset
    44
    When an entry is selected, an actionBlock (if nonNil) is evaluated
claus
parents: 120
diff changeset
    45
    and (if nonNil), the model is notified via the changeMessage.
125
claus
parents: 121
diff changeset
    46
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    47
    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
    48
    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
    49
    as defined via #action:.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    50
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    51
    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
    52
    aspectMessage (default is #selection or: #selectionIndex, depending on the setting 
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    53
    of useIndex) and the list via the listMessage (default is #list).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    54
    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
    55
    and can be set explicitely via #list:.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    56
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    57
    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
    58
    as model without further setup.
1077
b50cebc268e6 comments
Claus Gittinger <cg@exept.de>
parents: 1076
diff changeset
    59
    A simple valueHolder may also be used without further setup.
121
claus
parents: 120
diff changeset
    60
    (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
    61
     change/aspect and/or listMessage to something else ..)
125
claus
parents: 121
diff changeset
    62
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    63
    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
    64
    model, via the #value message. 
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    65
    This allows the popUpListView to aquire the list and value from different places.
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    66
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    67
1070
df1b79d1abab commentary
Claus Gittinger <cg@exept.de>
parents: 1069
diff changeset
    68
    Notice: PopUpList and ComboListView provide a similar protocol and functionality.
df1b79d1abab commentary
Claus Gittinger <cg@exept.de>
parents: 1069
diff changeset
    69
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    70
585
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    71
    [Instance variables:]
125
claus
parents: 121
diff changeset
    72
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    73
        menu                            helpers for the popup menu
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    74
        menuAction 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    75
        values 
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    76
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    77
        useIndex             <Boolean>  if true, the index of the selected entry
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    78
                                        is passed to the action block and the
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    79
                                        model in a change-message.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    80
                                        If false (the default), the value is passed.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    81
                                        Notice that the default changeMessage is
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    82
                                        #selection:, which is not ok to be used
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    83
                                        with useIndex:true and a selectionInList model.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    84
                                        (set the changeMessage to #selectionIndex: then)
125
claus
parents: 121
diff changeset
    85
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    86
        listMsg              <Symbol>   message to aquire a new list from the
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    87
                                        model. Default is #list.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    88
125
claus
parents: 121
diff changeset
    89
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    90
        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
    91
                                        list via the listMsg (instead of the model).
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    92
                                        Default is nil.
585
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    93
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    94
    [see also:]
1070
df1b79d1abab commentary
Claus Gittinger <cg@exept.de>
parents: 1069
diff changeset
    95
        SelectionInList ValueHolder
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
    96
        SelectionInListView
1070
df1b79d1abab commentary
Claus Gittinger <cg@exept.de>
parents: 1069
diff changeset
    97
        ComboListView
585
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    98
8f395aba0173 documentation
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    99
    [author:]
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   100
        Claus Gittinger
63
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
   101
"
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
   102
!
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   103
63
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
   104
examples
f4eaf04d1eaf *** empty log message ***
claus
parents: 59
diff changeset
   105
"
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   106
  non-MVC use:
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   107
                                                                        [exBegin]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   108
     |p|
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   109
     p := PopUpList label:'healthy fruit'.
119
claus
parents: 105
diff changeset
   110
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   111
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   112
                                                                        [exEnd]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   113
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   114
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   115
    with an initial selection:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   116
                                                                        [exBegin]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   117
     |p|
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   118
     p := PopUpList label:'dummy'.
119
claus
parents: 105
diff changeset
   119
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   120
     p selection:'apples'.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   121
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   122
                                                                        [exEnd]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   123
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   124
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   125
    with separating lines:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   126
                                                                        [exBegin]
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   127
     |p|
119
claus
parents: 105
diff changeset
   128
     p := PopUpList label:'fruit'.
claus
parents: 105
diff changeset
   129
     p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   130
     p selection:'apples'.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 20
diff changeset
   131
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   132
                                                                        [exEnd]
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   133
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   134
1772
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   135
    draw without menu-handle:
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   136
                                                                        [exBegin]
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   137
     |p|
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   138
     p := PopUpList label:'fruit'.
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   139
     p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   140
     p showHandle:false.
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   141
     p open
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   142
                                                                        [exEnd]
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   143
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   144
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   145
    with an action:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   146
                                                                        [exBegin]
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   147
     |p|
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   148
     p := PopUpList label:'dummy'.
119
claus
parents: 105
diff changeset
   149
     p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   150
     p selection:'apples'.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   151
     p action:[:what | Transcript showCR:'you selected: ' , what].
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   152
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   153
                                                                        [exEnd]
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   154
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   155
119
claus
parents: 105
diff changeset
   156
    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
   157
    (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
   158
                                                                        [exBegin]
119
claus
parents: 105
diff changeset
   159
     |p|
claus
parents: 105
diff changeset
   160
     p := PopUpList label:'dummy'.
claus
parents: 105
diff changeset
   161
     p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
claus
parents: 105
diff changeset
   162
     p selection:'apples'.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   163
     p action:[:what | Transcript show:'you selected: '; showCR:what].
119
claus
parents: 105
diff changeset
   164
     p useIndex:true.
claus
parents: 105
diff changeset
   165
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   166
                                                                        [exEnd]
119
claus
parents: 105
diff changeset
   167
claus
parents: 105
diff changeset
   168
claus
parents: 105
diff changeset
   169
    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
   170
    also, here values are different from the labels
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   171
                                                                        [exBegin]
119
claus
parents: 105
diff changeset
   172
     |p|
claus
parents: 105
diff changeset
   173
     p := PopUpList label:'dummy'.
claus
parents: 105
diff changeset
   174
     p list:#('apples' 'bananas' 'grape' 'lemon' 
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   175
              '=' 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   176
              'margaritas' 'pina colada'
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   177
              '=' 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   178
              'smalltalk' 'c++' 'eiffel' 'java').
119
claus
parents: 105
diff changeset
   179
     p values:#(apples bananas grape lemon 
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   180
                nil 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   181
                'mhmh - so good' 'makes headache'
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   182
                nil
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   183
                '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
   184
     p selection:'apples'.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   185
     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
   186
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   187
                                                                        [exEnd]
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   188
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   189
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   190
    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
   191
    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
   192
    things different from strings, arbitrary lists can be constructed:
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   193
    (see ListEntry, LabelAndIcon and Text classes)
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   194
                                                                        [exBegin]
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   195
     |p l|
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   196
     p := PopUpList label:'dummy'.
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   197
     l := OrderedCollection new.
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   198
     l add:(Text string:'apples' color:Color red).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   199
     l add:(Text string:'bananas' color:Color red).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   200
     l add:(Text string:'grape' color:Color red).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   201
     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
   202
     l add:'='.
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   203
     l add:(Text string:'margaritas' color:Color green darkened darkened).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   204
     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
   205
     l add:'='.
1065
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   206
     l add:(Text string:'smalltalk' color:Color blue).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   207
     l add:(Text string:'c++' color:Color blue).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   208
     l add:(Text string:'eiffel' color:Color blue).
01c863929ddc comment
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   209
     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
   210
     p list:l.
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   211
     p values:#(apples bananas grape lemon 
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   212
                nil 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   213
                'mhmh - so good' 'makes headache'
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   214
                nil
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   215
                'great' 'another headache' 'not bad' 'neat').
119
claus
parents: 105
diff changeset
   216
     p selection:'apples'.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   217
     p action:[:what | Transcript show:'you selected: '; showCR:what].
119
claus
parents: 105
diff changeset
   218
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   219
                                                                        [exEnd]
119
claus
parents: 105
diff changeset
   220
claus
parents: 105
diff changeset
   221
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   222
    with values different from the label strings:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   223
                                                                        [exBegin]
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   224
     |p|
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   225
     p := PopUpList label:'dummy'.
119
claus
parents: 105
diff changeset
   226
     p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   227
     p selection:'apples'.
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   228
     p values:#(10 20 30 40 nil 50).
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   229
     p action:[:what | Transcript show:'you selected: '; showCR:what].
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   230
     p open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   231
                                                                        [exEnd]
119
claus
parents: 105
diff changeset
   232
121
claus
parents: 120
diff changeset
   233
1069
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   234
    with values different from the label strings:
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   235
                                                                        [exBegin]
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   236
     |p|
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   237
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   238
     p := PopUpList label:'language selection'.
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   239
     p list:( #(
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   240
                'usa'
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   241
                'uk'
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   242
                'france'
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   243
                'germany'       
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   244
                'italy'
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   245
               ) collect:[:country |
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   246
                            LabelAndIcon 
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   247
                                icon:(Image fromFile:'bitmaps/xpmBitmaps/countries/' , country , '.xpm')
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   248
                                string:country
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   249
                         ]
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   250
            ).
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   251
     p values:#(us england france germany italy).
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   252
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   253
     p action:[:what | Transcript show:'you selected: '; showCR:what].
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   254
     p open
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   255
                                                                        [exEnd]
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   256
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   257
1064
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   258
  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
   259
  the defaults are setup to allow a SelectionInList directly as model:
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   260
                                                                        [exBegin]
119
claus
parents: 105
diff changeset
   261
     |p model|
claus
parents: 105
diff changeset
   262
claus
parents: 105
diff changeset
   263
     model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
claus
parents: 105
diff changeset
   264
claus
parents: 105
diff changeset
   265
     p := PopUpList label:'healthy fruit'.
claus
parents: 105
diff changeset
   266
     p model:model.
claus
parents: 105
diff changeset
   267
     p open.
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   268
     model inspect
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   269
                                                                        [exEnd]
121
claus
parents: 120
diff changeset
   270
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   271
1071
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   272
  model provides selection; list is explicit:
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   273
  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
   274
                                                                [exBegin]
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   275
     |model top b|
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   276
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   277
     model := 'foo' asValue.
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
     top := StandardSystemView new.
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   280
     top extent:(300 @ 200).
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   281
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   282
     b := PopUpList in:top.
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   283
     b origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   284
     b bottomInset:(b preferredExtent y negated).
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   285
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   286
     b list:#('hello' 'world' 'this' 'is' 'st/x').
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   287
     b model:model; aspect:#value; change:#value:.
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   288
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   289
     top openModal.
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   290
     Transcript showCR:('comboBox''s value: ' , model value).
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   291
                                                                [exEnd]
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   292
4bfcb90dd70c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   293
125
claus
parents: 121
diff changeset
   294
    a popupList and a SelectionInListView on the same model:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   295
                                                                        [exBegin]
125
claus
parents: 121
diff changeset
   296
     |p slv model|
claus
parents: 121
diff changeset
   297
claus
parents: 121
diff changeset
   298
     model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
claus
parents: 121
diff changeset
   299
     model selection:'apples'.
claus
parents: 121
diff changeset
   300
claus
parents: 121
diff changeset
   301
     p := PopUpList on:model.
1064
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   302
     p open.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   303
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   304
     slv := SelectionInListView on:model.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   305
     slv open.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   306
                                                                        [exEnd]
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   307
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   308
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   309
    dynamically changing the list (click button(s) to change):
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   310
                                                                        [exBegin]
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   311
     |p slv model b|
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   312
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   313
     model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   314
     model selection:'apples'.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   315
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   316
     p := PopUpList on:model.
125
claus
parents: 121
diff changeset
   317
     p open.
claus
parents: 121
diff changeset
   318
claus
parents: 121
diff changeset
   319
     slv := SelectionInListView on:model.
claus
parents: 121
diff changeset
   320
     slv open.
claus
parents: 121
diff changeset
   321
1064
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   322
     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
   323
     b open.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   324
     b := Button label:'short list' action:[model list:#('1' '2' '3')].
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   325
     b open.
dba203683e94 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   326
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   327
                                                                        [exEnd]
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   328
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   329
125
claus
parents: 121
diff changeset
   330
127
claus
parents: 126
diff changeset
   331
    two PopUpLists on the same model, different aspects:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   332
                                                                        [exBegin]
121
claus
parents: 120
diff changeset
   333
     |top panel p model|
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   334
121
claus
parents: 120
diff changeset
   335
     model := Plug new.
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   336
     model respondTo:#eat: with:[:val | Transcript showCR:'eat: ' , val].
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   337
     model respondTo:#drink: with:[:val | Transcript showCR:'drink: ' , val].
121
claus
parents: 120
diff changeset
   338
     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
   339
     model respondTo:#drinks with:[#(margarita water corona)].
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   340
121
claus
parents: 120
diff changeset
   341
     top := StandardSystemView new.
claus
parents: 120
diff changeset
   342
     top extent:(100@100).
claus
parents: 120
diff changeset
   343
     panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
claus
parents: 120
diff changeset
   344
     panel horizontalLayout:#fitSpace.
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   345
121
claus
parents: 120
diff changeset
   346
     p := PopUpList label:'meals'.
126
claus
parents: 125
diff changeset
   347
     p model:model; listMessage:#meals; aspect:nil; change:#eat:.
121
claus
parents: 120
diff changeset
   348
     panel add:p.
119
claus
parents: 105
diff changeset
   349
121
claus
parents: 120
diff changeset
   350
     p := PopUpList label:'drinks'.
126
claus
parents: 125
diff changeset
   351
     p model:model; listMessage:#drinks; aspect:nil; change:#drink:.
121
claus
parents: 120
diff changeset
   352
     panel add:p.
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
   353
121
claus
parents: 120
diff changeset
   354
     top open
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   355
                                                                        [exEnd]
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   356
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
    with separate list- and indexHolders:
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 selectionHolder 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
     selectionHolder := 'apples' 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 label:'healthy fruit'.
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:selectionHolder; aspect:#value; change:#value:.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   368
     p open.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   369
     selectionHolder inspect
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   370
                                                                        [exEnd]
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   371
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   372
    same, using index:
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   373
                                                                        [exBegin]
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   374
     |p selectionIndexHolder listHolder|
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   375
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   376
     listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   377
     selectionIndexHolder := 3 asValue.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   378
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   379
     p := PopUpList new.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   380
     p listHolder:listHolder.
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   381
     p model:selectionIndexHolder; aspect:#value; change:#value:.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   382
     p useIndex:true.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   383
     p open.
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   384
     selectionIndexHolder inspect
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   385
                                                                        [exEnd]
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   386
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   387
    using different values:
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   388
                                                                        [exBegin]
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   389
     |p selectionHolder listHolder values|
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   390
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   391
     listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   392
     values := #(apples bananas grape lemon alcohol).
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   393
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   394
     selectionHolder := #alcohol asValue.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   395
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   396
     p := PopUpList label:'healthy fruit'.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   397
     p listHolder:listHolder.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   398
     p model:selectionHolder; aspect:#value; change:#value:.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   399
     p values:values.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   400
     p open.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   401
     selectionHolder inspect
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   402
                                                                        [exEnd]
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   403
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   404
121
claus
parents: 120
diff changeset
   405
"
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   406
! !
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   407
998
ab1890b4e157 specClass
ca
parents: 799
diff changeset
   408
!PopUpList class methodsFor:'defaults'!
125
claus
parents: 121
diff changeset
   409
claus
parents: 121
diff changeset
   410
defaultAspectMessage
claus
parents: 121
diff changeset
   411
    ^ #selection
claus
parents: 121
diff changeset
   412
!
claus
parents: 121
diff changeset
   413
claus
parents: 121
diff changeset
   414
defaultChangeMessage
claus
parents: 121
diff changeset
   415
    ^ #selection:
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   416
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   417
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   418
defaultListMessage
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   419
    ^ #list 
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   420
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   421
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   422
!PopUpList methodsFor:'accessing'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   423
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   424
contents
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   425
    ^ self label
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   426
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   427
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   428
contents:con
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   429
    ^ self selection:con
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   430
684
015c23130d7b selection: / setSelection:
Claus Gittinger <cg@exept.de>
parents: 655
diff changeset
   431
    "Modified: 25.5.1996 / 14:20:57 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   432
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   433
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   434
defaultLabel:aString
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   435
    "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
   436
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   437
    defaultLabel := aString.
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   438
    shown ifFalse:[
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   439
        super label:defaultLabel
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   440
    ].
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   441
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   442
    "Modified: / 29.10.1997 / 15:50:10 / cg"
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   443
!
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   444
1086
76da3ddb3372 label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   445
label:aString
76da3ddb3372 label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   446
    self defaultLabel:aString.
76da3ddb3372 label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   447
    model isNil ifTrue:[
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   448
        super label:aString suppressResize:(self shown)
1086
76da3ddb3372 label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   449
    ].
76da3ddb3372 label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   450
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   451
    "Created: / 1.3.1997 / 02:09:02 / cg"
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   452
    "Modified: / 29.10.1997 / 15:49:50 / cg"
1086
76da3ddb3372 label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   453
!
76da3ddb3372 label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   454
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   455
list
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   456
    "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
   457
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   458
    ^ menu labels
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   459
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   460
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   461
list:aList
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   462
    "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
   463
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   464
    self createMenuFor:aList.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   465
    realized ifTrue:[
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   466
	self computeLabelSize
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   467
    ]
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   468
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
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   471
     p := PopUpList label:'fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   472
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   473
     p action:[:val | Transcript showCR:'selected: ' , val printString].   
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   474
     p open
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
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   477
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   478
selection:indexOrString
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   479
    "set (force) a selection - usually done to set
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   480
     an initial selection without updating others"
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   481
1839
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   482
    |index menuLabels newLabel|
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   483
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   484
    menu isNil ifTrue:[
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   485
        self getListFromModel.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   486
    ].
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   487
    menu isNil ifTrue:[^ self].
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   488
    menuLabels := menu labels.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   489
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   490
    (useIndex not and:[values notNil]) ifTrue:[
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   491
        index := values indexOf:indexOrString
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   492
    ] ifFalse:[
1237
712a7f548d4a selection:indexOrString
ca
parents: 1142
diff changeset
   493
        indexOrString isNumber ifTrue:[
712a7f548d4a selection:indexOrString
ca
parents: 1142
diff changeset
   494
            index := indexOrString
712a7f548d4a selection:indexOrString
ca
parents: 1142
diff changeset
   495
        ] ifFalse:[
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   496
            index := menuLabels indexOf:indexOrString.
1237
712a7f548d4a selection:indexOrString
ca
parents: 1142
diff changeset
   497
        ].
1079
0ffa5c8a2b74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   498
        "/ fails if list consists of symbols ...
0ffa5c8a2b74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   499
        "/ index := menu indexOf:indexOrString.
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   500
    ].
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   501
    index > menuLabels size ifTrue:[
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   502
        index := 0
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   503
    ].
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   504
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   505
    index == 0 ifTrue:[
1839
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   506
        newLabel := defaultLabel
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   507
    ] ifFalse:[
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   508
        newLabel := (menuLabels at:index) printString
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   509
    ].
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   510
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   511
    "kludge: dont want label to resize ..."
1839
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   512
    self label:newLabel suppressResize:true.
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   513
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   514
    "
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   515
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   516
     p := PopUpList label:'what fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   517
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   518
     p selection:'grape'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   519
     p open 
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   520
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   521
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   522
     p := PopUpList label:'what fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   523
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   524
     p selection:'blabla'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   525
     p open
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   526
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   527
     |p|
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   528
     p := PopUpList label:'what fruit ?'.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   529
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   530
     p defaultLabel:'nothing selected'.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   531
     p selection:'blabla'.
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   532
     p open
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   533
    "
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   534
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   535
    "Modified: / 29.10.1997 / 15:50:12 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   536
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   537
593
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   538
values:aList
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   539
    "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
   540
     the label strings."
593
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   541
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   542
    values := aList.
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   543
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   544
    "
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   545
     |p|
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   546
     p := PopUpList label:'fruit ?'.
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   547
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   548
     p values:#(1 2 3 4 'mhmh - good').
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   549
     p action:[:val | Transcript showCR:'selected: ' , val printString].   
593
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   550
     p open.
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   551
    "
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   552
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   553
    "Modified: 27.2.1997 / 10:24:12 / cg"
593
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   554
! !
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   555
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   556
!PopUpList methodsFor:'accessing-behavior'!
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   557
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   558
action:aOneArgBlock
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   559
    "set the action to be performed on selection changes;
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   560
     the argument, aOneArgBlock will be evaluated with the
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   561
     selection-value as argument"
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   562
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   563
    menuAction := aOneArgBlock
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   564
!
86dd024ed773 examples
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   565
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   566
menu:aMenu default:label
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   567
    menu := aMenu.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   568
    defaultLabel := label
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   569
!
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   570
1311
5230e0dfbb27 useIndex was missing
ca
parents: 1237
diff changeset
   571
useIndex
5230e0dfbb27 useIndex was missing
ca
parents: 1237
diff changeset
   572
    "tell the popuplist to pass the index (instead of the value)
5230e0dfbb27 useIndex was missing
ca
parents: 1237
diff changeset
   573
     to both the actionBlock and model. Notice, that if you use a model,
5230e0dfbb27 useIndex was missing
ca
parents: 1237
diff changeset
   574
     the default changeSelector is not ok for using index and a SelectionInList"
5230e0dfbb27 useIndex was missing
ca
parents: 1237
diff changeset
   575
5230e0dfbb27 useIndex was missing
ca
parents: 1237
diff changeset
   576
    ^ useIndex
5230e0dfbb27 useIndex was missing
ca
parents: 1237
diff changeset
   577
!
5230e0dfbb27 useIndex was missing
ca
parents: 1237
diff changeset
   578
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   579
useIndex:aBoolean 
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   580
    "tell the popuplist to pass the index (instead of the value)
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   581
     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
   582
     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
   583
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   584
    useIndex := aBoolean
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
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   588
     p := PopUpList label:'fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   589
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   590
     p action:[:val | Transcript showCR:'selected: ' , val printString].   
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   591
     p open.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   592
    "
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   593
    "
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   594
     |p|
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   595
     p := PopUpList label:'fruit ?'.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   596
     p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
655
acad3ef3a46c showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   597
     p action:[:val | Transcript showCR:'selected: ' , val printString].   
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   598
     p useIndex:true.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   599
     p open.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   600
    "
125
claus
parents: 121
diff changeset
   601
! !
claus
parents: 121
diff changeset
   602
1921
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   603
!PopUpList methodsFor:'accessing-look'!
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   604
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   605
showHandle
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   606
    "return true if the pull-handle is to be drawn; default is true"
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   607
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   608
    ^ showHandle
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   609
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   610
    "Created: / 6.3.1999 / 21:26:40 / cg"
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   611
!
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   612
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   613
showHandle:aBoolean
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   614
    "controls if the pull-handle is to be drawn; default is true"
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   615
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   616
    showHandle := aBoolean.
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   617
    self computeLabelSize
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   618
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   619
    "Modified: / 6.3.1999 / 21:58:21 / cg"
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   620
! !
93c064603431 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1840
diff changeset
   621
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   622
!PopUpList methodsFor:'accessing-mvc'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   623
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   624
addModelInterfaceTo:aDictionary
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   625
    "see comment in View>>modelInterface"
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   626
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   627
    super addModelInterfaceTo:aDictionary.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   628
    aDictionary at:#listMessage put:listMsg
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   629
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   630
    "Modified: 26.2.1997 / 19:08:04 / cg"
205
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
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   633
listHolder
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   634
    "return the listHolder if any"
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   635
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   636
    ^ listHolder
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   637
!
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   638
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   639
listHolder:aValueHolder
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   640
    "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
   641
     list via #value.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   642
     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
   643
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   644
    listHolder notNil ifTrue:[
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   645
        listHolder removeDependent:self.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   646
    ].
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   647
    listHolder := aValueHolder.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   648
    listHolder notNil ifTrue:[
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   649
        listHolder addDependent:self.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   650
    ].
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   651
    shown ifTrue:[
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   652
        self getListFromModel
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   653
    ]
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   654
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   655
    "Modified: 26.2.1997 / 19:06:01 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   656
!
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
listMessage
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   659
    "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
   660
     The default is #list. 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   661
     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
   662
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   663
    ^ listMsg
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   664
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   665
    "Modified: 26.2.1997 / 19:05:27 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   666
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   667
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   668
listMessage:aSelector
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   669
    "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
   670
     The default is #list. 
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   671
     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
   672
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   673
    listMsg := aSelector
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   674
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   675
    "Modified: 26.2.1997 / 19:05:18 / cg"
1083
13e64cc1c493 fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   676
!
13e64cc1c493 fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   677
13e64cc1c493 fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   678
model:aModel
13e64cc1c493 fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   679
    super model:aModel.
13e64cc1c493 fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   680
    self getListFromModel.
13e64cc1c493 fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   681
    self getSelectionFromModel.
13e64cc1c493 fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   682
13e64cc1c493 fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   683
    "Created: 28.2.1997 / 19:12:08 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   684
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   685
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   686
!PopUpList methodsFor:'change & update'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   687
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   688
update:something with:aParameter from:changedObject
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   689
    changedObject == listHolder ifTrue:[
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   690
        self getListFromModel.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   691
        ^ self
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   692
    ].
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   693
    changedObject == model ifTrue:[
1078
dfc190980181 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1077
diff changeset
   694
        aspectMsg notNil ifTrue:[
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   695
            self getSelectionFromModel.
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   696
        ].
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   697
        listHolder notNil ifTrue:[
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   698
            "/ that one holds the list;
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   699
            "/ model holds the value
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   700
            self getSelectionFromModel
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   701
        ] ifFalse:[
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   702
            listMsg notNil ifTrue:[
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   703
                self getListFromModel.
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   704
            ]
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   705
        ].
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   706
        ^ self
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   707
    ].
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   708
    super update:something with:aParameter from:changedObject
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   709
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   710
    "Modified: / 18.6.1998 / 23:48:47 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   711
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   712
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   713
!PopUpList methodsFor:'drawing'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   714
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   715
drawWith:fgColor and:bgColor
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   716
    |mmH mmV mW mH|
136
claus
parents: 135
diff changeset
   717
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   718
    controller pressed ifTrue:[
1758
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
   719
        super drawWith:enteredFgColor and:enteredBgColor
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   720
    ] ifFalse:[
1758
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
   721
        super drawWith:fgColor and:bgColor.
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   722
    ].
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   723
1758
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
   724
    showHandle ifTrue:[
1772
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   725
        mmH := device horizontalPixelPerMillimeter.
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   726
        mmV := device verticalPixelPerMillimeter.
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   727
        mW := (mmH * 2.5) rounded.
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   728
        mH := (mmV * 1.5) rounded.
1758
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
   729
1772
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   730
        self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV rounded
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   731
 // 2)
1758
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
   732
                     width:mW height:mH level:2
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
   733
    ].
1772
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   734
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   735
    "Modified: / 6.3.1999 / 21:56:13 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   736
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   737
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   738
showActive
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   739
    "no need to redraw - will pop menu ontop of me anyway ..."
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   740
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   741
    ^ self
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   742
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   743
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   744
showPassive
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   745
    "no need to redraw - will redraw from unpopped menu anyway ..."
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   746
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   747
    ^ self
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   748
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   749
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   750
!PopUpList methodsFor:'event handling'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   751
1492
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   752
keyPress:key x:x y:y
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   753
    (key == Character space
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   754
    or:[key == #Return])ifTrue:[
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   755
        self popMenu.
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   756
        ^ self
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   757
    ].
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   758
    super keyPress:key x:x y:y
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   759
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   760
    "Created: / 21.4.1998 / 20:05:19 / cg"
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   761
!
348f9d99ff8a popup on space or return
Claus Gittinger <cg@exept.de>
parents: 1376
diff changeset
   762
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   763
popMenu
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   764
    |org mv w theMenu val|
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   765
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   766
    menu notNil ifTrue:[
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   767
        theMenu := menu value
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   768
    ].
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   769
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   770
    theMenu notNil ifTrue:[
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   771
        self turnOffWithoutRedraw. 
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   772
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   773
        theMenu value labels size == 0 ifTrue:[
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   774
            ^ self
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   775
        ].
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   776
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   777
        theMenu isView ifTrue:[
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   778
            "/ oldStyle - theMenu is a PopUpMenu
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   779
            theMenu font:font.
136
claus
parents: 135
diff changeset
   780
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   781
            "
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   782
             adjust the menus width to my current width
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   783
            "
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   784
            mv := theMenu menuView.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   785
            mv create.      "/ stupid: it resizes itself upon first create
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   786
            w := mv width.  "/ to its preferred size.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   787
            w := w max:(self width - (2 * theMenu margin) - (theMenu borderWidth*2)).
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   788
            mv width:w.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   789
            mv level:0; borderWidth:0.
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   790
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   791
            "
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   792
             the popupMenu wants Display coordinates in its showAt: method
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   793
            "
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   794
            org := device translatePoint:0@0 
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   795
                                    from:(self id)
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   796
                                      to:(device rootView id).
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   797
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   798
            theMenu showAt:org "resizing:false"
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   799
        ] ifFalse:[
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   800
            "/ newStyle - theMenu is a Menu
2174
1245fc1a0654 compatibility stuff
Claus Gittinger <cg@exept.de>
parents: 2172
diff changeset
   801
            val := theMenu startUpOrNil.
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   802
            (theMenu isKindOf:PopUpMenu) ifFalse:[
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   803
                "/ sigh - brand new ...
2174
1245fc1a0654 compatibility stuff
Claus Gittinger <cg@exept.de>
parents: 2172
diff changeset
   804
                val notNil ifTrue:[
1245fc1a0654 compatibility stuff
Claus Gittinger <cg@exept.de>
parents: 2172
diff changeset
   805
                    self sendChangeMessage:changeMsg with:val.
1245fc1a0654 compatibility stuff
Claus Gittinger <cg@exept.de>
parents: 2172
diff changeset
   806
                    menuAction notNil ifTrue:[
1245fc1a0654 compatibility stuff
Claus Gittinger <cg@exept.de>
parents: 2172
diff changeset
   807
                        menuAction value:val
1245fc1a0654 compatibility stuff
Claus Gittinger <cg@exept.de>
parents: 2172
diff changeset
   808
                    ]
2172
411ac4dcf8b4 action invocation for VW compatibility.
Claus Gittinger <cg@exept.de>
parents: 1988
diff changeset
   809
                ].
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   810
            ].
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   811
        ]
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   812
    ].
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   813
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   814
    "Modified: / 18.6.1998 / 23:47:39 / cg"
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   815
! !
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   816
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   817
!PopUpList methodsFor:'initialization'!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   818
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   819
defaultControllerClass
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   820
    ^ PopUpListController
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   821
!
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   822
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   823
initialize
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   824
    super initialize.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   825
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   826
    controller beTriggerOnDown.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   827
    controller action:[self popMenu].
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   828
    useIndex := false.
1035
c7cfaead1621 dont pop menu if there are no list items.
ca
parents: 1012
diff changeset
   829
    defaultLabel := 'popup'.
1758
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
   830
    showHandle := true.
1840
4f19e7d33159 checkin from browser
tm
parents: 1839
diff changeset
   831
    self adjust:#left.
1758
30ad727ade43 checkin from browser
tm
parents: 1587
diff changeset
   832
1086
76da3ddb3372 label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   833
    super label:defaultLabel.
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   834
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   835
    listMsg := self class defaultListMessage.
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   836
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   837
    onLevel := offLevel.
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
   838
1086
76da3ddb3372 label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents: 1083
diff changeset
   839
    "Modified: 1.3.1997 / 02:12:55 / cg"
136
claus
parents: 135
diff changeset
   840
! !
claus
parents: 135
diff changeset
   841
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   842
!PopUpList methodsFor:'private'!
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   843
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   844
computeLabelSize
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   845
    "compute the extent needed to hold the label plus the mark"
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   846
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   847
    |mmH mmV savedLogo longest longestWidth labels|
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   848
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   849
    menu isNil ifTrue:[
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   850
        super computeLabelSize
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   851
    ] ifFalse:[
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   852
        "hack: simulate logo change to longest menu entry"
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   853
1988
55184833642a #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1921
diff changeset
   854
        font := font onDevice:device.
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   855
        longest := logo.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   856
        logo isNil ifTrue:[
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   857
            longestWidth := 0
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   858
        ] ifFalse:[
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   859
            longestWidth := font widthOf:logo.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   860
        ].
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   861
        labels := menu value labels.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   862
        labels notNil ifTrue:[
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   863
            labels do:[:entry |
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   864
                |this|
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   865
1098
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   866
                this := font widthOf:entry printString.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   867
                this > longestWidth ifTrue:[
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   868
                    longest := entry.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   869
                    longestWidth := this
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   870
                ].
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   871
            ].
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   872
        ].
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   873
        savedLogo := logo.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   874
        logo := longest printString.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   875
        super computeLabelSize.
e60febc8c26d preparations for Menu (instead of PopUpMenu)
ca
parents: 1086
diff changeset
   876
        logo := savedLogo.
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   877
    ].
1772
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   878
    showHandle ifTrue:[
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   879
        mmH := device horizontalPixelPerMillimeter.
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   880
        mmV := device verticalPixelPerMillimeter.
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   881
        labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace.
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   882
        labelHeight := labelHeight max: (mmV * 2) rounded
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   883
    ]
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
   884
1772
7ac24130dd51 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1758
diff changeset
   885
    "Modified: / 6.3.1999 / 21:51:14 / cg"
121
claus
parents: 120
diff changeset
   886
!
claus
parents: 120
diff changeset
   887
claus
parents: 120
diff changeset
   888
createMenuFor:aList
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   889
    (aList isKindOf:Menu) ifTrue:[
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   890
        menu := aList.
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   891
        ^ self.
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   892
    ].
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   893
121
claus
parents: 120
diff changeset
   894
    menu := PopUpMenu
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   895
                  labels:aList
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   896
               selectors:#select:
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   897
                    args:(1 to:aList size) 
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   898
                receiver:self
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   899
                     for:self.
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   900
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   901
    "Modified: / 18.6.1998 / 23:20:16 / cg"
128
claus
parents: 127
diff changeset
   902
!
claus
parents: 127
diff changeset
   903
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   904
getListFromModel
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   905
    "if I have a listHolder, ask it for the list;
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   906
     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
   907
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   908
    listHolder notNil ifTrue:[
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   909
        self list:listHolder value.
1587
8cacd0f9ed92 oops - leftover halt
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   910
"/        model notNil ifTrue:[
8cacd0f9ed92 oops - leftover halt
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   911
"/            self halt.
8cacd0f9ed92 oops - leftover halt
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   912
"/        ]
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   913
    ] ifFalse:[
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   914
        (listMsg notNil and:[model notNil]) ifTrue:[
1067
1933c253b537 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   915
            (model respondsTo:listMsg) ifTrue:[
1933c253b537 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   916
                self list:(model perform:listMsg).
1933c253b537 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   917
            ]
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   918
        ].
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   919
    ]
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   920
1587
8cacd0f9ed92 oops - leftover halt
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
   921
    "Modified: / 19.6.1998 / 01:54:17 / cg"
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   922
!
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   923
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   924
getSelectionFromModel
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   925
    "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
   926
1839
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   927
    |aspect val newLabel|
1075
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   928
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   929
    (model notNil and:[aspectMsg notNil]) ifTrue:[
1075
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   930
        "/ kludge - try #value if aspect is the default and
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   931
        "/ not understood by the model
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   932
        "/ this allows a valueHolder to be used, even
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   933
        "/ if the aspectMessage was not setup correctly.
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   934
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   935
        aspect := aspectMsg.
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   936
        aspect == self class defaultAspectMessage ifTrue:[
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   937
            (model respondsTo:aspect) ifFalse:[
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   938
                aspect := #value
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   939
            ]
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
   940
        ].
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   941
        val := (model perform:aspect).
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   942
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   943
        useIndex ifFalse:[
1839
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   944
            val isNil ifTrue:[
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   945
                newLabel := defaultLabel 
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   946
            ] ifFalse:[
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   947
                newLabel := val printString.
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   948
            ].
75f77fcf458b fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents: 1772
diff changeset
   949
            ^ self label:newLabel suppressResize:true.
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   950
        ].
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   951
        self selection:val
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   952
    ].
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   953
1586
e4e6e12cbd1f ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents: 1492
diff changeset
   954
    "Modified: / 18.6.1998 / 23:54:34 / cg"
121
claus
parents: 120
diff changeset
   955
! !
claus
parents: 120
diff changeset
   956
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   957
!PopUpList methodsFor:'private-controller access'!
121
claus
parents: 120
diff changeset
   958
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   959
menu
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   960
    "return the menu component"
125
claus
parents: 121
diff changeset
   961
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   962
    ^ menu
126
claus
parents: 125
diff changeset
   963
! !
claus
parents: 125
diff changeset
   964
136
claus
parents: 135
diff changeset
   965
!PopUpList methodsFor:'queries'!
claus
parents: 135
diff changeset
   966
claus
parents: 135
diff changeset
   967
preferredExtent
claus
parents: 135
diff changeset
   968
    "redefined to make certain that the menu is fully defined"
claus
parents: 135
diff changeset
   969
799
64f8700489a4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   970
    "/ If I have an explicit preferredExtent ..
64f8700489a4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   971
714
5ff02d2d9fa7 care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   972
    preferredExtent notNil ifTrue:[
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   973
	^ preferredExtent
714
5ff02d2d9fa7 care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   974
    ].
5ff02d2d9fa7 care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   975
136
claus
parents: 135
diff changeset
   976
    menu isNil ifTrue:[
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   977
	self getListFromModel
136
claus
parents: 135
diff changeset
   978
    ].
claus
parents: 135
diff changeset
   979
    self computeLabelSize.
claus
parents: 135
diff changeset
   980
    ^ super preferredExtent.
714
5ff02d2d9fa7 care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   981
799
64f8700489a4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   982
    "Modified: 19.7.1996 / 20:45:16 / cg"
155
claus
parents: 136
diff changeset
   983
!
claus
parents: 136
diff changeset
   984
claus
parents: 136
diff changeset
   985
specClass
1376
26f519265846 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   986
    "XXX no longer needed (inherited default works here)"
26f519265846 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   987
155
claus
parents: 136
diff changeset
   988
    self class == PopUpList ifTrue:[^ PopUpListSpec].
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   989
    ^ super specClass
1376
26f519265846 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   990
26f519265846 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1369
diff changeset
   991
    "Modified: / 31.10.1997 / 19:48:02 / cg"
136
claus
parents: 135
diff changeset
   992
! !
claus
parents: 135
diff changeset
   993
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   994
!PopUpList methodsFor:'user actions'!
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
   995
1069
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   996
select:anIndex
119
claus
parents: 105
diff changeset
   997
    "this is sent from the popupmenu when an entry was selected"
claus
parents: 105
diff changeset
   998
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
   999
    |value menuLabels label chg|
77
565b052f5277 *** empty log message ***
claus
parents: 70
diff changeset
  1000
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  1001
    menuLabels := menu labels.
1069
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1002
    values isNil ifTrue:[
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1003
        value := anIndex.
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1004
        useIndex ifFalse:[
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  1005
            value := menuLabels at:anIndex.
1069
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1006
        ]
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1007
    ] ifFalse:[
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1008
        value := values at:anIndex
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1009
    ].
d773b6e9dc28 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1010
1142
406d3829ddcc always change my label on select:;
Claus Gittinger <cg@exept.de>
parents: 1098
diff changeset
  1011
"/    model isNil ifTrue:[
1066
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1012
        "/ if there is a model,
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1013
        "/ the update will change my logo ...
d324041c0aaf examples and values-handling
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1014
1368
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  1015
        "/ self sizeFixed:true.
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  1016
        label := menuLabels at:anIndex.
5fcf20b3d507 useIndex - stuff
Claus Gittinger <cg@exept.de>
parents: 1311
diff changeset
  1017
        super label:label printString suppressResize:true.
1142
406d3829ddcc always change my label on select:;
Claus Gittinger <cg@exept.de>
parents: 1098
diff changeset
  1018
"/    ].
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
  1019
1075
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1020
    (model notNil and:[changeMsg notNil]) ifTrue:[
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1021
        "/
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1022
        "/ ST-80 way of doing it
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1023
        "/ tell my model - if any
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1024
        "/
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1025
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1026
        "/ kludge - try #value: if changeMsg is the default and
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1027
        "/ not understood by the model
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1028
        "/ this allows a valueHolder to be used, even
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1029
        "/ if the aspectMessage was not setup correctly.
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1030
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1031
        chg := changeMsg.
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1032
        chg == self class defaultChangeMessage ifTrue:[
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1033
            (model respondsTo:chg) ifFalse:[
1076
19d9daaad1a9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1075
diff changeset
  1034
                chg := #value:
1075
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1035
            ]
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1036
        ].
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1037
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1038
        self sendChangeMessage:chg with:value.
662f7e5069fd allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents: 1071
diff changeset
  1039
    ].
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1040
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1041
    "/
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1042
    "/ ST/X action blocks
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1043
    "/
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1044
    menuAction notNil ifTrue:[
1063
b315e2580bc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1052
diff changeset
  1045
        menuAction value:value.
1052
59f182d1304f added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1046
    ].
327
5cd2a6f4f28e fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents: 205
diff changeset
  1047
1369
d65ca0b910b1 removed debugPrints
Claus Gittinger <cg@exept.de>
parents: 1368
diff changeset
  1048
    "Modified: / 29.10.1997 / 21:08:50 / cg"
20
0d9c61aacaa4 Initial revision
claus
parents:
diff changeset
  1049
! !
121
claus
parents: 120
diff changeset
  1050
998
ab1890b4e157 specClass
ca
parents: 799
diff changeset
  1051
!PopUpList class methodsFor:'documentation'!
121
claus
parents: 120
diff changeset
  1052
205
6814c0bf8df8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
  1053
version
2174
1245fc1a0654 compatibility stuff
Claus Gittinger <cg@exept.de>
parents: 2172
diff changeset
  1054
    ^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.65 2000-04-01 14:30:31 cg Exp $'
121
claus
parents: 120
diff changeset
  1055
! !