Example #1
0
bool GUIXCreateDialog( gui_create_info *dlg_info, gui_window *wnd,
                       int num_controls, gui_control_info *controls_info,
                       bool sys, long dlg_id )
{
    EVENT       ev;
    int         i;
    a_dialog    *ui_dlg_info;
    VFIELD      *fields;
    char        *title;
    VFIELD      *focus;
    int         size;
    bool        colours_set;
    bool        ok;

    if( dlg_id != -1 ) {
        if( !GUICreateDialogFromRes( dlg_id, dlg_info->parent,
                                     dlg_info->call_back, dlg_info->extra ) ) {
            return( false );
        }
        GUIMemFree( wnd );
        return( true );
    }

    sys = sys;
    RadioGroup = NULL;
    Group = false;
    fields = NULL;
    title = NULL;
    ui_dlg_info = NULL;
    colours_set = false;

    wnd->flags |= DIALOG;
    if( !GUISetupStruct( wnd, dlg_info, true ) ) {
        return( false );
    }

    size = ( num_controls + 1 ) * sizeof( VFIELD );
    fields = (VFIELD *)GUIMemAlloc( size );
    if( fields == NULL ) {
       return( false );
    }
    memset( fields, 0, size );
    focus = NULL;
    for( i = 0; i < num_controls; i++ ) {
        uiyield();
        if( !GUIDoAddControl( &controls_info[i], wnd, &fields[i] ) ) {
            GUIFreeDialog( ui_dlg_info, fields, title, colours_set, true );
            return( false );
        } else {
            if( ( focus == NULL ) && ( controls_info[i].style & GUI_FOCUS ) ) {
                focus = &fields[i];
            }
        }
    }
    CleanUpRadioGroups();
    fields[num_controls].typ = FLD_VOID; /* mark end of list */
    title = GUIStrDup( dlg_info->title, &ok );
    if( !ok ) {
        GUIFreeDialog( ui_dlg_info, fields, title, colours_set, true );
        return( false );
    }
    colours_set = GUISetDialColours();
    ui_dlg_info = uibegdialog( title, fields, wnd->screen.area.height,
                             wnd->screen.area.width, wnd->screen.area.row,
                             wnd->screen.area.col );
    if( ui_dlg_info == NULL ) {
        GUIFreeDialog( ui_dlg_info, fields, title, colours_set, true );
        return( false );
    }
    if( focus != NULL ) {
        uidialogsetcurr( ui_dlg_info, focus );
    }
    if( !InsertDialog( wnd, ui_dlg_info, num_controls, title, colours_set ) ) {
        GUIFreeDialog( ui_dlg_info, fields, title, colours_set, true );
        return( false );
    }
    for( i = 0; i < num_controls; i++ ) {
        uiyield();
        GUIInsertControl( wnd, &controls_info[i], i );
    }
    GUIEVENTWND( wnd, GUI_INIT_DIALOG, NULL );
    uipushlist( NULL );
    uipushlist( GUIUserEvents );
    GUIPushControlEvents();
    uipushlist( DlgEvents );
    while( ( GetDialog( ui_dlg_info ) != NULL ) ) {
        ev = uidialog( ui_dlg_info );
        switch( ev ) {
        case EV_KILL_UI:
            uiforceevadd( EV_KILL_UI );
        case EV_ESCAPE:
            GUIEVENTWND( wnd, GUI_DIALOG_ESCAPE, NULL );
            GUICloseDialog( wnd );
            break;
        default :
            GUIProcessControlNotify( ev, ui_dlg_info, wnd );
        }
    }
    return( true );
}
Example #2
0
bool GUIXCreateWindow( gui_window *wnd, gui_create_info *info,
                       gui_window *parent )
{
    DWORD               style;
    HMENU               hmenu;
    gui_coord           pos;
    gui_coord           size;
    HWND                parent_hwnd;
    LPSTR               class_name;
    HWND                hwnd;
    wmcreate_info       wmcreateinfo;
    HWND                frame_hwnd;
    HWND                client_hwnd;
#ifdef __OS2_PM__
    ULONG               frame_flags;
    ULONG               flags;
    ULONG               show_flags;
    WPI_RECT            rect;
    WPI_RECT            parent_client;
#else
    DWORD               exstyle;
#endif

#ifdef __OS2_PM__
// Get rid of the changable font style for PM GUI app's
    info->style &= ~GUI_CHANGEABLE_FONT;
#endif

    wnd->root_pinfo.force_count = NUMBER_OF_FORCED_REPAINTS;
    wnd->hwnd_pinfo.force_count = NUMBER_OF_FORCED_REPAINTS;

    wnd->parent = parent;
    style = COMMON_STYLES;
    if( parent == NULL ) {
        parent_hwnd = HWND_DESKTOP;
        if( !( info->style & GUI_POPUP ) ) {
            wnd->flags |= IS_ROOT;
        }
    } else {
        parent_hwnd = parent->hwnd;
        if( !( info->style & GUI_POPUP ) ) {
            style |= CHILD_STYLE;
        }
    }
    hmenu = NULLHANDLE;
    if( !GUISetupStruct( wnd, info, &pos, &size, parent_hwnd, &hmenu ) ) {
        return( FALSE );
    }
    if( !(wnd->style & GUI_NOFRAME) ) {
        if( info->text ) {
            style |= WS_CAPTION;
            wnd->flags |= HAS_CAPTION;
        } else {
            style |= WS_BORDER;
        }
    }
    if( info->style & GUI_RESIZEABLE ) {
        style |= WS_THICKFRAME;
    }
    if( info->scroll & GUI_HSCROLL ) {
        style |= WS_HSCROLL;
    }
    if( info->scroll & GUI_VSCROLL ) {
        style |= WS_VSCROLL;
    }
    if( wnd->flags & HAS_CAPTION ) {
        if( info->style & GUI_MAXIMIZE ) {
            style |= WS_MAXIMIZEBOX;
        }
        if( info->style & GUI_MINIMIZE ) {
            style |= WS_MINIMIZEBOX;
        }
        if( info->style & GUI_SYSTEM_MENU ) {
            style |= WS_SYSMENU;
        }
    } else {
        wnd->style &= ~(GUI_MAXIMIZE|GUI_MINIMIZE|GUI_SYSTEM_MENU);
        info->style &= ~(GUI_MAXIMIZE|GUI_MINIMIZE|GUI_SYSTEM_MENU);
    }
    if( info->style & GUI_POPUP ) {
        style |= WS_POPUP;
    }
    if( info->style & GUI_DIALOG_LOOK ) {
        style |= GUI_DIALOG_STYLE;
        class_name = GUIDialogClass;
    } else {
        class_name = GUIClass;
    }

    wnd->font = GUIGetSystemFont();
    GUIInitHint( wnd, info->num_menus, info->menu, MENU_HINT );
    GUISetGUIHint( wnd );
    wmcreateinfo.size = sizeof(wmcreate_info);
    wmcreateinfo.wnd  = wnd;
    wmcreateinfo.info = info;
    hwnd        = NULLHANDLE;
    frame_hwnd  = NULLHANDLE;
    client_hwnd = NULLHANDLE;
#ifdef __OS2_PM__
    /* frame */
    flags = FCF_TASKLIST | FCF_NOBYTEALIGN;
    frame_flags = 0;
    if( wnd->flags & HAS_CAPTION ) {
        flags |= FCF_TITLEBAR;
        if( info->style & GUI_SYSTEM_MENU ) {
            flags |= FCF_SYSMENU;
        }
        if( info->style & GUI_MAXIMIZE ) {
            flags |= FCF_MAXBUTTON;
        }
        if( info->style & GUI_MINIMIZE ) {
            flags |= FCF_MINBUTTON;
        }
        flags |= FCF_BORDER;
    } else {
        if( !(wnd->style & GUI_NOFRAME) ) {
            flags |= FCF_BORDER;
            frame_flags |= FS_BORDER;
        }
        wnd->style &= ~(GUI_MAXIMIZE|GUI_MINIMIZE|GUI_SYSTEM_MENU);
        info->style &= ~(GUI_MAXIMIZE|GUI_MINIMIZE|GUI_SYSTEM_MENU);
    }
    if( info->style & GUI_RESIZEABLE ) {
        flags |= FCF_SIZEBORDER;
    }
    if( parent_hwnd == HWND_DESKTOP ) {
        if( info->num_menus > 0 ) {
            //flags |= FCF_MENU;
        }
    }
    if( info->scroll & GUI_HSCROLL ) {
        flags |= FCF_HORZSCROLL;
    }
    if( info->scroll & GUI_VSCROLL ) {
        flags |= FCF_VERTSCROLL;
    }
    if( info->style & GUI_DIALOG_LOOK ) {
        flags |= FCF_DLGBORDER;
    }
    if( info->style & GUI_POPUP ) {
        flags |= FCF_NOMOVEWITHOWNER;
    }
    frame_hwnd = WinCreateStdWindow( parent_hwnd, frame_flags | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, &flags,
                                     NULL, info->text,
                                     0, (HMODULE)0, 0, NULL );
    if( frame_hwnd != NULLHANDLE ) {
        oldFrameProc = _wpi_subclasswindow( frame_hwnd, (WPI_PROC)GUIFrameProc );
        _wpi_setmenu( frame_hwnd, hmenu );
        _wpi_getclientrect( parent_hwnd, &parent_client );
        show_flags = SWP_SIZE | SWP_MOVE;
        WinSetWindowPos( frame_hwnd, HWND_TOP, pos.x, pos.y, size.x, size.y, show_flags );
        hwnd = frame_hwnd;
        if( parent_hwnd == HWND_DESKTOP ) {
            wnd->root_frame = frame_hwnd;
        } else {
            wnd->hwnd_frame = frame_hwnd;
        }
        _wpi_getclientrect( frame_hwnd, &rect );
        client_hwnd = WinCreateWindow( frame_hwnd, class_name, NULL,
                                       WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
                                       rect.xLeft, rect.yBottom,
                                       rect.xRight-rect.xLeft,
                                       rect.yTop-rect.yBottom,
                                       frame_hwnd, HWND_TOP, FID_CLIENT,
                                       &wmcreateinfo, NULL );
        if( client_hwnd == NULLHANDLE ) {
            WinDestroyWindow( frame_hwnd );
            frame_hwnd = NULLHANDLE;
            hwnd = NULLHANDLE;
        }
    }
#else
    exstyle = WS_EX_NOPARENTNOTIFY;
#ifdef __NT__
    if( info->style & GUI_3D_BORDER ) {
        exstyle |= WS_EX_CLIENTEDGE;
        style &= ~WS_BORDER;
    }
#endif
    hwnd = _wpi_createwindow_ex( exstyle, class_name, info->text, style, 0, 0, pos.x,
                                 pos.y, size.x, size.y, parent_hwnd, hmenu, GUIMainHInst,
                                 &wmcreateinfo, &frame_hwnd );
#endif
    if( hwnd == NULLHANDLE ) {
        return( FALSE );
    }

    GUISetIcon( wnd, info->icon );

    if( info->style & (GUI_INIT_MAXIMIZED|GUI_INIT_MINIMIZED) ) {
        GUISetRedraw( wnd, FALSE );
        if( info->style & GUI_INIT_MAXIMIZED ) {
            GUIMaximizeWindow( wnd );
        } else if( info->style & GUI_INIT_MINIMIZED ) {
            GUIMinimizeWindow( wnd );
        }
        GUISetRedraw( wnd, TRUE );
        if( wnd->style & GUI_INIT_INVISIBLE ) {
            _wpi_showwindow( hwnd, SW_HIDE );
        }
    }

    if( !(wnd->style & GUI_INIT_INVISIBLE ) ) {
        GUIShowWindowNA( wnd );
    }

    return( wnd != NULL );
}