tbx  0.7.5
Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | List of all members
tbx::view::ItemView Class Referenceabstract

Base class for views that show an indexed list of items. More...

#include <itemview.h>

Inheritance diagram for tbx::view::ItemView:
tbx::RedrawListener tbx::ScrollRequestListener tbx::MouseClickListener tbx::view::SelectionListener tbx::Listener tbx::Listener tbx::Listener tbx::Listener tbx::view::ListView tbx::view::ReportView tbx::view::TileView

Public Member Functions

 ItemView (Window window)
 Construct the item view with the given renderer. More...
 
virtual ~ItemView ()
 Destructor removed any listeners.
 
tbx::Windowwindow ()
 Return the Window that this item view is attached to.
 
const tbx::Marginmargin () const
 Return the margin around the data in the window.
 
void margin (const tbx::Margin &margin)
 Change the margin.
 
virtual void auto_size (bool on)=0
 Set to true to resize the the view automatically when an item is added/removed or changed. More...
 
bool auto_size () const
 Returns true if auto size is on.
 
void updates_enabled (bool updates)
 Enable/disable updating of attached window. More...
 
bool updates_enabled () const
 Check if updates of the attached window are enabled. More...
 
unsigned int count () const
 Returns number of items being displayed.
 
void selection (Selection *selection)
 Set the selection model to use for the item view. More...
 
Selectionselection () const
 Get the selection model used for selecting items in the list. More...
 
Selectionselection ()
 Get the selection model used for selecting items in the list. More...
 
void add_click_listener (ItemViewClickListener *listener)
 Add a listener for a click on the item view. More...
 
void remove_click_listener (ItemViewClickListener *listener)
 Remove a listener for a click on the item view.
 
void allow_drag_selection (bool on, bool on_item=false)
 Allow selection of multiple items by using a drag box. More...
 
void menu_selects (bool on)
 Turn on/off selection of an item when the menu button is pressed over an item and no other item is selected. More...
 
bool menu_selects () const
 Returns true if the menu button selects an item.
 
void clear_menu_selection ()
 Clear the current selection if it was made by the menu button.
 
bool last_selection_menu () const
 Returns true if the last selection was made by the menu button.
 
virtual void redraw (const tbx::RedrawEvent &event)=0
 Subclasses must override the redraw event to draw the items in the view.
 
virtual void scroll_request (const tbx::ScrollRequestEvent &event)
 Process scroll requests. More...
 
virtual void mouse_click (tbx::MouseClickEvent &event)
 Mouse clicked on window containing list view. More...
 
virtual void selection_changed (const SelectionChangedEvent &event)
 Selection has changed event handling. More...
 
virtual void update_window_extent ()=0
 Called to update the window extent needed to contain this view.
 
virtual void refresh ()=0
 Called to refresh the entire views contents.
 
virtual void inserted (unsigned int where, unsigned int how_many)=0
 Inform the view that items have been inserted. More...
 
virtual void removing (unsigned int where, unsigned int how_many)
 Inform the view that items are about to be removed. More...
 
virtual void removed (unsigned int where, unsigned int how_many)=0
 Inform the view that items have been removed. More...
 
virtual void changing (unsigned int where, unsigned int how_many)
 Inform the view that items are about to be changed. More...
 
virtual void changed (unsigned int where, unsigned int how_many)=0
 Inform the view that items have been changed. More...
 
virtual void cleared ()=0
 Inform the view that all the data has been cleared.
 
virtual unsigned int insert_index (const Point &scr_pt) const =0
 Return the index for inserting an item from a screen point.
 
virtual unsigned int screen_index (const Point &scr_pt) const =0
 Return the index under the screen point, does not check if it hits content of the item renderer. More...
 
virtual unsigned int hit_test (const Point &scr_pt) const =0
 Return the index under the screen point, checks if it hits content of the item renderer. More...
 
virtual void get_bounds (BBox &bounds, unsigned int index) const =0
 Get bounding box of the given index in work area coordinates.
 
virtual void get_bounds (BBox &bounds, unsigned int first, unsigned int last) const =0
 Get bounding box of the range of indices in work area coordinates.
 
- Public Member Functions inherited from tbx::Listener
virtual ~Listener ()
 Destroy the listener object.
 
- Public Member Functions inherited from tbx::MouseClickListener
virtual ~MouseClickListener ()
 Destructor.
 

Static Public Attributes

