36 #include "../listener.h" 56 _first(first), _last(last), _selected(selected), _final(
final) {}
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;
157 void fire_event(
unsigned int index,
bool selected,
bool final);
158 void fire_event(
unsigned int from,
unsigned int to,
bool selected,
bool final);
172 enum Type {NONE, SINGLE, MULTIPLE};
177 static const unsigned int NO_SELECTION = -1;
182 virtual Type type()
const = 0;
189 virtual bool selected(
unsigned int index)
const = 0;
197 virtual unsigned int first()
const = 0;
201 virtual unsigned int last()
const = 0;
206 virtual bool empty()
const = 0;
214 virtual unsigned int count()
const = 0;
219 virtual bool any()
const = 0;
224 virtual bool one()
const = 0;
229 virtual bool many()
const = 0;
238 virtual void inserted(
unsigned int index,
unsigned int count) = 0;
247 virtual void removed(
unsigned int index,
unsigned int count) = 0;
252 virtual void clear() = 0;
261 virtual void set(
unsigned int index) = 0;
268 virtual void select(
unsigned int index) = 0;
275 virtual void deselect(
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;
370 virtual void next() = 0;
395 bool operator==(
const Iterator &other)
const;
396 bool operator!=(
const Iterator &other)
const;
397 unsigned int operator*()
const;
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;}
445 virtual bool empty()
const {
return (_selected == NO_SELECTION);}
450 virtual unsigned int count()
const {
return (_selected == NO_SELECTION) ? 0 : 1;}
455 virtual bool any()
const {
return (_selected != NO_SELECTION);}
460 virtual bool one()
const {
return (_selected != NO_SELECTION);};
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);
501 virtual IteratorImpl *
clone() {add_ref();
return this;}
507 virtual unsigned int index()
const {
return _index;}
513 virtual void next() {_index = NO_SELECTION;}
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;}
560 virtual bool empty()
const {
return (_first == NO_SELECTION);}
565 virtual unsigned int count()
const;
570 virtual bool any()
const {
return (_first != NO_SELECTION);}
575 virtual bool one()
const {
return (_first != NO_SELECTION && _first == _last);};
580 virtual bool many()
const {
return (_first != NO_SELECTION) && (_first < _last);}
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;
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 unsigned int first() const
Returns first selected item.
Definition: selection.h:436
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
SelectionChangedEvent(unsigned int first, unsigned int last, bool selected, bool final=true)
Construct a selection changed event.
Definition: selection.h:55
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
IteratorImpl()
Construct iterator implementation.
Definition: selection.h:331
virtual bool selected(unsigned int index) const
Returns true if an item is selected.
Definition: selection.h:429
Class derived to implement iterator.
Definition: selection.h:601
Helper classes to display and edit data.
virtual bool many() const
Always returns false.
Definition: selection.h:465
SingleIteratorImpl(unsigned int index)
Construct iterator for item with given index.
Definition: selection.h:495
bool shared() const
Check if the iterator implementation is being shared between two or more iterators.
Definition: selection.h:351
Class derived from in subclasses to actually provided the iterator implementation.
Definition: selection.h:324
Selection()
Protected constructor, must always use a subclass.
Definition: selection.h:154
void release()
Decrease reference count and delete this if reference count becomes zero.
Definition: selection.h:344
void add_ref()
Increase reference count.
Definition: selection.h:339
virtual bool any() const
Returns true if one or more items are selected.
Definition: selection.h:455
void first(unsigned int value)
Set first selected.
Definition: selection.h:77
Class to implement multiple selections.
Definition: selection.h:522
bool selected() const
Returns the type of the event.
Definition: selection.h:96
virtual bool any() const
Returns true if one or more items are selected.
Definition: selection.h:570
virtual unsigned int last() const
Returns last selected item.
Definition: selection.h:440
virtual unsigned int first() const
Returns first selected item.
Definition: selection.h:551
SelectionChangedEvent()
Default constructor creates a selection of item 0.
Definition: selection.h:60
virtual bool many() const
Returns true if there are more than one item selected.
Definition: selection.h:580
Class with the details of a select, deselect or toggle operation.
Definition: selection.h:44
virtual unsigned int count() const
Return the number of selected items.
Definition: selection.h:450
virtual IteratorImpl * get_iterator_impl() const
Override to return the iterator implementation for the selection iterator to used.
Definition: selection.h:515
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
virtual unsigned int index() const
Get the current index.
Definition: selection.h:507
unsigned int last() const
Returns the last selected/deselected item in the range.
Definition: selection.h:82
virtual bool empty() const
Returns true if selection is empty.
Definition: selection.h:560
void selected(bool value)
Set selected flag.
Definition: selection.h:101
Type
Type of selection.
Definition: selection.h:172
virtual void next()
Advance iterator.
Definition: selection.h:513
Class to iterate through all the selected indices.
Definition: selection.h:384
virtual unsigned int last() const
Returns last selected item.
Definition: selection.h:555
virtual bool empty() const
Returns true if selection is empty.
Definition: selection.h:445
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:33
virtual unsigned int index() const
Override this to get the current index.
Definition: selection.h:612
Class to represent a single selection.
Definition: selection.h:411
Class derived to implement iterator.
Definition: selection.h:486
Listener for selection changed events.
Definition: selection.h:129
void last(unsigned int value)
Set last selected.
Definition: selection.h:87
virtual ~IteratorImpl()
Destructor does nothing.
Definition: selection.h:335
virtual Type type() const
Returns the type of this selection class.
Definition: selection.h:537
Base class for selections of one or more indices from a zero based range.
Definition: selection.h:145
virtual Type type() const
Returns the type of this selection class.
Definition: selection.h:422
virtual bool one() const
Returns true if only one item is selected.
Definition: selection.h:460