// RstView.cpp : implementation of the CRstDemoView class // #include "StdAfx.h" #include "RstDemo.h" #include "RstDoc.h" #include "RstView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRstDemoView IMPLEMENT_DYNCREATE(CRstDemoView, CView) BEGIN_MESSAGE_MAP(CRstDemoView, CView) //{{AFX_MSG_MAP(CRstDemoView) ON_WM_CREATE() ON_COMMAND(ID_PROPS_BRUSH, OnPropsBrush) ON_COMMAND(ID_PROPS_FILL, OnPropsFill) ON_COMMAND(ID_PROPS_REGION, OnPropsRegion) ON_COMMAND(ID_PROPS_SHAPE, OnPropsShape) ON_COMMAND(ID_PROPS_TEXT, OnPropsText) ON_COMMAND(ID_EDIT_COPY, OnEditCopy) ON_COMMAND(ID_EDIT_PASTE, OnEditPaste) ON_COMMAND(ID_EDIT_REDO, OnEditRedo) ON_COMMAND(ID_EDIT_UNDO, OnEditUndo) ON_COMMAND(ID_EDIT_CUT, OnEditCut) ON_COMMAND(ID_EDIT_CLEAR, OnEditClear) ON_COMMAND(ID_SELECT_ALL, OnSelectAll) ON_COMMAND(ID_SELECT_NONE, OnSelectNone) ON_COMMAND(ID_FILE_PRINT, OnFilePrint) ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo) ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo) ON_WM_CONTEXTMENU() //}}AFX_MSG_MAP // Standard printing commands ON_MESSAGE(WM_HANDLEPALETTE,OnHandlePalette) ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRstDemoView construction/destruction CRstDemoView::CRstDemoView() { /* Change the initial value for the shape round rect width */ PAINTSHAPE* pPaintShape = m_RasterPntWnd.GetPaintShape(); pPaintShape->nRoundRectEllipseWidth = 25; pPaintShape->nRoundRectEllipseHeight = 25; m_RasterPntWnd.SetPaintShape(pPaintShape); /* Change the initial value for the region round rect width */ PAINTREGION* pPaintRegion = m_RasterPntWnd.GetPaintRegion(); pPaintRegion->nRoundRectEllipseWidth = 25; pPaintRegion->nRoundRectEllipseHeight = 25; m_RasterPntWnd.SetPaintRegion(pPaintRegion); memset(m_szFileName, 0, sizeof(m_szFileName)) ; } CRstDemoView::~CRstDemoView() { } BOOL CRstDemoView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CRstDemoView drawing void CRstDemoView::OnDraw(CDC* pDC) { CRstDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CRstDemoView printing BOOL CRstDemoView::OnPreparePrinting(CPrintInfo* pInfo) { // TODO: call DoPreparePrinting to invoke the Print dialog box return CView::OnPreparePrinting(pInfo); } void CRstDemoView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) { // TODO: Add your specialized code here and/or call the base class CView::OnBeginPrinting(pDC, pInfo); } void CRstDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CRstDemoView diagnostics #ifdef _DEBUG void CRstDemoView::AssertValid() const { CView::AssertValid(); } void CRstDemoView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CRstDemoDoc* CRstDemoView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRstDemoDoc))); return(CRstDemoDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CRstDemoView message handlers int CRstDemoView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if(CView::OnCreate(lpCreateStruct) == -1) return -1; m_RasterPntWnd.SetWndHandle(m_hWnd); return 0; } LRESULT CRstDemoView::OnHandlePalette(WPARAM wParam, LPARAM lParam) { if(lParam==TRUE) { m_RasterPntWnd.HandlePalette(WM_PALETTECHANGED,wParam,0); m_RasterPntWnd.Repaint(); } else { if(m_RasterPntWnd.HandlePalette(WM_QUERYNEWPALETTE,0,0)==FALSE) m_RasterPntWnd.Repaint(); } return TRUE; } void CRstDemoView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { if(bActivate==TRUE&&pActivateView==this) m_RasterPntWnd.HandlePalette(WM_QUERYNEWPALETTE,0,0); } void CRstDemoView::OnPropsBrush() { CRstDemoApp* pTheApp = (CRstDemoApp*)AfxGetApp(); PAINTDLGBRUSHINFO BrushDlgInfo; PAINTBRUSH* pPaintBrush = m_RasterPntWnd.GetPaintBrush(); L_INT nRetCode; L_TCHAR* TouchBitmap [ ] = { TEXT("Leaf") }; L_TCHAR* TextureBitmap [ ] = { TEXT("Texture-00") }; BrushDlgInfo.dwFlags = PAINT_DLG_BRUSH_SHOWTOUCHCONTENT | PAINT_DLG_BRUSH_SHOWTOUCHCOLOR | PAINT_DLG_BRUSH_SHOWTOUCHIMAGE | PAINT_DLG_BRUSH_SHOWDIAMETER | PAINT_DLG_BRUSH_SHOWHARDNESS | PAINT_DLG_BRUSH_SHOWSPACING | PAINT_DLG_BRUSH_SHOWOPACITY | PAINT_DLG_BRUSH_SHOWDENSITY | PAINT_DLG_BRUSH_SHOWFADEOUTRATE | PAINT_DLG_BRUSH_SHOWTEXTURE | PAINT_DLG_BRUSH_SHOWDEFAULT ; BrushDlgInfo.pszTitle = TEXT("Paintbrush Properties"); BrushDlgInfo.nContentsType = pPaintBrush->Touch.nContentsType; BrushDlgInfo.crColor = pPaintBrush->Touch.crColor; BrushDlgInfo.ppszTouchImage = TouchBitmap; BrushDlgInfo.uTouchImageCount = 1; BrushDlgInfo.nActiveTouchImageItem = 0; BrushDlgInfo.crTransparentColor = RGB ( 0, 0, 0 ); BrushDlgInfo.nDiameter = pPaintBrush->nDiameter; BrushDlgInfo.nHardnessValue = pPaintBrush->Hardness.nValue; BrushDlgInfo.nSpacing = pPaintBrush->nSpacing; BrushDlgInfo.nDensity = pPaintBrush->nDensity; BrushDlgInfo.nOpacity = pPaintBrush->nOpacity; BrushDlgInfo.nFadeOutRate = pPaintBrush->nFadeOutRate; BrushDlgInfo.ppszPaperTexture = TextureBitmap; BrushDlgInfo.uPaperTextureCount = 1; BrushDlgInfo.nActivePaperTextureItem = ((pPaintBrush->pTexture != NULL) ? 0 : -1); nRetCode = m_PaintDialog.DoModalBrush(m_hWnd, &BrushDlgInfo); if(nRetCode == SUCCESS) { pPaintBrush->nSize = sizeof(PAINTBRUSH); pPaintBrush->dwMask = PBF_ALL; pPaintBrush->Touch.nContentsType = BrushDlgInfo.nContentsType; pPaintBrush->Touch.crColor = BrushDlgInfo.crColor; pPaintBrush->Touch.nShape = PAINT_TOUCH_SHAPE_CIRCLE; pPaintBrush->Touch.pBitmap = ((BrushDlgInfo.nActiveTouchImageItem != -1) ? pTheApp->m_LBtmpBrush.GetHandle() : NULL); pPaintBrush->Touch.crTransparentColor = RGB(0, 0, 0); pPaintBrush->nDiameter = BrushDlgInfo.nDiameter; pPaintBrush->Hardness.nDistributionType = PAINT_HARDNESS_DISTRB_TYPE_0; pPaintBrush->Hardness.nValue = BrushDlgInfo.nHardnessValue; pPaintBrush->nSpacing = BrushDlgInfo.nSpacing; pPaintBrush->nDensity = BrushDlgInfo.nDensity; pPaintBrush->nOpacity = BrushDlgInfo.nOpacity; pPaintBrush->nFadeOutRate = BrushDlgInfo.nFadeOutRate; pPaintBrush->pTexture = ((BrushDlgInfo.nActivePaperTextureItem != -1) ? pTheApp->m_LBtmpPaperTexture.GetHandle() : NULL); m_RasterPntWnd.SetPaintBrush(pPaintBrush); } } void CRstDemoView::OnPropsFill() { CRstDemoApp* pTheApp = (CRstDemoApp*)AfxGetApp(); PAINTDLGFILLINFO FillDlgInfo; PAINTFILL* pPaintFill = m_RasterPntWnd.GetPaintFill(); L_INT nRetCode; L_TCHAR* BKTileBitmap [ ] = { TEXT("Blocks") }; L_TCHAR* TextureBitmap [ ] = { TEXT("Texture-00") }; FillDlgInfo.dwFlags = PAINT_DLG_FILL_SHOWALL; FillDlgInfo.pszTitle = TEXT("Fill Properties"); FillDlgInfo.nStyle = pPaintFill->nStyle; FillDlgInfo.crSolidFillColor = pPaintFill->crSolidFillColor; FillDlgInfo.ppszBackgroundTileBitmap = BKTileBitmap; FillDlgInfo.uBackgroundTileBitmapCount = 1; FillDlgInfo.nActiveBackgroundTileBitmapItem = 0; FillDlgInfo.nGradientStyle = pPaintFill->nGradientStyle; FillDlgInfo.crGradientStartColor = pPaintFill->crGradientStartColor; FillDlgInfo.crGradientEndColor = pPaintFill->crGradientEndColor; FillDlgInfo.uGradientSteps = pPaintFill->uGradientSteps; FillDlgInfo.crUpperTolerance = pPaintFill->crUpperTolerance; FillDlgInfo.crLowerTolerance = pPaintFill->crLowerTolerance; FillDlgInfo.nOpacity = pPaintFill->nOpacity; FillDlgInfo.ppszPaperTexture = TextureBitmap; FillDlgInfo.uPaperTextureCount = 1; FillDlgInfo.nActivePaperTextureItem = ((pPaintFill->pTexture != NULL) ? 0 : -1); nRetCode = m_PaintDialog.DoModalFill(m_hWnd, &FillDlgInfo); if(nRetCode == SUCCESS) { pPaintFill->nSize = sizeof(PAINTFILL); pPaintFill->dwMask = PFF_ALL; pPaintFill->nStyle = FillDlgInfo.nStyle; pPaintFill->crSolidFillColor = FillDlgInfo.crSolidFillColor; pPaintFill->pBackgroundTileBitmap = ((FillDlgInfo.nActiveBackgroundTileBitmapItem != -1) ? pTheApp->m_LBtmpBackTile.GetHandle() : NULL); pPaintFill->nGradientStyle = FillDlgInfo.nGradientStyle; pPaintFill->crGradientStartColor = FillDlgInfo.crGradientStartColor; pPaintFill->crGradientEndColor = FillDlgInfo.crGradientEndColor; pPaintFill->uGradientSteps = FillDlgInfo.uGradientSteps; pPaintFill->crUpperTolerance = FillDlgInfo.crUpperTolerance; pPaintFill->crLowerTolerance = FillDlgInfo.crLowerTolerance; pPaintFill->nOpacity = FillDlgInfo.nOpacity; pPaintFill->pTexture = ((FillDlgInfo.nActivePaperTextureItem != -1) ? pTheApp->m_LBtmpPaperTexture.GetHandle() : NULL); m_RasterPntWnd.SetPaintFill(pPaintFill); } } void CRstDemoView::OnPropsRegion() { CRstDemoApp* pTheApp = (CRstDemoApp*)AfxGetApp(); PAINTDLGREGIONINFO RegionDlgInfo; PAINTREGION* pPaintRegion = m_RasterPntWnd.GetPaintRegion(); L_INT nRetCode; RegionDlgInfo.dwFlags = PAINT_DLG_REGION_SHOWALL; RegionDlgInfo.pszTitle = TEXT("Region Properties"); RegionDlgInfo.crLowerTolerance = pPaintRegion->crLowerTolerance; RegionDlgInfo.crUpperTolerance = pPaintRegion->crUpperTolerance; RegionDlgInfo.nRoundRectEllipseWidth = pPaintRegion->nRoundRectEllipseWidth; RegionDlgInfo.nRoundRectEllipseHeight = pPaintRegion->nRoundRectEllipseHeight; nRetCode = m_PaintDialog.DoModalRegion(m_hWnd, &RegionDlgInfo); if(nRetCode == SUCCESS) { pPaintRegion->nSize = sizeof(PAINTREGION); pPaintRegion->dwMask = PRF_ALL; pPaintRegion->crLowerTolerance = RegionDlgInfo.crLowerTolerance; pPaintRegion->crUpperTolerance = RegionDlgInfo.crUpperTolerance; pPaintRegion->nRoundRectEllipseWidth = RegionDlgInfo.nRoundRectEllipseWidth; pPaintRegion->nRoundRectEllipseHeight = RegionDlgInfo.nRoundRectEllipseHeight; m_RasterPntWnd.SetPaintRegion(pPaintRegion); } } void CRstDemoView::OnPropsShape() { CRstDemoApp* pTheApp = (CRstDemoApp*)AfxGetApp(); PAINTDLGSHAPEINFO ShapeDlgInfo; PAINTSHAPE* pPaintShape = m_RasterPntWnd.GetPaintShape(); L_INT nRetCode; L_TCHAR* BKTileBitmap [ ] = { TEXT("Blocks") }; L_TCHAR* BorderTileBitmap [ ] = { TEXT("Border-00") }; L_TCHAR* TextureBitmap [ ] = { TEXT("Texture-00") }; ShapeDlgInfo.dwFlags = PAINT_DLG_SHAPE_SHOWALL; ShapeDlgInfo.pszTitle = TEXT("Shape Properties"); ShapeDlgInfo.nBackgroundStyle = pPaintShape->nBackgroundStyle; ShapeDlgInfo.crBackgroundColor = pPaintShape->crBackgroundColor; ShapeDlgInfo.ppszBackgroundTileBitmap = BKTileBitmap; ShapeDlgInfo.uBackgroundTileBitmapCount = 1; ShapeDlgInfo.nActiveBackgroundTileBitmapItem = 0; ShapeDlgInfo.nBorderStyle = pPaintShape->nBorderStyle; ShapeDlgInfo.nBorderBrushStyle = pPaintShape->nBorderBrushStyle; ShapeDlgInfo.crBorderColor = pPaintShape->crBorderColor; ShapeDlgInfo.ppszBorderTileBitmap = BorderTileBitmap; ShapeDlgInfo.uBorderTileBitmapCount = 1; ShapeDlgInfo.nActiveBorderTileBitmapItem = 0; ShapeDlgInfo.nBorderWidth = pPaintShape->nBorderWidth; ShapeDlgInfo.nBorderEndCap = pPaintShape->nBorderEndCap; ShapeDlgInfo.nGradientStyle = pPaintShape->nGradientStyle; ShapeDlgInfo.crGradientStartColor = pPaintShape->crGradientStartColor; ShapeDlgInfo.crGradientEndColor = pPaintShape->crGradientEndColor; ShapeDlgInfo.uGradientSteps = pPaintShape->uGradientSteps; ShapeDlgInfo.nRoundRectEllipseWidth = pPaintShape->nRoundRectEllipseWidth; ShapeDlgInfo.nRoundRectEllipseHeight = pPaintShape->nRoundRectEllipseHeight; ShapeDlgInfo.nOpacity = pPaintShape->nOpacity; ShapeDlgInfo.ppszPaperTexture = TextureBitmap; ShapeDlgInfo.uPaperTextureCount = 1; ShapeDlgInfo.nActivePaperTextureItem = ((pPaintShape->pTexture != NULL) ? 0 : -1); nRetCode = m_PaintDialog.DoModalShape(m_hWnd, &ShapeDlgInfo); if(nRetCode == SUCCESS) { pPaintShape->nSize = sizeof(PAINTSHAPE); pPaintShape->dwMask = PSF_ALL; pPaintShape->nBackgroundStyle = ShapeDlgInfo.nBackgroundStyle; pPaintShape->crBackgroundColor = ShapeDlgInfo.crBackgroundColor; pPaintShape->pBackgroundTileBitmap = ((ShapeDlgInfo.nActiveBackgroundTileBitmapItem != -1) ? pTheApp->m_LBtmpBackTile.GetHandle() : NULL); pPaintShape->nBorderStyle = ShapeDlgInfo.nBorderStyle; pPaintShape->nBorderBrushStyle = ShapeDlgInfo.nBorderBrushStyle; pPaintShape->crBorderColor = ShapeDlgInfo.crBorderColor; pPaintShape->hBorderTileBitmap = ((ShapeDlgInfo.nActiveBorderTileBitmapItem != -1) ? pTheApp->m_hBorderTile : NULL); pPaintShape->nBorderWidth = ShapeDlgInfo.nBorderWidth; pPaintShape->nBorderEndCap = ShapeDlgInfo.nBorderEndCap; pPaintShape->nGradientStyle = ShapeDlgInfo.nGradientStyle; pPaintShape->crGradientStartColor = ShapeDlgInfo.crGradientStartColor; pPaintShape->crGradientEndColor = ShapeDlgInfo.crGradientEndColor; pPaintShape->uGradientSteps = ShapeDlgInfo.uGradientSteps; pPaintShape->nRoundRectEllipseWidth = ShapeDlgInfo.nRoundRectEllipseWidth; pPaintShape->nRoundRectEllipseHeight = ShapeDlgInfo.nRoundRectEllipseHeight; pPaintShape->nOpacity = ShapeDlgInfo.nOpacity; pPaintShape->pTexture = ((ShapeDlgInfo.nActivePaperTextureItem != -1) ? pTheApp->m_LBtmpPaperTexture.GetHandle(): NULL); m_RasterPntWnd.SetPaintShape(pPaintShape); } } void CRstDemoView::OnPropsText() { CRstDemoApp* pTheApp = (CRstDemoApp*)AfxGetApp(); PAINTDLGTEXTINFO TextDlgInfo; PAINTTEXT* pPaintText = m_RasterPntWnd.GetPaintText(); L_INT nRetCode; LOGFONT lf; L_TCHAR* BKTileBitmap [ ] = { TEXT("Blocks") }; L_TCHAR* TextureBitmap [ ] = { TEXT("Texture-00") }; if(pPaintText->hFont != NULL) { GetObject(pPaintText->hFont, sizeof(LOGFONT), &lf); } TextDlgInfo.dwFlags = PAINT_DLG_TEXT_SHOWALL; TextDlgInfo.pszTitle = TEXT("Text Properties"); TextDlgInfo.pszText = pPaintText->pszText; TextDlgInfo.logFont = lf; TextDlgInfo.nBorderBrushStyle = pPaintText->nBorderBrushStyle; TextDlgInfo.nBorderWidth = pPaintText->nBorderWidth; TextDlgInfo.crBorderColor = pPaintText->crBorderColor; TextDlgInfo.nBackgroundStyle = pPaintText->nBackgroundStyle; TextDlgInfo.crBackgroundColor = pPaintText->crBackgroundColor; TextDlgInfo.ppszBackgroundTileBitmap = BKTileBitmap; TextDlgInfo.uBackgroundTileBitmapCount = 1; TextDlgInfo.nActiveBackgroundTileBitmapItem = 0; TextDlgInfo.nAlignment = pPaintText->nAlignment; TextDlgInfo.nOpacity = pPaintText->nOpacity; TextDlgInfo.ppszPaperTexture = TextureBitmap; TextDlgInfo.uPaperTextureCount = 1; TextDlgInfo.nActivePaperTextureItem = ((pPaintText->pTexture != NULL) ? 0 : -1); TextDlgInfo.TransformInfo = pPaintText->TransformInfo; nRetCode = m_PaintDialog.DoModalText(m_hWnd, &TextDlgInfo ); if(nRetCode == SUCCESS) { pPaintText->nSize = sizeof(PAINTTEXT) ; pPaintText->dwMask = PTF_ALL; pPaintText->pszText = TextDlgInfo.pszText; if(pPaintText->hFont != NULL) { DeleteObject(pPaintText->hFont); } pPaintText->hFont = CreateFontIndirect(&TextDlgInfo.logFont); pPaintText->nBorderBrushStyle = TextDlgInfo.nBorderBrushStyle; pPaintText->nBorderWidth = TextDlgInfo.nBorderWidth; pPaintText->crBorderColor = TextDlgInfo.crBorderColor; pPaintText->nBackgroundStyle = TextDlgInfo.nBackgroundStyle; pPaintText->crBackgroundColor = TextDlgInfo.crBackgroundColor; pPaintText->pBackgroundTileBitmap = ((TextDlgInfo.nActiveBackgroundTileBitmapItem != -1) ? pTheApp->m_LBtmpBackTile.GetHandle() : NULL); pPaintText->nAlignment = TextDlgInfo.nAlignment; pPaintText->nOpacity = TextDlgInfo.nOpacity; pPaintText->pTexture = ((TextDlgInfo.nActivePaperTextureItem != -1) ? pTheApp->m_LBtmpPaperTexture.GetHandle() : NULL); pPaintText->TransformInfo = TextDlgInfo.TransformInfo; m_RasterPntWnd.SetPaintText(pPaintText); } } void CRstDemoView::OnEditCopy() { m_RasterPntWnd.Copy(); } void CRstDemoView::OnEditPaste() { m_RasterPntWnd.Paste(); } void CRstDemoView::OnEditRedo() { m_RasterPntWnd.Redo(); } void CRstDemoView::OnUpdateEditRedo(CCmdUI* pCmdUI) { pCmdUI->Enable(m_RasterPntWnd.CanRedo()); } void CRstDemoView::OnUpdateEditUndo(CCmdUI* pCmdUI) { pCmdUI->Enable(m_RasterPntWnd.CanUndo()); } void CRstDemoView::OnEditUndo() { m_RasterPntWnd.Undo(); } void CRstDemoView::OnEditCut() { m_RasterPntWnd.Cut(); } void CRstDemoView::OnEditClear() { m_RasterPntWnd.Delete(); } void CRstDemoView::OnSelectAll() { m_RasterPntWnd.SelectAll(); } void CRstDemoView::OnSelectNone() { m_RasterPntWnd.SelectNone(); } void CRstDemoView::OnFilePrint() { m_RasterPntWnd.Print(); } void CRstDemoView::OnContextMenu(CWnd* pWnd, CPoint point) { CMenu menu; VERIFY(menu.LoadMenu(IDR_FLOAT_MENU)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); pPopup->TrackPopupMenu(TPM_RIGHTBUTTON|TPM_LEFTALIGN, point.x, point.y, this); //TPM_CENTERALIGN | }