EdMouse.icl 6.81 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
implementation module EdMouse

//*********************************************************************************
// Original Clean Library Software Module
// Written for Clean version  : 1.3
// Written for I/O version    : 1.2
// Author                     : Diederik van Arkel
// Date                       :
// Last Modified by           :
// Date                       :
// Copyright                  : 1999 Hilt - High Level Software Tools B.V.
//                            : University of Nijmegen
// e-mail                     : clean@cs.kun.nl or rinus@hilt.nl
//*********************************************************************************
// It is allowed to modify this module for your own purposes but it is NOT allowed
// to (re)distribute the code or the modified code in ANY form without written
// permission.
//*********************************************************************************

/*
 * EdMouse.icl: handling mouse events
 */

import StdClass, StdInt, StdBool, StdArray, StdChar, StdList, StdTuple
import StdIOCommon, StdPSt, StdWindow
import EdVisualCursor, EdVisualText, EdSelection

import EdAction, EdMonad, EdCommon
import Platform

platformCommand mods
	:== PlatformDependant mods.controlDown mods.commandDown

/* editWindowMouse wraps the monadic mouse function, so that the type
 * conforms to that of a call-back function in the Object I/O library
 */
/*
editWindowMouse :: Tree MouseState (!EditState, !PSt PLocState) -> (EditState, PSt PLocState)
editWindowMouse tree mouseState state
  # state = p4mouse tree mouseState state					// P4
*/
editWindowMouse :: MouseState (!EditState, !PSt PLocState) -> (EditState, PSt PLocState)
editWindowMouse mouseState state
  = noResult
	  (
	  	setVirtualX 0	>>>
	  	mouse mouseState
	  ) state 

mouse :: MouseState -> EditMonad (PSt PLocState) nothing
mouse (MouseDown point mods=:{shiftDown} nrDown)
  = vHideCursor					>>>
    getText						>>>= \text ->
    getFontInfo					>>>= \fontInfo ->
	let
		position = pointToPosition point text fontInfo
	in
	IF ( platformCommand mods )
	THEN
	  ( case nrDown of
			1 -> singleClick position
			2 -> controlDoubleClick shiftDown position
			3 -> tripleClick position
			_ -> skip
	  )
	ELSE
	(
	IF shiftDown
	THEN 
	  ( shiftClick position )
	ELSE
	  ( case nrDown of
			1 -> singleClick position
			2 -> doubleClick position
			3 -> tripleClick position
			_ -> skip
	  )
	)        	  
mouse (MouseDrag point modifiers)		 // mouse drag
  = getSelection						>>>= \selection -> 
	getText								>>>= \text ->
	getFontInfo							>>>= \fontInfo ->
	let
		newPosition = pointToPosition point text fontInfo
	in
	getSelectMode						>>>= \selectMode ->
	
	// change the selection depending on the current selection mode
	(case selectMode of 
		SelectChars ->
			vChangeSelectionTo {start=selection.start, end=newPosition} 

		SelectWords firstWord ->
			selectWordAt newPosition		>>>= \endSelection ->
			
			IF (newPosition < firstWord.end)
			THEN
			  ( vChangeSelectionTo { start=firstWord.end
			  					   , end=endSelection.start
			  					   }
			  )
			ELSE
			  (
			  	vChangeSelectionTo { start=firstWord.start
			  					   , end=endSelection.end
			  					   }
			  )
		
		SelectLines firstLine ->
			getText						>>>= \text ->
			vChangeSelectionTo (selectLines firstLine newPosition.row text)
	)									>>>
	vScrollToCursor

mouse (MouseUp point modifiers)					   // mouse up handling
  = getSelection						>>>= \selection ->
    mChangeSelectionTo selection		>>>
    IF (isEmptySelection selection)
    THEN ( vShowCursor )
    ELSE ( skip )

mouse _											   // ignore other mouse events
  = skip

