tbx  0.7.3
actionbutton.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 #ifndef TBX_ACTIONBUTTON_H
26 #define TBX_ACTIONBUTTON_H
27 
28 #include "gadget.h"
29 
30 namespace tbx
31 {
32  class ButtonSelectedListener;
33  class Command;
34 
40  class ActionButton : public Gadget
41  {
42  public:
43  enum { TOOLBOX_CLASS = 128 };
44 
46 
52  ActionButton(const ActionButton &other) : Gadget(other) {}
53 
63  ActionButton(const Gadget &other) : Gadget(other) {check_toolbox_class(ActionButton::TOOLBOX_CLASS);}
64 
71  ActionButton(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(ActionButton::TOOLBOX_CLASS);}
72 
77  ActionButton &operator=(const ActionButton &other) {_handle = other._handle; _id = other._id; return *this;}
78 
85  ActionButton &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
86 
94  ActionButton &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
95 
101  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
102 
108  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
109 
113  void text(const std::string &value) {string_property(128, value);}
114 
118  std::string text() const {return string_property(129);}
119 
125  int text_length() const {return string_property_length(129);}
126 
130  void event(int code) {int_property(130, code);}
131 
135  int event() const {return int_property(130);}
136 
137  void click_show(const Object &object, bool transient = false);
138  void clear_click_show();
139  bool has_click_show() const;
140  Object click_show(bool *transient = 0);
141 
144 
145  void add_selected_command(Command *command);
146  void remove_selected_command(Command *command);
147 
148  void add_select_command(Command *command);
149  void remove_select_command(Command *command);
150 
151  void add_adjust_command(Command *command);
152  void remove_adjust_command(Command *command);
153  };
154 }
155 
156 #endif
bool operator==(const Gadget &other) const
Check if this action button refers to the same underlying toolbox gadget as another gadget...
Definition: actionbutton.h:101
bool has_click_show() const
Check if action button will show an object.
Definition: actionbutton.cc:168
void remove_selected_listener(ButtonSelectedListener *listener)
Remove listener for button selected with the select or adjust mouse buttons or the keyboard (return o...
Definition: actionbutton.cc:66
Listener for button selected events.
Definition: buttonselectedlistener.h:82
void clear_click_show()
Clear object shown on click.
Definition: actionbutton.cc:149
ActionButton & operator=(const Gadget &other)
Assign a action button to refer to the same underlying toolbox gadget as an existing Gadget...
Definition: actionbutton.h:85
void add_select_command(Command *command)
Add command to be run if the button is selected with the select mouse button or the keyboard (return ...
Definition: actionbutton.cc:94
This is the base class for all Gadgets.
Definition: gadget.h:48
void click_show(const Object &object, bool transient=false)
Set object to show when the button is clicked.
Definition: actionbutton.cc:132
ActionButton & operator=(const ActionButton &other)
Assign a action button to refer to the same underlying toolbox gadget as another. ...
Definition: actionbutton.h:77
ActionButton(const Component &other)
Construct a action button from a gadget.
Definition: actionbutton.h:71
void add_adjust_command(Command *command)
Add command to be run if the button is selected with the adjust mouse button only.
Definition: actionbutton.cc:112
void add_selected_command(Command *command)
Add command to be run if the button is selected with the select or adjust mouse buttons or the keyboa...
Definition: actionbutton.cc:75
Base class for commands in tbx.
Definition: command.h:36
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
void text(const std::string &value)
Set the the text to display.
Definition: actionbutton.h:113
int int_property(int property_id) const
Get an integer property from the toolbox Component.
Definition: component.cc:165
ActionButton(const Gadget &other)
Construct a action button from another gadget.
Definition: actionbutton.h:63
ActionButton & operator=(const Component &other)
Assign a action button to refer to the same underlying toolbox component as an existing Gadget...
Definition: actionbutton.h:94
int string_property_length(int property_id) const
Get a the length of a string property from the toolbox object.
Definition: component.cc:302
void remove_select_command(Command *command)
Remove command to be run if the button is selected with the select mouse button or the keyboard (retu...
Definition: actionbutton.cc:103
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
void remove_selected_command(Command *command)
Remove command to be run if the button is selected with the select or adjust mouse buttons or the key...
Definition: actionbutton.cc:84
void remove_adjust_command(Command *command)
Remove command to be run if the button is selected with the adjust mouse button only.
Definition: actionbutton.cc:121
Base class for components in an object.
Definition: component.h:42
void event(int code)
Set the event to be raised when this action button is clicked.
Definition: actionbutton.h:130
bool operator!=(const Gadget &other) const
Check if this action button refers to the same underlying toolbox gadget as another gadget...
Definition: actionbutton.h:108
ActionButton()
Construct an uninitialised display field.
Definition: actionbutton.h:45
std::string string_property(int property_id) const
Get a string property from the toolbox object.
Definition: component.cc:261
ActionButton wrapper for an underlying toolbox ActionButton gadget.
Definition: actionbutton.h:40
The Window object represents a toolbox window.
Definition: window.h:69
int event() const
Get the event that will be raised when this action button is clicked.
Definition: actionbutton.h:135
std::string text() const
Get the the text this is being displayed.
Definition: actionbutton.h:118
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
void add_selected_listener(ButtonSelectedListener *listener)
Add listener for button selected with the select or adjust mouse buttons or the keyboard (return or e...
Definition: actionbutton.cc:57
int _id
Underlying toolbox component id.
Definition: component.h:46
Class to manipulate a toolbox object.
Definition: object.h:50
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
ActionButton(const ActionButton &other)
Construct a action button from another action button.
Definition: actionbutton.h:52
int text_length() const
Get the length of the text property.
Definition: actionbutton.h:125