ListView.st
changeset 1990 b0e6f2a8419e
parent 1985 3abfcfd15cbf
child 2082 d3ccb78e8c03
equal deleted inserted replaced
1989:f9b3c2a361eb 1990:b0e6f2a8419e
   389 
   389 
   390     aFont isNil ifTrue:[
   390     aFont isNil ifTrue:[
   391         ^ self error:'nil font' mayProceed:true
   391         ^ self error:'nil font' mayProceed:true
   392     ].
   392     ].
   393     font ~~ aFont ifTrue:[
   393     font ~~ aFont ifTrue:[
   394         super font:(aFont on:device).
   394         super font:(aFont onDevice:device).
   395         preferredExtent := nil.
   395         preferredExtent := nil.
   396         widthOfWidestLine := nil. "/ i.e. unknown
   396         widthOfWidestLine := nil. "/ i.e. unknown
   397         self getFontParameters.
   397         self getFontParameters.
   398         realized ifTrue:[
   398         realized ifTrue:[
   399             (font graphicsDevice == device) ifTrue:[
   399             (font graphicsDevice == device) ifTrue:[
  1664     super create.
  1664     super create.
  1665 
  1665 
  1666     "I cache font parameters here - they are used so often ..."
  1666     "I cache font parameters here - they are used so often ..."
  1667     self getFontParameters.
  1667     self getFontParameters.
  1668     self computeNumberOfLinesShown.
  1668     self computeNumberOfLinesShown.
  1669     fgColor := fgColor on:device.
  1669     fgColor := fgColor onDevice:device.
  1670     bgColor := bgColor on:device
  1670     bgColor := bgColor onDevice:device
  1671 !
  1671 !
  1672 
  1672 
  1673 defaultControllerClass
  1673 defaultControllerClass
  1674     self class == ListView ifTrue:[^ ListViewController].
  1674     self class == ListView ifTrue:[^ ListViewController].
  1675     ^ super defaultControllerClass
  1675     ^ super defaultControllerClass
  1678 fetchDeviceResources
  1678 fetchDeviceResources
  1679     "fetch device colors, to avoid reallocation at redraw time"
  1679     "fetch device colors, to avoid reallocation at redraw time"
  1680 
  1680 
  1681     super fetchDeviceResources.
  1681     super fetchDeviceResources.
  1682 
  1682 
  1683     fgColor notNil ifTrue:[fgColor := fgColor on:device].
  1683     fgColor notNil ifTrue:[fgColor := fgColor onDevice:device].
  1684     bgColor notNil ifTrue:[bgColor := bgColor on:device].
  1684     bgColor notNil ifTrue:[bgColor := bgColor onDevice:device].
  1685 
  1685 
  1686     "Created: 14.1.1997 / 00:12:12 / cg"
  1686     "Created: 14.1.1997 / 00:12:12 / cg"
  1687 !
  1687 !
  1688 
  1688 
  1689 initStyle
  1689 initStyle
  2028      Therefore, this method should be redefined in views which will be used
  2028      Therefore, this method should be redefined in views which will be used
  2029      with national characters (i.e. editTextViews)."
  2029      with national characters (i.e. editTextViews)."
  2030 
  2030 
  2031     |hMax|
  2031     |hMax|
  2032 
  2032 
  2033     font := font on:device.
  2033     font := font onDevice:device.
  2034     hMax := font height.
  2034     hMax := font height.
  2035 
  2035 
  2036     includesNonStrings == true ifTrue:[
  2036     includesNonStrings == true ifTrue:[
  2037 	"/
  2037         "/
  2038 	"/ find maximum height of lines
  2038         "/ find maximum height of lines
  2039 	"/
  2039         "/
  2040 	hMax := list inject:hMax into:[:maxSoFar :thisLine | 
  2040         hMax := list inject:hMax into:[:maxSoFar :thisLine | 
  2041 					thisLine isNil ifTrue:[
  2041                                         thisLine isNil ifTrue:[
  2042 					    maxSoFar
  2042                                             maxSoFar
  2043 					] ifFalse:[
  2043                                         ] ifFalse:[
  2044 					    (thisLine isMemberOf:String) ifTrue:[
  2044                                             (thisLine isMemberOf:String) ifTrue:[
  2045 						maxSoFar
  2045                                                 maxSoFar
  2046 					    ] ifFalse:[   
  2046                                             ] ifFalse:[   
  2047 						maxSoFar max:(thisLine heightOn:self)
  2047                                                 maxSoFar max:(thisLine heightOn:self)
  2048 					    ]
  2048                                             ]
  2049 					]
  2049                                         ]
  2050 			      ].
  2050                               ].
  2051 
  2051 
  2052     ].
  2052     ].
  2053     fontHeight := hMax + lineSpacing.
  2053     fontHeight := hMax + lineSpacing.
  2054     fontAscent := font ascent. "/ maxAscent.
  2054     fontAscent := font ascent. "/ maxAscent.
  2055     fontWidth := font width.
  2055     fontWidth := font width.
  2427 
  2427 
  2428 heightForLines:numberOfLines
  2428 heightForLines:numberOfLines
  2429     "return the height of the receiver, if numberOfLines are to be displayed"
  2429     "return the height of the receiver, if numberOfLines are to be displayed"
  2430 
  2430 
  2431     "need a device font for query"
  2431     "need a device font for query"
  2432     font := font on:device.
  2432     font := font onDevice:device.
  2433     ^ numberOfLines * fontHeight + topMargin + font descent + (lineSpacing) + (margin * 2)
  2433     ^ numberOfLines * fontHeight + topMargin + font descent + (lineSpacing) + (margin * 2)
  2434 
  2434 
  2435     "Created: 27.1.1996 / 16:55:39 / cg"
  2435     "Created: 27.1.1996 / 16:55:39 / cg"
  2436 !
  2436 !
  2437 
  2437 
  2451 "/        numLines := numLines + 1
  2451 "/        numLines := numLines + 1
  2452 "/    ].
  2452 "/    ].
  2453     "
  2453     "
  2454      need device-font for query
  2454      need device-font for query
  2455     "
  2455     "
  2456     font := font on:device.
  2456     font := font onDevice:device.
  2457     ^ numLines * fontHeight 
  2457     ^ numLines * fontHeight 
  2458 "/                            + textStartTop
  2458 "/                            + textStartTop
  2459                             - (lineSpacing // 2)
  2459                             - (lineSpacing // 2)
  2460                             + (font descent)
  2460                             + (font descent)
  2461 "/                            + (font descent)       
  2461 "/                            + (font descent)       
  2566 
  2566 
  2567 widthOfContents
  2567 widthOfContents
  2568     "return the width of the contents in pixels
  2568     "return the width of the contents in pixels
  2569      - used for scrollbar interface"
  2569      - used for scrollbar interface"
  2570 
  2570 
  2571     |max f|
  2571     |max f d|
  2572 
  2572 
  2573     list isNil ifTrue:[^ 0].
  2573     list isNil ifTrue:[^ 0].
  2574     widthOfWidestLine notNil ifTrue:[^ widthOfWidestLine + (leftMargin * 2)].
  2574     widthOfWidestLine notNil ifTrue:[^ widthOfWidestLine + (leftMargin * 2)].
  2575 
  2575 
  2576     device isNil ifTrue:[
  2576     (d := device) isNil ifTrue:[
  2577 	"/ mhmh - really dont know yet
  2577         "/ mhmh - really dont know yet
  2578 	f := font on:Screen current
  2578         d := Screen current
       
  2579     ].
       
  2580     f := font := font onDevice:d.
       
  2581 
       
  2582     includesNonStrings ifTrue:[
       
  2583         max := list 
       
  2584                    inject:0 
       
  2585                    into:[:maxSoFar :entry |
       
  2586                              (
       
  2587                                  entry isNil ifTrue:[
       
  2588                                      0
       
  2589                                  ] ifFalse:[
       
  2590                                     entry isString ifTrue:[
       
  2591                                         f widthOf:entry
       
  2592                                     ] ifFalse:[
       
  2593                                         entry widthOn:self
       
  2594                                     ]
       
  2595                                  ]
       
  2596                              ) max:maxSoFar.
       
  2597                         ]
  2579     ] ifFalse:[
  2598     ] ifFalse:[
  2580 	f := font := font on:device.
  2599         false "fontIsFixedWidth" ifTrue:[
  2581     ].
  2600             max := self lengthOfLongestLine * fontWidth
  2582 
  2601         ] ifFalse:[
  2583     includesNonStrings ifTrue:[
  2602             max := 0.
  2584 	max := list 
  2603             list notNil ifTrue:[
  2585 		   inject:0 
  2604                 list do:[:line |
  2586 		   into:[:maxSoFar :entry |
  2605                     line notNil ifTrue:[
  2587 			     (
  2606                         max := max max:(line widthOn:self)
  2588 				 entry isNil ifTrue:[
  2607                     ]
  2589 				     0
  2608                 ].
  2590 				 ] ifFalse:[
       
  2591 				    entry isString ifTrue:[
       
  2592 					f widthOf:entry
       
  2593 				    ] ifFalse:[
       
  2594 					entry widthOn:self
       
  2595 				    ]
       
  2596 				 ]
       
  2597 			     ) max:maxSoFar.
       
  2598 			]
       
  2599     ] ifFalse:[
       
  2600 	false "fontIsFixedWidth" ifTrue:[
       
  2601 	    max := self lengthOfLongestLine * fontWidth
       
  2602 	] ifFalse:[
       
  2603 	    max := 0.
       
  2604 	    list notNil ifTrue:[
       
  2605 		list do:[:line |
       
  2606 		    line notNil ifTrue:[
       
  2607 			max := max max:(line widthOn:self)
       
  2608 		    ]
       
  2609 		].
       
  2610 "/                max := max max:(f widthOf:list)
  2609 "/                max := max max:(f widthOf:list)
  2611 	    ].
  2610             ].
  2612 	].
  2611         ].
  2613     ].
  2612     ].
  2614     widthOfWidestLine := max.
  2613     widthOfWidestLine := max.
  2615     ^ max + (leftMargin * 2)
  2614     ^ max + (leftMargin * 2)
  2616 
  2615 
  2617     "Modified: / 24.9.1998 / 18:21:08 / cg"
  2616     "Modified: / 24.9.1998 / 18:21:08 / cg"
  2618 !
  2617 !
  2619 
  2618 
  2620 widthOfLine:lineNr
  2619 widthOfLine:lineNr
  2621     "return the width of a line in pixels"
  2620     "return the width of a line in pixels"
  2622 
  2621 
  2623     |line f|
  2622     |line f d|
  2624 
  2623 
  2625     list isNil ifTrue:[^ 0].
  2624     list isNil ifTrue:[^ 0].
  2626     lineNr > list size ifTrue:[^ 0].
  2625     lineNr > list size ifTrue:[^ 0].
  2627     line := list at:lineNr.
  2626     line := list at:lineNr.
  2628     list isNil ifTrue:[^ 0].
  2627     list isNil ifTrue:[^ 0].
  2629 
  2628 
  2630     device isNil ifTrue:[
  2629     (d := device) isNil ifTrue:[
  2631 	"/ mhmh - really dont know yet
  2630         "/ mhmh - really dont know yet
  2632 	f := font on:Screen current
  2631         d := Screen current
  2633     ] ifFalse:[
  2632     ].
  2634 	f := font := font on:device.
  2633     f := font := font onDevice:d.
  2635     ].
       
  2636 
  2634 
  2637     line isString ifTrue:[
  2635     line isString ifTrue:[
  2638 	^ f widthOf:line
  2636         ^ f widthOf:line
  2639     ].
  2637     ].
  2640     ^ line widthOn:self
  2638     ^ line widthOn:self
  2641 
  2639 
  2642     "Created: / 10.11.1998 / 23:59:20 / cg"
  2640     "Created: / 10.11.1998 / 23:59:20 / cg"
  2643     "Modified: / 11.11.1998 / 15:25:07 / cg"
  2641     "Modified: / 11.11.1998 / 15:25:07 / cg"
  3918 ! !
  3916 ! !
  3919 
  3917 
  3920 !ListView class methodsFor:'documentation'!
  3918 !ListView class methodsFor:'documentation'!
  3921 
  3919 
  3922 version
  3920 version
  3923     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.212 1999-08-12 14:08:21 cg Exp $'
  3921     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.213 1999-08-18 14:42:04 cg Exp $'
  3924 ! !
  3922 ! !