/// enum->ToolTip private ToolTip GetToolTip(BoundRelative name) { switch (name) { case BoundRelative.Left: return(this.BoundRelativeLeftToolTip); case BoundRelative.Top: return(this.BoundRelativeTopToolTip); case BoundRelative.Right: return(this.BoundRelativeRightToolTip); case BoundRelative.Bottom: return(this.BoundRelativeBottomToolTip); default: Debug.Fail("switch"); throw new System.ArgumentException(); } }
//------------------------------------------------------------------- /// enum->文字列 private string GetBoundRelativeValueString(BoundRelative name) { switch (name) { case BoundRelative.Left: return(StringConverter.GetBoundRelativeLeftString(App.Profile.Current)); case BoundRelative.Top: return(StringConverter.GetBoundRelativeTopString(App.Profile.Current)); case BoundRelative.Right: return(StringConverter.GetBoundRelativeRightString(App.Profile.Current)); case BoundRelative.Bottom: return(StringConverter.GetBoundRelativeBottomString(App.Profile.Current)); default: Debug.Fail("switch"); throw new System.ArgumentException(); } }
//=================================================================== // IBindingProfileの実装 //=================================================================== /// enumを指定して、イベントハンドラの実行なしにTextBox.Textを置き換える private void OverwriteText(BoundRelative name) { this.CanChangeProfile = false; var textBox = this.GetTextBox(name); textBox.Text = this.GetBoundRelativeValueString(name); if (textBox.IsKeyboardFocused) { textBox.Select(textBox.Text.Length, 0); } this.ResetError(name); this.CanChangeProfile = true; }
/// enumと値を指定してProfileを変更 private void SetBoundRelativeValue(BoundRelative name, double value) { switch (name) { case BoundRelative.Left: App.Profile.Current.BoundRelativeLeft = value; break; case BoundRelative.Top: App.Profile.Current.BoundRelativeTop = value; break; case BoundRelative.Right: App.Profile.Current.BoundRelativeRight = value; break; case BoundRelative.Bottom: App.Profile.Current.BoundRelativeBottom = value; break; default: Debug.Fail("switch"); throw new System.ArgumentException(); } }
/// enumと値を指定してProfileを変更 private void SetBoundRelativeValue(BoundRelative name, double value) { switch (name) { case BoundRelative.Left: App.Profile.Current.BoundRelativeLeft = value; break; case BoundRelative.Top: App.Profile.Current.BoundRelativeTop = value; break; case BoundRelative.Right: App.Profile.Current.BoundRelativeRight = value; break; case BoundRelative.Bottom: App.Profile.Current.BoundRelativeBottom = value; break; default: Debug.Fail("switch"); throw new System.ArgumentException(); } }
//=================================================================== // 入力エラー処理 //=================================================================== /// enumを指定してTextBoxのエラー状態解除 private void ResetError(BoundRelative name) { TextBoxError.ResetError(this.GetTextBox(name), this.GetToolTip(name)); }
//=================================================================== // IBindingProfileの実装 //=================================================================== /// enumを指定して、イベントハンドラの実行なしにTextBox.Textを置き換える private void OverwriteText(BoundRelative name) { this.CanChangeProfile = false; var textBox = this.GetTextBox(name); textBox.Text = this.GetBoundRelativeValueString(name); if (textBox.IsKeyboardFocused) { textBox.Select(textBox.Text.Length, 0); } this.ResetError(name); this.CanChangeProfile = true; }
/// enum->ToolTip private ToolTip GetToolTip(BoundRelative name) { switch (name) { case BoundRelative.Left: return this.BoundRelativeLeftToolTip; case BoundRelative.Top: return this.BoundRelativeTopToolTip; case BoundRelative.Right: return this.BoundRelativeRightToolTip; case BoundRelative.Bottom: return this.BoundRelativeBottomToolTip; default: Debug.Fail("switch"); throw new System.ArgumentException(); } }
//------------------------------------------------------------------- /// enum->文字列 private string GetBoundRelativeValueString(BoundRelative name) { switch (name) { case BoundRelative.Left: return StringConverter.GetBoundRelativeLeftString(App.Profile.Current); case BoundRelative.Top: return StringConverter.GetBoundRelativeTopString(App.Profile.Current); case BoundRelative.Right: return StringConverter.GetBoundRelativeRightString(App.Profile.Current); case BoundRelative.Bottom: return StringConverter.GetBoundRelativeBottomString(App.Profile.Current); default: Debug.Fail("switch"); throw new System.ArgumentException(); } }
/// enumを指定してレイアウト要素の内容を訂正後に変更する private void Correct(BoundRelative target) { var dependent = BoundRelativeInputCorrector.GetDependent(target); // Parse double value; if (!double.TryParse(this.GetTextBox(target).Text, out value)) { this.OverwriteText(target); this.ResetError(dependent); return; } // Window Check if (!App.Profile.Current.IsWindowValid) { this.OverwriteText(target); this.ResetError(dependent); return; } // Correct RelativeLTRB changed; var result = BoundRelativeInputCorrector.TryChange( App.Profile.Current, target, value, out changed); // 訂正の必要がない=TextChangedで設定済み if (result == BoundRelativeInputCorrector.TryResult.NothingChanged) return; // Update Profile App.Profile.Open(); App.Profile.Current.BoundRelativeLeft = changed.Left; App.Profile.Current.BoundRelativeTop = changed.Top; App.Profile.Current.BoundRelativeRight = changed.Right; App.Profile.Current.BoundRelativeBottom = changed.Bottom; App.Profile.Close(); //--------------------------------------------------------------- // Notify self if (result.HasFlag(BoundRelativeInputCorrector.TryResult.TargetChanged)) { this.OverwriteText(target); } else { this.ResetError(target); } if (result.HasFlag(BoundRelativeInputCorrector.TryResult.DependentChanged)) { this.OverwriteText(dependent); } else { this.ResetError(dependent); } // Notify other controls Commands.CurrentLayoutElementVisualChanged.Execute(null, this); //--------------------------------------------------------------- }
//=================================================================== // 入力エラー処理 //=================================================================== /// enumを指定してTextBoxのエラー状態解除 private void ResetError(BoundRelative name) { TextBoxError.ResetError(this.GetTextBox(name), this.GetToolTip(name)); }
//=================================================================== // BoundRelativeをキーとしたメソッド群 //=================================================================== /// TextBoxとToolTipの位置的な関連付け private void SetPlacementTarget(BoundRelative name) { this.GetToolTip(name).PlacementTarget = this.GetTextBox(name); }
/// enumを指定してレイアウト要素の内容を訂正後に変更する private void Correct(BoundRelative target) { var dependent = BoundRelativeInputCorrector.GetDependent(target); // Parse double value; if (!double.TryParse(this.GetTextBox(target).Text, out value)) { this.OverwriteText(target); this.ResetError(dependent); return; } // Window Check if (!App.Profile.Current.IsWindowValid) { this.OverwriteText(target); this.ResetError(dependent); return; } // Correct RelativeLTRB changed; var result = BoundRelativeInputCorrector.TryChange( App.Profile.Current, target, value, out changed); // 訂正の必要がない=TextChangedで設定済み if (result == BoundRelativeInputCorrector.TryResult.NothingChanged) { return; } // Update Profile App.Profile.Open(); App.Profile.Current.BoundRelativeLeft = changed.Left; App.Profile.Current.BoundRelativeTop = changed.Top; App.Profile.Current.BoundRelativeRight = changed.Right; App.Profile.Current.BoundRelativeBottom = changed.Bottom; App.Profile.Close(); //--------------------------------------------------------------- // Notify self if (result.HasFlag(BoundRelativeInputCorrector.TryResult.TargetChanged)) { this.OverwriteText(target); } else { this.ResetError(target); } if (result.HasFlag(BoundRelativeInputCorrector.TryResult.DependentChanged)) { this.OverwriteText(dependent); } else { this.ResetError(dependent); } // Notify other controls Commands.CurrentLayoutElementVisualChanged.Execute(null, this); //--------------------------------------------------------------- }
//------------------------------------------------------------------- /// enumを指定してレイアウト要素の内容を変更する private void Change(BoundRelative target) { var dependent = BoundRelativeInputCorrector.GetDependent(target); // Parse double value; if (!double.TryParse(this.GetTextBox(target).Text, out value)) { this.SetError(target, "must be double"); this.ResetError(dependent); return; } // Window Check if (!App.Profile.Current.IsWindowValid) { this.SetError(target, "Target window is invalid"); this.ResetError(dependent); return; } // Correct RelativeLTRB changed; var result = BoundRelativeInputCorrector.TryChange( App.Profile.Current, target, value, out changed); // Error表示 switch (result) { case BoundRelativeInputCorrector.TryResult.NothingChanged: { this.ResetError(target); this.ResetError(dependent); break; } case BoundRelativeInputCorrector.TryResult.TargetChanged: { this.SetWarning(target, "Return/Enter: Correct Value"); this.ResetError(dependent); return; } case BoundRelativeInputCorrector.TryResult.DependentChanged: case BoundRelativeInputCorrector.TryResult.BothChanged: { this.SetWarning(target, "Return/Enter: Correct Value"); this.SetWarning(dependent); return; } default: Debug.Fail("switch"); throw new System.ArgumentException(); } // 成功: そのまま書き換え(Textは変更しない) App.Profile.Open(); this.SetBoundRelativeValue(target, value); App.Profile.Close(); //--------------------------------------------------------------- // Notify self // Notify other controls Commands.CurrentLayoutElementVisualChanged.Execute(null, this); //--------------------------------------------------------------- }
/// enumを指定してTextBoxの警告状態設定 private void SetWarning(BoundRelative name, string message = null) { TextBoxError.SetWarning(this.GetTextBox(name), this.GetToolTip(name), message); }
//=================================================================== // BoundRelativeをキーとしたメソッド群 //=================================================================== /// TextBoxとToolTipの位置的な関連付け private void SetPlacementTarget(BoundRelative name) { this.GetToolTip(name).PlacementTarget = this.GetTextBox(name); }
/// enumを指定してTextBoxの警告状態設定 private void SetWarning(BoundRelative name, string message = null) { TextBoxError.SetWarning(this.GetTextBox(name), this.GetToolTip(name), message); }
//------------------------------------------------------------------- /// enumを指定してレイアウト要素の内容を変更する private void Change(BoundRelative target) { var dependent = BoundRelativeInputCorrector.GetDependent(target); // Parse double value; if (!double.TryParse(this.GetTextBox(target).Text, out value)) { this.SetError(target, "must be double"); this.ResetError(dependent); return; } // Window Check if (!App.Profile.Current.IsWindowValid) { this.SetError(target, "Target window is invalid"); this.ResetError(dependent); return; } // Correct RelativeLTRB changed; var result = BoundRelativeInputCorrector.TryChange( App.Profile.Current, target, value, out changed); // Error表示 switch (result) { case BoundRelativeInputCorrector.TryResult.NothingChanged: { this.ResetError(target); this.ResetError(dependent); break; } case BoundRelativeInputCorrector.TryResult.TargetChanged: { this.SetWarning(target, "Return/Enter: Correct Value"); this.ResetError(dependent); return; } case BoundRelativeInputCorrector.TryResult.DependentChanged: case BoundRelativeInputCorrector.TryResult.BothChanged: { this.SetWarning(target, "Return/Enter: Correct Value"); this.SetWarning(dependent); return; } default: Debug.Fail("switch"); throw new System.ArgumentException(); } // 成功: そのまま書き換え(Textは変更しない) App.Profile.Open(); this.SetBoundRelativeValue(target, value); App.Profile.Close(); //--------------------------------------------------------------- // Notify self // Notify other controls Commands.CurrentLayoutElementVisualChanged.Execute(null, this); //--------------------------------------------------------------- }