guixutil.c

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

C
722
字号
/****************************************************************************
*
*                            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 <stdlib.h>
#include <string.h>
#include "guicolor.h"
#include "guimenus.h"
#include "guiscale.h"
#include "guixutil.h"
#include "guiscrol.h"
#include "guixwind.h"
#include "guiwnclr.h"
#include "guimapky.h"
#include "guicontr.h"
#include "guihook.h"
#include "guixhook.h"
#include "guipaint.h"
#include "guizlist.h"

#define ERROR_STYLE MB_OK | MB_ICONEXCLAMATION

extern  gui_window      *GUICurrWnd;
extern  WPI_TEXTMETRIC  GUItm;
extern  WPI_INST        GUIMainHInst;
extern  WPI_INST        GUIResHInst;

static void MaxChild( gui_window *wnd, void *param )
{
    param = param;
    if( _wpi_iszoomed( wnd->hwnd_frame ) ) {
        GUISetRedraw( wnd, FALSE );
        GUIRestoreWindow( wnd );
        GUIMaximizeWindow( wnd );
        GUISetRedraw( wnd, TRUE );
        GUIShowWindowNA( wnd );
    }
}

void GUIMaximizeZoomedChildren( gui_window *wnd )
{
    GUIEnumChildWindows( wnd, &MaxChild, NULL );
}

/*
 * GUIIsOpen -- Is the given window open
 */

bool GUIIsOpen( gui_window *wnd )
{
    if( _wpi_iswindow( GUIMainHInst, wnd->hwnd ) ) {
        return( TRUE );
    }
    return( FALSE );
}

bool GUIIsParentADialog( gui_window *wnd )
{
    wnd = GUIGetParentWindow( wnd );
    while( wnd ) {
        if( wnd->flags & IS_DIALOG ) {
            return( TRUE );
        }
        wnd = GUIGetParentWindow( wnd );
    }
    return( FALSE );
}

bool GUIIsRectInUpdateRect( gui_window *wnd, WPI_RECT *rect )
{
    WPI_RECT    update_rect;
    WPI_RECT    intersect;

    if( !wnd || !wnd->ps || !rect ) {
        return( TRUE );
    }

#ifdef __OS2_PM__
    update_rect = *(wnd->ps);
#else
    _wpi_getpaintrect( wnd->ps, &update_rect );
#endif
    _wpi_intersectrect( GUIMainHInst, &intersect, &update_rect, rect );

    if( _wpi_isrectempty( GUIMainHInst, &intersect ) ) {
        return( FALSE );
    }

    return( TRUE );
}

void GUICalcLocation( gui_rect *rect, gui_coord *pos, gui_coord *size,
                      HWND parent )
{
    WPI_RECT    r;
    GUI_RECTDIM left, top, right, bottom;

    if( parent == NULLHANDLE ) {
        parent = HWND_DESKTOP;
    }
    pos->x = rect->x;
    pos->y = rect->y;
    size->x = rect->width;
    size->y = rect->height;
    if( parent == HWND_DESKTOP ) {
        GUIScaleToScreen( pos );
    } else {
        GUIScaleToScreenR( pos );
        _wpi_getclientrect( parent, &r );
        _wpi_getrectvalues( r, &left, &top, &right, &bottom );
        pos->x += left;
        pos->y += top;
    }
    GUIScaleToScreenR( size );

    pos->y = _wpi_cvtc_y_size_plus1( parent, pos->y, size->y );
}

/*
 * GUISetupStruct -- setup the gui_window structure according to the given
 *                   create_info information.
 */

bool GUISetupStruct( gui_window *wnd, gui_create_info *info,
                      gui_coord *pos, gui_coord *size, HWND parent,
                      HMENU *menu )
{
    GUICalcLocation( &info->rect, pos, size, parent );
    if( wnd != NULL ) {
        if( !(wnd->flags & IS_DIALOG) ) {
            wnd->style = info->style;
            wnd->scroll = info->scroll;
        }
        if( !GUISetColours( wnd, info->num_attrs, info->colours ) ) {
            return( FALSE );
        }
    }

    if( ( ( parent == HWND_DESKTOP ) || ( info->style & GUI_POPUP ) ) &&
        ( menu != NULL ) ) {
        if( info->resource_menu ) {
            *menu =  _wpi_loadmenu( GUIResHInst,
                                    MAKEINTRESOURCE( info->resource_menu ) );
        } else {
            return( GUICreateMenus( wnd, info->num_menus, info->menu, menu ) );
        }
    }

    return( TRUE );
}

/*
 * GUIError -- display an error message
 */

void GUIError( char *str )
{
    HWND focus;

    focus = _wpi_getfocus();
    if( focus != NULLHANDLE ) {
        _wpi_messagebox( focus, (LPSTR) str, NULL, ERROR_STYLE );
    }
}


