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