2 * Copyright (C) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
3 * Copyright (C) 2008-2012 Robert Ancell.
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, either version 2 of the License, or (at your option) any later
8 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
12 public class MathWindow
: Gtk
.ApplicationWindow
14 private MathEquation _equation
;
15 public MathEquation equation
{ get { return _equation
; } }
17 private MathDisplay _display
;
18 public MathDisplay display
{ get { return _display
; } }
20 private MathButtons _buttons
;
21 public MathButtons buttons
{ get { return _buttons
; } }
22 private bool right_aligned
;
24 public MathWindow (Gtk
.Application app
, MathEquation equation
)
26 Object (application
: app
);
28 set_title (/* Title of main window */
33 var main_vbox
= new Gtk
.Box (Gtk
.Orientation
.VERTICAL
, 0);
37 var vbox
= new Gtk
.Box (Gtk
.Orientation
.VERTICAL
, 6);
38 vbox
.border_width
= 6;
39 main_vbox
.pack_start (vbox
, true, true, 0);
42 var scrolled_window
= new Gtk
.ScrolledWindow (null, null);
43 scrolled_window
.set_policy (Gtk
.PolicyType
.AUTOMATIC
, Gtk
.PolicyType
.NEVER
);
44 scrolled_window
.set_shadow_type (Gtk
.ShadowType
.IN
);
45 vbox
.pack_start (scrolled_window
, false, false, 0);
46 scrolled_window
.get_hadjustment ().changed
.connect (scroll_changed_cb
);
47 scrolled_window
.get_hadjustment ().value_changed
.connect (scroll_value_changed_cb
);
49 scrolled_window
.show ();
51 _display
= new
MathDisplay (equation
);
52 scrolled_window
.add (display
);
55 _buttons
= new
MathButtons (equation
);
56 vbox
.pack_start (buttons
, true, true, 0);
60 public void critical_error (string title
, string contents
)
62 var dialog
= new Gtk
.MessageDialog (null, 0,
63 Gtk
.MessageType
.ERROR
,
66 dialog
.format_secondary_text ("%s", contents
);
67 dialog
.add_buttons (Gtk
.Stock
.QUIT
, Gtk
.ResponseType
.ACCEPT
);
74 protected override bool key_press_event (Gdk
.EventKey event
)
76 var result
= base.key_press_event (event
);
78 if (buttons
.mode
== ButtonMode
.PROGRAMMING
&& (event
.state
& Gdk
.ModifierType
.CONTROL_MASK
) == Gdk
.ModifierType
.CONTROL_MASK
)
84 equation
.number_base
= 2;
88 equation
.number_base
= 8;
92 equation
.number_base
= 10;
96 equation
.number_base
= 16;
104 private void scroll_changed_cb (Gtk
.Adjustment adjustment
)
107 adjustment
.set_value (adjustment
.get_upper () - adjustment
.get_page_size ());
110 private void scroll_value_changed_cb (Gtk
.Adjustment adjustment
)
112 if (adjustment
.get_value () == adjustment
.get_upper () - adjustment
.get_page_size ())
113 right_aligned
= true;
115 right_aligned
= false;