Exemple #1
0
/*
 * IECopyImage - copy the current clipping rectangle to the clipboard
 *
 * 1) Copy the bitmap to the clipboard (so other apps can use it).
 * 2) Make a copy of the XOR bitmap and the AND bitmaps so that if
 *    screen colors are involved, they will be preserved.
 *    Later, we check the owner of the clipboard to see if we really
 *    want to use the XOR/AND bitmaps or not.
 */
void IECopyImage( void )
{
    short       width;
    short       height;
    img_node    *node;

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

    if( !fEnableCutCopy ) {
        _wpi_setwrectvalues( &clipRect.rect, 0, 0, node->width, node->height );
        width = node->width;
        height = node->height;
    } else {
        width = _wpi_getwidthrect( clipRect.rect );
        height = _wpi_getheightrect( clipRect.rect );
    }

    copyImageToClipboard( width, height, node );

    if( !fEnableCutCopy ) {
        PrintHintTextByID( WIE_ENTIREIMAGECOPIED, NULL );
    } else {
        PrintHintTextByID( WIE_AREACOPIED, NULL );
        RedrawPrevClip( node->hwnd );
        fEnableCutCopy = FALSE;
    }

} /* IECopyImage */
Exemple #2
0
/*
 * BlowupImage - stretch the view window into the window given by hwnd
 */
void BlowupImage( HWND hmdiwnd, WPI_PRES pres )
{
    HDC         memdc;
    WPI_PRES    mempres;
    WPI_RECT    client;
    HBITMAP     oldbitmap;
    HBITMAP     newbitmap;
    HWND        hwnd;
    img_node    *node;
    BOOL        new_pres;

    if( hmdiwnd != NULL ) {
        hwnd = hmdiwnd;
    } else {
        node = GetCurrentNode();
        if( node == NULL ) {
            return;
        }
        hwnd = node->hwnd;
    }

    newbitmap = EnlargeImage( hwnd );
    if( newbitmap == NULL ) {
        return;
    }

    new_pres = FALSE;
    if( pres == (WPI_PRES)NULL ) {
        pres = _wpi_getpres( hwnd );
        new_pres = TRUE;
    }
    mempres = _wpi_createcompatiblepres( pres, Instance, &memdc );
    oldbitmap = _wpi_selectobject( mempres, newbitmap );

    if( ImgedConfigInfo.grid_on ) {
        showGrid( hwnd, mempres );
    } else {
        GetClientRect( hwnd, &client );
        _wpi_bitblt( pres, 0, 0, _wpi_getwidthrect( client ),
                     _wpi_getheightrect( client ), mempres, 0, 0, SRCCOPY );
        RedrawPrevClip( hwnd );   // Redraw if there was a clip region specified.
    }

    _wpi_selectobject( mempres, oldbitmap );
    _wpi_deletebitmap( newbitmap );
    _wpi_deletecompatiblepres( mempres, memdc );

    if( new_pres ) {
        _wpi_releasepres( hwnd, pres );
    }

} /* BlowupImage */
Exemple #3
0
/*
 * PlaceAndPaste - find out where the image is to be placed and then paste it there
 */
