1 /*
2 Copyright (c) 2013 Andrey Penechko
3 4 Boost Software License - Version 1.0 - August 17th, 2003
5 6 Permission is hereby granted, free of charge, to any person or organization
7 obtaining a copy of the software and accompanying documentation covered by
8 this license the "Software" to use, reproduce, display, distribute,
9 execute, and transmit the Software, and to prepare derivative works of the
10 Software, and to permit third-parties to whom the Software is furnished to
11 do so, all subject to the following:
12 13 The copyright notices in the Software and this entire statement, including
14 the above license grant, this restriction and the following disclaimer,
15 must be included in all copies of the Software, in whole or in part, and
16 all derivative works of the Software, unless such copies or derivative
17 works are solely in the form of machine-executable object code generated by
18 a source language processor.
19 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
23 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
24 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
25 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 DEALINGS IN THE SOFTWARE.
27 */28 29 moduleanchovy.utils.flexibleobject.flexibleproperty;
30 31 importstd.variant : Variant;
32 33 importanchovy.utils.flexibleobject.flexibleobject : FlexibleObject;
34 importanchovy.utils.signal : Signal;
35 36 abstractclassIProperty37 {
38 // called when value changes.39 aliasPropertyChangedSignal = Signal!(FlexibleObject, Variant);
40 aliasPropertyChangingSignal = Signal!(FlexibleObject, Variant*);
41 42 Variantvalue() @property;
43 Variantvalue(Variant) @property;
44 45 refPropertyChangedSignalvalueChanged() @property;
46 refPropertyChangingSignalvalueChanging() @property;
47 48 aliasvaluethis;
49 }
50 51 // Simple storage property52 classValueProperty : IProperty53 {
54 this(FlexibleObjectowner, Variantvalue = Variant(null))
55 {
56 _value = value;
57 _owner = owner;
58 }
59 60 this(T)(FlexibleObjectowner, Tvalue)
61 {
62 _owner = owner;
63 _value = Variant(value);
64 }
65 66 overrideVariantvalue() @property67 {
68 return_value;
69 }
70 71 overrideVariantvalue(VariantnewValue) @property72 {
73 // Strange error when comparing two variant with Widget[] inside74 // object.Error: object.Exception@src\object_.d(107):75 // need opCmp for class anchovy.gui.widget.Widget76 if (newValue == _value) return_value;
77 78 if (_isChanging)
79 {
80 return_value;
81 }
82 83 _isChanging = true;
84 85 _valueChanging.emit(_owner, &newValue);
86 87 if (newValue == _value)
88 {
89 _isChanging = false;
90 return_value;
91 }
92 _value = newValue;
93 _valueChanged.emit(_owner, _value);
94 95 _isChanging = false;
96 97 return_value;
98 }
99 100 overriderefPropertyChangedSignalvalueChanged() @property101 {
102 return_valueChanged;
103 }
104 105 overriderefPropertyChangingSignalvalueChanging() @property106 {
107 return_valueChanging;
108 }
109 110 Variant_value;
111 PropertyChangedSignal_valueChanged;
112 PropertyChangingSignal_valueChanging;
113 FlexibleObject_owner;
114 bool_isChanging = false;
115 }