source: trunk/dll/codepage.c@ 2

Last change on this file since 2 was 2, checked in by root, 23 years ago

Initial revision

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