GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_scrollbar_thumb_position_calculate.c Lines: 57 57 100.0 %
Date: 2026-03-06 19:21:09 Branches: 28 28 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   Scrollbar Management (Scrollbar)                                    */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_display.h"
29
#include "gx_context.h"
30
#include "gx_widget.h"
31
#include "gx_utility.h"
32
#include "gx_scrollbar.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_scrollbar_thumb_position_calculate              PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    Calculate and return the position of a GX_SCROLLBAR thumb button    */
47
/*    based scrollbar dimensions, current value, and visible range.       */
48
/*                                                                        */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    scroll                                Widget control block          */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
61
/*    _gx_widget_resize                     Resize a widget               */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    Application Code                                                    */
66
/*    GUIX Internal Code                                                  */
67
/*                                                                        */
68
/**************************************************************************/
69
7701
VOID _gx_scrollbar_thumb_position_calculate(GX_SCROLLBAR *scroll)
70
{
71
7701
INT  thumb_length = 0;
72
INT  travelsize;
73
INT  range;
74
INT  space;
75
INT  thumb_width;
76
INT  scroll_width;
77
78
GX_RECTANGLE thumbrect;
79
ULONG        style;
80
7701
GX_PIXELMAP *thumb_pixelmap = NULL;
81
82
    /* pick up scrollbar style */
83
7701
    style = scroll -> gx_widget_style;
84
85
    /* pick up the scroll width and thumb button width */
86
87
7701
    thumb_width = scroll -> gx_scrollbar_appearance.gx_scroll_thumb_width;
88
89
    /* see if the thumb has a pixelmap */
90
7701
    if (scroll -> gx_scrollbar_appearance.gx_scroll_thumb_pixelmap)
91
    {
92
171
        _gx_widget_pixelmap_get((GX_WIDGET *) scroll, scroll -> gx_scrollbar_appearance.gx_scroll_thumb_pixelmap, &thumb_pixelmap);
93
    }
94
95
7701
    if (style & GX_SCROLLBAR_VERTICAL)
96
    {
97
5956
        scroll_width = scroll -> gx_widget_size.gx_rectangle_right - scroll -> gx_widget_size.gx_rectangle_left + 1;
98
99
5956
        travelsize = (scroll -> gx_widget_size.gx_rectangle_bottom -
100
5956
                      scroll -> gx_widget_size.gx_rectangle_top) + 1;
101
    }
102
    else
103
    {
104
1745
        scroll_width = scroll -> gx_widget_size.gx_rectangle_bottom - scroll -> gx_widget_size.gx_rectangle_top + 1;
105
106
1745
        travelsize = (scroll -> gx_widget_size.gx_rectangle_right -
107
1745
                      scroll -> gx_widget_size.gx_rectangle_left) + 1;
108
    }
109
110
7701
    travelsize -= scroll -> gx_scrollbar_appearance.gx_scroll_thumb_travel_max +
111
7701
                  scroll -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min;
112
113
7701
    range = scroll -> gx_scrollbar_info.gx_scroll_maximum - scroll -> gx_scrollbar_info.gx_scroll_minimum + 1;
114
115
7701
    if (style & GX_SCROLLBAR_RELATIVE_THUMB)
116
    {
117
7508
        if (scroll -> gx_scrollbar_info.gx_scroll_maximum !=
118
7508
            scroll -> gx_scrollbar_info.gx_scroll_minimum)
119
        {
120
7505
            thumb_length = travelsize * scroll -> gx_scrollbar_info.gx_scroll_visible;
121
7505
            if (range)
122
            {
123
7504
                thumb_length /= range;
124
            }
125
7505
            if (thumb_length < thumb_width)
126
            {
127
640
                thumb_length = thumb_width;
128
            }
129
        }
130
    }
131
    else
132
    {
133
193
        if (thumb_pixelmap)
134
        {
135
170
            if (style & GX_SCROLLBAR_VERTICAL)
136
            {
137
58
                thumb_length = thumb_pixelmap -> gx_pixelmap_height;
138
58
                thumb_width = thumb_pixelmap -> gx_pixelmap_width;
139
            }
140
            else
141
            {
142
112
                thumb_length = thumb_pixelmap -> gx_pixelmap_width;
143
112
                thumb_width = thumb_pixelmap -> gx_pixelmap_height;
144
            }
145
        }
146
        else
147
        {
148
            /* just a square thumb button */
149
23
            thumb_length = thumb_width;
150
        }
151
    }
152
7701
    space = (travelsize - thumb_length);
153
7701
    space *= scroll -> gx_scrollbar_info.gx_scroll_value - scroll -> gx_scrollbar_info.gx_scroll_minimum;
154
7701
    range -= scroll -> gx_scrollbar_info.gx_scroll_visible;
155
156
7701
    if (range)
157
    {
158
7191
        space = (space + (range >> 1)) / range;
159
    }
160
161
162
7701
    if((scroll -> gx_scrollbar_info.gx_scroll_value > scroll -> gx_scrollbar_info.gx_scroll_minimum) &&
163
6239
       (scroll -> gx_scrollbar_info.gx_scroll_value + scroll -> gx_scrollbar_info.gx_scroll_visible - 1 < scroll -> gx_scrollbar_info.gx_scroll_maximum))
164
    {
165
4633
        if (space == 0)
166
        {
167
395
            space = 1;
168
        }
169
4238
        else if (space == (travelsize - thumb_length))
170
        {
171
5
            space -= 1;
172
        }
173
    }
174
175
7701
    thumbrect = scroll -> gx_widget_size;
176
177
7701
    if (style & GX_SCROLLBAR_VERTICAL)
178
    {
179
5956
        thumbrect.gx_rectangle_left = (GX_VALUE)(thumbrect.gx_rectangle_left + (scroll_width - thumb_width) / 2);
180
5956
        thumbrect.gx_rectangle_right = (GX_VALUE) (thumbrect.gx_rectangle_left + thumb_width - 1);
181
5956
        thumbrect.gx_rectangle_top = (GX_VALUE)(scroll -> gx_widget_size.gx_rectangle_top +
182
5956
                                                scroll -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min + space);
183
5956
        thumbrect.gx_rectangle_bottom = (GX_VALUE)(thumbrect.gx_rectangle_top + thumb_length - 1);
184
    }
185
    else
186
    {
187
1745
        thumbrect.gx_rectangle_top = (GX_VALUE)(thumbrect.gx_rectangle_top + (scroll_width - thumb_width) / 2);
188
1745
        thumbrect.gx_rectangle_bottom = (GX_VALUE)(thumbrect.gx_rectangle_top + thumb_width - 1);
189
190
1745
        thumbrect.gx_rectangle_left = (GX_VALUE)(scroll -> gx_widget_size.gx_rectangle_left +
191
1745
                                                 scroll -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min + space);
192
1745
        thumbrect.gx_rectangle_right = (GX_VALUE)(thumbrect.gx_rectangle_left + thumb_length - 1);
193
    }
194
195
7701
    _gx_widget_resize((GX_WIDGET *)&scroll -> gx_scrollbar_thumb, &thumbrect);
196
7701
}
197