source: trunk/dll/tools.c@ 1673

Last change on this file since 1673 was 1673, checked in by Gregg Young, 13 years ago

Update to Doxygen comment style Ticket 55. Also some minor code cleanup.

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