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