Mercurial > hg > xemacs-beta
comparison lwlib/xlwscrollbar.c @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | f220cc83d72e |
children | afd57c14dfc8 |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
2 Copyright (C) 1992, 1993, 1994 Lucid, Inc. | 2 Copyright (C) 1992, 1993, 1994 Lucid, Inc. |
3 Copyright (C) 1997 Sun Microsystems, Inc. | 3 Copyright (C) 1997 Sun Microsystems, Inc. |
4 | 4 |
5 This file is part of the Lucid Widget Library. | 5 This file is part of the Lucid Widget Library. |
6 | 6 |
7 The Lucid Widget Library is free software; you can redistribute it and/or | 7 The Lucid Widget Library is free software; you can redistribute it and/or |
8 modify it under the terms of the GNU General Public License as published by | 8 modify it under the terms of the GNU General Public License as published by |
9 the Free Software Foundation; either version 2, or (at your option) | 9 the Free Software Foundation; either version 2, or (at your option) |
10 any later version. | 10 any later version. |
11 | 11 |
12 The Lucid Widget Library is distributed in the hope that it will be useful, | 12 The Lucid Widget Library is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 17 You should have received a copy of the GNU General Public License |
18 along with XEmacs; see the file COPYING. If not, write to | 18 along with XEmacs; see the file COPYING. If not, write to |
611 | 611 |
612 if (w->sb.bottomShadowColor == fg || w->sb.bottomShadowColor == bg) | 612 if (w->sb.bottomShadowColor == fg || w->sb.bottomShadowColor == bg) |
613 { | 613 { |
614 botc.pixel = bg; | 614 botc.pixel = bg; |
615 XQueryColor (dpy, cmap, &botc); | 615 XQueryColor (dpy, cmap, &botc); |
616 botc.red *= 0.6; | 616 botc.red = (botc.red * 3) / 5; |
617 botc.green *= 0.6; | 617 botc.green = (botc.green * 3) / 5; |
618 botc.blue *= 0.6; | 618 botc.blue = (botc.blue * 3) / 5; |
619 if (allocate_nearest_color (dpy, cmap, &botc)) | 619 if (allocate_nearest_color (dpy, cmap, &botc)) |
620 { | 620 { |
621 if (botc.pixel == bg) | 621 if (botc.pixel == bg) |
622 { | 622 { |
623 XFreeColors (dpy, cmap, &botc.pixel, 1, 0); | 623 XFreeColors (dpy, cmap, &botc.pixel, 1, 0); |
696 | 696 |
697 if (w->sb.troughColor == w->core.background_pixel) | 697 if (w->sb.troughColor == w->core.background_pixel) |
698 { | 698 { |
699 troughC.pixel = w->core.background_pixel; | 699 troughC.pixel = w->core.background_pixel; |
700 XQueryColor (dpy, cmap, &troughC); | 700 XQueryColor (dpy, cmap, &troughC); |
701 troughC.red *= 0.8; | 701 troughC.red = (troughC.red * 4) / 5; |
702 troughC.green *= 0.8; | 702 troughC.green = (troughC.green * 4) / 5; |
703 troughC.blue *= 0.8; | 703 troughC.blue = (troughC.blue * 4) / 5; |
704 if (allocate_nearest_color (dpy, cmap, &troughC)) | 704 if (allocate_nearest_color (dpy, cmap, &troughC)) |
705 w->sb.troughColor = troughC.pixel; | 705 w->sb.troughColor = troughC.pixel; |
706 } | 706 } |
707 } | 707 } |
708 | 708 |
942 static void | 942 static void |
943 seg_pixel_sizes (XlwScrollBarWidget w, int *above_return, | 943 seg_pixel_sizes (XlwScrollBarWidget w, int *above_return, |
944 int *ss_return, int *below_return) | 944 int *ss_return, int *below_return) |
945 { | 945 { |
946 float total, height, fuz; | 946 float total, height, fuz; |
947 int value; | 947 int value, above, ss, below; |
948 int above, ss, below; | 948 |
949 | 949 height = widget_h (w); |
950 height= widget_h (w); | |
951 if (w->sb.showArrows) height -= (2 * arrow_h (w)); | 950 if (w->sb.showArrows) height -= (2 * arrow_h (w)); |
952 | 951 |
953 value = w->sb.value - w->sb.minimum; | 952 value = w->sb.value - w->sb.minimum; |
954 | 953 |
955 total = w->sb.maximum - w->sb.minimum; | 954 total = w->sb.maximum - w->sb.minimum; |
956 fuz = total / 2; | 955 fuz = total / 2; |
957 | 956 |
958 ss = ((height * w->sb.sliderSize + fuz) / total); | 957 ss = (int) ((height * w->sb.sliderSize + fuz) / total); |
959 above = ((height * value + fuz) / total); | 958 above = (int) ((height * value + fuz) / total); |
960 below = ((height) - (ss + above)); | 959 below = (int) ((height) - (ss + above)); |
961 | 960 |
962 /* Don't let slider get smaller than SS_MIN */ | 961 /* Don't let slider get smaller than SS_MIN */ |
963 if (ss < SS_MIN) | 962 if (ss < SS_MIN) |
964 { | 963 { |
965 /* add a percent amount for integer rounding */ | 964 /* add a percent amount for integer rounding */ |
966 float tmp = ((((float) (SS_MIN - ss) * (float) value)) / total) + 0.5; | 965 float tmp = ((((float) (SS_MIN - ss) * (float) value)) / total) + 0.5; |
967 | 966 |
968 above -= (int) tmp; | 967 above -= (int) tmp; |
969 ss = SS_MIN; | 968 ss = SS_MIN; |
970 below = ((height) - (ss + above)); | 969 below = (int) ((height) - (ss + above)); |
971 | 970 |
972 if (above < 0) | 971 if (above < 0) |
973 { | 972 { |
974 above = 0; | 973 above = 0; |
975 below = height - ss; | 974 below = (int) (height - ss); |
976 } | 975 } |
977 if (below < 0) | 976 if (below < 0) |
978 { | 977 { |
979 above = height - ss; | 978 above = (int) (height - ss); |
980 below = 0; | 979 below = 0; |
981 } | 980 } |
982 if (ss > height) | 981 if (ss > height) |
983 { | 982 { |
984 above = 0; | 983 above = 0; |
985 ss = height; | 984 ss = (int) height; |
986 below = 0; | 985 below = 0; |
987 } | 986 } |
988 } | 987 } |
989 | 988 |
990 *above_return = above; | 989 *above_return = above; |
1029 height -= (2 * arrow_h (w)); | 1028 height -= (2 * arrow_h (w)); |
1030 | 1029 |
1031 total = w->sb.maximum - w->sb.minimum; | 1030 total = w->sb.maximum - w->sb.minimum; |
1032 fuz = height / 2; | 1031 fuz = height / 2; |
1033 | 1032 |
1034 ss = ((height * w->sb.sliderSize + (total / 2)) / total); | 1033 ss = (int) ((height * w->sb.sliderSize + (total / 2)) / total); |
1035 | 1034 |
1036 if (ss < SS_MIN) | 1035 if (ss < SS_MIN) |
1037 { | 1036 { |
1038 /* add a percent amount for integer rounding */ | 1037 /* add a percent amount for integer rounding */ |
1039 above += ((((SS_MIN - ss) * above) + fuz) / height); | 1038 above += (int) ((((SS_MIN - ss) * above) + fuz) / height); |
1040 } | 1039 } |
1041 | 1040 |
1042 { | 1041 { |
1043 /* Prevent SIGFPE's that would occur if we don't truncate the value. */ | 1042 /* Prevent SIGFPE's that would occur if we don't truncate the value. */ |
1044 float floatval = w->sb.minimum + ((float)(above * total + fuz) / height); | 1043 float floatval = w->sb.minimum + ((float)(above * total + fuz) / height); |
1045 if (floatval >= (float) INT_MAX) | 1044 if (floatval >= (float) INT_MAX) |
1046 value = INT_MAX; | 1045 value = INT_MAX; |
1047 else if (floatval <= (float) INT_MIN) | 1046 else if (floatval <= (float) INT_MIN) |
1048 value = INT_MIN; | 1047 value = INT_MIN; |
1049 else | 1048 else |
1050 value = floatval; | 1049 value = (int) floatval; |
1051 } | 1050 } |
1052 | 1051 |
1053 return value; | 1052 return value; |
1054 } | 1053 } |
1055 | 1054 |