tbx  0.7.6
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_ */
tbx::ToolAction::operator=
ToolAction & operator=(const Component &other)
Assign a toolaction to refer to the same underlying toolbox component as an existing Gadget.
Definition: toolaction.h:109
tbx::ToolAction::remove_adjust_command
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
tbx::ToolAction::set_click_show
void set_click_show(Object select_object, Object adjust_object)
Set objects to show on select or adjust clicks.
Definition: toolaction.cc:189
tbx::ToolActionSelectedEvent::select
bool select() const
Check if select was held down.
Definition: toolaction.h:197
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::ToolAction::on
void on(bool value)
Set the on state.
Definition: toolaction.h:144
tbx::ToolAction::set_action
void set_action(int select_action, int adjust_action)
Set action to take on select and adjust clicks.
Definition: toolaction.cc:171
tbx::EventInfo::id_block
const IdBlock & id_block() const
IdBlock for the current event.
Definition: eventinfo.h:71
tbx::Window
The Window object represents a toolbox window.
Definition: window.h:70
tbx::ToolAction::ToolAction
ToolAction(const Gadget &other)
Construct a toolaction from another gadget.
Definition: toolaction.h:78
tbx::ToolAction::get_click_show
void get_click_show(Object &select_object, Object &adjust_object) const
Get the objects shown on select or adjust clicks.
Definition: toolaction.cc:198
tbx::EventInfo::_data
PollBlock & _data
raw data from the event
Definition: eventinfo.h:53
tbx::ToolAction::on_ident
std::string on_ident() const
Get text or sprite to show when button is on.
Definition: toolaction.cc:53
tbx::ToolAction::add_select_command
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
tbx::Component
Base class for components in an object.
Definition: component.h:42
tbx::PollBlock
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:72
tbx::ToolAction::fade_ident
std::string fade_ident() const
Get text or sprite to show when button is faded.
Definition: toolaction.cc:138
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::ToolAction::off_ident
std::string off_ident() const
Get text or sprite to show when button is off.
Definition: toolaction.cc:95
tbx::ToolAction::add_selected_listener
void add_selected_listener(ToolActionSelectedListener *listener)
Add listener for tool action button selected.
Definition: toolaction.cc:218
tbx::ToolAction::remove_select_command
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
tbx::ToolAction::operator!=
bool operator!=(const Gadget &other) const
Check if this toolaction refers to the same underlying toolbox gadget as another gadget.
Definition: toolaction.h:123
tbx::IdBlock
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:42
tbx::ToolAction::add_adjust_command
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
tbx::ToolAction::ToolAction
ToolAction(const ToolAction &other)
Construct a toolaction from another toolaction.
Definition: toolaction.h:67
tbx::ToolAction::remove_selected_command
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
tbx::ToolAction::ToolAction
ToolAction()
Construct an uninitialised toolaction.
Definition: toolaction.h:54
tbx::ToolAction::add_selected_command
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
tbx::ToolActionSelectedEvent::adjust
bool adjust() const
Check if adjust was held down.
Definition: toolaction.h:192
tbx::ToolAction::operator==
bool operator==(const Gadget &other) const
Check if this toolaction refers to the same underlying toolbox gadget as another gadget.
Definition: toolaction.h:116
tbx::ToolActionSelectedListener
Listener for ToolAction Selected events.
Definition: toolaction.h:209
tbx::ToolActionSelectedEvent::ToolActionSelectedEvent
ToolActionSelectedEvent(IdBlock &id_block, PollBlock &data)
Construct the event from Toolbox and WIMP event data.
Definition: toolaction.h:186
tbx::ToolActionSelectedEvent::on
bool on() const
Return true if tool action has been turned on.
Definition: toolaction.h:202
tbx::ToolAction::pressed
void pressed(bool value)
Set the pressed state.
Definition: toolaction.h:154
tbx::ToolAction::operator=
ToolAction & operator=(const Gadget &other)
Assign a toolaction to refer to the same underlying toolbox gadget as an existing Gadget.
Definition: toolaction.h:100
tbx::Component::bool_property
bool bool_property(int property_id) const
Get a boolean property from the toolbox Component.
Definition: component.cc:214
tbx::Object
Class to manipulate a toolbox object.
Definition: object.h:51
tbx::ToolAction::get_action
void get_action(int &select_action, int &adjust_action) const
Get the actions on select or adjust clicks.
Definition: toolaction.cc:180
tbx::ToolAction::operator=
ToolAction & operator=(const ToolAction &other)
Assign a toolaction to refer to the same underlying toolbox gadget as another.
Definition: toolaction.h:92
tbx::Listener
Base class for all toolbox event listeners.
Definition: listener.h:34
tbx::Command
Base class for commands in tbx.
Definition: command.h:37
tbx::ToolAction::on
bool on() const
Get the on state.
Definition: toolaction.h:149
tbx::ToolAction::remove_selected_listener
void remove_selected_listener(ToolActionSelectedListener *listener)
Remove listener for tool action button selected.
Definition: toolaction.cc:226
tbx::Component::_id
int _id
Underlying toolbox component id.
Definition: component.h:46
tbx::ToolActionSelectedListener::toolaction_selected
virtual void toolaction_selected(const ToolActionSelectedEvent &selected_event)=0
Method called when the tool action button is selected.
tbx::ToolAction
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:50
tbx::Gadget
This is the base class for all Gadgets.
Definition: gadget.h:49
tbx::ToolAction::~ToolAction
~ToolAction()
Destroy a toolaction gadget.
Definition: toolaction.h:60
tbx::PollBlock::word
int word[64]
Array containing information return from Wimp_Poll.
Definition: pollinfo.h:76
tbx::ToolAction::ToolAction
ToolAction(const Component &other)
Construct a toolaction from a component.
Definition: toolaction.h:86
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::ToolAction::pressed
bool pressed() const
Get the pressed state.
Definition: toolaction.h:159
tbx::EventInfo
Class to provide information on a toolbox event.
Definition: eventinfo.h:49
tbx::ToolActionSelectedEvent
Event information for ToolAction Selected events.
Definition: toolaction.h:178