tbx  0.7.3
resbutton.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_RESBUTTON_H
26 #define TBX_RES_RESBUTTON_H
27 
28 #include "resgadget.h"
29 
30 namespace tbx {
31 namespace res {
32 
36 class ResButton : public ResGadget
37 {
38 
39 public:
40  enum {TYPE_ID = 960 };
41 
48  ResButton(const ResGadget &other) : ResGadget(other)
49  {
50  check_type(TYPE_ID);
51  }
52 
58  ResButton(const ResButton &other) : ResGadget(other)
59  {
60  }
61 
62  virtual ~ResButton() {}
63 
70  ResButton &operator=(const ResGadget &other)
71  {
72  other.check_type(TYPE_ID);
73  ResBase::operator=(other);
74  return *this;
75  }
76 
82  ResButton &operator=(const ResButton &other)
83  {
84  ResBase::operator=(other);
85  return *this;
86  }
87 
94  : ResGadget(960,56)
95  {
96  int_value(36, 0x7000110); // foreground 7, icon data indirected (always set)
97  init_message(40,0); // value
98  init_string(48,0); // validation
99  }
100 
107  bool use_task_sprite_area() const {return flag(0, 1<<0);}
114  void use_task_sprite_area(bool value) {flag(0,1<<0,value);}
120  bool return_menu_clicks() const {return flag(0, 1<<1);}
126  void return_menu_clicks(bool value) {flag(0,1<<1,value);}
127 
134  int button_flags() const {return int_value(36);}
143  void button_flags(int value) {int_value(36,value);}
144 
150  bool has_text() const {return flag(36,1);}
156  void has_text(bool value) {flag(36, 1, value );}
162  bool is_sprite() const {return flag(36,1<<1);}
168  void is_sprite(bool value) {flag(36, 1<<1, value);}
174  bool has_border() const {return flag(36,1<<2);}
180  void has_border(bool value) {flag(36, 1<<2, value);}
186  bool hcentred() const {return flag(36,1<<3);}
192  void hcentred(bool value) {flag(36, 1<<3, value);}
198  bool vcentred() const {return flag(36,1<<4);}
204  void vcentred(bool value) {flag(36, 1<<4, value);}
210  bool filled() const {return flag(36, 1<<5);}
216  void filled(bool value) {flag(36, 1<<5, value);}
222  bool anti_aliased_font() const {return flag(36, 1 << 6);}
232  void anti_aliased_font(bool value) {flag(36, 1<<6, value);}
233  // 6 text is an anti-aliased font (affects meaning of bits 24 - 31)
239  bool redraw_needs_help() const {return flag(36, 1 << 7);}
245  void redraw_needs_help(bool value) {flag(36, 1<<7, value);}
246  // bit 8 - icon data is indirected always set
252  bool text_right_justified() const {return flag(36, 1 << 9);}
258  void text_right_justified(bool value) {flag(36, 1<<9, value);}
264  bool adjust_does_not_cancel() const {return flag(36, 1 << 10);}
270  void adjust_does_not_cancel(bool value) {flag(36, 1<<10, value);}
276  bool half_size_sprite() const {return flag(36, 1 << 11);}
282  void half_size_sprite(bool value) {flag(36, 1<<11, value);}
283 
288  {
289  IGNORE_CLICKS, // ignore mouse clicks or movements over the icon (except Menu)
290  CONTINUOUS, // notify task continuously while pointer is over this icon
291  CLICK_AUTO_REPEAT, // click notifies task (auto-repeat)
292  CLICK_ONCE, // click notifies task (once only)
293  CLICK_SELECTS, // click selects the icon; release over the icon notifies task; moving the pointer away deselects the icon
294  CLICK_SELECTS_DOUBLE, // click selects; double click notifies task
295  CLICK_ONCE_DRAG, // click notifies, but can also drag (returns button state * 16)
296  CLICK_SELECTS_DRAG, // as CLICK_SELECTS, but can also drag (returns button state * 16) and moving away from the icon doesn't deselect it
297  CLICK_SELECTS_DOUBLE_DRAG, // as CLICK_SELECTS_DOUBLE, but can also drag (returns button state * 16)
298  OVER_SELECTS, // pointer over icon selects; moving away from icon deselects; click over icon notifies task ('menu' icon)
299  CLICK_DOUBLE_DRAG, //click returns button state * 256, drag returns button state * 16, double click returns button state * 1
300  CLICK_NOTIFY_AND_SELECTS_DRAG, // click selects icon and returns button state, drag returns button state*16
301  FOCUS_AND_DRAG = 14, // clicks cause the icon to gain the caret and its parent window to become the input focus and can also drag (writable icon). For example, this is used by the FormEd application
302  WRITEABLE, // clicks cause the icon to gain the caret and its parent window to become the input focus (writable icon)
303  };
304 
310  ButtonType button_type() const {return ButtonType(flag_value(36, 0xF000) >> 12);}
316  void button_type(ButtonType type) {flag_value(36, ((int)type) << 12);}
317 
326  int esg() const {return flag_value(36, 0x1F0000) >> 16;}
335  void esg(int value) {flag_value(36, value << 16);}
336 
344  int foreground() const {return flag_value(36,0xF000000)>>24;} // !anti_aliased_font
352  void foreground(int value) {flag_value(36, value << 24);}
360  int background() const {return flag_value(36,0xF0000000)>>28;} // !anti_aliased_font
368  void background(int value) {flag_value(36, value << 28);}
369 
377  int font_handle() const {return flag_value(36,0xFF000000) >> 24;} // anti_aliased_font
385  void font_handle(int value) {flag_value(36, value << 24);}
386 
392  const char *value() const {return message(40);}
400  void value(const char *value, int max_length = -1) {message_with_length(40, value, max_length);}
408  void value(const std::string &value, int max_length = -1) {message_with_length(40, value, max_length);}
414  int max_value() const {return int_value(44);}
420  const char *validation() const {return string(48);}
427  void validation(const char *value, int max_length = -1) {string_with_length(48, value, max_length);}
434  void validation(const std::string &value, int max_length = -1) {string_with_length(48, value, max_length);}
438  int max_validation() const {return int_value(52);}
439 };
440 
441 }
442 }
443 
444 #endif // TBX_RES_RESBUTTON_H
445 
void has_border(bool value)
Set if the button has a border.
Definition: resbutton.h:180
unsigned short type() const
Get the gadget type.
Definition: resgadget.h:145
void hcentred(bool value)
Set if the contents of the button are horizontally centred.
Definition: resbutton.h:192
bool redraw_needs_help() const
Check if the button need help from the user application to be redrawn.
Definition: resbutton.h:239
Base class for gadget memory resources.
Definition: resgadget.h:42
int flag_value(int offset, int mask) const
Get the bits for the given mask.
Definition: resbase.h:362
ButtonType button_type() const
Get how the button processes mouse clicks.
Definition: resbutton.h:310
ResButton & operator=(const ResGadget &other)
Assign from a ResGadget.
Definition: resbutton.h:70
void init_string(int offset, const char *value)
Initialise a string in a constructor helper.
Definition: resbase.cc:1725
bool text_right_justified() const
Check if the text on the button is right justified.
Definition: resbutton.h:252
bool hcentred() const
Check if the contents of the button are horizontally centred.
Definition: resbutton.h:186
void value(const std::string &value, int max_length=-1)
Set the value (text or sprite name) of the button.
Definition: resbutton.h:408
void value(const char *value, int max_length=-1)
Set the value (text or sprite name) of the button.
Definition: resbutton.h:400
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
int foreground() const
Return the foreground WIMP colour.
Definition: resbutton.h:344
ResButton(const ResButton &other)
Construct an button gadget resource.
Definition: resbutton.h:58
void string_with_length(int offset, const char *value, int length=-1)
Assign a string where the length is at offset+4.
Definition: resbase.cc:1591
bool vcentred() const
Check if the contents of the button are vertically centred.
Definition: resbutton.h:198
bool flag(int offset, int mask) const
Check if any of the bits in a mask are set.
Definition: resbase.h:352
ResButton(const ResGadget &other)
Construct an button gadget resource.
Definition: resbutton.h:48
void has_text(bool value)
Set if the button shows text.
Definition: resbutton.h:156
bool use_task_sprite_area() const
Check if button uses the task sprite area.
Definition: resbutton.h:107
int button_flags() const
Raw access to all button flags.
Definition: resbutton.h:134
Class for Button gadget template.
Definition: resbutton.h:36
ResButton & operator=(const ResButton &other)
Assign from another button gadget resource.
Definition: resbutton.h:82
void button_type(ButtonType type)
Set how the button processes mouse clicks.
Definition: resbutton.h:316
const char * message(int offset) const
Get the message string at the given offset.
Definition: resbase.cc:1602
void filled(bool value)
Set if the button background is filled.
Definition: resbutton.h:216
const char * string(int offset) const
Return a string at the given offset.
Definition: resbase.cc:1555
const char * value() const
Get the value (text or sprite name) of the button.
Definition: resbutton.h:392
void return_menu_clicks(bool value)
Set if button will return clicks with the menu button.
Definition: resbutton.h:126
bool return_menu_clicks() const
Check if button will return clicks with the menu button.
Definition: resbutton.h:120
bool half_size_sprite() const
Check if the button display the sprite half size.
Definition: resbutton.h:276
bool filled() const
Check if the button background is filled.
Definition: resbutton.h:210
int max_value() const
Get the maximum length of the value string.
Definition: resbutton.h:414
void is_sprite(bool value)
Set if the button shows a sprite.
Definition: resbutton.h:168
bool adjust_does_not_cancel() const
Check if the adjust does not cancel other selections in the same ESG group.
Definition: resbutton.h:264
bool is_sprite() const
Check if the button shows a sprite.
Definition: resbutton.h:162
bool has_border() const
Check if the button has a border.
Definition: resbutton.h:174
void half_size_sprite(bool value)
Set if the button shows the sprite half size.
Definition: resbutton.h:282
void anti_aliased_font(bool value)
Set if the button uses an anti aliased font.
Definition: resbutton.h:232
void vcentred(bool value)
Set if the contents of the button are vertically centred.
Definition: resbutton.h:204
void validation(const char *value, int max_length=-1)
Set the validation (sprite name) for the button.
Definition: resbutton.h:427
void button_flags(int value)
Raw access to all button flags.
Definition: resbutton.h:143
void text_right_justified(bool value)
Set if the text on the button is right justified.
Definition: resbutton.h:258
void validation(const std::string &value, int max_length=-1)
Set the validation (sprite name) for the button.
Definition: resbutton.h:434
ResButton()
Construct a button gadget resource.
Definition: resbutton.h:93
void redraw_needs_help(bool value)
Set if the button need help from the user application to be redrawn.
Definition: resbutton.h:245
int background() const
Return the background WIMP colour.
Definition: resbutton.h:360
ResBase & operator=(const ResBase &other)
Assignment.
Definition: resbase.cc:1534
bool anti_aliased_font() const
Check if the button uses an anti aliased font.
Definition: resbutton.h:222
void adjust_does_not_cancel(bool value)
Set if the adjust does not cancel other selections in the same ESG group.
Definition: resbutton.h:270
void foreground(int value)
Set the foreground WIMP colour.
Definition: resbutton.h:352
void check_type(int type) const
Check if this gadgets type is as specified.
Definition: reswindow.cc:97
void background(int value)
Set the background WIMP colour.
Definition: resbutton.h:368
int esg() const
Return the exclusive selection group (ESG) for the button.
Definition: resbutton.h:326
const char * validation() const
Get the validation (sprite name) for the button.
Definition: resbutton.h:420
int font_handle() const
Get the WIMP font handle for drawing text.
Definition: resbutton.h:377
void font_handle(int value)
Set the WIMP font handle for drawing text.
Definition: resbutton.h:385
int max_validation() const
Get the maximum length the validation (sprite name) that can be used.
Definition: resbutton.h:438
void esg(int value)
Set the exclusive selection group (ESG) for the button.
Definition: resbutton.h:335
int int_value(int offset) const
Get an integer value.
Definition: resbase.h:316
ButtonType
Enumeration for how the button processes clicks.
Definition: resbutton.h:287
bool has_text() const
Check if the button shows text.
Definition: resbutton.h:150
void use_task_sprite_area(bool value)
Set if button uses the task sprite area.
Definition: resbutton.h:114
void init_message(int offset, const char *value)
Initialise a message in a constructor helper.
Definition: resbase.cc:1736