⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wdecust.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    for ( type = 0; type < control->control_info.ms.wCtlTypes; type++ ) {
        current = (WdeCurrCustControl *)
            WdeMemAlloc ( sizeof(WdeCurrCustControl) );
        if ( current == NULL ) {
            WdeWriteTrail("WdeSetSelectWinCBox: alloc failed!");
            return ( FALSE );
        }
        current->control = control;
        current->type    = type;
        if ( control->ms_lib ) {
            index =
                SendMessage ( cbox, CB_ADDSTRING, 0, (LPARAM) (LPCSTR )
                              control->control_info.ms.Type[type].szDescr );
        } else {
            index =
                SendMessage ( cbox, CB_ADDSTRING, 0, (LPARAM) (LPCSTR )
                              control->control_info.bor.Type[type].szDescr );
        }

        if ( ( index == CB_ERR ) || ( index == CB_ERRSPACE ) ) {
            WdeWriteTrail("WdeSetSelectWinCBox: CB_ADDSTRING failed!");
            WdeMemFree ( current );
            return ( FALSE );
        }

        index = SendMessage ( cbox, CB_SETITEMDATA, index,
                              (LPARAM) (DWORD) current );

        if ( index == CB_ERR ) {
            WdeWriteTrail("WdeSetSelectWinCBox: CB_SETITEMDATA failed!");
            WdeMemFree ( current );
            return ( FALSE );
        }

    }

    return ( TRUE );
}

Bool WdeSetSelectWin ( HWND win )
{
    LIST           *llist;
    LIST           *clist;
    WdeCustLib     *lib;
    WdeCustControl *control;
    HWND            cbox;

    cbox = GetDlgItem ( win, IDB_CUST_DESC );

    if ( WdeCustomLibList != NULL ) {
        for ( llist = WdeCustomLibList; llist; llist = ListNext(llist) ) {
            lib = (WdeCustLib *) ListElement(llist);
            if ( lib->controls != NULL ) {
                for ( clist=lib->controls; clist; clist=ListNext(clist) ) {
                    control = (WdeCustControl *) ListElement(clist);
                    if ( !WdeSetSelectWinCBox ( cbox, control ) ) {
                        return ( FALSE );
                    }
                }
            }
        }
    }

    return ( TRUE );
}

Bool WdeSetCurrentControl ( HWND win, int which )
{
    LRESULT             index;
    WdeCurrCustControl *current;

    index = SendDlgItemMessage ( win, IDB_CUST_DESC, CB_GETCOUNT, 0, 0 );
    if ( !index || (index == CB_ERR) ) {
        return ( TRUE );
    }

    index = SendDlgItemMessage ( win, IDB_CUST_DESC, CB_GETCURSEL, 0, 0 );

    current = (WdeCurrCustControl *)
        SendDlgItemMessage ( win, IDB_CUST_DESC, CB_GETITEMDATA,
                             (WPARAM)index, 0 );

    if ( current == NULL ) {
        WdeWriteTrail("WdeSetCurrentControl: CB_GETITEMDATA failed!");
        return ( FALSE );
    }

    WdeCurrControl[which].control = current->control;
    WdeCurrControl[which].type    = current->type;

    return ( TRUE );
}

void WdeMapCustomSize( uint_32 *w, uint_32 *h, WdeResizeRatio *r )
{
    DialogSizeInfo      dsize;
    RECT                trect;

    if( !(*w & 0x8000) && !(*h & 0x8000) ) {
        dsize.x      = 0;
        dsize.y      = 0;
        dsize.width  = *w;
        dsize.height = *h;
        WdeDialogToScreen ( NULL, r, &dsize, &trect );
        *w  = trect.right;
        *h = trect.bottom;
    } else if( !(*w & 0x8000) ) {
        dsize.x      = 0;
        dsize.y      = 0;
        dsize.width  = *w;
        dsize.height = 0;
        WdeDialogToScreen ( NULL, r, &dsize, &trect );
        *w  = trect.right;
    } else if( !(*h & 0x8000) ) {
        dsize.x      = 0;
        dsize.y      = 0;
        dsize.width  = 0;
        dsize.height = *h;
        WdeDialogToScreen ( NULL, r, &dsize, &trect );
        *h = trect.bottom;
    }
    if( *w & 0x8000 ) {
        *w &= ~0x8000;
    }
    if( *h & 0x8000 ) {
        *h &= ~0x8000;
    }
}

