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

📄 collect-table.c

📁 Gqview,Linux下基于GTK+库写成的轻量级而能丰富的图像浏览程序。
💻 C
📖 第 1 页 / 共 4 页
字号:
	CollectTable *ct = data;	file_util_move(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);}static void collection_table_popup_rename_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	file_util_rename(NULL, collection_table_popup_file_list(ct), ct->listview);}static void collection_table_popup_delete_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);}static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data){	CollectTable *ct;	SortType type;	ct = submenu_item_get_data(widget);	if (!ct) return;	type = (SortType)GPOINTER_TO_INT(data);	collection_set_sort_method(ct->cd, type);}static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))		{		view_window_new_from_collection(ct->cd, ct->click_info);		}}static void collection_table_popup_view_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))		{		layout_image_set_collection(NULL, ct->cd, ct->click_info);		}}static void collection_table_popup_selectall_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	collection_table_select_all(ct);	ct->prev_selection= ct->click_info;}static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	collection_table_unselect_all(ct);	ct->prev_selection= ct->click_info;}static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	GList *list;	if (!ct->click_info) return;                                                                                                                               	if (INFO_SELECTED(ct->click_info))		{		list = g_list_copy(ct->selection);		}	else		{		list = g_list_append(NULL, ct->click_info);		}	collection_remove_by_info_list(ct->cd, list);	g_list_free(list);}static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	GList *list;	list = layout_list(NULL);	if (list)		{		collection_table_add_path_list(ct, list);		path_list_free(list);		}}static void collection_table_popup_add_collection_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	collection_dialog_append(NULL, ct->cd);}static void collection_table_popup_find_dupes_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	DupeWindow *dw;	dw = dupe_window_new(DUPE_MATCH_NAME);	dupe_window_add_collection(dw, ct->cd);}static void collection_table_popup_print_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	const gchar *path;	path = (ct->click_info) ? ct->click_info->path : NULL;	print_window_new(path, collection_table_selection_get_list(ct), collection_table_get_list(ct), ct->listview);}static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	collection_table_toggle_filenames(ct);}static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data){	CollectTable *ct = data;	collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);	ct->click_info = NULL;	ct->popup = NULL;	path_list_free(ct->drop_list);	ct->drop_list = NULL;	ct->drop_info = NULL;}static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon){	GtkWidget *menu;	GtkWidget *item;	menu = popup_menu_short_lived();	g_signal_connect(G_OBJECT(menu), "destroy",			 G_CALLBACK(collection_table_popup_destroy_cb), ct);	menu_item_add_sensitive(menu, _("_View"), over_icon,			G_CALLBACK(collection_table_popup_view_cb), ct);	menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon,			G_CALLBACK(collection_table_popup_view_new_cb), ct);	menu_item_add_divider(menu);	menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon,			G_CALLBACK(collection_table_popup_remove_cb), ct);	menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD,			G_CALLBACK(collection_table_popup_add_filelist_cb), ct);	menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,			G_CALLBACK(collection_table_popup_add_collection_cb), ct);	menu_item_add_divider(menu);	menu_item_add(menu, _("Select all"),			G_CALLBACK(collection_table_popup_selectall_cb), ct);	menu_item_add(menu, _("Select none"),			G_CALLBACK(collection_table_popup_unselectall_cb), ct);	menu_item_add_divider(menu);	submenu_add_edit(menu, &item,			G_CALLBACK(collection_table_popup_edit_cb), ct);	gtk_widget_set_sensitive(item, over_icon);	menu_item_add_sensitive(menu, _("_Properties"), over_icon,			G_CALLBACK(collection_table_popup_info_cb), ct);	menu_item_add_divider(menu);	menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,			G_CALLBACK(collection_table_popup_copy_cb), ct);	menu_item_add_sensitive(menu, _("_Move..."), over_icon,			G_CALLBACK(collection_table_popup_move_cb), ct);	menu_item_add_sensitive(menu, _("_Rename..."), over_icon,			G_CALLBACK(collection_table_popup_rename_cb), ct);	menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon,			G_CALLBACK(collection_table_popup_delete_cb), ct);	menu_item_add_divider(menu);	submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);	menu_item_add_check(menu, _("Show filename _text"), ct->show_text,			G_CALLBACK(collection_table_popup_show_names_cb), ct);	menu_item_add_divider(menu);	menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE,			G_CALLBACK(collection_table_popup_save_cb), ct);	menu_item_add_stock(menu, _("Save collection _as..."), GTK_STOCK_SAVE_AS,			G_CALLBACK(collection_table_popup_save_as_cb), ct);	menu_item_add_divider(menu);	menu_item_add_stock(menu, _("_Find duplicates..."), GTK_STOCK_FIND,			G_CALLBACK(collection_table_popup_find_dupes_cb), ct);	menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, over_icon,			G_CALLBACK(collection_table_popup_print_cb), ct);			return menu;}/* *------------------------------------------------------------------- * keyboard callbacks *------------------------------------------------------------------- */static void collection_table_set_focus(CollectTable *ct, CollectInfo *info){	GtkTreeIter iter;	gint row, col;	if (g_list_find(ct->cd->list, ct->focus_info))		{		if (info == ct->focus_info)			{			/* ensure focus row col are correct */			collection_table_find_position(ct, ct->focus_info,						       &ct->focus_row, &ct->focus_column);			return;			}		collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, NULL);		}	if (!collection_table_find_position(ct, info, &row, &col))		{		ct->focus_info = NULL;		ct->focus_row = -1;		ct->focus_column = -1;		return;		}	ct->focus_info = info;	ct->focus_row = row;	ct->focus_column = col;	collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, NULL);	if (collection_table_find_iter(ct, ct->focus_info, &iter, NULL))		{		GtkTreePath *tpath;		GtkTreeViewColumn *column;		GtkTreeModel *store;		tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);		store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));		tpath = gtk_tree_model_get_path(store, &iter);		/* focus is set to an extra column with 0 width to hide focus, we draw it ourself */		column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);		gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);		gtk_tree_path_free(tpath);		}}static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative){	gint new_row;	gint new_col;	if (relative)		{		new_row = ct->focus_row;		new_col = ct->focus_column;		new_row += row;		if (new_row < 0) new_row = 0;		if (new_row >= ct->rows) new_row = ct->rows - 1;		while(col != 0)			{			if (col < 0)				{				new_col--;				col++;				}			else				{				new_col++;				col--;				}			if (new_col < 0)				{				if (new_row > 0)					{					new_row--;					new_col = ct->columns - 1;					}				else					{					new_col = 0;					}				}			if (new_col >= ct->columns)				{				if (new_row < ct->rows - 1)					{					new_row++;					new_col = 0;					}				else					{					new_col = ct->columns - 1;					}				}			}		}	else		{		new_row = row;		new_col = col;		if (new_row >= ct->rows)			{			if (ct->rows > 0)				new_row = ct->rows - 1;			else				new_row = 0;			new_col = ct->columns - 1;			}		if (new_col >= ct->columns) new_col = ct->columns - 1;		}	if (new_row == ct->rows - 1)		{		gint l;		/* if we moved beyond the last image, go to the last image */		l = g_list_length(ct->cd->list);		if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;		if (new_col >= l) new_col = l - 1;		}	if (new_row == -1 || new_col == -1)		{		if (!ct->cd->list) return;		new_row = new_col = 0;		}	collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, NULL));}static void collection_table_update_focus(CollectTable *ct){	gint new_row = 0;	gint new_col = 0;	if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))		{		/* first find the old focus, if it exists and is valid */		}	else		{		/* (try to) stay where we were */		new_row = ct->focus_row;		new_col = ct->focus_column;		}	collection_table_move_focus(ct, new_row, new_col, FALSE);}/* used to figure the page up/down distances */static gint page_height(CollectTable *ct){	GtkAdjustment *adj;	gint page_size;	gint row_height;	gint ret;	adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));	page_size = (gint)adj->page_increment;	row_height = thumb_max_height + THUMB_BORDER_PADDING * 2;	if (ct->show_text) row_height += thumb_max_height / 3;	ret = page_size / row_height;	if (ret < 1) ret = 1;	return ret;}static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data){	CollectTable *ct = data;	GtkTreeModel *store;	GtkTreeIter iter;	gint column;	GtkTreePath *tpath;	gint cw, ch;	if (!collection_table_find_iter(ct, ct->click_info, &iter, &column)) return;	store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));	tpath = gtk_tree_model_get_path(store, &iter);	tree_view_get_cell_clamped(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE, x, y, &cw, &ch);	gtk_tree_path_free(tpath);	*y += ch;	popup_menu_position_clamp(menu, x, y, 0);}static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data){	CollectTable *ct = data;	gint stop_signal = FALSE;	gint focus_row = 0;	gint focus_col = 0;	CollectInfo *info;	switch (event->keyval)		{		case GDK_Left: case GDK_KP_Left:			focus_col = -1;			stop_signal = TRUE;			break;		case GDK_Right: case GDK_KP_Right:			focus_col = 1;			stop_signal = TRUE;			break;		case GDK_Up: case GDK_KP_Up:			focus_row = -1;			stop_signal = TRUE;			break;		case GDK_Down: case GDK_KP_Down:			focus_row = 1;			stop_signal = TRUE;			break;		case GDK_Page_Up: case GDK_KP_Page_Up:			focus_row = -page_height(ct);			stop_signal = TRUE;			break;		case GDK_Page_Down: case GDK_KP_Page_Down:			focus_row = page_height(ct);			stop_signal = TRUE;			break;		case GDK_Home: case GDK_KP_Home:			focus_row = -ct->focus_row;			focus_col = -ct->focus_column;			stop_signal = TRUE;			break;		case GDK_End: case GDK_KP_End:			focus_row = ct->rows - 1 - ct->focus_row;			focus_col = ct->columns - 1 - ct->focus_column;			stop_signal = TRUE;			break;		case GDK_space:			info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);			if (info)				{				ct->click_info = info;				if (event->state & GDK_CONTROL_MASK)					{					collection_table_select_util(ct, info, !INFO_SELECTED(info));					}				else					{					collection_table_unselect_all(ct);					collection_table_select(ct, info);					}				}			stop_signal = TRUE;			break;		case 'T': case 't':			if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);			break;		case GDK_Menu:		case GDK_F10:			info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);			ct->click_info = info;			collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, NULL);			tip_unschedule(ct);			ct->popup = collection_table_popup_menu(ct, (info != NULL));			gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, collection_table_menu_pos_cb, ct, 0, GDK_CURRENT_TIME);			stop_signal = TRUE;			break;		default:			break;		}	if (focus_row != 0 || focus_col != 0)		{		CollectInfo *new_info;		CollectInfo *old_info;		old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);		collection_table_move_focus(ct, focus_row, focus_col, TRUE);		new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);		if (new_info != old_info)			{			if (event->state & GDK_SHIFT_MASK)				{				if (!collection_rectangular_selection)					{					collection_table_select_region_util(ct, old_info, new_info, FALSE);					}				else					{					collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);					}				collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);				}			else if (event->state & GDK_CONTROL_MASK)				{				ct->click_info = new_info;				}			else				{				ct->click_info = new_info;				collection_table_unselect_all(ct);				collection_table_select(ct, new_info);				}			}		}	if (stop_signal)		{		g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event");		tip_unschedule(ct);		}	return stop_signal;}/* *------------------------------------------------------------------- * insert marker *------------------------------------------------------------------- */static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell,						 gint use_coord, gint x, gint y){	CollectInfo *info = NULL;	GtkTreeModel *store;	GtkTreeIter iter;	GtkTreePath *tpath;	GtkTreeViewColumn *column;	store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));	if (!use_coord) gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);	if (source)		{		gint col;		if (collection_table_find_iter(ct, source, &iter, &col))			{			tpath = gtk_tree_model_get_path(store, &iter);			column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);			gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);			gtk_tree_path_free(tpath);			info = source;			*after = (x > cell->x + (cell->width / 2));			}		return info;		}	if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,					  &tpath, &column, NULL, NULL))		{		GList *list;		gint n;		gtk_tree_model_get_iter(store, &iter, tpath);		gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);		n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));		info = g_list_nth_data(list, n);		if (info)			{			gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);			*after = (x > cell->x + (cell->width / 2));			}		gtk_tree_path_free(tpath);		}	if (info == NULL)		{		GList *work;		work = g_list_last(ct->cd->list);		if (work)			{			gint col;			info = work->data;			*after = TRUE;			if (collection_table_find_iter(ct, info, &iter, &col))				{				tpath = gtk_tree_model_get_path(store, &iter);				column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);				gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);				gtk_tree_path_free(tpath);				}			}		}

⌨️ 快捷键说明

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