source: trunk/dll/tools.c@ 1348

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

More code cleanup

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