home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / leadtools / ocx32.lt / MFCDEVW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-03  |  55.1 KB  |  1,833 lines

  1. // mfcdevw.cpp : implementation of the CMfcdemoView class
  2. // Copyright (C) 1996 LEAD Technologies, Inc.
  3. // All rights reserved.
  4.  
  5. #include "stdafx.h"
  6.  
  7. #include "mfcdemo.h"
  8. #include "mfcdedoc.h"
  9. #include "mfcdevw.h"
  10. #include "mainfrm.h"
  11. #include "rangedlg.h"
  12. #include "listdlg.h"
  13. #include "dualrang.h"
  14. #include "resizedl.h"
  15. #include "floatdlg.h"
  16. #include "colorres.h"
  17. #include "underlay.h"
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. extern CMfcdemoApp theApp;
  25.  
  26. #define SZ_COMPASS _T("North|North-East|East|South-East|South|South-West|West|North-West|")
  27. #define SZ_SHIFTDIFF _T("Diagonal|Horizontal|Vertical|")
  28. #define SZ_LINESEG _T("Horizontal|Vertical|Left to Right|Right to Left|")
  29. #define SZ_LAPLACE _T("Filter 1|Filter 2|Filter 3|Diagonal|Horizontal|Vertical|")
  30. #define SZ_HORZVERT _T("Horizontal|Vertical|");
  31. #define SZ_BINARY _T("Omnidirectional|Horizontal|Vertical|Diagonal|")
  32.  
  33. static int aGradientFlt[] = {
  34.    CLead::FLT_GRADIENT_N,
  35.    CLead::FLT_GRADIENT_NE,
  36.    CLead::FLT_GRADIENT_E,
  37.    CLead::FLT_GRADIENT_SE,
  38.    CLead::FLT_GRADIENT_S,
  39.    CLead::FLT_GRADIENT_SW,
  40.    CLead::FLT_GRADIENT_W,
  41.    CLead::FLT_GRADIENT_NW
  42. };
  43.  
  44. static int aLaplaceFlt[] = {
  45.    CLead::FLT_LAPLACE_1,
  46.    CLead::FLT_LAPLACE_2,
  47.    CLead::FLT_LAPLACE_3,
  48.    CLead::FLT_LAPLACE_DIAG,
  49.    CLead::FLT_LAPLACE_HORZ,
  50.    CLead::FLT_LAPLACE_VERT,
  51. };
  52.  
  53. static int aSobelFlt[] = {
  54.    CLead::FLT_SOBEL_HORZ,
  55.    CLead::FLT_SOBEL_VERT,
  56. };
  57.  
  58.  
  59. static int aPrewittFlt[] = {
  60.    CLead::FLT_PREWITT_HORZ,
  61.    CLead::FLT_PREWITT_VERT,
  62. };
  63.  
  64. static int aShiftDiffFlt[] = {
  65.    CLead::FLT_SHIFTDIFF_DIAG,
  66.    CLead::FLT_SHIFTDIFF_HORZ,
  67.    CLead::FLT_SHIFTDIFF_VERT,
  68. };
  69.  
  70. static int aLineSegFlt[] = {
  71.    CLead::FLT_LINESEG_HORZ,
  72.    CLead::FLT_LINESEG_VERT,
  73.    CLead::FLT_LINESEG_LTOR,
  74.    CLead::FLT_LINESEG_RTOL,
  75. };
  76.  
  77. static int aErosionFlt[] = {
  78.    CLead::BFLT_EROSION_OMNI,
  79.    CLead::BFLT_EROSION_HORZ,
  80.    CLead::BFLT_EROSION_VERT,
  81.    CLead::BFLT_EROSION_DIAG,
  82. };
  83.  
  84. static int aDilationFlt[] = {
  85.    CLead::BFLT_DILATION_OMNI,
  86.    CLead::BFLT_DILATION_HORZ,
  87.    CLead::BFLT_DILATION_VERT,
  88.    CLead::BFLT_DILATION_DIAG,
  89. };
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CMfcdemoView
  93.  
  94. IMPLEMENT_DYNCREATE(CMfcdemoView, CView)
  95.  
  96. BEGIN_MESSAGE_MAP(CMfcdemoView, CView)
  97.    //{{AFX_MSG_MAP(CMfcdemoView)
  98.    ON_MESSAGE(WM_DOREALIZE, OnDoRealize)
  99.    ON_COMMAND(ID_IMAGE_FLIP, OnImageFlip)
  100.    ON_COMMAND(ID_IMAGE_REVERSE, OnImageReverse)
  101.    ON_COMMAND(ID_IMAGE_ROTATE_180CLOCKWISE, OnImageRotate180clockwise)
  102.    ON_COMMAND(ID_IMAGE_ROTATE_270CLOCKWISE, OnImageRotate270clockwise)
  103.    ON_COMMAND(ID_IMAGE_ROTATE_90CLOCKWISE, OnImageRotate90clockwise)
  104.    ON_COMMAND(ID_COLOR_GRAYSCALE, OnColorGrayscale)
  105.    ON_COMMAND(ID_COLOR_HISTOGRAMEQUALIZE, OnColorHistogramequalize)
  106.    ON_COMMAND(ID_COLOR_INVERT, OnColorInvert)
  107.    ON_COMMAND(ID_COLOR_STRETCHINTENSITY, OnColorStretchintensity)
  108.    ON_COMMAND(ID_IMAGE_EFFECTS_POSTERIZE, OnImageEffectsPosterize)
  109.    ON_COMMAND(ID_COLOR_BRIGHTNESS, OnColorBrightness)
  110.    ON_COMMAND(ID_COLOR_CONTRAST, OnColorContrast)
  111.    ON_COMMAND(ID_COLOR_HISTOCONTRAST, OnColorHistocontrast)
  112.    ON_COMMAND(ID_COLOR_HUE, OnColorHue)
  113.    ON_COMMAND(ID_COLOR_SATURATION, OnColorSaturation)
  114.    ON_COMMAND(ID_IMAGE_EFFECTS_ADDNOISE, OnImageEffectsAddnoise)
  115.    ON_COMMAND(ID_IMAGE_EFFECTS_AVERAGE, OnImageEffectsAverage)
  116.    ON_COMMAND(ID_IMAGE_EFFECTS_DESPECKLE, OnImageEffectsDespeckle)
  117.    ON_COMMAND(ID_IMAGE_EFFECTS_MEDIAN, OnImageEffectsMedian)
  118.    ON_COMMAND(ID_IMAGE_EFFECTS_MOSAIC, OnImageEffectsMosaic)
  119.    ON_COMMAND(ID_IMAGE_EFFECTS_SHARPEN, OnImageEffectsSharpen)
  120.    ON_COMMAND(ID_IMAGE_BINARYFILTERS_DILATION, OnImageBinaryfiltersDilation)
  121.    ON_COMMAND(ID_IMAGE_BINARYFILTERS_EROSION, OnImageBinaryfiltersErosion)
  122.    ON_COMMAND(ID_IMAGE_SPATIALFILTERS_GRADIENT, OnImageSpatialfiltersGradient)
  123.    ON_COMMAND(ID_IMAGE_SPATIALFILTERS_LAPLACIAN, OnImageSpatialfiltersLaplacian)
  124.    ON_COMMAND(ID_IMAGE_SPATIALFILTERS_LINESEGMENT, OnImageSpatialfiltersLinesegment)
  125.    ON_COMMAND(ID_IMAGE_SPATIALFILTERS_PREWITT, OnImageSpatialfiltersPrewitt)
  126.    ON_COMMAND(ID_IMAGE_SPATIALFILTERS_SHIFTANDDIFFERENCE, OnImageSpatialfiltersShiftanddifference)
  127.    ON_COMMAND(ID_IMAGE_SPATIALFILTERS_SOBEL, OnImageSpatialfiltersSobel)
  128.    ON_COMMAND(ID_COLOR_GAMMACORRECT, OnColorGammacorrect)
  129.    ON_COMMAND(ID_COLOR_INTENSITYDETECT, OnColorIntensitydetect)
  130.    ON_COMMAND(ID_IMAGE_RESIZE, OnImageResize)
  131.    ON_COMMAND(ID_IMAGE_ROTATE_ANYANGLE, OnImageRotateAnyangle)
  132.    ON_COMMAND(ID_IMAGE_SHEAR, OnImageShear)
  133.    ON_COMMAND(ID_COLOR_COLORRESOLUTION, OnColorColorresolution)
  134.    ON_COMMAND(ID_VIEW_ZOOM, OnViewZoom)
  135.    ON_COMMAND(ID_VIEW_NORMAL, OnViewNormal)
  136.    ON_COMMAND(ID_VIEW_PAINTEFFECTS, OnViewPainteffects)
  137.    ON_COMMAND(ID_VIEW_SNAPWINDOWTOIMAGE, OnViewSnapwindowtoimage)
  138.    ON_COMMAND(ID_VIEW_FITIMAGETOWINDOW, OnViewFitimagetowindow)
  139.    ON_WM_ERASEBKGND()
  140.    ON_COMMAND(ID_IMAGE_EFFECTS_EMBOSS, OnImageEffectsEmboss)
  141.    ON_COMMAND(ID_COLOR_HALFTONE, OnColorHalftone)
  142.    ON_COMMAND(ID_COLOR_FILL, OnColorFill)
  143.    ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
  144.    ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  145.    ON_COMMAND(ID_COLOR_SEPARATION, OnColorSeparation)
  146.    ON_COMMAND(ID_IMAGE_EFFECTS_EDGEENHANCE, OnImageEffectsEdgeenhance)
  147.    ON_UPDATE_COMMAND_UI(ID_IMAGE_EFFECTS_EDGEENHANCE, OnUpdateImageEffectsEdgeenhance)
  148.    ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
  149.    ON_COMMAND(ID_IMAGE_DESKEW, OnImageDeskew)
  150.    ON_COMMAND(ID_IMAGE_EFFECTS_UNDERLAY, OnImageEffectsUnderlay)
  151.    ON_UPDATE_COMMAND_UI(ID_IMAGE_DESKEW, OnUpdateImageDeskew)
  152.    ON_UPDATE_COMMAND_UI(ID_IMAGE_BINARYFILTERS_DILATION, OnUpdateImageBinaryfiltersDilation)
  153.    ON_UPDATE_COMMAND_UI(ID_IMAGE_BINARYFILTERS_EROSION, OnUpdateImageBinaryfiltersErosion)
  154.    ON_UPDATE_COMMAND_UI(ID_IMAGE_EFFECTS_DESPECKLE, OnUpdateImageEffectsDespeckle)
  155.    ON_COMMAND(IDM_TOOLNONE, OnToolnone)
  156.    ON_UPDATE_COMMAND_UI(IDM_TOOLNONE, OnUpdateToolnone)
  157.    ON_COMMAND(IDM_TOOLELLIPSE, OnToolellipse)
  158.    ON_UPDATE_COMMAND_UI(IDM_TOOLELLIPSE, OnUpdateToolellipse)
  159.    ON_COMMAND(IDM_TOOLFREEHAND, OnToolfreehand)
  160.    ON_UPDATE_COMMAND_UI(IDM_TOOLFREEHAND, OnUpdateToolfreehand)
  161.    ON_COMMAND(IDM_TOOLRECT, OnToolrect)
  162.    ON_UPDATE_COMMAND_UI(IDM_TOOLRECT, OnUpdateToolrect)
  163.    ON_COMMAND(IDM_TOOLRNDRECT, OnToolrndrect)
  164.    ON_UPDATE_COMMAND_UI(IDM_TOOLRNDRECT, OnUpdateToolrndrect)
  165.    ON_UPDATE_COMMAND_UI(ID_IMAGE_REGIONTRANSFORMATIONS_CANCEL, OnUpdateImageRegiontransformationsCancel)
  166.    ON_COMMAND(ID_IMAGE_REGIONTRANSFORMATIONS_CANCEL, OnImageRegiontransformationsCancel)
  167.    ON_UPDATE_COMMAND_UI(ID_IMAGE_SHEAR, OnUpdateImageShear)
  168.    ON_WM_SIZE()
  169.    ON_WM_CREATE()
  170.    //}}AFX_MSG_MAP
  171.    // Standard printing commands
  172.    ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  173.    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  174. END_MESSAGE_MAP()
  175.  
  176. /////////////////////////////////////////////////////////////////////////////
  177. // CMfcdemoView construction/destruction
  178.  
  179. CMfcdemoView::CMfcdemoView()
  180. {
  181.     m_pPalette = NULL;
  182.     m_nEffect = CLead::EFX_EFFECT_NONE;
  183.     m_nRegionTool = IDM_TOOLNONE;
  184.     m_nRegionType = 0;
  185.  
  186.     m_bMovingFloater = FALSE;
  187. }
  188.  
  189. CMfcdemoView::~CMfcdemoView()
  190. {
  191.    if(m_pPalette)
  192.       delete m_pPalette;
  193. }
  194.  
  195. /////////////////////////////////////////////////////////////////////////////
  196. // CMfcdemoView drawing
  197.  
  198. void CMfcdemoView::OnDraw(CDC* pDC)
  199. {
  200.         CRect rcClip;
  201.         CSize winext;
  202.         CSize viewext;
  203.         CSize paintext;
  204.  
  205.    CMfcdemoDoc* pDoc = GetDocument();
  206.    ASSERT_VALID(pDoc);
  207.  
  208.         if(pDC->IsPrinting())
  209.         {                
  210.                 pDC->SaveDC();
  211.                 ::GetWindowExtEx(pDC->m_hDC, &winext);
  212.                 ::GetViewportExtEx(pDC->m_hDC, &viewext);
  213.                 paintext.cx = MulDiv((int) m_Lead.GetBitmapWidth(), viewext.cx, winext.cx);
  214.                 paintext.cy = MulDiv((int) m_Lead.GetBitmapHeight(), viewext.cy, winext.cy);
  215.                 ::SetMapMode(pDC->m_hDC, MM_TEXT);                
  216.          m_Lead.Render((OLE_HANDLE) pDC->m_hDC, (float) 0, (float) 0, (float) paintext.cx, (float) paintext.cy);
  217.                 pDC->RestoreDC(-1);
  218.         }
  219. }
  220.  
  221. /////////////////////////////////////////////////////////////////////////////
  222. // CMfcdemoView printing
  223.  
  224. BOOL CMfcdemoView::OnPreparePrinting(CPrintInfo* pInfo)
  225. {
  226.    // default preparation
  227.    return DoPreparePrinting(pInfo);
  228. }
  229.  
  230. void CMfcdemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  231. {
  232.    // TODO: add extra initialization before printing
  233. }
  234.  
  235. void CMfcdemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  236. {
  237.    // TODO: add cleanup after printing
  238. }
  239.  
  240. /////////////////////////////////////////////////////////////////////////////
  241. // CMfcdemoView diagnostics
  242.  
  243. #ifdef _DEBUG
  244. void CMfcdemoView::AssertValid() const
  245. {
  246.    CView::AssertValid();
  247. }
  248.  
  249. void CMfcdemoView::Dump(CDumpContext& dc) const
  250. {
  251.    CView::Dump(dc);
  252. }
  253.  
  254. CMfcdemoDoc* CMfcdemoView::GetDocument() // non-debug version is inline
  255. {
  256.    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMfcdemoDoc)));
  257.    return (CMfcdemoDoc*)m_pDocument;
  258. }
  259. #endif //_DEBUG
  260.  
  261. /////////////////////////////////////////////////////////////////////////////
  262. // CMfcdemoView message handlers
  263.  
  264. void CMfcdemoView::BeginProcessing()
  265. {
  266.         BeginWaitCursor();
  267.         GetUndoLead()->SetBitmap(GetDocLead()->GetBitmap());
  268. }
  269.  
  270. void CMfcdemoView::EndProcessing(int nRet)
  271. {
  272.         EndWaitCursor();
  273.         theApp.DisplayLEADError(nRet);
  274. }
  275.  
  276. void CMfcdemoView::OnChanged()
  277. {
  278.    CMfcdemoDoc* pDoc = GetDocument();
  279.  
  280.    pDoc->SetModifiedFlag();
  281.    pDoc->UpdateAllViews(NULL, (LPARAM) 0);
  282. }
  283.  
  284. void CMfcdemoView::SetZoom(float nZoom) 
  285. {
  286.    CMfcdemoDoc* pDoc = GetDocument();
  287.    m_nZoom = nZoom;
  288.    OnUpdate(NULL, 0, NULL);
  289. }
  290.  
  291. CLead* CMfcdemoView::GetDocLead() 
  292. {
  293.         CMfcdemoDoc* pDoc = GetDocument();
  294.         return(&pDoc->m_Lead);
  295. }
  296.  
  297. CLead* CMfcdemoView::GetUndoLead() 
  298. {
  299.         CMfcdemoDoc* pDoc = GetDocument();
  300.         return(&pDoc->m_LeadUndo);
  301. }
  302.  
  303. void CMfcdemoView::OnInitialUpdate() 
  304. {
  305.    CMfcdemoDoc* pDoc = GetDocument();
  306.    SetZoom(100.0f);
  307.    CView::OnInitialUpdate();
  308. }
  309.  
  310. LRESULT CMfcdemoView::OnDoRealize(WPARAM wParam, LPARAM lParam)
  311. {
  312.    if(lParam)
  313.    {
  314.       return m_Lead.SendMessage(WM_PALETTECHANGED, wParam);
  315.    }
  316.    else
  317.    {
  318.       UINT nColorsChanged = 0;
  319.       CDC* pdc;
  320.  
  321.       pdc = theApp.m_pMainWnd->GetDC();
  322.       HPALETTE hpal = (HPALETTE)m_Lead.GetPalette((OLE_HANDLE) pdc->m_hDC);
  323.       if(hpal)
  324.       {
  325.          CPalette pal;
  326.  
  327.          pal.Attach(hpal);
  328.          CPalette* oldPalette = pdc->SelectPalette(&pal, (BOOL) lParam);
  329.          nColorsChanged = pdc->RealizePalette();
  330.          if (nColorsChanged > 0)
  331.             m_Lead.InvalidateRect(NULL, FALSE);
  332.          pdc->SelectPalette(oldPalette, TRUE);
  333.       }
  334.       theApp.m_pMainWnd->ReleaseDC(pdc);
  335.       return ((LRESULT) (BOOL) (nColorsChanged > 0));
  336.    }
  337. }
  338.  
  339. void CMfcdemoView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
  340. {
  341.    CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  342.    if (bActivate)
  343.    {
  344.       ASSERT(pActivateView == this);
  345.       OnDoRealize((WPARAM)theApp.m_pMainWnd->m_hWnd, (LPARAM) FALSE);   // same as SendMessage(WM_DOREALIZE);
  346.    }
  347. }
  348.  
  349. void CMfcdemoView::OnImageFlip()
  350. {
  351.     if(m_Lead.GetHasRgn())
  352.     {
  353.       OnImageRegiontransformationsFlip();
  354.     }
  355.     else
  356.     {
  357.       BeginProcessing();
  358.       int nRet = GetDocLead()->Flip();
  359.       OnChanged();
  360.       EndProcessing(nRet);
  361.     }
  362. }
  363.  
  364. void CMfcdemoView::OnImageReverse() 
  365. {
  366.     if(m_Lead.GetHasRgn())
  367.     {
  368.       OnImageRegiontransformationsReverse();
  369.     }
  370.     else
  371.     {
  372.       BeginProcessing();
  373.       int nRet = GetDocLead()->Reverse();
  374.       OnChanged();
  375.       EndProcessing(nRet);
  376.     }
  377. }
  378.  
  379. void CMfcdemoView::OnImageRotate180clockwise() 
  380. {
  381.     if(m_Lead.GetHasRgn())
  382.     {
  383.       OnImageRegiontransformationsRotate((long) 18000);
  384.     }
  385.     else
  386.     {
  387.       BeginProcessing();
  388.       int nRet = GetDocLead()->Rotate(18000, TRUE, RGB(0, 0, 0));
  389.       OnChanged();
  390.       EndProcessing(nRet);
  391.     }
  392. }
  393.  
  394. void CMfcdemoView::OnImageRotate270clockwise() 
  395. {
  396.     if(m_Lead.GetHasRgn())
  397.     {
  398.       OnImageRegiontransformationsRotate((long) 27000);
  399.     }
  400.     else
  401.     {
  402.       BeginProcessing();
  403.       int nRet = GetDocLead()->Rotate(27000, TRUE, RGB(0, 0, 0));
  404.       OnChanged();
  405.       EndProcessing(nRet);
  406.     }
  407. }
  408.  
  409. void CMfcdemoView::OnImageRotate90clockwise() 
  410. {
  411.     if(m_Lead.GetHasRgn())
  412.     {
  413.       OnImageRegiontransformationsRotate((long) 9000);
  414.     }
  415.     else
  416.     {
  417.       BeginProcessing();
  418.       int nRet = GetDocLead()->Rotate(9000, TRUE, RGB(0, 0, 0));
  419.       OnChanged();
  420.       EndProcessing(nRet);
  421.     }
  422. }
  423.  
  424.  
  425. void CMfcdemoView::OnColorGrayscale() 
  426. {
  427.         BeginProcessing();
  428.    int nRet = GetDocLead()->Grayscale(8);
  429.    OnChanged();
  430.         EndProcessing(nRet);
  431. }
  432.  
  433. void CMfcdemoView::OnColorHistogramequalize() 
  434. {
  435.         BeginProcessing();
  436.    int nRet = GetDocLead()->HistoEqualize();
  437.    OnChanged();
  438.         EndProcessing(nRet);
  439. }
  440.  
  441. void CMfcdemoView::OnColorInvert() 
  442. {
  443.         BeginProcessing();
  444.    int nRet = GetDocLead()->Invert();
  445.    OnChanged();
  446.         EndProcessing(nRet);
  447. }
  448.  
  449. void CMfcdemoView::OnColorStretchintensity() 
  450. {
  451.         BeginProcessing();
  452.    int nRet = GetDocLead()->StretchIntensity();
  453.    OnChanged();
  454.         EndProcessing(nRet);
  455. }
  456.  
  457. void CMfcdemoView::OnImageEffectsPosterize() 
  458. {
  459.         CRangeDlg dlg;
  460.  
  461.         dlg.m_strTitle = _T("Posterize");
  462.         dlg.m_strLabel = _T("&Levels");
  463.         dlg.m_nValue = 2;
  464.         dlg.m_nMin = 2;
  465.         dlg.m_nMax = 64;
  466.  
  467.         if(dlg.DoModal() == IDOK)
  468.         {
  469.                 BeginProcessing();
  470.          int nRet = GetDocLead()->Posterize(dlg.m_nValue);
  471.          OnChanged();
  472.                 EndProcessing(nRet);
  473.         }   
  474. }
  475.  
  476. void CMfcdemoView::OnColorBrightness() 
  477. {
  478.         CRangeDlg dlg;
  479.  
  480.         dlg.m_strTitle = _T("Brightness");
  481.         dlg.m_strLabel = _T("&Change");
  482.         dlg.m_nMin = -100;
  483.         dlg.m_nMax = 100;
  484.  
  485.         if(dlg.DoModal() == IDOK && dlg.m_nValue)
  486.         {
  487.                 BeginProcessing();
  488.          int nRet = GetDocLead()->Intensity(dlg.m_nValue * 10);
  489.          OnChanged();
  490.                 EndProcessing(nRet);
  491.         }   
  492. }
  493.  
  494. void CMfcdemoView::OnColorContrast() 
  495. {
  496.         CRangeDlg dlg;
  497.  
  498.         dlg.m_strTitle = _T("Contrast");
  499.         dlg.m_strLabel = _T("&Change");
  500.         dlg.m_nMin = -100;
  501.         dlg.m_nMax = 100;
  502.  
  503.         if(dlg.DoModal() == IDOK && dlg.m_nValue)
  504.         {
  505.                 BeginProcessing();
  506.          int nRet = GetDocLead()->Contrast(dlg.m_nValue * 10);
  507.          OnChanged();
  508.                 EndProcessing(nRet);
  509.         }   
  510.    
  511. }
  512.  
  513.  
  514. void CMfcdemoView::OnColorHistocontrast() 
  515. {
  516.         CRangeDlg dlg;
  517.  
  518.         dlg.m_strTitle = _T("Histo-Contrast");
  519.         dlg.m_strLabel = _T("&Change");
  520.         dlg.m_nMin = -100;
  521.         dlg.m_nMax = 100;
  522.  
  523.         if(dlg.DoModal() == IDOK && dlg.m_nValue)
  524.         {
  525.                 BeginProcessing();
  526.          int nRet = GetDocLead()->HistoContrast(dlg.m_nValue * 10);
  527.          OnChanged();
  528.                 EndProcessing(nRet);
  529.         }   
  530. }
  531.  
  532. void CMfcdemoView::OnColorHue() 
  533. {
  534.         CRangeDlg dlg;
  535.  
  536.         dlg.m_strTitle = _T("Hue");
  537.         dlg.m_strLabel = _T("&Angle");
  538.         dlg.m_nMin = -359;
  539.         dlg.m_nMax = 359;
  540.  
  541.         if(dlg.DoModal() == IDOK && dlg.m_nValue)
  542.         {
  543.                 BeginProcessing();
  544.          int nRet = GetDocLead()->Hue(dlg.m_nValue);
  545.          OnChanged();
  546.                 EndProcessing(nRet);
  547.         }   
  548.    
  549. }
  550.  
  551. void CMfcdemoView::OnColorSaturation() 
  552. {
  553.         CRangeDlg dlg;
  554.  
  555.         dlg.m_strTitle = _T("Saturation");
  556.         dlg.m_strLabel = _T("&Change");
  557.         dlg.m_nMin = -100;
  558.         dlg.m_nMax = 100;
  559.  
  560.         if(dlg.DoModal() == IDOK && dlg.m_nValue)
  561.         {
  562.                 BeginProcessing();
  563.          int nRet = GetDocLead()->Saturation(dlg.m_nValue * 10);
  564.          OnChanged();
  565.                 EndProcessing(nRet);
  566.         }   
  567.    
  568. }
  569.  
  570. void CMfcdemoView::OnImageEffectsAddnoise() 
  571. {
  572.         CRangeDlg dlg;
  573.  
  574.         dlg.m_strTitle = _T("Add Noise");
  575.         dlg.m_strLabel = _T("&Level");
  576.         dlg.m_fShowCombo = TRUE;
  577.         dlg.m_strComboLabel = _T("&Channel");
  578.         dlg.m_strComboInit = _T("Master|Red|Green|Blue|");
  579.                 
  580.         if(dlg.DoModal() == IDOK && dlg.m_nValue)
  581.         {
  582.                 BeginProcessing();
  583.          int nRet = GetDocLead()->AddNoise(dlg.m_nValue * 10, dlg.m_nComboValue);
  584.          OnChanged();
  585.                 EndProcessing(nRet);
  586.         }   
  587. }
  588.  
  589. void CMfcdemoView::OnImageEffectsAverage() 
  590. {
  591.         CRangeDlg dlg;
  592.  
  593.         dlg.m_strTitle = _T("Average");
  594.         dlg.m_strLabel = _T("&Size");
  595.         dlg.m_nValue = 3;
  596.         dlg.m_nMin = 3;
  597.         dlg.m_nMax = 11;
  598.         dlg.m_nPage = 2;
  599.  
  600.         if(dlg.DoModal() == IDOK)
  601.         {
  602.                 BeginProcessing();
  603.          int nRet = GetDocLead()->Average(dlg.m_nValue);
  604.          OnChanged();
  605.                 EndProcessing(nRet);
  606.         }   
  607. }
  608.  
  609. void CMfcdemoView::OnImageEffectsDespeckle() 
  610. {
  611.         BeginProcessing();
  612.          int nRet = GetDocLead()->Despeckle();
  613.          OnChanged();
  614.         EndProcessing(nRet);
  615. }
  616.  
  617. void CMfcdemoView::OnImageEffectsMedian() 
  618. {
  619.         CRangeDlg dlg;
  620.  
  621.         dlg.m_strTitle = _T("Median");
  622.         dlg.m_strLabel = _T("&Size");
  623.         dlg.m_nValue = 3;
  624.         dlg.m_nMin = 3;
  625.         dlg.m_nMax = 11;
  626.         dlg.m_nPage = 2;
  627.  
  628.         if(dlg.DoModal() == IDOK)
  629.         {
  630.                 BeginProcessing();
  631.          int nRet = GetDocLead()->Median(dlg.m_nValue);
  632.          OnChanged();
  633.                 EndProcessing(nRet);
  634.         }   
  635. }
  636.  
  637. void CMfcdemoView::OnImageEffectsMosaic() 
  638. {
  639.         CRangeDlg dlg;
  640.  
  641.         dlg.m_strTitle = _T("Mosaic");
  642.         dlg.m_strLabel = _T("&Size");
  643.         dlg.m_nValue = 2;
  644.         dlg.m_nMin = 2;
  645.         dlg.m_nMax = 64;
  646.  
  647.         if(dlg.DoModal() == IDOK)
  648.         {
  649.                 BeginProcessing();
  650.          int nRet = GetDocLead()->Mosaic(dlg.m_nValue);
  651.          OnChanged();
  652.                 EndProcessing(nRet);
  653.         }   
  654.    
  655. }
  656.  
  657. void CMfcdemoView::OnImageEffectsSharpen() 
  658. {
  659.         CRangeDlg dlg;
  660.  
  661.         dlg.m_strTitle = _T("Sharpen");
  662.         dlg.m_strLabel = _T("&Change");
  663.         dlg.m_nMin = -100;
  664.         dlg.m_nMax = 100;
  665.  
  666.         if(dlg.DoModal() == IDOK && dlg.m_nValue)
  667.         {
  668.                 BeginProcessing();
  669.          int nRet = GetDocLead()->Sharpen(dlg.m_nValue * 10);
  670.          OnChanged();
  671.                 EndProcessing(nRet);
  672.         }   
  673.    
  674. }
  675.  
  676. void CMfcdemoView::OnImageBinaryfiltersDilation() 
  677. {
  678.         CListDlg dlg;
  679.  
  680.         dlg.m_strTitle = _T("Dilation");
  681.         dlg.m_strLabel = _T("&Filter Type");
  682.         dlg.m_strInit = SZ_BINARY;
  683.         if(dlg.DoModal() == IDOK)
  684.         {
  685.                 BeginProcessing();
  686.          int nRet = GetDocLead()->BinaryFilter(aDilationFlt[dlg.m_nValue]);
  687.          OnChanged();
  688.                 EndProcessing(nRet);
  689.         }
  690. }
  691.  
  692. void CMfcdemoView::OnImageBinaryfiltersErosion() 
  693. {
  694.         CListDlg dlg;
  695.  
  696.         dlg.m_strTitle = _T("Erosion");
  697.         dlg.m_strLabel = _T("&Filter Type");
  698.         dlg.m_strInit = SZ_BINARY;
  699.         if(dlg.DoModal() == IDOK)
  700.         {
  701.                 BeginProcessing();
  702.          int nRet = GetDocLead()->BinaryFilter(aErosionFlt[dlg.m_nValue]);
  703.          OnChanged();
  704.                 EndProcessing(nRet);
  705.         }
  706. }
  707.  
  708. void CMfcdemoView::OnImageSpatialfiltersGradient() 
  709. {
  710.         CListDlg dlg;
  711.  
  712.         dlg.m_strTitle = _T("Gradient");
  713.         dlg.m_strLabel = _T("&Filter Type");
  714.         dlg.m_strInit = SZ_COMPASS;
  715.         if(dlg.DoModal() == IDOK)
  716.         {
  717.                 BeginProcessing();
  718.          int nRet = GetDocLead()->SpatialFilter(aGradientFlt[dlg.m_nValue]);
  719.          OnChanged();
  720.                 EndProcessing(nRet);
  721.         }
  722. }
  723.  
  724. void CMfcdemoView::OnImageSpatialfiltersLaplacian() 
  725. {
  726.         CListDlg dlg;
  727.  
  728.         dlg.m_strTitle = _T("Laplacian");
  729.         dlg.m_strLabel = _T("&Filter Type");
  730.         dlg.m_strInit = SZ_LAPLACE;
  731.         if(dlg.DoModal() == IDOK)
  732.         {
  733.                 BeginProcessing();
  734.          int nRet = GetDocLead()->SpatialFilter(aLaplaceFlt[dlg.m_nValue]);
  735.          OnChanged();
  736.                 EndProcessing(nRet);
  737.         }
  738. }
  739.  
  740. void CMfcdemoView::OnImageSpatialfiltersLinesegment() 
  741. {
  742.         CListDlg dlg;
  743.  
  744.         dlg.m_strTitle = _T("Line Segment");
  745.         dlg.m_strLabel = _T("&Filter Type");
  746.         dlg.m_strInit = SZ_LINESEG;
  747.         if(dlg.DoModal() == IDOK)
  748.         {
  749.                 BeginProcessing();
  750.          int nRet = GetDocLead()->SpatialFilter(aLineSegFlt[dlg.m_nValue]);
  751.          OnChanged();
  752.                 EndProcessing(nRet);
  753.         }
  754. }
  755.  
  756. void CMfcdemoView::OnImageSpatialfiltersPrewitt() 
  757. {
  758.         CListDlg dlg;
  759.  
  760.         dlg.m_strTitle = _T("Prewitt");
  761.         dlg.m_strLabel = _T("&Filter Type");
  762.         dlg.m_strInit = SZ_HORZVERT;
  763.         if(dlg.DoModal() == IDOK)
  764.         {
  765.                 BeginProcessing();
  766.          int nRet = GetDocLead()->SpatialFilter(aPrewittFlt[dlg.m_nValue]);
  767.          OnChanged();
  768.                 EndProcessing(nRet);
  769.         }
  770. }
  771.  
  772. void CMfcdemoView::OnImageSpatialfiltersShiftanddifference() 
  773. {
  774.         CListDlg dlg;
  775.  
  776.         dlg.m_strTitle = _T("Shift and Difference");
  777.         dlg.m_strLabel = _T("&Filter Type");
  778.         dlg.m_strInit = SZ_SHIFTDIFF;
  779.         if(dlg.DoModal() == IDOK)
  780.         {
  781.                 BeginProcessing();
  782.          int nRet = GetDocLead()->SpatialFilter(aShiftDiffFlt[dlg.m_nValue]);
  783.          OnChanged();
  784.                 EndProcessing(nRet);
  785.         }
  786. }
  787.  
  788. void CMfcdemoView::OnImageSpatialfiltersSobel() 
  789. {
  790.         CListDlg dlg;
  791.  
  792.         dlg.m_strTitle = _T("Sobel");
  793.         dlg.m_strLabel = _T("&Filter Type");
  794.         dlg.m_strInit = SZ_HORZVERT;
  795.         if(dlg.DoModal() == IDOK)
  796.         {
  797.                 BeginProcessing();
  798.          int nRet = GetDocLead()->SpatialFilter(aSobelFlt[dlg.m_nValue]);
  799.          OnChanged();
  800.                 EndProcessing(nRet);
  801.         }
  802.    
  803. }
  804.  
  805. void CMfcdemoView::OnColorGammacorrect() 
  806. {
  807.         CFloatDlg dlg;
  808.  
  809.         dlg.m_strTitle = _T("Gamma Correct");
  810.         dlg.m_strLabel = _T("&Value");
  811.         dlg.m_fltValue = 1.0f;
  812.         dlg.m_fltMin =  .01f;
  813.         dlg.m_fltMax =  4.99f;
  814.         dlg.m_fltStep =  .01f;
  815.         dlg.m_fltPage =  .10f;
  816.         if(dlg.DoModal() == IDOK)
  817.         {
  818.                 BeginProcessing();
  819.                 int nRet = GetDocLead()->GammaCorrect((int) (dlg.m_fltValue * 100));
  820.          OnChanged();
  821.                 EndProcessing(nRet);
  822.         }   
  823.    
  824. }
  825.  
  826.  
  827. void CMfcdemoView::OnImageResize() 
  828. {
  829.     if(m_Lead.GetHasRgn())
  830.     {
  831.       OnImageRegiontransformationsResize();
  832.     }
  833.     else
  834.     {
  835.       CResizeDlg dlg;
  836.  
  837.       dlg.m_nWidth = (int) GetDocLead()->GetBitmapWidth();
  838.       dlg.m_nHeight = (int) GetDocLead()->GetBitmapHeight();
  839.       if(dlg.DoModal() == IDOK)
  840.       {
  841.           int nRet;
  842.   
  843.           BeginProcessing();
  844.           if(dlg.m_fResample)
  845.               nRet = GetDocLead()->Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, CLead::RESIZE_RESAMPLE);
  846.           else
  847.               nRet = GetDocLead()->Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, CLead::RESIZE_NORMAL);
  848.           OnChanged();
  849.           EndProcessing(nRet);
  850.       }
  851.    }
  852. }
  853.  
  854. void CMfcdemoView::OnImageRotateAnyangle() 
  855. {
  856.     if(m_Lead.GetHasRgn())
  857.     {
  858.       OnImageRegiontransformationsRotate();
  859.     }
  860.     else
  861.     {
  862.       CFloatDlg dlg;
  863.  
  864.       dlg.m_strTitle = _T("Rotate");
  865.       dlg.m_strLabel = _T("&Angle");
  866.       dlg.m_strCheck = _T("&Resize");
  867.       dlg.m_fCheck = TRUE;
  868.       dlg.m_fShowCheck = TRUE;
  869.       dlg.m_fltMin =  -360.0f;
  870.       dlg.m_fltMax =  360.0f;
  871.       dlg.m_fltScale = 10.0f;
  872.       if(dlg.DoModal() == IDOK)
  873.       {
  874.           BeginProcessing();
  875.           int nRet = GetDocLead()->Rotate((long) (dlg.m_fltValue * 100), dlg.m_fCheck, RGB(255, 255, 255));
  876.           OnChanged();
  877.           EndProcessing(nRet);
  878.       }  
  879.    }
  880. }
  881.  
  882. void CMfcdemoView::OnImageShear() 
  883. {
  884.         CFloatDlg dlg;
  885.  
  886.         dlg.m_strTitle = _T("Shear");
  887.         dlg.m_strLabel = _T("&Angle");
  888.         dlg.m_strCheck = _T("&Horizontal");
  889.         dlg.m_fCheck = TRUE;
  890.         dlg.m_fShowCheck = TRUE;
  891.         dlg.m_fltMin = (float) -45.0;
  892.         dlg.m_fltMax = (float) 45.0;
  893.  
  894.         if(dlg.DoModal() == IDOK)
  895.         {
  896.                 BeginProcessing();
  897.                 int nRet = GetDocLead()->Shear((int) (dlg.m_fltValue * 100), dlg.m_fCheck, RGB(255, 255, 255));
  898.          OnChanged();
  899.                 EndProcessing(nRet);
  900.         }   
  901. }
  902.  
  903. void CMfcdemoView::OnColorColorresolution() 
  904. {
  905.         CColorResDlg dlg;
  906.  
  907.         dlg.m_nBitsPerPixel = GetDocLead()->GetBitmapBits();
  908.         if(dlg.DoModal() == IDOK)
  909.         {
  910.                 BeginProcessing();
  911.                 int nRet = GetDocLead()->ColorRes(dlg.m_nBitsPerPixel,
  912.                                 dlg.m_nPalette, dlg.m_nDither, 0);
  913.          OnChanged();
  914.                 EndProcessing(nRet);
  915.         }   
  916. }
  917. void CMfcdemoView::OnColorIntensitydetect() 
  918. {
  919.         CDualRangeDlg dlg;
  920.  
  921.         dlg.m_strTitle = _T("Intensity Detect");
  922.         dlg.m_strLabel1 = _T("&Min");
  923.         dlg.m_strLabel2 = _T("&Max");
  924.         dlg.m_nValue1 = 0;
  925.         dlg.m_nValue2 = 255;
  926.         dlg.m_nMin = 0;
  927.         dlg.m_nMax = 255;
  928.  
  929.         if(dlg.DoModal() == IDOK)
  930.         {
  931.                 BeginProcessing();
  932.          int nRet = GetDocLead()->IntensityDetect(dlg.m_nValue1, dlg.m_nValue2);
  933.          OnChanged();
  934.                 EndProcessing(nRet);
  935.         }   
  936. }
  937. void CMfcdemoView::OnViewZoom() 
  938. {
  939.    CRangeDlg dlg;
  940.  
  941.    dlg.m_strTitle = _T("Zoom");
  942.    dlg.m_strLabel = _T("&Amount");
  943.    dlg.m_nValue = (int)m_nZoom;
  944.    dlg.m_nMin = 1;
  945.    dlg.m_nMax = 800;
  946.    dlg.m_nPage = 100;
  947.  
  948.    if(dlg.DoModal() == IDOK)
  949.    {
  950.       SetZoom((float)dlg.m_nValue);
  951.    }   
  952. }
  953.  
  954. void CMfcdemoView::OnViewNormal() 
  955. {
  956.    SetZoom(100.0f);
  957. }
  958.  
  959. static int nEffectIndex[] =
  960. {
  961.    CLead::EFX_EFFECT_WIPE_CLASS,              CLead::EFX_EFFECT_WIPE_MAX,
  962.    CLead::EFX_EFFECT_WIPE_RECTANGLE_CLASS,    CLead::EFX_EFFECT_WIPE_RECTANGLE_MAX,
  963.    CLead::EFX_EFFECT_WIPE_CIRCLE_CLASS,       CLead::EFX_EFFECT_WIPE_CIRCLE_MAX,
  964.    CLead::EFX_EFFECT_PUSH_CLASS,              CLead::EFX_EFFECT_PUSH_MAX,
  965.    CLead::EFX_EFFECT_SLIDE_CLASS,             CLead::EFX_EFFECT_SLIDE_MAX,
  966.    CLead::EFX_EFFECT_ROLL_CLASS,              CLead::EFX_EFFECT_ROLL_MAX,
  967.    CLead::EFX_EFFECT_ROTATE_CLASS,            CLead::EFX_EFFECT_ROTATE_MAX,
  968.    CLead::EFX_EFFECT_ZOOM_CLASS,              CLead::EFX_EFFECT_ZOOM_MAX,
  969.    CLead::EFX_EFFECT_DRIP_CLASS,              CLead::EFX_EFFECT_DRIP_MAX,
  970.    CLead::EFX_EFFECT_BLIND_CLASS,             CLead::EFX_EFFECT_BLIND_MAX,
  971.    CLead::EFX_EFFECT_RANDOM_CLASS,            CLead::EFX_EFFECT_RANDOM_MAX,
  972.    CLead::EFX_EFFECT_CHECKERBOARD_CLASS,      CLead::EFX_EFFECT_CHECKERBOARD_MAX,
  973.    CLead::EFX_EFFECT_BLOCKS_CLASS,            CLead::EFX_EFFECT_BLOCKS_MAX,
  974.    CLead::EFX_EFFECT_CIRCLE_CLASS,            CLead::EFX_EFFECT_CIRCLE_MAX,
  975.    CLead::EFX_EFFECT_ELLIPSE_CLASS,           CLead::EFX_EFFECT_ELLIPSE_MAX,
  976. };
  977.  
  978. void CMfcdemoView::OnViewPainteffects() 
  979. {
  980.    CClientDC cdc(this);
  981.    DWORD dw; 
  982.    BOOL bOLDErase;
  983.    int i;
  984.  
  985.    BeginWaitCursor(); 
  986.    bOLDErase=m_Lead.GetBackErase();
  987.    m_Lead.SetBackErase(TRUE);
  988.    for (i = 0; i < sizeof(nEffectIndex) / sizeof(nEffectIndex[0]); i += 2)
  989.    {
  990.       for (m_nEffect = nEffectIndex[i]; m_nEffect <= nEffectIndex[i+1]; m_nEffect++)
  991.       {
  992.          m_Lead.SetPaintEffect(m_nEffect);
  993.          dw = GetTickCount ();
  994.          while ((GetTickCount () - dw) < 1000);
  995.       }
  996.    }
  997.    m_Lead.SetBackErase(bOLDErase);
  998.    m_nEffect = CLead::EFX_EFFECT_NONE;
  999.    m_Lead.SetPaintEffect(m_nEffect);
  1000.    EndWaitCursor();
  1001. }
  1002.  
  1003. void CMfcdemoView::OnViewSnapwindowtoimage() 
  1004. {
  1005.    CWnd* pFrame = GetParent();
  1006.    CRect rcWindow;
  1007.    CRect rcClient;
  1008.  
  1009.    pFrame->ShowWindow(SW_NORMAL);
  1010.    GetClientRect(&rcClient);
  1011.    pFrame->GetWindowRect(&rcWindow);
  1012.  
  1013.    pFrame->GetParent()->ScreenToClient (rcWindow);
  1014.  
  1015.    pFrame->MoveWindow (rcWindow.left, rcWindow.top,
  1016.                rcWindow.Width() + (int) m_Lead.GetDstWidth() - rcClient.Width(),
  1017.                rcWindow.Height() + (int) m_Lead.GetDstHeight() - rcClient.Height());
  1018.  
  1019. }
  1020.  
  1021. void CMfcdemoView::OnViewFitimagetowindow() 
  1022. {
  1023.    float cxZoom, cyZoom; 
  1024.    cxZoom = m_Lead.GetScaleWidth() * 100.0f / m_Lead.GetBitmapWidth();
  1025.    cyZoom = m_Lead.GetScaleHeight() * 100.0f / m_Lead.GetBitmapHeight();
  1026.    SetZoom(max(min(cxZoom, cyZoom), 1));
  1027. }
  1028.  
  1029. BOOL CMfcdemoView::OnEraseBkgnd(CDC* pDC) 
  1030. {
  1031. //        return CView::OnEraseBkgnd(pDC);
  1032.         return TRUE;
  1033. }
  1034.  
  1035. void CMfcdemoView::OnImageEffectsEmboss() 
  1036. {
  1037.         CRangeDlg dlg;
  1038.  
  1039.         dlg.m_strTitle = _T("Emboss");
  1040.         dlg.m_strLabel = _T("&Level");
  1041.         dlg.m_nValue = 50;
  1042.         dlg.m_fShowCombo = TRUE;
  1043.         dlg.m_strComboLabel = _T("&Direction");
  1044.         dlg.m_strComboInit = SZ_COMPASS;
  1045.                 
  1046.         if(dlg.DoModal() == IDOK && dlg.m_nValue)
  1047.         {
  1048.                 BeginProcessing();
  1049.          int nRet = GetDocLead()->Emboss(dlg.m_nComboValue, dlg.m_nValue * 10);
  1050.          OnChanged();
  1051.                 EndProcessing(nRet);
  1052.         }   
  1053.    
  1054. }
  1055.  
  1056. void CMfcdemoView::OnColorHalftone() 
  1057. {
  1058.         CRangeDlg dlg;
  1059.  
  1060.         dlg.m_strTitle = _T("Halftone");
  1061.         dlg.m_strLabel = _T("&Angle");
  1062.         dlg.m_nMin = -359;
  1063.         dlg.m_nMax = 359;
  1064.         dlg.m_fShowCombo = TRUE;
  1065.         dlg.m_strComboLabel = _T("&Type");
  1066.         dlg.m_strComboInit = _T("Print|View|");
  1067.  
  1068.         if(dlg.DoModal() == IDOK)
  1069.         {
  1070.                 BeginProcessing();
  1071.          int nRet = GetDocLead()->Halftone(dlg.m_nComboValue, (LONG) dlg.m_nValue * 100);
  1072.          OnChanged();
  1073.                 EndProcessing(nRet);
  1074.         }   
  1075.    
  1076. }
  1077.  
  1078. void CMfcdemoView::OnColorFill() 
  1079. {
  1080.         CColorDialog dlg;
  1081.  
  1082.         if(dlg.DoModal() == IDOK)
  1083.         {
  1084.                 BeginProcessing();
  1085.          int nRet = GetDocLead()->Fill(dlg.GetColor());
  1086.          OnChanged();
  1087.                 EndProcessing(nRet);
  1088.         }
  1089.  
  1090. }
  1091.  
  1092. void CMfcdemoView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
  1093. {
  1094.    CMfcdemoDoc* pDoc = GetDocument();
  1095.    OLE_HANDLE hRegion;
  1096.  
  1097.    m_Lead.SetAutoRepaint(FALSE);
  1098.    m_Lead.SetPaintPalette(theApp.m_fAutoPalette ? CLead::PAINTPALETTE_AUTO : CLead::PAINTPALETTE_FIXED);
  1099.    m_Lead.SetPaintDither(theApp.m_fOrderedDither ? CLead::PAINTDITHER_ORDERED : CLead::PAINTDITHER_DIFFUSION);
  1100.    m_Lead.SetBitonalScaling(theApp.m_nBitonalScaling);
  1101.    m_Lead.SetPaintZoomFactor(m_nZoom);
  1102.    if( GetDocLead()->GetBitmapListCount() > 1 )
  1103.       m_Lead.SetBitmapList(GetDocLead()->GetBitmapList());
  1104.    else
  1105.       m_Lead.SetBitmap(GetDocLead()->GetBitmap());
  1106.    /* copy the region from the document control */
  1107.    if( GetDocLead()->GetHasRgn() )
  1108.    {
  1109.       hRegion = GetDocLead()->GetRgnHandle();
  1110.       m_Lead.SetRgnHandle(hRegion,0.0f,0.0f,CLead::L_RGN_SET);
  1111.       m_Lead.SetRgnFrameType(CLead::RGNFRAME_ANIMATED);
  1112.       m_Lead.DeleteRgnHandle(hRegion);
  1113.    }
  1114.    else
  1115.    {
  1116.       if( !m_Lead.IsSupportLocked(CLead::L_SUPPORT_EXPRESS) )
  1117.       {
  1118.          m_Lead.SetRgnFrameType(CLead::RGNFRAME_NONE);
  1119.          m_Lead.FreeRgn();
  1120.       }
  1121.    }
  1122.    if( m_Lead.GetBitmapListCount() > 1 )
  1123.    {      
  1124.       m_Lead.SetAnimationWidth(GetDocLead()->GetAnimationWidth());      
  1125.       m_Lead.SetAnimationHeight(GetDocLead()->GetAnimationHeight());      
  1126.       m_Lead.SetAnimationBitsPerPixel(GetDocLead()->GetAnimationBitsPerPixel());      
  1127.       m_Lead.SetAnimationBackColor(GetDocLead()->GetAnimationBackColor());      
  1128.       m_Lead.SetAnimationLoop(GetDocLead()->GetAnimationLoop());      
  1129.       for(int i = 0; i < (1 << m_Lead.GetAnimationBitsPerPixel() ); i++)
  1130.       {
  1131.       
  1132.          m_Lead.SetAnimationPalette(i, GetDocLead()->GetAnimationPalette(i));      
  1133.       }
  1134.       m_Lead.SetAnimationEnable(TRUE);
  1135.    }
  1136.    m_Lead.SetAutoRepaint(TRUE);
  1137. }
  1138.  
  1139. void CMfcdemoView::OnEditUndo() 
  1140. {
  1141.         BeginWaitCursor();
  1142.         GetDocLead()->SetBitmap(GetUndoLead()->GetBitmap());
  1143.         GetUndoLead()->SetBitmap(0);
  1144.          OnChanged();
  1145.         EndWaitCursor();
  1146. }
  1147.  
  1148. void CMfcdemoView::OnUpdateEditUndo(CCmdUI* pCmdUI) 
  1149. {
  1150.         pCmdUI->Enable(GetUndoLead()->GetBitmap() != 0); 
  1151. }
  1152.  
  1153. void CMfcdemoView::OnEditCopy() 
  1154. {
  1155.         BeginWaitCursor();
  1156.         GetDocLead()->Copy(CLead::COPY_DIB | CLead::COPY_DDB | CLead::COPY_PALETTE);
  1157.         EndWaitCursor();
  1158. }
  1159.  
  1160. void CMfcdemoView::OnColorSeparation() 
  1161. {
  1162.         CListDlg dlg;
  1163.         int i, nPlanes;
  1164.  
  1165.         dlg.m_strTitle = _T("Separation");
  1166.         dlg.m_strLabel = _T("&Color Space");
  1167.         dlg.m_strInit = _T("RGB|CMYK|HSV|HLS|CMY|");
  1168.         if(dlg.DoModal() == IDOK)
  1169.         {
  1170.                 BeginProcessing();
  1171.          int nRet = GetDocLead()->ColorSeparate(dlg.m_nValue);
  1172.                 if(!nRet)
  1173.                 {
  1174.                         nPlanes = (dlg.m_nValue == CLead::COLORSEP_CMYK) ? 4 : 3;
  1175.                         for(i = 0; i < nPlanes; i++)
  1176.                         {
  1177.                                 theApp.m_Bitmap = GetDocLead()->GetColorPlanes(i);
  1178.                                 theApp.OpenDocument(OPENMODE_BITMAP);
  1179.                                 GetDocLead()->SetColorPlanes(i, 0);
  1180.                         }
  1181.                 }
  1182.                 EndProcessing(nRet);
  1183.         }
  1184. }
  1185.  
  1186. void CMfcdemoView::OnImageEffectsEdgeenhance() 
  1187. {
  1188.       BeginProcessing();
  1189.  
  1190.       int nRet = m_Lead.SpatialFilter(CLead::FLT_LAPLACE_1);
  1191.       if(!nRet)
  1192.       {
  1193.               nRet = GetDocLead()->Combine(0.0f, 0.0f, m_Lead.GetBitmapWidth(), m_Lead.GetBitmapHeight(),
  1194.                                 m_Lead.GetBitmap(), 0.0f, 0.0f, CLead::CB_OP_ADD);
  1195.       }
  1196.       OnChanged();
  1197.       EndProcessing(nRet);
  1198. }
  1199.  
  1200. void CMfcdemoView::OnUpdateImageEffectsEdgeenhance(CCmdUI* pCmdUI) 
  1201. {
  1202.         pCmdUI->Enable(GetDocLead()->GetBitmapBits() > 8); 
  1203. }
  1204.  
  1205.  
  1206. void CMfcdemoView::OnImageDeskew() 
  1207. {
  1208.         BeginProcessing();
  1209.    int nRet = GetDocLead()->Deskew();
  1210.    OnChanged();
  1211.         EndProcessing(nRet);
  1212. }
  1213.  
  1214. void CMfcdemoView::OnImageEffectsUnderlay() 
  1215. {
  1216.         CUnderLayDlg dlg;
  1217.  
  1218.         if(dlg.DoModal() == IDOK)
  1219.         {
  1220.                 BeginProcessing();
  1221.                 int nRet = GetDocLead()->Underlay(((CMfcdemoDoc*)dlg.m_pDocument)->m_Lead.GetBitmap(), dlg.m_fTile ? CLead::UNDERLAY_TILE : CLead::UNDERLAY_STRETCH);
  1222.          OnChanged();
  1223.                 EndProcessing(nRet);
  1224.         }
  1225. }
  1226.  
  1227. void CMfcdemoView::OnUpdateImageDeskew(CCmdUI* pCmdUI) 
  1228. {
  1229.     pCmdUI->Enable((GetDocLead()->GetVersionLevel() == CLead::VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == CLead::VERSIONLEVEL_MEDICAL)
  1230.                      && !m_Lead.GetHasRgn());
  1231. }
  1232.  
  1233. void CMfcdemoView::OnUpdateImageShear(CCmdUI* pCmdUI) 
  1234. {
  1235.     pCmdUI->Enable(!m_Lead.GetHasRgn());
  1236. }
  1237.  
  1238. void CMfcdemoView::OnUpdateImageBinaryfiltersDilation(CCmdUI* pCmdUI) 
  1239. {
  1240.         pCmdUI->Enable(GetDocLead()->GetVersionLevel() == CLead::VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == CLead::VERSIONLEVEL_MEDICAL);
  1241. }
  1242.  
  1243. void CMfcdemoView::OnUpdateImageBinaryfiltersErosion(CCmdUI* pCmdUI) 
  1244. {
  1245.         pCmdUI->Enable(GetDocLead()->GetVersionLevel() == CLead::VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == CLead::VERSIONLEVEL_MEDICAL);
  1246. }
  1247.  
  1248. void CMfcdemoView::OnUpdateImageEffectsDespeckle(CCmdUI* pCmdUI) 
  1249. {
  1250.         pCmdUI->Enable(GetDocLead()->GetVersionLevel() == CLead::VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == CLead::VERSIONLEVEL_MEDICAL);
  1251. }
  1252.  
  1253. void CMfcdemoView::OnSize(UINT nType, int cx, int cy) 
  1254. {
  1255.    CView::OnSize(nType, cx, cy);
  1256.    
  1257.    m_Lead.MoveControl(CRect( 0, 0, cx, cy));
  1258.    
  1259. }
  1260.  
  1261. int CMfcdemoView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  1262. {
  1263.    if (CView::OnCreate(lpCreateStruct) == -1)
  1264.       return -1;
  1265.    
  1266.    CRect rcClient;
  1267.    GetClientRect(rcClient);
  1268.    m_Lead.CreateInstance(&m_LeadContainer, this, rcClient);
  1269.    INIT_LEAD_MAPS(m_Lead);
  1270.    UNLOCKSUPPORT(m_Lead);
  1271.  
  1272.    m_Lead3.CreateInstance(&m_LeadContainer, this, rcClient);
  1273.    m_Lead3.ShowWindow(SW_HIDE);
  1274.    m_Lead3.SetAutoRepaint(FALSE);
  1275.  
  1276.    return 0;
  1277. }
  1278.  
  1279. void CMfcdemoView::OnToolnone() 
  1280. {
  1281.    SetRegionTool( IDM_TOOLNONE );
  1282. }
  1283.  
  1284. void CMfcdemoView::OnUpdateToolnone(CCmdUI* pCmdUI) 
  1285. {
  1286. //   pCmdUI->Enable(!m_Lead.IsSupportLocked(CLead::L_SUPPORT_EXPRESS));
  1287.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLNONE);
  1288. }
  1289.  
  1290. void CMfcdemoView::OnToolellipse() 
  1291. {
  1292.    SetRegionTool( IDM_TOOLELLIPSE );
  1293. }
  1294.  
  1295. void CMfcdemoView::OnUpdateToolellipse(CCmdUI* pCmdUI) 
  1296. {
  1297. //   pCmdUI->Enable(!m_Lead.IsSupportLocked(CLead::L_SUPPORT_EXPRESS));
  1298.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLELLIPSE);
  1299. }
  1300.  
  1301. void CMfcdemoView::OnToolfreehand() 
  1302. {
  1303.    SetRegionTool( IDM_TOOLFREEHAND );
  1304. }
  1305.  
  1306. void CMfcdemoView::OnUpdateToolfreehand(CCmdUI* pCmdUI) 
  1307. {
  1308. //   pCmdUI->Enable(!m_Lead.IsSupportLocked(CLead::L_SUPPORT_EXPRESS));
  1309.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLFREEHAND);
  1310. }
  1311.  
  1312. void CMfcdemoView::OnToolrect() 
  1313. {
  1314.    SetRegionTool( IDM_TOOLRECT );
  1315. }
  1316.  
  1317. void CMfcdemoView::OnUpdateToolrect(CCmdUI* pCmdUI) 
  1318. {
  1319. //   pCmdUI->Enable(!m_Lead.IsSupportLocked(CLead::L_SUPPORT_EXPRESS));
  1320.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLRECT);
  1321. }
  1322.  
  1323. void CMfcdemoView::OnToolrndrect() 
  1324. {
  1325.    SetRegionTool( IDM_TOOLRNDRECT );
  1326. }
  1327.  
  1328. void CMfcdemoView::OnUpdateToolrndrect(CCmdUI* pCmdUI) 
  1329. {
  1330. //   pCmdUI->Enable(!m_Lead.IsSupportLocked(CLead::L_SUPPORT_EXPRESS));
  1331.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLRNDRECT);
  1332. }
  1333.  
  1334. void CMfcdemoView::SetRegionTool( int nNewRegionTool )
  1335. {
  1336.    m_nRegionTool = nNewRegionTool;
  1337. }
  1338.  
  1339. BEGIN_LEAD_DISPATCH_MAP(CMfcdemoView, m_Lead)
  1340. // Place the functions handling Lead control messages here
  1341.    DISP_FUNCTION_ID(CMfcdemoView, "MouseDown", 0xFFFFFDA3, OnMouseDownLeadctrl1, VT_EMPTY, VTS_I2 VTS_I2 VTS_I4 VTS_I4 )
  1342.    DISP_FUNCTION_ID(CMfcdemoView, "MouseMove", 0xFFFFFDA2, OnMouseMoveLeadctrl1, VT_EMPTY, VTS_I2 VTS_I2 VTS_I4 VTS_I4 )
  1343.    DISP_FUNCTION_ID(CMfcdemoView, "MouseUp",   0xFFFFFDA1, OnMouseUpLeadctrl1,   VT_EMPTY, VTS_I2 VTS_I2 VTS_I4 VTS_I4 )
  1344.    DISP_FUNCTION_ID(CMfcdemoView, "RgnChange", 0x00000007, OnRgnChangeLeadctrl1,   VT_EMPTY, VTS_NONE )
  1345. END_LEAD_DISPATCH_MAP()
  1346.  
  1347.  
  1348.  
  1349. void CMfcdemoView::OnRgnChangeLeadctrl1()
  1350. {
  1351.       if(GetDocument()->m_Lead2.GetBitmap() == NULL)
  1352.         SaveBackground();
  1353. }
  1354.  
  1355. void CMfcdemoView::OnMouseDownLeadctrl1(short Button, short Shift, long x, long y) 
  1356. {
  1357.  
  1358.    if( Button != 1 )
  1359.       return; /* nothing to do! */
  1360.  
  1361.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1362.  
  1363.    if( m_Lead.GetHasRgn() && m_Lead.IsPtInRgn((x - m_Lead.GetDstLeft()) * m_Lead.GetSrcWidth() / m_Lead.GetDstWidth(), (y - m_Lead.GetDstTop()) * m_Lead.GetSrcHeight() / m_Lead.GetDstHeight()) )
  1364.    {
  1365.       m_Lead.SetAutoRepaint(FALSE);
  1366.       m_Lead.SetRgnMarkingMode(CLead::RGNMARK_NONE);
  1367.       m_Lead.SetRgnFrameType(CLead::RGNFRAME_NONE);
  1368.       m_xStart = x;
  1369.       m_yStart = y;
  1370.       // we put the floater into the bitmap only when we select another region
  1371.       // if we have a floater at this point, it's because we clicked INSIDE the floater
  1372.       m_Lead.SetFloaterVisible(FALSE);
  1373.       m_Lead.SetFloater(m_Lead.GetBitmap());
  1374.       // the floater coordinates are relative to the window, while the
  1375.       // ocx region coordinates are relative to the bitmap. Adding m_Lead.DstLeft
  1376.       // converts m_Lead.RgnLeft to window coordinates
  1377.       m_rcFloater.left = (int) ((m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() + m_Lead.GetSrcWidth() - 1) / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft());
  1378.       m_rcFloater.top = (int) (m_Lead.GetRgnTop() * m_Lead.GetDstHeight() / m_Lead.GetSrcHeight() + m_Lead.GetDstTop());
  1379.       m_rcFloater.right = (int) (((m_Lead.GetFloaterWidth() + m_Lead.GetRgnLeft()) * m_Lead.GetDstWidth() + m_Lead.GetSrcWidth() - 1) / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft());
  1380.       m_rcFloater.bottom = (int) ((m_Lead.GetFloaterHeight() + m_Lead.GetRgnTop()) * m_Lead.GetDstHeight() / m_Lead.GetSrcHeight() + m_Lead.GetDstTop());
  1381.       m_Lead.SetFloaterDstRect((float) m_rcFloater.left, (float) m_rcFloater.top,
  1382.                  (float) m_rcFloater.Width(), (float) m_rcFloater.Height());
  1383.       if( GetDocument()->m_Lead2.GetBitmap() != NULL )
  1384.       {
  1385.          m_Lead.Combine(m_Lead.GetRgnLeft(), 
  1386.                         m_Lead.GetRgnTop(), 
  1387.                         m_Lead.GetFloaterWidth(), 
  1388.                         m_Lead.GetFloaterHeight(), 
  1389.                         GetDocument()->m_Lead2.GetBitmap(), 
  1390.                         0.0f, 
  1391.                         0.0f, 
  1392.                         CLead::L_SRC_COPY );
  1393.          // RepaintRect uses window coordinates like the floater bitmap
  1394.          m_Lead.RepaintRect(m_Lead.GetFloaterDstLeft(), 
  1395.                            m_Lead.GetFloaterDstTop(), 
  1396.                            m_Lead.GetFloaterDstWidth(), 
  1397.                            m_Lead.GetFloaterDstHeight(), 
  1398.                            FALSE);
  1399.       }
  1400.       m_Lead.SetFloaterVisible(TRUE);
  1401.       m_bMovingFloater = TRUE;
  1402.    }
  1403.    else if (m_nRegionTool != IDM_TOOLNONE)
  1404.    {
  1405.       m_Lead.SetRgnFrameType(CLead::RGNFRAME_NONE);
  1406.  
  1407.       switch(m_nRegionTool)
  1408.       {
  1409.       case IDM_TOOLRECT:
  1410.          m_Lead.SetRgnMarkingMode(CLead::RGNMARK_RECT);
  1411.          break;
  1412.       case IDM_TOOLELLIPSE:
  1413.          m_Lead.SetRgnMarkingMode(CLead::RGNMARK_ELLIPSE);
  1414.          break;
  1415.       case IDM_TOOLRNDRECT:
  1416.          m_Lead.SetRgnMarkingMode(CLead::RGNMARK_ROUNDRECT);
  1417.          break;
  1418.       case IDM_TOOLFREEHAND:
  1419.          m_Lead.SetRgnMarkingMode(CLead::RGNMARK_FREEHAND);
  1420.          break;
  1421.       }
  1422.    }
  1423.  
  1424.    GetDocument()->m_Lead2.SetBitmap(0); // the background bitmap is not needed anymore
  1425.  
  1426.    SetCursor(hOldCursor);
  1427. }
  1428.  
  1429. void CMfcdemoView::OnMouseMoveLeadctrl1(short Button, short Shift, long x, long y) 
  1430. {
  1431.    if( (Button == 1) && m_bMovingFloater )
  1432.    {
  1433.       m_Lead.SetFloaterDstRect((float) (m_rcFloater.left + x - m_xStart), (float) (m_rcFloater.top + y - m_yStart),
  1434.           m_Lead.GetFloaterDstWidth(), m_Lead.GetFloaterDstHeight());
  1435.    }
  1436. }
  1437.  
  1438. void CMfcdemoView::OnMouseUpLeadctrl1(short Button, short Shift, long x, long y) 
  1439. {
  1440.    OLE_HANDLE hRegion;
  1441.    long dx, dy;
  1442.    if (Button != 1)
  1443.       return;  /* nothing to do ! */
  1444.  
  1445.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1446.  
  1447.    if( m_Lead.GetRgnMarkingMode() != CLead::RGNMARK_NONE )
  1448.    {
  1449.       m_Lead.SetRgnMarkingMode(CLead::RGNMARK_NONE);
  1450.       m_Lead.SetRgnFrameType(CLead::RGNFRAME_ANIMATED);
  1451.                         
  1452.       if( m_Lead.GetHasRgn() )
  1453.       {
  1454.          hRegion = m_Lead.GetRgnHandle();
  1455.          GetDocLead()->SetRgnHandle(hRegion,0.0f,0.0f,CLead::L_RGN_SET);
  1456.          m_Lead.DeleteRgnHandle(hRegion);
  1457.       }
  1458.       else
  1459.          GetDocLead()->FreeRgn();
  1460.  
  1461.       GetDocument()->UpdateAllViews(this, (LPARAM)0);
  1462.    }
  1463.    else if(m_bMovingFloater)
  1464.    {
  1465.       m_bMovingFloater = FALSE;
  1466.  
  1467.       m_Lead.SetRgnFrameType(CLead::RGNFRAME_NONE);
  1468.       
  1469.       // Calculate the region offset   
  1470.  
  1471.       if(x >= m_xStart)
  1472.         dx = (x - m_xStart) * (long) m_Lead.GetSrcWidth() / (long) m_Lead.GetDstWidth();
  1473.       else
  1474.         dx = ((x - m_xStart) * (long) m_Lead.GetSrcWidth() - (long) m_Lead.GetDstWidth() + 1) / (long) m_Lead.GetDstWidth();
  1475.       if(y >= m_yStart)
  1476.         dy = (y - m_yStart) * (long) m_Lead.GetSrcHeight() / (long) m_Lead.GetDstHeight();
  1477.       else
  1478.         dy = ((y - m_yStart) * (long) m_Lead.GetSrcHeight() - (long) m_Lead.GetDstHeight() + 1) / (long) m_Lead.GetDstHeight();
  1479.  
  1480.       m_Lead.OffsetRgn((float) dx, (float) dy);
  1481.  
  1482.       GetDocument()->m_Lead2.CreateBitmap(m_Lead.GetFloaterWidth(), 
  1483.                            m_Lead.GetFloaterHeight(), 
  1484.                            m_Lead.GetBitmapBits() );
  1485.  
  1486.       if((m_Lead.GetIsGrayscale() != CLead::GRAY_NO) && (m_Lead.GetBitmapBits()>8))
  1487.          GetDocument()->m_Lead2.Grayscale(m_Lead.GetBitmapBits());
  1488.  
  1489.       GetDocument()->m_Lead2.Combine( 0.0f, 
  1490.                         0.0f, 
  1491.                         m_Lead.GetFloaterWidth(), 
  1492.                         m_Lead.GetFloaterHeight(), 
  1493.                         m_Lead.GetBitmap(), 
  1494.                         m_Lead.GetRgnLeft(), 
  1495.                         m_Lead.GetRgnTop(), 
  1496.                         CLead::L_SRC_COPY);
  1497.  
  1498.       // now blend the floater into the bitmap and make it dissapear
  1499.       // if we leave it, when we scroll, the floater won't move with the bitmap
  1500.       // that's because the floater is independent of the bitmap
  1501.       m_Lead.Combine( m_Lead.GetRgnLeft(), 
  1502.                      m_Lead.GetRgnTop(), 
  1503.                      m_Lead.GetFloaterWidth(), 
  1504.                      m_Lead.GetFloaterHeight(), 
  1505.                      m_Lead.GetFloater(), 
  1506.                      0.0f, 
  1507.                      0.0f, 
  1508.                      CLead::L_SRC_COPY);
  1509.       // free the floater
  1510.       m_Lead.SetFloater(NULL);
  1511.       m_Lead.SetFloaterVisible(FALSE);
  1512.  
  1513.       // draw the frame
  1514.       m_Lead.SetRgnFrameType(CLead::RGNFRAME_ANIMATED);
  1515.       m_Lead.SetAutoRepaint(TRUE);
  1516.  
  1517.       /* update the changes back into the master document and all other views */
  1518.       UpdateMasterDocument();
  1519.    }
  1520.  
  1521.    SetCursor(hOldCursor);
  1522. }
  1523.  
  1524. void CMfcdemoView::OnImageRegiontransformationsFlip() 
  1525. {
  1526.    OLE_HANDLE hRegion;
  1527.    float xCenter;
  1528.    float yCenter;
  1529.  
  1530.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1531.  
  1532.    m_Lead.SetAutoRepaint(FALSE);
  1533.    m_Lead.SetFloaterVisible(FALSE);
  1534.    m_Lead.SetFloater(m_Lead.GetBitmap());
  1535.    RestoreBackground();
  1536.    m_Lead3.SetBitmap(m_Lead.GetFloater());
  1537.    m_Lead.SetFloater(0);
  1538.  
  1539.    // do the transformation on the copy
  1540.    m_Lead3.Flip();
  1541.  
  1542.    m_Lead.SetRgnFrameType(CLead::RGNFRAME_NONE);
  1543.    hRegion = m_Lead3.GetRgnHandle();
  1544.    xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
  1545.    yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
  1546.    /* The flollowing two statements 
  1547.    m_Lead.SetRgnHandle(hRegion, CLead::L_RGN_SET);
  1548.    m_Lead.OffsetRgn(
  1549.       xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1550.       yCenter - m_Lead3.GetBitmapHeight() / 2);
  1551.    do exactly the same thing as this statement: */
  1552.    m_Lead.SetRgnHandle(hRegion, 
  1553.       xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1554.       yCenter - m_Lead3.GetBitmapHeight() / 2,
  1555.       CLead::L_RGN_SET);
  1556.    m_Lead.DeleteRgnHandle (hRegion);
  1557.    SaveBackground();
  1558.    m_Lead.Combine(
  1559.       xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1560.       yCenter - m_Lead3.GetBitmapHeight() / 2, 
  1561.       m_Lead3.GetBitmapWidth(), 
  1562.       m_Lead3.GetBitmapHeight(), 
  1563.       m_Lead3.GetBitmap(), 
  1564.       0.0f, 
  1565.       0.0f, 
  1566.       CLead::L_SRC_COPY);
  1567.    m_Lead.RepaintRect(
  1568.       m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(), 
  1569.       m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(), 
  1570.       m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1571.       m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1572.       FALSE);
  1573.    m_Lead.SetRgnFrameType(CLead::RGNFRAME_ANIMATED);
  1574.    m_Lead3.SetBitmap(0);
  1575.    m_Lead.SetAutoRepaint(TRUE);
  1576.  
  1577.  
  1578.    /* update the changes back into the master document and all other views */
  1579.    UpdateMasterDocument();
  1580.  
  1581.    SetCursor(hOldCursor);
  1582. }
  1583.  
  1584. void CMfcdemoView::OnImageRegiontransformationsResize() 
  1585. {
  1586.    CResizeDlg dlg;
  1587.  
  1588.    dlg.m_nWidth = (int) GetDocLead()->GetRgnWidth();
  1589.    dlg.m_nHeight = (int) GetDocLead()->GetRgnHeight();
  1590.    if(dlg.DoModal() == IDOK)
  1591.    {
  1592.       int nRet;
  1593.       OLE_HANDLE hRegion;
  1594.       float xCenter;
  1595.       float yCenter;
  1596.  
  1597.       HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1598.  
  1599.       m_Lead.SetAutoRepaint(FALSE);
  1600.       m_Lead.SetFloaterVisible(FALSE);
  1601.       m_Lead.SetFloater(m_Lead.GetBitmap());
  1602.       RestoreBackground();
  1603.       m_Lead3.SetBitmap(m_Lead.GetFloater());
  1604.       m_Lead.SetFloater(0);
  1605.  
  1606.       // do the transformation on the copy
  1607.       if(dlg.m_fResample)
  1608.          nRet = m_Lead3.Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, CLead::RESIZE_RESAMPLE);
  1609.       else
  1610.          nRet = m_Lead3.Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, CLead::RESIZE_NORMAL);
  1611.  
  1612.       m_Lead.SetRgnFrameType(CLead::RGNFRAME_NONE);
  1613.       hRegion = m_Lead3.GetRgnHandle();
  1614.       xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
  1615.       yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
  1616.       m_Lead.SetRgnHandle(hRegion, 
  1617.          xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1618.          yCenter - m_Lead3.GetBitmapHeight() / 2,
  1619.          CLead::L_RGN_SET);
  1620.       m_Lead.DeleteRgnHandle (hRegion);
  1621.       SaveBackground();
  1622.       m_Lead.Combine(
  1623.          xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1624.          yCenter - m_Lead3.GetBitmapHeight() / 2, 
  1625.          m_Lead3.GetBitmapWidth(), 
  1626.          m_Lead3.GetBitmapHeight(), 
  1627.          m_Lead3.GetBitmap(), 
  1628.          0.0f, 
  1629.          0.0f, 
  1630.          CLead::L_SRC_COPY);
  1631.       m_Lead.RepaintRect(
  1632.          m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(), 
  1633.          m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(), 
  1634.          m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1635.          m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1636.          FALSE);
  1637.       m_Lead.SetRgnFrameType(CLead::RGNFRAME_ANIMATED);
  1638.       m_Lead3.SetBitmap(0);
  1639.       m_Lead.SetAutoRepaint(TRUE);
  1640.  
  1641.       /* update the changes back into the master document and all other views */
  1642.       UpdateMasterDocument();
  1643.  
  1644.       SetCursor(hOldCursor);
  1645.    }
  1646. }
  1647.  
  1648. void CMfcdemoView::OnImageRegiontransformationsReverse() 
  1649. {
  1650.    OLE_HANDLE hRegion;
  1651.    float xCenter;
  1652.    float yCenter;
  1653.  
  1654.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1655.  
  1656.    m_Lead.SetAutoRepaint(FALSE);
  1657.    m_Lead.SetFloaterVisible(FALSE);
  1658.    m_Lead.SetFloater(m_Lead.GetBitmap());
  1659.    RestoreBackground();
  1660.    m_Lead3.SetBitmap(m_Lead.GetFloater());
  1661.    m_Lead.SetFloater(0);
  1662.  
  1663.    // do the transformation on the copy
  1664.    m_Lead3.Reverse();
  1665.  
  1666.    m_Lead.SetRgnFrameType(CLead::RGNFRAME_NONE);
  1667.    hRegion = m_Lead3.GetRgnHandle();
  1668.    xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
  1669.    yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
  1670.    m_Lead.SetRgnHandle(hRegion, 
  1671.       xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1672.       yCenter - m_Lead3.GetBitmapHeight() / 2,
  1673.       CLead::L_RGN_SET);
  1674.    m_Lead.DeleteRgnHandle (hRegion);
  1675.    SaveBackground();
  1676.    m_Lead.Combine(
  1677.       xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1678.       yCenter - m_Lead3.GetBitmapHeight() / 2, 
  1679.       m_Lead3.GetBitmapWidth(), 
  1680.       m_Lead3.GetBitmapHeight(), 
  1681.       m_Lead3.GetBitmap(), 
  1682.       0.0f, 
  1683.       0.0f, 
  1684.       CLead::L_SRC_COPY);
  1685.    m_Lead.RepaintRect(
  1686.       m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(), 
  1687.       m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(), 
  1688.       m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1689.       m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1690.       FALSE);
  1691.    m_Lead.SetRgnFrameType(CLead::RGNFRAME_ANIMATED);
  1692.    m_Lead3.SetBitmap(0);
  1693.    m_Lead.SetAutoRepaint(TRUE);
  1694.  
  1695.    /* update the changes back into the master document and all other views */
  1696.    UpdateMasterDocument();
  1697.  
  1698.    SetCursor(hOldCursor);
  1699. }
  1700.  
  1701. void CMfcdemoView::OnImageRegiontransformationsRotate()
  1702. {
  1703.    CFloatDlg dlg;
  1704.  
  1705.    dlg.m_strTitle = _T("Rotate");
  1706.    dlg.m_strLabel = _T("&Angle");
  1707.    dlg.m_strCheck = _T("&Resize");
  1708.    dlg.m_fCheck = TRUE;
  1709.    dlg.m_fShowCheck = TRUE;
  1710.    dlg.m_fltMin =  -360.0f;
  1711.    dlg.m_fltMax =  360.0f;
  1712.    dlg.m_fltScale = 10.0f;
  1713.    if(dlg.DoModal() == IDOK)
  1714.    {
  1715.       OnImageRegiontransformationsRotate((long) (dlg.m_fltValue * 100), dlg.m_fCheck);
  1716.    }
  1717. }
  1718. void CMfcdemoView::OnImageRegiontransformationsRotate(long nAngle, BOOL fResize) 
  1719. {
  1720.  
  1721.     OLE_HANDLE hRegion;
  1722.     float xCenter;
  1723.     float yCenter;
  1724.  
  1725.     HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1726.  
  1727.     m_Lead.SetAutoRepaint(FALSE);
  1728.     m_Lead.SetFloaterVisible(FALSE);
  1729.     m_Lead.SetFloater(m_Lead.GetBitmap());
  1730.     RestoreBackground();
  1731.     m_Lead3.SetBitmap(m_Lead.GetFloater());
  1732.     m_Lead.SetFloater(0);
  1733.  
  1734.     // do the transformation on the copy
  1735.     m_Lead3.Rotate(nAngle, fResize, RGB(255, 255, 255));
  1736.  
  1737.     m_Lead.SetRgnFrameType(CLead::RGNFRAME_NONE);
  1738.     hRegion = m_Lead3.GetRgnHandle();
  1739.     xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
  1740.     yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
  1741.     m_Lead.SetRgnHandle(hRegion, 
  1742.        xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1743.        yCenter - m_Lead3.GetBitmapHeight() / 2,
  1744.        CLead::L_RGN_SET);
  1745.     m_Lead.DeleteRgnHandle (hRegion);
  1746.     SaveBackground();
  1747.     m_Lead.Combine(
  1748.        xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1749.        yCenter - m_Lead3.GetBitmapHeight() / 2, 
  1750.        m_Lead3.GetBitmapWidth(), 
  1751.        m_Lead3.GetBitmapHeight(), 
  1752.        m_Lead3.GetBitmap(), 
  1753.        0.0f, 
  1754.        0.0f, 
  1755.        CLead::L_SRC_COPY);
  1756.     m_Lead.RepaintRect(
  1757.        m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(), 
  1758.        m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(), 
  1759.        m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1760.        m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1761.        FALSE);
  1762.     m_Lead.SetRgnFrameType(CLead::RGNFRAME_ANIMATED);
  1763.     m_Lead3.SetBitmap(0);
  1764.     m_Lead.SetAutoRepaint(TRUE);
  1765.  
  1766.     /* update the changes back into the master document and all other views */
  1767.     UpdateMasterDocument();
  1768.  
  1769.     SetCursor(hOldCursor);
  1770.     
  1771. }
  1772.  
  1773. void CMfcdemoView::UpdateMasterDocument() 
  1774. {
  1775.    /* merge the changes back into the master document */
  1776.    OLE_HANDLE hRegion = m_Lead.GetRgnHandle();
  1777.    GetDocLead()->SetBitmap(m_Lead.GetBitmap());
  1778.    GetDocLead()->SetRgnHandle(hRegion,0.0f,0.0f,CLead::L_RGN_SET);
  1779.    m_Lead.DeleteRgnHandle(hRegion);
  1780.    GetDocument()->UpdateAllViews(this, (LPARAM)0);
  1781. }
  1782.  
  1783. void CMfcdemoView::SaveBackground() 
  1784. {
  1785.    GetDocument()->m_Lead2.CreateBitmap(m_Lead.GetRgnWidth(), m_Lead.GetRgnHeight(), m_Lead.GetBitmapBits());
  1786.  
  1787.    if((m_Lead.GetIsGrayscale() != CLead::GRAY_NO) && (m_Lead.GetBitmapBits()>8))
  1788.       GetDocument()->m_Lead2.Grayscale(m_Lead.GetBitmapBits());
  1789.  
  1790.    GetDocument()->m_Lead2.Combine(
  1791.       0.0f, 0.0f, 
  1792.       m_Lead.GetRgnWidth(), m_Lead.GetRgnHeight(), 
  1793.       m_Lead.GetBitmap(), 
  1794.       m_Lead.GetRgnLeft(), m_Lead.GetRgnTop(), 
  1795.       CLead::L_SRC_COPY);
  1796. }
  1797.  
  1798. void CMfcdemoView::RestoreBackground() 
  1799. {
  1800.    if(GetDocument()->m_Lead2.GetBitmap())
  1801.       m_Lead.Combine(
  1802.          m_Lead.GetRgnLeft(), 
  1803.          m_Lead.GetRgnTop(), 
  1804.          m_Lead.GetRgnWidth(), 
  1805.          m_Lead.GetRgnHeight(), 
  1806.          GetDocument()->m_Lead2.GetBitmap(), 
  1807.          0.0f, 
  1808.          0.0f, 
  1809.          CLead::L_SRC_COPY);
  1810. }
  1811.  
  1812. void CMfcdemoView::OnUpdateImageRegiontransformationsCancel(CCmdUI* pCmdUI) 
  1813. {
  1814.    pCmdUI->Enable(m_Lead.GetHasRgn());
  1815. }
  1816.  
  1817. void CMfcdemoView::OnImageRegiontransformationsCancel() 
  1818. {
  1819.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1820.  
  1821.    RestoreBackground();
  1822.  
  1823.    /* delete the regions from the master document and all other views */
  1824.    m_Lead.SetRgnFrameType(CLead::RGNFRAME_NONE);
  1825.    m_Lead.FreeRgn();
  1826.  
  1827.    GetDocLead()->SetBitmap(m_Lead.GetBitmap());
  1828.    GetDocLead()->FreeRgn();
  1829.    GetDocument()->UpdateAllViews(this, (LPARAM)0);
  1830.  
  1831.    SetCursor(hOldCursor);
  1832. }
  1833.