source: trunk/dll/tools.c@ 1402

Last change on this file since 1402 was 1402, checked in by Gregg Young, 16 years ago

Remove variable aurgs from docopy & unlinkf (not used); Move more strings to PCSZs and string table; Move PCSZs to compile time initialization; Fix hang on startup caused by a drive scan and a dircnr scan trying to update a drive in the tree at the same time (related to the "treeswitch options); Code cleanup mainly removal of old printfs, SayMsgs, DbgMsg and unneeded %s.

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