source: trunk/dll/tools.c@ 1544

Last change on this file since 1544 was 1544, checked in by Gregg Young, 15 years ago

Changes to fopen and _fsopen to allow FM2 to be loaded in high memory

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.8 KB
RevLine 
[2]1
[123]2/***********************************************************************
3
4 $Id: tools.c 1544 2010-09-30 13:00:59Z gyoung $
5
[329]6 Toolbar support routines
[123]7
8 Copyright (c) 1994-97 M. Kimes
[1498]9 Copyright (c) 2004, 2010 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
[1082]20 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
[1119]21 24 Aug 08 GKY Warn full drive on save of .DAT & .TLS files; prevent loss of existing file
[1121]22 26 Aug 08 GKY Require unique ID plus text and help strings for all tools save toolbar on button delete
[1140]23 01 Sep 08 GKY Save toolbars immediately on change.
[1395]24 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
[1402]25 08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
[1498]26 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
[123]27
28***********************************************************************/
29
[907]30#include <stdlib.h>
31#include <string.h>
32#include <share.h>
33
[2]34#define INCL_DOS
35#define INCL_WIN
[841]36#define INCL_LONGLONG
[2]37
[1184]38#include "fm3dll.h"
[1227]39#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
40#include "tools.h"
[1213]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)
[2]45#include "fm3dlg.h"
46#include "fm3str.h"
[907]47#include "errutil.h" // Dos_Error...
48#include "strutil.h" // GetPString
[1082]49#include "pathutil.h" // BldFullPathName
[1079]50#include "fortify.h"
[1160]51#include "loadbmp.h" // LoadBitmapFromFileNum
[1184]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
[2]62
[1213]63// Data definitions
[2]64#pragma data_seg(DATA1)
[329]65
66static PSZ pszSrcFile = __FILE__;
67
[1213]68#pragma data_seg(GLOBAL1)
69BOOL fToolsChanged;
[2]70TOOL *toolhead = NULL;
71
[1213]72#pragma data_seg(GLOBAL2)
73CHAR lasttoolbar[CCHMAXPATH];
74BOOL qtloaded;
75CHAR *quicktool[50];
76
[440]77//== load_quicktools() build *.tls array ==
[2]78
[440]79VOID load_quicktools(VOID)
80{
[551]81 FILE *fp;
82 CHAR s[CCHMAXPATH + 14];
83 INT x;
[1544]84 CHAR *moder = "r";
[2]85
86 qtloaded = TRUE;
[440]87 for (x = 0; x < 50 && quicktool[x]; x++) {
[1039]88 free(quicktool[x]);
[2]89 quicktool[x] = NULL;
90 }
[440]91 if (!fToolbar) {
[2]92 qtloaded = FALSE;
93 return;
94 }
[1398]95 BldFullPathName(s, pFM2SaveDirectory, PCSZ_QUICKTLSDAT);
[1544]96 fp = xfsopen(s, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
[329]97 if (fp) {
[440]98 x = 0;
99 while (!feof(fp)) {
[551]100 if (!xfgets_bstripcr(s, CCHMAXPATH + 2, fp, pszSrcFile, __LINE__))
101 break;
[440]102 if (!*s || *s == ';')
[551]103 continue;
[440]104 if (x >= 50) {
105 Runtime_Error(pszSrcFile, __LINE__, "add");
106 break;
[2]107 }
[551]108 quicktool[x] = xstrdup(s, pszSrcFile, __LINE__);
[440]109 if (!quicktool[x])
[551]110 break;
[440]111 x++;
[2]112 }
113 fclose(fp);
114 }
115}
116
[440]117VOID save_quicktools(VOID)
118{
[2]119 FILE *fp;
[551]120 INT x = 0;
121 CHAR s[CCHMAXPATH + 14];
[1544]122 CHAR *modew = "w";
[2]123
[487]124 if (!quicktool[0])
[2]125 return;
[1398]126 BldFullPathName(s, pFM2SaveDirectory, PCSZ_QUICKTLSDAT);
[1118]127 if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2)
[1117]128 return; //already gave error msg
[1544]129 fp = xfopen(s, modew, pszSrcFile, __LINE__, FALSE);
[329]130 if (fp) {
[551]131 for (x = 0; quicktool[x] && x < 50; x++)
132 fprintf(fp, "%s\n", quicktool[x]);
[2]133 fclose(fp);
134 }
135}
136
[440]137//== load_tools() Build tools list given .tls filename ==
[2]138
[551]139TOOL *load_tools(CHAR * filename)
[440]140{
[551]141 FILE *fp;
142 CHAR help[80], text[80], flagstr[80], idstr[80], *fname;
143 TOOL *info;
[1544]144 CHAR *moder = "r";
[2]145
[487]146 if (!fToolbar) {
[2]147 toolhead = free_tools();
148 return toolhead;
149 }
[551]150 if (!filename || !*filename)
[1122]151 filename = (*lasttoolbar) ? lasttoolbar : "CMDS.TLS";
[487]152 if (*filename)
[2]153 fname = searchpath(filename);
[551]154 if (!fname || !*fname)
[1398]155 fname = (PSZ) PCSZ_FM3TOOLSDAT;
[551]156 if (fname && *fname) {
[2]157 filename = fname;
[1122]158 strcpy(lasttoolbar, filename);
[1544]159 fp = xfsopen(filename, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
[329]160 if (fp) {
[2]161 toolhead = free_tools();
[487]162 while (!feof(fp)) {
[551]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) {
[1079]179# ifdef FORTIFY
180 Fortify_SetOwner(info, 1);
181 Fortify_SetScope(info, 1);
182# endif
[551]183 if (*help) {
184 literal(help);
[1079]185 if (*help) {
[551]186 info->help = xstrdup(help, pszSrcFile, __LINE__);
[1079]187# ifdef FORTIFY
188 Fortify_SetOwner(info->help, 1);
189 Fortify_SetScope(info->help, 1);
190# endif
191 }
[551]192 }
[1079]193 if (*text) {
[551]194 info->text = xstrdup(text, pszSrcFile, __LINE__);
[1079]195# ifdef FORTIFY
196 Fortify_SetOwner(info->text, 1);
197 Fortify_SetScope(info->text, 1);
198# endif
199 }
[551]200 info->flags = (atoi(flagstr) & (~(T_TEXT | T_EMPHASIZED)));
201 info->id = (USHORT) atoi(idstr);
202 info->next = NULL;
203 add_tool(info);
204 }
[2]205 }
206 fclose(fp);
207 fToolsChanged = FALSE;
208 }
209 }
210 return toolhead;
211}
212
[551]213VOID save_tools(CHAR * filename)
[440]214{
[551]215 FILE *fp;
216 CHAR *fname;
217 TOOL *info;
[1544]218 CHAR *modew = "w";
[2]219
[487]220 if (!filename)
[1122]221 filename = lasttoolbar;
[487]222 if (*filename)
[2]223 fname = searchpath(filename);
[487]224 if (fname && *fname)
[2]225 filename = fname;
226 else {
[1122]227 if (*lasttoolbar)
228 filename = lasttoolbar;
[2]229 else
230 filename = "FM3TOOLS.TLS";
231 fname = searchpath(filename);
[487]232 if (fname && *fname)
[2]233 filename = fname;
234 }
235
[1398]236 if (stristr(filename, PCSZ_FM3TOOLSDAT))
[2]237 filename = "FM3TOOLS.TLS";
[487]238 if (toolhead && filename && *filename) {
[1122]239 strcpy(lasttoolbar, filename);
[1505]240 PrfWriteProfileString(fmprof, FM3Str, "LastToolbar", filename);
[2]241 }
[487]242 if (!toolhead) {
[1402]243 unlinkf(filename);
[2]244 return;
245 }
[1118]246 if (CheckDriveSpaceAvail(filename, ullDATFileSpaceNeeded, 1) == 2)
[1117]247 return; //already gave error msg
[1544]248 fp = xfopen(filename, modew, pszSrcFile, __LINE__, FALSE);
[329]249 if (fp) {
[551]250 fprintf(fp, GetPString(IDS_TOOLFILETEXT), filename);
[2]251 info = toolhead;
[487]252 while (info) {
[2]253 fprintf(fp,
[551]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);
[2]258 info = info->next;
259 }
260 fclose(fp);
261 fToolsChanged = FALSE;
262 }
[487]263 if (hwndMain)
[551]264 PostMsg(hwndMain, UM_FILLBUTTONLIST, MPVOID, MPVOID);
[2]265}
266
[551]267TOOL *add_tool(TOOL * tool)
[440]268{
[2]269 TOOL *info;
270
[487]271 if (tool) {
[2]272 info = toolhead;
[487]273 if (info) {
274 while (info->next)
[551]275 info = info->next;
[2]276 }
[487]277 if (info)
[2]278 info->next = tool;
279 else
280 toolhead = tool;
281 fToolsChanged = TRUE;
282 }
283 return toolhead;
284}
285
[551]286TOOL *insert_tool(TOOL * tool, TOOL * after)
[440]287{
[487]288 if (tool) {
289 if (!toolhead)
[2]290 return add_tool(tool);
[487]291 if (!after) {
[2]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
[551]305TOOL *del_tool(TOOL * tool)
[440]306{
[551]307 TOOL *info, *prev = NULL;
[2]308
[487]309 if (tool) {
[2]310 info = toolhead;
[487]311 while (info) {
312 if (info == tool) {
[551]313 if (info == toolhead)
314 toolhead = info->next;
315 if (prev)
316 prev->next = info->next;
[1009]317 xfree(info->help, pszSrcFile, __LINE__);
318 xfree(info->text, pszSrcFile, __LINE__);
[1039]319 free(info);
[551]320 fToolsChanged = TRUE;
321 break;
[2]322 }
323 prev = info;
324 info = info->next;
325 }
326 }
327 return toolhead;
328}
329
[440]330TOOL *find_tool(USHORT id)
331{
[2]332 TOOL *tool;
333
[487]334 if (id) {
[2]335 tool = toolhead;
[487]336 while (tool) {
337 if (id && tool->id == id)
[551]338 return tool;
[2]339 tool = tool->next;
340 }
341 }
342 return NULL;
343}
344
[551]345TOOL *next_tool(TOOL * tool, BOOL skipinvisible)
[440]346{
[487]347 while (tool) {
348 if (tool->next && (skipinvisible && (tool->next->flags & T_INVISIBLE)))
[2]349 tool = tool->next;
350 else
351 return (tool->next) ? tool->next : toolhead;
352 }
353 return NULL;
354}
355
[551]356TOOL *prev_tool(TOOL * tool, BOOL skipinvisible)
[440]357{
[2]358 TOOL *info;
359
360Again:
[487]361 while (tool) {
[2]362 info = toolhead;
[487]363 while (info) {
364 if (info->next == tool) {
[551]365 if (skipinvisible && (info->flags & T_INVISIBLE)) {
366 tool = info;
367 goto Again;
368 }
369 return info;
[2]370 }
[487]371 if (!info->next && tool == toolhead)
[551]372 return info;
[2]373 info = info->next;
374 }
375 return toolhead;
376 }
377 return NULL;
378}
379
[551]380TOOL *swap_tools(TOOL * tool1, TOOL * tool2)
[440]381{
[551]382 TOOL *prev1 = NULL, *prev2 = NULL, *info;
[2]383
[487]384 if (tool1 && tool2 && tool1 != tool2) {
[2]385 info = toolhead;
[487]386 while (info && !prev1 && !prev2) {
387 if (info->next == tool1)
[551]388 prev1 = info;
[487]389 else if (info->next == tool2)
[551]390 prev2 = info;
[2]391 info = info->next;
392 }
393 info = tool2;
394 tool2 = tool1;
395 tool1 = info;
396 info = tool2->next;
[487]397 if (prev1)
[2]398 prev1->next = tool2;
[487]399 if (prev2)
[2]400 prev2->next = tool1;
401 tool2->next = tool1->next;
402 tool1->next = info;
403 fToolsChanged = TRUE;
404 }
405 return toolhead;
406}
407
[440]408TOOL *free_tools(VOID)
409{
[551]410 TOOL *tool, *next;
[2]411
412 tool = toolhead;
[487]413 while (tool) {
[2]414 next = tool->next;
[1009]415 xfree(tool->help, pszSrcFile, __LINE__);
416 xfree(tool->text, pszSrcFile, __LINE__);
[1039]417 free(tool);
[2]418 tool = next;
419 }
420 toolhead = NULL;
421 return toolhead;
422}
423
[551]424MRESULT EXPENTRY ReOrderToolsProc(HWND hwnd, ULONG msg, MPARAM mp1,
425 MPARAM mp2)
[440]426{
[487]427 switch (msg) {
[551]428 case WM_INITDLG:
429 if (!toolhead || !toolhead->next)
430 WinDismissDlg(hwnd, 0);
[1498]431 WinSetWindowText(hwnd, (CHAR *) GetPString(IDS_RETOOLTEXT));
[551]432 {
433 TOOL *tool;
434 CHAR s[133];
435 SHORT sSelect;
[2]436
[551]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;
[2]450 }
[551]451 }
452 break;
[2]453
[551]454 case WM_CONTROL:
455 return 0;
[2]456
[551]457 case WM_COMMAND:
458 switch (SHORT1FROMMP(mp1)) {
459 case DID_CANCEL:
460 WinDismissDlg(hwnd, 0);
461 break;
[2]462
[551]463 case DID_OK:
464 {
465 TOOL *tool, *thead = NULL, *last = NULL;
466 SHORT sSelect = 0, numitems;
[2]467
[551]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 }
[1131]505 save_tools(NULL);
[551]506 WinDismissDlg(hwnd, 1);
507 break;
[2]508
[551]509 case IDM_HELP:
510 if (hwndHelp)
511 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
512 MPFROM2SHORT(HELP_REORDERBUTTONS, 0),
513 MPFROMSHORT(HM_RESOURCEID));
514 break;
[2]515
[551]516 case RE_ADD:
517 {
518 SHORT sSelect, sSelect2;
519 CHAR s[133];
520 TOOL *tool;
[2]521
[551]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;
[2]561
[551]562 case RE_REMOVE:
563 {
564 SHORT sSelect, sSelect2;
565 CHAR s[133];
566 TOOL *tool;
[2]567
[551]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 }
[2]605 }
[551]606 break;
607 }
608 return 0;
[2]609 }
[551]610 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]611}
612
[551]613MRESULT EXPENTRY AddToolProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[440]614{
[487]615 switch (msg) {
[551]616 case WM_INITDLG:
617 WinSetWindowPtr(hwnd, QWL_USER, mp2);
618 if (mp2) {
[1498]619 WinSetWindowText(hwnd, (CHAR *) GetPString(IDS_EDITTOOLTEXT));
[551]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];
[2]634
[551]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;
[2]658
[551]659 case WM_ADJUSTWINDOWPOS:
660 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
661 break;
[2]662
[551]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;
[2]669
[551]670 case UM_SETUP:
671 {
672 HBITMAP hbm = (HBITMAP) 0, hbmd, hbmdd;
673 HPS hps;
674 CHAR idstr[7];
675 USHORT id;
[1486]676 CHAR text[CCHMAXPATH];
[2]677
[551]678 *idstr = 0;
679 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
[1486]680 WinQueryDlgItemText(hwnd, ADDBTN_TEXT,CCHMAXPATH - 1, text);
[551]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)
[1486]687 hbm = LoadBitmapFromFileIdentifier(id, text);
[551]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 }
[2]696 }
[551]697 }
698 return 0;
[2]699
[551]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,
[1498]707 (CHAR *) GetPString(IDS_ADDTOOLQUICKHELPTEXT));
[551]708 break;
[2]709
[551]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,
[1498]715 (CHAR *) GetPString(IDS_ADDTOOLBUTTONTEXT));
[551]716 break;
[2]717
[551]718 case ADDBTN_ID:
719 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) {
720 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
721 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
[2]722 }
[551]723 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
724 WinSetDlgItemText(hwnd,
[1498]725 ADDBTN_HELPME, (CHAR *) GetPString(IDS_ADDTOOLBUTTONIDTEXT));
[551]726 break;
[2]727
[551]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;
[2]735
[551]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;
[1121]742 TOOL *tool;
743 BOOL BadID = FALSE;
[2]744
[1435]745 help[0] = text[0] = 0;
[551]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);
[1009]768 xfree(tool->help, pszSrcFile, __LINE__);
[551]769 tool->help = NULL;
[1009]770 xfree(tool->text, pszSrcFile, __LINE__);
[551]771 tool->text = NULL;
[1121]772 if (*help && *text && help && text) {
[551]773 tool->help = xstrdup(help, pszSrcFile, __LINE__);
[1121]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 }
[551]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));
[1131]788 save_tools(NULL);
[551]789 WinDismissDlg(hwnd, 1);
790 break;
791 }
792 *idstr = 0;
793 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
794 if (!(USHORT) atoi(idstr)) {
[1395]795 if (!fAlertBeepOff)
796 DosBeep(250, 100);
[551]797 break;
798 }
799 tool = toolhead;
800 while (tool) {
[1121]801 if (tool->id == (USHORT) atoi(idstr)) { // && tool != tool) {
[551]802 saymsg(MB_ENTER,
803 hwnd,
804 GetPString(IDS_DUPLICATETEXT),
805 GetPString(IDS_TOOLIDEXISTS));
806 WinSetDlgItemText(hwnd, ADDBTN_ID, NullStr);
[1121]807 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ADDBTN_ID));
808 BadID =TRUE;
[551]809 break;
810 }
811 tool = tool->next;
[1121]812 }
813 if (BadID)
814 break;
[551]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));
[1108]826 add_tool(tool);
827 save_tools(NULL);
[551]828 WinDismissDlg(hwnd, tool->id);
829 }
830 }
831 break;
[2]832
[551]833 case DID_CANCEL:
834 WinDismissDlg(hwnd, 0);
835 break;
[2]836
[551]837 case ADDBTN_EDITBMP:
838 {
839 CHAR idstr[6], filename[34];
[2]840
[551]841 *idstr = 0;
842 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
843 if (!(USHORT) atoi(idstr)) {
[1395]844 if (!fAlertBeepOff)
845 DosBeep(250, 100);
[551]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,
[888]855 hwnd, pszSrcFile, __LINE__,
856 NULL, NULL, "ICONEDIT.EXE %s", filename);
[2]857 }
[551]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;
[2]874 }
[551]875 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]876}
877
[551]878MRESULT EXPENTRY PickToolProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[440]879{
[487]880 switch (msg) {
[551]881 case WM_INITDLG:
882 if (mp2) {
883 CHAR s[133];
[2]884
[1009]885 sprintf(s, GetPString(IDS_PICKTOOLTITLETEXT), (CHAR *)mp2);
[551]886 WinSetWindowText(hwnd, s);
887 }
888 {
889 TOOL *tool;
890 CHAR s[133];
[2]891
[551]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;
[2]899 }
[551]900 }
901 break;
[2]902
[551]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;
[2]909 }
[551]910 }
911 return 0;
[2]912
[551]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];
[2]922
[551]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 }
[2]933 }
[551]934 break;
935 }
936 return 0;
[2]937 }
[551]938 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]939}
940
[551]941MRESULT EXPENTRY ToolIODlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[440]942{
[487]943 switch (msg) {
[551]944 case WM_INITDLG:
945 if (mp2)
946 WinSetWindowULong(hwnd, QWL_USER, TRUE);
947 else {
948 WinSetWindowULong(hwnd, QWL_USER, FALSE);
[1498]949 WinSetWindowText(hwnd, (CHAR *) GetPString(IDS_LOADTOOLBARTITLETEXT));
[551]950 }
951 WinSendDlgItemMsg(hwnd,
952 SVBTN_ENTRY,
953 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
954 {
[847]955 FILEFINDBUF3 findbuf;
[551]956 HDIR hDir;
957 ULONG ulSearchCount, x = 0;
958 CHAR *masks[] = { "*.TLS", "FM3TOOLS.DAT", NULL };
959
[487]960 if (mp2)
[551]961 masks[1] = NULL;
962 while (masks[x]) {
963 hDir = HDIR_CREATE;
[766]964 ulSearchCount = 1;
[551]965 DosError(FERR_DISABLEHARDERR);
[847]966 if (!DosFindFirst(masks[x],
967 &hDir,
968 FILE_ARCHIVED,
969 &findbuf,
970 sizeof(FILEFINDBUF3),
971 &ulSearchCount, FIL_STANDARD)) {
[551]972 do {
973 priority_bumped();
974 WinSendMsg(WinWindowFromID(hwnd,
975 SVBTN_LISTBOX),
976 LM_INSERTITEM,
977 MPFROM2SHORT(LIT_SORTASCENDING, 0),
978 MPFROMP(findbuf.achName));
[766]979 ulSearchCount = 1;
[847]980 } while (!DosFindNext(hDir,
981 &findbuf,
982 sizeof(FILEFINDBUF3), &ulSearchCount));
[551]983 DosFindClose(hDir);
984 priority_bumped();
985 }
986 x++;
[2]987 }
[551]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,
[1498]998 (*lasttoolbar) ? lasttoolbar : (CHAR *) PCSZ_FM3TOOLSDAT);
[551]999 break;
[2]1000
[551]1001 case UM_SETUP:
1002 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SVBTN_ENTRY));
1003 return 0;
[2]1004
[551]1005 case WM_CONTROL:
1006 if (SHORT1FROMMP(mp1) == SVBTN_LISTBOX) {
1007 SHORT sSelect;
1008 CHAR szBuffer[CCHMAXPATH];
[2]1009
[551]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;
[2]1024
[551]1025 case LN_ENTER:
1026 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
1027 break;
1028 }
1029 }
1030 return 0;
[2]1031
[551]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));
[2]1044 }
[551]1045 break;
[2]1046
[551]1047 case DID_CANCEL:
1048 WinDismissDlg(hwnd, 0);
1049 break;
[2]1050
[551]1051 case DID_OK:
1052 {
1053 BOOL saving = WinQueryWindowULong(hwnd, QWL_USER);
1054 CHAR temptools[CCHMAXPATH];
[2]1055
[1122]1056 strcpy(temptools, lasttoolbar);
[551]1057 if (fToolsChanged)
1058 save_tools(NULL);
1059 WinQueryDlgItemText(hwnd,
[1122]1060 SVBTN_ENTRY, sizeof(lasttoolbar), lasttoolbar);
1061 if (*lasttoolbar) {
1062 if (!strchr(lasttoolbar, '.'))
[1398]1063 strcat(lasttoolbar, PCSZ_DOTTLS);
[551]1064 }
[1122]1065 if (saving && *lasttoolbar)
[551]1066 save_tools(NULL);
1067 else {
1068 if (!load_tools(NULL)) {
[1122]1069 strcpy(lasttoolbar, temptools);
[551]1070 if (!load_tools(NULL)) {
[1122]1071 *lasttoolbar = 0;
[551]1072 load_tools(NULL);
1073 }
1074 }
1075 }
[1505]1076 PrfWriteProfileString(fmprof, FM3Str, "LastToolbar", lasttoolbar);
[2]1077 }
[551]1078 WinDismissDlg(hwnd, 1);
1079 break;
1080 }
1081 return 0;
[2]1082 }
[551]1083 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]1084}
[793]1085
[1108]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)
[793]1088#pragma alloc_text(TOOLS1,ReOrderToolsProc,PickToolProc,AddToolProc,ToolIODlgProc)
Note: See TracBrowser for help on using the repository browser.