source: trunk/dll/codepage.c@ 1346

Last change on this file since 1346 was 1346, checked in by Gregg Young, 17 years ago

Code cleanup; removal of dead 07 code copywrite updates etc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
RevLine 
[347]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
[1346]9 Copyright (c) 2006, 2008 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
[347]13
14***********************************************************************/
15
[907]16#include <stdlib.h>
17#include <string.h>
18
[2]19#define INCL_DOS
20#define INCL_WIN
[907]21#define INCL_LONGLONG // dircnrs.h
[2]22
[1183]23#include "fm3dll.h"
[1221]24#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1205]25#include "notebook.h" // Data declaration(s)
26#include "mainwnd.h" // Data declaration(s)
[2]27#include "fm3dlg.h"
28#include "fm3str.h"
[907]29#include "strutil.h" // GetPString
30#include "errutil.h" // Runtime_Error
[1159]31#include "codepage.h"
[1183]32#include "misc.h" // PostMsg
[2]33
34#pragma data_seg(DATA1)
35
[347]36static PSZ pszSrcFile = __FILE__;
37
[551]38MRESULT EXPENTRY PickCodePageDlgBox(HWND hwnd, ULONG msg, MPARAM mp1,
39 MPARAM mp2)
40{
[2]41
42 SHORT sSelect;
43
[551]44 switch (msg) {
45 case WM_INITDLG:
46 WinShowWindow(WinWindowFromID(hwnd, PICK_SAVEPOS), FALSE);
47 {
48 ULONG cp;
49 char *p;
[2]50
[551]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 }
[2]68 }
[551]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;
[2]76
[551]77 case UM_STRETCH:
78 {
79 SWP swp, swpL, swpE;
80 LONG titl, szbx, szby;
[2]81
[551]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);
[2]103 }
[551]104 }
105 return 0;
[2]106
[551]107 case WM_ADJUSTWINDOWPOS:
108 {
109 SWP swp;
[2]110
[551]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;
[2]135 }
136 break;
[551]137 }
138 return 0;
[2]139
[551]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 }
[2]159 }
[551]160 break;
[2]161
[551]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;
[2]169
[551]170 case PICK_SAVEPOS:
171 break;
[2]172
[551]173 case DID_CANCEL:
174 WinDismissDlg(hwnd, 0);
175 break;
176 }
177 return 0;
[2]178
[551]179 case WM_CLOSE:
180 return 0;
[2]181 }
[551]182 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]183}
184
[551]185INT PickCodepage(HWND hwnd)
186{
[2]187
188 INT cp;
189
[551]190 cp = (INT) WinDlgBox(HWND_DESKTOP,
191 hwnd,
192 PickCodePageDlgBox, FM3ModHandle, PICK_FRAME, MPVOID);
193 if (cp > 0) {
[2]194
[551]195 HMQ hmq;
196 ULONG cps[50], len, x;
[2]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*/
[551]210 if (cp == 1004) {
211 hmq = WinQueryWindowULong(hwnd, QWL_HMQ);
212 WinSetCp(hmq, cp);
[2]213 }
[551]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 }
[2]221 }
222 }
223 DosSetProcessCp(cp);
224 }
225 else
226 cp = -1;
227 return cp;
228}
[793]229
230#pragma alloc_text(FMCODEPAGE,PickCodePageDlgBox,PickCodepage)
Note: See TracBrowser for help on using the repository browser.