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