tbx  0.7.6
textarea.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  * textarea.h
27  *
28  * Created on: 30-Mar-2009
29  * Author: alanb
30  */
31 
32 #ifndef TBX_TEXTAREA_H_
33 #define TBX_TEXTAREA_H_
34 
35 #include "gadget.h"
36 #include "colour.h"
37 
38 namespace tbx {
39 
46 class TextArea: public tbx::Gadget
47 {
48 public:
49  enum {TOOLBOX_CLASS = 0x4018};
50 
51  TextArea() {}
52 
57  ~TextArea() {}
58 
64  TextArea(const TextArea &other) : Gadget(other) {}
65 
75  TextArea(const Gadget &other) : Gadget(other) {check_toolbox_class(TextArea::TOOLBOX_CLASS);}
76 
83  TextArea(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(TextArea::TOOLBOX_CLASS);}
84 
89  TextArea &operator=(const TextArea &other) {_handle = other._handle; _id = other._id; return *this;}
90 
97  TextArea &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
98 
106  TextArea &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
107 
113  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
114 
120  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
121 
122 
126  int state() const {return int_property(0x4018);}
127 
131  void state(int state) {int_property(0x4019, state);}
132 
138  bool has_vertical_scrollbar() const {return flag_property(0x4018, 1);}
143  void has_vertical_scrollbar(bool value) {flag_property(0x4018, 1, value);}
149  bool has_horizontal_scrollbar() const {return flag_property(0x4018, 2);}
154  void has_horizontal_scrollbar(bool value) {flag_property(0x4018, 2, value);}
160  bool wordwrap() const {return flag_property(0x4018, 4);}
166  void wordwrap(bool value) {flag_property(0x4018, 4, value);}
172  bool allow_selection() const {return flag_property(0x4018, 8);}
178  void allow_selection(bool value) {flag_property(0x4018, 8, value);}
184  bool allow_save() const {return flag_property(0x4018, 0x10);}
190  void allow_save(bool value) {flag_property(0x4018, 0x10, value);}
196  bool allow_load() const {return flag_property(0x4018, 0x20);}
202  void allow_load(bool value) {flag_property(0x4018, 0x20, value);}
208  bool clipboard() const {return flag_property(0x4018, 0x40);}
214  void clipboard(bool value) {flag_property(0x4018, 0x40, value);}
218  bool auto_scroll() const {return flag_property(0x4018, 0x80);}
224  void auto_scroll(bool value) {flag_property(0x4018, 0x80, value);}
225 
231  void text(const std::string &text) {string_property(0x401A, text);}
237  std::string text() const {return string_property(0x401B);}
241  int text_length() const {return string_property_length(0x401B);}
242 
243  void insert_text(int where, const std::string &text);
244  void replace_text(int start, int end, const std::string &text);
245 
246  void get_selecton(int &start, int &end) const;
247  void set_selection(int start, int end);
248  int selection_length() const;
249  std::string selection_text() const;
250 
251  void font(const std::string &name, int width, int height);
252  void system_font(int width, int height);
253 
254  void set_colour(WimpColour foreground, WimpColour background);
255  void set_colour(Colour foreground, Colour background);
256  void get_colour(Colour &foreground, Colour &background) const;
257 
263  void border_size(int value) {int_property(0x4023, value);}
264 };
265 
266 }
267 
268 #endif /* TBX_TEXTAREA_H_ */
tbx::TextArea::wordwrap
void wordwrap(bool value)
Set word wrapping in the text area.
Definition: textarea.h:166
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::TextArea::auto_scroll
bool auto_scroll() const
Check if text area will auto scroll.
Definition: textarea.h:218
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::TextArea::text_length
int text_length() const
Get the length of the text.
Definition: textarea.h:241
tbx::Component::handle
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
tbx::WimpColour
Class to represent a standard desktop WIMP colour.
Definition: colour.h:147
tbx::TextArea::border_size
void border_size(int value)
Set the size of the border for the text area.
Definition: textarea.h:263
tbx::TextArea::text
std::string text() const
Get the text from the text area.
Definition: textarea.h:237
tbx::TextArea::TextArea
TextArea()
Construct an uninitialised text area.
Definition: textarea.h:51
tbx::TextArea::clipboard
void clipboard(bool value)
Set if clipboard support is used the text area.
Definition: textarea.h:214
tbx::TextArea::has_horizontal_scrollbar
bool has_horizontal_scrollbar() const
Check if text area has a horizontal scroll bar.
Definition: textarea.h:149
tbx::Window
The Window object represents a toolbox window.
Definition: window.h:70
tbx::TextArea::TextArea
TextArea(const TextArea &other)
Construct a text area from another text area.
Definition: textarea.h:64
tbx::Component::int_property
int int_property(int property_id) const
Get an integer property from the toolbox Component.
Definition: component.cc:165
tbx::TextArea::allow_save
bool allow_save() const
Check if saving from the text area is allowed.
Definition: textarea.h:184
tbx::TextArea::replace_text
void replace_text(int start, int end, const std::string &text)
Rpelace text in the text area.
Definition: textarea.cc:64
tbx::TextArea::system_font
void system_font(int width, int height)
Set the scroll list to use the system font to display the text.
Definition: textarea.cc:192
tbx::TextArea::operator!=
bool operator!=(const Gadget &other) const
Check if this text area refers to the same underlying toolbox gadget as another gadget.
Definition: textarea.h:120
tbx::Component
Base class for components in an object.
Definition: component.h:42
tbx::TextArea::get_colour
void get_colour(Colour &foreground, Colour &background) const
Get the colours used in the text area.
Definition: textarea.cc:247
tbx::TextArea::operator=
TextArea & operator=(const TextArea &other)
Assign a text area to refer to the same underlying toolbox gadget as another.
Definition: textarea.h:89
tbx::TextArea::~TextArea
~TextArea()
Destroy a text area gadget.
Definition: textarea.h:57
tbx::Component::_handle
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
tbx::TextArea::operator=
TextArea & operator=(const Gadget &other)
Assign a text area to refer to the same underlying toolbox gadget as an existing Gadget.
Definition: textarea.h:97
tbx::Component::id
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
tbx::TextArea::operator==
bool operator==(const Gadget &other) const
Check if this text area refers to the same underlying toolbox gadget as another gadget.
Definition: textarea.h:113
tbx::TextArea::get_selecton
void get_selecton(int &start, int &end) const
Get location of selection.
Definition: textarea.cc:84
tbx::TextArea::allow_save
void allow_save(bool value)
Set if saving is allowed in the text area.
Definition: textarea.h:190
tbx::TextArea::font
void font(const std::string &name, int width, int height)
Set the font used for the scroll list items.
Definition: textarea.cc:172
tbx::TextArea::selection_length
int selection_length() const
Get the length of the selection.
Definition: textarea.cc:117
tbx::TextArea::has_horizontal_scrollbar
void has_horizontal_scrollbar(bool value)
Set if text area has a horizontal scroll bar.
Definition: textarea.h:154
tbx::Colour
Class to represent a RGB colour.
Definition: colour.h:44
tbx::TextArea::state
void state(int state)
Set all state flags.
Definition: textarea.h:131
tbx::TextArea::allow_load
bool allow_load() const
Check if loading from the text area is allowed.
Definition: textarea.h:196
tbx::TextArea::wordwrap
bool wordwrap() const
Check if text area is wrapping words.
Definition: textarea.h:160
tbx::TextArea::state
int state() const
Return all state flags.
Definition: textarea.h:126
tbx::TextArea::clipboard
bool clipboard() const
Check if this text area supports the clipboard.
Definition: textarea.h:208
tbx::TextArea::text
void text(const std::string &text)
Set the text in the text area.
Definition: textarea.h:231
tbx::TextArea::allow_selection
bool allow_selection() const
Check if text area allows a selection to be made.
Definition: textarea.h:172
tbx::TextArea::allow_load
void allow_load(bool value)
Set if loading is allowed in the text area.
Definition: textarea.h:202
tbx::TextArea::auto_scroll
void auto_scroll(bool value)
Set if text area will auto scroll.
Definition: textarea.h:224
tbx::TextArea::TextArea
TextArea(const Gadget &other)
Construct a text area from another gadget.
Definition: textarea.h:75
tbx::TextArea::selection_text
std::string selection_text() const
Get the text of the selection.
Definition: textarea.cc:134
tbx::Component::_id
int _id
Underlying toolbox component id.
Definition: component.h:46
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::TextArea
Class to manipulate a toolbox TextArea gadget.
Definition: textarea.h:47
tbx::TextArea::insert_text
void insert_text(int where, const std::string &text)
Insert text into the text area.
Definition: textarea.cc:45
tbx::Gadget
This is the base class for all Gadgets.
Definition: gadget.h:49
tbx::TextArea::operator=
TextArea & operator=(const Component &other)
Assign a text area to refer to the same underlying toolbox component as an existing Gadget.
Definition: textarea.h:106
tbx::Component::flag_property
bool flag_property(int property_id, int flag) const
Check if a particular flag is set in a property.
Definition: component.cc:351
tbx::TextArea::has_vertical_scrollbar
void has_vertical_scrollbar(bool value)
Set if text area has a vertical scroll bar.
Definition: textarea.h:143
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::TextArea::TextArea
TextArea(const Component &other)
Construct a text area from a gadget.
Definition: textarea.h:83
tbx::TextArea::allow_selection
void allow_selection(bool value)
Set if text can be selected in the text area.
Definition: textarea.h:178
tbx::TextArea::has_vertical_scrollbar
bool has_vertical_scrollbar() const
Check if text area has a vertical scroll bar.
Definition: textarea.h:138
tbx::TextArea::set_colour
void set_colour(WimpColour foreground, WimpColour background)
Set the colours of the text area using WIMP colours.
Definition: textarea.cc:211
tbx::TextArea::set_selection
void set_selection(int start, int end)
Set the selection.
Definition: textarea.cc:102