Tools__ViewTreeApplication.st
author Claus Gittinger <cg@exept.de>
Thu, 14 Mar 2013 14:21:20 +0100
changeset 2978 a952dfdb1b6a
parent 2888 9adfb8a84696
child 3000 7b530cc76688
permissions -rw-r--r--
class: Tools::ViewTreeInspectorApplication
allow for the event catching to be switched off,
so that interaction with the view is possible,
even while showing the widget hierarchy.
Added a force redraw button.
cg@2748
     1
"
cg@2748
     2
 COPYRIGHT (c) 2007 by eXept Software AG
cg@2748
     3
              All Rights Reserved
cg@2748
     4
cg@2748
     5
 This software is furnished under a license and may be used
cg@2748
     6
 only in accordance with the terms of that license and with the
cg@2748
     7
 inclusion of the above copyright notice.   This software may not
cg@2748
     8
 be provided or otherwise made available to, or used by, any
cg@2748
     9
 other person.  No title to or ownership of the software is
cg@2748
    10
 hereby transferred.
cg@2748
    11
"
ca@2177
    12
"{ Package: 'stx:libtool2' }"
ca@2177
    13
ca@2177
    14
"{ NameSpace: Tools }"
ca@2177
    15
cg@2744
    16
ToolApplicationModel subclass:#ViewTreeInspectorApplication
ca@2177
    17
	instanceVariableNames:'model treeView hasSingleSelectionHolder clickedItem clickedPoint
cg@2770
    18
		motionAction process followFocusChannel showNamesHolder
cg@2770
    19
		inspectorView'
ca@2177
    20
	classVariableNames:''
ca@2177
    21
	poolDictionaries:''
cg@2744
    22
	category:'Interface-Smalltalk'
ca@2177
    23
!
ca@2177
    24
ca@2177
    25
Object subclass:#MenuDesc
ca@2177
    26
	instanceVariableNames:'title value action'
ca@2177
    27
	classVariableNames:''
ca@2177
    28
	poolDictionaries:''
cg@2744
    29
	privateIn:ViewTreeInspectorApplication
ca@2177
    30
!
ca@2177
    31
cg@2744
    32
HierarchicalItem subclass:#ViewTreeItem
cg@2744
    33
	instanceVariableNames:'widget isDrawnShown exists xOffsetAdditionalName'
cg@2744
    34
	classVariableNames:'HandleExtent'
cg@2744
    35
	poolDictionaries:''
cg@2744
    36
	privateIn:ViewTreeInspectorApplication
cg@2744
    37
!
cg@2744
    38
cg@2744
    39
ValueModel subclass:#ViewTreeModel
cg@2744
    40
	instanceVariableNames:'lockSema selectedSuperItems selection hiddenLevel listOfItems
cg@2744
    41
		inputEventAction mappedViewAction beforeSelectionChangedAction
cg@2744
    42
		icons timedUpdateTask selectOnClickHolder testModeChannel
cg@2978
    43
		hasTargetWidgetChannel catchEvents'
cg@2744
    44
	classVariableNames:''
cg@2744
    45
	poolDictionaries:''
cg@2744
    46
	privateIn:ViewTreeInspectorApplication
cg@2744
    47
!
cg@2744
    48
cg@2744
    49
HierarchicalList subclass:#ItemList
cg@2744
    50
	instanceVariableNames:'treeModel eventHook eventHookInitialized showWidgetNames'
cg@2744
    51
	classVariableNames:''
cg@2744
    52
	poolDictionaries:''
cg@2744
    53
	privateIn:ViewTreeInspectorApplication::ViewTreeModel
cg@2744
    54
!
cg@2744
    55
cg@2744
    56
!ViewTreeInspectorApplication class methodsFor:'documentation'!
ca@2177
    57
cg@2748
    58
copyright
cg@2748
    59
"
cg@2748
    60
 COPYRIGHT (c) 2007 by eXept Software AG
cg@2748
    61
              All Rights Reserved
cg@2748
    62
cg@2748
    63
 This software is furnished under a license and may be used
cg@2748
    64
 only in accordance with the terms of that license and with the
cg@2748
    65
 inclusion of the above copyright notice.   This software may not
cg@2748
    66
 be provided or otherwise made available to, or used by, any
cg@2748
    67
 other person.  No title to or ownership of the software is
cg@2748
    68
 hereby transferred.
cg@2748
    69
"
cg@2748
    70
!
cg@2748
    71
ca@2177
    72
documentation
ca@2177
    73
"
ca@2177
    74
     Small application showing a ViewTreeModel use.
ca@2177
    75
ca@2177
    76
     It displays a hierarchical list of a selected TopView and
ca@2177
    77
     all its contained subViews.
ca@2177
    78
     Useful to have a look at subcomponents - to see how views
ca@2177
    79
     are structured.
ca@2177
    80
ca@2177
    81
ca@2177
    82
    [Instance variables:]
ca@2177
    83
        model           <ViewTreeModel>      the used ViewTreeModel
ca@2177
    84
        clickedItem     <ViewTreeItem>       item under the clickedPoint (motion action)
ca@2177
    85
        clickedPoint    <Point>              point where the motion action started from.
ca@2177
    86
        motionAction    <Action>             (oneArg-) action called durring buttonMotion.
ca@2177
    87
ca@2177
    88
ca@2177
    89
    [author:]
ca@2177
    90
        Claus Atzkern
ca@2177
    91
ca@2177
    92
    [see also:]
ca@2177
    93
        ViewTreeModel
ca@2177
    94
        ViewTreeItem
ca@2177
    95
"
ca@2177
    96
! !
ca@2177
    97
cg@2744
    98
!ViewTreeInspectorApplication class methodsFor:'initialization'!
ca@2177
    99
ca@2177
   100
initialize
ca@2177
   101
    "add myself to the launcher menu
ca@2177
   102
    "
ca@2177
   103
    self installInLauncher.
ca@2177
   104
!
ca@2177
   105
ca@2177
   106
installInLauncher
cg@2744
   107
    "add myself to the launcher menu"
cg@2744
   108
ca@2177
   109
    |menuItem icon|
ca@2177
   110
ca@2177
   111
    NewLauncher isNil ifTrue:[^ self].
cg@2744
   112
    "/ cg - disabled. the icon is too ugly.
cg@2744
   113
    ^ self.
ca@2177
   114
ca@2177
   115
    icon := ToolbarIconLibrary inspectLocals20x20Icon magnifiedTo:28@28.
ca@2177
   116
ca@2177
   117
    menuItem := MenuItem new 
cg@2744
   118
                    label: 'View Tree Inspector';
cg@2744
   119
                    value: [ ViewTreeInspectorApplication open];
ca@2177
   120
                    isButton: true;
ca@2177
   121
                    icon: icon;
ca@2177
   122
                    nameKey: #viewInspect.
ca@2177
   123
ca@2177
   124
    menuItem startGroup:#right.
ca@2177
   125
    NewLauncher addMenuItem:menuItem in:'toolbar'
ca@2177
   126
                   position:#( #before #help)
ca@2177
   127
                      space:false.
ca@2177
   128
ca@2177
   129
"
ca@2177
   130
self installInLauncher
ca@2177
   131
self removeFromLauncher
ca@2177
   132
"
ca@2177
   133
!
ca@2177
   134
ca@2177
   135
postAutoload
ca@2177
   136
    "add myself to the launcher menu
ca@2177
   137
    "
ca@2177
   138
    self installInLauncher.
ca@2177
   139
"
ca@2177
   140
self installInLauncher
ca@2177
   141
self removeFromLauncher
ca@2177
   142
"
ca@2177
   143
!
ca@2177
   144
ca@2177
   145
removeFromLauncher
ca@2177
   146
    "remove myself from the launcher menu
ca@2177
   147
    "
ca@2177
   148
    NewLauncher isNil ifTrue:[^ self].
ca@2177
   149
    NewLauncher removeUserTool:#viewInspect
ca@2177
   150
ca@2177
   151
"
ca@2177
   152
self installInLauncher
ca@2177
   153
self removeFromLauncher
ca@2177
   154
"
ca@2177
   155
!
ca@2177
   156
ca@2177
   157
unload
ca@2177
   158
    "class is about to be unloaded - remove myself from the launcher menu
ca@2177
   159
    "
ca@2177
   160
    self removeFromLauncher.
ca@2177
   161
    super unload.
ca@2177
   162
! !
ca@2177
   163
cg@2744
   164
!ViewTreeInspectorApplication class methodsFor:'image specs'!
cg@2744
   165
cg@2759
   166
crossHairIcon
cg@2759
   167
    "This resource specification was automatically generated
cg@2759
   168
     by the ImageEditor of ST/X."
cg@2759
   169
cg@2759
   170
    "Do not manually edit this!! If it is corrupted,
cg@2759
   171
     the ImageEditor may not be able to read the specification."
cg@2759
   172
cg@2759
   173
    "
cg@2759
   174
     self crossHairIcon inspect
cg@2759
   175
     ImageEditor openOnClass:self andSelector:#crossHairIcon
cg@2759
   176
     Icon flushCachedIcons
cg@2759
   177
    "
cg@2759
   178
cg@2759
   179
    <resource: #image>
cg@2759
   180
cg@2759
   181
    ^Icon
cg@2759
   182
        constantNamed:'Tools::ViewTreeInspectorApplication class crossHairIcon'
cg@2759
   183
        ifAbsentPut:[(Depth1Image new) width: 24; height: 24; photometric:(#palette); bitsPerSample:(#[1]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@@@@@@F0@@XL@@>>@A8O@A>?@B,Z B(J @@@@B(J B,Z A>?@A8O@@>>@@XL@@F0@@@@@@@@@@@@@@@@@@@@@') ; colorMapFromArray:#[255 255 255 0 0 0]; mask:((Depth1Image new) width: 24; height: 24; photometric:(#blackIs0); bitsPerSample:(#[1]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@@G0@@_<@@?>@A??@C?? C?? G??0G<_0G<_0G<_0G??0C?? C?? A??@@?>@@_<@@G0@@@@@@@@@@@@@@@@@') ; yourself); yourself]
cg@2759
   184
!
cg@2759
   185
cg@2744
   186
pickWindowIcon
cg@2744
   187
    "This resource specification was automatically generated
cg@2744
   188
     by the ImageEditor of ST/X."
cg@2744
   189
cg@2744
   190
    "Do not manually edit this!! If it is corrupted,
cg@2744
   191
     the ImageEditor may not be able to read the specification."
cg@2744
   192
cg@2744
   193
    "
cg@2744
   194
     self pickWindowIcon inspect
cg@2744
   195
     ImageEditor openOnClass:self andSelector:#pickWindowIcon
cg@2744
   196
     Icon flushCachedIcons
cg@2744
   197
    "
cg@2744
   198
cg@2744
   199
    <resource: #image>
cg@2744
   200
cg@2744
   201
    ^Icon
cg@2744
   202
        constantNamed:'Tools::ViewTreeInspectorApplication class pickWindowIcon'
cg@2744
   203
        ifAbsentPut:[(Depth8Image new) width: 22; height: 22; photometric:(#palette); bitsPerSample:(#[8]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'
cg@2744
   204
,;N3,;N3,;N3,;N3,;N3,;N3,;N3,3H<P38;M3P,H2@^GA(VEQHQCP0KA D<[&-%XU=WST%BN#D!!GQ$TD@(IBP\BQF)+Z6E_U4-FPCX+G1,WEA@JBP$HAT23
cg@2744
   205
,;N3,;N3,;N3,;N$():Z&IRR&1!!^,;N3,;N3,;N3,;N$)JJ^&)"T$),0W[N3,;N3,;N3,;N3,:R"'')*X%IJWK523,;N3,;N3,0@@@KN3)JJ^&)"T$"5Z,;N3
cg@2744
   206
,;N3@@B3-KL@@JJ^&)"T$)D*V[N3,;N3@KN3-KR4)JH@&)"T$)*MJE"3,;N3,0B3)JJ4&*R"@I*X%IJZ#RYV,;N3,0B3@JR"-JR"-I(@%IJV%H %U[N3,;L@
cg@2744
   207
-@B4-KR4-KR4@IRR%IJEIER3,;N3@KL@)JJ4():4&@BO#9RR!!RIS,;N3,;L@,:R"-JJ^& BT#8>O#8H"T+N3,;N3@KN$@@@@'')(@%H>O#(>AH%F3,;N3,;L@
cg@2744
   208
@JR4'' @@%IJO#8>O RIO,;N3,;N3):P@@@BX%IJO#8>O#7<"S*63,;N$():Z&IRR&IRR#8>O#8=>H"&-,;N$():Z&IRR&)"T$(>O#8>O @<)R$!!GQTD?OS$8
cg@2744
   209
MSL.I2H"H"H"H"HO,;N3,;N3,;N3,;N3,;N3,;N3,;N3,0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@a') ; colorMapFromArray:#[0 0 0 0 50 164 0 50 171 0 137 0 0 206 0 1 50 177 2 56 178 3 64 241 3 67 246 3 73 255 4 74 255 5 63 191 7 66 194 10 71 196 10 79 255 12 59 167 12 82 255 14 77 199 18 83 201 19 88 255 21 91 255 23 89 204 27 95 206 28 97 255 29 72 179 30 100 255 32 101 209 36 106 255 36 107 211 39 109 255 41 113 214 45 115 255 45 119 216 48 118 255 50 87 176 50 125 219 51 88 176 51 88 177 52 89 178 52 90 178 53 90 178 53 127 212 54 91 179 54 123 255 54 131 221 55 92 180 55 95 181 56 93 180 56 94 181 57 127 255 57 149 229 58 99 184 58 137 224 61 104 187 63 132 255 63 143 226 64 108 190 66 113 193 66 135 255 67 149 229 68 157 232 69 117 196 71 155 231 72 122 199 72 141 255 75 126 202 75 144 255 75 160 234 77 163 236 78 131 206 80 149 255 81 136 209 84 140 212 84 153 255 87 145 215 88 157 255 91 168 235 93 161 255 94 154 222 96 157 223 96 165 255 97 159 225 98 160 225 98 162 226 99 163 227 100 165 228 101 166 229 101 170 255 102 167 230 103 169 231 104 170 232 104 173 255 105 172 233 105 174 234 106 175 235 109 178 255 112 180 255 117 186 255 119 187 255 122 154 245 125 160 253 125 193 255 126 161 253 126 194 255 127 162 254 130 165 254 132 200 255 132 201 255 133 60 36 135 170 255 139 207 255 140 175 255 144 179 255 149 184 255 153 188 255 157 192 255 162 196 255 166 200 255 170 204 255 174 208 255 174 218 230 177 212 255 181 215 255 185 219 255 188 222 255 191 225 255 212 211 224 218 217 230 219 219 230 220 220 231 222 221 232 223 223 233 225 224 234 225 225 234 226 226 237 227 226 235 227 227 236 227 227 238 228 228 237 229 229 239 231 230 238 231 231 238 231 231 240 232 232 241 233 232 239 233 233 240 234 234 242 235 234 241 236 236 243 237 236 242 237 237 244 238 237 243 238 238 244 239 238 243 239 239 245 240 239 244 241 240 245 241 241 246 241 241 247 242 242 246 242 242 247 243 243 247 243 243 248 244 244 248 244 244 249 245 244 247 246 246 249 246 246 250 247 246 249 247 247 250 248 248 251 249 249 250 249 249 251 250 250 251 250 250 252 251 251 252 251 251 253 253 253 254 254 254 255 255 255 255 0 0 0]; mask:((Depth1Image new) width: 22; height: 22; photometric:(#blackIs0); bitsPerSample:(#[1]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@C????????????????????????????????????????????????????????????????????????????????@@@C') ; yourself); yourself]
cg@2759
   210
!
cg@2759
   211
cg@2759
   212
pickWindowIcon2
cg@2759
   213
    "This resource specification was automatically generated
cg@2759
   214
     by the ImageEditor of ST/X."
cg@2759
   215
cg@2759
   216
    "Do not manually edit this!! If it is corrupted,
cg@2759
   217
     the ImageEditor may not be able to read the specification."
cg@2759
   218
cg@2759
   219
    "
cg@2759
   220
     self pickWindowIcon2 inspect
cg@2759
   221
     ImageEditor openOnClass:self andSelector:#pickWindowIcon2
cg@2759
   222
     Icon flushCachedIcons
cg@2759
   223
    "
cg@2759
   224
cg@2759
   225
    <resource: #image>
cg@2759
   226
cg@2759
   227
    ^Icon
cg@2759
   228
        constantNamed:'Tools::ViewTreeInspectorApplication class pickWindowIcon2'
cg@2759
   229
        ifAbsentPut:[(Depth8Image new) width: 22; height: 23; photometric:(#palette); bitsPerSample:(#[8]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'
cg@2759
   230
@CH<O#,7MB0#HA8\F!!XUD!!DMC@,F@P@<[&U!!W5]MRTH:LRD]FQPPB $IA0H@QF)+XU=WR4Y@M",_F1\TD@(IBP E@D23,;N3,;N3,;N3,;N"'')*X%IJ[F@A^
cg@2759
   231
,;N3,;N3,0@@@@@@():Z&IRR&3@@W+N3,;N3@@B3,0B3)@@@&)"T$),0@E63,;N3@KN3@@@@@@B"'' BX%IJWK0A\,;N3@KN3,;N3@JR"'')*X@IRR&24@V+N3
cg@2759
   232
@KN3,;L@@@@@@I:Z&IP@$),*@E&3,0B3,;N3,:P@():Z&IRT@IJ[J@AX,0B3@KL@,;L@@@B^& BT@IP@&2X@U+L@,0B3@KL@)JJ^@I @%@BT@I,%@EV3@@@@
cg@2759
   233
@@@@@JR"'' @@@@@@@@B[I@AT,0B3@KL@)@B$()8@&@BZ@IP@&2H@T;L@,0B3@JR$@@@@%I @& BT@I,"@EJ3,0B3,:R$)I8@&IRX%I*X@IJ[H AQ,;L@,:R$
cg@2759
   234
)@@@@@@@&IRO#0BO RH@S;N3,0B$)JR"'' BX%I"T#0BO#7<"@D:-,;N$@JR$@@@@@@BR#0BO#8=>H AN+[N$)JH@@I"T@I"T@@BO#8>O_"H@JZ63)JJ^&) @
cg@2759
   235
