GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_vertical_list_total_rows_set.c Lines: 45 45 100.0 %
Date: 2026-03-06 19:21:09 Branches: 26 26 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
/**   Vertical List (List)                                                */
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_system.h"
31
#include "gx_utility.h"
32
#include "gx_scrollbar.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_vertical_list_total_rows_set                    PORTABLE C      */
39
/*                                                           6.1.10       */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function assigns total number of list rows.                    */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    vertical_list                         Vertical list control block   */
51
/*    count                                 Number of rows                */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    status                                Completion status             */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    GX_ENTER_CRITICAL                     Obtain GUIX system lock       */
60
/*    GX_EXIT_CRITICAL                      Release GUIX system lock      */
61
/*    _gx_first_client_child_get            Get the first client child    */
62
/*    [gx_vertical_list_callback]           Vertical list callback        */
63
/*    _gx_window_scrollbar_find             Find the scrollbar            */
64
/*    _gx_scrollbar_reset                   Reset the schollbar           */
65
/*    _gx_system_dirty_mark                 Mark the widget dirty         */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    GUIX Internal Code                                                  */
70
/*                                                                        */
71
/**************************************************************************/
72
62
UINT _gx_vertical_list_total_rows_set(GX_VERTICAL_LIST *list, INT count)
73
{
74
INT           page_index;
75
INT           index;
76
GX_WIDGET    *test;
77
GX_SCROLLBAR *pScroll;
78
79
62
    GX_ENTER_CRITICAL
80
81
    /* Update total count of rows. */
82
62
    list -> gx_vertical_list_total_rows = count;
83
84
    /* Update selected index. */
85
62
    if (list -> gx_vertical_list_selected < 0)
86
    {
87
5
        list -> gx_vertical_list_selected = 0;
88
    }
89
90
62
    if (list -> gx_vertical_list_selected > count - 1)
91
    {
92
15
        list -> gx_vertical_list_selected = count - 1;
93
    }
94
95
    /* Calculate current page index. */
96
62
    page_index = list -> gx_vertical_list_top_index;
97
98
62
    test = _gx_widget_first_client_child_get((GX_WIDGET *)list);
99
100

113
    while (test && (test -> gx_widget_size.gx_rectangle_bottom <= list -> gx_widget_size.gx_rectangle_top))
101
    {
102
51
        page_index++;
103
51
        test = _gx_widget_next_client_child_get(test);
104
    }
105
106
    /* Calculate new page index */
107
62
    if (page_index + list -> gx_vertical_list_visible_rows > count)
108
    {
109
37
        if (count > list -> gx_vertical_list_visible_rows)
110
        {
111
8
            page_index = count - list -> gx_vertical_list_visible_rows;
112
        }
113
        else
114
        {
115
29
            page_index = 0;
116
        }
117
    }
118
119
    /* Add idle children back to vertical list.  */
120
62
    if (list -> gx_vertical_list_idle_child_list)
121
    {
122
222
        while (list -> gx_vertical_list_idle_child_list)
123
        {
124
193
            test = list -> gx_vertical_list_idle_child_list;
125
193
            list -> gx_vertical_list_idle_child_list = list -> gx_vertical_list_idle_child_list -> gx_widget_next;
126
127
193
            _gx_widget_attach((GX_WIDGET *)list, test);
128
193
            list -> gx_vertical_list_child_count++;
129
        }
130
    }
131
132
    /* Check whether list child count is larger than count. */
133
418
    while (list -> gx_vertical_list_child_count > count)
134
    {
135
357
        test = _gx_widget_last_client_child_get((GX_WIDGET *)list);
136
137
357
        if (test)
138
        {
139
356
            _gx_widget_detach(test);
140
141
            /* Put detached widget to idle list.  */
142
356
            test -> gx_widget_next = list -> gx_vertical_list_idle_child_list;
143
356
            list -> gx_vertical_list_idle_child_list = test;
144
356
            list -> gx_vertical_list_child_count--;
145
        }
146
        else
147
        {
148
1
            return GX_FAILURE;
149
        }
150
    }
151
152
61
    list -> gx_vertical_list_top_index = 0;
153
61
    index = 0;
154
61
    test = _gx_widget_first_client_child_get((GX_WIDGET *)list);
155
156
476
    while (test)
157
    {
158
415
        list -> gx_vertical_list_callback(list, test, index++);
159
160
415
        test = _gx_widget_next_client_child_get(test);
161
    }
162
163
    /* Reposition child widgets.  */
164
61
    _gx_vertical_list_children_position(list);
165
166
    /* Make new page index visible */
167
61
    _gx_vertical_list_page_index_set(list, page_index);
168
169
61
    _gx_window_scrollbar_find((GX_WINDOW *)list, GX_TYPE_VERTICAL_SCROLL, &pScroll);
170
171
61
    if (pScroll)
172
    {
173
31
        _gx_scrollbar_reset(pScroll, GX_NULL);
174
    }
175
176
61
    GX_EXIT_CRITICAL
177
178
    /* Refresh screen. */
179
61
    if (list -> gx_widget_status & GX_STATUS_VISIBLE)
180
    {
181
59
        _gx_system_dirty_mark((GX_WIDGET *)list);
182
    }
183
61
    return GX_SUCCESS;
184
}
185