tbx  0.7.3
stringset.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  * stringset.h
27  *
28  * Created on: 28-Nov-2008
29  * Author: alanb
30  */
31 
32 #ifndef TBX_STRINGSET_H_
33 #define TBX_STRINGSET_H_
34 
35 #include "gadget.h"
36 #include "menu.h"
37 #include "listener.h"
38 #include "eventinfo.h"
39 
40 namespace tbx {
41 
42 class TextChangedListener;
43 class StringSetAboutToBeShownListener;
44 
45 
54 class StringSet: public tbx::Gadget
55 {
56 public:
57  enum {TOOLBOX_CLASS = 896};
58 
59  StringSet() {}
60 
67 
73  StringSet(const StringSet &other) : Gadget(other) {}
74 
84  StringSet(const Gadget &other) : Gadget(other) {check_toolbox_class(StringSet::TOOLBOX_CLASS);}
85 
93  StringSet(const Component &other) : Gadget(other) {}
94 
99  StringSet &operator=(const StringSet &other) {_handle = other.handle(); _id = other._id; return *this;}
100 
107  StringSet &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
108 
116  StringSet &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
117 
123  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
124 
130  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
131 
138  void available(const std::string &value) {string_property(896, value);}
139 
143  void selected(const std::string &value) {string_property(898, value);}
144 
148  std::string selected() const {return string_property(899);}
149 
154  void selected_index(int index);
155 
160  int selected_index() const;
161 
189  void allowable(const std::string &value) {string_property(900, value);}
190 
191  Gadget alphanumeric_gadget() const;
192  Menu popup_menu() const;
193 
194  // Listeners
197 
200 
201 };
202 
207 {
208 public:
210  virtual ~StringSetAboutToBeShownListener() {}
211 
217  virtual void stringset_about_to_be_shown(const EventInfo &event) = 0;
218 };
219 
220 }
221 
222 #endif /* TBX_STRINGSET_H_ */
void selected(const std::string &value)
Set the string to be selected.
Definition: stringset.h:143
Listener for the string set about to be shown event.
Definition: stringset.h:206
Class representing a toolbox menu.
Definition: menu.h:49
StringSet()
Construct an uninitialised display field.
Definition: stringset.h:59
StringSet wrapper class for an underlying toolbox StringSet gadget.
Definition: stringset.h:54
StringSet & operator=(const StringSet &other)
Assign a string set to refer to the same underlying toolbox gadget as another.
Definition: stringset.h:99
This is the base class for all Gadgets.
Definition: gadget.h:48
StringSet & operator=(const Component &other)
Assign a string set field to refer to the same underlying toolbox component as an existing Gadget...
Definition: stringset.h:116
virtual void stringset_about_to_be_shown(const EventInfo &event)=0
Method called just before the popup menu for a string set is shown.
StringSet(const StringSet &other)
Construct a string set from another string set.
Definition: stringset.h:73
void add_about_to_be_shown_listener(StringSetAboutToBeShownListener *listener)
Add a listener to be called just before the string set's menu is shown.
Definition: stringset.cc:158
bool operator==(const Gadget &other) const
Check if this string set refers to the same underlying toolbox gadget as another gadget.
Definition: stringset.h:123
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
~StringSet()
Destroy a string set gadget.
Definition: stringset.h:66
Menu popup_menu() const
Get the popup menu used with the string set.
Definition: stringset.cc:126
Gadget alphanumeric_gadget() const
Get the gadget used to display the selected string.
Definition: stringset.cc:114
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
StringSet & operator=(const Gadget &other)
Assign a string set to refer to the same underlying toolbox gadget as an existing Gadget...
Definition: stringset.h:107
Base class for components in an object.
Definition: component.h:42
void available(const std::string &value)
Set the list of strings available.
Definition: stringset.h:138
Listener for text changed events.
Definition: textchangedlistener.h:92
void allowable(const std::string &value)
Set the characters that are allowed to be entered into a string set.
Definition: stringset.h:189
std::string string_property(int property_id) const
Get a string property from the toolbox object.
Definition: component.cc:261
int selected_index() const
Get the index of the selected string in the available list.
Definition: stringset.cc:98
StringSet(const Gadget &other)
Construct a string set from another gadget.
Definition: stringset.h:84
void add_text_changed_listener(TextChangedListener *listener)
Add a listener to report when the text has changed in the string set.
Definition: stringset.cc:140
bool operator!=(const Gadget &other) const
Check if this string set refers to the same underlying toolbox gadget as another gadget.
Definition: stringset.h:130
The Window object represents a toolbox window.
Definition: window.h:69
Class to provide information on a toolbox event.
Definition: eventinfo.h:48
void remove_text_changed_listener(TextChangedListener *listener)
Remove a text changed listener.
Definition: stringset.cc:148
Base class for all toolbox event listeners.
Definition: listener.h:33
void remove_about_to_be_shown_listener(StringSetAboutToBeShownListener *listener)
Remove a listener to be called just before the string set's menu is shown.
Definition: stringset.cc:168
StringSet(const Component &other)
Construct a string set from a Component.
Definition: stringset.h:93
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
std::string selected() const
Get the currently selected string.
Definition: stringset.h:148
int _id
Underlying toolbox component id.
Definition: component.h:46
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95