TextView.st
changeset 3251 156d3ee6a6c1
parent 3245 b17c15b61e94
child 3258 0a07b6fdd85d
equal deleted inserted replaced
3250:6a00500f093f 3251:156d3ee6a6c1
  1068 !TextView methodsFor:'event handling'!
  1068 !TextView methodsFor:'event handling'!
  1069 
  1069 
  1070 buttonMotion:buttonState x:x y:y
  1070 buttonMotion:buttonState x:x y:y
  1071     "mouse-move while button was pressed - handle selection changes"
  1071     "mouse-move while button was pressed - handle selection changes"
  1072 
  1072 
  1073     |movedVisibleLine movedLine movedCol 
       
  1074      movedUp 
       
  1075      oldStartLine oldEndLine oldStartCol oldEndCol|
       
  1076 
       
  1077     (clickLine isNil or:[clickPos isNil]) ifTrue:[
  1073     (clickLine isNil or:[clickPos isNil]) ifTrue:[
  1078         dragIsActive := false.
  1074         dragIsActive := false.
  1079         ^ self
  1075         ^ self
  1080     ].
  1076     ].
  1081 
  1077 
  1125     "move inside - stop autoscroll if any"
  1121     "move inside - stop autoscroll if any"
  1126     autoScrollBlock notNil ifTrue:[
  1122     autoScrollBlock notNil ifTrue:[
  1127         self stopScrollSelect
  1123         self stopScrollSelect
  1128     ].
  1124     ].
  1129 
  1125 
  1130     movedVisibleLine := self visibleLineOfY:y.
  1126     self extendSelectionToX:x y:y.
  1131     movedLine := self visibleLineToAbsoluteLine:movedVisibleLine.
       
  1132 
       
  1133     (x < leftMargin) ifTrue:[
       
  1134         movedCol := 0
       
  1135     ] ifFalse:[
       
  1136         movedCol := self colOfX:x inVisibleLine:movedVisibleLine
       
  1137     ].
       
  1138     y < 0 ifTrue:[
       
  1139         movedCol := 0
       
  1140     ].
       
  1141     ((movedLine == clickLine) and:[movedCol == clickCol]) ifTrue:[
       
  1142         selectionStartLine notNil ifTrue:[
       
  1143             ^ self
       
  1144         ].
       
  1145         (clickPos isNil 
       
  1146         or:[(clickPos x - x) abs < 3 
       
  1147             and:[(clickPos y - y) abs < 3]]) ifTrue:[
       
  1148             ^ self
       
  1149         ].
       
  1150         selectionStartLine := clickLine.
       
  1151         selectionStartCol := clickCol.
       
  1152         selectionEndLine := selectionStartLine.
       
  1153         selectionEndCol := selectionStartCol.
       
  1154 
       
  1155         oldStartLine := selectionStartLine.
       
  1156         oldEndLine := selectionEndLine.
       
  1157         oldStartCol := selectionStartCol.
       
  1158         oldEndCol := selectionEndCol-1.
       
  1159     ] ifFalse:[
       
  1160         selectionStartLine isNil ifTrue:[
       
  1161             selectionStartLine := clickLine.
       
  1162             selectionStartCol := clickCol.
       
  1163             selectionEndLine := selectionStartLine.
       
  1164             selectionEndCol := selectionStartCol
       
  1165         ].
       
  1166         oldStartLine := selectionStartLine.
       
  1167         oldEndLine := selectionEndLine.
       
  1168         oldStartCol := selectionStartCol.
       
  1169         oldEndCol := selectionEndCol.
       
  1170     ].
       
  1171 
       
  1172     "find out if we are before or after initial click"
       
  1173     movedUp := false.
       
  1174     (movedLine < clickStartLine) ifTrue:[
       
  1175         movedUp := true
       
  1176     ] ifFalse:[
       
  1177         (movedLine == clickStartLine) ifTrue:[
       
  1178             (movedCol < clickStartCol) ifTrue:[
       
  1179                 movedUp := true
       
  1180             ]
       
  1181         ]
       
  1182     ].
       
  1183 
       
  1184     movedUp ifTrue:[
       
  1185         "change selectionStart"
       
  1186         selectionStartCol := movedCol.
       
  1187         selectionStartLine := movedLine.
       
  1188         selectionEndCol := clickStartCol.
       
  1189         selectionEndLine := clickStartLine.
       
  1190         selectStyle notNil ifTrue:[
       
  1191             selectionEndCol := wordEndCol.
       
  1192             selectionEndLine := wordEndLine.
       
  1193         ]
       
  1194     ] ifFalse:[
       
  1195         "change selectionEnd"
       
  1196         selectionEndCol := movedCol.
       
  1197         selectionEndLine := movedLine.
       
  1198         selectionStartCol := clickStartCol.
       
  1199         selectionStartLine := clickStartLine.
       
  1200         selectStyle notNil ifTrue:[
       
  1201             selectionStartCol := wordStartCol.
       
  1202             selectionStartLine := wordStartLine.
       
  1203         ]
       
  1204     ].
       
  1205 
       
  1206     selectionStartLine isNil ifTrue:[^ self].
       
  1207 
       
  1208     (selectionStartCol == 0) ifTrue:[
       
  1209         selectionStartCol := 1
       
  1210     ].
       
  1211 
       
  1212     "
       
  1213      if in word-select, just catch the rest of the word
       
  1214     "
       
  1215     (selectStyle notNil and:[selectStyle startsWith:'word']) ifTrue:[
       
  1216         movedUp ifTrue:[
       
  1217             selectionStartCol := self findBeginOfWordAtLine:selectionStartLine col:selectionStartCol
       
  1218         ] ifFalse:[
       
  1219             selectionEndCol := self findEndOfWordAtLine:selectionEndLine col:selectionEndCol.
       
  1220             selectionEndCol == 0 ifTrue:[
       
  1221                 selectionEndLine := selectionEndLine + 1
       
  1222             ]
       
  1223         ].
       
  1224     ].
       
  1225 
       
  1226     selectStyle == #line ifTrue:[
       
  1227         movedUp ifTrue:[
       
  1228             selectionStartCol := 1.
       
  1229         ] ifFalse:[
       
  1230             selectionEndCol := 0.
       
  1231             selectionEndLine := selectionEndLine + 1
       
  1232         ]
       
  1233     ].
       
  1234 
       
  1235     self validateNewSelection.
       
  1236 
       
  1237     self clearSearchAction.
       
  1238 
       
  1239     (oldStartLine == selectionStartLine) ifTrue:[
       
  1240         (oldStartCol ~~ selectionStartCol) ifTrue:[
       
  1241             self redrawLine:oldStartLine 
       
  1242                        from:((selectionStartCol min:oldStartCol) max:1)
       
  1243                          to:((selectionStartCol max:oldStartCol) max:1)
       
  1244         ]
       
  1245     ] ifFalse:[
       
  1246         self redrawFromLine:(oldStartLine min:selectionStartLine)
       
  1247                          to:(oldStartLine max:selectionStartLine)
       
  1248     ].
       
  1249 
       
  1250     (oldEndLine == selectionEndLine) ifTrue:[
       
  1251         (oldEndCol ~~ selectionEndCol) ifTrue:[
       
  1252             self redrawLine:oldEndLine 
       
  1253                        from:((selectionEndCol min:oldEndCol) max:1)
       
  1254                          to:((selectionEndCol max:oldEndCol) max:1)
       
  1255         ]
       
  1256     ] ifFalse:[
       
  1257         selectionStartLine notNil ifTrue:[
       
  1258             self redrawFromLine:(oldEndLine min:selectionEndLine)
       
  1259                              to:(oldEndLine max:selectionEndLine)
       
  1260         ]
       
  1261     ].
       
  1262     clickLine := movedLine.
       
  1263     clickCol := movedCol
       
  1264 
  1127 
  1265     "Modified: / 28.7.1998 / 16:02:18 / cg"
  1128     "Modified: / 28.7.1998 / 16:02:18 / cg"
  1266 !
  1129 !
  1267 
  1130 
  1268 buttonMultiPress:button x:x y:y
  1131 buttonMultiPress:button x:x y:y
  1302     sensor       := self sensor.
  1165     sensor       := self sensor.
  1303 
  1166 
  1304     ((button == 1) or:[button == #select]) ifTrue:[
  1167     ((button == 1) or:[button == #select]) ifTrue:[
  1305         sensor shiftDown ifTrue:[
  1168         sensor shiftDown ifTrue:[
  1306             "mouse-click with shift - adding to selection"
  1169             "mouse-click with shift - adding to selection"
  1307 
  1170             self extendSelectionToX:x y:y.
  1308             "very simple - just simulate a move"
  1171             ^ self
  1309             ^ self buttonMotion:(device button1MotionMask) x:x y:y
       
  1310         ].
  1172         ].
  1311 
  1173 
  1312         clickVisibleLine := self visibleLineOfY:y.
  1174         clickVisibleLine := self visibleLineOfY:y.
  1313         clickPos := x @ y.
  1175         clickPos := x @ y.
  1314         clickCol := self colOfX:x inVisibleLine:clickVisibleLine.
  1176         clickCol := self colOfX:x inVisibleLine:clickVisibleLine.
  1511         wordEndCol := selectionEndCol
  1373         wordEndCol := selectionEndCol
  1512     ]
  1374     ]
  1513 
  1375 
  1514     "Created: 11.9.1997 / 04:12:55 / cg"
  1376     "Created: 11.9.1997 / 04:12:55 / cg"
  1515     "Modified: 19.9.1997 / 06:43:10 / cg"
  1377     "Modified: 19.9.1997 / 06:43:10 / cg"
       
  1378 !
       
  1379 
       
  1380 extendSelectionToX:x y:y
       
  1381     "mouse-move while button was pressed - handle selection changes"
       
  1382 
       
  1383     |movedVisibleLine movedLine movedCol 
       
  1384      movedUp 
       
  1385      oldStartLine oldEndLine oldStartCol oldEndCol|
       
  1386 
       
  1387     movedVisibleLine := self visibleLineOfY:y.
       
  1388     movedLine := self visibleLineToAbsoluteLine:movedVisibleLine.
       
  1389 
       
  1390     (x < leftMargin) ifTrue:[
       
  1391         movedCol := 0
       
  1392     ] ifFalse:[
       
  1393         movedCol := self colOfX:x inVisibleLine:movedVisibleLine
       
  1394     ].
       
  1395     y < 0 ifTrue:[
       
  1396         movedCol := 0
       
  1397     ].
       
  1398     ((movedLine == clickLine) and:[movedCol == clickCol]) ifTrue:[
       
  1399         selectionStartLine notNil ifTrue:[
       
  1400             ^ self
       
  1401         ].
       
  1402         (clickPos isNil 
       
  1403         or:[(clickPos x - x) abs < 3 
       
  1404             and:[(clickPos y - y) abs < 3]]) ifTrue:[
       
  1405             ^ self
       
  1406         ].
       
  1407         selectionStartLine := clickLine.
       
  1408         selectionStartCol := clickCol.
       
  1409         selectionEndLine := selectionStartLine.
       
  1410         selectionEndCol := selectionStartCol.
       
  1411 
       
  1412         oldStartLine := selectionStartLine.
       
  1413         oldEndLine := selectionEndLine.
       
  1414         oldStartCol := selectionStartCol.
       
  1415         oldEndCol := selectionEndCol-1.
       
  1416     ] ifFalse:[
       
  1417         selectionStartLine isNil ifTrue:[
       
  1418             selectionStartLine := clickLine.
       
  1419             selectionStartCol := clickCol.
       
  1420             selectionEndLine := selectionStartLine.
       
  1421             selectionEndCol := selectionStartCol
       
  1422         ].
       
  1423         oldStartLine := selectionStartLine.
       
  1424         oldEndLine := selectionEndLine.
       
  1425         oldStartCol := selectionStartCol.
       
  1426         oldEndCol := selectionEndCol.
       
  1427     ].
       
  1428 
       
  1429     "find out if we are before or after initial click"
       
  1430     movedUp := false.
       
  1431     (movedLine < clickStartLine) ifTrue:[
       
  1432         movedUp := true
       
  1433     ] ifFalse:[
       
  1434         (movedLine == clickStartLine) ifTrue:[
       
  1435             (movedCol < clickStartCol) ifTrue:[
       
  1436                 movedUp := true
       
  1437             ]
       
  1438         ]
       
  1439     ].
       
  1440 
       
  1441     movedUp ifTrue:[
       
  1442         "change selectionStart"
       
  1443         selectionStartCol := movedCol.
       
  1444         selectionStartLine := movedLine.
       
  1445         selectionEndCol := clickStartCol.
       
  1446         selectionEndLine := clickStartLine.
       
  1447         selectStyle notNil ifTrue:[
       
  1448             selectionEndCol := wordEndCol.
       
  1449             selectionEndLine := wordEndLine.
       
  1450         ]
       
  1451     ] ifFalse:[
       
  1452         "change selectionEnd"
       
  1453         selectionEndCol := movedCol.
       
  1454         selectionEndLine := movedLine.
       
  1455         selectionStartCol := clickStartCol.
       
  1456         selectionStartLine := clickStartLine.
       
  1457         selectStyle notNil ifTrue:[
       
  1458             selectionStartCol := wordStartCol.
       
  1459             selectionStartLine := wordStartLine.
       
  1460         ]
       
  1461     ].
       
  1462 
       
  1463     selectionStartLine isNil ifTrue:[^ self].
       
  1464 
       
  1465     (selectionStartCol == 0) ifTrue:[
       
  1466         selectionStartCol := 1
       
  1467     ].
       
  1468 
       
  1469     "
       
  1470      if in word-select, just catch the rest of the word
       
  1471     "
       
  1472     (selectStyle notNil and:[selectStyle startsWith:'word']) ifTrue:[
       
  1473         movedUp ifTrue:[
       
  1474             selectionStartCol := self findBeginOfWordAtLine:selectionStartLine col:selectionStartCol
       
  1475         ] ifFalse:[
       
  1476             selectionEndCol := self findEndOfWordAtLine:selectionEndLine col:selectionEndCol.
       
  1477             selectionEndCol == 0 ifTrue:[
       
  1478                 selectionEndLine := selectionEndLine + 1
       
  1479             ]
       
  1480         ].
       
  1481     ].
       
  1482 
       
  1483     selectStyle == #line ifTrue:[
       
  1484         movedUp ifTrue:[
       
  1485             selectionStartCol := 1.
       
  1486         ] ifFalse:[
       
  1487             selectionEndCol := 0.
       
  1488             selectionEndLine := selectionEndLine + 1
       
  1489         ]
       
  1490     ].
       
  1491 
       
  1492     self validateNewSelection.
       
  1493 
       
  1494     self clearSearchAction.
       
  1495 
       
  1496     (oldStartLine == selectionStartLine) ifTrue:[
       
  1497         (oldStartCol ~~ selectionStartCol) ifTrue:[
       
  1498             self redrawLine:oldStartLine 
       
  1499                        from:((selectionStartCol min:oldStartCol) max:1)
       
  1500                          to:((selectionStartCol max:oldStartCol) max:1)
       
  1501         ]
       
  1502     ] ifFalse:[
       
  1503         self redrawFromLine:(oldStartLine min:selectionStartLine)
       
  1504                          to:(oldStartLine max:selectionStartLine)
       
  1505     ].
       
  1506 
       
  1507     (oldEndLine == selectionEndLine) ifTrue:[
       
  1508         (oldEndCol ~~ selectionEndCol) ifTrue:[
       
  1509             self redrawLine:oldEndLine 
       
  1510                        from:((selectionEndCol min:oldEndCol) max:1)
       
  1511                          to:((selectionEndCol max:oldEndCol) max:1)
       
  1512         ]
       
  1513     ] ifFalse:[
       
  1514         selectionStartLine notNil ifTrue:[
       
  1515             self redrawFromLine:(oldEndLine min:selectionEndLine)
       
  1516                              to:(oldEndLine max:selectionEndLine)
       
  1517         ]
       
  1518     ].
       
  1519     clickLine := movedLine.
       
  1520     clickCol := movedCol
       
  1521 
       
  1522     "Modified: / 28.7.1998 / 16:02:18 / cg"
  1516 !
  1523 !
  1517 
  1524 
  1518 keyPress:key x:x y:y
  1525 keyPress:key x:x y:y
  1519     "handle some keyboard input (there is not much to be done here)"
  1526     "handle some keyboard input (there is not much to be done here)"
  1520 
  1527 
  3847 ! !
  3854 ! !
  3848 
  3855 
  3849 !TextView class methodsFor:'documentation'!
  3856 !TextView class methodsFor:'documentation'!
  3850 
  3857 
  3851 version
  3858 version
  3852     ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.258 2006-01-24 16:50:59 cg Exp $'
  3859     ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.259 2006-01-31 15:09:06 cg Exp $'
  3853 ! !
  3860 ! !
  3854 
  3861 
  3855 TextView initialize!
  3862 TextView initialize!