Esempio n. 1
0
void GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg )
{
    HDC         prev_hdc;
    PAINTSTRUCT *prev_ps;
    gui_row_num row_num;
    PAINTSTRUCT ps;
    WPI_RECT    fill_area;
#ifdef __OS2_PM__
    ULONG       flags;
    RECTL       client;
#endif

    isdlg=isdlg;
    /* save old state */
    prev_hdc = wnd->hdc;
    prev_ps = wnd->ps;

    /* Setup Paint */
    wnd->ps = &ps;
    wnd->hdc = _wpi_beginpaint( hwnd, NULLHANDLE, wnd->ps );
    _wpi_torgbmode( wnd->hdc );
    _wpi_getpaintrect( wnd->ps, &fill_area );
#ifdef __OS2_PM__
    fill_area = *(wnd->ps);
    if( isdlg ) {
        _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10);
    }
    WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) );
#endif
#if defined( __NT__ )
    if( isdlg ) {
        _wpi_fillrect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ),
                       wnd->bk_brush );
    }
#endif
    if( wnd->font != NULL ) {
        wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font );
    } else {
        wnd->prev_font = NULL;
    }

    /* send paint to app */
    GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num );
    if( row_num.num > 0 ) {
        GUIEVENTWND( wnd, GUI_PAINT, &row_num );
    }

    /* finish painting */
    if( wnd->prev_font != NULL ) {
        _wpi_getoldfont( wnd->hdc, wnd->prev_font );
        wnd->prev_font = NULL;
    }

#ifdef __OS2_PM__
    if( isdlg ) {
        flags = DB_AREAATTRS | DB_DLGBORDER;
  #ifdef _M_I86
        if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) {
  #else
        if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) {
  #endif
        //if( _wpi_getfocus() != hwnd ) {
            flags |= DB_PATINVERT;
        }
        WinQueryWindowRect( hwnd, &client );
        WinDrawBorder( wnd->hdc, &client, 1, 1, 0, 0, flags );
    }
#endif

    _wpi_endpaint( hwnd, wnd->hdc, wnd->ps );

    /* restore old state */
    wnd->hdc = prev_hdc;
    wnd->ps = prev_ps;
}

#else

// this is some experimental PM stuff
void GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg )
{
    HDC         prev_hdc;
    PAINTSTRUCT *prev_ps;
    gui_row_num row_num;
    PAINTSTRUCT ps;
    PAINTSTRUCT fill_area;

    // experimenal stuff
    HPS                 hps;
    RECTL               client;
    LONG                width, height;
    ULONG               flags;
    int                 compat_created;
    gui_paint_info      *pinfo;

    // figure out which paint info to use
    if( !isdlg && wnd->root == hwnd ) {
        pinfo = &wnd->root_pinfo;
    } else {
        pinfo = &wnd->hwnd_pinfo;
    }
    pinfo->in_use++;
    compat_created = FALSE;

    /* save old state */
    prev_hdc = wnd->hdc;
    prev_ps = wnd->ps;
    if( isdlg ) {
        _wpi_getclientrect( hwnd, &client );
    } else {
        WinQueryWindowRect( hwnd, &client );
    }
    width = client.xRight - client.xLeft;
    height = client.yTop - client.yBottom;

    wnd->ps = &ps;
    //hps = _wpi_beginpaint( hwnd, pinfo->normal_pres, wnd->ps );
    hps = _wpi_beginpaint( hwnd, NULL, wnd->ps );
    if( pinfo->compatible_pres == (WPI_PRES)NULL ) {
        compat_created = TRUE;
        pinfo->compatible_pres = _wpi_createcompatiblepres( hps, GUIMainHInst, &pinfo->compatible_hdc );
        pinfo->draw_bmp = _wpi_createcompatiblebitmap( hps, width, height );
        pinfo->old_bmp = _wpi_selectbitmap( pinfo->compatible_pres, pinfo->draw_bmp );
    }

    // the condition is here VERY conservative!!
    // its gains have to analyzed
    if( compat_created || pinfo->force_count ) {
        wnd->hdc = pinfo->compatible_pres;
        //wnd->hdc = hps;
        _wpi_torgbmode( wnd->hdc );
        fill_area = *(wnd->ps);
        if( isdlg ) {
            _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10);
        }
        WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) );
        wnd->prev_font = NULL;
        if( wnd->font != NULL ) {
            wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font );
        }

        /* send paint to app */
        GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num );
        if( row_num.num > 0 ) {
            GUIEVENTWND( wnd, GUI_PAINT, &row_num );
        }

        /* finish painting */
        if( wnd->prev_font != NULL ) {
            _wpi_getoldfont( wnd->hdc, wnd->prev_font );
            wnd->prev_font = NULL;
        }

        if( pinfo->force_count ) {
            //pinfo->force_count--;
        }
    }

    //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height,
    //       wnd->hdc, 0, 0, SRCCOPY );

    if( pinfo->in_use == 1 ) {
        //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height,
        //               wnd->hdc, 0, 0, SRCCOPY );
        _wpi_bitblt( hps, ps.xLeft, ps.yBottom,
                     ps.xRight - ps.xLeft,
                     ps.yTop - ps.yBottom,
                     wnd->hdc,
                     ps.xLeft, ps.yBottom,
                     SRCCOPY );
        if( pinfo->delete_when_done ) {
            GUIFreePaintHandles( pinfo, TRUE );
        }
    }

    if( isdlg ) {
        flags = DB_AREAATTRS | DB_DLGBORDER;
  #ifdef _M_I86
        if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) {
  #else
        if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) {
  #endif
        //if( _wpi_getfocus() != hwnd ) {
            flags |= DB_PATINVERT;
        }
        WinQueryWindowRect( hwnd, &client );
        WinDrawBorder( hps, &client, 1, 1, 0, 0, flags );
    }

    _wpi_endpaint( hwnd, hps, wnd->ps );

    /* restore old state */
    wnd->hdc = prev_hdc;
    wnd->ps = prev_ps;

    if( pinfo->in_use ) {
        pinfo->in_use--;
    }
}

#endif

void GUIInvalidatePaintHandles( gui_window *wnd )
{
    GUIFreeWndPaintHandles( wnd, FALSE );
}
Esempio n. 2
0
/*
 * FindOrigin - "cascade" the windows to find the placement of the new MDI child
 *            - origin is expected to come in as (0, 0) or the equivalent for PM
 */
void FindOrigin( WPI_POINT *new_origin )
{
    WPI_ENUMPROC    fp;
    int             image_count;
    int             i, j;
    WPI_POINT       temp;
    WPI_RECT        proposed;
    WPI_RECTDIM     width;
    int             base;

    image_count = DoImagesExist();

    if( image_count == 0 ) {
        return;
    }

#ifdef __OS2_PM__
    imageMax = image_count;
#endif
    windowCoords = MemAlloc( image_count * sizeof( WPI_POINT ) );
    windowIndex = 0;

    fp = _wpi_makeenumprocinstance( GetPosProc, Instance );
    _wpi_enumchildwindows( ClientWindow, fp, 0L );
    _wpi_freeprocinstance( fp );

    /*
     * I'm just using a simple bubble sort ... we're using small amounts of data
     */
    for( i = 0; i < image_count; i++ ) {
        for( j = 0; j < image_count - i - 1; j++ ) {
            if( windowCoords[j].x > windowCoords[j + 1].x ) {
                temp = windowCoords[j];
                windowCoords[j] = windowCoords[j + 1];
                windowCoords[j + 1] = temp;
            }
        }
    }

    /*
     * Minimized windows will have coordinates set to negative, and we only
     * want non-minimized windows.
     */
    for( base = 0; base < image_count; base++ ) {
        if( windowCoords[base].x >= 0 ) {
            break;
        }
    }
    if( base >= image_count ) {
        MemFree( windowCoords );
        return;
    }

    width = _wpi_getsystemmetrics( SM_CYCAPTION );
#ifndef __OS2_PM__
    _wpi_setintrectvalues( &proposed, new_origin->x, new_origin->y,
                           new_origin->x + width, new_origin->y + width );
#else
    _wpi_setrectvalues( &proposed, new_origin->x, new_origin->y - 1,
                        new_origin->x + width, new_origin->y + width - 1 );
#endif

    /*
     * Try to place at the origin passed in if we can.
     */
    if( !_wpi_ptinrect( &proposed, windowCoords[base] ) ) {
        MemFree( windowCoords );
        return;
    }

    for( i = base; i < image_count - 1; i++ ) {
        if( windowCoords[i + 1].x - windowCoords[i].x > 2 * width ) {
            break;
        }
    }

    temp.x = windowCoords[i].x + width;
#ifndef __OS2_PM__
    temp.y = windowCoords[i].x + width;
#else
    temp.y = windowCoords[i].y - width;
#endif

    _wpi_getclientrect( ClientWindow, &proposed );
#ifndef __OS2_PM__
    if( !_wpi_ptinrect( &proposed, temp ) ) {
        return;
    } else {
        new_origin->x = temp.x;
        new_origin->y = temp.y;
    }
#else
    new_origin->x = temp.x;
    new_origin->y = temp.y;
#endif

    MemFree( windowCoords );

} /* FindOrigin */
Esempio n. 3
0
/*
 * drawPt - Actually draws the point on the drawing region. (uses LineDDA)
 */
