source: trunk/dll/tools.c

Last change on this file was 1750, checked in by John Small, 11 years ago

Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.

So calls to these functions, direct and indirect, had to be changed.

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