void PlaceAndPaste( void )
{
    HBITMAP         hbitmap;
    WPI_POINT       pointsize;
    img_node        *node;
    WPI_POINT       pt;
    unsigned long   format;
    int             bm_width;
    int             bm_height;

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

    if( !_wpi_isclipboardformatavailable( Instance, CF_BITMAP, &format ) ) {
        PrintHintTextByID( WIE_NOBITMAPINCLIPBOARD, NULL );
        return;
    }

    pointsize = GetPointSize( node->hwnd );
    if( fEnableCutCopy ) {
        RedrawPrevClip( node->hwnd );
        PasteImage( NULL, pointsize, node->hwnd );
        fEnableCutCopy = FALSE;
        return;
    }

    prevToolType = SetToolType( IMGED_PASTE );
    pointCursor = _wpi_loadcursor( Instance, POINT_CUR );
    prevCursor = _wpi_setcursor( pointCursor );

    _wpi_openclipboard( Instance, HMainWindow );
    hbitmap = _wpi_getclipboarddata( Instance, CF_BITMAP );
    _wpi_getbitmapdim( hbitmap, &bm_width, &bm_height );
    _wpi_closeclipboard( Instance );

    dragWidth = (short)(bm_width * pointsize.x);
    dragHeight = (short)(bm_height * pointsize.y);
    WriteSetSizeText( WIE_CLIPBOARDBITMAPSIZE, bm_width, bm_height);

    _wpi_getcursorpos( &pt );
    _wpi_screentoclient( node->hwnd, &pt );
    pt.x = pt.x / pointsize.x;
    pt.y = pt.y / pointsize.y;
    _wpi_setcapture( node->hwnd );
    firstTime = true;
    DragClipBitmap( node->hwnd, &pt, pointsize );

} /* PlaceAndPaste */
Exemple #4
0
/*
 * FocusOnImage - Selects one of the mdi children.
 */
void FocusOnImage( HWND hwnd )
{
    char        current_file[ _MAX_PATH ];
    char        *text;

    if (activeImage) {
        RedrawPrevClip(activeImage->hwnd);
        SetRectExists( FALSE );
    }

    activeImage = SelectImage( hwnd );
    if (!activeImage) {
        WImgEditError( WIE_ERR_BAD_HWND, WIE_INTERNAL_001 );
        return;
    }
    ResetViewWindow( activeImage->viewhwnd );
    CreateDrawnImage( activeImage );

    SetMenus( activeImage );
    SetNumColours( 1<<(activeImage->bitcount) );

    SetHotSpot( activeImage );
    DisplayImageText( activeImage );
    CheckForUndo( activeImage );

    GetFnameFromPath( activeImage->fname, current_file );

    text = (char *)
        MemAlloc( strlen( IEAppTitle ) + strlen( current_file ) + 3 + 1 );
    if( text ) {
        strcpy( text, IEAppTitle );
        strcat( text, " - " );
        strcat( text, current_file );
        _wpi_setwindowtext( _wpi_getframe(HMainWindow), text );
        MemFree( text );
    }

#ifndef __OS2_PM__
    RedrawWindow( hwnd, NULL, NULL, RDW_UPDATENOW );
#endif
} /* FocusOnImage */
Exemple #5
0
/*
 * showGrid - Display the grid on the draw area.
 */
static void showGrid( HWND hwnd, WPI_PRES mempres )
{
    short       i;
    short       psx;
    short       psy;
    WPI_RECT    rcclient;
    HPEN        hblackpen;
    HPEN        holdpen;
    img_node    *node;
    short       width;
    short       height;
    IMGED_DIM   left;
    IMGED_DIM   right;
    IMGED_DIM   top;
    IMGED_DIM   bottom;
    WPI_PRES    pres;
    WPI_POINT   startpt;
    WPI_POINT   endpt;

    node = SelectImage( hwnd );

    _wpi_torgbmode( mempres );
    GetClientRect( hwnd, &rcclient );
    width = (short)( _wpi_getwidthrect(rcclient) );
    height = (short)( _wpi_getheightrect(rcclient) );

    if (((width / node->width) < POINTSIZE_MIN) ||
                                ((height / node->height) < POINTSIZE_MIN)) {
        psx = 0;
        psy = 0;
    } else {
        psx = width / node->width;
        psy = height / node->height;

        hblackpen = _wpi_createpen( PS_SOLID, 0, BLACK );
        holdpen = _wpi_selectobject( mempres, hblackpen );

        _wpi_getrectvalues( rcclient, &left, &top, &right, &bottom );

        for (i=0; i < width; i = i + psx) {
            _wpi_setpoint( &startpt, i, top );
            _wpi_setpoint( &endpt, i, bottom );
            _wpi_movetoex( mempres, &startpt, NULL );
            _wpi_lineto( mempres, &endpt );
        }
        for (i=0; i <= height; i = i + psy) {
            _wpi_setpoint( &startpt, left, i );
            _wpi_setpoint( &endpt, right, i );
            _wpi_movetoex( mempres, &startpt, NULL );
            _wpi_lineto( mempres, &endpt );
        }

        _wpi_selectobject( mempres, holdpen );
        _wpi_deleteobject( hblackpen );
    }

    pres = _wpi_getpres( hwnd );
    _wpi_bitblt( pres, 0, 0, width, height, mempres, 0, 0, SRCCOPY );
    _wpi_releasepres( hwnd, pres );
    RedrawPrevClip(hwnd);  // Redraws if there was a clip region specified.
} /* showGrid */
Exemple #6
0
/*
 * SetToolType - set the tool type
 */
