source: trunk/dll/tools.c@ 1213

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

Ticket 187: Move data declarations/definitions out of fm3dll.h

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