tbx  0.7.6
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 class KeyListener;
41 
49 class WritableField: public tbx::Gadget {
50 public:
51  enum {TOOLBOX_CLASS = 512};
52 
54 
61 
67  WritableField(const WritableField &other) : Gadget(other) {}
68 
78  WritableField(const Gadget &other) : Gadget(other) {check_toolbox_class(WritableField::TOOLBOX_CLASS);}
79 
87  WritableField(const Component &other) : Gadget(other) {}
88 
93  WritableField &operator=(const WritableField &other) {_handle = other.handle(); _id = other._id; return *this;}
94 
101  WritableField &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
102 
110  WritableField &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
111 
117  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
118 
124  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
125 
131  void text(const std::string &value) {string_property(512, value);}
132 
136  std::string text() const {return string_property(513);}
137 
143  int text_length() const {return string_property_length(513);}
144 
172  void allowable(const std::string &value) {string_property(514, value);}
178  std::string allowable() const {return string_property(515);}
182  int allowable_length() const {return string_property_length(515);}
183 
184  void font(const std::string &name, int width, int height);
185  void system_font(int width, int height);
186 
187  // Listeners
190 
191  void add_key_listener(KeyListener *listener);
192  void remove_key_listener(KeyListener *listener);
193 };
194 
195 }
196 
197 #endif /* TBX_WRITEABLEFIELD_H_ */
tbx::WritableField::WritableField
WritableField(const Component &other)
Construct a writable field from a Component.
Definition: writablefield.h:87
tbx::Component::string_property
std::string string_property(int property_id) const
Get a string property from the toolbox object.
Definition: component.cc:261
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::WritableField::~WritableField
~WritableField()
Destroy a Writable Field gadget.
Definition: writablefield.h:60
tbx::WritableField::operator=
WritableField & operator=(const Component &other)
Assign a writable field to refer to the same underlying toolbox component as an existing Gadget.
Definition: writablefield.h:110
tbx::Component::handle
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
tbx::WritableField::operator==
bool operator==(const Gadget &other) const
Check if this display field refers to the same underlying toolbox gadget as another gadget.
Definition: writablefield.h:117
tbx::WritableField::operator!=
bool operator!=(const Gadget &other) const
Check if this display field refers to the same underlying toolbox gadget as another gadget.
Definition: writablefield.h:124
tbx::Window
The Window object represents a toolbox window.
Definition: window.h:70
tbx::WritableField::allowable
std::string allowable() const
Get the pattern that specifies the character that can be entered into this field.
Definition: writablefield.h:178
tbx::WritableField::remove_text_changed_listener
void remove_text_changed_listener(TextChangedListener *listener)
Remove a text changed listener.
Definition: writablefield.cc:133
tbx::Component
Base class for components in an object.
Definition: component.h:42
tbx::Component::_handle
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
tbx::Component::id
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
tbx::WritableField
WritableField wrapper class for an underlying toolbox WritableField gadget.
Definition: writablefield.h:49
tbx::WritableField::WritableField
WritableField(const Gadget &other)
Construct a writable field from another gadget.
Definition: writablefield.h:78
tbx::WritableField::font
void font(const std::string &name, int width, int height)
Set the font used for the writable field.
Definition: writablefield.cc:85
tbx::WritableField::text
std::string text() const
Get the the text that is being displayed.
Definition: writablefield.h:136
tbx::WritableField::system_font
void system_font(int width, int height)
Set the writable field to use the system font to display the text.
Definition: writablefield.cc:105
tbx::WritableField::text
void text(const std::string &value)
Set the the text to display.
Definition: writablefield.h:131
tbx::WritableField::text_length
int text_length() const
Get the length of the text property.
Definition: writablefield.h:143
tbx::WritableField::allowable_length
int allowable_length() const
Get the length of the allowable pattern.
Definition: writablefield.h:182
tbx::WritableField::add_key_listener
void add_key_listener(KeyListener *listener)
Add a listener to report the keys pressed in a Writable field.
Definition: writablefield.cc:141
tbx::WritableField::remove_key_listener
void remove_key_listener(KeyListener *listener)
Remove the keys pressed event.
Definition: writablefield.cc:149
tbx::WritableField::operator=
WritableField & operator=(const Gadget &other)
Assign a writable field to refer to the same underlying toolbox gadget as an existing Gadget.
Definition: writablefield.h:101
tbx::WritableField::operator=
WritableField & operator=(const WritableField &other)
Assign a writable field to refer to the same underlying toolbox gadget as another.
Definition: writablefield.h:93
tbx::WritableField::add_text_changed_listener
void add_text_changed_listener(TextChangedListener *listener)
Add a listener to report when the text has changed in the writable field.
Definition: writablefield.cc:125
tbx::Component::_id
int _id
Underlying toolbox component id.
Definition: component.h:46
tbx::TextChangedListener
Listener for text changed events.
Definition: textchangedlistener.h:93
tbx::Component::string_property_length
int string_property_length(int property_id) const
Get a the length of a string property from the toolbox object.
Definition: component.cc:302
tbx::KeyListener
Listener for KeyPressed WIMP event.
Definition: keylistener.h:179
tbx::Gadget
This is the base class for all Gadgets.
Definition: gadget.h:49
tbx::WritableField::WritableField
WritableField()
Construct an uninitialised display field.
Definition: writablefield.h:53
tbx::Gadget::check_toolbox_class
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
tbx::WritableField::allowable
void allowable(const std::string &value)
Definition: writablefield.h:172
tbx::WritableField::WritableField
WritableField(const WritableField &other)
Construct a writable field from another writableField.
Definition: writablefield.h:67