source: dev/ProjectEditor/nkf_class.cpp@ 87

Last change on this file since 87 was 24, checked in by dai_9181, 18 years ago

保存されていないドキュメントのタブに(*)をつける機能に対応。
MDITEXTEDITINFOをCMdiTextEditに変更。今後、オブジェクト指向化を進める。

File size: 4.4 KB
Line 
1#include "common.h"
2
3//文字コード変換用クラスライブラリ
4CNkf nkf;
5
6CNkf::CNkf(){
7 char temporary[MAX_PATH];
8 sprintf(temporary,"%sSubOperation\\nkf32.dll",pj_editor_Dir);
9
10 hLib=LoadLibrary(temporary);
11
12 pGetNkfVersion=(GetNkfVersion)GetProcAddress(hLib,"GetNkfVersion");
13 pSetNkfOption=(SetNkfOption)GetProcAddress(hLib,"SetNkfOption");
14 pNkfConvert=(NkfConvert)GetProcAddress(hLib,"NkfConvert");
15 pNkfGetKanjiCode=(NkfGetKanjiCode)GetProcAddress(hLib,"NkfGetKanjiCode");
16}
17
18CNkf::~CNkf(){
19 FreeLibrary(hLib);
20}
21
22
23char *CNkf::RestoreBuffer(char *buffer,int iCharCode){
24 /////////////////////
25 // 文字コードを復元
26 // ※内部表現はShift-JIS
27 /////////////////////
28 extern HANDLE hHeap;
29 char *pBuf;
30
31 pBuf=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)*2+1);
32
33 switch(iCharCode){
34 case NKF_SHIFT_JIS:
35 lstrcpy(pBuf,buffer);
36 break;
37 case NKF_EUC:
38 pSetNkfOption("-ex");
39 pNkfConvert(pBuf,buffer);
40 break;
41 case NKF_ISO_2022_JP:
42 pSetNkfOption("-jx");
43 pNkfConvert(pBuf,buffer);
44 break;
45 case NKF_UTF_8:
46 pSetNkfOption("-wx");
47 pNkfConvert(pBuf,buffer);
48 break;
49 }
50
51 return pBuf;
52}
53
54void CNkf::GetCharCodeName(int iCharCode,char *name){
55 switch(iCharCode){
56 case NKF_SHIFT_JIS:
57 lstrcpy(name,"Shift-JIS");
58 break;
59 case NKF_EUC:
60 lstrcpy(name,"EUC");
61 break;
62 case NKF_ISO_2022_JP:
63 lstrcpy(name,"JIS");
64 break;
65 case NKF_UTF_8:
66 lstrcpy(name,"UTF-8");
67 break;
68 }
69}
70
71char *CNkf::ToCRLF(int iLfCode,char *buffer){
72 extern HANDLE hHeap;
73 int i,i2;
74
75 char *temp;
76 temp=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)*2+1);
77
78 for(i=0,i2=0;;i++,i2++){
79 if(buffer[i]=='\0'){
80 temp[i2]=0;
81 break;
82 }
83 if(iLfCode==LFCODE_LF){
84 if(buffer[i]=='\n'){
85 temp[i2++]='\r';
86 temp[i2]='\n';
87 continue;
88 }
89 }
90 else if(iLfCode==LFCODE_CR){
91 if(buffer[i]=='\r'){
92 temp[i2++]='\r';
93 temp[i2]='\n';
94 continue;
95 }
96 }
97
98 temp[i2]=buffer[i];
99 }
100
101 return temp;
102}
103void CNkf::ToLF(char *buffer){
104 extern HANDLE hHeap;
105 int i,i2;
106
107 for(i=0,i2=0;;i++,i2++){
108 if(buffer[i]=='\r'&&buffer[i+1]=='\n'){
109 buffer[i2]='\n';
110 i++;
111 continue;
112 }
113
114 buffer[i2]=buffer[i];
115 if(buffer[i]=='\0') break;
116 }
117}
118void CNkf::ToCR(char *buffer){
119 extern HANDLE hHeap;
120 int i,i2;
121
122 for(i=0,i2=0;;i++,i2++){
123 if(buffer[i]=='\r'&&buffer[i+1]=='\n'){
124 buffer[i2]='\r';
125 i++;
126 continue;
127 }
128
129 buffer[i2]=buffer[i];
130 if(buffer[i]=='\0') break;
131 }
132}
133
134void CNkf::GetLfCodeName(int iLfCode,char *name){
135 switch(iLfCode){
136 case LFCODE_CRLF:
137 lstrcpy(name,"CRLF");
138 break;
139 case LFCODE_LF:
140 lstrcpy(name,"LF");
141 break;
142 case LFCODE_CR:
143 lstrcpy(name,"CR");
144 break;
145 }
146}
147
148
149
150BOOL CALLBACK nkfDlgCodeSave(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
151 extern MDIINFO MdiInfo[MAX_WNDNUM];
152 static int WndNum;
153 HWND hList;
154
155 switch(message){
156 case WM_INITDIALOG:
157 SetPosCenter(hwnd);
158
159 WndNum=GetWndNum(GetWindow(hClient,GW_CHILD));
160 if(WndNum==-1){
161 //ウィンドウの取得に失敗
162 EndDialog(hwnd,0);
163 break;
164 }
165 if(!IS_DOCUMENT_TEXT(MdiInfo[WndNum].DocType)){
166 //テキストドキュメントでないとき
167 EndDialog(hwnd,0);
168 break;
169 }
170
171 hList=GetDlgItem(hwnd,IDC_LIST_CHARCODE);
172 SendMessage(hList,LB_ADDSTRING,0,(long)"Shift-JIS");
173 SendMessage(hList,LB_ADDSTRING,0,(long)"EUC");
174 SendMessage(hList,LB_ADDSTRING,0,(long)"JIS");
175 SendMessage(hList,LB_ADDSTRING,0,(long)"UTF-8");
176 SendMessage(hList,LB_SETCURSEL,MdiInfo[WndNum].pMdiTextEdit->iCharCode,0);
177
178 hList=GetDlgItem(hwnd,IDC_LIST_LFCODE);
179 SendMessage(hList,LB_ADDSTRING,0,(long)"CRLF(Windows)");
180 SendMessage(hList,LB_ADDSTRING,0,(long)"LF(Unix)");
181 SendMessage(hList,LB_ADDSTRING,0,(long)"CR(Macintosh)");
182 SendMessage(hList,LB_SETCURSEL,MdiInfo[WndNum].pMdiTextEdit->iLfCode,0);
183 break;
184 case WM_COMMAND:
185 switch(LOWORD(wParam)){
186 case IDOK:
187 //文字コードを取得
188 MdiInfo[WndNum].pMdiTextEdit->iCharCode=
189 (int)SendDlgItemMessage(hwnd,IDC_LIST_CHARCODE,LB_GETCURSEL,0,0);
190
191 //改行コードを取得
192 MdiInfo[WndNum].pMdiTextEdit->iLfCode=
193 (int)SendDlgItemMessage(hwnd,IDC_LIST_LFCODE,LB_GETCURSEL,0,0);
194
195 //保存
196 if(!SaveDocument(GetWindow(hClient,GW_CHILD),NULL)) return 0;
197
198 EndDialog(hwnd,1);
199 break;
200 case IDCANCEL:
201 EndDialog(hwnd,0);
202 break;
203 }
204 break;
205 }
206 return 0;
207}
Note: See TracBrowser for help on using the repository browser.