void DocHistory::OnMouseWheel(wxMouseEvent& event) { if (GetScrollThumb(wxVERTICAL)) { // Only handle scrollwheel if we have a scrollbar const wxSize size = GetClientSize(); int pos = m_scrollPos; const int rotation = event.GetWheelRotation(); const int linescount = (abs(rotation) / event.GetWheelDelta()) * event.GetLinesPerAction(); if (rotation > 0) { // up pos = pos - (pos % m_lineHeight) - (m_lineHeight * linescount); if (pos < 0) pos = 0; } else if (rotation < 0) { // down pos = pos - (pos % m_lineHeight) + (m_lineHeight * linescount); if (pos > m_treeHeight - size.y) pos = m_treeHeight - size.y; } else return; // no rotation if (pos != m_scrollPos) { m_oldScrollPos = m_scrollPos; m_scrollPos = pos; m_isScrolling = true; wxClientDC dc(this); DrawLayout(dc); } } }
bool ScrollBox::Update(const Point2i &mousePosition, const Point2i &lastMousePosition) { // Force redrawing if we are scrolling and the mouse has moved if (start_drag_offset!=NO_DRAG && mousePosition!=lastMousePosition) { //NeedRedrawing(); } bool redraw = need_redrawing; bool updated = Widget::Update(mousePosition, lastMousePosition); need_redrawing = redraw; bool has_scrollbar = HasScrollBar(); m_up->SetVisible(has_scrollbar); m_down->SetVisible(has_scrollbar); updated |= WidgetList::Update(mousePosition, lastMousePosition); if (has_scrollbar) { GetMainWindow().BoxColor(GetScrollTrack(), dark_gray_color); const Rectanglei& thumb = GetScrollThumb(); bool over = scroll_mode==SCROLL_MODE_THUMB || thumb.Contains(mousePosition); GetMainWindow().BoxColor(thumb, over ? white_color : gray_color); } return updated; }
Widget * ScrollBox::Click(const Point2i & mousePosition, uint button) { if (!Contains(mousePosition)) { return NULL; } start_drag_offset = NO_DRAG; scroll_mode = SCROLL_MODE_NONE; if (HasScrollBar() && Mouse::IS_CLICK_BUTTON(button)) { start_drag_y = mousePosition.y; if (GetScrollThumb().Contains(mousePosition)) { if (!offset) { // Not yet set, derive from mouse position const Rectanglei& scroll_track = GetScrollTrack(); int height = scroll_track.GetSizeY(); offset = ( (mousePosition.y - scroll_track.GetPositionY()) * (size.y+GetMaxOffset()) + (height/2) ) / height; } start_drag_offset = offset; scroll_mode = SCROLL_MODE_THUMB; } else if (vbox->Contains(mousePosition)) { // The click occurred inside the vbox, this means scrolling scroll_mode = SCROLL_MODE_DRAG; start_drag_offset = offset; } } return WidgetList::Click(mousePosition, button); }
void BaseEditor::OnScrollPageDownEvt(wxScrollWinEvent& event) { int nOrientation = event.GetOrientation(); int nDistance = GetScrollThumb(nOrientation); int nPos = GetScrollPos(nOrientation); SetScrollPos(nOrientation, nPos+nDistance, true); UpdateScrollPosition(GetScrollPos(wxHORIZONTAL), GetScrollPos(wxVERTICAL)); }
void wxJigsawEditorCanvas::OnScrollPageDown(wxScrollWinEvent & event) { wxLogTrace(wxTraceMask(), _("wxJigsawEditorCanvas::OnScrollPageDown;")); SetScrollPos(event.GetOrientation(), GetScrollPos(event.GetOrientation()) + GetScrollThumb(event.GetOrientation())); FixViewOffset(); RefreshBuffer(); }
void DocHistory::DrawLayout(wxDC& dc) { if (!IsShown()) { // Sometimes OnSize() might get called while control is hidden m_needRedrawing = true; return; } const wxSize size = GetClientSize(); wxRect rect; if (m_isScrolling) { // If there is overlap, then move the image if (m_scrollPos + size.y > m_oldScrollPos && m_scrollPos < m_oldScrollPos + size.y) { const int top = wxMax(m_scrollPos, m_oldScrollPos); const int bottom = wxMin(m_scrollPos, m_oldScrollPos) + size.y; const int overlap_height = bottom - top; m_mdc.Blit(0, (top - m_oldScrollPos) + (m_oldScrollPos - m_scrollPos), size.x, overlap_height, &m_mdc, 0, top - m_oldScrollPos); const int new_height = size.y - overlap_height; const int newtop = (top == m_scrollPos) ? bottom : m_scrollPos; rect = wxRect(0,newtop,size.x,new_height); // Just redraw the revealed part } else { rect = wxRect(0,m_scrollPos,size.x,size.y); } SetScrollPos(wxVERTICAL, m_scrollPos); m_isScrolling = false; } else { // Check if we need a scrollbar bool hasScroll = (GetScrollThumb(wxVERTICAL) != 0); if (m_treeHeight > size.y) { SetScrollbar(wxVERTICAL, m_scrollPos, size.y, m_treeHeight); if (!hasScroll) return; // have sent a size event } else { SetScrollbar(wxVERTICAL, 0, 0, 0); if (hasScroll) return; // have sent a size event } // Can we make room for more of the history? if (m_scrollPos + size.y > m_treeHeight) { m_scrollPos = wxMax(0, m_treeHeight-size.y); } rect = wxRect(0, m_scrollPos, size.x, size.y); } // Resize & scroll the versiontree wxSize timelinesize = m_pTimeline->GetBestSize(); wxSize treesize = m_pTree->GetBestSize(); if (timelinesize.x + treesize.x >= size.x) { timelinesize.x = treesize.x = size.x / 3; } m_pTimeline->Move(0, 0); m_pTimeline->SetSize(wxSize(timelinesize.x, size.y)); m_pTimeline->Scroll(m_scrollPos); m_pTimeline->ReDraw(); // Resize & scroll the versiontree (positioned right of Timeline) m_pTree->Move(timelinesize.x, 0); m_pTree->SetSize(wxSize(treesize.x, size.y)); m_pTree->Scroll(m_scrollPos); m_xposDesc = timelinesize.x + treesize.x; const int textwidth = size.x - m_xposDesc; rect = wxRect(m_xposDesc, rect.y, textwidth, rect.height); // resize the bitmap used for doublebuffering if (m_bitmap.GetWidth() < textwidth || m_bitmap.GetHeight() < size.y) { m_bitmap = wxBitmap(textwidth, size.y); m_mdc.SelectObject(m_bitmap); } // Draw the description area // Notice that the memDc is moved so that m_xposDesc=0 { // Clear the background m_mdc.SetBrush(bgBrush); m_mdc.SetPen(*wxWHITE_PEN); m_mdc.DrawRectangle(0, rect.y - m_scrollPos, textwidth, rect.height); // Find the first visible node unsigned int i; for (i = 0; i < m_items.size(); ++i) { if (m_items[i].ypos+m_lineHeight >= rect.y) break; } const int ybottom = m_scrollPos + size.y; // Draw Label & Description m_mdc.SetTextForeground(*wxBLACK); const int textindent = 3; cxLOCK_READ(m_catalyst) while (i < m_items.size() && m_items[i].ypos < ybottom) { wxString label = catalyst.GetLabel(m_items[i].doc); if (!label.empty()) { label = label.BeforeFirst('\n'); label += wxT(": "); } int x; int y; m_mdc.GetTextExtent(label, &x, &y); m_mdc.DrawText(label, textindent, m_items[i].ypos-m_scrollPos); wxString desc = catalyst.GetDescription(m_items[i].doc); desc = desc.BeforeFirst('\n'); m_mdc.DrawText(desc, textindent+x, m_items[i].ypos-m_scrollPos); ++i; } cxENDLOCK } // Copy MemoryDC to Display dc.Blit(m_xposDesc, 0, textwidth, size.y, &m_mdc, 0, 0); m_needRedrawing = false; }