guixdraw.c

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

C
490
字号
/****************************************************************************
*
*                            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:  draw various character graphics
*
****************************************************************************/


#include "guiwind.h"
#include "guidraw.h"
#include "guixdraw.h"
#include "guix.h"
#include "guixutil.h"
#include "guicontr.h"
#include "guiscale.h"
#include "uiattrs.h"
#include "guigadgt.h"
#include "guiicon.h"
#include "guistat.h"
#include "guixinit.h"
#include "guixdlg.h"
#include <string.h>
#include "walloca.h"


extern int uionnec();

static char DrawIndex[] =
{
    DRAW_BLANK,                 // GUI_FRAME_TOP
    DRAW_BLANK,                 // GUI_FRAME_UL_CORNER
    DRAW_BLANK,                 // GUI_FRAME_LEFT
    DRAW_BLANK,                 // GUI_FRAME_LL_CORNER
    DRAW_BLANK,                 // GUI_FRAME_BOTTOM
    DRAW_BLANK,                 // GUI_FRAME_LR_CORNER
    DRAW_BLANK,                 // GUI_FRAME_RIGHT
    DRAW_BLANK,                 // GUI_FRAME_UR_CORNER
    DRAW_VERT_LINE,             // GUI_LR_VERT_BAR,
    DRAW_HOR_LINE,              // GUI_LR_HORZ_BAR,
    DRAW_BLANK,                 // GUI_LEFT_TITLE_MARK
    DRAW_BLANK,                 // GUI_RIGHT_TITLE_MARK
    DRAW_VERT_LINE,             // GUI_LEFT_GADGET_MARK
    DRAW_VERT_LINE,             // GUI_RIGHT_GADGET_MARK
    DRAW_BLANK,                 // GUI_TITLE_SPACE
    DRAW_CLOSER,                // GUI_CLOSER
    DRAW_MAXIMIZE,              // GUI_MAXIMIZE_GADGET
    DRAW_MINIMIZE,              // GUI_MINIMIZE_GADGET
    DRAW_RESIZE,                // GUI_RESIZE_GADGET
    DRAW_BLANK,                 // GUI_HOR_SCROLL
    DRAW_BLANK,                 // GUI_VERT_SCROLL
    DRAW_LEFT_POINT,            // GUI_LEFT_SCROLL_ARROW
    DRAW_RIGHT_POINT,           // GUI_RIGHT_SCROLL_ARROW
    DRAW_UP_POINT,              // GUI_UP_SCROLL_ARROW
    DRAW_DOWN_POINT,            // GUI_DOWN_SCROLL_ARROW
    DRAW_SLIDER,                // GUI_SCROLL_SLIDER

    DRAW_HOR_FRAME,             // GUI_INACT_FRAME_TOP
    DRAW_UL_CORNER,             // GUI_INACT_FRAME_UL_CORNER
    DRAW_VERT_FRAME,            // GUI_INACT_FRAME_LEFT
    DRAW_LL_CORNER,             // GUI_INACT_FRAME_LL_CORNER
    DRAW_HOR_FRAME,             // GUI_INACT_FRAME_BOTTOM
    DRAW_LR_CORNER,             // GUI_INACT_FRAME_LR_CORNER
    DRAW_VERT_FRAME,            // GUI_INACT_FRAME_RIGHT
    DRAW_UR_CORNER,             // GUI_INACT_FRAME_UR_CORNER
    DRAW_RIGHT_TITLE_MARK,      // GUI_INACT_LR_VERT_BAR,
    DRAW_C2,                    // GUI_INACT_LR_HORZ_BAR,
    DRAW_LEFT_TITLE_MARK,       // GUI_INACT_LEFT_TITLE_MARK
    DRAW_RIGHT_TITLE_MARK,      // GUI_INACT_RIGHT_TITLE_MARK
    DRAW_LEFT_TITLE_MARK,       // GUI_INACT_LEFT_GADGET_MARK
    DRAW_RIGHT_TITLE_MARK,      // GUI_INACT_RIGHT_GADGET_MARK
    DRAW_BLANK,                 // GUI_INACT_TITLE_SPACE
    DRAW_CLOSER,                // GUI_INACT_CLOSER
    DRAW_MAXIMIZE,              // GUI_INACT_MAXIMIZE_GADGET
    DRAW_MINIMIZE,              // GUI_INACT_MINIMIZE_GADGET
    DRAW_RESIZE,                // GUI_INACT_RESIZE_GADGET
    DRAW_HOR_FRAME_DBL,         // GUI_INACT_HOR_SCROLL
    DRAW_VERT_FRAME_DBL,        // GUI_INACT_VERT_SCROLL
    DRAW_LEFT_POINT,            // GUI_INACT_LEFT_SCROLL_ARROW
    DRAW_RIGHT_POINT,           // GUI_INACT_RIGHT_SCROLL_ARROW
    DRAW_UP_POINT,              // GUI_INACT_UP_SCROLL_ARROW
    DRAW_DOWN_POINT,            // GUI_INACT_DOWN_SCROLL_ARROW
    DRAW_BLOCK,                 // GUI_INACT_SCROLL_SLIDER

    DRAW_BLOCK_SLIDER,          // GUI_DIAL_VERT_SCROLL
    DRAW_UP_POINT,              // GUI_DIAL_UP_SCROLL_ARROW,
    DRAW_DOWN_POINT,            // GUI_DIAL_DOWN_SCROLL_ARROW,
    DRAW_BLOCK,                 // GUI_DIAL_SCROLL_SLIDER
};

