void Editor::placeCaret() { if (GetFocus() == hWnd) { POINT pt = toPoint(caret); if (insertMode || caret != selStart) CreateCaret(hWnd, NULL, 1, chSize.cy); else CreateCaret(hWnd, NULL, chSize.cx, chSize.cy); SetCaretPos((pt.x - scrollPos.x) * chSize.cx + LeftMargin(), (pt.y - scrollPos.y) * chSize.cy); ShowCaret(hWnd); } }
/* * setCursorOnScreen - set cursor at specified row and column in edit window */ static void setCursorOnScreen( int row, int col ) { window *w; int x, y; int width; int funny; if( BAD_ID( CurrentWindow ) ) { return; } if( EditFlags.Quiet || EditFlags.NoSetCursor ) { return; } funny = getCursorInfo( CurrentWindow, row, col, &x, &width ); w = WINDOW_FROM_ID( CurrentWindow ); y = row * FontHeight( WIN_FONT( w ) ) - cursorHeight; width = (long) width * cursorType.width / 100L; if( cursorWidth != width ) { MyHideCaret( CurrentWindow ); DestroyCaret(); CreateCaret( CurrentWindow, (HBITMAP)NULLHANDLE, width, cursorHeight ); cursorWidth = width; } // adjust position for italic sillyness SetCaretPos( x - funny, y ); MyShowCaret( CurrentWindow ); } /* setCursorOnScreen */
/*********************************************************************** * NOTEPAD_SetFocus * * WM_SETFOCUS window message handle function * * ARGUMENTS: * - handle of window: * HWND hWnd * - (not used): * HWND lostFocusWnd * RETURNS: none */ static void NOTEPAD_OnSetFocus(HWND hWnd, HWND lostFocusWnd) { CreateCaret(hWnd, NULL, 0, Globals.CharH); //SetCaretPos(marginX + caretXpos * tm.tmAveCharWidth, caretYpos * tm.tmHeight + marginY); SendMessage(Globals.hMainWnd, WM_KEYDOWN, 0, 0); // Restore caret position ShowCaret(hWnd); }
void CSelection::ResetCaret( HFONT hFont ) { HDC hDC = GetDC( NULL ); HFONT hOldFont = ( HFONT ) SelectObject( hDC, hFont ); TEXTMETRIC tm; VERIFY( GetTextMetrics( hDC, &tm ) ); SelectObject( hDC, hOldFont ); ReleaseDC( NULL, hDC ); // caret height is the font height m_cyCaret = tm.tmExternalLeading + tm.tmHeight; // insert caret width is the font height / 6 m_cxCaretIns = m_cyCaret / 6; m_cxCaretIns = max( m_cxCaretIns, 2 ); if ( m_pCtrl->OvertypeCaret() && m_pCtrl->InOvertypeMode() ) { m_cxCaret = tm.tmAveCharWidth; } else { m_cxCaret = m_cxCaretIns; } // recreate the caret in the right dimensions if ( ::GetFocus() == m_hWnd ) { VERIFY( DestroyCaret() ); VERIFY( CreateCaret( m_hWnd, NULL, m_cxCaret, m_cyCaret ) ); ::ShowCaret( m_hWnd ); } }
/* * SetCursorOnLine - set cursor at specified column in single line text string */ void SetCursorOnLine( window_id id, int col, char *str, type_style *style ) { window *w; int x, y; int width, height; if( BAD_ID( id ) ) { return; } w = WINDOW_FROM_ID( id ); // y = FontHeight( WIN_FONT( w ) ) - cursorHeight; x = MyTextExtent( id, style, str, col - 1 ); width = MyTextExtent( id, style, str, col ) - x; /* adjust so that Insert cursor is 0 width * Also make the overstrike cursor the height of the insert cursor. */ width = (long) width * cursorType.width / 100L; height = EditVars.InsertCursorType.height; y = FontHeight( WIN_FONT( w ) ) - height; MyHideCaret( id ); DestroyCaret(); // CreateCaret( id, (HBITMAP)NULLHANDLE, width, cursorHeight ); CreateCaret( id, (HBITMAP)NULLHANDLE, width, height ); SetCaretPos( x, y ); MyShowCaret( id ); } /* SetCursorOnLine */
/* * NewCursor - create a new cursor for a window */ void NewCursor( window_id id, cursor_type ct ) { window *w; int height; int width; if( BAD_ID( id ) ) { return; } w = WINDOW_FROM_ID( id ); height = FontHeight( WIN_FONT( w ) ); width = FontAverageWidth( WIN_FONT( w ) ); height = (long) height * ct.height / 100L; width = (long) width * ct.width / 100L; MyHideCaret( id ); DestroyCaret(); cursorHeight = height; cursorWidth = width; if( !haveOldBlinkTime ) { oldBlinkTime = GetCaretBlinkTime(); haveOldBlinkTime = TRUE; } CreateCaret( id, (HBITMAP)NULLHANDLE, cursorWidth, cursorHeight ); SetCursorBlinkRate( EditVars.CursorBlinkRate ); MyShowCaret( id ); cursorType = ct; } /* NewCursor */
static void ShowCursor(void) { CreateCaret(CrtWindow, 0, CharSize.x, 2); SetCaretPos((_Cursor.x - _Origin.x) * CharSize.x, (_Cursor.y - _Origin.y) * CharSize.y + CharAscent); ShowCaret(CrtWindow); }
void text_font(TW *tw, const char *name, int size) { /* make a new font */ LOGFONT lf; TEXTMETRIC tm; LPSTR p; HDC hdc; /* reject inappropriate arguments */ if (name == NULL) return; if (size < 4) return; /* set new name and size */ if (tw->fontname) free(tw->fontname); tw->fontname = (char *)malloc(strlen(name)+1); if (tw->fontname == NULL) return; strcpy(tw->fontname, name); tw->fontsize = size; /* if window not open, hwnd == 0 == HWND_DESKTOP */ hdc = GetDC(tw->hwnd); memset(&lf, 0, sizeof(LOGFONT)); strncpy(lf.lfFaceName,tw->fontname,LF_FACESIZE); lf.lfHeight = -MulDiv(tw->fontsize, GetDeviceCaps(hdc, LOGPIXELSY), 72); lf.lfPitchAndFamily = FIXED_PITCH; lf.lfCharSet = DEFAULT_CHARSET; if ( (p = strstr(tw->fontname," Italic")) != (LPSTR)NULL ) { lf.lfFaceName[ (unsigned int)(p-tw->fontname) ] = '\0'; lf.lfItalic = TRUE; } if ( (p = strstr(tw->fontname," Bold")) != (LPSTR)NULL ) { lf.lfFaceName[ (unsigned int)(p-tw->fontname) ] = '\0'; lf.lfWeight = FW_BOLD; } if (tw->hfont) DeleteFont(tw->hfont); tw->hfont = CreateFontIndirect((LOGFONT FAR *)&lf); /* get text size */ SelectFont(hdc, tw->hfont); GetTextMetrics(hdc,(TEXTMETRIC FAR *)&tm); tw->CharSize.y = tm.tmHeight; tw->CharSize.x = tm.tmAveCharWidth; tw->CharAscent = tm.tmAscent; if (tw->bFocus) CreateCaret(tw->hwnd, 0, tw->CharSize.x, 2+tw->CaretHeight); ReleaseDC(tw->hwnd, hdc); /* redraw window if necessary */ if (tw->hwnd != HWND_DESKTOP) { /* INCOMPLETE */ } }
static void CommandLineKey(int id, WPARAM wParam, int keytype) { TCHAR code = (TCHAR)wParam; int len = (int)wcslen(commandLine); if (keytype == KEYCHAR) { if (!commandLineFocus && code == L':') { CreateCaret(g_hWnd, (HBITMAP)NULL, 1, FONTSIZE_CMD); commandLineFocus = 1; commandLine[commandLinePos++] = L':'; commandLine[commandLinePos] = L'\0'; CommandLineSetpos(); ShowCaret(g_hWnd); } else if (commandLineFocus) { if (code == L'\r' || code == VK_ESCAPE) { if(code == L'\r' && LoaderRun(commandLine + 1)) ErrorPrintf(L"CommandLineError: Cannot parse the command"); commandLine[0] = L'\0'; commandLinePos = 0; commandLineFocus = 0; HideCaret(g_hWnd); DestroyCaret(); memset(KeyboardIsDown, 0, sizeof(KeyboardIsDown)); } if (code < L' ' || len == MAX_COMMANDLINEBUFFER) return; MoveMemory(commandLine + commandLinePos + 1, commandLine + commandLinePos, (len - commandLinePos + 1) * sizeof(TCHAR)); commandLine[commandLinePos++] = code; CommandLineSetpos(); } } else if (keytype == KEYDOWN && commandLineFocus) { switch (code) { case VK_LEFT: if (commandLinePos > 1) --commandLinePos; CommandLineSetpos(); break; case VK_RIGHT: if (commandLinePos < len) ++commandLinePos; CommandLineSetpos(); break; case VK_HOME: commandLinePos = 1; break; case VK_END: commandLinePos = len; break; case VK_BACK: if (commandLinePos > 1) { MoveMemory(commandLine + commandLinePos - 1, commandLine + commandLinePos, (len - commandLinePos + 1) * sizeof(TCHAR)); commandLinePos--; } CommandLineSetpos(); break; } } }
/*---------------------------------------------------------------------------*\ | | \*---------------------------------------------------------------------------*/ void OnSetFocus(HWND hwnd, HWND hwndOldFocus) { /* * Set up caret when we get keyboard. */ CreateCaret(hwnd, NULL, cxIcon, cyIcon); SetCaretPos(xCaret, yCaret); ShowCaret(hwnd); }
void ME_MoveCaret(ME_TextEditor *editor) { int x, y, height; ME_WrapMarkedParagraphs(editor); ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height); CreateCaret(editor->hWnd, NULL, 0, height); SetCaretPos(x, y); }
static LRESULT HOTKEY_SetFocus (HOTKEY_INFO *infoPtr) { infoPtr->bFocus = TRUE; CreateCaret (infoPtr->hwndSelf, NULL, 1, infoPtr->nHeight); SetCaretPos (infoPtr->CaretPos, GetSystemMetrics(SM_CYBORDER)); ShowCaret (infoPtr->hwndSelf); return 0; }
static inline LRESULT HexEdit_SetFocus (HEXEDIT_INFO *infoPtr, HWND lostFocus) { infoPtr->bFocus = TRUE; CreateCaret(infoPtr->hwndSelf, NULL, 1, infoPtr->nHeight); HexEdit_UpdateCaret(infoPtr); ShowCaret(infoPtr->hwndSelf); return 0; }
/* * _NewCursor - change the cursor type */ void _NewCursor( LPWDATA w, cursors type ) { if( w->hascursor ) { DestroyCaret(); w->hascursor = FALSE; } if( type == KILL_CURSOR ) return; w->CaretType = type; switch( type ) { case SMALL_CURSOR: CreateCaret( w->hwnd, (HBITMAP)NULL, 0, w->ychar ); w->hascursor = TRUE; break; case FAT_CURSOR: CreateCaret( w->hwnd, (HBITMAP)NULL, 4, w->ychar ); w->hascursor = TRUE; break; case ORIGINAL_CURSOR: break; } } /* _NewCursor */
void QWindowsInputContext::initContext(HWND hwnd) { if (m_compositionContext.hwnd) doneContext(); m_compositionContext.hwnd = hwnd; // Create a hidden caret which is kept at the microfocus // position in update(). This is important for some // Chinese input methods. m_compositionContext.haveCaret = CreateCaret(hwnd, 0, 1, 1); HideCaret(hwnd); update(Qt::ImQueryAll); m_compositionContext.isComposing = false; m_compositionContext.position = 0; }
void CSelection::OnFocusChange( BOOL bSetFocus ) { if ( bSetFocus ) { VERIFY( CreateCaret( m_hWnd, NULL, m_cxCaret, m_cyCaret ) ); UpdateCaretPosition(); ShowCaret(); } else { HideCaret(); DestroyCaret(); } }
void ME_MoveCaret(ME_TextEditor *editor) { int x, y, height; if (ME_WrapMarkedParagraphs(editor)) ME_UpdateScrollBar(editor); ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height); if(editor->bHaveFocus) { CreateCaret(editor->hWnd, NULL, 0, height); SetCaretPos(x, y); } }
void ME_MoveCaret(ME_TextEditor *editor) { int x, y, height; if (ME_WrapMarkedParagraphs(editor)) ME_UpdateScrollBar(editor); ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height); if(editor->bHaveFocus && !ME_IsSelection(editor)) { x = min(x, editor->rcFormat.right-1); CreateCaret(editor->hWnd, NULL, 0, height); SetCaretPos(x, y); } }
static void hugsprim_CreateCaret_40(HugsStackPtr hugs_root) { HsPtr arg1; HsPtr arg2; HsInt32 arg3; HsInt32 arg4; HsBool res1; arg1 = hugs->getPtr(); arg2 = hugs->getPtr(); arg3 = hugs->getInt32(); arg4 = hugs->getInt32(); res1 = CreateCaret(arg1, arg2, arg3, arg4); hugs->putBool(res1); hugs->returnIO(hugs_root,1); }
void CSelection::OnFocusChange( BOOL bSetFocus ) { if ( bSetFocus ) { ASSERT( IsWindow( m_hWnd ) ); ASSERT( GetFocus() == m_hWnd ); VERIFY( CreateCaret( m_hWnd, NULL, m_cxCaret, m_cyCaret ) ); UpdateCaretPosition(); ShowCaret(); } else { HideCaret(); ASSERT( IsWindow( m_hWnd ) ); DestroyCaret(); } }
void Caret::start( CView* parent, const CPoint& pos, CCoord height ) { parent_ = parent; frame_ = parent_->getFrame(); ASSERT( frame_ ); HWND hwnd = (HWND)frame_->getSystemWindow(); CreateCaret( hwnd, NULL, 1, height ); setPosition( pos ); height_ = height; ShowCaret( hwnd ); //timer_ = new CVSTGUITimer( this, 500 ); //timer_->start (); }
void CreateTheCaret( LPCLASSDATA lpcd ) { int cx, cy; /* * Make sure the character size is * present. */ GetCharSize( NULL, lpcd ); /* * Setup caret height. */ cy = Parser->szCharSize.cy; /* * When in insert mode we switch to the * block style caret. */ if ( lpcd->bOverwrite ) cx = Parser->szCharSize.cx; else { /* * Default width. */ cx = GetSystemMetrics( SM_CXBORDER ); /* * What type of caret? */ if ( Parser->nCaretType == CARET_WIDE ) cx *= 2; else if ( Parser->nCaretType == CARET_BLOCK ) cx = Parser->szCharSize.cx; else if ( Parser->nCaretType == CARET_HORIZONTAL ) { cx = Parser->szCharSize.cx; cy = GetSystemMetrics( SM_CYBORDER ) * 2; } } /* * Create and update the caret. */ CreateCaret( lpcd->hWnd, NULL, cx, cy ); UpdateCaret( lpcd ); }
void CSelection::UpdateCaretPosition() const { ASSERT( m_pView ); RECT rcView; m_pView->GetViewRect( &rcView ); if ( GetFocus() == m_hWnd && !m_pCtrl->DelayPaint() ) { int yCaret = rcView.top + ( ( m_nEndRow - m_pView->GetTopIndex() ) * m_pView->GetLineHeight() ); int cxLeftMargin = m_pView->GetLeftMargin( TRUE, TRUE ); int xCaret = rcView.left + cxLeftMargin + ( ( m_nEndViewCol - m_pView->GetLeftIndex() ) * m_pView->GetCharWidth() ); if ( m_pCtrl->ShowHScrollBar() && ( ( ( yCaret + m_cyCaret ) > rcView.bottom ) || ( yCaret < rcView.top ) ) ) { // don't let the caret draw over the scrollbars yCaret = -m_cyCaret - 1; } if ( ( xCaret < rcView.left + cxLeftMargin ) || ( m_pCtrl->ShowVScrollBar() && ( ( ( xCaret + m_cxCaret ) > rcView.right ) || ( xCaret < rcView.left ) ) ) ) { // don't let the caret draw over the scrollbars xCaret = -m_cxCaret - 1; } POINT pt; GetCaretPos( &pt ); if ( pt.x != xCaret || pt.y != yCaret ) { if (!SetCaretPos (xCaret, yCaret)) { // this seems to work around a bug in a HTML Help version that causes SetCaretPos to // fail with a 0x05 (permission denied) error, even though CreateCaret had succeeded // and the window had focus. maybe it was stealing the caret back after CreateCaret ? VERIFY (CreateCaret (m_hWnd, NULL, m_cxCaret, m_cyCaret)) ; VERIFY (SetCaretPos (xCaret, yCaret)) ; } } } }
/************************************************************************ * * ResetCaret - Reset caret shape to match input mode (overtype/insert) * ************************************************************************/ void ResetCaret( HWND hWnd ) { HideCaret( hWnd ); DestroyCaret(); CreateCaret( hWnd, NULL, (fInsertMode && IsDBCSLeadByte( textbuf[yPos][xPos] )) ? CaretWidth*2 : CaretWidth, cyMetrics ); SetCaretPos( xPos * cxMetrics, yPos * cyMetrics ); if ( !( gImeUIData.fdwProperty & IME_PROP_AT_CARET ) && !( gImeUIData.fdwProperty & IME_PROP_SPECIAL_UI ) ) { // near caret. SetIMECompFormPos( hWnd ); } ShowCaret( hWnd ); }
/************************************************************************ * * MouseHandler - WM_BUTTONDOWN handler * ************************************************************************/ void MouseHandler( HWND hWnd, LONG lParam ) { if ( ( gImeUIData.ImeState & IME_IN_CHOSECAND ) || ( gImeUIData.ImeState & IME_IN_COMPOSITION && !MoveCaret( hWnd ) ) ) return; HideCaret( hWnd ); // // Calculate caret position based on fixed pitched font // yPos = MAKEPOINTS(lParam).y / cyMetrics; xPos = MAKEPOINTS(lParam).x / cxMetrics; // // Adjust caret position if click landed on a trail byte // if ( IsDBCSTrailByte( (LPSTR)textbuf[yPos], (LPSTR)&(textbuf[yPos][xPos]) ) ) { // // If click landed on the last quarter of the DBCS character, // assume the user was aiming at the next character. // if ( (MAKEPOINTS(lParam).x - xPos * cxMetrics) > (cxMetrics / 2) ) xPos++; else xPos--; } DestroyCaret(); CreateCaret(hWnd, NULL, (fInsertMode && IsDBCSLeadByte( textbuf[yPos][xPos] )) ? CaretWidth*2 : CaretWidth, cyMetrics ); SetCaretPos( xPos * cxMetrics, yPos * cyMetrics ); ShowCaret( hWnd ); }
int CTextView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; /* //创建设备描述表 CClientDC dc(this); //定义文本信息结构体变量 TEXTMETRIC tm; //获得设备描述表中的文本信息 dc.GetTextMetrics(&tm); //根据字体大小,创建合适的插入符 CreateSolidCaret(tm.tmAveCharWidth/8, tm.tmHeight); //显示插入符 ShowCaret(); */ bitmap.LoadBitmap(IDB_BITMAP1); CreateCaret(&bitmap); ShowCaret(); SetTimer(1,100,NULL); return 0; }
void FAR PASCAL EmacsCaret (BOOL Show) /* the Show parameter is TRUE if the caret should be created and FALSE if it should be destroyed */ { short xsize, ysize; if (Show) { if (hCaretWnd == 0) return; if (hFrameWnd == GetActiveWindow ()) { if (!IsWindow (hCaretWnd)) { /* this may happen in some transient cases when closing down a screen */ hCaretWnd = 0; return; } if (hCaretWnd == hFrameWnd) { xsize = GetSystemMetrics (SM_CXBORDER); ysize = EmacsCM.SizeY; } else { xsize = (caret_shape == 1)? EmacsCM.SizeX/4: EmacsCM.SizeX; ysize = (caret_shape == 0)? EmacsCM.SizeY/4: EmacsCM.SizeY; } CreateCaret (hCaretWnd, NULL, xsize, ysize); UpdateEmacsCaretPos(); if (CaretVisible && !IsIconic (hCaretWnd)) ShowCaret (hCaretWnd); } } else /* destroy the caret */ DestroyCaret (); } /* EmacsCaret */
void setCaretSize(int w,int h) { DestroyCaret(); CreateCaret(g_hWnd,0,w,h); SetCaretPos(g_caretX,g_caretY); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { HDC hdc; hdc = GetDC(hwnd); g_hbitmap = CreateCompatibleBitmap( hdc, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); g_hmemdc = CreateCompatibleDC(hdc); SelectObject(g_hmemdc, g_hbitmap); BitBlt(g_hmemdc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), g_hmemdc, 0, 0, WHITENESS); DeleteDC(g_hmemdc); ReleaseDC(hwnd, hdc); CreateCaret(hwnd,0,g_caretWidth,g_caretHeight); g_caretX = g_wndWidth; g_caretY = g_wndHeight; SetCaretPos(g_caretX,g_caretY); break; } case WM_ERASEBKGND: break; case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; RECT rect; hdc = BeginPaint(hwnd, &ps); g_hmemdc = CreateCompatibleDC(hdc); SelectObject(g_hmemdc, g_hbitmap); GetClientRect(hwnd,&rect); BitBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, g_hmemdc, 0, 0, SRCCOPY); DeleteDC(g_hmemdc); g_hmemdc = 0; EndPaint(hwnd,&ps); break; } case WM_CHAR: if (g_char != NULL) g_char((int) wParam); break; case WM_KEYDOWN: if (g_keyboard != NULL) g_keyboard((int) wParam,KEY_DOWN); break; case WM_KEYUP: if(g_keyboard != NULL) g_keyboard((int) wParam,KEY_UP); break; case WM_LBUTTONDOWN: if (g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), LEFT_BUTTON, BUTTON_DOWN); break; case WM_LBUTTONUP: if (g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), LEFT_BUTTON, BUTTON_UP); break; case WM_LBUTTONDBLCLK: if (g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), LEFT_BUTTON, BUTTON_DOUBLECLICK); break; case WM_MBUTTONDOWN: if (g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), MIDDLE_BUTTON, BUTTON_DOWN); break; case WM_MBUTTONUP: if (g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), MIDDLE_BUTTON, BUTTON_UP); break; case WM_MBUTTONDBLCLK: if (g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), MIDDLE_BUTTON, BUTTON_DOUBLECLICK); break; case WM_RBUTTONDOWN: if (g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), RIGHT_BUTTON, BUTTON_DOWN); break; case WM_RBUTTONUP: if (g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), RIGHT_BUTTON, BUTTON_UP); break; case WM_RBUTTONDBLCLK: if (g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), RIGHT_BUTTON, BUTTON_DOUBLECLICK); break; case WM_MOUSEMOVE: if(g_mouse != NULL) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam), MOUSEMOVE, MOUSEMOVE); break; case WM_MOUSEWHEEL: if(g_mouse == NULL) break; if(HIWORD(wParam) == 120) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam),MIDDLE_BUTTON,ROLL_UP); else if(HIWORD(wParam)==65416) g_mouse((int) LOWORD(lParam), (int) HIWORD(lParam),MIDDLE_BUTTON,ROLL_DOWN); break; case WM_TIMER: if (g_timer != NULL) g_timer(wParam); break; case WM_DESTROY: DeleteObject(g_hbitmap); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
long CALLBACK EXPORT ConsoleFunc(HWND hwnd,unsigned message,WPARAM wParam, LPARAM lParam) { CONSOLE *con; PAINTSTRUCT ps; RECT rect; switch (message) { case WM_CHAR: if ((con=Hwnd2Console(hwnd))!=NULL) { /* store in a key queue */ if ((con->keyq_end+1)%KEYQUEUE_SIZE==con->keyq_start) { MessageBeep(MB_OK); break; } /* if */ con->keyqueue[con->keyq_end]=(short)wParam; con->keyq_end=(con->keyq_end+1)%KEYQUEUE_SIZE; } /* if */ break; case WM_CREATE: /* The "hwnd" member of the CONSOLE structure has not yet been set, which * means that Hwnd2Console() cannot work on the real "hwnd". There should * at every instant be only one CONSOLE structure with a NULL handle, * however. */ if ((con=Hwnd2Console(NULL))!=NULL) { con->hwnd=hwnd; SetConsoleFont(con,con->cheight); GetWindowRect(hwnd, &rect); SetRect(&rect,rect.left,rect.top, rect.left+con->cwidth*con->columns, rect.top+con->cheight*con->winlines); AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE); if (con->winlines<con->lines) rect.right+=GetSystemMetrics(SM_CXVSCROLL); ClampToScreen(&rect); SetWindowPos(hwnd,NULL,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top, SWP_NOZORDER); } /* if */ break; case WM_DESTROY: if ((con=Hwnd2Console(hwnd))!=NULL) DoDeleteConsole(con); break; case WM_GETMINMAXINFO: if ((con=Hwnd2Console(hwnd))!=NULL) { MINMAXINFO FAR *lpmmi=(MINMAXINFO FAR*)lParam; int rx,ry,hsize,vsize; GetClientRect(hwnd,&rect); rx= (rect.right < con->columns*con->cwidth) ? con->columns*con->cwidth-rect.right : 0; ry= (rect.bottom < con->lines*con->cheight) ? con->lines*con->cheight-rect.bottom : 0; hsize= (ry>0) ? GetSystemMetrics(SM_CXVSCROLL) : 0; vsize= (rx>0) ? GetSystemMetrics(SM_CYHSCROLL) : 0; SetRect(&rect,0,0,con->cwidth*con->columns+hsize,con->cheight*con->lines+vsize); AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE); lpmmi->ptMaxTrackSize.x=rect.right-rect.left; lpmmi->ptMaxTrackSize.y=rect.bottom-rect.top; lpmmi->ptMaxSize=lpmmi->ptMaxTrackSize; } /* if */ break; case WM_SYSKEYDOWN: case WM_KEYDOWN: if ((con=Hwnd2Console(hwnd))!=NULL) { TCHAR str[20]; int i; str[0]=__T('\0'); switch (LOWORD(wParam)) { case VK_F1: case VK_F2: case VK_F3: case VK_F4: case VK_F5: case VK_F6: case VK_F7: case VK_F8: case VK_F9: case VK_F10: case VK_F11: case VK_F12: if (LOWORD(wParam)<=VK_F5) _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F1+11); else if (LOWORD(wParam)==VK_F10) _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F6+17); else _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F11+23); break; case VK_ADD: case VK_SUBTRACT: /* check Ctrl key */ if ((GetKeyState(VK_CONTROL) & 0x8000)!=0) { POINT pt; int newheight=con->cheight; int oldheight=newheight; int incr= (LOWORD(wParam)==VK_SUBTRACT) ? -1 : 1; do { newheight+=incr; /* make a new font, re-create a caret and redraw everything */ SetConsoleFont(con,newheight); } while (newheight>5 && (oldheight==con->cheight || con->hfont==NULL)); if (con->hfont==NULL) /* reset to original on failure */ SetConsoleFont(con,oldheight); GetClientRect(hwnd,&rect); DestroyCaret(); CreateCaret(hwnd,NULL,con->cwidth,2); RefreshCaretPos(con); /* redraw the window */ InvalidateRect(hwnd,NULL,TRUE); /* resize the window */ SetRect(&rect,0,0,con->cwidth*con->columns,con->cheight*con->winlines); AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE); pt.x=pt.y=0; ClientToScreen(hwnd,&pt); OffsetRect(&rect,pt.x,pt.y); ClampToScreen(&rect); SetWindowPos(hwnd,NULL,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top, SWP_NOZORDER); } /* if */ break; case VK_UP: _tcscpy(str,__T("\033[A")); break; case VK_DOWN: _tcscpy(str,__T("\033[B")); break; case VK_RIGHT: _tcscpy(str,__T("\033[C")); break; case VK_LEFT: _tcscpy(str,__T("\033[D")); break; case VK_HOME: _tcscpy(str,__T("\033[1~")); break; case VK_END: _tcscpy(str,__T("\033[4~")); break; case VK_INSERT: _tcscpy(str,__T("\033[2~")); break; case VK_DELETE: _tcscpy(str,__T("\033[3~")); break; case VK_PRIOR: /* PageUp */ _tcscpy(str,__T("\033[5~")); break; case VK_NEXT: /* PageDown */ _tcscpy(str,__T("\033[6~")); break; default: return DefWindowProc(hwnd,message,wParam,lParam); } /* switch */ for (i=0; str[i]!=__T('\0'); i++) { if ((con->keyq_end+1)%KEYQUEUE_SIZE!=con->keyq_start) { con->keyqueue[con->keyq_end]=(short)str[i]; con->keyq_end=(con->keyq_end+1)%KEYQUEUE_SIZE; } /* if */ } /* for */ } /* if */ break; case WM_KILLFOCUS: HideCaret(hwnd); DestroyCaret(); break; case WM_SETFOCUS: if ((con=Hwnd2Console(hwnd))!=NULL) { CreateCaret(hwnd,NULL,con->cwidth,2); RefreshCaretPos(con); ShowCaret(hwnd); } /* if */ break; case WM_LBUTTONDOWN: SetFocus(hwnd); break; case WM_PAINT: HideCaret(hwnd); BeginPaint(hwnd, &ps); if ((con=Hwnd2Console(hwnd))!=NULL && con->buffer!=NULL) { TCHAR *string; string=malloc(con->columns*sizeof(TCHAR)); if (string!=NULL) { int l,c,bpos,start; TCHAR attr; HFONT hfontOrg; int scrollx=GetScrollPos(hwnd,SB_HORZ); int scrolly=GetScrollPos(hwnd,SB_VERT); GetClientRect(hwnd,&rect); hfontOrg=SelectObject(ps.hdc,con->hfont); SetBkMode(ps.hdc,OPAQUE); for (l=0; l<con->lines; l++) { bpos=l*con->columns*2; c=0; while (c<con->columns) { /* find stretches with the same attribute */ attr=con->buffer[bpos+1]; start=c; while (c<con->columns && con->buffer[bpos+1]==attr) { assert(c-start>=0); assert(c-start<con->columns); string[c-start]=con->buffer[bpos]; c++; bpos+=2; } /* if */ SetTextAttribute(ps.hdc,attr); TextOut(ps.hdc,start*con->cwidth-scrollx,l*con->cheight-scrolly,string,c-start); } /* while */ } /* for */ SelectObject(ps.hdc,hfontOrg); free(string); } /* if */ } /* if */ EndPaint(hwnd, &ps); ShowCaret(hwnd); break; case WM_SIZE: if ((con=Hwnd2Console(hwnd))!=NULL) { int rx,ry; /* add/remove/recalculate scroll bars */ GetClientRect(hwnd,&rect); rx= (rect.right < con->columns*con->cwidth) ? con->columns*con->cwidth-rect.right : 0; ry= (rect.bottom < con->lines*con->cheight) ? con->lines*con->cheight-rect.bottom : 0; /* adjust scrolling position, if necessary */ if (GetScrollPos(hwnd,SB_HORZ)>=rx) { SetScrollPos(hwnd,SB_HORZ,rx,FALSE); InvalidateRect(hwnd,NULL,FALSE); } /* if */ if (GetScrollPos(hwnd,SB_VERT)>=ry) { SetScrollPos(hwnd,SB_VERT,ry,FALSE); InvalidateRect(hwnd,NULL,FALSE); } /* if */ SetScrollRange(hwnd,SB_HORZ,0,rx,TRUE); SetScrollRange(hwnd,SB_VERT,0,ry,TRUE); } /* if */ break; case WM_HSCROLL: if ((con=Hwnd2Console(hwnd))!=NULL) { int scrollx=GetScrollPos(hwnd,SB_HORZ); int oldpos=scrollx; int min,max; GetScrollRange(hwnd,SB_HORZ,&min,&max); switch (LOWORD(wParam)) { case SB_TOP: scrollx=min; break; case SB_BOTTOM: scrollx=max; break; case SB_LINELEFT: scrollx=(scrollx>min) ? scrollx-1 : min; break; case SB_LINERIGHT: scrollx=(scrollx<max) ? scrollx+1 : max; break; case SB_PAGELEFT: scrollx=(scrollx>min) ? scrollx-50 : min; break; case SB_PAGERIGHT: scrollx=(scrollx<max) ? scrollx+50 : max; break; case SB_THUMBTRACK: scrollx=(int)HIWORD(wParam); break; } /* switch */ if (oldpos!=scrollx) { SetScrollPos(hwnd,SB_HORZ,scrollx,TRUE); InvalidateRect(hwnd,NULL,FALSE); RefreshCaretPos(con); } /* if */ } /* if */ break; case WM_VSCROLL: if ((con=Hwnd2Console(hwnd))!=NULL) { int scrolly=GetScrollPos(hwnd,SB_VERT); int oldpos=scrolly; int min,max; GetScrollRange(hwnd,SB_VERT,&min,&max); switch (LOWORD(wParam)) { case SB_TOP: scrolly=min; break; case SB_BOTTOM: scrolly=max; break; case SB_LINELEFT: scrolly=(scrolly>min) ? scrolly-1 : min; break; case SB_LINERIGHT: scrolly=(scrolly<max) ? scrolly+1 : max; break; case SB_PAGELEFT: scrolly=(scrolly>min) ? scrolly-50 : min; break; case SB_PAGERIGHT: scrolly=(scrolly<max) ? scrolly+50 : max; break; case SB_THUMBTRACK: scrolly=(int)HIWORD(wParam); break; } /* switch */ if (oldpos!=scrolly) { SetScrollPos(hwnd,SB_VERT,scrolly,TRUE); InvalidateRect(hwnd,NULL,FALSE); RefreshCaretPos(con); } /* if */ } /* if */ break; default: return DefWindowProc(hwnd,message,wParam,lParam); } /* switch */ return 0L; }