source: trunk/dll/codepage.c@ 347

Last change on this file since 347 was 347, checked in by root, 19 years ago

Use Runtime_Error

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
RevLine 
[347]1
2/***********************************************************************
3
4 $Id: codepage.c 347 2006-07-26 05:43:28Z root $
5
6 Select code page
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2006 Steven H.Levine
10
11 14 Jul 06 SHL Use Runtime_Error
12
13***********************************************************************/
14
[2]15#define INCL_DOS
16#define INCL_WIN
[347]17#include <os2.h>
[2]18
19#include <stdlib.h>
20#include <stdio.h>
21#include <string.h>
22#include <time.h>
[347]23
[2]24#include "fm3dll.h"
25#include "fm3dlg.h"
26#include "fm3str.h"
27
28#pragma data_seg(DATA1)
29
[347]30static PSZ pszSrcFile = __FILE__;
31
[2]32#pragma alloc_text(FMCODEPAGE,PickCodePageDlgBox,PickCodepage)
33
34MRESULT EXPENTRY PickCodePageDlgBox (HWND hwnd,ULONG msg,MPARAM mp1,
35 MPARAM mp2) {
36
37 SHORT sSelect;
38
39 switch(msg) {
40 case WM_INITDLG:
41 WinShowWindow(WinWindowFromID(hwnd,PICK_SAVEPOS),
42 FALSE);
43 {
44 ULONG cp;
45 char *p;
46
47 cp = WinQueryCp(WinQueryWindowULong(hwnd,
48 QWL_HMQ));
49 for(sSelect = 0;
50 (p = GetPString(IDS_CODEPAGES1 + sSelect)) != NULL;
51 sSelect++) {
52 if(!strcmp(p,"0"))
53 break;
54 WinSendDlgItemMsg(hwnd,
55 PICK_LISTBOX,
56 LM_INSERTITEM,
57 MPFROMSHORT(LIT_END),
58 MPFROMP(p));
59 if(atoi(p) == cp) {
60 WinSendDlgItemMsg(hwnd,
61 PICK_LISTBOX,
62 LM_SETTOPINDEX,
63 MPFROM2SHORT(sSelect,0),
64 MPVOID);
65 WinSendDlgItemMsg(hwnd,
66 PICK_LISTBOX,
67 LM_SELECTITEM,
68 MPFROM2SHORT(sSelect,0),
69 MPFROMSHORT(TRUE));
70 }
71 }
72 }
73 WinSendDlgItemMsg(hwnd,
74 PICK_INPUT,
75 EM_SETTEXTLIMIT,
76 MPFROM2SHORT(256,0),
77 MPVOID);
78 WinSetWindowText(hwnd,
79 GetPString(IDS_PICKCODEPAGETEXT));
80 PostMsg(hwnd,
81 UM_STRETCH,
82 MPVOID,
83 MPVOID);
84 break;
85
86 case UM_STRETCH:
87 {
88 SWP swp,swpL,swpE;
89 LONG titl,szbx,szby;
90
91 WinQueryWindowPos(hwnd,&swp);
92 if(!(swp.fl & (SWP_HIDE | SWP_MINIMIZE)) &&
93 (swp.x != SHORT1FROMMP(mp1) || swp.cx != SHORT2FROMMP(mp1) ||
94 swp.y != SHORT1FROMMP(mp2) || swp.cy != SHORT2FROMMP(mp2))) {
95 szbx = SysVal(SV_CXSIZEBORDER);
96 szby = SysVal(SV_CYSIZEBORDER);
97 titl = SysVal(SV_CYTITLEBAR);
98 WinQueryWindowPos(WinWindowFromID(hwnd,PICK_LISTBOX),&swpL);
99 WinQueryWindowPos(WinWindowFromID(hwnd,PICK_INPUT),&swpE);
100 WinSetWindowPos(WinWindowFromID(hwnd,PICK_LISTBOX),HWND_TOP,
101 szbx,
102 swpL.y,
103 swp.cx - (szbx * 2L),
104 ((((swp.cy - swpL.y) - swpE.cy) - 8) - titl) -
105 (szby * 2L),
106 SWP_MOVE | SWP_SIZE);
107 WinSetWindowPos(WinWindowFromID(hwnd,PICK_INPUT),HWND_TOP,
108 szbx + 2,
109 swpL.y + (((((swp.cy - swpL.y) - swpE.cy) - 8) -
110 titl) - (szby * 2L)) + 4,
111 0L,0L,
112 SWP_MOVE);
113 WinInvalidateRect(WinWindowFromID(hwnd,PICK_INPUT),
114 NULL,
115 FALSE);
116 }
117 }
118 return 0;
119
120 case WM_ADJUSTWINDOWPOS:
121 {
122 SWP swp;
123
124 WinQueryWindowPos(hwnd,&swp);
125 PostMsg(hwnd,
126 UM_STRETCH,
127 MPFROM2SHORT((SHORT)swp.x,(SHORT)swp.cx),
128 MPFROM2SHORT((SHORT)swp.y,(SHORT)swp.cy));
129 }
130 break;
131
132 case WM_CONTROL:
133 switch(SHORT1FROMMP(mp1)) {
134 case PICK_LISTBOX:
135 switch(SHORT2FROMMP(mp1)) {
136 case LN_SELECT:
137 sSelect = (USHORT)WinSendDlgItemMsg(hwnd,
138 PICK_LISTBOX,
139 LM_QUERYSELECTION,
140 MPFROMSHORT(LIT_FIRST),
141 MPVOID);
142 if(sSelect >= 0)
143 WinSetDlgItemText(hwnd,
144 PICK_INPUT,
145 GetPString(IDS_CODEPAGES1 + sSelect));
146 break;
147 case LN_ENTER:
148 PostMsg(hwnd,
149 WM_COMMAND,
150 MPFROM2SHORT(DID_OK,0),
151 MPVOID);
152 break;
153 }
154 break;
155 }
156 return 0;
157
158 case WM_COMMAND:
159 switch(SHORT1FROMMP(mp1)) {
160 case DID_OK:
161 {
162 INT x;
163 CHAR s[257],*p;
164
165 *s = 0;
166 WinQueryDlgItemText(hwnd,
167 PICK_INPUT,
168 257,
169 s);
[347]170 if(!*s)
171 Runtime_Error(pszSrcFile, __LINE__, "no input");
172 else {
[2]173 for(x = 0;
174 (p = GetPString(IDS_CODEPAGES1 + x)) != NULL;
175 x++) {
176 if(!stricmp(s,p)) {
177 WinDismissDlg(hwnd,atoi(p));
178 break;
179 }
180 }
181 }
182 }
183 break;
184
185 case IDM_HELP:
186 if(hwndHelp)
187 WinSendMsg(hwndHelp,
188 HM_DISPLAY_HELP,
189 MPFROM2SHORT(HELP_CODEPAGE,0),
190 MPFROMSHORT(HM_RESOURCEID));
191 break;
192
193 case PICK_SAVEPOS:
194 break;
195
196 case DID_CANCEL:
197 WinDismissDlg(hwnd,0);
198 break;
199 }
200 return 0;
201
202 case WM_CLOSE:
203 return 0;
204 }
205 return WinDefDlgProc(hwnd,msg,mp1,mp2);
206}
207
208
209INT PickCodepage (HWND hwnd) {
210
211 INT cp;
212
213 cp = (INT)WinDlgBox(HWND_DESKTOP,
214 hwnd,
215 PickCodePageDlgBox,
216 FM3ModHandle,
217 PICK_FRAME,
218 MPVOID);
219 if(cp > 0) {
220
221 HMQ hmq;
222 ULONG cps[50],len,x;
223
224/*
225 numcps = WinQueryCpList(WinQueryAnchorBlock(hwnd),50,cps);
226 if(numcps) {
227 for(x = 0;x < numcps;x++) {
228 if(cps[x] == (ULONG)cp) {
229 hmq = WinQueryWindowULong(hwnd,QWL_HMQ);
230 WinSetCp(hmq,cp);
231 break;
232 }
233 }
234 }
235*/
236 if(cp == 1004) {
237 hmq = WinQueryWindowULong(hwnd,QWL_HMQ);
238 WinSetCp(hmq,cp);
239 }
240 else if(!DosQueryCp(sizeof(cps),cps,&len)) {
241 for(x = 0;x < len / sizeof(ULONG);x++) {
242 if(cps[x] == (ULONG)cp) {
243 hmq = WinQueryWindowULong(hwnd,QWL_HMQ);
244 WinSetCp(hmq,cp);
245 break;
246 }
247 }
248 }
249 DosSetProcessCp(cp);
250 }
251 else
252 cp = -1;
253 return cp;
254}
255
Note: See TracBrowser for help on using the repository browser.