~ubuntu-branches/ubuntu/hardy/nast/hardy

« back to all changes in this revision

Viewing changes to ncurses/n_scroll_win.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2004-02-17 22:14:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040217221421-f1h39tzviblbp2lh
Tags: upstream-0.2.0
ImportĀ upstreamĀ versionĀ 0.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    nast
 
3
 
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 
 
18
*/
 
19
 
 
20
#include "n_nast.h"
 
21
 
 
22
#ifdef HAVE_LIBNCURSES
 
23
 
 
24
N_SCROLLWIN *newscrollwin(int lines, int cols, int y, int x, char *title, int maxlines)
 
25
{
 
26
   N_SCROLLWIN *win;
 
27
 
 
28
   win = calloc(1, sizeof(N_SCROLLWIN));
 
29
 
 
30
   win->win = newpad(maxlines, cols - 2);
 
31
   win->out = newwin(lines, cols, y, x);
 
32
   win->y_max = maxlines;
 
33
   win->lines = lines;
 
34
   win->cols = cols;
 
35
   win->x = x;
 
36
   win->y = y;
 
37
   win->title = strdup(title);
 
38
 
 
39
   scrollok(win->win, TRUE);
 
40
 
 
41
   /* move the cursor to the right starting point */
 
42
 
 
43
   win->y_scroll = maxlines - (lines-2);
 
44
   wmove(win->win, win->y_scroll - 1, 0);
 
45
 
 
46
   /* draw the outer window */
 
47
 
 
48
   wattrset(win->out, COLOR_PAIR(3));
 
49
 
 
50
   wborder(win->out, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,
 
51
           ACS_ULCORNER, ACS_URCORNER,
 
52
           ACS_LLCORNER, ACS_LRCORNER);
 
53
 
 
54
   wmove(win->out, 0, 2);
 
55
   wattrset(win->out, COLOR_PAIR(2));
 
56
   waddstr(win->out, " ");
 
57
   waddstr(win->out, title);
 
58
   waddstr(win->out, " ");
 
59
   wattrset(win->out, COLOR_PAIR(3));
 
60
 
 
61
   drawscroller(win);
 
62
 
 
63
   return win;
 
64
}
 
65
 
 
66
/* redraw the window with or without focus */
 
67
 
 
68
void redrawscrollwin(N_SCROLLWIN *win, int focus)
 
69
{
 
70
 
 
71
   if (focus)
 
72
     wattron(win->out, A_BOLD);
 
73
 
 
74
   werase(win->out);
 
75
   wmove(win->out, 0, 0);
 
76
 
 
77
   wattron(win->out, COLOR_PAIR(3));
 
78
 
 
79
   wborder(win->out, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,
 
80
           ACS_ULCORNER, ACS_URCORNER,
 
81
           ACS_LLCORNER, ACS_LRCORNER);
 
82
 
 
83
   if (focus)
 
84
     {
 
85
        wmove(win->out, 0, 0);
 
86
        wattron(win->out, COLOR_PAIR(4));
 
87
        waddch(win->out, ACS_LARROW);
 
88
        waddch(win->out, ACS_RARROW);
 
89
        wattroff(win->out, COLOR_PAIR(4));
 
90
     }
 
91
 
 
92
   wattron(win->out, COLOR_PAIR(2));
 
93
   wmove(win->out, 0, 2);
 
94
   waddstr(win->out, " ");
 
95
   waddstr(win->out, win->title);
 
96
   waddstr(win->out, " ");
 
97
   wattroff(win->out, COLOR_PAIR(2));
 
98
 
 
99
   redrawwin(win->out);
 
100
 
 
101
   if (focus)
 
102
     wattroff(win->out, A_BOLD);
 
103
 
 
104
   drawscroller(win);
 
105
 
 
106
   SAFE_SCROLL_REFRESH(win);
 
107
}
 
108
 
 
109
/* display the scroll indicator on the right */
 
110
 
 
111
void drawscroller(N_SCROLLWIN *win)
 
112
{
 
113
   short height = (win->lines-2) * (win->lines-2) / win->y_max;
 
114
   short vpos = win->lines * win->y_scroll / win->y_max;
 
115
 
 
116
   wattron(win->out, COLOR_PAIR(2));
 
117
   wattroff(win->out, A_BOLD);
 
118
 
 
119
   height = (height < 1) ? 1 : height;
 
120
 
 
121
   vpos = (vpos == 0) ? 1 : vpos;
 
122
   vpos = (vpos > (win->lines-1) - height) ? (win->lines-1) - height : vpos;
 
123
 
 
124
   wmove(win->out, 1, win->x + win->cols - 1);
 
125
   wvline(win->out, ACS_CKBOARD, win->lines - 2);
 
126
   wattron(win->out, A_REVERSE);
 
127
   wmove(win->out, vpos, win->x + win->cols - 1);
 
128
   wvline(win->out, ' ', height);
 
129
   wattroff(win->out, A_REVERSE);
 
130
 
 
131
   wnoutrefresh(win->out);
 
132
}
 
133
 
 
134
/* scroll a window for delta lines */
 
135
 
 
136
void winscroll(N_SCROLLWIN *win, int delta)
 
137
{
 
138
   win->y_scroll += delta;
 
139
   win->y_scroll = (win->y_scroll < 0) ? 0 : win->y_scroll;
 
140
   win->y_scroll = (win->y_scroll > win->y_max - (win->lines-2) )
 
141
     ? win->y_max - (win->lines-2)
 
142
       : win->y_scroll;
 
143
 
 
144
   drawscroller(win);
 
145
 
 
146
   SAFE_SCROLL_REFRESH(win);
 
147
}
 
148
 
 
149
void delscrollwin(N_SCROLLWIN **win)
 
150
{
 
151
 
 
152
   werase((*win)->win);
 
153
   SAFE_WREFRESH((*win)->win);
 
154
   werase((*win)->out);
 
155
   SAFE_WREFRESH((*win)->out);
 
156
   delwin((*win)->win);
 
157
   delwin((*win)->out);
 
158
   SAFE_FREE((*win)->title);
 
159
   SAFE_FREE(*win);
 
160
}
 
161
 
 
162
#endif
 
163