GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_generic_scroll_wheel_scroll.c Lines: 31 31 100.0 %
Date: 2026-03-06 19:21:09 Branches: 32 32 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 (Generic 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_widget.h"
29
#include "gx_window.h"
30
#include "gx_scroll_wheel.h"
31
#include "gx_utility.h"
32
#include "gx_system.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_generic_scroll_wheel_scroll                     PORTABLE C      */
39
/*                                                           6.2.1        */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Ting Zhu, Microsoft Corporation                                     */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function moves up or down the generic scroll wheel.            */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    wheel                                 Generic scroll wheel control  */
51
/*                                            block                       */
52
/*    amount                                Shifting value                */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_scroll_wheel_selected_row_calculate                             */
61
/*                                          Calculate the new selected row*/
62
/*    _gx_widget_first_visible_client_child_get                           */
63
/*                                          Get the first visible client  */
64
/*    _gx_widget_next_visible_client_child_get                            */
65
/*                                          Get the next visible client   */
66
/*    _gx_widget_scroll_shift               Shift a widget                */
67
/*    _gx_generic_scroll_wheel_up_wrap      Scroll up the scroll wheel    */
68
/*    _gx_generic_scroll_wheel_down_wrap    Scroll down the scroll wheel  */
69
/*    _gx_system_dirty_mark                 Mark the widget as dirty      */
70
/*                                                                        */
71
/*  CALLED BY                                                             */
72
/*                                                                        */
73
/*    GUIX Internal Code                                                  */
74
/*                                                                        */
75
/**************************************************************************/
76
232
UINT _gx_generic_scroll_wheel_scroll(GX_GENERIC_SCROLL_WHEEL *wheel, GX_VALUE shift)
77
{
78
GX_WIDGET *child;
79
INT        y_shift;
80
INT        min_shift;
81
INT        max_shift;
82
83
232
    if (!shift)
84
    {
85
1
        return GX_SUCCESS;
86
    }
87
88
231
    if (!wheel -> gx_scroll_wheel_wrap_style_check((GX_SCROLL_WHEEL *)wheel))
89
    {
90

158
        if ((shift > 0 && wheel -> gx_scroll_wheel_selected_row == 0) ||
91
86
            (shift < 0 && wheel -> gx_scroll_wheel_selected_row == wheel -> gx_scroll_wheel_total_rows - 1))
92
        {
93
8
            y_shift = wheel -> gx_scroll_wheel_selected_yshift + shift;
94
95
8
            min_shift = (wheel -> gx_scroll_wheel_selected_row - wheel -> gx_scroll_wheel_total_rows + 1) * wheel -> gx_scroll_wheel_row_height;
96
8
            max_shift = (wheel -> gx_scroll_wheel_selected_row * wheel -> gx_scroll_wheel_row_height);
97
98

8
            if ((y_shift < min_shift) || (y_shift > max_shift))
99
            {
100
101
                /* Slow down the speed when scroll outside the valid row range.  */
102
3
                shift = (GX_VALUE)(shift + wheel -> gx_scroll_wheel_shift_error);
103
3
                wheel -> gx_scroll_wheel_shift_error = (GX_BYTE)(shift % 4);
104
3
                shift /= 4;
105
            }
106
            else
107
            {
108
5
                wheel -> gx_scroll_wheel_shift_error = 0;
109
            }
110
        }
111
    }
112
113
231
    wheel -> gx_scroll_wheel_selected_yshift = (GX_VALUE)(wheel -> gx_scroll_wheel_selected_yshift + shift);
114
115
    /* Calculate the new selected row.  */
116
231
    _gx_scroll_wheel_selected_row_calculate((GX_SCROLL_WHEEL *)wheel);
117
118
119
    /* First shift my child widgets.  */
120
231
    child = _gx_widget_first_visible_client_child_get((GX_WIDGET *)wheel);
121
122
1861
    while (child)
123
    {
124
1630
        _gx_widget_scroll_shift(child, 0, shift, GX_TRUE);
125
126
1630
        if (child -> gx_widget_style & GX_STYLE_DRAW_SELECTED)
127
        {
128
61
            child -> gx_widget_style &= (~GX_STYLE_DRAW_SELECTED);
129
        }
130
131
1630
        child = _gx_widget_next_visible_client_child_get(child);
132
    }
133
134
    /* Next check to see if we need to wrap any child widgets.  */
135
136
231
    if ((wheel -> gx_generic_scroll_wheel_callback != GX_NULL) &&
137
160
        (wheel -> gx_generic_scroll_wheel_visible_rows < wheel -> gx_scroll_wheel_total_rows) &&
138

153
        ((wheel -> gx_generic_scroll_wheel_child_count < wheel -> gx_scroll_wheel_total_rows) || (wheel -> gx_widget_style & GX_STYLE_WRAP)))
139
    {
140
141
        /* This means we have fewer children than list rows, so we
142
           need to move and re-use the child widgets.  */
143
151
        if (shift < 0)
144
        {
145
66
            _gx_generic_scroll_wheel_up_wrap(wheel);
146
        }
147
        else
148
        {
149
85
            _gx_generic_scroll_wheel_down_wrap(wheel);
150
        }
151
    }
152
153
231
    if (wheel -> gx_widget_status & GX_STATUS_VISIBLE)
154
    {
155
229
        _gx_system_dirty_mark((GX_WIDGET *)wheel);
156
    }
157
231
    return GX_SUCCESS;
158
}
159