GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_vertical_list_scroll_info_get.c Lines: 27 27 100.0 %
Date: 2024-12-05 08:52:37 Branches: 12 14 85.7 %

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
/**   Vertical List Management                                            */
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_window.h"
29
#include "gx_system.h"
30
#include "gx_scrollbar.h"
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_vertical_list_scroll_info_get                   PORTABLE C      */
37
/*                                                           6.4.0        */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function gets the scrollbar information.                       */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    win                                   Pointer to window             */
49
/*    style                                 Style                         */
50
/*    info                                  Information of scrollbar      */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    None                                                                */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_first_client_child_get            Get the first client child    */
59
/*                                                                        */
60
/*  CALLED BY                                                             */
61
/*                                                                        */
62
/*    Application Code                                                    */
63
/*                                                                        */
64
/*  RELEASE HISTORY                                                       */
65
/*                                                                        */
66
/*    DATE              NAME                      DESCRIPTION             */
67
/*                                                                        */
68
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
69
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
70
/*                                            resulting in version 6.1    */
71
/*  12-31-2023     Ting Zhu                 Modified comments(s),         */
72
/*                                            improved the calculation of */
73
/*                                            the maximum scrolling value.*/
74
/*                                            resulting in version 6.4.0  */
75
/*                                                                        */
76
/**************************************************************************/
77
953
VOID _gx_vertical_list_scroll_info_get(GX_VERTICAL_LIST *list, ULONG style, GX_SCROLL_INFO *info)
78
{
79
INT        value;
80
GX_VALUE   height;
81
GX_WIDGET *child;
82
83
    GX_PARAMETER_NOT_USED(style);
84
85
953
    if (list -> gx_vertical_list_callback)
86
    {
87
        /* If list callback is set, children winthin the list should share the same height. */
88
945
        info -> gx_scroll_maximum = (list->gx_vertical_list_total_rows * list -> gx_vertical_list_child_height - 1);
89
    }
90
    else
91
    {
92
8
        info -> gx_scroll_maximum = 0;
93
94
8
        child = _gx_widget_first_client_child_get((GX_WIDGET *)list);
95
96
256
        while (child)
97
        {
98
248
            _gx_widget_height_get(child, &height);
99
100
248
            info -> gx_scroll_maximum += height;
101
102
248
            child = _gx_widget_next_client_child_get(child);
103
        }
104
    }
105
953
    info -> gx_scroll_minimum = 0;
106
953
    info -> gx_scroll_visible = (GX_VALUE)(list -> gx_window_client.gx_rectangle_bottom - list -> gx_window_client.gx_rectangle_top + 1);
107
108
953
    if (info -> gx_scroll_maximum <= info -> gx_scroll_visible)
109
    {
110
36
        info -> gx_scroll_value = 0;
111
36
        info -> gx_scroll_increment = 0;
112
36
        info -> gx_scroll_maximum = info->gx_scroll_visible;
113
36
        return;
114
    }
115
116
917
    value = list -> gx_vertical_list_top_index * list -> gx_vertical_list_child_height;
117
118
917
    if (list -> gx_vertical_list_top_index >= 0)
119
    {
120
917
        child = _gx_widget_first_client_child_get((GX_WIDGET *)list);
121
122
917
        if (child)
123
        {
124
917
            value += list -> gx_window_client.gx_rectangle_top - child -> gx_widget_size.gx_rectangle_top;
125
        }
126
    }
127
128
917
    if (value < info -> gx_scroll_minimum)
129
    {
130
166
        value = info -> gx_scroll_minimum;
131
    }
132
    else
133
    {
134
751
        if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
135
        {
136
108
            value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
137
        }
138
    }
139
140
917
    info -> gx_scroll_value = value;
141
917
    info -> gx_scroll_increment = list -> gx_vertical_list_child_height / 2;
142
}
143