4
Copyright (C) 2014 Peter Arnold
5
This program is free software: you can redistribute it and/or modify it
6
under the terms of the GNU Lesser General Public License version 3, as
7
published by the Free Software Foundation.
9
This program is distributed in the hope that it will be useful, but
10
WITHOUT ANY WARRANTY; without even the implied warranties of
11
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
PURPOSE. See the GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License along
15
with this program. If not, see <http://www.gnu.org/licenses>
2
* Copyright (c) 2015 Peter Arnold
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
20
20
public class ResultView : Gtk.Box {
21
21
private Gtk.TextView text_view;
22
22
private Gdk.Cursor left_ptr = new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.LEFT_PTR);
23
23
private Gdk.Cursor hand = new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.HAND2);
24
24
private bool hovering_over_result = false;
25
public Gee.ArrayList<ResultLine> result_list { get; private set;}
25
public Gee.ArrayList<ResultLine> result_list { get; private set; }
26
26
private const int START_WIDTH = 210;
27
27
private int actual_width = START_WIDTH;
28
28
private bool update_needed;
50
50
text_view.set_can_focus (false);
51
51
bold_tag = text_view.buffer.create_tag ("bold");
52
52
bold_tag.weight = Pango.Weight.BOLD;
53
// use 12pt font because the superscripts are displayed wrong if font is smaller!
53
/* use 12pt font because the superscripts are displayed wrong if font is smaller! */
54
54
var font_desc = text_view.get_style_context ().get_font (Gtk.StateFlags.NORMAL);
55
55
font_desc.set_size (12 * Pango.SCALE);
56
56
text_view.override_font (font_desc);
57
// background color very light grey
57
/* background color very light grey */
58
58
var color = Gdk.RGBA ();
63
63
text_view.override_background_color (Gtk.StateFlags.NORMAL, color);
64
// listen on result press
64
/* listen on result press */
65
65
text_view.set_events (Gdk.EventMask.BUTTON_PRESS_MASK);
66
66
text_view.button_press_event.connect ((evt) => {
67
67
if (!hovering_over_result) {
80
80
text_view.window_to_buffer_coords (Gtk.TextWindowType.TEXT, (int)evt.x, (int)evt.y, out x, out y);
81
text_view.get_iter_at_location ( out iter, x, y);
81
text_view.get_iter_at_location (out iter, x, y);
82
82
int line_number = iter.get_line ();
83
83
insert_variable (result_list.get (line_number));
84
84
text_view.get_window (Gtk.TextWindowType.TEXT).set_cursor (left_ptr);
87
// listen on result hovering
88
/* listen on result hovering */
88
89
text_view.set_events (Gdk.EventMask.POINTER_MOTION_MASK);
89
text_view.motion_notify_event .connect ((evt) => {
90
text_view.motion_notify_event.connect ((evt) => {
92
93
text_view.window_to_buffer_coords (Gtk.TextWindowType.TEXT, (int)evt.x, (int)evt.y, out x, out y);
93
text_view.get_iter_at_location ( out iter, x, y);
94
text_view.get_iter_at_location (out iter, x, y);
94
95
bool hovering = false;
96
97
foreach (var tag in iter.get_tags ()) {
131
131
public override bool draw (Cairo.Context cr) {
132
132
var res = base.draw (cr);
133
// change cursor to normal
133
/* change cursor to normal */
134
134
text_view.get_window (Gtk.TextWindowType.TEXT).set_cursor (left_ptr);
138
// shows a spinner at the line
139
/* shows a spinner at the line */
139
140
public void show_spinner (int line) {
140
141
spinner_box.no_show_all = false;
141
142
spinner.margin_top = Nasc.top_padding + (line * 27);
142
143
spinner_box.show_all ();
143
// for (int i = line; i < result_list.size; i++) {
144
// var res = result_list.get (i);
147
// update (line, true);
145
* for (int i = line; i < result_list.size; i++) {
146
* var res = result_list.get (i);
149
* update (line, true);
150
153
public void hide_spinner () {
168
171
public void add_line (int line, int count) {
169
// add new line/lines
172
/* add new line/lines */
170
173
for (int i = 0; i < count; i++) {
171
174
if (i + line > result_list.size) {
172
175
string variable_name = NascSettings.variable_names + "%d".printf (result_list.size);
173
176
result_list.add (new ResultLine (result_list.size, variable_name, "", actual_width));
176
178
string variable_name = NascSettings.variable_names + "%d".printf (i + line);
177
179
result_list.insert (i + line, new ResultLine (i + line, variable_name, "", actual_width));
181
//update all lines greater than line
182
for (int i = result_list.size - 1; i >= line + count ; i--) {
183
/* update all lines greater than line */
184
for (int i = result_list.size - 1; i >= line + count; i--) {
183
185
var tmp = result_list.get (i);
185
187
tmp.variable_name = NascSettings.variable_names + "%d".printf (i);
228
231
text_view.buffer.text = "";
229
232
text_view.buffer.get_iter_at_offset (out iter, 0);
234
/* setting results */
232
235
for (int i = 0; i < result_list.size; i++) {
233
236
var res = result_list.get (i);
234
237
Gtk.TextTag tag = text_view.buffer.tag_table.lookup (NascSettings.variable_names + "%d".printf (i));