source: trunk/dll/tools.c@ 1402

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

Remove variable aurgs from docopy & unlinkf (not used); Move more strings to PCSZs and string table; Move PCSZs to compile time initialization; Fix hang on startup caused by a drive scan and a dircnr scan trying to update a drive in the tree at the same time (related to the "treeswitch options); Code cleanup mainly removal of old printfs, SayMsgs, DbgMsg and unneeded %s.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.4 KB
RevLine 
[2]1
[123]2/***********************************************************************
3
4 $Id: tools.c 1402 2009-03-14 17:17:59Z gyoung $
5
[329]6 Toolbar support routines
[123]7
8 Copyright (c) 1994-97 M. Kimes
[1348]9 Copyright (c) 2004, 2008 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)
[123]26
27***********************************************************************/
28
[907]29#include <stdlib.h>
30#include <string.h>
31#include <share.h>
32
[2]33#define INCL_DOS
34#define INCL_WIN
[841]35#define INCL_LONGLONG
[2]36
[1184]37#include "fm3dll.h"
[1227]38#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
39#include "tools.h"
[1213]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)
[2]44#include "fm3dlg.h"
45#include "fm3str.h"
[907]46#include "errutil.h" // Dos_Error...
47#include "strutil.h" // GetPString
[1082]48#include "pathutil.h" // BldFullPathName
[1079]49#include "fortify.h"
[1160]50#include "loadbmp.h" // LoadBitmapFromFileNum
[1184]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
[2]61
[1213]62// Data definitions
[2]63#pragma data_seg(DATA1)
[329]64
65static PSZ pszSrcFile = __FILE__;
66
[1213]67#pragma data_seg(GLOBAL1)
68BOOL fToolsChanged;
[2]69TOOL *toolhead = NULL;
70
[1213]71#pragma data_seg(GLOBAL2)
72CHAR lasttoolbar[CCHMAXPATH];
73BOOL qtloaded;
74CHAR *quicktool[50];
75
[440]76//== load_quicktools() build *.tls array ==
[2]77
[440]78VOID load_quicktools(VOID)
79{
[551]80 FILE *fp;
81 CHAR s[CCHMAXPATH + 14];
82 INT x;
[2]83
84 qtloaded = TRUE;
[440]85 for (x = 0; x < 50 && quicktool[x]; x++) {
[1039]86 free(quicktool[x]);
[2]87 quicktool[x] = NULL;
88 }
[440]89 if (!fToolbar) {
[2]90 qtloaded = FALSE;
91 return;
92 }
[1398]93 BldFullPathName(s, pFM2SaveDirectory, PCSZ_QUICKTLSDAT);
[551]94 fp = _fsopen(s, "r", SH_DENYWR);
[329]95 if (fp) {
[440]96 x = 0;
97 while (!feof(fp)) {
[551]98 if (!xfgets_bstripcr(s, CCHMAXPATH + 2, fp, pszSrcFile, __LINE__))
99 break;
[440]100 if (!*s || *s == ';')
[551]101 continue;
[440]102 if (x >= 50) {
103 Runtime_Error(pszSrcFile, __LINE__, "add");
104 break;
[2]105 }
[551]106 quicktool[x] = xstrdup(s, pszSrcFile, __LINE__);
[440]107 if (!quicktool[x])
[551]108 break;
[440]109 x++;
[2]110 }
111 fclose(fp);
112 }
113}
114
[440]115VOID save_quicktools(VOID)
116{
[2]117 FILE *fp;
[551]118 INT x = 0;
119 CHAR s[CCHMAXPATH + 14];
[2]120
[487]121 if (!quicktool[0])
[2]122 return;
[1398]123 BldFullPathName(s, pFM2SaveDirectory, PCSZ_QUICKTLSDAT);
[1118]124 if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2)
[1117]125 return; //already gave error msg
[551]126 fp = xfopen(s, "w", pszSrcFile, __LINE__);
[329]127 if (fp) {
[551]128 for (x = 0; quicktool[x] && x < 50; x++)
129 fprintf(fp, "%s\n", quicktool[x]);
[2]130 fclose(fp);
131 }
132}
133
[440]134//== load_tools() Build tools list given .tls filename ==
[2]135
[551]136TOOL *load_tools(CHAR * filename)
[440]137{
[551]138 FILE *fp;
139 CHAR help[80], text[80], flagstr[80], idstr[80], *fname;
140 TOOL *info;
[2]141
[487]142 if (!fToolbar) {
[2]143 toolhead = free_tools();
144 return toolhead;
145 }
[551]146 if (!filename || !*filename)
[1122]147 filename = (*lasttoolbar) ? lasttoolbar : "CMDS.TLS";
[487]148 if (*filename)
[2]149 fname = searchpath(filename);
[551]150 if (!fname || !*fname)
[1398]151 fname = (PSZ) PCSZ_FM3TOOLSDAT;
[551]152 if (fname && *fname) {
[2]153 filename = fname;
[1122]154 strcpy(lasttoolbar, filename);
[551]155 fp = _fsopen(filename, "r", SH_DENYWR);
[329]156 if (fp) {
[2]157 toolhead = free_tools();
[487]158 while (!feof(fp)) {
[551]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) {
[1079]175# ifdef FORTIFY
176 Fortify_SetOwner(info, 1);
177 Fortify_SetScope(info, 1);
178# endif
[551]179 if (*help) {
180 literal(help);
[1079]181 if (*help) {
[551]182 info->help = xstrdup(help, pszSrcFile, __LINE__);
[1079]183# ifdef FORTIFY
184 Fortify_SetOwner(info->help, 1);
185 Fortify_SetScope(info->help, 1);
186# endif
187 }
[551]188 }
[1079]189 if (*text) {
[551]190 info->text = xstrdup(text, pszSrcFile, __LINE__);
[1079]191# ifdef FORTIFY
192 Fortify_SetOwner(info->text, 1);
193 Fortify_SetScope(info->text, 1);
194# endif
195 }
[551]196 info->flags = (atoi(flagstr) & (~(T_TEXT | T_EMPHASIZED)));
197 info->id = (USHORT) atoi(idstr);
198 info->next = NULL;
199 add_tool(info);
200 }
[2]201 }
202 fclose(fp);
203 fToolsChanged = FALSE;
204 }
205 }
206 return toolhead;
207}
208
[551]209VOID save_tools(CHAR * filename)
[440]210{
[551]211 FILE *fp;
212 CHAR *fname;
213 TOOL *info;
[2]214
[487]215 if (!filename)
[1122]216 filename = lasttoolbar;
[487]217 if (*filename)
[2]218 fname = searchpath(filename);
[487]219 if (fname && *fname)
[2]220 filename = fname;
221 else {
[1122]222 if (*lasttoolbar)
223 filename = lasttoolbar;
[2]224 else
225 filename = "FM3TOOLS.TLS";
226 fname = searchpath(filename);
[487]227 if (fname && *fname)
[2]228 filename = fname;
229 }
230
[1398]231 if (stristr(filename, PCSZ_FM3TOOLSDAT))
[2]232 filename = "FM3TOOLS.TLS";
[487]233 if (toolhead && filename && *filename) {
[1122]234 strcpy(lasttoolbar, filename);
235 PrfWriteProfileString(fmprof, FM3Str, "LastToolbar", filename);
[2]236 }
[487]237 if (!toolhead) {
[1402]238 unlinkf(filename);
[2]239 return;
240 }
[1118]241 if (CheckDriveSpaceAvail(filename, ullDATFileSpaceNeeded, 1) == 2)
[1117]242 return; //already gave error msg
[551]243 fp = xfopen(filename, "w", pszSrcFile, __LINE__);
[329]244 if (fp) {
[551]245 fprintf(fp, GetPString(IDS_TOOLFILETEXT), filename);
[2]246 info = toolhead;
[487]247 while (info) {
[2]248 fprintf(fp,
[551]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);
[2]253 info = info->next;
254 }
255 fclose(fp);
256 fToolsChanged = FALSE;
257 }
[487]258 if (hwndMain)
[551]259 PostMsg(hwndMain, UM_FILLBUTTONLIST, MPVOID, MPVOID);
[2]260}
261
[551]262TOOL *add_tool(TOOL * tool)
[440]263{
[2]264 TOOL *info;
265
[487]266 if (tool) {
[2]267 info = toolhead;
[487]268 if (info) {
269 while (info->next)
[551]270 info = info->next;
[2]271 }
[487]272 if (info)
[2]273 info->next = tool;
274 else
275 toolhead = tool;
276 fToolsChanged = TRUE;
277 }
278 return toolhead;
279}
280
[551]281TOOL *insert_tool(TOOL * tool, TOOL * after)
[440]282{
[487]283 if (tool) {
284 if (!toolhead)
[2]285 return add_tool(tool);
[487]286 if (!after) {
[2]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
[551]300TOOL *del_tool(TOOL * tool)
[440]301{
[551]302 TOOL *info, *prev = NULL;
[2]303
[487]304 if (tool) {
[2]305 info = toolhead;
[487]306 while (info) {
307 if (info == tool) {
[551]308 if (info == toolhead)
309 toolhead = info->next;
310 if (prev)
311 prev->next = info->next;
[1009]312 xfree(info->help, pszSrcFile, __LINE__);
313 xfree(info->text, pszSrcFile, __LINE__);
[1039]314 free(info);
[551]315 fToolsChanged = TRUE;
316 break;
[2]317 }
318 prev = info;
319 info = info->next;
320 }
321 }
322 return toolhead;
323}
324
[440]325TOOL *find_tool(USHORT id)
326{
[2]327 TOOL *tool;
328
[487]329 if (id) {
[2]330 tool = toolhead;
[487]331 while (tool) {
332 if (id && tool->id == id)
[551]333 return tool;
[2]334 tool = tool->next;
335 }
336 }
337 return NULL;
338}
339
[551]340TOOL *next_tool(TOOL * tool, BOOL skipinvisible)
[440]341{
[487]342 while (tool) {
343 if (tool->next && (skipinvisible && (tool->next->flags & T_INVISIBLE)))
[2]344 tool = tool->next;
345 else
346 return (tool->next) ? tool->next : toolhead;
347 }
348 return NULL;
349}
350
[551]351TOOL *prev_tool(TOOL * tool, BOOL skipinvisible)
[440]352{
[2]353 TOOL *info;
354
355Again:
[487]356 while (tool) {
[2]357 info = toolhead;
[487]358 while (info) {
359 if (info->next == tool) {
[551]360 if (skipinvisible && (info->flags & T_INVISIBLE)) {
361 tool = info;
362 goto Again;
363 }
364 return info;
[2]365 }
[487]366 if (!info->next && tool == toolhead)
[551]367 return info;
[2]368 info = info->next;
369 }
370 return toolhead;
371 }
372 return NULL;
373}
374
[551]375TOOL *swap_tools(TOOL * tool1, TOOL * tool2)
[440]376{
[551]377 TOOL *prev1 = NULL, *prev2 = NULL, *info;
[2]378
[487]379 if (tool1 && tool2 && tool1 != tool2) {
[2]380 info = toolhead;
[487]381 while (info && !prev1 && !prev2) {
382 if (info->next == tool1)
[551]383 prev1 = info;
[487]384 else if (info->next == tool2)
[551]385 prev2 = info;
[2]386 info = info->next;
387 }
388 info = tool2;
389 tool2 = tool1;
390 tool1 = info;
391 info = tool2->next;
[487]392 if (prev1)
[2]393 prev1->next = tool2;
[487]394 if (prev2)
[2]395 prev2->next = tool1;
396 tool2->next = tool1->next;
397 tool1->next = info;
398 fToolsChanged = TRUE;
399 }
400 return toolhead;
401}
402
[440]403TOOL *free_tools(VOID)
404{
[551]405 TOOL *tool, *next;
[2]406
407 tool = toolhead;
[487]408 while (tool) {
[2]409 next = tool->next;
[1009]410 xfree(tool->help, pszSrcFile, __LINE__);
411 xfree(tool->text, pszSrcFile, __LINE__);
[1039]412 free(tool);
[2]413 tool = next;
414 }
415 toolhead = NULL;
416 return toolhead;
417}
418
[551]419MRESULT EXPENTRY ReOrderToolsProc(HWND hwnd, ULONG msg, MPARAM mp1,
420 MPARAM mp2)
[440]421{
[487]422 switch (msg) {
[551]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;
[2]431
[551]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;
[2]445 }
[551]446 }
447 break;
[2]448
[551]449 case WM_CONTROL:
450 return 0;
[2]451
[551]452 case WM_COMMAND:
453 switch (SHORT1FROMMP(mp1)) {
454 case DID_CANCEL:
455 WinDismissDlg(hwnd, 0);
456 break;
[2]457
[551]458 case DID_OK:
459 {
460 TOOL *tool, *thead = NULL, *last = NULL;
461 SHORT sSelect = 0, numitems;
[2]462
[551]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 }
[1131]500 save_tools(NULL);
[551]501 WinDismissDlg(hwnd, 1);
502 break;
[2]503
[551]504 case IDM_HELP:
505 if (hwndHelp)
506 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
507 MPFROM2SHORT(HELP_REORDERBUTTONS, 0),
508 MPFROMSHORT(HM_RESOURCEID));
509 break;
[2]510
[551]511 case RE_ADD:
512 {
513 SHORT sSelect, sSelect2;
514 CHAR s[133];
515 TOOL *tool;
[2]516
[551]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;
[2]556
[551]557 case RE_REMOVE:
558 {
559 SHORT sSelect, sSelect2;
560 CHAR s[133];
561 TOOL *tool;
[2]562
[551]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 }
[2]600 }
[551]601 break;
602 }
603 return 0;
[2]604 }
[551]605 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]606}
607
[551]608MRESULT EXPENTRY AddToolProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[440]609{
[487]610 switch (msg) {
[551]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];
[2]629
[551]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;
[2]653
[551]654 case WM_ADJUSTWINDOWPOS:
655 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
656 break;
[2]657
[551]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;
[2]664
[551]665 case UM_SETUP:
666 {
667 HBITMAP hbm = (HBITMAP) 0, hbmd, hbmdd;
668 HPS hps;
669 CHAR idstr[7];
670 USHORT id;
[2]671
[551]672 *idstr = 0;
673 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
674 id = atoi(idstr);
675 if (id) {
676 hps = WinGetPS(WinWindowFromID(hwnd, ADDBTN_BMP));
677 if (!WinQueryButtonCheckstate(hwnd, ADDBTN_MYICON))
678 hbm = GpiLoadBitmap(hps, 0, id, 28, 28);
679 if (!hbm)
680 hbm = LoadBitmapFromFileNum(id);
681 if (hbm) {
682 hbmd = (HBITMAP) WinSendDlgItemMsg(hwnd, ADDBTN_BMP, SM_QUERYHANDLE,
683 MPVOID, MPVOID);
684 hbmdd = (HBITMAP) WinSendDlgItemMsg(hwnd, ADDBTN_BMP, SM_SETHANDLE,
685 MPFROMLONG(hbm), MPVOID);
686 if (hbmdd && hbmd && hbmd != hbmdd)
687 GpiDeleteBitmap(hbmd);
688 }
[2]689 }
[551]690 }
691 return 0;
[2]692
[551]693 case WM_CONTROL:
694 switch (SHORT1FROMMP(mp1)) {
695 case ADDBTN_HELP:
696 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
697 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
698 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
699 WinSetDlgItemText(hwnd, ADDBTN_HELPME,
700 GetPString(IDS_ADDTOOLQUICKHELPTEXT));
701 break;
[2]702
[551]703 case ADDBTN_TEXT:
704 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
705 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
706 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
707 WinSetDlgItemText(hwnd, ADDBTN_HELPME,
708 GetPString(IDS_ADDTOOLBUTTONTEXT));
709 break;
[2]710
[551]711 case ADDBTN_ID:
712 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) {
713 WinSetDlgItemText(hwnd, ADDBTN_HELPME, NullStr);
714 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
[2]715 }
[551]716 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
717 WinSetDlgItemText(hwnd,
718 ADDBTN_HELPME, GetPString(IDS_ADDTOOLBUTTONIDTEXT));
719 break;
[2]720
[551]721 case ADDBTN_MYICON:
722 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
723 WinEnableWindow(WinWindowFromID(hwnd, ADDBTN_EDITBMP),
724 WinQueryButtonCheckstate(hwnd, ADDBTN_MYICON));
725 break;
726 }
727 return 0;
[2]728
[551]729 case WM_COMMAND:
730 switch (SHORT1FROMMP(mp1)) {
731 case DID_OK:
732 {
733 CHAR help[81], text[81], idstr[7];
734 BOOL invisible, dropable, separator, istext, myicon;
[1121]735 TOOL *tool;
736 BOOL BadID = FALSE;
[2]737
[1121]738 help[0] = text[0] = NULL;
[551]739 WinQueryDlgItemText(hwnd, ADDBTN_HELP, 80, help);
740 WinQueryDlgItemText(hwnd, ADDBTN_TEXT, 80, text);
741 if (WinQueryButtonCheckstate(hwnd, ADDBTN_DROPABLE))
742 dropable = TRUE;
743 else
744 dropable = FALSE;
745 myicon = WinQueryButtonCheckstate(hwnd, ADDBTN_MYICON);
746 if (WinQueryButtonCheckstate(hwnd, ADDBTN_VISIBLE))
747 invisible = FALSE;
748 else
749 invisible = TRUE;
750 if (WinQueryButtonCheckstate(hwnd, ADDBTN_SEPARATOR))
751 separator = TRUE;
752 else
753 separator = FALSE;
754 if (WinQueryButtonCheckstate(hwnd, ADDBTN_SHOWTEXT))
755 istext = TRUE;
756 else
757 istext = FALSE;
758 tool = INSTDATA(hwnd);
759 if (tool) { /* just editing strings... */
760 istext = ((tool->flags & T_TEXT) != 0);
[1009]761 xfree(tool->help, pszSrcFile, __LINE__);
[551]762 tool->help = NULL;
[1009]763 xfree(tool->text, pszSrcFile, __LINE__);
[551]764 tool->text = NULL;
[1121]765 if (*help && *text && help && text) {
[551]766 tool->help = xstrdup(help, pszSrcFile, __LINE__);
[1121]767 tool->text = xstrdup(text, pszSrcFile, __LINE__);
768 }
769 else {
770 saymsg(MB_ENTER,
771 hwnd,
772 GetPString(IDS_MISSINGTEXT),
773 GetPString(IDS_TOOLHELPTEXTBLANK));
774 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ADDBTN_HELP));
775 break;
776 }
[551]777 tool->flags = (((dropable) ? T_DROPABLE : 0) |
778 ((invisible) ? T_INVISIBLE : 0) |
779 ((separator) ? T_SEPARATOR : 0) |
780 ((myicon) ? T_MYICON : 0) | ((istext) ? T_TEXT : 0));
[1131]781 save_tools(NULL);
[551]782 WinDismissDlg(hwnd, 1);
783 break;
784 }
785 *idstr = 0;
786 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
787 if (!(USHORT) atoi(idstr)) {
[1395]788 if (!fAlertBeepOff)
789 DosBeep(250, 100);
[551]790 break;
791 }
792 tool = toolhead;
793 while (tool) {
[1121]794 if (tool->id == (USHORT) atoi(idstr)) { // && tool != tool) {
[551]795 saymsg(MB_ENTER,
796 hwnd,
797 GetPString(IDS_DUPLICATETEXT),
798 GetPString(IDS_TOOLIDEXISTS));
799 WinSetDlgItemText(hwnd, ADDBTN_ID, NullStr);
[1121]800 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ADDBTN_ID));
801 BadID =TRUE;
[551]802 break;
803 }
804 tool = tool->next;
[1121]805 }
806 if (BadID)
807 break;
[551]808 tool = xmallocz(sizeof(TOOL), pszSrcFile, __LINE__);
809 if (tool) {
810 if (*help)
811 tool->help = xstrdup(help, pszSrcFile, __LINE__);
812 if (*text)
813 tool->text = xstrdup(text, pszSrcFile, __LINE__);
814 tool->id = (USHORT) atoi(idstr);
815 tool->flags = (((dropable) ? T_DROPABLE : 0) |
816 ((invisible) ? T_INVISIBLE : 0) |
817 ((separator) ? T_SEPARATOR : 0) |
818 ((myicon) ? T_MYICON : 0) | ((istext) ? T_TEXT : 0));
[1108]819 add_tool(tool);
820 save_tools(NULL);
[551]821 WinDismissDlg(hwnd, tool->id);
822 }
823 }
824 break;
[2]825
[551]826 case DID_CANCEL:
827 WinDismissDlg(hwnd, 0);
828 break;
[2]829
[551]830 case ADDBTN_EDITBMP:
831 {
832 CHAR idstr[6], filename[34];
[2]833
[551]834 *idstr = 0;
835 WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
836 if (!(USHORT) atoi(idstr)) {
[1395]837 if (!fAlertBeepOff)
838 DosBeep(250, 100);
[551]839 break;
840 }
841 sprintf(filename, "%u.BMP", atoi(idstr));
842 if (IsFile(filename) != 1) {
843 CHAR s[CCHMAXPATH] = "EMPTY.BMP";
844
845 docopyf(COPY, s, filename);
846 }
847 runemf2(SEPARATE | WINDOWED,
[888]848 hwnd, pszSrcFile, __LINE__,
849 NULL, NULL, "ICONEDIT.EXE %s", filename);
[2]850 }
[551]851 break;
852
853 case IDM_HELP:
854 if (hwndHelp) {
855 if (INSTDATA(hwnd))
856 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
857 MPFROM2SHORT(HELP_CHANGEBUTTON, 0),
858 MPFROMSHORT(HM_RESOURCEID));
859 else
860 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
861 MPFROM2SHORT(HELP_ADDBUTTON, 0),
862 MPFROMSHORT(HM_RESOURCEID));
863 }
864 break;
865 }
866 return 0;
[2]867 }
[551]868 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]869}
870
[551]871MRESULT EXPENTRY PickToolProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[440]872{
[487]873 switch (msg) {
[551]874 case WM_INITDLG:
875 if (mp2) {
876 CHAR s[133];
[2]877
[1009]878 sprintf(s, GetPString(IDS_PICKTOOLTITLETEXT), (CHAR *)mp2);
[551]879 WinSetWindowText(hwnd, s);
880 }
881 {
882 TOOL *tool;
883 CHAR s[133];
[2]884
[551]885 tool = toolhead;
886 while (tool) {
887 sprintf(s, "%-5u %s", tool->id, (tool->help) ? tool->help : "?");
888 WinSendDlgItemMsg(hwnd,
889 PICKBTN_LISTBOX,
890 LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(s));
891 tool = tool->next;
[2]892 }
[551]893 }
894 break;
[2]895
[551]896 case WM_CONTROL:
897 if (SHORT1FROMMP(mp1) == PICKBTN_LISTBOX) {
898 switch (SHORT2FROMMP(mp1)) {
899 case LN_ENTER:
900 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
901 break;
[2]902 }
[551]903 }
904 return 0;
[2]905
[551]906 case WM_COMMAND:
907 switch (SHORT1FROMMP(mp1)) {
908 case DID_CANCEL:
909 WinDismissDlg(hwnd, 0);
910 break;
911 case DID_OK:
912 {
913 SHORT sSelect;
914 CHAR s[33];
[2]915
[551]916 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, PICKBTN_LISTBOX,
917 LM_QUERYSELECTION,
918 MPFROMSHORT(LIT_FIRST), MPVOID);
919 if (sSelect >= 0) {
920 *s = 0;
921 WinSendDlgItemMsg(hwnd, PICKBTN_LISTBOX, LM_QUERYITEMTEXT,
922 MPFROM2SHORT(sSelect, 32), MPFROMP(s));
923 if (*s)
924 WinDismissDlg(hwnd, (USHORT) atoi(s));
925 }
[2]926 }
[551]927 break;
928 }
929 return 0;
[2]930 }
[551]931 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]932}
933
[551]934MRESULT EXPENTRY ToolIODlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[440]935{
[487]936 switch (msg) {
[551]937 case WM_INITDLG:
938 if (mp2)
939 WinSetWindowULong(hwnd, QWL_USER, TRUE);
940 else {
941 WinSetWindowULong(hwnd, QWL_USER, FALSE);
[1122]942 WinSetWindowText(hwnd, GetPString(IDS_LOADTOOLBARTITLETEXT));
[551]943 }
944 WinSendDlgItemMsg(hwnd,
945 SVBTN_ENTRY,
946 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
947 {
[847]948 FILEFINDBUF3 findbuf;
[551]949 HDIR hDir;
950 ULONG ulSearchCount, x = 0;
951 CHAR *masks[] = { "*.TLS", "FM3TOOLS.DAT", NULL };
952
[487]953 if (mp2)
[551]954 masks[1] = NULL;
955 while (masks[x]) {
956 hDir = HDIR_CREATE;
[766]957 ulSearchCount = 1;
[551]958 DosError(FERR_DISABLEHARDERR);
[847]959 if (!DosFindFirst(masks[x],
960 &hDir,
961 FILE_ARCHIVED,
962 &findbuf,
963 sizeof(FILEFINDBUF3),
964 &ulSearchCount, FIL_STANDARD)) {
[551]965 do {
966 priority_bumped();
967 WinSendMsg(WinWindowFromID(hwnd,
968 SVBTN_LISTBOX),
969 LM_INSERTITEM,
970 MPFROM2SHORT(LIT_SORTASCENDING, 0),
971 MPFROMP(findbuf.achName));
[766]972 ulSearchCount = 1;
[847]973 } while (!DosFindNext(hDir,
974 &findbuf,
975 sizeof(FILEFINDBUF3), &ulSearchCount));
[551]976 DosFindClose(hDir);
977 priority_bumped();
978 }
979 x++;
[2]980 }
[551]981 DosError(FERR_DISABLEHARDERR);
982 }
983 if (!WinSendDlgItemMsg(hwnd,
984 SVBTN_LISTBOX,
985 LM_QUERYITEMCOUNT, MPVOID, MPVOID)) {
986 WinEnableWindow(WinWindowFromID(hwnd, SVBTN_LISTBOX), FALSE);
987 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
988 }
989 WinSetDlgItemText(hwnd,
990 SVBTN_CURRENT,
[1398]991 (*lasttoolbar) ? lasttoolbar : PCSZ_FM3TOOLSDAT);
[551]992 break;
[2]993
[551]994 case UM_SETUP:
995 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SVBTN_ENTRY));
996 return 0;
[2]997
[551]998 case WM_CONTROL:
999 if (SHORT1FROMMP(mp1) == SVBTN_LISTBOX) {
1000 SHORT sSelect;
1001 CHAR szBuffer[CCHMAXPATH];
[2]1002
[551]1003 switch (SHORT2FROMMP(mp1)) {
1004 case LN_SELECT:
1005 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, SVBTN_LISTBOX,
1006 LM_QUERYSELECTION,
1007 MPFROMSHORT(LIT_FIRST), MPVOID);
1008 if (sSelect >= 0) {
1009 *szBuffer = 0;
1010 WinSendDlgItemMsg(hwnd, SVBTN_LISTBOX, LM_QUERYITEMTEXT,
1011 MPFROM2SHORT(sSelect, CCHMAXPATH),
1012 MPFROMP(szBuffer));
1013 if (*szBuffer)
1014 WinSetDlgItemText(hwnd, SVBTN_ENTRY, szBuffer);
1015 }
1016 break;
[2]1017
[551]1018 case LN_ENTER:
1019 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
1020 break;
1021 }
1022 }
1023 return 0;
[2]1024
[551]1025 case WM_COMMAND:
1026 switch (SHORT1FROMMP(mp1)) {
1027 case IDM_HELP:
1028 if (hwndHelp) {
1029 if (INSTDATA(hwnd))
1030 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
1031 MPFROM2SHORT(HELP_SAVETOOLS, 0),
1032 MPFROMSHORT(HM_RESOURCEID));
1033 else
1034 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
1035 MPFROM2SHORT(HELP_LOADTOOLS, 0),
1036 MPFROMSHORT(HM_RESOURCEID));
[2]1037 }
[551]1038 break;
[2]1039
[551]1040 case DID_CANCEL:
1041 WinDismissDlg(hwnd, 0);
1042 break;
[2]1043
[551]1044 case DID_OK:
1045 {
1046 BOOL saving = WinQueryWindowULong(hwnd, QWL_USER);
1047 CHAR temptools[CCHMAXPATH];
[2]1048
[1122]1049 strcpy(temptools, lasttoolbar);
[551]1050 if (fToolsChanged)
1051 save_tools(NULL);
1052 WinQueryDlgItemText(hwnd,
[1122]1053 SVBTN_ENTRY, sizeof(lasttoolbar), lasttoolbar);
1054 if (*lasttoolbar) {
1055 if (!strchr(lasttoolbar, '.'))
[1398]1056 strcat(lasttoolbar, PCSZ_DOTTLS);
[551]1057 }
[1122]1058 if (saving && *lasttoolbar)
[551]1059 save_tools(NULL);
1060 else {
1061 if (!load_tools(NULL)) {
[1122]1062 strcpy(lasttoolbar, temptools);
[551]1063 if (!load_tools(NULL)) {
[1122]1064 *lasttoolbar = 0;
[551]1065 load_tools(NULL);
1066 }
1067 }
1068 }
[1122]1069 PrfWriteProfileString(fmprof, FM3Str, "LastToolbar", lasttoolbar);
[2]1070 }
[551]1071 WinDismissDlg(hwnd, 1);
1072 break;
1073 }
1074 return 0;
[2]1075 }
[551]1076 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]1077}
[793]1078
[1108]1079#pragma alloc_text(TOOLS,load_tools,save_tools,add_tool,insert_tool,del_tool,free_tools,swap_tools)
1080#pragma alloc_text(TOOLS,load_quicktools,save_quicktools)
[793]1081#pragma alloc_text(TOOLS1,ReOrderToolsProc,PickToolProc,AddToolProc,ToolIODlgProc)
Note: See TracBrowser for help on using the repository browser.