00001 #include <gtk/gtk.h>
00002 #include "vapiString.h"
00003 #include "vapiGtkTable.h"
00004
00005 vBoolean
00006 vapiGtkTableSelectRow (GtkWidget * Table, int row)
00007 {
00008 GtkTreeModel *treeModel;
00009 GtkTreeSelection *treeSelection;
00010 GtkTreeIter iter;
00011 treeModel = gtk_tree_view_get_model ((GtkTreeView *) Table);
00012 if (vapiGtkTreeModelSelectRow (treeModel, &iter, row))
00013 {
00014 return vTRUE;
00015 }
00016 treeSelection = gtk_tree_view_get_selection ((GtkTreeView *) Table);
00017 gtk_tree_selection_select_iter (treeSelection, &iter);
00018 return vFALSE;
00019 }
00020
00021 void
00022 vapiGtkComboBoxSetActive (GtkWidget * ComboBox, int row)
00023 {
00024 GtkTreeModel *treeModel;
00025 GtkTreeIter iter;
00026 treeModel = gtk_combo_box_get_model ((GtkComboBox *) ComboBox);
00027 vapiGtkTreeModelSelectRow (treeModel, &iter, row);
00028
00029 gtk_combo_box_set_active_iter ((GtkComboBox *) ComboBox, &iter);
00030 }
00031
00032 vBoolean
00033 vapiGtkTreeModelSelectRow (GtkTreeModel * treeModel, GtkTreeIter * iter,
00034 int row)
00035 {
00036 int i;
00037
00038 gtk_tree_model_get_iter_first ((GtkTreeModel *) treeModel, iter);
00039
00040 if (row > 0)
00041 {
00042 for (i = 0; i < row; i++)
00043 {
00044 if (!gtk_tree_model_iter_next (treeModel, iter))
00045 {
00046 return vTRUE;
00047 }
00048 }
00049 }
00050 return vFALSE;
00051 }
00052
00053 int
00054 vapiGtkTableGetSelectedRow (GtkWidget * Table)
00055 {
00056 GtkTreeIter iter;
00057 GtkTreeModel *model;
00058 GtkTreePath *path;
00059 gint *itemNum;
00060 GtkTreeSelection *selection;
00061
00062 path = gtk_tree_path_new ();
00063 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (Table));
00064 if (gtk_tree_selection_get_selected (selection, &model, &iter))
00065 {
00066 path = gtk_tree_model_get_path (model, &iter);
00067 itemNum = gtk_tree_path_get_indices (path);
00068 return itemNum[0];
00069 }
00070 else
00071 {
00072 v_error ("Nenhuma linha seleccionada");
00073 return -1;
00074 }
00075
00076 }
00077
00078 void
00079 vapiGtkTableGetValueFromSelection (GtkWidget * Table, GValue * gvalue,
00080 int Column)
00081 {
00082 GtkTreeModel *treeModel;
00083 GtkTreeIter iter;
00084 GtkTreeSelection *treeSelection;
00085
00086
00087
00088
00089
00090
00091 treeSelection = gtk_tree_view_get_selection ((GtkTreeView *) Table);
00092 gtk_tree_selection_get_selected (treeSelection, &treeModel, &iter);
00093
00094 gtk_tree_model_get_value (treeModel, &iter, Column, gvalue);
00095 }
00096
00097 int
00098 vapiGtkComboBoxGetActiveRow (GtkWidget * ComboBox)
00099 {
00100 GtkTreeIter iter;
00101 GtkTreePath *path;
00102 gint *itemNum;
00103 GtkTreeModel *treeModel;
00104
00105 path = gtk_tree_path_new ();
00106 treeModel = gtk_combo_box_get_model ((GtkComboBox *) ComboBox);
00107 if (!gtk_combo_box_get_active_iter ((GtkComboBox *) ComboBox, &iter))
00108 {
00109 return -1;
00110 }
00111
00112 path = gtk_tree_model_get_path (treeModel, &iter);
00113
00114 itemNum = gtk_tree_path_get_indices (path);
00115
00116 return itemNum[0];
00117 }