source: trunk/dll/tools.c@ 1140

Last change on this file since 1140 was 1140, checked in by Gregg Young, 17 years ago

Comments added for recent changes

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