source: trunk/dll/tools.c@ 1227

Last change on this file since 1227 was 1227, checked in by John Small, 17 years ago

Ticket 187: Moved typedef's and some #define's from fm3dll.h

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