tbx  0.7.5
resgadget.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_RES_RESGADGET_H
26 #define TBX_RES_RESGADGET_H
27 
28 #include "resbase.h"
29 #include "../handles.h"
30 
31 namespace tbx {
32 
33 class Window;
34 
35 namespace res {
36 
37 class ResWindow;
38 
42 class ResGadget : public ResBase
43 {
44  friend class ResWindow;
45 
46  ResGadget(void *item_header, int size, ResData *data);
47 
48  // Access to allow window object to add a gadget from
49  // this template
50  friend class tbx::Window;
51  void *header() const {return _impl->header();}
52 
53 public:
59  ResGadget(const ResGadget &other) : ResBase(other)
60  {
61  }
62 
63  virtual ~ResGadget() {}
64 
70  ResGadget &operator=(const ResGadget &other)
71  {
72  ResBase::operator=(other);
73  return *this;
74  }
75 
76  ResGadget(int type, int size);
77 
78  void check_type(int type) const;
79 
80 protected:
85  {
86  if (!_impl->unique())
87  {
88  ResImpl *new_impl = new ResImpl(*_impl);
89  _impl->release();
90  _impl = new_impl;
91  }
92  }
93 
94 public:
102  unsigned int flags() const {return uint_value(0);}
103 
112  void flags(unsigned int value) {uint_value(0, value);}
113 
119  bool back() const {return flag(0, (1<<30));}
125  void back(bool value) {flag(0, (1<<30), value);}
126 
132  bool faded() const {return flag(0, (1<<31));}
138  void faded(bool value) {flag(0, (1<<31), value);}
139 
145  unsigned short type() const {return ushort_value(4);}
146 
155  unsigned short stored_size() const {return ushort_value(6);}
156 
163  int size() const {return gadget_size(uint_value(4));}
164 
170  static int gadget_size(unsigned int type_and_size);
171 
177  int xmin() const {return int_value(8);}
183  void xmin(int x) {int_value(8, x);}
189  int ymin() const {return int_value(12);}
195  void ymin(int y) {int_value(12, y);}
201  int xmax() const {return int_value(16);}
207  void xmax(int x) {int_value(16, x);}
213  int ymax() const {return int_value(20);}
219  void ymax(int y) {int_value(20, y);}
220 
232  void component_id(ComponentId value) {int_value(24, (int)value);}
233 
239  const char *help_message() const {return message(28);}
247  void help_message(const char *msg, int max_length = -1) {message_with_length(28, msg, max_length);}
255  void help_message(const std::string &msg, int max_length = -1) {message_with_length(28, msg, max_length);}
256 
260  int max_help() const {return int_value(32);}
261 };
262 
263 }
264 }
265 
266 #endif // TBX_RES_RESGADGET_H
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
Base class for gadget memory resources.
Definition: resgadget.h:42
bool faded() const
Check if the gadget is faded.
Definition: resgadget.h:132
Base class for objects, gadgets and menu items from ressources.
Definition: resbase.h:252
void flags(unsigned int value)
Set all flags as a word.
Definition: resgadget.h:112
unsigned int flags() const
Get all flags as a word raw access.
Definition: resgadget.h:102
void help_message(const std::string &msg, int max_length=-1)
Set the help message for the gadget.
Definition: resgadget.h:255
void message_with_length(int offset, const char *value, int length=-1)
Assign a message where the length is at offset+4.
Definition: resbase.cc:1639
bool flag(int offset, int mask) const
Check if any of the bits in a mask are set.
Definition: resbase.h:352
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
unsigned short type() const
Get the gadget type.
Definition: resgadget.h:145
int ymin() const
Get the minimum y coordinate of the gadget&#39;s bounding box.
Definition: resgadget.h:189
unsigned int uint_value(int offset) const
Get an unsigned integer value.
Definition: resbase.h:324
Classes to use/edit toolbox resources in memory.
ResGadget(const ResGadget &other)
Construct a resource gadget as a copy of another.
Definition: resgadget.h:59
Window resource object.
Definition: reswindow.h:48
void component_id(ComponentId value)
Set the Component ID.
Definition: resgadget.h:232
void xmax(int x)
Set the maximum x coordinate of the gadget&#39;s bounding box.
Definition: resgadget.h:207
int xmin() const
Get the minimum x coordinate of the gadget&#39;s bounding box.
Definition: resgadget.h:177
int int_value(int offset) const
Get an integer value.
Definition: resbase.h:316
unsigned short stored_size() const
Get the size stored in template.
Definition: resgadget.h:155
static int gadget_size(unsigned int type_and_size)
Get gadget size given its type and size value.
Definition: reswindow.cc:36
void back(bool value)
Set if gadget should be at the back.
Definition: resgadget.h:125
ComponentId component_id() const
Get the Component ID.
Definition: resgadget.h:226
int xmax() const
Get the maximum x coordinate of the gadget&#39;s bounding box.
Definition: resgadget.h:201
const char * message(int offset) const
Get the message string at the given offset.
Definition: resbase.cc:1602
The Window object represents a toolbox window.
Definition: window.h:69
ResGadget & operator=(const ResGadget &other)
Assign a resource gadget as a copy of another.
Definition: resgadget.h:70
unsigned short ushort_value(int offset) const
Get a unsigned short value.
Definition: resbase.h:342
void help_message(const char *msg, int max_length=-1)
Set the help message for the gadget.
Definition: resgadget.h:247
ResBase & operator=(const ResBase &other)
Assignment.
Definition: resbase.cc:1534
int max_help() const
Max size of message.
Definition: resgadget.h:260
void xmin(int x)
Set the minimum x coordinate of the gadget&#39;s bounding box.
Definition: resgadget.h:183
bool back() const
Check if gadget is at the back (created first)
Definition: resgadget.h:119
int ymax() const
Get the maximum y coordinate of the gadget&#39;s bounding box.
Definition: resgadget.h:213
void make_writeable()
Make item writeable.
Definition: resgadget.h:84
void faded(bool value)
Set if the gadget is faded.
Definition: resgadget.h:138
void ymin(int y)
Set the minimum y coordinate of the gadget&#39;s bounding box.
Definition: resgadget.h:195
void check_type(int type) const
Check if this gadgets type is as specified.
Definition: reswindow.cc:97
const char * help_message() const
Get the help message for the gadget.
Definition: resgadget.h:239
int size() const
Size of gadget (including header).
Definition: resgadget.h:163
void ymax(int y)
Set the maximum y coordinate of the gadget&#39;s bounding box.
Definition: resgadget.h:219
ResImpl * _impl
Internal Resource implementation.
Definition: resbase.h:255