summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Componentes/CustomPasswordBox.cs
blob: 39b5a0b38ed6159d9eb2b6dcf74fae6048b3fabe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Markup;

namespace Gestor.Application.Componentes;

public class CustomPasswordBox : UserControl, IComponentConnector
{
	public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(CustomPasswordBox), new PropertyMetadata((object)false, new PropertyChangedCallback(OnBoundIsReadOnlyChanged)));

	public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CustomPasswordBox), new PropertyMetadata((object)string.Empty, new PropertyChangedCallback(OnBoundPasswordChanged)));

	public static readonly DependencyProperty PasswordViewProperty = DependencyProperty.Register("PasswordViewProperty", typeof(bool), typeof(CustomPasswordBox), new PropertyMetadata((object)false, new PropertyChangedCallback(OnBoundPasswordViewChanged)));

	private bool _typing;

	internal Grid LayoutRoot;

	internal TextBox TextRead;

	internal TextBox TextMask;

	internal PasswordBox PasswordBox;

	private bool _contentLoaded;

	public bool IsReadOnly
	{
		get
		{
			return (bool)((DependencyObject)this).GetValue(IsReadOnlyProperty);
		}
		set
		{
			((DependencyObject)this).SetValue(IsReadOnlyProperty, (object)value);
		}
	}

	public string Text
	{
		get
		{
			return (string)((DependencyObject)this).GetValue(TextProperty);
		}
		set
		{
			((DependencyObject)this).SetValue(TextProperty, (object)value);
		}
	}

	public bool PasswordView
	{
		get
		{
			return (bool)((DependencyObject)this).GetValue(PasswordViewProperty);
		}
		set
		{
			((DependencyObject)this).SetValue(PasswordViewProperty, (object)value);
		}
	}

	private static void OnBoundIsReadOnlyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
	{
		CustomPasswordBox customPasswordBox = d as CustomPasswordBox;
		if (d != null && customPasswordBox != null)
		{
			bool flag = (bool)((DependencyPropertyChangedEventArgs)(ref e)).NewValue;
			((UIElement)customPasswordBox.PasswordBox).Visibility = (Visibility)(flag ? 2 : 0);
			((UIElement)customPasswordBox.TextRead).Visibility = (Visibility)((!flag) ? 2 : 0);
			((UIElement)customPasswordBox.TextMask).Visibility = (Visibility)((!flag) ? 2 : 0);
		}
	}

	private static void OnBoundPasswordChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
	{
		CustomPasswordBox customPasswordBox = d as CustomPasswordBox;
		if (d != null && customPasswordBox != null)
		{
			string text = ((string)((DependencyPropertyChangedEventArgs)(ref e)).NewValue) ?? "";
			if (!customPasswordBox._typing)
			{
				customPasswordBox.TextMask.Text = "".PadLeft(text.Length, '•');
				customPasswordBox.PasswordBox.Password = text;
			}
		}
	}

	private static void OnBoundPasswordViewChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		CustomPasswordBox customPasswordBox = d as CustomPasswordBox;
		if (d != null && customPasswordBox != null)
		{
			bool flag = (bool)((DependencyPropertyChangedEventArgs)(ref e)).NewValue;
			if (flag)
			{
				customPasswordBox.TextRead.Text = customPasswordBox.PasswordBox.Password;
			}
			else
			{
				customPasswordBox.PasswordBox.Password = customPasswordBox.TextRead.Text;
			}
			((UIElement)customPasswordBox.PasswordBox).Visibility = (Visibility)(flag ? 2 : 0);
			((UIElement)customPasswordBox.TextRead).Visibility = (Visibility)((!flag) ? 2 : 0);
			((UIElement)customPasswordBox.TextMask).Visibility = ((UIElement)customPasswordBox.PasswordBox).Visibility;
		}
	}

	public CustomPasswordBox()
	{
		InitializeComponent();
		((FrameworkElement)LayoutRoot).DataContext = this;
		PasswordView = false;
	}

	private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
	{
		_typing = true;
		Text = PasswordBox.Password;
		_typing = false;
		TextMask.Text = "".PadLeft(PasswordBox.Password.Length, '•');
	}

	private void Eye_Click(object sender, RoutedEventArgs e)
	{
		if (!IsReadOnly)
		{
			PasswordView = !PasswordView;
		}
	}

	private void TextRead_PasswordChanged(object sender, TextChangedEventArgs e)
	{
		Text = TextRead.Text;
	}

	[DebuggerNonUserCode]
	[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
	public void InitializeComponent()
	{
		if (!_contentLoaded)
		{
			_contentLoaded = true;
			Uri uri = new Uri("/Gestor.Application;component/componentes/custompasswordbox.xaml", UriKind.Relative);
			Application.LoadComponent((object)this, uri);
		}
	}

	[DebuggerNonUserCode]
	[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
	[EditorBrowsable(EditorBrowsableState.Never)]
	void IComponentConnector.Connect(int connectionId, object target)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		switch (connectionId)
		{
		case 1:
			LayoutRoot = (Grid)target;
			break;
		case 2:
			TextRead = (TextBox)target;
			((TextBoxBase)TextRead).TextChanged += new TextChangedEventHandler(TextRead_PasswordChanged);
			break;
		case 3:
			TextMask = (TextBox)target;
			break;
		case 4:
			PasswordBox = (PasswordBox)target;
			PasswordBox.PasswordChanged += new RoutedEventHandler(PasswordBox_PasswordChanged);
			break;
		case 5:
			((ButtonBase)(Button)target).Click += new RoutedEventHandler(Eye_Click);
			break;
		default:
			_contentLoaded = true;
			break;
		}
	}
}