// single click
//singleClick :: .Position -> .(*(EditState,*PSt *General) -> *(b,*(EditState,*PSt *General)));
singleClick position =
	vChangeSelectionTo 
		{start=position,end=position}			>>>
	setSelectMode SelectChars					>>>
    getUndoInfo                                     >>>= \undoinfo ->
    case undoinfo.uninfo of
    (InsertInfo True state) -> setUndoInfo {undoinfo & uninfo=(InsertInfo False state)}
    (RemoveInfo True state) -> setUndoInfo {undoinfo & uninfo=(RemoveInfo False state)}
    _ -> skip

// double click
//doubleClick :: .Position -> .(*(EditState,*PSt *General) -> *(b,*(EditState,*PSt *General)));
doubleClick position =
	selectWordAt position						>>>= \selection ->
	vChangeSelectionTo selection				>>>
	setSelectMode (SelectWords selection)

// triple click
//tripleClick :: .Position -> .(*(EditState,*PSt *General) -> *(b,*(EditState,*PSt *General)));
tripleClick position=:{row} =
	getText										>>>= \text ->
	vChangeSelectionTo
		 (selectLines row row text)				>>>
 	setSelectMode (SelectLines row)

// shift click
//shiftClick :: .Position -> .(*(EditState,*PSt *General) -> *(b,*(EditState,*PSt *General)));
shiftClick position =
	getSelection								>>>= \selection ->
	vChangeSelectionTo
		{start=selection.start, end=position}

//--

noMouseMoved :: !MouseState -> Bool
noMouseMoved (MouseMove _ _) = doP4
noMouseMoved _				 = True

//-- P4 --- !!! ZITTEN OOK NOG WIJZIGINGEN IN EdMonad !!!

doP4 :== False
noP4 :== True
/*
import StdTimer,tooltip,PmParse,UtilStrictLists,EdFile,treeparse

p4mouse boom mouseState state
  | noP4 = state
  # (winId,state)	= getWindowId state								// P4
  # (timId,state)	= getTimerId state								// P4
  # pos				= getMouseStatePos mouseState					// P4
  # (oldpos,state)	= getToolPt state								// P4
  # state			= case (pos == oldpos) of						// P4
  						True	-> state							// P4
  						_		-> p4fun boom timId winId pos state		// P4
  # (_,state)		= setToolPt pos state							// P4
  = state															// P4

p4fun boom timerId windowId pos state
    # (text,state)		= getText state
    # (fontInfo,state)	= getFontInfo state
	# position			= pointToPosition pos text fontInfo
	# (sel,state)		= selectWordAt position state
	# orderedSelection	= orderSelection sel
	# (fragment, _)		= getTextFragment orderedSelection text
	# str				= stringsToString fragment
	# (es,ps)			= state
	# ps				= appPIO (closeTimer timerId) ps
	# (_,ps)			= openTimer Void (tdef boom timerId windowId pos str) ps 
	= (es,ps)

tdef boom timerId winId pos str = Timer (1 * ticksPerSecond) NilLS [TimerId timerId,TimerFunction tfunctie]
where
	tfunctie nr_of_intervals (ls,ps)
//		# (def,ps)	= findDefinition str ps
		# def		= searchTree str boom
		# ps		= ShowToolTip winId pos.x pos.y def ps
		# ps		= appPIO (closeTimer timerId) ps
		= (ls,ps)

//    # (boom, ps) 	= readFileInTree ps

findDefinition str ps
	# mod				= "C:\\Projects\\CleanIDE\\Ed\\EdText.dcl"
	# ((imp,pos),ps)	= accFiles (FindDefinitionInFile False Nil str mod) ps
	# found = case pos of
		(Pos ln cn tl)	-> Just ln
		(Cls ln cn tl)	-> Just ln
		_				-> Nothing
	| isNothing found
		= (str+++" not found ",ps)
	# ln				= fromJust found
	# ((txt,_,_),ps)	= readText mod ps
	| isError txt
		= (mod+++" not read ",ps)
	# txt				= fromOk txt
	# (line,txt)		= getLine ln txt
	= (line,ps)
*/