void CALLBACK drawPt( int xpos, int ypos, WPI_PARAM2 lparam )
{
    HBRUSH      colourbrush;
    HBRUSH      oldbrush;
    HPEN        colourpen;
    HPEN        oldpen;
    COLORREF    selected_colour;
    COLORREF    dithered;
    short       mousebutton;
    WPI_PRES    pres;
    HWND        hwnd;
    short       area_x;
    short       area_y;
    short       width;
    short       height;
    short       i;
    short       j;
    WPI_POINT   pt;
    WPI_RECT    rcclient;
    wie_clrtype type;
    int         brushsize;
    BOOL        gridvisible;

    hwnd = (HWND)GET_HWND_PARAM2( lparam );
    mousebutton = currentMouseButton;
    _wpi_getclientrect( hwnd, &rcclient );
    brushsize = ImgedConfigInfo.brush_size;

    gridvisible = ImgedConfigInfo.grid_on && (pointSize.x >= POINTSIZE_MIN &&
                                                pointSize.y >= POINTSIZE_MIN);
    if ((!gridvisible) && (toolType == IMGED_FREEHAND)) {
        area_x = xpos * pointSize.x;
        area_y = ypos * pointSize.y;
        width = (short)pointSize.x;
        height = (short)pointSize.y;
    } else if ((!gridvisible) && (toolType == IMGED_BRUSH)) {
        area_x = max(0, xpos-brushsize/2) * pointSize.x;
        area_y = max(0, ypos-brushsize/2) * pointSize.y;
        width = (short)(brushsize * pointSize.x);
        height = (short)(brushsize * pointSize.y);
        /*
         * We just have to check that we don't spill over the image dimensions
         */
        area_x = min( area_x, _wpi_getwidthrect(rcclient)-width );
        area_y = min( area_y, _wpi_getheightrect(rcclient)-width );
    } else if ((gridvisible) && (toolType == IMGED_FREEHAND)) {
        area_x = xpos * pointSize.x+1;
        area_y = ypos * pointSize.y+1;
        width = (short)(pointSize.x-1);
        height = (short)(pointSize.y-1);
    } else {
        area_x = max(0, xpos-brushsize/2) * pointSize.x+1;
        area_y = max(0, ypos-brushsize/2) * pointSize.y+1;
        width = (short)(pointSize.x - 1);
        height = (short)(pointSize.y - 1);
        /*
         * We just have to check that we don't spill over the image dimensions
         */
        area_x = min( area_x, _wpi_getwidthrect(rcclient) - pointSize.x *
                                                                brushsize+1 );
        area_y = min( area_y, _wpi_getheightrect(rcclient) - pointSize.y *
                                                                brushsize+1 );
    }

    pres = _wpi_getpres( hwnd );
    _wpi_torgbmode( pres );
    dithered = GetSelectedColour( mousebutton, &selected_colour, &type );

    colourbrush = _wpi_createsolidbrush( selected_colour );
    oldbrush = _wpi_selectobject(pres, colourbrush);
    colourpen = _wpi_createpen(PS_SOLID, 0, selected_colour);
    oldpen = _wpi_selectobject(pres, colourpen);

    if (gridvisible && (toolType == IMGED_BRUSH)) {
        for (i=0; i < brushsize; ++i) {
            for (j=0; j < brushsize; ++j) {
                _wpi_patblt(pres, area_x+i*pointSize.x, area_y+j*pointSize.y,
                                                width, height, PATCOPY);
            }
        }
    } else {
        _wpi_patblt(pres, area_x, area_y, width, height, PATCOPY);
    }

    _wpi_selectobject(pres, oldbrush);
    _wpi_selectobject(pres, oldpen);
    _wpi_releasepres( hwnd, pres );

    _wpi_deleteobject( colourbrush );
    _wpi_deleteobject( colourpen );

    pt.x = area_x / pointSize.x;
    pt.y = area_y / pointSize.y;
    if (toolType == IMGED_BRUSH) {
        if (type == SCREEN_CLR) {
            BrushThePoints(selected_colour, BLACK, WHITE, &pt, brushsize);
        } else if (type == INVERSE_CLR) {
            BrushThePoints(selected_colour, WHITE, WHITE, &pt, brushsize);
        } else {
            BrushThePoints(selected_colour, selected_colour, BLACK, &pt,
                                                                brushsize);
        }
    } else {
        if (type == SCREEN_CLR) {
            DrawThePoints(selected_colour, BLACK, WHITE, &pt);
        } else if (type == INVERSE_CLR) {
            DrawThePoints(selected_colour, WHITE, WHITE, &pt);
        } else {
            DrawThePoints(selected_colour, selected_colour, BLACK, &pt);
        }
    }
} /* drawPt */
Esempio n. 4
0
/*
 * WinCreateViewWin - create the view window for the Windows version
 */
HWND WinCreateViewWin( HWND hviewwnd, BOOL foneview,
                       int *showstate, int width, int height )
{
    HWND        hwnd;
    RECT        location;
    int         x, y;
    int         h_adj;
    int         v_adj;

    if( hviewwnd != NULL && foneview ) {
        GetWindowRect( hviewwnd, &location );
        x = location.left;
        y = location.top;
    } else {
        x = ImgedConfigInfo.view_xpos;
        y = ImgedConfigInfo.view_ypos;
    }

    width += 2 * BORDER_WIDTH;
    height += 2 * BORDER_WIDTH;

    h_adj = 2 * GetSystemMetrics( SM_CXDLGFRAME );
    v_adj = 2 * GetSystemMetrics( SM_CYDLGFRAME ) +
#ifndef __NT__
            GetSystemMetrics( SM_CYCAPTION ) - 1;
#else
            GetSystemMetrics( SM_CYSMCAPTION ) - 1;
#endif

#ifndef __NT__
    hwnd = CreateWindow(
            ViewWinClass,                       /* Window class name */
            "View",
            WS_POPUPWINDOW | WS_CAPTION |
            WS_VISIBLE | WS_CLIPSIBLINGS |
            WS_DLGFRAME,                        /* Window style */
            x,                                  /* Initial X position */
            y,                                  /* Initial Y position */
            h_adj + width,                      /* Initial X size */
            v_adj + height,                     /* Initial Y size */
            HMainWindow,                        /* Parent window handle */
            (HMENU) NULL,                       /* Window menu handle */
            Instance,                           /* Program instance handle */
            NULL );                             /* Create parameters */
#else
    hwnd = CreateWindowEx(
            WS_EX_TOOLWINDOW,
            ViewWinClass,                       /* Window class name */
            "View",
            WS_POPUPWINDOW | WS_CAPTION |
            WS_VISIBLE | WS_CLIPSIBLINGS |
            WS_DLGFRAME,                        /* Window style */
            x,                                  /* Initial X position */
            y,                                  /* Initial Y position */
            h_adj + width,                      /* Initial X size */
            v_adj + height,                     /* Initial Y size */
            HMainWindow,                        /* Parent window handle */
            (HMENU) NULL,                       /* Window menu handle */
            Instance,                           /* Program instance handle */
            NULL );                             /* Create parameters */
#endif
    ShowWindow( hwnd, SW_HIDE );

    if( hwnd != (HWND)NULL ) {
        RECT    rect;
        int     w, h;
        _wpi_getclientrect( hwnd, &rect );
        w = _wpi_getwidthrect( rect );
        h = _wpi_getheightrect( rect );
        if( w < width || h < height ) {
            GetWindowRect( hwnd, &rect );
            w = _wpi_getwidthrect( rect ) + (width - w);
            h = _wpi_getheightrect( rect ) + (height - h);
            SetWindowPos( hwnd, HWND_TOP, 0, 0, w, h,
                          SWP_SIZE | SWP_NOZORDER | SWP_NOMOVE );
        }
    }

    if( ImgedConfigInfo.show_state & SET_SHOW_VIEW ) {
        *showstate = SW_SHOWNORMAL;
    } else {
        *showstate = SW_HIDE;
    }
    return( hwnd );

} /* WinCreateViewWin */
Esempio n. 5
0
/*
 * EnlargeImage - take an MDI window handle and enlarge the view bitmap
 *                that goes with it
 *              - returns a handle to the bitmap
 *              - the bitmap must be deleted by the calling routine
 */
