GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_generic_scroll_wheel_up_wrap.c Lines: 21 21 100.0 %
Date: 2024-12-05 08:52:37 Branches: 14 14 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 (Generic 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_widget.h"
28
#include "gx_utility.h"
29
#include "gx_scroll_wheel.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_generic_scroll_wheel_up_wrap                    PORTABLE C      */
36
/*                                                           6.1.7        */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Ting Zhu, Microsoft Corporation                                     */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function scrolls up the generic scroll wheel.                  */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    wheel                                 Generic scroll wheel control  */
48
/*                                            block                       */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    None                                                                */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*    _gx_widget_first_visible_client_child_get                           */
57
/*                                          Get the first visible client  */
58
/*    _gx_widget_last_visible_client_child_get                            */
59
/*                                          Get the last visible client   */
60
/*    _gx_utility_rectangle_shift           Move a rectangle              */
61
/*    [gx_generic_scroll_wheel_callback]     Callback to create row item  */
62
/*    _gx_widget_resize                     Resize a widget               */
63
/*    _gx_widget_attach                     Attach a widget to its parent */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    _gx_generic_scroll_wheel_scroll        Generic scroll wheel scroll  */
68
/*                                            function                    */
69
/*                                                                        */
70
/*  RELEASE HISTORY                                                       */
71
/*                                                                        */
72
/*    DATE              NAME                      DESCRIPTION             */
73
/*                                                                        */
74
/*  06-02-2021     Ting Zhu                 Initial Version 6.1.7         */
75
/*                                                                        */
76
/**************************************************************************/
77
66
VOID _gx_generic_scroll_wheel_up_wrap(GX_GENERIC_SCROLL_WHEEL *wheel)
78
{
79
GX_WIDGET   *test;
80
GX_WIDGET   *check;
81
GX_RECTANGLE newpos;
82
INT          index;
83
84
86
    while ((wheel -> gx_generic_scroll_wheel_top_index + wheel -> gx_generic_scroll_wheel_child_count < wheel -> gx_scroll_wheel_total_rows) ||
85
58
           (wheel -> gx_widget_style & GX_STYLE_WRAP))
86
    {
87
88
        /* Scrolling up. See if my top widget is already above my client area.  */
89
90
59
        test = _gx_widget_first_visible_client_child_get((GX_WIDGET *)wheel);
91
92

59
        if (test && test -> gx_widget_size.gx_rectangle_bottom < wheel -> gx_widget_size.gx_rectangle_top)
93
        {
94
95
            /* Top widget is above my client area, move it to the bottom.  */
96
21
            check = _gx_widget_last_visible_client_child_get((GX_WIDGET *)wheel);
97
98
21
            if (check)
99
            {
100
20
                _gx_widget_detach(test);
101
102
20
                newpos = test -> gx_widget_size;
103
20
                _gx_utility_rectangle_shift(&newpos, 0, (GX_VALUE)(check -> gx_widget_size.gx_rectangle_bottom - newpos.gx_rectangle_top + 1));
104
20
                _gx_widget_resize(test, &newpos);
105
106
20
                index = wheel -> gx_generic_scroll_wheel_top_index + wheel -> gx_generic_scroll_wheel_child_count;
107
108
                /* Wrap index.  */
109
20
                if (index >= wheel -> gx_scroll_wheel_total_rows)
110
                {
111
14
                    index -= wheel -> gx_scroll_wheel_total_rows;
112
                }
113
114
20
                wheel -> gx_generic_scroll_wheel_callback(wheel, test, index);
115
116
20
                _gx_widget_attach((GX_WIDGET *)wheel, test);
117
20
                wheel -> gx_generic_scroll_wheel_top_index++;
118
119
                /* Wrap page index.  */
120
20
                if (wheel -> gx_generic_scroll_wheel_top_index >= wheel -> gx_scroll_wheel_total_rows)
121
                {
122
1
                    wheel -> gx_generic_scroll_wheel_top_index -= wheel -> gx_scroll_wheel_total_rows;
123
                }
124
            }
125
            else
126
            {
127
1
                break;
128
            }
129
        }
130
        else
131
        {
132
            break;
133
        }
134
    }
135
66
}
136