static const unsigned int NO_INDEX = -1
 Constant for invalid index. More...
 

Protected Types

enum  ViewFlags {
  NONE = 0, AUTO_SIZE = 1, SELECT_DRAG = 2, SELECT_DRAG_ON_ITEM = 4,
  SELECT_MENU = 8, AUTO_SIZE_CHECKED = 0x100, WANT_AUTO_SIZE = 0x200, LAST_SELECT_MENU = 0x400,
  NO_UPDATES = 0x800
}
 Internal view flags enum, can be one or more of the following. More...
 

Protected Member Functions

virtual void process_drag_selection (const BBox &drag_box, bool adjust)
 Override this method to process selection by dragging. More...
 
void process_mouse_click (int index, MouseClickEvent &event)
 Helper function to process mouse clicks.
 
- Protected Member Functions inherited from tbx::Listener
 Listener ()
 Construct the Listener object.
 

Protected Attributes

Window _window
 Window displaying this view.
 
Margin _margin
 Margin around areas displaying items.
 
Selection_selection
 Selection model.
 
SafeList< ItemViewClickListener > * _click_listeners
 Listeners for a mouse click on the view.
 
unsigned int _count
 Number of items displayed in this view.
 
unsigned int _flags
 Internal view flags.
 

Detailed Description

Base class for views that show an indexed list of items.

The view does not maintain the list of items itself, it must be told when the list of items are changed using the inserted, removed and changed methods.

The items are rendered using the ItemRenderer passed to the constructor.

Member Enumeration Documentation

◆ ViewFlags

Internal view flags enum, can be one or more of the following.

Enumerator
NONE 

No flags size.

AUTO_SIZE 

Autosizing on.

SELECT_DRAG 

Select by dragging box allowed.

SELECT_DRAG_ON_ITEM 

Select by dragging box starting on an item allowed.

SELECT_MENU 

Menu button selects item if no others selected.

AUTO_SIZE_CHECKED 

Removing or changing called.

WANT_AUTO_SIZE 

Need to auto size on removed called.

LAST_SELECT_MENU 

Last selection was caused by menu button.

NO_UPDATES 

Do not update window.

Constructor & Destructor Documentation

◆ ItemView()

tbx::view::ItemView::ItemView ( Window  window)

Construct the item view with the given renderer.

By default auto sizing is on a select dragging when using a multiple selection

Member Function Documentation

◆ add_click_listener()

void tbx::view::ItemView::add_click_listener ( ItemViewClickListener listener)

Add a listener for a click on the item view.

The click listeners are run after any selection process.

◆ allow_drag_selection()

void tbx::view::ItemView::allow_drag_selection ( bool  on,
bool  on_item = false 
)

Allow selection of multiple items by using a drag box.

Parameters
onallow or disallow drag selection
on_itemset to true to allow drag selection starting on an item

◆ auto_size()

virtual void tbx::view::ItemView::auto_size ( bool  on)
pure virtual

Set to true to resize the the view automatically when an item is added/removed or changed.

Derived classes should set the AUTO_SIZE flag and when set on should recalculate the size for the existing items.

Implemented in tbx::view::TileView, tbx::view::ListView, and tbx::view::ReportView.

◆ changed()

virtual void tbx::view::ItemView::changed ( unsigned int  where,
unsigned int  how_many 
)
pure virtual

Inform the view that items have been changed.

Parameters
wherelocation of first change
how_manynumber of items changed

Implemented in tbx::view::ReportView, tbx::view::ListView, and tbx::view::TileView.

◆ changing()

virtual void tbx::view::ItemView::changing ( unsigned int  where,
unsigned int  how_many 
)
inlinevirtual

Inform the view that items are about to be changed.

This call is optional, but it stops the need for a full scan every time something an item is changed when auto size is on.

Parameters
wherelocation items will be changed from
how_manynumber of items that will be changed

Reimplemented in tbx::view::ReportView, tbx::view::ListView, and tbx::view::TileView.

◆ hit_test()

virtual unsigned int tbx::view::ItemView::hit_test ( const Point scr_pt) const
pure virtual

Return the index under the screen point, checks if it hits content of the item renderer.

Returns: NO_INDEX if doesn't hit content

Implemented in tbx::view::ReportView, tbx::view::ListView, and tbx::view::TileView.

◆ inserted()

virtual void tbx::view::ItemView::inserted ( unsigned int  where,
unsigned int  how_many 
)
pure virtual

