Scrollbar stuff to sb.c.

This commit is contained in:
William McBrine
2019-08-27 16:20:22 -04:00
parent b0a3a33de2
commit c0fd64beb7
3 changed files with 125 additions and 124 deletions

View File

@@ -100,6 +100,10 @@ void XCursesExit(void);
void XC_display_text(const chtype *, int, int, int);
void XC_resize(void);
void XC_refresh_scrollbar(void);
void XC_scroll_up_down(Widget, XtPointer, XtPointer);
void XC_scroll_left_right(Widget, XtPointer, XtPointer);
void XC_thumb_up_down(Widget, XtPointer, XtPointer);
void XC_thumb_left_right(Widget, XtPointer, XtPointer);
void XC_set_blink(bool);
XColor XC_get_color(short);
void XC_set_color(short, XColor);

116
x11/sb.c
View File

@@ -37,6 +37,122 @@ sb
bool sb_started = FALSE;
#if NeedWidePrototypes
# define PDC_SCROLLBAR_TYPE double
#else
# define PDC_SCROLLBAR_TYPE float
#endif
void XC_refresh_scrollbar(void)
{
PDC_LOG(("XC_refresh_scrollbar() - called\n"));
if (SP->sb_on)
{
PDC_SCROLLBAR_TYPE total_y = SP->sb_total_y;
PDC_SCROLLBAR_TYPE total_x = SP->sb_total_x;
if (total_y)
XawScrollbarSetThumb(scrollVert,
(PDC_SCROLLBAR_TYPE)(SP->sb_cur_y) / total_y,
(PDC_SCROLLBAR_TYPE)(SP->sb_viewport_y) / total_y);
if (total_x)
XawScrollbarSetThumb(scrollHoriz,
(PDC_SCROLLBAR_TYPE)(SP->sb_cur_x) / total_x,
(PDC_SCROLLBAR_TYPE)(SP->sb_viewport_x) / total_x);
}
}
void XC_scroll_up_down(Widget w, XtPointer client_data, XtPointer call_data)
{
int pixels = (long) call_data;
int total_y = SP->sb_total_y * font_height;
int viewport_y = SP->sb_viewport_y * font_height;
int cur_y = SP->sb_cur_y * font_height;
/* When pixels is negative, right button pressed, move data down,
thumb moves up. Otherwise, left button pressed, pixels positive,
move data up, thumb down. */
cur_y += pixels;
/* limit panning to size of overall */
if (cur_y < 0)
cur_y = 0;
else
if (cur_y > (total_y - viewport_y))
cur_y = total_y - viewport_y;
SP->sb_cur_y = cur_y / font_height;
XawScrollbarSetThumb(w, (double)((double)cur_y / (double)total_y),
(double)((double)viewport_y / (double)total_y));
}
void XC_scroll_left_right(Widget w, XtPointer client_data, XtPointer call_data)
{
int pixels = (long) call_data;
int total_x = SP->sb_total_x * font_width;
int viewport_x = SP->sb_viewport_x * font_width;
int cur_x = SP->sb_cur_x * font_width;
cur_x += pixels;
/* limit panning to size of overall */
if (cur_x < 0)
cur_x = 0;
else
if (cur_x > (total_x - viewport_x))
cur_x = total_x - viewport_x;
SP->sb_cur_x = cur_x / font_width;
XawScrollbarSetThumb(w, (double)((double)cur_x / (double)total_x),
(double)((double)viewport_x / (double)total_x));
}
void XC_thumb_up_down(Widget w, XtPointer client_data, XtPointer call_data)
{
double percent = *(double *) call_data;
double total_y = (double)SP->sb_total_y;
double viewport_y = (double)SP->sb_viewport_y;
int cur_y = SP->sb_cur_y;
/* If the size of the viewport is > overall area simply return,
as no scrolling is permitted. */
if (SP->sb_viewport_y >= SP->sb_total_y)
return;
if ((SP->sb_cur_y = (int)((double)total_y * percent)) >=
(total_y - viewport_y))
SP->sb_cur_y = total_y - viewport_y;
XawScrollbarSetThumb(w, (double)(cur_y / total_y),
(double)(viewport_y / total_y));
}
void XC_thumb_left_right(Widget w, XtPointer client_data, XtPointer call_data)
{
double percent = *(double *) call_data;
double total_x = (double)SP->sb_total_x;
double viewport_x = (double)SP->sb_viewport_x;
int cur_x = SP->sb_cur_x;
if (SP->sb_viewport_x >= SP->sb_total_x)
return;
if ((SP->sb_cur_x = (int)((float)total_x * percent)) >=
(total_x - viewport_x))
SP->sb_cur_x = total_x - viewport_x;
XawScrollbarSetThumb(w, (double)(cur_x / total_x),
(double)(viewport_x / total_x));
}
/* sb_init() is the sb initialization routine.
This must be called before initscr(). */

129
x11/x11.c
View File

