Ejemplo n.º 1
0
/************************************************************************
*
*   SteWndProc - STE class window procedure
*
************************************************************************/
int WINAPI SteWndProc( HWND hWnd, UINT msg, UINT wParam, LONG lParam )
{
    int i;
    HDC hdc;
    PAINTSTRUCT ps = {0};

    switch( msg ) 
    {
    case WM_CREATE:
        SteCreate( hWnd );
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    case WM_CLOSE:
        DestroyWindow( hWnd );
        break;

    case WM_SETFOCUS:
        CreateCaret( hWnd, NULL,
                     (fInsertMode && IsDBCSLeadByte( textbuf[yPos][xPos] )) ?
                         CaretWidth*2 : CaretWidth,
                     cyMetrics );
        SetCaretPos( xPos * cxMetrics, yPos * cyMetrics );
        ShowCaret( hWnd );
        break;

    case WM_KILLFOCUS:
        HideCaret( hWnd );
        DestroyCaret();
        break;

    case WM_IME_KEYDOWN: /* fall-through */
    case WM_KEYDOWN:
        VirtualKeyHandler( hWnd, wParam );
        break;

    case WM_KEYUP:
        break;

    case WM_CHAR:
        CharHandler( hWnd, (WORD)wParam );
        break;

    case WM_LBUTTONDOWN:
        MouseHandler( hWnd, lParam );
        break;

    case WM_MOVE:
        ImeUIMoveCandWin( hWnd );
        break;

    case WM_COMMAND:
        SteCommand( hWnd, wParam, lParam );
        break;

    case WM_PAINT:
        InvalidateRect(hWnd,NULL,FALSE);  //for repaint allignment problem??
    				  // WinChi3.0
        hdc = BeginPaint( hWnd, &ps );

        //
        // Refresh display from text buffer
        //
        for ( i = FIRSTROW; i <= LASTROW; i++ )
            TextOut( hdc, 0, i*cyMetrics, (LPSTR)textbuf[i], MAXCOL );

        EndPaint( hWnd, &ps );
        RestoreImeUI( hWnd );
        break;

    case WM_INPUTLANGCHANGE:
        InputChangeHandler( hWnd );
        goto call_defwinproc;
        break;

    case WM_IME_SETCONTEXT:
        //
        // The application have to pass WM_IME_SETCONTEXT to DefWindowProc.
        // When the application want to handle the IME at the timing of
        // focus changing, the application should use WM_SETFOCUS or
        // WM_KILLFOCUS.
        //
     
        if ( gImeUIData.fdwProperty & IME_PROP_SPECIAL_UI )
        {
            goto call_defwinproc;
        }
        else if ( gImeUIData.fdwProperty & IME_PROP_AT_CARET )
        {
            //
            // application wants to draw UI ny itself.
            //
            lParam &= ~(ISC_SHOWUICOMPOSITIONWINDOW | ISC_SHOWUIALLCANDIDATEWINDOW);
        }
        goto call_defwinproc;

    case WM_IME_STARTCOMPOSITION:
        //
        // CheckProperty is a macro, if IME already provides near caret or
        // special UI then let IME handle this message.
        //
        CheckProperty;
        ImeUIStartComposition( hWnd );
        break;

    case WM_IME_COMPOSITION:
        CheckProperty;
        ImeUIComposition( hWnd, wParam, lParam );
        break;

    case WM_IME_ENDCOMPOSITION:
        CheckProperty;
        ImeUIEndComposition( hWnd );
        break;

    case WM_IME_COMPOSITIONFULL:
        //
        // Make sure the size for drawing the composition string.
        // Application should draw the composition string correctly.
        // 
        break;

    case WM_IME_NOTIFY:
        CheckProperty;
        if ( !ImeUINotify( hWnd, wParam, lParam ) )
            // This application does not handle all notification message.
            // So we pass those notification messages which are not hanlded
            // by this application to the DefWindowProc.
            goto call_defwinproc;
        break;
        

    case WM_IME_CONTROL:
        //
        // This message is not received by the application window.
        // But don't pass it to DefWindowProc().
        //
        break;


    default:

call_defwinproc:
        return (int)DefWindowProc( hWnd, msg, wParam, lParam );
    }

    return 0;
}
int WindowLister( int x,
                  int y,
                  int xx,
                  int yy,
                  int CharToExitOn,
                  int *NumItems,
                  int NumToStartWith,
				  int (*CharHandler)(int ch, int Index),
                  void (*ScreenClearer)( void ),
                  void (*DisplayLineFunction)(int Index) )
{
    register int i;
    register int CurrLine = 0;
    int PrevLine;
    int NumLines = yy - y;
    int Top = NumToStartWith;
    int OldTop;
    int RefreshScreen = 1;
    int ch;
    union REGS regs, regs2;
    int Index;

    regs.x.cx = ( (y-1) << 8 ) + x-1;
    regs.x.dx = ( (yy-1) << 8 ) + xx-1;
    regs.x.ax = 0;
    regs.h.bh = A_NORMAL;
    regs.h.ah = 0x06;
    regs.x.ax = 1;

    for (;;) {

        if ( RefreshScreen ) {
            ScreenClearer();
            ChangeBlock( x, y, xx, yy, A_NORMAL );
            RefreshScreen = 0;
            PrevLine = 500;
            OldTop = -500;
            for (i=0; i<=NumLines; ++i) {
                gotoxy( x, i+y );
                if ( i+Top <= *NumItems )
                    DisplayLineFunction( i+Top );
            }
        }

        Index = CurrLine + Top;

        if ( PrevLine != CurrLine || OldTop != Top ) {
			SetAttrib( A_REVERSE );
            gotoxy( x, y + CurrLine );
            DisplayLineFunction( Index );
			SetAttrib( A_NORMAL );
        }
        HideCursor();

        PrevLine = CurrLine;
        OldTop = Top;

        ch = GComm();
        if ( ch == CharToExitOn ) return( Index );

        switch( ch ) {

			case ESC:
				return( -1 );

			case DOWN:
                CurrLine++;
                if (CurrLine > NumLines) {
                    CurrLine = NumLines;
                    if ( Top < *NumItems - NumLines ) {
                        Top++;
                           ChangeBlock( x, y, xx, yy, A_NORMAL );
                        regs.h.ah = 0x06;
                        int86( 0x10, &regs, &regs2 );
                        gotoxy( x, yy );
                    }
                }
                break;

            case UP:
                CurrLine--;
                if (CurrLine < 0) {
                    CurrLine=0;
                    if ( Top > 0 ) {
                        Top--;
                           ChangeBlock( x, yy, xx, yy, A_NORMAL );
                        regs.h.ah = 7;
                        int86( 0x10, &regs, &regs2 );
                        gotoxy( x, y );
                    }
                }
                break;

            case END:
                Top = *NumItems - NumLines;
                if ( Top < 0 ) {
                    Top = 0;
                }
                CurrLine = NumLines;
                if ( CurrLine > *NumItems ) {
                    CurrLine = *NumItems;
                }
                RefreshScreen++;
                break;

            case PGDN:
                Top += NumLines;
                if (Top > *NumItems - NumLines) {
                    Top = *NumItems - NumLines;
                    if ( Top < 0 )
                        Top = 0;
                    CurrLine = NumLines;
                    if ( CurrLine > *NumItems ) {
                        CurrLine = *NumItems;
                    }
                }
                RefreshScreen++;
                break;

            case PGUP:
                Top -= NumLines;
                if (Top < 0) {
                    Top = 0;
                    CurrLine = 0;
                }
                RefreshScreen++;
                break;

            case HOME:
                Top = CurrLine = 0;
                RefreshScreen++;
                break;

            default:
                gotoxy( x, CurrLine + y );
                ReverseText();
                DisplayLineFunction( Index );
                NormalText();
				/*HideCursor();*/
                RefreshScreen++;
				CurrLine = CharHandler( ch, Index );
				RefreshScreen = 1;
				if ( CurrLine - Top <= NumLines && CurrLine - Top >= 0 )
					CurrLine -= Top;
				else {
					Top = CurrLine - 1;
					CurrLine = 1;
					if ( Top < 0 ) {
						Top = CurrLine = 0;
					}
                }
                break;

        }
        if ( Top < 0 ) {
            Top = 0;
            CurrLine = 0;
        }
        if ( Top + CurrLine > *NumItems ) {
            CurrLine = *NumItems - Top;
        }
        if ( PrevLine != CurrLine || Top != OldTop ) {
            ChangeBlock( x, y, xx, yy, A_NORMAL );
        }
        if ( RefreshScreen > 1 ) {
            Top = CurrLine = 0;
        }
    }
}