HBITMAP EnlargeImage( HWND hwnd )
{
    WPI_PRES    pres;
    WPI_PRES    srcpres;
    WPI_PRES    destpres;
    HDC         srcdc;
    HDC         destdc;
    HBITMAP     oldbitmap;
    HBITMAP     newbitmap;
    HBITMAP     olddestbitmap;
    HBITMAP     viewbitmap;
    img_node    *node;
    WPI_RECT    rc;
    short       width;
    short       height;
    int         window_width;
    int         window_height;
    BITMAP      bm;

    node = SelectImage( hwnd );
    if( node == NULL ) {
        return( NULL );
    }

    viewbitmap = CreateViewBitmap( node );
    _wpi_getclientrect( hwnd, &rc );
    /*
     * I add this so that if the window's client rect doesn't fit on the
     * screen, it will still enlarge to the right size.
     */
    window_width = _wpi_getwidthrect( rc );
    window_height = _wpi_getheightrect( rc );
    if( window_width < node->width ) {
        window_width = node->width;
    }
    if( window_height < node->height ) {
        window_height = node->height;
    }

    pres = _wpi_getpres( HWND_DESKTOP );
    srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc );
    destpres = _wpi_createcompatiblepres( pres, Instance, &destdc );
    newbitmap = _wpi_createcompatiblebitmap( pres, _wpi_getwidthrect( rc ),
                                                   _wpi_getheightrect( rc ) );
    _wpi_releasepres( HWND_DESKTOP, pres );
    GetObject( newbitmap, sizeof( BITMAP ), &bm );

    _wpi_torgbmode( destpres );
    _wpi_torgbmode( srcpres );
    olddestbitmap = _wpi_selectobject( destpres, newbitmap );
    oldbitmap = _wpi_selectobject( srcpres, viewbitmap );
    height = node->height;
    width = node->width;

    IEStretchBlt( destpres, 0, 0, _wpi_getwidthrect( rc ),
                  _wpi_getheightrect( rc ), srcpres, 0, 0, width, height,
                  SRCCOPY, bm.bmBitsPixel );

    _wpi_selectobject( srcpres, oldbitmap );
    _wpi_deletecompatiblepres( srcpres, srcdc );
    _wpi_deleteobject( viewbitmap );

    _wpi_selectobject( destpres, olddestbitmap );
    _wpi_deletecompatiblepres( destpres, destdc );

    return( newbitmap );

} /* EnlargeImage */
Esempio n. 6
0
static void DoScroll( gui_window *wnd, int rows, int cols, int start, int end,
                      bool chars )
{
    int         dx, dy;
    WPI_RECT    client;
    HWND        hwnd;
    int         multx, multy;
    GUI_RECTDIM left, top, right, bottom;
#ifdef __OS2_PM__
    int         bottom_adjust;
#endif

    hwnd = GUIGetScrollHWND( wnd );
    _wpi_getclientrect( wnd->hwnd, &client );
    _wpi_getrectvalues( client, &left, &top, &right, &bottom );
#ifdef __OS2_PM__
    bottom_adjust = bottom - GUIGetScrollScreenSize( wnd, SB_VERT );
    top += bottom_adjust;
#else
    bottom = GUIGetScrollScreenSize( wnd, SB_VERT );
#endif
    multx = 1;
    multy = 1;
    if( chars ) {
        multx = GUIFromTextX( multx, wnd );
        multy = GUIFromTextY( multy, wnd );
    }
    dx = -cols * multx;
    dy = -rows * multy;
    if( dy != 0 ) {
#ifdef __OS2_PM__
        start *= multy;
        end *= multy;
        if( end > -multy ) {
            end += multy;
            if( end > bottom ) {
                end = bottom;
            }
            top = _wpi_getheightrect( client ) - end;
            //bottom = end + bottom_adjust;
        }
        if( start > -multy ) {
            //start += multy;
            if( start > bottom ) {
                start = bottom;
            }
            bottom = _wpi_getheightrect( client ) - start;
            //top = start + bottom_adjust;
        }
#else
        start *= multy;
        end *= multy;
        if( start > -multy ) {
            if( start > bottom ) {
                start = bottom;
            }
            top = start;
        }
        if( end > -multy ) {
            end += multy;
            if( end > bottom ) {
                end = bottom;
            }
            bottom = end;
        }
#endif

    }

    if( dx != 0 ) {
        start *= multx;
        end *= multx;
        if( start > -multx ) {
            if( start > right ) {
                start = right;
            }
            left = start;
        }
        if( end > -multx ) {
            end += multx;
            if( end > right ) {
                end = right;
            }
            right = end;
        }
    }

    _wpi_setrectvalues( &client, left, top, right, bottom );
    GUIInvalidatePaintHandles( wnd );
    _wpi_scrollwindow( hwnd, dx, dy, &client, &client );
    _wpi_updatewindow( hwnd );
}
Esempio n. 7
0
/*
 * WinNewDrawPad - create a new drawing pad for Windows version
 */
HWND WinNewDrawPad( img_node *node )
{
    MDICREATESTRUCT     mdicreate;
    short               y_adjustment;
    short               x_adjustment;
    short               pad_x;
    short               pad_y;
    int                 i;
    img_node            *temp;
    POINT               origin;
    char                filename[_MAX_PATH];
    HWND                drawarea;
    HMENU               sys_menu;

    node->viewhwnd = CreateViewWin( node->width, node->height );
    pad_x = 0;
    pad_y = 0;

    temp = node->nexticon;

    for( i = 1; i < node->num_of_images; i++ ) {
        temp->viewhwnd = node->viewhwnd;
        temp = temp->nexticon;
    }

    if( node->imgtype == BITMAP_IMG ) {
        mdicreate.szClass = DrawAreaClassB;
    } else if( node->imgtype == ICON_IMG ) {
        mdicreate.szClass = DrawAreaClassI;
    } else {
        mdicreate.szClass = DrawAreaClassC;
    }

    GetFnameFromPath( node->fname, filename );
    mdicreate.szTitle = filename;
    mdicreate.hOwner = Instance;

    x_adjustment = (short)(2 * GetSystemMetrics( SM_CXFRAME ));
    y_adjustment = (short)(2 * GetSystemMetrics( SM_CYFRAME ) +
                           GetSystemMetrics( SM_CYCAPTION ) - 1);

    origin.x = 0;
    origin.y = 0;
    FindOrigin( &origin );
    CalculateDims( node->width, node->height, &pad_x, &pad_y );

    mdicreate.cx = x_adjustment + pad_x;
    mdicreate.cy = y_adjustment + pad_y;
    mdicreate.x = origin.x;
    mdicreate.y = origin.y;
    mdicreate.style = WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE |
                      WS_CLIPSIBLINGS | WS_DLGFRAME | WS_MINIMIZEBOX |
                      WS_THICKFRAME;
    mdicreate.lParam = (LPARAM)(LPVOID)node;

    drawarea = (HWND)SendMessage( ClientWindow, WM_MDICREATE, 0,
                                  (LPARAM)(LPVOID)&mdicreate );

    if( drawarea != (HWND)NULL ) {
        RECT    rect;
        int     w, h;
        _wpi_getclientrect( drawarea, &rect );
        w = _wpi_getwidthrect( rect );
        h = _wpi_getheightrect( rect );
        if( w != pad_x || h != pad_y ) {
            GetWindowRect( drawarea, &rect );
            w = _wpi_getwidthrect( rect ) + (pad_x - w);
            h = _wpi_getheightrect( rect ) + (pad_y - h);
            SetWindowPos( drawarea, HWND_TOP, 0, 0, w, h,
                          SWP_SIZE | SWP_NOZORDER | SWP_NOMOVE );
        }
    }

    if( ImgedIsDDE ) {
        sys_menu = GetSystemMenu( drawarea, FALSE );
        if( sys_menu != (HMENU)NULL ) {
            EnableMenuItem( sys_menu, SC_CLOSE, MF_GRAYED );
        }
    }

    BlowupImage( NULL, NULL );
    return( drawarea );

} /* WinNewDrawPad */
Esempio n. 8
0
WPI_MRESULT CALLBACK GraphWndProc( HWND         Wnd,
                                   WPI_MSG      message,
                                   WPI_PARAM1   wParam,
                                   WPI_PARAM2   lParam )