gui_window *GUIFindWindowFromHWND( HWND hwnd )
{
    gui_window *curr;

    for( curr = GUIGetFront(); curr != NULL; curr = GUIGetNextWindow( curr ) ) {
        if( ( curr->hwnd == hwnd ) || ( curr->hwnd_frame == hwnd ) ||
            ( curr->root == hwnd ) || ( curr->root_frame == hwnd ) ) {
            return( curr );
        }
    }

    return( NULL );
}

bool GUIIsGUIChild( HWND hwnd )
{
    gui_window  *root;

    root = GUIGetRootWindow();
    if( root ) {
        hwnd = GUIGetTopParentHWND( hwnd );
        if( root->root_frame == hwnd ) {
            return( TRUE );
        }
    }

    return( FALSE );
}

/*
 * GUISetRedraw -- set the redraw flag for a given window
 */
bool GUISetRedraw( gui_window *wnd, bool redraw )
{
    _wpi_setredraw( wnd->hwnd, redraw );
    return( TRUE );
}

/*
 * GUIBringNewToFront - bring the next window in the z-order to the front.
 *                      Do not bring forward the given window or a decendent
 *                      of that window.
 */

bool GUIBringNewToFront( gui_window *prev )
{
    gui_window *curr;

    for( curr = GUIGetFront(); curr != NULL; curr = GUIGetNextWindow( curr ) ) {
        if( ( curr != prev ) && !_wpi_ischild( prev->hwnd, curr->hwnd ) &&
            !(curr->flags & DOING_DESTROY) ) {
            GUIBringToFront( curr );
            return( TRUE );
        }
    }
    return( FALSE );
}

gui_window *GUIXGetRootWindow( void )
{
    gui_window *curr;

    for( curr = GUIGetFront(); curr != NULL; curr = GUIGetNextWindow( curr ) ) {
        if( curr->flags & IS_ROOT ) {
            return( curr );
        }
    }

    return( NULL );
}

gui_window *GUIFindFirstChild( gui_window *parent )
{
    gui_window *wnd;

    for( wnd = GUIGetFront(); wnd != NULL; wnd = GUIGetNextWindow( wnd ) ) {
        if( wnd->parent == parent && !( wnd->flags & UTILITY_BIT ) ){
            return( wnd );
        }
    }

    return( NULL );
}

gui_window *GUIFindFirstPopupWithNoParent( void )
{
    gui_window *wnd;

    for( wnd = GUIGetFront(); wnd != NULL; wnd = GUIGetNextWindow( wnd ) ) {
        if( ( wnd->style & GUI_POPUP ) && ( wnd->parent == NULL ) ) {
            return( wnd );
        }
    }

    return( NULL );
}

static void GUIMarkChildrenWithFlag( gui_window *parent, gui_flags flag )
{
    gui_window *wnd;

    for( wnd = GUIGetFront(); wnd != NULL; wnd = GUIGetNextWindow( wnd ) ) {
        if( wnd->parent == parent ){
            wnd->flags |= flag;
        }
    }
}

void GUIDestroyAllChildren( gui_window *parent )
{
    gui_window  *wnd;

    GUIMarkChildrenWithFlag( parent, DOING_DESTROY );
    wnd = GUIFindFirstChild( parent );
    while( wnd ) {
        wnd->flags |= UTILITY_BIT;
        GUIDestroyWnd( wnd );
        wnd = GUIFindFirstChild( parent );
    }
}

void GUIDestroyAllPopupsWithNoParent( void )
{
    gui_window  *wnd;

    wnd = GUIFindFirstPopupWithNoParent();
    while( wnd ) {
        GUIDestroyWnd( wnd );
        wnd = GUIFindFirstPopupWithNoParent();
    }
}


/*
 * GUIFreeWindowMemory -- free the memory of the given window
 */

void GUIFreeWindowMemory( gui_window *wnd, bool from_parent, bool dialog )
{
    gui_window  *root;
    HWND        capture;

    from_parent = from_parent;
    if( ( wnd->hwnd != NULLHANDLE ) && ( GUICurrWnd == wnd ) ) {
        capture = _wpi_getcapture();
        if( capture == wnd->hwnd ) {
            _wpi_releasecapture();
        }
    }
    if( wnd->font != NULL ) {
        _wpi_deletefont( wnd->font );
        wnd->font = NULL;
    }
    if( wnd->icon != (WPI_HICON)NULL ) {
        _wpi_destroyicon( wnd->icon );
    }
    GUIFreeColours( wnd );
    GUIFreeBKBrush( wnd );
    GUIControlDeleteAll( wnd );
    //GUICloseToolBar( wnd );
    GUIFreeHint( wnd );
    _wpi_setwindowlong( wnd->hwnd, GUI_EXTRA_WORD * EXTRA_SIZE, 0 );
    if( wnd->root != NULLHANDLE ) {
        _wpi_setwindowlong( wnd->root, GUI_EXTRA_WORD * EXTRA_SIZE, 0 );
    }
    if( !dialog ) {

⌨️ 快捷键说明

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