GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_horizontal_list_total_columns_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
/**   Window Management (Window)                                          */
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_horizontal_list_total_columns_set               PORTABLE C      */
39
/*                                                           6.1.10       */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function assigns the number of list columns                    */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    vertical_list                         Vertical list widget control  */
51
/*                                          block                         */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
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_window_scrollbar_find             Find the scrollbar            */
63
/*    _gx_scrollbar_reset                   Reset the schollbar           */
64
/*    _gx_system_dirty_mark                 Mark the widget dirty         */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    GUIX Internal Code                                                  */
69
/*                                                                        */
70
/**************************************************************************/
71
62
UINT _gx_horizontal_list_total_columns_set(GX_HORIZONTAL_LIST *list, INT count)
72
{
73
INT           page_index;
74
INT           index;
75
GX_WIDGET    *test;
76
GX_SCROLLBAR *pScroll;
77
78
62
    GX_ENTER_CRITICAL
79
80
    /* Update total count of rows. */
81
62
    list -> gx_horizontal_list_total_columns = count;
82
83
    /* Update selected index. */
84
62
    if (list -> gx_horizontal_list_selected < 0)
85
    {
86
5
        list -> gx_horizontal_list_selected = 0;
87
    }
88
89
62
    if (list -> gx_horizontal_list_selected > count - 1)
90
    {
91
15
        list -> gx_horizontal_list_selected = count - 1;
92
    }
93
94
    /* Calculate current page index. */
95
62
    page_index = list -> gx_horizontal_list_top_index;
96
97
62
    test = _gx_widget_first_client_child_get((GX_WIDGET *)list);
98
99

113
    while (test && (test -> gx_widget_size.gx_rectangle_right <= list -> gx_widget_size.gx_rectangle_left))
100
    {
101
51
        page_index++;
102
51
        test = _gx_widget_next_client_child_get(test);
103
    }
104
105
    /* Calculate new page index */
106
62
    if (page_index + list -> gx_horizontal_list_visible_columns > count)
107
    {
108
37
        if (count > list -> gx_horizontal_list_visible_columns)
109
        {
110
8
            page_index = count - list -> gx_horizontal_list_visible_columns;
111
        }
112
        else
113
        {
114
29
            page_index = 0;
115
        }
116
    }
117
118
    /* Add idle children back to horizontal list.  */
119
62
    if (list -> gx_horizontal_list_idle_child_list)
120
    {
121
222
        while (list -> gx_horizontal_list_idle_child_list)
122
        {
123
193
            test = list -> gx_horizontal_list_idle_child_list;
124
193
            list -> gx_horizontal_list_idle_child_list = list -> gx_horizontal_list_idle_child_list -> gx_widget_next;
125
126
193
            _gx_widget_attach((GX_WIDGET *)list, test);
127
193
            list -> gx_horizontal_list_child_count++;
128
        }
129
    }
130
131
    /* Check whether list child count is larger than count. */
132
321
    while (list -> gx_horizontal_list_child_count > count)
133
    {
134
260
        test = _gx_widget_last_client_child_get((GX_WIDGET *)list);
135
136
260
        if (test)
137
        {
138
259
            _gx_widget_detach(test);
139
140
            /* Put detached widget to idle list.  */
141
259
            test -> gx_widget_next = list -> gx_horizontal_list_idle_child_list;
142
259
            list -> gx_horizontal_list_idle_child_list = test;
143
259
            list -> gx_horizontal_list_child_count--;
144
        }
145
        else
146
        {
147
1
            return GX_FAILURE;
148
        }
149
    }
150
151
61
    list -> gx_horizontal_list_top_index = 0;
152
61
    index = 0;
153
61
    test = _gx_widget_first_client_child_get((GX_WIDGET *)list);
154
155
476
    while (test)
156
    {
157
415
        list -> gx_horizontal_list_callback(list, test, index++);
158
159
415
        test = _gx_widget_next_client_child_get(test);
160
    }
161
162
    /* Reposition child widgets.  */
163
61
    _gx_horizontal_list_children_position(list);
164
165
166
    /* Make new page index visible */
167
61
    _gx_horizontal_list_page_index_set(list, page_index);
168
169
61
    _gx_window_scrollbar_find((GX_WINDOW *)list, GX_TYPE_HORIZONTAL_SCROLL, &pScroll);
170
171
61
    if (pScroll)
172
    {
173
30
        _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
58
        _gx_system_dirty_mark((GX_WIDGET *)list);
182
    }
183
61
    return GX_SUCCESS;
184
}
185