source: trunk/dll/tools.c@ 1213

Last change on this file since 1213 was 1213, checked in by John Small, 17 years ago

Ticket 187: Move data declarations/definitions out of fm3dll.h

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