tbx  0.7.5
scrolllist.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 #ifndef TBX_SCROLLLIST_H_
26 #define TBX_SCROLLLIST_H_
27 
28 #include "gadget.h"
29 #include "sprite.h"
30 #include "listener.h"
31 #include "eventinfo.h"
32 
33 namespace tbx
34 {
35 
36 class ScrollListSelectionListener;
37 
41 class ScrollList: public tbx::Gadget
42 {
43 public:
44  enum {TOOLBOX_CLASS = 0x401a};
45 
46  ScrollList() {}
47 
53 
59  ScrollList(const ScrollList &other) : Gadget(other) {}
60 
70  ScrollList(const Gadget &other) : Gadget(other) {check_toolbox_class(ScrollList::TOOLBOX_CLASS);}
71 
78  ScrollList(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(ScrollList::TOOLBOX_CLASS);}
79 
84  ScrollList &operator=(const ScrollList &other) {_handle = other._handle; _id = other._id; return *this;}
85 
92  ScrollList &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
93 
101  ScrollList &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
102 
108  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
109 
115  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
116 
120  int state() const {return int_property(0x401A);}
121 
127  void state(int value) {int_property(0x401B, value);}
128 
132  bool allow_multiple_selections() const {return flag_property(0x401A, 1);}
133 
139  void allow_multiple_selections(bool value) {flag_property(0x401A, 1, value);}
140 
141  void add_item(const std::string &text, int index = -1);
142  void add_item(const std::string &text, const WimpSprite &sprite, int index = -1);
143  void add_item(const std::string &text, const UserSprite &sprite, int index = -1);
144  void delete_item(int index);
145  void delete_items(int start, int end);
146  void clear();
147 
148  void select_unique_item(int index);
149  void select_item(int index);
150  void deselect_item(int index);
151  int first_selected() const;
152  int next_selected(int from) const;
153 
154  void make_visible(int index);
155  void item_text(int index, const std::string &text);
156  std::string item_text(int index) const;
157 
158  int count_items() const;
159 
160  void font(const std::string &name, int width, int height);
161  void system_font(int width, int height);
162 
163  void set_colour(WimpColour foreground, WimpColour background);
164  void set_colour(Colour foreground, Colour background);
165  void get_colour(Colour &foreground, Colour &background) const;
166 
169 };
170 
175 {
176 public:
184  EventInfo(id_block, data) {}
185 
186  virtual ~ScrollListSelectionEvent() {};
187 
191  int index() const {return _data.word[5];}
192 
193  /***
194  * true if index was selected
195  *
196  * Following flag does not seem to be set
197  * bool selected() const {return (_data.word[4] & 1) !=0;}
198  */
199 
203  bool double_click() const {return (_data.word[4] & 2) != 0;}
204 
208  int adjust() const {return (_data.word[4] & 4) != 0;}
209 };
210 
215 {
216 public:
217  virtual ~ScrollListSelectionListener() {}
218 
224  virtual void scrolllist_selection(const ScrollListSelectionEvent &event) = 0;
225 };
226 
227 
228 }
229 
230 #endif /* SCROLLLIST_H_ */
Item has been selected event.
Definition: scrolllist.h:174
void select_unique_item(int index)
Select an item, clearing any other selection.
Definition: scrolllist.cc:159
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
int int_property(int property_id) const
Get an integer property from the toolbox Component.
Definition: component.cc:165
void select_item(int index)
Add the specified item to the selection.
Definition: scrolllist.cc:175
int state() const
Get the state.
Definition: scrolllist.h:120
void make_visible(int index)
Ensure an item is visible in the scrolllist.
Definition: scrolllist.cc:244
void clear()
Delete all the items.
Definition: scrolllist.cc:142
This is the base class for all Gadgets.
Definition: gadget.h:48
ScrollList & operator=(const Component &other)
Assign a scroll list to refer to the same underlying toolbox component as an existing Gadget...
Definition: scrolllist.h:101
bool operator!=(const Gadget &other) const
Check if this scroll list refers to the same underlying toolbox gadget as another gadget...
Definition: scrolllist.h:115
ScrollList & operator=(const ScrollList &other)
Assign a scroll list to refer to the same underlying toolbox gadget as another.
Definition: scrolllist.h:84
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
void font(const std::string &name, int width, int height)
Set the font used for the scroll list items.
Definition: scrolllist.cc:332
void check_toolbox_class(int class_id) const
Check the underlying gadget class for this object has the given class id.
Definition: gadget.cc:47
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:71
void delete_items(int start, int end)
Delete a range of items.
Definition: scrolllist.cc:127
void system_font(int width, int height)
Set the scroll list to use the system font to display the text.
Definition: scrolllist.cc:351
bool flag_property(int property_id, int flag) const
Check if a particular flag is set in a property.
Definition: component.cc:351
bool allow_multiple_selections() const
Get Allow multiple selections.
Definition: scrolllist.h:132
Sprite from a user sprite area.
Definition: sprite.h:447
bool operator==(const Gadget &other) const
Check if this scroll list refers to the same underlying toolbox gadget as another gadget...
Definition: scrolllist.h:108
Class to represent a standard desktop WIMP colour.
Definition: colour.h:146
ScrollList(const Gadget &other)
Construct a scroll list from another gadget.
Definition: scrolllist.h:70
void get_colour(Colour &foreground, Colour &background) const
Get the colours used in the scrolllist.
Definition: scrolllist.cc:406
void allow_multiple_selections(bool value)
Set allow multiple selections.
Definition: scrolllist.h:139
Class for handling sprites from the Wimp sprite pool.
Definition: sprite.h:604
Base class for components in an object.
Definition: component.h:42
ScrollListSelectionEvent(IdBlock &id_block, PollBlock &data)
Construct the event from Toolbox and WIMP event data.
Definition: scrolllist.h:183
int adjust() const
true if event was caused by adjust button click
Definition: scrolllist.h:208
void add_selection_listener(ScrollListSelectionListener *listener)
Add listener for when the selected items changes.
Definition: scrolllist.cc:433
void item_text(int index, const std::string &text)
Update the text of an item.
Definition: scrolllist.cc:261
~ScrollList()
Destroy a scroll list gadget.
Definition: scrolllist.h:52
int count_items() const
Get the number of items in the scroll list.
Definition: scrolllist.cc:314
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
void remove_selection_listener(ScrollListSelectionListener *listener)
Remove listener for when the selected items changes.
Definition: scrolllist.cc:443
void deselect_item(int index)
Remove an item from the selection.
Definition: scrolllist.cc:191
void add_item(const std::string &text, int index=-1)
Add a text item to the scroll list.
Definition: scrolllist.cc:45
void state(int value)
Set the state.
Definition: scrolllist.h:127
ScrollList(const Component &other)
Construct a scroll list from a gadget.
Definition: scrolllist.h:78
ScrollList(const ScrollList &other)
Construct a scroll list from another scroll list.
Definition: scrolllist.h:59
The Window object represents a toolbox window.
Definition: window.h:69
Class to provide information on a toolbox event.
Definition: eventinfo.h:48
void delete_item(int index)
Delete an item.
Definition: scrolllist.cc:109
Base class for all toolbox event listeners.
Definition: listener.h:33
int first_selected() const
Return the first selected item.
Definition: scrolllist.cc:207
Class to represent a RGB colour.
Definition: colour.h:43
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
int index() const
Index of item event is for.
Definition: scrolllist.h:191
ScrollList & operator=(const Gadget &other)
Assign a scroll list to refer to the same underlying toolbox gadget as an existing Gadget...
Definition: scrolllist.h:92
int next_selected(int from) const
Return the next selected item id.
Definition: scrolllist.cc:226
Listener for selections on a scroll list.
Definition: scrolllist.h:214
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:41
bool double_click() const
true if index was double-clicked
Definition: scrolllist.h:203
int _id
Underlying toolbox component id.
Definition: component.h:46
void set_colour(WimpColour foreground, WimpColour background)
Set the colours of the scroll list using WIMP colours.
Definition: scrolllist.cc:370
Scrolling list of items with an optional sprite.
Definition: scrolllist.h:41
ScrollList()
Construct an uninitialised ScrollList range.
Definition: scrolllist.h:46