tbx  0.7.6
button.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010-2011 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 /*
27  * button.h
28  *
29  * Created on: 6-Jul-2010
30  * Author: alanb
31  */
32 
33 #ifndef TBX_BUTTON_H_
34 #define TBX_BUTTON_H_
35 
36 #include "gadget.h"
37 #include "mouseclicklistener.h"
38 #include "eventinfo.h"
39 #include "colour.h"
40 
41 namespace tbx
42 {
43 
51 class Button: public tbx::Gadget
52 {
53 public:
54  enum {TOOLBOX_CLASS = 960};
55 
56  Button() {}
57 
62  ~Button() {}
63 
69  Button(const Button &other) : Gadget(other) {}
70 
80  Button(const Gadget &other) : Gadget(other) {check_toolbox_class(Button::TOOLBOX_CLASS);}
81 
88  Button(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(Button::TOOLBOX_CLASS);}
89 
94  Button &operator=(const Button &other) {_handle = other._handle; _id = other._id; return *this;}
95 
102  Button &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
103 
111  Button &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
112 
118  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
119 
125  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
126 
135  int flags() const {return int_property(960);}
136 
149  void flags(int clear, int eor);
155  bool has_text() const {return (flags() & 1)!=0;}
161  void has_text(bool value) {flags(1, value?1:0 );}
167  bool is_sprite() const {return (flags()&2)!=0;}
173  void is_sprite(bool value) {flags(2,value?2:0);}
179  bool has_border() const {return (flags() & 4)!=0;}
185  void has_border(bool value) {flags(4, value?4:0);}
191  bool hcentred() const {return (flags()&8)!=0;}
197  void hcentred(bool value) {flags(8, value?8:0);}
203  bool vcentred() const {return (flags()&16)!=0;}
209  void vcentred(bool value) {flags(16,value?16:0);}
215  bool filled() const {return (flags()&32)!=0;}
221  void filled(bool value) {flags(32, value?32:0);}
227  bool anti_aliased_font() const {return (flags()&64)!=0;}
237  void anti_aliased_font(bool value) {flags(64, value?64:0);}
238  // 6 text is an anti-aliased font (affects meaning of bits 24 - 31)
244  bool redraw_needs_help() const {return (flags()&128)!=0;}
250  void redraw_needs_help(bool value) {flags(128,value?128:0);}
251  // bit 8 - icon data is indirected always set
257  bool text_right_justified() const {return (flags() & 512)!=0;}
263  void text_right_justified(bool value) {flags(512, value?512:0);}
269  bool adjust_does_not_cancel() const {return (flags()&1024)!=0;}
275  void adjust_does_not_cancel(bool value) {flags(1024,value?1024:0);}
281  bool half_size_sprite() const {return (flags()&2048)!=0;}
287  void half_size_sprite(bool value) {flags(2048, value?2048:0);}
288 
293  {
294  IGNORE_CLICKS, // ignore mouse clicks or movements over the icon (except Menu)
295  CONTINUOUS, // notify task continuously while pointer is over this icon
296  CLICK_AUTO_REPEAT, // click notifies task (auto-repeat)
297  CLICK_ONCE, // click notifies task (once only)
298  CLICK_SELECTS, // click selects the icon; release over the icon notifies task; moving the pointer away deselects the icon
299  CLICK_SELECTS_DOUBLE, // click selects; double click notifies task
300  CLICK_ONCE_DRAG, // click notifies, but can also drag (returns button state * 16)
301  CLICK_SELECTS_DRAG, // as CLICK_SELECTS, but can also drag (returns button state * 16) and moving away from the icon doesn't deselect it
302  CLICK_SELECTS_DOUBLE_DRAG, // as CLICK_SELECTS_DOUBLE, but can also drag (returns button state * 16)
303  OVER_SELECTS, // pointer over icon selects; moving away from icon deselects; click over icon notifies task ('menu' icon)
304  CLICK_DOUBLE_DRAG, //click returns button state * 256, drag returns button state * 16, double click returns button state * 1
305  CLICK_NOTIFY_AND_SELECTS_DRAG, // click selects icon and returns button state, drag returns button state*16
306  FOCUS_AND_DRAG = 14, // clicks cause the icon to gain the caret and its parent window to become the input focus and can also drag (writable icon). For example, this is used by the FormEd application
307  WRITEABLE, // clicks cause the icon to gain the caret and its parent window to become the input focus (writable icon)
308  };
309 
315  ButtonType button_type() const {return ButtonType((flags() & 0xF000) >> 12);}
321  void button_type(ButtonType type) {flags(0xF000, ((int)type) << 12);}
322 
331  int esg() const {return (flags() & 0x1F0000) >> 16;}
340  void esg(int value) {flags(0x1F0000, value << 16);}
341 
349  WimpColour foreground() const {return WimpColour((flags()&0xF000000)>>24);} // !anti_aliased_font
357  void foreground(WimpColour value) {flags(0xF000000, ((int)value) << 24);}
365  WimpColour background() const {return WimpColour((flags()&0xF0000000)>>28);} // !anti_aliased_font
373  void background(WimpColour value) {flags(0xF0000000, ((int)value) << 28);}
374 
382  int font_handle() const {return (flags() & 0xFF000000) >> 24;} // anti_aliased_font
390  void font_handle(int value) {flags(0xFF000000, value << 24);}
391 
392 
396  void value(std::string v) {string_property(962, v);}
397 
401  std::string value() const {return string_property(963);}
402 
406  int value_length() const {return string_property_length(963);}
407 
411  void validation(std::string v) {string_property(964, v);}
412 
416  std::string validation() const {return string_property(965);}
417 
421  int validation_length() const {return string_property_length(965);}
422 
423  void font(const std::string &name, int width, int height);
424  void system_font(int width, int height);
425 
428 };
429 
430 }
431 
432 #endif /* TBX_BUTTON_H_ */
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::Button::button_type
void button_type(ButtonType type)
Set how the button processes mouse clicks.
Definition: button.h:321
tbx::Button::font_handle
int font_handle() const
Get the WIMP font handle for drawing text.
Definition: button.h:382
tbx::MouseClickListener
Listener for mouse clicks on a Window.
Definition: mouseclicklistener.h:130
tbx::Button::filled
void filled(bool value)
Set if the button background is filled.
Definition: button.h:221
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
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::Button::validation
std::string validation() const
Get the button validation.
Definition: button.h:416
tbx::Button::esg
void esg(int value)
Set the exclusive selection group (ESG) for the button.
Definition: button.h:340
tbx::Button::adjust_does_not_cancel
bool adjust_does_not_cancel() const
Check if the adjust does not cancel other selections in the same ESG group.
Definition: button.h:269
tbx::Button::operator=
Button & operator=(const Button &other)
Assign a button to refer to the same underlying toolbox gadget as another.
Definition: button.h:94
tbx::Button::Button
Button(const Component &other)
Construct a button from a component.
Definition: button.h:88
tbx::Button::half_size_sprite
bool half_size_sprite() const
Check if the button display the sprite half size.
Definition: button.h:281
tbx::Button::redraw_needs_help
bool redraw_needs_help() const
Check if the button need help from the user application to be redrawn.
Definition: button.h:244
tbx::Window
The Window object represents a toolbox window.
Definition: window.h:70
tbx::Button::operator=
Button & operator=(const Gadget &other)
Assign a button to refer to the same underlying toolbox gadget as an existing Gadget.
Definition: button.h:102
tbx::Button::foreground
WimpColour foreground() const
Return the foreground WIMP colour.
Definition: button.h:349
tbx::Component::int_property
int int_property(int property_id) const
Get an integer property from the toolbox Component.
Definition: component.cc:165
tbx::Component
Base class for components in an object.
Definition: component.h:42
tbx::Button::background
WimpColour background() const
Return the background WIMP colour.
Definition: button.h:365
tbx::Button::operator=
Button & operator=(const Component &other)
Assign a button to refer to the same underlying toolbox component as an existing Gadget.
Definition: button.h:111
tbx::Component::_handle
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
tbx::Button::font_handle
void font_handle(int value)
Set the WIMP font handle for drawing text.
Definition: button.h:390
tbx::Button::validation
void validation(std::string v)
Set the button validation.
Definition: button.h:411
tbx::Button::anti_aliased_font
void anti_aliased_font(bool value)
Set if the button uses an anti aliased font.
Definition: button.h:237
tbx::Component::id
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
tbx::Button::hcentred
bool hcentred() const
Check if the contents of the button are horizontally centred.
Definition: button.h:191
tbx::Button::value
std::string value() const
Get the button value.
Definition: button.h:401
tbx::Button::esg
int esg() const
Return the exclusive selection group (ESG) for the button.
Definition: button.h:331
tbx::Button::has_text
void has_text(bool value)
Set if the button shows text.
Definition: button.h:161
tbx::Button::half_size_sprite
void half_size_sprite(bool value)
Set if the button shows the sprite half size.
Definition: button.h:287
tbx::Button::button_type
ButtonType button_type() const
Get how the button processes mouse clicks.
Definition: button.h:315
tbx::Button::is_sprite
bool is_sprite() const
Check if the button shows a sprite.
Definition: button.h:167
tbx::Button::has_border
bool has_border() const
Check if the button has a border.
Definition: button.h:179
tbx::Button::add_mouse_click_listener
void add_mouse_click_listener(MouseClickListener *listener)
Add listener for mouse click on the button.
Definition: button.cc:89
tbx::Button::flags
int flags() const
Returns the flags for the button, these are the same as for a wimp icon.
Definition: button.h:135
tbx::Button::redraw_needs_help
void redraw_needs_help(bool value)
Set if the button need help from the user application to be redrawn.
Definition: button.h:250
tbx::Button::adjust_does_not_cancel
void adjust_does_not_cancel(bool value)
Set if the adjust does not cancel other selections in the same ESG group.
Definition: button.h:275
tbx::Button::vcentred
void vcentred(bool value)
Set if the contents of the button are vertically centred.
Definition: button.h:209
tbx::Button::vcentred
bool vcentred() const
Check if the contents of the button are vertically centred.
Definition: button.h:203
tbx::Button::foreground
void foreground(WimpColour value)
Set the foreground WIMP colour.
Definition: button.h:357
tbx::Button::Button
Button()
Construct an uninitialised button.
Definition: button.h:56
tbx::Button::font
void font(const std::string &name, int width, int height)
Set the font used for the button.
Definition: button.cc:53
tbx::Button::filled
bool filled() const
Check if the button background is filled.
Definition: button.h:215
tbx::Button::background
void background(WimpColour value)
Set the background WIMP colour.
Definition: button.h:373
tbx::Button::value
void value(std::string v)
Set the button value.
Definition: button.h:396
tbx::Button::Button
Button(const Gadget &other)
Construct a button from another gadget.
Definition: button.h:80
tbx::Button::system_font
void system_font(int width, int height)
Set the button to use the system font to display the text.
Definition: button.cc:73
tbx::Button::operator!=
bool operator!=(const Gadget &other) const
Check if this button refers to the same underlying toolbox gadget as another gadget.
Definition: button.h:125
tbx::Button::~Button
~Button()
Destroy a button gadget.
Definition: button.h:62
tbx::Button::remove_mouse_click_listener
void remove_mouse_click_listener(MouseClickListener *listener)
Remove listener for mouse click on the button.
Definition: button.cc:97
tbx::Button::has_border
void has_border(bool value)
Set if the button has a border.
Definition: button.h:185
tbx::Button::has_text
bool has_text() const
Check if the button shows text.
Definition: button.h:155
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::Button::hcentred
void hcentred(bool value)
Set if the contents of the button are horizontally centred.
Definition: button.h:197
tbx::Button::Button
Button(const Button &other)
Construct a button from another button.
Definition: button.h:69
tbx::Button::text_right_justified
bool text_right_justified() const
Check if the text on the button is right justified.
Definition: button.h:257
tbx::Gadget
This is the base class for all Gadgets.
Definition: gadget.h:49
tbx::Button::ButtonType
ButtonType
Enumeration for how the button processes clicks.
Definition: button.h:293
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::Button::operator==
bool operator==(const Gadget &other) const
Check if this button refers to the same underlying toolbox gadget as another gadget.
Definition: button.h:118
tbx::Button
A Button is a gadget that show a sprite or some text in the window.
Definition: button.h:52
tbx::Button::is_sprite
void is_sprite(bool value)
Set if the button shows a sprite.
Definition: button.h:173
tbx::Button::value_length
int value_length() const
Return the length of the button value.
Definition: button.h:406
tbx::Button::validation_length
int validation_length() const
Return the length of the button validation.
Definition: button.h:421
tbx::Button::anti_aliased_font
bool anti_aliased_font() const
Check if the button uses an anti aliased font.
Definition: button.h:227
tbx::Button::text_right_justified
void text_right_justified(bool value)
Set if the text on the button is right justified.
Definition: button.h:263