tbx  0.7.6
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 
tbx::OptionButton::on
void on(bool value)
Turn option button on or off.
Definition: optionbutton.h:156
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::Slider
A Slider is a gadget that shows bar in a well which may be draggable by the user.
Definition: slider.h:49
tbx::Gadget::toolbox_class
int toolbox_class() const
Get the toolbox class for a gadget.
Definition: gadget.cc:64
tbx::NumberRange
NumberRange wrapper for an underlying toolbox NumberRange gadget.
Definition: numberrange.h:42
tbx::Slider::value
void value(int value)
Set the value of the slider.
Definition: slider.h:128
tbx::WritableField
WritableField wrapper class for an underlying toolbox WritableField gadget.
Definition: writablefield.h:49
tbx::NumberRange::value
void value(int value)
Set the value of the number range.
Definition: numberrange.h:122
tbx::DisplayField::text
void text(const std::string &value)
Set the the text to display.
Definition: displayfield.h:118
tbx::RadioButton::on
void on(bool turn_on)
Turn radio button on or off.
Definition: radiobutton.h:160
tbx::WritableField::text
void text(const std::string &value)
Set the the text to display.
Definition: writablefield.h:131
tbx::Button::value
void value(std::string v)
Set the button value.
Definition: button.h:396
tbx::StringSet::selected
void selected(const std::string &value)
Set the string to be selected.
Definition: stringset.h:143
tbx::Button::has_text
bool has_text() const
Check if the button shows text.
Definition: button.h:155
tbx::DisplayField
DisplayField wrapper for an underlying toolbox DisplayField gadget.
Definition: displayfield.h:38
tbx::RadioButton
A RadioButton is a gadget that is shown with other RadioButtons to allow the choice of one item of a ...
Definition: radiobutton.h:49
tbx::Gadget
This is the base class for all Gadgets.
Definition: gadget.h:49
tbx::gadget_copy_value
void gadget_copy_value(Gadget &from_gadget, Gadget &to_gadget)
Copy the main value property from one gadget to another.
Definition: gadgetcopyvalue.h:49
tbx::OptionButton
OptionButton wrapper for an underlying toolbox OptionButton gadget.
Definition: optionbutton.h:47
tbx::Button
A Button is a gadget that show a sprite or some text in the window.
Definition: button.h:52
tbx::StringSet
StringSet wrapper class for an underlying toolbox StringSet gadget.
Definition: stringset.h:55