tbx  0.7.5
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:
63  Object() : _handle(NULL_ObjectId) {}
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;
132  Component ancestor_component() 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 
146  void add_object_deleted_listener(ObjectDeletedListener *listener);
147  void remove_object_deleted_listener(ObjectDeletedListener *listener);
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
ObjectId _handle
Handle for toolbox object.
Definition: object.h:173
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
void(* RawToolboxEventHandler)(IdBlock &id_block, PollBlock &data, Listener *listener)
Function type for handlers of raw (unprocessed) Toolbox events.
Definition: pollinfo.h:86
const ObjectId NULL_ObjectId
NULL object id.
Definition: handles.h:42
Base class for commands in tbx.
Definition: command.h:36
Classes to use/edit toolbox resources in memory.
Object()
Constructs an object unattached to a toolbox object.
Definition: object.h:63
Base class for components in an object.
Definition: component.h:42
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
Listener for toolbox object deleted event.
Definition: objectdeletedlistener.h:49
Base class for all toolbox event listeners.
Definition: listener.h:33
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
bool operator==(const Object &other) const
Check if this object references the same toolbox object as another.
Definition: object.h:107
Object(ObjectId handle)
Construct an object referencing the given toolbox object.
Definition: object.h:70
bool null() const
Check if object has been initialised.
Definition: object.h:87
A UserEventListener can be used to capture any event on an object or component.
Definition: usereventlistener.h:62
Class to manipulate a toolbox object.
Definition: object.h:50
bool operator!=(const Object &other) const
Check if this object does not reference the same toolbox object as another.
Definition: object.h:114
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93