@@ -19,12 +19,6 @@ typedef char * XPointer;
XCursesAppData xc_app_data;
#if NeedWidePrototypes
# define PDC_SCROLLBAR_TYPE double
#else
# define PDC_SCROLLBAR_TYPE float
#endif
#define COLOR_CURSOR PDC_MAXCOL /* color of cursor */
#define COLOR_BORDER PDC_MAXCOL + 1 /* color of border */
@@ -452,27 +446,6 @@ static void _initialize_colors(void)
colors[COLOR_BORDER] = xc_app_data.borderColor;
}
void XC_refresh_scrollbar(void)
{
PDC_LOG(("XC_refresh_scrollbar() - called\n"));
if (SP->sb_on)
{
PDC_SCROLLBAR_TYPE total_y = SP->sb_total_y;
PDC_SCROLLBAR_TYPE total_x = SP->sb_total_x;
if (total_y)
XawScrollbarSetThumb(scrollVert,
(PDC_SCROLLBAR_TYPE)(SP->sb_cur_y) / total_y,
(PDC_SCROLLBAR_TYPE)(SP->sb_viewport_y) / total_y);
if (total_x)
XawScrollbarSetThumb(scrollHoriz,
(PDC_SCROLLBAR_TYPE)(SP->sb_cur_x) / total_x,
(PDC_SCROLLBAR_TYPE)(SP->sb_viewport_x) / total_x);
}
}
static void _set_cursor_color(chtype *ch, short *fore, short *back)
{
int attr;
@@ -798,99 +771,6 @@ static void XCursesButton(Widget w, XEvent *event, String *params,
{
}
static void _scroll_up_down(Widget w, XtPointer client_data,
XtPointer call_data)
{
int pixels = (long) call_data;
int total_y = SP->sb_total_y * font_height;
int viewport_y = SP->sb_viewport_y * font_height;
int cur_y = SP->sb_cur_y * font_height;
/* When pixels is negative, right button pressed, move data down,
thumb moves up. Otherwise, left button pressed, pixels positive,
move data up, thumb down. */
cur_y += pixels;
/* limit panning to size of overall */
if (cur_y < 0)
cur_y = 0;
else
if (cur_y > (total_y - viewport_y))
cur_y = total_y - viewport_y;
SP->sb_cur_y = cur_y / font_height;
XawScrollbarSetThumb(w, (double)((double)cur_y / (double)total_y),
(double)((double)viewport_y / (double)total_y));
}
static void _scroll_left_right(Widget w, XtPointer client_data,
XtPointer call_data)
{
int pixels = (long) call_data;
int total_x = SP->sb_total_x * font_width;
int viewport_x = SP->sb_viewport_x * font_width;
int cur_x = SP->sb_cur_x * font_width;
cur_x += pixels;
/* limit panning to size of overall */
if (cur_x < 0)
cur_x = 0;
else
if (cur_x > (total_x - viewport_x))
cur_x = total_x - viewport_x;
SP->sb_cur_x = cur_x / font_width;
XawScrollbarSetThumb(w, (double)((double)cur_x / (double)total_x),
(double)((double)viewport_x / (double)total_x));
}
static void _thumb_up_down(Widget w, XtPointer client_data,
XtPointer call_data)
{
double percent = *(double *) call_data;
double total_y = (double)SP->sb_total_y;
double viewport_y = (double)SP->sb_viewport_y;
int cur_y = SP->sb_cur_y;
/* If the size of the viewport is > overall area simply return,
as no scrolling is permitted. */
if (SP->sb_viewport_y >= SP->sb_total_y)
return;
if ((SP->sb_cur_y = (int)((double)total_y * percent)) >=
(total_y - viewport_y))
SP->sb_cur_y = total_y - viewport_y;
XawScrollbarSetThumb(w, (double)(cur_y / total_y),
(double)(viewport_y / total_y));
}
static void _thumb_left_right(Widget w, XtPointer client_data,
XtPointer call_data)
{
double percent = *(double *) call_data;
double total_x = (double)SP->sb_total_x;
double viewport_x = (double)SP->sb_viewport_x;
int cur_x = SP->sb_cur_x;
if (SP->sb_viewport_x >= SP->sb_total_x)
return;
if ((SP->sb_cur_x = (int)((float)total_x * percent)) >=
(total_x - viewport_x))
SP->sb_cur_x = total_x - viewport_x;
XawScrollbarSetThumb(w, (double)(cur_x / total_x),
(double)(viewport_x / total_x));
}
void XCursesExit(void)
{
if (icon_pixmap)
@@ -1149,16 +1029,17 @@ int XCursesSetupX(int argc, char *argv[])
XtorientVertical, XtNheight, window_height, XtNwidth,
xc_app_data.scrollbarWidth, NULL);
XtAddCallback(scrollVert, XtNscrollProc, _scroll_up_down, drawing);
XtAddCallback(scrollVert, XtNjumpProc, _thumb_up_down, drawing);
XtAddCallback(scrollVert, XtNscrollProc, XC_scroll_up_down, drawing);
XtAddCallback(scrollVert, XtNjumpProc, XC_thumb_up_down, drawing);
scrollHoriz = XtVaCreateManagedWidget("scrollHoriz",
scrollbarWidgetClass, scrollBox, XtNorientation,
XtorientHorizontal, XtNwidth, window_width, XtNheight,
xc_app_data.scrollbarWidth, NULL);
XtAddCallback(scrollHoriz, XtNscrollProc, _scroll_left_right, drawing);
XtAddCallback(scrollHoriz, XtNjumpProc, _thumb_left_right, drawing);
XtAddCallback(scrollHoriz, XtNscrollProc, XC_scroll_left_right,
drawing);
XtAddCallback(scrollHoriz, XtNjumpProc, XC_thumb_left_right, drawing);
}
else
{