bool ListControl::OnTimer(WindowTimer &timer) { if (timer == kinetic_timer) { assert(UsePixelPan()); if (kinetic.IsSteady()) { kinetic_timer.Cancel(); } else SetPixelOrigin(kinetic.GetPosition()); return true; } return PaintWindow::OnTimer(timer); }
void ListControl::EnsureVisible(unsigned i) { assert(i < length); if (origin > i || (origin == i && pixel_pan > 0)) { SetOrigin(i); SetPixelPan(0); } else if (origin + items_visible <= i) { if (UsePixelPan()) { SetOrigin(i - items_visible); if (origin > 0 || i >= items_visible) SetPixelPan(((items_visible + 1) * item_height - GetHeight()) % item_height); } else { /* no pixel panning on e-paper screens to avoid tearing */ SetOrigin(i + 1 - items_visible); } } }
bool ListControl::OnMouseDown(PixelScalar x, PixelScalar y) { // End any previous drag scroll_bar.DragEnd(this); drag_end(); #ifndef _WIN32_WCE kinetic_timer.Cancel(); #endif RasterPoint Pos; Pos.x = x; Pos.y = y; // If possible -> Give focus to the Control const bool had_focus = !HasCursorKeys() || HasFocus(); if (!had_focus) SetFocus(); if (scroll_bar.IsInsideSlider(Pos)) { // if click is on scrollbar handle // -> start mouse drag scroll_bar.DragBegin(this, Pos.y); } else if (scroll_bar.IsInside(Pos)) { // if click in scroll bar up/down/pgup/pgdn if (scroll_bar.IsInsideUpArrow(Pos.y)) // up MoveOrigin(-1); else if (scroll_bar.IsInsideDownArrow(Pos.y)) // down MoveOrigin(1); else if (scroll_bar.IsAboveSlider(Pos.y)) // page up MoveOrigin(-(int)items_visible); else if (scroll_bar.IsBelowSlider(Pos.y)) // page down MoveOrigin(items_visible); } else { // if click in ListBox area // -> select appropriate item int index = ItemIndexAt(y); // If mouse was clicked outside the list items -> cancel if (index < 0) return false; drag_y = GetPixelOrigin() + y; drag_y_window = y; if (had_focus && (unsigned)index == GetCursorIndex() && CanActivateItem()) { drag_mode = DragMode::CURSOR; Invalidate_item(cursor); } else { // If item was not selected before // -> select it SetCursorIndex(index); drag_mode = DragMode::SCROLL; } #ifndef _WIN32_WCE if (UsePixelPan()) kinetic.MouseDown(GetPixelOrigin()); #endif SetCapture(); } return true; }