source: trunk/dll/tools.c@ 1140

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

Comments added for recent changes

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