source: trunk/dll/chklist.c@ 847

Last change on this file since 847 was 847, checked in by Gregg Young, 18 years ago

Removed large file APIs from code where hey are not needed.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.6 KB
Line 
1
2/***********************************************************************
3
4 $Id: chklist.c 847 2007-09-29 18:45:16Z gyoung $
5
6 Utility windows and mouse positioning
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2005, 2006 Steven H.Levine
10
11 10 Jan 05 SHL Allow DND_TARGET to hold CCHMAXPATH
12 14 Jul 06 SHL Use Runtime_Error
13 22 Mar 07 GKY Use QWL_USER
14 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
15
16***********************************************************************/
17
18#define INCL_DOS
19#define INCL_WIN
20#define INCL_GPI
21#define INCL_LONGLONG
22#include <os2.h>
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <ctype.h>
28
29#include "fm3dll.h"
30#include "fm3dlg.h"
31#include "fm3str.h"
32
33#pragma data_seg(DATA1)
34
35static PSZ pszSrcFile = __FILE__;
36
37VOID CenterOverWindow(HWND hwnd)
38{
39 SWP swp;
40 POINTL ptl;
41
42 if (!fDontMoveMouse) {
43 if (WinQueryWindowPos(hwnd, &swp)) {
44 ptl.x = swp.x + (swp.cx / 2);
45 ptl.y = swp.y + (swp.cy / 2);
46 WinMapWindowPoints(WinQueryWindow(hwnd, QW_PARENT), HWND_DESKTOP, &ptl,
47 1L);
48 WinSetPointerPos(HWND_DESKTOP, ptl.x, ptl.y);
49 }
50 }
51}
52
53BOOL PopupMenu(HWND hwndParent, HWND hwndOwner, HWND hwndMenu)
54{
55 POINTL ptl;
56 BOOL rc;
57
58 if (!WinQueryPointerPos(HWND_DESKTOP, &ptl))
59 ptl.x = ptl.y = 32;
60 WinMapWindowPoints(HWND_DESKTOP, hwndParent, &ptl, 1L);
61 rc = WinPopupMenu(hwndParent, hwndOwner, hwndMenu,
62 ptl.x, ptl.y, 0,
63 PU_HCONSTRAIN | PU_VCONSTRAIN |
64 PU_KEYBOARD | PU_MOUSEBUTTON1);
65 if (rc)
66 CenterOverWindow(hwndMenu);
67 return rc;
68}
69
70VOID PosOverOkay(HWND hwnd)
71{
72 SWP swp;
73 POINTL ptl;
74
75 if (!fDontMoveMouse) {
76 if (WinQueryWindowPos(WinWindowFromID(hwnd, DID_OK), &swp)) {
77 ptl.x = swp.x + (swp.cx / 2);
78 ptl.y = swp.y + (swp.cy / 2);
79 WinMapWindowPoints(hwnd, HWND_DESKTOP, &ptl, 1L);
80 WinSetPointerPos(HWND_DESKTOP, ptl.x, ptl.y);
81 }
82 }
83}
84
85MRESULT EXPENTRY CheckListProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
86{
87 CHECKLIST *cl;
88
89 switch (msg) {
90 case WM_INITDLG:
91 if (mp2) {
92
93 SHORT x;
94
95 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mp2);
96 cl = (CHECKLIST *) mp2;
97 if (!cl->list || !cl->list[0]) {
98 WinDismissDlg(hwnd, 0);
99 break;
100 }
101 WinSetDlgItemText(hwnd, CHECK_PROMPT, cl->prompt);
102 for (x = 0; cl->list[x]; x++) {
103 WinSendDlgItemMsg(hwnd, CHECK_LISTBOX, LM_INSERTITEM,
104 MPFROM2SHORT(LIT_END, 0), MPFROMP(cl->list[x]));
105 WinSendDlgItemMsg(hwnd, CHECK_LISTBOX, LM_SELECTITEM,
106 MPFROM2SHORT(x, 0), MPFROMSHORT(TRUE));
107 }
108 PosOverOkay(hwnd);
109 WinEnableWindow(WinWindowFromID(hwnd, CHECK_INFO),
110 ((cl->flags & CHECK_FILES) != 0));
111 WinShowWindow(WinWindowFromID(hwnd, CHECK_INFO),
112 ((cl->flags & CHECK_FILES) != 0));
113 {
114 HBITMAP hbm, hbmd, hbmdd;
115 HPS hps;
116
117 hps = WinGetPS(WinWindowFromID(hwnd, CHECK_BITMAP));
118 hbm = GpiLoadBitmap(hps, 0, cl->cmd, 28, 28);
119 if (hbm) {
120 hbmd =
121 (HBITMAP) WinSendDlgItemMsg(hwnd, CHECK_BITMAP, SM_QUERYHANDLE,
122 MPVOID, MPVOID);
123 hbmdd =
124 (HBITMAP) WinSendDlgItemMsg(hwnd, CHECK_BITMAP, SM_SETHANDLE,
125 MPFROMLONG(hbm), MPVOID);
126 if (hbmdd && hbmd && hbmd != hbmdd)
127 GpiDeleteBitmap(hbmd);
128 }
129 if (hps)
130 WinReleasePS(hps);
131 WinSetWindowPos(WinWindowFromID(hwnd, CHECK_BITMAP), HWND_TOP,
132 0, 0, 28, 28, SWP_SIZE);
133 }
134 }
135 else
136 WinDismissDlg(hwnd, 0);
137 break;
138
139 case WM_ADJUSTWINDOWPOS:
140 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
141 break;
142
143 case UM_SETDIR:
144 PaintRecessedWindow(WinWindowFromID(hwnd, CHECK_HELP), (HPS) 0, FALSE,
145 TRUE);
146 return 0;
147
148 case WM_CONTROL:
149 switch (SHORT1FROMMP(mp1)) {
150 case CHECK_LISTBOX:
151 switch (SHORT2FROMMP(mp1)) {
152 case LN_ENTER:
153 {
154 SHORT x;
155 CHAR szBuffer[CCHMAXPATH];
156
157 x = (SHORT) WinSendDlgItemMsg(hwnd, CHECK_LISTBOX,
158 LM_QUERYSELECTION,
159 MPFROMSHORT(LIT_FIRST), MPVOID);
160 if (x >= 0) {
161 *szBuffer = 0;
162 WinSendDlgItemMsg(hwnd, CHECK_LISTBOX, LM_QUERYITEMTEXT,
163 MPFROM2SHORT(x, CCHMAXPATH), MPFROMP(szBuffer));
164 if (*szBuffer)
165 QuickView(hwnd, szBuffer);
166 }
167 }
168 break;
169 }
170 break;
171 }
172 return 0;
173
174 case WM_COMMAND:
175 switch (SHORT1FROMMP(mp1)) {
176 case CHECK_INFO:
177 cl = INSTDATA(hwnd);
178 if (cl)
179 WinDlgBox(HWND_DESKTOP, hwnd, FileInfoProc, FM3ModHandle,
180 FLE_FRAME, (PVOID) cl->list);
181 break;
182
183 case IDM_HELP:
184 if (hwndHelp)
185 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
186 MPFROM2SHORT(HELP_CHECKLIST, 0),
187 MPFROMSHORT(HM_RESOURCEID));
188 break;
189
190 case DID_OK:
191 cl = INSTDATA(hwnd);
192 if (cl) {
193
194 CHAR szBuffer[CCHMAXPATH + 1];
195 INT numfiles = 0, numalloc = 0, error;
196 SHORT x;
197
198 FreeList(cl->list);
199 cl->list = NULL;
200 x = (SHORT) WinSendDlgItemMsg(hwnd, CHECK_LISTBOX, LM_QUERYSELECTION,
201 MPFROMSHORT(LIT_FIRST), MPVOID);
202 if (x >= 0) {
203 do {
204 *szBuffer = 0;
205 WinSendDlgItemMsg(hwnd, CHECK_LISTBOX, LM_QUERYITEMTEXT,
206 MPFROM2SHORT(x, CCHMAXPATH), MPFROMP(szBuffer));
207 if (*szBuffer) {
208 error = AddToList(szBuffer, &cl->list, &numfiles, &numalloc);
209 if (error) {
210 Runtime_Error(pszSrcFile, __LINE__, "AddToList");
211 break;
212 }
213 }
214 x = (SHORT) WinSendDlgItemMsg(hwnd, CHECK_LISTBOX,
215 LM_QUERYSELECTION,
216 MPFROMSHORT(x), MPVOID);
217 } while (x >= 0);
218 }
219 WinDismissDlg(hwnd, 1);
220 }
221 else
222 WinDismissDlg(hwnd, 0);
223 break;
224
225 case DID_CANCEL:
226 WinDismissDlg(hwnd, 0);
227 break;
228 }
229 return 0;
230 }
231 return WinDefDlgProc(hwnd, msg, mp1, mp2);
232}
233
234MRESULT EXPENTRY DropListProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
235{
236 CHECKLIST *cl;
237 static BOOL Shadow = FALSE, Wild = FALSE;
238
239 switch (msg) {
240 case WM_INITDLG:
241 if (mp2) {
242
243 SHORT x;
244
245 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mp2);
246 cl = (CHECKLIST *) mp2;
247 if (!cl->list || !cl->list[0]) {
248 WinDismissDlg(hwnd, 0);
249 break;
250 }
251 if (IsRoot(cl->list[0])) {
252 WinDismissDlg(hwnd, DND_COMPARE);
253 break;
254 }
255 WinSendDlgItemMsg(hwnd, DND_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
256 for (x = 0; cl->list[x]; x++) {
257 WinSendDlgItemMsg(hwnd, DND_LISTBOX, LM_INSERTITEM,
258 MPFROM2SHORT(LIT_END, 0), MPFROMP(cl->list[x]));
259 WinSendDlgItemMsg(hwnd, DND_LISTBOX, LM_SELECTITEM,
260 MPFROM2SHORT(x, 0), MPFROMSHORT(TRUE));
261 }
262 WinSendDlgItemMsg(hwnd, DND_TARGET, EM_SETTEXTLIMIT,
263 (MPARAM) CCHMAXPATH, (MPARAM) 0);
264 PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
265 }
266 else
267 WinDismissDlg(hwnd, 0);
268 break;
269
270 case UM_UNDO:
271 cl = INSTDATA(hwnd);
272 if (cl) {
273
274 CHAR *p;
275
276 WinSetDlgItemText(hwnd, DND_TARGET, cl->prompt);
277 WinEnableWindow(WinWindowFromID(hwnd, DND_LAUNCH),
278 (IsExecutable(cl->prompt)));
279 WinEnableWindow(WinWindowFromID(hwnd, DND_COPY), TRUE);
280 WinEnableWindow(WinWindowFromID(hwnd, DND_MOVE), TRUE);
281 WinEnableWindow(WinWindowFromID(hwnd, DND_RENAME), TRUE);
282 WinEnableWindow(WinWindowFromID(hwnd, DND_OBJECT), TRUE);
283 WinEnableWindow(WinWindowFromID(hwnd, DND_SHADOW), TRUE);
284 WinEnableWindow(WinWindowFromID(hwnd, DND_EXTRACT), TRUE);
285 WinEnableWindow(WinWindowFromID(hwnd, DND_SETICON), FALSE);
286 p = strrchr(cl->list[0], '.');
287 if (p) {
288 p++;
289 if (!stricmp(p, "ICO") || !stricmp(p, "PTR"))
290 WinEnableWindow(WinWindowFromID(hwnd, DND_SETICON), TRUE);
291 }
292 if (IsFile(cl->prompt)) {
293 WinEnableWindow(WinWindowFromID(hwnd, DND_OBJECT), FALSE);
294 WinEnableWindow(WinWindowFromID(hwnd, DND_SHADOW), FALSE);
295 WinEnableWindow(WinWindowFromID(hwnd, DND_EXTRACT), FALSE);
296 WinEnableWindow(WinWindowFromID(hwnd, DND_RENAME), FALSE);
297 }
298 else {
299
300 ARC_TYPE *info;
301
302 info = find_type(cl->list[0], NULL);
303 if (!info)
304 WinEnableWindow(WinWindowFromID(hwnd, DND_EXTRACT), FALSE);
305 }
306 if (Shadow)
307 WinCheckButton(hwnd, DND_SHADOW, TRUE);
308 if (Wild)
309 WinCheckButton(hwnd, DND_RENAME, TRUE);
310 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
311 if (cl->prompt && isalpha(*cl->prompt) &&
312 (driveflags[toupper(*cl->prompt) - 'A'] & DRIVE_NOTWRITEABLE)) {
313 WinEnableWindow(WinWindowFromID(hwnd, DND_COPY), FALSE);
314 WinEnableWindow(WinWindowFromID(hwnd, DND_MOVE), FALSE);
315 WinEnableWindow(WinWindowFromID(hwnd, DND_RENAME), FALSE);
316 WinEnableWindow(WinWindowFromID(hwnd, DND_OBJECT), FALSE);
317 WinEnableWindow(WinWindowFromID(hwnd, DND_SHADOW), FALSE);
318 WinEnableWindow(WinWindowFromID(hwnd, DND_EXTRACT), FALSE);
319 }
320 if (cl->prompt && IsFile(cl->prompt) == 1) {
321
322 ARC_TYPE *info;
323
324 info = find_type(cl->prompt, NULL);
325 if (!info) {
326 WinEnableWindow(WinWindowFromID(hwnd, DND_COPY), FALSE);
327 WinEnableWindow(WinWindowFromID(hwnd, DND_MOVE), FALSE);
328 WinEnableWindow(WinWindowFromID(hwnd, DND_RENAME), FALSE);
329 WinEnableWindow(WinWindowFromID(hwnd, DND_OBJECT), FALSE);
330 WinEnableWindow(WinWindowFromID(hwnd, DND_SHADOW), FALSE);
331 WinEnableWindow(WinWindowFromID(hwnd, DND_EXTRACT), FALSE);
332 }
333 }
334 }
335 break;
336
337 case UM_SETUP:
338 cl = WinQueryWindowPtr(hwnd, QWL_USER);
339 if (cl) {
340 if (cl->flags == DO_MOVE)
341 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, DND_MOVE));
342 else if (cl->flags == DO_LINK)
343 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, DND_COMPARE));
344 else
345 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, DND_COPY));
346 }
347 return 0;
348
349 case WM_ADJUSTWINDOWPOS:
350 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
351 break;
352
353 case UM_SETDIR:
354 PaintRecessedWindow(WinWindowFromID(hwnd, DND_HELP), (HPS) 0, FALSE,
355 TRUE);
356 return 0;
357
358 case WM_CONTROL:
359 switch (SHORT1FROMMP(mp1)) {
360 case DND_LISTBOX:
361 switch (SHORT2FROMMP(mp1)) {
362 case LN_SETFOCUS:
363 WinSetDlgItemText(hwnd, DND_HELP, GetPString(IDS_DNDLISTBOXHELPTEXT));
364 break;
365 case LN_KILLFOCUS:
366 WinSetDlgItemText(hwnd, DND_HELP, GetPString(IDS_DNDHELPTEXT));
367 break;
368 case LN_ENTER:
369 {
370 SHORT x;
371 CHAR szBuffer[CCHMAXPATH];
372
373 x = (SHORT) WinSendDlgItemMsg(hwnd, DND_LISTBOX, LM_QUERYSELECTION,
374 MPFROMSHORT(LIT_FIRST), MPVOID);
375 if (x >= 0) {
376 *szBuffer = 0;
377 WinSendDlgItemMsg(hwnd, DND_LISTBOX, LM_QUERYITEMTEXT,
378 MPFROM2SHORT(x, CCHMAXPATH), MPFROMP(szBuffer));
379 if (*szBuffer)
380 QuickView(hwnd, szBuffer);
381 }
382 }
383 break;
384 }
385 break;
386 case DND_TARGET:
387 switch (SHORT2FROMMP(mp1)) {
388 case EN_SETFOCUS:
389 WinSetDlgItemText(hwnd, DND_HELP, GetPString(IDS_DNDTARGETHELPTEXT));
390 break;
391 case EN_KILLFOCUS:
392 WinSetDlgItemText(hwnd, DND_HELP, GetPString(IDS_DNDHELPTEXT));
393 break;
394 }
395 break;
396 }
397 return 0;
398
399 case WM_COMMAND:
400 switch (SHORT1FROMMP(mp1)) {
401 case IDM_HELP:
402 if (hwndHelp)
403 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
404 MPFROM2SHORT(HELP_DNDDLG, 0), MPFROMSHORT(HM_RESOURCEID));
405 break;
406
407 case DND_INFO:
408 cl = INSTDATA(hwnd);
409 if (cl)
410 WinDlgBox(HWND_DESKTOP, hwnd, FileInfoProc, FM3ModHandle,
411 FLE_FRAME, (PVOID) cl->list);
412 break;
413
414 case DND_CHANGETARGET:
415 cl = INSTDATA(hwnd);
416 if (cl) {
417 if (cl->prompt && *cl->prompt) {
418 if (!IsFile(cl->prompt)) {
419
420 CHAR newpath[CCHMAXPATH];
421
422 strcpy(newpath, cl->prompt);
423 if (WinDlgBox(HWND_DESKTOP, hwnd, WalkAllDlgProc,
424 FM3ModHandle, WALK_FRAME,
425 MPFROMP(newpath)) && *newpath) {
426 strcpy(cl->prompt, newpath);
427 PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
428 }
429 }
430 else {
431
432 FILEDLG fdlg;
433 FILESTATUS3 fs3;
434 CHAR drive[3], *pdrive = drive, filename[CCHMAXPATH], *p;
435
436 memset(&fdlg, 0, sizeof(FILEDLG));
437 fdlg.cbSize = (ULONG) sizeof(FILEDLG);
438 fdlg.fl = FDS_HELPBUTTON | FDS_CENTER |
439 FDS_OPEN_DIALOG | FDS_CUSTOM;
440 fdlg.pszTitle = GetPString(IDS_NEWTARGETTEXT);
441 fdlg.pszOKButton = GetPString(IDS_CHANGETEXT);
442 *drive = *cl->prompt;
443 drive[1] = ':';
444 drive[2] = 0;
445 fdlg.pszIDrive = pdrive;
446 strcpy(fdlg.szFullFile, cl->prompt);
447 p = strrchr(fdlg.szFullFile, '\\');
448 if (p)
449 *p = 0;
450 strcat(fdlg.szFullFile, "\\*");
451
452 fdlg.pfnDlgProc = (PFNWP) CustomFileDlg;
453 fdlg.hMod = FM3ModHandle;
454 fdlg.usDlgId = FDLG_FRAME;
455
456 if (WinFileDlg(HWND_DESKTOP, hwnd, &fdlg)) {
457 if (fdlg.lReturn != DID_CANCEL && !fdlg.lSRC) {
458 if (!DosQueryPathInfo(fdlg.szFullFile,
459 FIL_QUERYFULLNAME,
460 filename, sizeof(filename))) {
461 if (!DosQueryPathInfo(filename,
462 FIL_STANDARD, &fs3, sizeof(fs3))) {
463 p = filename;
464 while (*p) {
465 if (*p == '/')
466 *p = '\\';
467 p++;
468 }
469 strcpy(cl->prompt, filename);
470 PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
471 }
472// else saymsg(MB_ENTER,hwnd,DEBUG_STRING,"DosQueryPathInfo FIL_STANDARDL failed");
473 }
474// else saymsg(MB_ENTER,hwnd,DEBUG_STRING,"DosQueryPathInfo FIL_QUERYFULLNAME failed");
475 }
476// else saymsg(MB_ENTER,hwnd,DEBUG_STRING,"lReturn = %lu lSRC = %lu",fdlg.lReturn,fdlg.lSRC);
477 }
478// else saymsg(MB_ENTER,hwnd,DEBUG_STRING,"WinFileDlg failed");
479 }
480 }
481 }
482 break;
483
484 case DND_TARGETINFO:
485 cl = INSTDATA(hwnd);
486 if (cl) {
487
488 CHAR *list[2];
489
490 list[0] = cl->prompt;
491 list[1] = NULL;
492 WinDlgBox(HWND_DESKTOP, hwnd, FileInfoProc, FM3ModHandle,
493 FLE_FRAME, (PVOID) & list);
494 }
495 break;
496
497 case DND_EXTRACT:
498 case DND_LAUNCH:
499 case DND_COPY:
500 case DND_MOVE:
501 case DND_OBJECT:
502 case DND_COMPARE:
503 case DND_SETICON:
504 case DND_APPEND:
505 cl = INSTDATA(hwnd);
506 if (cl) {
507
508 SHORT x;
509 CHAR szBuffer[CCHMAXPATH + 1];
510 INT numfiles = 0, numalloc = 0, error;
511 USHORT cmd;
512
513 FreeList(cl->list);
514 cl->list = NULL;
515 x = (SHORT) WinSendDlgItemMsg(hwnd, DND_LISTBOX, LM_QUERYSELECTION,
516 MPFROMSHORT(LIT_FIRST), MPVOID);
517 if (x >= 0) {
518 do {
519 *szBuffer = 0;
520 WinSendDlgItemMsg(hwnd, DND_LISTBOX, LM_QUERYITEMTEXT,
521 MPFROM2SHORT(x, CCHMAXPATH), MPFROMP(szBuffer));
522 if (*szBuffer) {
523 error = AddToList(szBuffer, &cl->list, &numfiles, &numalloc);
524 if (error) {
525 Runtime_Error(pszSrcFile, __LINE__, "AddToList");
526 break;
527 }
528 }
529 x = (SHORT) WinSendDlgItemMsg(hwnd, DND_LISTBOX,
530 LM_QUERYSELECTION,
531 MPFROMSHORT(x), MPVOID);
532 } while (x >= 0);
533 }
534 cmd = SHORT1FROMMP(mp1);
535 switch (cmd) {
536 case DND_COPY:
537 if (WinQueryButtonCheckstate(hwnd, DND_RENAME)) {
538 Wild = TRUE;
539 cmd = DND_WILDCOPY;
540 }
541 else
542 Wild = FALSE;
543 break;
544 case DND_MOVE:
545 if (WinQueryButtonCheckstate(hwnd, DND_RENAME)) {
546 Wild = TRUE;
547 cmd = DND_WILDMOVE;
548 }
549 else
550 Wild = FALSE;
551 break;
552 case DND_OBJECT:
553 if (WinQueryButtonCheckstate(hwnd, DND_SHADOW)) {
554 Shadow = TRUE;
555 cmd = DND_SHADOW;
556 }
557 else
558 Shadow = FALSE;
559 break;
560 }
561 WinDismissDlg(hwnd, cmd);
562 }
563 else
564 WinDismissDlg(hwnd, 0);
565 break;
566
567 case DID_CANCEL:
568 WinDismissDlg(hwnd, 0);
569 break;
570 }
571 return 0;
572 }
573 return WinDefDlgProc(hwnd, msg, mp1, mp2);
574}
575
576#pragma alloc_text(CHECKLIST,CheckListProc)
577#pragma alloc_text(DNDLIST,DropListProc)
578#pragma alloc_text(MISC7,PosOverOkay,CenterOverWindow,PopupMenu)
Note: See TracBrowser for help on using the repository browser.