GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_scroll_wheel_selected_row_calculate.c Lines: 25 25 100.0 %
Date: 2026-03-06 19:21:09 Branches: 18 18 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
/**   Scroll Wheel Management (Scroll Wheel)                              */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_scroll_wheel.h"
29
30
/**************************************************************************/
31
/*                                                                        */
32
/*  FUNCTION                                               RELEASE        */
33
/*                                                                        */
34
/*    _gx_scroll_wheel_selected_row_calculate             PORTABLE C      */
35
/*                                                           6.1.7        */
36
/*  AUTHOR                                                                */
37
/*                                                                        */
38
/*    Kenneth Maxwell, Microsoft Corporation                              */
39
/*                                                                        */
40
/*  DESCRIPTION                                                           */
41
/*                                                                        */
42
/*    This function calculates the current selected row for scroll wheel  */
43
/*    widget.                                                             */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    wheel                                 Scroll wheel control block    */
48
/*                                                                        */
49
/*  OUTPUT                                                                */
50
/*                                                                        */
51
/*    status                                Completion status             */
52
/*                                                                        */
53
/*  CALLS                                                                 */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLED BY                                                             */
58
/*                                                                        */
59
/*    _gx_text_scroll_wheel_scroll                                        */
60
/*                                                                        */
61
/**************************************************************************/
62
559
UINT _gx_scroll_wheel_selected_row_calculate(GX_SCROLL_WHEEL *wheel)
63
{
64
INT      yshift;
65
INT      selected_row;
66
559
GX_VALUE half_row_height = (wheel -> gx_scroll_wheel_row_height >> 1);
67
68
559
    yshift = wheel -> gx_scroll_wheel_selected_yshift;
69
559
    selected_row = wheel -> gx_scroll_wheel_selected_row;
70
71
559
    if (wheel -> gx_scroll_wheel_wrap_style_check(wheel))
72
    {
73
228
        while (yshift > half_row_height)
74
        {
75
            /* Scroll Down. */
76
69
            yshift -= wheel -> gx_scroll_wheel_row_height;
77
69
            selected_row--;
78
        }
79
80
206
        while (yshift < -half_row_height)
81
        {
82
            /* Scroll Up. */
83
47
            yshift += wheel -> gx_scroll_wheel_row_height;
84
47
            selected_row++;
85
        }
86
87
169
        while (selected_row > wheel -> gx_scroll_wheel_total_rows - 1)
88
        {
89
10
            selected_row -= wheel -> gx_scroll_wheel_total_rows;
90
        }
91
92
172
        while (selected_row < 0)
93
        {
94
13
            selected_row += wheel -> gx_scroll_wheel_total_rows;
95
        }
96
    }
97
    else
98
    {
99

484
        while ((yshift > half_row_height) &&
100
               (selected_row > 0))
101
        {
102
            /* Scroll Down. */
103
84
            yshift -= wheel -> gx_scroll_wheel_row_height;
104
84
            selected_row--;
105
        }
106
107
497
        while ((yshift < -half_row_height) &&
108
109
               (selected_row < wheel -> gx_scroll_wheel_total_rows - 1))
109
        {
110
            /* Scroll Up. */
111
97
            yshift += wheel -> gx_scroll_wheel_row_height;
112
97
            selected_row++;
113
        }
114
    }
115
116
559
    wheel -> gx_scroll_wheel_selected_row = selected_row;
117
559
    wheel -> gx_scroll_wheel_selected_yshift = (GX_VALUE)yshift;
118
119
559
    return GX_SUCCESS;
120
}
121