tbx  0.7.3
gadgetcopyvalue.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 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 #ifndef _TBX_GADGETCOPYVALUE_H
25 #define _TBX_GADGETCOPYVALUE_H
26 
27 #include "writablefield.h"
28 #include "displayfield.h"
29 #include "button.h"
30 #include "numberrange.h"
31 #include "optionbutton.h"
32 #include "radiobutton.h"
33 #include "slider.h"
34 #include "stringset.h"
35 
36 namespace tbx
37 {
38 
49 inline void gadget_copy_value(Gadget &from_gadget, Gadget &to_gadget)
50 {
51  switch(from_gadget.toolbox_class())
52  {
53  case WritableField::TOOLBOX_CLASS:
54  {
55  WritableField from = from_gadget;
56  WritableField to = to_gadget;
57  to.text(from.text());
58  }
59  break;
60 
61  case DisplayField::TOOLBOX_CLASS:
62  DisplayField(to_gadget).text(DisplayField(from_gadget).text());
63  break;
64 
65  case Button::TOOLBOX_CLASS:
66  {
67  Button from(from_gadget);
68  Button to(to_gadget);
69  if (from.has_text() && to.has_text())
70  {
71  to.value(from.value());
72  }
73  }
74  break;
75 
76  case NumberRange::TOOLBOX_CLASS:
77  NumberRange(to_gadget).value(NumberRange(from_gadget).value());
78  break;
79 
80  case OptionButton::TOOLBOX_CLASS:
81  OptionButton(to_gadget).on(OptionButton(from_gadget).on());
82  break;
83  case RadioButton::TOOLBOX_CLASS:
84  RadioButton(to_gadget).on(RadioButton(from_gadget).on());
85  break;
86 
87  case Slider::TOOLBOX_CLASS:
88  Slider(to_gadget).value(Slider(from_gadget).value());
89  break;
90 
91  case StringSet::TOOLBOX_CLASS:
92  StringSet(to_gadget).selected(StringSet(from_gadget).selected());
93  break;
94 
95  default:
96  // Ignore what we don't understand
97  break;
98  }
99 }
100 
101 } /* end of tbx namespace */
102 
103 #endif
104 
void value(int value)
Set the value of the slider.
Definition: slider.h:128
void selected(const std::string &value)
Set the string to be selected.
Definition: stringset.h:143
StringSet wrapper class for an underlying toolbox StringSet gadget.
Definition: stringset.h:54
This is the base class for all Gadgets.
Definition: gadget.h:48
NumberRange wrapper for an underlying toolbox NumberRange gadget.
Definition: numberrange.h:42
void text(const std::string &value)
Set the the text to display.
Definition: writablefield.h:130
A Button is a gadget that show a sprite or some text in the window.
Definition: button.h:51
void value(std::string v)
Set the button value.
Definition: button.h:396
void value(int value)
Set the value of the number range.
Definition: numberrange.h:122
void gadget_copy_value(Gadget &from_gadget, Gadget &to_gadget)
Copy the main value property from one gadget to another.
Definition: gadgetcopyvalue.h:49
OptionButton wrapper for an underlying toolbox OptionButton gadget.
Definition: optionbutton.h:46
int toolbox_class() const
Get the toolbox class for a gadget.
Definition: gadget.cc:64
A RadioButton is a gadget that is shown with other RadioButtons to allow the choice of one item of a ...
Definition: radiobutton.h:48
void text(const std::string &value)
Set the the text to display.
Definition: displayfield.h:118
WritableField wrapper class for an underlying toolbox WritableField gadget.
Definition: writablefield.h:48
bool has_text() const
Check if the button shows text.
Definition: button.h:155
DisplayField wrapper for an underlying toolbox DisplayField gadget.
Definition: displayfield.h:38
void on(bool turn_on)
Turn radio button on or off.
Definition: radiobutton.h:160
A Slider is a gadget that shows bar in a well which may be draggable by the user. ...
Definition: slider.h:48
void on(bool value)
Turn option button on or off.
Definition: optionbutton.h:156