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