예제 #1
0
 public ActionLayout(CalculatorBase calc, CalculatorHost application)
     : this()
 {
     _calc = calc;
     _app = application;
     this.Title.Text = calc.Name;
     foreach (Operation op in calc.Operations)
     {
         Button b = new Button();
         b.Tag = op;
         b.Content = op.Name;
         b.Click += new RoutedEventHandler(b_Click);
         Actions.Children.Add(b);
     }
     ValidateButtons(application.Stack.Items.Count);
     application.StackChanged += _stackChangedHandler;
 }
 internal void Operate(CalculatorBase calc, Operation op)
 {
     double[] operands = new double[op.NumOperands];
     for (int i = 0; i < op.NumOperands; i++)
     {
         ListViewItem item = (ListViewItem)Stack.Items[0];
         operands[i] = double.Parse(item.Content.ToString());
         Stack.Items.RemoveAt(0);
     }
     if (typeof(Calculator).IsAssignableFrom(calc.GetType()))
     {
         double result = ((Calculator)calc).Operate(op, operands);
         ListViewItem newItem = new ListViewItem();
         newItem.Content = result;
         Stack.Items.Insert(0, newItem);
     }
     else
     {
         UIElement visual = ((VisualCalculator)calc).Operate(op, operands);
         CalculatorVisual.Children.Clear();
         CalculatorVisual.Children.Add(visual);
     }
     UpdateStack();
 }
 void UnloadAddIn(CalculatorBase calc)
 {
     ActionLayout calcsAl = null;
     foreach (ActionLayout al in Actions.Items)
     {
         if (al.Calculator.Equals(calc))
         {
             calcsAl = al;
             break;
         }
     }
     calcsAl.Calculator = null;
     Actions.Items.Remove(calcsAl);
     _calcs.Remove(calc);
     CalculatorVisual.Children.Clear();
 }
 void InitAddIn(CalculatorBase calc, bool addMenu)
 {
     Actions.Items.Add(new ActionLayout(calc, this));
     if (addMenu)
     {
         CheckBox cb = new CheckBox();
         cb.Content = calc.Name;
         cb.IsChecked = true;
         cb.Tag = calc;
         cb.Checked += new RoutedEventHandler(cb_Checked);
         cb.Unchecked += new RoutedEventHandler(cb_Unchecked);
         this.AddInMenuList.Items.Add(cb);
     }
 }