source: trunk/dll/tools.c@ 1486

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

Initial changes to commands handling. Allows you to reorder commands menu without breaking toolbars and changing hotkeys. Fixes the environment so it is used and so it is deleted if the command is deleted. Allows for user defined bitmaps in toolbars which are named based on the text or the the ID of the command.The new commands.dat will not be usable with earlier versions of FM/2

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.5 KB
Line 
1
2/***********************************************************************
3
4 $Id: tools.c 1486 2009-12-17 00:36:04Z 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 CHAR text[CCHMAXPATH];
672
673 *idstr = 0;
674 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
675 WinQueryDlgItemText(hwnd, ADDBTN_TEXT,CCHMAXPATH - 1, text);
676 id = atoi(idstr);
677 if (id) {
678 hps = WinGetPS(WinWindowFromID(hwnd, ADDBTN_BMP));
679 if (!WinQueryButtonCheckstate(hwnd, ADDBTN_MYICON))
680 hbm = GpiLoadBitmap(hps, 0, id, 28, 28);
681 if (!hbm)
682 hbm = LoadBitmapFromFileIdentifier(id, text);
683 if (hbm) {
684 hbmd = (HBITMAP) WinSendDlgItemMsg(hwnd, ADDBTN_BMP, SM_QUERYHANDLE,
685 MPVOID, MPVOID);
686 hbmdd = (HBITMAP) WinSendDlgItemMsg(hwnd, ADDBTN_BMP, SM_SETHANDLE,
687 MPFROMLONG(hbm), MPVOID);
688 if (hbmdd && hbmd && hbmd != hbmdd)
689 GpiDeleteBitmap(hbmd);
690 }
691 }
692 }
693 return 0;
694
695 case WM_CONTROL:
696 switch (SHORT1FROMMP(mp1)) {
697 case ADDBTN_HELP:
698 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
699 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
700 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
701 WinSetDlgItemText(hwnd, ADDBTN_HELPME,
702 GetPString(IDS_ADDTOOLQUICKHELPTEXT));
703 break;
704
705 case ADDBTN_TEXT:
706 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
707 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
708 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
709 WinSetDlgItemText(hwnd, ADDBTN_HELPME,
710 GetPString(IDS_ADDTOOLBUTTONTEXT));
711 break;
712
713 case ADDBTN_ID:
714 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) {
715 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
716 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
717 }
718 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
719 WinSetDlgItemText(hwnd,
720 ADDBTN_HELPME, GetPString(IDS_ADDTOOLBUTTONIDTEXT));
721 break;
722
723 case ADDBTN_MYICON:
724 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
725 WinEnableWindow(WinWindowFromID(hwnd, ADDBTN_EDITBMP),
726 WinQueryButtonCheckstate(hwnd, ADDBTN_MYICON));
727 break;
728 }
729 return 0;
730
731 case WM_COMMAND:
732 switch (SHORT1FROMMP(mp1)) {
733 case DID_OK:
734 {
735 CHAR help[81], text[81], idstr[7];
736 BOOL invisible, dropable, separator, istext, myicon;
737 TOOL *tool;
738 BOOL BadID = FALSE;
739
740 help[0] = text[0] = 0;
741 WinQueryDlgItemText(hwnd, ADDBTN_HELP, 80, help);
742 WinQueryDlgItemText(hwnd, ADDBTN_TEXT, 80, text);
743 if (WinQueryButtonCheckstate(hwnd, ADDBTN_DROPABLE))
744 dropable = TRUE;
745 else
746 dropable = FALSE;
747 myicon = WinQueryButtonCheckstate(hwnd, ADDBTN_MYICON);
748 if (WinQueryButtonCheckstate(hwnd, ADDBTN_VISIBLE))
749 invisible = FALSE;
750 else
751 invisible = TRUE;
752 if (WinQueryButtonCheckstate(hwnd, ADDBTN_SEPARATOR))
753 separator = TRUE;
754 else
755 separator = FALSE;
756 if (WinQueryButtonCheckstate(hwnd, ADDBTN_SHOWTEXT))
757 istext = TRUE;
758 else
759 istext = FALSE;
760 tool = INSTDATA(hwnd);
761 if (tool) { /* just editing strings... */
762 istext = ((tool->flags & T_TEXT) != 0);
763 xfree(tool->help, pszSrcFile, __LINE__);
764 tool->help = NULL;
765 xfree(tool->text, pszSrcFile, __LINE__);
766 tool->text = NULL;
767 if (*help && *text && help && text) {
768 tool->help = xstrdup(help, pszSrcFile, __LINE__);
769 tool->text = xstrdup(text, pszSrcFile, __LINE__);
770 }
771 else {
772 saymsg(MB_ENTER,
773 hwnd,
774 GetPString(IDS_MISSINGTEXT),
775 GetPString(IDS_TOOLHELPTEXTBLANK));
776 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ADDBTN_HELP));
777 break;
778 }
779 tool->flags = (((dropable) ? T_DROPABLE : 0) |
780 ((invisible) ? T_INVISIBLE : 0) |
781 ((separator) ? T_SEPARATOR : 0) |
782 ((myicon) ? T_MYICON : 0) | ((istext) ? T_TEXT : 0));
783 save_tools(NULL);
784 WinDismissDlg(hwnd, 1);
785 break;
786 }
787 *idstr = 0;
788 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
789 if (!(USHORT) atoi(idstr)) {
790 if (!fAlertBeepOff)
791 DosBeep(250, 100);
792 break;
793 }
794 tool = toolhead;
795 while (tool) {
796 if (tool->id == (USHORT) atoi(idstr)) { // && tool != tool) {
797 saymsg(MB_ENTER,
798 hwnd,
799 GetPString(IDS_DUPLICATETEXT),
800 GetPString(IDS_TOOLIDEXISTS));
801 WinSetDlgItemText(hwnd, ADDBTN_ID, NullStr);
802 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ADDBTN_ID));
803 BadID =TRUE;
804 break;
805 }
806 tool = tool->next;
807 }
808 if (BadID)
809 break;
810 tool = xmallocz(sizeof(TOOL), pszSrcFile, __LINE__);
811 if (tool) {
812 if (*help)
813 tool->help = xstrdup(help, pszSrcFile, __LINE__);
814 if (*text)
815 tool->text = xstrdup(text, pszSrcFile, __LINE__);
816 tool->id = (USHORT) atoi(idstr);
817 tool->flags = (((dropable) ? T_DROPABLE : 0) |
818 ((invisible) ? T_INVISIBLE : 0) |
819 ((separator) ? T_SEPARATOR : 0) |
820 ((myicon) ? T_MYICON : 0) | ((istext) ? T_TEXT : 0));
821 add_tool(tool);
822 save_tools(NULL);
823 WinDismissDlg(hwnd, tool->id);
824 }
825 }
826 break;
827
828 case DID_CANCEL:
829 WinDismissDlg(hwnd, 0);
830 break;
831
832 case ADDBTN_EDITBMP:
833 {
834 CHAR idstr[6], filename[34];
835
836 *idstr = 0;
837 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
838 if (!(USHORT) atoi(idstr)) {
839 if (!fAlertBeepOff)
840 DosBeep(250, 100);
841 break;
842 }
843 sprintf(filename, "%u.BMP", atoi(idstr));
844 if (IsFile(filename) != 1) {
845 CHAR s[CCHMAXPATH] = "EMPTY.BMP";
846
847 docopyf(COPY, s, filename);
848 }
849 runemf2(SEPARATE | WINDOWED,
850 hwnd, pszSrcFile, __LINE__,
851 NULL, NULL, "ICONEDIT.EXE %s", filename);
852 }
853 break;
854
855 case IDM_HELP:
856 if (hwndHelp) {
857 if (INSTDATA(hwnd))
858 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
859 MPFROM2SHORT(HELP_CHANGEBUTTON, 0),
860 MPFROMSHORT(HM_RESOURCEID));
861 else
862 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
863 MPFROM2SHORT(HELP_ADDBUTTON, 0),
864 MPFROMSHORT(HM_RESOURCEID));
865 }
866 break;
867 }
868 return 0;
869 }
870 return WinDefDlgProc(hwnd, msg, mp1, mp2);
871}
872
873MRESULT EXPENTRY PickToolProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
874{
875 switch (msg) {
876 case WM_INITDLG:
877 if (mp2) {
878 CHAR s[133];
879
880 sprintf(s, GetPString(IDS_PICKTOOLTITLETEXT), (CHAR *)mp2);
881 WinSetWindowText(hwnd, s);
882 }
883 {
884 TOOL *tool;
885 CHAR s[133];
886
887 tool = toolhead;
888 while (tool) {
889 sprintf(s, "%-5u %s", tool->id, (tool->help) ? tool->help : "?");
890 WinSendDlgItemMsg(hwnd,
891 PICKBTN_LISTBOX,
892 LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(s));
893 tool = tool->next;
894 }
895 }
896 break;
897
898 case WM_CONTROL:
899 if (SHORT1FROMMP(mp1) == PICKBTN_LISTBOX) {
900 switch (SHORT2FROMMP(mp1)) {
901 case LN_ENTER:
902 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
903 break;
904 }
905 }
906 return 0;
907
908 case WM_COMMAND:
909 switch (SHORT1FROMMP(mp1)) {
910 case DID_CANCEL:
911 WinDismissDlg(hwnd, 0);
912 break;
913 case DID_OK:
914 {
915 SHORT sSelect;
916 CHAR s[33];
917
918 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, PICKBTN_LISTBOX,
919 LM_QUERYSELECTION,
920 MPFROMSHORT(LIT_FIRST), MPVOID);
921 if (sSelect >= 0) {
922 *s = 0;
923 WinSendDlgItemMsg(hwnd, PICKBTN_LISTBOX, LM_QUERYITEMTEXT,
924 MPFROM2SHORT(sSelect, 32), MPFROMP(s));
925 if (*s)
926 WinDismissDlg(hwnd, (USHORT) atoi(s));
927 }
928 }
929 break;
930 }
931 return 0;
932 }
933 return WinDefDlgProc(hwnd, msg, mp1, mp2);
934}
935
936MRESULT EXPENTRY ToolIODlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
937{
938 switch (msg) {
939 case WM_INITDLG:
940 if (mp2)
941 WinSetWindowULong(hwnd, QWL_USER, TRUE);
942 else {
943 WinSetWindowULong(hwnd, QWL_USER, FALSE);
944 WinSetWindowText(hwnd, GetPString(IDS_LOADTOOLBARTITLETEXT));
945 }
946 WinSendDlgItemMsg(hwnd,
947 SVBTN_ENTRY,
948 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
949 {
950 FILEFINDBUF3 findbuf;
951 HDIR hDir;
952 ULONG ulSearchCount, x = 0;
953 CHAR *masks[] = { "*.TLS", "FM3TOOLS.DAT", NULL };
954
955 if (mp2)
956 masks[1] = NULL;
957 while (masks[x]) {
958 hDir = HDIR_CREATE;
959 ulSearchCount = 1;
960 DosError(FERR_DISABLEHARDERR);
961 if (!DosFindFirst(masks[x],
962 &hDir,
963 FILE_ARCHIVED,
964 &findbuf,
965 sizeof(FILEFINDBUF3),
966 &ulSearchCount, FIL_STANDARD)) {
967 do {
968 priority_bumped();
969 WinSendMsg(WinWindowFromID(hwnd,
970 SVBTN_LISTBOX),
971 LM_INSERTITEM,
972 MPFROM2SHORT(LIT_SORTASCENDING, 0),
973 MPFROMP(findbuf.achName));
974 ulSearchCount = 1;
975 } while (!DosFindNext(hDir,
976 &findbuf,
977 sizeof(FILEFINDBUF3), &ulSearchCount));
978 DosFindClose(hDir);
979 priority_bumped();
980 }
981 x++;
982 }
983 DosError(FERR_DISABLEHARDERR);
984 }
985 if (!WinSendDlgItemMsg(hwnd,
986 SVBTN_LISTBOX,
987 LM_QUERYITEMCOUNT, MPVOID, MPVOID)) {
988 WinEnableWindow(WinWindowFromID(hwnd, SVBTN_LISTBOX), FALSE);
989 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
990 }
991 WinSetDlgItemText(hwnd,
992 SVBTN_CURRENT,
993 (*lasttoolbar) ? lasttoolbar : PCSZ_FM3TOOLSDAT);
994 break;
995
996 case UM_SETUP:
997 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SVBTN_ENTRY));
998 return 0;
999
1000 case WM_CONTROL:
1001 if (SHORT1FROMMP(mp1) == SVBTN_LISTBOX) {
1002 SHORT sSelect;
1003 CHAR szBuffer[CCHMAXPATH];
1004
1005 switch (SHORT2FROMMP(mp1)) {
1006 case LN_SELECT:
1007 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, SVBTN_LISTBOX,
1008 LM_QUERYSELECTION,
1009 MPFROMSHORT(LIT_FIRST), MPVOID);
1010 if (sSelect >= 0) {
1011 *szBuffer = 0;
1012 WinSendDlgItemMsg(hwnd, SVBTN_LISTBOX, LM_QUERYITEMTEXT,
1013 MPFROM2SHORT(sSelect, CCHMAXPATH),
1014 MPFROMP(szBuffer));
1015 if (*szBuffer)
1016 WinSetDlgItemText(hwnd, SVBTN_ENTRY, szBuffer);
1017 }
1018 break;
1019
1020 case LN_ENTER:
1021 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
1022 break;
1023 }
1024 }
1025 return 0;
1026
1027 case WM_COMMAND:
1028 switch (SHORT1FROMMP(mp1)) {
1029 case IDM_HELP:
1030 if (hwndHelp) {
1031 if (INSTDATA(hwnd))
1032 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
1033 MPFROM2SHORT(HELP_SAVETOOLS, 0),
1034 MPFROMSHORT(HM_RESOURCEID));
1035 else
1036 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
1037 MPFROM2SHORT(HELP_LOADTOOLS, 0),
1038 MPFROMSHORT(HM_RESOURCEID));
1039 }
1040 break;
1041
1042 case DID_CANCEL:
1043 WinDismissDlg(hwnd, 0);
1044 break;
1045
1046 case DID_OK:
1047 {
1048 BOOL saving = WinQueryWindowULong(hwnd, QWL_USER);
1049 CHAR temptools[CCHMAXPATH];
1050
1051 strcpy(temptools, lasttoolbar);
1052 if (fToolsChanged)
1053 save_tools(NULL);
1054 WinQueryDlgItemText(hwnd,
1055 SVBTN_ENTRY, sizeof(lasttoolbar), lasttoolbar);
1056 if (*lasttoolbar) {
1057 if (!strchr(lasttoolbar, '.'))
1058 strcat(lasttoolbar, PCSZ_DOTTLS);
1059 }
1060 if (saving && *lasttoolbar)
1061 save_tools(NULL);
1062 else {
1063 if (!load_tools(NULL)) {
1064 strcpy(lasttoolbar, temptools);
1065 if (!load_tools(NULL)) {
1066 *lasttoolbar = 0;
1067 load_tools(NULL);
1068 }
1069 }
1070 }
1071 PrfWriteProfileString(fmprof, FM3Str, "LastToolbar", lasttoolbar);
1072 }
1073 WinDismissDlg(hwnd, 1);
1074 break;
1075 }
1076 return 0;
1077 }
1078 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1079}
1080
1081#pragma alloc_text(TOOLS,load_tools,save_tools,add_tool,insert_tool,del_tool,free_tools,swap_tools)
1082#pragma alloc_text(TOOLS,load_quicktools,save_quicktools)
1083#pragma alloc_text(TOOLS1,ReOrderToolsProc,PickToolProc,AddToolProc,ToolIODlgProc)
Note: See TracBrowser for help on using the repository browser.