36 #include "../listener.h"
72 unsigned int first()
const {
return _first;}
77 void first(
unsigned int value) {_first = value;}
82 unsigned int last()
const {
return _last;}
87 void last(
unsigned int value) {_last = value;}
117 bool final()
const {
return _final;}
122 void final(
bool value) {_final = value;}
148 std::vector<SelectionListener *> _listeners;
172 enum Type {NONE, SINGLE, MULTIPLE};
189 virtual bool selected(
unsigned int index)
const = 0;
197 virtual unsigned int first()
const = 0;
201 virtual unsigned int last()
const = 0;
214 virtual unsigned int count()
const = 0;
219 virtual bool any()
const = 0;
224 virtual bool one()
const = 0;
261 virtual void set(
unsigned int index) = 0;
268 virtual void select(
unsigned int index) = 0;
282 virtual void toggle(
unsigned int index) = 0;
293 virtual void set(
unsigned int from,
unsigned int to) = 0;
301 virtual void select(
unsigned int from,
unsigned int to) = 0;
309 virtual void deselect(
unsigned int from,
unsigned int to) = 0;
317 virtual void toggle(
unsigned int from,
unsigned int to) = 0;
326 unsigned int _refcount;
344 void release() {
if (--_refcount == 0)
delete this;}
351 bool shared()
const {
return _refcount > 1;}
365 virtual unsigned int index()
const = 0;
414 unsigned int _selected;
429 virtual bool selected(
unsigned int index)
const {
return _selected == index;}
436 virtual unsigned int first()
const {
return _selected;}
440 virtual unsigned int last()
const {
return _selected;}
465 virtual bool many()
const {
return false;}
468 virtual void inserted(
unsigned int index,
unsigned int count);
469 virtual void removed(
unsigned int index,
unsigned int count);
472 virtual void clear();
473 virtual void set(
unsigned int index);
474 virtual void select(
unsigned int index);
475 virtual void deselect(
unsigned int index);
476 virtual void toggle(
unsigned int index);
477 virtual void set(
unsigned int from,
unsigned int to);
478 virtual void select(
unsigned int from,
unsigned int to);
479 virtual void deselect(
unsigned int from,
unsigned int to);
480 virtual void toggle(
unsigned int from,
unsigned int to);
507 virtual unsigned int index()
const {
return _index;}
524 typedef std::pair<unsigned int, unsigned int> Range;
527 std::vector<Range> _selected;
528 typedef std::vector<Range>::iterator RangeIterator;
529 typedef std::vector<Range>::const_iterator ConstRangeIterator;
544 virtual bool selected(
unsigned int index)
const;
551 virtual unsigned int first()
const {
return _first;}
555 virtual unsigned int last()
const {
return _last;}
565 virtual unsigned int count()
const;
583 virtual void inserted(
unsigned int index,
unsigned int count);
584 virtual void removed(
unsigned int index,
unsigned int count);
587 virtual void clear();
588 virtual void set(
unsigned int index);
589 virtual void select(
unsigned int index);
590 virtual void deselect(
unsigned int index);
591 virtual void toggle(
unsigned int index);
592 virtual void set(
unsigned int from,
unsigned int to);
593 virtual void select(
unsigned int from,
unsigned int to);
594 virtual void deselect(
unsigned int from,
unsigned int to);
595 virtual void toggle(
unsigned int from,
unsigned int to);
603 ConstRangeIterator _current;
604 ConstRangeIterator _end;
610 virtual IteratorImpl *
clone();
612 virtual unsigned int index()
const {
return _index;}
620 RangeIterator find_last_ge(
unsigned int index);
621 void fire_changes(std::vector<SelectionChangedEvent> &changes);
virtual void set(unsigned int index)
Select an item.
Definition: selection.cc:271
Listener for selection changed events.
Definition: selection.h:130
virtual bool selected(unsigned int index) const
Returns true if an item is selected.
Definition: selection.cc:411
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
SingleIteratorImpl(unsigned int index)
Construct iterator for item with given index.
Definition: selection.h:495
SelectionChangedEvent()
Default constructor creates a selection of item 0.
Definition: selection.h:60
void remove_listener(SelectionListener *listener)
Remove listener for selection changes.
Definition: selection.cc:80
void add_listener(SelectionListener *listener)
Add listeners.
Definition: selection.cc:72
unsigned int operator*() const
Get index for iterator.
Definition: selection.cc:165
virtual void clear()
Clear the selection.
Definition: selection.cc:509
bool final() const
Returns true if this is the last event in a group of events triggered by a single action.
Definition: selection.h:117
Iterator begin() const
Get iterator to first selected item.
Definition: selection.cc:95
virtual bool empty() const =0
Override to return true if selection is empty.
virtual IteratorImpl * get_iterator_impl() const =0
Override to return the iterator implementation for the selection iterator to used.
unsigned int first() const
Returns the first selected/deselected item in the range.
Definition: selection.h:72
virtual IteratorImpl * clone()
Get copy of this iterator implentation.
Definition: selection.h:501
void fire_event(const SelectionChangedEvent &event)
Helper for subclasses to fire Selection Changed Events.
Definition: selection.cc:44
virtual void select(unsigned int from, unsigned int to)=0
Override to selection a range of items.
virtual void deselect(unsigned int index)
Remove selection from given index.
Definition: selection.cc:650
virtual bool selected(unsigned int index) const =0
Override to return true if an item is selected.
virtual void deselect(unsigned int from, unsigned int to)=0
Override to deselect a range of items.
virtual unsigned int last() const
Returns last selected item.
Definition: selection.h:440
virtual void toggle(unsigned int from, unsigned int to)=0
Override to toggle the selection of a range of items.
virtual IteratorImpl * clone()
Make a copy of the current iterator.
Definition: selection.cc:1043
virtual unsigned int first() const =0
Override to return first selected item.
Selection()
Protected constructor, must always use a subclass.
Definition: selection.h:154
virtual Type type() const =0
Override to return the type of this selection class.
Iterator & operator++()
Prefix operator.
Definition: selection.cc:173
virtual void set(unsigned int index)
Modifiy the selection so it only consist of the given index.
Definition: selection.cc:535
virtual void set(unsigned int index)=0
Override to change selection to given item.
virtual unsigned int index() const
Get the current index.
Definition: selection.h:507
bool selected() const
Returns the type of the event.
Definition: selection.h:96
virtual bool selected(unsigned int index) const
Returns true if an item is selected.
Definition: selection.h:429
bool shared() const
Check if the iterator implementation is being shared between two or more iterators.
Definition: selection.h:351
virtual ~IteratorImpl()
Destructor does nothing.
Definition: selection.h:335
void release()
Decrease reference count and delete this if reference count becomes zero.
Definition: selection.h:344
virtual bool any() const
Returns true if one or more items are selected.
Definition: selection.h:455
MultiIteratorImpl(ConstRangeIterator start, ConstRangeIterator end)
Construct iterator implementation from iterators.
Definition: selection.cc:1032
void selected(bool value)
Set selected flag.
Definition: selection.h:101
virtual unsigned int last() const
Returns last selected item.
Definition: selection.h:555
virtual bool any() const
Returns true if one or more items are selected.
Definition: selection.h:570
virtual bool one() const =0
Override to return true if only one item is selected.
Class derived from in subclasses to actually provided the iterator implementation.
Definition: selection.h:325
IteratorImpl()
Construct iterator implementation.
Definition: selection.h:331
virtual void toggle(unsigned int index)
Toggle the selected index.
Definition: selection.cc:690
virtual void clear()=0
Override to clear the current selection.
virtual void selection_changed(const SelectionChangedEvent &event)=0
Called whenever the selection has been changed.
Iterator & operator=(const Iterator &other)
Assignment.
Definition: selection.cc:130
virtual unsigned int last() const =0
Override to return last selected item.
virtual void inserted(unsigned int index, unsigned int count)
Data has been inserted so adjust selection.
Definition: selection.cc:443
virtual void toggle(unsigned int index)=0
Override to toggle the selection for an item.
virtual void inserted(unsigned int index, unsigned int count)=0
Override called by the object selection is on when new items have been inserted and selected items ne...
Class to implement multiple selections.
Definition: selection.h:523
virtual bool empty() const
Returns true if selection is empty.
Definition: selection.h:560
void add_ref()
Increase reference count.
Definition: selection.h:339
virtual bool many() const =0
Override to return true if more than one item is selected.
virtual unsigned int first() const
Returns first selected item.
Definition: selection.h:436
virtual bool many() const
Returns true if there are more than one item selected.
Definition: selection.h:580
virtual bool empty() const
Returns true if selection is empty.
Definition: selection.h:445
virtual unsigned int first() const
Returns first selected item.
Definition: selection.h:551
Class with the details of a select, deselect or toggle operation.
Definition: selection.h:45
virtual bool many() const
Always returns false.
Definition: selection.h:465
virtual IteratorImpl * clone()=0
Override this method to return a copy of the iterator implementation.
virtual unsigned int count() const
Return the number of selected items.
Definition: selection.cc:428
Class to represent a single selection.
Definition: selection.h:412
virtual void next()
Advance iterator.
Definition: selection.h:513
virtual bool one() const
Returns true if only one item is selected.
Definition: selection.h:575
Base class for all toolbox event listeners.
Definition: listener.h:34
virtual IteratorImpl * get_iterator_impl() const
Override to return the iterator implementation for the selection iterator to used.
Definition: selection.h:515
virtual void clear()
Clear the current selection.
Definition: selection.cc:241
Class to iterate through all the selected indices.
Definition: selection.h:385
Class derived to implement iterator.
Definition: selection.h:487
Type
Type of selection.
Definition: selection.h:172
Iterator end() const
Get iterator to end of selection.
Definition: selection.cc:105
virtual void select(unsigned int index)=0
Override to select an item.
virtual void removed(unsigned int index, unsigned int count)=0
Override called by the object selection is on when items have been removed and selected items to be d...
virtual unsigned int count() const
Return the number of selected items.
Definition: selection.h:450
bool operator==(const Iterator &other) const
Compare two iterators.
Definition: selection.cc:144
virtual void select(unsigned int index)
Select an item.
Definition: selection.cc:259
static const unsigned int NO_SELECTION
Constant for indices when there is no selection.
Definition: selection.h:177
virtual void deselect(unsigned int index)=0
Override to clear the selection for an item.
virtual unsigned int count() const =0
Override to return the number of selected items.
virtual void toggle(unsigned int index)
Toggle the selection for an item.
Definition: selection.cc:307
virtual void inserted(unsigned int index, unsigned int count)
Called by the object selection is on when new items have been inserted and selected item need to be m...
Definition: selection.cc:209
virtual void select(unsigned int index)
Add the index to the selection.
Definition: selection.cc:584
virtual void next()=0
Override this method to advance the iterator to the next item.
Base class for selections of one or more indices from a zero based range.
Definition: selection.h:146
bool operator!=(const Iterator &other) const
Compare two iterators.
Definition: selection.cc:154
virtual void next()
Advance iterator.
Definition: selection.cc:1053
unsigned int last() const
Returns the last selected/deselected item in the range.
Definition: selection.h:82
virtual bool any() const =0
Override to return true if one or more items are selected.
virtual void removed(unsigned int index, unsigned int count)
Called by the object selection is on when items have been removed and selected item to be deleted or ...
Definition: selection.cc:224
virtual Type type() const
Returns the type of this selection class.
Definition: selection.h:422
Class derived to implement iterator.
Definition: selection.h:602
virtual unsigned int index() const =0
Override this to get the current index.
virtual void set(unsigned int from, unsigned int to)=0
Override to change selection to given item.
virtual void removed(unsigned int index, unsigned int count)
Data has been removed so adjust selection.
Definition: selection.cc:471
virtual IteratorImpl * get_iterator_impl() const
Get initial iterator implementation.
Definition: selection.cc:1071
virtual void deselect(unsigned int index)
Clear the selection for an item.
Definition: selection.cc:293
void last(unsigned int value)
Set last selected.
Definition: selection.h:87
SelectionChangedEvent(unsigned int first, unsigned int last, bool selected, bool final=true)
Construct a selection changed event.
Definition: selection.h:55
virtual bool one() const
Returns true if only one item is selected.
Definition: selection.h:460
virtual Type type() const
Returns the type of this selection class.
Definition: selection.h:537
void first(unsigned int value)
Set first selected.
Definition: selection.h:77