tbx  0.7.6
selectcommands.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 /*
26  * selectcommands.h
27  *
28  * Created on: 28 Apr 2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_SELECTCOMMANDS_H_
33 #define TBX_SELECTCOMMANDS_H_
34 
35 #include "../command.h"
36 #include "itemview.h"
37 namespace tbx
38 {
39 namespace view
40 {
41 
45 class SelectAllCommand : public Command
46 {
47  ItemView *_view;
48 public:
52  SelectAllCommand(ItemView *v) : _view(v) {}
56  virtual void execute()
57  {
58  if (_view->count())
59  {
60  _view->selection()->select(0, _view->count()-1);
61  }
62  }
63 };
64 
69 {
70  ItemView *_view;
71 public:
75  ClearSelectionCommand(ItemView *v) : _view(v) {}
79  virtual void execute() {_view->selection()->clear();}
80 };
81 
86 {
87  ItemView *_view;
88 public:
92  InvertSelectionCommand(ItemView *v) : _view(v) {}
96  virtual void execute()
97  {
98  if (_view->count())
99  {
100  _view->selection()->toggle(0, _view->count()-1);
101  }
102  }
103 };
104 
105 
106 }
107 }
108 
109 #endif /* TBX_SELECTCOMMANDS_H_ */
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::view::ItemView::count
unsigned int count() const
Returns number of items being displayed.
Definition: itemview.h:149
tbx::view::ItemView::selection
void selection(Selection *selection)
Set the selection model to use for the item view.
Definition: itemview.cc:76
tbx::view::SelectAllCommand::execute
virtual void execute()
Select all items in the given view.
Definition: selectcommands.h:56
tbx::view::InvertSelectionCommand::execute
virtual void execute()
Select all items in the given view.
Definition: selectcommands.h:96
tbx::view::SelectAllCommand::SelectAllCommand
SelectAllCommand(ItemView *v)
Constructor giving view.
Definition: selectcommands.h:52
tbx::view::ItemView
Base class for views that show an indexed list of items.
Definition: itemview.h:68
tbx::view::ClearSelectionCommand
Command to clear selection from the current view.
Definition: selectcommands.h:69
tbx::view::ClearSelectionCommand::execute
virtual void execute()
Select all items in the given view.
Definition: selectcommands.h:79
tbx::Command
Base class for commands in tbx.
Definition: command.h:37
tbx::view::InvertSelectionCommand
Command to invert selection in an item view.
Definition: selectcommands.h:86
tbx::view::SelectAllCommand
Command to select all items in an item view.
Definition: selectcommands.h:46
tbx::view::ClearSelectionCommand::ClearSelectionCommand
ClearSelectionCommand(ItemView *v)
Constructor giving view.
Definition: selectcommands.h:75
tbx::view::InvertSelectionCommand::InvertSelectionCommand
InvertSelectionCommand(ItemView *v)
Constructor giving view.
Definition: selectcommands.h:92