📄 edit.c
字号:
return 0; case MSG_FONTCHANGED: { int starty; starty = sled->topMargin + ( sled->rcCont.bottom - sled->rcCont.top - GetWindowFont (hWnd)->size - 1 ) / 2; sled->editPos = 0; DestroyCaret (hWnd); CreateCaret (hWnd, NULL, 1, GetWindowFont (hWnd)->size); SetCaretPos (hWnd, sled->leftMargin, starty); InvalidateRect (hWnd, NULL, TRUE); return 0; } case MSG_SETCURSOR: if (dwStyle & WS_DISABLED) { SetCursor (GetSystemCursor (IDC_ARROW)); return 0; } break; case MSG_KILLFOCUS: if (sled->status & EST_FOCUSED) { BOOL refresh = FALSE; sled->status &= ~EST_FOCUSED; HideCaret (hWnd); if ( sled->selStart != sled->selEnd || (dwStyle & ES_TIP && sled->content.txtlen <= 0)) { refresh = TRUE; } if (sled->selStart != sled->selEnd && !(dwStyle & ES_NOHIDESEL)) sled->selStart = sled->selEnd = sled->editPos; if (refresh) InvalidateRect (hWnd, NULL, TRUE); NotifyParent (hWnd, GetDlgCtrlID(hWnd), EN_KILLFOCUS); } break; case MSG_SETFOCUS: if (sled->status & EST_FOCUSED) break; sled->status |= EST_FOCUSED; ActiveCaret (hWnd); ShowCaret(hWnd); if (dwStyle & ES_AUTOSELECT) { if (sleSetSel (hWnd, sled, 0, sled->content.txtlen) <= 0 && dwStyle & ES_TIP) InvalidateRect (hWnd, NULL, TRUE); if (lParam == 1) sled->status |= EST_TMP; } else if ( (dwStyle & ES_NOHIDESEL && sled->selStart != sled->selEnd) || (dwStyle & ES_TIP && sled->content.txtlen <= 0)) { InvalidateRect (hWnd, NULL, TRUE); } NotifyParent (hWnd, GetDlgCtrlID(hWnd), EN_SETFOCUS); break; case MSG_ENABLE: if ( (!(dwStyle & WS_DISABLED) && !wParam) || ((dwStyle & WS_DISABLED) && wParam) ) { if (wParam) ExcludeWindowStyle(hWnd,WS_DISABLED); else IncludeWindowStyle(hWnd,WS_DISABLED); InvalidateRect (hWnd, NULL, TRUE); } return 0; case MSG_GETTEXTLENGTH: return sled->content.txtlen; case MSG_GETTEXT: { char* buffer = (char*)lParam; int len; len = MIN ((int)wParam, sled->content.txtlen); memcpy (buffer, sled->content.string, len); buffer [len] = '\0'; return len; } case MSG_SETTEXT: { if (lParam == 0) return -1; sledit_settext (sled, (const char*)lParam); sled->selStart = sled->selEnd = 0; if ( wParam == 1 && !(GetWindowStyle(hWnd) & ES_READONLY) ) { sled->editPos = sled->content.txtlen; sled->selStart = sled->selEnd = sled->editPos; edtSetCaretPos (hWnd, sled); } else { sled->editPos = 0; SetCaretPos (hWnd, sled->leftMargin, sled->starty); } InvalidateRect (hWnd, NULL, TRUE); return 0; } case MSG_KEYDOWN: { return sleKeyDown (hWnd, wParam, lParam); } case MSG_CHAR: { unsigned char charBuffer [2]; int chars; if (wParam == 127) // BS wParam = '\b'; if (dwStyle & ES_READONLY) return 0; if (HIBYTE (wParam)) { charBuffer [0] = LOBYTE (wParam); charBuffer [1] = HIBYTE (wParam); chars = 2; } else { chars = 1; if (dwStyle & ES_UPPERCASE) { charBuffer [0] = toupper (LOBYTE (wParam)); } else if (dwStyle & ES_LOWERCASE) { charBuffer [0] = tolower (LOBYTE (wParam)); } else charBuffer [0] = LOBYTE (wParam); } if (chars == 1) { if (charBuffer [0] < 0x20 && charBuffer[0] != '\b') //FIXME return 0; } if (wParam == '\b') { //backspace int del; if (sled->editPos == 0 && sled->selStart == sled->selEnd) return 0; del = - CHLENPREV( sled->content.string, (sled->content.string + sled->editPos) ); sleInsertText (hWnd, sled, NULL, del); } else { sleInsertText (hWnd, sled, charBuffer, chars); } return 0; } case MSG_LBUTTONDBLCLK: sleSetSel (hWnd, sled, 0, sled->content.txtlen); NotifyParent (hWnd, GetDlgCtrlID(hWnd), EN_DBLCLK); break; case MSG_LBUTTONDOWN: { if ( sled->status & EST_TMP) { sled->status &= ~EST_TMP; break; } if (HISWORD(lParam) < sled->rcCont.top || HISWORD(lParam) > sled->rcCont.bottom) break; set_caret_pos (hWnd, sled, LOSWORD(lParam), FALSE); ActiveCaret (hWnd); ShowCaret(hWnd); SetCapture(hWnd); InvalidateRect(hWnd, NULL, TRUE); NotifyParent (hWnd, GetDlgCtrlID(hWnd), EN_CLICKED); break; } case MSG_NCLBUTTONUP: case MSG_LBUTTONUP: if (GetCapture() == hWnd) ReleaseCapture(); break; case MSG_MOUSEMOVE: { if (GetCapture () == hWnd) sleMouseMove (hWnd, sled, lParam); return 0; } case MSG_GETDLGCODE: return DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS | DLGC_WANTENTER; case MSG_DOESNEEDIME: if (dwStyle & ES_READONLY) return FALSE; return TRUE; case EM_GETCARETPOS: case EM_GETSELPOS: { int nr_chars, pos; int* line_pos = (int *)wParam; int* char_pos = (int *)lParam; if (message == EM_GETSELPOS) pos = (sled->editPos == sled->selStart) ? sled->selEnd : sled->selStart; else pos = sled->editPos; nr_chars = GetTextMCharInfo (GetWindowFont (hWnd), sled->content.string, pos, NULL); if (line_pos) *line_pos = 0; if (char_pos) *char_pos = nr_chars; return pos; } case EM_SETCARETPOS: case EM_SETSEL: { int char_pos = (int)lParam; int nr_chars, pos; int *pos_chars; if (char_pos < 0) return -1; pos_chars = ALLOCATE_LOCAL (sled->content.txtlen * sizeof(int)); nr_chars = GetTextMCharInfo (GetWindowFont (hWnd), sled->content.string, sled->content.txtlen, pos_chars); if (char_pos > nr_chars) { DEALLOCATE_LOCAL (pos_chars); return -1; } if (char_pos == nr_chars) pos = sled->content.txtlen; else pos = pos_chars[char_pos]; DEALLOCATE_LOCAL (pos_chars); if (message == EM_SETCARETPOS) { sled->editPos = pos; sled->selStart = sled->selEnd = 0; edtSetCaretPos (hWnd, sled); return sled->editPos; } else { int start, end; if (sled->editPos < pos) { start = sled->editPos; end = pos; } else { start = pos; end = sled->editPos; } return sleSetSel (hWnd, sled, start, end); } } case EM_SETREADONLY: if (wParam) IncludeWindowStyle (hWnd, ES_READONLY); else ExcludeWindowStyle (hWnd, ES_READONLY); return 0; case EM_SETPASSWORDCHAR: if (sled->passwdChar != (int)wParam) { if (dwStyle & ES_PASSWORD) { sled->passwdChar = (int)wParam; InvalidateRect (hWnd, NULL, TRUE); } } return 0; case EM_GETPASSWORDCHAR: { if (lParam) *((int*)lParam) = sled->passwdChar; return 0; } case EM_LIMITTEXT: { int newLimit = (int)wParam; if (newLimit >= 0) { if (sled->content.buffsize < newLimit) sled->hardLimit = -1; else sled->hardLimit = newLimit; } return 0; } case EM_GETTIPTEXT: { int len, tip_len; char *buffer = (char *)lParam; if (!(dwStyle & ES_TIP)) return -1; tip_len = strlen (sled->tiptext); if (!buffer) return tip_len; if (wParam >= 0) len = (wParam > DEF_TIP_LEN) ? DEF_TIP_LEN : wParam; else len = DEF_TIP_LEN; strncpy (buffer, sled->tiptext, len); buffer[len] = '\0'; return tip_len; } case EM_SETTIPTEXT: { int len; if (!(dwStyle & ES_TIP) || !lParam) return -1; if (wParam >= 0) len = (wParam > DEF_TIP_LEN) ? DEF_TIP_LEN : wParam; else len = DEF_TIP_LEN; strncpy (sled->tiptext, (char *)lParam, len); sled->tiptext[len] = '\0'; if (sled->content.txtlen <= 0) InvalidateRect (hWnd, NULL, TRUE); return strlen(sled->tiptext); } case EM_GETSEL: { char *buffer = (char *)lParam; int len; if (!buffer || sled->selEnd - sled->selStart <= 0) return 0; if (wParam < 0) len = sled->selEnd - sled->selStart; else len = MIN(sled->selEnd - sled->selStart, (int)wParam); strncpy (buffer, sled->content.string + sled->selStart, len); return len; } case EM_INSERTCBTEXT: { return sleInsertCbText (hWnd, sled); } case EM_COPYTOCB: case EM_CUTTOCB: { if (sled->selEnd - sled->selStart > 0) { SetClipBoardData (CBNAME_TEXT, sled->content.string + sled->selStart, sled->selEnd - sled->selStart, CBOP_NORMAL); if (message == EM_CUTTOCB && !(GetWindowStyle(hWnd) & ES_READONLY)) { sleInsertText (hWnd, sled, NULL, 0); } return sled->selEnd - sled->selStart; } return 0; } default: break; } // end switch return DefaultControlProc (hWnd, message, wParam, lParam);}#endif /* _CTRL_SLEDIT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -