GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_horizontal_list_children_position.c Lines: 29 29 100.0 %
Date: 2026-03-06 19:21:09 Branches: 12 12 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
/**   Horizontal 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
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_horizontal_list_children_position               PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function positions the children for the horizontal list.       */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    horizontal_list                       Horizontal list widget        */
50
/*                                            control block               */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    status                                Completion status             */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_widget_width_get                  Retrieves the width of the    */
59
/*                                            widget                      */
60
/*    _gx_widget_resize                     Resizes the widget            */
61
/*    _gx_window_client_width_get           Retrieves the width of the    */
62
/*                                            client                      */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    _gx_horizontal_list_event_process                                   */
67
/*                                                                        */
68
/**************************************************************************/
69
223
UINT _gx_horizontal_list_children_position(GX_HORIZONTAL_LIST *horizontal_list)
70
{
71
223
GX_RECTANGLE childsize = horizontal_list -> gx_window_client;
72
223
GX_WIDGET   *child = horizontal_list -> gx_widget_first_child;
73
223
INT          index    = horizontal_list -> gx_horizontal_list_top_index;
74
75
GX_VALUE     width;
76
GX_VALUE     client_width;
77
78
223
    horizontal_list -> gx_horizontal_list_child_width = 0;
79
223
    horizontal_list -> gx_horizontal_list_child_count = 0;
80
81
1512
    while (child)
82
    {
83
1289
        if (!(child -> gx_widget_status & GX_STATUS_NONCLIENT))
84
        {
85
            /* increment child count */
86
1245
            horizontal_list -> gx_horizontal_list_child_count++;
87
88
            /* assign this child's id */
89
90
1245
            if (!(child -> gx_widget_id))
91
            {
92
827
                child -> gx_widget_id = (USHORT)(LIST_CHILD_ID_START + horizontal_list -> gx_horizontal_list_child_count);
93
            }
94
95
1245
            if (index == horizontal_list -> gx_horizontal_list_selected)
96
            {
97
195
                child -> gx_widget_style |= GX_STYLE_DRAW_SELECTED;
98
            }
99
            else
100
            {
101
1050
                child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
102
            }
103
1245
            index++;
104
105
1245
            child -> gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS;
106
107
            /* pick up child item width, needed for scrolling */
108
1245
            _gx_widget_width_get(child, &width);
109
1245
            if (width > horizontal_list -> gx_horizontal_list_child_width)
110
            {
111
199
                horizontal_list -> gx_horizontal_list_child_width = width;
112
            }
113
114
            /* move this child into position */
115
1245
            childsize.gx_rectangle_right = (GX_VALUE)(childsize.gx_rectangle_left + width - 1);
116
1245
            _gx_widget_resize(child, &childsize);
117
1245
            childsize.gx_rectangle_left = (GX_VALUE)(childsize.gx_rectangle_right + 1);
118
        }
119
1289
        child = child -> gx_widget_next;
120
    }
121
122
    /* calculate number of visible columns, needed for scrolling info */
123
124
223
    if (horizontal_list -> gx_horizontal_list_child_width > 0)
125
    {
126
197
        _gx_window_client_width_get((GX_WINDOW *)horizontal_list, &client_width);
127
197
        horizontal_list -> gx_horizontal_list_visible_columns = (GX_VALUE)((client_width + horizontal_list -> gx_horizontal_list_child_width - 1) /
128
197
                                                                           horizontal_list -> gx_horizontal_list_child_width);
129
    }
130
    else
131
    {
132
26
        horizontal_list -> gx_horizontal_list_visible_columns = 1;
133
    }
134
223
    return(GX_SUCCESS);
135
}
136