void CTimeBarItem::OnMouse(wxMouseEvent& event) { CTimeBarItemContainer* pParent = (CTimeBarItemContainer*)GetParent(); CTimeBarFrame* pFrame = pParent->GetTimeBarFrameWindow(); wxPoint pstn= event.GetPosition(); int index = PointToCell(pstn); int iCellWidth = pParent->GetCellWidth(); int CursorPosition = pstn.x / iCellWidth; CursorPosition *= iCellWidth; CursorPosition += iCellWidth * 0.5F; if (event.ButtonDown(wxMOUSE_BTN_LEFT)) { pFrame->SetClickOnScalebar(false); pParent->GetCurrentSelect().m_iSelectRowBegin = index; pParent->GetCurrentSelect().m_iSelectColumnBegin = GetColumnID(); pParent->GetCurrentSelect().m_iSelectRowEnd = index; pParent->GetCurrentSelect().m_iSelectColumnEnd = GetColumnID(); pFrame->SetCursorPositionX(CursorPosition); pFrame->ClickOnScaleBar(); } else if (event.Dragging()) { if (pstn.x % FREQUENCYREDUCTIONFACTOR == 0) { if (!pParent->GetTimeBarFrameWindow()->IsClickOnScalebar()) { pParent->GetCurrentSelect().m_iSelectRowEnd = index; pParent->GetCurrentSelect().m_iSelectColumnEnd = GetColumnID(); } pFrame->SetCursorPositionX(CursorPosition); pFrame->ClickOnScaleBar(); } } else if (event.ButtonUp(wxMOUSE_BTN_LEFT)) { int id = GetColumnID(); pFrame->SetCurrentSelect(id); } event.Skip(); };
void CTimeBarItem::DrawItem() { static const size_t GrayCellOffset = 5; SetBackgroundStyle(wxBG_STYLE_PAINT); wxAutoBufferedPaintDC ScaleDC(this); wxRect ItemRect = GetRect(); CTimeBarItemContainer* pContainer = (CTimeBarItemContainer*)GetParent(); wxPoint ViewStart = pContainer->GetViewStart(); wxSize size = pContainer->GetSize(); int cursorpositionx = pContainer->GetTimeBarFrameWindow()->GetCursorPositionX(); int iWidith = pContainer->GetCellWidth(); int iCount = size.x / iWidith; iCount += ViewStart.x - 1; int iDrawRectWdith = iWidith +1; int iPositionX = -1; int iDefaultCellHeight = ItemRect.height + 1; int iCellDataHeight = ItemRect.height - 2 * DATACELLOFFSET; ScaleDC.SetPen(*wxLIGHT_GREY); ScaleDC.DrawRectangle(ItemRect); for(int i = ViewStart.x; i < iCount; i++) { iPositionX = i * iWidith; bool bHasData = HasData(i); bool bHasSelected = HasSelected(i); if (!bHasData) { if (bHasSelected) { ScaleDC.SetBrush(*wxBLUE); ScaleDC.DrawRectangle(iPositionX, 0, iDrawRectWdith, iDefaultCellHeight); ScaleDC.SetBrush(*wxWHITE); } else { if (i % GrayCellOffset == 0) { ScaleDC.SetBrush(*wxLIGHT_GREY); ScaleDC.DrawRectangle(iPositionX, 0, iDrawRectWdith, iDefaultCellHeight); ScaleDC.SetBrush(*wxWHITE); } else { ScaleDC.DrawRectangle(iPositionX, 0, iDrawRectWdith, iDefaultCellHeight); } } } else//if(bHasData) { if (bHasSelected) { DrawDefaultItem(&ScaleDC, i, iPositionX, iDrawRectWdith, iDefaultCellHeight); ScaleDC.SetBrush(*wxBLUE); ScaleDC.DrawRectangle(iPositionX, DATACELLOFFSET, iDrawRectWdith, iCellDataHeight); ScaleDC.SetBrush(*wxWHITE); } else { DrawDefaultItem(&ScaleDC, i, iPositionX, iDrawRectWdith, iDefaultCellHeight); ScaleDC.SetBrush(*wxGREEN); ScaleDC.DrawRectangle(iPositionX, DATACELLOFFSET, iDrawRectWdith, iCellDataHeight); ScaleDC.SetBrush(*wxWHITE); } } } wxPen pen = *wxRED_PEN; pen.SetWidth(CURSORWIDTH); ScaleDC.SetPen(pen); ScaleDC.DrawLine(cursorpositionx, 0, cursorpositionx, ItemRect.height); }