GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_scroll_wheel_scroll.c Lines: 19 19 100.0 %
Date: 2024-12-05 08:52:37 Branches: 16 16 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** GUIX Component                                                        */
16
/**                                                                       */
17
/**   Scroll Wheel Management (Scroll Wheel)                              */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_scroll_wheel.h"
29
30
/**************************************************************************/
31
/*                                                                        */
32
/*  FUNCTION                                               RELEASE        */
33
/*                                                                        */
34
/*    _gx_scroll_wheel_scroll                             PORTABLE C      */
35
/*                                                           6.1.7        */
36
/*  AUTHOR                                                                */
37
/*                                                                        */
38
/*    Kenneth Maxwell, Microsoft Corporation                              */
39
/*                                                                        */
40
/*  DESCRIPTION                                                           */
41
/*                                                                        */
42
/*    This function scrolls a scroll widget widget.                       */
43
/*                                                                        */
44
/*  INPUT                                                                 */
45
/*                                                                        */
46
/*    wheel                                 Scroll wheel control block    */
47
/*    shift                                 Value to be shift             */
48
/*                                                                        */
49
/*  OUTPUT                                                                */
50
/*                                                                        */
51
/*    status                                Completion status             */
52
/*                                                                        */
53
/*  CALLS                                                                 */
54
/*                                                                        */
55
/*    _gx_scroll_wheel_selected_row_calculate                             */
56
/*                                          Calculate current selected row*/
57
/*    _gx_system_dirty_mark                 Mark a widget as dirty        */
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    _gx_scroll_wheel_event_process                                      */
62
/*                                                                        */
63
/*  RELEASE HISTORY                                                       */
64
/*                                                                        */
65
/*    DATE              NAME                      DESCRIPTION             */
66
/*                                                                        */
67
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
68
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
69
/*                                            resulting in version 6.1    */
70
/*  06-02-2021     Ting Zhu                 Modified comment(s),          */
71
/*                                            modified wrap style test    */
72
/*                                            logic,                      */
73
/*                                            resulting in version 6.1.7  */
74
/*                                                                        */
75
/**************************************************************************/
76
328
UINT _gx_scroll_wheel_scroll(GX_SCROLL_WHEEL *wheel, GX_VALUE shift)
77
{
78
INT y_shift;
79
INT min_shift;
80
INT max_shift;
81
82
328
    if (!wheel -> gx_scroll_wheel_wrap_style_check(wheel))
83
    {
84
242
        y_shift = wheel -> gx_scroll_wheel_selected_yshift + shift;
85
86

242
        if ((shift > 0 && wheel -> gx_scroll_wheel_selected_row == 0) ||
87
131
            (shift < 0 && wheel -> gx_scroll_wheel_selected_row == wheel -> gx_scroll_wheel_total_rows - 1))
88
        {
89
17
            y_shift = wheel -> gx_scroll_wheel_selected_yshift + shift;
90
91
17
            min_shift = (wheel -> gx_scroll_wheel_selected_row - wheel -> gx_scroll_wheel_total_rows + 1) *
92
17
                wheel -> gx_scroll_wheel_row_height;
93
17
            max_shift = (wheel -> gx_scroll_wheel_selected_row * wheel -> gx_scroll_wheel_row_height);
94
95

17
            if ((y_shift < min_shift) || (y_shift > max_shift))
96
            {
97
15
                shift = (GX_VALUE)(shift + wheel -> gx_scroll_wheel_shift_error);
98
15
                wheel -> gx_scroll_wheel_shift_error = (GX_BYTE)(shift % 4);
99
15
                shift /= 4;
100
            }
101
            else
102
            {
103
2
                wheel -> gx_scroll_wheel_shift_error = 0;
104
            }
105
        }
106
    }
107
108
328
    wheel -> gx_scroll_wheel_selected_yshift = (GX_VALUE)(wheel -> gx_scroll_wheel_selected_yshift + shift);
109
110
328
    _gx_scroll_wheel_selected_row_calculate(wheel);
111
112
328
    if (wheel -> gx_widget_status & GX_STATUS_VISIBLE)
113
    {
114
320
        _gx_system_dirty_mark((GX_WIDGET *)wheel);
115
    }
116
328
    return GX_SUCCESS;
117
}
118