using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace MatteKalkylatorn
{
// Last modified: 2002-07-31
// Version: 0.44 ID:LAJ44002
// Compiles with Microsoft Visual C# .NET 7.0.9466 on Windows 95.
// The source code is free. It is not under any kind of license.
// If this code works, it was written by Lars Johansson, Göteborg.
// If not, I don't know who wrote it.
///
/// Summary description for AvaliableFunctions.
///
public class AvaliableFunctions : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ListBox listBox3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ListBox listBox4;
private System.Windows.Forms.Label labelFunction;
private System.Windows.Forms.TextBox textBoxFormula;
private System.Windows.Forms.TextBox textBoxVariableName;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.ListBox listBox5;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Label labelFunctionDescription;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public AvaliableFunctions()
{
InitializeComponent();
funcDescInit();
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.listBox2 = new System.Windows.Forms.ListBox();
this.label3 = new System.Windows.Forms.Label();
this.listBox3 = new System.Windows.Forms.ListBox();
this.label4 = new System.Windows.Forms.Label();
this.listBox4 = new System.Windows.Forms.ListBox();
this.textBoxFormula = new System.Windows.Forms.TextBox();
this.labelFunction = new System.Windows.Forms.Label();
this.textBoxVariableName = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.listBox5 = new System.Windows.Forms.ListBox();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelFunctionDescription = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.Items.AddRange(new object[] {
"+",
"-",
"*",
"/",
"^",
"(",
")",
"E"});
this.listBox1.Location = new System.Drawing.Point(88, 24);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(72, 199);
this.listBox1.TabIndex = 1;
this.listBox1.DoubleClick += new System.EventHandler(this.listBox_DoubleClick);
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(88, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Operators";
//
// label2
//
this.label2.Location = new System.Drawing.Point(168, 8);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 16);
this.label2.TabIndex = 3;
this.label2.Text = "Trigonometric";
//
// listBox2
//
this.listBox2.Items.AddRange(new object[] {
"sin",
"sinh",
"asin",
"asinh",
"cos",
"cosh",
"acos",
"acosh",
"tan",
"tanh",
"atan",
"atanh",
"cot",
"DegToRad",
"RadToDeg"});
this.listBox2.Location = new System.Drawing.Point(168, 24);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(72, 199);
this.listBox2.TabIndex = 2;
this.listBox2.DoubleClick += new System.EventHandler(this.listBox_DoubleClick);
this.listBox2.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged);
//
// label3
//
this.label3.Location = new System.Drawing.Point(248, 8);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 16);
this.label3.TabIndex = 5;
this.label3.Text = "Exponential";
//
// listBox3
//
this.listBox3.Items.AddRange(new object[] {
"exp",
"log",
"pow10",
"log10",
"sqrt",
"sqr"});
this.listBox3.Location = new System.Drawing.Point(248, 24);
this.listBox3.Name = "listBox3";
this.listBox3.Size = new System.Drawing.Size(72, 199);
this.listBox3.TabIndex = 3;
this.listBox3.DoubleClick += new System.EventHandler(this.listBox_DoubleClick);
this.listBox3.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged);
//
// label4
//
this.label4.Location = new System.Drawing.Point(328, 8);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(64, 16);
this.label4.TabIndex = 7;
this.label4.Text = "The rest";
//
// listBox4
//
this.listBox4.Items.AddRange(new object[] {
"abs",
"ceil",
"fix",
"floor",
"round",
"sign"});
this.listBox4.Location = new System.Drawing.Point(328, 24);
this.listBox4.Name = "listBox4";
this.listBox4.Size = new System.Drawing.Size(72, 199);
this.listBox4.TabIndex = 4;
this.listBox4.DoubleClick += new System.EventHandler(this.listBox_DoubleClick);
this.listBox4.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged);
//
// textBoxFormula
//
this.textBoxFormula.Location = new System.Drawing.Point(8, 272);
this.textBoxFormula.Name = "textBoxFormula";
this.textBoxFormula.Size = new System.Drawing.Size(392, 20);
this.textBoxFormula.TabIndex = 5;
this.textBoxFormula.Text = "";
//
// labelFunction
//
this.labelFunction.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelFunction.Location = new System.Drawing.Point(8, 224);
this.labelFunction.Name = "labelFunction";
this.labelFunction.Size = new System.Drawing.Size(384, 23);
this.labelFunction.TabIndex = 9;
this.labelFunction.Text = "labelFunction";
//
// textBoxVariableName
//
this.textBoxVariableName.Location = new System.Drawing.Point(408, 24);
this.textBoxVariableName.MaxLength = 1;
this.textBoxVariableName.Name = "textBoxVariableName";
this.textBoxVariableName.Size = new System.Drawing.Size(24, 20);
this.textBoxVariableName.TabIndex = 6;
this.textBoxVariableName.Text = "x";
this.textBoxVariableName.DoubleClick += new System.EventHandler(this.textBoxVariableName_DoubleClick);
//
// label5
//
this.label5.Location = new System.Drawing.Point(408, 8);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 23);
this.label5.TabIndex = 11;
this.label5.Text = "Variable name";
//
// label6
//
this.label6.Location = new System.Drawing.Point(8, 8);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(64, 16);
this.label6.TabIndex = 13;
this.label6.Text = "Numbers";
//
// listBox5
//
this.listBox5.Items.AddRange(new object[] {
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
".",
"PI"});
this.listBox5.Location = new System.Drawing.Point(8, 24);
this.listBox5.Name = "listBox5";
this.listBox5.Size = new System.Drawing.Size(72, 199);
this.listBox5.TabIndex = 0;
this.listBox5.DoubleClick += new System.EventHandler(this.listBox_DoubleClick);
this.listBox5.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged);
//
// buttonOK
//
this.buttonOK.Location = new System.Drawing.Point(408, 56);
this.buttonOK.Name = "buttonOK";
this.buttonOK.TabIndex = 7;
this.buttonOK.Text = "OK";
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(408, 88);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.TabIndex = 8;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// labelFunctionDescription
//
this.labelFunctionDescription.Location = new System.Drawing.Point(8, 248);
this.labelFunctionDescription.Name = "labelFunctionDescription";
this.labelFunctionDescription.Size = new System.Drawing.Size(400, 24);
this.labelFunctionDescription.TabIndex = 16;
this.labelFunctionDescription.Text = "labelFunctionDescription";
//
// AvaliableFunctions
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(488, 301);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBoxVariableName,
this.labelFunctionDescription,
this.buttonCancel,
this.buttonOK,
this.label6,
this.listBox5,
this.label5,
this.labelFunction,
this.textBoxFormula,
this.label4,
this.listBox4,
this.label3,
this.listBox3,
this.label2,
this.listBox2,
this.label1,
this.listBox1});
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AvaliableFunctions";
this.Text = "Avaliable Functions";
this.Load += new System.EventHandler(this.AvaliableFunctions_Load);
this.ResumeLayout(false);
}
#endregion
string originalFormula = "";
Hashtable funcDesc = new Hashtable();
void funcDescInit()
{
funcDesc.Add("+", "Plus. X + Y adds X and Y.");
funcDesc.Add("-", "Minus. X - Y subtracts Y from X.");
funcDesc.Add("*", "Multiplication. X*Y is the product of X and Y.");
funcDesc.Add("/", "Division. X/Y is the division of X into Y.");
funcDesc.Add("^", "Power. Z = X^Y is X to the Y power.");
funcDesc.Add("(", "Left parenteses.");
funcDesc.Add(")", "Right parenteses.");
funcDesc.Add("sin", "Sine. SIN(X) is the sine of X.");
funcDesc.Add("sinh", "Hyperbolic sine. SINH(X) is the hyperbolic sine of X.");
funcDesc.Add("asin", "Inverse sine. ASIN(X) is the arcsine of X.");
funcDesc.Add("asinh", "Inverse hyperbolic sine. ASINH(X) is the inverse hyperbolic sine of X.");
funcDesc.Add("cos", "Cosine. COS(X) is the cosine of X.");
funcDesc.Add("cosh", "Hyperbolic cosine. COSH(X) is the hyperbolic cosine of X.");
funcDesc.Add("acos", "Inverse cosine. ACOS(X) is the arccosine of X.");
funcDesc.Add("acosh", "Inverse hyperbolic cosine. ACOSH(X) is the inverse hyperbolic cosine of X.");
funcDesc.Add("tan", "Tangent. TAN(X) is the tangent of X.");
funcDesc.Add("tanh", "Hyperbolic tangent. TANH(X) is the hyperbolic tangent of X.");
funcDesc.Add("atan", "Inverse tangent. ATAN(X) is the arctangent of X.");
funcDesc.Add("atanh", "Inverse hyperbolic tangent. ATANH(X) is the inverse hyperbolic tangent of X.");
funcDesc.Add("cot", "Cotangent. COT(X) is the cotangent of X.");
funcDesc.Add("DegToRad", "Radians = Degrees * PI / 180");
funcDesc.Add("RadToDeg", "Degrees = Radians * 180 / PI");
funcDesc.Add("exp", "Exponential. EXP(X) is the exponential of X, e to the X.");
funcDesc.Add("log", "Natural logarithm. LOG(X) is the natural logarithm of X.");
funcDesc.Add("pow10", "10 to the X");
funcDesc.Add("log10", "Common logarithm. LOG10(X) is the logarithm base 10 of X.");
funcDesc.Add("sqrt", "Square root. SQRT(X) is the square root of X.");
funcDesc.Add("sqr", "Square. X^2");
funcDesc.Add("abs", "Absolute value. ABS(X) is the absolute value of X.");
funcDesc.Add("ceil", "Round towards plus infinity. CEIL(X) rounds X to the nearest integers towards infinity.");
funcDesc.Add("fix", "Round towards zero. FIX(X) rounds X to the nearest integers towards zero.");
funcDesc.Add("floor", "Round towards minus infinity. FLOOR(X) rounds X to the nearest integers towards minus infinity.");
funcDesc.Add("round", "Round towards nearest integer. ROUND(X) X to the nearest integers.");
funcDesc.Add("sign", "Signum function. SIGN(X) returns 1 if X is greater than zero, 0 if X equals zero and -1 if X is less than zero.");
funcDesc.Add("E", "Used for 3E2 (=300)");
funcDesc.Add("PI", "3.1415...");
}
string appendVariableToFunction(string function)
{
if (function.Length > 2)
{
function += "(" + textBoxVariableName.Text + ")";
}
return function;
}
void insertFunctionInFormula(string function)
{
function = appendVariableToFunction(function);
string s = textBoxFormula.Text;
int b = textBoxFormula.SelectionStart;
int L = textBoxFormula.SelectionLength;
s = s.Remove(b, L);
s = s.Insert(b, function);
textBoxFormula.Text = s;
textBoxFormula.SelectionStart = b + function.Length;
}
private void listBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
ListBox lb = (ListBox)sender;
string function = lb.Text;
labelFunction.Text = appendVariableToFunction(function);
labelFunctionDescription.Text = (string)funcDesc[function];
}
private void listBox_DoubleClick(object sender, System.EventArgs e)
{
ListBox lb = (ListBox)sender;
string function = lb.Text;
insertFunctionInFormula(function);
}
private void textBoxVariableName_DoubleClick(object sender, System.EventArgs e)
{
string variable = textBoxVariableName.Text;
insertFunctionInFormula(variable);
}
public string UpdateFormulaModal(string formula)
{
originalFormula = formula;
string sx = Laj.Mathematics.MCUtil.GetOriginalVariableName(formula);
if (sx.Length > 0)
{
textBoxVariableName.Text = sx;
}
else
{
textBoxVariableName.Text = "x";
}
textBoxFormula.Text = formula;
textBoxFormula.SelectionStart = textBoxFormula.Text.Length;
this.ShowDialog();
return originalFormula;
}
private void buttonOK_Click(object sender, System.EventArgs e)
{
originalFormula = textBoxFormula.Text;
this.Close();
}
private void buttonCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void AvaliableFunctions_Load(object sender, System.EventArgs e)
{
labelFunction.Text = "";
labelFunctionDescription.Text = "";
textBoxFormula.Select();
}
}
}