You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
7.8 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GummingCommon;
namespace Gumming
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class NumberInputView : Window
{
public NumberInputView()
{
InitializeComponent();
this.Loaded += NumberInputView_Loaded;
}
private void NumberInputView_Loaded(object sender, RoutedEventArgs e)
{
}
private void NumberInputView_OnSendSelectedDelegate(object content)
{
//this.TargetsFieldNameView.ScrollIntoView(content);
}
#region Main Functionality
private static bool _ShiftFlag;
protected static bool ShiftFlag
{
get { return _ShiftFlag; }
set { _ShiftFlag = value; }
}
private static bool _CapsLockFlag;
protected static bool CapsLockFlag
{
get { return NumberInputView._CapsLockFlag; }
set { NumberInputView._CapsLockFlag = value; }
}
private static Window _InstanceObject;
private static Control _CurrentControl;
public static string TouchScreenText
{
get
{
if (_CurrentControl is TextBox)
{
return ((TextBox)_CurrentControl).Text;
}
else if (_CurrentControl is PasswordBox)
{
return ((PasswordBox)_CurrentControl).Password;
}
else return "";
}
set
{
if (_CurrentControl is TextBox)
{
((TextBox)_CurrentControl).Text = value;
}
else if (_CurrentControl is PasswordBox)
{
((PasswordBox)_CurrentControl).Password = value;
}
}
}
public static RoutedUICommand Cmd1 = new RoutedUICommand();
static NumberInputView()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumberInputView), new FrameworkPropertyMetadata(typeof(NumberInputView)));
CommandBinding Cb1 = new CommandBinding(Cmd1, RunCommand);
CommandManager.RegisterClassCommandBinding(typeof(NumberInputView), Cb1);
}
static void RunCommand(object sender, ExecutedRoutedEventArgs e)
{
}
private static void AddKeyBoardINput(char input)
{
if (CapsLockFlag)
{
if (ShiftFlag)
{
NumberInputView.TouchScreenText += char.ToLower(input).ToString();
ShiftFlag = false;
}
else
{
NumberInputView.TouchScreenText += char.ToUpper(input).ToString();
}
}
else
{
if (!ShiftFlag)
{
NumberInputView.TouchScreenText += char.ToLower(input).ToString();
}
else
{
NumberInputView.TouchScreenText += char.ToUpper(input).ToString();
ShiftFlag = false;
}
}
}
private static void syncchild()
{
if (_CurrentControl != null && _InstanceObject != null)
{
System.Windows.Point virtualpoint = new System.Windows.Point(0, _CurrentControl.ActualHeight + 3);
System.Windows.Point Actualpoint = _CurrentControl.PointToScreen(virtualpoint);
if (166 + Actualpoint.X > SystemParameters.VirtualScreenWidth)
{
double difference = 166 + Actualpoint.X - SystemParameters.VirtualScreenWidth;
_InstanceObject.Left = Actualpoint.X - difference;
}
else if (!(Actualpoint.X > 1))
{
_InstanceObject.Left = 1;
}
else
_InstanceObject.Left = Actualpoint.X;
_InstanceObject.Top = Actualpoint.Y;
_InstanceObject.Show();
}
}
public static bool GetNumberInputView(DependencyObject obj)
{
return (bool)obj.GetValue(NumberInputViewProperty);
}
public static void SetNumberInputView(DependencyObject obj, bool value)
{
obj.SetValue(NumberInputViewProperty, value);
}
public static readonly DependencyProperty NumberInputViewProperty =
DependencyProperty.RegisterAttached("NumberInputView", typeof(bool), typeof(NumberInputView), new UIPropertyMetadata(default(bool), NumberInputViewPropertyChanged));
static void NumberInputViewPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
FrameworkElement host = sender as FrameworkElement;
if (host != null)
{
host.GotFocus += new RoutedEventHandler(OnGotFocus);
host.LostFocus += new RoutedEventHandler(OnLostFocus);
}
}
static void OnGotFocus(object sender, RoutedEventArgs e)
{
Control host = sender as Control;
//_PreviousTextBoxBorderThickness = host.BorderThickness;
//host.BorderThickness = new Thickness(4);
_CurrentControl = host;
if (_InstanceObject == null)
{
FrameworkElement ct = host;
while (true)
{
if (ct is Window)
{
((Window)ct).LocationChanged += new EventHandler(NumberInputView_LocationChanged);
((Window)ct).Activated += new EventHandler(NumberInputView_Activated);
((Window)ct).Deactivated += new EventHandler(NumberInputView_Deactivated);
break;
}
ct = (FrameworkElement)ct.Parent;
}
_InstanceObject = new NumberInputView();
_InstanceObject.AllowsTransparency = true;
_InstanceObject.WindowStyle = WindowStyle.None;
_InstanceObject.ShowInTaskbar = false;
_InstanceObject.ShowInTaskbar = false;
_InstanceObject.Topmost = true;
host.LayoutUpdated += new EventHandler(tb_LayoutUpdated);
}
}
static void NumberInputView_Deactivated(object sender, EventArgs e)
{
if (_InstanceObject != null)
{
_InstanceObject.Topmost = false;
}
}
static void NumberInputView_Activated(object sender, EventArgs e)
{
if (_InstanceObject != null)
{
_InstanceObject.Topmost = true;
}
}
static void NumberInputView_LocationChanged(object sender, EventArgs e)
{
syncchild();
}
static void tb_LayoutUpdated(object sender, EventArgs e)
{
syncchild();
}
static void OnLostFocus(object sender, RoutedEventArgs e)
{
Control host = sender as Control;
//host.BorderThickness = _PreviousTextBoxBorderThickness;
if (_InstanceObject != null)
{
_InstanceObject.Close();
_InstanceObject = null;
}
}
#endregion
}
}