source: trunk/dll/tools.c@ 1009

Last change on this file since 1009 was 1009, checked in by Steven Levine, 17 years ago

Add xfree xstrdup Fortify support
Add MT capable Fortify scope logic

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