source: trunk/dll/tools.c

Last change on this file was 1750, checked in by John Small, 11 years ago

Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.

So calls to these functions, direct and indirect, had to be changed.

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