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