// ----------------------------------------------------------------------------------- bool cgUILineEdit::OnMessage( UINT uMsg, unsigned wparam, unsigned lparam ) { switch (uMsg) { case WM_LBUTTONDOWN: { OnLButtonDown(wparam, lparam); }break; case WM_MOUSEMOVE: { OnMouseMove(wparam, lparam); }break; case WM_CHAR: { return OnChar(wparam, lparam); }break; case WM_KEYDOWN: { if ( OnKeyDown(wparam, lparam)) return true; }break; case WM_LBUTTONDBLCLK: { SetSelBegin(0); SetCursorPos(m_strText.length()); }break; case cgUIMsg_Copy: { return OnCopy(); }break; case cgUIMsg_Cut: { return OnCut(); }break; case cgUIMsg_Paste: { return OnPaste(); }break; case cgUIMsg_MouseOut: { OnMouseMove(wparam, lparam); }break; case cgUIMsg_MouseIn: { } default: break; } return cgUIWidget::OnMessage(uMsg, wparam, lparam); }
void EditorBase::InitActions() { mNewAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this); mNewAct->setShortcut(tr("Ctrl+N")); mNewAct->setStatusTip(tr("Create a new file")); connect(mNewAct, SIGNAL(triggered()), this, SLOT(OnNew())); mOpenAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); mOpenAct->setShortcut(tr("Ctrl+O")); mOpenAct->setStatusTip(tr("Open an existing file")); connect(mOpenAct, SIGNAL(triggered()), this, SLOT(OnOpen())); mSaveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this); mSaveAct->setShortcut(tr("Ctrl+S")); mSaveAct->setStatusTip(tr("Save the document to disk")); connect(mSaveAct, SIGNAL(triggered()), this, SLOT(OnSave())); mSaveAsAct = new QAction(tr("Save &As..."), this); mSaveAsAct->setStatusTip(tr("Save the document under a new name")); connect(mSaveAsAct, SIGNAL(triggered()), this, SLOT(OnSaveAs())); mExitAct = new QAction(tr("E&xit"), this); mExitAct->setShortcut(tr("Ctrl+Q")); mExitAct->setStatusTip(tr("Exit the application")); connect(mExitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); mCutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this); mCutAct->setShortcut(tr("Ctrl+X")); mCutAct->setStatusTip(tr("Cut the current selection's contents to the clipboard")); connect(mCutAct, SIGNAL(triggered()), this, SLOT(OnCut())); mCopyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this); mCopyAct->setShortcut(tr("Ctrl+C")); mCopyAct->setStatusTip(tr("Copy the current selection's contents to the clipboard")); connect(mCopyAct, SIGNAL(triggered()), this, SLOT(OnCopy())); mPasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this); mPasteAct->setShortcut(tr("Ctrl+V")); mPasteAct->setStatusTip(tr("Paste the clipboard's contents into the current selection")); connect(mPasteAct, SIGNAL(triggered()), this, SLOT(OnPaste())); mSeparatorAct = new QAction(this); mSeparatorAct->setSeparator(true); mAboutAct = new QAction(tr("&About"), this); mAboutAct->setStatusTip(tr("Show the application's About box")); connect(mAboutAct, SIGNAL(triggered()), this, SLOT(OnAbout())); mAboutQtAct = new QAction(tr("About &Qt"), this); mAboutQtAct->setStatusTip(tr("Show the Qt library's About box")); connect(mAboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); }
// // Process keyboard-navigation keys // LONG TextViewBase::OnKeyDown(UINT nKeyCode, UINT nFlags) { bool fCtrlDown = IsKeyPressed(VK_CONTROL); bool fShiftDown = IsKeyPressed(VK_SHIFT); BOOL fAdvancing = FALSE; long oldCursorOffset = m_nSelectionEnd; // // Process the key-press. Cursor movement is different depending // on if <ctrl> is held down or not, so act accordingly // switch(nKeyCode) { case VK_SHIFT: case VK_CONTROL: return 0; case 'a': case 'A': { if(fCtrlDown) SelectAll(); } return 0; // CTRL+Z undo case 'z': case 'Z': if(fCtrlDown && Undo()) /*NotifyParent(TVN_CHANGED);*/ return 0; // CTRL+Y redo case 'y': case 'Y': if(fCtrlDown && Redo()) //NotifyParent(TVN_CHANGED); return 0; // CTRL+C copy case 'c': case 'C': { //if(fCtrlDown && Redo()) // NotifyParent(TVN_CHANGED); if(fCtrlDown) return OnCopy(); else break; } case 'x': case 'X': { if(fCtrlDown) return OnCut(); else break; } case 'v': case 'V': { if(fCtrlDown) return OnPaste(); else break; } // Change insert mode / clipboard copy&paste case VK_INSERT: if(fCtrlDown) { OnCopy(); NotifyParent(TVN_CHANGED); } else if(fShiftDown) { OnPaste(); NotifyParent(TVN_CHANGED); } else { if(m_nEditMode == MODE_INSERT) m_nEditMode = MODE_OVERWRITE; else if(m_nEditMode == MODE_OVERWRITE) m_nEditMode = MODE_INSERT; NotifyParent(TVN_EDITMODE_CHANGE); } return 0; case VK_DELETE: if(m_nEditMode != MODE_READONLY) { if(fShiftDown) OnCut(); else ForwardDelete(); NotifyParent(TVN_CHANGED); } return 0; case VK_BACK: if(m_nEditMode != MODE_READONLY) { BackDelete(); fAdvancing = FALSE; NotifyParent(TVN_CHANGED); } return 0; case VK_LEFT: if(fCtrlDown) MoveWordPrev(); else MoveCharPrev(); fAdvancing = FALSE; break; case VK_RIGHT: if(fCtrlDown) MoveWordNext(); else MoveCharNext(); fAdvancing = TRUE; break; case VK_UP: if(fCtrlDown) Scroll(0, -1); else MoveLineUp(1); break; case VK_DOWN: if(fCtrlDown) Scroll(0, 1); else MoveLineDown(1); break; case VK_PRIOR: if(!fCtrlDown) MovePageUp(); break; case VK_NEXT: if(!fCtrlDown) MovePageDown(); break; case VK_HOME: if(fCtrlDown) MoveFileStart(); else MoveLineStart(m_nCurrentLine); break; case VK_END: if(fCtrlDown) MoveFileEnd(); else MoveLineEnd(m_nCurrentLine); break; default: return 0; } // Extend selection if <shift> is down if(fShiftDown) { InvalidateRange(m_nSelectionEnd, oldCursorOffset); //m_nSelectionEnd = m_nCursorOffset; } // Otherwise clear the selection else { if(m_nSelectionStart != m_nSelectionEnd) InvalidateRange(m_nSelectionStart, m_nSelectionEnd); //m_nSelectionEnd = m_nCursorOffset; m_nSelectionStart = m_nSelectionEnd; } // update caret-location (xpos, line#) from the offset //UpdateCaretOffset(m_nCursorOffset, fAdvancing, &m_nCaretPosX, &m_nCurrentLine); CHAR_POS cp; FilePosToCharPos(m_nSelectionEnd, &cp); m_nCurrentLine_D = cp.logLine; // maintain the caret 'anchor' position *except* for up/down actions if(nKeyCode != VK_UP && nKeyCode != VK_DOWN) { //m_nAnchorPosX = m_nCaretPosX; // scroll as necessary to keep caret within viewport //ScrollToPosition(m_nCaretPosX, m_nCurrentLine); } else { // scroll as necessary to keep caret within viewport if(!fCtrlDown); //ScrollToPosition(m_nCaretPosX, m_nCurrentLine); } NotifyParent(TVN_CURSOR_CHANGE); return 0; }
bool TextViewBase::HandleWndProc(UINT msg, WPARAM wParam, LPARAM lParam, LONG *pResult) { HIMC hIMC = NULL; switch (msg) { // Draw contents of TextView whenever window needs updating case WM_ERASEBKGND: *pResult = 1; return true; // Need to custom-draw the border for XP/Vista themes case WM_NCPAINT: *pResult = OnNcPaint((HRGN)wParam); return true; case WM_PAINT: *pResult = OnPaint(); return true; // Set a new font case WM_SETFONT: *pResult = OnSetFont((HFONT)wParam); return true; case WM_SIZE: *pResult = OnSize(wParam, LOWORD(lParam), HIWORD(lParam)); return true; case WM_VSCROLL: *pResult = OnVScroll(LOWORD(wParam), HIWORD(wParam)); return true; case WM_HSCROLL: *pResult = OnHScroll(LOWORD(wParam), HIWORD(wParam)); return true; case WM_MOUSEACTIVATE: *pResult = OnMouseActivate((HWND)wParam, LOWORD(lParam), HIWORD(lParam)); return true; //case WM_CONTEXTMENU: // return OnContextMenu((HWND)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam)); case WM_MOUSEWHEEL: if (IsKeyPressed(VK_CONTROL)) return false; else *pResult = OnMouseWheel((short)HIWORD(wParam)); return true; case WM_SETFOCUS: *pResult = OnSetFocus((HWND)wParam); return true; case WM_KILLFOCUS: *pResult = OnKillFocus((HWND)wParam); return true; // make sure we get arrow-keys, enter, tab, etc when hosted inside a dialog case WM_GETDLGCODE: *pResult = DLGC_WANTALLKEYS;//DLGC_WANTMESSAGE;//DLGC_WANTARROWS; return true; case WM_LBUTTONDOWN: *pResult = OnLButtonDown(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam)); return true; case WM_LBUTTONUP: *pResult = OnLButtonUp(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam)); return true; case WM_LBUTTONDBLCLK: *pResult = OnLButtonDblClick(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam)); return true; case WM_RBUTTONDOWN: *pResult = OnRButtonDown(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam)); return true; case WM_MOUSEMOVE: *pResult = OnMouseMove(wParam, (short)LOWORD(lParam), (short)HIWORD(lParam)); return true; case WM_KEYDOWN: *pResult = OnKeyDown(wParam, lParam); return true; case WM_UNDO: case TXM_UNDO: case EM_UNDO: *pResult = Undo(); return true; case TXM_REDO : case EM_REDO: *pResult = Redo(); return true; case TXM_CANUNDO: case EM_CANUNDO: *pResult = CanUndo(); return true; case TXM_CANREDO: case EM_CANREDO: *pResult = CanRedo(); return true; case WM_CHAR: OutputDebugString(L"WM_CHAR\n"); *pResult = OnChar(wParam, lParam); return true; case WM_SETCURSOR: if (LOWORD(lParam) == HTCLIENT) { *pResult = TRUE; return true; } else return false; case WM_COPY: *pResult = OnCopy(); return true; case WM_CUT: *pResult = OnCut(); return true; case WM_PASTE: *pResult = OnPaste(); return true; case WM_CLEAR: *pResult = OnClear(); return true; case WM_GETTEXT: *pResult = GetText((WCHAR*)lParam, 0, (ULONG)wParam); return true; case WM_SETTEXT: *pResult = OnSetText((WCHAR*)lParam, lstrlen((WCHAR*)lParam)); return true; //case TXM_SETTEXT: // { // ClearFile(); // EnterText((WCHAR*)lParam, (LONG)wParam); // return 0; // } case WM_TIMER: *pResult = OnTimer(wParam); return true; case WM_IME_STARTCOMPOSITION: OutputDebugString(L"WM_IME_STARTCOMPOSITION\n"); *pResult = OnStartComposition(wParam, lParam); return true; //return DefWindowProc(m_hWnd, WM_IME_STARTCOMPOSITION, wParam, lParam); case WM_IME_COMPOSITION: OutputDebugString(L"WM_IME_COMPOSITION\n"); *pResult = DefWindowProc(m_hWnd, WM_IME_COMPOSITION, wParam, lParam); return true; //return OnComposition(wParam, lParam); case WM_IME_ENDCOMPOSITION: OutputDebugString(L"WM_IME_ENDCOMPOSITION\n"); *pResult = DefWindowProc(m_hWnd, WM_IME_ENDCOMPOSITION, wParam, lParam); return true; //return OnEndComposition(wParam, lParam); case WM_IME_CHAR: OutputDebugString(L"WM_IME_CHAR\n"); *pResult = DefWindowProc(m_hWnd, WM_IME_CHAR, wParam, lParam); return true; case WM_IME_CONTROL: OutputDebugString(L"WM_IME_CONTROL\n"); *pResult = DefWindowProc(m_hWnd, WM_IME_CONTROL, wParam, lParam); return true; case WM_IME_NOTIFY: OutputDebugString(L"WM_IME_NOTIFY\n"); *pResult = DefWindowProc(m_hWnd, WM_IME_NOTIFY, wParam, lParam); return true; //return HandleImeNotify(wParam, lParam); case WM_IME_REQUEST: OutputDebugString(L"WM_IME_REQUEST\n"); *pResult = DefWindowProc(m_hWnd, WM_IME_REQUEST, wParam, lParam); return true; case WM_INPUTLANGCHANGE: *pResult = OnInputLanChange(wParam, lParam); return true; case TXM_PRINT: *pResult = OnPrint((HDC)wParam, (int)lParam); return true; // case TXM_OPENFILE: *pResult = OpenFile((TCHAR *)lParam); return true; case TXM_SAVEFILE: *pResult = SaveFile((TCHAR *)lParam); return true; case TXM_IMPORTFILE: *pResult = ImportFile((TCHAR *)lParam, (int)wParam); return true; case TXM_EXPORTFILE: { int convertype = LOWORD(wParam); int utf_type = HIWORD(wParam); *pResult = ExportFile((TCHAR *)lParam, convertype, utf_type); return true; } case TXM_CLEAR: *pResult = ClearFile(); return true; case TXM_GETFORMAT: *pResult = m_pTextDoc->getformat(); return true; case TXM_SETFORMAT: *pResult = m_pTextDoc->setformat((int)wParam); return true; case TXM_GETSELSIZE: *pResult = SelectionSize(); return true; case TXM_SETSELALL: *pResult = SelectAll(); return true; case TXM_GETCURPOS: *pResult = m_CurrentCharPos.get(); return true; case TXM_GETCURLINE_D: *pResult = m_nCurrentLine_D; return true; case TXM_GETCURLINE_V: *pResult = OnGetCurLineV(); return true; case TXM_GETCURCOL: *pResult = OnGetCurCol(); return true; case TXM_GETEDITMODE: *pResult = m_nEditMode; return true; case TXM_SETEDITMODE: lParam = m_nEditMode; m_nEditMode = wParam; *pResult = lParam; return true; case TXM_FIND_INIT: FindInitial((WCHAR*)lParam); *pResult = 0; return true; case TXM_FIND: { BOOL m = (BOOL)LOWORD(wParam); BOOL b = (BOOL)HIWORD(wParam); //FindText() if (b) *pResult = FindBackward(m, NULL); else *pResult = FindForward(m, NULL); return true; } case TXM_FIND_TEXT: { FIND_OPTION* fp = (FIND_OPTION*)(lParam); *pResult = Find_Text(fp->text, lstrlen(fp->text), fp->fBackward, fp->fMachCase, fp->fWarp); return true; } case TXM_REPLACE_TEXT: { *pResult = Replace_Text((REPLACE_OPTION*)(lParam)); return true; } case TXM_SETRESMODULE: { *pResult = OnSetResModule((HMODULE)lParam); return true; } case WM_GETTEXTLENGTH: case TXM_GETTEXTLEN: { *pResult = OnGetTextLen(); return true; } case TXM_REPLACE: { BOOL ra = (BOOL)LOWORD(wParam); WORD mb = (WORD)HIWORD(wParam); BOOL m = (BOOL)LOBYTE(mb); BOOL b = (BOOL)HIBYTE(mb); if (b) *pResult = FindBackward(m, (WCHAR*)lParam, ra); else *pResult = FindForward(m, (WCHAR*)lParam, ra); return true; } case TXM_FIND_GETTEXTLENGTH: *pResult = m_pFndIterator->find_text_length(); return true; case TXM_GETSELSTART: *pResult = m_nSelectionStart; return true; case TXM_GETSELEND: *pResult = m_nSelectionEnd; return true; case TXM_GETSELTEXT: *pResult = OnGetSelText((WCHAR*)wParam, ULONG(lParam)); return true; case TXM_SETTESTERMODE: OnTesterMode((bool)wParam); *pResult = 0; return true; case TXM_SETCONTEXTMENU: m_hUserMenu = (HMENU)wParam; *pResult = 0; return true; case TXM_STATISTIC: *pResult = OnDoStatistic((STATISTIC*)(lParam)); return true; case TXM_GETCONVERTTYPES: *pResult = OnGetConvertTypes((convert_type*)(lParam)); return true; case EM_GETSEL: *pResult = OnMsg_EM_GETSEL((ULONG*)wParam, (ULONG*)lParam); return true; case EM_SETSEL: *pResult = OnMsg_EM_SETSEL((LONG)wParam, (LONG)lParam); return true; default: return false; } }