source: trunk/dll/tools.c@ 1160

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

Ticket 187: Draft 1: Functions only

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