guitool.c

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

C
455
字号
                       gui_colour_set *standout, gui_rect *float_pos  )
{
    gui_coord           size;
    gui_coord           pos;
    HWND                parent;
    HWND                toolhwnd;
    toolbarinfo         *toolbar;
    int                 i;
    TOOLITEMINFO        info;
    int                 fixed_height;
    int                 fixed_width;
    int                 adjust_amount;
    int                 width;
    int                 new_right;
    int                 bm_h;
    int                 bm_w;
    GUI_RECTDIM         left, top, right, bottom;
    int                 h;

    excl = excl;
    plain = plain;
    standout = standout;
    if( ( wnd == NULL ) || ( num_toolbar_items < 1 ) || ( toolinfo == NULL ) ||
        ( wnd->hwnd == NULLHANDLE ) || ( wnd->root == NULLHANDLE ) ) {
        return( FALSE );
    }
    if( wnd->toolbar != NULL ) {
        GUICloseToolBar( wnd );
    }
    wnd->toolbar = ( toolbarinfo * )GUIMemAlloc( sizeof( toolbarinfo ) );
    if( wnd->toolbar == NULL ) {
        return( FALSE );
    }
    toolbar = wnd->toolbar;
    memset( toolbar, 0, sizeof( toolbarinfo ) );
    parent = wnd->root;
    toolbar->fixedrect = wnd->hwnd_client;
    toolbar->bitmaps = (HBITMAP *)GUIMemAlloc( num_toolbar_items * sizeof( HBITMAP ) );
    if( toolbar->bitmaps == NULL ) {
        GUIMemFree( wnd->toolbar );
        wnd->toolbar = NULL;
        return( FALSE );
    }
    if( height == 0 ) {
        fixed_height = 0;
        fixed_width = 0;
    }
    for( i = 0; i < num_toolbar_items; i++ ) {
        toolbar->bitmaps[i] = _wpi_loadbitmap( GUIResHInst,
                                _wpi_makeintresource( toolinfo[i].bitmap ) );
        if( height == 0 ) {
            _wpi_getbitmapdim( toolbar->bitmaps[i], &bm_w, &bm_h );
            if( bm_h > fixed_height ) {
                fixed_height = bm_h;
            }
            if( bm_w > fixed_width ) {
                fixed_width = bm_w;
            }
        }
    }
    toolbar->info.border_size.x = BORDER_AMOUNT;
    toolbar->info.border_size.y = BORDER_AMOUNT;
    /* space for border and space before border */
    adjust_amount = 2*(_wpi_getsystemmetrics( SM_CYBORDER )+BORDER_AMOUNT);
    if( height == 0 ) { /* maintian # of pixels in bitmap */
        height = fixed_height + adjust_amount + OUTLINE_AMOUNT;
        width = fixed_width + OUTLINE_AMOUNT;
    } else {
        /* only height of windows given, make bitmaps square */
        size.x = 0;
        size.y = height - 2;
        GUIScaleToScreenR( &size );
        height = size.y;
        width = size.y;
    }

    _wpi_getrectvalues( toolbar->fixedrect, &left, &top, &right, &bottom );
    h      = _wpi_getheightrect( toolbar->fixedrect );
    bottom = _wpi_cvth_y_plus1( height, h );
    top    = _wpi_cvth_y_plus1( top, h );
    _wpi_setwrectvalues( &toolbar->fixedrect, left, top, right, bottom );
    height -= adjust_amount; /* leaving just button size */
    toolbar->info.button_size.x = width;
    toolbar->info.button_size.y = height;
    bottom = height + BORDER_AMOUNT * 2 +
             _wpi_getsystemmetrics( SM_CYCAPTION ) +
             2 * ( _wpi_getsystemmetrics( SM_CYFRAME ) -
                   _wpi_getsystemmetrics( SM_CYBORDER ) );
    bottom = _wpi_cvth_y_plus1( bottom, h );
#ifdef __OS2_PM__
    bottom -= 2;
#endif
    new_right = width * num_toolbar_items -
                (num_toolbar_items - 1) * toolbar->info.border_size.x +
                left + 2 * _wpi_getsystemmetrics( SM_CXFRAME ) +
                BORDER_AMOUNT * 2;
    if( new_right < right ) {
        right = new_right;
    }

    _wpi_setwrectvalues( &toolbar->floatrect, left, top, right, bottom );
    _wpi_mapwindowpoints( parent, HWND_DESKTOP, (WPI_PPOINT)&toolbar->floatrect, 2 );

    if( fixed ) {
        toolbar->info.area = toolbar->fixedrect;
        toolbar->info.style = TOOLBAR_FIXED_STYLE;
    } else {
        if( float_pos != NULL ) {
            GUICalcLocation( float_pos, &pos, &size, parent );
            _wpi_setwrectvalues( &toolbar->floatrect, pos.x, pos.y,
                                 pos.x + size.x, pos.y + size.y );
            _wpi_mapwindowpoints( parent, HWND_DESKTOP, (WPI_PPOINT)&toolbar->floatrect, 2 );
        }
        toolbar->info.area = toolbar->floatrect;
        toolbar->info.style = TOOLBAR_FLOAT_STYLE;
    }

    toolbar->info.hook = GUIToolBarProc;
    toolbar->info.helphook = GUIToolBarHelp;
    toolbar->info.background = 0;
    toolbar->info.foreground = 0;
    toolbar->num = num_toolbar_items;
    toolbar->info.is_fixed = fixed;

    toolbar->hdl = ToolBarInit( parent );

    ToolBarDisplay( toolbar->hdl, &toolbar->info );

    GUIResizeBackground( wnd, TRUE );

    for( i = 0; i < num_toolbar_items; i++ ) {
        info.u.bmp = toolbar->bitmaps[i];
        info.id = toolinfo[i].id;
        info.flags = 0;
        ToolBarAddItem( toolbar->hdl, &info );
    }
    toolhwnd = ToolBarWindow( toolbar->hdl );
    _wpi_showwindow( toolhwnd, SW_SHOWNORMAL );
    _wpi_updatewindow( toolhwnd );
    return( TRUE );
}

