~ubuntu-branches/ubuntu/dapper/newt/dapper

« back to all changes in this revision

Viewing changes to scrollbar.c

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2004-11-27 09:49:00 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041127094900-mf7cbmb00g7t8xow
Tags: 0.51.6-20
Upgrade bug; lbnewt0.51 was supplying /usr/lib/libnewt.so in conflict
with libnewt-dev. Closes: #283185.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <slang.h>
2
 
#include <stdlib.h>
3
 
#include <string.h>
4
 
 
5
 
#include "newt.h"
6
 
#include "newt_pr.h"
7
 
 
8
 
struct scrollbar {
9
 
    int curr;
10
 
    int cs, csThumb;
11
 
    int arrows;
12
 
} ;
13
 
 
14
 
static void sbDraw(newtComponent co);
15
 
static void sbDestroy(newtComponent co);
16
 
static void sbDrawThumb(newtComponent co, int isOn);
17
 
 
18
 
static struct componentOps sbOps = {
19
 
    sbDraw,
20
 
    newtDefaultEventHandler,
21
 
    sbDestroy,
22
 
    newtDefaultPlaceHandler,
23
 
    newtDefaultMappedHandler,
24
 
} ;
25
 
 
26
 
void newtScrollbarSet(newtComponent co, int where, int total) {
27
 
    struct scrollbar * sb = co->data;
28
 
    int new;
29
 
 
30
 
    if (sb->arrows)
31
 
        new = (where * (co->height - 3)) / (total ? total : 1) + 1;
32
 
    else
33
 
        new = (where * (co->height - 1)) / (total ? total : 1);
34
 
    if (new != sb->curr) {
35
 
        sbDrawThumb(co, 0);
36
 
        sb->curr = new;
37
 
        sbDrawThumb(co, 1);
38
 
    }
39
 
}
40
 
 
41
 
newtComponent newtVerticalScrollbar(int left, int top, int height,
42
 
                                    int normalColorset, int thumbColorset) {
43
 
    newtComponent co;
44
 
    struct scrollbar * sb;
45
 
 
46
 
    co = malloc(sizeof(*co));
47
 
    sb = malloc(sizeof(*sb));
48
 
    co->data = sb;
49
 
 
50
 
    if (!strcmp(getenv("TERM"), "linux") && height >= 2) {
51
 
        sb->arrows = 1;
52
 
        sb->curr = 1;
53
 
    } else {
54
 
        sb->arrows = 0;
55
 
        sb->curr = 0;
56
 
    }
57
 
    sb->cs = normalColorset;
58
 
    sb->csThumb = thumbColorset;
59
 
 
60
 
    co->ops = &sbOps;
61
 
    co->isMapped = 0;
62
 
    co->left = left;
63
 
    co->top = top;
64
 
    co->height = height;
65
 
    co->width = 1;
66
 
    co->takesFocus = 0;  
67
 
    
68
 
    return co;
69
 
}
70
 
 
71
 
static void sbDraw(newtComponent co) {
72
 
    struct scrollbar * sb = co->data;
73
 
    int i;
74
 
 
75
 
    if (!co->isMapped) return;
76
 
 
77
 
    newtColor(sb->cs);
78
 
 
79
 
    SLsmg_set_char_set(1);
80
 
    if (sb->arrows) {
81
 
        newtGotorc(co->top, co->left);
82
 
        SLsmg_write_char('\x2d');
83
 
        for (i = 1; i < co->height - 1; i++) {
84
 
            newtGotorc(i + co->top, co->left);
85
 
            SLsmg_write_char('\x61');
86
 
        }
87
 
        newtGotorc(co->top + co->height - 1, co->left);
88
 
        SLsmg_write_char('\x2e');
89
 
    } else {
90
 
        for (i = 0; i < co->height; i++) {
91
 
            newtGotorc(i + co->top, co->left);
92
 
            SLsmg_write_char('\x61');
93
 
        }
94
 
    }
95
 
 
96
 
    SLsmg_set_char_set(0);
97
 
 
98
 
    sbDrawThumb(co, 1);
99
 
}
100
 
 
101
 
static void sbDrawThumb(newtComponent co, int isOn) {
102
 
    struct scrollbar * sb = co->data;
103
 
    char ch = isOn ? '#' : '\x61';
104
 
 
105
 
    if (!co->isMapped) return;
106
 
 
107
 
    newtGotorc(sb->curr + co->top, co->left);
108
 
    SLsmg_set_char_set(1);
109
 
 
110
 
    /*if (isOn)
111
 
        newtColor(sb->csThumb);
112
 
    else*/
113
 
        newtColor(sb->cs);
114
 
 
115
 
    SLsmg_write_char(ch);
116
 
    SLsmg_set_char_set(0);
117
 
}
118
 
 
119
 
static void sbDestroy(newtComponent co) {
120
 
    struct scrollbar * sb = co->data;
121
 
 
122
 
    free(sb);
123
 
    free(co);
124
 
}