int SetToolType( int toolid )
{
    HMENU       hmenu;
    int         i;
    int         prev_tool;
    img_node    *node;

    if( toolType == IMGED_CLIP ) {
        node = GetCurrentNode();
        if( node != NULL ) {
            RedrawPrevClip( node->hwnd );
            SetRectExists( FALSE );
        }
    }

    prev_tool = toolType;
    toolType = toolid;

    if( toolid == IMGED_PASTE || toolid == IMGED_SNAP ) {
        return( prev_tool );
    }

    if( HMainWindow == NULL ) {
        return( 0 );
    }
    hmenu = _wpi_getmenu( _wpi_getframe( HMainWindow ) );

    switch( toolid ) {
    case IMGED_FREEHAND:
        setTheCursor( PENCIL_CUR, NULL );
        break;
    case IMGED_LINE:
        setTheCursor( CROSS_CUR, NULL );
        break;
    case IMGED_HOTSPOT:
        setTheCursor( HOTSPOT_CUR, NULL );
        break;
    case IMGED_RECTO:
        setTheCursor( CROSS_CUR, NULL );
        break;
    case IMGED_RECTF:
        setTheCursor( CROSS_CUR, NULL );
        break;
    case IMGED_CIRCLEO:
        setTheCursor( CROSS_CUR, NULL );
        break;
    case IMGED_CIRCLEF:
        setTheCursor( CROSS_CUR, NULL );
        break;
    case IMGED_FILL:
        setTheCursor( FILL_CUR, NULL );
        break;
    case IMGED_BRUSH:
        setTheCursor( BRUSH_CUR, NULL );
        if( prev_tool != IMGED_PASTE && prev_tool !=IMGED_SNAP ) {
            WriteSetSizeText( WIE_BRUSHSIZEIS, ImgedConfigInfo.brush_size,
                              ImgedConfigInfo.brush_size );
        }
        break;
    case IMGED_CLIP:
        setTheCursor( CROSS_CUR, NULL );
        break;

    default:
        setTheCursor( PENCIL_CUR, NULL );
        toolType = IMGED_FREEHAND;
        break;
    }

    for( i = IMGED_CLIP; i <= IMGED_HOTSPOT; i++ ) {
#if 0
        if( _wpi_isitemenabled( hmenu, i ) ) {
            _wpi_checkmenuitem( hmenu, i, FALSE, FALSE );
        }
#else
        if( _wpi_isitemchecked( hmenu, i ) ) {
            _wpi_checkmenuitem( hmenu, i, FALSE, FALSE );
        }
#endif
    }
    _wpi_checkmenuitem( hmenu, toolType, TRUE, FALSE );

    SetDrawTool( toolType );
    return( prev_tool );

} /* SetToolType */
Exemple #7
0
/*
 * DrawAreaWinProc - window procedure for the drawing area window
 *                 - this window is an MDI window
 */
