Updated kn translations
[gcalctool.git] / src / math-window.vala
blob1c3a614c886a21cd18315bbbf9d8cadd165bfe6f
1 /*
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
9 * license.
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);
27 _equation = equation;
28 set_title (/* Title of main window */
29 _("Calculator"));
30 role = "gcalctool";
31 resizable = false;
33 var main_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
34 add (main_vbox);
35 main_vbox.show ();
37 var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
38 vbox.border_width = 6;
39 main_vbox.pack_start (vbox, true, true, 0);
40 vbox.show ();
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);
48 right_aligned = true;
49 scrolled_window.show ();
51 _display = new MathDisplay (equation);
52 scrolled_window.add (display);
53 display.show ();
55 _buttons = new MathButtons (equation);
56 vbox.pack_start (buttons, true, true, 0);
57 buttons.show ();
60 public void critical_error (string title, string contents)
62 var dialog = new Gtk.MessageDialog (null, 0,
63 Gtk.MessageType.ERROR,
64 Gtk.ButtonsType.NONE,
65 "%s", title);
66 dialog.format_secondary_text ("%s", contents);
67 dialog.add_buttons (Gtk.Stock.QUIT, Gtk.ResponseType.ACCEPT);
69 dialog.run ();
71 destroy ();
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)
80 switch (event.keyval)
82 /* Binary */
83 case Gdk.Key.b:
84 equation.number_base = 2;
85 return true;
86 /* Octal */
87 case Gdk.Key.o:
88 equation.number_base = 8;
89 return true;
90 /* Decimal */
91 case Gdk.Key.d:
92 equation.number_base = 10;
93 return true;
94 /* Hexdecimal */
95 case Gdk.Key.h:
96 equation.number_base = 16;
97 return true;
101 return result;
104 private void scroll_changed_cb (Gtk.Adjustment adjustment)
106 if (right_aligned)
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;
114 else
115 right_aligned = false;