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

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