Inform the view that items have been inserted.

Parameters
wherelocation for insertion
how_manynumber of items inserted

Implemented in tbx::view::ReportView, tbx::view::ListView, and tbx::view::TileView.

◆ menu_selects()

void tbx::view::ItemView::menu_selects ( bool  on)

Turn on/off selection of an item when the menu button is pressed over an item and no other item is selected.

Usually you would add the ItemViewClearMenuSelection as a has been hidden listener to the menu on the views window so a menu selection is removed when the menu is closed.

Parameters
ontrue to turn menu selection on, false to turn it off.

◆ mouse_click()

void tbx::view::ItemView::mouse_click ( tbx::MouseClickEvent event)
virtual

Mouse clicked on window containing list view.

The version in this class processes the selection if necessary and fires the ItemViewClickListeners.

If it is overridden then this functionality will be lost unless it is replaced or the ItemView implementation called.

Implements tbx::MouseClickListener.

◆ process_drag_selection()

virtual void tbx::view::ItemView::process_drag_selection ( const BBox drag_box,
bool  adjust 
)
inlineprotectedvirtual

Override this method to process selection by dragging.

allow_drag_selection must be set for this to be called.

Parameters
drag_boxFinal bounding box of drag
adjustadjust button was used for selection

Reimplemented in tbx::view::ReportView, tbx::view::ListView, and tbx::view::TileView.

◆ removed()

virtual void tbx::view::ItemView::removed ( unsigned int  where,
unsigned int  how_many 
)
pure virtual

Inform the view that items have been removed.

Parameters
wherelocation for removal
how_manynumber of items removed

Implemented in tbx::view::ReportView, tbx::view::ListView, and tbx::view::TileView.

◆ removing()

virtual void tbx::view::ItemView::removing ( unsigned int  where,
unsigned int  how_many 
)
inlinevirtual

Inform the view that items are about to be removed.

This call is optional, but it stops the need for a full scan of the list when auto size is on.

Reimplemented in tbx::view::ReportView, tbx::view::ListView, and tbx::view::TileView.

◆ screen_index()

virtual unsigned int tbx::view::ItemView::screen_index ( const Point scr_pt) const
pure virtual

Return the index under the screen point, does not check if it hits content of the item renderer.

Parameters
scr_ptthe point to test
Returns
the index of the item below the point or NO_INDEX if the point is not over an item.

Implemented in tbx::view::ReportView, tbx::view::ListView, and tbx::view::TileView.

◆ scroll_request()

void tbx::view::ItemView::scroll_request ( const tbx::ScrollRequestEvent event)
virtual

Process scroll requests.

This allows page clicks on the scroll bar to take into account the margins.

It makes line clicks on the scroll bar move 32 units left/right and 40 OS units up/down.

The appropriate flag in the window must be set for this event to be generated.

Override this to customise the scrolling behaviour.

Implements tbx::ScrollRequestListener.

◆ selection() [1/3]

void tbx::view::ItemView::selection ( Selection selection)

Set the selection model to use for the item view.

Parameters
selectionSelection model to use for selecting items in the list or 0 to disable selection.

◆ selection() [2/3]

Selection* tbx::view::ItemView::selection ( ) const
inline

Get the selection model used for selecting items in the list.

Returns
selection model or 0 if selection is not allowed

◆ selection() [3/3]

Selection* tbx::view::ItemView::selection ( )
inline

Get the selection model used for selecting items in the list.

Returns
selection model or 0 if selection is not allowed

◆ selection_changed()

void tbx::view::ItemView::selection_changed ( const SelectionChangedEvent event)
virtual

Selection has changed event handling.

The ItemView implementation forces a redraw of the items that have had there selection changed.

Implements tbx::view::SelectionListener.

◆ updates_enabled() [1/2]

void tbx::view::ItemView::updates_enabled ( bool  updates)
inline

Enable/disable updating of attached window.

After turning on updates - a call to update_window_extents to refresh the window

Parameters
updatestrue to turn on updates (the default), false to turn them off

◆ updates_enabled() [2/2]

bool tbx::view::ItemView::updates_enabled ( ) const
inline

Check if updates of the attached window are enabled.

Returns
true if updates are enabled

Member Data Documentation

◆ NO_INDEX

const unsigned int tbx::view::ItemView::NO_INDEX = -1
static

Constant for invalid index.

Used as a result from hit testing.


The documentation for this class was generated from the following files: