VariablePanelController.st
changeset 1720 896886032334
parent 1626 3013631d4384
child 1722 cfbd32394b80
equal deleted inserted replaced
1719:3d4adf98c079 1720:896886032334
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 Controller subclass:#VariablePanelController
    13 Controller subclass:#VariablePanelController
    14 	instanceVariableNames:'movedHandle prevPos startPos clickPos'
    14 	instanceVariableNames:'movedHandle prevPos startPos clickPos'
    15 	classVariableNames:''
    15 	classVariableNames:'OpaqueResize'
    16 	poolDictionaries:''
    16 	poolDictionaries:''
    17 	category:'Interface-Support-Controllers'
    17 	category:'Interface-Support-Controllers'
    18 !
    18 !
    19 
    19 
    20 !VariablePanelController class methodsFor:'documentation'!
    20 !VariablePanelController class methodsFor:'documentation'!
    44     [author:]
    44     [author:]
    45         Claus Gittinger
    45         Claus Gittinger
    46 "
    46 "
    47 ! !
    47 ! !
    48 
    48 
       
    49 !VariablePanelController class methodsFor:'defaults'!
       
    50 
       
    51 opaqueResize:aBoolean
       
    52     "set/clear opaque-resizing.
       
    53      If off (the default), the resizing takes place at the end of
       
    54      the handle move operation (when the mouse button is released).
       
    55      If on, the resizing is syncronous with the move.
       
    56      On slow machines, it may make sense to leave it off."
       
    57 
       
    58     OpaqueResize := aBoolean.
       
    59 
       
    60     "
       
    61      self opaqueResize:true
       
    62      self opaqueResize:false
       
    63     "
       
    64 
       
    65     "Modified: / 13.11.1998 / 15:16:37 / cg"
       
    66 ! !
       
    67 
    49 !VariablePanelController methodsFor:'event handling'!
    68 !VariablePanelController methodsFor:'event handling'!
    50 
    69 
    51 buttonMotion:state x:bx y:by
    70 buttonMotion:state x:bx y:by
    52     "mouse-button was moved while pressed;
    71     "mouse-button was moved while pressed;
    53      clear prev handleBar and draw handle bar at new position" 
    72      clear prev handleBar and draw handle bar at new position" 
    64 
    83 
    65     subViews := view subViews.
    84     subViews := view subViews.
    66     barHeight := view barHeight.
    85     barHeight := view barHeight.
    67 
    86 
    68     view orientation ~~ #vertical ifTrue:[
    87     view orientation ~~ #vertical ifTrue:[
    69 	pos := bx - startPos.
    88         pos := bx - startPos.
    70 	"
    89         "
    71 	 the two lines below will not allow resizing down to zero
    90          the two lines below will not allow resizing down to zero
    72 	 (so that some is always visible)
    91          (so that some is always visible)
    73 	"
    92         "
    74 "/        limitMin := barHeight // 2.
    93 "/        limitMin := barHeight // 2.
    75 "/        limitMax := view width - barHeight.
    94 "/        limitMax := view width - barHeight.
    76 	"
    95         "
    77 	 these allow resizing to zero - which is better ?
    96          these allow resizing to zero - which is better ?
    78 	"
    97         "
    79 	limitMin := 0.
    98         limitMin := 0.
    80 	limitMax := view innerWidth.
    99         limitMax := view innerWidth.
    81 
   100 
    82 	movedHandle > 1 ifTrue:[
   101         movedHandle > 1 ifTrue:[
    83 	    limitMin := (subViews at:movedHandle) origin x + (barHeight // 2)
   102             limitMin := (subViews at:movedHandle) origin x + (barHeight // 2)
    84 	].
   103         ].
    85 	movedHandle < (subViews size - 1) ifTrue:[
   104         movedHandle < (subViews size - 1) ifTrue:[
    86 	    limitMax := (subViews at:(movedHandle + 2)) origin x - barHeight
   105             limitMax := (subViews at:(movedHandle + 2)) origin x - barHeight
    87 	].
   106         ].
    88     ] ifFalse:[
   107     ] ifFalse:[
    89 	pos := by - startPos.
   108         pos := by - startPos.
    90 	"
   109         "
    91 	 the two lines below will not allow resizing down to zero
   110          the two lines below will not allow resizing down to zero
    92 	 (so that some is always visible)
   111          (so that some is always visible)
    93 	"
   112         "
    94 "/        limitMin := barHeight // 2.
   113 "/        limitMin := barHeight // 2.
    95 "/        limitMax := view height - barHeight.
   114 "/        limitMax := view height - barHeight.
    96 	"
   115         "
    97 	 these allow resizing to zero - which is better ?
   116          these allow resizing to zero - which is better ?
    98 	"
   117         "
    99 	limitMin := 0.
   118         limitMin := 0.
   100 	limitMax := view innerHeight.
   119         limitMax := view innerHeight.
   101 
   120 
   102 	movedHandle > 1 ifTrue:[
   121         movedHandle > 1 ifTrue:[
   103 	    limitMin := (subViews at:movedHandle) origin y + (barHeight // 2)
   122             limitMin := (subViews at:movedHandle) origin y + (barHeight // 2)
   104 	].
   123         ].
   105 	movedHandle < (subViews size - 1) ifTrue:[
   124         movedHandle < (subViews size - 1) ifTrue:[
   106 	    limitMax := (subViews at:(movedHandle + 2)) origin y - barHeight
   125             limitMax := (subViews at:(movedHandle + 2)) origin y - barHeight
   107 	].
   126         ].
   108     ].
   127     ].
   109 
   128 
   110     limitMax := limitMax - barHeight.
   129     limitMax := limitMax - barHeight.
   111     (pos < limitMin) ifTrue:[ "check against view limits"
   130     (pos < limitMin) ifTrue:[ "check against view limits"
   112 	pos := limitMin
   131         pos := limitMin
   113     ] ifFalse:[
   132     ] ifFalse:[
   114 	(pos > limitMax) ifTrue:[
   133         (pos > limitMax) ifTrue:[
   115 	    pos := limitMax
   134             pos := limitMax
   116 	]
   135         ]
   117     ].
   136     ].
   118 
   137 
   119     prevPos == pos ifTrue:[^ self].
   138     prevPos == pos ifTrue:[^ self].
   120 
   139 
   121     view orientation ~~ #vertical ifTrue:[
   140     view orientation ~~ #vertical ifTrue:[
   122 	oldHx := prevPos. 
   141         oldHx := prevPos. 
   123 	newHx := pos.
   142         newHx := pos.
   124 	oldHy := newHy := 0.
   143         oldHy := newHy := 0.
   125     ] ifFalse:[
   144     ] ifFalse:[
   126 	oldHy := prevPos.
   145         oldHy := prevPos.
   127 	newHy := pos.
   146         newHy := pos.
   128 	oldHx := newHx := 0.
   147         oldHx := newHx := 0.
   129     ].
   148     ].
   130     view invertHandleBarAtX:oldHx y:oldHy. 
   149 
   131     view invertHandleBarAtX:newHx y:newHy.
   150     OpaqueResize ~~ true ifTrue:[
   132 
   151         view invertHandleBarAtX:oldHx y:oldHy. 
   133     prevPos := pos
   152         view invertHandleBarAtX:newHx y:newHy.
       
   153     ].
       
   154     prevPos := pos.
       
   155 
       
   156     OpaqueResize == true ifTrue:[
       
   157         self buttonRelease:1 x:bx y:by.
       
   158         self buttonPress:1 x:bx y:by.
       
   159     ]
       
   160 
       
   161     "Modified: / 13.11.1998 / 15:13:47 / cg"
   134 !
   162 !
   135 
   163 
   136 buttonPress:button x:bx y:by
   164 buttonPress:button x:bx y:by
   137     "button was pressed - if it hits a handle, start move"
   165     "button was pressed - if it hits a handle, start move"
   138 
   166 
   170                 ].
   198                 ].
   171             ].
   199             ].
   172 
   200 
   173             thatsTheHandle ifTrue:[
   201             thatsTheHandle ifTrue:[
   174                 movedHandle := handle.
   202                 movedHandle := handle.
   175                 view grabPointer.
   203 
   176                 view invertHandleBarAtX:hx y:hy.
   204                 OpaqueResize ~~ true ifTrue:[
       
   205                     view grabPointer.
       
   206                     view invertHandleBarAtX:hx y:hy.
       
   207                 ].
   177                 (group := view windowGroup) notNil ifTrue:[
   208                 (group := view windowGroup) notNil ifTrue:[
   178                     group showCursor:view cursor
   209                     group showCursor:view cursor
   179                 ].
   210                 ].
   180                 clickPos := bx @ by.
   211                 clickPos := bx @ by.
   181                 ^ self
   212                 ^ self
   186         movedHandle := nil
   217         movedHandle := nil
   187     ] ifFalse:[
   218     ] ifFalse:[
   188         super buttonPress:button x:bx y:by
   219         super buttonPress:button x:bx y:by
   189     ]
   220     ]
   190 
   221 
   191     "Modified: / 29.7.1998 / 15:52:35 / cg"
   222     "Modified: / 13.11.1998 / 15:18:10 / cg"
   192 !
   223 !
   193 
   224 
   194 buttonRelease:button x:bx y:by
   225 buttonRelease:button x:bx y:by
   195     "end bar-move"
   226     "end bar-move"
   196 
   227 
   202     ((button == 1) or:[button == #select]) ifTrue:[
   233     ((button == 1) or:[button == #select]) ifTrue:[
   203         movedHandle isNil ifTrue:[^ self].
   234         movedHandle isNil ifTrue:[^ self].
   204 
   235 
   205         isHorizontal := view orientation ~~ #vertical.
   236         isHorizontal := view orientation ~~ #vertical.
   206 
   237 
   207         view ungrabPointer.
   238         OpaqueResize ~~ true ifTrue:[
       
   239             view ungrabPointer.
       
   240         ].
       
   241 
   208         (group := view windowGroup) notNil ifTrue:[
   242         (group := view windowGroup) notNil ifTrue:[
   209             group restoreCursors
   243             group restoreCursors
   210         ].
   244         ].
   211 
   245 
   212         "undo the last invert"
   246         "undo the last invert"
   214         isHorizontal ifTrue:[
   248         isHorizontal ifTrue:[
   215             hX := prevPos. hY := 0. 
   249             hX := prevPos. hY := 0. 
   216         ] ifFalse:[
   250         ] ifFalse:[
   217             hX := 0. hY := prevPos. 
   251             hX := 0. hY := prevPos. 
   218         ].
   252         ].
   219         view invertHandleBarAtX:hX y:hY. 
   253         OpaqueResize ~~ true ifTrue:[
       
   254             view invertHandleBarAtX:hX y:hY. 
       
   255         ].
   220 
   256 
   221         "/ any change ?
   257         "/ any change ?
   222         isHorizontal ifTrue:[
   258         isHorizontal ifTrue:[
   223             bx == clickPos x ifTrue:[^ self].
   259             bx == clickPos x ifTrue:[^ self].
   224         ] ifFalse:[
   260         ] ifFalse:[
   262         view unlockRedraw.
   298         view unlockRedraw.
   263     ] ifFalse:[
   299     ] ifFalse:[
   264         super buttonRelease:button x:bx y:by
   300         super buttonRelease:button x:bx y:by
   265     ]
   301     ]
   266 
   302 
   267     "Modified: / 29.7.1998 / 15:52:43 / cg"
   303     "Modified: / 13.11.1998 / 15:17:54 / cg"
   268 !
   304 !
   269 
   305 
   270 pointerEnter:state x:x y:y
   306 pointerEnter:state x:x y:y
   271     state == 0 ifTrue:[
   307     state == 0 ifTrue:[
   272         movedHandle notNil ifTrue:[self buttonRelease:1 x:x y:y]
   308         movedHandle notNil ifTrue:[self buttonRelease:1 x:x y:y]
   277 ! !
   313 ! !
   278 
   314 
   279 !VariablePanelController class methodsFor:'documentation'!
   315 !VariablePanelController class methodsFor:'documentation'!
   280 
   316 
   281 version
   317 version
   282     ^ '$Header: /cvs/stx/stx/libwidg/VariablePanelController.st,v 1.16 1998-07-29 16:00:06 cg Exp $'
   318     ^ '$Header: /cvs/stx/stx/libwidg/VariablePanelController.st,v 1.17 1998-11-13 14:20:00 cg Exp $'
   283 ! !
   319 ! !