tbx  0.7.5
gadget.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010-2015 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_GADGET_H
26 #define TBX_GADGET_H
27 
28 #include "window.h"
29 #include "component.h"
30 #include <vector>
31 
32 namespace tbx
33 {
34  class Loader;
35 
48  class Gadget : public tbx::Component
49  {
50  private:
51  Gadget(ObjectId handle, ComponentId id) : Component(handle, id) {};
52  friend class Window;
53 
54  public:
61  Gadget() {}
62 
68  Gadget(const Gadget &other) : Component(other.handle(), other.id()) {};
69 
78  Gadget(const Component &other) : Component(other) {Window check(_handle);}
79 
83  Window window() {return Window(_handle);}
84 
88  Window window() const {return Window(_handle);}
89 
94  Gadget &operator=(const Gadget &other) {_handle = other._handle; _id = other._id; return *this;}
95 
103  Gadget &operator=(const Component &other) {Window check(_handle); _handle = other.handle(); _id = other.id(); return *this;}
104 
110  bool operator==(const Component &other) const {return (_handle == other.handle() && _id == other.id());}
111 
117  bool operator!=(const Component &other) const {return (_handle != other.handle() || _id != other.id());}
118 
124  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
125 
131  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other._id);}
132 
133  void check_toolbox_class(int class_id) const;
134 
135  int toolbox_class() const;
136  int toolbox_class_and_size() const;
137 
138  // Attributes
139  unsigned int flags() const;
140  void set_flag(unsigned int set);
141  void clear_flag(unsigned int clear);
142 
143  void fade();
144  void unfade();
145  void fade(bool fade);
146  bool faded() const;
147 
148  void focus();
149 
150  std::vector<IconHandle> icon_list();
151 
152  BBox bounds() const;
153  void bounds(const BBox &bounds);
154  Point bottom_left() const;
155  Point top_left() const;
156  void move_to(const Point &pos);
157  void move_to(int x, int y);
158  void move_by(int bx, int by);
159  Size size() const;
160  void size(const Size &sz);
161 
162  void add_loader(Loader *loader, int file_type = -2);
163  void remove_loader(Loader *loader, int file_type = -2);
164 
165  };
166 }
167 
168 #endif
void fade()
Fade the gadget.
Definition: gadget.cc:162
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
bool operator!=(const Component &other) const
Check if this gadget refers to the same underlying toolbox component as the given Component...
Definition: gadget.h:117
void remove_loader(Loader *loader, int file_type=-2)
Remove a file loader.
Definition: gadget.cc:472
Class to represent a two-dimensional size.
Definition: size.h:34
Window window() const
Get the window that contains this gadget.
Definition: gadget.h:88
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
BBox bounds() const
Get the bounding box of the gadget.
Definition: gadget.cc:250
Class to represent a two dimensional bounding box.
Definition: bbox.h:37
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
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
unsigned int flags() const
Return the gadget flags.
Definition: gadget.cc:97
int toolbox_class_and_size() const
Get the toolbox class and size for a gadget.
Definition: gadget.cc:81
Size size() const
Return the size of the gadget.
Definition: gadget.cc:410
Point bottom_left() const
Get the bottom left location of gadget.
Definition: gadget.cc:292
Base class for components in an object.
Definition: component.h:42
bool operator!=(const Gadget &other) const
Check if this gadget refers to the same underlying toolbox component as the given Gadget...
Definition: gadget.h:131
Class to represent a position in two dimensional space.
Definition: point.h:36
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
void move_to(const Point &pos)
Move gadget (without resizing)
Definition: gadget.cc:334
void move_by(int bx, int by)
Move gadget relative to it&#39;s current position without resizing.
Definition: gadget.cc:385
Class to handle file/data loading from the filer or an external application.
Definition: loader.h:179
void set_flag(unsigned int set)
Sets bits in the gadgets flags.
Definition: gadget.cc:116
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
Window window()
Get the window that contains this gadget.
Definition: gadget.h:83
int toolbox_class() const
Get the toolbox class for a gadget.
Definition: gadget.cc:64
bool operator==(const Component &other) const
Check if this gadget refers to the same underlying toolbox component as the given Component...
Definition: gadget.h:110
The Window object represents a toolbox window.
Definition: window.h:69
Gadget()
Construct an uninitialised gadget.
Definition: gadget.h:61
Gadget(const Component &other)
Construct a gadget as a copy of another component object.
Definition: gadget.h:78
bool operator==(const Gadget &other) const
Check if this gadget refers to the same underlying toolbox component as the given Gadget...
Definition: gadget.h:124
void add_loader(Loader *loader, int file_type=-2)
Add a file loader.
Definition: gadget.cc:458
Gadget & operator=(const Component &other)
Assign this gadget to refer to the same underlying toolbox gadget as the specified Component...
Definition: gadget.h:103
Point top_left() const
Get the top left location of gadget.
Definition: gadget.cc:313
Gadget & operator=(const Gadget &other)
Assign this gadget to refer to the same underlying toolbox gadget as another gadget.
Definition: gadget.h:94
Component()
Construct an uninitialised component.
Definition: component.h:55
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
std::vector< IconHandle > icon_list()
Get list of icons used in this gadget.
Definition: gadget.cc:220
void clear_flag(unsigned int clear)
Clear bits in the gadget flags.
Definition: gadget.cc:140
bool faded() const
Check if the gadget is faded.
Definition: gadget.cc:191
void unfade()
Clear the gadgets fade state.
Definition: gadget.cc:170
int _id
Underlying toolbox component id.
Definition: component.h:46
Gadget(const Gadget &other)
Construct a gadget as a copy of another gadget object.
Definition: gadget.h:68
void focus()
Set input focus to the gadget.
Definition: gadget.cc:202