@@@@@IJO#8>O#8@O@B&3,;N3,;N3,;N3,;N"'')*X%IJ[C0@)R$]EPS<=NS 5L28''H"H"H"H"H <b') ; colorMapFromArray:#[0 0 0 0 50 164 0 50 171 0 137 0 0 206 0 1 50 177 2 56 178 3 64 241 3 67 246 3 73 255 4 74 255 5 63 191 7 66 194 10 71 196 10 79 255 12 59 167 12 82 255 14 77 199 18 83 201 19 88 255 21 91 255 23 89 204 27 95 206 28 97 255 29 72 179 30 100 255 32 101 209 36 106 255 36 107 211 39 109 255 41 113 214 45 115 255 45 119 216 48 118 255 50 87 176 50 125 219 51 88 176 51 88 177 52 89 178 52 90 178 53 90 178 53 127 212 54 91 179 54 123 255 54 131 221 55 92 180 55 95 181 56 93 180 56 94 181 57 127 255 57 149 229 58 99 184 58 137 224 61 104 187 63 132 255 63 143 226 64 108 190 66 113 193 66 135 255 67 149 229 68 157 232 69 117 196 71 155 231 72 122 199 72 141 255 75 126 202 75 144 255 75 160 234 77 163 236 78 131 206 80 149 255 81 136 209 84 140 212 84 153 255 87 145 215 88 157 255 91 168 235 93 161 255 94 154 222 96 157 223 96 165 255 97 159 225 98 160 225 98 162 226 99 163 227 100 165 228 101 166 229 101 170 255 102 167 230 103 169 231 104 170 232 104 173 255 105 172 233 105 174 234 106 175 235 109 178 255 112 180 255 117 186 255 119 187 255 122 154 245 125 160 253 125 193 255 126 161 253 126 194 255 127 162 254 130 165 254 132 200 255 132 201 255 133 60 36 135 170 255 139 207 255 140 175 255 144 179 255 149 184 255 153 188 255 157 192 255 162 196 255 166 200 255 170 204 255 174 208 255 174 218 230 177 212 255 181 215 255 185 219 255 188 222 255 191 225 255 212 211 224 218 217 230 219 219 230 220 220 231 222 221 232 223 223 233 225 224 234 225 225 234 226 226 237 227 226 235 227 227 236 227 227 238 228 228 237 229 229 239 231 230 238 231 231 238 231 231 240 232 232 241 233 232 239 233 233 240 234 234 242 235 234 241 236 236 243 237 236 242 237 237 244 238 237 243 238 238 244 239 238 243 239 239 245 240 239 244 241 240 245 241 241 246 241 241 247 242 242 246 242 242 247 243 243 247 243 243 248 244 244 248 244 244 249 245 244 247 246 246 249 246 246 250 247 246 249 247 247 250 248 248 251 249 249 250 249 249 251 250 250 251 250 250 252 251 251 252 251 251 253 253 253 254 254 254 255 255 255 255]; mask:((Depth1Image new) width: 22; height: 23; photometric:(#blackIs0); bitsPerSample:(#[1]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<_??<') ; yourself); yourself]
cg@2744
   236
! !
cg@2744
   237
cg@2744
   238
!ViewTreeInspectorApplication class methodsFor:'interface specs'!
ca@2177
   239
ca@2177
   240
windowSpec
ca@2177
   241
    "This resource specification was automatically generated
ca@2177
   242
     by the UIPainter of ST/X."
ca@2177
   243
ca@2177
   244
    "Do not manually edit this!! If it is corrupted,
ca@2177
   245
     the UIPainter may not be able to read the specification."
ca@2177
   246
ca@2177
   247
    "
cg@2757
   248
     UIPainter new openOnClass:Tools::ViewTreeInspectorApplication andSelector:#windowSpec
cg@2757
   249
     Tools::ViewTreeInspectorApplication new openInterface:#windowSpec
cg@2757
   250
     Tools::ViewTreeInspectorApplication open
ca@2177
   251
    "
ca@2177
   252
ca@2177
   253
    <resource: #canvas>
ca@2177
   254
ca@2177
   255
    ^ 
ca@2177
   256
     #(FullSpec
ca@2177
   257
        name: windowSpec
ca@2177
   258
        window: 
ca@2177
   259
       (WindowSpec
cg@2744
   260
          label: 'View Tree Inspector'
cg@2757
   261
          name: 'View Tree Inspector'
ca@2177
   262
          min: (Point 10 10)
ca@2177
   263
          max: (Point 1024 9999)
ca@2451
   264
          bounds: (Rectangle 0 0 381 654)
ca@2177
   265
          menu: menu
ca@2177
   266
        )
ca@2177
   267
        component: 
ca@2177
   268
       (SpecCollection
ca@2177
   269
          collection: (
ca@2177
   270
           (MenuPanelSpec
ca@2177
   271
              name: 'toolbarMenu'
cg@2757
   272
              layout: (LayoutFrame 0 0.0 0 0 0 1.0 40 0)
ca@2177
   273
              menu: toolbarMenu
ca@2177
   274
              textDefault: true
ca@2177
   275
            )
cg@2770
   276
       (VariableVerticalPanelSpec
cg@2770
   277
              name: 'VariableVerticalPanel1'
cg@2757
   278
              layout: (LayoutFrame 0 0.0 40 0.0 0 1.0 0 1.0)
cg@2770
   279
              component: 
cg@2770
   280
             (SpecCollection
cg@2770
   281
                collection: (
cg@2770
   282
                 (HierarchicalListViewSpec
cg@2770
   283
                    name: 'List'
cg@2770
   284
                    level: 1
cg@2770
   285
                    model: model
cg@2770
   286
                    menu: middleButtonMenu
cg@2770
   287
                    hasHorizontalScrollBar: true
cg@2770
   288
                    hasVerticalScrollBar: true
cg@2770
   289
                    miniScrollerHorizontal: true
cg@2770
   290
                    miniScrollerVertical: false
cg@2770
   291
                    listModel: listOfItems
cg@2770
   292
                    multipleSelectOk: true
cg@2770
   293
                    useIndex: false
cg@2770
   294
                    highlightMode: label
cg@2770
   295
                    showLeftIndicators: false
cg@2770
   296
                    indicatorSelector: indicatorClicked:
cg@2770
   297
                    useDefaultIcons: false
cg@2770
   298
                    postBuildCallback: postBuildTree:
cg@2770
   299
                  )
cg@2770
   300
                 (ViewSpec
cg@2770
   301
                    name: 'Box1'
cg@2770
   302
                    viewClassName: 'InspectorView'
cg@2770
   303
                    postBuildCallback: postBuildInspectorView:
cg@2770
   304
                  )
cg@2770
   305
                 )
cg@2770
   306
               
cg@2770
   307
              )
cg@2770
   308
              handles: (Any 0.5 1.0)
ca@2177
   309
            )
ca@2177
   310
           )
ca@2177
   311
         
ca@2177
   312
        )
ca@2177
   313
      )
ca@2177
   314
! !
ca@2177
   315
cg@2744
   316
!ViewTreeInspectorApplication class methodsFor:'menu specs'!
ca@2177
   317
ca@2177
   318
menu
ca@2177
   319
    "This resource specification was automatically generated
ca@2177
   320
     by the MenuEditor of ST/X."
ca@2177
   321
ca@2177
   322
    "Do not manually edit this!! If it is corrupted,
ca@2177
   323
     the MenuEditor may not be able to read the specification."
ca@2177
   324
cg@2978
   325
ca@2177
   326
    "
cg@2978
   327
     MenuEditor new openOnClass:Tools::ViewTreeInspectorApplication andSelector:#menu
cg@2978
   328
     (Menu new fromLiteralArrayEncoding:(Tools::ViewTreeInspectorApplication menu)) startUp
ca@2177
   329
    "
ca@2177
   330
ca@2177
   331
    <resource: #menu>
ca@2177
   332
ca@2177
   333
    ^ 
ca@2177
   334
     #(Menu
ca@2177
   335
        (
ca@2177
   336
         (MenuItem
ca@2177
   337
            label: 'File'
ca@2177
   338
            submenu: 
ca@2177
   339
           (Menu
ca@2177
   340
              (
ca@2177
   341
               (MenuItem
ca@2177
   342
                  label: 'Pick a View'
cg@2762
   343
                  itemValue: doPickView
ca@2177
   344
                )
ca@2177
   345
               (MenuItem
ca@2455
   346
                  enabled: hasTargetWidgetChannel
ca@2177
   347
                  label: 'Release Picked View'
ca@2177
   348
                  itemValue: doUnpick
ca@2177
   349
                )
ca@2177
   350
               (MenuItem
ca@2177
   351
                  label: '-'
ca@2177
   352
                )
ca@2177
   353
               (MenuItem
cg@2744
   354
                  label: 'Settings'
cg@2744
   355
                  submenu: 
cg@2744
   356
                 (Menu
cg@2744
   357
                    (
cg@2744
   358
                     (MenuItem
cg@2744
   359
                        label: 'Test Mode'
cg@2744
   360
                        hideMenuOnActivated: false
cg@2744
   361
                        indication: testModeChannel
cg@2744
   362
                      )
cg@2744
   363
                     (MenuItem
cg@2744
   364
                        enabled: testModeChannel
cg@2744
   365
                        label: 'Follow Focus'
cg@2744
   366
                        hideMenuOnActivated: false
cg@2744
   367
                        indication: followFocusChannel
cg@2744
   368
                      )
cg@2744
   369
                     (MenuItem
cg@2744
   370
                        label: '-'
cg@2744
   371
                      )
cg@2744
   372
                     (MenuItem
cg@2744
   373
                        label: 'Select on Click'
cg@2744
   374
                        hideMenuOnActivated: false
cg@2744
   375
                        indication: selectOnClickHolder
cg@2744
   376
                      )
cg@2744
   377
                     (MenuItem
cg@2744
   378
                        label: '-'
cg@2744
   379
                      )
cg@2744
   380
                     (MenuItem
cg@2744
   381
                        label: 'Show Name of Widgets'
cg@2744
   382
                        hideMenuOnActivated: false
cg@2744
   383
                        indication: showNamesHolder
cg@2744
   384
                      )
cg@2744
   385
                     )
cg@2744
   386
                    nil
cg@2744
   387
                    nil
cg@2744
   388
                  )
cg@2744
   389
                )
cg@2744
   390
               (MenuItem
cg@2744
   391
                  label: '-'
cg@2744
   392
                )
cg@2744
   393
               (MenuItem
ca@2177
   394
                  label: 'Exit'
ca@2177
   395
                  itemValue: closeRequest
ca@2177
   396
                )
ca@2177
   397
               )
ca@2177
   398
              nil
ca@2177
   399
              nil
ca@2177
   400
            )
ca@2177
   401
          )
ca@2177
   402
         (MenuItem
cg@2744
   403
            enabled: hasSingleSelectionHolder
cg@2744
   404
            label: 'Selection'
cg@2744
   405
            submenuChannel: middleButtonMenu
cg@2744
   406
          )
cg@2744
   407
         (MenuItem
cg@2744
   408
            label: 'Application'
ca@2454
   409
            submenu: 
ca@2454
   410
           (Menu
ca@2454
   411
              (
ca@2454
   412
               (MenuItem
cg@2978
   413
                  label: 'Redraw'
cg@2978
   414
                  itemValue: doRedraw
cg@2978
   415
                )
cg@2978
   416
               (MenuItem
cg@2978
   417
                  label: '-'
cg@2978
   418
                )
cg@2978
   419
               (MenuItem
cg@2744
   420
                  enabled: hasSingleSelectionHolder
cg@2744
   421
                  label: 'Browse'
cg@2744
   422
                  itemValue: doBrowse:
cg@2744
   423
                  argument: application
ca@2454
   424
                )
ca@2454
   425
               (MenuItem
cg@2744
   426
                  enabled: hasSingleSelectionHolder
cg@2744
   427
                  label: 'Inspect'
cg@2744
   428
                  itemValue: doInspect:
cg@2744
   429
                  argument: application
ca@2454
   430
                )
ca@2454
   431
               (MenuItem
ca@2454
   432
                  label: '-'
ca@2454
   433
                )
ca@2454
   434
               (MenuItem
cg@2744
   435
                  enabled: hasTargetWidgetChannel
cg@2744
   436
                  label: 'All Applications'
cg@2744
   437
                  submenuChannel: submenuApplications:
cg@2744
   438
                )
cg@2744
   439
               )
cg@2744
   440
              nil
cg@2744
   441
              nil
cg@2744
   442
            )
cg@2744
   443
          )
cg@2744
   444
         (MenuItem
cg@2744
   445
            label: 'Widget'
cg@2744
   446
            submenu: 
cg@2744
   447
           (Menu
cg@2744
   448
              (
cg@2744
   449
               (MenuItem
cg@2744
   450
                  enabled: hasSingleSelectionHolder
cg@2744
   451
                  label: 'Browse'
cg@2744
   452
                  itemValue: doBrowse:
cg@2744
   453
                  argument: view
cg@2744
   454
                )
cg@2744
   455
               (MenuItem
cg@2744
   456
                  enabled: hasSingleSelectionHolder
cg@2744
   457
                  label: 'Inspect'
cg@2744
   458
                  itemValue: doInspect:
cg@2744
   459
                  argument: view
ca@2454
   460
                )
ca@2454
   461
               (MenuItem
ca@2454
   462
                  label: '-'
ca@2454
   463
                )
ca@2454
   464
               (MenuItem
cg@2744
   465
                  enabled: hasTargetWidgetChannel
cg@2744
   466
                  label: 'All Components'
cg@2744
   467
                  startGroup: right
cg@2744
   468
                  submenuChannel: submenuComponents:
ca@2454
   469
                )
ca@2454
   470
               )
ca@2454
   471
              nil
ca@2454
   472
              nil
ca@2454
   473
            )
ca@2454
   474
          )
ca@2454
   475
         (MenuItem
cg@2744
   476
            label: 'Help'
cg@2744
   477
            startGroup: conditionalRight
cg@2744
   478
            submenu: 
cg@2744
   479
           (Menu
cg@2744
   480
              (
cg@2744
   481
               (MenuItem
cg@2744
   482
                  label: 'Documentation'
cg@2744
   483
                  itemValue: openDocumentation
cg@2744
   484
                )
cg@2744
   485
               (MenuItem
cg@2744
   486
                  label: '-'
cg@2744
   487
                )
cg@2744
   488
               (MenuItem
cg@2744
   489
                  label: 'About this Application...'
cg@2744
   490
                  itemValue: openAboutThisApplication
cg@2744
   491
                )
cg@2744
   492
               )
cg@2744
   493
              nil
cg@2744
   494
              nil
cg@2744
   495
            )
ca@2177
   496
          )
ca@2177
   497
         )
ca@2177
   498
        nil
ca@2177
   499
        nil
ca@2177
   500
      )
ca@2177
   501
!
ca@2177
   502
ca@2177
   503
middleButtonMenu
ca@2177
   504
    "This resource specification was automatically generated
ca@2177
   505
     by the MenuEditor of ST/X."
ca@2177
   506
ca@2177
   507
    "Do not manually edit this!! If it is corrupted,
ca@2177
   508
     the MenuEditor may not be able to read the specification."
ca@2177
   509
ca@2177
   510
    "
ca@2177
   511
     MenuEditor new openOnClass:ViewTreeApplication andSelector:#middleButtonMenu
ca@2177
   512
     (Menu new fromLiteralArrayEncoding:(ViewTreeApplication middleButtonMenu)) startUp
ca@2177
   513
    "
ca@2177
   514
ca@2177
   515
    <resource: #menu>
ca@2177
   516
ca@2177
   517
    ^ 
ca@2177
   518
     #(Menu
