tbx  0.7.5
draggable.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 /*
27  * draggable.h
28  *
29  * Created on: 6-Jul-2010
30  * Author: alanb
31  */
32 
33 #ifndef TBX_DRAGABLE_H_
34 #define TBX_DRAGABLE_H_
35 
36 #include "gadget.h"
37 #include "mouseclicklistener.h"
38 
39 namespace tbx
40 {
41 
42 class DragStartedListener;
43 class DragEndedListener;
44 class PointerInfo;
45 
49 class Draggable: public tbx::Gadget
50 {
51 public:
52  enum {TOOLBOX_CLASS = 640};
53 
54  Draggable() {}
55 
61 
67  Draggable(const Draggable &other) : Gadget(other) {}
68 
78  Draggable(const Gadget &other) : Gadget(other) {check_toolbox_class(Draggable::TOOLBOX_CLASS);}
79 
86  Draggable(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(Draggable::TOOLBOX_CLASS);}
87 
92  Draggable &operator=(const Draggable &other) {_handle = other._handle; _id = other._id; return *this;}
93 
100  Draggable &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
101 
109  Draggable &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 
128  void sprite(std::string name) {string_property(640, name);}
129 
133  std::string sprite() const {return string_property(641);}
134 
138  int sprite_length() const {return string_property_length(641);}
139 
143  void text(std::string name) {string_property(642, name);}
144 
148  std::string text() const {return string_property(643);}
149 
153  int text_length() const {return string_property_length(643);}
154 
158  void selected(bool value) {bool_property(644, value);}
159 
163  bool selected() const {return bool_property(645);}
164 
169 
172 };
173 
178 {
179 public:
187  DragStartedEvent(IdBlock &id_block, PollBlock &data) :
188  EventInfo(id_block, data) {}
189 
193  bool adjust() const {return (_data.word[3] & 1) != 0;}
194 
198  bool select() const {return (_data.word[3] & 4) != 0;}
199 
203  bool shift() const {return (_data.word[3] & 8) != 0;}
207  bool control() const {return (_data.word[3] & 16) != 0;}
208 
209 };
210 
215 {
216 public:
217  virtual ~DragStartedListener() {}
218 
224  virtual void drag_started(const DragStartedEvent &drag_started_event) = 0;
225 };
226 
236 class DragEndedEvent : public EventInfo
237 {
238 public:
245  DragEndedEvent(IdBlock &id_block, PollBlock &data) :
246  EventInfo(id_block, data) {}
247 
252  bool toolbox_ids() const {return (_data.word[3] & 1) != 0;}
253 
259  Object object() const {return (toolbox_ids()) ? Object((ObjectId)_data.word[4]) : Object();}
260 
266  Component component() const {return (toolbox_ids()) ? Component((ObjectId)_data.word[4], (ComponentId)_data.word[5]) : Component();}
267 
271  WindowHandle window_handle() const {return (WindowHandle)_data.word[4];}
272 
276  IconHandle icon_handle() const {return (IconHandle)_data.word[5];}
277 
281  int x() const {return _data.word[6];}
282 
286  int y() const {return _data.word[7];}
287 
291  PointerInfo where() const;
292 };
293 
298 {
299 public:
300  virtual ~DragEndedListener() {}
306  virtual void drag_ended(const DragEndedEvent &drag_ended_event) = 0;
307 };
308 
309 }
310 
311 #endif /* TBX_DRAGABLE_H_ */
Draggable()
Construct an uninitialised draggable.
Definition: draggable.h:54
std::string sprite() const
Get name of sprite.
Definition: draggable.h:133
int text_length() const
Return length of text.
Definition: draggable.h:153
Class to store and fetch information about the WIMP mouse pointer.
Definition: pointerinfo.h:43
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
Draggable & operator=(const Component &other)
Assign a draggable to refer to the same underlying toolbox component as an existing Gadget...
Definition: draggable.h:109
void remove_drag_ended_listener(DragEndedListener *listener)
Remove listener for end of drag.
Definition: draggable.cc:80
void remove_drag_started_listener(DragStartedListener *listener)
Remove listener for start of drag.
Definition: draggable.cc:58
void sprite(std::string name)
Set name of sprite.
Definition: draggable.h:128
int x() const
x coordinate of drag finish
Definition: draggable.h:281
This is the base class for all Gadgets.
Definition: gadget.h:48
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
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
Listener for DragStarted events.
Definition: draggable.h:214
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
Listener for DragStarted events.
Definition: draggable.h:297
WindowHandle window_handle() const
Returns WIMP Window handle if toolbox_ids if false.
Definition: draggable.h:271
bool control() const
return true if control is held down
Definition: draggable.h:207
DragStartedEvent(IdBlock &id_block, PollBlock &data)
Construct a drag started event from the information returned for the toolbox.
Definition: draggable.h:187
int WindowHandle
Type for WIMP windows handle.
Definition: handles.h:35
bool selected() const
Get selected state of draggable.
Definition: draggable.h:163
void add_drag_ended_listener(DragEndedListener *listener)
Add listener for end of drag.
Definition: draggable.cc:72
Object object() const
Returns toolbox object at end of drag if toolbox_ids is true.
Definition: draggable.h:259
std::string string_property(int property_id) const
Get a string property from the toolbox object.
Definition: component.cc:261
Base class for components in an object.
Definition: component.h:42
int y() const
y coordinate of drag finish
Definition: draggable.h:286
Event information for Drag started event.
Definition: draggable.h:177
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
void remove_mouse_click_listener(MouseClickListener *listener)
Remove listener for mouse click on the button.
Definition: draggable.cc:96
void add_drag_started_listener(DragStartedListener *listener)
Add listener for start of drag.
Definition: draggable.cc:50
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
Listener for mouse clicks on a Window.
Definition: mouseclicklistener.h:129
bool toolbox_ids() const
Returns true if toolbox ids are returned at end of drag.
Definition: draggable.h:252
Draggable(const Gadget &other)
Construct a draggable from another gadget.
Definition: draggable.h:78
DragEndedEvent(IdBlock &id_block, PollBlock &data)
Construct the event from the information returned by the toolbox.
Definition: draggable.h:245
int IconHandle
Type for WIMP icon handle.
Definition: handles.h:37
bool select() const
return true if select is held down
Definition: draggable.h:198
void selected(bool value)
Set selected state of draggable.
Definition: draggable.h:158
The Window object represents a toolbox window.
Definition: window.h:69
Class to provide information on a toolbox event.
Definition: eventinfo.h:48
Base class for all toolbox event listeners.
Definition: listener.h:33
A Draggable is a gadget that shows.
Definition: draggable.h:49
int sprite_length() const
Return length of sprite name.
Definition: draggable.h:138
Event information for Drag ended event.
Definition: draggable.h:236
std::string text() const
Get text.
Definition: draggable.h:148
bool operator==(const Gadget &other) const
Check if this draggable refers to the same underlying toolbox gadget as another gadget.
Definition: draggable.h:116
Component component() const
Return toolbox component at end of drag if toolbox_ids is true.
Definition: draggable.h:266
void text(std::string name)
Set text.
Definition: draggable.h:143
bool shift() const
return true if shift is held down
Definition: draggable.h:203
IconHandle icon_handle() const
Return WIMP icon handle if toolbox_ids is false.
Definition: draggable.h:276
Draggable(const Draggable &other)
Construct a draggable from another draggable.
Definition: draggable.h:67
Component()
Construct an uninitialised component.
Definition: component.h:55
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
bool adjust() const
return true if adjust is held down
Definition: draggable.h:193
~Draggable()
Destroy a draggable gadget.
Definition: draggable.h:60
bool operator!=(const Gadget &other) const
Check if this draggable refers to the same underlying toolbox gadget as another gadget.
Definition: draggable.h:123
Draggable & operator=(const Gadget &other)
Assign a draggable to refer to the same underlying toolbox gadget as an existing Gadget.
Definition: draggable.h:100
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
void add_mouse_click_listener(MouseClickListener *listener)
Add listener for mouse click on the button.
Definition: draggable.cc:88
Draggable & operator=(const Draggable &other)
Assign a draggable to refer to the same underlying toolbox gadget as another.
Definition: draggable.h:92
int string_property_length(int property_id) const
Get a the length of a string property from the toolbox object.
Definition: component.cc:302
Draggable(const Component &other)
Construct a draggable from a component.
Definition: draggable.h:86