source: trunk/dll/codepage.c@ 1183

Last change on this file since 1183 was 1183, checked in by John Small, 17 years ago

Ticket 187: Draft 2: Move remaining function declarations

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