home *** CD-ROM | disk | FTP | other *** search
- // drawView.cpp : implementation of the CDrawView class
- //
-
- #include "stdafx.h"
- #include "draw.h"
-
- #include "drawDoc.h"
- #include "drawView.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- extern CDrawApp theApp;
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView
-
- IMPLEMENT_DYNCREATE(CDrawView, CFormView)
-
- BEGIN_MESSAGE_MAP(CDrawView, CFormView)
- //{{AFX_MSG_MAP(CDrawView)
- ON_WM_SIZE()
- ON_MESSAGE(WM_DOREALIZE, OnDoRealize)
- ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
- ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView construction/destruction
-
- CDrawView::CDrawView()
- : CFormView(CDrawView::IDD)
- {
- //{{AFX_DATA_INIT(CDrawView)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // TODO: add construction code here
-
- }
-
- CDrawView::~CDrawView()
- {
- }
-
- void CDrawView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDrawView)
- DDX_Control(pDX, IDC_LEADCTRL1, m_Lead);
- //}}AFX_DATA_MAP
- }
-
- BOOL CDrawView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CFormView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView diagnostics
-
- #ifdef _DEBUG
- void CDrawView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CDrawView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
-
- CDrawDoc* CDrawView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawDoc)));
- return (CDrawDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView message handlers
- LRESULT CDrawView::OnDoRealize(WPARAM wParam, LPARAM lParam)
- {
- if( !IsWindow(m_Lead.m_hWnd) )
- return FALSE;
- if(lParam)
- {
- return m_Lead.SendMessage(WM_PALETTECHANGED, wParam);
- }
- else
- {
- UINT nColorsChanged = 0;
- CDC* pdc;
-
- pdc = theApp.m_pMainWnd->GetDC();
- HPALETTE hpal = (HPALETTE)m_Lead.GetPalette((OLE_HANDLE) pdc->m_hDC);
- if(hpal)
- {
- CPalette pal;
-
- pal.Attach(hpal);
- CPalette* oldPalette = pdc->SelectPalette(&pal, (BOOL) lParam);
- nColorsChanged = pdc->RealizePalette();
- if (nColorsChanged > 0)
- {
- m_Lead.InvalidateRect(NULL, FALSE);
- }
- pdc->SelectPalette(oldPalette, TRUE);
- }
- theApp.m_pMainWnd->ReleaseDC(pdc);
- return ((LRESULT) (BOOL) (nColorsChanged > 0));
- }
- }
-
- void CDrawView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
- {
- CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
- if (bActivate)
- {
- ASSERT(pActivateView == this);
- OnDoRealize((WPARAM)theApp.m_pMainWnd->m_hWnd, (LPARAM) FALSE); // same as SendMessage(WM_DOREALIZE);
- }
- }
-
- void CDrawView::OnSize(UINT nType, int cx, int cy)
- {
- CFormView::OnSize(nType, cx, cy);
-
- if( IsWindow(m_Lead.m_hWnd) )
- m_Lead.MoveWindow(CRect( 0, 0, cx, cy));
- }
-
- CLead* CDrawView::GetDocLead()
- {
- CDrawDoc* pDoc = GetDocument();
- return(&pDoc->m_Lead);
- }
-
- void CDrawView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- // Note that this program has one instance of the Lead control for each
- // view, plus the one instance for the document, which is used as the master copy.
- // The UpdateAllViews function calls this function once for each view; and
- // this function uses the master copy to update each view.
-
- ASSERT(pSender != this);
- UNUSED(pSender); // unused in release builds
-
- CDrawDoc* pDoc = GetDocument();
-
- // Save the current rectangles used for zooming and scrolling.
- float xLeft = m_Lead.GetDstLeft(), yTop = m_Lead.GetDstTop(),
- xWidth = m_Lead.GetDstWidth(), yHeight = m_Lead.GetDstHeight();
- float xsLeft = m_Lead.GetSrcLeft(), ysTop = m_Lead.GetSrcTop(),
- xsWidth = m_Lead.GetSrcWidth(), ysHeight = m_Lead.GetSrcHeight();
-
- // Avoid repainting until we are ready.
- m_Lead.SetAutoRepaint(FALSE);
-
- // Update the this view's bitmap with the document bitmap.
- m_Lead.SetBackErase(TRUE);
- m_Lead.SetBitmap(GetDocLead()->GetBitmap());
- m_Lead.SetPaintPalette(PAINTPALETTE_AUTO);
- m_Lead.SetPaintDither(PAINTDITHER_DIFFUSION);
- m_Lead.SetBitonalScaling(BITONALSCALING_NORMAL);
-
-
- if (lHint == 2) // All views, except the sender, are updated after a drawing change.
- {
- // Restore the saved rectangles.
- m_Lead.SetDstRect(xLeft, yTop, xWidth, yHeight);
- m_Lead.SetDstClipRect(xLeft, yTop, xWidth, yHeight);
- m_Lead.SetSrcRect(xsLeft, ysTop, xsWidth, ysHeight);
- m_Lead.SetSrcClipRect(xsLeft, ysTop, xsWidth, ysHeight);
- }
- else if (lHint == 1) // Zooming is disabled, and the view is returned to normal.
- {
- // Set the default display rectangles.
- float xExt = m_Lead.GetBitmapWidth(),
- yExt = m_Lead.GetBitmapHeight();
- m_Lead.SetDstRect(0.0f, 0.0f, xExt, yExt);
- m_Lead.SetDstClipRect(0.0f, 0.0f, xExt, yExt);
- m_Lead.SetSrcRect(0.0f, 0.0f, xExt, yExt);
- m_Lead.SetSrcClipRect(0.0f, 0.0f, xExt, yExt);
-
- // Fit the LEAD control to the client area and enable autoscrolling.
- CRect rcClient;
- GetClientRect(rcClient);
- m_Lead.MoveWindow(0, 0, rcClient.right, rcClient.bottom, FALSE);
- m_Lead.SetAutoScroll(TRUE);
-
- // Update the window title because we have stopped drawing.
- pDoc->SetTitle(pDoc->GetTitle());
- }
-
-
- // invalidate the entire pane, erase background too
- Invalidate(TRUE);
- m_Lead.SetAutoRepaint(TRUE);
- }
-
- void CDrawView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- // Set the default display rectangles.
- float xExt = m_Lead.GetBitmapWidth(),
- yExt = m_Lead.GetBitmapHeight();
- m_Lead.SetDstRect(0.0f, 0.0f, xExt, yExt);
- m_Lead.SetDstClipRect(0.0f, 0.0f, xExt, yExt);
- m_Lead.SetSrcRect(0.0f, 0.0f, xExt, yExt);
- m_Lead.SetSrcClipRect(0.0f, 0.0f, xExt, yExt);
-
- // Disable the scroll bars in the parent window
- SetScrollSizes(MM_TEXT,CSize(1,1));
-
- // Fit the LEAD control to the client area and enable autoscrolling.
- CRect rcClient;
- GetClientRect(rcClient);
- m_Lead.MoveWindow(0, 0, rcClient.right, rcClient.bottom, FALSE);
- m_Lead.SetAutoScroll(TRUE);
-
- }
-
- BEGIN_EVENTSINK_MAP(CDrawView, CFormView)
- //{{AFX_EVENTSINK_MAP(CDrawView)
- ON_EVENT(CDrawView, IDC_LEADCTRL1, -605 /* MouseDown */, OnMouseDownLeadctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- ON_EVENT(CDrawView, IDC_LEADCTRL1, -606 /* MouseMove */, OnMouseMoveLeadctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- ON_EVENT(CDrawView, IDC_LEADCTRL1, -607 /* MouseUp */, OnMouseUpLeadctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CDrawView::OnMouseDownLeadctrl1(short Button, short Shift, long X, long Y)
- {
- CDrawDoc *pDoc = GetDocument();
- CLead *pLead = &pDoc->m_Lead;
-
- if( Button != 1 )
- return;
-
- if( pDoc->nDraw != ID_DRAW_DISABLE )
- {
- // Initialize the zoom factors
- if (m_Lead.GetBitmap() != 0)
- {
- ZoomFactorX = m_Lead.GetDstWidth() / m_Lead.GetSrcWidth();
- ZoomFactorY = m_Lead.GetDstHeight() / m_Lead.GetSrcHeight();
- }
- // Determine the mouse coordinates on the screen
- StartX = (int)X;
- StartY = (int)Y;
-
- // Determine the mouse coordinates on the bitmap
- BStartX = (int)((StartX / ZoomFactorX) - (m_Lead.GetDstLeft() / ZoomFactorX) + m_Lead.GetSrcLeft());
- BStartY = (int)((StartY / ZoomFactorY) - (m_Lead.GetDstTop() / ZoomFactorY) + m_Lead.GetSrcTop());
-
- // Set the conditions that the OnMouseMove and OnMouseUp functions check.
- bFirstDraw = TRUE;
- bDrawing = TRUE;
-
- // Take control of when the image paints.
- m_Lead.SetAutoRepaint(FALSE);
- }
-
-
- // The rest of this is function is only for pasting
- if( pDoc->nDraw == ID_DRAW_PASTE )
- {
- // Set the mouse to an hourglass while pasting
- HCURSOR hOldCursor = ::SetCursor(::LoadCursor(NULL,MAKEINTRESOURCE(IDC_WAIT)));
-
- // Get the image from the clipboard
- PasteClipboard(BStartX, BStartY);
-
- ::SetCursor(hOldCursor);
- }
-
- }
-
- void CDrawView::OnMouseMoveLeadctrl1(short Button, short Shift, long X, long Y)
- {
- CDrawDoc *pDoc = GetDocument();
- CLead *pLead = &pDoc->m_Lead;
-
- if( pDoc->nDraw == ID_DRAW_OBJECT )
- {
- m_Lead.SetMousePointer(2);
-
- char szCaption[50];
- wsprintf(szCaption, "Mouse X = %d, Mouse Y = %d", X, Y);
- char text[500];
- GetWindowText(text,sizeof(text));
- GetParent()->SetWindowText(szCaption);
-
- if( Button == 1 )
- {
- HDC LeadDC = (HDC)m_Lead.GetClientDC();
-
- HPEN hOldPen = (HPEN)::SelectObject(LeadDC, GetStockObject(WHITE_PEN));
- HBRUSH hOldBrush = (HBRUSH)::SelectObject(LeadDC, GetStockObject(HOLLOW_BRUSH));
-
- int DisplayMode = ::SetROP2(LeadDC, R2_NOT);
-
- switch(pDoc->nObject)
- {
- case ID_OBJECT_ELLIPSE:
- if( !bFirstDraw )
- ::Ellipse(LeadDC, StartX, StartY, EndX, EndY);
-
- EndX = (int)X;
- EndY = (int)Y;
- ::Ellipse(LeadDC, StartX, StartY, EndX, EndY);
- break;
- case ID_OBJECT_LINE:
- if( !bFirstDraw )
- {
- MoveToEx( LeadDC, StartX, StartY, NULL );
- LineTo(LeadDC, EndX, EndY);
- }
- EndX = (int)X;
- EndY = (int)Y;
- MoveToEx( LeadDC, StartX, StartY, NULL );
- LineTo(LeadDC, EndX, EndY);
- break;
- case ID_OBJECT_RECTANGLE:
- if( !bFirstDraw )
- Rectangle(LeadDC, StartX, StartY, EndX, EndY);
- EndX = (int)X;
- EndY = (int)Y;
- Rectangle(LeadDC, StartX, StartY, EndX, EndY);
- break;
- }
- bFirstDraw = FALSE;
- SetROP2(LeadDC, DisplayMode);
- m_Lead.ReleaseClientDC();
- }
- }
- else if(pDoc->nDraw == ID_DRAW_COPY || pDoc->nDraw == ID_DRAW_ZOOMIN)
- {
- m_Lead.SetMousePointer(2);
-
- char szCaption[50];
- wsprintf(szCaption, "Mouse X = %d, Mouse Y = %d", X, Y);
- GetParent()->SetWindowText(szCaption);
-
- if( Button == 1 )
- {
- int rbX, rbY;
- if( X >= StartX )
- rbX = StartX;
- else
- rbX = (int)X;
-
- if( Y >= StartY )
- rbY = StartY;
- else
- rbY = (int)Y;
-
- int rbWidth = abs(StartX - (int)X);
- int rbHeight = abs(StartY - (int)Y);
- int OldScale = m_Lead.GetScaleMode();
- m_Lead.SetScaleMode(3);
- m_Lead.SetRubberBandRect((float)rbX, (float)rbY, (float)rbWidth, (float)rbHeight);
- m_Lead.SetRubberBandVisible(TRUE);
- m_Lead.SetScaleMode (OldScale);
- }
- }
- else if( pDoc->nDraw == ID_DRAW_PASTE)
- {
- char szCaption[50];
- wsprintf(szCaption, "Mouse X = %d, Mouse Y = %d", X, Y);
- GetParent()->SetWindowText(szCaption);
- m_Lead.SetMousePointer(10);
- }
- else
- m_Lead.SetMousePointer(0);
- }
-
- void CDrawView::OnMouseUpLeadctrl1(short Button, short Shift, long X, long Y)
- {
- long ColorRGB;
- CDrawDoc *pDoc = GetDocument();
- CLead *pLead = &pDoc->m_Lead;
-
- HPEN hPen;
- HPEN hOldBitmapPen;
- HBRUSH hOldBitmapBrush;
-
- if( bDrawing )
- {
- EndX = (int)X;
- EndY = (int)Y;
-
- BEndX = (int)((EndX / ZoomFactorX) - (m_Lead.GetDstLeft() / ZoomFactorX) + m_Lead.GetSrcLeft());
- BEndY = (int)((EndY / ZoomFactorY) - (m_Lead.GetDstTop() / ZoomFactorY) + m_Lead.GetSrcTop());
-
- m_Lead.SetAutoRepaint(TRUE);
- if( pDoc->nDraw == ID_DRAW_OBJECT )
- {
- switch(pDoc->nColor)
- {
- case ID_COLOR_BLACK:
- ColorRGB = RGB(0, 0, 0);
- break;
- case ID_COLOR_BLUE:
- ColorRGB = RGB(0, 0, 255);
- break;
- case ID_COLOR_GREEN:
- ColorRGB = RGB(0, 255, 0);
- break;
- case ID_COLOR_RED:
- ColorRGB = RGB(255, 0, 0);
- break;
- case ID_COLOR_WHITE:
- ColorRGB = RGB(255, 255, 255);
- break;
- }
-
- // the ClientDC uses client window coordinates,
- // but the BitmapDC uses Bitmap coordinates !!
- HDC LeadBitmapDC = (HDC)m_Lead.GetBitmapDC();
-
- hPen = ::CreatePen(PS_SOLID, pDoc->nThickness, ColorRGB);
-
- hOldBitmapPen = (HPEN)::SelectObject(LeadBitmapDC, hPen);
- hOldBitmapBrush = (HBRUSH)::SelectObject(LeadBitmapDC, GetStockObject(HOLLOW_BRUSH));
-
- switch( pDoc->nObject )
- {
- case ID_OBJECT_ELLIPSE:
- Ellipse(LeadBitmapDC, BStartX, BStartY, BEndX, BEndY);
- break;
- case ID_OBJECT_LINE:
- MoveToEx(LeadBitmapDC, BStartX, BStartY, NULL);
- LineTo(LeadBitmapDC, BEndX, BEndY);
- break;
- case ID_OBJECT_RECTANGLE:
- Rectangle(LeadBitmapDC, BStartX, BStartY, BEndX, BEndY);
- break;
- }
-
- ::SelectObject(LeadBitmapDC, hOldBitmapPen);
- ::SelectObject(LeadBitmapDC, hOldBitmapBrush);
-
- bDrawing = FALSE;
- m_Lead.ReleaseBitmapDC();
- DeleteObject(hPen);
- m_Lead.SetBackErase(FALSE);
- pLead->SetBitmap(m_Lead.GetBitmap());
-
- pDoc->UpdateAllViews(this, (LPARAM)2, NULL);
- }
- else if( pDoc->nDraw == ID_DRAW_COPY )
- {
- CLead *pFrameLead = theApp.GetMainLead();
- m_Lead.SetMousePointer(11);
-
- //Get rid of the rectangle
- m_Lead.SetRubberBandVisible(FALSE);
-
-
- //Get the width and height of the selected area
- float ImageWidth = (float)abs(BEndX - BStartX);
- float ImageHeight = (float)abs(BEndY - BStartY);
-
- // Create the second bitmap
- pFrameLead->CreateBitmap(ImageWidth, ImageHeight, m_Lead.GetBitmapBits());
- if (m_Lead.GetBitmapBits() < 16)
- {
- int NoColors = 1 << m_Lead.GetBitmapBits();
- for( int i = 0; i < NoColors; i++ )
- {
- pFrameLead->SetBitmapPalette(i, m_Lead.GetBitmapPalette(i));
- }
- }
- pFrameLead->Fill(RGB(0, 0, 0));
-
- float xSrc, ySrc;
- // Find the top left corner of the selected rectangle.
- if (BStartX < BEndX)
- xSrc = (float)BStartX;
- else
- xSrc = (float)BEndX;
- if (BStartY < BEndY)
- ySrc = (float)BStartY;
- else
- ySrc = (float)BEndY;
-
- // Use the Combine method to copy the selected rectangle to the second bitmap.
- pFrameLead->Combine(0.0f, 0.0f, ImageWidth, ImageHeight, m_Lead.GetBitmap(), xSrc, ySrc, CB_OP_ADD | CB_DST_0);
-
-
- // Copy the second bitmap to the clipboard
- pFrameLead->Copy(COPY_DIB);
- // Change next option to paste
- pDoc->nDraw = ID_DRAW_PASTE;
-
- m_Lead.SetMousePointer(0);
- }
- else if( pDoc->nDraw == ID_DRAW_ZOOMIN )
- {
-
- float CropLeft, CropTop;
- // Find the top left corner of the selected rectangle.
- if (BStartX < BEndX)
- CropLeft = (float)BStartX;
- else
- CropLeft = (float)BEndX;
- if (BStartY < BEndY)
- CropTop = (float)BStartY;
- else
- CropTop = (float)BEndY;
-
- // Get the width and height of the selected rectangle.
- float CropWidth = (float)abs(BEndX - BStartX);
- float CropHeight = (float)abs(BEndY - BStartY);
-
- // Quit if the selected area is too small.
- if (CropWidth < 1 || CropHeight < 1)
- {
- m_Lead.SetRubberBandVisible(FALSE); // Hides the rubberband
- m_Lead.SetBackErase(FALSE); // Forces a repaint
- bFirstDraw = FALSE;
- return;
- }
-
- // Size and redisplay the control, using the new source rectangle.
- // Set the variables used for preserving the aspect ratio.
- float HeightFactor = CropHeight;
- float WidthFactor = CropWidth;
- CRect rcWindow;
- GetClientRect(rcWindow);
- float HeightAllowed = (float)rcWindow.Height();
- float WidthAllowed = (float)rcWindow.Width();
-
- // Place the lead control on the form, preserving the selected area's aspect ratio.
- // Check to see if using the maximum width will make the image too tall.
- // Set the dimensions based on the result.
- float Left, Width, Height, Top;
- if(((WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed)
- {
- Left = 0.0f;
- Width = WidthAllowed;
- Height = (Width * HeightFactor) / WidthFactor;
- Top = (HeightAllowed - Height) / 2;
- }
- else
- {
- Top = 0.0f;
- Height = HeightAllowed;
- Width = (Height * WidthFactor) / HeightFactor;
- Left = (WidthAllowed - Width) / 2;
- }
- rcWindow.SetRect(0, 0, (int) Width, (int) Height);
- rcWindow.OffsetRect((int) Left, (int) Top);
-
- // Hide the Lead control while we adjust the display.
- m_Lead.ShowWindow(SW_HIDE);
- m_Lead.MoveWindow(rcWindow);
-
- // Zoom in on the source rectangle
- m_Lead.SetSrcRect(CropLeft, CropTop, CropWidth, CropHeight);
- m_Lead.SetSrcClipRect(CropLeft, CropTop, CropWidth, CropHeight);
-
- // Set the image display size to match the Lead control.
- m_Lead.SetDstRect(0.0f, 0.0f, m_Lead.GetScaleWidth(), m_Lead.GetScaleHeight());
- m_Lead.SetDstClipRect(0.0f, 0.0f, m_Lead.GetScaleWidth(), m_Lead.GetScaleHeight());
-
- // Show the adjusted display.
- m_Lead.ShowWindow(SW_SHOW);
-
- m_Lead.SetRubberBandVisible(FALSE); // Hides the rubberband
- m_Lead.SetMousePointer(0);
-
- // Display the Lead control
- m_Lead.ForceRepaint();
- }
- }
- }
-
- void CDrawView::OnEditPaste()
- {
- PasteClipboard(0, 0);
- }
-
- BOOL CDrawView::PasteClipboard( long BStartX, long BStartY )
- {
- CDrawDoc *pDoc = GetDocument();
- CLead *pLead = &pDoc->m_Lead;
- CLead *pFrameLead = theApp.GetMainLead();
- if( !ClipboardHasBitmap() )
- {
- MessageBox("No image data on the clipboard", "ERROR");
- return FALSE;
- }
-
- if( pFrameLead->Paste( COPY_DIB ) || !pFrameLead->GetBitmapBits() )
- // an error occured during pasting
- return FALSE;
-
- // If the LEAD control has a palette, see if the new data has the same palette.
- // Initialize the flag
- BOOL fMustDoColorRes = FALSE;
- if ( m_Lead.GetBitmapBits() < 16 )
- {
- if( pFrameLead->GetBitmapBits() > 8)
- {
- // The new data has no palette
- fMustDoColorRes = TRUE;
- }
- else
- {
- // Check to see if the palettes match
- int NoColors = 1 << m_Lead.GetBitmapBits();
- for( int i = 0; i < NoColors; i++ )
- {
- if( m_Lead.GetBitmapPalette(i) != pFrameLead->GetBitmapPalette(i) )
- {
- fMustDoColorRes = TRUE;
- break;
- }
- }
- }
- // If it is not the same palette, let the user decide whether to continue.
- if (fMustDoColorRes == TRUE)
- {
- if ( MessageBox("Palette mismatch. Convert to 24-bit", "Notice", MB_YESNO))
- {
- m_Lead.ColorRes(24, CRP_BYTEORDERBGR, 0, 0);
- pFrameLead->ColorRes(24, CRP_BYTEORDERBGR, 0, 0);
- }
- else
- {
- return FALSE;
- }
- }
- }
- else if(m_Lead.GetBitmapBits() != pFrameLead->GetBitmapBits())
- {
- // Convert the new data to the same bits per pixel as the LEAD control (16 or higher)
- pFrameLead->ColorRes(m_Lead.GetBitmapBits(), CRP_BYTEORDERBGR, 0, 0);
- }
-
- // Combine the new data with the current bitmap at the current position.
- long MyOp = CB_OP_ADD | CB_DST_0; // Operation flags for a simple paste
- m_Lead.Combine((float)BStartX, (float)BStartY, pFrameLead->GetSrcWidth(), pFrameLead->GetSrcHeight(),pFrameLead->GetBitmap(),0.0f,0.0f, MyOp);
-
- // Repaint the changed portion of the bitmap, unless the palette has changed.
- if (fMustDoColorRes == FALSE)
- {
- m_Lead.SetSrcClipRect((float)BStartX, (float)BStartY, pFrameLead->GetSrcWidth(), pFrameLead->GetSrcHeight());
- m_Lead.SetBackErase(FALSE);
- m_Lead.ForceRepaint;
- m_Lead.SetSrcClipRect(m_Lead.GetSrcLeft(), m_Lead.GetSrcTop(), m_Lead.GetSrcWidth(), m_Lead.GetSrcHeight());
- }
-
- // Copy this view's bitmap to the document's master copy.
- pLead->SetBitmap(m_Lead.GetBitmap());
-
- // Update other views of the bitmap; also update this one if the palette has changed.
- if (fMustDoColorRes == FALSE)
- pDoc->UpdateAllViews(this, (LPARAM)2, NULL); // Update views except this one
- else
- pDoc->UpdateAllViews(NULL, (LPARAM)2, NULL); // Update views, including this one
- return TRUE;
- }
-
- void CDrawView::OnUpdateEditPaste(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable( ClipboardHasBitmap() );
- }
-
- BOOL CDrawView::ClipboardHasBitmap()
- {
- BOOL retval = FALSE;
- if( OpenClipboard() )
- {
- retval = IsClipboardFormatAvailable(CF_DIB);
- CloseClipboard();
- }
- return retval;
- }
-
-
-