ca@2177
   519
        (
ca@2177
   520
         (MenuItem
ca@2177
   521
            label: 'Geometry'
ca@2177
   522
            translateLabel: true
ca@2177
   523
            submenuChannel: submenuGeometry:
ca@2177
   524
            keepLinkedMenu: true
ca@2177
   525
          )
ca@2177
   526
         (MenuItem
ca@2177
   527
            label: 'Interface'
ca@2177
   528
            translateLabel: true
ca@2177
   529
            submenuChannel: submenuInterface:
ca@2177
   530
            keepLinkedMenu: true
ca@2177
   531
          )
ca@2177
   532
         (MenuItem
ca@2177
   533
            label: 'Visibility'
ca@2177
   534
            translateLabel: true
ca@2177
   535
            submenuChannel: submenuVisibility:
ca@2177
   536
            keepLinkedMenu: true
ca@2177
   537
          )
ca@2177
   538
         (MenuItem
ca@2177
   539
            label: '-'
ca@2177
   540
          )
ca@2177
   541
         (MenuItem
ca@2177
   542
            label: 'Browse View Class'
ca@2177
   543
            itemValue: doBrowse:
ca@2177
   544
            translateLabel: true
ca@2177
   545
            argument: view
ca@2177
   546
          )
ca@2177
   547
         (MenuItem
ca@2177
   548
            label: 'Browse Model Class'
ca@2177
   549
            itemValue: doBrowse:
ca@2177
   550
            translateLabel: true
ca@2177
   551
            isVisible: hasModel
ca@2177
   552
            argument: model
ca@2177
   553
          )
ca@2177
   554
         (MenuItem
ca@2177
   555
            label: 'Browse Application Class'
ca@2177
   556
            itemValue: doBrowse:
ca@2177
   557
            translateLabel: true
ca@2177
   558
            isVisible: hasApplication
ca@2177
   559
            argument: application
ca@2177
   560
          )
ca@2177
   561
         (MenuItem
ca@2177
   562
            label: 'Browse Controller Class'
ca@2177
   563
            itemValue: doBrowse:
ca@2177
   564
            translateLabel: true
ca@2177
   565
            isVisible: hasController
ca@2177
   566
            argument: controller
ca@2177
   567
          )
ca@2177
   568
         (MenuItem
ca@2177
   569
            label: '-'
ca@2177
   570
          )
ca@2177
   571
         (MenuItem
ca@2177
   572
            label: 'Inspect View'
ca@2177
   573
            itemValue: doInspect:
ca@2177
   574
            translateLabel: true
ca@2177
   575
            argument: view
ca@2177
   576
          )
ca@2177
   577
         (MenuItem
ca@2177
   578
            label: 'Inspect Window Group'
ca@2177
   579
            itemValue: doInspect:
ca@2177
   580
            translateLabel: true
ca@2177
   581
            argument: group
ca@2177
   582
          )
ca@2177
   583
         (MenuItem
ca@2177
   584
            label: 'Inspect Model'
ca@2177
   585
            itemValue: doInspect:
ca@2177
   586
            translateLabel: true
ca@2177
   587
            isVisible: hasModel
ca@2177
   588
            argument: model
ca@2177
   589
          )
ca@2177
   590
         (MenuItem
ca@2177
   591
            label: 'Inspect Application'
ca@2177
   592
            itemValue: doInspect:
ca@2177
   593
            translateLabel: true
ca@2177
   594
            isVisible: hasApplication
ca@2177
   595
            argument: application
ca@2177
   596
          )
ca@2177
   597
         (MenuItem
ca@2177
   598
            label: 'Inspect Controller'
ca@2177
   599
            itemValue: doInspect:
ca@2177
   600
            translateLabel: true
ca@2177
   601
            isVisible: hasController
ca@2177
   602
            argument: controller
ca@2177
   603
          )
ca@2177
   604
         (MenuItem
ca@2177
   605
            label: '-'
ca@2177
   606
          )
ca@2177
   607
         (MenuItem
ca@2177
   608
            label: 'Flash'
ca@2177
   609
            itemValue: doFlash
ca@2177
   610
            translateLabel: true
ca@2177
   611
          )
ca@2177
   612
         (MenuItem
ca@2177
   613
            label: '-'
ca@2177
   614
          )
ca@2177
   615
         (MenuItem
ca@2177
   616
            label: 'Destroy'
ca@2177
   617
            itemValue: doDestroy
ca@2177
   618
            translateLabel: true
ca@2177
   619
          )
ca@2177
   620
         (MenuItem
ca@2177
   621
            label: '-'
ca@2177
   622
          )
ca@2177
   623
         (MenuItem
ca@2177
   624
            label: 'Instance Variables'
ca@2177
   625
            translateLabel: true
ca@2177
   626
            submenuChannel: submenuInspector:
ca@2177
   627
            keepLinkedMenu: true
ca@2177
   628
          )
ca@2177
   629
         (MenuItem
ca@2177
   630
            label: '='
ca@2177
   631
          )
ca@2177
   632
         (MenuItem
ca@2177
   633
            label: ''
ca@2177
   634
          )
ca@2177
   635
         (MenuItem
ca@2177
   636
            enabled: selectedComponentHasChildren
ca@2177
   637
            label: 'Applications'
ca@2177
   638
            nameKey: single
ca@2177
   639
            translateLabel: true
ca@2177
   640
            submenuChannel: submenuApplications:
ca@2177
   641
            keepLinkedMenu: true
ca@2177
   642
          )
ca@2177
   643
         (MenuItem
ca@2177
   644
            enabled: selectedComponentHasChildren
ca@2177
   645
            label: 'Components'
ca@2177
   646
            nameKey: single
ca@2177
   647
            translateLabel: true
ca@2177
   648
            submenuChannel: submenuComponents:
ca@2177
   649
            keepLinkedMenu: true
ca@2177
   650
          )
ca@2177
   651
         )
ca@2177
   652
        nil
ca@2177
   653
        nil
ca@2177
   654
      )
ca@2177
   655
!
ca@2177
   656
ca@2177
   657
toolbarMenu
ca@2177
   658
    "This resource specification was automatically generated
ca@2177
   659
     by the MenuEditor of ST/X."
ca@2177
   660
ca@2177
   661
    "Do not manually edit this!! If it is corrupted,
ca@2177
   662
     the MenuEditor may not be able to read the specification."
ca@2177
   663
cg@2978
   664
ca@2177
   665
    "
cg@2757
   666
     MenuEditor new openOnClass:Tools::ViewTreeInspectorApplication andSelector:#toolbarMenu
cg@2757
   667
     (Menu new fromLiteralArrayEncoding:(Tools::ViewTreeInspectorApplication toolbarMenu)) startUp
ca@2177
   668
    "
ca@2177
   669
ca@2177
   670
    <resource: #menu>
ca@2177
   671
ca@2177
   672
    ^ 
ca@2177
   673
     #(Menu
ca@2177
   674
        (
ca@2177
   675
         (MenuItem
cg@2978
   676
            enabled: hasTargetWidgetChannel
cg@2978
   677
            label: 'Redraw'
cg@2978
   678
            itemValue: doRedraw
cg@2978
   679
            isButton: true
cg@2978
   680
            labelImage: (ResourceRetriever ToolbarIconLibrary reloadIcon)
cg@2978
   681
          )
cg@2978
   682
         (MenuItem
cg@2978
   683
            label: '-'
cg@2978
   684
          )
cg@2978
   685
         (MenuItem
cg@2978
   686
            label: 'Pick a View and Catch Events'
cg@2762
   687
            itemValue: doPickView
cg@2744
   688
            translateLabel: false
cg@2744
   689
            isButton: true
cg@2744
   690
            hideMenuOnActivated: false
cg@2759
   691
            labelImage: (ResourceRetriever #'Tools::ViewTreeInspectorApplication' pickWindowIcon2)
cg@2744
   692
          )
cg@2744
   693
         (MenuItem
cg@2757
   694
            enabled: hasTargetWidgetChannel
cg@2978
   695
            label: 'Release Picked View and Uncatch Events'
cg@2978
   696
            itemValue: doUncatchEvents
cg@2757
   697
            isButton: true
cg@2757
   698
            labelImage: (ResourceRetriever ToolbarIconLibrary undoIcon)
cg@2757
   699
          )
cg@2757
   700
         (MenuItem
cg@2757
   701
            label: '-'
cg@2757
   702
          )
cg@2757
   703
         (MenuItem
ca@2454
   704
            enabled: hasSingleSelectionHolder
cg@2744
   705
            label: 'Browse Application'
ca@2454
   706
            itemValue: doBrowse:
ca@2454
   707
            translateLabel: false
cg@2744
   708
            isButton: true
cg@2744
   709
            hideMenuOnActivated: false
ca@2454
   710
            labelImage: (ResourceRetriever ToolbarIconLibrary systemBrowser24x24Icon2)
ca@2454
   711
            argument: application
ca@2177
   712
          )
ca@2177
   713
         (MenuItem
ca@2454
   714
            enabled: hasSingleSelectionHolder
cg@2744
   715
            label: 'Inspect Application'
ca@2454
   716
            itemValue: doInspect:
ca@2454
   717
            translateLabel: false
cg@2744
   718
            isButton: true
cg@2744
   719
            hideMenuOnActivated: false
cg@2744
   720
            labelImage: (ResourceRetriever ToolbarIconLibrary inspect22x24Icon)
ca@2454
   721
            argument: application
ca@2177
   722
          )
ca@2177
   723
         )
ca@2177
   724
        nil
ca@2177
   725
        nil
ca@2177
   726
      )
ca@2177
   727
! !
ca@2177
   728
cg@2747
   729
!ViewTreeInspectorApplication class methodsFor:'startup'!
cg@2747
   730
cg@2747
   731
openInPickMode
cg@2747
   732
    |app|
cg@2747
   733
cg@2747
   734
    app := self new.
cg@2747
   735
    app open.
cg@2762
   736
    app doPickView.
cg@2747
   737
! !
cg@2747
   738
cg@2744
   739
!ViewTreeInspectorApplication methodsFor:'actions'!
ca@2177
   740
ca@2177
   741
indicatorClicked:anIndex
ca@2177
   742
    |item sensor|
ca@2177
   743
ca@2177
   744
    item := model listOfItems at:anIndex ifAbsent:nil.
ca@2177
   745
ca@2177
   746
    item notNil ifTrue:[
ca@2177
   747
        (     (sensor := self window sensor) notNil
ca@2177
   748
         and:[(sensor ctrlDown or:[sensor shiftDown])]
ca@2177
   749
        ) ifTrue:[
ca@2177
   750
            item recursiveToggleExpand
ca@2177
   751
        ] ifFalse:[
ca@2177
   752
            item toggleExpand
ca@2177
   753
        ]
ca@2177
   754
    ].
ca@2177
   755
! !
ca@2177
   756
cg@2744
   757
!ViewTreeInspectorApplication methodsFor:'aspects'!
ca@2177
   758
ca@2177
   759
followFocusChannel
ca@2455
   760
    "boolean holder, which indicates whether selection changed dependend on the focus view"
ca@2455
   761
ca@2177
   762
    ^ followFocusChannel
ca@2177
   763
!
ca@2177
   764
ca@2177
   765
hasSingleSelectionHolder
ca@2455
   766
    "boolean holder, true if one item is selected"
ca@2455
   767
ca@2177
   768
    ^ hasSingleSelectionHolder
ca@2177
   769
!
ca@2177
   770
ca@2455
   771
hasTargetWidgetChannel
ca@2455
   772
    "answer the channel which is set to true if a target widget exists"
ca@2455
   773
ca@2455
   774
    ^ model hasTargetWidgetChannel
ca@2455
   775
!
ca@2455
   776
ca@2177
   777
listOfItems
ca@2455
   778
    "returns the hierarchical list of items"
ca@2455
   779
ca@2177
   780
    ^ model listOfItems
ca@2177
   781
!
ca@2177
   782
ca@2177
   783
model
ca@2455
   784
    "returns my selection model, a ViewTreeModel"
ca@2455
   785
ca@2177
   786
    ^ model
ca@2177
   787
!
ca@2177
   788
ca@2177
   789
selectOnClickHolder
ca@2455
   790
    "boolean holder, which indicates whether the selection will change on click"
ca@2455
   791
ca@2177
   792
    ^ model selectOnClickHolder
ca@2177
   793
!
ca@2177
   794
ca@2451
   795
showNamesHolder
ca@2451
   796
    "boolean holder, which indicates whether application names or widget names
ca@2455
   797
     as additional text are shown for the items"
ca@2455
   798
ca@2451
   799
    ^ showNamesHolder
ca@2451
   800
!
ca@2451
   801
ca@2177
   802
testModeChannel
ca@2455
   803
    "answer a boolean channel which describes the behaviour how to process
ca@2455
   804
     events on the target view.
ca@2455
   805
ca@2455
   806
     false: all input events are eaten and the selection is shown on the target view.
ca@2455
   807
     true:  no  input events are eaten and no  selection is shown on the target view."
ca@2455
   808
ca@2455
   809
    ^ model testModeChannel
ca@2177
   810
! !
ca@2177
   811
cg@2744
   812
!ViewTreeInspectorApplication methodsFor:'change & update'!
ca@2177
   813
ca@2177
   814
selectionChanged
ca@2177
   815
    |info view item|
ca@2177
   816
ca@2177
   817
    item := model selectedItem.
ca@2177
   818
ca@2177
   819
    item notNil ifTrue:[ |state|
ca@2177
   820
        view := item widget.
ca@2177
   821
ca@2177
   822
        view id isNil ifTrue:[
ca@2177
   823
            state := 'no ID'.
ca@2177
   824
        ] ifFalse:[
ca@2177
   825
            view shown ifTrue:[
ca@2177
   826
                state := 'visible'.
ca@2177
   827
            ] ifFalse:[
ca@2177
   828
                state := 'invisible'
ca@2177
   829
            ].
ca@2177
   830
        ].
ca@2177
   831
        info := '%1 [%2] - %3' bindWith:(view class name)
ca@2177
   832
                                   with:(view name ? '') with:state allBold.
ca@2177
   833
ca@2177
   834
    ] ifFalse:[
ca@2177
   835
        info := ''
ca@2177
   836
    ].
ca@2177
   837
    hasSingleSelectionHolder value:(view notNil).
cg@2770
   838
    inspectorView inspect:view.
ca@2177
   839
!
ca@2177
   840
ca@2177
   841
update:something with:someArgument from:aModel
ca@2454
   842
    |oldSelection|
ca@2454
   843
ca@2451
   844
    aModel == showNamesHolder ifTrue:[
ca@2455
   845
        oldSelection := model selectedItem.
ca@2454
   846
        model selectedItem:nil.
ca@2451
   847
        self listOfItems showWidgetNames:(aModel value).
ca@2454
   848
        model selectedItem:oldSelection.
ca@2451
   849
        ^ self
ca@2451
   850
    ].
ca@2458
   851
ca@2458
   852
    aModel == model ifTrue:[
ca@2458
   853
        self selectionChanged.
ca@2458
   854
        ^ self
ca@2458
   855
    ].
ca@2458
   856
ca@2177
   857
    super update:something with:someArgument from:aModel.
ca@2177
   858
! !
ca@2177
   859
cg@2744
   860
!ViewTreeInspectorApplication methodsFor:'event processing'!
ca@2177
   861
ca@2177
   862
processButtonMotionEvent:ev
ca@2455
   863
    |click rootView|
ca@2177
   864
ca@2455
   865
    motionAction isNil ifTrue:[^ self].
ca@2455
   866
ca@2455
   867
    (rootView := model rootView) isNil ifTrue:[
ca@2455
   868
        clickedItem := motionAction := nil.
ca@2455
   869
        ^ self
ca@2455
   870
    ].
ca@2455
   871
ca@2455
   872
    click := rootView device
ca@2455
   873
            translatePoint:((ev x)@ (ev y))
ca@2455
   874
            fromView:(ev view)
ca@2455
   875
            toView:rootView.
ca@2455
   876
ca@2455
   877
    click = clickedPoint ifFalse:[
ca@2455
   878
        (clickedItem isNil or:[(click dist:clickedPoint) > 5.0]) ifTrue:[
ca@2455
   879
            motionAction value:click
ca@2177
   880
        ]
ca@2177
   881
    ].
ca@2177
   882
!
ca@2177
   883
ca@2177
   884
processButtonPressEvent:ev
ca@2455
   885
    |rootView sensor lastRectangle|
ca@2455
   886
ca@2455
   887
    rootView    := model rootView.
ca@2177
   888
    sensor      := model rootView sensor.
ca@2177
   889
    clickedItem := model listOfItems detectItemRespondsToView:(ev view).
ca@2177
   890
ca@2177
   891
    (sensor ctrlDown or:[sensor shiftDown]) ifTrue:[
ca@2177
   892
        clickedItem notNil ifTrue:[
ca@2177
   893
            self selectOnClickHolder value ifTrue:[
ca@2177
   894
                model toggleSelectItem:clickedItem
ca@2177
   895
            ].
ca@2177
   896
        ].
ca@2177
   897
        clickedItem := motionAction := nil.
ca@2455
   898
        ^ self
ca@2455
   899
    ].
ca@2177
   900
ca@2455
   901
    clickedPoint := rootView device translatePoint:((ev x)@ (ev y))  fromView:(ev view) toView:rootView.
ca@2455
   902
    lastRectangle := nil.
ca@2177
   903
ca@2455
   904
    motionAction :=[:p|
ca@2455
   905
        rootView    := model rootView device rootView.
ca@2455
   906
        rootView    := model rootView.
ca@2455
   907
        clickedItem := nil.
ca@2177
   908
ca@2455
   909
        rootView xoring:[
ca@2455
   910
            lastRectangle notNil ifTrue:[ rootView displayRectangle:lastRectangle ]
ca@2455
   911
                                ifFalse:[ rootView clippedByChildren:false ].
ca@2455
   912
ca@2455
   913
            p isNil ifTrue:[
ca@2455
   914
                rootView clippedByChildren:true.
ca@2455
   915
                motionAction := nil.
ca@2455
   916
            ] ifFalse:[
ca@2455
   917
                lastRectangle := Rectangle origin:(clickedPoint min:p) corner:(clickedPoint max:p).
ca@2455
   918
                rootView displayRectangle:lastRectangle.
ca@2177
   919
            ].
ca@2455
   920
            rootView flush.
ca@2455
   921
        ].
ca@2455
   922
        lastRectangle
ca@2455
   923
    ].
ca@2177
   924
!
ca@2177
   925
ca@2177
   926
processButtonReleaseEvent:anEvent
ca@2177
   927
    |rootView rectangle newItems widget origin|
ca@2177
   928
ca@2455
   929
    (rootView := model rootView) isNil ifTrue:[
ca@2455
   930
        clickedItem := motionAction := nil.
ca@2455
   931
        ^ self
ca@2455
   932
    ].
ca@2177
   933
    motionAction isNil ifTrue:[ ^ self ].
ca@2177
   934
    clickedItem notNil ifTrue:[ ^ model selectItem:clickedItem ].
ca@2177
   935
ca@2455
   936
    rectangle := motionAction value:nil.
ca@2455
   937
    rectangle isNil ifTrue:[^ self].
ca@2177
   938
ca@2455
   939
    newItems := OrderedCollection new.
ca@2177
   940
ca@2455
   941
    model rootItem recursiveDo:[:anItem|
ca@2455
   942
        widget := anItem widget.
ca@2455
   943
        origin := widget originRelativeTo:rootView.
ca@2455
   944
ca@2455
   945
        (rectangle containsRect:(Rectangle origin:origin extent:(widget extent))) ifTrue:[
ca@2455
   946
            newItems add:anItem.
ca@2455
   947
        ]
ca@2177
   948
    ].
ca@2455
   949
    model value:newItems.
ca@2177
   950
!
ca@2177
   951
ca@2177
   952
processEvent:anEvent
ca@2177
   953
    |button menu|
ca@2177
   954
cg@2758
   955
    anEvent isKeyPressEvent ifTrue:[ self processKeyPressEvent:anEvent. ^ self  ].
ca@2177
   956
    anEvent isButtonEvent  ifFalse:[ ^ self ].
ca@2177
   957
ca@2177
   958
    button := anEvent button.
ca@2177
   959
