bool ListControl::OnMouseMove(PixelScalar x, PixelScalar y, unsigned keys) { // If we are currently dragging the ScrollBar slider if (scroll_bar.IsDragging()) { // -> Update ListBox origin unsigned value = scroll_bar.DragMove(length * item_height, GetHeight(), y); SetPixelOrigin(value); return true; } else if (drag_mode == DragMode::CURSOR) { if (abs(y - drag_y_window) > ((int)item_height / 5)) { drag_mode = DragMode::SCROLL; Invalidate_item(cursor); } else return true; } if (drag_mode == DragMode::SCROLL) { int new_origin = drag_y - y; SetPixelOrigin(new_origin); #ifndef _WIN32_WCE kinetic.MouseMove(GetPixelOrigin()); #endif return true; } return PaintWindow::OnMouseMove(x, y, keys); }
bool ListControl::OnMouseMove(PixelPoint p, unsigned keys) { // If we are currently dragging the ScrollBar slider if (scroll_bar.IsDragging()) { // -> Update ListBox origin if (UsePixelPan()) SetPixelOrigin(scroll_bar.DragMove(length * item_height, GetHeight(), p.y)); else SetOrigin(scroll_bar.DragMove(length, items_visible, p.y)); return true; } else if (drag_mode == DragMode::CURSOR) { if (abs(p.y - drag_y_window) > ((int)item_height / 5)) { drag_mode = DragMode::SCROLL; Invalidate_item(cursor); } else return true; } if (drag_mode == DragMode::SCROLL) { int new_origin = drag_y - p.y; SetPixelOrigin(new_origin); if (UsePixelPan()) kinetic.MouseMove(GetPixelOrigin()); return true; } return PaintWindow::OnMouseMove(p, keys); }
bool ListControl::OnMouseUp(PixelScalar x, PixelScalar y) { if (scroll_bar.IsDragging()) { scroll_bar.DragEnd(this); return true; } if (drag_mode == DragMode::CURSOR && x >= 0 && x <= ((PixelScalar)GetWidth() - scroll_bar.GetWidth())) { drag_end(); ActivateItem(); return true; } if (drag_mode == DragMode::SCROLL || drag_mode == DragMode::CURSOR) { drag_end(); #ifndef _WIN32_WCE kinetic.MouseUp(GetPixelOrigin()); kinetic_timer.Schedule(30); #endif return true; } else return PaintWindow::OnMouseUp(x, y); }
bool ListControl::OnMouseUp(PixelPoint p) { if (scroll_bar.IsDragging()) { scroll_bar.DragEnd(this); return true; } if (drag_mode == DragMode::CURSOR && p.x >= 0 && p.x <= ((int)GetWidth() - scroll_bar.GetWidth())) { drag_end(); ActivateItem(); return true; } if (drag_mode == DragMode::SCROLL || drag_mode == DragMode::CURSOR) { const bool enable_kinetic = UsePixelPan() && drag_mode == DragMode::SCROLL; drag_end(); if (enable_kinetic) { kinetic.MouseUp(GetPixelOrigin()); kinetic_timer.Schedule(30); } return true; } else return PaintWindow::OnMouseUp(p); }
void ListControl::DrawScrollBar(Canvas &canvas) { if (!scroll_bar.IsDefined()) return; scroll_bar.SetSlider(length * item_height, GetHeight(), GetPixelOrigin()); scroll_bar.Paint(canvas); }
void ListControl::MoveOrigin(int delta) { if (UsePixelPan()) { int pixel_origin = (int)GetPixelOrigin(); SetPixelOrigin(pixel_origin + delta * (int)item_height); } else { SetOrigin(origin + delta); } }
void ListControl::DrawScrollBar(Canvas &canvas) { if (!scroll_bar.IsDefined()) return; if (UsePixelPan()) scroll_bar.SetSlider(length * item_height, GetHeight(), GetPixelOrigin()); else scroll_bar.SetSlider(length, items_visible, origin); scroll_bar.Paint(canvas); }
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 = 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 kinetic.MouseDown(GetPixelOrigin()); #endif SetCapture(); } return true; }
void ListControl::MoveOrigin(int delta) { int pixel_origin = (int)GetPixelOrigin(); SetPixelOrigin(pixel_origin + delta * (int)item_height); }