GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_horizontal_list_scroll_info_get.c Lines: 22 28 78.6 %
Date: 2024-12-05 08:52:37 Branches: 9 14 64.3 %

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
/**   Horizontal List (List)                                              */
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_horizontal_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
609
VOID _gx_horizontal_list_scroll_info_get(GX_WINDOW *win, ULONG style, GX_SCROLL_INFO *info)
78
{
79
INT                 value;
80
GX_WIDGET          *child;
81
609
GX_HORIZONTAL_LIST *list = (GX_HORIZONTAL_LIST *)win;
82
GX_VALUE            width;
83
84
85
    GX_PARAMETER_NOT_USED(style);
86
87
609
    if (list -> gx_horizontal_list_callback)
88
    {
89
    	/* If list callback is set, children winthin the list should share the same width. */
90
609
        info -> gx_scroll_maximum = (list -> gx_horizontal_list_total_columns * list -> gx_horizontal_list_child_width - 1);
91
    }
92
    else
93
    {
94
        info -> gx_scroll_maximum = 0;
95
96
        child = _gx_widget_first_client_child_get((GX_WIDGET*)list);
97
        while (child)
98
        {
99
            _gx_widget_width_get(child, &width);
100
            info -> gx_scroll_maximum += width;
101
            child = _gx_widget_next_client_child_get(child);
102
        }
103
    }
104
609
    info -> gx_scroll_minimum = 0;
105
609
    info -> gx_scroll_visible = (GX_VALUE)(list -> gx_window_client.gx_rectangle_right - list -> gx_window_client.gx_rectangle_left + 1);
106
107
609
    if (info -> gx_scroll_maximum <= info -> gx_scroll_visible)
108
    {
109
31
        info -> gx_scroll_value = 0;
110
31
        info -> gx_scroll_increment = 0;
111
31
        info -> gx_scroll_maximum = info -> gx_scroll_visible;
112
31
        return;
113
    }
114
115
578
    value = list -> gx_horizontal_list_top_index * list -> gx_horizontal_list_child_width;
116
117
578
    if (list -> gx_horizontal_list_top_index >= 0)
118
    {
119
578
        child = _gx_widget_first_client_child_get((GX_WIDGET *)win);
120
121
578
        if (child)
122
        {
123
578
            value += win -> gx_window_client.gx_rectangle_left - child -> gx_widget_size.gx_rectangle_left;
124
        }
125
    }
126
127
578
    if (value < info -> gx_scroll_minimum)
128
    {
129
150
        value = info -> gx_scroll_minimum;
130
    }
131
    else
132
    {
133
428
        if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
134
        {
135
108
            value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
136
        }
137
    }
138
139
578
    info -> gx_scroll_value = value;
140
578
    info -> gx_scroll_increment = list -> gx_horizontal_list_child_width / 2;
141
}
142