/* Copyright (c) 2021 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __UIListViewBase_H__ #define __UIListViewBase_H__ #ifdef __cplusplus extern "C" { #endif typedef struct UIListViewBase UIListViewBase; #define UIListViewBase_superclass UIElement #include "shell/Shell.h" #include "uitoolkit/UIElement.h" #include "utilities/IndexSelection.h" #define LIST_VIEW_EDGE_PADDING 1 #define LIST_VIEW_UNFOCUS_HIT_TEST_PRIORITY 10 #define LIST_VIEW_DRAG_DRAW_ORDER_OFFSET 1100 #define LIST_VIEW_DRAG_START_THRESHOLD 4 typedef void (* UIListViewActionCallback)(UIListViewBase * listView, double referenceTime, void * context); typedef void (* UIListViewSelectionChangedCallback)(UIListViewBase * listView, double referenceTime, void * context); typedef void (* UIListViewDeleteLineCallback)(UIListViewBase * listView, unsigned int modifiers, bool isRepeat, double referenceTime, void * context); typedef enum UIListViewSelectMode { SELECT_MODE_NONE, SELECT_MODE_SINGLE, SELECT_MODE_SINGLE_NO_DESELECT, SELECT_MODE_MULTIPLE } UIListViewSelectMode; #define UIListViewBase_ivars \ UIElement_ivars \ \ float width; \ float lineHeight; \ unsigned int displayedLineCount; \ UIListViewSelectMode selectMode; \ UIListViewActionCallback actionCallback; \ UIListViewSelectionChangedCallback selectionChangedCallback; \ UIListViewDeleteLineCallback deleteLineCallback; \ void * callbackContext; \ IndexSelection * selection; \ float scrollPosition; \ bool mouseoverScrollbar; \ bool draggingScrollbar; \ bool draggingScrollOffset; \ float dragStartY; \ float dragStartScrollPosition; \ float scrollDragOffset; \ bool focusLocked; \ unsigned int focusLineIndex; \ unsigned int selectedLineIndex; \ unsigned int selectionAnchorIndex; \ bool alternateActionHeld; \ unsigned int lastClickedLine; \ double lastClickTime; \ Vector2f lastClickPosition; \ Renderable * dragRenderable; \ bool maybeDraggingLines; \ bool draggingLines; \ Vector2f dragStartPosition; \ Vector2f dragStartOffset; \ Vector2f draggingLinePosition; \ unsigned int dragStartLineIndex; \ unsigned int dragStartModifiers; \ ShellTimer dragScrollTimer; \ float dragScrollForce; \ bool allowDrag; \ bool drawAlternatingColors; #define UIListViewBase_vtable(self_type) \ UIElement_vtable(self_type) \ \ unsigned int (* getLineCount)(self_type * self); \ Rect4f (* getLineBounds)(self_type * self, Rect4f listViewBounds, unsigned int lineIndex); \ void (* drawBackground)(self_type * self, Rect4f bounds, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); \ void (* drawLine)(self_type * self, unsigned int lineIndex, Rect4f lineBounds, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); \ void (* drawDragLine)(self_type * self, unsigned int lineIndex, Rect4f lineBounds, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); \ bool (* lineAction)(self_type * self, unsigned int lineIndex, double referenceTime); \ void (* lineDoubleClicked)(self_type * self, unsigned int lineIndex, double referenceTime); \ void (* linesDraggedToIndex)(self_type * self, unsigned int lineIndex, unsigned int modifiersAtDragStart, unsigned int modifiersAtDragEnd); \ void (* scrollToLine)(self_type * self, unsigned int lineIndex); \ void (* clearSelection)(self_type * self); \ void (* selectAll)(self_type * self); \ void (* selectLineAtIndex)(self_type * self, unsigned int lineIndex); \ void (* deselectLineAtIndex)(self_type * self, unsigned int lineIndex); \ bool (* isLineSelected)(self_type * self, unsigned int lineIndex); \ unsigned int (* getSelectedLineCount)(self_type * self); \ stemobject_declare(UIListViewBase) bool UIListViewBase_init(UIListViewBase * self, Vector2f position, Vector2f origin, float width, float lineHeight, unsigned int displayedLineCount, UIListViewSelectMode selectMode, UIListViewActionCallback actionCallback, UIListViewSelectionChangedCallback selectionChangedCallback, UIListViewDeleteLineCallback deleteLineCallback, void * callbackContext, UIAppearance appearance); void UIListViewBase_dispose(UIListViewBase * self); bool UIListViewBase_hitTest(UIListViewBase * self, float x, float y, UIHitTestType type, int * outPriority, bool * outForwardNext); UIEventResponse UIListViewBase_mouseDown(UIListViewBase * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, bool isFinalTarget, double referenceTime); bool UIListViewBase_mouseUp(UIListViewBase * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, double referenceTime); bool UIListViewBase_mouseMoved(UIListViewBase * self, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime); bool UIListViewBase_mouseDragged(UIListViewBase * self, unsigned int buttonMask, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime); UIEventResponse UIListViewBase_scrollWheel(UIListViewBase * self, float x, float y, int deltaX, int deltaY, unsigned int modifiers, bool isFinalTarget, double referenceTime); UIEventResponse UIListViewBase_keyDown(UIListViewBase * self, unsigned int charCode, unsigned int keyCode, unsigned int modifiers, bool isRepeat, bool isFinalTarget, double referenceTime); bool UIListViewBase_menuActionDown(UIListViewBase * self, unsigned int actionNumber, bool isRepeat, double referenceTime); bool UIListViewBase_menuActionUp(UIListViewBase * self, unsigned int actionNumber, double referenceTime); bool UIListViewBase_menuDirectionDown(UIListViewBase * self, UINavigationDirection direction, bool isRepeat, double referenceTime); bool UIListViewBase_acceptsFocus(UIListViewBase * self); Rect4f UIListViewBase_getBounds(UIListViewBase * self); Rect4f UIListViewBase_getFocusBounds(UIListViewBase * self); void UIListViewBase_draw(UIListViewBase * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UIListViewBase_listRenderables(UIListViewBase * self, RenderableIO * renderableIO, int drawOrderOffset, Rect4i clipBounds); void UIListViewBase_setFocusedLine(UIListViewBase * self, unsigned int lineIndex); void UIListViewBase_setSelectedLine(UIListViewBase * self, unsigned int lineIndex); void UIListViewBase_scrollToLine(UIListViewBase * self, unsigned int lineIndex); void UIListViewBase_clearSelection(UIListViewBase * self); void UIListViewBase_selectAll(UIListViewBase * self); void UIListViewBase_selectLineAtIndex(UIListViewBase * self, unsigned int lineIndex); void UIListViewBase_deselectLineAtIndex(UIListViewBase * self, unsigned int lineIndex); bool UIListViewBase_isLineSelected(UIListViewBase * self, unsigned int lineIndex); unsigned int UIListViewBase_getSelectedLineCount(UIListViewBase * self); unsigned int UIListViewBase_getLineCount(UIListViewBase * self); Rect4f UIListViewBase_getLineBounds(UIListViewBase * self, Rect4f listViewBounds, unsigned int lineIndex); void UIListViewBase_drawBackground(UIListViewBase * self, Rect4f bounds, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UIListViewBase_drawLine(UIListViewBase * self, unsigned int lineIndex, Rect4f lineBounds, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UIListViewBase_drawDragLine(UIListViewBase * self, unsigned int lineIndex, Rect4f lineBounds, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); bool UIListViewBase_lineAction(UIListViewBase * self, unsigned int lineIndex, double referenceTime); void UIListViewBase_lineDoubleClicked(UIListViewBase * self, unsigned int lineIndex, double referenceTime); void UIListViewBase_linesDraggedToIndex(UIListViewBase * self, unsigned int lineIndex, unsigned int modifiersAtDragStart, unsigned int modifiersAtDragEnd); #ifdef __cplusplus } #endif #endif