Bool WdePreviewSelected ( HWND win )
{
    WdeCurrCustControl *current;
    LRESULT             index;
    char               *class;
    char               *caption;
    HWND                pwin;
    HWND                parea;
    RECT                psize;
    RECT                trect;
    uint_32             pstyle;
    POINT               p;
    uint_32             pwidth;
    uint_32             pheight;
    WdeResizeRatio      resizer;

    index = SendDlgItemMessage ( win, IDB_CUST_DESC, CB_GETCOUNT, 0, 0 );
    if ( !index || (index == CB_ERR) ) {
        return ( TRUE );
    }

    parea = GetDlgItem ( win, IDB_CUST_PREVIEW );

    pwin = GetDlgItem ( win, WDE_PREVIEW_ID );
    if ( pwin != NULL ) {
        DestroyWindow ( pwin );
    }

    GetClientRect ( parea, &psize );

    InflateRect ( &psize, -WDE_PREVIEW_PAD, -WDE_PREVIEW_PAD );

    index = SendDlgItemMessage ( win, IDB_CUST_DESC, CB_GETCURSEL, 0, 0 );

    current = (WdeCurrCustControl *)
        SendDlgItemMessage ( win, IDB_CUST_DESC, CB_GETITEMDATA,
                             (WPARAM)index, 0 );

    if ( current == NULL ) {
        WdeWriteTrail("WdePreviewSelected: CB_GETITEMDATA failed!");
        return ( FALSE );
    }

    if ( current->control->ms_lib ) {
        class=current->control->control_info.ms.szClass;
        caption=current->control->control_info.ms.szTitle;
        pstyle=current->control->control_info.ms.Type[current->type].dwStyle;
        pwidth=current->control->control_info.ms.Type[current->type].wWidth;
        pheight=current->control->control_info.ms.Type[current->type].wHeight;
    } else {
        class=current->control->control_info.bor.szClass;
        caption=current->control->control_info.bor.szTitle;
        pstyle=current->control->control_info.bor.Type[current->type].dwStyle;
        pwidth=current->control->control_info.bor.Type[current->type].wWidth;
        pheight=current->control->control_info.bor.Type[current->type].wHeight;
    }

    WdeGetResizerFromFont ( &resizer, "System", 10 );

    WdeMapCustomSize( &pwidth, &pheight, &resizer );

    if ( pwidth > (psize.right - psize.left) ) {
        pwidth = psize.right - psize.left;
    }

    if ( pheight > (psize.bottom - psize.top) ) {
        pheight = psize.bottom - psize.top;
    }

    p.x = 0;
    p.y = 0;


    SendDlgItemMessage ( win, IDB_CUST_CLASSNAME, WM_SETTEXT,
                         0, (LPARAM) (LPCSTR ) class );

    pstyle &= ( 0xffffffff ^ ( WS_POPUP | WS_VISIBLE | WS_TABSTOP ) );
    pstyle |= WS_CHILD;

    pwin = CreateWindow ( class, caption,
                          pstyle, p.x, p.y, pwidth, pheight, win,
                          (HMENU) WDE_PREVIEW_ID, WdeGetAppInstance(), NULL);

    if ( pwin == NULL ) {
        WdeWriteTrail("WdePreviewSelected: CreateWindow failed!");
        return ( FALSE );
    }

    GetClientRect ( pwin, &trect );

    pwidth  = trect.right;
    pheight = trect.bottom;

    p.x = ( (psize.right - psize.left) - pwidth ) / 2 + WDE_PREVIEW_PAD;
    p.y = ( (psize.bottom - psize.top) - pheight ) / 2 + WDE_PREVIEW_PAD;

    MapWindowPoints ( parea, win, &p, 1 );

    SetWindowPos ( pwin, (HWND) NULL, p.x, p.y, 0, 0,
                   SWP_NOZORDER | SWP_NOSIZE );

    ShowWindow ( pwin, SW_SHOW );

    return ( TRUE );
}

