Annotation of OpenXM_contrib/gnuplot/win/wmenu.c, Revision 1.1
1.1 ! maekawa 1: #ifndef lint
! 2: static char *RCSid = "$Id: wmenu.c,v 1.8 1998/03/22 22:35:29 drd Exp $";
! 3: #endif
! 4:
! 5: /* GNUPLOT - win/wmenu.c */
! 6: /*[
! 7: * Copyright 1992, 1993, 1998 Maurice Castro, Russell Lang
! 8: *
! 9: * Permission to use, copy, and distribute this software and its
! 10: * documentation for any purpose with or without fee is hereby granted,
! 11: * provided that the above copyright notice appear in all copies and
! 12: * that both that copyright notice and this permission notice appear
! 13: * in supporting documentation.
! 14: *
! 15: * Permission to modify the software is granted, but not the right to
! 16: * distribute the complete modified source code. Modifications are to
! 17: * be distributed as patches to the released version. Permission to
! 18: * distribute binaries produced by compiling modified sources is granted,
! 19: * provided you
! 20: * 1. distribute the corresponding source modifications from the
! 21: * released version in the form of a patch file along with the binaries,
! 22: * 2. add special version identification to distinguish your version
! 23: * in addition to the base release version number,
! 24: * 3. provide your name and address as the primary contact for the
! 25: * support of your modified version, and
! 26: * 4. retain our contact information in regard to use of the base
! 27: * software.
! 28: * Permission to distribute the released version of the source code along
! 29: * with corresponding source modifications in the form of a patch file is
! 30: * granted with same provisions 2 through 4 for binary distributions.
! 31: *
! 32: * This software is provided "as is" without express or implied warranty
! 33: * to the extent permitted by applicable law.
! 34: ]*/
! 35:
! 36: /*
! 37: * AUTHORS
! 38: *
! 39: * Maurice Castro
! 40: * Russell Lang
! 41: *
! 42: * Send your comments or suggestions to
! 43: * info-gnuplot@dartmouth.edu.
! 44: * This is a mailing list; to join it send a note to
! 45: * majordomo@dartmouth.edu.
! 46: * Send bug reports to
! 47: * bug-gnuplot@dartmouth.edu.
! 48: */
! 49:
! 50: #define STRICT
! 51: #include <windows.h>
! 52: #include <windowsx.h>
! 53: #if WINVER >= 0x030a
! 54: #include <commdlg.h>
! 55: #endif
! 56: #include <string.h> /* only use far items */
! 57: #include "wgnuplib.h"
! 58: #include "wresourc.h"
! 59: #include "wcommon.h"
! 60:
! 61: BOOL CALLBACK WINEXPORT InputBoxDlgProc(HWND, UINT, WPARAM, LPARAM);
! 62: LRESULT CALLBACK WINEXPORT MenuButtonProc(HWND, UINT, WPARAM, LPARAM);
! 63:
! 64: /* limits */
! 65: #define MAXSTR 255
! 66: #define MACROLEN 5000
! 67: /* #define NUMMENU 256 defined in wresourc.h */
! 68: #define MENUDEPTH 3
! 69:
! 70: /* menu tokens */
! 71: #define CMDMIN 129
! 72: #define INPUT 129
! 73: #define EOS 130
! 74: #define OPEN 131
! 75: #define SAVE 132
! 76: #define CMDMAX 132
! 77: char * keyword[] = {
! 78: "[INPUT]", "[EOS]", "[OPEN]", "[SAVE]",
! 79: "{ENTER}", "{ESC}", "{TAB}",
! 80: "{^A}", "{^B}", "{^C}", "{^D}", "{^E}", "{^F}", "{^G}", "{^H}",
! 81: "{^I}", "{^J}", "{^K}", "{^L}", "{^M}", "{^N}", "{^O}", "{^P}",
! 82: "{^Q}", "{^R}", "{^S}", "{^T}", "{^U}", "{^V}", "{^W}", "{^X}",
! 83: "{^Y}", "{^Z}", "{^[}", "{^\\}", "{^]}", "{^^}", "{^_}",
! 84: NULL};
! 85: BYTE keyeq[] = {
! 86: INPUT, EOS, OPEN, SAVE,
! 87: 13, 27, 9,
! 88: 1, 2, 3, 4, 5, 6, 7, 8,
! 89: 9, 10, 11, 12, 13, 14, 15, 16,
! 90: 17, 18, 19, 20, 21, 22, 23, 24,
! 91: 25, 26, 28, 29, 30, 31,
! 92: 0};
! 93:
! 94:
! 95: /* Send a macro to the text window */
! 96: void
! 97: SendMacro(LPTW lptw, UINT m)
! 98: {
! 99: BYTE FAR *s;
! 100: char *d;
! 101: char *buf;
! 102: BOOL flag=TRUE;
! 103: int i;
! 104: LPMW lpmw = lptw->lpmw;
! 105: #if WINVER >= 0x030a
! 106: OPENFILENAME ofn;
! 107: char *szTitle;
! 108: char *szFile;
! 109: char *szFilter;
! 110: #endif
! 111:
! 112: if ( (buf = LocalAllocPtr(LHND, MAXSTR+1)) == (char *)NULL )
! 113: return;
! 114:
! 115: if (m>=lpmw->nCountMenu)
! 116: return;
! 117: s = lpmw->macro[m];
! 118: d = buf;
! 119: *d = '\0';
! 120: while (s && *s && (d-buf < MAXSTR)) {
! 121: if (*s>=CMDMIN && *s<=CMDMAX) {
! 122: switch (*s) {
! 123: case SAVE: /* [SAVE] - get a save filename from a file list box */
! 124: case OPEN: /* [OPEN] - get a filename from a file list box */
! 125: #if WINVER >= 0x030a
! 126: /* This uses COMMDLG.DLL from Windows 3.1
! 127: COMMDLG.DLL is redistributable */
! 128: {
! 129: BOOL save;
! 130: if ( (szTitle = LocalAllocPtr(LHND, MAXSTR+1)) == (char *)NULL )
! 131: return;
! 132: if ( (szFile = LocalAllocPtr(LHND, MAXSTR+1)) == (char *)NULL )
! 133: return;
! 134: if ( (szFilter = LocalAllocPtr(LHND, MAXSTR+1)) == (char *)NULL )
! 135: return;
! 136:
! 137: save = (*s==SAVE);
! 138: s++;
! 139: for(i=0; (*s >= 32 && *s <= 126); i++)
! 140: szTitle[i] = *s++; /* get dialog box title */
! 141: szTitle[i]='\0';
! 142: s++;
! 143: for(i=0; (*s >= 32 && *s <= 126); i++)
! 144: szFile[i] = *s++; /* temporary copy of filter */
! 145: szFile[i++]='\0';
! 146: lstrcpy(szFilter,"Default (");
! 147: lstrcat(szFilter,szFile);
! 148: lstrcat(szFilter,")");
! 149: i=lstrlen(szFilter);
! 150: i++; /* move past NULL */
! 151: lstrcpy(szFilter+i,szFile);
! 152: i+=lstrlen(szFilter+i);
! 153: i++; /* move past NULL */
! 154: lstrcpy(szFilter+i,"All Files (*.*)");
! 155: i+=lstrlen(szFilter+i);
! 156: i++; /* move past NULL */
! 157: lstrcpy(szFilter+i,"*.*");
! 158: i+=lstrlen(szFilter+i);
! 159: i++; /* move past NULL */
! 160: szFilter[i++]='\0'; /* add a second NULL */
! 161: flag = 0;
! 162:
! 163: /* the Windows 3.1 implentation - MC */
! 164: szFile[0] = '\0';
! 165: /* clear the structrure */
! 166: _fmemset(&ofn, 0, sizeof(OPENFILENAME));
! 167: ofn.lStructSize = sizeof(OPENFILENAME);
! 168: ofn.hwndOwner = lptw->hWndParent;
! 169: ofn.lpstrFilter = szFilter;
! 170: ofn.nFilterIndex = 1;
! 171: ofn.lpstrFile = szFile;
! 172: ofn.nMaxFile = MAXSTR;
! 173: ofn.lpstrFileTitle = szFile;
! 174: ofn.nMaxFileTitle = MAXSTR;
! 175: ofn.lpstrTitle = szTitle;
! 176: ofn.lpstrInitialDir = (LPSTR)NULL;
! 177: ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
! 178: flag = (save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn));
! 179: if( flag ) {
! 180: lpmw->nChar = lstrlen(ofn.lpstrFile);
! 181: for (i=0; i<lpmw->nChar; i++)
! 182: *d++=ofn.lpstrFile[i];
! 183: }
! 184:
! 185: LocalFreePtr((void NEAR *)OFFSETOF(szTitle));
! 186: LocalFreePtr((void NEAR *)OFFSETOF(szFilter));
! 187: LocalFreePtr((void NEAR *)OFFSETOF(szFile));
! 188:
! 189: }
! 190: break;
! 191: #else
! 192: /* Use InputBox if you don't have COMMDLG.DLL.
! 193: s++; /* skip list box title */
! 194: for(i=0; (*s >= 32 && *s <= 126); i++)
! 195: s++;
! 196: #endif
! 197: case INPUT: /* [INPUT] - input a string of characters */
! 198: s++;
! 199: for(i=0; (*s >= 32 && *s <= 126); i++)
! 200: lpmw->szPrompt[i] = *s++;
! 201: lpmw->szPrompt[i]='\0';
! 202: #ifdef WIN32
! 203: flag = DialogBox( hdllInstance, "InputDlgBox", lptw->hWndParent, InputBoxDlgProc);
! 204: #else
! 205: #ifdef __DLL__
! 206: lpmw->lpProcInput = (DLGPROC)GetProcAddress(hdllInstance, "InputBoxDlgProc");
! 207: #else
! 208: lpmw->lpProcInput = (DLGPROC)MakeProcInstance((FARPROC)InputBoxDlgProc, hdllInstance);
! 209: #endif
! 210: flag = DialogBox( hdllInstance, "InputDlgBox", lptw->hWndParent, lpmw->lpProcInput);
! 211: #endif
! 212: if( flag ) {
! 213: for (i=0; i<lpmw->nChar; i++)
! 214: *d++=lpmw->szAnswer[i];
! 215: }
! 216: #ifndef WIN32
! 217: #ifndef __DLL__
! 218: FreeProcInstance((FARPROC)lpmw->lpProcInput);
! 219: #endif
! 220: #endif
! 221: break;
! 222: case EOS: /* [EOS] - End Of String - do nothing */
! 223: default:
! 224: s++;
! 225: break;
! 226: }
! 227: if (!flag) { /* abort */
! 228: d = buf;
! 229: s = (BYTE FAR *)"";
! 230: }
! 231: }
! 232: else {
! 233: *d++ = *s++;
! 234: }
! 235: }
! 236: *d = '\0';
! 237: if (buf[0]!='\0') {
! 238: d = buf;
! 239: while (*d) {
! 240: SendMessage(lptw->hWndText,WM_CHAR,*d,1L);
! 241: d++;
! 242: }
! 243: }
! 244: }
! 245:
! 246:
! 247: #define GBUFSIZE 512
! 248: typedef struct tagGFILE {
! 249: HFILE hfile;
! 250: char getbuf[GBUFSIZE];
! 251: int getnext;
! 252: int getleft;
! 253: } GFILE;
! 254:
! 255: GFILE * Gfopen(LPSTR lpszFileName, int fnOpenMode)
! 256: {
! 257: GFILE *gfile;
! 258:
! 259: gfile = (GFILE *)LocalAllocPtr(LHND, sizeof(GFILE));
! 260: if (!gfile)
! 261: return NULL;
! 262:
! 263: gfile->hfile = _lopen(lpszFileName, fnOpenMode);
! 264: if (gfile->hfile == HFILE_ERROR) {
! 265: LocalFreePtr((void NEAR *)OFFSETOF(gfile));
! 266: return NULL;
! 267: }
! 268: gfile->getleft = 0;
! 269: gfile->getnext = 0;
! 270: return gfile;
! 271: }
! 272:
! 273: void Gfclose(GFILE * gfile)
! 274: {
! 275:
! 276: _lclose(gfile->hfile);
! 277: LocalFreePtr((void NEAR *)OFFSETOF(gfile));
! 278: return;
! 279: }
! 280:
! 281: /* returns number of characters read */
! 282: int
! 283: Gfgets(LPSTR lp, int size, GFILE *gfile)
! 284: {
! 285: int i;
! 286: int ch;
! 287: for (i=0; i<size; i++) {
! 288: if (gfile->getleft <= 0) {
! 289: if ( (gfile->getleft = _lread(gfile->hfile, gfile->getbuf, GBUFSIZE)) == 0)
! 290: break;
! 291: gfile->getnext = 0;
! 292: }
! 293: ch = *lp++ = gfile->getbuf[gfile->getnext++];
! 294: gfile->getleft --;
! 295: if (ch == '\r') {
! 296: i--;
! 297: lp--;
! 298: }
! 299: if (ch == '\n') {
! 300: i++;
! 301: break;
! 302: }
! 303: }
! 304: if (i<size)
! 305: *lp++ = '\0';
! 306: return i;
! 307: }
! 308:
! 309: /* Get a line from the menu file */
! 310: /* Return number of lines read from file including comment lines */
! 311: int GetLine(char * buffer, int len, GFILE *gfile)
! 312: {
! 313: BOOL status;
! 314: int nLine = 0;
! 315:
! 316: status = (Gfgets(buffer,len,gfile) != 0);
! 317: nLine++;
! 318: while( status && ( buffer[0] == 0 || buffer[0] == '\n' || buffer[0] == ';' ) ) {
! 319: /* blank line or comment - ignore */
! 320: status = (Gfgets(buffer,len,gfile) != 0);
! 321: nLine++;
! 322: }
! 323: if (lstrlen(buffer)>0)
! 324: buffer[lstrlen(buffer)-1] = '\0'; /* remove trailing \n */
! 325:
! 326: if (!status)
! 327: nLine = 0; /* zero lines if file error */
! 328:
! 329: return nLine;
! 330: }
! 331:
! 332: /* Left justify string */
! 333: void LeftJustify(char *d, char *s)
! 334: {
! 335: while ( *s && (*s==' ' || *s=='\t') )
! 336: s++; /* skip over space */
! 337: do {
! 338: *d++ = *s;
! 339: } while (*s++);
! 340: }
! 341:
! 342: /* Translate string to tokenized macro */
! 343: void TranslateMacro(char *string)
! 344: {
! 345: int i, len;
! 346: LPSTR ptr;
! 347:
! 348: for( i=0; keyword[i]!=(char *)NULL; i++ ) {
! 349: if( (ptr = _fstrstr( string, keyword[i] )) != NULL ) {
! 350: len = lstrlen( keyword[i] );
! 351: *ptr = keyeq[i];
! 352: lstrcpy( ptr+1, ptr+len );
! 353: i--; /* allows for more than one occurrence of keyword */
! 354: }
! 355: }
! 356: }
! 357:
! 358: /* Load Macros, and create Menu from Menu file */
! 359: void
! 360: LoadMacros(LPTW lptw)
! 361: {
! 362: GFILE *menufile;
! 363: BYTE FAR *macroptr;
! 364: char *buf;
! 365: int nMenuLevel;
! 366: HMENU hMenu[MENUDEPTH+1];
! 367: LPMW lpmw;
! 368: int nLine = 1;
! 369: int nInc;
! 370: HGLOBAL hmacro, hmacrobuf;
! 371:
! 372: int i;
! 373: HDC hdc;
! 374: TEXTMETRIC tm;
! 375: RECT rect;
! 376: int ButtonX, ButtonY;
! 377: char FAR *ButtonText[BUTTONMAX];
! 378:
! 379: lpmw = lptw->lpmw;
! 380:
! 381: /* mark all buffers and menu file as unused */
! 382: buf = (char *)NULL;
! 383: hmacro = 0;
! 384: hmacrobuf = 0;
! 385: lpmw->macro = (BYTE FAR * FAR *)NULL;
! 386: lpmw->macrobuf = (BYTE FAR *)NULL;
! 387: lpmw->szPrompt = (char *)NULL;
! 388: lpmw->szAnswer = (char *)NULL;
! 389: menufile = (GFILE *)NULL;
! 390:
! 391: /* open menu file */
! 392: if ((menufile=Gfopen(lpmw->szMenuName,OF_READ)) == (GFILE *)NULL)
! 393: goto errorcleanup;
! 394:
! 395: /* allocate buffers */
! 396: if ((buf = LocalAllocPtr(LHND, MAXSTR)) == (char *)NULL)
! 397: goto nomemory;
! 398: hmacro = GlobalAlloc(GHND,(NUMMENU) * sizeof(BYTE FAR *));
! 399: if ((lpmw->macro = (BYTE FAR * FAR *)GlobalLock(hmacro)) == (BYTE FAR * FAR *)NULL)
! 400: goto nomemory;
! 401: hmacrobuf = GlobalAlloc(GHND, MACROLEN);
! 402: if ((lpmw->macrobuf = (BYTE FAR*)GlobalLock(hmacrobuf)) == (BYTE FAR *)NULL)
! 403: goto nomemory;
! 404: if ((lpmw->szPrompt = LocalAllocPtr(LHND, MAXSTR)) == (char *)NULL)
! 405: goto nomemory;
! 406: if ((lpmw->szAnswer = LocalAllocPtr(LHND, MAXSTR)) == (char *)NULL)
! 407: goto nomemory;
! 408:
! 409: macroptr = lpmw->macrobuf;
! 410: lpmw->nButton = 0;
! 411: lpmw->nCountMenu = 0;
! 412: lpmw->hMenu = hMenu[0] = CreateMenu();
! 413: nMenuLevel = 0;
! 414:
! 415: while ((nInc = GetLine(buf,MAXSTR,menufile)) != 0) {
! 416: nLine += nInc;
! 417: LeftJustify(buf,buf);
! 418: if (buf[0]=='\0') {
! 419: /* ignore blank lines */
! 420: }
! 421: else if (!lstrcmpi(buf,"[Menu]")) {
! 422: /* new menu */
! 423: if (!(nInc = GetLine(buf,MAXSTR,menufile))) {
! 424: nLine += nInc;
! 425: wsprintf(buf,"Problem on line %d of %s\n",nLine,lpmw->szMenuName);
! 426: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 427: goto errorcleanup;
! 428: }
! 429: LeftJustify(buf,buf);
! 430: if (nMenuLevel<MENUDEPTH)
! 431: nMenuLevel++;
! 432: else {
! 433: wsprintf(buf,"Menu is too deep at line %d of %s\n",nLine,lpmw->szMenuName);
! 434: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 435: goto errorcleanup;
! 436: }
! 437: hMenu[nMenuLevel] = CreateMenu();
! 438: AppendMenu(hMenu[nMenuLevel > 0 ? nMenuLevel-1 : 0],
! 439: MF_STRING | MF_POPUP, (UINT)hMenu[nMenuLevel], (LPCSTR)buf);
! 440: }
! 441: else if (!lstrcmpi(buf,"[EndMenu]")) {
! 442: if (nMenuLevel > 0)
! 443: nMenuLevel--; /* back up one menu */
! 444: }
! 445: else if (!lstrcmpi(buf,"[Button]")) {
! 446: /* button macro */
! 447: if (lpmw->nButton >= BUTTONMAX) {
! 448: wsprintf(buf,"Too many buttons at line %d of %s\n",nLine,lpmw->szMenuName);
! 449: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 450: goto errorcleanup;
! 451: }
! 452: if (!(nInc = GetLine(buf,MAXSTR,menufile))) {
! 453: nLine += nInc;
! 454: wsprintf(buf,"Problem on line %d of %s\n",nLine,lpmw->szMenuName);
! 455: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 456: goto errorcleanup;
! 457: }
! 458: LeftJustify(buf,buf);
! 459: if (lstrlen(buf)+1 < MACROLEN - (macroptr-lpmw->macrobuf))
! 460: lstrcpy((char FAR *)macroptr,buf);
! 461: else {
! 462: wsprintf(buf,"Out of space for storing menu macros\n at line %d of \n",nLine,lpmw->szMenuName);
! 463: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 464: goto errorcleanup;
! 465: }
! 466: ButtonText[lpmw->nButton] = (char FAR *)macroptr;
! 467: macroptr += lstrlen((char FAR *)macroptr)+1;
! 468: *macroptr = '\0';
! 469: if (!(nInc = GetLine(buf,MAXSTR,menufile))) {
! 470: nLine += nInc;
! 471: wsprintf(buf,"Problem on line %d of %s\n",nLine,lpmw->szMenuName);
! 472: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 473: goto errorcleanup;
! 474: }
! 475: LeftJustify(buf,buf);
! 476: TranslateMacro(buf);
! 477: if (lstrlen(buf)+1 < MACROLEN - (macroptr-lpmw->macrobuf))
! 478: lstrcpy((char FAR *)macroptr,buf);
! 479: else {
! 480: wsprintf(buf,"Out of space for storing menu macros\n at line %d of \n",nLine,lpmw->szMenuName);
! 481: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 482: goto errorcleanup;
! 483: }
! 484: lpmw->hButtonID[lpmw->nButton] = lpmw->nCountMenu;
! 485: lpmw->macro[lpmw->nCountMenu] = macroptr;
! 486: macroptr += lstrlen((char FAR *)macroptr)+1;
! 487: *macroptr = '\0';
! 488: lpmw->nCountMenu++;
! 489: lpmw->nButton++;
! 490: }
! 491: else {
! 492: /* menu item */
! 493: if (lpmw->nCountMenu>=NUMMENU) {
! 494: wsprintf(buf,"Too many menu items at line %d of %s\n",nLine,lpmw->szMenuName);
! 495: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 496: goto errorcleanup;
! 497: }
! 498: LeftJustify(buf,buf);
! 499: /* HBB 981202: added MF_SEPARATOR to the MF_MENU*BREAK items. This is meant
! 500: * to maybe avoid a CodeGuard warning about passing last argument zero
! 501: * when item style is not SEPARATOR... Actually, a better solution would
! 502: * have been to combine the '|' divider with the next menu item. */
! 503: if (buf[0]=='-') {
! 504: if (nMenuLevel == 0)
! 505: AppendMenu(hMenu[0], MF_SEPARATOR | MF_MENUBREAK, 0, (LPSTR)NULL);
! 506: else
! 507: AppendMenu(hMenu[nMenuLevel], MF_SEPARATOR, 0, (LPSTR)NULL);
! 508: }
! 509: else if (buf[0]=='|') {
! 510: AppendMenu(hMenu[nMenuLevel], MF_SEPARATOR | MF_MENUBARBREAK, 0, (LPSTR)NULL);
! 511: }
! 512: else {
! 513: AppendMenu(hMenu[nMenuLevel],MF_STRING, lpmw->nCountMenu, (LPSTR)buf);
! 514: if (!(nInc = GetLine(buf,MAXSTR,menufile))) {
! 515: nLine += nInc;
! 516: wsprintf(buf,"Problem on line %d of %s\n",nLine,lpmw->szMenuName);
! 517: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 518: goto errorcleanup;
! 519: }
! 520: LeftJustify(buf,buf);
! 521: TranslateMacro(buf);
! 522: if (lstrlen(buf)+1 < MACROLEN - (macroptr-lpmw->macrobuf))
! 523: lstrcpy((char FAR *)macroptr,buf);
! 524: else {
! 525: wsprintf(buf,"Out of space for storing menu macros\n at line %d of %s\n",nLine,lpmw->szMenuName);
! 526: MessageBox(lptw->hWndParent,(LPSTR) buf,lptw->Title, MB_ICONEXCLAMATION);
! 527: goto errorcleanup;
! 528: }
! 529: lpmw->macro[lpmw->nCountMenu] = macroptr;
! 530: macroptr += lstrlen((char FAR *)macroptr)+1;
! 531: *macroptr = '\0';
! 532: lpmw->nCountMenu++;
! 533: }
! 534: }
! 535: }
! 536:
! 537: if ( (lpmw->nCountMenu - lpmw->nButton) > 0 ) {
! 538: /* we have a menu bar so put it on the window */
! 539: SetMenu(lptw->hWndParent,lpmw->hMenu);
! 540: DrawMenuBar(lptw->hWndParent);
! 541: }
! 542:
! 543: if (!lpmw->nButton)
! 544: goto cleanup; /* no buttons */
! 545:
! 546: /* calculate size of buttons */
! 547: hdc = GetDC(lptw->hWndParent);
! 548: SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
! 549: GetTextMetrics(hdc, &tm);
! 550: ButtonX = 8 * tm.tmAveCharWidth;
! 551: ButtonY = 6 * (tm.tmHeight + tm.tmExternalLeading) / 4;
! 552: ReleaseDC(lptw->hWndParent,hdc);
! 553:
! 554: /* move top of client text window down to allow space for buttons */
! 555: lptw->ButtonHeight = ButtonY+1;
! 556: GetClientRect(lptw->hWndParent, &rect);
! 557: SetWindowPos(lptw->hWndText, (HWND)NULL, 0, lptw->ButtonHeight,
! 558: rect.right, rect.bottom-lptw->ButtonHeight,
! 559: SWP_NOZORDER | SWP_NOACTIVATE);
! 560:
! 561: /* create the buttons */
! 562: #ifdef __DLL__
! 563: lpmw->lpfnMenuButtonProc = (WNDPROC)GetProcAddress(hdllInstance, "MenuButtonProc");
! 564: #else
! 565: lpmw->lpfnMenuButtonProc = (WNDPROC)MakeProcInstance((FARPROC)MenuButtonProc, hdllInstance);
! 566: #endif
! 567: for (i=0; i<lpmw->nButton; i++) {
! 568: lpmw->hButton[i] = CreateWindow("button", ButtonText[i],
! 569: WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
! 570: i * ButtonX, 0,
! 571: ButtonX, ButtonY,
! 572: lptw->hWndParent, (HMENU)i,
! 573: lptw->hInstance, lptw);
! 574: lpmw->lpfnButtonProc[i] = (WNDPROC) GetWindowLong(lpmw->hButton[i], GWL_WNDPROC);
! 575: SetWindowLong(lpmw->hButton[i], GWL_WNDPROC, (LONG)lpmw->lpfnMenuButtonProc);
! 576: }
! 577:
! 578: goto cleanup;
! 579:
! 580:
! 581: nomemory:
! 582: MessageBox(lptw->hWndParent,"Out of memory",lptw->Title, MB_ICONEXCLAMATION);
! 583: errorcleanup:
! 584: if (hmacro) {
! 585: GlobalUnlock(hmacro);
! 586: GlobalFree(hmacro);
! 587: }
! 588: if (hmacrobuf) {
! 589: GlobalUnlock(hmacrobuf);
! 590: GlobalFree(hmacrobuf);
! 591: }
! 592: if (lpmw->szPrompt != (char *)NULL)
! 593: LocalFreePtr((void NEAR *)OFFSETOF(lpmw->szPrompt));
! 594: if (lpmw->szAnswer != (char *)NULL)
! 595: LocalFreePtr((void NEAR *)OFFSETOF(lpmw->szAnswer));
! 596:
! 597: cleanup:
! 598: if (buf != (char *)NULL)
! 599: LocalFreePtr((void NEAR *)OFFSETOF(buf));
! 600: if (menufile != (GFILE *)NULL)
! 601: Gfclose(menufile);
! 602: return;
! 603:
! 604: }
! 605:
! 606: void
! 607: CloseMacros(LPTW lptw)
! 608: {
! 609: HGLOBAL hglobal;
! 610: LPMW lpmw;
! 611: lpmw = lptw->lpmw;
! 612:
! 613: #ifndef WIN32
! 614: #ifndef __DLL__
! 615: if (lpmw->lpfnMenuButtonProc)
! 616: FreeProcInstance((FARPROC)lpmw->lpfnMenuButtonProc);
! 617: #endif
! 618: #endif
! 619: hglobal = (HGLOBAL)GlobalHandle( SELECTOROF(lpmw->macro) );
! 620: if (hglobal) {
! 621: GlobalUnlock(hglobal);
! 622: GlobalFree(hglobal);
! 623: }
! 624: hglobal = (HGLOBAL)GlobalHandle( SELECTOROF(lpmw->macrobuf) );
! 625: if (hglobal) {
! 626: GlobalUnlock(hglobal);
! 627: GlobalFree(hglobal);
! 628: }
! 629: if (lpmw->szPrompt != (char *)NULL)
! 630: LocalFreePtr((void NEAR *)OFFSETOF(lpmw->szPrompt));
! 631: if (lpmw->szAnswer != (char *)NULL)
! 632: LocalFreePtr((void NEAR *)OFFSETOF(lpmw->szAnswer));
! 633: }
! 634:
! 635:
! 636: /***********************************************************************/
! 637: /* InputBoxDlgProc() - Message handling routine for Input dialog box */
! 638: /***********************************************************************/
! 639:
! 640: BOOL CALLBACK WINEXPORT
! 641: InputBoxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
! 642: {
! 643: LPTW lptw;
! 644: LPMW lpmw;
! 645: lptw = (LPTW)GetWindowLong(GetParent(hDlg), 0);
! 646: lpmw = lptw->lpmw;
! 647:
! 648: switch( message) {
! 649: case WM_INITDIALOG:
! 650: SetDlgItemText( hDlg, ID_PROMPT, lpmw->szPrompt);
! 651: return( TRUE);
! 652:
! 653: case WM_COMMAND:
! 654: switch(LOWORD(wParam)) {
! 655: case ID_ANSWER:
! 656: return( TRUE);
! 657:
! 658: case IDOK:
! 659: lpmw->nChar = GetDlgItemText( hDlg, ID_ANSWER, lpmw->szAnswer, MAXSTR);
! 660: EndDialog( hDlg, TRUE);
! 661: return( TRUE);
! 662:
! 663: case IDCANCEL:
! 664: lpmw->szAnswer[0] = 0;
! 665: EndDialog( hDlg, FALSE);
! 666: return( TRUE);
! 667:
! 668: default:
! 669: return( FALSE);
! 670: }
! 671: default:
! 672: return( FALSE);
! 673: }
! 674: }
! 675:
! 676:
! 677: LRESULT CALLBACK WINEXPORT
! 678: MenuButtonProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
! 679: {
! 680: LPTW lptw;
! 681: LPMW lpmw;
! 682: #ifdef WIN32
! 683: LONG n = GetWindowLong(hwnd, GWL_ID);
! 684: #else
! 685: WORD n = GetWindowWord(hwnd, GWW_ID);
! 686: #endif
! 687: lptw = (LPTW)GetWindowLong(GetParent(hwnd), 0);
! 688: lpmw = lptw->lpmw;
! 689:
! 690: switch(message) {
! 691: case WM_LBUTTONUP:
! 692: {
! 693: RECT rect;
! 694: POINT pt;
! 695: GetWindowRect(hwnd, &rect);
! 696: GetCursorPos(&pt);
! 697: if (PtInRect(&rect, pt))
! 698: SendMessage(lptw->hWndText, WM_COMMAND, lpmw->hButtonID[n], 0L);
! 699: SetFocus(lptw->hWndText);
! 700: }
! 701: break;
! 702: }
! 703: return CallWindowProc((lpmw->lpfnButtonProc[n]), hwnd, message, wParam, lParam);
! 704: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>