tbx  0.7.5
resoptionbutton.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_RESOPTIONBUTTON_H
26 #define TBX_RES_RESOPTIONBUTTON_H
27 
28 #include "resgadget.h"
29 
30 namespace tbx {
31 namespace res {
32 
36 class ResOptionButton : public ResGadget
37 {
38 
39 public:
40  enum {TYPE_ID = 192 };
41 
48  ResOptionButton(const ResGadget &other) : ResGadget(other)
49  {
50  check_type(TYPE_ID);
51  }
52 
58  ResOptionButton(const ResOptionButton &other) : ResGadget(other)
59  {
60  }
61 
62  virtual ~ResOptionButton() {}
63 
71  {
72  other.check_type(TYPE_ID);
73  ResBase::operator=(other);
74  return *this;
75  }
76 
83  {
84  ResBase::operator=(other);
85  return *this;
86  }
87 
94  : ResGadget(192,48)
95  {
96  init_message(36,0); // label
97  }
98 
104  bool generate_state_changed() const {return flag(0, 1<<0);}
110  void generate_state_changed(bool value) {flag(0,1<<0,value);}
116  bool on() const {return flag(0, 1<<2);}
122  void on(bool value) {flag(0,1<<2,value);}
123 
129  const char *label() const {return message(36);}
137  void label(const char *value, int max_length = -1) {message_with_length(36, value, max_length);}
145  void label(const std::string &value, int max_length = -1) {message_with_length(36, value, max_length);}
151  int max_label_len() const {return int_value(40);}
157  int event_id() const {return int_value(44);}
163  void event_id(int value) {int_value(44,value);}
164 };
165 
166 }
167 }
168 
169 #endif // TBX_RES_RESOPTIONBUTTON_H
170 
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
Base class for gadget memory resources.
Definition: resgadget.h:42
void generate_state_changed(bool value)
Set if state change message will be generated.
Definition: resoptionbutton.h:110
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
void label(const char *value, int max_length=-1)
Set the label for the option button.
Definition: resoptionbutton.h:137
bool on() const
Check if option is on.
Definition: resoptionbutton.h:116
const char * label() const
Get the label for the option button.
Definition: resoptionbutton.h:129
Classes to use/edit toolbox resources in memory.
ResOptionButton(const ResGadget &other)
Construct an option button gadget resource.
Definition: resoptionbutton.h:48
int int_value(int offset) const
Get an integer value.
Definition: resbase.h:316
int max_label_len() const
Get the maximum length of the label text.
Definition: resoptionbutton.h:151
void event_id(int value)
Set the event ID generated when the state changes.
Definition: resoptionbutton.h:163
void on(bool value)
Set state of option button.
Definition: resoptionbutton.h:122
void label(const std::string &value, int max_length=-1)
Set the label for the option button.
Definition: resoptionbutton.h:145
ResOptionButton(const ResOptionButton &other)
Construct an option button gadget resource.
Definition: resoptionbutton.h:58
ResOptionButton()
Construct a option button gadget resource.
Definition: resoptionbutton.h:93
int event_id() const
Get the event ID generated when the state changes.
Definition: resoptionbutton.h:157
bool generate_state_changed() const
Check if state change message will be generated.
Definition: resoptionbutton.h:104
const char * message(int offset) const
Get the message string at the given offset.
Definition: resbase.cc:1602
ResBase & operator=(const ResBase &other)
Assignment.
Definition: resbase.cc:1534
ResOptionButton & operator=(const ResOptionButton &other)
Assign from another option button gadget resource.
Definition: resoptionbutton.h:82
Class for OptionButton gadget template.
Definition: resoptionbutton.h:36
void check_type(int type) const
Check if this gadgets type is as specified.
Definition: reswindow.cc:97
ResOptionButton & operator=(const ResGadget &other)
Assign from a ResGadget.
Definition: resoptionbutton.h:70
void init_message(int offset, const char *value)
Initialise a message in a constructor helper.
Definition: resbase.cc:1736