//=============================================================

{
    WPI_PRES            Win_dc;
    PAINTSTRUCT         ps;
    int                 width, height;
    int                 x, y, t;
    int                 h_minpos, h_maxpos, h_currpos;
    int                 v_minpos, v_maxpos, v_currpos;
    WPI_RECTDIM         left, top, right, bottom;
    WPI_RECT            rect;
    struct ScrollStruct scroll_info;
    LPWDATA             w;
    HWND                frame;
#if defined( __OS2__ )
    int                 wheight;
    WPI_RECT            wrect;
#endif

    w = _GetWindowData( Wnd );
    if( w == NULL ) {
        return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) );
    }
#if defined( __OS2__ )
    frame = w->frame;
#else
    frame = Wnd;
#endif

    switch( message ) {
#if defined( __WINDOWS__ )
    case WM_SETFOCUS:
        SetFocus( _MainWindow );
    case WM_SYSCOMMAND:
    case WM_MOUSEACTIVATE:
        _MakeWindowActive( w );
        return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) );

    case WM_KILLFOCUS:
        if( ( wParam != NULL) && ( wParam != _MainWindow ) ) {
            _ShowWindowActive( NULL, w );
        }
        return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) );
#else
    case WM_FOCUSCHANGE:
    case WM_SYSCOMMAND:
        _MakeWindowActive( w );
        return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) );
#endif

    case WM_PAINT:
        // Setup
        Win_dc = _wpi_beginpaint( Wnd, NULLHANDLE, &ps );
        _wpi_torgbmode( Win_dc );
        _wpi_getpaintrect( &ps, &rect );
        _wpi_getwrectvalues( rect, &left, &top, &right, &bottom );
        width = _wpi_getwidthrect( rect );
        height = _wpi_getheightrect( rect );

        // Copy from the memory dc to the screen
#if defined( __OS2__ )
        GetClientRect( Wnd, &wrect );
        wheight = _wpi_getheightrect( wrect );
        y = _GetPresHeight() - wheight - _BitBlt_Coord.ycoord + top;
#else
        y = _BitBlt_Coord.ycoord + top;
#endif
        _wpi_bitblt( Win_dc,
                left,
                top,
                width, height,
                _Mem_dc,
                _BitBlt_Coord.xcoord + left,
                y,
                SRCCOPY );

        //Cleanup
        _wpi_endpaint( Wnd, Win_dc, &ps );
        break;
#if defined( __OS2__ )
    case WM_CLOSE:
        WinDestroyWindow( w->frame );
        return( 0 );
#endif
    case WM_DESTROY:
        // free the system resources allocated

        if( _Mem_dc ){
            _wpi_deletecliprgn( _Mem_dc, _ClipRgn );
            _wpi_deletecompatiblepres( _Mem_dc, _Hdc );
            if( _Mem_bmp ){
                _wpi_deletebitmap( _Mem_bmp );
                if( !_IsStockFont() ){
                    _wpi_f_deletefont( _CurFnt );
                }
            }
#if defined( __OS2__ )
            WinSendMsg( _GetWinMenuHandle(), ( ULONG )MM_DELETEITEM,
                MPFROM2SHORT( ( w->handles[0] + DID_WIND_STDIO ), FALSE ), 0 );
#endif
            _DestroyAWindow( w );
        }
        break;

    case WM_VSCROLL:
        scroll_info = getscrolldata( frame, SB_VERT );
        CalPos( &scroll_info, wParam, lParam, &v_currpos, &y );

        // Make sure we have to refresh first
        if( _BitBlt_Coord.ycoord != y ) {
            _BitBlt_Coord.ycoord = y;
            _wpi_setscrollpos( frame,
                          SB_VERT,
                          v_currpos,
                          TRUE );
            _wpi_invalidaterect( Wnd, NULL, 0 );
            _wpi_updatewindow( Wnd );
        }
        return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) );

    case WM_HSCROLL:
        scroll_info = getscrolldata( frame, SB_HORZ );
        CalPos( &scroll_info, wParam, lParam, &h_currpos, &x );

        // make sure we need to refresh first
        if( _BitBlt_Coord.xcoord != x ) {
            _BitBlt_Coord.xcoord = x;
            _wpi_setscrollpos(  frame,
                                SB_HORZ,
                                h_currpos,
                                TRUE );
            _wpi_invalidaterect( Wnd, NULL, 0 );
            _wpi_updatewindow( Wnd );
        }
        return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) );

    case WM_SIZE:
        x = _wpi_getsystemmetrics( SM_CXSCREEN );
        y = _wpi_getsystemmetrics( SM_CYSCREEN );

        _wpi_getscrollrange( frame, SB_VERT, &v_minpos, &v_maxpos );
        _wpi_getscrollrange( frame, SB_HORZ, &h_minpos, &h_maxpos );
        _wpi_getclientrect( Wnd, &rect );
        _wpi_getrectvalues( rect, &left, &top, &right, &bottom );
        height = bottom - top + 1;
        width = right - left + 1;

        if( width >= x ) {
            // hide the scroll bar
#if defined( __OS2__ )
            WinShowWindow( WinWindowFromID( frame, FID_HORZSCROLL ),
                           FALSE );
#else
            ShowScrollBar( Wnd, SB_HORZ, FALSE );
#endif
            _BitBlt_Coord.xcoord = 0;
            h_currpos = 0;
        } else {
            // if the window isn't as big as the device context
            // show the scroll bar
            t = x - width + 1;
            if( x - _BitBlt_Coord.xcoord + 1 < width ) {
                _BitBlt_Coord.xcoord = x - width + 1;
            }
            if( _BitBlt_Coord.xcoord == t ) {
                h_currpos = h_maxpos;
            } else {
            h_currpos = CalScrollAmt( h_maxpos, h_minpos,
                                      _BitBlt_Coord.xcoord,
                                      x, width );
            }
#if defined( __OS2__ )
            WinShowWindow( WinWindowFromID( frame, FID_HORZSCROLL ),
                           TRUE );
#else
            ShowScrollBar( Wnd, SB_HORZ, 1 );
#endif
        }

        if( height >= y ) {
            // hide the scroll bar
#if defined( __OS2__ )
            WinShowWindow( WinWindowFromID( frame, FID_VERTSCROLL ),
                           FALSE );
#else
            ShowScrollBar( Wnd, SB_VERT, 0 );
#endif
            _BitBlt_Coord.ycoord = 0;
            v_currpos = 0;
        } else {
            // if the the window isn't as big as the device context
            // then show the scroll bar
            t = y - height + 1;
            if( y - _BitBlt_Coord.ycoord + 1 < height ) {
                _BitBlt_Coord.ycoord = t;
            }
            if( _BitBlt_Coord.ycoord == t ) {
                v_currpos = v_maxpos;
            } else {
                v_currpos = CalScrollAmt( v_maxpos, v_minpos,
                                          _BitBlt_Coord.ycoord,
                                          y, height );
            }
#if defined( __OS2__ )
            WinShowWindow( WinWindowFromID( frame, FID_VERTSCROLL ),
                           TRUE );
#else
            ShowScrollBar( Wnd, SB_VERT, 1 );
#endif
        }


        // Adjust the scroll bar thumbs' positions
        _wpi_setscrollpos( frame, SB_HORZ, h_currpos, TRUE );
        _wpi_setscrollpos( frame, SB_VERT, v_currpos, TRUE );
