source: trunk/dll/tools.c@ 1505

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

Remove unnecessary type casts; minor formating cleanup.

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