source: trunk/dll/tools.c@ 1036

Last change on this file since 1036 was 1009, checked in by Steven Levine, 17 years ago

Add xfree xstrdup Fortify support
Add MT capable Fortify scope logic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: tools.c 1009 2008-05-10 07:51:58Z stevenhl $
5
6 Toolbar support routines
7
8 Copyright (c) 1994-97 M. Kimes
9 Copyright (c) 2004, 2006 Steven H.Levine
10
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 23 May 05 SHL Use QWL_USER
13 22 Jul 06 SHL Check more run time errors
14 29 Jul 06 SHL Use xfgets, xfgets_bstripcr
15 18 Aug 06 SHL Report more runtime errors
16 05 Sep 06 SHL docopyf filename args must be variables
17 05 Sep 06 SHL Sync with standard source formatting
18 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
19 29 Feb 08 GKY Use xfree where appropriate
20
21***********************************************************************/
22
23#include <stdlib.h>
24#include <string.h>
25#include <share.h>
26
27#define INCL_DOS
28#define INCL_WIN
29#define INCL_LONGLONG
30
31#include "fm3dlg.h"
32#include "tools.h"
33#include "fm3str.h"
34#include "errutil.h" // Dos_Error...
35#include "strutil.h" // GetPString
36#include "fm3dll.h"
37
38#pragma data_seg(DATA1)
39
40static PSZ pszSrcFile = __FILE__;
41
42TOOL *toolhead = NULL;
43
44//== load_quicktools() build *.tls array ==
45
46VOID load_quicktools(VOID)
47{
48 FILE *fp;
49 CHAR s[CCHMAXPATH + 14];
50 INT x;
51
52 qtloaded = TRUE;
53 for (x = 0; x < 50 && quicktool[x]; x++) {
54 xfree(quicktool[x], pszSrcFile, __LINE__);
55 quicktool[x] = NULL;
56 }
57 if (!fToolbar) {
58 qtloaded = FALSE;
59 return;
60 }
61 save_dir2(s);
62 if (s[strlen(s) - 1] != '\\')
63 strcat(s, "\\");
64 strcat(s, "QUICKTLS.DAT");
65 fp = _fsopen(s, "r", SH_DENYWR);
66 if (fp) {
67 x = 0;
68 while (!feof(fp)) {
69 if (!xfgets_bstripcr(s, CCHMAXPATH + 2, fp, pszSrcFile, __LINE__))
70 break;
71 if (!*s || *s == ';')
72 continue;
73 if (x >= 50) {
74 Runtime_Error(pszSrcFile, __LINE__, "add");
75 break;
76 }
77 quicktool[x] = xstrdup(s, pszSrcFile, __LINE__);
78 if (!quicktool[x])
79 break;
80 x++;
81 }
82 fclose(fp);
83 }
84}
85
86VOID save_quicktools(VOID)
87{
88 FILE *fp;
89 INT x = 0;
90 CHAR s[CCHMAXPATH + 14];
91
92 if (!quicktool[0])
93 return;
94 save_dir2(s);
95 if (s[strlen(s) - 1] != '\\')
96 strcat(s, "\\");
97 strcat(s, "QUICKTLS.DAT");
98 fp = xfopen(s, "w", pszSrcFile, __LINE__);
99 if (fp) {
100 for (x = 0; quicktool[x] && x < 50; x++)
101 fprintf(fp, "%s\n", quicktool[x]);
102 fclose(fp);
103 }
104}
105
106//== load_tools() Build tools list given .tls filename ==
107
108TOOL *load_tools(CHAR * filename)
109{
110 FILE *fp;
111 CHAR help[80], text[80], flagstr[80], idstr[80], *fname;
112 TOOL *info;
113
114 if (!fToolbar) {
115 toolhead = free_tools();
116 return toolhead;
117 }
118 if (!filename || !*filename)
119 filename = (*lasttoolbox) ? lasttoolbox : "CMDS.TLS";
120 if (*filename)
121 fname = searchpath(filename);
122 if (!fname || !*fname)
123 fname = "FM3TOOLS.DAT";
124 if (fname && *fname) {
125 filename = fname;
126 strcpy(lasttoolbox, filename);
127 fp = _fsopen(filename, "r", SH_DENYWR);
128 if (fp) {
129 toolhead = free_tools();
130 while (!feof(fp)) {
131 do {
132 if (!xfgets(help, sizeof(help), fp, pszSrcFile, __LINE__))
133 break;
134 } while (*help == ';' && !feof(fp));
135 stripcr(help);
136 if (!xfgets(text, sizeof(text), fp, pszSrcFile, __LINE__))
137 break;
138 stripcr(text);
139 if (!xfgets(flagstr, sizeof(flagstr), fp, pszSrcFile, __LINE__))
140 break;
141 if (!xfgets(idstr, sizeof(idstr), fp, pszSrcFile, __LINE__))
142 break;
143 if (!(USHORT) atoi(idstr))
144 continue;
145 info = xmallocz(sizeof(TOOL), pszSrcFile, __LINE__);
146 if (info) {
147 if (*help) {
148 literal(help);
149 if (*help)
150 info->help = xstrdup(help, pszSrcFile, __LINE__);
151 }
152 if (*text)
153 info->text = xstrdup(text, pszSrcFile, __LINE__);
154 info->flags = (atoi(flagstr) & (~(T_TEXT | T_EMPHASIZED)));
155 info->id = (USHORT) atoi(idstr);
156 info->next = NULL;
157 add_tool(info);
158 }
159 }
160 fclose(fp);
161 fToolsChanged = FALSE;
162 }
163 }
164 return toolhead;
165}
166
167VOID save_tools(CHAR * filename)
168{
169 FILE *fp;
170 CHAR *fname;
171 TOOL *info;
172
173 if (!filename)
174 filename = lasttoolbox;
175 if (*filename)
176 fname = searchpath(filename);
177 if (fname && *fname)
178 filename = fname;
179 else {
180 if (*lasttoolbox)
181 filename = lasttoolbox;
182 else
183 filename = "FM3TOOLS.TLS";
184 fname = searchpath(filename);
185 if (fname && *fname)
186 filename = fname;
187 }
188
189 if (stristr(filename, "FM3TOOLS.DAT"))
190 filename = "FM3TOOLS.TLS";
191 if (toolhead && filename && *filename) {
192 strcpy(lasttoolbox, filename);
193 PrfWriteProfileString(fmprof, FM3Str, "LastToolBox", filename);
194 }
195 if (!toolhead) {
196 unlinkf("%s", filename);
197 return;
198 }
199 fp = xfopen(filename, "w", pszSrcFile, __LINE__);
200 if (fp) {
201 fprintf(fp, GetPString(IDS_TOOLFILETEXT), filename);
202 info = toolhead;
203 while (info) {
204 fprintf(fp,
205 "%s\n%s\n%u\n%u\n;\n",
206 (info->help) ? info->help : NullStr,
207 (info->text) ? info->text : NullStr,
208 (info->flags & (~(T_EMPHASIZED | T_TEXT))), info->id);
209 info = info->next;
210 }
211 fclose(fp);
212 fToolsChanged = FALSE;
213 }
214 if (hwndMain)
215 PostMsg(hwndMain, UM_FILLBUTTONLIST, MPVOID, MPVOID);
216}
217
218TOOL *add_tool(TOOL * tool)
219{
220 TOOL *info;
221
222 if (tool) {
223 info = toolhead;
224 if (info) {
225 while (info->next)
226 info = info->next;
227 }
228 if (info)
229 info->next = tool;
230 else
231 toolhead = tool;
232 fToolsChanged = TRUE;
233 }
234 return toolhead;
235}
236
237TOOL *insert_tool(TOOL * tool, TOOL * after)
238{
239 if (tool) {
240 if (!toolhead)
241 return add_tool(tool);
242 if (!after) {
243 tool->next = toolhead;
244 toolhead = tool;
245 fToolsChanged = TRUE;
246 }
247 else {
248 tool->next = after->next;
249 after->next = tool;
250 fToolsChanged = TRUE;
251 }
252 }
253 return toolhead;
254}
255
256TOOL *del_tool(TOOL * tool)
257{
258 TOOL *info, *prev = NULL;
259
260 if (tool) {
261 info = toolhead;
262 while (info) {
263 if (info == tool) {
264 if (info == toolhead)
265 toolhead = info->next;
266 if (prev)
267 prev->next = info->next;
268 xfree(info->help, pszSrcFile, __LINE__);
269 xfree(info->text, pszSrcFile, __LINE__);
270 xfree(info, pszSrcFile, __LINE__);
271 fToolsChanged = TRUE;
272 break;
273 }
274 prev = info;
275 info = info->next;
276 }
277 }
278 return toolhead;
279}
280
281TOOL *find_tool(USHORT id)
282{
283 TOOL *tool;
284
285 if (id) {
286 tool = toolhead;
287 while (tool) {
288 if (id && tool->id == id)
289 return tool;
290 tool = tool->next;
291 }
292 }
293 return NULL;
294}
295
296TOOL *next_tool(TOOL * tool, BOOL skipinvisible)
297{
298 while (tool) {
299 if (tool->next && (skipinvisible && (tool->next->flags & T_INVISIBLE)))
300 tool = tool->next;
301 else
302 return (tool->next) ? tool->next : toolhead;
303 }
304 return NULL;
305}
306
307TOOL *prev_tool(TOOL * tool, BOOL skipinvisible)
308{
309 TOOL *info;
310
311Again:
312 while (tool) {
313 info = toolhead;
314 while (info) {
315 if (info->next == tool) {
316 if (skipinvisible && (info->flags & T_INVISIBLE)) {
317 tool = info;
318 goto Again;
319 }
320 return info;
321 }
322 if (!info->next && tool == toolhead)
323 return info;
324 info = info->next;
325 }
326 return toolhead;
327 }
328 return NULL;
329}
330
331TOOL *swap_tools(TOOL * tool1, TOOL * tool2)
332{
333 TOOL *prev1 = NULL, *prev2 = NULL, *info;
334
335 if (tool1 && tool2 && tool1 != tool2) {
336 info = toolhead;
337 while (info && !prev1 && !prev2) {
338 if (info->next == tool1)
339 prev1 = info;
340 else if (info->next == tool2)
341 prev2 = info;
342 info = info->next;
343 }
344 info = tool2;
345 tool2 = tool1;
346 tool1 = info;
347 info = tool2->next;
348 if (prev1)
349 prev1->next = tool2;
350 if (prev2)
351 prev2->next = tool1;
352 tool2->next = tool1->next;
353 tool1->next = info;
354 fToolsChanged = TRUE;
355 }
356 return toolhead;
357}
358
359TOOL *free_tools(VOID)
360{
361 TOOL *tool, *next;
362
363 tool = toolhead;
364 while (tool) {
365 next = tool->next;
366 xfree(tool->help, pszSrcFile, __LINE__);
367 xfree(tool->text, pszSrcFile, __LINE__);
368 xfree(tool, pszSrcFile, __LINE__);
369 tool = next;
370 }
371 toolhead = NULL;
372 return toolhead;
373}
374
375MRESULT EXPENTRY ReOrderToolsProc(HWND hwnd, ULONG msg, MPARAM mp1,
376 MPARAM mp2)
377{
378 switch (msg) {
379 case WM_INITDLG:
380 if (!toolhead || !toolhead->next)
381 WinDismissDlg(hwnd, 0);
382 WinSetWindowText(hwnd, GetPString(IDS_RETOOLTEXT));
383 {
384 TOOL *tool;
385 CHAR s[133];
386 SHORT sSelect;
387
388 tool = toolhead;
389 while (tool) {
390 sprintf(s, "%-5u %s", tool->id, (tool->help) ? tool->help : "?");
391 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
392 RE_ADDLISTBOX,
393 LM_INSERTITEM,
394 MPFROMSHORT(LIT_END), MPFROMP(s));
395 if (sSelect >= 0)
396 WinSendDlgItemMsg(hwnd,
397 RE_ADDLISTBOX,
398 LM_SETITEMHANDLE,
399 MPFROMSHORT(sSelect), MPFROMLONG((ULONG) tool));
400 tool = tool->next;
401 }
402 }
403 break;
404
405 case WM_CONTROL:
406 return 0;
407
408 case WM_COMMAND:
409 switch (SHORT1FROMMP(mp1)) {
410 case DID_CANCEL:
411 WinDismissDlg(hwnd, 0);
412 break;
413
414 case DID_OK:
415 {
416 TOOL *tool, *thead = NULL, *last = NULL;
417 SHORT sSelect = 0, numitems;
418
419 numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
420 LM_QUERYITEMCOUNT,
421 MPVOID, MPVOID);
422 while (numitems) {
423 tool = (TOOL *) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
424 LM_QUERYITEMHANDLE,
425 MPFROMSHORT(sSelect++), MPVOID);
426 if (tool) {
427 if (!thead)
428 thead = tool;
429 else
430 last->next = tool;
431 last = tool;
432 }
433 numitems--;
434 }
435 sSelect = 0;
436 numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
437 LM_QUERYITEMCOUNT,
438 MPVOID, MPVOID);
439 while (numitems) {
440 tool = (TOOL *) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
441 LM_QUERYITEMHANDLE,
442 MPFROMSHORT(sSelect++), MPVOID);
443 if (tool) {
444 if (!thead)
445 thead = tool;
446 else
447 last->next = tool;
448 last = tool;
449 }
450 numitems--;
451 }
452 if (last)
453 last->next = NULL;
454 toolhead = thead;
455 }
456 fToolsChanged = TRUE;
457 WinDismissDlg(hwnd, 1);
458 break;
459
460 case IDM_HELP:
461 if (hwndHelp)
462 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
463 MPFROM2SHORT(HELP_REORDERBUTTONS, 0),
464 MPFROMSHORT(HM_RESOURCEID));
465 break;
466
467 case RE_ADD:
468 {
469 SHORT sSelect, sSelect2;
470 CHAR s[133];
471 TOOL *tool;
472
473 sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
474 RE_ADDLISTBOX,
475 LM_QUERYSELECTION,
476 MPFROMSHORT(LIT_FIRST), MPVOID);
477 while (sSelect >= 0) {
478 tool = (TOOL *) WinSendDlgItemMsg(hwnd,
479 RE_ADDLISTBOX,
480 LM_QUERYITEMHANDLE,
481 MPFROMSHORT(sSelect), MPVOID);
482 if (tool) {
483 sprintf(s, "%-5u %s", tool->id, (tool->help) ? tool->help : "?");
484 sSelect2 = (SHORT) WinSendDlgItemMsg(hwnd,
485 RE_REMOVELISTBOX,
486 LM_INSERTITEM,
487 MPFROM2SHORT(LIT_END, 0),
488 MPFROMP(s));
489 if (sSelect2 >= 0)
490 WinSendDlgItemMsg(hwnd,
491 RE_REMOVELISTBOX,
492 LM_SETITEMHANDLE,
493 MPFROMSHORT(sSelect2),
494 MPFROMLONG((ULONG) tool));
495 WinSendDlgItemMsg(hwnd,
496 RE_ADDLISTBOX,
497 LM_DELETEITEM, MPFROMSHORT(sSelect), MPVOID);
498 }
499 else
500 WinSendDlgItemMsg(hwnd,
501 RE_ADDLISTBOX,
502 LM_SELECTITEM,
503 MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
504 sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
505 RE_ADDLISTBOX,
506 LM_QUERYSELECTION,
507 MPFROMSHORT(LIT_FIRST),
508 MPVOID);
509 }
510 }
511 break;
512
513 case RE_REMOVE:
514 {
515 SHORT sSelect, sSelect2;
516 CHAR s[133];
517 TOOL *tool;
518
519 sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
520 RE_REMOVELISTBOX,
521 LM_QUERYSELECTION,
522 MPFROMSHORT(LIT_FIRST), MPVOID);
523 while (sSelect >= 0) {
524 tool = (TOOL *) WinSendDlgItemMsg(hwnd,
525 RE_REMOVELISTBOX,
526 LM_QUERYITEMHANDLE,
527 MPFROMSHORT(sSelect), MPVOID);
528 if (tool) {
529 sprintf(s, "%-5u %s", tool->id, (tool->help) ? tool->help : "?");
530 sSelect2 = (SHORT) WinSendDlgItemMsg(hwnd,
531 RE_ADDLISTBOX,
532 LM_INSERTITEM,
533 MPFROM2SHORT(LIT_END, 0),
534 MPFROMP(s));
535 if (sSelect2 >= 0)
536 WinSendDlgItemMsg(hwnd,
537 RE_ADDLISTBOX,
538 LM_SETITEMHANDLE,
539 MPFROMSHORT(sSelect2),
540 MPFROMLONG((ULONG) tool));
541 WinSendDlgItemMsg(hwnd,
542 RE_REMOVELISTBOX,
543 LM_DELETEITEM, MPFROMSHORT(sSelect), MPVOID);
544 }
545 else
546 WinSendDlgItemMsg(hwnd,
547 RE_REMOVELISTBOX,
548 LM_SELECTITEM,
549 MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
550 sSelect = (USHORT) WinSendDlgItemMsg(hwnd,
551 RE_REMOVELISTBOX,
552 LM_QUERYSELECTION,
553 MPFROMSHORT(LIT_FIRST),
554 MPVOID);
555 }
556 }
557 break;
558 }
559 return 0;
560 }
561 return WinDefDlgProc(hwnd, msg, mp1, mp2);
562}
563
564MRESULT EXPENTRY AddToolProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
565{
566 switch (msg) {
567 case WM_INITDLG:
568 WinSetWindowPtr(hwnd, QWL_USER, mp2);
569 if (mp2) {
570 WinSetWindowText(hwnd, GetPString(IDS_EDITTOOLTEXT));
571 WinSendDlgItemMsg(hwnd, ADDBTN_ID, EM_SETREADONLY,
572 MPFROM2SHORT(TRUE, 0), MPVOID);
573 }
574 WinSendDlgItemMsg(hwnd, ADDBTN_HELP, EM_SETTEXTLIMIT,
575 MPFROM2SHORT(80, 0), MPVOID);
576 WinSendDlgItemMsg(hwnd, ADDBTN_TEXT, EM_SETTEXTLIMIT,
577 MPFROM2SHORT(80, 0), MPVOID);
578 WinSendDlgItemMsg(hwnd, ADDBTN_ID, EM_SETTEXTLIMIT,
579 MPFROM2SHORT(5, 0), MPVOID);
580 if (!mp2)
581 WinCheckButton(hwnd, ADDBTN_VISIBLE, TRUE);
582 else {
583 TOOL *tool = (TOOL *) mp2;
584 CHAR s[33];
585
586 if (tool->help)
587 WinSetDlgItemText(hwnd, ADDBTN_HELP, tool->help);
588 if (tool->text)
589 WinSetDlgItemText(hwnd, ADDBTN_TEXT, tool->text);
590 if (tool->flags & T_MYICON)
591 WinCheckButton(hwnd, ADDBTN_MYICON, TRUE);
592 else
593 WinEnableWindow(WinWindowFromID(hwnd, ADDBTN_EDITBMP), FALSE);
594 if (tool->flags & T_DROPABLE)
595 WinCheckButton(hwnd, ADDBTN_DROPABLE, TRUE);
596 if (!(tool->flags & T_INVISIBLE))
597 WinCheckButton(hwnd, ADDBTN_VISIBLE, TRUE);
598 if (tool->flags & T_SEPARATOR)
599 WinCheckButton(hwnd, ADDBTN_SEPARATOR, TRUE);
600 if (tool->flags & T_TEXT)
601 WinCheckButton(hwnd, ADDBTN_SHOWTEXT, TRUE);
602 sprintf(s, "%u", tool->id);
603 WinSetDlgItemText(hwnd, ADDBTN_ID, s);
604 WinEnableWindow(WinWindowFromID(hwnd, ADDBTN_SHOWTEXT), FALSE);
605 }
606 WinShowWindow(WinWindowFromID(hwnd, ADDBTN_SHOWTEXT), FALSE);
607 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
608 break;
609
610 case WM_ADJUSTWINDOWPOS:
611 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
612 break;
613
614 case UM_SETDIR:
615 PaintRecessedWindow(WinWindowFromID(hwnd, ADDBTN_HELPME), (HPS) 0, FALSE,
616 TRUE);
617 PaintRecessedWindow(WinWindowFromID(hwnd, ADDBTN_BMP), (HPS) 0, TRUE,
618 FALSE);
619 return 0;
620
621 case UM_SETUP:
622 {
623 HBITMAP hbm = (HBITMAP) 0, hbmd, hbmdd;
624 HPS hps;
625 CHAR idstr[7];
626 USHORT id;
627
628 *idstr = 0;
629 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
630 id = atoi(idstr);
631 if (id) {
632 hps = WinGetPS(WinWindowFromID(hwnd, ADDBTN_BMP));
633 if (!WinQueryButtonCheckstate(hwnd, ADDBTN_MYICON))
634 hbm = GpiLoadBitmap(hps, 0, id, 28, 28);
635 if (!hbm)
636 hbm = LoadBitmapFromFileNum(id);
637 if (hbm) {
638 hbmd = (HBITMAP) WinSendDlgItemMsg(hwnd, ADDBTN_BMP, SM_QUERYHANDLE,
639 MPVOID, MPVOID);
640 hbmdd = (HBITMAP) WinSendDlgItemMsg(hwnd, ADDBTN_BMP, SM_SETHANDLE,
641 MPFROMLONG(hbm), MPVOID);
642 if (hbmdd && hbmd && hbmd != hbmdd)
643 GpiDeleteBitmap(hbmd);
644 }
645 }
646 }
647 return 0;
648
649 case WM_CONTROL:
650 switch (SHORT1FROMMP(mp1)) {
651 case ADDBTN_HELP:
652 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
653 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
654 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
655 WinSetDlgItemText(hwnd, ADDBTN_HELPME,
656 GetPString(IDS_ADDTOOLQUICKHELPTEXT));
657 break;
658
659 case ADDBTN_TEXT:
660 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
661 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
662 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
663 WinSetDlgItemText(hwnd, ADDBTN_HELPME,
664 GetPString(IDS_ADDTOOLBUTTONTEXT));
665 break;
666
667 case ADDBTN_ID:
668 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) {
669 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
670 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
671 }
672 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
673 WinSetDlgItemText(hwnd,
674 ADDBTN_HELPME, GetPString(IDS_ADDTOOLBUTTONIDTEXT));
675 break;
676
677 case ADDBTN_MYICON:
678 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
679 WinEnableWindow(WinWindowFromID(hwnd, ADDBTN_EDITBMP),
680 WinQueryButtonCheckstate(hwnd, ADDBTN_MYICON));
681 break;
682 }
683 return 0;
684
685 case WM_COMMAND:
686 switch (SHORT1FROMMP(mp1)) {
687 case DID_OK:
688 {
689 CHAR help[81], text[81], idstr[7];
690 BOOL invisible, dropable, separator, istext, myicon;
691 TOOL *tool;
692
693 WinQueryDlgItemText(hwnd, ADDBTN_HELP, 80, help);
694 WinQueryDlgItemText(hwnd, ADDBTN_TEXT, 80, text);
695 if (WinQueryButtonCheckstate(hwnd, ADDBTN_DROPABLE))
696 dropable = TRUE;
697 else
698 dropable = FALSE;
699 myicon = WinQueryButtonCheckstate(hwnd, ADDBTN_MYICON);
700 if (WinQueryButtonCheckstate(hwnd, ADDBTN_VISIBLE))
701 invisible = FALSE;
702 else
703 invisible = TRUE;
704 if (WinQueryButtonCheckstate(hwnd, ADDBTN_SEPARATOR))
705 separator = TRUE;
706 else
707 separator = FALSE;
708 if (WinQueryButtonCheckstate(hwnd, ADDBTN_SHOWTEXT))
709 istext = TRUE;
710 else
711 istext = FALSE;
712 tool = INSTDATA(hwnd);
713 if (tool) { /* just editing strings... */
714 istext = ((tool->flags & T_TEXT) != 0);
715 xfree(tool->help, pszSrcFile, __LINE__);
716 tool->help = NULL;
717 xfree(tool->text, pszSrcFile, __LINE__);
718 tool->text = NULL;
719 if (*help)
720 tool->help = xstrdup(help, pszSrcFile, __LINE__);
721 if (*text)
722 tool->text = xstrdup(text, pszSrcFile, __LINE__);
723 tool->flags = (((dropable) ? T_DROPABLE : 0) |
724 ((invisible) ? T_INVISIBLE : 0) |
725 ((separator) ? T_SEPARATOR : 0) |
726 ((myicon) ? T_MYICON : 0) | ((istext) ? T_TEXT : 0));
727 fToolsChanged = TRUE;
728 WinDismissDlg(hwnd, 1);
729 break;
730 }
731 *idstr = 0;
732 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
733 if (!(USHORT) atoi(idstr)) {
734 DosBeep(250, 100);
735 break;
736 }
737 tool = toolhead;
738 while (tool) {
739 if (tool->id == (USHORT) atoi(idstr) && tool != tool) {
740 saymsg(MB_ENTER,
741 hwnd,
742 GetPString(IDS_DUPLICATETEXT),
743 GetPString(IDS_TOOLIDEXISTS));
744 WinSetDlgItemText(hwnd, ADDBTN_ID, NullStr);
745 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ADDBTN_ID));
746 break;
747 }
748 tool = tool->next;
749 }
750 tool = xmallocz(sizeof(TOOL), pszSrcFile, __LINE__);
751 if (tool) {
752 if (*help)
753 tool->help = xstrdup(help, pszSrcFile, __LINE__);
754 if (*text)
755 tool->text = xstrdup(text, pszSrcFile, __LINE__);
756 tool->id = (USHORT) atoi(idstr);
757 tool->flags = (((dropable) ? T_DROPABLE : 0) |
758 ((invisible) ? T_INVISIBLE : 0) |
759 ((separator) ? T_SEPARATOR : 0) |
760 ((myicon) ? T_MYICON : 0) | ((istext) ? T_TEXT : 0));
761 add_tool(tool);
762 WinDismissDlg(hwnd, tool->id);
763 }
764 }
765 break;
766
767 case DID_CANCEL:
768 WinDismissDlg(hwnd, 0);
769 break;
770
771 case ADDBTN_EDITBMP:
772 {
773 CHAR idstr[6], filename[34];
774
775 *idstr = 0;
776 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
777 if (!(USHORT) atoi(idstr)) {
778 DosBeep(250, 100);
779 break;
780 }
781 sprintf(filename, "%u.BMP", atoi(idstr));
782 if (IsFile(filename) != 1) {
783 CHAR s[CCHMAXPATH] = "EMPTY.BMP";
784
785 docopyf(COPY, s, filename);
786 }
787 runemf2(SEPARATE | WINDOWED,
788 hwnd, pszSrcFile, __LINE__,
789 NULL, NULL, "ICONEDIT.EXE %s", filename);
790 }
791 break;
792
793 case IDM_HELP:
794 if (hwndHelp) {
795 if (INSTDATA(hwnd))
796 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
797 MPFROM2SHORT(HELP_CHANGEBUTTON, 0),
798 MPFROMSHORT(HM_RESOURCEID));
799 else
800 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
801 MPFROM2SHORT(HELP_ADDBUTTON, 0),
802 MPFROMSHORT(HM_RESOURCEID));
803 }
804 break;
805 }
806 return 0;
807 }
808 return WinDefDlgProc(hwnd, msg, mp1, mp2);
809}
810
811MRESULT EXPENTRY PickToolProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
812{
813 switch (msg) {
814 case WM_INITDLG:
815 if (mp2) {
816 CHAR s[133];
817
818 sprintf(s, GetPString(IDS_PICKTOOLTITLETEXT), (CHAR *)mp2);
819 WinSetWindowText(hwnd, s);
820 }
821 {
822 TOOL *tool;
823 CHAR s[133];
824
825 tool = toolhead;
826 while (tool) {
827 sprintf(s, "%-5u %s", tool->id, (tool->help) ? tool->help : "?");
828 WinSendDlgItemMsg(hwnd,
829 PICKBTN_LISTBOX,
830 LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(s));
831 tool = tool->next;
832 }
833 }
834 break;
835
836 case WM_CONTROL:
837 if (SHORT1FROMMP(mp1) == PICKBTN_LISTBOX) {
838 switch (SHORT2FROMMP(mp1)) {
839 case LN_ENTER:
840 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
841 break;
842 }
843 }
844 return 0;
845
846 case WM_COMMAND:
847 switch (SHORT1FROMMP(mp1)) {
848 case DID_CANCEL:
849 WinDismissDlg(hwnd, 0);
850 break;
851 case DID_OK:
852 {
853 SHORT sSelect;
854 CHAR s[33];
855
856 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, PICKBTN_LISTBOX,
857 LM_QUERYSELECTION,
858 MPFROMSHORT(LIT_FIRST), MPVOID);
859 if (sSelect >= 0) {
860 *s = 0;
861 WinSendDlgItemMsg(hwnd, PICKBTN_LISTBOX, LM_QUERYITEMTEXT,
862 MPFROM2SHORT(sSelect, 32), MPFROMP(s));
863 if (*s)
864 WinDismissDlg(hwnd, (USHORT) atoi(s));
865 }
866 }
867 break;
868 }
869 return 0;
870 }
871 return WinDefDlgProc(hwnd, msg, mp1, mp2);
872}
873
874MRESULT EXPENTRY ToolIODlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
875{
876 switch (msg) {
877 case WM_INITDLG:
878 if (mp2)
879 WinSetWindowULong(hwnd, QWL_USER, TRUE);
880 else {
881 WinSetWindowULong(hwnd, QWL_USER, FALSE);
882 WinSetWindowText(hwnd, GetPString(IDS_LOADTOOLBOXTITLETEXT));
883 }
884 WinSendDlgItemMsg(hwnd,
885 SVBTN_ENTRY,
886 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
887 {
888 FILEFINDBUF3 findbuf;
889 HDIR hDir;
890 ULONG ulSearchCount, x = 0;
891 CHAR *masks[] = { "*.TLS", "FM3TOOLS.DAT", NULL };
892
893 if (mp2)
894 masks[1] = NULL;
895 while (masks[x]) {
896 hDir = HDIR_CREATE;
897 ulSearchCount = 1;
898 DosError(FERR_DISABLEHARDERR);
899 if (!DosFindFirst(masks[x],
900 &hDir,
901 FILE_ARCHIVED,
902 &findbuf,
903 sizeof(FILEFINDBUF3),
904 &ulSearchCount, FIL_STANDARD)) {
905 do {
906 priority_bumped();
907 WinSendMsg(WinWindowFromID(hwnd,
908 SVBTN_LISTBOX),
909 LM_INSERTITEM,
910 MPFROM2SHORT(LIT_SORTASCENDING, 0),
911 MPFROMP(findbuf.achName));
912 ulSearchCount = 1;
913 } while (!DosFindNext(hDir,
914 &findbuf,
915 sizeof(FILEFINDBUF3), &ulSearchCount));
916 DosFindClose(hDir);
917 priority_bumped();
918 }
919 x++;
920 }
921 DosError(FERR_DISABLEHARDERR);
922 }
923 if (!WinSendDlgItemMsg(hwnd,
924 SVBTN_LISTBOX,
925 LM_QUERYITEMCOUNT, MPVOID, MPVOID)) {
926 WinEnableWindow(WinWindowFromID(hwnd, SVBTN_LISTBOX), FALSE);
927 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
928 }
929 WinSetDlgItemText(hwnd,
930 SVBTN_CURRENT,
931 (*lasttoolbox) ? lasttoolbox : "FM3TOOLS.DAT");
932 break;
933
934 case UM_SETUP:
935 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SVBTN_ENTRY));
936 return 0;
937
938 case WM_CONTROL:
939 if (SHORT1FROMMP(mp1) == SVBTN_LISTBOX) {
940 SHORT sSelect;
941 CHAR szBuffer[CCHMAXPATH];
942
943 switch (SHORT2FROMMP(mp1)) {
944 case LN_SELECT:
945 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, SVBTN_LISTBOX,
946 LM_QUERYSELECTION,
947 MPFROMSHORT(LIT_FIRST), MPVOID);
948 if (sSelect >= 0) {
949 *szBuffer = 0;
950 WinSendDlgItemMsg(hwnd, SVBTN_LISTBOX, LM_QUERYITEMTEXT,
951 MPFROM2SHORT(sSelect, CCHMAXPATH),
952 MPFROMP(szBuffer));
953 if (*szBuffer)
954 WinSetDlgItemText(hwnd, SVBTN_ENTRY, szBuffer);
955 }
956 break;
957
958 case LN_ENTER:
959 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
960 break;
961 }
962 }
963 return 0;
964
965 case WM_COMMAND:
966 switch (SHORT1FROMMP(mp1)) {
967 case IDM_HELP:
968 if (hwndHelp) {
969 if (INSTDATA(hwnd))
970 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
971 MPFROM2SHORT(HELP_SAVETOOLS, 0),
972 MPFROMSHORT(HM_RESOURCEID));
973 else
974 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
975 MPFROM2SHORT(HELP_LOADTOOLS, 0),
976 MPFROMSHORT(HM_RESOURCEID));
977 }
978 break;
979
980 case DID_CANCEL:
981 WinDismissDlg(hwnd, 0);
982 break;
983
984 case DID_OK:
985 {
986 BOOL saving = WinQueryWindowULong(hwnd, QWL_USER);
987 CHAR temptools[CCHMAXPATH];
988
989 strcpy(temptools, lasttoolbox);
990 if (fToolsChanged)
991 save_tools(NULL);
992 WinQueryDlgItemText(hwnd,
993 SVBTN_ENTRY, sizeof(lasttoolbox), lasttoolbox);
994 if (*lasttoolbox) {
995 if (!strchr(lasttoolbox, '.'))
996 strcat(lasttoolbox, ".TLS");
997 }
998 if (saving && *lasttoolbox)
999 save_tools(NULL);
1000 else {
1001 if (!load_tools(NULL)) {
1002 strcpy(lasttoolbox, temptools);
1003 if (!load_tools(NULL)) {
1004 *lasttoolbox = 0;
1005 load_tools(NULL);
1006 }
1007 }
1008 }
1009 PrfWriteProfileString(fmprof, FM3Str, "LastToolBox", lasttoolbox);
1010 }
1011 WinDismissDlg(hwnd, 1);
1012 break;
1013 }
1014 return 0;
1015 }
1016 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1017}
1018
1019#pragma alloc_text(TOOLS,load_tools,save_tools,add_tool,insert_tool,del_tool,free_tools,swap_tools,load_quicktools,save_quicktools)
1020#pragma alloc_text(TOOLS1,ReOrderToolsProc,PickToolProc,AddToolProc,ToolIODlgProc)
Note: See TracBrowser for help on using the repository browser.