~mantas/pinta/stable

« back to all changes in this revision

Viewing changes to Pinta.Gui.Widgets/Widgets/HScaleSpinButtonWidget.cs

  • Committer: Iain Lane
  • Date: 2010-03-13 18:20:18 UTC
  • mfrom: (1.1.2)
  • Revision ID: git-v1:1781694a68ecf232d0110c0b2f3d4a1b96c74ec2
Merge commit 'upstream/0.2'

Conflicts:
        debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// HScaleSpinButtonWidget.cs
 
3
//  
 
4
// Author:
 
5
//       Krzysztof Marecki
 
6
// 
 
7
// Copyright (c) 2010 Krzysztof Marecki <marecki.krzysztof@gmail.com>
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.ComponentModel;
 
29
 
 
30
namespace Pinta.Gui.Widgets
 
31
{
 
32
        [System.ComponentModel.ToolboxItem(true)]
 
33
        public partial class HScaleSpinButtonWidget : Gtk.Bin
 
34
        {
 
35
                [Category("Custom Properties")]
 
36
                public string Label {
 
37
                        get { return label.Text; }
 
38
                        set { label.Text = value; }
 
39
                }
 
40
 
 
41
                [Category("Custom Properties")]
 
42
                public int DefaultValue { get; set; }
 
43
 
 
44
                private int max_value;
 
45
                [Category("Custom Properties")]
 
46
                public int MaximumValue {
 
47
                        get { return max_value; }
 
48
                        set {
 
49
                                max_value = value;
 
50
                                hscale.Adjustment.Upper = value;
 
51
                                spin.Adjustment.Upper = value;
 
52
                        }
 
53
                }
 
54
 
 
55
                private int min_value;
 
56
                [Category("Custom Properties")]
 
57
                public int MinimumValue {
 
58
                        get { return min_value; }
 
59
                        set {
 
60
                                min_value = value;
 
61
                                hscale.Adjustment.Lower = value;
 
62
                                spin.Adjustment.Lower = value;
 
63
                        }
 
64
                }
 
65
 
 
66
                [Category("Custom Properties")]
 
67
                public int Value {
 
68
                        get { return spin.ValueAsInt; }
 
69
                        set {
 
70
                                if (spin.Value != value) {
 
71
                                        spin.Value = value;
 
72
                                        OnValueChanged ();
 
73
                                }
 
74
                        }
 
75
                }
 
76
 
 
77
                public HScaleSpinButtonWidget ()
 
78
                {
 
79
                        this.Build ();
 
80
                        
 
81
                        hscale.ValueChanged += HandleHscaleValueChanged;
 
82
                        spin.ValueChanged += HandleSpinValueChanged;
 
83
                        button.Clicked += HandleButtonClicked;
 
84
                }
 
85
 
 
86
                protected override void OnShown ()
 
87
                {
 
88
                        base.OnShown ();
 
89
                        
 
90
                        Value = DefaultValue;
 
91
                }
 
92
 
 
93
                private void HandleHscaleValueChanged (object sender, EventArgs e)
 
94
                {
 
95
                        if (spin.Value != hscale.Value) {
 
96
                                spin.Value = hscale.Value;
 
97
                                OnValueChanged ();
 
98
                        }
 
99
                }
 
100
 
 
101
                private void HandleSpinValueChanged (object sender, EventArgs e)
 
102
                {
 
103
                        if (hscale.Value != spin.Value) {
 
104
                                hscale.Value = spin.Value;
 
105
                                OnValueChanged ();
 
106
                        }
 
107
                }
 
108
 
 
109
                private void HandleButtonClicked (object sender, EventArgs e)
 
110
                {
 
111
                        Value = DefaultValue;
 
112
                }
 
113
 
 
114
                #region Protected Methods
 
115
                protected void OnValueChanged ()
 
116
                {
 
117
                        if (ValueChanged != null)
 
118
                                ValueChanged (this, EventArgs.Empty);
 
119
                }
 
120
                #endregion
 
121
 
 
122
                #region Public Events
 
123
                public event EventHandler ValueChanged;
 
124
                #endregion
 
125
        }
 
126
}