source: trunk/dll/codepage.c@ 1205

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

Ticket 187: Move datadevlarations/definitions out of fm3dll.h

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