1 | #include "common.h" |
---|
2 | |
---|
3 | extern int font_width,font_height; |
---|
4 | |
---|
5 | BOOL IsRightTurn(char *pBuf,int i,int now_x){ |
---|
6 | if(pobj_nv->bRightTurn==0) return 0; |
---|
7 | if(pobj_nv->iMaxOneLineTextLength-1<=now_x && pBuf[i]!='\r') return 1; |
---|
8 | return 0; |
---|
9 | } |
---|
10 | |
---|
11 | int GetBufferIndexFromCaretPos(char *pBuf,int now_x,int now_y){ |
---|
12 | int i,i2; |
---|
13 | int x,y; |
---|
14 | |
---|
15 | // 行の確認 |
---|
16 | for(i=0,x=0,y=0;;i++,x++){ |
---|
17 | if(y>=now_y) break; |
---|
18 | if(pBuf[i]=='\0') return 0; |
---|
19 | if(IsRightTurn(pBuf,i,x)){ |
---|
20 | //右端で折り返す |
---|
21 | y++; |
---|
22 | x=-1; |
---|
23 | i--; |
---|
24 | continue; |
---|
25 | } |
---|
26 | if(pBuf[i]=='\t'){ |
---|
27 | //タブ文字 |
---|
28 | int tab; |
---|
29 | tab=pobj_nv->TabSize; |
---|
30 | |
---|
31 | if(x%tab==0) i2=tab; |
---|
32 | else i2=tab-x%tab; |
---|
33 | x+=i2-1; |
---|
34 | continue; |
---|
35 | } |
---|
36 | else if(IsDBCSLeadByte(pBuf[i])){ |
---|
37 | //マルチバイト文字 |
---|
38 | x++; |
---|
39 | i++; |
---|
40 | continue; |
---|
41 | } |
---|
42 | |
---|
43 | if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'){ |
---|
44 | y++; |
---|
45 | i++; |
---|
46 | x=-1; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | //列の確認 |
---|
51 | for(x=0;x<now_x;i++,x++){ |
---|
52 | if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'||pBuf[i]=='\0') return 0; |
---|
53 | |
---|
54 | if(pBuf[i]=='\t'){ |
---|
55 | //タブ文字 |
---|
56 | int tab; |
---|
57 | tab=pobj_nv->TabSize; |
---|
58 | |
---|
59 | if(x%tab==0) i2=tab; |
---|
60 | else i2=tab-x%tab; |
---|
61 | x+=i2-1; |
---|
62 | continue; |
---|
63 | } |
---|
64 | else if(IsDBCSLeadByte(pBuf[i])){ |
---|
65 | //マルチバイト文字 |
---|
66 | x++; |
---|
67 | i++; |
---|
68 | continue; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | return i; |
---|
73 | } |
---|
74 | void GetCaretPosFromBufferIndex(char *pBuf,int index,POINT *pCaretPos){ |
---|
75 | int i,i2; |
---|
76 | |
---|
77 | pCaretPos->x=0; |
---|
78 | pCaretPos->y=0; |
---|
79 | for(i=0;i<index;i++,pCaretPos->x++){ |
---|
80 | if(pBuf[i]=='\0') break; |
---|
81 | if(IsRightTurn(pBuf,i,pCaretPos->x)){ |
---|
82 | //右端で折り返す |
---|
83 | pCaretPos->y++; |
---|
84 | pCaretPos->x=-1; |
---|
85 | i--; |
---|
86 | continue; |
---|
87 | } |
---|
88 | if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'){ |
---|
89 | pCaretPos->x=-1; |
---|
90 | pCaretPos->y++; |
---|
91 | i++; |
---|
92 | continue; |
---|
93 | } |
---|
94 | if(IsDBCSLeadByte(pBuf[i])){ |
---|
95 | i++; |
---|
96 | pCaretPos->x++; |
---|
97 | continue; |
---|
98 | } |
---|
99 | if(pBuf[i]=='\t'){ |
---|
100 | //タブ文字 |
---|
101 | int tab; |
---|
102 | tab=pobj_nv->TabSize; |
---|
103 | |
---|
104 | if(pCaretPos->x%tab==0) i2=tab; |
---|
105 | else i2=tab-pCaretPos->x%tab; |
---|
106 | pCaretPos->x+=i2-1; |
---|
107 | continue; |
---|
108 | } |
---|
109 | else if(IsDBCSLeadByte(pBuf[i])){ |
---|
110 | //マルチバイト文字 |
---|
111 | pCaretPos->x++; |
---|
112 | i++; |
---|
113 | continue; |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | void TextEdit_GetSel(int WndNum,CHARRANGE *pCharRange){ |
---|
119 | ////////////////////////////////////////// |
---|
120 | // 選択範囲(バッファインデックス)を取得 |
---|
121 | ////////////////////////////////////////// |
---|
122 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
123 | |
---|
124 | pCharRange->cpMin=GetBufferIndexFromCaretPos( |
---|
125 | MdiInfo[WndNum].pmti->buffer, |
---|
126 | MdiInfo[WndNum].pmti->StartCaretPos.x, |
---|
127 | MdiInfo[WndNum].pmti->StartCaretPos.y); |
---|
128 | |
---|
129 | if(MdiInfo[WndNum].pmti->StartCaretPos.x==MdiInfo[WndNum].pmti->EndCaretPos.x&& |
---|
130 | MdiInfo[WndNum].pmti->StartCaretPos.y==MdiInfo[WndNum].pmti->EndCaretPos.y){ |
---|
131 | //選択されていないとき |
---|
132 | pCharRange->cpMax=pCharRange->cpMin; |
---|
133 | } |
---|
134 | else{ |
---|
135 | pCharRange->cpMax=GetBufferIndexFromCaretPos( |
---|
136 | MdiInfo[WndNum].pmti->buffer, |
---|
137 | MdiInfo[WndNum].pmti->EndCaretPos.x, |
---|
138 | MdiInfo[WndNum].pmti->EndCaretPos.y); |
---|
139 | } |
---|
140 | |
---|
141 | if(pCharRange->cpMin>pCharRange->cpMax){ |
---|
142 | long temp; |
---|
143 | temp=pCharRange->cpMin; |
---|
144 | pCharRange->cpMin=pCharRange->cpMax; |
---|
145 | pCharRange->cpMax=temp; |
---|
146 | } |
---|
147 | } |
---|
148 | void TextEdit_GetSelText(int WndNum,CHARRANGE *pCharRange,char *buffer){ |
---|
149 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
150 | |
---|
151 | memcpy(buffer, |
---|
152 | MdiInfo[WndNum].pmti->buffer+pCharRange->cpMin, |
---|
153 | pCharRange->cpMax-pCharRange->cpMin); |
---|
154 | buffer[pCharRange->cpMax-pCharRange->cpMin]=0; |
---|
155 | } |
---|
156 | |
---|
157 | void GetScrollBaseCaretPos(int WndNum,int *pNaturalBaseX,int *pNaturalBaseY){ |
---|
158 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
159 | |
---|
160 | HWND hEdit; |
---|
161 | hEdit=MdiInfo[WndNum].pmti->hEdit; |
---|
162 | |
---|
163 | //垂直スクロールバーの位置 |
---|
164 | SCROLLINFO si; |
---|
165 | si.cbSize=sizeof(SCROLLINFO); |
---|
166 | si.fMask=SIF_POS; |
---|
167 | GetScrollInfo(hEdit,SB_VERT,&si); |
---|
168 | *pNaturalBaseY-=si.nPos; //文字単位 |
---|
169 | |
---|
170 | //水平スクロールバーの位置 |
---|
171 | GetScrollInfo(hEdit,SB_HORZ,&si); |
---|
172 | *pNaturalBaseX-=si.nPos; //文字単位 |
---|
173 | } |
---|
174 | |
---|
175 | void GetNaturalBaseCaretPos(int WndNum,int *pScrollBaseX,int *pScrollBaseY){ |
---|
176 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
177 | |
---|
178 | HWND hEdit; |
---|
179 | hEdit=GetWindow(MdiInfo[WndNum].hwnd,GW_CHILD); |
---|
180 | |
---|
181 | //垂直スクロールバーの位置 |
---|
182 | SCROLLINFO si; |
---|
183 | si.cbSize=sizeof(SCROLLINFO); |
---|
184 | si.fMask=SIF_POS; |
---|
185 | GetScrollInfo(hEdit,SB_VERT,&si); |
---|
186 | *pScrollBaseY+=si.nPos; //文字単位 |
---|
187 | |
---|
188 | //水平スクロールバーの位置 |
---|
189 | GetScrollInfo(hEdit,SB_HORZ,&si); |
---|
190 | *pScrollBaseX+=si.nPos; //文字単位 |
---|
191 | } |
---|
192 | |
---|
193 | void TextEdit_SetSel(int WndNum,int StartIndex,int EndIndex,BOOL bShowCenter){ |
---|
194 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
195 | |
---|
196 | GetCaretPosFromBufferIndex( |
---|
197 | MdiInfo[WndNum].pmti->buffer, |
---|
198 | StartIndex, |
---|
199 | &MdiInfo[WndNum].pmti->StartCaretPos); |
---|
200 | |
---|
201 | GetCaretPosFromBufferIndex( |
---|
202 | MdiInfo[WndNum].pmti->buffer, |
---|
203 | EndIndex, |
---|
204 | &MdiInfo[WndNum].pmti->EndCaretPos); |
---|
205 | |
---|
206 | HWND hEdit; |
---|
207 | hEdit=GetWindow(MdiInfo[WndNum].hwnd,GW_CHILD); |
---|
208 | |
---|
209 | if(!TextEdit_ScrollCaret(WndNum,0,bShowCenter)) |
---|
210 | InvalidateRect(hEdit,NULL,0); |
---|
211 | ResetCaretPos(WndNum); |
---|
212 | |
---|
213 | ResetState_EditMenu(); |
---|
214 | } |
---|
215 | void TextEdit_SelectOneLine(int WndNum,int code_pos,BOOL bShowCenter){ |
---|
216 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
217 | |
---|
218 | /////////////////////// |
---|
219 | // 定義行の選択範囲 |
---|
220 | /////////////////////// |
---|
221 | |
---|
222 | int iStartPos; |
---|
223 | iStartPos=code_pos; |
---|
224 | while(MdiInfo[WndNum].pmti->buffer[iStartPos]!='\n'&&iStartPos>0) iStartPos--; |
---|
225 | if(MdiInfo[WndNum].pmti->buffer[iStartPos]=='\n') iStartPos++; |
---|
226 | |
---|
227 | int iEndPos; |
---|
228 | iEndPos=code_pos; |
---|
229 | while(MdiInfo[WndNum].pmti->buffer[iEndPos]!='\r'&&MdiInfo[WndNum].pmti->buffer[iEndPos]!='\0') iEndPos++; |
---|
230 | |
---|
231 | TextEdit_SetSel(WndNum,iStartPos,iEndPos,bShowCenter); |
---|
232 | } |
---|
233 | void ResetCaretPos(int WndNum,BOOL bInputAndReset){ |
---|
234 | extern HANDLE hHeap; |
---|
235 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
236 | int x,y; |
---|
237 | |
---|
238 | POINT OldPos; |
---|
239 | GetCaretPos(&OldPos); |
---|
240 | |
---|
241 | x=MdiInfo[WndNum].pmti->StartCaretPos.x; |
---|
242 | y=MdiInfo[WndNum].pmti->StartCaretPos.y; |
---|
243 | GetScrollBaseCaretPos(WndNum,&x,&y); |
---|
244 | |
---|
245 | //エディタ画面左端のコントロールタブ |
---|
246 | int iControlTabSpace; |
---|
247 | iControlTabSpace=MdiInfo[WndNum].pmti->iWidth_ControlTabSpace; |
---|
248 | |
---|
249 | //コントロールタブ上にカーソルがきたときに、非表示にする |
---|
250 | if(OldPos.x>=iControlTabSpace&&x<0) HideCaret(MdiInfo[WndNum].pmti->hEdit); |
---|
251 | else if(OldPos.x<iControlTabSpace&&x>=0) ShowCaret(MdiInfo[WndNum].pmti->hEdit); |
---|
252 | |
---|
253 | SetCaretPos( |
---|
254 | x*font_width +iControlTabSpace, |
---|
255 | y*font_height); |
---|
256 | |
---|
257 | SetStatusText(NULL); |
---|
258 | |
---|
259 | |
---|
260 | ////////////////////////////////////////////// |
---|
261 | // Web検索文字列 |
---|
262 | ////////////////////////////////////////////// |
---|
263 | if(IS_DOCUMENT_TEXT(MdiInfo[WndNum].DocType)){ |
---|
264 | int start,end; |
---|
265 | if(MdiInfo[WndNum].pmti->StartCaretPos.x==MdiInfo[WndNum].pmti->EndCaretPos.x&& |
---|
266 | MdiInfo[WndNum].pmti->StartCaretPos.y==MdiInfo[WndNum].pmti->EndCaretPos.y){ |
---|
267 | //文字列を選択中でないとき |
---|
268 | |
---|
269 | int sw=0; |
---|
270 | if(bInputAndReset){ |
---|
271 | if(MdiInfo[WndNum].pmti->StartCaretPos.x>1){ |
---|
272 | MdiInfo[WndNum].pmti->StartCaretPos.x-=2; |
---|
273 | sw=1; |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | TextEdit_GetWordCaret( |
---|
278 | MdiInfo[WndNum].pmti->hEdit, |
---|
279 | WndNum, |
---|
280 | &MdiInfo[WndNum].pmti->StartCaretPos, |
---|
281 | &start,&end, |
---|
282 | WORDCARET_BEFORE); |
---|
283 | |
---|
284 | if(sw) MdiInfo[WndNum].pmti->StartCaretPos.x+=2; |
---|
285 | |
---|
286 | //半角文字列を選択時の全角とのズレを修正 |
---|
287 | POINT pos; |
---|
288 | GetCaretPosFromBufferIndex(MdiInfo[WndNum].pmti->buffer,start,&pos); |
---|
289 | start=GetBufferIndexFromCaretPos(MdiInfo[WndNum].pmti->buffer,pos.x,pos.y); |
---|
290 | GetCaretPosFromBufferIndex(MdiInfo[WndNum].pmti->buffer,end,&pos); |
---|
291 | end=GetBufferIndexFromCaretPos(MdiInfo[WndNum].pmti->buffer,pos.x,pos.y); |
---|
292 | } |
---|
293 | else{ |
---|
294 | //文字列を選択中のとき |
---|
295 | start=GetBufferIndexFromCaretPos( |
---|
296 | MdiInfo[WndNum].pmti->buffer, |
---|
297 | MdiInfo[WndNum].pmti->StartCaretPos.x, |
---|
298 | MdiInfo[WndNum].pmti->StartCaretPos.y); |
---|
299 | end=GetBufferIndexFromCaretPos( |
---|
300 | MdiInfo[WndNum].pmti->buffer, |
---|
301 | MdiInfo[WndNum].pmti->EndCaretPos.x, |
---|
302 | MdiInfo[WndNum].pmti->EndCaretPos.y); |
---|
303 | } |
---|
304 | |
---|
305 | if(start>end){ |
---|
306 | int iTemp; |
---|
307 | iTemp=start; |
---|
308 | start=end; |
---|
309 | end=iTemp; |
---|
310 | } |
---|
311 | |
---|
312 | char *pTemp; |
---|
313 | int length; |
---|
314 | length=end-start; |
---|
315 | if(length<0) length=0; |
---|
316 | pTemp=(char *)HeapAlloc(hHeap,0,length+1024); |
---|
317 | memcpy(pTemp,MdiInfo[WndNum].pmti->buffer+start,length); |
---|
318 | pTemp[length]=0; |
---|
319 | |
---|
320 | char *temp2; |
---|
321 | temp2=strstr(pTemp,"\r\n"); |
---|
322 | if(temp2) temp2[0]=0; |
---|
323 | |
---|
324 | extern HWND hWebSearchCombo; |
---|
325 | SetWindowText(GetWindow(hWebSearchCombo,GW_CHILD),pTemp); |
---|
326 | |
---|
327 | //未完成 |
---|
328 | HeapDefaultFree(pTemp); |
---|
329 | /*if((!IsHiragana(pTemp))&&pTemp[0]&&pTemp[1]){ |
---|
330 | //バックグラウンドでWeb検索をかける |
---|
331 | _beginthread(WebSearchThread,0,(void *)pTemp); |
---|
332 | |
---|
333 | //※pTempはWebSearchThreadスレッド内で破棄する |
---|
334 | } |
---|
335 | else{ |
---|
336 | HeapDefaultFree(pTemp); |
---|
337 | }*/ |
---|
338 | } |
---|
339 | |
---|
340 | |
---|
341 | //////////////////////////////////////////////////// |
---|
342 | // パラメータヒントを更新 |
---|
343 | //////////////////////////////////////////////////// |
---|
344 | |
---|
345 | extern METHODCHECKINFO MethodCheckInfo; |
---|
346 | if(MethodCheckInfo.hWnd){ |
---|
347 | if(MdiInfo[WndNum].DocType==WNDTYPE_BASIC) |
---|
348 | ShowParameterHint(WndNum); |
---|
349 | } |
---|
350 | |
---|
351 | |
---|
352 | ////////////////////////////////// |
---|
353 | // コード補完機能を利用中の場合 |
---|
354 | ////////////////////////////////// |
---|
355 | |
---|
356 | extern COMPLEMENT_WINDOW_INFO ComplementWndInfo; |
---|
357 | if(ComplementWndInfo.hWnd){ |
---|
358 | int i,i2; |
---|
359 | char *pTemp,temporary[VN_SIZE]; |
---|
360 | |
---|
361 | i=GetBufferIndexFromCaretPos(MdiInfo[WndNum].pmti->buffer, |
---|
362 | MdiInfo[WndNum].pmti->StartCaretPos.x, |
---|
363 | MdiInfo[WndNum].pmti->StartCaretPos.y); |
---|
364 | |
---|
365 | if(i<ComplementWndInfo.iPos||ComplementWndInfo.iPos+ComplementWndInfo.iLength<i){ |
---|
366 | //参照文字列以外にカーソルが移動した場合はコード補完リストを破棄 |
---|
367 | |
---|
368 | DestroyWindow(ComplementWndInfo.hWnd); |
---|
369 | ComplementWndInfo.hWnd=0; |
---|
370 | } |
---|
371 | if(ComplementWndInfo.pMemberInfo[0].dwAccess==ACCESS_PAIRCOMMAND){ |
---|
372 | ///////////////////////////////////// |
---|
373 | // ペアステートメント補完 |
---|
374 | ///////////////////////////////////// |
---|
375 | //※リストを自動選択、場合により破棄 |
---|
376 | |
---|
377 | if(ComplementWndInfo.iLength==0){ |
---|
378 | //自動選択の指標となる文字列がないときは、補完ウィンドウを破棄する |
---|
379 | DestroyWindow(ComplementWndInfo.hWnd); |
---|
380 | ComplementWndInfo.hWnd=0; |
---|
381 | return; |
---|
382 | } |
---|
383 | |
---|
384 | pTemp=(char *)HeapAlloc(hHeap,0,ComplementWndInfo.iLength+1); |
---|
385 | memcpy(pTemp, |
---|
386 | MdiInfo[WndNum].pmti->buffer+ComplementWndInfo.iPos, |
---|
387 | ComplementWndInfo.iLength); |
---|
388 | pTemp[ComplementWndInfo.iLength]=0; |
---|
389 | |
---|
390 | for(i=0;i<ComplementWndInfo.MemberNum;i++){ |
---|
391 | ListView_GetItemText(ComplementWndInfo.hList,i,0,temporary,VN_SIZE); |
---|
392 | |
---|
393 | if(memicmp(pTemp,temporary,ComplementWndInfo.iLength)==0){ |
---|
394 | if(lstrcmpi(pTemp,temporary)==0){ |
---|
395 | //完全一致の場合 |
---|
396 | SendMessage(ComplementWndInfo.hList,WM_KEYDOWN,VK_RETURN,0); |
---|
397 | } |
---|
398 | break; |
---|
399 | } |
---|
400 | } |
---|
401 | if(i==ComplementWndInfo.MemberNum){ |
---|
402 | //エンドペアステートメントの先端部分と一致しなかったとき |
---|
403 | DestroyWindow(ComplementWndInfo.hWnd); |
---|
404 | ComplementWndInfo.hWnd=0; |
---|
405 | } |
---|
406 | |
---|
407 | //アイテムを選択 |
---|
408 | ListView_SetItemState(ComplementWndInfo.hList, |
---|
409 | i, |
---|
410 | LVIS_SELECTED|LVIS_FOCUSED, |
---|
411 | LVIS_SELECTED|LVIS_FOCUSED); |
---|
412 | |
---|
413 | //必要であればスクロール |
---|
414 | ListView_EnsureVisible(ComplementWndInfo.hList,i,0); |
---|
415 | |
---|
416 | HeapDefaultFree(pTemp); |
---|
417 | } |
---|
418 | else{ |
---|
419 | ///////////////////////////////// |
---|
420 | // クラスメンバのコード補完機能 |
---|
421 | ///////////////////////////////// |
---|
422 | //※リストを自動選択 |
---|
423 | |
---|
424 | if(ComplementWndInfo.iLength==0){ |
---|
425 | //自動選択の指標となる文字列がないとき |
---|
426 | return; |
---|
427 | } |
---|
428 | |
---|
429 | if(ComplementWndInfo.iLength<0){ |
---|
430 | //文字数がマイナス値になったとき(.や>が消されたとき) |
---|
431 | // 補完ウィンドウを破棄する |
---|
432 | DestroyWindow(ComplementWndInfo.hWnd); |
---|
433 | ComplementWndInfo.hWnd=0; |
---|
434 | return; |
---|
435 | } |
---|
436 | |
---|
437 | pTemp=(char *)HeapAlloc(hHeap,0,ComplementWndInfo.iLength+1); |
---|
438 | memcpy(pTemp, |
---|
439 | MdiInfo[WndNum].pmti->buffer+ComplementWndInfo.iPos, |
---|
440 | ComplementWndInfo.iLength); |
---|
441 | pTemp[ComplementWndInfo.iLength]=0; |
---|
442 | |
---|
443 | for(i=0;i<ComplementWndInfo.MemberNum;i++){ |
---|
444 | ListView_GetItemText(ComplementWndInfo.hList,i,0,temporary,VN_SIZE); |
---|
445 | |
---|
446 | i2=lstrcmpi(pTemp,temporary); |
---|
447 | if(i2<=0) break; |
---|
448 | } |
---|
449 | if(i==ComplementWndInfo.MemberNum) i--; |
---|
450 | |
---|
451 | //アイテムを選択 |
---|
452 | ListView_SetItemState(ComplementWndInfo.hList, |
---|
453 | i, |
---|
454 | LVIS_SELECTED|LVIS_FOCUSED, |
---|
455 | LVIS_SELECTED|LVIS_FOCUSED); |
---|
456 | |
---|
457 | //必要であればスクロール |
---|
458 | ListView_EnsureVisible(ComplementWndInfo.hList,i,0); |
---|
459 | |
---|
460 | HeapDefaultFree(pTemp); |
---|
461 | } |
---|
462 | } |
---|
463 | } |
---|
464 | BOOL TextEdit_ScrollCaret(int WndNum,BOOL bScrollOneStep_x,BOOL bShowCenter){ |
---|
465 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
466 | int x,y; |
---|
467 | BOOL bScroll=0; |
---|
468 | |
---|
469 | HWND hEdit; |
---|
470 | hEdit=MdiInfo[WndNum].pmti->hEdit; |
---|
471 | |
---|
472 | x=MdiInfo[WndNum].pmti->StartCaretPos.x; |
---|
473 | y=MdiInfo[WndNum].pmti->StartCaretPos.y; |
---|
474 | GetScrollBaseCaretPos(WndNum,&x,&y); |
---|
475 | |
---|
476 | //垂直方向 |
---|
477 | SCROLLINFO si; |
---|
478 | si.cbSize=sizeof(SCROLLINFO); |
---|
479 | si.fMask=SIF_POS|SIF_PAGE|SIF_RANGE; |
---|
480 | GetScrollInfo(hEdit,SB_VERT,&si); |
---|
481 | if(bShowCenter==0){ |
---|
482 | //通常キャレットスクロール |
---|
483 | if(y<0){ |
---|
484 | //上へスクロール |
---|
485 | |
---|
486 | si.nPos+=y; |
---|
487 | SetScrollInfo(hEdit,SB_VERT,&si,1); |
---|
488 | InvalidateRect(hEdit,NULL,0); |
---|
489 | bScroll=1; |
---|
490 | } |
---|
491 | if(si.nPage&&y>(int)si.nPage-1){ |
---|
492 | //下へスクロール |
---|
493 | |
---|
494 | si.nPos+=y-si.nPage; |
---|
495 | |
---|
496 | SetScrollInfo(hEdit,SB_VERT,&si,1); |
---|
497 | InvalidateRect(hEdit,NULL,0); |
---|
498 | bScroll=1; |
---|
499 | } |
---|
500 | } |
---|
501 | else{ |
---|
502 | //上部にキャレットがくるようにスクロール |
---|
503 | |
---|
504 | if(y<0|| |
---|
505 | si.nPage&&y>(int)si.nPage-1){ |
---|
506 | |
---|
507 | si.nPos+=y-si.nPage/3; |
---|
508 | SetScrollInfo(hEdit,SB_VERT,&si,1); |
---|
509 | InvalidateRect(hEdit,NULL,0); |
---|
510 | bScroll=1; |
---|
511 | } |
---|
512 | } |
---|
513 | |
---|
514 | |
---|
515 | //水平方向 |
---|
516 | GetScrollInfo(hEdit,SB_HORZ,&si); |
---|
517 | if(x<0){ |
---|
518 | si.nPos+=x-1; |
---|
519 | if(!bScrollOneStep_x) si.nPos-=si.nPage/4; |
---|
520 | if(si.nPos<0) si.nPos=0; |
---|
521 | SetScrollInfo(hEdit,SB_HORZ,&si,1); |
---|
522 | InvalidateRect(hEdit,NULL,0); |
---|
523 | bScroll=1; |
---|
524 | } |
---|
525 | if(si.nPage&&x>(int)si.nPage){ |
---|
526 | si.nPos+=x-si.nPage; |
---|
527 | if(!bScrollOneStep_x) si.nPos+=si.nPage/3; |
---|
528 | SetScrollInfo(hEdit,SB_HORZ,&si,1); |
---|
529 | InvalidateRect(hEdit,NULL,0); |
---|
530 | bScroll=1; |
---|
531 | } |
---|
532 | |
---|
533 | return bScroll; |
---|
534 | } |
---|
535 | |
---|
536 | void CaretPos_LooseToNatural(int WndNum,int loose_x,int loose_y,POINT *pCaretPos){ |
---|
537 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
538 | int i,i2,LastPos; |
---|
539 | int x,y; |
---|
540 | char *pBuf; |
---|
541 | |
---|
542 | //負数の場合は0をセット |
---|
543 | if(loose_x<0) loose_x=0; |
---|
544 | if(loose_y<0) loose_y=0; |
---|
545 | |
---|
546 | pBuf=MdiInfo[WndNum].pmti->buffer; |
---|
547 | |
---|
548 | // 行の確認 |
---|
549 | LastPos=0; |
---|
550 | for(i=0,x=0,y=0;;i++,x++){ |
---|
551 | if(y>=loose_y){ |
---|
552 | pCaretPos->y=y; |
---|
553 | break; |
---|
554 | } |
---|
555 | if(pBuf[i]=='\0'){ |
---|
556 | pCaretPos->y=y; |
---|
557 | i=LastPos; |
---|
558 | break; |
---|
559 | } |
---|
560 | |
---|
561 | if(IsRightTurn(pBuf,i,x)){ |
---|
562 | LastPos=i; |
---|
563 | |
---|
564 | //右端で折り返す |
---|
565 | y++; |
---|
566 | x=-1; |
---|
567 | i--; |
---|
568 | continue; |
---|
569 | } |
---|
570 | if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'){ |
---|
571 | LastPos=i+2; |
---|
572 | y++; |
---|
573 | i++; |
---|
574 | x=-1; |
---|
575 | } |
---|
576 | |
---|
577 | if(pBuf[i]=='\t'){ |
---|
578 | //タブ文字 |
---|
579 | int tab; |
---|
580 | tab=pobj_nv->TabSize; |
---|
581 | |
---|
582 | if(x%tab==0) i2=tab; |
---|
583 | else i2=tab-x%tab; |
---|
584 | x+=i2-1; |
---|
585 | continue; |
---|
586 | } |
---|
587 | else if(IsDBCSLeadByte(pBuf[i])){ |
---|
588 | //マルチバイト文字 |
---|
589 | x++; |
---|
590 | i++; |
---|
591 | continue; |
---|
592 | } |
---|
593 | } |
---|
594 | |
---|
595 | //列の確認 |
---|
596 | x=0; |
---|
597 | for(;;i++,x++){ |
---|
598 | if(IsRightTurn(pBuf,i,x)){ |
---|
599 | //折り返しよりも右側が指定場所のとき |
---|
600 | pCaretPos->x=x; |
---|
601 | break; |
---|
602 | } |
---|
603 | |
---|
604 | if(pBuf[i]=='\t'){ |
---|
605 | //タブ文字 |
---|
606 | int tab; |
---|
607 | tab=pobj_nv->TabSize; |
---|
608 | |
---|
609 | if(x%tab==0) i2=tab; |
---|
610 | else i2=tab-x%tab; |
---|
611 | if(x+i2-1>=loose_x){ |
---|
612 | //指定場所にキャレットが存在するとき(タブ内) |
---|
613 | pCaretPos->x=x; |
---|
614 | break; |
---|
615 | } |
---|
616 | x+=i2-1; |
---|
617 | continue; |
---|
618 | } |
---|
619 | else if(IsDBCSLeadByte(pBuf[i])){ |
---|
620 | //マルチバイト文字 |
---|
621 | x++; |
---|
622 | i++; |
---|
623 | if(x>=loose_x){ |
---|
624 | //マルチバイト文字の間にキャレットが存在するとき |
---|
625 | pCaretPos->x=x-1; |
---|
626 | break; |
---|
627 | } |
---|
628 | continue; |
---|
629 | } |
---|
630 | |
---|
631 | if(x>=loose_x){ |
---|
632 | //指定場所にキャレットが存在するとき(通常) |
---|
633 | pCaretPos->x=x; |
---|
634 | break; |
---|
635 | } |
---|
636 | |
---|
637 | if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'||pBuf[i]=='\0'){ |
---|
638 | //改行文字よりも右側が指定場所のとき |
---|
639 | pCaretPos->x=x; |
---|
640 | break; |
---|
641 | } |
---|
642 | } |
---|
643 | } |
---|
644 | |
---|
645 | void GetNaturalCaretPos_Click(int WndNum,int mouse_x,int mouse_y,POINT *pCaretPos){ |
---|
646 | ///////////////////////////// |
---|
647 | // キャレット移動(クリック) |
---|
648 | ///////////////////////////// |
---|
649 | |
---|
650 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
651 | |
---|
652 | //ピクセル座標をカーソル座標(文字単位)に変更 |
---|
653 | mouse_x=(int)((double)mouse_x/(double)font_width+0.5); |
---|
654 | mouse_y/=font_height; |
---|
655 | GetNaturalBaseCaretPos(WndNum,&mouse_x,&mouse_y); |
---|
656 | |
---|
657 | CaretPos_LooseToNatural(WndNum,mouse_x,mouse_y,pCaretPos); |
---|
658 | } |
---|
659 | void GetNaturalCaretPos_Left(int WndNum){ |
---|
660 | /////////////////////////// |
---|
661 | // キャレット移動(左キー) |
---|
662 | /////////////////////////// |
---|
663 | |
---|
664 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
665 | int i; |
---|
666 | int x,y; |
---|
667 | char *pBuf; |
---|
668 | |
---|
669 | POINT *pCaretPos; |
---|
670 | pCaretPos=&MdiInfo[WndNum].pmti->StartCaretPos; |
---|
671 | |
---|
672 | if(pCaretPos->x==0&&pCaretPos->y==0){ |
---|
673 | //ファイルの先頭から左へは行けない |
---|
674 | return; |
---|
675 | } |
---|
676 | |
---|
677 | pBuf=MdiInfo[WndNum].pmti->buffer; |
---|
678 | |
---|
679 | i=GetBufferIndexFromCaretPos(pBuf, |
---|
680 | pCaretPos->x, |
---|
681 | pCaretPos->y); |
---|
682 | |
---|
683 | if(i>=2){ |
---|
684 | if(pBuf[i-2]=='\r'&&pBuf[i-1]=='\n'){ |
---|
685 | //列先頭から前行の終端へ |
---|
686 | x=INT_MAX; |
---|
687 | y=pCaretPos->y-1; |
---|
688 | CaretPos_LooseToNatural(WndNum, |
---|
689 | x,y, |
---|
690 | pCaretPos); |
---|
691 | return; |
---|
692 | } |
---|
693 | } |
---|
694 | |
---|
695 | x=pCaretPos->x-1; |
---|
696 | y=pCaretPos->y; |
---|
697 | |
---|
698 | BOOL sw=0; |
---|
699 | if(x<0){ |
---|
700 | x=INT_MAX; |
---|
701 | y--; |
---|
702 | |
---|
703 | sw=1; |
---|
704 | } |
---|
705 | |
---|
706 | CaretPos_LooseToNatural(WndNum, |
---|
707 | x,y, |
---|
708 | pCaretPos); |
---|
709 | |
---|
710 | if(sw){ |
---|
711 | GetNaturalCaretPos_Left(WndNum); |
---|
712 | } |
---|
713 | } |
---|
714 | void GetNaturalCaretPos_Right(int WndNum,POINT *pCaretPos){ |
---|
715 | /////////////////////////// |
---|
716 | // キャレット移動(右キー) |
---|
717 | /////////////////////////// |
---|
718 | |
---|
719 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
720 | int i,i2; |
---|
721 | char *pBuf; |
---|
722 | |
---|
723 | pBuf=MdiInfo[WndNum].pmti->buffer; |
---|
724 | |
---|
725 | i=GetBufferIndexFromCaretPos(pBuf, |
---|
726 | pCaretPos->x, |
---|
727 | pCaretPos->y); |
---|
728 | |
---|
729 | if(pBuf[i]=='\0'){ |
---|
730 | //ファイルの終端から右へは行けない |
---|
731 | return; |
---|
732 | } |
---|
733 | else if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'){ |
---|
734 | //改行コードから右へ |
---|
735 | pCaretPos->x=0; |
---|
736 | pCaretPos->y++; |
---|
737 | } |
---|
738 | else if(pBuf[i]=='\t'){ |
---|
739 | //タブ文字から右へ |
---|
740 | int tab; |
---|
741 | tab=pobj_nv->TabSize; |
---|
742 | |
---|
743 | if(pCaretPos->x%tab==0) i2=tab; |
---|
744 | else i2=tab-pCaretPos->x%tab; |
---|
745 | pCaretPos->x+=i2; |
---|
746 | } |
---|
747 | else if(IsDBCSLeadByte(pBuf[i])){ |
---|
748 | //マルチバイト文字 |
---|
749 | pCaretPos->x+=2; |
---|
750 | } |
---|
751 | else{ |
---|
752 | //右へ(通常) |
---|
753 | pCaretPos->x++; |
---|
754 | } |
---|
755 | |
---|
756 | //折り返し |
---|
757 | int iMax_OneLine_TextLength; |
---|
758 | iMax_OneLine_TextLength=40; |
---|
759 | if(IsRightTurn(pBuf,i,pCaretPos->x)){ |
---|
760 | pCaretPos->x=0; |
---|
761 | pCaretPos->y++; |
---|
762 | } |
---|
763 | |
---|
764 | CaretPos_LooseToNatural(WndNum, |
---|
765 | pCaretPos->x, |
---|
766 | pCaretPos->y, |
---|
767 | pCaretPos); |
---|
768 | } |
---|
769 | void GetNaturalCaretPos_Up(int WndNum,POINT *pCaretPos){ |
---|
770 | /////////////////////////// |
---|
771 | // キャレット移動(上キー) |
---|
772 | /////////////////////////// |
---|
773 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
774 | |
---|
775 | if(pCaretPos->y==0){ |
---|
776 | //1行目にキャレットがあるとき |
---|
777 | return; |
---|
778 | } |
---|
779 | |
---|
780 | //上下のキャレット移動時には、左右方向の位置を保持する |
---|
781 | if(MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos==-1) |
---|
782 | MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos=pCaretPos->x; |
---|
783 | |
---|
784 | pCaretPos->y--; |
---|
785 | |
---|
786 | CaretPos_LooseToNatural(WndNum, |
---|
787 | MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos, |
---|
788 | pCaretPos->y, |
---|
789 | pCaretPos); |
---|
790 | } |
---|
791 | void GetNaturalCaretPos_Down(int WndNum,POINT *pCaretPos){ |
---|
792 | /////////////////////////// |
---|
793 | // キャレット移動(下キー) |
---|
794 | /////////////////////////// |
---|
795 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
796 | |
---|
797 | //上下のキャレット移動時には、左右方向の位置を保持する |
---|
798 | if(MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos==-1) |
---|
799 | MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos=pCaretPos->x; |
---|
800 | |
---|
801 | pCaretPos->y++; |
---|
802 | |
---|
803 | CaretPos_LooseToNatural(WndNum, |
---|
804 | MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos, |
---|
805 | pCaretPos->y, |
---|
806 | pCaretPos); |
---|
807 | } |
---|
808 | void GetNaturalCaretPos_PageUp(int WndNum,POINT *pCaretPos){ |
---|
809 | /////////////////////////////// |
---|
810 | // キャレット移動(PageUpキー) |
---|
811 | /////////////////////////////// |
---|
812 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
813 | |
---|
814 | if(pCaretPos->y==0){ |
---|
815 | //1行目にキャレットがあるとき |
---|
816 | return; |
---|
817 | } |
---|
818 | |
---|
819 | //上下のキャレット移動時には、左右方向の位置を保持する |
---|
820 | if(MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos==-1) |
---|
821 | MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos=pCaretPos->x; |
---|
822 | |
---|
823 | SCROLLINFO si; |
---|
824 | si.cbSize=sizeof(SCROLLINFO); |
---|
825 | si.fMask=SIF_PAGE; |
---|
826 | GetScrollInfo(MdiInfo[WndNum].pmti->hEdit,SB_VERT,&si); |
---|
827 | pCaretPos->y-=si.nPage; |
---|
828 | if(pCaretPos->y<0) pCaretPos->y=0; |
---|
829 | |
---|
830 | CaretPos_LooseToNatural(WndNum, |
---|
831 | MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos, |
---|
832 | pCaretPos->y, |
---|
833 | pCaretPos); |
---|
834 | } |
---|
835 | void GetNaturalCaretPos_PageDown(int WndNum,POINT *pCaretPos){ |
---|
836 | /////////////////////////////// |
---|
837 | // キャレット移動(PageUpキー) |
---|
838 | /////////////////////////////// |
---|
839 | extern MDIINFO MdiInfo[MAX_WNDNUM]; |
---|
840 | |
---|
841 | //上下のキャレット移動時には、左右方向の位置を保持する |
---|
842 | if(MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos==-1) |
---|
843 | MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos=pCaretPos->x; |
---|
844 | |
---|
845 | SCROLLINFO si; |
---|
846 | si.cbSize=sizeof(SCROLLINFO); |
---|
847 | si.fMask=SIF_PAGE; |
---|
848 | GetScrollInfo(MdiInfo[WndNum].pmti->hEdit,SB_VERT,&si); |
---|
849 | pCaretPos->y+=si.nPage; |
---|
850 | |
---|
851 | CaretPos_LooseToNatural(WndNum, |
---|
852 | MdiInfo[WndNum].pmti->Temp_UpDown_CaretXPos, |
---|
853 | pCaretPos->y, |
---|
854 | pCaretPos); |
---|
855 | } |
---|