tbx  0.7.3
writablefield.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  * writablefield.h
27  *
28  * Created on: 18-Sep-2008
29  * Author: alanb
30  */
31 
32 #ifndef TBX_WRITEABLEFIELD_H_
33 #define TBX_WRITEABLEFIELD_H_
34 
35 #include "gadget.h"
36 
37 namespace tbx {
38 
39 class TextChangedListener;
40 
48 class WritableField: public tbx::Gadget {
49 public:
50  enum {TOOLBOX_CLASS = 512};
51 
53 
60 
66  WritableField(const WritableField &other) : Gadget(other) {}
67 
77  WritableField(const Gadget &other) : Gadget(other) {check_toolbox_class(WritableField::TOOLBOX_CLASS);}
78 
86  WritableField(const Component &other) : Gadget(other) {}
87 
92  WritableField &operator=(const WritableField &other) {_handle = other.handle(); _id = other._id; return *this;}
93 
100  WritableField &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
101 
109  WritableField &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
110 
116  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
117 
123  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
124 
130  void text(const std::string &value) {string_property(512, value);}
131 
135  std::string text() const {return string_property(513);}
136 
142  int text_length() const {return string_property_length(513);}
143 
171  void allowable(const std::string &value) {string_property(514, value);}
177  std::string allowable() const {return string_property(515);}
181  int allowable_length() const {return string_property_length(515);}
182 
183  void font(const std::string &name, int width, int height);
184  void system_font(int width, int height);
185 
186  // Listeners
189 };
190 
191 }
192 
193 #endif /* TBX_WRITEABLEFIELD_H_ */
int text_length() const
Get the length of the text property.
Definition: writablefield.h:142
void font(const std::string &name, int width, int height)
Set the font used for the writable field.
Definition: writablefield.cc:84
void add_text_changed_listener(TextChangedListener *listener)
Add a listener to report when the text has changed in the writable field.
Definition: writablefield.cc:124
This is the base class for all Gadgets.
Definition: gadget.h:48
void system_font(int width, int height)
Set the writable field to use the system font to display the text.
Definition: writablefield.cc:104
WritableField & operator=(const WritableField &other)
Assign a writable field to refer to the same underlying toolbox gadget as another.
Definition: writablefield.h:92
void text(const std::string &value)
Set the the text to display.
Definition: writablefield.h:130
WritableField & operator=(const Gadget &other)
Assign a writable field to refer to the same underlying toolbox gadget as an existing Gadget...
Definition: writablefield.h:100
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
int string_property_length(int property_id) const
Get a the length of a string property from the toolbox object.
Definition: component.cc:302
WritableField(const WritableField &other)
Construct a writable field from another writableField.
Definition: writablefield.h:66
std::string allowable() const
Get the pattern that specifies the character that can be entered into this field. ...
Definition: writablefield.h:177
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
WritableField(const Component &other)
Construct a writable field from a Component.
Definition: writablefield.h:86
Base class for components in an object.
Definition: component.h:42
bool operator==(const Gadget &other) const
Check if this display field refers to the same underlying toolbox gadget as another gadget...
Definition: writablefield.h:116
Listener for text changed events.
Definition: textchangedlistener.h:92
std::string text() const
Get the the text that is being displayed.
Definition: writablefield.h:135
int allowable_length() const
Get the length of the allowable pattern.
Definition: writablefield.h:181
std::string string_property(int property_id) const
Get a string property from the toolbox object.
Definition: component.cc:261
WritableField(const Gadget &other)
Construct a writable field from another gadget.
Definition: writablefield.h:77
WritableField wrapper class for an underlying toolbox WritableField gadget.
Definition: writablefield.h:48
The Window object represents a toolbox window.
Definition: window.h:69
void allowable(const std::string &value)
Set the characters that are allowed to be entered into a writable field.
Definition: writablefield.h:171
~WritableField()
Destroy a Writable Field gadget.
Definition: writablefield.h:59
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
int _id
Underlying toolbox component id.
Definition: component.h:46
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
WritableField & operator=(const Component &other)
Assign a writable field to refer to the same underlying toolbox component as an existing Gadget...
Definition: writablefield.h:109
WritableField()
Construct an uninitialised display field.
Definition: writablefield.h:52
void remove_text_changed_listener(TextChangedListener *listener)
Remove a text changed listener.
Definition: writablefield.cc:132
bool operator!=(const Gadget &other) const
Check if this display field refers to the same underlying toolbox gadget as another gadget...
Definition: writablefield.h:123