GUAC-803: Actually scroll when the scrollbar handle is dragged.

This commit is contained in:
Michael Jumper 2015-02-04 00:41:45 -08:00
parent 0a7f13ab5c
commit fc476fd99e
4 changed files with 59 additions and 10 deletions

View File

@ -213,14 +213,8 @@ void guac_terminal_scrollbar_flush(guac_terminal_scrollbar* scrollbar) {
calculate_state(scrollbar, &new_state, &new_value);
/* Notify of scroll if value is changing */
if (new_value != old_value) {
/* TODO: Call scroll value handler */
guac_client_log(scrollbar->client, GUAC_LOG_DEBUG,
"SCROLL: min=%i max=%i value=%i",
scrollbar->min, scrollbar->max, new_value);
}
if (new_value != old_value && scrollbar->scroll_handler)
scrollbar->scroll_handler(scrollbar, new_value);
/* Reposition container if moved */
if (old_state->container_x != new_state.container_x

View File

@ -96,12 +96,21 @@ typedef struct guac_terminal_scrollbar_render_state {
} guac_terminal_scrollbar_render_state;
typedef struct guac_terminal_scrollbar guac_terminal_scrollbar;
/**
* Handler which is called whenever the scrollbar value changes outside a call
* to guac_terminal_scrollbar_set_value().
*/
typedef void guac_terminal_scrollbar_scroll_handler(
guac_terminal_scrollbar* scrollbar, int value);
/**
* A scrollbar, made up of a containing layer and inner draggable handle. The
* position of the handle within the layer represents the value of the
* scrollbar.
*/
typedef struct guac_terminal_scrollbar {
struct guac_terminal_scrollbar {
/**
* The client associated with this scrollbar.
@ -177,7 +186,18 @@ typedef struct guac_terminal_scrollbar {
*/
int drag_current_y;
} guac_terminal_scrollbar;
/**
* The function to call when the scrollbar handle is being dragged, and
* the new scrollbar value needs to be handled and assigned.
*/
guac_terminal_scrollbar_scroll_handler* scroll_handler;
/**
* Arbitrary reference to data related to this scrollbar.
*/
void* data;
};
/**
* Allocates a new scrollbar, associating that scrollbar with the given client

View File

@ -264,6 +264,10 @@ guac_terminal* guac_terminal_create(guac_client* client,
term->scrollbar = guac_terminal_scrollbar_alloc(term->client,
GUAC_DEFAULT_LAYER, width, height, term->term_height);
/* Associate scrollbar with this terminal */
term->scrollbar->data = term;
term->scrollbar->scroll_handler = guac_terminal_scroll_handler;
/* Init terminal */
guac_terminal_reset(term);
@ -1472,6 +1476,24 @@ int guac_terminal_send_mouse(guac_terminal* term, int x, int y, int mask) {
}
void guac_terminal_scroll_handler(guac_terminal_scrollbar* scrollbar, int value) {
guac_terminal* terminal = (guac_terminal*) scrollbar->data;
/* Calculate change in scroll offset */
int delta = -value - terminal->scroll_offset;
/* Update terminal based on change in scroll offset */
if (delta < 0)
guac_terminal_scroll_display_down(terminal, -delta);
else if (delta > 0)
guac_terminal_scroll_display_up(terminal, delta);
/* Update scrollbar value */
guac_terminal_scrollbar_set_value(scrollbar, value);
}
void guac_terminal_clipboard_reset(guac_terminal* term, const char* mimetype) {
guac_common_clipboard_reset(term->clipboard, mimetype);
}

View File

@ -388,6 +388,19 @@ int guac_terminal_send_key(guac_terminal* term, int keysym, int pressed);
*/
int guac_terminal_send_mouse(guac_terminal* term, int x, int y, int mask);
/**
* Handles a scroll event received from the scrollbar associated with a
* terminal.
*
* @param scrollbar
* The scrollbar that has been scrolled.
*
* @param value
* The new value that should be stored within the scrollbar, and
* represented within the terminal display.
*/
void guac_terminal_scroll_handler(guac_terminal_scrollbar* scrollbar, int value);
/**
* Clears the current clipboard contents and sets the mimetype for future
* contents.