+/** @brief Called when the 'next search result' button is clicked */
+static void next_clicked(GtkButton attribute((unused)) *button,
+ gpointer attribute((unused)) userdata) {
+ /* We want to find the highest (lowest ymax) track that is below the current
+ * visible range */
+ int n;
+ const gdouble bottom = gtk_adjustment_get_value(vadjust) + vadjust->page_size;
+ const struct choosenode *candidate = 0;
+
+ for(n = 0; n < nsearchresults; ++n) {
+ const struct choosenode *const cn = searchnodes[n];
+
+ if(cn
+ && cn->ymax > bottom
+ && (candidate == 0
+ || cn->ymax < candidate->ymax))
+ candidate = cn;
+ }
+ if(candidate)
+ gtk_adjustment_clamp_page(vadjust, candidate->ymin, candidate->ymax);
+}
+
+/** @brief Called when the 'previous search result' button is clicked */
+static void prev_clicked(GtkButton attribute((unused)) *button,
+ gpointer attribute((unused)) userdata) {
+ /* We want to find the lowest (greated ymax) track that is above the current
+ * visible range */
+ int n;
+ const gdouble top = gtk_adjustment_get_value(vadjust);
+ const struct choosenode *candidate = 0;
+
+ for(n = 0; n < nsearchresults; ++n) {
+ const struct choosenode *const cn = searchnodes[n];
+
+ if(cn
+ && cn->ymin < top
+ && (candidate == 0
+ || cn->ymax > candidate->ymax))
+ candidate = cn;
+ }
+ if(candidate)
+ gtk_adjustment_clamp_page(vadjust, candidate->ymin, candidate->ymax);
+}
+