DSVLabelView.st
changeset 907 3250a67fcce2
parent 893 7e52a293a3da
child 1085 cebea5318863
equal deleted inserted replaced
906:6173137343de 907:3250a67fcce2
    20 	poolDictionaries:''
    20 	poolDictionaries:''
    21 	category:'Views-DataSet'
    21 	category:'Views-DataSet'
    22 !
    22 !
    23 
    23 
    24 Object subclass:#Item
    24 Object subclass:#Item
    25 	instanceVariableNames:'label selector argument isDrawable adjust font fgColor bgColor
    25 	instanceVariableNames:'label selector argument adjust font fgColor bgColor layout
    26 		layout preferredExtent'
    26 		preferredExtent'
    27 	classVariableNames:'DefaultLayout'
    27 	classVariableNames:'DefaultLayout'
    28 	poolDictionaries:''
    28 	poolDictionaries:''
    29 	privateIn:DSVLabelView
    29 	privateIn:DSVLabelView
    30 !
    30 !
    31 
    31 
   167     savClip := clipRect.
   167     savClip := clipRect.
   168 
   168 
   169     self clippingRectangle:(Rectangle left:x top:y width:w height:h).
   169     self clippingRectangle:(Rectangle left:x top:y width:w height:h).
   170 
   170 
   171     items do:[:anItem|
   171     items do:[:anItem|
   172         anItem isDrawable ifTrue:[
   172         layout := anItem layout.
   173             layout := anItem layout.
   173         left   := layout left.
   174             left   := layout left.
   174         width  := layout width.
   175             width  := layout width.
   175 
   176 
   176         (left < maxX and:[layout right > x]) ifTrue:[
   177             (left < maxX and:[layout right > x]) ifTrue:[
   177             (bg := anItem backgroundColor) notNil ifTrue:[
   178                 (bg := anItem backgroundColor) notNil ifTrue:[
   178                 bg ~= bgColor ifTrue:[
   179                     bg ~= bgColor ifTrue:[
   179                     self paint:bg.
   180                         self paint:bg.
   180                     self fillRectangleX:left y:y width:width height:h.
   181                         self fillRectangleX:left y:y width:width height:h.
   181                 ]
   182                     ]
   182             ] ifFalse:[
   183                 ] ifFalse:[
   183                 bg := bgColor
   184                     bg := bgColor
   184             ].
   185                 ].
   185 
   186 
   186             fg := (anItem foregroundColor) ? fgColor.
   187                 fg := (anItem foregroundColor) ? fgColor.
   187             lv := selection == anItem ifTrue:[actLvl] ifFalse:[pasLvl].
   188                 lv := selection == anItem ifTrue:[actLvl] ifFalse:[pasLvl].
   188             self paint:fg on:bg.
   189                 self paint:fg on:bg.
   189             anItem redrawLabelOn:self hInset:inset + (lv abs).
   190                 anItem redrawLabelOn:self hInset:inset + (lv abs).
   190             columnView drawEdgesAtX:left y:0 width:width height:height level:lv on:self
   191                 columnView drawEdgesAtX:left y:0 width:width height:height level:lv on:self
       
   192             ]
       
   193         ]
   191         ]
   194     ].
   192     ].
   195     self clippingRectangle:savClip.
   193     self clippingRectangle:savClip.
   196 
   194 
   197 
   195 
   308 !
   306 !
   309 
   307 
   310 columnsSizeChanged
   308 columnsSizeChanged
   311     "the list of columns changed; recreate all items
   309     "the list of columns changed; recreate all items
   312     "
   310     "
   313     |height font lastCol prevCol|
   311     |height font|
   314 
   312 
   315     items   := OrderedCollection new.
   313     items := OrderedCollection new.
   316     font    := columnView font.
   314 
   317     height  := 0.
   315     columnView numberOfColumns ~~ 0 ifTrue:[
   318 
   316         font   := columnView font.
   319     columnView numberOfColumns == 0 ifTrue:[
   317         height := 0.
   320         ^ self redraw
   318 
   321     ].
   319         columnView columnsDo:[:aColumn||item|
   322     lastCol := columnView lastColumn.
   320             items add:(item := Item column:aColumn font:font on:self).
   323     prevCol := nil.
   321             height := (item preferredExtent y) max:height.
   324 
   322         ].
   325     columnView columnsDo:[:aColumn||item|
   323         height := height + self class verticalInset.
   326         items add:(item := Item column:aColumn font:font on:self).
   324         self updateLayoutsHeight:height.
   327 
   325         self bottomInset:height negated.
   328         item isDrawable ifTrue:[
   326     ].
   329             height  := (item preferredExtent y) max:height.
       
   330             prevCol := aColumn showColSeparator ifTrue:[nil] ifFalse:[aColumn].
       
   331         ] ifFalse:[
       
   332             prevCol isNil ifTrue:[
       
   333                 (aColumn == lastCol or:[aColumn showColSeparator]) ifTrue:[
       
   334                     prevCol := nil.
       
   335                     item makeDrawable.
       
   336                 ]
       
   337             ]
       
   338         ]
       
   339     ].
       
   340     height := height + self class verticalInset.
       
   341 
       
   342     self updateLayoutsHeight:height.
       
   343     self bottomInset:height negated.
       
   344     self redraw.
   327     self redraw.
   345 
   328 
   346 ! !
   329 ! !
   347 
   330 
   348 !DSVLabelView methodsFor:'private'!
   331 !DSVLabelView methodsFor:'private'!
   358 !
   341 !
   359 
   342 
   360 updateLayoutsHeight:h
   343 updateLayoutsHeight:h
   361     "update the rectangle layout for each item based on a height
   344     "update the rectangle layout for each item based on a height
   362     "
   345     "
   363     |idx x0 x1 x col|
   346     |i x w|
   364 
   347 
   365     idx := 1.
   348     i := 1.
   366     x1  := 0.
   349     x := columnView margin - columnView xOriginOfContents.
   367     x1  := columnView has3Dseparators ifTrue:[0] ifFalse:[1].
   350     columnView has3Dseparators ifFalse:[ x := x + 1].
   368     x0  := columnView margin - columnView xOriginOfContents.
   351 
   369     col := nil.
   352     columnView columnsDo:[:aCol|
   370 
   353         w := aCol width.
   371     columnView columnsDo:[:aCol||itm w|
   354         (items at:i) layout:(Rectangle origin:(x @ 0) extent:(w @ h)).
   372         w   := aCol width.
   355         i := i + 1.
   373         x1  := x1 + w.
   356         x := x + w.
   374         itm := items at:idx.
   357     ].
   375         idx := idx + 1.
       
   376 
       
   377         (itm isDrawable or:[aCol showColSeparator]) ifTrue:[
       
   378             col notNil ifTrue:[
       
   379                 itm isDrawable ifTrue:[
       
   380                     x  := x1 - w.
       
   381                     x1 := w.
       
   382                 ] ifFalse:[
       
   383                     x  := x1.
       
   384                     x1 := 0
       
   385                 ].
       
   386                 col layout:(Rectangle origin:(x0 @ 0) extent:(x @ h)).
       
   387                 x0  := x0 + x.
       
   388                 col := nil.
       
   389             ].
       
   390 
       
   391             itm isDrawable ifTrue:[
       
   392                 col := itm.
       
   393             ]
       
   394         ]
       
   395     ].
       
   396 
       
   397     col notNil ifTrue:[
       
   398         col layout:(Rectangle origin:(x0 @ 0) extent:(x1 @ h)).
       
   399     ].
       
   400 
       
   401 
       
   402 
       
   403 ! !
   358 ! !
   404 
   359 
   405 !DSVLabelView::Item class methodsFor:'constants'!
   360 !DSVLabelView::Item class methodsFor:'constants'!
   406 
   361 
   407 defaultLayout
   362 defaultLayout
   428         selector        <Symbol>        a selector, which is evaluated with the argument
   383         selector        <Symbol>        a selector, which is evaluated with the argument
   429                                         if the item is selected and the button is released.
   384                                         if the item is selected and the button is released.
   430 
   385 
   431         argument        <Object>        user defined argument for the selector.
   386         argument        <Object>        user defined argument for the selector.
   432 
   387 
   433         isDrawable      <Boolean>       computed: is the label drawable
       
   434 
       
   435         adjust          <Symbol>        align label left, right or center; default is center
   388         adjust          <Symbol>        align label left, right or center; default is center
   436 
   389 
   437         font            <Font>          font used to dispaly the label; if the font is
   390         font            <Font>          font used to dispaly the label; if the font is
   438                                         undefined, the default font is used.
   391                                         undefined, the default font is used.
   439 
   392 
   514 
   467 
   515 
   468 
   516 ! !
   469 ! !
   517 
   470 
   518 !DSVLabelView::Item methodsFor:'actions'!
   471 !DSVLabelView::Item methodsFor:'actions'!
   519 
       
   520 makeDrawable
       
   521     "make the item drawable
       
   522     "
       
   523     isDrawable := true
       
   524 
       
   525 
       
   526 !
       
   527 
   472 
   528 sendClickMsgTo:aReceiver
   473 sendClickMsgTo:aReceiver
   529     "inform the receiver of a button release notification
   474     "inform the receiver of a button release notification
   530     "
   475     "
   531     (aReceiver notNil and:[selector notNil]) ifTrue:[
   476     (aReceiver notNil and:[selector notNil]) ifTrue:[
   579 
   524 
   580     label    := aColumn label.
   525     label    := aColumn label.
   581     selector := aColumn description labelActionSelector.
   526     selector := aColumn description labelActionSelector.
   582     argument := (aColumn description labelActionArgument) ? label.
   527     argument := (aColumn description labelActionArgument) ? label.
   583 
   528 
   584     preferredExtent := 0 @ 0.
       
   585     adjust := aColumn labelAlignment.
   529     adjust := aColumn labelAlignment.
   586     layout := self class defaultLayout.
   530     layout := self class defaultLayout.
   587 
   531 
   588     (fgColor := aColumn labelForegroundColor) notNil ifTrue:[
   532     (fgColor := aColumn labelForegroundColor) notNil ifTrue:[
   589         fgColor := fgColor on:(aGC device)
   533         fgColor := fgColor on:(aGC device)
   620                 (img := label icon)  isImage ifTrue:[img clearMaskedPixels].
   564                 (img := label icon)  isImage ifTrue:[img clearMaskedPixels].
   621             ]
   565             ]
   622         ]
   566         ]
   623     ].
   567     ].
   624 
   568 
   625     label notNil ifTrue:[
   569     preferredExtent := label notNil ifTrue:[ Point x:(label widthOn:aGC) y:(label heightOn:aGC) ]
   626         preferredExtent := Point x:(label widthOn:aGC) y:(label heightOn:aGC).
   570                                    ifFalse:[ 0 @ 0 ].
   627         isDrawable := true.
       
   628     ] ifFalse:[
       
   629         isDrawable := selector notNil
       
   630     ]
       
   631 
       
   632 
   571 
   633 ! !
   572 ! !
   634 
   573 
   635 !DSVLabelView::Item methodsFor:'notification'!
   574 !DSVLabelView::Item methodsFor:'notification'!
   636 
   575 
   646 
   585 
   647 
   586 
   648 ! !
   587 ! !
   649 
   588 
   650 !DSVLabelView::Item methodsFor:'queries'!
   589 !DSVLabelView::Item methodsFor:'queries'!
   651 
       
   652 isDrawable
       
   653     "returns true if the item is drawble
       
   654     "
       
   655     ^ isDrawable
       
   656 
       
   657 
       
   658 !
       
   659 
   590 
   660 isSelectable
   591 isSelectable
   661     "returns true if the item is selectable; a valid selector
   592     "returns true if the item is selectable; a valid selector
   662      to notify the receiver for a release button event exists
   593      to notify the receiver for a release button event exists
   663     "
   594     "
   667 ! !
   598 ! !
   668 
   599 
   669 !DSVLabelView class methodsFor:'documentation'!
   600 !DSVLabelView class methodsFor:'documentation'!
   670 
   601 
   671 version
   602 version
   672     ^ '$Header: /cvs/stx/stx/libwidg2/DSVLabelView.st,v 1.15 1998-05-20 07:47:25 ca Exp $'
   603     ^ '$Header: /cvs/stx/stx/libwidg2/DSVLabelView.st,v 1.16 1998-06-03 14:30:36 ca Exp $'
   673 ! !
   604 ! !