guixdisp.c

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

C
498
字号
/****************************************************************************
*
*                            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 "guiwind.h"
#include "guidlg.h"
#include "guistr.h"
#include <stdlib.h>
#include <string.h>
#ifdef UNIX
    #include "clibext.h"
#endif

/* buttons and icons that can be in the dialog */
typedef enum {
    NO_CONTROL  = 0x000,
    ABORT       = 0x001,
    CANCEL      = 0x002,
    IGNORE      = 0x004,
    NO          = 0x008,
    OK          = 0x010,
    RETRY       = 0x020,
    YES         = 0x040,
    EXCLAMATION = NO_CONTROL,
    QUESTION    = NO_CONTROL,
    INFORMATION = NO_CONTROL,
    STOP        = NO_CONTROL
} control_types;

/* information about the controls needed for each gui_message_type */
typedef struct message_types {
    gui_message_type    type;
    int                 num_controls;
    control_types       controls;
} message_types;

/* control definition for each control that can be in the dialog */
typedef struct control_pairs {
    gui_control_info    control;
    control_types       type;
} control_pairs;

/* struct used to describe string broken into segments that can be displayed
 * one per line */
typedef struct string_info {
    char        *text;
    int         length;
} string_info;

#define TEXT_ROW        1
#define TEXT_START_COL  2
#define ICON_ROW        1
#define BUTTON_ROW      3
#define BUTTON_WIDTH    7

/* control definition for each control that can be in the dialog */
static control_pairs MessageControls[] = {
 {  DLG_BUTTON( NULL,           GUI_RET_ABORT,  0, 0, BUTTON_WIDTH ),   ABORT       },
 {  DLG_BUTTON( NULL,           GUI_RET_CANCEL, 0, 0, BUTTON_WIDTH ),   CANCEL      },
 {  DLG_BUTTON( NULL,           GUI_RET_IGNORE, 0, 0, BUTTON_WIDTH ),   IGNORE      },
 {  DLG_BUTTON( NULL,           GUI_RET_NO,     0, 0, BUTTON_WIDTH ),   NO          },
 {  DLG_DEFBUTTON( NULL,        GUI_RET_OK,     0, 0, BUTTON_WIDTH ),   OK          },
 {  DLG_BUTTON( NULL,           GUI_RET_RETRY,  0, 0, BUTTON_WIDTH ),   RETRY       },
 {  DLG_BUTTON( NULL,           GUI_RET_YES,    0, 0, BUTTON_WIDTH ),   YES         },
 {  DLG_STRING( "!",                            0, 0, 1 ),              EXCLAMATION },
 {  DLG_STRING( "?",                            0, 0, 1 ),              QUESTION    },
 {  DLG_STRING( "i",                            0, 0, 1 ),              INFORMATION },
 {  DLG_STRING( NULL,                           0, 0, 5 ),              STOP        }
};
#define NUM_CONTROL_TYPES ( sizeof( MessageControls ) / sizeof( control_pairs ) )

/* static text controls used for displaying message */
static gui_control_info StaticMessage = DLG_STRING( NULL, TEXT_START_COL, TEXT_ROW, 0 );

/* information about the controls needed for each gui_message_type */
static message_types ControlsNeeded[] = {
  { GUI_ABORT_RETRY_IGNORE,     3,      ABORT | IGNORE | RETRY  },
  { GUI_EXCLAMATION,            1,      EXCLAMATION | OK        },
  { GUI_INFORMATION,            1,      INFORMATION | OK        },
  { GUI_QUESTION,               1,      QUESTION | OK           },
  { GUI_STOP,                   1,      STOP | OK               },
  { GUI_OK,                     1,      OK                      },
  { GUI_OK_CANCEL,              2,      OK | CANCEL             },
  { GUI_RETRY_CANCEL,           2,      RETRY | CANCEL          },
  { GUI_YES_NO,                 2,      YES | NO                },
  { GUI_YES_NO_CANCEL,          3,      YES | NO | CANCEL       },
  { GUI_SYSTEMMODAL,            0,      NO_CONTROL                      }
};
#define NUM_STYLES ( sizeof( ControlsNeeded ) / sizeof( message_types ) )

static bool MessagesInitialized = FALSE;

static void InitMessageControls( void )
{
    int j;

    for( j = 0; j < NUM_CONTROL_TYPES; j++ ) {
        switch( MessageControls[j].type ) {
            case ABORT:
                MessageControls[j].control.text = LIT( XAbort );
                break;
            case CANCEL:
                MessageControls[j].control.text = LIT( Cancel );
                break;
            case IGNORE:
                MessageControls[j].control.text = LIT( XIgnore );
                break;
            case NO:
                MessageControls[j].control.text = LIT( XNo );
                break;
            case OK:
                MessageControls[j].control.text = LIT( OK );
                break;
            case RETRY:
                MessageControls[j].control.text = LIT( XRetry );
                break;
            case YES:
                MessageControls[j].control.text = LIT( XYes );
                break;
            case STOP:
                MessageControls[j].control.text = LIT( Stop_Bang );
                break;
            default :
                break;
        }
    }
}

/*
 * DisplayMessage - callback function for dialog box
 */

bool DisplayMessage( gui_window *gui, gui_event gui_ev, void *param )
{
    gui_message_return *ret;
    unsigned            id;

    ret = GUIGetExtra( gui );
    switch( gui_ev ) {
    case GUI_CONTROL_CLICKED :
        GUI_GETID( param, id );
        switch( id ) {
        case GUI_RET_ABORT :
        case GUI_RET_CANCEL :
        case GUI_RET_IGNORE :
        case GUI_RET_NO :
        case GUI_RET_OK :
        case GUI_RET_RETRY :
        case GUI_RET_YES :
            *ret = id;
            GUICloseDialog( gui );
            return( TRUE );
            break;
        default :
            break;
        }
    default :
        break;
    }
    return( TRUE );
}

/*
 * GUIStrnDup -- duplicate the string text up to length characters
 */

bool GUIStrnDup( char * text, char ** new, int length )
{
    int str_len;

    if( text == NULL ) {
        *new = NULL;
        return( TRUE );
    } else {
        str_len = strlen( text );
        if( str_len < length ) {
            length = str_len;
        }
        *new = (char *)GUIMemAlloc( length + 1 );
        if( *new == NULL ) {
            return( FALSE );
        }
        strncpy( *new, text, length );
        (*new)[length] = '\0';
    }
    return( TRUE );
}


/*
* TabFilter -- Expand tabs to blanks
*/
char *TabFilter( char *message )
{
    char *new_message;
    char *start;
    int  tab_pos;

#define TAB_SIZE 4
                                /* allocate another chunk of memory since */
                                /* reallocating space for string literals is a no no */
    new_message = ( char *)GUIMemAlloc( strlen(message)+1 );
    strcpy( new_message, message );
    for( ; ; ){
        tab_pos = strcspn(new_message, "\t");
        if( tab_pos == strlen(new_message) ) break;   /* no more tabs */
        new_message = ( char *)GUIMemRealloc(new_message, strlen(new_message)+TAB_SIZE+1 );
        start = new_message + tab_pos;                /* don't forget the NULL */
        memmove(start+TAB_SIZE, start+1, strlen( start+1 )+1 );
        strnset( start, ' ', TAB_SIZE);
    }
    return( new_message );
}


/*
 * GetNumStringControls -- divide string up into segments that can be
 *                         displayed one per line.  Attempt to break
 *                         lines at spaces.
 */

⌨️ 快捷键说明

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