/* * Copyright (c) 2006 * Morten Slot Kristensen, Århus, Denmark. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "matrix.hpp" #include "operations.hpp" #include "gtk.hpp" #include "defs.hpp" using namespace std; /* * Destroys the program */ gint destroy_app(GtkWidget *widget, gpointer gdata) { gtk_main_quit(); } /* * Shows a messagebox with a specified text, message-type * and button-type */ void msgbox(string msg, GtkMessageType mtype, GtkButtonsType btype) { GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, mtype, btype, msg.c_str()); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } /* * Adds columns to the treeview (list) */ void add_columns_to_treeview(GtkTreeView *treeview) { GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeModel *model = gtk_tree_view_get_model(treeview); // ID column renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("ID", renderer, "text", COLUMN_ID, NULL); gtk_tree_view_column_set_sort_column_id(column, COLUMN_ID); gtk_tree_view_append_column(treeview, column); // Info column renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("Information", renderer, "text", COLUMN_INFO, NULL); gtk_tree_view_column_set_sort_column_id(column, COLUMN_INFO); gtk_tree_view_append_column(treeview, column); } /* * Shows the about dialog */ void show_about(GtkWidget *widget, gpointer gdata) { GtkWidget *about = gtk_about_dialog_new(); gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), string(VERSION).c_str()); gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about), string(DEVSITE).c_str()); gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), string("Copyright 2006 - "+to_string(DEVNAME)+" <"+to_string( DEVMAIL)+">").c_str()); gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), "Mathemathical matrix calculator."); gtk_dialog_run(GTK_DIALOG(about)); gtk_widget_destroy(about); } /* * Adds a matrix to the treeview (list) */ void add_matrix_to_treeview(GtkTreeView *treeview, matrix *m, GtkListStore *store) { GtkTreeIter iter; gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, COLUMN_ID, m->get_id(), COLUMN_INFO, string(to_string(m->get_rows())+"x"+to_string(m->get_columns())).c_str(), -1); gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(store)); } /* * Inserts a matrix into a textbuffer */ void insert_matrix(GtkTextBuffer *widget, matrix *m) { string matrix = gen_text_matrix(m); gtk_text_buffer_set_text(widget, matrix.c_str(), matrix.length()); }