BOOL WINEXPORT WdeSelectCustProc ( HWND hDlg, UINT message,
                                   WPARAM wParam, volatile LPARAM lParam )
{
    static int which = 0;
    BOOL       ret;

    ret = FALSE;

    switch (message) {

        case WM_SETFONT:
            WdeSelectFont = (HFONT) wParam;
            break;

        case WM_INITDIALOG:
            which = *( (int *) lParam );
            if ( !WdeSetSelectWin ( hDlg ) ) {
                WdeFreeSelectWinCBox ( hDlg );
                EndDialog(hDlg, FALSE);
            }
            SendDlgItemMessage ( hDlg, IDB_CUST_DESC, CB_SETCURSEL, 0, 0 );
            WdePreviewSelected ( hDlg );
            break;

        case WM_COMMAND:
            switch ( LOWORD(wParam) ) {

                case IDB_HELP:
                    WinHelp( WdeGetMainWindowHandle(), "resdlg.hlp",
                             HELP_CONTENTS, 0 );
                    break;

                case IDOK:
                    WdeSetCurrentControl ( hDlg, which );
                    WdeFreeSelectWinCBox ( hDlg );
                    EndDialog(hDlg, TRUE);
                    ret  = TRUE;
                    break;

                case IDCANCEL:
                    WdeFreeSelectWinCBox ( hDlg );
                    EndDialog(hDlg, FALSE);
                    ret  = TRUE;
                    break;

                case IDB_CUST_DESC:
                    switch ( GET_WM_COMMAND_CMD(wParam,lParam) ) {
                        case CBN_CLOSEUP:
                        case CBN_SELCHANGE:
                            WdePreviewSelected ( hDlg );
                            break;
                    }

            }
    }

    return ( ret );
}

void WdeSetLoadCustInfo ( HWND hDlg, WdeCustLib *lib )
{
    char info[_MAX_FNAME+4];
    char style[_MAX_FNAME+5];
    char flags[_MAX_FNAME+5];

    _splitpath ( lib->file_name, NULL, NULL, info, NULL );

    strlwr ( info );
    info[0] = toupper ( info[0] );

    strcpy ( style, info );
    strcpy ( flags, info );

    strcat ( info,  "Info" );
    strcat ( style, "Style" );
    strcat ( flags, "Flags" );

    WdeSetEditWithStr ( info,  hDlg, IDB_CUST_INFO );
    WdeSetEditWithStr ( style, hDlg, IDB_CUST_STYLE );
    WdeSetEditWithStr ( flags, hDlg, IDB_CUST_FLAGS );

}

void WdeSetLoadCustInfoOrd( HWND hDlg )
{
    char str[2];

    str[1] = '\0';

    str[0] = '0' + CCINFOORD;
    WdeSetEditWithStr( str, hDlg, IDB_CUST_INFO );
    str[0] = '0' + CCSTYLEORD;
    WdeSetEditWithStr( str, hDlg, IDB_CUST_STYLE );
    str[0] = '0' + CCFLAGSORD;
    WdeSetEditWithStr( str, hDlg, IDB_CUST_FLAGS );
}

void WdeEnableNonStandardCustInfo ( HWND hDlg, Bool flag, Bool init )
{
    int i;

    for ( i=IDB_CUST_INFO; i<=IDB_CUST_GBOX; i++ ) {
        if ( init ) {
            SendMessage ( GetDlgItem ( hDlg, i ), WM_ENABLE, flag, 0 );
        } else {
            EnableWindow ( GetDlgItem ( hDlg, i ), flag );
        }
    }
}