char DrawingChars[DRAW_LAST];
#define GET_CHAR( val, inact ) ( &DrawingChars[ DrawIndex[val+ GUI_INACTIVE_OFFSET * inact] ] )

#define TOP( inact )            GET_CHAR( GUI_FRAME_TOP, inact )
#define UL_CORNER( inact )      GET_CHAR( GUI_FRAME_UL_CORNER, inact )
#define LEFT( inact )           GET_CHAR( GUI_FRAME_LEFT, inact )
#define LL_CORNER( inact )      GET_CHAR( GUI_FRAME_LL_CORNER, inact )
#define BOTTOM( inact )         GET_CHAR( GUI_FRAME_BOTTOM, inact )
#define LR_CORNER( inact )      GET_CHAR( GUI_FRAME_LR_CORNER, inact )
#define RIGHT( inact )          GET_CHAR( GUI_FRAME_RIGHT, inact )
#define UR_CORNER( inact )      GET_CHAR( GUI_FRAME_UR_CORNER, inact )
#define LT_MARK( inact )        GET_CHAR( GUI_LEFT_TITLE_MARK, inact )
#define RT_MARK( inact )        GET_CHAR( GUI_RIGHT_TITLE_MARK, inact )
#define LG_MARK( inact )        GET_CHAR( GUI_LEFT_GADGET_MARK, inact )
#define RG_MARK( inact )        GET_CHAR( GUI_RIGHT_GADGET_MARK, inact )
#define TITLE_SP( inact )       GET_CHAR( GUI_TITLE_SPACE, inact )
#define CLOSER( inact )         GET_CHAR( GUI_CLOSER, inact )
#define MIN_GAD( inact )        GET_CHAR( GUI_MINIMIZE_GADGET, inact )
#define MAX_GAD( inact )        GET_CHAR( GUI_MAXIMIZE_GADGET, inact )
#define RESIZE_GAD( inact )     GET_CHAR( GUI_RESIZE_GADGET, inact )
#define LRV_BAR( inact )        GET_CHAR( GUI_LR_VERT_BAR, inact )
#define LRH_BAR( inact )        GET_CHAR( GUI_LR_HORZ_BAR, inact )

/* includes from guixmain.c */
extern gui_window *GUICurrWnd;

