ListView.st
changeset 4536 c9d840b654b4
parent 4523 585ec7f5fac2
child 4570 1cce72ca7d18
equal deleted inserted replaced
4535:cf725b6f666f 4536:c9d840b654b4
   195     for TextView, EditTextView and SelectionInListView.
   195     for TextView, EditTextView and SelectionInListView.
   196 
   196 
   197     anyway, here are a few examples:
   197     anyway, here are a few examples:
   198 
   198 
   199      basic simple setup:
   199      basic simple setup:
   200 									[exBegin]
   200                                                                         [exBegin]
   201 	|top l|
   201         |top l|
   202 
   202 
   203 	top := StandardSystemView new.
   203         top := StandardSystemView new.
   204 	top extent:100@200.
   204         top extent:100@200.
   205 
   205 
   206 	l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   206         l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   207 	l list:#('one' 'two' 'three').
   207         l list:#('one' 'two' 'three').
   208 
   208 
   209 	top open
   209         top open
   210 									[exEnd]
   210                                                                         [exEnd]
   211 
   211 
   212 
   212 
   213 
   213 
   214       specifying textMargins (these have NOTHING to do with the viewInset):
   214       specifying textMargins (these have NOTHING to do with the viewInset):
   215 									[exBegin]
   215                                                                         [exBegin]
   216 	|top l|
   216         |top l|
   217 
   217 
   218 	top := StandardSystemView new.
   218         top := StandardSystemView new.
   219 	top extent:100@200.
   219         top extent:100@200.
   220 
   220 
   221 	l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   221         l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   222 	l list:#('one' 'two' 'three').
   222         l list:#('one' 'two' 'three').
   223 	l topMargin:10.
   223         l topMargin:10.
   224 	l leftMargin:20.
   224         l leftMargin:20.
   225 
   225 
   226 	top open
   226         top open
   227 									[exEnd]
   227                                                                         [exEnd]
   228 
   228 
   229 
   229 
   230 
   230 
   231       globally set the fg/bg colors:
   231       globally set the fg/bg colors:
   232 									[exBegin]
   232                                                                         [exBegin]
   233 	|top l|
   233         |top l|
   234 
   234 
   235 	top := StandardSystemView new.
   235         top := StandardSystemView new.
   236 	top extent:100@200.
   236         top extent:100@200.
   237 
   237 
   238 	l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   238         l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   239 	l list:#('one' 'two' 'three').
   239         l list:#('one' 'two' 'three').
   240 	l foregroundColor:(Color white).
   240         l foregroundColor:(Color white).
   241 	l backgroundColor:(Color blue).
   241         l backgroundColor:(Color blue).
   242 
   242 
   243 	top open
   243         top open
   244 									[exEnd]
   244                                                                         [exEnd]
   245 
   245 
   246 
   246 
   247 
   247 
   248       non-string (text) entries:
   248       non-string (text) entries:
   249 									[exBegin]
   249                                                                         [exBegin]
   250 	|top list l|
   250         |top list l|
   251 
   251 
   252 	top := StandardSystemView new.
   252         top := StandardSystemView new.
   253 	top extent:100@200.
   253         top extent:100@200.
   254 
   254 
   255 	l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   255         l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   256 	list := #('all' 'of' 'your' 'preferred' 'colors')
   256         list := #('all' 'of' 'your' 'preferred' 'colors')
   257 		with:#(red green blue 'orange' cyan)
   257                 with:#(red green blue 'orange' cyan)
   258 		collect:[:s :clr |
   258                 collect:[:s :clr |
   259 			    Text string:s
   259                             Text string:s
   260 				 emphasis:(Array with:#bold
   260                                  emphasis:(Array with:#bold
   261 						 with:(#color->(Color name:clr))) ].
   261                                                  with:(#color->(Color name:clr))) ].
   262 	l list:list.
   262         l list:list.
   263 
   263 
   264 	top open
   264         top open
   265 									[exEnd]
   265                                                                         [exEnd]
   266 
   266 
   267 
   267 
   268 
   268 
   269       generic non-string entries:
   269       generic non-string entries:
   270       (notice: ColoredListEntry is obsoleted by Text)
   270       (notice: ColoredListEntry is obsoleted by Text)
   271 									[exBegin]
   271                                                                         [exBegin]
   272 	|top list l|
   272         |top list l|
   273 
   273 
   274 	top := StandardSystemView new.
   274         top := StandardSystemView new.
   275 	top extent:100@200.
   275         top extent:100@200.
   276 
   276 
   277 	l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   277         l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   278 	list := #('all' 'of' 'your' 'preferred' 'colors')
   278         list := #('all' 'of' 'your' 'preferred' 'colors')
   279 		with:#(red green blue 'orange' cyan)
   279                 with:#(red green blue 'orange' cyan)
   280 		collect:[:s :clr | ColoredListEntry string:s color:(Color name:clr) ].
   280                 collect:[:s :clr | ColoredListEntry string:s color:(Color name:clr) ].
   281 	l list:list.
   281         l list:list.
   282 
   282 
   283 	top open
   283         top open
   284 									[exEnd]
   284                                                                         [exEnd]
   285 
   285 
   286 
   286 
   287 
   287 
   288       using a model (default listMessage is aspectMessage):
   288       using a model (default listMessage is aspectMessage):
   289 									[exBegin]
   289                                                                         [exBegin]
   290 	|top model l theModelsText|
   290         |top model l theModelsText|
   291 
   291 
   292 	model := Plug new.
   292         model := Plug new.
   293 	model respondTo:#modelsAspect
   293         model respondTo:#modelsAspect
   294 		   with:[ theModelsText ].
   294                    with:[ theModelsText ].
   295 
   295 
   296 	top := StandardSystemView new.
   296         top := StandardSystemView new.
   297 	top extent:100@200.
   297         top extent:100@200.
   298 
   298 
   299 	l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   299         l := ListView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
   300 	l model:model.
   300         l model:model.
   301 	l aspect:#modelsAspect.
   301         l aspect:#modelsAspect.
   302 
   302 
   303 	top open.
   303         top open.
   304 
   304 
   305 	Delay waitForSeconds:3.
   305         Delay waitForSeconds:3.
   306 	theModelsText := #('foo' 'bar' 'baz').
   306         theModelsText := #('foo' 'bar' 'baz').
   307 	model changed:#modelsAspect.
   307         model changed:#modelsAspect.
   308 									[exEnd]
   308                                                                         [exEnd]
   309 
   309 
   310 
   310 
   311 
   311 
   312       using a model with different aspects
   312       using a model with different aspects
   313       for two listViews:
   313       for two listViews:
   314 									[exBegin]
   314                                                                         [exBegin]
   315 	|top model l1 l2 plainText|
   315         |top model l1 l2 plainText|
   316 
   316 
   317 	plainText := #('').
   317         plainText := #('').
   318 
   318 
   319 	model := Plug new.
   319         model := Plug new.
   320 	model respondTo:#modelsUppercaseText
   320         model respondTo:#modelsUppercaseText
   321 		   with:[ plainText asStringCollection
   321                    with:[ plainText asStringCollection
   322 			      collect:[:l | l asUppercase]].
   322                               collect:[:l | l asUppercase]].
   323 	model respondTo:#modelsLowercaseText
   323         model respondTo:#modelsLowercaseText
   324 		   with:[ plainText asStringCollection
   324                    with:[ plainText asStringCollection
   325 			      collect:[:l | l asLowercase]].
   325                               collect:[:l | l asLowercase]].
   326 
   326 
   327 	top := StandardSystemView extent:200@200.
   327         top := StandardSystemView extent:200@200.
   328 
   328 
   329 	l1 := ListView origin:0.0 @ 0.0 corner:1.0 @ 0.5 in:top.
   329         l1 := ListView origin:0.0 @ 0.0 corner:1.0 @ 0.5 in:top.
   330 	l1 model:model.
   330         l1 model:model.
   331 	l1 aspect:#modelsAspect.
   331         l1 aspect:#modelsAspect.
   332 	l1 listMessage:#modelsUppercaseText.
   332         l1 listMessage:#modelsUppercaseText.
   333 
   333 
   334 	l2 := ListView origin:0.0 @ 0.5 corner:1.0 @ 1.0 in:top.
   334         l2 := ListView origin:0.0 @ 0.5 corner:1.0 @ 1.0 in:top.
   335 	l2 model:model.
   335         l2 model:model.
   336 	l2 aspect:#modelsAspect.
   336         l2 aspect:#modelsAspect.
   337 	l2 listMessage:#modelsLowercaseText.
   337         l2 listMessage:#modelsLowercaseText.
   338 
   338 
   339 	top open.
   339         top open.
   340 
   340 
   341 	Delay waitForSeconds:3.
   341         Delay waitForSeconds:3.
   342 	plainText := #('foo' 'bar' 'baz').
   342         plainText := #('foo' 'bar' 'baz').
   343 	model changed:#modelsAspect.
   343         model changed:#modelsAspect.
   344 									[exEnd]
   344                                                                         [exEnd]
   345 
   345 
   346       using a big list (100000 lines):
   346       using a big list (100000 lines),
   347 									[exBegin]
   347       wrapping in a ScrollableView:
   348 	|bigList top lv|
   348                                                                         [exBegin]
   349 
   349         |bigList top lv|
   350 	bigList := (1 to:100000) collect:[:lineNr | 'List line Nr. ' , lineNr printString].
   350 
   351 
   351         bigList := (1 to:100000) collect:[:lineNr | 'List line Nr. ' , lineNr printString].
   352 	top := StandardSystemView extent:200@200.
   352         bigList at:10 put:('Some Text ' asText , 'with Bold part' allBold).
   353 
   353         bigList at:20 put:('Some Text ' asText , 'with Italic part' allItalic).
   354 	lv := ScrollableView for:ListView in:top.
   354 
   355 	lv origin:0.0 @ 0.0 corner:1.0 @ 1.0.
   355         top := StandardSystemView extent:200@200.
   356 	lv list:bigList expandTabs:false scanForNonStrings:false includesNonStrings:false.
   356 
   357 
   357         lv := HVScrollableView for:ListView in:top.
   358 	top open.
   358         lv origin:0.0 @ 0.0 corner:1.0 @ 1.0.
   359 									[exEnd]
   359         lv list:bigList expandTabs:false scanForNonStrings:false includesNonStrings:false.
   360 
   360 
   361       using a huge virtual list (1 mio simulated lines):
   361         top open.
   362 									[exBegin]
   362                                                                         [exEnd]
   363 	|virtualList top lv|
   363 
   364 
   364       using a huge virtual list (1 mio simulated lines),
   365 	virtualList := Plug new.
   365       wrapping in a ScrollableView:
   366 	virtualList inheritFrom:SequenceableCollection.
   366                                                                         [exBegin]
   367 	virtualList respondTo:#size with:[ 1000000 ].
   367         |virtualList top lv|
   368 	virtualList respondTo:#at:  with:[:lineNr | 'List line Nr. ' , lineNr printString ].
   368 
   369 
   369         virtualList := Plug new.
   370 	top := StandardSystemView extent:200@200.
   370         virtualList inheritFrom:SequenceableCollection.
   371 
   371         virtualList respondTo:#size with:[ 1000000 ].
   372 	lv := ScrollableView for:ListView in:top.
   372         virtualList respondTo:#at:  with:[:lineNr | 'List line Nr. ' , lineNr printString ].
   373 	lv origin:0.0 @ 0.0 corner:1.0 @ 1.0.
   373 
   374 	lv list:virtualList expandTabs:false scanForNonStrings:false includesNonStrings:false.
   374         top := StandardSystemView extent:200@200.
   375 
   375 
   376 	top open.
   376         lv := ScrollableView for:ListView in:top.
   377 									[exEnd]
   377         lv origin:0.0 @ 0.0 corner:1.0 @ 1.0.
   378 
   378         lv list:virtualList expandTabs:false scanForNonStrings:false includesNonStrings:false.
       
   379 
       
   380         top open.
       
   381                                                                         [exEnd]
   379 "
   382 "
   380 ! !
   383 ! !
   381 
   384 
   382 !ListView class methodsFor:'defaults'!
   385 !ListView class methodsFor:'defaults'!
   383 
   386 
  2096     self paint:bgColor.
  2099     self paint:bgColor.
  2097     self fillRectangleX:x y:y width:w height:h.
  2100     self fillRectangleX:x y:y width:w height:h.
  2098     backgroundAlreadyClearedColor := bgColor.
  2101     backgroundAlreadyClearedColor := bgColor.
  2099 
  2102 
  2100     (includesNonStrings or:[w > (width // 4 * 3)]) ifTrue:[
  2103     (includesNonStrings or:[w > (width // 4 * 3)]) ifTrue:[
  2101 	"includes non strings or area is big enough redraw whole lines"
  2104         "includes non strings or area is big enough redraw whole lines"
  2102 	self redrawFromVisibleLine:startLine to:stopLine
  2105         self redrawFromVisibleLine:startLine to:stopLine
  2103     ] ifFalse:[
  2106     ] ifFalse:[
  2104 	line := self visibleAt:startLine.
  2107         line := self visibleAt:startLine.
  2105 
  2108 
  2106 	(fontIsFixedWidth and:[line isMemberOf:String]) ifFalse:[
  2109         (fontIsFixedWidth and:[line isMemberOf:String]) ifFalse:[
  2107 	    "start/end col has to be computed for each line"
  2110             "start/end col has to be computed for each line"
  2108 
  2111 
  2109 	    startLine to:stopLine do:[:i |
  2112             startLine to:stopLine do:[:i |
  2110 		startCol := self colOfX:x inVisibleLine:i.
  2113                 startCol := self colOfX:x inVisibleLine:i.
  2111 		endCol := self colOfX:(x + w) inVisibleLine:i.
  2114                 endCol := self colOfX:(x + w) inVisibleLine:i.
  2112 		startCol > 0 ifTrue:[
  2115                 startCol > 0 ifTrue:[
  2113 		    endCol > 0 ifTrue:[
  2116                     endCol > 0 ifTrue:[
  2114 			self redrawVisibleLine:i from:startCol to:endCol
  2117                         self redrawVisibleLine:i from:startCol to:endCol
  2115 		    ]
  2118                     ]
  2116 		]
  2119                 ]
  2117 	    ]
  2120             ]
  2118 	] ifTrue:[
  2121         ] ifTrue:[
  2119 	    "start/end col is the same for all lines"
  2122             "start/end col is the same for all lines"
  2120 	    startCol := self colOfX:x inVisibleLine:startLine.
  2123             startCol := self colOfX:x inVisibleLine:startLine.
  2121 	    endCol := self colOfX:(x + w) inVisibleLine:startLine.
  2124             endCol := self colOfX:(x + w) inVisibleLine:startLine.
  2122 	    startCol > 0 ifTrue:[
  2125             startCol > 0 ifTrue:[
  2123 		endCol > 0 ifTrue:[
  2126                 endCol > 0 ifTrue:[
  2124 		    startLine to:stopLine do:[:i |
  2127                     startLine to:stopLine do:[:i |
  2125 			line := self visibleAt:i.
  2128                         line := self visibleAt:i.
  2126 			(line isMemberOf:String) ifTrue:[
  2129                         (line isMemberOf:String) ifTrue:[
  2127 			    self redrawVisibleLine:i from:startCol to:endCol
  2130                             self redrawVisibleLine:i from:startCol to:endCol
  2128 			] ifFalse:[
  2131                         ] ifFalse:[
  2129 			    self redrawVisibleLine:i
  2132                             self redrawVisibleLine:i
  2130 			]
  2133                         ]
  2131 		    ]
  2134                     ]
  2132 		]
  2135                 ]
  2133 	    ]
  2136             ]
  2134 	]
  2137         ]
  2135     ].
  2138     ].
  2136     backgroundAlreadyClearedColor := nil.
  2139     backgroundAlreadyClearedColor := nil.
  2137     self clippingRectangle:saveClip.
  2140     self clippingRectangle:saveClip.
  2138 !
  2141 !
  2139 
  2142 
  4030     ].
  4033     ].
  4031 
  4034 
  4032     (x == 0 and:[y == 0]) ifTrue:[                              "/ has viewOrigin changed ?
  4035     (x == 0 and:[y == 0]) ifTrue:[                              "/ has viewOrigin changed ?
  4033         ^ self
  4036         ^ self
  4034     ].
  4037     ].
  4035 
       
  4036 
  4038 
  4037     (noLn := y) ~~ 0 ifTrue:[
  4039     (noLn := y) ~~ 0 ifTrue:[
  4038         y := y * fontHeight
  4040         y := y * fontHeight
  4039     ].
  4041     ].
  4040     delta := (x @ y).
  4042     delta := (x @ y).
  4855 ! !
  4857 ! !
  4856 
  4858 
  4857 !ListView class methodsFor:'documentation'!
  4859 !ListView class methodsFor:'documentation'!
  4858 
  4860 
  4859 version
  4861 version
  4860     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.359 2013-02-25 14:58:23 cg Exp $'
  4862     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.360 2013-03-20 10:35:25 cg Exp $'
  4861 !
  4863 !
  4862 
  4864 
  4863 version_CVS
  4865 version_CVS
  4864     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.359 2013-02-25 14:58:23 cg Exp $'
  4866     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.360 2013-03-20 10:35:25 cg Exp $'
  4865 ! !
  4867 ! !
  4866 
  4868