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