home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------
- LOCALOPT.C -- Extension DLL for E! - version 1.0
-
- To compile: nmake /f localopt.mak
-
- Once compiled, copy LOCALOPT.EWD to your USER directory.
-
- To use this DLL simply load it from the user menu or add its name to the
- list of autoloaded Extension DLLs by using the Autoload dialog box from
- the User Menu of E!. That's all.
-
- LocalOpt allows to toggle 3 important local options (AutoInsert,
- AutoTab and AutoIndent) from the User Menu or more usefully with
- a keystroke instead of setting these values from the Local
- Options dialog box.
-
- The options are changed for the current Editor only.
-
- If you want to attach these functions to keystrokes, please use
- Routine Id = 1 for the AutoInsert toggle, RoutineId = 2 for the
- AutoTab toggle and RoutineId = 3 for the AutoIndent toggle in the
- Keyboard Assignment dialog box.
-
- If you are not interested in having the menu items defined by LocalOpt
- appear in the User Menu, create a [localopt] section in EW.INI and
- add the following entry:
-
- addtomenu=no
-
- This way, you'll only be able to assign the different LocalOpt routines
- to a keystroke but the User Menu will not be affected. In that case,
- the FuncExitHook is useless and will not be installed.
-
- If you change these options from the Local Options dialog box, the
- User Menu will keep in synch.
-
- This is a sample code. It will be easy to apply this code to other
- options, either Local or Global.
-
- ------------------------------------------------*/
-
- #include <windows.h>
- #include "ewapi.h"
- #include "string.h"
-
- #define nInsertRoutineId 1
- #define nTabRoutineId 2
- #define nIndentRoutineId 3
-
- long lInsertEntryId, lTabEntryId, lIndentEntryId;
-
- char *pszInsertSuffix = "AutoInsert";
- char *pszTabSuffix = "AutoTab";
- char *pszIndentSuffix = "AutoIndent";
-
- char *pszEnablePrefix = "Enable ";
- char *pszDisablePrefix = "Disable ";
-
- char szInsertTitle[20];
- char szTabTitle[20];
- char szIndentTitle[20];
-
- BOOL bAddToMenu;
- char *pszDefOption = "yes";
-
-
-
- void MakeTitles()
- // Prepare title strings for insertion in the User Menu
-
- {
- if (EWGetEditorLocalFlag(EWLclbAutoInsert))
- _fstrcpy(szInsertTitle, pszDisablePrefix);
- else
- _fstrcpy(szInsertTitle, pszEnablePrefix);
- _fstrcat(szInsertTitle, pszInsertSuffix);
-
- if (EWGetEditorLocalFlag(EWLclbAutoTab))
- _fstrcpy(szTabTitle, pszDisablePrefix);
- else
- _fstrcpy(szTabTitle, pszEnablePrefix);
- _fstrcat(szTabTitle, pszTabSuffix);
-
- if (EWGetEditorLocalFlag(EWLclbAutoIndent))
- _fstrcpy(szIndentTitle, pszDisablePrefix);
- else
- _fstrcpy(szIndentTitle, pszEnablePrefix);
- _fstrcat(szIndentTitle, pszIndentSuffix);
- }
-
- void RemoveMenuItems()
- // Delete items from the User Menu
-
- {
- if (lInsertEntryId)
- EWRemoveMenuEntry(lInsertEntryId);
- if (lTabEntryId)
- EWRemoveMenuEntry(lTabEntryId);
- if (lIndentEntryId)
- EWRemoveMenuEntry(lIndentEntryId);
- }
-
- void AddMenuItems()
- // Add Items to the User Menu
-
- {
- RemoveMenuItems();
- MakeTitles();
- lInsertEntryId = EWAddMenuEntry("localopt", szInsertTitle, 0, EWMNU_Extension, nInsertRoutineId);
- lTabEntryId = EWAddMenuEntry("localopt", szTabTitle, 0, EWMNU_Extension, nTabRoutineId);
- lIndentEntryId = EWAddMenuEntry("localopt", szIndentTitle, 0, EWMNU_Extension, nIndentRoutineId);
- }
-
- int FAR PASCAL _export FuncExitHook(unsigned int command, int FAR* pRetCode)
- // This hook allows to keep the Local Options dialog box and the User Menu
- // in synch. After the ew_MLSet command has been executed (Open the Local
- // Options dialog box), this hook is called by E!.
-
- {
- if (command == ew_MLSet)
- AddMenuItems();
- return(0);
- }
-
- int FAR PASCAL _export EWExecute(unsigned int RoutineId)
- // EWExecute uses the Menu Dispatching feature to decide which toggle has
- // to be changed.
-
- {
- switch (RoutineId) {
- case nInsertRoutineId: // AutoInsert toggle selected in the User Menu
- {
- EWSetEditorLocalFlag(EWLclbAutoInsert, !(BOOL)EWGetEditorLocalFlag(EWLclbAutoInsert));
- break;
- }
- case nTabRoutineId: // AutoTab toggle selected in the User Menu
- {
- EWSetEditorLocalFlag(EWLclbAutoTab, !(BOOL)EWGetEditorLocalFlag(EWLclbAutoTab));
- break;
- }
- case nIndentRoutineId: // AutoIndent toggle selected in the User Menu
- {
- EWSetEditorLocalFlag(EWLclbAutoIndent, !(BOOL)EWGetEditorLocalFlag(EWLclbAutoIndent));
- break;
- }
- default: // We do have a serious problem!
- return(ewerr_EXTFAILED);
- }
- if (bAddToMenu)
- AddMenuItems(); // Update User Menu items.
- return(0);
- }
-
- int FAR PASCAL _export WEP(int nParameter)
-
- {
- if (bAddToMenu)
- {
- // On Exit remove User Menu items...
- RemoveMenuItems();
- // ...and unregister the hook (otherwise a GPF is guaranteed)
- EWRemoveHook(EWHook_FunctionExit, FuncExitHook);
- }
- return(1);
- }
-
- int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
- LPSTR lpszCmdLine)
- {
- char szOptionValue[4];
-
- if (wHeapSize > 0)
- UnlockData (0) ;
- // Check EW.INI to see whether User Menu Insertion is allowed
- GetPrivateProfileString("localopt", "addtomenu", pszDefOption, szOptionValue, 4, "ew.ini");
- bAddToMenu = (BOOL)(_fstricmp(szOptionValue, pszDefOption) == 0);
- if (bAddToMenu)
- {
- // On entry, add the User Menu items...
- AddMenuItems();
- // ... and install the function exit hook.
- EWSetHook(EWHook_FunctionExit, FuncExitHook);
- }
- return 1 ;
- }
-
-