#if defined( __OS2__ )
        Win_dc = WinBeginPaint( Wnd, NULL, &rect );
        WinFillRect( Win_dc, &rect, CLR_BLACK );
        WinEndPaint( Win_dc );
#endif
        _wpi_invalidaterect( Wnd, NULL, 0 );
        break;
    default:
        return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) );
    }
   return( NULL );
}
Esempio n. 9
0
/*
 * imgEditInit - initialization
 */
static BOOL imgEditInit( HAB hab )
{
    ULONG       flags;
    BOOL        maximized;
    HWND        frame;
    char        clientclass[] = { "IMGEDClientClass" };
    HWND        hwnd;
    WPI_RECT    rect;
    HMENU       hmenu;

    // Change this to use the querycaps routine
    ColourPlanes = 1;
    BitsPerPixel = 4;

    Instance.hab = hab;
    Instance.mod_handle = NULL;
    /*
     * set up window class
     */
    if (!WinRegisterClass( hab,
                           className,
                           (PFNWP)ImgEdFrameProc,
                           CS_MOVENOTIFY | CS_SIZEREDRAW | CS_CLIPCHILDREN,
                           0 )) {
        return( FALSE );
    }
    if (!WinRegisterClass( hab,
                           clientclass,
                           (PFNWP)ClientProc,
                           CS_MOVENOTIFY | CS_SIZEREDRAW | CS_CLIPCHILDREN,
                           0 )) {
        return( FALSE );
    }
    if (!WinRegisterClass( hab,
                           PaletteClass,
                           (PFNWP)ColourPalWinProc,
                           CS_MOVENOTIFY | CS_SIZEREDRAW | CS_CLIPCHILDREN,
                           0 )) {
        return( FALSE );
    }
    if (!WinRegisterClass( hab,
                           CURRENT_CLASS,
                           (PFNWP)CurrentWndProc,
                           CS_SIZEREDRAW | CS_SYNCPAINT,
                           0 )) {
        return( FALSE );
    }
    if (!WinRegisterClass( hab,
                           AVAIL_CLASS,
                           (PFNWP)ColoursWndProc,
                           CS_SIZEREDRAW | CS_SYNCPAINT,
                           0 )) {
        return( FALSE );
    }
    if (!WinRegisterClass( hab,
                           SCREEN_CLASS,
                           (PFNWP)ScreenWndProc,
                           CS_SIZEREDRAW,
                           0 )) {
        return( FALSE );
    }
    if (!WinRegisterClass( hab,
                           DrawAreaClassB,
                           (PFNWP)DrawAreaWinProc,
                           CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPSIBLINGS,
                           0 )) {
        return( FALSE );
    }
    if (!WinRegisterClass( hab,
                           DrawAreaClassI,
                           (PFNWP)DrawAreaWinProc,
                           CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPSIBLINGS,
                           0 )) {
        return( FALSE );
    }
    if (!WinRegisterClass( hab,
                           DrawAreaClassC,
                           (PFNWP)DrawAreaWinProc,
                           CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPSIBLINGS,
                           0 )) {
        return( FALSE );
    }
    if (!WinRegisterClass( hab,
                           ViewWinClass,
                           (PFNWP)ViewWindowProc,
                           CS_MOVENOTIFY | CS_SIZEREDRAW | CS_CLIPCHILDREN,
                           0 )) {
        return( FALSE );
    }

    LoadImgedConfig();
    maximized = ImgedConfigInfo.ismaximized;
    InitPalette();
    /*
     * now make the main window
     */
    flags = FCF_TITLEBAR        |
            FCF_SIZEBORDER      |
            FCF_MINMAX          |
            FCF_SYSMENU         |
            FCF_TASKLIST        |
            FCF_ICON            |
            FCF_MENU;

    frame = WinCreateStdWindow(
        HWND_DESKTOP,
        0L,
        &flags,
        className,
        ImgEdName,
        0L,
        (HMODULE)0,
        IMGED_MAIN,
        &HMainWindow);

    WinSetWindowPos(frame, HWND_TOP, ImgedConfigInfo.x_pos,
                ImgedConfigInfo.y_pos, ImgedConfigInfo.width,
                ImgedConfigInfo.height, SWP_MOVE | SWP_SHOW | SWP_SIZE);

    _wpi_getclientrect( HMainWindow, &rect );
    flags = 0L;
    /*
     * N.B. - NOTE that ClientWindow is actually a FRAME WINDOW!!!!!  The
     *        name is a bit misleading and it is unlike HMainWindow which
     *        is a client window.
     */
    ClientWindow = WinCreateStdWindow( HMainWindow, 0L, &flags, clientclass,
                                        "", 0L, (HMODULE)0, 0, &hwnd);

    WinSetWindowPos(ClientWindow, HWND_TOP, 0, STATUS_WIDTH,
                _wpi_getwidthrect( rect ),
                _wpi_getheightrect(rect) -STATUS_WIDTH -FUNCTIONBAR_WIDTH -1,
                SWP_MOVE | SWP_SHOW | SWP_SIZE);

    CreateColourPal();
    InitFunctionBar( HMainWindow );
    InitTools( _wpi_getframe(HMainWindow) );

    hmenu = _wpi_getmenu( frame );
    if (ImgedConfigInfo.grid_on) {
        CheckGridItem(hmenu);
    }
    SetHintText("Open Watcom Image Editor.");
    WinSetFocus( HWND_DESKTOP, _wpi_getframe(HMainWindow) );
    return( TRUE );
} /* imgEditInit */
Esempio n. 10
0
/*
 * ChangeImageSize - changes the size of the current image being edited
 */
