From 849a39ad7b8d846b97cf183842a7e8ec9a2a125b Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Mon, 8 Aug 2005 10:33:11 +0000 Subject: [PATCH] moo_icon_view_activate_selected, moo_icon_view_move_cursor --- moo.kdevelop | 40 ++++++++--------- moo/mooutils/mooiconview.c | 91 ++++++++++++++++++++------------------ moo/mooutils/mooiconview.h | 3 ++ 3 files changed, 71 insertions(+), 63 deletions(-) diff --git a/moo.kdevelop b/moo.kdevelop index 38ee9acd..e757bfd8 100644 --- a/moo.kdevelop +++ b/moo.kdevelop @@ -24,7 +24,7 @@ . false - + C @@ -36,17 +36,17 @@ debug - tests/editor + tests/testfileview executable / - + false false - --enable-debug=full --enable-all-gcc-warnings=fatal --enable-developer-mode --disable-moo-module --without-python + --enable-debug=full --enable-all-gcc-warnings=fatal --enable-developer-mode --disable-moo-module --without-python --without-mooapp --without-mooterm build/debug kdevgccoptions kdevgppoptions @@ -54,13 +54,13 @@ -O0 -g3 -pg -O0 -g3 -pg - - - - - - - + + + + + + + --enable-all-gcc-warnings=fatal --enable-developer-mode @@ -166,10 +166,10 @@ libtool --g-fatal-warnings --sync - - - - + + + + true false true @@ -234,16 +234,16 @@ - + A new empty GAP source file - + A new empty C++ file. - + A new empty header file for C/C++. - + A new empty C file. @@ -270,7 +270,7 @@ - + set m_,_ theValue diff --git a/moo/mooutils/mooiconview.c b/moo/mooutils/mooiconview.c index 05d9af90..6b3f6764 100644 --- a/moo/mooutils/mooiconview.c +++ b/moo/mooutils/mooiconview.c @@ -1280,7 +1280,8 @@ static int path_get_index (GtkTreePath *path) static Column *find_column_by_path (MooIconView *view, - GtkTreePath *path) + GtkTreePath *path, + int *index) { GSList *l; int path_index; @@ -1293,7 +1294,11 @@ static Column *find_column_by_path (MooIconView *view, int first = path_get_index (column->first); if (first <= path_index && path_index < first + num_entries (column)) - return column; + { + if (index) + *index = path_index - first; + return column; + } } g_return_val_if_reached (NULL); @@ -1371,21 +1376,15 @@ static void rows_reordered (G_GNUC_UNUSED GtkTreeModel *model, static void invalidate_cell_rect (MooIconView *view, Column *column, - GtkTreePath *path) + int index) { GdkRectangle rect; - int first, path_index; if (view->priv->update_idle) return; - first = path_get_index (column->first); - path_index = path_get_index (path); - g_assert (first <= path_index); - g_assert (path_index < first + num_entries (column)); - rect.x = column->offset - view->priv->xoffset; - rect.y = (path_index - first) * view->priv->layout->row_height; + rect.y = index * view->priv->layout->row_height; rect.width = column->width; rect.height = view->priv->layout->row_height; @@ -1514,6 +1513,7 @@ static void invalidate_path_rectangle (MooIconView *view, GtkTreePath *path) { Column *column; + int index; if (view->priv->update_idle) return; @@ -1521,9 +1521,9 @@ static void invalidate_path_rectangle (MooIconView *view, if (check_empty (view)) return; - column = find_column_by_path (view, path); + column = find_column_by_path (view, path, &index); g_return_if_fail (column != NULL); - invalidate_cell_rect (view, column, path); + invalidate_cell_rect (view, column, index); } @@ -1689,6 +1689,13 @@ GtkTreePath *moo_icon_view_get_path (MooIconView *view, } +void moo_icon_view_activate_selected (MooIconView *view) +{ + g_return_if_fail (MOO_IS_ICON_VIEW (view)); + g_signal_emit (view, signals[ACTIVATE_SELECTED], 0); +} + + static void activate_selected (MooIconView *view) { GtkTreePath *path; @@ -1774,24 +1781,6 @@ static GtkTreePath *get_path_at_cursor (MooIconView *view) } -static int column_get_index (Column *column, - GtkTreePath *path) -{ - int first, index; - - g_return_val_if_fail (column != NULL, -1); - g_return_val_if_fail (gtk_tree_path_get_depth (path) == 1, -1); - - index = gtk_tree_path_get_indices(path)[0]; - first = gtk_tree_path_get_indices(column->first)[0]; - - g_return_val_if_fail (first <= index, -1); - g_return_val_if_fail (index < first + num_entries (column), -1); - - return index - first; -} - - static GtkTreePath *column_get_path (Column *column, int index) { @@ -1853,18 +1842,18 @@ static void move_cursor_right (MooIconView *view) path = get_path_at_cursor (view); - column = find_column_by_path (view, path); + column = find_column_by_path (view, path, &y); g_return_if_fail (column != NULL); next = column_next (view, column); if (!next) { - moo_icon_view_select_path (view, path); + move_cursor_to_entry (view, column, + num_entries (column) - 1); } else { - y = column_get_index (column, path); if (y >= num_entries (next)) y = num_entries (next) - 1; move_cursor_to_entry (view, next, y); @@ -1878,22 +1867,22 @@ static void move_cursor_left (MooIconView *view) { GtkTreePath *path; Column *column, *prev; + int index; if (check_empty (view)) return; path = get_path_at_cursor (view); - column = find_column_by_path (view, path); + column = find_column_by_path (view, path, &index); g_return_if_fail (column != NULL); prev = column_prev (view, column); if (!prev) - moo_icon_view_select_path (view, path); + move_cursor_to_entry (view, column, 0); else - move_cursor_to_entry (view, prev, - column_get_index (column, path)); + move_cursor_to_entry (view, prev, index); gtk_tree_path_free (path); } @@ -1910,11 +1899,9 @@ static void move_cursor_up (MooIconView *view) path = get_path_at_cursor (view); - column = find_column_by_path (view, path); + column = find_column_by_path (view, path, &y); g_return_if_fail (column != NULL); - y = column_get_index (column, path); - if (y) { move_cursor_to_entry (view, column, y - 1); @@ -1944,11 +1931,9 @@ static void move_cursor_down (MooIconView *view) path = get_path_at_cursor (view); - column = find_column_by_path (view, path); + column = find_column_by_path (view, path, &y); g_return_if_fail (column != NULL); - y = column_get_index (column, path); - if (y < num_entries (column) - 1) { move_cursor_to_entry (view, column, y + 1); @@ -2062,6 +2047,26 @@ static void move_cursor_to_entry (MooIconView *view, } +void moo_icon_view_move_cursor (MooIconView *view, + GtkTreePath *path) +{ + Column *column; + int index; + + g_return_if_fail (MOO_IS_ICON_VIEW (view)); + + if (!path) + return moo_icon_view_select_path (view, NULL); + + g_return_if_fail (gtk_tree_path_get_depth (path) == 1); + + column = find_column_by_path (view, path, &index); + g_return_if_fail (column != NULL); + + move_cursor_to_entry (view, column, index); +} + + GtkTreePath *moo_icon_view_get_selected (MooIconView *view) { g_return_val_if_fail (MOO_IS_ICON_VIEW (view), NULL); diff --git a/moo/mooutils/mooiconview.h b/moo/mooutils/mooiconview.h index 56f41757..ab8509a9 100644 --- a/moo/mooutils/mooiconview.h +++ b/moo/mooutils/mooiconview.h @@ -103,6 +103,9 @@ GtkTreePath *moo_icon_view_get_path (MooIconView *view, int window_x, int window_y); GtkTreePath *moo_icon_view_get_selected (MooIconView *view); +void moo_icon_view_activate_selected (MooIconView *view); +void moo_icon_view_move_cursor (MooIconView *view, + GtkTreePath *path); G_END_DECLS