display.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 591 行 · 第 1/2 页

C
591
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include <string.h>
#include <assert.h>
#include "winvi.h"
#include "winaux.h"
#include "win.h"
#include "color.h"
#include "font.h"
#include "utils.h"
#include "source.h"
#include "sstyle.h"

static void funnyFix( RECT *rect, int x, window_id id, char *display, int len,
                HDC hdc, int max_width, type_style *ts, HBRUSH thisBrush );

void MyTabbedTextOut( HDC hdc, char **display, int len,
                      int funny_italic, POINT *p, type_style *ts, RECT *rect,
                      window_id id, char *otmp, int y );

BOOL            AllowDisplay = TRUE;
static int      pageCnt;
static int      lastFont, thisFont;
static int      lastFore, thisFore;
static int      lastBack, thisBack;
static HBRUSH   thisBrush;



void ScreenPage( int page )
{
    pageCnt += page;
    AllowDisplay = !pageCnt;
}

void WindowTitleAOI( window_id id, char *title, bool active )
{
    active = active;
    if( !BAD_ID( id ) ) {
        SetWindowText( id, title );
    }
}

void WindowTitle( window_id id, char *title )
{
    WindowTitleAOI( id, title, FALSE );
}

void ClearWindow( window_id id )
{
    RECT        rect;
    window      *w;
    HDC         hdc;

    if( !AllowDisplay || BAD_ID( id ) ) {
        return;
    }
    w = WINDOW_FROM_ID( id );
    GetWindowRect( id, &rect );
    hdc = TextGetDC( id, WIN_STYLE( w ) );
    // should clear with SEType[ SE_WHITESPACE ].background for edit windows
    FillRect( hdc, &rect, ColorBrush( WIN_BACKCOLOR( w ) ) );
    TextReleaseDC( id, hdc );
}

int DisplayLineInWindow( window_id id, int line, char *text )
{
    text = text;
    id = id;
    DCDisplaySomeLines( line - 1, line - 1 );
    return 0; /* probably never checked */
}

void ShiftWindowUpDown( window_id id, int lines )
{
    int         change, height;
    window      *w;
    window_data *wd;
    RECT        clip_rect;

    if( lines == 0 || !AllowDisplay || BAD_ID( id ) ) {
        return;
    }
    w = WINDOW_FROM_ID( id );
    height = FontHeight( WIN_FONT( w ) );
    change = -lines * height;
    DCScroll( -lines );

    MyHideCaret( id );
    wd = DATA_FROM_ID( id );
    // don't scroll extra bit bit at bottom
    // clip extra bit in case scrolling w/ positive change
    GetClientRect( id, &clip_rect );
    clip_rect.bottom = wd->extra.top;
    if( change > 0 ){
        // dont scroll into extra bit
        ScrollWindow( id, 0, change, &clip_rect, &clip_rect );
    } else {
        ScrollWindow( id, 0, change, &clip_rect, NULL );
    }
    UpdateWindow( id );
    MyShowCaret( id );

    wd =wd;
    clip_rect.top = 0;

} /* ShiftWindowUpDown */

int SetDrawingObjects( HDC hdc, type_style *ts ){
    static int funny_italic = 0;

    // setup font and colours for next string.
    thisFore = ts->foreground;
    if( lastFore != thisFore ) {
        SetTextColor( hdc, ColorRGB( thisFore ) );
        lastFore = thisFore;
    }

    thisBack = ts->background;
    if( lastBack != thisBack ) {
        SetBkColor( hdc, ColorRGB( thisBack ) );
        thisBrush = ColorBrush( ts->background );
        lastBack = thisBack;
    }

    thisFont = ts->font;
    if( lastFont != thisFont ) {
        SelectObject( hdc, FontHandle( thisFont ) );
        lastFont = thisFont;
        if( FontIsFunnyItalic( thisFont ) ){
            funny_italic = TRUE;
        } else {
            funny_italic = FALSE;
        }
    }
    return( funny_italic );
}

