source: trunk/dll/tools.c@ 1395

Last change on this file since 1395 was 1395, checked in by Gregg Young, 17 years ago

Allow user to turn off alert and/or error beeps in settings notebook. Ticket 341 Move repeated strings to PCSZs. Ticket 6 Add *DateFormat functions to format dates based on locale Ticket 28 Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error Ticket 6

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