// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "ppaint.h" #include "Paint.h" #include "paintcon.h" #include "tbbutton.h" #include "toolbar.h" #include "MainFrm.h" #include "PaintVw.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CPaintApp theApp; ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_WM_DESTROY() ON_COMMAND(ID_VIEW_FLOATTOOLBAR, OnViewFloatToolbar) ON_UPDATE_COMMAND_UI(ID_VIEW_FLOATTOOLBAR, OnUpdateViewFloatToolbar) ON_COMMAND(ID_TOOL_BRUSH, OnToolBrush) ON_UPDATE_COMMAND_UI(ID_TOOL_BRUSH, OnUpdateToolBrush) ON_COMMAND(ID_TOOL_SHAPE_LINE, OnToolShapeLine) ON_UPDATE_COMMAND_UI(ID_TOOL_SHAPE_LINE, OnUpdateToolShapeLine) ON_COMMAND(ID_TOOL_SHAPE_POLYGON, OnToolShapePolygon) ON_UPDATE_COMMAND_UI(ID_TOOL_SHAPE_POLYGON, OnUpdateToolShapePolygon) ON_COMMAND(ID_TOOL_SHAPE_RECTANGLE, OnToolShapeRectangle) ON_UPDATE_COMMAND_UI(ID_TOOL_SHAPE_RECTANGLE, OnUpdateToolShapeRectangle) ON_COMMAND(ID_TOOL_SHAPE_ROUNDRECTANGLE, OnToolShapeRoundrectangle) ON_UPDATE_COMMAND_UI(ID_TOOL_SHAPE_ROUNDRECTANGLE, OnUpdateToolShapeRoundrectangle) ON_COMMAND(ID_TOOL_SHAPE_ELLIPSE, OnToolShapeEllipse) ON_UPDATE_COMMAND_UI(ID_TOOL_SHAPE_ELLIPSE, OnUpdateToolShapeEllipse) ON_COMMAND(ID_TOOL_REGION_BORDER, OnToolRegionBorder) ON_UPDATE_COMMAND_UI(ID_TOOL_REGION_BORDER, OnUpdateToolRegionBorder) ON_COMMAND(ID_TOOL_REGION_CANCEL, OnToolRegionCancel) ON_UPDATE_COMMAND_UI(ID_TOOL_REGION_CANCEL, OnUpdateToolRegionCancel) ON_COMMAND(ID_TOOL_REGION_COLOR, OnToolRegionColor) ON_UPDATE_COMMAND_UI(ID_TOOL_REGION_COLOR, OnUpdateToolRegionColor) ON_COMMAND(ID_TOOL_REGION_ELLIPSE, OnToolRegionEllipse) ON_UPDATE_COMMAND_UI(ID_TOOL_REGION_ELLIPSE, OnUpdateToolRegionEllipse) ON_COMMAND(ID_TOOL_REGION_POLYGON, OnToolRegionPolygon) ON_UPDATE_COMMAND_UI(ID_TOOL_REGION_POLYGON, OnUpdateToolRegionPolygon) ON_COMMAND(ID_TOOL_REGION_RECTANGLE, OnToolRegionRectangle) ON_UPDATE_COMMAND_UI(ID_TOOL_REGION_RECTANGLE, OnUpdateToolRegionRectangle) ON_COMMAND(ID_TOOL_REGION_ROUNDRECTANGLE, OnToolRegionRoundrectangle) ON_UPDATE_COMMAND_UI(ID_TOOL_REGION_ROUNDRECTANGLE, OnUpdateToolRegionRoundrectangle) ON_COMMAND(ID_TOOL_REGION_SURFACE, OnToolRegionSurface) ON_UPDATE_COMMAND_UI(ID_TOOL_REGION_SURFACE, OnUpdateToolRegionSurface) ON_COMMAND(ID_TOOL_FILL_BORDER, OnToolFillBorder) ON_UPDATE_COMMAND_UI(ID_TOOL_FILL_BORDER, OnUpdateToolFillBorder) ON_COMMAND(ID_TOOL_FILL_COLORREPLACE, OnToolFillColorreplace) ON_UPDATE_COMMAND_UI(ID_TOOL_FILL_COLORREPLACE, OnUpdateToolFillColorreplace) ON_COMMAND(ID_TOOL_FILL_SURFACE, OnToolFillSurface) ON_UPDATE_COMMAND_UI(ID_TOOL_FILL_SURFACE, OnUpdateToolFillSurface) ON_COMMAND(ID_TOOL_TEXT, OnToolText) ON_UPDATE_COMMAND_UI(ID_TOOL_TEXT, OnUpdateToolText) ON_COMMAND(ID_OPTIONS_BRUSH, OnOptionsBrush) ON_COMMAND(ID_OPTIONS_SHAPE, OnOptionsShape) ON_COMMAND(ID_OPTIONS_REGION, OnOptionsRegion) ON_COMMAND(ID_OPTIONS_FILL, OnOptionsFill) ON_COMMAND(ID_OPTIONS_TEXT, OnOptionsText) ON_WM_QUERYNEWPALETTE() ON_WM_PALETTECHANGED() ON_WM_PALETTEISCHANGING() ON_WM_SYSCOLORCHANGE() //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator //ID_CUSTOM_PANE, //ID_CUSTOM_PANE2, ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { m_pToolbar = NULL; m_nToolType = TOOL_NONE; m_pToolbarSink=NULL; } CMainFrame::~CMainFrame() { } static const WCHAR BASED_CODE _szLicString[] = L"LEADTOOLS OCX Copyright (c) 1991-2004 LEAD Technologies, Inc."; int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); // pass the license string to the CLead::Create function. //The CLead::Create expects a BSTR parameter and SysAllocString converts the // WCHAR[] to a BSTR BSTR lpLic = SysAllocString(_szLicString); m_Lead.Create("", 0,CRect(0,0,50,50),this,0,NULL,FALSE,lpLic); m_oToolBar.Create("", 0, CRect(0,0,10,10), this, 0, NULL, FALSE,lpLic); m_LeadPaper.Create("", 0, CRect(0,0,10,10), this, 0, NULL, FALSE,lpLic); m_LeadBackground.Create("", 0, CRect(0,0,10,10), this, 0, NULL, FALSE,lpLic); m_LeadTouch.Create("", 0, CRect(0,0,10,10), this, 0, NULL, FALSE,lpLic); m_LeadBorder.Create("", 0, CRect(0,0,10,10), this, 0, NULL, FALSE,lpLic); m_LeadTemp.Create("", 0, CRect(0,0,10,10), this, 0, NULL, FALSE,lpLic); m_LeadPaint.Create("", 0, CRect(0,0,10,10), this, IDC_LEADPAINTCTRL1, NULL, FALSE,lpLic); // connect our sink to the toolbar ocx control LPUNKNOWN pUnkToolbar = m_oToolBar.GetControlUnknown(); m_pToolbarSink = NULL; m_dwCookie = 0; m_pToolbarSink = new CToolbarSink; LPUNKNOWN pUnkSink = m_pToolbarSink->GetIDispatch(FALSE); AfxConnectionAdvise(pUnkToolbar, DIID__LEADToolBarEvents, pUnkSink, FALSE, &m_dwCookie); m_pToolbarSink->m_pMainWnd = this; UNLOCKSUPPORT(m_Lead); m_Lead.ShowWindow(SW_HIDE); SysFreeString(lpLic); LoadResourceBitmap(IDB_BITMAP_PAPER); m_LeadPaper.SetBitmap( m_LeadTemp.GetBitmap()); LoadResourceBitmap(IDB_BITMAP_BACKGROUND); m_LeadBackground.SetBitmap( m_LeadTemp.GetBitmap()); LoadResourceBitmap(IDB_BITMAP_TOUCH); m_LeadTouch.SetBitmap( m_LeadTemp.GetBitmap()); LoadResourceBitmap(IDB_BITMAP_BORDER); m_LeadBorder.SetBitmap( m_LeadTemp.GetBitmap()); m_LeadPaint.SetPaintUserMode(PAINT_USERMODE_AUTO); CreateToolbar(); m_LeadPaint.SetToolbarControl(m_pToolbar); //Set up all dialog data CreateDefaultObjects(); CRect rc; GetWindowRect(&rc); m_oToolBar.SetXPosition(rc.left + 25); m_oToolBar.SetYPosition(rc.top + 50); m_oToolBar.SetVisible(TRUE); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CMDIFrameWnd::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CMDIFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CMDIFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers void CMainFrame::UpdateStatusBar(LPCSTR pszMsg, int nPane) { if (pszMsg == NULL) pszMsg = ""; m_wndStatusBar.SetPaneText(nPane, pszMsg); } void CMainFrame::OnDestroy() { //Terminate a connection between source and sink. if(m_pToolbarSink) { LPUNKNOWN pUnkSink = m_pToolbarSink->GetIDispatch(FALSE); LPUNKNOWN pUnkToolbar = m_oToolBar.GetControlUnknown(); AfxConnectionUnadvise(pUnkToolbar, DIID__LEADToolBarEvents, pUnkSink, FALSE, m_dwCookie); delete m_pToolbarSink; } m_LeadPaint.SetToolbarControl(NULL); //release the toolbar CMDIFrameWnd::OnDestroy(); } void CMainFrame::CreateToolbar() { static BOOL b = FALSE; //only do this once //////////////////////Initialize and create tool bar if(!b) { int nRet = m_oToolBar.CreateToolbar((long)this->m_hWnd, "Paint Tools", TOOLBAR_PAINT); m_oToolBar.SetRowCount(1); //setup toolbar m_pToolbar = NULL; m_pToolbar = (LPDISPATCH)m_oToolBar.GetControlUnknown(); b=TRUE; } } void CMainFrame::LoadResourceBitmap(long nResourceID) { HRSRC hRsrc; HGLOBAL hGlobal; HBITMAP hBitmapFinal = NULL; LPBITMAPINFOHEADER lpbi; HDC hdc; int iNumColors; HPALETTE hPalette; if (hRsrc = ::FindResource(theApp.m_hInstance, MAKEINTRESOURCE(nResourceID), RT_BITMAP)) { hGlobal = ::LoadResource(theApp.m_hInstance, hRsrc); lpbi = (LPBITMAPINFOHEADER)::LockResource(hGlobal); hdc = ::GetDC(NULL); hPalette = CreateDIBPalette((LPBITMAPINFO)lpbi, &iNumColors); if (hPalette) { SelectPalette(hdc,hPalette,FALSE); RealizePalette(hdc); } hBitmapFinal = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)lpbi, (LONG)CBM_INIT, (LPSTR)lpbi + lpbi->biSize + iNumColors * sizeof(RGBQUAD), (LPBITMAPINFO)lpbi, DIB_RGB_COLORS ); m_LeadTemp.SetDDB( (long)hdc, (long)hBitmapFinal, (long)hPalette); ::ReleaseDC(NULL,hdc); UnlockResource(hGlobal); FreeResource(hGlobal); ::DeleteObject(hPalette); ::DeleteObject(hBitmapFinal); } } HPALETTE CMainFrame::CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors) { LPBITMAPINFOHEADER lpbi; LPLOGPALETTE lpPal; HANDLE hLogPal; HPALETTE hPal = NULL; int i; lpbi = (LPBITMAPINFOHEADER)lpbmi; if (lpbi->biBitCount <= 8) *lpiNumColors = (1 << lpbi->biBitCount); else *lpiNumColors = 0; // No palette needed for 24 BPP DIB if (lpbi->biClrUsed > 0) *lpiNumColors = lpbi->biClrUsed; // Use biClrUsed if (*lpiNumColors) { hLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) + sizeof (PALETTEENTRY) * (*lpiNumColors)); lpPal = (LPLOGPALETTE) GlobalLock (hLogPal); lpPal->palVersion = 0x300; lpPal->palNumEntries = *lpiNumColors; for (i = 0; i < *lpiNumColors; i++) { lpPal->palPalEntry[i].peRed = lpbmi->bmiColors[i].rgbRed; lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen; lpPal->palPalEntry[i].peBlue = lpbmi->bmiColors[i].rgbBlue; lpPal->palPalEntry[i].peFlags = 0; } hPal = CreatePalette (lpPal); GlobalUnlock (hLogPal); GlobalFree (hLogPal); } return hPal; } void CMainFrame::CreateDefaultObjects() { //create a Brushobject //set some properties m_LeadPaint.GetBrush().SetTouchShape(BRUSH_TOUCH_SHAPE_CIRCLE); m_LeadPaint.GetBrush().SetTouchContentsType(BRUSH_TOUCH_CONTENTS_COLOR); m_LeadPaint.GetBrush().SetTouchTransparentColor(RGB(0,0,0)); m_LeadPaint.GetBrush().SetTouchBitmap(m_LeadTouch.GetBitmap()); m_LeadPaint.GetBrush().SetTouchColor(RGB(0,0,0)); m_LeadPaint.GetBrush().SetDiameter(1); m_LeadPaint.GetBrush().SetHardnessDistributionType(BRUSH_HD_TYPE_0); m_LeadPaint.GetBrush().SetHardnessValue(1); m_LeadPaint.GetBrush().SetSpacing(1); m_LeadPaint.GetBrush().SetOpacity(0); m_LeadPaint.GetBrush().SetDensity(100); m_LeadPaint.GetBrush().SetFadeOutRate(0); //create Shapeobject //set some properties m_LeadPaint.GetShape().SetBackgroundStyle(SHAPE_BACKSTYLE_GRADIENT); m_LeadPaint.GetShape().SetBackgroundColor(RGB(255,0,0)); m_LeadPaint.GetShape().SetBorderStyle(SHAPE_BORDERSTYLE_SOLID); m_LeadPaint.GetShape().SetBorderWidth(3); m_LeadPaint.GetShape().SetBorderBrushStyle(SHAPE_BORDERBRUSHSTYLE_COLOR); m_LeadPaint.GetShape().SetBorderColor(RGB(0,0,0)); m_LeadPaint.GetShape().SetGradientStyle(SHAPE_GRADIENTSTYLE_CONE_FROM_LT); m_LeadPaint.GetShape().SetGradientStartColor(RGB(255,0,0)); m_LeadPaint.GetShape().SetGradientEndColor(RGB(0,0,255)); m_LeadPaint.GetShape().SetGradientSteps(255); m_LeadPaint.GetShape().SetBorderEndCap(SHAPE_BORDERENDCAP_ROUND); m_LeadPaint.GetShape().SetRoundRectEllipseHeight(25); m_LeadPaint.GetShape().SetRoundRectEllipseWidth(25); m_LeadPaint.GetShape().SetOpacity(0); m_LeadPaint.GetShape().SetBackgroundTileBitmap(m_LeadBackground.GetBitmap()); m_LeadPaint.GetShape().SetBorderTileBitmap(m_LeadBorder.GetBitmap()); //create a Region object //set some properties m_LeadPaint.GetRegion().SetLowerTolerance(RGB(25,25,25)); m_LeadPaint.GetRegion().SetUpperTolerance(RGB(25,25,25)); m_LeadPaint.GetRegion().SetRoundRectEllipseWidth(25); m_LeadPaint.GetRegion().SetRoundRectEllipseHeight(25); //create a Fill object //set some properties m_LeadPaint.GetFill().SetStyle(FILL_FILLSTYLE_SOLID); m_LeadPaint.GetFill().SetGradientStyle(FILL_GRADIENTSTYLE_LINE_L_TO_R); //m_LeadPaint.GetFill().SetGradientDirection(); m_LeadPaint.GetFill().SetSolidFillColor(RGB(255,0,0)); m_LeadPaint.GetFill().SetUpperTolerance(RGB(20,20,20)); m_LeadPaint.GetFill().SetLowerTolerance(RGB(20,20,20)); m_LeadPaint.GetFill().SetOpacity(1); m_LeadPaint.GetFill().SetBackgroundTileBitmap(m_LeadBackground.GetBitmap()); //create Text object //set some properties m_LeadPaint.GetText().GetFont().SetName("Arial"); m_LeadPaint.GetText().GetFont().SetBold(TRUE); m_LeadPaint.GetText().GetFont().SetItalic(TRUE); m_LeadPaint.GetText().GetFont().SetSize(20); m_LeadPaint.GetText().SetBorderBrushStyle(TEXT_BORDER_BRUSHSTYLE_COLOR); m_LeadPaint.GetText().SetBorderWidth(1); m_LeadPaint.GetText().SetBorderColor(RGB(255,0,0)); m_LeadPaint.GetText().SetBackgroundStyle(TEXT_BACKSTYLE_OPAQUE); m_LeadPaint.GetText().SetBackgroundColor(RGB(0,0,255)); m_LeadPaint.GetText().SetAlignment(PAINT_ALIGN_HCENTER | PAINT_ALIGN_VCENTER); m_LeadPaint.GetText().SetOpacity(1); m_LeadPaint.GetText().SetBackgroundTileBitmap(m_LeadBackground.GetBitmap()); m_LeadPaint.GetText().SetString("LEADTOOLS!"); } BEGIN_EVENTSINK_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_EVENTSINK_MAP(CMainFrame) ON_EVENT(CMainFrame, IDC_LEADPAINTCTRL1, 1 /* PaintContainer */, OnPaintContainerLeadpaintctrl1, VTS_I4 VTS_I2 VTS_I2 VTS_I2 VTS_I2) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CMainFrame::OnPaintContainerLeadpaintctrl1(long hWndContainer, short nEventType, short nObjectType, short nState, short nStatus) { float Zoom; //this will check the automation action. //if it was Zoom, then it will update the Main control //and then update the XForm CMDIChildWnd *pChild = MDIGetActive(); if(!pChild) return; CPaintView* pView = (CPaintView*)pChild->GetActiveView(); if(pView) { if(nEventType == PAINT_CONTAINER_EVENT_DRAW) { if(nObjectType == PAINT_CONTAINER_OBJECT_TYPE_POINT) { if(m_oToolBar.GetButton(BUTTON_ID_TOOL_PAINT_ZOOM).GetChecked()) { if((nState == PAINT_CONTAINER_STATE_END) && (nStatus == 0)) { Zoom = (float)(m_LeadPaint.GetAutoContainer((long)pView->m_Lead.m_hWnd)).GetScalarNumX() / (float)m_LeadPaint.GetAutoContainer((long)pView->m_Lead.m_hWnd).GetScalarDenX(); Zoom = Zoom * 100; if(pView->m_Lead.GetPaintZoomFactor() != Zoom) { pView->m_Lead.SetPaintZoomFactor(Zoom); pView->UpdateXForm(); } } } } } } } void CMainFrame::OnViewFloatToolbar() { m_oToolBar.SetVisible( !m_oToolBar.GetVisible() ); } void CMainFrame::OnUpdateViewFloatToolbar(CCmdUI* pCmdUI) { pCmdUI->SetCheck( m_oToolBar.GetVisible() ); } void CMainFrame::OnToolBrush() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_BRUSH) { m_nToolType = BUTTON_ID_TOOL_PAINT_BRUSH; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolBrush(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_BRUSH); } void CMainFrame::OnToolShapeLine() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_SHAPE_LINE) { m_nToolType = BUTTON_ID_TOOL_PAINT_SHAPE_LINE; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolShapeLine(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_SHAPE_LINE); } void CMainFrame::OnToolShapePolygon() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_SHAPE_POLYGON) { m_nToolType = BUTTON_ID_TOOL_PAINT_SHAPE_POLYGON; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolShapePolygon(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_SHAPE_POLYGON); } void CMainFrame::OnToolShapeRectangle() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_SHAPE_RECT) { m_nToolType = BUTTON_ID_TOOL_PAINT_SHAPE_RECT; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolShapeRectangle(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_SHAPE_RECT); } void CMainFrame::OnToolShapeRoundrectangle() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_SHAPE_ROUNDRECT) { m_nToolType = BUTTON_ID_TOOL_PAINT_SHAPE_ROUNDRECT; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolShapeRoundrectangle(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_SHAPE_ROUNDRECT); } void CMainFrame::OnToolShapeEllipse() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_SHAPE_ELLIPSE) { m_nToolType = BUTTON_ID_TOOL_PAINT_SHAPE_ELLIPSE; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolShapeEllipse(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_SHAPE_ELLIPSE); } void CMainFrame::OnToolRegionBorder() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_REGION_BORDER) { m_nToolType = BUTTON_ID_TOOL_PAINT_REGION_BORDER; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolRegionBorder(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_REGION_BORDER); } void CMainFrame::OnToolRegionCancel() { m_LeadPaint.SetClipRgn(NULL); m_LeadPaint.AutoSelect(PAINT_AUTOMATION_SELTYPE_NONE, 0); CMDIChildWnd *pChild = (CMDIChildWnd *) MDIGetActive(); if(pChild) { CPaintView *pView = (CPaintView *) pChild->GetActiveView(); if(pView) { pView->m_Lead.FreeRgn(); pView->UpdatePaintMetrics(); pView->m_Lead.ForceRepaint(); } } } void CMainFrame::OnUpdateToolRegionCancel(CCmdUI* pCmdUI) { CMDIChildWnd *pChild = (CMDIChildWnd *) MDIGetActive(); if(pChild) { CPaintView *pView = (CPaintView *) pChild->GetActiveView(); if(pView) { pCmdUI->Enable(pView->m_Lead.GetHasRgn()==TRUE); } } } void CMainFrame::OnToolRegionColor() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_REGION_COLOR) { m_nToolType = BUTTON_ID_TOOL_PAINT_REGION_COLOR; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolRegionColor(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_REGION_COLOR); } void CMainFrame::OnToolRegionEllipse() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_REGION_ELLIPSE) { m_nToolType = BUTTON_ID_TOOL_PAINT_REGION_ELLIPSE; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolRegionEllipse(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_REGION_ELLIPSE); } void CMainFrame::OnToolRegionPolygon() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_REGION_POLYGON) { m_nToolType = BUTTON_ID_TOOL_PAINT_REGION_POLYGON; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolRegionPolygon(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_REGION_POLYGON); } void CMainFrame::OnToolRegionRectangle() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_REGION_RECT) { m_nToolType = BUTTON_ID_TOOL_PAINT_REGION_RECT; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolRegionRectangle(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_REGION_RECT); } void CMainFrame::OnToolRegionRoundrectangle() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_REGION_ROUNDRECT) { m_nToolType = BUTTON_ID_TOOL_PAINT_REGION_ROUNDRECT; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolRegionRoundrectangle(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_REGION_ROUNDRECT); } void CMainFrame::OnToolRegionSurface() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_REGION_SURFACE) { m_nToolType = BUTTON_ID_TOOL_PAINT_REGION_SURFACE; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolRegionSurface(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_REGION_SURFACE); } void CMainFrame::OnToolFillBorder() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_FILL_BORDER) { m_nToolType = BUTTON_ID_TOOL_PAINT_FILL_BORDER; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolFillBorder(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_FILL_BORDER); } void CMainFrame::OnToolFillColorreplace() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_FILL_COLORREPLACE) { m_nToolType = BUTTON_ID_TOOL_PAINT_FILL_COLORREPLACE; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolFillColorreplace(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_FILL_COLORREPLACE); } void CMainFrame::OnToolFillSurface() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_FILL_SURFACE) { m_nToolType = BUTTON_ID_TOOL_PAINT_FILL_SURFACE; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolFillSurface(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_FILL_SURFACE); } void CMainFrame::OnToolText() { if(m_nToolType != BUTTON_ID_TOOL_PAINT_TEXT) { m_nToolType = BUTTON_ID_TOOL_PAINT_TEXT; m_oToolBar.GetButton(m_nToolType).SetChecked(TRUE); } } void CMainFrame::OnUpdateToolText(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nToolType == BUTTON_ID_TOOL_PAINT_TEXT); } void CMainFrame::OnOptionsBrush() { int nRet; m_LeadPaint.SetEnableMethodErrors(FALSE); m_LeadPaint.SetDlgTitle("Brush Options"); m_LeadPaint.SetDlgOpacity(m_LeadPaint.GetBrush().GetOpacity()); m_LeadPaint.SetDlgFlags(PAINT_DLG_BRUSH_SHOWALL); m_LeadPaint.SetDlgTouchImageCount(1); m_LeadPaint.SetDlgTouchImage(0, "Leaves"); m_LeadPaint.SetDlgPaperTextureCount(1); m_LeadPaint.SetDlgPaperTexture(0, "Texture1"); if (m_LeadPaint.GetBrush().GetTexture()) m_LeadPaint.SetDlgPaperTextureIndex(0); else m_LeadPaint.SetDlgPaperTextureIndex(-1); nRet = m_LeadPaint.ShowBrushDlg((long)m_hWnd); if (nRet == 0) { m_LeadPaint.GetBrush().SetTouchColor (m_LeadPaint.GetDlgTouchColor()); m_LeadPaint.GetBrush().SetTouchContentsType( m_LeadPaint.GetDlgTouchContentsType()); m_LeadPaint.GetBrush().SetDiameter(m_LeadPaint.GetDlgDiameter()); m_LeadPaint.GetBrush().SetHardnessValue (m_LeadPaint.GetDlgHardnessValue()); m_LeadPaint.GetBrush().SetSpacing(m_LeadPaint.GetDlgSpacing()); m_LeadPaint.GetBrush().SetOpacity(m_LeadPaint.GetDlgOpacity()); m_LeadPaint.GetBrush().SetDensity(m_LeadPaint.GetDlgDensity()); m_LeadPaint.GetBrush().SetFadeOutRate(m_LeadPaint.GetDlgFadeOut()); if (m_LeadPaint.GetDlgPaperTextureIndex() == 0) { m_LeadPaint.GetBrush().SetTexture(m_LeadPaper.GetBitmap()); } else { m_LeadPaint.GetBrush().SetTexture(0); } } } void CMainFrame::OnOptionsShape() { int nRet; m_LeadPaint.SetEnableMethodErrors(FALSE); m_LeadPaint.SetDlgTitle("ShapeOptions"); m_LeadPaint.SetDlgOpacity(m_LeadPaint.GetShape().GetOpacity()); m_LeadPaint.SetDlgFlags(PAINT_DLG_SHAPE_SHOWALL); m_LeadPaint.SetDlgShapeBackgroundStyle(m_LeadPaint.GetShape().GetBackgroundStyle()); m_LeadPaint.SetDlgBackgroundColor(m_LeadPaint.GetShape().GetBackgroundColor()); m_LeadPaint.SetDlgShapeGradientStyle(m_LeadPaint.GetShape().GetGradientStyle()); m_LeadPaint.SetDlgGradientStartColor(m_LeadPaint.GetShape().GetGradientStartColor()); m_LeadPaint.SetDlgGradientEndColor(m_LeadPaint.GetShape().GetGradientEndColor()); m_LeadPaint.SetDlgGradientSteps(m_LeadPaint.GetShape().GetGradientSteps()); m_LeadPaint.SetDlgRoundRectEllipseWidth(m_LeadPaint.GetShape().GetRoundRectEllipseWidth()); m_LeadPaint.SetDlgRoundRectEllipseHeight(m_LeadPaint.GetShape().GetRoundRectEllipseHeight()); m_LeadPaint.SetDlgPaperTextureCount(1); m_LeadPaint.SetDlgPaperTexture(0,"Texture1"); if(m_LeadPaint.GetShape().GetTexture()!=0) m_LeadPaint.SetDlgPaperTextureIndex(0); else m_LeadPaint.SetDlgPaperTextureIndex(-1); m_LeadPaint.SetDlgBackgroundTileBitmapCount(1); m_LeadPaint.SetDlgBackgroundTileBitmap(0,"Tile0"); m_LeadPaint.SetDlgBorderTileBitmapCount(1); m_LeadPaint.SetDlgBorderTileBitmap(0,"Border0"); m_LeadPaint.SetDlgBorderStyle(m_LeadPaint.GetShape().GetBorderStyle()); m_LeadPaint.SetDlgBorderWidth((short)m_LeadPaint.GetShape().GetBorderWidth()); m_LeadPaint.SetDlgShapeBorderBrushStyle(m_LeadPaint.GetShape().GetBorderBrushStyle()); m_LeadPaint.SetDlgBorderColor(m_LeadPaint.GetShape().GetBorderColor()); m_LeadPaint.SetDlgBorderEndCap(m_LeadPaint.GetShape().GetBorderEndCap()); nRet=m_LeadPaint.ShowShapeDlg((long)m_hWnd); if(nRet==0) { m_LeadPaint.GetShape().SetBackgroundStyle(m_LeadPaint.GetDlgShapeBackgroundStyle()); m_LeadPaint.GetShape().SetBackgroundColor(m_LeadPaint.GetDlgBackgroundColor()); m_LeadPaint.GetShape().SetGradientStyle(m_LeadPaint.GetDlgShapeGradientStyle()); m_LeadPaint.GetShape().SetGradientStartColor(m_LeadPaint.GetDlgGradientStartColor()); m_LeadPaint.GetShape().SetGradientEndColor(m_LeadPaint.GetDlgGradientEndColor()); m_LeadPaint.GetShape().SetGradientSteps(m_LeadPaint.GetDlgGradientSteps()); m_LeadPaint.GetShape().SetRoundRectEllipseWidth(m_LeadPaint.GetDlgRoundRectEllipseWidth()); m_LeadPaint.GetShape().SetRoundRectEllipseHeight(m_LeadPaint.GetDlgRoundRectEllipseHeight()); m_LeadPaint.GetShape().SetOpacity(m_LeadPaint.GetDlgOpacity()); if(m_LeadPaint.GetDlgPaperTextureIndex()==0) m_LeadPaint.GetShape().SetTexture(m_LeadBackground.GetBitmap()); else m_LeadPaint.GetShape().SetTexture(0); m_LeadPaint.GetShape().SetBorderStyle(m_LeadPaint.GetDlgBorderStyle()); m_LeadPaint.GetShape().SetBorderWidth(m_LeadPaint.GetDlgBorderWidth()); m_LeadPaint.GetShape().SetBorderBrushStyle(m_LeadPaint.GetDlgShapeBorderBrushStyle()); m_LeadPaint.GetShape().SetBorderColor(m_LeadPaint.GetDlgBorderColor()); m_LeadPaint.GetShape().SetBorderEndCap(m_LeadPaint.GetDlgBorderEndCap()); } } void CMainFrame::OnOptionsRegion() { int nRet; m_LeadPaint.SetEnableMethodErrors(FALSE); m_LeadPaint.SetDlgTitle ( "Region Options"); m_LeadPaint.SetDlgFlags ( PAINT_DLG_REGION_SHOWALL); m_LeadPaint.SetDlgUpperTolerance ( m_LeadPaint.GetRegion().GetUpperTolerance()); m_LeadPaint.SetDlgLowerTolerance ( m_LeadPaint.GetRegion().GetLowerTolerance()); m_LeadPaint.SetDlgRoundRectEllipseWidth ( m_LeadPaint.GetRegion().GetRoundRectEllipseWidth()); m_LeadPaint.SetDlgRoundRectEllipseHeight ( m_LeadPaint.GetRegion().GetRoundRectEllipseHeight()); nRet = m_LeadPaint.ShowRegionDlg((long)m_hWnd); if (nRet == 0) { m_LeadPaint.GetRegion().SetUpperTolerance ( m_LeadPaint.GetDlgUpperTolerance()); m_LeadPaint.GetRegion().SetLowerTolerance ( m_LeadPaint.GetDlgLowerTolerance()); m_LeadPaint.GetRegion().SetRoundRectEllipseWidth ( m_LeadPaint.GetDlgRoundRectEllipseWidth()); m_LeadPaint.GetRegion().SetRoundRectEllipseHeight ( m_LeadPaint.GetDlgRoundRectEllipseHeight()); } } void CMainFrame::OnOptionsFill() { int nRet; m_LeadPaint.SetEnableMethodErrors(FALSE); m_LeadPaint.SetDlgTitle ( "Fill Options"); m_LeadPaint.SetDlgFlags ( PAINT_DLG_SHAPE_SHOWALL); m_LeadPaint.SetDlgFillStyle ( m_LeadPaint.GetFill().GetStyle()); m_LeadPaint.SetDlgSolidFillColor ( m_LeadPaint.GetFill().GetSolidFillColor()); m_LeadPaint.SetDlgFillGradientStyle ( m_LeadPaint.GetFill().GetGradientStyle()); m_LeadPaint.SetDlgGradientStartColor ( m_LeadPaint.GetFill().GetGradientStartColor()); m_LeadPaint.SetDlgGradientEndColor ( m_LeadPaint.GetFill().GetGradientEndColor()); m_LeadPaint.SetDlgGradientSteps ( m_LeadPaint.GetFill().GetGradientSteps()); m_LeadPaint.SetDlgOpacity ( m_LeadPaint.GetFill().GetOpacity()); m_LeadPaint.SetDlgBackgroundTileBitmapCount ( 1); m_LeadPaint.SetDlgBackgroundTileBitmap(0, "Tile 0"); m_LeadPaint.SetDlgPaperTextureCount ( 1); m_LeadPaint.SetDlgPaperTexture(0, "Texture1"); if (m_LeadPaint.GetFill().GetTexture() != 0) { m_LeadPaint.SetDlgPaperTextureIndex ( 0); } else { m_LeadPaint.SetDlgPaperTextureIndex ( -1); } m_LeadPaint.SetDlgUpperTolerance ( m_LeadPaint.GetFill().GetUpperTolerance()); m_LeadPaint.SetDlgLowerTolerance ( m_LeadPaint.GetFill().GetLowerTolerance()); nRet = m_LeadPaint.ShowFillDlg((long)m_hWnd); if (nRet == 0) { m_LeadPaint.GetFill().SetStyle(m_LeadPaint.GetDlgFillStyle()); m_LeadPaint.GetFill().SetSolidFillColor(m_LeadPaint.GetDlgSolidFillColor()); m_LeadPaint.GetFill().SetGradientStyle ( m_LeadPaint.GetDlgFillGradientStyle()); m_LeadPaint.GetFill().SetGradientStartColor ( m_LeadPaint.GetDlgGradientStartColor()); m_LeadPaint.GetFill().SetGradientEndColor ( m_LeadPaint.GetDlgGradientEndColor()); m_LeadPaint.GetFill().SetGradientSteps ( m_LeadPaint.GetDlgGradientSteps()); m_LeadPaint.GetFill().SetOpacity ( m_LeadPaint.GetDlgOpacity()); if (m_LeadPaint.GetDlgPaperTextureIndex() == 0) { m_LeadPaint.GetFill().SetTexture ( m_LeadPaper.GetBitmap()); } else { m_LeadPaint.GetFill().SetTexture ( 0); } m_LeadPaint.GetFill().SetUpperTolerance ( m_LeadPaint.GetDlgUpperTolerance()); m_LeadPaint.GetFill().SetLowerTolerance ( m_LeadPaint.GetDlgLowerTolerance()); } } void CMainFrame::OnOptionsText() { int nRet; m_LeadPaint.SetEnableMethodErrors(FALSE); m_LeadPaint.SetDlgTitle ( "Text Options"); m_LeadPaint.SetDlgFlags ( PAINT_DLG_TEXT_SHOWALL); m_LeadPaint.SetDlgTextString ( m_LeadPaint.GetText().GetString()); m_LeadPaint.SetDlgOpacity ( m_LeadPaint.GetText().GetOpacity()); m_LeadPaint.GetDlgTextFont().SetBold ( m_LeadPaint.GetText().GetFont().GetBold()); m_LeadPaint.GetDlgTextFont().SetItalic ( m_LeadPaint.GetText().GetFont().GetItalic()); m_LeadPaint.GetDlgTextFont().SetName ( m_LeadPaint.GetText().GetFont().GetName()); m_LeadPaint.GetDlgTextFont().SetSize ( m_LeadPaint.GetText().GetFont().GetSize()); m_LeadPaint.SetDlgBackgroundTileBitmapCount ( 1); m_LeadPaint.SetDlgBackgroundTileBitmap(0, "Tile 0"); m_LeadPaint.SetDlgPaperTextureCount ( 1); m_LeadPaint.SetDlgPaperTexture(0, "Texture1"); if (m_LeadPaint.GetText().GetTexture ()!= 0) { m_LeadPaint.SetDlgPaperTextureIndex ( 0); } else { m_LeadPaint.SetDlgPaperTextureIndex ( -1); } m_LeadPaint.SetDlgTextBackgroundStyle ( m_LeadPaint.GetText().GetBackgroundStyle()); m_LeadPaint.SetDlgBackgroundColor ( m_LeadPaint.GetText().GetBackgroundColor()); m_LeadPaint.SetDlgTextBorderBrushStyle ( m_LeadPaint.GetText().GetBorderBrushStyle()); m_LeadPaint.SetDlgBorderWidth ( (short)m_LeadPaint.GetText().GetBorderWidth()); m_LeadPaint.SetDlgBorderColor ( m_LeadPaint.GetText().GetBorderColor()); m_LeadPaint.SetDlgAlignment ( m_LeadPaint.GetText().GetAlignment()); m_LeadPaint.SetDlgTransformRotate ( m_LeadPaint.GetText().GetTransformRotate()); m_LeadPaint.SetDlgTransformScaleX ( m_LeadPaint.GetText().GetTransformScaleX()); m_LeadPaint.SetDlgTransformScaleY ( m_LeadPaint.GetText().GetTransformScaleY()); nRet = m_LeadPaint.ShowTextDlg((long)m_hWnd); if (nRet == 0) { m_LeadPaint.GetText().SetString(m_LeadPaint.GetDlgTextString()); m_LeadPaint.GetText().GetFont().SetBold( m_LeadPaint.GetDlgTextFont().GetBold()); m_LeadPaint.GetText().GetFont().SetItalic ( m_LeadPaint.GetDlgTextFont().GetItalic()); m_LeadPaint.GetText().GetFont().SetName ( m_LeadPaint.GetDlgTextFont().GetName()); m_LeadPaint.GetText().GetFont().SetSize ( m_LeadPaint.GetDlgTextFont().GetSize()); m_LeadPaint.GetText().SetOpacity ( m_LeadPaint.GetDlgOpacity()); if (m_LeadPaint.GetDlgPaperTextureIndex () == 0) { m_LeadPaint.GetText().SetTexture ( m_LeadPaper.GetBitmap()); } else { m_LeadPaint.GetText().SetTexture ( 0); } m_LeadPaint.GetText().SetBackgroundStyle ( m_LeadPaint.GetDlgTextBackgroundStyle()); m_LeadPaint.GetText().SetBackgroundColor ( m_LeadPaint.GetDlgBackgroundColor()); m_LeadPaint.GetText().SetBorderBrushStyle ( m_LeadPaint.GetDlgTextBorderBrushStyle()); m_LeadPaint.GetText().SetBorderWidth ( m_LeadPaint.GetDlgBorderWidth()); m_LeadPaint.GetText().SetBorderColor ( m_LeadPaint.GetDlgBorderColor()); m_LeadPaint.GetText().SetAlignment ( m_LeadPaint.GetDlgAlignment()); m_LeadPaint.GetText().SetTransformRotate ( m_LeadPaint.GetDlgTransformRotate()); m_LeadPaint.GetText().SetTransformScaleX ( m_LeadPaint.GetDlgTransformScaleX()); m_LeadPaint.GetText().SetTransformScaleY ( m_LeadPaint.GetDlgTransformScaleY()); } } BOOL CMainFrame::OnQueryNewPalette() { // always realize the palette for the active view CMDIChildWnd* pMDIChildWnd = MDIGetActive(); if (pMDIChildWnd == NULL) return FALSE; // no active MDI child frame (no new palette) CView* pView = pMDIChildWnd->GetActiveView(); ASSERT(pView != NULL); // just notify the target view return((BOOL) pView->SendMessage(WM_DOREALIZE, (WPARAM)m_hWnd, (LPARAM) FALSE)); } void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd) { CMDIFrameWnd::OnPaletteChanged(pFocusWnd); CMDIChildWnd* pMDIChildWnd = MDIGetActive(); if (pMDIChildWnd == NULL) return; // no active MDI child frame SendMessageToDescendants(WM_DOREALIZE, (WPARAM)pFocusWnd->m_hWnd, (LPARAM) TRUE); } void CMainFrame::OnPaletteIsChanging(CWnd* pRealizeWnd) { OnPaletteChanged(pRealizeWnd); } void CMainFrame::OnSysColorChange() { OnQueryNewPalette(); }