1 /*--------------------------------------------------------------------
2 nxeditor
3 FILE NAME:cursor.c
4 Programed by : I.Neva
5 R & D ADVANCED SYSTEMS. IMAGING PRODUCTS.
6 1992.06.01
7
8 Copyright (c) 1998,1999,2000 SASAKI Shunsuke.
9 All rights reserved.
10 --------------------------------------------------------------------*/
11 #include "ed.h"
12 #include <ctype.h>
13
14
GetCol()15 int GetCol() {return csrle.cx;}
GetScroll()16 int GetScroll() {return csrle.sx;}
GetBufferOffset()17 int GetBufferOffset() {return csrle.lx;}
18
GetRow()19 int GetRow() {return csrse.cy;}
GetLineOffset()20 long GetLineOffset() {return csrse.ly;}
21
22
csr_fix()23 void csr_fix()
24 {
25 csrse.f_cx=csrle.cx;
26 csrse.f_sx=csrle.sx;
27 }
28
csr_lenew()29 void csr_lenew()
30 {
31 strcpy(csrle.buf, GetList(GetLineOffset())->buffer);
32 csrle.dsize=GetColWidth()- NumWidth; // !!
33 }
34
csr_leupdate()35 void csr_leupdate()
36 {
37 EditLine *ed;
38
39 ed=GetList(GetLineOffset());
40 if (strcmp(csrle.buf, ed->buffer)!=0)
41 {
42 Realloc(ed, csrle.buf);
43 SetFileChangeFlag();
44 }
45 }
46
csr_movehook()47 void csr_movehook()
48 {
49 block_cmove();
50 search_clrword();
51 }
52
OffsetSetByColumn()53 void OffsetSetByColumn()
54 {
55 int i;
56 int csx,f_csx;
57
58 f_csx=csrse.f_cx+csrse.f_sx;
59 csx=0;
60 for (i=0; csx<f_csx;)
61 {
62 if (csrle.buf[i]=='\0')
63 break;
64 csx+= kanji_countdsp(csrle.buf[i], csx);
65 i=kanji_posnext(i, csrle.buf);
66 }
67
68 if (sysinfo.freecursorf)
69 i+= f_csx-csx;
70
71 if (csx>f_csx)
72 i=kanji_posprev(i, csrle.buf);
73
74 csrle.sx=csrse.f_sx;
75 le_setlx(&csrle,i);
76 }
77
csr_setlx(int lx)78 void csr_setlx(int lx)
79 {
80 le_setlx(&csrle,lx);
81 csr_fix();
82
83 csr_movehook();
84 }
85
86
87
88
LineOffsetSet(long n)89 void LineOffsetSet(long n)
90 {
91 csr_leupdate();
92
93 n=max(n, GetTopNumber());
94 n=min(n, GetLastNumber());
95
96 csrse.ed=GetList(n);
97 csrse.ly=n;
98
99 csr_lenew();
100 OffsetSetByColumn();
101
102 csr_movehook();
103 }
104
CursorSetRow(int n)105 void CursorSetRow(int n)
106 {
107 n=max(n,GetMinRow());
108 n=min(n,GetMaxRow()-1);
109 csrse.cy=n;
110 }
111
csr_getsy()112 long csr_getsy() {return csrse.ly-csrse.cy;}
113
csr_setly(long n)114 void csr_setly(long n)
115 {
116 n=max(n,GetTopNumber());
117 n=min(n,GetLastNumber());
118
119 if (n==GetLineOffset())
120 return;
121
122 if (n<GetRow())
123 CursorSetRow(n);
124 LineOffsetSet(n);
125 }
126
csr_setdy(int dy)127 void csr_setdy(int dy)
128 {
129 dy=min(dy,GetLastNumber());
130
131 LineOffsetSet(GetLineOffset()+dy-GetRow());
132
133 dy=max(dy,GetMinRow());
134 dy=min(dy,GetMaxRow()-1);
135 csrse.cy=dy;
136 }
137
138
CursorMove()139 void CursorMove()
140 {
141 if (csrle.lx==strlen(csrle.buf)&& csrse.ly<GetLastNumber()
142 && sysinfo.crmarkf)
143 {
144 term_locate(GetRow(), GetCol()+NumWidth);
145 term_color_normal();
146 term_putch(' '); /* �����ޡ�����ä��� */
147
148 csrse.gf=TRUE;
149 }
150
151 term_locate(GetRow(), GetCol()+NumWidth);
152 }
153
154
155
156
157
158
159
160
161
162
163
op_cursor_up()164 SHELL void op_cursor_up()
165 {
166 csr_setdy(GetRow()-1);
167 }
168
op_cursor_down()169 SHELL void op_cursor_down()
170 {
171 if (GetLineOffset() < GetLastNumber())
172 csr_setdy(GetRow()+1);
173 }
174
op_cursor_sleft()175 SHELL void op_cursor_sleft()
176 {
177 csr_setlx(0);
178 }
179
op_cursor_sright()180 SHELL void op_cursor_sright()
181 {
182 csr_setlx(strlen(csrle.buf));
183 }
184
185
op_cursor_tkprev()186 SHELL void op_cursor_tkprev()
187 {
188 if (GetBufferOffset()>0)
189 csr_setlx(kanji_tkprev(csrle.buf, csrle.lx, TRUE)); else
190 {
191 if (GetLineOffset() > 1)
192 {
193 op_cursor_up();
194 op_cursor_sright();
195 }
196 }
197 }
198
op_cursor_tknext()199 SHELL void op_cursor_tknext()
200 {
201 if (GetBufferOffset()<strlen(csrle.buf))
202 csr_setlx(kanji_tknext(csrle.buf,csrle.lx,TRUE)); else
203 {
204 if (GetLineOffset() < GetLastNumber())
205 {
206 op_cursor_down();
207 op_cursor_sleft();
208 }
209 }
210 }
211
op_cursor_left()212 SHELL void op_cursor_left()
213 {
214 if (GetBufferOffset()>0)
215 csr_setlx(GetBufferOffset()-1); else
216 {
217 if (GetLineOffset() > 1)
218 {
219 op_cursor_up();
220 op_cursor_sright();
221 }
222 }
223
224 }
225
op_cursor_right()226 SHELL void op_cursor_right()
227 {
228 if (sysinfo.freecursorf||
229 GetBufferOffset()<strlen(csrle.buf))
230 csr_setlx(GetBufferOffset()+1+ (IsKanjiPosition()?1:0)); else
231 {
232 if (GetLineOffset() < GetLastNumber())
233 {
234 op_cursor_down();
235 op_cursor_sleft();
236 }
237 }
238
239 }
240
op_cursor_sup()241 SHELL void op_cursor_sup()
242 {
243 csr_setdy(GetMinRow());
244 }
245
op_cursor_sdown()246 SHELL void op_cursor_sdown()
247 {
248 csr_setdy(min(GetMaxRow()-1,GetRow()+GetLastNumber()-GetLineOffset()));
249 }
250
op_cursor_top()251 SHELL void op_cursor_top()
252 {
253 lm_mark(GetLineOffset(), 0);
254 csr_setly(GetTopNumber());
255 }
256
op_cursor_bottom()257 SHELL void op_cursor_bottom()
258 {
259 lm_mark(GetLineOffset(), 0);
260 csr_setly(GetLastNumber());
261 csr_setdy(GetMaxRow()-1);
262 }
263
op_cursor_pup()264 SHELL void op_cursor_pup()
265 {
266 if (edbuf[CurrentFileNo].pm)
267 op_search_prev(); else
268 csr_setly(GetLineOffset()-(GetRowWidth()-1));
269 }
270
op_cursor_pdown()271 SHELL void op_cursor_pdown()
272 {
273 if (edbuf[CurrentFileNo].pm)
274 op_search_next(); else
275 csr_setly(GetLineOffset()+(GetRowWidth()-1));
276 }
277
op_cursor_rup()278 SHELL void op_cursor_rup()
279 {
280 int n;
281
282 n=0;
283 if (keyf_numarg()>0)
284 n= atoi(keyf_getarg(0));
285
286 csr_setly(GetLineOffset()- (n<=0?1:n));
287 }
288
op_cursor_rdown()289 SHELL void op_cursor_rdown()
290 {
291 int n;
292
293 n=0;
294 if (keyf_numarg()>0)
295 n=atoi(keyf_getarg(0));
296
297 csr_setly(GetLineOffset()+ (n<=0?1:n));
298 }
299
300
301