source: dev/ProjectEditor/TextEditor.cpp@ 7

Last change on this file since 7 was 3, checked in by dai_9181, 18 years ago
File size: 7.7 KB
Line 
1#include "Common.h"
2
3extern HFONT hFont_TextEdit,hFont_HyperLink_TextEdit;
4extern int font_width,font_height;
5
6
7int GetControlTabSpace(int WndNum,int *piCount){
8 if(pobj_nv->bEditor_LineNumber){
9 extern MDIINFO MdiInfo[MAX_WNDNUM];
10
11 char *pBuf;
12 pBuf=MdiInfo[WndNum].pmti->buffer;
13
14 int i,iNum=1,x=0;
15 for(i=0;;i++,x++){
16 if(IsRightTurn(pBuf,i,x)){
17 //右端で折り返す
18 iNum++;
19 x=-1;
20 i--;
21 continue;
22 }
23 if(pBuf[i]=='\0') break;
24 if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'){
25 iNum++;
26
27 x=-1;
28 }
29 }
30 char temporary[255];
31 sprintf(temporary,"%d",iNum);
32
33 extern SIZE sizeLineNumberFont;
34
35 i=lstrlen(temporary);
36 if(piCount) *piCount=i;
37
38 return sizeLineNumberFont.cx*(i+2);
39 }
40
41 return CONTROL_TAB_SPACE_DEFAULT;
42}
43
44void ResetTextEditFont(HWND hwnd){
45 if(hFont_TextEdit) DeleteObject(hFont_TextEdit);
46 hFont_TextEdit=CreateFontIndirect(&pobj_nv->lf);
47
48 //下線フォント
49 LOGFONT lf;
50 lf=pobj_nv->lf;
51 lf.lfUnderline=TRUE;
52 if(hFont_HyperLink_TextEdit) DeleteObject(hFont_HyperLink_TextEdit);
53 hFont_HyperLink_TextEdit=CreateFontIndirect(&lf);
54
55 HDC hdc;
56 HFONT hOldFont;
57 hdc=GetDC(hwnd);
58
59
60 hOldFont=(HFONT)SelectObject(hdc,hFont_TextEdit);
61
62 //単位文字の幅、高さ
63 SIZE size;
64 GetTextExtentPoint32(hdc,"A",1,&size);
65 font_width=size.cx;
66 font_height=size.cy;
67
68 SelectObject(hdc,hOldFont);
69
70
71 //行番号表示用フォントのサイズ
72 extern HFONT hFont_LineNumber;
73 hOldFont=(HFONT)SelectObject(hdc,hFont_LineNumber);
74 extern SIZE sizeLineNumberFont;
75 GetTextExtentPoint32(hdc,"A",1,&sizeLineNumberFont);
76 SelectObject(hdc, hOldFont);
77
78
79 ReleaseDC(hwnd,hdc);
80}
81void SetTextEditWordColor(int WndNum){
82 extern MDIINFO MdiInfo[MAX_WNDNUM];
83 int i,i2,i3,IsStr;
84 char str[255];
85 char *pBuf;
86
87 pBuf=MdiInfo[WndNum].pmti->buffer;
88
89 if(MdiInfo[WndNum].DocType==WNDTYPE_TEXT){
90 //通常のテキストはすべてをデフォルトカラー(標準で黒)にする
91 for(i=0;;i++){
92 if(pBuf[i]=='\0') break;
93 MdiInfo[WndNum].pmti->pColorRef[i]=tci.rgbDefault;
94 }
95 return;
96 }
97
98
99 if(!bProfessional){
100 //Standard版ではHTMLタグの色分け機能を排除
101 if(MdiInfo[WndNum].DocType==WNDTYPE_HTML){
102 for(i=0;;i++){
103 if(pBuf[i]=='\0') break;
104 MdiInfo[WndNum].pmti->pColorRef[i]=tci.rgbDefault;
105 }
106 return;
107 }
108 }
109
110 for(i=0,IsStr=0;;i++){
111 if(pBuf[i]=='\0') break;
112
113 if((IsVariableTopChar(pBuf[i]))&&IsStr==0){
114 for(i2=0;;i++,i2++){
115 if((!IsVariableChar(pBuf[i]))||pBuf[i]=='.'){
116 str[i2]=0;
117 break;
118 }
119 str[i2]=pBuf[i];
120 }
121
122 BOOL bResult=0;
123 if(MdiInfo[WndNum].DocType==WNDTYPE_BASIC){
124 i3=IsBasicReservedWord(str);
125 bResult=IsManagementCommand(i3);
126 }
127 else if(MdiInfo[WndNum].DocType==WNDTYPE_HTML){
128 bResult=IsHtmlReservedWord(str);
129 }
130
131 if(bResult){
132 for(i3=i-i2;i3<i;i3++){
133 MdiInfo[WndNum].pmti->pColorRef[i3]=tci.rgbStatement;
134 }
135 }
136 else{
137 for(i3=i-i2;i3<i;i3++){
138 MdiInfo[WndNum].pmti->pColorRef[i3]=tci.rgbDefault;
139 }
140 }
141 i--;
142 continue;
143 }
144 else{
145 if(IsStr||pBuf[i]=='\"'&&IsStr==0){
146 //文字列カラー(""で囲まれる範囲)
147 MdiInfo[WndNum].pmti->pColorRef[i]=tci.rgbString;
148 }
149 else{
150 //通常カラー
151 MdiInfo[WndNum].pmti->pColorRef[i]=tci.rgbDefault;
152 }
153 }
154
155 if(pBuf[i]=='\"') IsStr^=1;
156
157 if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'){
158 IsStr=0;
159 continue;
160 }
161 }
162}
163void ResetScrollbar(int WndNum,int max_x,int max_y){
164 extern MDIINFO MdiInfo[MAX_WNDNUM];
165 RECT rect;
166
167 //エディタ画面左端のコントロールタブ
168 int iControlTabSpace;
169 iControlTabSpace=MdiInfo[WndNum].pmti->iWidth_ControlTabSpace;
170
171 HWND hEdit;
172 hEdit=GetWindow(MdiInfo[WndNum].hwnd,GW_CHILD);
173 GetClientRect(hEdit,&rect);
174
175 SCROLLINFO si;
176 si.cbSize=sizeof(SCROLLINFO);
177 si.fMask=SIF_PAGE|SIF_RANGE|SIF_DISABLENOSCROLL;
178
179 //垂直スクロールバーの設定
180 GetScrollInfo(hEdit,SB_VERT,&si);
181 si.nPage=(rect.bottom/font_height)-1;
182 si.nMin=0;
183 si.nMax=max_y+si.nPage/5*3;
184 SetScrollInfo(hEdit,SB_VERT,&si,1);
185
186 //水平スクロールバーの設定
187 GetScrollInfo(hEdit,SB_HORZ,&si);
188 si.nMin=0;
189 si.nPage=(rect.right-iControlTabSpace)/font_width -1;
190 si.nMax=max_x+si.nPage/3;
191 SetScrollInfo(hEdit,SB_HORZ,&si,1);
192
193 //ルーラーを再描画
194 InvalidateRect(MdiInfo[WndNum].pmti->pobj_Ruler->hRulerWnd,NULL,0);
195 UpdateWindow(MdiInfo[WndNum].pmti->pobj_Ruler->hRulerWnd);
196}
197
198#define HIRA_START (unsigned char)0x9F //ひらがなの2バイト目の範囲
199#define HIRA_END (unsigned char)0xF1
200#define KATA_START (unsigned char)0x40 //カタカナの2バイト目の範囲
201#define KATA_END (unsigned char)0x96
202BOOL IsHiragana(char *pBuf){
203 if((unsigned char)pBuf[0]==(unsigned char)0x82&&
204 HIRA_START<=(unsigned char)pBuf[1]&&(unsigned char)pBuf[1]<=HIRA_END) return 1;
205 return 0;
206}
207BOOL IsKatakana(char *pBuf){
208 if(((unsigned char)pBuf[0]==(unsigned char)0x83&&
209 KATA_START<=(unsigned char)pBuf[1]&&(unsigned char)pBuf[1]<=KATA_END)||
210 (unsigned char)pBuf[0]==(unsigned char)0x81&&(unsigned char)pBuf[1]==(unsigned char)0x5B) return 1;
211 return 0;
212}
213BOOL IsKanji(char *pBuf){
214 if((unsigned char)0x88<=(unsigned char)pBuf[0] && (unsigned char)pBuf[0]<=(unsigned char)0xEA) return 1;
215 return 0;
216}
217BOOL IsAlphabet(char c){
218 if('a'<=c&&c<='z'||'A'<=c&&c<='Z') return 1;
219 return 0;
220}
221BOOL IsReturnCode(char *pBuf){
222 if(pBuf[0]=='\r'&&pBuf[1]=='\n') return 1;
223 return 0;
224}
225void TextEdit_GetWordCaret(HWND hwnd,int WndNum,POINT *pPos,int *piStart,int *piEnd,BOOL bBeforeAfterFlag){
226 extern MDIINFO MdiInfo[MAX_WNDNUM];
227 int i,start,end;
228 char *pBuf;
229
230 pBuf=MdiInfo[WndNum].pmti->buffer;
231
232 //ダブルクリック位置を取得(バッファインデックス)
233 i=GetBufferIndexFromCaretPos(pBuf,
234 pPos->x,
235 pPos->y);
236
237 if(IsDBCSLeadByte(pBuf[i])){
238 ///////////////////
239 // 全角文字のとき
240 ///////////////////
241
242 if(IsHiragana(pBuf+i)){
243 //ひらがな
244
245 //単語の先頭位置を取得
246 start=i;
247 for(;;start-=2){
248 if(0>start){
249 start+=2;
250 break;
251 }
252 if(!IsHiragana(pBuf+start)){
253 start+=2;
254 break;
255 }
256 }
257
258 //単語の終端位置を取得
259 end=i;
260 for(;;end+=2){
261 if(!IsHiragana(pBuf+end)) break;
262 }
263 }
264 else if(IsKatakana(pBuf+i)){
265 //カタカナ
266
267 //単語の先頭位置を取得
268 start=i;
269 for(;;start-=2){
270 if(0>start){
271 start+=2;
272 break;
273 }
274 if(!IsKatakana(pBuf+start)){
275 start+=2;
276 break;
277 }
278 }
279
280 //単語の終端位置を取得
281 end=i;
282 for(;;end+=2){
283 if(!IsKatakana(pBuf+end)) break;
284 }
285 }
286 else if(IsKanji(pBuf+i)){
287 //漢字
288
289 //単語の先頭位置を取得
290 start=i;
291 for(;;start-=2){
292 if(0>start){
293 start+=2;
294 break;
295 }
296 if(!IsKanji(pBuf+start)){
297 start+=2;
298 break;
299 }
300 }
301
302 //単語の終端位置を取得
303 end=i;
304 for(;;end+=2){
305 if(!IsKanji(pBuf+end)) break;
306 }
307 }
308 else{
309 //漢字とその他の全角文字
310 start=i;
311 end=start+2;
312 }
313 }
314 else{
315 ///////////////////
316 // 半角文字のとき
317 ///////////////////
318
319 //単語の先頭位置を取得
320 start=i;
321 for(;0<=start;start--){
322 if(!(IsVariableChar(pBuf[start])&&pBuf[start]!='.')){
323 break;
324 }
325 }
326 start++;
327
328 //単語の終端位置を取得
329 end=i;
330 for(;;end++){
331 if(!(IsVariableChar(pBuf[end])&&pBuf[end]!='.')) break;
332 }
333 }
334
335 *piStart=start;
336 *piEnd=end;
337}
338void CancelBeforeAutoIndent(int WndNum){
339 extern MDIINFO MdiInfo[MAX_WNDNUM];
340 int i;
341
342 i=GetBufferIndexFromCaretPos(
343 MdiInfo[WndNum].pmti->buffer,
344 MdiInfo[WndNum].pmti->StartCaretPos.x,
345 MdiInfo[WndNum].pmti->StartCaretPos.y);
346 GetCaretPosFromBufferIndex(
347 MdiInfo[WndNum].pmti->buffer,
348 i-lstrlen(MdiInfo[WndNum].IndentStr),
349 &MdiInfo[WndNum].pmti->StartCaretPos);
350
351 TextEdit_Replace(WndNum,"",1);
352
353 HeapDefaultFree(MdiInfo[WndNum].IndentStr);
354 MdiInfo[WndNum].IndentStr=0;
355}
Note: See TracBrowser for help on using the repository browser.