ca@2177
   960
    (button == 2 or:[button == #menu]) ifTrue:[
ca@2177
   961
        motionAction isNil ifTrue:[
ca@2177
   962
            anEvent isButtonPressEvent ifTrue:[
ca@2177
   963
                self selectOnClickHolder value ifTrue:[
ca@2177
   964
                    menu := self middleButtonMenu value.
ca@2177
   965
                    menu notNil ifTrue:[
cg@2758
   966
                        menu := MenuPanel 
cg@2758
   967
                                    menu:(Menu new fromLiteralArrayEncoding:menu)
cg@2758
   968
                                    receiver:self.
ca@2177
   969
                        menu startUp.
ca@2177
   970
                    ]
ca@2177
   971
                ].
ca@2177
   972
            ].
ca@2177
   973
            clickedItem := nil.
ca@2177
   974
        ].
ca@2177
   975
        ^ self
ca@2177
   976
    ].
ca@2177
   977
cg@2758
   978
    anEvent isButtonPressEvent  ifTrue:[ self processButtonPressEvent:anEvent. ^ self ].
cg@2758
   979
    anEvent isButtonMotionEvent ifTrue:[ self processButtonMotionEvent:anEvent. ^ self ].
ca@2177
   980
ca@2177
   981
    anEvent isButtonReleaseEvent ifTrue:[
ca@2177
   982
        self selectOnClickHolder value ifTrue:[
ca@2177
   983
            self processButtonReleaseEvent:anEvent
ca@2177
   984
        ].
ca@2177
   985
    ].
ca@2177
   986
    clickedItem := motionAction := nil.
ca@2177
   987
ca@2177
   988
    anEvent type == #'buttonMultiPress:x:y:' ifTrue:[
ca@2177
   989
        self selectOnClickHolder value ifTrue:[
ca@2177
   990
            self doInspect:#view.
ca@2177
   991
        ].
ca@2177
   992
    ].
ca@2177
   993
!
ca@2177
   994
ca@2177
   995
processKeyPressEvent:anEvent
ca@2177
   996
    |item prnt idx key max next|
ca@2177
   997
ca@2177
   998
    key := anEvent key.
ca@2177
   999
    key isSymbol ifFalse:[^ self].
ca@2177
  1000
ca@2177
  1001
    key == #Delete    ifTrue:[ ^ self doDestroy ].
ca@2177
  1002
    key == #InspectIt ifTrue:[ ^ self doInspect:#view ].
ca@2177
  1003
