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