1 /* Public Domain Curses */
2
3 #include "pdcx11.h"
4
5 RCSID("$Id: sb.c,v 1.27 2008/07/14 04:24:52 wmcbrine Exp $")
6
7 /*man-start**************************************************************
8
9 Name: sb
10
11 Synopsis:
12 int sb_init(void)
13 int sb_set_horz(int total, int viewport, int cur)
14 int sb_set_vert(int total, int viewport, int cur)
15 int sb_get_horz(int *total, int *viewport, int *cur)
16 int sb_get_vert(int *total, int *viewport, int *cur)
17 int sb_refresh(void);
18
19 Description:
20 These functions manipulate the scrollbar.
21
22 Return Value:
23 All functions return OK on success and ERR on error.
24
25 Portability X/Open BSD SYS V
26 sb_init - - -
27 sb_set_horz - - -
28 sb_set_vert - - -
29 sb_get_horz - - -
30 sb_get_vert - - -
31 sb_refresh - - -
32
33 **man-end****************************************************************/
34
35 bool sb_started = FALSE;
36
37 /* sb_init() is the sb initialization routine.
38 This must be called before initscr(). */
39
sb_init(void)40 int sb_init(void)
41 {
42 PDC_LOG(("sb_init() - called\n"));
43
44 if (SP)
45 return ERR;
46
47 sb_started = TRUE;
48
49 return OK;
50 }
51
52 /* sb_set_horz() - Used to set horizontal scrollbar.
53
54 total = total number of columns
55 viewport = size of viewport in columns
56 cur = current column in total */
57
sb_set_horz(int total,int viewport,int cur)58 int sb_set_horz(int total, int viewport, int cur)
59 {
60 PDC_LOG(("sb_set_horz() - called: total %d viewport %d cur %d\n",
61 total, viewport, cur));
62
63 if (!SP)
64 return ERR;
65
66 SP->sb_total_x = total;
67 SP->sb_viewport_x = viewport;
68 SP->sb_cur_x = cur;
69
70 return OK;
71 }
72
73 /* sb_set_vert() - Used to set vertical scrollbar.
74
75 total = total number of columns on line
76 viewport = size of viewport in columns
77 cur = current column in total */
78
sb_set_vert(int total,int viewport,int cur)79 int sb_set_vert(int total, int viewport, int cur)
80 {
81 PDC_LOG(("sb_set_vert() - called: total %d viewport %d cur %d\n",
82 total, viewport, cur));
83
84 if (!SP)
85 return ERR;
86
87 SP->sb_total_y = total;
88 SP->sb_viewport_y = viewport;
89 SP->sb_cur_y = cur;
90
91 return OK;
92 }
93
94 /* sb_get_horz() - Used to get horizontal scrollbar.
95
96 total = total number of lines
97 viewport = size of viewport in lines
98 cur = current line in total */
99
sb_get_horz(int * total,int * viewport,int * cur)100 int sb_get_horz(int *total, int *viewport, int *cur)
101 {
102 PDC_LOG(("sb_get_horz() - called\n"));
103
104 if (!SP)
105 return ERR;
106
107 if (total)
108 *total = SP->sb_total_x;
109 if (viewport)
110 *viewport = SP->sb_viewport_x;
111 if (cur)
112 *cur = SP->sb_cur_x;
113
114 return OK;
115 }
116
117 /* sb_get_vert() - Used to get vertical scrollbar.
118
119 total = total number of lines
120 viewport = size of viewport in lines
121 cur = current line in total */
122
sb_get_vert(int * total,int * viewport,int * cur)123 int sb_get_vert(int *total, int *viewport, int *cur)
124 {
125 PDC_LOG(("sb_get_vert() - called\n"));
126
127 if (!SP)
128 return ERR;
129
130 if (total)
131 *total = SP->sb_total_y;
132 if (viewport)
133 *viewport = SP->sb_viewport_y;
134 if (cur)
135 *cur = SP->sb_cur_y;
136
137 return OK;
138 }
139
140 /* sb_refresh() - Used to draw the scrollbars. */
141
sb_refresh(void)142 int sb_refresh(void)
143 {
144 PDC_LOG(("sb_refresh() - called\n"));
145
146 if (!SP)
147 return ERR;
148
149 XCursesInstruct(CURSES_REFRESH_SCROLLBAR);
150
151 return OK;
152 }
153