ca@2177
  1004
    (   key == #CursorUp
ca@2177
  1005
    or:[key == #CursorDown
ca@2177
  1006
    or:[key == #CursorLeft
ca@2177
  1007
    or:[key == #CursorRight]]]
ca@2177
  1008
    ) ifFalse:[
ca@2177
  1009
        ^ self
ca@2177
  1010
    ].
ca@2177
  1011
    item := model selectedItem.
ca@2177
  1012
ca@2177
  1013
    item isNil ifTrue:[
ca@2177
  1014
        ^ model selectedItem:(model first ? model rootItem)
ca@2177
  1015
    ].
ca@2177
  1016
ca@2177
  1017
    prnt := item parent.
ca@2177
  1018
    prnt isNil ifTrue:[
ca@2177
  1019
        "/ is the root item
ca@2177
  1020
        (key == #CursorUp or:[key == #CursorLeft]) ifTrue:[item := model listOfItems last]
ca@2177
  1021
                                                  ifFalse:[item := item at:1 ifAbsent:item].
ca@2177
  1022
cg@2758
  1023
        ^ model selectedItem:item
ca@2177
  1024
    ].
ca@2177
  1025
    key == #CursorLeft ifTrue:[ ^ model selectedItem:prnt ].
ca@2177
  1026
ca@2177
  1027
    key == #CursorRight ifTrue:[
ca@2177
  1028
        next := item at:1 ifAbsent:nil.
ca@2177
  1029
        next notNil ifTrue:[ model selectedItem:next ].
cg@2758
  1030
        ^ self
ca@2177
  1031
    ].
ca@2177
  1032
ca@2177
  1033
    max := prnt size.
ca@2177
  1034
ca@2177
  1035
    key == #CursorUp ifTrue:[
ca@2177
  1036
        idx := prnt identityIndexOf:item.
ca@2177
  1037
        idx == 1 ifTrue:[idx := max + 1].
ca@2177
  1038
        model selectedItem:(prnt at:idx - 1).
cg@2758
  1039
        ^ self.
ca@2177
  1040
    ].
ca@2177
  1041
ca@2177
  1042
    key == #CursorDown ifTrue:[
ca@2177
  1043
        idx := prnt identityIndexOf:item.
ca@2177
  1044
        idx == max ifTrue:[idx := 0].
ca@2177
  1045
        model selectedItem:(prnt at:idx + 1).
cg@2758
  1046
        ^ self.
ca@2177
  1047
    ].
ca@2177
  1048
!
ca@2177
  1049
ca@2177
  1050
processMappedView:aView
ca@2177
  1051
    |parent anchor|
ca@2177
  1052
ca@2177
  1053
    parent := self listOfItems detectItemRespondsToView:aView.
ca@2177
  1054
    parent isNil ifTrue:[ ^ self ].
ca@2177
  1055
ca@2177
  1056
    NotFoundSignal handle:[:ex|
ca@2177
  1057
        "contained subvies used by spec are not yet created;
ca@2177
  1058
         thus we have to wait until last used subview is build
ca@2177
  1059
        "
ca@2177
  1060
        anchor := nil.
ca@2177
  1061
    ] do:[
ca@2177
  1062
        anchor := parent class buildViewsFrom:(parent widget).
ca@2177
  1063
    ].
ca@2177
  1064
    anchor notNil ifTrue:[
ca@2177
  1065
        parent updateFromChildren:anchor children.
ca@2177
  1066
    ].
ca@2177
  1067
! !
ca@2177
  1068
cg@2744
  1069
!ViewTreeInspectorApplication methodsFor:'initialization & release'!
ca@2177
  1070
ca@2177
  1071
closeDownViews
ca@2455
  1072
    "release the grapped application"
ca@2455
  1073
ca@2177
  1074
    process := nil.
ca@2177
  1075
    super closeDownViews.
ca@2177
  1076
    self doUnpick.
ca@2177
  1077
!
ca@2177
  1078
ca@2177
  1079
initialize
ca@2455
  1080
    "setup my model and channels"
ca@2455
  1081
ca@2177
  1082
    super initialize.
ca@2177
  1083
ca@2177
  1084
    hasSingleSelectionHolder := false asValue.
ca@2177
  1085
    followFocusChannel       := false asValue.
ca@2177
  1086
ca@2177
  1087
    model := ViewTreeModel new.
ca@2177
  1088
    model inputEventAction:[:ev| self processEvent:ev ].
ca@2177
  1089
    model mappedViewAction:[:vw| self processMappedView:vw ].
ca@2177
  1090
    model application:self.
ca@2458
  1091
    model addDependent:self.
ca@2458
  1092
ca@2177
  1093
ca@2451
  1094
    showNamesHolder := false asValue.
ca@2451
  1095
    showNamesHolder addDependent:self.
ca@2177
  1096
!
ca@2177
  1097
cg@2770
  1098
postBuildInspectorView:anInspector
cg@2770
  1099
    inspectorView := anInspector.
cg@2770
  1100
!
cg@2770
  1101
ca@2177
  1102
postBuildTree:aTree
ca@2177
  1103
    treeView := aTree scrolledView.
ca@2177
  1104
    treeView hasConstantHeight:true.
ca@2177
  1105
! !
ca@2177
  1106
cg@2744
  1107
!ViewTreeInspectorApplication methodsFor:'menu queries'!
ca@2177
  1108
ca@2177
  1109
hasApplication
ca@2455
  1110
    "returns true if the current selected view has an application"
ca@2455
  1111
ca@2177
  1112
    |view|
ca@2177
  1113
ca@2177
  1114
    view := self selectedView.
ca@2177
  1115
  ^ (view notNil and:[view application notNil])
ca@2177
  1116
!
ca@2177
  1117
ca@2177
  1118
hasController
ca@2177
  1119
    "returns true if the current selected item's view has a controller
ca@2455
  1120
     other than nil or the view itself"
ca@2455
  1121
ca@2177
  1122
    |view controller|
ca@2177
  1123
ca@2177
  1124
    view := self selectedView.
ca@2177
  1125
ca@2177
  1126
    view notNil ifTrue:[
ca@2177
  1127
        controller := view controller.
ca@2177
  1128
      ^ (controller notNil and:[controller ~~ view])
ca@2177
  1129
    ].
ca@2177
  1130
    ^ false
ca@2177
  1131
!
ca@2177
  1132
ca@2177
  1133
hasModel
ca@2455
  1134
    "returns true if the current selected view has a model"
ca@2455
  1135
ca@2177
  1136
    |view|
ca@2177
  1137
ca@2177
  1138
    view := self selectedView.
ca@2177
  1139
  ^ (view notNil and:[view model notNil])
ca@2177
  1140
! !
ca@2177
  1141
cg@2744
  1142
!ViewTreeInspectorApplication methodsFor:'menu specs'!
ca@2177
  1143
ca@2177
  1144
middleButtonMenu
ca@2455
  1145
    "returns the middleButton menu for the single selected item or nil"
ca@2455
  1146
cg@2758
  1147
    ^ [ 
cg@2758
  1148
        model selectedItem notNil 
cg@2758
  1149
            ifTrue:[self class middleButtonMenu]
cg@2758
  1150
            ifFalse:[nil]
ca@2177
  1151
      ]
ca@2177
  1152
!
ca@2177
  1153
ca@2177
  1154
submenuApplications:aMenu
ca@2177
  1155
    |applications menu item list addBlock|
ca@2177
  1156
ca@2177
  1157
    item := aMenu selection nameKey == #single ifTrue:[model selectedItem]
ca@2177
  1158
                                              ifFalse:[model rootItem].
ca@2177
  1159
    item isNil ifTrue:[^ nil].
ca@2177
  1160
ca@2177
  1161
    applications := IdentityDictionary new.
ca@2177
  1162
ca@2177
  1163
    addBlock := [:el| |cls ctr|
ca@2177
  1164
        cls := self resolveApplicationClassFor:el.
ca@2177
  1165
ca@2177
  1166
        cls notNil ifTrue:[
ca@2177
  1167
            ctr := applications at:cls ifAbsent:0.
ca@2177
  1168
            applications at:cls put:(ctr + 1).
ca@2177
  1169
        ].
ca@2177
  1170
    ].
ca@2177
  1171
    item recursiveDo:addBlock.
ca@2177
  1172
    addBlock value:item.
ca@2177
  1173
ca@2177
  1174
    applications isEmpty ifTrue:[^ nil ].
ca@2177
  1175
    list := SortedCollection sortBlock:[:a :b| a title < b title ].
ca@2177
  1176
ca@2177
  1177
    applications keysAndValuesDo:[:cls :ctr|
ca@2177
  1178
       list add:(MenuDesc title:(cls name)
ca@2177
  1179
                          value:(ctr printString)
ca@2177
  1180
                         action:[self doSelectNextOfApplicationClass:cls startingIn:item]
ca@2177
  1181
                 ).
ca@2177
  1182
    ].
ca@2177
  1183
ca@2177
  1184
    menu := MenuDesc buildFromList:list onGC:aMenu.
ca@2177
  1185
    menu do:[:el|
ca@2177
  1186
        el hideMenuOnActivated:false
ca@2177
  1187
    ].
ca@2177
  1188
    ^ menu
ca@2177
  1189
!
ca@2177
  1190
ca@2177
  1191
submenuComponents:aMenu
ca@2177
  1192
    |widgets list total menu item|
ca@2177
  1193
ca@2177
  1194
    item := aMenu selection nameKey == #single ifTrue:[model selectedItem]
ca@2177
  1195
                                              ifFalse:[model rootItem].
ca@2177
  1196
    item isNil ifTrue:[^ nil].
ca@2177
  1197
ca@2177
  1198
    widgets := IdentityDictionary new.
ca@2177
  1199
    total   := 0.
ca@2177
  1200
ca@2177
  1201
    item recursiveDo:[:el| |cls ctr|
ca@2177
  1202
        cls := el widget.
ca@2177
  1203
ca@2177
  1204
        cls notNil ifTrue:[
ca@2177
  1205
            cls := cls class.
ca@2177
  1206
            ctr := widgets at:cls ifAbsent:0.
ca@2177
  1207
            widgets at:cls put:(ctr + 1).
ca@2177
  1208
            total := total + 1.
ca@2177
  1209
        ].
ca@2177
  1210
    ].
ca@2177
  1211
    total == 0 ifTrue:[^ nil].
ca@2177
  1212
    list := SortedCollection sortBlock:[:a :b| a title < b title ].
ca@2177
  1213
ca@2177
  1214
    widgets keysAndValuesDo:[:cls :ctr|
ca@2177
  1215
        list add:(MenuDesc title:(cls name)
ca@2177
  1216
                           value:(ctr printString)
ca@2177
  1217
                          action:[self doSelectNextOfClass:cls startingIn:item]
ca@2177
  1218
                 ).
ca@2177
  1219
    ].
ca@2177
  1220
    list := list asOrderedCollection.
ca@2177
  1221
    list add:(MenuDesc separator).
ca@2177
  1222
    list add:(MenuDesc title:'Total' value:(total printString)).
ca@2177
  1223
    menu := MenuDesc buildFromList:list onGC:aMenu.
ca@2177
  1224
    menu do:[:el|
ca@2177
  1225
        el hideMenuOnActivated:false
ca@2177
  1226
    ].
ca@2177
  1227
    ^ menu
ca@2177
  1228
!
ca@2177
  1229
ca@2177
  1230
submenuGeometry:aMenu
ca@2455
  1231
    "builds and returns the geometry submenu"
ca@2455
  1232
ca@2177
  1233
    |view point inst list x y|
ca@2177
  1234
ca@2177
  1235
    view := self selectedView.
ca@2177
  1236
    view isNil ifTrue:[^ nil].
ca@2177
  1237
ca@2177
  1238
    list := OrderedCollection new.
ca@2177
  1239
ca@2177
  1240
    "/ origin
ca@2177
  1241
    point := view relativeOrigin.
ca@2177
  1242
    point isNil ifTrue:[ point := view origin ].
ca@2177
  1243
ca@2177
  1244
    x := view left.
ca@2177
  1245
    y := view top.
ca@2177
  1246
ca@2177
  1247
    (x == point x and:[y == point y]) ifTrue:[ inst := point ]
ca@2177
  1248
                                     ifFalse:[ inst := '%1 --> (%2@%3)' bindWith:point with:x with:y ].
ca@2177
  1249
ca@2177
  1250
    list add:(MenuDesc title:'origin' value:inst).
ca@2177
  1251
ca@2177
  1252
    "/ corner
ca@2177
  1253
    point := view relativeCorner.
ca@2177
  1254
    point isNil ifTrue:[ point := view corner ].
ca@2177
  1255
ca@2177
  1256
    x := view right.
ca@2177
  1257
    y := view bottom.
ca@2177
  1258
ca@2177
  1259
    (x == point x and:[y == point y]) ifTrue:[ inst := point ]
ca@2177
  1260
                                     ifFalse:[ inst := '%1 --> (%2@%3)' bindWith:point with:x with:y ].
ca@2177
  1261
ca@2177
  1262
    list add:(MenuDesc title:'corner' value:inst).
ca@2177
  1263
ca@2177
  1264
    "/ extent
ca@2177
  1265
    (point := view relativeExtent) isNil ifTrue:[point := view extent].
ca@2177
  1266
    list add:(MenuDesc title:'extent' value:point).
ca@2177
  1267
ca@2177
  1268
    "/ preferred extent
ca@2177
  1269
    list add:(MenuDesc title:'pref. extent' value:(view preferredExtent)).
ca@2177
  1270
    list add:(MenuDesc separator).
ca@2177
  1271
ca@2177
  1272
    "/ view insets
ca@2177
  1273
    inst := 'l:%1  r:%2  t:%3  b:%4' bindWith:(view leftInset)
ca@2177
  1274
                                         with:(view rightInset)
ca@2177
  1275
                                         with:(view topInset)
ca@2177
  1276
                                         with:(view bottomInset).
ca@2177
  1277
ca@2177
  1278
    list add:(MenuDesc title:'insets'      value:inst).
ca@2177
  1279
    list add:(MenuDesc title:'borderWidth' value:(view borderWidth)).
ca@2177
  1280
    list add:(MenuDesc title:'level'       value:(view level)).
ca@2177
  1281
    list add:(MenuDesc separator).
ca@2177
  1282
ca@2177
  1283
    (inst := view layout) notNil ifTrue:[ inst := inst displayString ].
ca@2177
  1284
    list add:(MenuDesc title:'layout' value:inst).
ca@2177
  1285
ca@2177
  1286
    (inst := view transformation) notNil ifTrue:[ inst := inst displayString ].
ca@2177
  1287
    list add:(MenuDesc title:'transformation' value:inst).
ca@2177
  1288
ca@2177
  1289
  ^ MenuDesc buildFromList:list onGC:aMenu
ca@2177
  1290
!
ca@2177
  1291
ca@2177
  1292
submenuInspector:aMenu
ca@2455
  1293
    "builds and returns the inspector submenu"
ca@2455
  1294
ca@2177
  1295
    |view list n names label value|
ca@2177
  1296
ca@2177
  1297
    view := self selectedView.
ca@2177
  1298
    view isNil ifTrue:[^ nil].
ca@2177
  1299
ca@2177
  1300
    n := view class instSize.
ca@2177
  1301
    n > 0 ifFalse:[^ nil ].
ca@2177
  1302
ca@2177
  1303
    list  := OrderedCollection new:n.
ca@2177
  1304
    names := view class allInstVarNames.
ca@2177
  1305
ca@2177
  1306
    1 to:n do:[:i| |action|
ca@2177
  1307
        label := (names at:i) printString.
ca@2177
  1308
        value := view instVarAt:i.
ca@2177
  1309
        value isNil ifTrue:[
ca@2177
  1310
            value  := '------'.
ca@2177
  1311
            action := nil.
ca@2177
  1312
        ] ifFalse:[
ca@2177
  1313
            value  := value displayString contractAtEndTo:40.
ca@2177
  1314
            action := [(view instVarAt:i) inspect].
ca@2177
  1315
        ].
ca@2177
  1316
        list add:(MenuDesc title:label value:value action:action).
ca@2177
  1317
    ].
ca@2177
  1318
ca@2177
  1319
    ^ MenuDesc buildFromList:list onGC:aMenu
ca@2177
  1320
!
ca@2177
  1321
ca@2177
  1322
submenuInterface:aMenu
ca@2455
  1323
    "builds and returns the interface submenu"
ca@2455
  1324
ca@2177
  1325
    |view label inst value list|
ca@2177
  1326
ca@2177
  1327
    view := self selectedView.
ca@2177
  1328
    view isNil ifTrue:[^ nil].
ca@2177
  1329
ca@2177
  1330
    list := OrderedCollection new.
ca@2177
  1331
ca@2177
  1332
    inst  := view controller.
ca@2177
  1333
    value := nil.
ca@2177
  1334
ca@2177
  1335
    inst isNil ifTrue:[
ca@2177
  1336
        label := nil
ca@2177
  1337
    ] ifFalse:[
cg@2758
  1338
        inst == view ifTrue:[ 
cg@2758
  1339
            label := '== view itself' 
cg@2758
  1340
        ] ifFalse:[ 
cg@2758
  1341
            label := inst displayString.
cg@2758
  1342
            value := [view controller inspect].
cg@2758
  1343
        ].
ca@2177
  1344
    ].
ca@2177
  1345
    list add:(MenuDesc title:'controller' value:label action:value).
ca@2177
  1346
ca@2177
  1347
    inst := view delegate.
ca@2177
  1348
    inst notNil ifTrue:[
ca@2177
  1349
        list add:(MenuDesc title:'delegate' value:(inst displayString) action:[ view delegate inspect ]).
ca@2177
  1350
    ].
ca@2177
  1351
ca@2177
  1352
    inst := view application.
ca@2177
  1353
cg@2758
  1354
    inst notNil ifTrue:[ 
cg@2758
  1355
        |topAppl|
cg@2758
  1356
ca@2177
  1357
        list add:(MenuDesc title:'application' value:inst action:[ view application inspect ]).
ca@2177
  1358
ca@2177
  1359
        topAppl := inst topApplication.
ca@2177
  1360
ca@2177
  1361
        (topAppl notNil and:[topAppl ~~ inst]) ifTrue:[
ca@2177
  1362
            list add:(MenuDesc title:'topApplication' value:topAppl action:[ inst topApplication inspect ]).
ca@2177
  1363
        ].
ca@2177
  1364
    ].
ca@2177
  1365
    list add:(MenuDesc separator).
ca@2177
  1366
cg@2888
  1367
    (view respondsTo:#'model') ifTrue:[
cg@2779
  1368
        inst := view model.
ca@2177
  1369
cg@2888
  1370
        inst isNil 
cg@2888
  1371
            ifTrue:[ label := value := nil ]
cg@2888
  1372
            ifFalse:[ label := inst displayString.
cg@2888
  1373
                      label := label,(self aspectLabelFor:inst inApplicationOf:view).  
cg@2888
  1374
                      value := [ view model inspect ].
cg@2888
  1375
                    ].
ca@2177
  1376
ca@2177
  1377
        list add:(MenuDesc title:'model' value:label action:value).
ca@2177
  1378
ca@2177
  1379
        (inst notNil and:[view respondsTo:#modelInterface]) ifTrue:[
ca@2177
  1380
            view modelInterface keysAndValuesDo:[:key : val|
ca@2177
  1381
                val isNil ifTrue:[ label := nil ]
ca@2177
  1382
                         ifFalse:[ label := val displayString ].
ca@2177
  1383
ca@2177
  1384
                list add:(MenuDesc title:('      - ', key) value:label ).
ca@2177
  1385
            ]
ca@2177
  1386
        ].
ca@2177
  1387
    ].
ca@2177
  1388
ca@2177
  1389
    (view respondsTo:#enableChannel) ifTrue:[
ca@2177
  1390
        inst := view enableChannel.
ca@2177
  1391
ca@2177
  1392
        inst isNil ifTrue:[ label := value := nil ]
ca@2177
  1393
                  ifFalse:[ label := inst displayString.
cg@2888
  1394
                            label := label,(self aspectLabelFor:inst inApplicationOf:view).  
ca@2177
  1395
                            value := [ view enableChannel inspect ].
ca@2177
  1396
                          ].
ca@2177
  1397
ca@2177
  1398
        list add:(MenuDesc title:'enableChannel' value:label action:value).
ca@2177
  1399
    ].
ca@2177
  1400
cg@2888
  1401
    #( #action #pressAction #releaseAction ) do:[:actionSelector |
cg@2779
  1402
        (view respondsTo:actionSelector) ifTrue:[
cg@2779
  1403
            inst := view perform:actionSelector.
cg@2779
  1404
cg@2779
  1405
            inst isNil 
cg@2779
  1406
                ifTrue:[ label := value := nil ]
cg@2779
  1407
                ifFalse:[ label := inst displayString.
cg@2779
  1408
                            value := [ (view perform:actionSelector) inspect ].
cg@2779
  1409
                        ].
cg@2779
  1410
cg@2779
  1411
            list add:(MenuDesc title:'action' value:label action:value).
cg@2779
  1412
        ].
cg@2779
  1413
    ].
cg@2779
  1414
ca@2177
  1415
    list last isSeparator ifFalse:[ list add:(MenuDesc separator) ].
ca@2177
  1416
ca@2177
  1417
    (view respondsTo:#listHolder) ifTrue:[
ca@2177
  1418
        inst := view listHolder.
ca@2177
  1419
ca@2177
  1420
        inst isNil ifTrue:[ label := value := nil ]
ca@2177
  1421
                  ifFalse:[ label := inst class printString.
cg@2888
  1422
                            label := label,(self aspectLabelFor:inst inApplicationOf:view).  
ca@2177
  1423
                            value := [ view listHolder inspect ].
ca@2177
  1424
                          ].
ca@2177
  1425
        list add:(MenuDesc title:'listHolder' value:label action:value).
ca@2177
  1426
    ].
ca@2177
  1427
ca@2177
  1428
    (view respondsTo:#list) ifTrue:[
ca@2177
  1429
        inst := view list.
ca@2177
  1430
ca@2177
  1431
        inst isNil ifTrue:[ label := value := nil ]
ca@2177
  1432
                  ifFalse:[ label := '%1 [%2]' bindWith:(inst class printString) with:(inst size).
cg@2888
  1433
                            label := label,(self aspectLabelFor:inst inApplicationOf:view).  
ca@2177
  1434
                            value := [ view list inspect ].
ca@2177
  1435
                          ].
ca@2177
  1436
ca@2177
  1437
        list add:(MenuDesc title:'list' value:label action:value).
ca@2177
  1438
    ].
ca@2177
  1439
ca@2177
  1440
    list last isSeparator ifTrue:[ list removeLast ].
cg@2888
  1441
    ^ MenuDesc buildFromList:list onGC:aMenu
cg@2888
  1442
cg@2888
  1443
    "Modified: / 27-04-2012 / 14:22:34 / cg"
ca@2177
  1444
!
ca@2177
  1445
ca@2177
  1446
submenuVisibility:aMenu
ca@2455
  1447
    "builds and returns the geometry submenu"
ca@2455
  1448
ca@2177
  1449
    |view list value|
ca@2177
  1450
ca@2177
  1451
    view := self selectedView.
ca@2177
  1452
    view isNil ifTrue:[^ nil].
ca@2177
  1453
ca@2177
  1454
    list := OrderedCollection new.
ca@2177
  1455
ca@2177
  1456
    list add:(MenuDesc title:'device'     value:(view device printString)).
ca@2177
  1457
    list add:(MenuDesc title:'drawableId' value:(view id)).
ca@2177
  1458
    list add:(MenuDesc title:'gcId'       value:(view gcId)).
ca@2177
  1459
ca@2177
  1460
    list add:(MenuDesc separator).
ca@2177
  1461
ca@2177
  1462
    list add:(MenuDesc title:'shown'    value:(view shown)).
ca@2177
  1463
    list add:(MenuDesc title:'realized' value:(view realized)).
ca@2177
  1464
ca@2177
  1465
    list add:(MenuDesc separator).
ca@2177
  1466
ca@2177
  1467
    list add:(MenuDesc title:'hiddenOnRealize' value:(view isHiddenOnRealize)).
ca@2177
  1468
ca@2177
  1469
    (value := view visibilityChannel) isNil ifTrue:[
ca@2177
  1470
        list add:(MenuDesc title:'visibilityChannel' value:'------').
ca@2177
  1471
    ] ifFalse:[
ca@2177
  1472
        list add:(MenuDesc title:'visibilityChannel'
ca@2177
  1473
                           value:(value displayString)
ca@2177
  1474
                          action:[view visibilityChannel inspect]).
ca@2177
  1475
    ].
ca@2177
  1476
cg@2758
  1477
    ^ MenuDesc buildFromList:list onGC:aMenu
ca@2177
  1478
! !
ca@2177
  1479
cg@2744
  1480
!ViewTreeInspectorApplication methodsFor:'private'!
ca@2177
  1481
cg@2888
  1482
aspectLabelFor:aModel inApplicationOf:aView
cg@2888
  1483
    |app|
cg@2888
  1484
cg@2888
  1485
    aModel isNil ifTrue:[^ ''].
cg@2888
  1486
    aView isNil ifTrue:[^ ''].
cg@2888
  1487
    (app := aView application) isNil ifTrue:[^ ''].
cg@2888
  1488
    app builder bindings keysAndValuesDo:[:aspect :value |
cg@2888
  1489
        value == aModel ifTrue:[^ ' [aspect: ',aspect,']'].
cg@2888
  1490
    ].
cg@2888
  1491
    app class allInstVarNames do:[:nm | 
cg@2888
  1492
        (app instVarNamed:nm) == aModel ifTrue:[^ ' [instvar: ',nm,']']
cg@2888
  1493
    ].
cg@2888
  1494
cg@2888
  1495
    ^ ''
cg@2888
  1496
cg@2888
  1497
    "Created: / 27-04-2012 / 14:22:09 / cg"
cg@2888
  1498
!
cg@2888
  1499
ca@2177
  1500
selectFocusView
cg@2762
  1501
    |rootView focusView|
ca@2177
  1502
ca@2177
  1503
    rootView := model rootView.
ca@2177
  1504
ca@2177
  1505
    (rootView notNil and:[rootView shown]) ifTrue:[
ca@2177
  1506
        focusView := rootView windowGroup focusView.
ca@2177
  1507
    ].
ca@2177
  1508
    focusView isNil ifTrue:[^ self ].
ca@2177
  1509
cg@2762
  1510
    self selectView:focusView
cg@2762
  1511
!
cg@2762
  1512
cg@2762
  1513
selectView:aView
cg@2762
  1514
    |currentItem viewItem|
cg@2762
  1515
cg@2762
  1516
    currentItem := model selectedItem.
cg@2762
  1517
cg@2762
  1518
    (currentItem notNil and:[currentItem widget == aView]) ifTrue:[
ca@2177
  1519
        ^ self
ca@2177
  1520
    ].
cg@2762
  1521
    viewItem := model listOfItems recursiveDetect:[:el| el widget == aView ].
cg@2762
  1522
cg@2762
  1523
    viewItem notNil ifTrue:[
cg@2762
  1524
        model selectItem:viewItem.
ca@2177
  1525
    ].        
ca@2177
  1526
!
ca@2177
  1527
ca@2177
  1528
setRootItem:aRootItemOrNil
ca@2177
  1529
    |theProcess|
ca@2177
  1530
ca@2177
  1531
    aRootItemOrNil isNil ifTrue:[
ca@2177
  1532
        process := nil.
ca@2177
  1533
    ] ifFalse:[
ca@2177
  1534
        "/ expand tree to level 3
ca@2177
  1535
        aRootItemOrNil do:[:aRootChild|
ca@2177
  1536
            aRootChild do:[:aSubChild| aSubChild expand ].
ca@2177
  1537
            aRootChild expand.
ca@2177
  1538
        ].
ca@2177
  1539
        aRootItemOrNil expand.
ca@2177
  1540
ca@2177
  1541
        process isNil ifTrue:[
ca@2177
  1542
            theProcess := process :=
ca@2455
  1543
                Process for:[   |update testModeChannel|
ca@2177
  1544
ca@2177
  1545
                                update := false.
ca@2455
  1546
                                testModeChannel := model testModeChannel.
ca@2177
  1547
ca@2455
  1548
                                [process == theProcess] whileTrue:[
ca@2177
  1549
                                    Delay waitForSeconds:0.5.
ca@2177
  1550
ca@2177
  1551
                                    (treeView notNil and:[process == theProcess and:[treeView shown]]) ifTrue:[
ca@2455
  1552
                                        (testModeChannel value == true and:[followFocusChannel value == true]) ifTrue:[
ca@2177
  1553
                                            self selectFocusView.
ca@2177
  1554
                                        ].
ca@2177
  1555
                                        update ifTrue:[
ca@2177
  1556
                                            self updateShownStatus.
ca@2177
  1557
                                        ].
ca@2177
  1558
                                        update := update not.
ca@2177
  1559
                                    ].
ca@2177
  1560
                                ].
ca@2177
  1561
ca@2177
  1562
                             ] priority:8.
cg@2744
  1563
            theProcess name:'ViewTreeInspector - Follow Focus'.
ca@2177
  1564
            theProcess resume.
ca@2177
  1565
        ].
ca@2177
  1566
    ].
ca@2177
  1567
    model rootItem:aRootItemOrNil.
ca@2177
  1568
!
ca@2177
  1569
ca@2177
  1570
updateShownStatus
ca@2177
  1571
    |rootItem min max visState listIdx visY0 visY1 height damage|
ca@2177
  1572
ca@2177
  1573
    rootItem := model rootItem.
ca@2177
  1574
    (rootItem notNil and:[rootItem widget shown]) ifFalse:[^ self].
ca@2177
  1575
ca@2177
  1576
    max := 0.
ca@2177
  1577
    min := 9999999.
ca@2177
  1578
ca@2177
  1579
    rootItem recursiveEachVisibleItemDo:[:anItem|
ca@2177
  1580
        visState := (anItem widget shown).
ca@2177
  1581
ca@2177
  1582
        visState ~~ anItem isDrawnShown ifTrue:[
ca@2177
  1583
            anItem isDrawnShown:visState.
ca@2177
  1584
            listIdx := treeView identityIndexOf:anItem.
ca@2177
  1585
ca@2177
  1586
            listIdx > 0 ifTrue:[    
ca@2177
  1587
                max := max max:listIdx.
ca@2177
  1588
                min := min min:listIdx.
ca@2177
  1589
            ].
ca@2177
  1590
        ].
ca@2177
  1591
    ].
ca@2177
  1592
    max < min ifTrue:[^ self].
ca@2177
  1593
    max := max + 1.
ca@2177
  1594
ca@2177
  1595
    visY0  := (treeView yVisibleOfLine:min) max:0.
ca@2177
  1596
    visY1  := (treeView yVisibleOfLine:max) min:(treeView height).
ca@2177
  1597
    height := visY1 - visY0.
ca@2177
  1598
    
ca@2177
  1599
    height > 2 ifTrue:[
ca@2177
  1600
        treeView shown ifTrue:[
ca@2177
  1601
            damage := Rectangle left:0 top:visY0 width:(treeView width) height:height.
ca@2177
  1602
            treeView invalidateDeviceRectangle:damage repairNow:false.
ca@2177
  1603
        ].
ca@2177
  1604
    ].
ca@2177
  1605
! !
ca@2177
  1606
cg@2744
  1607
!ViewTreeInspectorApplication methodsFor:'selection'!
ca@2177
  1608
ca@2177
  1609
selectedView
ca@2455
  1610
    "answer the selected view or nil"
ca@2455
  1611
ca@2177
  1612
    |item|
ca@2177
  1613
ca@2177
  1614
    item := model selectedItem.
ca@2177
  1615
    item notNil ifTrue:[ ^ item widget ].
ca@2177
  1616
  ^ nil
ca@2177
  1617
! !
ca@2177
  1618
cg@2744
  1619
!ViewTreeInspectorApplication methodsFor:'testing'!
ca@2177
  1620
ca@2177
  1621
resolveApplicationClassFor:aTreeItem
ca@2177
  1622
    aTreeItem isApplicationClass ifTrue:[
ca@2177
  1623
       ^ aTreeItem applicationClass
ca@2177
  1624
    ].
ca@2177
  1625
    ^ nil
ca@2177
  1626
!
ca@2177
  1627
ca@2177
  1628
selectedComponentHasChildren
ca@2177
  1629
    |item|
ca@2177
  1630
ca@2177
  1631
    item := model selectedItem.
ca@2177
  1632
    ^ (item notNil and:[item hasChildren])
ca@2177
  1633
! !
ca@2177
  1634
cg@2744
  1635
!ViewTreeInspectorApplication methodsFor:'user operations'!
ca@2177
  1636
ca@2177
  1637
doBrowse:what
ca@2177
  1638
    "open browser on:
ca@2177
  1639
        #view           browse class
ca@2177
  1640
        #model          browse model class
ca@2177
  1641
        #application    browse application class
ca@2177
  1642
        #controller     browse controller class
ca@2177
  1643
    "
ca@2177
  1644
    |view inst|
ca@2177
  1645
ca@2177
  1646
    view := self selectedView.
ca@2177
  1647
    view isNil ifTrue:[^ self].
ca@2177
  1648
ca@2177
  1649
             what == #view        ifTrue:[ inst := view ]
ca@2177
  1650
    ifFalse:[what == #model       ifTrue:[ inst := view model ]
ca@2177
  1651
    ifFalse:[what == #application ifTrue:[ inst := view application ]
ca@2177
  1652
    ifFalse:[what == #controller  ifTrue:[ inst := view controller ]
ca@2177
  1653
    ifFalse:[
ca@2177
  1654
        ^ self
ca@2177
  1655
    ]]]].
ca@2177
  1656
ca@2177
  1657
    inst notNil ifTrue:[
ca@2177
  1658
        inst class browserClass openInClass:(inst class) selector:nil
ca@2177
  1659
    ].
ca@2177
  1660
!
ca@2177
  1661
ca@2177
  1662
doDestroy
ca@2455
  1663
    "destroy the current selected view"
ca@2455
  1664
ca@2177
  1665
    |item parent|
ca@2177
  1666
ca@2177
  1667
    item := model selectedItem.
ca@2177
  1668
    item isNil ifTrue:[ ^ self].
ca@2177
  1669
ca@2177
  1670
    parent := item parent.
ca@2177
  1671
ca@2177
  1672
    parent isNil ifTrue:[
ca@2177
  1673
        "/ the root
ca@2177
  1674
        model withSelectionHiddenDo:[item deleteAll].
ca@2177
  1675
      ^ self
ca@2177
  1676
    ].
ca@2177
  1677
ca@2177
  1678
    model withSelectionHiddenDo:[
ca@2177
  1679
        |idx nsel|
ca@2177
  1680
ca@2177
  1681
        idx := parent identityIndexOf:item.
ca@2177
  1682
ca@2177
  1683
        idx == parent size ifTrue:[
ca@2177
  1684
            nsel := parent at:(idx - 1) ifAbsent:parent
ca@2177
  1685
        ] ifFalse:[
ca@2177
  1686
            nsel := parent at:(idx + 1)
ca@2177
  1687
        ].
ca@2177
  1688
        model setValue:nil.
ca@2177
  1689
        item delete.
ca@2177
  1690
ca@2177
  1691
        parent isLayoutContainer ifTrue:[
ca@2177
  1692
            parent widget sizeChanged:nil
ca@2177
  1693
        ].
ca@2177
  1694
        model value:nsel.
ca@2177
  1695
    ].
ca@2177
  1696
!
ca@2177
  1697
ca@2177
  1698
doFlash
ca@2455
  1699
    "flash the selected view"
ca@2455
  1700
ca@2177
  1701
    |view|
ca@2177
  1702
ca@2177
  1703
    view := self selectedView.
ca@2177
  1704
    view isNil ifTrue:[ ^ self].
ca@2177
  1705
ca@2177
  1706
    view shown ifTrue:[
ca@2177
  1707
        model withSelectionHiddenDo:[
ca@2177
  1708
            view perform:#flash ifNotUnderstood:nil.
ca@2177
  1709
        ].
ca@2177
  1710
    ].
ca@2177
  1711
!
ca@2177
  1712
ca@2177
  1713
doInspect:what
ca@2177
  1714
    "open inspector on:
ca@2177
  1715
        #view           inspect class
ca@2177
  1716
        #group          inspect windowGroup
ca@2177
  1717
        #model          inspect model
ca@2177
  1718
        #application    inspect application
ca@2177
  1719
        #controller     inspect controller
ca@2177
  1720
    "
ca@2177
  1721
    |inst|
ca@2177
  1722
ca@2177
  1723
    inst := self selectedView.
ca@2177
  1724
    inst isNil ifTrue:[^ self].
ca@2177
  1725
ca@2177
  1726
             what == #group       ifTrue:[ inst := inst windowGroup ]
ca@2177
  1727
    ifFalse:[what == #model       ifTrue:[ inst := inst model ]
ca@2177
  1728
    ifFalse:[what == #application ifTrue:[ inst := inst application ]
ca@2177
  1729
    ifFalse:[what == #controller  ifTrue:[ inst := inst controller  ]]]].
ca@2177
  1730
ca@2177
  1731
    inst notNil ifTrue:[ inst inspect ].
ca@2177
  1732
!
ca@2177
  1733
cg@2762
  1734
doPickView
ca@2455
  1735
    "pick a window's topView"
ca@2455
  1736
cg@2762
  1737
    |screen clickedView topWindow cursor|
ca@2177
  1738
ca@2177
  1739
    self doUnpick.
ca@2177
  1740
cg@2759
  1741
    cursor := Cursor fromImage:(self class crossHairIcon).
cg@2759
  1742
cg@2759
  1743
    screen := Screen current.
cg@2762
  1744
    clickedView := screen viewFromPoint:(screen pointFromUserShowing:cursor).
cg@2762
  1745
    clickedView isNil ifTrue:[^ self].
cg@2762
  1746
cg@2762
  1747
    topWindow := clickedView topView.
cg@2762
  1748
cg@2762
  1749
    (    topWindow == Screen current rootView
cg@2762
  1750
     or:[topWindow == self window topView]
ca@2177
  1751
    ) ifTrue:[
ca@2177
  1752
        ^ self
ca@2177
  1753
    ].
cg@2978
  1754
cg@2978
  1755
    model catchEvents:true.
cg@2762
  1756
    self setRootItem:(ViewTreeItem buildViewsFrom:topWindow).
cg@2762
  1757
    self selectView:clickedView.
ca@2177
  1758
!
ca@2177
  1759
cg@2978
  1760
doRedraw
cg@2978
  1761
    "redraw the app"
cg@2978
  1762
cg@2978
  1763
    model rootView withAllSubViewsDo:[:v | v redraw; invalidate].
cg@2978
  1764
!
cg@2978
  1765
ca@2177
  1766
doSelectNextOfApplicationClass:aClass startingIn:anItem
ca@2177
  1767
    |startItem firstFound searchNext|
ca@2177
  1768
ca@2177
  1769
    startItem  := model last.
ca@2177
  1770
    searchNext := startItem notNil.        
ca@2177
  1771
    firstFound := nil.
ca@2177
  1772
ca@2177
  1773
    anItem recursiveDo:[:el|
ca@2177
  1774
        el == startItem ifTrue:[
ca@2177
  1775
            searchNext := false
ca@2177
  1776
        ] ifFalse:[
ca@2177
  1777
            (self resolveApplicationClassFor:el) == aClass ifTrue:[
ca@2177
  1778
                searchNext ifFalse:[^ model selectItem:el].
ca@2177
  1779
ca@2177
  1780
                firstFound isNil ifTrue:[
ca@2177
  1781
                    firstFound := el
ca@2177
  1782
                ]
ca@2177
  1783
            ]
ca@2177
  1784
        ]
ca@2177
  1785
    ].
ca@2177
  1786
    firstFound notNil ifTrue:[
ca@2177
  1787
        self window beep.
ca@2177
  1788
        model selectItem:firstFound
ca@2177
  1789
    ].
ca@2177
  1790
!
ca@2177
  1791
ca@2177
  1792
doSelectNextOfClass:aClass startingIn:anItem
ca@2177
  1793
    |startItem firstFound searchNext|
ca@2177
  1794
ca@2177
  1795
    startItem  := model last.
ca@2177
  1796
    searchNext := startItem notNil.        
ca@2177
  1797
    firstFound := nil.
ca@2177
  1798
ca@2177
  1799
    anItem recursiveDo:[:el|
ca@2177
  1800
        el == startItem ifTrue:[
ca@2177
  1801
            searchNext := false
ca@2177
  1802
        ] ifFalse:[
ca@2177
  1803
            el widget class == aClass ifTrue:[
ca@2177
  1804
                searchNext ifFalse:[^ model selectItem:el].
ca@2177
  1805
ca@2177
  1806
                firstFound isNil ifTrue:[
ca@2177
  1807
                    firstFound := el
ca@2177
  1808
                ]
ca@2177
  1809
            ]
ca@2177
  1810
        ]
ca@2177
  1811
    ].
ca@2177
  1812
    firstFound notNil ifTrue:[
ca@2177
  1813
        self window beep.
ca@2177
  1814
        model selectItem:firstFound
ca@2177
  1815
    ].
ca@2177
  1816
!
ca@2177
  1817
cg@2978
  1818
doUncatchEvents
cg@2978
  1819
    model catchEvents:false.
cg@2978
  1820
    self doRedraw
cg@2978
  1821
!
cg@2978
  1822
ca@2177
  1823
doUnpick
ca@2455
  1824
    "release current picked window and contained subwindows"
ca@2455
  1825
ca@2177
  1826
    self setRootItem:nil.
cg@2744
  1827
!
cg@2744
  1828
cg@2744
  1829
openDocumentation
cg@2744
  1830
    HTMLDocumentView openFullOnDocumentationFile:'tools/misc/TOP.html#VIEWTREEINSPECTOR'
ca@2177
  1831
! !
ca@2177
  1832
cg@2744
  1833
!ViewTreeInspectorApplication::MenuDesc class methodsFor:'building'!
ca@2177
  1834
ca@2177
  1835
buildFromList:aList onGC:aMenu
ca@2177
  1836
    |tabSpec menu w menuPanel|
ca@2177
  1837
ca@2177
  1838
    w := 0.
ca@2177
  1839
    aList do:[:el| w := w max:(el widthOn:aMenu) ].
ca@2177
  1840
ca@2177
  1841
    tabSpec := TabulatorSpecification new.
ca@2177
  1842
    tabSpec unit:#pixel.
ca@2177
  1843
    tabSpec positions:#(0     1.5 ).
ca@2177
  1844
    tabSpec align:#(#left #left).
ca@2177
  1845
ca@2177
  1846
    w := w + 15.
ca@2177
  1847
    tabSpec positions:(Array with:0 with:w).
ca@2177
  1848
ca@2177
  1849
    menu := Menu new.
ca@2177
  1850
ca@2177
  1851
    aList do:[:el|
ca@2177
  1852
        menu addItem:(el asMenuItemWithTabulatorSpecification:tabSpec).
ca@2177
  1853
    ].
ca@2177
  1854
    menuPanel := MenuPanel menu:menu.
ca@2177
  1855
    ^ menuPanel
ca@2177
  1856
! !
ca@2177
  1857
cg@2744
  1858
!ViewTreeInspectorApplication::MenuDesc class methodsFor:'instance creation'!
ca@2177
  1859
ca@2177
  1860
separator
ca@2177
  1861
    ^ self new
ca@2177
  1862
!
ca@2177
  1863
ca@2177
  1864
title:aTitle value:aValue
ca@2177
  1865
    ^ self title:aTitle value:aValue action:nil
ca@2177
  1866
!
ca@2177
  1867
ca@2177
  1868
title:aTitle value:aValue action:anAction
ca@2177
  1869
    ^ self new title:aTitle value:aValue action:anAction
ca@2177
  1870
! !
ca@2177
  1871
cg@2744
  1872
!ViewTreeInspectorApplication::MenuDesc methodsFor:'accessing'!
ca@2177
  1873
ca@2177
  1874
title
ca@2177
  1875
    ^ title
ca@2177
  1876
! !
ca@2177
  1877
cg@2744
  1878
!ViewTreeInspectorApplication::MenuDesc methodsFor:'building'!
ca@2177
  1879
ca@2177
  1880
asMenuItemWithTabulatorSpecification:aTabSpec
ca@2177
  1881
    |array|
ca@2177
  1882
ca@2177
  1883
    title isNil ifTrue:[ ^ MenuItem label:value ].     "/ separator
ca@2177
  1884
ca@2177
  1885
    array := Array with:(title, ':') with:'------'.
ca@2177
  1886
ca@2177
  1887
    value notNil ifTrue:[
ca@2177
  1888
        array at:2 put:(value printString, ' ')
ca@2177
  1889
    ].
ca@2177
  1890
cg@2758
  1891
   ^ MenuItem 
cg@2758
  1892
        label:(MultiColListEntry fromStrings:array tabulatorSpecification:aTabSpec)
cg@2758
  1893
        value:action
ca@2177
  1894
! !
ca@2177
  1895
cg@2744
  1896
!ViewTreeInspectorApplication::MenuDesc methodsFor:'instance creation'!
ca@2177
  1897
ca@2177
  1898
title:aTitle value:aValue action:anAction
ca@2177
  1899
    "test for separator
ca@2177
  1900
    "
ca@2177
  1901
    title  := aTitle withoutSeparators.
ca@2177
  1902
    action := anAction.
ca@2177
  1903
ca@2177
  1904
    aValue notNil ifTrue:[
ca@2177
  1905
        value := aValue printString.
ca@2177
  1906
ca@2177
  1907
        value size > 70 ifTrue:[
ca@2177
  1908
            value := value copyFrom:1 to:70.
ca@2177
  1909
            value := value, '...'
ca@2177
  1910
        ]
ca@2177
  1911
    ].
ca@2177
  1912
! !
ca@2177
  1913
cg@2744
  1914
!ViewTreeInspectorApplication::MenuDesc methodsFor:'queries'!
ca@2177
  1915
ca@2177
  1916
isSeparator
ca@2177
  1917
    ^ title isNil
ca@2177
  1918
!
ca@2177
  1919
ca@2177
  1920
widthOn:aGC
ca@2177
  1921
    title isNil ifTrue:[^ 5].  "/ separator
cg@2758
  1922
    ^ title widthOn:aGC
ca@2177
  1923
! !
ca@2177
  1924
cg@2744
  1925
!ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'building'!
cg@2744
  1926
cg@2744
  1927
buildViewsFrom:aView
cg@2744
  1928
    "build the items starting from a source view;
cg@2744
  1929
     returns the anhor.
cg@2744
  1930
    "
cg@2744
  1931
    |item subViews subItems|
cg@2744
  1932
cg@2744
  1933
    aView isNil ifTrue:[^ nil].
cg@2744
  1934
cg@2744
  1935
    item     := self forView:aView.
cg@2744
  1936
    subViews := aView subViews.
cg@2744
  1937
cg@2744
  1938
    subViews notEmptyOrNil ifTrue:[
cg@2744
  1939
        subItems := OrderedCollection new.
cg@2744
  1940
        subViews do:[:aSubView|
cg@2744
  1941
            subItems add:(self buildViewsFrom:aSubView).
cg@2744
  1942
        ].
cg@2744
  1943
        item children:subItems.
cg@2744
  1944
    ].
cg@2744
  1945
    ^ item
cg@2744
  1946
! !
cg@2744
  1947
cg@2744
  1948
!ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'documentation'!
cg@2744
  1949
cg@2744
  1950
documentation
cg@2744
  1951
"
cg@2744
  1952
    ViewTreeItems represants a pickable object within a ViewTreeModel.
cg@2744
  1953
    The class is used to build up the hierarchical tree.
cg@2744
  1954
cg@2744
  1955
    [Instance variables:]
cg@2744
  1956
        widget        <View>            the widget represented by the item
cg@2744
  1957
        spec          <UISpecification> the UISpecification or nil
cg@2744
  1958
cg@2744
  1959
    [Class variables:]
cg@2744
  1960
        HandleExtent  <Point>           keeps the extent of a handle
cg@2744
  1961
cg@2744
  1962
cg@2744
  1963
    [author:]
cg@2744
  1964
        Claus Atzkern
cg@2744
  1965
cg@2744
  1966
    [see also:]
cg@2744
  1967
        HierarchicalItem
cg@2744
  1968
        ViewTreeModel
cg@2744
  1969
"
cg@2744
  1970
!
ca@2177
  1971
ca@2177
  1972
version
ca@2177
  1973
    ^ '$Header$'
ca@2177
  1974
! !
ca@2177
  1975
cg@2744
  1976
!ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'initialization'!
cg@2744
  1977
cg@2744
  1978
initialize
cg@2744
  1979
    "set the extent of the Handle
cg@2744
  1980
    "
cg@2744
  1981
    HandleExtent := 6@6.
cg@2744
  1982
! !
cg@2744
  1983
cg@2744
  1984
!ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'instance creation'!
cg@2744
  1985
cg@2744
  1986
forView:aView
cg@2744
  1987
    |item|
cg@2744
  1988
cg@2744
  1989
    item := self basicNew initialize.
cg@2744
  1990
    item forView:aView.
cg@2744
  1991
  ^ item
cg@2744
  1992
!
cg@2744
  1993
cg@2744
  1994
new
cg@2744
  1995
    self error:'not allowed'.
cg@2744
  1996
  ^ nil
cg@2744
  1997
!
cg@2744
  1998
cg@2744
  1999
on:aView withSpec:aSpec
cg@2744
  2000
    |item|
cg@2744
  2001
cg@2744
  2002
    item := self basicNew initialize.
cg@2744
  2003
    item on:aView withSpec:aSpec.
cg@2744
  2004
  ^ item
cg@2744
  2005
! !
cg@2744
  2006
cg@2744
  2007
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'accessing'!
cg@2744
  2008
cg@2744
  2009
applicationClass
cg@2744
  2010
    |appl|
cg@2744
  2011
cg@2744
  2012
    widget notNil ifTrue:[
cg@2744
  2013
        appl := widget application.
cg@2744
  2014
        appl notNil ifTrue:[^ appl class ].
cg@2744
  2015
    ].
cg@2744
  2016
    ^ nil
cg@2744
  2017
!
cg@2744
  2018
cg@2744
  2019
isDrawnShown
cg@2744
  2020
    "returns true if the last display operations was done during the widget was shown
cg@2744
  2021
    "
cg@2744
  2022
    ^ isDrawnShown
cg@2744
  2023
!
cg@2744
  2024
cg@2744
  2025
isDrawnShown:aBoolean
cg@2744
  2026
    isDrawnShown := aBoolean.
cg@2744
  2027
!
cg@2744
  2028
cg@2744
  2029
rootView
cg@2744
  2030
    "returns the widget assigned to the root or nil
cg@2744
  2031
    "
cg@2744
  2032
    ^ parent rootView
cg@2744
  2033
!
cg@2744
  2034
cg@2744
  2035
specClass
cg@2744
  2036
    "returns the spec-class assigned to the item
cg@2744
  2037
    "
cg@2744
  2038
    ^ widget specClass
cg@2744
  2039
!
cg@2744
  2040
cg@2744
  2041
treeModel
cg@2744
  2042
    "returns the assigned treeModel, an instance of ViewTreeModel
cg@2744
  2043
    "
cg@2744
  2044
    ^ parent treeModel
cg@2744
  2045
!
cg@2744
  2046
cg@2744
  2047
widget
cg@2744
  2048
    "returns the widget assigned to the item
cg@2744
  2049
    "
cg@2744
  2050
    ^ widget
cg@2744
  2051
! !
cg@2744
  2052
cg@2744
  2053
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'accessing layout'!
cg@2744
  2054
cg@2744
  2055
boundsRelativeToRoot
cg@2744
  2056
    "returns the bounds relative to the root widget
cg@2744
  2057
    "
cg@2744
  2058
    ^ self originRelativeToRoot extent:(widget extent)
cg@2744
  2059
!
cg@2744
  2060
cg@2744
  2061
cornerRelativeToRoot
cg@2744
  2062
    "returns the corner relative to the root widget
cg@2744
  2063
    "
cg@2744
  2064
    ^ self originRelativeToRoot + (widget extent)
cg@2744
  2065
!
cg@2744
  2066
cg@2744
  2067
extent
cg@2744
  2068
    "returns the extent of the widget
cg@2744
  2069
    "
cg@2744
  2070
    ^ widget extent
cg@2744
  2071
!
cg@2744
  2072
cg@2744
  2073
layoutType
cg@2744
  2074
    "returns the type of layout assigned to the wiget; nil if the
cg@2744
  2075
     superView cannot resize its sub widgets
cg@2744
  2076
    "
cg@2744
  2077
    |layout specClass superView|
cg@2744
  2078
cg@2744
  2079
    (superView := widget superView) isNil ifTrue:[
cg@2744
  2080
        ^ #Extent
cg@2744
  2081
    ].
cg@2744
  2082
        
cg@2744
  2083
    specClass := superView specClass.
cg@2744
  2084
cg@2744
  2085
    (specClass notNil and:[specClass isLayoutContainer]) ifTrue:[
cg@2744
  2086
        ^ specClass canResizeSubComponents ifTrue:[#Extent] ifFalse:[nil]
cg@2744
  2087
    ].
cg@2744
  2088
cg@2744
  2089
    (layout := widget geometryLayout) isNil ifTrue:[
cg@2744
  2090
        ^ #Extent
cg@2744
  2091
    ].
cg@2744
  2092
cg@2744
  2093
    layout isLayout ifTrue:[
cg@2744
  2094
        layout isLayoutFrame        ifTrue:[ ^ #LayoutFrame ].
cg@2744
  2095
        layout isAlignmentOrigin    ifTrue:[ ^ #AlignmentOrigin ].
cg@2744
  2096
        layout isLayoutOrigin       ifTrue:[ ^ #LayoutOrigin ].
cg@2744
  2097
    ] ifFalse:[
cg@2744
  2098
        layout isRectangle          ifTrue:[ ^ #Rectangle ].
cg@2744
  2099
        layout isPoint              ifTrue:[ ^ #Point ].
cg@2744
  2100
cg@2744
  2101
    ].
cg@2744
  2102
    Transcript showCR:'UNSUPPORTRD LAYOUT: ', layout printString.
cg@2744
  2103
  ^ nil
cg@2744
  2104
!
cg@2744
  2105
cg@2744
  2106
originRelativeToRoot
cg@2744
  2107
    "returns the origin relative to the root widget
cg@2744
  2108
    "
cg@2744
  2109
    ^ widget originRelativeTo:(self rootView)
cg@2744
  2110
! !
cg@2744
  2111
cg@2744
  2112
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'accessing optimize'!
cg@2744
  2113
cg@2744
  2114
children
cg@2744
  2115
    "redefined: optimize
cg@2744
  2116
    "
cg@2744
  2117
    ^ children
cg@2744
  2118
!
cg@2744
  2119
cg@2744
  2120
hasChildren
cg@2744
  2121
    |subViews list item|
cg@2744
  2122
cg@2744
  2123
    children size ~~ 0 ifTrue:[
cg@2744
  2124
        ^ true
cg@2744
  2125
    ].
cg@2744
  2126
    isExpanded := false.
cg@2744
  2127
    subViews   := widget subViews.
cg@2744
  2128
cg@2744
  2129
    subViews size == 0 ifTrue:[^ false].
cg@2744
  2130
cg@2744
  2131
    list := OrderedCollection new.
cg@2744
  2132
cg@2744
  2133
    subViews do:[:aSubView|
cg@2744
  2134
        item := self class buildViewsFrom:aSubView.
cg@2744
  2135
        item parent:self.
cg@2744
  2136
        list add:item.
cg@2744
  2137
    ].
cg@2744
  2138
    children := list.
cg@2744
  2139
    ^ true
cg@2744
  2140
!
cg@2744
  2141
cg@2744
  2142
size
cg@2744
  2143
    "redefined: returns list of children
cg@2744
  2144
    "
cg@2744
  2145
    ^ children size
cg@2744
  2146
! !
cg@2744
  2147
cg@2744
  2148
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'displaying'!
cg@2744
  2149
cg@2744
  2150
additionalLabelForItem:anItem
cg@2744
  2151
    "answer an additional item for an Item or nil"
cg@2744
  2152
cg@2744
  2153
    parent notNil ifTrue:[
cg@2744
  2154
        ^ parent additionalLabelForItem:anItem
cg@2744
  2155
    ].
cg@2744
  2156
    ^ nil
cg@2744
  2157
!
cg@2744
  2158
cg@2744
  2159
displayIcon:anIcon atX:x y:y on:aGC
cg@2744
  2160
    |x0 y0 y1 w|
cg@2744
  2161
cg@2744
  2162
    super displayIcon:anIcon atX:x y:y on:aGC.
cg@2744
  2163
cg@2744
  2164
    self exists ifFalse:[
cg@2744
  2165
        aGC paint:(Color red).
cg@2744
  2166
cg@2744
  2167
        y0 := y + 1.
cg@2744
  2168
        y1 := y + anIcon height - 2.
cg@2744
  2169
cg@2744
  2170
        x0 := x - 1.
cg@2744
  2171
        w  := anIcon width.
cg@2744
  2172
cg@2744
  2173
        2 timesRepeat:[
cg@2744
  2174
            aGC displayLineFromX:x0 y:y0 toX:(x0 + w) y:y1.
cg@2744
  2175
            aGC displayLineFromX:x0 y:y1 toX:(x0 + w) y:y0.
cg@2744
  2176
            x0 := x0 + 1.
cg@2744
  2177
        ].
cg@2744
  2178
    ].
cg@2744
  2179
!
cg@2744
  2180
cg@2744
  2181
displayOn:aGC x:x y:y h:h
cg@2744
  2182
    |labelHeight additionalName label isValidAndShown|
cg@2744
  2183
cg@2744
  2184
    label := self label.
cg@2744
  2185
    label isEmptyOrNil ifTrue:[^ self].
cg@2744
  2186
cg@2744
  2187
    widget id isNil ifTrue:[
cg@2744
  2188
        isDrawnShown := false.
cg@2744
  2189
cg@2744
  2190
        self exists ifFalse:[
cg@2744
  2191
            xOffsetAdditionalName := nil.
cg@2744
  2192
        ].
cg@2744
  2193
        isValidAndShown := false.
cg@2744
  2194
    ] ifFalse:[
cg@2744
  2195
        isValidAndShown := widget shown.
cg@2744
  2196
    ].
cg@2744
  2197
    isValidAndShown ifFalse:[
cg@2762
  2198
        label := Text string:label emphasis:#italic.
cg@2762
  2199
        label colorizeAllWith:Color grey.
cg@2744
  2200
    ].
cg@2744
  2201
cg@2744
  2202
    labelHeight := self heightOn:aGC.
cg@2744
  2203
    self displayLabel:label h:labelHeight on:aGC x:x y:y h:h.
cg@2744
  2204
cg@2744
  2205
    xOffsetAdditionalName notNil ifTrue:[
cg@2744
  2206
        additionalName := self additionalLabelForItem:self.
cg@2744
  2207
cg@2744
  2208
        additionalName notNil ifTrue:[
cg@2744
  2209
            self displayLabel:additionalName
cg@2744
  2210
                            h:labelHeight on:aGC
cg@2744
  2211
                            x:(x + xOffsetAdditionalName)
cg@2744
  2212
                            y:y
cg@2744
  2213
                            h:h.
cg@2744
  2214
        ] ifFalse:[
cg@2744
  2215
            xOffsetAdditionalName := nil.
cg@2744
  2216
        ].
cg@2744
  2217
    ].
cg@2744
  2218
!
cg@2744
  2219
cg@2744
  2220
recursiveAdditionalNameBehaviourChanged
cg@2744
  2221
    width := xOffsetAdditionalName := nil.
cg@2744
  2222
cg@2744
  2223
    children notNil ifTrue:[
cg@2744
  2224
        children do:[:each| each recursiveAdditionalNameBehaviourChanged ]
cg@2744
  2225
    ].
cg@2744
  2226
!
cg@2744
  2227
cg@2744
  2228
widthOn:aGC
cg@2744
  2229
    "return the width of the receiver, if it is to be displayed on aGC
cg@2744
  2230
    "
cg@2744
  2231
    |additionalName|
cg@2744
  2232
cg@2744
  2233
    width isNil ifTrue:[
cg@2744
  2234
        width := self widthOf:(self label) on:aGC.
cg@2744
  2235
        width := width + 2.
cg@2744
  2236
cg@2744
  2237
        additionalName := self additionalLabelForItem:self.
cg@2744
  2238
cg@2744
  2239
        additionalName notNil ifTrue:[
cg@2744
  2240
            xOffsetAdditionalName := width + 10.
cg@2744
  2241
            width := xOffsetAdditionalName + (self widthOf:additionalName on:aGC).
cg@2744
  2242
            width := width + 2.
cg@2744
  2243
        ] ifFalse:[
cg@2744
  2244
            xOffsetAdditionalName := nil.
cg@2744
  2245
        ].
cg@2744
  2246
    ].
cg@2744
  2247
    ^ width
cg@2744
  2248
! !
cg@2744
  2249
cg@2744
  2250
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'enumerating'!
cg@2744
  2251
cg@2744
  2252
handlesDo:aTwoArgAction
cg@2744
  2253
    "evaluate the two arg block on each handle; the arguments to the block is
cg@2744
  2254
     the rectangle relative to the rootView and the handle type which is
cg@2744
  2255
     set to nil if not resizeable.
cg@2744
  2256
cg@2744
  2257
     TYPES:     type    position( X - Y )
cg@2744
  2258
                -------------------------        
cg@2744
  2259
                #LT     Left   - Top
cg@2744
  2260
                #LC     Left   - Center
cg@2744
  2261
                #LB     Left   - Bottom
cg@2744
  2262
                #CT     Center - Top
cg@2744
  2263
                #CB     Center - Bottom
cg@2744
  2264
                #RT     Right  - Top
cg@2744
  2265
                #RC     Right  - Center
cg@2744
  2266
                #RB     Right  - Bottom
cg@2744
  2267
cg@2744
  2268
                nil     ** handle not pickable **
cg@2744
  2269
    "
cg@2744
  2270
    |type relOrg relCrn maxExt rootView w h
cg@2744
  2271
     xL    "{ Class:SmallInteger }"
cg@2744
  2272
     xC    "{ Class:SmallInteger }"
cg@2744
  2273
     xR    "{ Class:SmallInteger }"
cg@2744
  2274
     yT    "{ Class:SmallInteger }"
cg@2744
  2275
     yC    "{ Class:SmallInteger }"
cg@2744
  2276
     yB    "{ Class:SmallInteger }"
cg@2744
  2277
    |
cg@2744
  2278
    rootView := self rootView.
cg@2744
  2279
    relOrg   := widget originRelativeTo:rootView.
cg@2744
  2280
    relOrg isNil ifTrue:[ ^ self ].    "/ widget destroyed
cg@2744
  2281
cg@2744
  2282
    relOrg   := relOrg - (HandleExtent // 2).
cg@2744
  2283
    relCrn   := relOrg + widget extent.
cg@2744
  2284
    maxExt   := rootView extent - HandleExtent.
cg@2744
  2285
cg@2744
  2286
    xL := relOrg x max:0.
cg@2744
  2287
    xR := relCrn x min:(maxExt x).
cg@2744
  2288
    xC := xR + xL // 2.
cg@2744
  2289
cg@2744
  2290
    yT := relOrg y max:0.
cg@2744
  2291
    yB := relCrn y min:(maxExt y).
cg@2744
  2292
    yC := yB + yT // 2.
cg@2744
  2293
cg@2744
  2294
    type := self layoutType.
cg@2744
  2295
    w   := HandleExtent x.
cg@2744
  2296
    h   := HandleExtent y.
cg@2744
  2297
cg@2744
  2298
    (type == #LayoutFrame or:[type == #Rectangle]) ifTrue:[
cg@2744
  2299
        aTwoArgAction value:(Rectangle left:xL top:yT width:w height:h) value:#LT.
cg@2744
  2300
        aTwoArgAction value:(Rectangle left:xL top:yC width:w height:h) value:#LC.
cg@2744
  2301
        aTwoArgAction value:(Rectangle left:xL top:yB width:w height:h) value:#LB.
cg@2744
  2302
        aTwoArgAction value:(Rectangle left:xC top:yT width:w height:h) value:#CT.
cg@2744
  2303
        aTwoArgAction value:(Rectangle left:xC top:yB width:w height:h) value:#CB.
cg@2744
  2304
        aTwoArgAction value:(Rectangle left:xR top:yT width:w height:h) value:#RT.
cg@2744
  2305
        aTwoArgAction value:(Rectangle left:xR top:yC width:w height:h) value:#RC.
cg@2744
  2306
        aTwoArgAction value:(Rectangle left:xR top:yB width:w height:h) value:#RB.
cg@2744
  2307
      ^ self
cg@2744
  2308
    ].
cg@2744
  2309
cg@2744
  2310
    aTwoArgAction value:(Rectangle left:xL top:yT width:w height:h) value:nil.
cg@2744
  2311
    aTwoArgAction value:(Rectangle left:xL top:yB width:w height:h) value:nil.
cg@2744
  2312
    aTwoArgAction value:(Rectangle left:xR top:yT width:w height:h) value:nil.
cg@2744
  2313
cg@2744
  2314
    type == #Extent ifTrue:[
cg@2744
  2315
        aTwoArgAction value:(Rectangle left:xC top:yB width:w height:h) value:#CB.
cg@2744
  2316
        aTwoArgAction value:(Rectangle left:xR top:yC width:w height:h) value:#RC.
cg@2744
  2317
        aTwoArgAction value:(Rectangle left:xR top:yB width:w height:h) value:#RB.
cg@2744
  2318
      ^ self
cg@2744
  2319
    ].
cg@2744
  2320
    aTwoArgAction value:(Rectangle left:xR top:yB width:w height:h) value:nil.
cg@2744
  2321
!
cg@2744
  2322
cg@2744
  2323
recursiveEachVisibleItemDo:anOneArgBlock
cg@2744
  2324
    "recursive evaluate the block on each child which is visible
cg@2744
  2325
    "
cg@2744
  2326
    (isExpanded and:[children size > 0]) ifTrue:[
cg@2744
  2327
        children do:[:aChild|
cg@2744
  2328
            anOneArgBlock value:aChild.
cg@2744
  2329
            aChild recursiveEachVisibleItemDo:anOneArgBlock.
cg@2744
  2330
        ]
cg@2744
  2331
    ].
cg@2744
  2332
!
cg@2744
  2333
cg@2744
  2334
subViewsDo:aOneArgBlock
cg@2744
  2335
    "evaluate aBlock for all subviews other than InputView's   
cg@2744
  2336
    "
cg@2744
  2337
    |subViews|
cg@2744
  2338
cg@2744
  2339
    subViews := widget subViews.
cg@2744
  2340
cg@2744
  2341
    subViews notNil ifTrue:[
cg@2744
  2342
        subViews do:aOneArgBlock
cg@2744
  2343
    ].
cg@2744
  2344
! !
cg@2744
  2345
cg@2744
  2346
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'initialization'!
cg@2744
  2347
cg@2744
  2348
forView:aView
cg@2744
  2349
    widget := aView.
cg@2744
  2350
!
cg@2744
  2351
cg@2744
  2352
initialize
cg@2744
  2353
    "setup default attributes
cg@2744
  2354
    "
cg@2744
  2355
    super initialize.
cg@2744
  2356
    isDrawnShown := false.
cg@2744
  2357
    isExpanded   := false.
cg@2744
  2358
    children     := OrderedCollection new.
cg@2744
  2359
! !
cg@2744
  2360
cg@2744
  2361
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'operations delete'!
cg@2744
  2362
cg@2744
  2363
delete
cg@2744
  2364
    "delete self and all contained items; the assigned views are destroyed
cg@2744
  2365
     in case of rootView, only the children are deleted
cg@2744
  2366
    "
cg@2744
  2367
    parent isHierarchicalItem ifTrue:[
cg@2744
  2368
        self criticalDo:[
cg@2744
  2369
            parent remove:self.
cg@2744
  2370
            widget destroy.
cg@2744
  2371
        ]
cg@2744
  2372
    ] ifFalse:[
cg@2744
  2373
        self deleteAll
cg@2744
  2374
    ].
cg@2744
  2375
!
cg@2744
  2376
cg@2744
  2377
deleteAll
cg@2744
  2378
    "delete all contained items; the assigned views are destroyed
cg@2744
  2379
    "
cg@2744
  2380
    children size == 0 ifTrue:[^ self].
cg@2744
  2381
cg@2744
  2382
    self criticalDo:[
cg@2744
  2383
        self nonCriticalDo:[:el| el widget destroy ].
cg@2744
  2384
        self removeAll
cg@2744
  2385
    ].
cg@2744
  2386
! !
cg@2744
  2387
cg@2744
  2388
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'operations layout'!
cg@2744
  2389
cg@2744
  2390
asLayoutFrame
cg@2744
  2391
    "convert the layout of the widget to a LayoutFrame;
cg@2744
  2392
    "
cg@2744
  2393
    |extent layout newLyt lftFrc lftOff topFrc topOff|
cg@2744
  2394
cg@2744
  2395
    layout := widget geometryLayout.
cg@2744
  2396
cg@2744
  2397
    layout isNil ifTrue:[
cg@2744
  2398
        ^ widget bounds asLayout
cg@2744
  2399
    ].
cg@2744
  2400
cg@2744
  2401
    layout isLayout ifFalse:[
cg@2744
  2402
        layout isRectangle ifTrue:[
cg@2744
  2403
            ^ LayoutFrame leftOffset:(layout left) rightOffset:(layout right)
cg@2744
  2404
                           topOffset:(layout top) bottomOffset:(layout bottom)
cg@2744
  2405
        ].
cg@2744
  2406
        layout isPoint ifTrue:[
cg@2744
  2407
            extent := widget extent.
cg@2744
  2408
          ^ LayoutFrame leftOffset:(layout x)  rightOffset:(layout x + extent x)
cg@2744
  2409
                         topOffset:(layout y) bottomOffset:(layout y + extent y)
cg@2744
  2410
        ].
cg@2744
  2411
cg@2744
  2412
        Transcript showCR:'UNSUPPORTRD LAYOUT: ', layout printString.
cg@2744
  2413
      ^ nil
cg@2744
  2414
    ].
cg@2744
  2415
cg@2744
  2416
    layout isLayoutFrame ifTrue:[ ^ layout copy ].    
cg@2744
  2417
cg@2744
  2418
    lftFrc := layout leftFraction.
cg@2744
  2419
    lftOff := layout leftOffset.
cg@2744
  2420
    topFrc := layout topFraction.
cg@2744
  2421
    topOff := layout topOffset.
cg@2744
  2422
    extent := widget extent.
cg@2744
  2423
cg@2744
  2424
    newLyt := LayoutFrame leftFraction:lftFrc offset:lftOff
cg@2744
  2425
                         rightFraction:lftFrc offset:(lftOff + extent x)
cg@2744
  2426
                           topFraction:topFrc offset:topOff
cg@2744
  2427
                        bottomFraction:topFrc offset:(topOff + extent y).
cg@2744
  2428
cg@2744
  2429
    (      layout isAlignmentOrigin
cg@2744
  2430
     and:[(layout leftAlignmentFraction ~= 0 or:[layout topAlignmentFraction ~= 0])]
cg@2744
  2431
    ) ifTrue:[
cg@2744
  2432
        |svRc prBd dlta|
cg@2744
  2433
cg@2744
  2434
        svRc := widget superView viewRectangle.
cg@2744
  2435
        prBd := widget preferredBounds.
cg@2744
  2436
cg@2744
  2437
        dlta := (  ((layout rectangleRelativeTo:svRc preferred:prBd) corner)
cg@2744
  2438
                 - ((newLyt rectangleRelativeTo:svRc preferred:prBd) corner)
cg@2744
  2439
                ) rounded.
cg@2744
  2440
cg@2744
  2441
        newLyt   leftOffset:(lftOff + dlta x).
cg@2744
  2442
        newLyt  rightOffset:(lftOff + extent x + dlta x).
cg@2744
  2443
        newLyt    topOffset:(topOff + dlta y).
cg@2744
  2444
        newLyt bottomOffset:(topOff + extent y + dlta y).
cg@2744
  2445
    ].
cg@2744
  2446
    ^ newLyt
cg@2744
  2447
!
cg@2744
  2448
cg@2744
  2449
moveLeft:l top:t
cg@2744
  2450
    "move the widget n pixele left and right
cg@2744
  2451
    "
cg@2744
  2452
    |layout|
cg@2744
  2453
cg@2744
  2454
    self isMoveable ifFalse:[ ^ self ].
cg@2744
  2455
cg@2744
  2456
    (layout := widget geometryLayout) isNil ifTrue:[
cg@2744
  2457
        "Extent"
cg@2744
  2458
        widget origin:(widget origin + (l@t)).
cg@2744
  2459
      ^ self
cg@2744
  2460
    ].
cg@2744
  2461
cg@2744
  2462
    layout := layout copy.
cg@2744
  2463
cg@2744
  2464
    layout isLayout ifTrue:[
cg@2744
  2465
        layout leftOffset:(layout leftOffset + l)
cg@2744
  2466
                topOffset:(layout topOffset  + t).
cg@2744
  2467
cg@2744
  2468
        layout isLayoutFrame ifTrue:[
cg@2744
  2469
            layout  rightOffset:(layout rightOffset  + l).
cg@2744
  2470
            layout bottomOffset:(layout bottomOffset + t).
cg@2744
  2471
        ]
cg@2744
  2472
cg@2744
  2473
    ] ifFalse:[
cg@2744
  2474
        layout isRectangle ifTrue:[
cg@2744
  2475
            layout setLeft:(layout left + l).
cg@2744
  2476
            layout  setTop:(layout top  + t).
cg@2744
  2477
        ] ifFalse:[
cg@2744
  2478
            layout isPoint ifFalse:[^ self].
cg@2744
  2479
            layout x:(layout x + l) y:(layout y + t).
cg@2744
  2480
        ]
cg@2744
  2481
    ].
cg@2744
  2482
    widget geometryLayout:layout.
cg@2744
  2483
!
cg@2744
  2484
cg@2744
  2485
resizeLeft:l top:t right:r bottom:b
cg@2744
  2486
    "resize the widget measured in pixels
cg@2744
  2487
    "
cg@2744
  2488
    |layout|
cg@2744
  2489
cg@2744
  2490
    self isResizeable ifFalse:[
cg@2744
  2491
        ^ self
cg@2744
  2492
    ].
cg@2744
  2493
cg@2744
  2494
    (layout := widget geometryLayout) isNil ifTrue:[
cg@2744
  2495
        "Extent"
cg@2744
  2496
        (r == l and:[b == t]) ifFalse:[
cg@2744
  2497
            widget extent:(widget computeExtent + ((r-l) @ (b-t))).
cg@2744
  2498
        ].
cg@2744
  2499
        ^ self
cg@2744
  2500
    ].
cg@2744
  2501
cg@2744
  2502
    layout isLayout ifTrue:[
cg@2744
  2503
        layout := layout copy.
cg@2744
  2504
cg@2744
  2505
        layout leftOffset:(layout leftOffset + l)
cg@2744
  2506
                topOffset:(layout topOffset  + t).
cg@2744
  2507
cg@2744
  2508
        layout isLayoutFrame ifTrue:[
cg@2744
  2509
            layout bottomOffset:(layout bottomOffset + b).
cg@2744
  2510
            layout  rightOffset:(layout rightOffset  + r).
cg@2744
  2511
        ]
cg@2744
  2512
    ] ifFalse:[
cg@2744
  2513
        layout isRectangle ifFalse:[^ self].
cg@2744
  2514
        layout := layout copy.
cg@2744
  2515
cg@2744
  2516
        layout left:(layout left   + l)
cg@2744
  2517
              right:(layout right  + r)
cg@2744
  2518
                top:(layout top    + t)
cg@2744
  2519
             bottom:(layout bottom + b).
cg@2744
  2520
    ].
cg@2744
  2521
    widget geometryLayout:layout.
cg@2744
  2522
! !
cg@2744
  2523
cg@2744
  2524
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'operations update'!
cg@2744
  2525
cg@2744
  2526
updateChildren
cg@2744
  2527
    |list|
cg@2744
  2528
cg@2744
  2529
    self do:[:el|
cg@2744
  2530
        el exists ifTrue:[
cg@2744
  2531
            el updateChildren.
cg@2744
  2532
        ] ifFalse:[
cg@2744
  2533
            list isNil ifTrue:[list := OrderedCollection new].
cg@2744
  2534
            list add:el.
cg@2744
  2535
        ]
cg@2744
  2536
    ].
cg@2744
  2537
    list notNil ifTrue:[
cg@2744
  2538
        list do:[:el| self remove:el ].
cg@2744
  2539
    ].
cg@2744
  2540
!
cg@2744
  2541
cg@2744
  2542
updateFromChildren:mergedList
cg@2744
  2543
    "update my children against the list of items derived from
cg@2744
  2544
     the merged list.
cg@2744
  2545
    "
cg@2744
  2546
cg@2744
  2547
    mergedList size == 0 ifTrue:[ ^ self removeAll ].
cg@2744
  2548
    children   size == 0 ifTrue:[ ^ self addAll:mergedList ].
cg@2744
  2549
cg@2744
  2550
    self criticalDo:[
cg@2744
  2551
        self nonCriticalDo:[:el| |wdg|
cg@2744
  2552
            wdg := el widget.
cg@2744
  2553
            mergedList detect:[:e2| e2 widget == wdg ] ifNone:[ self remove:el ].
cg@2744
  2554
        ].
cg@2744
  2555
cg@2744
  2556
        mergedList keysAndValuesDo:[:i :el| |wdg e2|
cg@2744
  2557
            wdg := el widget.
cg@2744
  2558
cg@2744
  2559
            e2  := self at:i ifAbsent:nil.
cg@2744
  2560
cg@2744
  2561
            (e2 isNil or:[e2 widget ~~ wdg]) ifTrue:[
cg@2744
  2562
                self add:el beforeIndex:i
cg@2744
  2563
            ]
cg@2744
  2564
        ]
cg@2744
  2565
    ].
cg@2744
  2566
! !
cg@2744
  2567
cg@2744
  2568
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'printing & storing'!
cg@2744
  2569
cg@2744
  2570
icon
cg@2744
  2571
    "get the icon used for presentation
cg@2744
  2572
    "
cg@2744
  2573
    |specClass model|
cg@2744
  2574
cg@2744
  2575
    specClass := self specClass.
cg@2744
  2576
    specClass isNil ifTrue:[^ nil].
cg@2744
  2577
cg@2744
  2578
    model := self treeModel.
cg@2744
  2579
cg@2744
  2580
    model notNil ifTrue:[
cg@2744
  2581
        ^ model iconAt:specClass ifNonePut:[specClass icon]
cg@2744
  2582
    ].
cg@2744
  2583
    ^ specClass icon
cg@2744
  2584
!
cg@2744
  2585
cg@2744
  2586
label
cg@2744
  2587
    "get the label used for presentation
cg@2744
  2588
    "
cg@2744
  2589
    ^ self string
cg@2744
  2590
!
cg@2744
  2591
cg@2744
  2592
printOn:aStream
cg@2744
  2593
    "append a a printed representation of the item to aStream
cg@2744
  2594
    "
cg@2744
  2595
    aStream nextPutAll:(self string)
cg@2744
  2596
!
cg@2744
  2597
cg@2744
  2598
string
cg@2744
  2599
    "get the string
cg@2744
  2600
    "
cg@2744
  2601
    ^ widget class name.
cg@2744
  2602
! !
cg@2744
  2603
cg@2744
  2604
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'queries'!
cg@2744
  2605
cg@2744
  2606
canChangeLayout
cg@2744
  2607
    "returns true if the layout of the widget can be changed and the
cg@2744
  2608
     layout is not organized by its superView
cg@2744
  2609
    "
cg@2744
  2610
    ^ self isResizeable
cg@2744
  2611
!
cg@2744
  2612
cg@2744
  2613
canResizeSubComponents
cg@2744
  2614
    "returns true if the widget can resize its sub components
cg@2744
  2615
    "
cg@2744
  2616
    |specClass|
cg@2744
  2617
cg@2744
  2618
    specClass := self specClass.
cg@2744
  2619
cg@2744
  2620
    specClass notNil ifTrue:[
cg@2744
  2621
        ^ specClass canResizeSubComponents
cg@2744
  2622
    ].
cg@2744
  2623
    ^ false
cg@2744
  2624
!
cg@2744
  2625
cg@2744
  2626
exists
cg@2744
  2627
    widget id notNil ifTrue:[^ true ].
cg@2744
  2628
cg@2744
  2629
    exists ~~ false ifTrue:[
cg@2744
  2630
        exists := false.
cg@2744
  2631
cg@2744
  2632
        widget superView notNil ifTrue:[
cg@2744
  2633
            (parent isHierarchicalItem and:[parent exists]) ifTrue:[
cg@2744
  2634
                exists := (parent widget subViews includesIdentical:widget).
cg@2744
  2635
            ].
cg@2744
  2636
        ].
cg@2744
  2637
    ].
cg@2744
  2638
    ^ exists
cg@2744
  2639
!
cg@2744
  2640
cg@2744
  2641
isApplicationClass
cg@2744
  2642
    |cls|
cg@2744
  2643
cg@2744
  2644
    cls := widget class.
cg@2744
  2645
cg@2744
  2646
    ^ (    cls == ApplicationSubView
cg@2744
  2647
        or:[cls == ApplicationWindow
cg@2744
  2648
        or:[cls == SubCanvas]]
cg@2744
  2649
      ) 
cg@2744
  2650
!
cg@2744
  2651
cg@2744
  2652
isSelected
cg@2744
  2653
    |model|
cg@2744
  2654
cg@2744
  2655
    model := self treeModel.
cg@2744
  2656
    model notNil ifTrue:[^ model isSelected:self].
cg@2744
  2657
    ^ false
cg@2744
  2658
!
cg@2744
  2659
cg@2744
  2660
supportsSubComponents
cg@2744
  2661
    "returns true if the widget supports sub components
cg@2744
  2662
    "
cg@2744
  2663
    |specClass|
cg@2744
  2664
cg@2744
  2665
    widget isScrollWrapper ifTrue:[
cg@2744
  2666
        ^ false
cg@2744
  2667
    ].
cg@2744
  2668
    specClass := self specClass.
cg@2744
  2669
cg@2744
  2670
    specClass notNil ifTrue:[
cg@2744
  2671
        ^ specClass supportsSubComponents
cg@2744
  2672
    ].
cg@2744
  2673
    ^ false
cg@2744
  2674
! !
cg@2744
  2675
cg@2744
  2676
!ViewTreeInspectorApplication::ViewTreeItem methodsFor:'testing'!
cg@2744
  2677
cg@2744
  2678
isInLayoutContainer
cg@2744
  2679
    "returns true if the widget is in a layout container
cg@2744
  2680
    "
cg@2744
  2681
    |sv specClass|
cg@2744
  2682
cg@2744
  2683
    sv := widget superView.
cg@2744
  2684
cg@2744
  2685
    sv notNil ifTrue:[
cg@2744
  2686
        specClass := sv specClass.
cg@2744
  2687
cg@2744
  2688
        specClass notNil ifTrue:[
cg@2744
  2689
            ^ specClass isLayoutContainer
cg@2744
  2690
        ].
cg@2744
  2691
    ].
cg@2744
  2692
    ^ false
cg@2744
  2693
!
cg@2744
  2694
cg@2744
  2695
isLayoutContainer
cg@2744
  2696
    "answer whether corresponding view instances of the spec class can contain
cg@2744
  2697
     (and arrange) other view
cg@2744
  2698
    "
cg@2744
  2699
    |specClass|
cg@2744
  2700
cg@2744
  2701
    specClass := self specClass.
cg@2744
  2702
cg@2744
  2703
    specClass notNil ifTrue:[
cg@2744
  2704
        ^ specClass isLayoutContainer
cg@2744
  2705
    ].
cg@2744
  2706
    ^ false
cg@2744
  2707
!
cg@2744
  2708
cg@2744
  2709
isMoveable
cg@2744
  2710
    "returns true if the widget is not in a layout container
cg@2744
  2711
    "
cg@2744
  2712
    self isInLayoutContainer ifFalse:[
cg@2744
  2713
        ^ widget superView notNil
cg@2744
  2714
    ].
cg@2744
  2715
    ^ false
cg@2744
  2716
!
cg@2744
  2717
cg@2744
  2718
isResizeable
cg@2744
  2719
    "returns true if the widget is resizeable
cg@2744
  2720
    "
cg@2744
  2721
    |sv specClass|
cg@2744
  2722
cg@2744
  2723
    sv := widget superView.
cg@2744
  2724
cg@2744
  2725
    sv notNil ifTrue:[
cg@2744
  2726
        specClass := sv specClass.
cg@2744
  2727
cg@2744
  2728
        specClass notNil ifTrue:[
cg@2744
  2729
            ^ specClass canResizeSubComponents
cg@2744
  2730
        ].
cg@2744
  2731
    ].
cg@2744
  2732
    ^ false
cg@2744
  2733
! !
cg@2744
  2734
cg@2744
  2735
!ViewTreeInspectorApplication::ViewTreeModel class methodsFor:'documentation'!
cg@2744
  2736
cg@2744
  2737
documentation
cg@2744
  2738
"
cg@2744
  2739
    Instances of ViewTreeModel can be used as model on a View and all
cg@2744
  2740
    it contained subviews for a HierarchicalListView.
cg@2744
  2741
    The model keeps two values, the hierarchical representation of the views
cg@2744
  2742
    and subviews (ViewTreeItems) and the selection, a list of selected ViewTreeItems's.
cg@2744
  2743
    It shows the selected items highlighted.
cg@2744
  2744
cg@2744
  2745
cg@2744
  2746
    [Instance variables:]
cg@2744
  2747
        lockSema            <Semaphore>         lock selection notifications and redraws
cg@2744
  2748
cg@2744
  2749
        testModeChannel     <ValueHolder>       true, than running in test mode.
cg@2744
  2750
cg@2744
  2751
        hasTargetWidgetChannel <ValueHolder>    true, than any target view is grapped
cg@2744
  2752
cg@2744
  2753
        selection           <Sequence or nil>   selected items or nil
cg@2744
  2754
cg@2744
  2755
        hiddenLevel         <Integer>           internal use; redrawing the selection
cg@2744
  2756
                                                only is done if the counter is 0.
cg@2744
  2757
cg@2744
  2758
        listOfItems         <HierarchicalList>  hiearchical list build from existing items.
cg@2744
  2759
cg@2744
  2760
        selectedSuperItems  <Sequence>          list of selected super items; items selected
cg@2744
  2761
                                                but not contained in another selected item.
cg@2744
  2762
cg@2744
  2763
        inputEventAction    <Action>            called for each InputEvent
cg@2744
  2764
cg@2744
  2765
        mappedViewAction    <Action>            called for a new mapped view which
cg@2744
  2766
                                                can not be found in the current item list.
cg@2744
  2767
cg@2744
  2768
        beforeSelectionChangedAction <Action>   called before the selection changed
cg@2744
  2769
cg@2744
  2770
    [author:]
cg@2744
  2771
        Claus Atzkern
cg@2744
  2772
cg@2744
  2773
    [see also:]
cg@2744
  2774
        ViewTreeItem
cg@2744
  2775
"
cg@2744
  2776
!
cg@2744
  2777
cg@2744
  2778
examples
cg@2744
  2779
"
cg@2744
  2780
    example 1: pick any window and show views and contained views
cg@2744
  2781
                                                                                [exBegin]
cg@2744
  2782
    |top sel model panel|
cg@2744
  2783
cg@2744
  2784
    model := ViewTreeModel new.
cg@2744
  2785
    top   := StandardSystemView new; extent:440@400.
cg@2744
  2786
    sel   := ScrollableView for:HierarchicalListView miniScroller:true origin:0.0@0.0 corner:1.0@1.0 in:top.
cg@2744
  2787
    sel bottomInset:24.
cg@2744
  2788
cg@2744
  2789
    panel := HorizontalPanelView origin:0.0@1.0 corner:1.0@1.0 in:top.
cg@2744
  2790
    panel topInset:-24.
cg@2744
  2791
    panel horizontalLayout:#fitSpace.
cg@2744
  2792
cg@2744
  2793
    Button label:'Exit'       action:[model rootItem:nil. top destroy] in:panel.
cg@2744
  2794
    Button label:'Pick Views' action:[  |win|
cg@2744
  2795
                                        (     (win := Screen current viewFromUser) notNil
cg@2744
  2796
                                         and:[(win := win topView) ~~ Screen current rootView
cg@2744
  2797