⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree_view.cpp

📁 graph是一款linux/unix下绘制数据曲线图形的程序
💻 CPP
字号:
/* * treeview.cpp - просмотр функций в списке  * Copyright (C) 2007 lester *  * 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 of the * License, 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA *  */#include "tree_view.h"GtkWidget *functions_tree;GtkTreeModel *model;GtkWidget *info_text;extern gintcolor_find_color (const gchar *style);GtkTreeModel *create_model (void){  GtkListStore *store;  /* create list store */  store = gtk_list_store_new (NUM_COLUMNS,			      G_TYPE_BOOLEAN,			      G_TYPE_STRING,                  GDK_TYPE_PIXBUF);  return GTK_TREE_MODEL (store);}voidgraph_render_to_pixbuf();voidon_cell_edited (GtkCellRendererText *cell,             const gchar         *path_string,             const gchar         *new_text,             gpointer             data){  GtkTreeModel *model = (GtkTreeModel *)data;  GtkTreePath *path = gtk_tree_path_new_from_string (path_string);  GtkTreeIter iter;  gtk_tree_model_get_iter (model, &iter, path);  gint i;  gchar *old_text;  gtk_tree_model_get (model, &iter, COLUMN_FUNCTION, &old_text, -1);  if (!g_strcasecmp (old_text, new_text))  {      gtk_tree_path_free (path);      return;  }  g_free (old_text);  i = gtk_tree_path_get_indices (path)[0];  FunctionList &fl = functions_get_function_list ();    functions_modify_function1 (fl[i], std::string(new_text));  std::cout << (*fl[i]).eq << std::endl;    gtk_list_store_set (GTK_LIST_STORE (model), &iter, COLUMN_FUNCTION,                             new_text, -1);    set_modified (TRUE);    graph_render_to_pixbuf ();    gtk_tree_path_free (path);}voidon_tree_show_toggled (GtkCellRendererToggle *cell,	       gchar                 *path_str,	       gpointer               data){  GtkTreeModel *model = (GtkTreeModel *)data;  GtkTreeIter  iter;  GtkTreePath *path = gtk_tree_path_new_from_string (path_str);  gboolean show;  gtk_tree_model_get_iter (model, &iter, path);  gtk_tree_model_get (model, &iter, COLUMN_SHOW, &show, -1);  show ^= 1;  gint i = gtk_tree_path_get_indices (path)[0];    // Сжечь меня на костре за такое уродство :(  FunctionList &fl = functions_get_function_list ();  Function *f = fl[i];  f->show = show;  gtk_list_store_set (GTK_LIST_STORE (model), &iter, COLUMN_SHOW, show, -1);  set_modified (TRUE);  graph_render_to_pixbuf ();  gtk_tree_path_free (path);}gbooleanon_treeview_item_select (GtkTreeView *treeview,                        gpointer user_data){    GtkTreeIter iter;    GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(functions_tree));    if ( gtk_tree_selection_get_selected(selection, NULL, &iter))    {        GtkTreePath *path = gtk_tree_model_get_path(model, &iter);        gint i = gtk_tree_path_get_indices (path)[0];        gtk_tree_path_free (path);        std::string str = functions_get_func_info (i);        GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(info_text));        gtk_text_buffer_set_text (buffer, str.c_str(), -1);    }    return TRUE;}ginttree_view_delete_item (){    GtkTreeIter iter;    GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(functions_tree));    if ( gtk_tree_selection_get_selected(selection, NULL, &iter))    {        GtkTreePath *path = gtk_tree_model_get_path(model, &iter);        gtk_list_store_remove (GTK_LIST_STORE(model), &iter);        gint i = gtk_tree_path_get_indices (path)[0];        gtk_tree_path_free (path);        return i;    }    return -1;}voidtree_view_clear (){    GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(functions_tree));    gtk_list_store_clear (GTK_LIST_STORE(model));}voidtree_view_fill_items (){    FunctionList &list = functions_get_function_list ();    FunctionList::iterator it;    for (it = list.begin(); it != list.end(); ++it)    {        gint clr = color_find_color ((*it)->style);        if (clr == -1) clr = 0x000000;        tree_add_item ((*it)->eq, clr << 8, (*it)->show);    }}voidtree_add_item (const char *eq, guint32 color, gboolean show){  GtkTreeIter iter;  GdkPixbuf *pixbuf;  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, false, 8, 20, 20);  gdk_pixbuf_fill (pixbuf, color);  gtk_list_store_append (GTK_LIST_STORE (model), &iter);  gtk_list_store_set (GTK_LIST_STORE (model), &iter,                      COLUMN_SHOW, show,                      COLUMN_FUNCTION, eq,                      COLUMN_COLOR, pixbuf,                      -1);    g_object_unref (pixbuf);}voidprepare_tree_view (GladeXML *xml){    functions_tree = glade_xml_get_widget(xml, "treeview1");    assert(G_IS_OBJECT(functions_tree));    info_text = glade_xml_get_widget(xml, "info_text");    assert(G_IS_OBJECT(info_text));    g_signal_connect (G_OBJECT(functions_tree), "cursor-changed",                        G_CALLBACK(on_treeview_item_select), NULL);    model = create_model();    gtk_tree_view_set_model(GTK_TREE_VIEW(functions_tree), model);    GtkCellRenderer *renderer = gtk_cell_renderer_toggle_new ();    GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes ("Вкл.",						     renderer,						     "active", COLUMN_SHOW,						     NULL);    gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),				   GTK_TREE_VIEW_COLUMN_AUTOSIZE);    g_signal_connect(G_OBJECT(renderer), "toggled",                            G_CALLBACK(on_tree_show_toggled), static_cast<gpointer>(model));    gtk_tree_view_append_column (GTK_TREE_VIEW(functions_tree), column);    renderer = gtk_cell_renderer_pixbuf_new ();    column = gtk_tree_view_column_new_with_attributes ("Цвет",						     renderer,						     "pixbuf",						     COLUMN_COLOR,						     NULL);    gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),				   GTK_TREE_VIEW_COLUMN_FIXED);    gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN(column), 40);    gtk_tree_view_append_column (GTK_TREE_VIEW(functions_tree), column);    renderer = gtk_cell_renderer_text_new ();    g_object_set (renderer,                "editable", TRUE,                NULL);    g_signal_connect (renderer, "edited",                        G_CALLBACK (on_cell_edited), model);    column = gtk_tree_view_column_new_with_attributes ("Функция",						     renderer,						     "text",						     COLUMN_FUNCTION,						     NULL);    gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),				   GTK_TREE_VIEW_COLUMN_AUTOSIZE);    gtk_tree_view_append_column (GTK_TREE_VIEW(functions_tree), column);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -