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::SetCursorIndex(unsigned i) { if (i >= length) return false; if (i == GetCursorIndex()) return true; EnsureVisible(i); Invalidate_item(cursor); cursor = i; Invalidate_item(cursor); if (cursor_handler != nullptr) cursor_handler->OnCursorMoved(i); return true; }
void ListControl::drag_end() { if (drag_mode != DragMode::NONE) { if (drag_mode == DragMode::CURSOR) Invalidate_item(cursor); drag_mode = DragMode::NONE; ReleaseCapture(); } }
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::OnKillFocus() { PaintWindow::OnKillFocus(); Invalidate_item(cursor); }