VariableVerticalPanelController.st
changeset 105 3d064ba4a0cc
parent 98 987762f1f7ad
child 126 40228f4fd66b
equal deleted inserted replaced
104:ca75c90df7a9 105:3d064ba4a0cc
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 'From Smalltalk/X, Version:2.10.4 on 6-mar-1995 at 20:00:02'!
    13 'From Smalltalk/X, Version:2.10.4 on 6-mar-1995 at 20:00:05'!
    14 
    14 
    15 Controller subclass:#VariableVerticalPanelController
    15 VariablePanelController subclass:#VariableVerticalPanelController
    16 	 instanceVariableNames:'movedHandle prev start'
    16 	 instanceVariableNames:''
    17 	 classVariableNames:''
    17 	 classVariableNames:''
    18 	 poolDictionaries:''
    18 	 poolDictionaries:''
    19 	 category:'Interface-Support'
    19 	 category:'Interface-Support'
    20 !
    20 !
    21 
    21 
    35 "
    35 "
    36 !
    36 !
    37 
    37 
    38 version
    38 version
    39 "
    39 "
    40 $Header: /cvs/stx/stx/libwidg/VariableVerticalPanelController.st,v 1.1 1995-03-06 21:06:04 claus Exp $
    40 $Header: /cvs/stx/stx/libwidg/VariableVerticalPanelController.st,v 1.2 1995-03-18 05:16:41 claus Exp $
    41 "
    41 "
    42 ! !
    42 ! !
    43 
    43 
    44 !VariableVerticalPanelController methodsFor:'event handling'!
    44 !VariableVerticalPanelController methodsFor:'initialization'!
    45 
    45 
    46 buttonMotion:button x:bx y:by
    46 initialize
    47     "mouse-button was moved while pressed;
    47     super initialize.
    48      clear prev handleBar and draw handle bar at new position" 
    48     isHorizontal := false
       
    49 ! !
    49 
    50 
    50     |ypos limitTop limitBot subViews barHeight|
       
    51 
       
    52     movedHandle isNil ifTrue: [^ self].          "should not happen"
       
    53 
       
    54     "speedup - if there is already another movement, 
       
    55      ignore thisone ... "
       
    56 
       
    57     view buttonMotionEventPending ifTrue:[^ self].
       
    58 
       
    59     ypos := by - start.
       
    60 
       
    61     "
       
    62      the two lines below will not allow resizing down to zero
       
    63      (so that some is always visible)
       
    64     "
       
    65 "/    limitTop := barHeight // 2.
       
    66 "/    limitBot := self height - barHeight.
       
    67 
       
    68     "
       
    69      these allow resizing to zero - which is better ?
       
    70     "
       
    71     limitTop := 0.
       
    72     limitBot := view innerHeight.
       
    73     subViews := view subViews.
       
    74     barHeight := view barHeight.
       
    75 
       
    76     movedHandle > 1 ifTrue:[
       
    77 	limitTop := (subViews at:movedHandle) origin y + (barHeight // 2)
       
    78     ].
       
    79     movedHandle < (subViews size - 1) ifTrue:[
       
    80 	limitBot := (subViews at:(movedHandle + 2)) origin y - barHeight
       
    81     ].
       
    82     limitBot := limitBot - barHeight.
       
    83     (ypos < limitTop) ifTrue:[ "check against view limits"
       
    84 	ypos := limitTop
       
    85     ] ifFalse:[
       
    86 	(ypos > limitBot) ifTrue:[
       
    87 	    ypos := limitBot
       
    88 	]
       
    89     ].
       
    90 
       
    91     view invertHandleBarAtX:0 y:prev.
       
    92     view invertHandleBarAtX:0 y:ypos.
       
    93 
       
    94     prev := ypos
       
    95 !
       
    96 
       
    97 buttonRelease:button x:x y:y
       
    98     "end bar-move"
       
    99 
       
   100     |aboveView belowView aboveIndex belowIndex newY oldY group subViews|
       
   101 
       
   102     ((button == 1) or:[button == #select]) ifTrue:[
       
   103 	movedHandle isNil ifTrue:[^ self].
       
   104 
       
   105 	(group := view windowGroup) notNil ifTrue:[
       
   106 	    group restoreCursors
       
   107 	].
       
   108 
       
   109 	"undo the last xor"
       
   110 
       
   111 	view invertHandleBarAtX:0 y:prev. 
       
   112 
       
   113 	"compute the new relative heights"
       
   114 
       
   115 	aboveIndex := movedHandle.
       
   116 	belowIndex := movedHandle + 1.
       
   117 	movedHandle := nil.
       
   118 	subViews := view subViews.
       
   119 
       
   120 	aboveView := subViews at:aboveIndex.
       
   121 	belowView := subViews at:belowIndex.
       
   122 
       
   123 	oldY := aboveView relativeCorner y.
       
   124 	newY := (prev + start / view height) asFloat.
       
   125 	aboveView relativeCorner:aboveView relativeCorner x @ newY.
       
   126 	belowView relativeOrigin:belowView relativeOrigin x @ newY.
       
   127 
       
   128 	view lockRedraw.
       
   129 	oldY > newY ifTrue:[
       
   130 	    view resizeSubviewsFrom:aboveIndex to:belowIndex.
       
   131 	] ifFalse:[
       
   132 	    view resizeSubviewsFrom:belowIndex to:aboveIndex.
       
   133 	].
       
   134 	view redrawHandlesFrom:aboveIndex to:belowIndex.
       
   135 	view unlockRedraw.
       
   136     ] ifFalse:[
       
   137 	super buttonRelease:button x:x y:y
       
   138     ]
       
   139 !
       
   140 
       
   141 buttonPress:button x:bx y:by
       
   142     "button was pressed - if it hits a handle, start move"
       
   143 
       
   144     |handle barHeight group|
       
   145 
       
   146     ((button == 1) or:[button == #select]) ifTrue:[
       
   147 	handle := 1.
       
   148 	barHeight := view barHeight.
       
   149 	view handleOriginsDo:[:hPoint |
       
   150 	    |hy|
       
   151 
       
   152 	    hy := hPoint y.
       
   153 	    (by between:hy and:(hy + barHeight)) ifTrue:[
       
   154 		movedHandle := handle.
       
   155 		prev := hy.
       
   156 		start := by - hy.
       
   157 
       
   158 		view invertHandleBarAtX:0 y:hy.
       
   159 		(group := view windowGroup) notNil ifTrue:[
       
   160 		    group showCursor:view cursor
       
   161 		].
       
   162 		^ self
       
   163 	    ].
       
   164 	    handle := handle + 1
       
   165 	].
       
   166 	movedHandle := nil
       
   167     ] ifFalse:[
       
   168 	super buttonPress:button x:bx y:by
       
   169     ]
       
   170 ! !