[347] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: codepage.c 1498 2010-01-18 00:57:01Z gyoung $
|
---|
| 5 |
|
---|
| 6 | Select code page
|
---|
| 7 |
|
---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
---|
[1498] | 9 | Copyright (c) 2006, 2010 Steven H.Levine
|
---|
[347] | 10 |
|
---|
| 11 | 14 Jul 06 SHL Use Runtime_Error
|
---|
[793] | 12 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[1391] | 13 | 11 Jan 09 GKY Moved codepage names to a character array here from the string file.
|
---|
[1498] | 14 | 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
|
---|
[347] | 15 |
|
---|
| 16 | ***********************************************************************/
|
---|
| 17 |
|
---|
[907] | 18 | #include <stdlib.h>
|
---|
| 19 | #include <string.h>
|
---|
| 20 |
|
---|
[2] | 21 | #define INCL_DOS
|
---|
| 22 | #define INCL_WIN
|
---|
[907] | 23 | #define INCL_LONGLONG // dircnrs.h
|
---|
[2] | 24 |
|
---|
[1183] | 25 | #include "fm3dll.h"
|
---|
[1221] | 26 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
[1205] | 27 | #include "notebook.h" // Data declaration(s)
|
---|
| 28 | #include "mainwnd.h" // Data declaration(s)
|
---|
[2] | 29 | #include "fm3dlg.h"
|
---|
| 30 | #include "fm3str.h"
|
---|
[907] | 31 | #include "strutil.h" // GetPString
|
---|
| 32 | #include "errutil.h" // Runtime_Error
|
---|
[1159] | 33 | #include "codepage.h"
|
---|
[1183] | 34 | #include "misc.h" // PostMsg
|
---|
[2] | 35 |
|
---|
| 36 | #pragma data_seg(DATA1)
|
---|
| 37 |
|
---|
[347] | 38 | static PSZ pszSrcFile = __FILE__;
|
---|
[1391] | 39 | static CHAR *CodePage[23] = {"437 USA",
|
---|
| 40 | "850 Multilingual",
|
---|
| 41 | "852 Latin 2",
|
---|
| 42 | "857 Turkish",
|
---|
| 43 | "860 Portuguese",
|
---|
| 44 | "861 Iceland",
|
---|
| 45 | "863 French-Canadian",
|
---|
| 46 | "865 Nordic",
|
---|
| 47 | "866 Russian OS/2",
|
---|
| 48 | "878 Russian KOI8-R",
|
---|
| 49 | "932 Japan",
|
---|
| 50 | "934 Korea",
|
---|
| 51 | "936 China",
|
---|
| 52 | "938 Taiwan",
|
---|
| 53 | "942 Japan SAA",
|
---|
| 54 | "944 Korea SAA",
|
---|
| 55 | "946 China SAA",
|
---|
| 56 | "948 Taiwan SAA",
|
---|
| 57 | "949 Korea KS",
|
---|
| 58 | "950 Taiwan (Big 5)",
|
---|
| 59 | "1004 DTP/Win",
|
---|
| 60 | "1251 Russian Win",
|
---|
| 61 | "1381 China GB"};
|
---|
[347] | 62 |
|
---|
[551] | 63 | MRESULT EXPENTRY PickCodePageDlgBox(HWND hwnd, ULONG msg, MPARAM mp1,
|
---|
| 64 | MPARAM mp2)
|
---|
| 65 | {
|
---|
[2] | 66 |
|
---|
| 67 | SHORT sSelect;
|
---|
| 68 |
|
---|
[551] | 69 | switch (msg) {
|
---|
| 70 | case WM_INITDLG:
|
---|
| 71 | WinShowWindow(WinWindowFromID(hwnd, PICK_SAVEPOS), FALSE);
|
---|
| 72 | {
|
---|
| 73 | ULONG cp;
|
---|
| 74 | char *p;
|
---|
[2] | 75 |
|
---|
[551] | 76 | cp = WinQueryCp(WinQueryWindowULong(hwnd, QWL_HMQ));
|
---|
[1391] | 77 | for (sSelect = 0; sSelect < 23; sSelect++) {
|
---|
| 78 | p = CodePage[sSelect];
|
---|
[551] | 79 | WinSendDlgItemMsg(hwnd,
|
---|
| 80 | PICK_LISTBOX,
|
---|
| 81 | LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(p));
|
---|
| 82 | if (atoi(p) == cp) {
|
---|
| 83 | WinSendDlgItemMsg(hwnd,
|
---|
| 84 | PICK_LISTBOX,
|
---|
| 85 | LM_SETTOPINDEX, MPFROM2SHORT(sSelect, 0), MPVOID);
|
---|
| 86 | WinSendDlgItemMsg(hwnd,
|
---|
| 87 | PICK_LISTBOX,
|
---|
| 88 | LM_SELECTITEM,
|
---|
| 89 | MPFROM2SHORT(sSelect, 0), MPFROMSHORT(TRUE));
|
---|
| 90 | }
|
---|
[2] | 91 | }
|
---|
[551] | 92 | }
|
---|
| 93 | WinSendDlgItemMsg(hwnd,
|
---|
| 94 | PICK_INPUT,
|
---|
| 95 | EM_SETTEXTLIMIT, MPFROM2SHORT(256, 0), MPVOID);
|
---|
[1498] | 96 | WinSetWindowText(hwnd, (CHAR *) GetPString(IDS_PICKCODEPAGETEXT));
|
---|
[551] | 97 | PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
|
---|
| 98 | break;
|
---|
[2] | 99 |
|
---|
[551] | 100 | case UM_STRETCH:
|
---|
| 101 | {
|
---|
| 102 | SWP swp, swpL, swpE;
|
---|
| 103 | LONG titl, szbx, szby;
|
---|
[2] | 104 |
|
---|
[551] | 105 | WinQueryWindowPos(hwnd, &swp);
|
---|
| 106 | if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE)) &&
|
---|
| 107 | (swp.x != SHORT1FROMMP(mp1) || swp.cx != SHORT2FROMMP(mp1) ||
|
---|
| 108 | swp.y != SHORT1FROMMP(mp2) || swp.cy != SHORT2FROMMP(mp2))) {
|
---|
| 109 | szbx = SysVal(SV_CXSIZEBORDER);
|
---|
| 110 | szby = SysVal(SV_CYSIZEBORDER);
|
---|
| 111 | titl = SysVal(SV_CYTITLEBAR);
|
---|
| 112 | WinQueryWindowPos(WinWindowFromID(hwnd, PICK_LISTBOX), &swpL);
|
---|
| 113 | WinQueryWindowPos(WinWindowFromID(hwnd, PICK_INPUT), &swpE);
|
---|
| 114 | WinSetWindowPos(WinWindowFromID(hwnd, PICK_LISTBOX), HWND_TOP,
|
---|
| 115 | szbx,
|
---|
| 116 | swpL.y,
|
---|
| 117 | swp.cx - (szbx * 2L),
|
---|
| 118 | ((((swp.cy - swpL.y) - swpE.cy) - 8) - titl) -
|
---|
| 119 | (szby * 2L), SWP_MOVE | SWP_SIZE);
|
---|
| 120 | WinSetWindowPos(WinWindowFromID(hwnd, PICK_INPUT), HWND_TOP,
|
---|
| 121 | szbx + 2,
|
---|
| 122 | swpL.y + (((((swp.cy - swpL.y) - swpE.cy) - 8) -
|
---|
| 123 | titl) - (szby * 2L)) + 4,
|
---|
| 124 | 0L, 0L, SWP_MOVE);
|
---|
| 125 | WinInvalidateRect(WinWindowFromID(hwnd, PICK_INPUT), NULL, FALSE);
|
---|
[2] | 126 | }
|
---|
[551] | 127 | }
|
---|
| 128 | return 0;
|
---|
[2] | 129 |
|
---|
[551] | 130 | case WM_ADJUSTWINDOWPOS:
|
---|
| 131 | {
|
---|
| 132 | SWP swp;
|
---|
[2] | 133 |
|
---|
[551] | 134 | WinQueryWindowPos(hwnd, &swp);
|
---|
| 135 | PostMsg(hwnd,
|
---|
| 136 | UM_STRETCH,
|
---|
| 137 | MPFROM2SHORT((SHORT) swp.x, (SHORT) swp.cx),
|
---|
| 138 | MPFROM2SHORT((SHORT) swp.y, (SHORT) swp.cy));
|
---|
| 139 | }
|
---|
| 140 | break;
|
---|
| 141 |
|
---|
| 142 | case WM_CONTROL:
|
---|
| 143 | switch (SHORT1FROMMP(mp1)) {
|
---|
| 144 | case PICK_LISTBOX:
|
---|
| 145 | switch (SHORT2FROMMP(mp1)) {
|
---|
| 146 | case LN_SELECT:
|
---|
| 147 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
|
---|
| 148 | PICK_LISTBOX,
|
---|
| 149 | LM_QUERYSELECTION,
|
---|
| 150 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
| 151 | if (sSelect >= 0)
|
---|
[1391] | 152 | WinSetDlgItemText(hwnd, PICK_INPUT, CodePage[sSelect]);
|
---|
[551] | 153 | break;
|
---|
| 154 | case LN_ENTER:
|
---|
| 155 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
---|
| 156 | break;
|
---|
[2] | 157 | }
|
---|
| 158 | break;
|
---|
[551] | 159 | }
|
---|
| 160 | return 0;
|
---|
[2] | 161 |
|
---|
[551] | 162 | case WM_COMMAND:
|
---|
| 163 | switch (SHORT1FROMMP(mp1)) {
|
---|
| 164 | case DID_OK:
|
---|
| 165 | {
|
---|
| 166 | INT x;
|
---|
| 167 | CHAR s[257], *p;
|
---|
| 168 |
|
---|
| 169 | *s = 0;
|
---|
| 170 | WinQueryDlgItemText(hwnd, PICK_INPUT, 257, s);
|
---|
| 171 | if (!*s)
|
---|
| 172 | Runtime_Error(pszSrcFile, __LINE__, "no input");
|
---|
| 173 | else {
|
---|
[1391] | 174 | for (x = 0; x < 23; x++) {
|
---|
| 175 | p = CodePage[x];
|
---|
[551] | 176 | if (!stricmp(s, p)) {
|
---|
| 177 | WinDismissDlg(hwnd, atoi(p));
|
---|
| 178 | break;
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
[2] | 182 | }
|
---|
[551] | 183 | break;
|
---|
[2] | 184 |
|
---|
[551] | 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;
|
---|
[2] | 192 |
|
---|
[551] | 193 | case PICK_SAVEPOS:
|
---|
| 194 | break;
|
---|
[2] | 195 |
|
---|
[551] | 196 | case DID_CANCEL:
|
---|
| 197 | WinDismissDlg(hwnd, 0);
|
---|
| 198 | break;
|
---|
| 199 | }
|
---|
| 200 | return 0;
|
---|
[2] | 201 |
|
---|
[551] | 202 | case WM_CLOSE:
|
---|
| 203 | return 0;
|
---|
[2] | 204 | }
|
---|
[551] | 205 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
[2] | 206 | }
|
---|
| 207 |
|
---|
[551] | 208 | INT PickCodepage(HWND hwnd)
|
---|
| 209 | {
|
---|
[2] | 210 |
|
---|
| 211 | INT cp;
|
---|
| 212 |
|
---|
[551] | 213 | cp = (INT) WinDlgBox(HWND_DESKTOP,
|
---|
| 214 | hwnd,
|
---|
| 215 | PickCodePageDlgBox, FM3ModHandle, PICK_FRAME, MPVOID);
|
---|
| 216 | if (cp > 0) {
|
---|
[2] | 217 |
|
---|
[551] | 218 | HMQ hmq;
|
---|
| 219 | ULONG cps[50], len, x;
|
---|
[2] | 220 |
|
---|
| 221 | /*
|
---|
| 222 | numcps = WinQueryCpList(WinQueryAnchorBlock(hwnd),50,cps);
|
---|
| 223 | if(numcps) {
|
---|
| 224 | for(x = 0;x < numcps;x++) {
|
---|
| 225 | if(cps[x] == (ULONG)cp) {
|
---|
| 226 | hmq = WinQueryWindowULong(hwnd,QWL_HMQ);
|
---|
| 227 | WinSetCp(hmq,cp);
|
---|
| 228 | break;
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | */
|
---|
[551] | 233 | if (cp == 1004) {
|
---|
| 234 | hmq = WinQueryWindowULong(hwnd, QWL_HMQ);
|
---|
| 235 | WinSetCp(hmq, cp);
|
---|
[2] | 236 | }
|
---|
[551] | 237 | else if (!DosQueryCp(sizeof(cps), cps, &len)) {
|
---|
| 238 | for (x = 0; x < len / sizeof(ULONG); x++) {
|
---|
| 239 | if (cps[x] == (ULONG) cp) {
|
---|
| 240 | hmq = WinQueryWindowULong(hwnd, QWL_HMQ);
|
---|
| 241 | WinSetCp(hmq, cp);
|
---|
| 242 | break;
|
---|
| 243 | }
|
---|
[2] | 244 | }
|
---|
| 245 | }
|
---|
| 246 | DosSetProcessCp(cp);
|
---|
| 247 | }
|
---|
| 248 | else
|
---|
| 249 | cp = -1;
|
---|
| 250 | return cp;
|
---|
| 251 | }
|
---|
[793] | 252 |
|
---|
| 253 | #pragma alloc_text(FMCODEPAGE,PickCodePageDlgBox,PickCodepage)
|
---|