tbx  0.7.5
reswritablefield.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_RESWRITABLEFIELD_H
26 #define TBX_RES_RESWRITABLEFIELD_H
27 
28 #include "resgadget.h"
29 #include "resjustification.h"
30 #include "../handles.h"
31 
32 namespace tbx {
33 namespace res {
34 
39 {
40 
41 public:
42  enum {TYPE_ID = 512 };
43 
50  ResWritableField(const ResGadget &other) : ResGadget(other)
51  {
52  check_type(TYPE_ID);
53  }
54 
61  {
62  }
63 
64  virtual ~ResWritableField() {}
65 
73  {
74  other.check_type(TYPE_ID);
75  ResBase::operator=(other);
76  return *this;
77  }
78 
85  {
86  ResBase::operator=(other);
87  return *this;
88  }
89 
96  : ResGadget(512,60)
97  {
98  init_message(36,0); // text
99  init_message(44,0); // allowable
100  before(-1);
101  after(-1);
102  }
103 
109  bool generate_value_changed() const {return flag(0, 1<<0);}
115  void generate_value_changed(bool value) {flag(0,1<<0,value);}
121  ResJustification justification() const {return ResJustification(flag_value(0, 12)>>2);}
127  void justification(ResJustification value) {flag_value(0,12,(int)value<<2);}
135  bool do_not_display_text() const {return flag(0, 1<<4);}
143  void do_not_display_text(bool value) {flag(0,1<<4,value);}
144 
150  const char *text() const {return message(36);}
158  void text(const char *value, int max_length = -1) {message_with_length(36, value, max_length);}
166  void text(const std::string &value, int max_length = -1) {message_with_length(36, value, max_length);}
170  int max_text_len() const {return int_value(40);}
171 
180  const char *allowable() const {return message(44);}
192  void allowable(const char *value, int max_length = -1) {message_with_length(44, value, max_length);}
203  void allowable(const std::string &value, int max_length = -1) {message_with_length(44, value, max_length);}
208  int max_allowable_len() const {return int_value(48);}
214  ComponentId before() const {return ComponentId(int_value(52));}
220  void before(ComponentId value) {int_value(52,(int)value);}
226  ComponentId after() const {return ComponentId(int_value(56));}
232  void after(ComponentId value) {int_value(56,(int)value);}
233 
234 };
235 
236 }
237 }
238 
239 #endif // TBX_RES_RESWRITABLEFIELD_H
240 
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
ResWritableField(const ResGadget &other)
Construct an writable field gadget resource.
Definition: reswritablefield.h:50
Base class for gadget memory resources.
Definition: resgadget.h:42
ResWritableField & operator=(const ResWritableField &other)
Assign from another writable field gadget resource.
Definition: reswritablefield.h:84
const char * allowable() const
Get the allowable characters in a writable field.
Definition: reswritablefield.h:180
void before(ComponentId value)
Set the component ID of the gadget before this one in the Tab order.
Definition: reswritablefield.h:220
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
bool do_not_display_text() const
Check if the text should not be displayed.
Definition: reswritablefield.h:135
int max_allowable_len() const
Get the maximum length the allowable character can be changed to when the gadget is shown...
Definition: reswritablefield.h:208
int flag_value(int offset, int mask) const
Get the bits for the given mask.
Definition: resbase.h:362
void justification(ResJustification value)
Set justification of the value.
Definition: reswritablefield.h:127
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
bool generate_value_changed() const
Check if the value changed event will be generated.
Definition: reswritablefield.h:109
ResWritableField()
Construct a writable field gadget resource.
Definition: reswritablefield.h:95
Classes to use/edit toolbox resources in memory.
Class for WritableField gadget template.
Definition: reswritablefield.h:38
void after(ComponentId value)
Set the component ID of the gadget after this one in the Tab order.
Definition: reswritablefield.h:232
int max_text_len() const
Get the maximum length for the writable text.
Definition: reswritablefield.h:170
ResJustification justification() const
Get justification of the value.
Definition: reswritablefield.h:121
ComponentId after() const
Get the component ID of the gadget after this one in the Tab order.
Definition: reswritablefield.h:226
const char * text() const
Get the initially text for the writable field.
Definition: reswritablefield.h:150
int int_value(int offset) const
Get an integer value.
Definition: resbase.h:316
void text(const char *value, int max_length=-1)
Set the initially text for the writable field.
Definition: reswritablefield.h:158
void allowable(const std::string &value, int max_length=-1)
Set the allowable characters in a writable field.
Definition: reswritablefield.h:203
void allowable(const char *value, int max_length=-1)
Set the allowable characters in a writable field.
Definition: reswritablefield.h:192
const char * message(int offset) const
Get the message string at the given offset.
Definition: resbase.cc:1602
ComponentId before() const
Get the component ID of the gadget before this one in the Tab order.
Definition: reswritablefield.h:214
ResWritableField & operator=(const ResGadget &other)
Assign from a ResGadget.
Definition: reswritablefield.h:72
void do_not_display_text(bool value)
Set if the text should not be displayed.
Definition: reswritablefield.h:143
ResBase & operator=(const ResBase &other)
Assignment.
Definition: resbase.cc:1534
void generate_value_changed(bool value)
Set if the value changed event will be generated.
Definition: reswritablefield.h:115
void text(const std::string &value, int max_length=-1)
Set the initially text for the writable field.
Definition: reswritablefield.h:166
ResWritableField(const ResWritableField &other)
Construct an writable field gadget resource.
Definition: reswritablefield.h:60
void check_type(int type) const
Check if this gadgets type is as specified.
Definition: reswindow.cc:97
void init_message(int offset, const char *value)
Initialise a message in a constructor helper.
Definition: resbase.cc:1736