/* * Copyright (C) 2004-2005 Vadim Berezniker * http://www.kryptolus.com * * This Program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ #include "stdafx.h" #include "common.h" #include "sabbu.h" #include "gui_main_navigation.h" #include "gui_main_event.h" #include "gui_event_list.h" extern struct sabbu app; void gui_main_menu_navigation_next_row(gpointer callback_data, guint callback_action, GtkWidget *menu_item) { GtkTreeIter iter; gui_main_event_current_save_text(); gui_main_event_select(1, &iter, FALSE, FALSE); } void gui_main_menu_navigation_previous_row(gpointer callback_data, guint callback_action, GtkWidget *menu_item) { GtkTreeIter iter; gui_main_event_current_save_text(); gui_main_event_select(-1, &iter, FALSE, FALSE); } void gui_main_menu_navigation_page_up(gpointer callback_data, guint callback_action, GtkWidget *menu_item) { GtkAdjustment *adjustment = gtk_tree_view_get_vadjustment(gui_event_list_get_view(app.ui.event_list)); GtkTreeIter iter; GtkTreeModel *model; GtkTreeSelection *selection = gui_event_list_get_selection(app.ui.event_list); GList *children = gtk_tree_selection_get_selected_rows(selection, &model); GdkRectangle rectangle; GtkTreePath *path; int x,y; if(!adjustment || !children) { g_list_foreach (children, (GFunc) gtk_tree_path_free, NULL); g_list_free(children); return; } gui_main_event_current_save_text(); adjustment->value -= adjustment->page_increment; if(adjustment->value < 0) adjustment->value = 0; gtk_adjustment_value_changed(adjustment); if(adjustment->value == 0) { gui_main_menu_navigation_top(callback_data, callback_action, menu_item); g_list_foreach (children, (GFunc) gtk_tree_path_free, NULL); g_list_free(children); return; } gtk_tree_view_get_visible_rect(gui_event_list_get_view(app.ui.event_list), &rectangle); gtk_tree_view_tree_to_widget_coords(gui_event_list_get_view(app.ui.event_list), rectangle.x, rectangle.y, &x, &y); y += 50; gtk_tree_view_get_path_at_pos(gui_event_list_get_view(app.ui.event_list), x, y, &path, NULL, NULL, NULL); gtk_tree_view_scroll_to_cell(gui_event_list_get_view(app.ui.event_list), path, NULL, FALSE, 0, 0); gtk_tree_model_get_iter(model, &iter, path); gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_iter(selection, &iter); gtk_tree_path_free(path); g_list_foreach (children, (GFunc) gtk_tree_path_free, NULL); g_list_free(children); } void gui_main_menu_navigation_page_down(gpointer callback_data, guint callback_action, GtkWidget *menu_item) { GtkAdjustment *adjustment = gtk_tree_view_get_vadjustment(gui_event_list_get_view(app.ui.event_list)); GtkTreeIter iter; GtkTreeModel *model; GtkTreeSelection *selection = gui_event_list_get_selection(app.ui.event_list); GList *children = gtk_tree_selection_get_selected_rows(selection, &model); GdkRectangle rectangle; GtkTreePath *path; kryEvent *line; int x,y; if(!adjustment || !children) { g_list_foreach (children, (GFunc) gtk_tree_path_free, NULL); g_list_free(children); return; } gui_main_event_current_save_text(); adjustment->value += adjustment->page_increment; if(adjustment->value > adjustment->upper - adjustment->page_size) adjustment->value = adjustment->upper - adjustment->page_size; gtk_adjustment_value_changed(adjustment); gtk_tree_view_get_visible_rect(gui_event_list_get_view(app.ui.event_list), &rectangle); gtk_tree_view_tree_to_widget_coords(gui_event_list_get_view(app.ui.event_list), rectangle.x, rectangle.y, &x, &y); y += 50; gtk_tree_view_get_path_at_pos(gui_event_list_get_view(app.ui.event_list), x, y, &path, NULL, NULL, NULL); gtk_tree_model_get_iter(model, &iter, path); while(1) { gtk_tree_model_get(model, &iter, PTR_COLUMN, &line, -1); if(line->GetType() != kryEvent::EVENT_BLANK) break; if(!gtk_tree_path_prev(path)) break; gtk_tree_model_get_iter(model, &iter, path); } gtk_tree_view_scroll_to_cell(gui_event_list_get_view(app.ui.event_list), path, NULL, FALSE, 0, 0); gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_iter(selection, &iter); gtk_tree_path_free(path); g_list_foreach (children, (GFunc) gtk_tree_path_free, NULL); g_list_free(children); } void gui_main_menu_navigation_top(gpointer callback_data, guint callback_action, GtkWidget *menu_item) { GtkTreeSelection *selection = gui_event_list_get_selection(app.ui.event_list); GtkTreePath *path = gtk_tree_path_new_from_string("0"); GtkTreeIter iter; gui_main_event_current_save_text(); gtk_tree_model_get_iter(GTK_TREE_MODEL(gui_event_list_get_store(app.ui.event_list)), &iter, path); gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_iter(selection, &iter); gtk_tree_view_scroll_to_cell(gui_event_list_get_view(app.ui.event_list), path, NULL, FALSE, 0, 0); gtk_tree_path_free(path); } void gui_main_menu_navigation_bottom(gpointer callback_data, guint callback_action, GtkWidget *menu_item) { GtkTreeSelection *selection = gui_event_list_get_selection(app.ui.event_list); char *end; if(app.script->GetEventCount() - app.script->GetBlankCount() == 0) end = kry_strdup("0"); else end = kry_strdup_printf(KRY_LOC "%d", app.script->GetEventCount() - app.script->GetBlankCount() - 1); GtkTreePath *path = gtk_tree_path_new_from_string(end); GtkTreeIter iter; gui_main_event_current_save_text(); gtk_tree_model_get_iter(GTK_TREE_MODEL(gui_event_list_get_store(app.ui.event_list)), &iter, path); gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_iter(selection, &iter); gtk_tree_view_scroll_to_cell(gui_event_list_get_view(app.ui.event_list), path, NULL, TRUE, 0.5, 0.0); gtk_tree_path_free(path); kry_free(end); }