home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------*\
- | |
- | |
- | WE_EXT.C - A Sample DLL Extension Processor for WinEdit |
- | |
- | |
- \*-------------------------------------------------------------------------*/
- #define STRICT
- #define _WINDLL
- #include <windows.h>
- #include "we_ext.h"
- #include "private.h"
- #include <string.h>
-
- #define NOREF(a) {a=a;}
-
- HMENU hTrackMenu;
- BOOL bWait=TRUE;
- BOOL bCapture=TRUE;
- char szCommand[256];
-
- /*
- * JLD-12/9/92 Added this to setup the default GREP string, which recurs if
- * no work is under the cursor. See line 204.
- */
-
- char GLOB_GrepCmd[256] = {"tee.com fgrep.com -M %s *.c"};
-
- #ifndef WIN32
- #define APIENTRY WINAPI
- #endif
-
- #if !defined(LONG2POINT)
- #define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), (pt).y=(SHORT)HIWORD(l))
- #endif
-
- /*-------------------------------------------------------------------------*\
- | |
- | Function: WE_ExtensionProc |
- | |
- | Purpose: WinEdit calls this function with the WEN_* messages and |
- | whenever a user-defined menu item or accelerator is |
- | accessed. |
- | |
- | Parameters: HWND hWnd - WinEdit's window handle |
- | |
- | UINT wParam - Message ID. If wParam is >= WE_EXTFIRST, |
- | the DLL is being requested to perform the |
- | user-defined action. |
- | |
- \*-------------------------------------------------------------------------*/
- UINT APIENTRY WE_ExtensionProc(HWND hWnd, /* WinEdit's window handle */
- HANDLE hInst, /* instance identifier */
- UINT wParam, /* command ID */
- LONG lParam) /* additional information */
- {
-
- switch (wParam)
- {
-
- case WEN_LOADMENU:
-
- /* This is the menu WinEdit will display when there
- * is at least one document window open. Return NULL
- * to use the default WinEdit menu.
- *
- */
-
- return (UINT)LoadMenu(hInst, "MyMenu");
- break;
-
- case WEN_LOADSHORTMENU:
-
- /* this is the menu WinEdit will display when there
- * are no document windows open. Return NULL
- * to use the default WinEdit menu.
- *
- */
-
- return (UINT)LoadMenu(hInst, "MyShortMenu");
- return 0;
- break;
-
- case WEN_LOADACCELS:
-
- /* To add accelerators for new commands, load your
- * own accelerator table here. Return NULL to
- * use the default WinEdit accelerators.
- *
- */
-
- return (UINT)LoadAccelerators (hInst,"MyAccels");
- break;
-
- case WEN_GETWINDOWMENU:
-
- /* WinEdit needs the handle of the submenu to
- * append MDI document names to. The hWnd parameter
- * is used to send the handle to the main menu.
- * This message will not be sent if you return
- * NULL to the WEN_LOADMENU message.
- */
- return (UINT)GetSubMenu ((HMENU)hWnd, WINDOWMENU);
- break;
-
- case WEN_RBUTTONDOWNS:
- edHelpKeyWord(hWnd);
- break;
-
- case WEN_RBUTTONDOWN:
-
- if (!hTrackMenu)
- {
-
- hTrackMenu = CreatePopupMenu();
- if (!hTrackMenu)
- break;
-
- /* JLD 12/9/92 - Changed these labels to the Ctrl-V,X,Z, etc. which matches the
- * current pull-down labels.
- * Also changed F3 to Previous error, F4 to next error, which seems
- * more consistent. I left Re-Do as Ctrl-Backspace.
- * Added Close to this menu.
- * Added Ctrl L as a synonym for Ctrl-F5. (similar to Wordstar)
- */
-
- AppendMenu(hTrackMenu,MF_STRING,IDM_FILEOPEN,"&Open...\tF3");
- AppendMenu(hTrackMenu,MF_STRING,IDM_FILESAVE,"&Save\tF2");
- AppendMenu(hTrackMenu,MF_STRING,IDM_WINDOWCLOSE,"&Close\tCtrl+F4");
- AppendMenu(hTrackMenu,MF_STRING,IDM_FILEPRINT,"&Print\tF9");
- AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
- AppendMenu(hTrackMenu,MF_STRING,IDM_EDITUNDO,"&Undo\tCtrl+Z");
- AppendMenu(hTrackMenu,MF_STRING,IDM_EDITREDO,"&Redo\tCtrl+BkSp");
- AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
- AppendMenu(hTrackMenu,MF_STRING,IDM_EDITCUT,"Cu&t\tCtrl+X");
- AppendMenu(hTrackMenu,MF_STRING,IDM_EDITCOPY,"&Copy\tCtrl+C");
- AppendMenu(hTrackMenu,MF_STRING,IDM_EDITPASTE,"&Paste\tCtrl+V");
- AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
- AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHFIND,"&Find...\tF5");
- AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHNEXT,"&Repeat Last Find\tCtrl+F5|L");
- AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHCHANGE,"&Change...\tF6");
- AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
- AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHPREVERR,"&Previous Error\tShift+F3");
- AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHNEXTERR,"&Next Error\tShift+F4");
- AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
- AppendMenu(hTrackMenu,MF_STRING,IDM_HELPKEYWORDS,"&Key Word Help\tShift+F1");
- }
-
- if (hTrackMenu)
- {
- POINT pt;
- #ifdef WIN32
- LONG2POINT((LPARAM)lParam,pt);
- #else
- pt = MAKEPOINT(lParam);
- #endif
- TrackPopupMenu(hTrackMenu,0,pt.x-10,pt.y-6,0,hWnd,0L);
- }
-
- return TRUE;
- break;
-
- case WEN_END:
-
- /* WinEdit is shutting down. Do any clean-up processing
- * here.
- */
- if (hTrackMenu)
- {
- DestroyMenu(hTrackMenu);
- hTrackMenu = (HMENU)NULL;
- }
- return TRUE;
- break;
-
- case WEN_INITMENU:
-
- /* This message is sent before showing any drop down
- * menu items. Respond by setting any checkmarks,
- * graying any inapplicable items, etc.
- *
- */
- return InitMenu(hWnd);
- break;
-
-
- /* You can define your own commands in the range
- * WE_EXTFIRST to WE_EXTLAST that can be attached to
- * menu items or accelerators.
- */
-
- case EXT_GREP:
- {
- char szWord[64];
- edEditGetCurrentWord(hWnd,szWord,63);
- if (szWord[0])
- wsprintf(szCommand,"tee.com fgrep.com -M %s *.c",(LPSTR)szWord);
- else
- wsprintf(szCommand,GLOB_GrepCmd); /* JLD 12/9/92 see beginning of file */
-
- /* JLD 12/9/92 this *remembers* the last string if no word is selected */
-
- if (DialogBox(hInst,"CommandBox",hWnd,CommandDlgProc))
- edRunCommand(hWnd, bWait, bCapture, szCommand);
- strcpy(GLOB_GrepCmd,szCommand); /* JLD 12/9/92 save current into the GLOB var */
- return TRUE;
- break;
- }
- /* JLD 12/9/92 the following now provide braces for if and for, similar to the switch */
-
- case EXT_IF:
- {
- /* Ctrl+I: 'C' template for if ( )
- {
-
- }
- */
- UINT wColNo;
- UINT wLineNo;
-
- edEditInsertString(hWnd,"if ( )\r{\r\r}");
-
- wColNo = edGetColumnNumber(hWnd);
- wLineNo = edGetLineNumber(hWnd);
-
- edEditGoToColumn(hWnd,wColNo+4);
-
- edEditGoToLine(hWnd,wLineNo-3);
-
- return TRUE;
- break;
- }
-
-
- case EXT_FOR:
- {
- /* Ctrl+F: 'C' template for for ( ; ; )
-
- */
- UINT wColNo;
- UINT wLineNo;
-
- edEditInsertString(hWnd,"for ( ; ; )\r{\r\r}");
-
- wColNo = edGetColumnNumber(hWnd);
- wLineNo = edGetLineNumber(hWnd);
-
- edEditGoToColumn(hWnd,wColNo+5);
-
- edEditGoToLine(hWnd,wLineNo-3);
-
-
- return TRUE;
- break;
- }
-
- case EXT_SWITCH:
- {
- /* Ctrl+S: 'C' template for switch ( )
- {
-
- }
- */
- UINT wColNo;
- UINT wLineNo;
-
- edEditInsertString(hWnd,"switch ( )\r {\r\r}");
-
- wColNo = edGetColumnNumber(hWnd);
- wLineNo = edGetLineNumber(hWnd);
-
- edEditGoToColumn(hWnd,wColNo+5);
-
- edEditGoToLine(hWnd,wLineNo-3);
-
- return TRUE;
- break;
- }
-
- default:
-
- /* return NULL to all messages not processed. */
-
- break;
-
- } /* end switch (wParam) */
-
- return 0;
-
- }
-
- #ifdef WIN32
- INT APIENTRY LibMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
- {
- return 1;
- UNREFERENCED_PARAMETER(ul_reason_being_called);
- UNREFERENCED_PARAMETER(lpReserved);
- }
- #else
- BOOL APIENTRY LibMain(HANDLE hInstance, UINT wDataSeg, UINT cbHeap, LPSTR lpszCmdLine)
- {
- return TRUE;
-
- NOREF(hInstance);
- NOREF(wDataSeg);
- NOREF(cbHeap);
- NOREF(lpszCmdLine);
- }
- #endif
-
- int FAR PASCAL WEP(int nParameter)
- {
- return TRUE;
-
- NOREF(nParameter);
- }
-
-
- BOOL APIENTRY CommandDlgProc(HWND hDlg, UINT msg, UINT wParam, LONG lParam)
- {
- switch (msg)
- {
- case WM_INITDIALOG:
- CheckDlgButton(hDlg,IDD_WAIT,bWait);
- CheckDlgButton(hDlg,IDD_CAPTURE,bCapture);
- SetDlgItemText(hDlg,IDD_COMMAND,szCommand);
-
- case WM_COMMAND:
- switch(wParam)
- {
- case IDOK:
- bWait = IsDlgButtonChecked(hDlg,IDD_WAIT);
- bCapture = IsDlgButtonChecked(hDlg,IDD_CAPTURE);
- if (GetDlgItemText(hDlg,IDD_COMMAND,szCommand,sizeof(szCommand)))
- {
- EndDialog(hDlg,TRUE);
- break;
- }
- /* else fall through */
-
- case IDCANCEL:
- EndDialog(hDlg,FALSE);
- break;
-
- default:
- return (FALSE);
- }
- break;
-
- default:
- return(FALSE);
- }
- return (TRUE);
-
- NOREF(lParam);
- }
-
-
- int InitMenu(HWND hWnd)
- {
- UINT wStatus;
- HMENU hCurrentMenu;
- POINT ptStart,ptEnd;
-
- hCurrentMenu = GetMenu(hWnd);
-
- /* if there is a current selection, enable the cut & copy
- * commands.
- */
- wStatus = (UINT)edGetSelectionState(hWnd, &ptStart, &ptEnd);
- if (!wStatus)
- wStatus = MF_GRAYED;
- else
- wStatus = MF_ENABLED;
- EnableMenuItem(hCurrentMenu, IDM_EDITCUT, wStatus);
- EnableMenuItem(hCurrentMenu, IDM_EDITCOPY, wStatus);
-
- /* if there is text on the clipboard, enable the paste
- * command.
- */
- if (OpenClipboard(hWnd))
- {
- if (IsClipboardFormatAvailable(CF_TEXT)
- || IsClipboardFormatAvailable(CF_OEMTEXT))
- EnableMenuItem(hCurrentMenu, IDM_EDITPASTE, MF_ENABLED);
- else
- EnableMenuItem(hCurrentMenu, IDM_EDITPASTE, MF_GRAYED);
- CloseClipboard();
- }
- else
- EnableMenuItem(hCurrentMenu, IDM_EDITPASTE, MF_GRAYED);
-
- /* set the Undo, Redo, Insert, and WordWrap menu items */
- wStatus = (UINT)edGetUndoState(hWnd);
- if (!wStatus)
- wStatus = MF_GRAYED;
- else
- wStatus = MF_ENABLED;
- EnableMenuItem(hCurrentMenu, IDM_EDITUNDO, wStatus);
-
- wStatus = (UINT)edGetRedoState(hWnd);
- if (!wStatus)
- wStatus = MF_GRAYED;
- else
- wStatus = MF_ENABLED;
- EnableMenuItem(hCurrentMenu, IDM_EDITREDO, wStatus);
-
- wStatus = (UINT)edGetWordWrapState(hWnd);
- if (!wStatus)
- wStatus = MF_UNCHECKED;
- else
- wStatus = MF_CHECKED;
- CheckMenuItem (hCurrentMenu, IDM_EDITTOGGLEWRAP, MF_BYCOMMAND|wStatus);
-
- wStatus = (UINT)edGetInsertState(hWnd);
- if (!wStatus)
- wStatus = MF_UNCHECKED;
- else
- wStatus = MF_CHECKED;
- CheckMenuItem (hCurrentMenu, IDM_EDITTOGGLEINS, MF_BYCOMMAND|wStatus);
-
- return TRUE; /* we handled it, don't return 0 */
- }
-