source: trunk/dll/tools.c@ 888

Last change on this file since 888 was 888, checked in by Gregg Young, 18 years ago

runemf2 now quotes executable strings if needed (Ticket 180); it also reports where it was called from on errors

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