#define TITLE_EXTRA_AMOUNT      4
#define GADGET_WIDTH            3

void GUIInitDrawingChars( bool dbcs )
{
#ifdef __LINUX__
    #define draw_pick( a,b,c,d,e ) DrawingChars[DRAW_##a] = e;
    #include "guidraw.h"
    #undef draw_pick
#else
    if( dbcs ) {
        if( uionnec() ) {
            #define draw_pick( a,b,c,d,e ) DrawingChars[DRAW_##a] = d;
            #include "guidraw.h"
            #undef draw_pick
        } else {
            #define draw_pick( a,b,c,d,e ) DrawingChars[DRAW_##a] = c;
            #include "guidraw.h"
            #undef draw_pick
        }
    } else {
        #define draw_pick( a,b,c,d,e ) DrawingChars[DRAW_##a] = b;
        #include "guidraw.h"
        #undef draw_pick
    }
#endif
}


char GUIGetCharacter( gui_draw_char draw_char )
{
    if( draw_char < GUI_NUM_DRAW_CHARS ) {
        return( DrawingChars[ (unsigned)DrawIndex[ draw_char ] ] );
    }
    return( (char)0 );
}

void GUISetCharacter( gui_draw_char draw_char, char ch )
{
    ch=ch;draw_char=draw_char;
    // not implemented in this revision
    // some apps do a
    // if an app calls GUISetCharacter( GUI_SCROLL_SLIDER, 177 );
    // just delete the call since that is the default now.
}

static void DrawText( gui_window *wnd, int row, int col, ATTR attr, char *buff,
                      int length )
{
    if( length > 0 ) {
        uivtextput( &wnd->screen, row, col, attr, buff, length );
    }
}

/*
 * DrawFrame -- draw the frame of the window
 */

static void DrawFrame( gui_window *wnd )
{
    SAREA       area;
    ATTR        attr, title_attr;
    char        *buffer;
    char        *buff;
    int         width;
    int         str_length;
    int         indent;
    int         title_extra, closer_amount;
    char        *lgadget, *mgadget, *rgadget;
    int         inact;
    bool        inact_gadgets;
    int         len;

    if( (wnd->style & GUI_NOFRAME) ||
        !( (wnd->flags & FRAME_INVALID) || (wnd->flags & TITLE_INVALID) ) ) {
        return;
    }
    inact = 0;
    if( ( wnd == GUICurrWnd ) || ( wnd->parent == NULL ) ) {
        attr = wnd->colours[GUI_FRAME_ACTIVE];
        title_attr = attr;
    } else {
        if( !( GUIGetWindowStyles() & GUI_INACT_SAME ) ) {
            inact = 1;
        }
        attr = wnd->colours[GUI_FRAME_INACTIVE];
        title_attr = wnd->colours[GUI_TITLE_INACTIVE];
    }
    inact_gadgets = GUIGetWindowStyles() & GUI_INACT_GADGETS;
    if( wnd->flags & FRAME_INVALID ) {
        DrawText( wnd, wnd->screen.area.height-1, 0, attr,
                  LL_CORNER( inact ), 1 );
        DrawText( wnd, 0, 0, attr, UL_CORNER( inact ), 1 );
        DrawText( wnd, 0, wnd->screen.area.width-1, attr,
                  UR_CORNER( inact ), 1 );
        DrawText( wnd, wnd->screen.area.height-1,
                  wnd->screen.area.width-1, attr, LR_CORNER( inact ), 1 );
        /* bottom border */
        if( GUIUseGadget( wnd, wnd->hgadget ) ) {
            if( GUIDrawGadgetLine( wnd->hgadget ) ) {
                DrawText( wnd, wnd->screen.area.height-1,
                          wnd->screen.area.width-1-GUIGetScrollOffset(),
                          attr, LRV_BAR( inact ), 1 );
            }
        } else {
            area.col = 1;
            area.row = wnd->screen.area.height-1;

⌨️ 快捷键说明

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