|
|
|
|
@ -134,7 +134,7 @@ void yon_gtk_tree_view_column_set_fixed_size(GtkTreeView *target,int column_num)
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model(target);
|
|
|
|
|
GtkTreeViewColumn *current_column = gtk_tree_view_get_column(target,column_num);
|
|
|
|
|
int column_size = gtk_tree_view_column_get_fixed_width(current_column);
|
|
|
|
|
int column_size = 0;
|
|
|
|
|
|
|
|
|
|
for_iter(model,&iter){
|
|
|
|
|
GList *list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(current_column));
|
|
|
|
|
@ -146,59 +146,10 @@ void yon_gtk_tree_view_column_set_fixed_size(GtkTreeView *target,int column_num)
|
|
|
|
|
}
|
|
|
|
|
g_list_free(list);
|
|
|
|
|
if (column_size<cur_size) {
|
|
|
|
|
gtk_tree_view_column_set_fixed_width(current_column,cur_size);
|
|
|
|
|
column_size=cur_size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct fixed_info {
|
|
|
|
|
GtkWidget *target;
|
|
|
|
|
int *columns;
|
|
|
|
|
int size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void yon_on_fixed_changed(GtkTreeViewColumn *self, GParamSpec*,struct fixed_info *info);
|
|
|
|
|
void on_row_fixed_changed(GtkTreeModel* self, GtkTreePath* path, GtkTreeIter* iter, struct fixed_info *info){
|
|
|
|
|
for (int i=0;i<info->size;i++){
|
|
|
|
|
g_signal_handlers_block_by_func(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(info->target),info->columns[i])),yon_on_fixed_changed,info);
|
|
|
|
|
yon_gtk_tree_view_column_set_fixed_size(GTK_TREE_VIEW(info->target),info->columns[i]);
|
|
|
|
|
g_signal_handlers_unblock_by_func(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(info->target),info->columns[i])),yon_on_fixed_changed,info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void on_row_fixed_deleted(GtkTreeModel* self, GtkTreePath* path, struct fixed_info *info){
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<info->size;i++){
|
|
|
|
|
g_signal_handlers_block_by_func(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(info->target),info->columns[i])),yon_on_fixed_changed,info);
|
|
|
|
|
yon_gtk_tree_view_column_set_fixed_size(GTK_TREE_VIEW(info->target),info->columns[i]);
|
|
|
|
|
g_signal_handlers_unblock_by_func(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(info->target),info->columns[i])),yon_on_fixed_changed,info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void yon_on_fixed_changed(GtkTreeViewColumn *self, GParamSpec*,struct fixed_info *info){
|
|
|
|
|
for (int i=0;i<info->size;i++){
|
|
|
|
|
if (self == gtk_tree_view_get_column(GTK_TREE_VIEW(info->target),info->columns[i])){
|
|
|
|
|
int *new_columns = malloc(sizeof(int)*(info->size-1));
|
|
|
|
|
for (int j=0;j<info->size-1;j++){
|
|
|
|
|
if (j<i) new_columns[j]=info->columns[j];
|
|
|
|
|
else new_columns[j]=info->columns[j+1];
|
|
|
|
|
}
|
|
|
|
|
free(info->columns);
|
|
|
|
|
info->columns=new_columns;
|
|
|
|
|
info->size--;
|
|
|
|
|
if (!info->size){
|
|
|
|
|
GObject *model = G_OBJECT(gtk_tree_view_get_model(GTK_TREE_VIEW(info->target)));
|
|
|
|
|
g_signal_handlers_disconnect_by_func(model,on_row_fixed_changed,info);
|
|
|
|
|
g_signal_handlers_disconnect_by_func(model,on_row_fixed_deleted,info);
|
|
|
|
|
free(info->columns);
|
|
|
|
|
free(info);
|
|
|
|
|
}
|
|
|
|
|
g_signal_handlers_disconnect_by_func(self,yon_on_fixed_changed,info);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gtk_tree_view_column_set_fixed_width(current_column,column_size+10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int yon_gtk_tree_view_set_fixed_size(GtkTreeView *target,...){
|
|
|
|
|
@ -207,20 +158,10 @@ int yon_gtk_tree_view_set_fixed_size(GtkTreeView *target,...){
|
|
|
|
|
int current;
|
|
|
|
|
int target_columns = gtk_tree_view_get_n_columns(target);
|
|
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model(target);
|
|
|
|
|
struct fixed_info *info = malloc(sizeof(struct fixed_info));
|
|
|
|
|
info->target=GTK_WIDGET(target);
|
|
|
|
|
info->columns=NULL;
|
|
|
|
|
info->size=0;
|
|
|
|
|
g_signal_connect(G_OBJECT(model),"row-changed",G_CALLBACK(on_row_fixed_changed),info);
|
|
|
|
|
g_signal_connect(G_OBJECT(model),"row-deleted",G_CALLBACK(on_row_fixed_deleted),info);
|
|
|
|
|
|
|
|
|
|
while ((current=va_arg(args,int))!=-1){
|
|
|
|
|
if (current>target_columns) return 0;
|
|
|
|
|
if (!info->columns) info->columns = malloc(sizeof(int));
|
|
|
|
|
else info->columns = realloc(info->columns,sizeof(int)*(info->size+1));
|
|
|
|
|
info->columns[info->size]=current;
|
|
|
|
|
g_signal_connect(G_OBJECT(gtk_tree_view_get_column(target,current)),"notify::fixed-width",G_CALLBACK(yon_on_fixed_changed),info);
|
|
|
|
|
info->size++;
|
|
|
|
|
yon_gtk_tree_view_column_set_fixed_size(target,current);
|
|
|
|
|
}
|
|
|
|
|
va_end(args);
|
|
|
|
|
return 1;
|
|
|
|
|
|