tbx  0.7.3
object.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_OBJECT_H
26 #define TBX_OBJECT_H
27 
28 #include <string>
29 #include "handles.h"
30 #include "pollinfo.h"
31 
32 namespace tbx
33 {
34  class Application;
35  class Command;
36  class UserEventListener;
37  class ObjectDeletedListener;
38  class Component;
39 
40  namespace res
41  {
42  class ResObject;
43  }
44 
50  class Object
51  {
52  protected:
53  Object(const res::ResObject &object_template);
54 
55  public:
64 
70  Object(ObjectId handle) : _handle(handle) {};
71 
76  Object(const Object &other) : _handle(other._handle) {};
77 
78  Object(const std::string &template_name);
79 
80  void delete_object();
81 
87  bool null() const {return (_handle == NULL_ObjectId);}
93  ObjectId handle() const {return _handle;}
94 
100  Object &operator=(const Object &other) {_handle = other._handle; return *this;}
107  bool operator==(const Object &other) const {return (_handle == other._handle);}
114  bool operator!=(const Object &other) const {return (_handle != other._handle);}
115 
121  operator bool() const {return (_handle != NULL_ObjectId);}
122 
123  int toolbox_class() const;
124  void check_toolbox_class(int class_id) const;
125 
126  void *client_handle() const;
127  void client_handle(void *client_handle);
128 
129  Object parent_object() const;
130  Component parent_component() const;
131  Object ancestor_object() const;
133 
134  // Visibility
135  void show();
136  void hide();
137  bool showing() const;
138 
139  // Listeners for all objects
140  void add_command(int command_id, Command *command);
141  void remove_command(int command_id, Command *command);
142 
143  void add_user_event_listener(int event_id, UserEventListener *listener);
144  void remove_user_event_listener(int event_id, UserEventListener *listener);
145 
148 
149  void remove_all_listeners();
150 
151  protected:
152  // Add listener helper
153  void add_listener( int action, Listener *listener, RawToolboxEventHandler handler);
154  void remove_listener(int action, Listener *listener);
155 
156  void set_handler(int action, Listener *listener, RawToolboxEventHandler handler);
157 
158  // Helper functions for standard properties
159  int int_property(int property_id) const;
160  void int_property(int property_id, int value);
161 
162  std::string string_property(int property_id) const;
163  void string_property(int property_id, const std::string &value);
164  int string_property_length(int property_id) const;
165 
166  bool bool_property(int property_id) const;
167  void bool_property(int property_id, bool value);
168 
169  protected:
174  };
175 }
176 
177 #endif
void remove_command(int command_id, Command *command)
Remove a command from this object.
Definition: object.cc:323
ObjectId _handle
Handle for toolbox object.
Definition: object.h:173
bool operator!=(const Object &other) const
Check if this object does not reference the same toolbox object as another.
Definition: object.h:114
Object parent_object() const
Get parent object.
Definition: object.cc:163
void add_command(int command_id, Command *command)
Add a command to this Object.
Definition: object.cc:309
void check_toolbox_class(int class_id) const
Check if this objects toolbox class is as specified.
Definition: object.cc:122
void(* RawToolboxEventHandler)(IdBlock &id_block, PollBlock &data, Listener *listener)
Function type for handlers of raw (unprocessed) Toolbox events.
Definition: pollinfo.h:86
void add_object_deleted_listener(ObjectDeletedListener *listener)
Add listener for when the toolbox object referenced by this object has been deleted.
Definition: object.cc:366
void hide()
Hide the object.
Definition: object.cc:261
void * client_handle() const
Return user defined handle stored against this object.
Definition: object.cc:136
const ObjectId NULL_ObjectId
NULL object id.
Definition: handles.h:42
int string_property_length(int property_id) const
Gets the size of a string properties buffer.
Definition: object.cc:530
Base class for commands in tbx.
Definition: command.h:36
Component ancestor_component() const
Get ancestor component.
Definition: object.cc:216
void add_user_event_listener(int event_id, UserEventListener *listener)
Add a user event listener.
Definition: object.cc:339
void set_handler(int action, Listener *listener, RawToolboxEventHandler handler)
Set handler for an event that should not have more than one listener.
Definition: object.cc:419
bool showing() const
Check if an object is currently showing.
Definition: object.cc:274
Object()
Constructs an object unattached to a toolbox object.
Definition: object.h:63
void add_listener(int action, Listener *listener, RawToolboxEventHandler handler)
Add a listener for the given toolbox event.
Definition: object.cc:392
void remove_user_event_listener(int event_id, UserEventListener *listener)
Remove a user event listener from this object.
Definition: object.cc:353
Component parent_component() const
Get parent component.
Definition: object.cc:181
void remove_listener(int action, Listener *listener)
Remove listener for toolbox event.
Definition: object.cc:405
Base class for components in an object.
Definition: component.h:42
int int_property(int property_id) const
Return the value of a property that returns an integer.
Definition: object.cc:435
std::string string_property(int property_id) const
Return the value of a property that returns text.
Definition: object.cc:477
bool bool_property(int property_id) const
Get a boolean property from the toolbox Cobject.
Definition: object.cc:553
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
Listener for toolbox object deleted event.
Definition: objectdeletedlistener.h:49
void remove_all_listeners()
Remove all listeners and commands from this object.
Definition: object.cc:292
void show()
Show the object at the default place.
Definition: object.cc:240
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
bool null() const
Check if object has been initialised.
Definition: object.h:87
void remove_object_deleted_listener(ObjectDeletedListener *listener)
Remove listener for when the toolbox object referenced by this object has been deleted.
Definition: object.cc:377
Base class for all toolbox event listeners.
Definition: listener.h:33
void delete_object()
Delete the underlying toolbox object.
Definition: object.cc:89
Object(const Object &other)
Construct an object referencing the same toolbox object as another.
Definition: object.h:76
Object & operator=(const Object &other)
Assign this object to reference the same toolbox object as another.
Definition: object.h:100
Base class for a resource object that can be edited.
Definition: resobject.h:52
Object(ObjectId handle)
Construct an object referencing the given toolbox object.
Definition: object.h:70
A UserEventListener can be used to capture any event on an object or component.
Definition: usereventlistener.h:62
int toolbox_class() const
Get the toolbox class of this object.
Definition: object.cc:104
Class to manipulate a toolbox object.
Definition: object.h:50
Object ancestor_object() const
Get ancestor object.
Definition: object.cc:198
bool operator==(const Object &other) const
Check if this object references the same toolbox object as another.
Definition: object.h:107