+static void
+update_find_results (EvView *view)
+{
+ const EvFindResult *results;
+ int i;
+ int on_this_page;
+ int next_page_with_result;
+ int earliest_page_with_result;
+ int current_page;
+ gboolean counts_changed;
+
+ results = (EvFindResult*) view->find_results->data;
+ current_page = ev_document_get_page (view->document);
+ next_page_with_result = 0;
+ on_this_page = 0;
+ earliest_page_with_result = 0;
+
+ i = 0;
+ while (i < view->find_results->len) {
+ if (results[i].page_num == current_page) {
+ ++on_this_page;
+ } else {
+ int delta = results[i].page_num - current_page;
+
+ if (delta > 0 && /* result on later page */
+ (next_page_with_result == 0 ||
+ results[i].page_num < next_page_with_result))
+ next_page_with_result = results[i].page_num;
+
+ if (delta < 0 && /* result on a previous page */
+ (earliest_page_with_result == 0 ||
+ results[i].page_num < earliest_page_with_result))
+ earliest_page_with_result = results[i].page_num;
+ }
+ ++i;
+ }
+
+ /* If earliest page is just the current page, there is no earliest page */
+ if (earliest_page_with_result == current_page)
+ earliest_page_with_result = 0;
+
+ /* If no next page, then wrap and the wrapped page is the next page */
+ if (next_page_with_result == 0)
+ next_page_with_result = earliest_page_with_result;
+
+ counts_changed = FALSE;
+ if (on_this_page != view->results_on_this_page ||
+ next_page_with_result != view->next_page_with_result) {
+ view->results_on_this_page = on_this_page;
+ view->next_page_with_result = next_page_with_result;
+ counts_changed = TRUE;
+ }
+
+ /* If there are no results at all, then the
+ * results of ev_view_get_find_status_message() will change
+ * to reflect the percent_complete so we have to emit the signal
+ */
+ if (counts_changed ||
+ view->find_results->len == 0) {
+ g_signal_emit_by_name (view,
+ "find-status-changed");
+ }
+}