LabelAndIcon.st
changeset 726 4b3a40124f6d
parent 719 3a833ca1c54a
child 810 847d7f52a2fd
equal deleted inserted replaced
725:0e051202859d 726:4b3a40124f6d
   182 ! !
   182 ! !
   183 
   183 
   184 !LabelAndIcon class methodsFor:'instance creation'!
   184 !LabelAndIcon class methodsFor:'instance creation'!
   185 
   185 
   186 form:aForm image:anImage
   186 form:aForm image:anImage
       
   187 
   187     ^self new form:aForm image:anImage string:''
   188     ^self new form:aForm image:anImage string:''
   188 !
   189 !
   189 
   190 
   190 form:aForm image:anImage string:aString
   191 form:aForm image:anImage string:aString
       
   192 
   191     ^self new form:aForm image:anImage string:aString
   193     ^self new form:aForm image:anImage string:aString
   192 !
   194 !
   193 
   195 
   194 icon:anIcon string:aString
   196 icon:anIcon string:aString
       
   197 
   195     ^ self new icon:anIcon string:aString
   198     ^ self new icon:anIcon string:aString
   196 
   199 
   197     "Created: 12.5.1996 / 20:00:58 / cg"
   200     "Created: 12.5.1996 / 20:00:58 / cg"
   198 !
   201 !
   199 
   202 
   283 !LabelAndIcon methodsFor:'displaying'!
   286 !LabelAndIcon methodsFor:'displaying'!
   284 
   287 
   285 displayOn:aGC x:x y:y opaque:opaque
   288 displayOn:aGC x:x y:y opaque:opaque
   286     "display the receiver on a GC"
   289     "display the receiver on a GC"
   287 
   290 
   288     |yOffs yGap font fH iH fA yI xOffs|
   291     |y1 x1 iconHeight imageHeight stringHeight maxHeight gapY asc|
   289 
   292 
   290     font := aGC font on:aGC device.
   293     gapY := (aGC device pixelPerMillimeter x) rounded.
   291     fH := font height.
   294     asc  := (aGC font on:aGC device) ascent.
   292     icon isNil ifTrue:[
   295 
   293         iH := 0.
   296     iconHeight   := icon notNil     ifTrue:[icon   height]       ifFalse:[0].
   294         yGap := 0.
   297     imageHeight  := image notNil    ifTrue:[image  height]       ifFalse:[0].
   295         xOffs := 0.
   298     stringHeight := string size > 0 ifTrue:[string heightOn:aGC] ifFalse:[0].
   296     ] ifFalse:[
   299 
   297         yGap := (aGC device pixelPerMillimeter x rounded).
   300     maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight.
   298         iH := icon height + yGap.
   301     x1 := x.
   299         xOffs := icon width + gap.
       
   300     ].
       
   301     fA := font ascent.
       
   302 
       
   303     yOffs := 0.
       
   304 
   302 
   305     icon notNil ifTrue:[
   303     icon notNil ifTrue:[
   306 
   304         y1 := y - asc + (maxHeight - iconHeight + 1 // 2).
   307 "/ #ifdef OLD
       
   308 "/        iH <= fA ifTrue:[
       
   309 "/            "/ place the icon on the baseLine
       
   310 "/            yI := y-fA.
       
   311 "/ #else NEW
       
   312 
       
   313         iH <= fH ifTrue:[
       
   314             "/ place the icon centered
       
   315             yI := (fH-iH)//2 + y - fA + (yGap).
       
   316 "/ #endif NEW
       
   317         ] ifFalse:[
       
   318             iH := iH - yGap. yGap := 0. 
       
   319             iH <= fH ifTrue:[
       
   320                 "/ place the icon centered - no gap
       
   321                 yI := (fH-iH)//2 + y - fA + (yGap).
       
   322             ] ifFalse:[
       
   323                 yI := y-(fA+(font descent // 2)).
       
   324                 yOffs := (iH - fH) // 2
       
   325             ]
       
   326         ].
       
   327 
       
   328         icon := icon onDevice:aGC device.
   305         icon := icon onDevice:aGC device.
   329         (opaque 
   306 
   330         and:[icon mask isNil]) ifTrue:[
   307         (opaque and:[icon mask isNil]) ifTrue:[aGC displayOpaqueForm:icon x:x1 y:y1]
   331             aGC displayOpaqueForm:icon x:x y:yI.
   308                                       ifFalse:[aGC displayForm:icon x:x1 y:y1].
   332         ] ifFalse:[
   309 
   333             aGC displayForm:icon x:x y:yI. 
   310         x1 := x1 + icon width + gap
   334         ].
       
   335     ].
   311     ].
   336 
   312 
   337     image notNil ifTrue:[
   313     image notNil ifTrue:[
   338         iH := image height + yGap.
   314         y1 := y - asc + (maxHeight - imageHeight + 1 // 2).
   339         iH <= fH ifTrue:[
       
   340             "/ place the icon centered
       
   341             yI := (fH-iH)//2 + y - fA + (yGap).
       
   342         ] ifFalse:[
       
   343             iH := iH - yGap. yGap := 0. 
       
   344             iH <= fH ifTrue:[
       
   345                 "/ place the icon centered - no gap
       
   346                 yI := (fH-iH)//2 + y - fA + (yGap).
       
   347             ] ifFalse:[
       
   348                 yI := y-(fA+(font descent // 2)).
       
   349                 yOffs := (iH - fH) // 2
       
   350             ]
       
   351         ].
       
   352 
       
   353         image := image onDevice:aGC device.
   315         image := image onDevice:aGC device.
   354         (opaque 
   316 
   355         and:[image mask isNil]) ifTrue:[
   317         (opaque and:[image mask isNil]) ifTrue:[aGC displayOpaqueForm:image x:x1 y:y1]
   356             aGC displayOpaqueForm:image x:x + xOffs y:yI.
   318                                        ifFalse:[aGC displayForm:image x:x1 y:y1].
   357         ] ifFalse:[
   319 
   358             aGC displayForm:image x:x + xOffs y:yI. 
   320         x1 := x1 + image width + gap
   359         ].  
   321     ].
   360         xOffs := xOffs + image width + gap.
   322 
   361     ].
   323     stringHeight ~~ 0 ifTrue:[
   362     string 
   324         y1 := y + (maxHeight - stringHeight + 1 // 2).
   363         displayOn:aGC 
   325         string displayOn:aGC x:x1 y:y1
   364         x:x+xOffs
   326     ]    
   365         y:y+yOffs.
       
   366 
       
   367     "Modified: / 29.10.1997 / 03:33:29 / cg"
       
   368 ! !
   327 ! !
   369 
   328 
   370 !LabelAndIcon methodsFor:'initialization'!
   329 !LabelAndIcon methodsFor:'initialization'!
   371 
   330 
   372 initialize
   331 initialize
   395     string size > 0 ifTrue:[
   354     string size > 0 ifTrue:[
   396         stringHeight := string heightOn:aGC
   355         stringHeight := string heightOn:aGC
   397     ] ifFalse:[
   356     ] ifFalse:[
   398         stringHeight := 0   
   357         stringHeight := 0   
   399     ].
   358     ].
   400     ^ (iconHeight max: imageHeight) max: stringHeight
   359     ^ ((iconHeight max: imageHeight) max: stringHeight)
   401 !
   360 !
   402 
   361 
   403 widthOn:aGC
   362 widthOn:aGC
   404     "return the width of the receiver, if it is to be displayed on aGC"
   363     "return the width of the receiver, if it is to be displayed on aGC"
   405 
   364 
   420 ! !
   379 ! !
   421 
   380 
   422 !LabelAndIcon class methodsFor:'documentation'!
   381 !LabelAndIcon class methodsFor:'documentation'!
   423 
   382 
   424 version
   383 version
   425     ^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.19 1998-02-03 17:46:39 tz Exp $'
   384     ^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.20 1998-02-04 17:52:06 tz Exp $'
   426 ! !
   385 ! !