tbx  0.7.5
toolaction.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  * toolaction.h
27  *
28  * Created on: 6-Jul-2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_TOOLACTION_H_
33 #define TBX_TOOLACTION_H_
34 
35 #include "gadget.h"
36 #include "listener.h"
37 #include "eventinfo.h"
38 
39 namespace tbx
40 {
41 
42 class ToolActionSelectedListener;
43 class Command;
44 
49 class ToolAction: public tbx::Gadget
50 {
51 public:
52  enum {TOOLBOX_CLASS = 0x4014};
53 
54  ToolAction() {}
55 
61 
67  ToolAction(const ToolAction &other) : Gadget(other) {}
68 
78  ToolAction(const Gadget &other) : Gadget(other) {check_toolbox_class(ToolAction::TOOLBOX_CLASS);}
79 
86  ToolAction(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(ToolAction::TOOLBOX_CLASS);}
87 
92  ToolAction &operator=(const ToolAction &other) {_handle = other._handle; _id = other._id; return *this;}
93 
100  ToolAction &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
101 
109  ToolAction &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 
125  // Idents (text or sprite)
126  void on_ident(std::string text);
127  std::string on_ident() const;
128  void off_ident(std::string text);
129  std::string off_ident() const;
130  void fade_ident(std::string text);
131  std::string fade_ident() const;
132 
133  // Actions
134  void set_action(int select_action, int adjust_action);
135  void get_action(int &select_action, int &adjust_action) const;
136 
137  // click show
138  void set_click_show(Object select_object, Object adjust_object);
139  void get_click_show(Object &select_object, Object &adjust_object) const;
140 
144  void on(bool value) {bool_property(0x140146, value);}
145 
149  bool on() const {return bool_property(0x140147);}
150 
154  void pressed(bool value) {bool_property(0x140148, value);}
155 
159  bool pressed() const {return bool_property(0x140149);}
160 
163 
164  void add_selected_command(Command *command);
165  void remove_selected_command(Command *command);
166 
167  void add_select_command(Command *command);
168  void remove_select_command(Command *command);
169 
170  void add_adjust_command(Command *command);
171  void remove_adjust_command(Command *command);
172 };
173 
178 {
179 public:
187  EventInfo(id_block, data) {}
188 
192  bool adjust() const {return (_data.word[3] & 1)!=0;}
193 
197  bool select() const {return (_data.word[3] & 4)!=0;}
198 
202  bool on() const {return (_data.word[4] != 0);}
203 };
204 
209 {
210 public:
211  virtual ~ToolActionSelectedListener() {}
212 
218  virtual void toolaction_selected(const ToolActionSelectedEvent &selected_event) = 0;
219 };
220 
221 }
222 
223 #endif /* TBX_TOOLACTION_H_ */
void set_click_show(Object select_object, Object adjust_object)
Set objects to show on select or adjust clicks.
Definition: toolaction.cc:189
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
std::string on_ident() const
Get text or sprite to show when button is on.
Definition: toolaction.cc:53
void add_select_command(Command *command)
Add command to be run if the button is selected with the select mouse button.
Definition: toolaction.cc:263
void remove_adjust_command(Command *command)
Remove command to be run if the button is selected with the adjust mouse button only.
Definition: toolaction.cc:289
A ToolAction is a gadget that shows a button that changes it's sprite or text depending on if it is o...
Definition: toolaction.h:49
This is the base class for all Gadgets.
Definition: gadget.h:48
ToolAction & operator=(const Component &other)
Assign a toolaction to refer to the same underlying toolbox component as an existing Gadget...
Definition: toolaction.h:109
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
void set_action(int select_action, int adjust_action)
Set action to take on select and adjust clicks.
Definition: toolaction.cc:171
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
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:71
ToolAction(const Gadget &other)
Construct a toolaction from another gadget.
Definition: toolaction.h:78
Base class for commands in tbx.
Definition: command.h:36
bool adjust() const
Check if adjust was held down.
Definition: toolaction.h:192
void add_selected_command(Command *command)
Add command to be run if the button is selected with the select or adjust.
Definition: toolaction.cc:246
void on(bool value)
Set the on state.
Definition: toolaction.h:144
bool operator==(const Gadget &other) const
Check if this toolaction refers to the same underlying toolbox gadget as another gadget.
Definition: toolaction.h:116
void get_click_show(Object &select_object, Object &adjust_object) const
Get the objects shown on select or adjust clicks.
Definition: toolaction.cc:198
std::string fade_ident() const
Get text or sprite to show when button is faded.
Definition: toolaction.cc:138
void remove_select_command(Command *command)
Remove command to be run if the button is selected with the select mouse button.
Definition: toolaction.cc:271
ToolActionSelectedEvent(IdBlock &id_block, PollBlock &data)
Construct the event from Toolbox and WIMP event data.
Definition: toolaction.h:186
void pressed(bool value)
Set the pressed state.
Definition: toolaction.h:154
ToolAction()
Construct an uninitialised toolaction.
Definition: toolaction.h:54
Base class for components in an object.
Definition: component.h:42
void add_selected_listener(ToolActionSelectedListener *listener)
Add listener for tool action button selected.
Definition: toolaction.cc:218
std::string off_ident() const
Get text or sprite to show when button is off.
Definition: toolaction.cc:95
ToolAction(const ToolAction &other)
Construct a toolaction from another toolaction.
Definition: toolaction.h:67
void add_adjust_command(Command *command)
Add command to be run if the button is selected with the adjust mouse button only.
Definition: toolaction.cc:280
bool select() const
Check if select was held down.
Definition: toolaction.h:197
bool operator!=(const Gadget &other) const
Check if this toolaction refers to the same underlying toolbox gadget as another gadget.
Definition: toolaction.h:123
bool bool_property(int property_id) const
Get a boolean property from the toolbox Component.
Definition: component.cc:214
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
void get_action(int &select_action, int &adjust_action) const
Get the actions on select or adjust clicks.
Definition: toolaction.cc:180
Listener for ToolAction Selected events.
Definition: toolaction.h:208
void remove_selected_command(Command *command)
Remove command to be run if the button is selected with the select or adjust.
Definition: toolaction.cc:254
void remove_selected_listener(ToolActionSelectedListener *listener)
Remove listener for tool action button selected.
Definition: toolaction.cc:226
The Window object represents a toolbox window.
Definition: window.h:69
ToolAction(const Component &other)
Construct a toolaction from a component.
Definition: toolaction.h:86
Class to provide information on a toolbox event.
Definition: eventinfo.h:48
bool on() const
Get the on state.
Definition: toolaction.h:149
~ToolAction()
Destroy a toolaction gadget.
Definition: toolaction.h:60
Base class for all toolbox event listeners.
Definition: listener.h:33
ToolAction & operator=(const Gadget &other)
Assign a toolaction to refer to the same underlying toolbox gadget as an existing Gadget...
Definition: toolaction.h:100
ToolAction & operator=(const ToolAction &other)
Assign a toolaction to refer to the same underlying toolbox gadget as another.
Definition: toolaction.h:92
Event information for ToolAction Selected events.
Definition: toolaction.h:177
bool pressed() const
Get the pressed state.
Definition: toolaction.h:159
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:41
int _id
Underlying toolbox component id.
Definition: component.h:46
Class to manipulate a toolbox object.
Definition: object.h:50
bool on() const
Return true if tool action has been turned on.
Definition: toolaction.h:202