dlggen.c

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

C
916
字号
/****************************************************************************
*
*                            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:  Generate dynamic dialogs.
*
****************************************************************************/


/*
*   COMMENTS: This generic dialog box module replaces the old dialog box
*             functions for - Welcome Dialog
*                           - Modify Dialog
*             and is general enough for other dialogs that may be needed
*             in the future.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gui.h"
#include "guistr.h"
#include "guidlg.h"
#include "dlgbutn.h"
#include "setup.h"
#include "setupinf.h"
#include "dlggen.h"
#include "genvbl.h"
#include "genctrl.h"
#include "gendlg.h"
#include "utils.h"
#include "ctype.h"
#if !defined( __WATCOMC__ )
#include <clibext.h>
#endif


/* A few new defines, rather than hard numbers in source */
/* Controls per line */
#define MAX_CTRL_PER_LINE      4
#define NORMAL_BUTTONS         (MAX_CTRL_PER_LINE - 1)
#define NORMAL_CHECKMARKS      2

/* Extra chars for CONTROL width calculations */
/* Necessary to handle different character widths when */
/* using proportional fonts (most graphical UI's).     */
#define BUTTON_EXTRA           2

/* Ends up close to horizontal default size for button in dialogs */
#define WIN_BW                15

#define WIN_BUTTON_POS( num, of, cols, bwidth ) \
    ( of == 1 ? \
        (cols - bwidth) / 2 : \
        ( 1 + ( num - 1 ) * ( bwidth + BUTTON_GAP( cols, of, bwidth, 1 ) ) ) )


extern vhandle          FullInstall;
extern vhandle          SelectiveInstall;

typedef struct dlg_window_set {
    dlg_state           state;
    a_dialog_header     *current_dialog;     /* stuff needed in future */
} DLG_WINDOW_SET;

dlg_state       GenericDialog( gui_window *parent, a_dialog_header * );
extern void     SetDefaultAutoSetValue( vhandle var_handle );
extern void     ResetDriveInfo();

int VisibilityCondition = 0;

static gui_control_class ControlClass( int id,
                                       a_dialog_header *curr_dialog )
/********************************************************************/
/* return the control class of a variable based on its id. */
{
    int                 i;

    for( i = 0; i < curr_dialog->num_controls; i++ ) {
        if( curr_dialog->controls[ i ].id == id ) {
            return( curr_dialog->controls[ i ].control_class );
        }
    }
    SetupError( "IDS_CONTROLCLASSERROR" );
    return( GUI_NUM_CONTROL_CLASSES );
}


static void SetDynamic( gui_window *gui, vhandle var_handle, bool *drive_checked )
/*******************************************************************************/
{
    char        buff[256];
    char        *p;

    p = VarGetStrVal( var_handle );
    if( !*drive_checked ) {
        while( *p ) {
            if( *p == '%' ) {
                if( strnicmp( p, "%DriveFree", 10 ) == 0 ) {
                    CheckDrive( FALSE );
                    *drive_checked = TRUE;
                }
            }
            ++p;
        }
    }
    ReplaceVars( buff, VarGetStrVal( var_handle ) );
    AddInstallName( buff, FALSE );
    GUISetText( gui, VarGetId( var_handle ), buff );
}


static void SetDefaultVals( gui_window *gui, a_dialog_header *curr_dialog )
/*************************************************************************/
/* Set the default variable values. Decide how to set these  */
/* default values based on edit control type. */
{
    int                 i;
    gui_control_class   a_control_class;
    vhandle             var_handle;
    char                *cond;
    bool                drive_checked;

    drive_checked = FALSE;
    for( i = 0; curr_dialog->pVariables[ i ] != NO_VAR; ++i ) {
        var_handle = curr_dialog->pVariables[ i ];
        cond = curr_dialog->pConditions[ i ];
        if( !curr_dialog->defaults_set &&
            cond != NULL && VarGetIntVal( var_handle ) == 0 ) {
            if( isdigit( *cond ) ) {
                SetVariableByHandle( var_handle, cond );
            } else if( EvalCondition( cond ) ) {
                SetVariableByHandle( var_handle, "1" );
            }
        }
        a_control_class = ControlClass( VarGetId( var_handle ), curr_dialog );
        switch( a_control_class ) {
        case GUI_STATIC:
            SetDynamic( gui, var_handle, &drive_checked );
            break;
        case GUI_RADIO_BUTTON:
        case GUI_CHECK_BOX:
            GUISetChecked( gui, VarGetId( var_handle ), VarGetIntVal( var_handle ) != 0 );
            break;
        case GUI_EDIT_MLE:
        case GUI_EDIT:
            GUISetText( gui, VarGetId( var_handle ), VarGetStrVal( var_handle ) );
            break;
        default:
            break;
        }
    }
    curr_dialog->defaults_set = TRUE;
}

static void SetFocusCtrl( gui_window *gui, a_dialog_header *curr_dialog )
/*************************************************************************/
/* Set the default variable values. Decide how to set these  */
/* default values based on edit control type. */
{
    int                 i, j;

    for( i = 0; i < curr_dialog->num_controls; i++ ) {
        switch( curr_dialog->controls[i].control_class ) {
        case GUI_EDIT_MLE:
        case GUI_EDIT:
            GUISetFocus( gui, curr_dialog->controls[i].id );
            return;
        case GUI_RADIO_BUTTON:
        case GUI_CHECK_BOX:
            for( j = i;; ++j ) {
                if( curr_dialog->controls[j].control_class != GUI_RADIO_BUTTON
                &&  curr_dialog->controls[j].control_class != GUI_CHECK_BOX
                ) {
                    break;
                }
                if( GUIIsChecked( gui, curr_dialog->controls[ j ].id ) ) {
                    GUISetFocus( gui, curr_dialog->controls[j].id );
                    return;
                }
            }
            GUISetFocus( gui, curr_dialog->controls[i].id );
            return;
        default:
            break;
        }
    }
    for( i = 0; i < curr_dialog->num_controls; i++ ) {
        if( curr_dialog->controls[i].control_class == GUI_DEFPUSH_BUTTON ) {
            GUISetFocus( gui, curr_dialog->controls[i].id );
            return;
        }
    }
}


static void GetVariableVals( gui_window *gui,
                             a_dialog_header *curr_dialog, bool closing )
/***********************************************************************/
/* Get the input variable values. Decide how to set these */
/* default values based on edit control type. */
{
    char                *text;
    int                 i;
    int                 is_checked;
    gui_control_class   a_control_class;
    vhandle             *pVariable;
    vhandle             var_handle;
    bool                drive_checked;

    drive_checked = FALSE;
    pVariable = curr_dialog->pVariables;
    for( i = 0; pVariable[ i ] != NO_VAR; i++ ) {
        var_handle = pVariable[ i ];
        a_control_class = ControlClass( VarGetId( var_handle ), curr_dialog );
        switch( a_control_class ) {
        case GUI_STATIC:
            if( !closing ) {
                SetDynamic( gui, var_handle, &drive_checked );
            }
            break;
        case GUI_RADIO_BUTTON:
        case GUI_CHECK_BOX:
            is_checked = (int)GUIIsChecked( gui, VarGetId( var_handle ) );
            if( is_checked ) {
                if( VarIsRestrictedFalse( var_handle ) ) {
                    if( !closing ) {
                        MsgBox( gui, "IDS_NODISKFOROPTION", GUI_OK );
                        GUISetChecked( gui, VarGetId( var_handle ), 0 );
                        if( var_handle == FullInstall ) {
                            GUISetChecked( gui, VarGetId( SelectiveInstall ), 1 );
                        }
                    }
                    SetVariableByHandle( var_handle, "0" );
                    if( var_handle == FullInstall ) {
                        SetVariableByHandle( SelectiveInstall, "1" );
                    }
                } else {
                    SetVariableByHandle( var_handle, "1" );
                }
            } else {
                SetVariableByHandle( var_handle, "0" );
            }
            break;
        case GUI_EDIT:
            text = GUIGetText( gui, VarGetId( var_handle ) );
            if( text != NULL ) {
                SetVariableByHandle( var_handle, text );
                GUIMemFree( text );
            }
        break;
        default:
            break;
        }
    }
}


static void CheckAnyCheck( gui_window *gui, a_dialog_header *child )
/******************************************************************/
/* If any of the sub-dialog check boxes are on, turn on the */
/* 'anycheck' variable */
{
    int                 i;

    for( i = 0; child->pVariables[ i ] != NO_VAR; i++ ) {
        if( ControlClass( VarGetId( child->pVariables[i] ), child ) == GUI_CHECK_BOX
         && VarGetIntVal( child->pVariables[i] ) ) {
            SetVariableByHandle( child->any_check, "1" );
            GUISetChecked( gui, VarGetId( child->any_check ), 1 );
            return;
        }
    }
    SetVariableByHandle( child->any_check, "0" );
    GUISetChecked( gui, VarGetId( child->any_check ), 0 );
}


static void CheckChildChecks( a_dialog_header *child )
/******************************************************************/
/* If all child checks are off, set them to the defaults */
{
    int                 i;

⌨️ 快捷键说明

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