GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_scroll_wheel_selected_set.c Lines: 20 20 100.0 %
Date: 2026-03-06 19:21:09 Branches: 14 14 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
#include "gx_system.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_scroll_wheel_selected_set                       PORTABLE C      */
36
/*                                                           6.1.7        */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function sets the current selected row index for scroll wheel  */
44
/*    widget.                                                             */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    wheel                                 Scroll wheel control block    */
49
/*    row                                   Selected row to be set        */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    status                                Completion status             */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    None                                                                */
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    Application Code                                                    */
62
/*    GUIX Internal Code                                                  */
63
/*                                                                        */
64
/**************************************************************************/
65
502
UINT _gx_scroll_wheel_selected_set(GX_SCROLL_WHEEL *wheel, INT row)
66
{
67
INT dist;
68
69

502
    if ((row < 0) || (wheel -> gx_scroll_wheel_total_rows == 0))
70
    {
71
18
        row = 0;
72
    }
73
484
    else if (row > wheel -> gx_scroll_wheel_total_rows - 1)
74
    {
75
5
        row = wheel -> gx_scroll_wheel_total_rows - 1;
76
    }
77
78
502
    if (wheel -> gx_scroll_wheel_selected_row == row)
79
    {
80
179
        return GX_SUCCESS;
81
    }
82
83
323
    if (wheel -> gx_widget_status & GX_STATUS_VISIBLE)
84
    {
85
27
        if (wheel -> gx_scroll_wheel_wrap_style_check(wheel))
86
        {
87
9
            if (GX_ABS(wheel -> gx_scroll_wheel_selected_row - row) <
88
9
                GX_ABS(wheel -> gx_scroll_wheel_selected_row + wheel -> gx_scroll_wheel_total_rows - row))
89
            {
90
6
                dist = wheel -> gx_scroll_wheel_selected_row - row;
91
            }
92
            else
93
            {
94
3
                dist = wheel -> gx_scroll_wheel_selected_row + wheel -> gx_scroll_wheel_total_rows - row;
95
            }
96
        }
97
        else
98
        {
99
18
            dist = wheel -> gx_scroll_wheel_selected_row - row;
100
        }
101
102
27
        wheel -> gx_scroll_wheel_animation_steps = 10;
103
27
        wheel -> gx_scroll_wheel_animation_speed = (GX_VALUE)(dist * wheel -> gx_scroll_wheel_row_height) / 10;
104
27
        wheel -> gx_scroll_wheel_shift_error = (GX_BYTE)(dist * wheel -> gx_scroll_wheel_row_height) % 10;
105
27
        _gx_system_timer_start((GX_WIDGET *)wheel, GX_ANIMATION_TIMER, 2, 2);
106
    }
107
    else
108
    {
109
296
        wheel -> gx_scroll_wheel_selected_row = row;
110
    }
111
112
323
    return GX_SUCCESS;
113
}
114