haiku/headers/os/interface/ListView.h

215 lines
6.3 KiB
C
Raw Normal View History

/*
Set*UIColor, etc. The inseparable changes necessary to support live color updating across the system in a sane, safe, and performant manner. BView gains: HasSystemColors() HasDefaultColors() AdoptSystemColors() AdoptParentColors() AdoptViewColor(BView*) SetViewUIColor(color_which, float tint) SetHighUIColor(... SetLowUIColor(... ViewUIColor(float* tint) HighUIColor(... LowUIColor(... DelayedInvalidate() BWindow gains a simple helper method: IsOffscreenWindow() BMessage gains: AddColor() FindColor() GetColor() HasColor() * allegedly this API is deprecated, but I implemented it anyway ReplaceColor() SetColor() Previous private ColorTools methods are made public and moved into GraphicsDefs: mix_color, blend_color, disable_color These are fully compatible with BeOS dan0 R5.1 methods and are just code cleanup of BeOS example code under the OpenTracker license. In addition, four new colors are created: B_LINK_TEXT_COLOR B_LINK_HOVER_COLOR B_LINK_ACTIVE_COLOR B_LINK_VISITED_COLOR These changes are documented in their proper user documentation files. In addition, due to a history rewrite, B_FOLLOW_LEFT_TOP has been defined and used in lieu of B_FOLLOW_TOP | B_FOLLOW_LEFT and is included in this commit. On the app_server side, the following has changed: Add DelayedMessage - a system by which messages can be sent at a scheduled time, and can also be merged according to set rules. A single thread is used to service the message queue and multiple recipients can be set for each message. Desktop gains the ability to add message ports to a DelayedMessage so that said messages can target either all applications or all windows, as needed. Desktop maintains a BMessage which is used to queue up all pending color changes and the delayed messaging system is used to enact these changes after a short period of time has passed. This prevents abuse and allows the system to merge repeated set_ui_color events into one event for client applications, improving performance drastically. In addition, B_COLORS_UPDATED is sent to the BApplication, which forwards the message to each BWindow. This is done to improve performance over having the app_server independently informing each window. Decorator changes are live now, which required some reworking. Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
2015-12-10 12:52:48 -06:00
* Copyright 2002-2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _LIST_VIEW_H
#define _LIST_VIEW_H
#include <Invoker.h>
#include <List.h>
#include <ListItem.h>
#include <View.h>
struct track_data;
enum list_view_type {
B_SINGLE_SELECTION_LIST,
B_MULTIPLE_SELECTION_LIST
};
class BListView : public BView, public BInvoker {
public:
BListView(BRect frame, const char* name,
list_view_type type
= B_SINGLE_SELECTION_LIST,
Set*UIColor, etc. The inseparable changes necessary to support live color updating across the system in a sane, safe, and performant manner. BView gains: HasSystemColors() HasDefaultColors() AdoptSystemColors() AdoptParentColors() AdoptViewColor(BView*) SetViewUIColor(color_which, float tint) SetHighUIColor(... SetLowUIColor(... ViewUIColor(float* tint) HighUIColor(... LowUIColor(... DelayedInvalidate() BWindow gains a simple helper method: IsOffscreenWindow() BMessage gains: AddColor() FindColor() GetColor() HasColor() * allegedly this API is deprecated, but I implemented it anyway ReplaceColor() SetColor() Previous private ColorTools methods are made public and moved into GraphicsDefs: mix_color, blend_color, disable_color These are fully compatible with BeOS dan0 R5.1 methods and are just code cleanup of BeOS example code under the OpenTracker license. In addition, four new colors are created: B_LINK_TEXT_COLOR B_LINK_HOVER_COLOR B_LINK_ACTIVE_COLOR B_LINK_VISITED_COLOR These changes are documented in their proper user documentation files. In addition, due to a history rewrite, B_FOLLOW_LEFT_TOP has been defined and used in lieu of B_FOLLOW_TOP | B_FOLLOW_LEFT and is included in this commit. On the app_server side, the following has changed: Add DelayedMessage - a system by which messages can be sent at a scheduled time, and can also be merged according to set rules. A single thread is used to service the message queue and multiple recipients can be set for each message. Desktop gains the ability to add message ports to a DelayedMessage so that said messages can target either all applications or all windows, as needed. Desktop maintains a BMessage which is used to queue up all pending color changes and the delayed messaging system is used to enact these changes after a short period of time has passed. This prevents abuse and allows the system to merge repeated set_ui_color events into one event for client applications, improving performance drastically. In addition, B_COLORS_UPDATED is sent to the BApplication, which forwards the message to each BWindow. This is done to improve performance over having the app_server independently informing each window. Decorator changes are live now, which required some reworking. Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
2015-12-10 12:52:48 -06:00
uint32 resizeMask = B_FOLLOW_LEFT_TOP,
uint32 flags = B_WILL_DRAW
| B_FRAME_EVENTS | B_NAVIGABLE);
BListView(const char* name,
list_view_type type
= B_SINGLE_SELECTION_LIST,
uint32 flags = B_WILL_DRAW
| B_FRAME_EVENTS | B_NAVIGABLE);
BListView(list_view_type type
= B_SINGLE_SELECTION_LIST);
BListView(BMessage* data);
virtual ~BListView();
static BArchivable* Instantiate(BMessage* data);
virtual status_t Archive(BMessage* data,
bool deep = true) const;
virtual void Draw(BRect updateRect);
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void AllAttached();
virtual void AllDetached();
virtual void FrameResized(float newWidth, float newHeight);
virtual void FrameMoved(BPoint newPosition);
2014-06-11 19:00:46 -04:00
virtual void TargetedByScrollView(BScrollView* view);
virtual void WindowActivated(bool active);
virtual void MessageReceived(BMessage* message);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void MouseDown(BPoint where);
2013-04-08 23:49:57 -04:00
virtual void MouseUp(BPoint where);
virtual void MouseMoved(BPoint where, uint32 code,
const BMessage* dragMessage);
virtual void ResizeToPreferred();
2013-04-08 23:49:57 -04:00
virtual void GetPreferredSize(float *_width,
float *_height);
virtual BSize MinSize();
virtual BSize MaxSize();
virtual BSize PreferredSize();
virtual void MakeFocus(bool state = true);
virtual void SetFont(const BFont* font, uint32 mask
= B_FONT_ALL);
virtual void ScrollTo(BPoint where);
inline void ScrollTo(float x, float y);
virtual bool AddItem(BListItem* item);
virtual bool AddItem(BListItem* item, int32 atIndex);
virtual bool AddList(BList* newItems);
virtual bool AddList(BList* newItems, int32 atIndex);
virtual bool RemoveItem(BListItem* item);
virtual BListItem* RemoveItem(int32 index);
virtual bool RemoveItems(int32 index, int32 count);
virtual void SetSelectionMessage(BMessage* message);
virtual void SetInvocationMessage(BMessage* message);
BMessage* SelectionMessage() const;
uint32 SelectionCommand() const;
BMessage* InvocationMessage() const;
uint32 InvocationCommand() const;
virtual void SetListType(list_view_type type);
list_view_type ListType() const;
BListItem* ItemAt(int32 index) const;
int32 IndexOf(BPoint point) const;
int32 IndexOf(BListItem* item) const;
BListItem* FirstItem() const;
BListItem* LastItem() const;
bool HasItem(BListItem* item) const;
int32 CountItems() const;
virtual void MakeEmpty();
bool IsEmpty() const;
void DoForEach(bool (*func)(BListItem* item));
void DoForEach(bool (*func)(BListItem* item,
void* arg), void* arg);
const BListItem** Items() const;
void InvalidateItem(int32 index);
void ScrollTo(int32 index);
void ScrollToSelection();
void Select(int32 index, bool extend = false);
void Select(int32 from, int32 to,
bool extend = false);
bool IsItemSelected(int32 index) const;
int32 CurrentSelection(int32 index = 0) const;
virtual status_t Invoke(BMessage* message = NULL);
void DeselectAll();
void DeselectExcept(int32 exceptFrom,
int32 exceptTo);
void Deselect(int32 index);
virtual void SelectionChanged();
virtual bool InitiateDrag(BPoint where, int32 index,
bool wasSelected);
void SortItems(int (*cmp)(const void*,
const void*));
// These functions bottleneck through DoMiscellaneous()
bool SwapItems(int32 a, int32 b);
bool MoveItem(int32 from, int32 to);
bool ReplaceItem(int32 index, BListItem* item);
BRect ItemFrame(int32 index);
virtual BHandler* ResolveSpecifier(BMessage* message,
int32 index, BMessage* specifier,
2014-06-11 19:00:46 -04:00
int32 what, const char* property);
virtual status_t GetSupportedSuites(BMessage* data);
virtual status_t Perform(perform_code code, void* arg);
private:
virtual void _ReservedListView2();
virtual void _ReservedListView3();
virtual void _ReservedListView4();
BListView& operator=(const BListView& other);
protected:
enum MiscCode { B_NO_OP, B_REPLACE_OP, B_MOVE_OP, B_SWAP_OP };
union MiscData {
struct Spare { int32 data[5]; };
struct Replace { int32 index; BListItem *item; } replace;
struct Move { int32 from; int32 to; } move;
struct Swap { int32 a; int32 b; } swap;
};
virtual bool DoMiscellaneous(MiscCode code, MiscData* data);
private:
friend class BOutlineListView;
void _InitObject(list_view_type type);
void _FixupScrollBar();
void _InvalidateFrom(int32 index);
status_t _PostMessage(BMessage* message);
void _UpdateItems();
int32 _RangeCheck(int32 index);
bool _Select(int32 index, bool extend);
bool _Select(int32 from, int32 to, bool extend);
bool _Deselect(int32 index);
bool _DeselectAll(int32 exceptFrom, int32 exceptTo);
int32 _CalcFirstSelected(int32 after);
int32 _CalcLastSelected(int32 before);
void _RecalcItemTops(int32 start, int32 end = -1);
virtual void DrawItem(BListItem* item, BRect itemRect,
bool complete = false);
bool _SwapItems(int32 a, int32 b);
bool _MoveItem(int32 from, int32 to);
bool _ReplaceItem(int32 index, BListItem* item);
void _RescanSelection(int32 from, int32 to);
BListView: Update selection on mouse down and mouse up A version of this feature was originally implemented in hrev50495 that allowed you to scroll through a list of list items while the mouse was held down updating the selection as you went. This feature was removed when we switched to selecting on mouse up in hrev52062 and was never reimplimented when we switched back to selecting on mouse down in hrev52121. In BeOS R5 as you scrolled through a single-selection list with the mouse button held down the selected item appeared to change, but the selection didn't actually update until you released the mouse button. The selection never changes on mouse down, only on mouse up. You could click on one item then move your mouse off the first item to a second item releasing your mouse button and it would select the second item without ever selecting the first item. In this commit we replicate this behavior with one exception, we always select on mouse down, but still allow the selection to change on mouse up. The big difference between this and the BeOS behavior is that on BeOS you could only select exactly one item on mouse up, while with this you can select one item on mouse down and a second item on mouse up. ScrollToSelection() in MouseMoved() if mouse button is down and we are not not dragging. This performs auto-scroll. Create private _DoSelection() method copied from MouseDown(). Remove Thread.h include that is no longer used. Fixes #15009 (and doesn't cause regression for #9190 #14264 #14289) Change-Id: Icae02b8d37ed281390647504b4efa3d694ea522a Reviewed-on: https://review.haiku-os.org/c/haiku/+/1956 Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk> Reviewed-by: John Scipione <jscipione@gmail.com> Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2019-11-13 13:52:44 -05:00
void _DoSelection(int32 index);
private:
BList fList;
list_view_type fListType;
int32 fFirstSelected;
int32 fLastSelected;
int32 fAnchorIndex;
BMessage* fSelectMessage;
BScrollView* fScrollView;
track_data* fTrack;
uint32 _reserved[4];
};
inline void
BListView::ScrollTo(float x, float y)
{
ScrollTo(BPoint(x, y));
}
#endif // _LIST_VIEW_H