/* void CDrawView::OnUpdate(CView* , LPARAM lHint, CObject* pHint) { switch (lHint) { case HINT_UPDATE_WINDOW: // redraw entire window Invalidate(FALSE); break; case HINT_UPDATE_DRAWOBJ: // a single object has changed g_pGuiManager->InvalObj((CDrawObj*)pHint); break; case HINT_UPDATE_SELECTION: // an entire selection has changed { //选中之后实时刷新 g_pGuiManager->RefrshSelectionList(); } break; case HINT_DELETE_SELECTION: // an entire selection has been removed if (pHint != &m_selection) { CDrawObjLists::iterator it = g_pGuiManager->m_SelectList.begin(); CDrawObjLists::iterator it_end = g_pGuiManager->m_SelectList.end(); for (; it != it_end; it++) { CDrawObj* pObj = *it; if (NULL != pObj) { g_pGuiManager->InvalObj(pObj); g_pGuiManager->RemoveSelection(pObj); // remove it from this view's selection } } } break; case HINT_UPDATE_OLE_ITEMS: { CDrawObjLists* pDrawObjLists = g_pGuiManager->GetObjLists(); CDrawObjLists::iterator it = pDrawObjLists->begin(); CDrawObjLists::iterator it_end = pDrawObjLists->end(); for (it; it != it_end; it++) { CDrawObj* pObj_temp = *it; if (pObj_temp != NULL) { if (pObj_temp->IsKindOf(RUNTIME_CLASS(CDrawOleObj))) g_pGuiManager->InvalObj(pObj_temp); } } } break; default: ASSERT(FALSE); break; } } */ LRESULT CDrawView::DemoData(WPARAM wParam, LPARAM lParam) { Data_Bus *pDemo_Data = (Data_Bus*)lParam; COLORREF color; CDrawObjLists* pDrawObjLists = g_pGuiManager->GetObjLists(); CDrawObjLists::iterator it = pDrawObjLists->begin(); CDrawObjLists::iterator it_end = pDrawObjLists->end(); for (it; it != it_end; it++) { CDrawObj* pObj = *it; if (pObj != NULL) { if (pObj->m_nType == 1) // DI/DO状态量 { color= (pDemo_Data->DI_DO[pObj->m_nOrder]==0)?RGB(0,255,0):RGB(255,0,0); pObj->SetFillColor(color); } } } CDrawDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->SetModifiedFlag(FALSE); return 0; }
//颜色选择完成 LRESULT CMainFrame::OnSelEndOKColor(WPARAM wParam, LPARAM lParam) { UINT uiCmd = ( UINT )lParam; CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CDrawView *pView = (CDrawView*)pChild->GetActiveView(); if(pView == NULL) return 0; if ( uiCmd == ID_FORMATTING_COLOR ) { m_crCurrent = ( COLORREF )wParam; if(pView->m_selection.GetCount() >= 1) { POSITION pos = pView->m_selection.GetHeadPosition(); while(pos != NULL) { CDrawObj * pObj = pView->m_selection.GetNext(pos); if(pObj->IsKindOf(RUNTIME_CLASS(CDrawButton))) { CDrawButton *pButton = (CDrawButton *)pObj; pButton->m_color = m_crCurrent; pButton->Invalidate(); } } } pView->GetDocument()->SetModifiedFlag(); } if( uiCmd == ID_FORMATTING_BACK_COLOR) { m_crFillColor = ( COLORREF )wParam; if(pView->m_selection.GetCount() >= 1) { POSITION pos = pView->m_selection.GetHeadPosition(); while(pos != NULL) { CDrawObj * pObj = pView->m_selection.GetNext(pos); if(!pObj->IsKindOf(RUNTIME_CLASS(CDrawButton))) { pObj->m_clrFillColor = m_crFillColor; pObj->Invalidate(); } } } pView->GetDocument()->SetModifiedFlag(); } return 0; }
void CSelectTool::OnLButtonDown(CDrawView* pView, UINT nFlags, const CPoint& point) { CPoint local = point; pView->ClientToDoc(local); CDrawObj* pObj; selectMode = none; // Check for resizing(only allowed on single selections) if (pView->m_selection.GetCount() == 1) { pObj = pView->m_selection.GetHead(); nDragHandle = pObj->HitTest(local, pView, TRUE); if (nDragHandle != 0) selectMode = size; } // See if the click was on an object, select and start move if so if (selectMode == none) { pObj = pView->GetDocument()->ObjectAt(local); if (pObj != NULL) { selectMode = move; if (!pView->IsSelected(pObj)) pView->Select(pObj, (nFlags & MK_SHIFT) != 0); // Ctrl+Click clones the selection... if ((nFlags & MK_CONTROL) != 0) pView->CloneSelection(); } } // Click on background, start a net-selection if (selectMode == none) { if ((nFlags & MK_SHIFT) == 0) pView->Select(NULL); selectMode = netSelect; CClientDC dc(pView); CRect rect(point.x, point.y, point.x, point.y); rect.NormalizeRect(); dc.DrawFocusRect(rect); } ((CMainFrame*)AfxGetMainWnd())->UpdateUI(pView); lastPoint = local; CDrawTool::OnLButtonDown(pView, nFlags, point); }
void CDrawDoc::Draw(CDC* pDC, CDrawView* pView) { POSITION pos = m_objects.GetHeadPosition(); while (pos != NULL) { CDrawObj* pObj = m_objects.GetNext(pos); pObj->Draw(pDC); if (pView->m_bActive && !pDC->IsPrinting() && pView->IsSelected(pObj)) pObj->DrawTracker(pDC, CDrawObj::selected); } }
// point is in logical coordinates CDrawObj* CDrawDoc::ObjectAt(const CPoint& point) { CRect rect(point, CSize(1, 1)); POSITION pos = m_objects.GetTailPosition(); while (pos != NULL) { CDrawObj* pObj = m_objects.GetPrev(pos); if (pObj->Intersects(rect)) return pObj; } return NULL; }
void CRectTool::OnLButtonUp(CDrawView* pView, UINT nFlags, const CPoint& point) { if (point == c_down) { // Don't create empty objects... CDrawObj *pObj = pView->m_selection.GetTail(); pView->GetDocument()->Remove(pObj); pObj->Remove(); selectTool.OnLButtonDown(pView, nFlags, point); // try a select! } selectTool.OnLButtonUp(pView, nFlags, point); }
//字体或字号选择完成 void CMainFrame::OnSelEndOk() { int iSel = m_wndComboSize.GetCurSel( ); if ( iSel != CB_ERR ) { m_wndComboSize.GetLBText( iSel, m_strFontSize ); } else { m_wndComboSize.GetWindowText( m_strFontSize ); } //m_wndComboFont.GetWindowText(m_strFontName); m_wndComboFont.GetSelFont(m_strFontName); int nFontSize = atoi(m_strFontSize); CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); CDrawView *pView = (CDrawView*)pChild->GetActiveView(); if(pView == NULL) return; if(pView->m_selection.GetCount() >= 1) { POSITION pos = pView->m_selection.GetHeadPosition(); while(pos != NULL) { CDrawObj * pObj = pView->m_selection.GetNext(pos); if(pObj->IsKindOf(RUNTIME_CLASS(CDrawButton))) { CDrawButton *pButton = (CDrawButton *)pObj; if(m_strFontName.GetLength() > 0) { pButton->m_fontName = m_strFontName; } if( nFontSize > 0) pButton->m_fontSize = nFontSize; pButton->Invalidate(); } } } pView->GetDocument()->SetModifiedFlag(); }
void CSelectTool::OnMouseMove(CDrawView* pView, UINT nFlags, const CPoint& point) { if (pView->GetCapture() != pView) { if (c_drawShape == selection && pView->m_selection.GetCount() == 1) { CDrawObj* pObj = pView->m_selection.GetHead(); CPoint local = point; pView->ClientToDoc(local); int nHandle = pObj->HitTest(local, pView, TRUE); if (nHandle != 0) { SetCursor(pObj->GetHandleCursor(nHandle)); return; // bypass CDrawTool } } if (c_drawShape == selection) CDrawTool::OnMouseMove(pView, nFlags, point); return; } if (selectMode == netSelect) { CClientDC dc(pView); CRect rect(c_down.x, c_down.y, c_last.x, c_last.y); rect.NormalizeRect(); dc.DrawFocusRect(rect); rect.SetRect(c_down.x, c_down.y, point.x, point.y); rect.NormalizeRect(); dc.DrawFocusRect(rect); CDrawTool::OnMouseMove(pView, nFlags, point); return; } CPoint local = point; pView->ClientToDoc(local); CPoint delta = (CPoint)(local - lastPoint); POSITION pos = pView->m_selection.GetHeadPosition(); while (pos != NULL) { CDrawObj* pObj = pView->m_selection.GetNext(pos); CRect position = pObj->m_position; if (selectMode == move) { position += delta; pObj->MoveTo(position, pView); } else if (nDragHandle != 0) { pObj->MoveHandleTo(nDragHandle, local, pView); } } lastPoint = local; if (selectMode == size && c_drawShape == selection) { c_last = point; SetCursor(pView->m_selection.GetHead()->GetHandleCursor(nDragHandle)); return; // bypass CDrawTool } c_last = point; if (c_drawShape == selection) CDrawTool::OnMouseMove(pView, nFlags, point); }
void CMainFrame::UpdateContextTabFromObject(CDrawObjList& list) { int count = (int) list.GetCount(); if (count == 0) { return; } COLORREF clrFill = (COLORREF)-1; COLORREF clrLine = (COLORREF)-1; int nLineWeight = -1; if (count == 1) { CDrawObj* pObj = list.GetHead(); if (pObj->CanChangeFillColor() && pObj->IsEnableFill()) { clrFill = pObj->GetFillColor(); } if (pObj->CanChangeLineColor() && pObj->IsEnableLine()) { clrLine = pObj->GetLineColor(); } if (pObj->CanChangeLineWeight() && pObj->IsEnableLine()) { nLineWeight = pObj->GetLineWeight() - 1; } } { CArray<CMFCRibbonBaseElement*, CMFCRibbonBaseElement*> arButtons; m_wndRibbonBar.GetElementsByID(ID_OBJECT_FILLCOLOR, arButtons); if (arButtons.GetSize() > 0) { for (int i = 0; i < arButtons.GetSize(); i++) { CMFCRibbonColorButton* pButton = DYNAMIC_DOWNCAST (CMFCRibbonColorButton, arButtons[i] ); pButton->SetColor(clrFill); } } } { CArray<CMFCRibbonBaseElement*, CMFCRibbonBaseElement*> arButtons; m_wndRibbonBar.GetElementsByID(ID_OBJECT_LINECOLOR, arButtons); if (arButtons.GetSize() > 0) { for (int i = 0; i < arButtons.GetSize(); i++) { CMFCRibbonColorButton* pButton = DYNAMIC_DOWNCAST (CMFCRibbonColorButton, arButtons[i] ); pButton->SetColor(clrLine); } } } { CArray<CMFCRibbonBaseElement*, CMFCRibbonBaseElement*> arButtons; m_wndRibbonBar.GetElementsByID(ID_OBJECT_LINEWEIGHT, arButtons); if (arButtons.GetSize() > 0) { for (int i = 0; i < arButtons.GetSize(); i++) { CRibbonListButton* pButton = DYNAMIC_DOWNCAST (CRibbonListButton, arButtons[i] ); pButton->SelectItem(nLineWeight); } } } m_wndRibbonBar.RedrawWindow(); }