source: trunk/dll/tools.c@ 1505

Last change on this file since 1505 was 1505, checked in by Gregg Young, 15 years ago

Remove unnecessary type casts; minor formating cleanup.

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