OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [generic/] [tixScroll.c] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixScroll.c -- Handle all the mess of Tk scroll bars
3
 *
4
 *
5
 *
6
 */
7
 
8
#include <tixInt.h>
9
 
10
 
11
void Tix_InitScrollInfo(siPtr, type)
12
    Tix_ScrollInfo * siPtr;
13
    int type;
14
{
15
    Tix_IntScrollInfo*    isiPtr = (Tix_IntScrollInfo*)   siPtr;
16
    Tix_DoubleScrollInfo* dsiPtr = (Tix_DoubleScrollInfo*)siPtr;
17
 
18
    siPtr->command      = NULL;
19
    siPtr->type         = type;
20
 
21
    if (type == TIX_SCROLL_INT) {
22
        isiPtr->total   = 1;
23
        isiPtr->window  = 1;
24
        isiPtr->offset  = 0;
25
        isiPtr->unit    = 1;
26
    }
27
    else {
28
        dsiPtr->total   = 1.0;
29
        dsiPtr->window  = 1.0;
30
        dsiPtr->offset  = 0.0;
31
        dsiPtr->unit    = 1.0;
32
    }
33
}
34
 
35
/*----------------------------------------------------------------------
36
 * Tix_GetScrollFractions --
37
 *
38
 * Compute the fractions of a scroll-able widget.
39
 *
40
 */
41
void Tix_GetScrollFractions(siPtr, first_ret, last_ret)
42
    Tix_ScrollInfo * siPtr;
43
    double * first_ret;
44
    double * last_ret;
45
{
46
    Tix_IntScrollInfo*    isiPtr = (Tix_IntScrollInfo*)   siPtr;
47
    Tix_DoubleScrollInfo* dsiPtr = (Tix_DoubleScrollInfo*)siPtr;
48
    double total, window, first;
49
 
50
    if (siPtr->type == TIX_SCROLL_INT) {
51
        total  = isiPtr->total;
52
        window = isiPtr->window;
53
        first  = isiPtr->offset;
54
    } else {
55
        total  = dsiPtr->total;
56
        window = dsiPtr->window;
57
        first  = dsiPtr->offset;
58
    }
59
 
60
    if (total == 0 || total < window) {
61
        *first_ret = 0.0;
62
        *last_ret  = 1.0;
63
    } else {
64
        *first_ret = first / total;
65
        *last_ret  = (first+window) / total;
66
    }
67
}
68
 
69
void Tix_UpdateScrollBar(interp, siPtr)
70
    Tcl_Interp *interp;
71
    Tix_ScrollInfo * siPtr;
72
{
73
    Tix_IntScrollInfo*    isiPtr = (Tix_IntScrollInfo*)   siPtr;
74
    Tix_DoubleScrollInfo* dsiPtr = (Tix_DoubleScrollInfo*)siPtr;
75
    double d_first, d_last;
76
    char string[100];
77
 
78
    if (siPtr->type == TIX_SCROLL_INT) {
79
        /* Check whether the topPixel is out of bound */
80
        if (isiPtr->offset < 0) {
81
            isiPtr->offset = 0;
82
        } else {
83
            if (isiPtr->window > isiPtr->total) {
84
                isiPtr->offset = 0;
85
            }
86
            else if((isiPtr->offset+isiPtr->window) > isiPtr->total) {
87
                isiPtr->offset = isiPtr->total - isiPtr->window;
88
            }
89
        }
90
    } else {
91
        /* Check whether the topPixel is out of bound */
92
        if (dsiPtr->offset < 0) {
93
            dsiPtr->offset = 0;
94
        } else {
95
            if (dsiPtr->window > dsiPtr->total) {
96
                dsiPtr->offset = 0;
97
            }
98
            else if((dsiPtr->offset+dsiPtr->window) > dsiPtr->total) {
99
                dsiPtr->offset = dsiPtr->total - dsiPtr->window;
100
            }
101
        }
102
    }
103
 
104
 
105
    if (siPtr->command) {
106
        Tix_GetScrollFractions(siPtr, &d_first, &d_last);
107
 
108
        sprintf(string, " %f %f", d_first, d_last);
109
        if (Tcl_VarEval(interp, siPtr->command, string,
110
            (char *) NULL) != TCL_OK) {
111
            Tcl_AddErrorInfo(interp,
112
                "\n    (scrolling command executed by tixTList)");
113
            Tk_BackgroundError(interp);
114
        }
115
    }
116
}
117
 
118
int Tix_SetScrollBarView(interp, siPtr, argc, argv, compat)
119
    Tcl_Interp *interp;         /* Current interpreter. */
120
    Tix_ScrollInfo * siPtr;
121
    int argc;                   /* Number of arguments. */
122
    char **argv;                /* Argument strings. */
123
    int compat;                 /* compatibility mode */
124
{
125
    Tix_IntScrollInfo*    isiPtr = (Tix_IntScrollInfo*)   siPtr;
126
    Tix_DoubleScrollInfo* dsiPtr = (Tix_DoubleScrollInfo*)siPtr;
127
    int offset;
128
 
129
    if (compat && Tcl_GetInt(interp, argv[0], &offset) == TCL_OK) {
130
        /* backward-compatible mode */
131
        if (siPtr->type == TIX_SCROLL_INT) {
132
            isiPtr->offset = offset;
133
        }
134
        else {
135
            dsiPtr->offset = (double)offset;
136
        }
137
 
138
        return TCL_OK;
139
    }
140
    else {
141
        int type, count;
142
        double fraction;
143
 
144
        Tcl_ResetResult(interp);
145
 
146
        /* Tk_GetScrollInfo () wants strange argc,argv combinations .. */
147
        type = Tk_GetScrollInfo(interp, argc+2, argv-2, &fraction, &count);
148
 
149
        if (siPtr->type == TIX_SCROLL_INT) {
150
            switch (type) {
151
              case TK_SCROLL_ERROR:
152
                return TCL_ERROR;
153
 
154
              case TK_SCROLL_MOVETO:
155
                isiPtr->offset =
156
                  (int)(fraction * (double)isiPtr->total);
157
                break;
158
 
159
              case TK_SCROLL_PAGES:
160
                isiPtr->offset += count * isiPtr->window;
161
                break;
162
 
163
              case TK_SCROLL_UNITS:
164
                isiPtr->offset += count * isiPtr->unit;
165
                break;
166
            }
167
        } else {
168
            switch (type) {
169
              case TK_SCROLL_ERROR:
170
                return TCL_ERROR;
171
 
172
              case TK_SCROLL_MOVETO:
173
                dsiPtr->offset =
174
                  fraction * dsiPtr->total;
175
                break;
176
 
177
              case TK_SCROLL_PAGES:
178
                dsiPtr->offset += count * dsiPtr->window;
179
                break;
180
 
181
              case TK_SCROLL_UNITS:
182
                dsiPtr->offset += count * dsiPtr->unit;
183
                break;
184
            }
185
        }
186
    }
187
    return TCL_OK;
188
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.