📄 mledit.c
字号:
/* Copyright (C) 2004-2005 Li Yudong*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include "../include/common.h"#include "../include/regclass.h"#include "../include/hdc.h"#include "../include/gdi.h"#include "../include/rect.h"#include "../include/message.h"#include "../include/blockheap.h"#include "../include/invalidregion.h"#include "../include/clipregion.h"#include "../include/caret.h"#include "../include/winnc.h"#include "../include/winbase.h"#include "../include/window.h"#include "../include/mledit.h"#include "../include/scrollbar.h"#include "../include/keyboard_pro.h"//#include "../include/skbwin.h"#include "../include/text.h"//=====================================================================================static BOOLedtGetALineFromString( char* lpString, char* pLine);static BOOLedtInitFixData( HWND hWnd);//Initial editboxox datastatic BOOLedtInitVarData( HWND hWnd, char* lpString);//destroy the editbox datastatic BOOLedtDestroyData( HWND hWnd);static BOOLedtGetText( HWND hWnd, int iLimitLen, char* buffer);static BOOLedtPenDown( HWND hWnd, int x, int y);static BOOLedtReCalTopLine( HWND hWnd);//Get Line Pointer by display Positionstatic BOOLedtGetBoxTopLineInfo( PMLEditData pEditData, PLineData* ppRetLineData, int* pStartPos);//Get display string by line numberstatic BOOLedtGetDispString( PLineData* ppLineData, int iLineNumber, char* pStrDisp);//Draw EditBox Textstatic BOOLedtDrawEditBoxText( HWND hWnd, HDC hDC);static BOOLedtCalCaretPos( HWND hWnd, int* px, int* py);static BOOLedtSetEditPos( HWND hWnd);static BOOLedtGetStrPointerByLineNumber( PLineData* ppLineData, int iLineNumber, char** ppString //return the string pointer );static BOOLedtGetValidRect( HWND hWnd, LPRECT lpRect);static BOOLedtIsACChar( char* pString);static BOOLedtIsACCharBeforePos( char* pBuffer);static BOOLedtIsCarry( char* pString);static BOOLedtIsReadOnly( HWND hWnd);static BOOLedtIsFocus( HWND hWnd);static BOOLedtIsVScroll( HWND hWnd);static BOOLedtIsReplace( HWND hWnd);//get pLineData->pString by edit positionstatic BOOLedtGetCurLineData( PMLEditData pEditData, PLineData* ppLineData);//whether caret at begin position of pLineData->pStringstatic BOOL edtIsCaretAtLineBegin( PMLEditData pEditData);//whether caret at end position of pLineData->pStringstatic BOOLedtIsCaretAtLineEnd( PMLEditData pEditData);static BOOLedtReIndexDataAfterInsLine( PMLEditData pEditData, PLineData pCurLineData);static BOOLedtInsLineDataAfter( PMLEditData pEditData, PLineData pCurLineData);static BOOLedtInsLineDataBefore( PMLEditData pEditData, PLineData pCurLineData);static BOOLedtReIndexDataAfterBreak( PMLEditData pEditData, PLineData pCurLineData);static BOOLedtBreakLineAtCurPos( PMLEditData pEditData, PLineData pCurLineData);////////////////////////////////////////////Key Down///////////////////////////////////////////==================== ENTER ========================static BOOLedtScanCodeEnter( HWND hWnd);//==================== HOME ========================static BOOLedtScanCodeHome( HWND hWnd);//==================== END ========================static BOOLedtScanCodeEnd( HWND hWnd);//==================== LEFT ========================static BOOLedtScanCodeLeft( HWND hWnd);//==================== RIGHT========================static BOOLedtScanCodeRight( HWND hWnd);static BOOLedtReCalCaretXPos( PMLEditData pEditData, int iPrevCaretYPos, int *px);static BOOLedtReCalCaretXPosNoRef( PMLEditData pEditData, int *px);//==================== UP ========================static BOOLedtScanCodeUp( HWND hWnd);//==================== Down ========================static BOOLedtScanCodeDown( HWND hWnd);//==================== Ins ========================static BOOLedtScanCodeIns( HWND hWnd);static BOOLedtReIndexDataAfterDelChar( PMLEditData pEditData, PLineData pCurLineData);static BOOLedtReIndexDataAfterDelWrapLine( PMLEditData pEditData, PLineData pCurLineData);static BOOLedtReIndexDataAfterDelLine( PMLEditData pEditData, PLineData pCurLineData);static BOOLedtCombineAdjLine( PMLEditData pEditData, PLineData pLineData);//==================== Del ========================static BOOLedtScanCodeDel( HWND hWnd);//==================== BackSpace ========================static BOOLedtScanCodeBackSpace( HWND hWnd);//==================== PageUp ========================static BOOLedtScanCodePageUp( HWND hWnd);//==================== PageDown ========================static BOOLedtScanCodePageDown( HWND hWnd);//==================== CHAR ========================static BOOLedtProChar( HWND hWnd, char* charBuffer, int iChars);static BOOLedtProCharInsert( HWND hWnd, char* charBuffer, int iChars);static BOOLedtReplaceChar( char* pString, char* pChars, int iChars, int* pReplaced);static BOOLedtProCharReplace( HWND hWnd, char* charBuffer, int iChars);//======== scroll ==========static void edtSetVScrollInfo ( HWND hWnd, PMLEditData pEditData, BOOL fRedraw);//=======================================================================================//注册窗口类BOOL RegisterMLEditControl(){ WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = 0; wcex.lpfnWndProc = (WNDPROC)MLEditCtrlProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = 0; wcex.hIcon = 0; wcex.hCursor = 0; wcex.hbrBackground = CreateSolidBrush(RGB(198,239,229)); wcex.lpszMenuName = NULL; wcex.lpszClassName = "mledit"; wcex.hIconSm = 0; RegisterClass(&wcex); return true;}LRESULT MLEditCtrlProc( HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam){// PLineData pLineData; PMLEditData pEditData; PWindowsTree pWin; pWin = (PWindowsTree)hWnd; switch(iMsg){ case LMSG_CREATE: { int x,y; pEditData = (PMLEditData)malloc(sizeof(MLEditData)); if(!pEditData) return false; memset(pEditData,0,sizeof(MLEditData)); pWin->dwData = (DWORD)pEditData; edtInitFixData(hWnd); edtInitVarData(hWnd,pWin->lpszCaption); //init edit position edtSetEditPos(hWnd); CreateCaret(hWnd,NULL,1,pEditData->iLineHeight); edtCalCaretPos(hWnd,&x,&y); SetCaretPos(hWnd,x,y); edtSetVScrollInfo(hWnd, pEditData, false); SetTimer(hWnd,1,50,NULL); break; } case LMSG_TIMER: { BlinkCaret(hWnd); break; } case LMSG_ERASEBKGND: { PWNDCLASSEX pWndClass; HBRUSH hBrush; COLORREF crColor; LRESULT res; pWndClass=GetRegClass(pWin->lpszClassName); if(!pWndClass) return (LRESULT)NULL; //is Enable ? hBrush=pWndClass->hbrBackground; crColor=((BRUSH*)hBrush)->crBrushColor; if(!IsEnable(hWnd)) ((BRUSH*)hBrush)->crBrushColor=RGB_SYSTEMLTGRAY; else ((BRUSH*)hBrush)->crBrushColor=RGB_SYSTEMWHITE; res=DefWindowProc(hWnd, iMsg, wParam, lParam); ((BRUSH*)hBrush)->crBrushColor=crColor; return res; } case LMSG_NCPAINT: { PWindowsTree pWin; BOOL bVScroll; RECT rcVBar; LPSCROLLCURSTATE pCurState; RECT rect; HDC hDC; HPEN hPen; POINT point; GetWindowRect(hWnd,&rect); SetRect(&rect,0,0,rect.right-rect.left,rect.bottom-rect.top); if(IsBorder(hWnd)){ hDC = (HDC)wParam; if(!hDC) return false; hPen=CreatePen(PS_SOLID,1,RGB(88,87,81)); SelectObject(hDC,hPen); DeleteObject(hPen); winMoveToEx(hDC,rect.left,rect.top,&point); winLineTo(hDC,rect.right,rect.top); winMoveToEx(hDC,rect.left,rect.top,&point); winLineTo(hDC,rect.left,rect.bottom); hPen=GetStockObject(LTGRAY_PEN); SelectObject(hDC,hPen); DeleteObject(hPen); winMoveToEx(hDC,rect.right,rect.top+1,&point); winLineTo(hDC,rect.right,rect.bottom); winMoveToEx(hDC,rect.right,rect.bottom,&point); winLineTo(hDC,rect.left,rect.bottom); } pWin=(PWindowsTree)hWnd; if(!pWin) return false; if(pWin->dwStyle & WS_VSCROLL) bVScroll = true; else bVScroll = false; //draw bound //wndDrawNCArea(hWnd, hDC); //draw vert scroll if(bVScroll){ pCurState = pWin->pVCurState; wndGetVScrollBarRect(hWnd,&rcVBar); ScreenToWindowRect(hWnd,&rcVBar); wndDrawVScrollBar(&rcVBar,hDC,pWin->pVScroll->dwStatus,pCurState); } break; } case LMSG_PAINT: { RECT rect; HDC hDC; PAINTSTRUCT ps; ps.bPaintDirect=false; hDC=BeginPaint(hWnd, &ps); if(!hDC){ return true; } if(IsFocus(hWnd)){ HideCaret(hWnd); } edtDrawEditBoxText(hWnd,hDC); EndPaint(hWnd, &ps); if(IsFocus(hWnd)){ ShowCaret(hWnd); SetTimer(hWnd,1,50); } break; } case LMSG_DESTROY: DestroyCaret(hWnd); KillTimer(hWnd,1); edtDestroyData(hWnd); break; case LMSG_KILLFOCUS: { if(!edtIsFocus(hWnd)) break; pEditData = (PMLEditData)(pWin->dwData); pEditData->dwStatus &= ~ EST_FOCUSED; HideCaret(hWnd); NotifyParent(hWnd, EN_KILLFOCUS); break; } case LMSG_SETFOCUS: { int x, y; if(edtIsReadOnly(hWnd)) break; if(edtIsFocus(hWnd)) break; pEditData = (PMLEditData)(pWin->dwData); if(!pEditData) return false; pEditData->dwStatus |= EST_FOCUSED; edtCalCaretPos(hWnd,&x,&y); SetCaretPos(hWnd,x,y); ShowCaret(hWnd); NotifyParent(hWnd, EN_SETFOCUS); break; } case LMSG_GETTEXTLENGTH: { pEditData = (PMLEditData)(pWin->dwData); if(!pEditData) return false; return pEditData->iTotalLen; } case LMSG_GETTEXT: { edtGetText(hWnd,(int)wParam,(char*)lParam); break; } case LMSG_SETTEXT: { int x, y; if(edtIsReadOnly(hWnd)) break; pEditData = (PMLEditData)(pWin->dwData); if(!pEditData) return false; edtInitVarData(hWnd,(char*)lParam); pEditData->iDispPos = 0; pEditData->iCaretXPos = 0; pEditData->iCaretYPos = 0; edtSetEditPos(hWnd); //set edit position edtCalCaretPos(hWnd,&x,&y); SetCaretPos(hWnd,x,y); InvalidateRect(hWnd,NULL,true); break; } case EM_SETREADONLY: { pEditData = (PMLEditData)(pWin->dwData); if(wParam){ pEditData->dwStatus |= EST_READONLY; } else{ pEditData->dwStatus &= ~EST_READONLY; } break; } case LMSG_PENDOWN: { int x,y; x = (int)wParam; y = (int)lParam;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -