dlgstat.c

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

C
504
字号
/****************************************************************************
*
*                            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:  GUI sample program dialogs.
*
****************************************************************************/


#include <string.h>
#include "sample.h"
#include "dlgstat.h"
#include "samprc.h"

bool            DialogScaled    = FALSE;
bool            ButtonsScaled   = FALSE;
bool            ControlsScaled  = FALSE;
char * ListBoxData[] = { "one", "two", "three" };
int    NUM_LIST_BOX_DATA = ( sizeof( ListBoxData ) / sizeof( char * ) );
extern out_info Child1_Out;

static  char            *LongText       = "inserted_really_long_piece_of_text";

static gui_resource DlgWinIcon = { WIN1, "Win1" };

gui_create_info DlgWin = {
    "Dlg Window",
    { 20, 20, 200, 200 },
    GUI_SCROLL_BOTH,
    GUI_SCROLL_EVENTS | GUI_ALL,
    NULL,
    0,
    NULL,
    0,
    NULL,
    &Child1EventWnd,
    &Child1_Out,
    &DlgWinIcon,
    0
};

gui_control_info Controls[] = {
  { GUI_STATIC,
    "Hi there",
    { 25, 180, 125, 45 },
    NULL,
    GUI_NOSCROLL,
    AUTOMATIC,
    STATIC_CONTROL },
  { GUI_EDIT,
    "hello",
    { 175, 180, 100, 120 },
    NULL,
    GUI_NOSCROLL,
    GUI_TAB_GROUP | AUTOMATIC | GUI_FOCUS | GUI_CONTROL_MULTILINE | GUI_CONTROL_WANTRETURN,
    EDIT_CONTROL },
  { GUI_GROUPBOX,
    "Group 1",
    { 50, 270, 300, 135 },
    NULL,
    GUI_NOSCROLL,
    AUTOMATIC,
    -1},
  { GUI_RADIO_BUTTON,
    "RA&DIO 1",
    { 25, 45, BUTTON_WIDTH, BUTTON_HEIGHT },
    NULL,
    GUI_NOSCROLL,
    GUI_GROUP | GUI_TAB_GROUP | AUTOMATIC,
    RADIOBUTTON_CONTROL1 },
  { GUI_RADIO_BUTTON,
    "&RADIO 2",
    { 150, 45, BUTTON_WIDTH, BUTTON_HEIGHT },
    NULL,
    GUI_NOSCROLL,
    GUI_GROUP | AUTOMATIC | GUI_CHECKED,
    RADIOBUTTON_CONTROL2 },
  { GUI_GROUPBOX,
    "Group 2",
    { 10, 270, 340, 135 },
    NULL,
    GUI_NOSCROLL,
    AUTOMATIC,
    -1},
  { GUI_CHECK_BOX,
    "&CHECK 1",
    { 25, 315, BUTTON_WIDTH + 20, BUTTON_HEIGHT },
    NULL,
    GUI_NOSCROLL,
    GUI_GROUP | GUI_TAB_GROUP | AUTOMATIC,
    CHECKBOX_CONTROL1 },
  { GUI_CHECK_BOX,
    "CHECK &2",
    { 170, 315, BUTTON_WIDTH + 20, BUTTON_HEIGHT },
    NULL,
    GUI_NOSCROLL,
    GUI_GROUP | GUI_CHECKED | AUTOMATIC,
    CHECKBOX_CONTROL2 },
  { GUI_DEFPUSH_BUTTON,
    "OK",
    { 175, 450, BUTTON_WIDTH, BUTTON_HEIGHT },
    NULL,
    GUI_NOSCROLL,
    GUI_TAB_GROUP | AUTOMATIC,
    OKBUTTON_CONTROL },
  { GUI_PUSH_BUTTON,
    "Cancel",
    { 25, 450, BUTTON_WIDTH, BUTTON_HEIGHT },
    NULL,
    GUI_NOSCROLL,
    GUI_TAB_GROUP | AUTOMATIC,
    CANCELBUTTON_CONTROL } ,
  { GUI_EDIT_COMBOBOX,
    "Title",
    { 350, 45, 150, 250 },
    NULL,
    GUI_VSCROLL | GUI_HSCROLL,
    GUI_TAB_GROUP,
    LISTBOX_CONTROL },
  { GUI_PUSH_BUTTON,
    "&Add Data",
    { 325, 450, BUTTON_WIDTH, BUTTON_HEIGHT },
    NULL,
    GUI_NOSCROLL,
    GUI_TAB_GROUP | AUTOMATIC,
    ADDBUTTON_CONTROL } ,
  { GUI_PUSH_BUTTON,
    "C&lear",
    { 475, 450, BUTTON_WIDTH, BUTTON_HEIGHT },
    NULL,
    GUI_NOSCROLL,
    GUI_TAB_GROUP | AUTOMATIC,
    CLEARBUTTON_CONTROL }
};

static gui_create_info DialogControl = {
    "Static Dialog Box",                // Title
    { 100, 100, 700, 700 },             // Position
    GUI_NOSCROLL,                       // Scroll Styles
    GUI_VISIBLE | GUI_CLOSEABLE,        // Window Styles
    NULL,                               // Parent
    0,                                  // Number of menus
    NULL,                               // Menu's
    0,                                  // Number of color attributes
    NULL,                               // Array of color attributes
    &StaticDialogEventWnd,              // Callback function
    NULL,                               // Extra
    NULL,                               // Icon
    0
};

char *ListBoxFunc( void *param, unsigned item )
{
    char        **list;

    list = (char **)param;
    return( list[item] );
}

void ContrCallBack( gui_window *gui, unsigned id, void *param )
{
    int                 i;
    int                 *num;
    gui_control_class   control_class;

    gui = gui;
    num = (int *)param;
    for( i = 0; i < NUM_CONTROLS; i ++ ) {
        if( Controls[i].id == id ) {
            (*num)++;
            if( !GUIGetControlClass( gui, id, &control_class ) ||
                ( control_class != Controls[i].control_class ) ) {
                GUIDisplayMessage( gui, "Got Invalid Control Class",
                                   "Doing Enum Controls", GUI_INFORMATION );
            }
            return;
        }
    }
    GUIDisplayMessage( gui, "Got Invalid ID", "Doing Enum Controls",
                       GUI_INFORMATION );
}

static void CheckNumControls( gui_window *gui, int act_num )
{
    int num;

    num = 0;
    GUIEnumControls( gui, &ContrCallBack, &num );
    if( num == act_num ) {
#if 0
        GUIDisplayMessage( gui, "Got Correct Number of Controls",
                           "Doing Enum Controls", GUI_INFORMATION );
#endif
    } else {
        GUIDisplayMessage( gui, "Got Incorrect Number of Controls",
                           "Doing Enum Controls", GUI_STOP );
    }
}

static void InitDialog( gui_window *parent )
{
    parent = parent;
}

/*
 * StaticDialogEventWnd
 */

bool StaticDialogEventWnd( gui_window *gui, gui_event gui_ev, void *param )
{
    bool        ret;
    unsigned    id;
    char        *new;
    unsigned    i;
    char        *text;
    int         sel;
    int         size;
    int         num;
    gui_rect    rect;
    int         extent, top, start, end;
    gui_rgb     rgb, green;

    ret = TRUE;
    switch( gui_ev ) {
    case GUI_PAINT :
        GUIGetRGB( GUI_BRIGHT_YELLOW, &rgb );
        GUIGetRGB( GUI_GREEN, &green );
        GUIDrawTextRGB( gui, "Line Draw!", 10, 0, 1, green, rgb );
        GUIDrawTextRGB( gui, "Line Draw!", 10, 1, 1, rgb, green );
        GUIDrawBar( gui,  7, 1, 30, GUI_BAR_SIMPLE, GUI_FRAME_ACTIVE, TRUE );

⌨️ 快捷键说明

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