Bool WdeGetLoadCustInfo ( HWND hDlg, WdeCustLib *lib )
{
    char    *info;
    char    *style;
    char    *flags;
    Bool     ok;

    ok = TRUE;

    if ( !IsDlgButtonChecked ( hDlg, IDB_CUST_NONSTANDARD ) ) {
        lib->info_name  = (char *) (uint_32) CCINFOORD;
        lib->style_name = (char *) (uint_32) CCSTYLEORD;
        lib->flags_name = (char *) (uint_32) CCFLAGSORD;
    } else if ( IsDlgButtonChecked ( hDlg, IDB_CUST_ORD ) ) {
        lib->info_name  =
            (char *) WdeGetUINT32FromEdit ( hDlg, IDB_CUST_INFO, NULL );
        lib->style_name =
            (char *) WdeGetUINT32FromEdit ( hDlg, IDB_CUST_STYLE, NULL );
        lib->flags_name =
            (char *) WdeGetUINT32FromEdit ( hDlg, IDB_CUST_FLAGS, NULL );
        if ( !lib->info_name || !lib->style_name || !lib->flags_name ) {
            WdeDisplayErrorMsg( WDE_BADPROCEDUREORDINAL );
            ok = FALSE;
        }
    } else {
        info  = WdeGetStrFromEdit ( hDlg, IDB_CUST_INFO,  NULL );
        style = WdeGetStrFromEdit ( hDlg, IDB_CUST_STYLE, NULL );
        flags = WdeGetStrFromEdit ( hDlg, IDB_CUST_FLAGS, NULL );
        if ( GetProcAddress ( lib->inst, info ) == NULL ) {
            WdeDisplayErrorMsg( WDE_CANTFINDINFOPROC );
            ok = FALSE;
        }
        if ( ok && GetProcAddress ( lib->inst, style ) == NULL ) {
            WdeDisplayErrorMsg( WDE_CANTFINDSTYLEPROC );
            ok = FALSE;
        }
        if ( ok && GetProcAddress ( lib->inst, flags ) == NULL ) {
            WdeDisplayErrorMsg( WDE_CANTFINDFLAGSPROC );
            ok = FALSE;
        }
        if ( !ok ) {
            WdeMemFree ( info );
            WdeMemFree ( style );
            WdeMemFree ( flags );
        } else {
            lib->info_name  = info;
            lib->style_name = style;
            lib->flags_name = flags;
        }
    }

    return ( ok );
}

BOOL WINEXPORT WdeLoadCustProc( HWND hDlg, UINT message,
                                WPARAM wParam, volatile LPARAM lParam )
{
    static WdeCustLib *lib;
    BOOL               checked;
    BOOL               ret;

    ret = FALSE;

    switch (message) {

        case WM_INITDIALOG:
            lib = (WdeCustLib *) lParam;
            WdeSetLoadCustInfo( hDlg, lib );
            WdeEnableNonStandardCustInfo( hDlg, FALSE, TRUE );
            break;

        case WM_COMMAND:
            switch( LOWORD(wParam) ) {
                case IDB_HELP:
                    WinHelp( WdeGetMainWindowHandle(), "resdlg.hlp",
                             HELP_CONTENTS, 0 );
                    break;

                case IDOK:
                    if( WdeGetLoadCustInfo( hDlg, lib ) ) {
                        EndDialog( hDlg, TRUE );
                        ret  = TRUE;
                    }
                    break;

                case IDCANCEL:
                    EndDialog( hDlg, FALSE );
                    ret  = TRUE;
                    break;

                case IDB_CUST_NONSTANDARD:
                    if( GET_WM_COMMAND_CMD(wParam,lParam) == BN_CLICKED ) {
                        checked = IsDlgButtonChecked( hDlg, LOWORD(wParam) );
                        if( !checked ) {
                            WdeSetLoadCustInfo( hDlg, lib );
                        }
                        WdeEnableNonStandardCustInfo( hDlg, checked, FALSE );
                    }
                    break;

                case IDB_CUST_ORD:
                    if( GET_WM_COMMAND_CMD(wParam,lParam) == BN_CLICKED ) {
                        checked = IsDlgButtonChecked( hDlg, LOWORD(wParam) );
                        if( checked ) {
                            WdeSetLoadCustInfoOrd( hDlg );
                        }
                    }
                    break;

            }
    }

    return ( ret );
}

⌨️ 快捷键说明

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