📄 diag_win.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* A Product Of The */ /* Software Technology Branch */ /* NASA - Johnson Space Center */ /* */ /* CLIPS Version 6.00 10/01/92 */ /* */ /* MAIN MODULE */ /*******************************************************//**************************************************************//* Purpose: Maintains all functions for all I/O in the main *//* Dialog Window. *//* *//* Principal Programmer(s): *//* Christopher J. Ortiz *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//**************************************************************//*-------------------------------+| Windows & System Include Files |+-------------------------------*/#include <windows.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <alloc.h>/*------------------------+| CLIPS 6.0 Include Files |+------------------------*/#include "setup.h"#include "commline.h"#include "scanner.h"#include "router.h"#include "factbld.h"#include "agenda.h"/*------------------------+| Interface Include Files |+------------------------*/#include "ids.h"#include "diag_win.h"#include "main.h"#include "clipsdde.h"#include "menucmds.h"SCREEN WinDialog;int OldLine = 0;int HorizScroll = 0;#if WIN_32char **Terminal;#elsechar far **Terminal;#endifvoid SendToScreen( void );void FreeTerminalText ( void );void DeleteTerminal ( void );/********************************************************************** CreateTerminal: Initialize the structure which will hold all* the text for the terminal.*********************************************************************/void CreateTerminal ( void ){ int i;#if WIN_32 Terminal = (char **) malloc (sizeof(char *)*(DIALOG_SIZE+1));#else Terminal = (char **) farmalloc (sizeof(char *)*(DIALOG_SIZE+1));#endif if ( Terminal == NULL ) ExitToShell(); for (i=0; i<=(DIALOG_SIZE); i++) Terminal[i] = NULL;}/********************************************** Free all text associated with the Terminal ***********************************************/void FreeTerminalText ( void ){ int i; for (i=0; i<=(DIALOG_SIZE); i++) { if ( Terminal[i] != NULL )#if WIN_32 free(Terminal[i]);#else farfree ( Terminal[i] );#endif Terminal[i] = NULL; }}/********************************************** Free all text associated with the Terminal ***********************************************/void DeleteTerminal ( void ){ FreeTerminalText();#if WIN_32 free(Terminal);#else farfree(Terminal);#endif}/********************************************************************** GetUserCmd: Function used to filter/display characters typed in* from the keyboard. *********************************************************************/void GetUserCmd ( wParam, ScreenOnly, InputSize) WPARAM wParam; /* Key Code */ BOOL ScreenOnly; /* Send to Screen and or Command Buffer */ int InputSize; /* Number of characters send to screen only */ { extern int HorizScroll; /* Automatic Scrolling Enabled/Disabled */ switch (wParam) { extern SCREEN WinDialog; extern int UserInput; /*------------------+ | Handle Back Space | +------------------*/ case VK_BACK: { /*-----------------------------------------------+ | Init Values when sending to the command buffer | +-----------------------------------------------*/ if (! ScreenOnly) { HorizScroll = 1; if (GetCommandString() != NULL) { InputSize = strlen(GetCommandString()); } else { InputSize = 0; } } if (InputSize > 0 ) { int size; if (Terminal[WinDialog.LastLine] != NULL) { size = strlen(Terminal[WinDialog.LastLine]); } else { size = 0; } if (!ScreenOnly) ExpandCommandString ('\b'); if (size > 0) Terminal[WinDialog.LastLine][size - 1] = '\0'; else { int min, max; extern int OldLine; if ( Terminal[WinDialog.LastLine] != NULL ) {#if WIN_32 free(Terminal[WinDialog.LastLine]);#else farfree(Terminal[WinDialog.LastLine]);#endif Terminal[WinDialog.LastLine] = NULL; } WinDialog.LastLine --; OldLine --; if ( WinDialog.LastLine < 0 ) WinDialog.LastLine = DIALOG_SIZE; GetScrollRange (WinDialog.hWnd, SB_VERT, &min, &max); if ( WinDialog.NoLines < max && max < DIALOG_SIZE ) { SetScrollRange ( WinDialog.hWnd, SB_VERT, WinDialog.NoLines, max-1, FALSE ); SetScrollPos ( WinDialog.hWnd, SB_VERT, max-1, FALSE ); } InvalidateRect ( WinDialog.hWnd, NULL, TRUE ); } SendToScreen(); } break; } /*--------------------------+ | Remove Special Keys (ALT) | +--------------------------*/ case '\f': case VK_MENU: break; /*----------------+ | Handle Tab Keys | +----------------*/ case '\t': { if ( !ScreenOnly) { if ( GetCommandString() == NULL) SetCommandString(" "); else AppendCommandString(" "); } PrintCLIPS ("stdout", " " ); break; } /*---------------------+ | Return / Newline Key | +---------------------*/ case '\r': case '\n': { wParam = (int)'\n'; if (GetScrollPos (WinDialog.hWnd, SB_HORZ) != 0) { SetScrollPos ( WinDialog.hWnd, SB_HORZ, 0, TRUE ); InvalidateRect(WinDialog.hWnd, NULL, FALSE); SendMessage ( WinDialog.hWnd, WM_PAINT, NULL, NULL ); } } /*---------------------+ | All other characters | +---------------------*/ default: { char text[2]; text[0] = (char) wParam; text[1] = '\0'; if(isprint ( text[0]) || isspace (text[0])) { /*----------------------------+ | Add to CLIPS Command Buffer | +----------------------------*/ if (!ScreenOnly) { if ( GetCommandString() == NULL) SetCommandString(text); else AppendCommandString(text); } PrintCLIPS ("stdout", text ); } break; } } HorizScroll = 0;}/***************************************************************** DoWindowMessage: Callback function for dialog main window.* WM_COMMAND has been filtered.****************************************************************/long FAR PASCAL DoWindowMessage ( hMain, message, wParam, lParam) HWND hMain; unsigned message; WORD wParam; LONG lParam;{ switch ( message ) { case WM_CREATE: return (StartUpDDE()); case WM_KEYDOWN: { if ( wParam == VK_SHIFT ) { extern int ShiftKeyDown; ShiftKeyDown = TRUE; } break; } case WM_KEYUP: { if ( wParam == VK_SHIFT ) { extern int ShiftKeyDown; ShiftKeyDown = FALSE; } break; } case WM_CHAR: { GetUserCmd ( wParam, FALSE, 0 ); break; } case WM_ACTIVATEAPP: { extern int ApplicationFocus; ApplicationFocus = (int) wParam; if (!ApplicationFocus ) UpdateCursor( ARROW_CURSOR ); break; } case WM_TIMER: { static int value = 0; extern HCURSOR NowCursor, WAIT[]; extern int ApplicationFocus; value ++; NowCursor = WAIT[value]; if (ApplicationFocus ) SetCursor ( NowCursor ); if (value > 7 ) value = 0; break; } case WM_SETCURSOR: { extern HCURSOR NowCursor; SetCursor ( NowCursor ); break; } case WM_SETFOCUS: { extern SCREEN WinDialog; CreateCaret ( hMain, NULL, 1, WinDialog.LineSize); ShowCaret ( hMain ); break; } case WM_KILLFOCUS: { HideCaret ( hMain ); DestroyCaret(); break; } case WM_PAINT: { PAINTSTRUCT ps; HDC hDC; BeginPaint (hMain, (LPPAINTSTRUCT)&ps); hDC = ps.hdc; SetMapMode (hDC, MM_TEXT); RedrawTerminal(hDC); ValidateRect (hMain, (LPRECT)NULL); EndPaint (hMain, (LPPAINTSTRUCT)&ps); break; } case WM_SIZE: { extern SCREEN WinDialog; int min, max; GetScrollRange (hMain,SB_VERT,&min, &max); WinDialog.NoLines = (HIWORD (lParam) / WinDialog.LineSize) - 1; SetScrollRange (hMain, SB_VERT, WinDialog.NoLines, max, TRUE ); InvalidateRect ( hMain, NULL, TRUE ); switch ( wParam ) { case SIZE_MINIMIZED: PostMessage ( hMain, WM_COMMAND, IDC_WIN_MINIMIZE, NULL); break; case SIZE_RESTORED: PostMessage ( hMain, WM_COMMAND, IDC_WIN_MAXIMIZE, NULL); break; } break; } case WM_HSCROLL: { extern SCREEN WinDialog; int min, max, cp; GetScrollRange (hMain,SB_HORZ,&min, &max); cp = GetScrollPos ( hMain, SB_HORZ ); switch (wParam) { case SB_LINEDOWN: { cp++; break; } case SB_LINEUP: { cp--; break; } case SB_PAGEDOWN: { cp += WinDialog.NoLines; break; } case SB_PAGEUP: { cp -= WinDialog.NoLines; break; } case SB_THUMBTRACK: { cp = LOWORD(lParam); break; } default: { return (0); } } if (cp > max) cp = max; if (cp < min) cp = min; SetScrollPos (hMain, SB_HORZ, cp, TRUE ); InvalidateRect (hMain, NULL, TRUE ); break; } case WM_VSCROLL: { extern SCREEN WinDialog; int min, max, cp; static int CaretON = TRUE; GetScrollRange (hMain,SB_VERT,&min, &max); cp = GetScrollPos ( hMain, SB_VERT ); switch (wParam) { case SB_LINEDOWN: { cp++; break; } case SB_LINEUP: { cp--; break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -