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