void ChangeImageSize( void )
{
    img_node        *node;
    WPI_DLGPROC     dlgproc;
    WPI_DLGRESULT   button_type;
    img_node        new_node;
    WPI_PRES        pres;
    HDC             srcdc;
    WPI_PRES        srcpres;
    HDC             destdc;
    WPI_PRES        destpres;
    HBITMAP         oldsrc;
    HBITMAP         olddest;
    int             retcode;
    WPI_PARAM2      lparam;
    WPI_RECT        rc;
    short           new_width;
    short           new_height;
    int             y_src;
    int             y_dest;
    char            *title;
    char            *text;

    node = GetCurrentNode();
    if( node == NULL ) {
        return;
    }

    if( node->imgtype != BITMAP_IMG ) {
        return;
    }

    imgHeight = node->height;
    imgWidth = node->width;

    dlgproc = _wpi_makedlgprocinstance( ChangeSizeDlgProc, Instance );
    button_type = _wpi_dialogbox( HMainWindow, dlgproc, Instance, IMAGESIZE, 0L );
    _wpi_freedlgprocinstance( dlgproc );

    if( button_type == DLGID_CANCEL ) {
        return;
    }
    if( imgWidth == node->width && imgHeight == node->height ) {
        PrintHintTextByID( WIE_IMAGESIZEUNCHANGED, NULL );
        return;
    }
    title = IEAllocRCString( WIE_INFORMATIONTEXT );
    text = IEAllocRCString( WIE_RESETUNDOSTACKWARNING );
    retcode = _wpi_messagebox( HMainWindow, text, title, MB_YESNO | MB_ICONINFORMATION );
    if( text != NULL ) {
        IEFreeRCString( text );
    }
    if( title != NULL ) {
        IEFreeRCString( title );
    }

    if( retcode == WPI_IDNO ) {
        return;
    }

    new_node.width = (short)imgWidth;
    new_node.height = (short)imgHeight;
    new_node.bitcount = node->bitcount;
    new_node.imgtype = BITMAP_IMG;

    MakeBitmap( &new_node, TRUE );

    pres = _wpi_getpres( HWND_DESKTOP );
    srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc );
    destpres = _wpi_createcompatiblepres( pres, Instance, &destdc );
    _wpi_releasepres( HWND_DESKTOP, pres );

    oldsrc = _wpi_selectbitmap( srcpres, node->hxorbitmap );
    olddest = _wpi_selectbitmap( destpres, new_node.hxorbitmap );

    if( stretchImage ) {
        _wpi_stretchblt( destpres, 0, 0, imgWidth, imgHeight,
                         srcpres, 0, 0, node->width, node->height, SRCCOPY );
    } else {
#ifdef __OS2_PM__
        y_src = node->height - imgHeight;
        if( y_src < 0 ) {
            y_src = 0;
            y_dest = imgHeight - node->height;
        } else {
            y_dest = 0;
        }
#else
        y_src = 0;
        y_dest = 0;
#endif
        _wpi_bitblt( destpres, 0, y_dest, node->width, node->height,
                     srcpres, 0, y_src, SRCCOPY );
    }
    _wpi_getoldbitmap( srcpres, oldsrc );
    oldsrc = _wpi_selectbitmap( srcpres, node->handbitmap );
    _wpi_getoldbitmap( destpres, olddest );
    olddest = _wpi_selectbitmap( destpres, new_node.handbitmap );

    if( stretchImage ) {
        _wpi_stretchblt( destpres, 0, 0, imgWidth, imgHeight,
                         srcpres, 0, 0, node->width, node->height, SRCCOPY );
    } else {
        _wpi_bitblt( destpres, 0, 0, node->width, node->height, srcpres, 0, 0, SRCCOPY );
    }

    _wpi_getoldbitmap( srcpres, oldsrc );
    _wpi_getoldbitmap( destpres, olddest );
    _wpi_deletebitmap( node->hxorbitmap );
    _wpi_deletebitmap( node->handbitmap );
    _wpi_deletecompatiblepres( srcpres, srcdc );
    _wpi_deletecompatiblepres( destpres, destdc );

    node->hxorbitmap = new_node.hxorbitmap;
    node->handbitmap = new_node.handbitmap;
    node->width = (short)imgWidth;
    node->height = (short)imgHeight;

    SetIsSaved( node->hwnd, FALSE );
    ResetUndoStack( node );

    RePositionViewWnd( node );

    _wpi_getclientrect( node->hwnd, &rc );
    new_width = (short)_wpi_getwidthrect( rc );
    new_height = (short)_wpi_getheightrect( rc );
    lparam = WPI_MAKEP2( new_width, new_height );

    ResizeChild( lparam, node->hwnd, false );
    DisplayImageText( node );
    WriteSetSizeText( WIE_NEWIMAGESIZE, imgWidth, imgHeight );

} /* ChangeImageSize */
Esempio n. 11
0
WPI_MRESULT CALLBACK GUIWindowProc( HWND hwnd, WPI_MSG msg, WPI_PARAM1 wparam,
                                    WPI_PARAM2 lparam )
{
    gui_window          *wnd;
    gui_window          *root;
    WORD                param;
    WPI_POINT           currentpoint;
    gui_coord           point;
    gui_coord           size;
    WPI_MRESULT         ret;
    WPI_MINMAXINFO _W386FAR *info;
    WPI_RECT            rect;
    HWND                parent;
    CREATESTRUCT FAR    *lpcs;
    wmcreate_info _W386FAR *wmcreateinfo;
    gui_create_info     *createinfo;
    bool                use_defproc;
    unsigned            control_id;
    HWND                win;
#ifndef __OS2_PM__
    gui_key_state       key_state;
    RECT                rc;
#endif

    root = NULL;
    ret = 0L;
    use_defproc = FALSE;
    if( msg == WM_CREATE ) {
        lpcs = ( CREATESTRUCT FAR * )MK_FP32( (void *)lparam );
        wmcreateinfo = (wmcreate_info _W386FAR *)MK_FP32( _wpi_getcreateparms( lpcs ) );
        if ( wmcreateinfo != NULL ) {
            wnd = wmcreateinfo->wnd;
            createinfo = wmcreateinfo->info;
            if( wnd->hwnd == NULLHANDLE ) {
#ifdef __OS2_PM__
                if( wnd->root_frame != NULLHANDLE && wnd->root == NULLHANDLE ) {
                    wnd->root = hwnd;
                } else {
                    wnd->hwnd = hwnd;
                }
#else
                if( _wpi_getparent( hwnd ) == HWND_DESKTOP ) {
                    wnd->root       = hwnd;
                    wnd->root_frame = hwnd;
                } else {
                    wnd->hwnd       = hwnd;
                    wnd->hwnd_frame = hwnd;
                }
#endif
            }
            DoSetWindowLong( hwnd, wnd );
        }
    }
    wnd = GUIGetWindow( hwnd );
    if( wnd == NULL ) {
        return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
    }

    if( GUIMDIProcessMessage( wnd, hwnd, msg, wparam, lparam, &ret ) ) {
        return( ret );
    }

    if( wnd->root == hwnd ) {
        /* message for root window */
        switch( msg ) {
        case WM_CREATE :
#ifdef __OS2_PM__
            wnd->root_pinfo.normal_pres =
                _wpi_createos2normpres( GUIMainHInst, hwnd );
#endif
            _wpi_getclientrect( wnd->root_frame, &wnd->root_client );
            if( CreateBackgroundWnd( wnd, createinfo ) ) {
                return( 0 );
            }
            return( (WPI_MRESULT)WPI_ERROR_ON_CREATE );
            break;
        case WM_DESTROY :
            wnd->flags |= DOING_DESTROY;
            GUICloseToolBar( wnd );
            //ret =  _wpi_defwindowproc( hwnd, msg, wparam, lparam );
            //wnd->root       = NULL;
            //wnd->root_frame = NULL;
            return( 0L );
        }
    } else if( ( wnd->root != NULLHANDLE ) && ( hwnd == wnd->hwnd ) ) {
        /* message for container window */
        switch( msg ) {
        case WM_SIZE :
            if( !_wpi_isiconic( _wpi_getframe( hwnd ) ) ) {
                size.x = _wpi_getwmsizex( wparam, lparam );
                size.y = _wpi_getwmsizey( wparam, lparam );
                GUIDoResize( wnd, hwnd, &size );
            }
            return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
            break;
        case WM_MOVE :
            return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
            break;
        case WM_VSCROLL :
        case WM_HSCROLL :
        case WM_CLOSE :
            return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
            break;
        }
    }

    switch( msg ) {
    case WM_CREATE :
#ifdef __OS2_PM__
        wnd->hwnd_pinfo.normal_pres =
            _wpi_createos2normpres( GUIMainHInst, hwnd );
#endif
        NumWindows++; // even if -1 is returned, window will get WM_DESTROY
        win = GUIGetParentFrameHWND( wnd );
        if( (  wnd->root_frame != NULLHANDLE ) ||
            ( createinfo->style & GUI_POPUP ) ) {
            if( !GUIAddToSystemMenu( wnd, win, 0, NULL,
                                     createinfo->style ) ) {
                return( (WPI_MRESULT)WPI_ERROR_ON_CREATE );
            }
        } else {
            if( !GUIAddToSystemMenu( wnd, win, createinfo->num_menus,
                                createinfo->menu, createinfo->style ) ) {
                return( (WPI_MRESULT)WPI_ERROR_ON_CREATE );
            }
        }
        _wpi_getclientrect( hwnd, &wnd->hwnd_client );
        GUISetRowCol( wnd, NULL );
        if( ( hwnd == wnd->hwnd ) && ( wnd->root == NULLHANDLE ) ) {
            GUIMDINewWindow( hwnd );
        }
        if( GUIEVENTWND( wnd, GUI_INIT_WINDOW, NULL ) ) {
            wnd->flags |= SENT_INIT;
            GUISetScroll( wnd ); /* initalize scroll ranges */
            GUIBringToFront( wnd );
            return( 0 );
        } else {
            /* app decided not to create window */
            return( (WPI_MRESULT)WPI_ERROR_ON_CREATE );
        }
        break;
#if defined(__NT__) || defined(WILLOWS)
    case WM_CTLCOLORBTN :
    case WM_CTLCOLORDLG :
    //case WM_CTLCOLORLISTBOX :
    case WM_CTLCOLORSTATIC :
    //case WM_CTLCOLOREDIT :
        ret = (WPI_MRESULT)GUICtl3dCtlColorEx( msg, wparam, lparam );
        if( ret == (HBRUSH)NULL ) {
            SetBkColor( (HDC)wparam, GetNearestColor( (HDC)wparam,
                        GUIGetBack( wnd, GUI_BACKGROUND ) ) );
            ret = (WPI_MRESULT)wnd->bk_brush;
        }
        return( ret );
#elif !defined( __OS2_PM__ )
    case WM_CTLCOLOR :
        switch( HIWORD( lparam ) ) {
        case CTLCOLOR_BTN :
        case CTLCOLOR_DLG :
        case CTLCOLOR_EDIT :
        case CTLCOLOR_LISTBOX :
        case CTLCOLOR_MSGBOX :
        case CTLCOLOR_STATIC :
            ret = (WPI_MRESULT)GUICtl3dCtlColorEx( msg, wparam, lparam );
            if( ret == (HBRUSH)NULL ) {
                SetBkColor( (HDC)wparam, GetNearestColor( (HDC)wparam,
                            GUIGetBack( wnd, GUI_BACKGROUND ) ) );
                ret = (WPI_MRESULT)wnd->bk_brush;
            }
            break;
        }
        return( ret );
#endif
#ifndef __OS2_PM__
    case WM_INITMENUPOPUP :
        return( GUIProcessInitMenuPopup( wnd, hwnd, msg, wparam, lparam ) );

    case WM_MENUSELECT :
        return( GUIProcessMenuSelect( wnd, hwnd, msg, wparam, lparam ) );
#endif
    case WM_GETMINMAXINFO :
        info = (WPI_MINMAXINFO _W386FAR *)MK_FP32( (void *)lparam );
        ret = _wpi_defwindowproc( hwnd, msg, wparam, lparam );
        if( wnd->root == NULLHANDLE ) {
            parent = _wpi_getparent( hwnd );
            _wpi_getclientrect( parent, &rect );
            _wpi_setmaxposition( *info, 0, 0 );
            _wpi_setmaxtracksize( info, _wpi_getwidthrect( rect ),
                             _wpi_getheightrect( rect ) );
        }
        return( ret );
    case WM_ERASEBKGND:
#ifdef __OS2_PM__
        //GUIInvalidatePaintHandles( wnd );
        return( (WPI_MRESULT)TRUE );
#else
        if( !_wpi_isiconic( hwnd ) ) {
            GetClientRect( hwnd, &rc );
            FillRect( (HDC)wparam, &rc, wnd->bk_brush );
        }
        use_defproc = TRUE;
        break;
#endif
#if !defined(__OS2_PM__) && !defined(WILLOWS)
    case WM_PAINTICON :
    {
        HICON   old;
        old = SET_HICON( wnd->hwnd, wnd->icon );
        ret = _wpi_defwindowproc( hwnd, msg, wparam, lparam );
        SET_HICON( wnd->hwnd, old );
        return( ret );
    }
#endif
    case WM_PAINT:
        if( _wpi_isiconic( hwnd ) ) {
            return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
        } else {
            GUIPaint( wnd, hwnd, FALSE );
        }
        break;
#ifndef __OS2_PM__
    case WM_ACTIVATEAPP :
        root = GUIGetRootWindow();
        ActivateNC( root, wparam );
        if( GUICurrWnd != NULL ) {
            ActivateNC( GUICurrWnd, wparam );
        }
        use_defproc = (bool)wparam; // I'm cheating and using 'use_defproc'
                                    // outside of its self-documented purpose
        if( root ) GUIEVENTWND( root, GUI_ACTIVATEAPP, &use_defproc );
        use_defproc = TRUE;
        break;
#if 0
    // this repaints the nc client area when the window loses focus to
    // a window that is not a descendant of a GUI window
    case WM_KILLFOCUS :
        if( !GUIIsGUIChild( (HWND)wparam ) ) {
            ActivateNC( wnd, FALSE );
        }
        break;
#endif
    case WM_SETFOCUS :
        if( !_wpi_ismsgsetfocus( msg, lparam ) ) {
            return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
        }
        if( !EditControlHasFocus ) {
            if( SetFocusToParent() ) {
                return( 0L );
            }
        }
        break;
#endif
    case WM_VSCROLL :
    case WM_HSCROLL :
        GUIProcessScrollMsg( wnd, msg, wparam, lparam );
        return( 0L );
#ifdef __NT__
    case WM_MOUSEWHEEL :
        {
        // Try to handle mousewheel messages...
        // Fake them into GUIProcessScrollMsg()
        // as "normal" vertical scroll messages.
        short gcWheelDelta; //wheel delta from roll
        WORD  wKey;

        // The wnd I get is not the same as WM_VSCROLL : above gets...
        // Note to self: Fix it...
        // Seems like the main app window gets the message, rather than
        // the MDI clients...

        gcWheelDelta = HIWORD(wparam);
        wKey = LOWORD(wparam);
        // Scroll wheel upwards  gives  120
        //    "     "   downward   "   -120
        if( wnd != GUICurrWnd ) // Send to child window with focus
            wnd = GUICurrWnd;
        if( gcWheelDelta > 0 ) {
            // positive - scroll up
            if( wKey == MK_CONTROL || wKey == MK_SHIFT )
               GUIProcessScrollMsg( wnd, WM_VSCROLL, SB_PAGEUP, 0L );
            else
               GUIProcessScrollMsg( wnd, WM_VSCROLL, SB_LINEUP, 0L );
        } else {
            // negative - scroll down
            if( wKey == MK_CONTROL || wKey == MK_SHIFT )
               GUIProcessScrollMsg( wnd, WM_VSCROLL, SB_PAGEDOWN, 0L );
            else
               GUIProcessScrollMsg( wnd, WM_VSCROLL, SB_LINEDOWN, 0L );
        }
        // Inform GUI system we are done with scrolling for now.
        GUIProcessScrollMsg( wnd, WM_VSCROLL, SB_ENDSCROLL, 0 );
        }
        return( 0L );
#endif
    case WM_MOVE :
        use_defproc = TRUE;
        if( wnd->flags & DOING_CLOSE ) {
            break;
        }
        if( !GUIParentHasFlags( wnd, IS_MINIMIZED ) ) {
            GUIEVENTWND( wnd, GUI_MOVE, NULL );
        }
        use_defproc = TRUE;
        break;
    case WM_SIZE:
        use_defproc = TRUE;
        if( wnd->flags & DOING_CLOSE ) {
            break;
        }
        if( _wpi_isiconic( _wpi_getframe( hwnd ) ) ) {
            wnd->flags |= IS_MINIMIZED;
            if( wnd->style & GUI_CHANGEABLE_FONT ) {
                GUIEnableSysMenuItem( wnd, GUI_CHANGE_FONT, FALSE );
            }
            GUIEVENTWND( wnd, GUI_ICONIFIED, NULL );
            if( GUIMDI ) {
                GUIBringNewToFront( wnd );
            }
        } else {
            wnd->flags &= ~IS_MINIMIZED;
            size.x = _wpi_getwmsizex( wparam, lparam );
            size.y = _wpi_getwmsizey( wparam, lparam );
            GUIDoResize( wnd, hwnd, &size );
            if( wnd->flags & IS_ROOT ) {
                win = GUIGetParentFrameHWND( wnd );
                if( !_wpi_isiconic( win ) ) {
                    GUIMaximizeZoomedChildren( wnd );
                }
            }
        }
        //Call back to tell about resizing so system tray can be used
        WndSizeChange( hwnd, wparam, lparam );
        break;
    case WM_MOUSEMOVE:
        currentpoint.x = GET_WM_MOUSEMOVE_POSX( wparam, lparam );
        currentpoint.y = GET_WM_MOUSEMOVE_POSY( wparam, lparam );
        point.x = currentpoint.x;
        point.y = currentpoint.y;
        GUIScreenToScaleR( &point );
        if( ( currentpoint.x != prevpoint.x ) ||
            ( currentpoint.y != prevpoint.y ) ) {
            prevpoint.x = currentpoint.x;
            prevpoint.y = currentpoint.y;
            SendPointEvent( wparam, lparam, wnd, GUI_MOUSEMOVE, TRUE );
        }
        break;
#ifndef __OS2_PM__
    case WM_NCLBUTTONDOWN :
    case WM_NCMBUTTONDOWN :
    case WM_NCRBUTTONDOWN :
        CheckDoFront( wnd );
        use_defproc = TRUE;
        break;
    case WM_RBUTTONDOWN:
        _wpi_setcapture( hwnd );
        CheckDoFront( wnd );
        SendPointEvent( wparam, lparam, wnd, GUI_RBUTTONDOWN, TRUE );
        break;
#else
    case WM_RBUTTONDOWN :
        WPI_MAKEPOINT( wparam, lparam, currentpoint );
        win = PM1632WinWindowFromPoint( hwnd, &currentpoint, FALSE );
        if( ( win != (HWND)NULL) && ( win != hwnd ) ) {
            control_id = _wpi_getdlgctrlid( win );
            if( control_id != 0 ) {
                GUIEVENTWND( wnd, GUI_CONTROL_RCLICKED, &control_id );
            }
        } else {
            _wpi_setcapture( hwnd );
            CheckDoFront( wnd );
            SendPointEvent( wparam, lparam, wnd, GUI_RBUTTONDOWN, TRUE );
        }
        break;
#endif
    case WM_LBUTTONDOWN:
        _wpi_setcapture( hwnd );
        CheckDoFront( wnd );
        SendPointEvent( wparam, lparam, wnd, GUI_LBUTTONDOWN, TRUE );
        use_defproc = TRUE;
        break;
    case WM_LBUTTONUP:
        _wpi_releasecapture();
        SendPointEvent( wparam, lparam, wnd, GUI_LBUTTONUP, TRUE );
        use_defproc = TRUE;
        break;
    case WM_RBUTTONUP:
        _wpi_releasecapture();
        SendPointEvent( wparam, lparam, wnd, GUI_RBUTTONUP, TRUE );
        break;
    case WM_LBUTTONDBLCLK:
        CheckDoFront( wnd );
        SendPointEvent( wparam, lparam, wnd, GUI_LBUTTONDBLCLK, TRUE );
        break;
    case WM_RBUTTONDBLCLK:
        CheckDoFront( wnd );
        SendPointEvent( wparam, lparam, wnd, GUI_RBUTTONDBLCLK, TRUE );
        break;
    case WM_SYSCOMMAND:
        param = _wpi_getid( wparam );
        switch( param ) {
            case SC_NEXTWINDOW :
                if( GUIMDI ) {
                    NextWndToFront( hwnd );
                    return( 0L );
                }
            default :
                if( ( param & 0xf000 ) == ( SC_NEXTWINDOW & 0xf000 ) ) {
                    /* top value same for all SC_* values */
                    return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
                } else {
                    ProcessMenu( wnd, param );
                }
                break;
        }
        break;
#ifdef __OS2_PM__
    case WM_CONTROL :
        GUIProcessControlNotification( SHORT1FROMMP(wparam),
                                       SHORT2FROMMP(wparam), wnd );
        break;
#else
    case WM_PARENTNOTIFY:
        if( ( LOWORD(wparam) == WM_RBUTTONDOWN ) ||
            ( LOWORD(wparam) == WM_LBUTTONDOWN ) ||
            ( LOWORD(wparam) == WM_MBUTTONDOWN ) ) {
            if( wnd->root == NULLHANDLE ) {
                CheckDoFront( wnd );
            }
        }

        if( LOWORD(wparam) == WM_RBUTTONDOWN ) {
            WPI_MAKEPOINT( wparam, lparam, currentpoint );
            MapWindowPoints( hwnd, (HWND)NULL, &currentpoint, 1 );
            win = _wpi_windowfrompoint( currentpoint );
            control_id = _wpi_getdlgctrlid( win );
            if( control_id != 0 ) {
                if( _wpi_getparent(win) == hwnd ) {
                    GUIEVENTWND( wnd, GUI_CONTROL_RCLICKED, &control_id );
                }
            }
        }
        break;
    case WM_ENDSESSION : {
        gui_end_session     es;

        es.endsession = (bool)wparam;
        es.logoff = (bool)( lparam == 0x80000000L );
        GUIEVENTWND( wnd, GUI_ENDSESSION, &es );
        return( 0L );
    }
    case WM_QUERYENDSESSION : {
        gui_end_session     es;

        es.endsession = (bool)wparam;
        es.logoff = (bool)( lparam == 0x80000000L ); // ENDSESSION_LOGOFF
        if( !GUIEVENTWND( wnd, GUI_QUERYENDSESSION, &es ) ) {
            return( TRUE );
        }
        return( 0L );
    }
#endif
    case WM_COMMAND:
        if( _wpi_ismenucommand( wparam, lparam ) ||
            IsToolBarCommand( wnd, wparam, lparam ) ) { /* from menu or toolbar */
            ProcessMenu( wnd, _wpi_getid( wparam ) );
            //SetFocusToParent();
        } else {
            GUIProcessControlMsg( wparam, lparam, wnd, NULL );
        }
        use_defproc = TRUE;
        break;
#ifndef __OS2_PM__
    case WM_VKEYTOITEM :
        use_defproc = FALSE;
        ret = -1;
        GUIGetKeyState( &key_state.state );
        if( ( GUIWindowsMapKey( wparam, lparam, &key_state.key ) ) ) {
            ret = GUIEVENTWND( wnd, GUI_KEYTOITEM, &key_state );
        }
        break;
#endif
#ifdef __OS2_PM__
    case WM_CHAR :
    case WM_TRANSLATEACCEL :
#else
    case WM_MENUCHAR :
    case WM_SYSKEYDOWN :
    case WM_SYSKEYUP :
    case WM_KEYUP :
    case WM_KEYDOWN :
#endif
        return( GUIProcesskey( hwnd, msg, wparam, lparam ) );
    case WM_CLOSE :
        if( wnd->flags & DOING_CLOSE ) {
            return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
        } else if( wnd->style & GUI_CLOSEABLE ) {
            if( GUIEVENTWND( wnd, GUI_CLOSE, NULL ) ) {
                wnd->flags |= DOING_CLOSE;
                if( wnd->flags & IS_ROOT ) {
                    return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
                } else {
                    _wpi_destroywindow( wnd->hwnd_frame );
                }
            }
        }
        return( 0L );

    // Message to deal with tray icons (Win 95 and NT 4.0 ).
    case WM_TRAYCALLBACK :
        TrayCallBack( hwnd, wparam, lparam );
        return( 0L );

    case WM_DESTROY :
        wnd->flags |= DOING_DESTROY;
        NumWindows--;
        GUIEVENTWND( wnd, GUI_DESTROY, NULL );
        //ret = _wpi_defwindowproc( hwnd, msg, wparam, lparam );
        GUIDestroyAllChildren( wnd );
        if( wnd->flags & IS_ROOT ) {
            GUIDestroyAllPopupsWithNoParent();
        }
        GUIFreeWindowMemory( wnd, FALSE, FALSE );
        if( NumWindows == 0 ) {
            _wpi_postquitmessage( 0 );
            Posted = TRUE;
        }
        return( 0L );
    default:
        use_defproc = TRUE;
    }

    if( use_defproc ) {
        return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
    } else {
        return( ret );
    }
}
Esempio n. 12
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 );
}