MRESULT CALLBACK DrawAreaWinProc( HWND hwnd, WPI_MSG msg,
                                  WPI_PARAM1 wparam, WPI_PARAM2 lparam )
{
    static WPI_POINT    start_pt = { -1, -1 };
    static WPI_POINT    end_pt = { -1, -1 };
    static WPI_POINT    prev_pt = { -1, -1 };
    static WPI_POINT    new_pt = { -1, -1 };
    static WPI_POINT    pt1;
    static BOOL         flbuttondown = FALSE;
    static BOOL         frbuttondown = FALSE;
    static BOOL         fdraw_shape = FALSE;
    static BOOL         firsttime;
    static BOOL         wasicon;
    int                 mousebutton;
    WPI_POINT           pointsize;
    WPI_POINT           pt2;
#ifndef __OS2_PM__
    CREATESTRUCT        *cs;
    MDICREATESTRUCT     *mdi_cs;
    MINMAXINFO          *minmax;
#endif
    img_node            *node;
    int                 i;

    switch ( msg ) {
    case WM_CREATE:
#ifndef __OS2_PM__
        cs = (CREATESTRUCT __FAR *)lparam;
        mdi_cs = (MDICREATESTRUCT __FAR *)cs->lpCreateParams;
        node = (img_node *)mdi_cs->lParam;

        for( i = 0; i < node->num_of_images; i++ ) {
            node[i].hwnd = hwnd;
        }
        AddImageNode( node );
        CreateUndoStack( node );
        setTheCursor( -1, hwnd );
        wasicon = FALSE;
#endif
        firsttime = TRUE;
        i = i;
        return( 0 );

    case WM_MDIACTIVATE:
        if( IMGED_GET_MDI_FACTIVATE( hwnd, wparam, lparam ) ) {
            if( _wpi_isiconic( hwnd ) ) {
                wasicon = TRUE;
                break;
            } else {
                wasicon = FALSE;
                FocusOnImage( hwnd );
            }
        }
        return( 0 );

#ifndef __OS2_PM__
    case WM_GETMINMAXINFO:
        node = SelectImage( hwnd );
        if( node != NULL ) {
            minmax = (MINMAXINFO *)lparam;
            minmax->ptMinTrackSize.x = node->width +
                2 * _wpi_getsystemmetrics( SM_CXFRAME );
            minmax->ptMinTrackSize.y = node->height +
                2 * _wpi_getsystemmetrics( SM_CYFRAME ) +
                _wpi_getsystemmetrics( SM_CYCAPTION ) - 1;
        }
        break;
#endif

    case UM_SHOWVIEWWINDOW:
        ShowViewWindows( hwnd );
        return 0;

    case WM_SIZE:
        if ( _imgwpi_issizerestored( wparam ) ) {
            ResizeChild( lparam, hwnd, firsttime );
            firsttime = FALSE;
            if( wasicon ) {
                FocusOnImage( hwnd );
                wasicon = FALSE;
            }
#ifndef __OS2_PM__
        } else if ( _imgwpi_issizeminimized( wparam ) ) {
            node = SelectImage( hwnd );
            HideViewWindow( hwnd );
            DeleteActiveImage();
            ClearImageText();
            SendMessage( ClientWindow, WM_MDINEXT, (WPARAM)(LPVOID)hwnd, 0L );
            wasicon = TRUE;
#endif
        }
        return( 0 );

#ifndef __OS2_PM__
    case WM_CHAR:
        pointsize = GetPointSize( hwnd );
        if( LOWORD( wparam ) == ESC_CHAR ) {
            if( !(lparam & 0x40000000) ) {
                switch( toolType ) {
                case IMGED_PASTE:
                    fdraw_shape = FALSE;
                    flbuttondown = FALSE;
                    frbuttondown = FALSE;
                    DontPaste( hwnd, &pt1, pointsize );
                    break;

                case IMGED_LINE:
                case IMGED_RECTO:
                case IMGED_RECTF:
                case IMGED_CIRCLEO:
                case IMGED_CIRCLEF:
                case IMGED_CLIP:
                    if( !flbuttondown && !frbuttondown ) {
                        break;
                    }
                    fdraw_shape = FALSE;
                    flbuttondown = FALSE;
                    frbuttondown = FALSE;
                    if( toolType == IMGED_LINE ) {
                        OutlineLine( hwnd, &start_pt, &prev_pt, &new_pt, TRUE );
                    } else if( toolType == IMGED_CLIP ) {
                        OutlineClip( hwnd, &start_pt, &prev_pt, &new_pt, TRUE );
                        SetRectExists( FALSE );
                    } else {
                        OutlineRegion( hwnd, &start_pt, &prev_pt, &new_pt, TRUE );
                    }
                    break;
                default:
                    break;
                }
            }
        }
        return( 0 );
#endif

    case WM_MOUSEMOVE:
        pointsize = GetPointSize( hwnd );
#ifdef __OS2_PM__
        WinSetPointer( HWND_DESKTOP, hCursor[cursorIndex] );
#endif
        IMGED_MAKEPOINT( wparam, lparam, new_pt );

        switch( toolType ) {
        case IMGED_SNAP:
#ifndef __OS2_PM__
            OutlineSnap();
#endif
            break;

        case IMGED_PASTE:
            pt1.x = new_pt.x / pointsize.x;
            pt1.y = new_pt.y / pointsize.y;
            pt2.x = prev_pt.x / pointsize.x;
            pt2.y = prev_pt.y / pointsize.y;
            if( pt1.x != pt2.x || pt1.y != pt2.y ) {
                DragClipBitmap( hwnd, &pt1, pointsize );
            }
            SetPosInStatus( &new_pt, &pointsize, hwnd );
            break;

        case IMGED_FREEHAND:
        case IMGED_BRUSH:
            if( flbuttondown ) {
                Paint( hwnd, &prev_pt, &new_pt, LMOUSEBUTTON );
            } else if( frbuttondown ) {
                Paint( hwnd, &prev_pt, &new_pt, RMOUSEBUTTON );
            }
            SetPosInStatus( &new_pt, &pointsize, hwnd );
            break;

        case IMGED_LINE:
        case IMGED_RECTO:
        case IMGED_RECTF:
        case IMGED_CIRCLEO:
        case IMGED_CIRCLEF:
        case IMGED_CLIP:
            if( flbuttondown || frbuttondown ) {
                if( new_pt.x / pointsize.x != end_pt.x / pointsize.x ||
                    new_pt.y / pointsize.y != end_pt.y / pointsize.y ) {
                    if( toolType == IMGED_LINE ) {
                        OutlineLine( hwnd, &start_pt, &new_pt, &prev_pt, FALSE );
                    } else if( toolType == IMGED_CLIP ) {
                        OutlineClip( hwnd, &start_pt, &new_pt, &prev_pt, FALSE );
                    } else {
                        OutlineRegion( hwnd, &start_pt, &new_pt, &prev_pt, FALSE );
                    }
                    end_pt = new_pt;
                    SetSizeInStatus( hwnd, &start_pt, &new_pt, &pointsize );
                }
            } else {
                SetPosInStatus( &new_pt, &pointsize, hwnd );
            }
            break;

        case IMGED_FILL:
            SetPosInStatus( &new_pt, &pointsize, hwnd );
            break;

        default:
            SetPosInStatus( &new_pt, &pointsize, hwnd );
            break;
        }
        prev_pt = new_pt;
        return( 0 );

    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN:
        pointsize = GetPointSize( hwnd );
        SetCapture( hwnd );
        if( msg == WM_LBUTTONDOWN ) {
            if( frbuttondown ) {
                break;
            }
#ifdef __OS2_PM__
            node = GetCurrentNode();
            if( hwnd != node->hwnd ) {
                break;
            }
#endif
            flbuttondown = TRUE;
            mousebutton = LMOUSEBUTTON;
        } else {
            if( flbuttondown ) {
                break;
            }
            node = GetCurrentNode();
            if( hwnd != node->hwnd ) {
                break;
            }
            frbuttondown = TRUE;
            mousebutton = RMOUSEBUTTON;
        }
        fdraw_shape = TRUE;
        IMGED_MAKEPOINT( wparam, lparam, start_pt );
        IMGED_MAKEPOINT( wparam, lparam, new_pt );

        switch( toolType ) {
        case IMGED_SNAP:
#ifndef __OS2_PM__
            TransferImage( hwnd );
#endif
            fdraw_shape = FALSE;
            flbuttondown = FALSE;
            frbuttondown = FALSE;
            break;

        case IMGED_FREEHAND:
        case IMGED_BRUSH:
            BeginFreeHand( hwnd );
            DrawSinglePoint( hwnd, &start_pt, mousebutton );
            break;

        case IMGED_LINE:
            IMGED_MAKEPOINT( wparam, lparam, end_pt );
            OutlineLine( hwnd, &start_pt, &new_pt, &prev_pt, TRUE );
            break;

        case IMGED_RECTO:
        case IMGED_RECTF:
        case IMGED_CIRCLEO:
        case IMGED_CIRCLEF:
            IMGED_MAKEPOINT( wparam, lparam, end_pt );
            OutlineRegion( hwnd, &start_pt, &new_pt, &prev_pt, TRUE );
            break;

        case IMGED_CLIP:
            IMGED_MAKEPOINT( wparam, lparam, end_pt );
            RedrawPrevClip( hwnd );
            OutlineClip( hwnd, &start_pt, &new_pt, &prev_pt, TRUE );
            break;

        case IMGED_FILL:
            FillArea( &start_pt, mousebutton );
            RecordImage( hwnd );
            break;

        case IMGED_HOTSPOT:
            SetIsSaved( hwnd, FALSE );
            prev_pt.x = start_pt.x / pointsize.x;
            prev_pt.y = start_pt.y / pointsize.y;
            SetNewHotSpot( &prev_pt );
            break;

        default:
            break;
        }
        prev_pt = new_pt;
        return 0;

    case WM_LBUTTONUP:
    case WM_RBUTTONUP:
        pointsize = GetPointSize( hwnd );
        IMGED_MAKEPOINT( wparam, lparam, end_pt );
        IMGED_MAKEPOINT( wparam, lparam, new_pt );
        if( msg == WM_LBUTTONUP ) {
            mousebutton = LMOUSEBUTTON;
        } else {
            mousebutton = RMOUSEBUTTON;
        }

        if( fdraw_shape ) {
            switch( toolType ) {
            case IMGED_PASTE:
                PasteImage( &start_pt, pointsize, hwnd );
                flbuttondown = FALSE;
                frbuttondown = FALSE;
                break;

            case IMGED_FREEHAND:
            case IMGED_BRUSH:
                if( flbuttondown || frbuttondown ) {
                    EndFreeHand( hwnd );
                    RecordImage( hwnd );
                }
                break;

            case IMGED_LINE:
                DrawLine( hwnd, &start_pt, &end_pt, mousebutton );
                RecordImage( hwnd );
                break;

            case IMGED_RECTO:
            case IMGED_RECTF:
            case IMGED_CIRCLEO:
            case IMGED_CIRCLEF:
                DisplayRegion( hwnd, &start_pt, &end_pt, mousebutton );
                RecordImage( hwnd );
                break;

            case IMGED_CLIP:
                SetClipRect( hwnd, &start_pt, &end_pt, pointsize );
                break;

            default:
                break;
            }
            fdraw_shape = FALSE;
        }
        ReleaseCapture();
        flbuttondown = FALSE;
        frbuttondown = FALSE;
        prev_pt = new_pt;
        return( 0 );

    case WM_PAINT:
        RepaintDrawArea( hwnd );
        return( 0 );

    case WM_QUERYENDSESSION:
    case WM_CLOSE:
        if( lastChanceSave( hwnd ) ) {
            CloseCurrentImage( hwnd );
            return( (MRESULT)1 );
        } else {
            return( (MRESULT)0 );
        }

#ifndef __OS2_PM__
    case WM_DESTROY:
        SetCursor( LoadCursor( NULL, IDC_ARROW ) );
        return( 0 );
#endif

    default:
        break;
    }
    return( _imgwpi_defMDIchildproc( hwnd, msg, wparam, lparam ) );

} /* DrawAreaWinProc */