/*
 * GUIResizeToolBar -- used to resize the fixed tool bar when the parent
 *                     window resizes
 */

void GUIResizeToolBar( gui_window *wnd )
{
    WPI_RECT    rect;
    GUI_RECTDIM left, top, right, bottom;
    GUI_RECTDIM height;
    GUI_RECTDIM t, h;

    if( wnd->toolbar != NULL ) {
        rect = wnd->root_client;
        if( wnd->root == NULLHANDLE ) {
            rect = wnd->hwnd_client;
        }
        _wpi_rationalize_rect( &rect );
        if( wnd->toolbar->info.is_fixed ) {
            height = _wpi_getheightrect( wnd->toolbar->fixedrect );
            h = _wpi_getheightrect( rect );
            _wpi_getrectvalues( rect, &left, &top, &right, &bottom );
            t = _wpi_cvth_y_plus1( top, h );
            bottom = _wpi_cvth_y_plus1( height, h );
            _wpi_setwrectvalues( &wnd->toolbar->fixedrect, left, t, right, bottom );
            t = _wpi_cvth_y_size_plus1( top, h, height );
            _wpi_movewindow( ToolBarWindow( wnd->toolbar->hdl ),
                             left, t, right - left, height, TRUE );
        }
    }
}

extern bool GUIHasToolBar( gui_window *wnd )
{
    return( wnd->toolbar != NULL );
}

bool GUIChangeToolBar( gui_window *wnd )
{
    gui_event   gui_ev;
    toolbarinfo *toolbar;
    HWND        toolhwnd;
    int         t;
    GUI_RECTDIM left, top, right, bottom;

    toolbar = wnd->toolbar;
    if( !toolbar->info.is_fixed ) {
        toolbar->info.is_fixed = TRUE;
        toolbar->info.style = TOOLBAR_FIXED_STYLE;
        toolbar->info.area = toolbar->fixedrect;
        gui_ev = GUI_TOOLBAR_FIXED;
    } else {
        toolbar->info.is_fixed = FALSE;
        toolbar->info.style = TOOLBAR_FLOAT_STYLE;
        toolbar->info.area = toolbar->floatrect;
        _wpi_cvtc_rect_plus1( wnd->root, &toolbar->info.area );
        gui_ev = GUI_TOOLBAR_FLOATING;
    }
    ToolBarDisplay( toolbar->hdl, &toolbar->info );
    if( toolbar->info.style != TOOLBAR_FLOAT_STYLE ) {
        ToolBarRedrawButtons( toolbar->hdl );
    }
    toolhwnd = ToolBarWindow( toolbar->hdl );
    if( toolbar->info.style == TOOLBAR_FLOAT_STYLE ) {
        _wpi_getrectvalues( toolbar->floatrect, &left, &top, &right, &bottom );
        t = top;
        //t = _wpi_cvtc_y_size( wnd->hwnd, t, bottom - top );
        t = _wpi_cvtc_y_plus1( wnd->root, t );
        _wpi_movewindow( toolhwnd, left, t, right-left, bottom-top, TRUE );
    }
    GUIResizeBackground( wnd, TRUE );
    _wpi_showwindow( toolhwnd, SW_SHOWNORMAL );
    _wpi_updatewindow( toolhwnd );
    GUIEVENTWND( wnd, gui_ev, NULL );
    return( TRUE );
}

bool GUIToolBarFixed( gui_window *wnd )
{
    if( GUIHasToolBar( wnd ) ) {
        return( wnd->toolbar->info.is_fixed );
    }
    return( FALSE );
}

⌨️ 快捷键说明

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