DSVColumnView.st
changeset 2636 103067a67ff9
parent 2593 24ddc48c5ad4
child 2637 d563163414b8
equal deleted inserted replaced
2635:a8add4698dea 2636:103067a67ff9
    29 		checkToggleActiveImage checkTogglePassiveImage checkToggleLevel
    29 		checkToggleActiveImage checkTogglePassiveImage checkToggleLevel
    30 		comboButtonExtent comboButtonForm comboButtonLevel dropTarget
    30 		comboButtonExtent comboButtonForm comboButtonLevel dropTarget
    31 		dropSource columnAdaptor tabAtEndAction tabAtStartAction
    31 		dropSource columnAdaptor tabAtEndAction tabAtStartAction
    32 		modifiedChannel autoScroll autoScrollBlock needFitColumns
    32 		modifiedChannel autoScroll autoScrollBlock needFitColumns
    33 		scrollWhenUpdating selectionForegroundColor
    33 		scrollWhenUpdating selectionForegroundColor
    34 		selectionBackgroundColor previousExtent'
    34 		selectionBackgroundColor previousExtent selectConditionBlock'
    35 	classVariableNames:'DefaultForegroundColor DefaultBackgroundColor
    35 	classVariableNames:'DefaultForegroundColor DefaultBackgroundColor
    36 		DefaultHilightForegroundColor DefaultHilightBackgroundColor
    36 		DefaultHilightForegroundColor DefaultHilightBackgroundColor
    37 		ButtonLightColor ButtonShadowColor CheckToggleActiveImage
    37 		ButtonLightColor ButtonShadowColor CheckToggleActiveImage
    38 		CheckTogglePassiveImage ButtonHalfLightColor
    38 		CheckTogglePassiveImage ButtonHalfLightColor
    39 		ButtonHalfShadowColor ButtonEdgeStyle CheckToggleForm
    39 		ButtonHalfShadowColor ButtonEdgeStyle CheckToggleForm
   388      block returns the row which is put to the list
   388      block returns the row which is put to the list
   389     "
   389     "
   390     rowIfAbsentBlock := aOneArgAction
   390     rowIfAbsentBlock := aOneArgAction
   391 
   391 
   392 
   392 
       
   393 !
       
   394 
       
   395 selectConditionBlock
       
   396     "get the select-conditionBlock; this block is evaluated before 
       
   397      any selection change is performed (passing the to-be-changed row number
       
   398      index as arg).
       
   399      The change will not be done, if the block returns false. 
       
   400     "
       
   401     ^ selectConditionBlock
       
   402 !
       
   403 
       
   404 selectConditionBlock:aOneArgBlockOrNil
       
   405     "set the select-conditionBlock; this block is evaluated before 
       
   406      any selection change is performed (passing the to-be-changed row number
       
   407      index as arg).
       
   408      The change will not be done, if the block returns false. 
       
   409     "
       
   410     selectConditionBlock := aOneArgBlockOrNil.
   393 !
   411 !
   394 
   412 
   395 tabAtEndAction:aNoneArgAction
   413 tabAtEndAction:aNoneArgAction
   396     "set the action, called without any argument at end of the list entering
   414     "set the action, called without any argument at end of the list entering
   397      tab next.
   415      tab next.
  2078     ) ifFalse:[
  2096     ) ifFalse:[
  2079         super buttonPress:button x:x y:y.
  2097         super buttonPress:button x:x y:y.
  2080         ^ self
  2098         ^ self
  2081     ].
  2099     ].
  2082 
  2100 
       
  2101     (self isRowSelectable:rowNr) ifFalse:[^ self ].
       
  2102 
  2083     sensor ctrlDown ifTrue:[
  2103     sensor ctrlDown ifTrue:[
  2084         self buttonControlPressAtRowNr:rowNr.
  2104         self buttonControlPressAtRowNr:rowNr.
  2085         ^ self
  2105         ^ self
  2086     ].
  2106     ].
  2087 
  2107 
  2302     (aKey == #CursorUp 
  2322     (aKey == #CursorUp 
  2303         or:[aKey == #CursorDown
  2323         or:[aKey == #CursorDown
  2304         or:[rawKey == #Home
  2324         or:[rawKey == #Home
  2305         or:[rawKey == #End] 
  2325         or:[rawKey == #End] 
  2306     ]]) ifTrue:[
  2326     ]]) ifTrue:[
  2307         (hasSelectables or:[selectRowOnDefault]) ifTrue:[
  2327         (hasSelectables or:[selectRowOnDefault]) ifTrue:[ |step start|
  2308             minSelRowNr := self minIndexSelected.
  2328             minSelRowNr := self minIndexSelected.
  2309             maxSelRowNr := self maxIndexSelected.
  2329             maxSelRowNr := self maxIndexSelected.
  2310 
  2330 
  2311             selColNr := hasSelectables ifFalse:[0]
  2331             selColNr := hasSelectables ifFalse:[0]
  2312                                         ifTrue:[selectedColIndex].
  2332                                         ifTrue:[selectedColIndex].
  2313         
  2333 
  2314             aKey == #CursorUp ifTrue:[
  2334             aKey == #CursorUp ifTrue:[
  2315                 selRowNr := minSelRowNr > 1 ifTrue:[minSelRowNr - 1] ifFalse:[listSize].
  2335                 selRowNr := minSelRowNr > 1 ifTrue:[minSelRowNr - 1] ifFalse:[listSize].
       
  2336                 step := -1.
  2316             ] ifFalse:[
  2337             ] ifFalse:[
  2317                 aKey == #CursorDown ifTrue:[
  2338                 aKey == #CursorDown ifTrue:[
  2318                     selRowNr := maxSelRowNr < listSize ifTrue:[maxSelRowNr + 1] ifFalse:[1].
  2339                     selRowNr := maxSelRowNr < listSize ifTrue:[maxSelRowNr + 1] ifFalse:[1].
       
  2340                     step := 1.
  2319                 ] ifFalse:[
  2341                 ] ifFalse:[
  2320                     aKey == #BeginOfLine ifTrue:[
  2342                     aKey == #BeginOfLine ifTrue:[
  2321                         selRowNr := 1.
  2343                         selRowNr := 1.
       
  2344                         step := 1.
  2322                     ] ifFalse:[
  2345                     ] ifFalse:[
  2323                         selRowNr := listSize.
  2346                         selRowNr := listSize.
       
  2347                         step := -1.
  2324                     ]
  2348                     ]
  2325                 ]
  2349                 ]
  2326             ].
  2350             ].
  2327 
  2351             start := selRowNr.
       
  2352 
       
  2353             [ self isRowSelectable:selRowNr ] whileFalse:[
       
  2354                 selRowNr := selRowNr + step.
       
  2355 
       
  2356                 selRowNr == 0 ifTrue:[
       
  2357                     selRowNr := listSize.
       
  2358                 ] ifFalse:[
       
  2359                     selRowNr > listSize ifTrue:[
       
  2360                         selRowNr := 1.
       
  2361                     ].
       
  2362                 ].
       
  2363                 selRowNr == start ifTrue:[^ self ].
       
  2364             ].
       
  2365                                 
  2328             ((aKey == #CursorUp) or:[aKey == #CursorDown]) ifTrue:[
  2366             ((aKey == #CursorUp) or:[aKey == #CursorDown]) ifTrue:[
  2329                 (multipleSelectOk and:[self sensor shiftDown]) ifTrue:[
  2367                 (multipleSelectOk and:[self sensor shiftDown]) ifTrue:[
  2330                     self addRowToSelection:selRowNr.
  2368                     self addRowToSelection:selRowNr.
  2331 
  2369 
  2332                     aKey == #CursorDown ifTrue:[
  2370                     aKey == #CursorDown ifTrue:[
  2378         selRowNr == 0 ifTrue:[selRowNr := listSize].
  2416         selRowNr == 0 ifTrue:[selRowNr := listSize].
  2379         selColNr == 0 ifTrue:[selColNr := maxColNr + 1].
  2417         selColNr == 0 ifTrue:[selColNr := maxColNr + 1].
  2380 
  2418 
  2381         [true] whileTrue:[
  2419         [true] whileTrue:[
  2382             (selColNr := selColNr - 1) == 0 ifTrue:[
  2420             (selColNr := selColNr - 1) == 0 ifTrue:[
  2383                 (selRowNr := selRowNr - 1) == 0 ifTrue:[
  2421                 [   selRowNr := selRowNr - 1.
       
  2422                     selRowNr == 0 ifTrue:[
       
  2423                         isTab ifTrue:[
       
  2424                             tabAtStartAction notNil ifTrue:[
       
  2425                                 tabAtStartAction value
       
  2426                             ] ifFalse:[
       
  2427                                 self deselect.
       
  2428                                 self windowGroup focusPreviousFrom:self
       
  2429                             ]
       
  2430                         ].
       
  2431                         ^ self
       
  2432                     ].
       
  2433                     (self isRowSelectable:selRowNr)
       
  2434                 ] whileFalse.
       
  2435 
       
  2436                 selColNr := maxColNr
       
  2437             ].
       
  2438             column := self columnAt:selColNr.
       
  2439 
       
  2440             (column rendererType ~~ #rowSelector and:[column canSelect:selRowNr]) ifTrue:[
       
  2441                 ^ self selectColIndex:selColNr rowIndex:selRowNr.
       
  2442             ]
       
  2443         ]
       
  2444     ].
       
  2445 
       
  2446     selRowNr := firstSelRowNr.
       
  2447     selRowNr == 0 ifTrue:[selRowNr := 1].
       
  2448 
       
  2449     [true] whileTrue:[
       
  2450         (selColNr := selColNr + 1) > maxColNr ifTrue:[
       
  2451             [   selRowNr := selRowNr + 1.
       
  2452                 selRowNr > listSize ifTrue:[
  2384                     isTab ifTrue:[
  2453                     isTab ifTrue:[
  2385                         tabAtStartAction notNil ifTrue:[
  2454                         tabAtEndAction notNil ifTrue:[
  2386                             tabAtStartAction value
  2455                             tabAtEndAction value
  2387                         ] ifFalse:[
  2456                         ] ifFalse:[
  2388                             self deselect.
  2457                             self deselect.
  2389                             self windowGroup focusPreviousFrom:self
  2458                             self windowGroup focusNextFrom:self
  2390                         ]
  2459                         ]
  2391                     ].
  2460                     ].
  2392                     ^ self
  2461                     ^ self
  2393                 ].
  2462                 ].
  2394                 selColNr := maxColNr
  2463                 (self isRowSelectable:selRowNr)
  2395             ].
  2464             ] whileFalse.
  2396             column := self columnAt:selColNr.
  2465 
  2397 
       
  2398             (column rendererType ~~ #rowSelector and:[column canSelect:selRowNr]) ifTrue:[
       
  2399                 ^ self selectColIndex:selColNr rowIndex:selRowNr.
       
  2400             ]
       
  2401         ]
       
  2402     ].
       
  2403 
       
  2404     selRowNr := firstSelRowNr.
       
  2405     selRowNr == 0 ifTrue:[selRowNr := 1].
       
  2406 
       
  2407     [true] whileTrue:[
       
  2408         (selColNr := selColNr + 1) > maxColNr ifTrue:[
       
  2409             (selRowNr := selRowNr + 1) > listSize ifTrue:[
       
  2410                 isTab ifTrue:[
       
  2411                     tabAtEndAction notNil ifTrue:[
       
  2412                         tabAtEndAction value
       
  2413                     ] ifFalse:[
       
  2414                         self deselect.
       
  2415                         self windowGroup focusNextFrom:self
       
  2416                     ]
       
  2417                 ].
       
  2418                 ^ self
       
  2419             ].
       
  2420             selColNr := 1
  2466             selColNr := 1
  2421         ].
  2467         ].
  2422         column := self columnAt:selColNr.
  2468         column := self columnAt:selColNr.
  2423 
  2469 
  2424         (column rendererType ~~ #rowSelector and:[column canSelect:selRowNr]) ifTrue:[
  2470         (column rendererType ~~ #rowSelector and:[column canSelect:selRowNr]) ifTrue:[
  2985 
  3031 
  2986 isEnabled
  3032 isEnabled
  2987     ^ enableChannel value ~~ false
  3033     ^ enableChannel value ~~ false
  2988 !
  3034 !
  2989 
  3035 
       
  3036 isRowSelectable:aRowNumber
       
  3037     "returne true if a row number is selectable
       
  3038     "
       
  3039     (aRowNumber notNil and:[aRowNumber ~~ 0]) ifTrue:[
       
  3040         selectConditionBlock isNil ifTrue:[^ true].
       
  3041         ^ (selectConditionBlock value:aRowNumber)
       
  3042     ].
       
  3043     ^ false
       
  3044 !
       
  3045 
  2990 numberOfColumns
  3046 numberOfColumns
  2991     "returns number of columns
  3047     "returns number of columns
  2992     "
  3048     "
  2993     ^ columnDescriptors size
  3049     ^ columnDescriptors size
  2994 
  3050 
  3373     "add a row to the selection
  3429     "add a row to the selection
  3374      if a column is selected, the column will be closed
  3430      if a column is selected, the column will be closed
  3375     "
  3431     "
  3376     |newSelection|
  3432     |newSelection|
  3377 
  3433 
       
  3434     (self isRowSelectable:aRowNr) ifFalse:[
       
  3435         ^ self
       
  3436     ].
       
  3437 
  3378     self numberOfSelections == 0 ifTrue:[
  3438     self numberOfSelections == 0 ifTrue:[
  3379         self selectColIndex:0 rowIndex:aRowNr.
  3439         self selectColIndex:0 rowIndex:aRowNr.
  3380         ^ self
  3440         ^ self
  3381     ].
  3441     ].
  3382     (self isInSelection:aRowNr) ifTrue:[^ self].
  3442     (self isInSelection:aRowNr) ifTrue:[^ self].
  3588 !
  3648 !
  3589 
  3649 
  3590 selectAllRows
  3650 selectAllRows
  3591     "select all
  3651     "select all
  3592     "
  3652     "
  3593     selectedRowIndex isNil ifTrue:[selectedRowIndex := OrderedCollection new].
  3653     multipleSelectOk ifFalse:[^ self].
  3594     1 to:list size do:[:eachRowNr |
  3654 
  3595         selectedRowIndex add:eachRowNr.    
  3655     selectedRowIndex := (1 to:list size) select:[:idx| self isRowSelectable:idx ].
  3596         self invalidateRowAt:eachRowNr.
       
  3597     ].
       
  3598     self selectionChanged.
  3656     self selectionChanged.
       
  3657     self invalidate.
  3599 !
  3658 !
  3600 
  3659 
  3601 selectColIndex:aColNr rowIndex:aRowNr
  3660 selectColIndex:aColNr rowIndex:aRowNr
  3602     "change selection with notification
  3661     "change selection with notification
  3603     "
  3662     "
  3643         ^ self
  3702         ^ self
  3644     ].
  3703     ].
  3645 
  3704 
  3646     step := (start <= stop) ifTrue:1 ifFalse:-1.
  3705     step := (start <= stop) ifTrue:1 ifFalse:-1.
  3647 
  3706 
  3648     newSelection := (start to:stop by:step) asOrderedCollection.
  3707     newSelection := (start to:stop by:step) select:[:idx| self isRowSelectable: idx ].
  3649 
  3708 
  3650     selectedColIndex ~~ 0 ifTrue:[
  3709     selectedColIndex ~~ 0 ifTrue:[
  3651         self selectColIndex:0 rowIndex:newSelection.
  3710         self selectColIndex:0 rowIndex:newSelection.
  3652         ^ self
  3711         ^ self
  3653     ].
  3712     ].
  3922 
  3981 
  3923     (list size == 0 or:[newSel isNil or:[newSel == 0]]) ifTrue:[
  3982     (list size == 0 or:[newSel isNil or:[newSel == 0]]) ifTrue:[
  3924         ^ multipleSelectOk ifFalse:[0] ifTrue:[nil]
  3983         ^ multipleSelectOk ifFalse:[0] ifTrue:[nil]
  3925     ].
  3984     ].
  3926 
  3985 
  3927     newSel isNumber ifTrue:[
       
  3928         ^ multipleSelectOk ifFalse:[newSel] ifTrue:[OrderedCollection with:newSel]
       
  3929     ].
       
  3930     multipleSelectOk ifFalse:[
  3986     multipleSelectOk ifFalse:[
  3931         newSel := self identityIndexOfRow:aSelection
  3987         newSel isNumber ifFalse:[
  3932     ] ifTrue:[
  3988             newSel := self identityIndexOfRow:aSelection.
  3933         newSel := nil.
  3989         ].
  3934 
  3990         ^ (self isRowSelectable:newSel) ifTrue:[newSel] ifFalse:[0].
  3935         aSelection size ~~ 0 ifTrue:[
  3991     ].
  3936             aSelection first isNumber ifTrue:[
  3992 
  3937                 newSel := aSelection
  3993     "multiple selection
  3938             ] ifFalse:[
  3994     "
  3939                 newSel := aSelection 
  3995     aSelection size ~~ 0 ifTrue:[
  3940                                 collect:[:el | self identityIndexOfRow:el ]
  3996         aSelection first isNumber ifTrue:[
  3941                                 thenSelect:[:idx | idx ~~ 0].
  3997             newSel := aSelection select:[:idx| self isRowSelectable:idx ].
  3942                 newSel isEmpty ifTrue:[ newSel := nil ].
  3998         ] ifFalse:[
  3943             ]
  3999             newSel := aSelection 
  3944         ]
  4000                             collect:[:el| self identityIndexOfRow:el ]
  3945     ].
  4001                             thenSelect:[:idx| self isRowSelectable:idx ].
  3946     ^ newSel
  4002         ].
       
  4003         newSel notEmpty ifTrue:[
       
  4004             ^ newSel
       
  4005         ].
       
  4006     ] ifFalse:[
       
  4007         (newSel isNumber and:[self isRowSelectable:newSel]) ifTrue:[
       
  4008             ^ Array with:newSel
       
  4009         ].
       
  4010     ].
       
  4011     ^ nil
  3947 ! !
  4012 ! !
  3948 
  4013 
  3949 !DSVColumnView class methodsFor:'documentation'!
  4014 !DSVColumnView class methodsFor:'documentation'!
  3950 
  4015 
  3951 version
  4016 version
  3952     ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.177 2003-12-17 12:30:08 ca Exp $'
  4017     ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.178 2004-02-17 13:10:51 ca Exp $'
  3953 ! !
  4018 ! !