#ifndef BITBLT_BUFFER_DISPLAY

static void funnyFix( RECT *rect, int x, window_id id, char *display, int len,
                HDC hdc, int max_width, type_style *ts, HBRUSH brush ){

    // FunnyItalic so draw at bit at begining and end!

    RECT smallrect;
    int advance;
    int width;

    smallrect.top = rect->top;
    smallrect.bottom = rect->bottom;

    // draw bit at the beginning
    smallrect.left = x;
    width = MyTextExtent( id, ts, display, len );
    max_width = min( width, max_width );
    smallrect.right = max_width + x;
    FillRect( hdc, &smallrect, brush );

    // and at the end
    advance = x + width;
    smallrect.left = max( advance - max_width, smallrect.right );
    smallrect.right = advance;
    FillRect( hdc, &smallrect, brush );
}

void MyTabbedTextOut( HDC hdc,
                 char   **display,      // a reference to a string
                 int    len,            // number of chars to display
                 int    funny_italic,   // fix up begin and end ?
                 POINT  *p,             // reference to current position
                 type_style *ts,        // current style
                 RECT   *rect,
                 window_id id,
                 char   *otmp,
                 int    y
                 ){
    if( EditFlags.RealTabs ) {
        char    *tstring = *display;
        char    *string_end = tstring + len;
        int     tlen;
        RECT    new;

        while( tstring < string_end ) {
            tlen = 0;
            while( *tstring != '\t' ){
                // BAD! Kevin.P.
                // I think this portion of code is 8-bit dependant.
                // Should call getNext() or something from TabHell
                if( tstring == string_end ) break;
                tstring++;
                tlen++;
            }
            if( funny_italic ){
                // FunnyItalic so draw at bit at begining and end!
                funnyFix( rect, p->x, id, *display, tlen,
                          hdc, FontMaxWidth(thisFont), ts, thisBrush );
            }
            TextOut( hdc, 0, 0, *display, tlen );
            *display = tstring;
            if( tstring >= string_end ) break;

            tlen = 0;
            while( *tstring == '\t' ){
                if( tstring == string_end ) break;
                tstring++;
                tlen++;
            }
            if( tlen == 0 ) break;
            *display = tstring;

            GetCurrentPositionEx( hdc, p );
            new.left = p->x;
            new.right = (WinVirtualCursorPosition(otmp,tstring-otmp)
                           -LeftColumn) * FontAverageWidth(thisFont);
            new.top = rect->top;
            new.bottom = rect->bottom;
            FillRect(hdc, &new, thisBrush );
            MoveToEx( hdc, new.right, y, NULL );
            GetCurrentPositionEx( hdc, p );
        }
    }
    else {
        if( funny_italic ){
            // FunnyItalic so draw at bit at begining and end!
            funnyFix( rect, p->x, id, *display, len,
                  hdc, FontMaxWidth( thisFont ), ts, thisBrush );
        }
        TextOut( hdc, 0, 0, *display, len );
        *display += len;
    }
}

int DisplayLineInWindowWithSyntaxStyle( window_id id, int c_line_no,
    line *line, linenum line_no, char *text, int start_col, HDC hdc )
{
    char        *display, *old;
    char        *tmp, *otmp;
    dc          c_line;
    RECT        rect;
    int         height, len;
    int         x, y, indent;
    BOOL        changed;
    int         ssDifIndex;
    ss_block    *ss_cache, *ss_step;
    int         lastPos;


    type_style  *ts;
    POINT       p;
    BOOL        funny_italic=FALSE;
    //
    int prev_col;

    if( !AllowDisplay || BAD_ID( id ) ) return( ERR_NO_ERR );

    /* all font heights should be the same
     *   - note this may not quite be true for bold fonts but so what!
     */
    height = FontHeight( SEType[ SE_WHITESPACE ].font );
    y = ( c_line_no - 1 ) * height;
    GetClientRect( id, &rect );
    rect.top = y;
    rect.bottom = y + height;

    // set up tabs for drawing

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?