GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_vertical_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
/**   Vertical 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_vertical_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 vertical list          */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    vertical_list                         Vertical list control block   */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    status                                Completion status             */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*    _gx_widget_height_get                 retrieves the height of the   */
57
/*                                            widget                      */
58
/*    _gx_widget_resize                     resizes the widget            */
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
/*                                                                        */
72
/**************************************************************************/
73
223
UINT _gx_vertical_list_children_position(GX_VERTICAL_LIST *vertical_list)
74
{
75
223
GX_RECTANGLE childsize = vertical_list -> gx_window_client;
76
223
GX_WIDGET   *child = vertical_list -> gx_widget_first_child;
77
223
INT          index    = vertical_list -> gx_vertical_list_top_index;
78
GX_VALUE     height;
79
GX_VALUE     client_height;
80
81
223
    vertical_list -> gx_vertical_list_child_height = 0;
82
223
    vertical_list -> gx_vertical_list_child_count = 0;
83
84
2370
    while (child)
85
    {
86
2147
        if (!(child -> gx_widget_status & GX_STATUS_NONCLIENT))
87
        {
88
            /* increment child count */
89
2085
            vertical_list -> gx_vertical_list_child_count++;
90
91
            /* assign this child's id */
92
93
2085
            if (!(child -> gx_widget_id))
94
            {
95
1042
                child -> gx_widget_id = (USHORT)(LIST_CHILD_ID_START + vertical_list -> gx_vertical_list_child_count);
96
            }
97
98
2085
            if (index == vertical_list -> gx_vertical_list_selected)
99
            {
100
207
                child -> gx_widget_style |= GX_STYLE_DRAW_SELECTED;
101
            }
102
            else
103
            {
104
1878
                child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
105
            }
106
2085
            index++;
107
108
2085
            child -> gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS;
109
110
            /* pick up child item height, needed for scrolling */
111
2085
            _gx_widget_height_get(child, &height);
112
2085
            if (height > vertical_list -> gx_vertical_list_child_height)
113
            {
114
209
                vertical_list -> gx_vertical_list_child_height = height;
115
            }
116
117
            /* move this child into position */
118
2085
            childsize.gx_rectangle_bottom = (GX_VALUE)(childsize.gx_rectangle_top + height - 1);
119
2085
            _gx_widget_resize(child, &childsize);
120
2085
            childsize.gx_rectangle_top = (GX_VALUE)(childsize.gx_rectangle_bottom + 1);
121
        }
122
2147
        child = child -> gx_widget_next;
123
    }
124
125
    /* calculate number of visible rows, needed for scrolling info */
126
223
    if (vertical_list -> gx_vertical_list_child_height > 0)
127
    {
128
209
        _gx_window_client_height_get((GX_WINDOW *)vertical_list, &client_height);
129
209
        vertical_list -> gx_vertical_list_visible_rows = (GX_VALUE)((client_height + vertical_list -> gx_vertical_list_child_height - 1) /
130
209
                                                                    vertical_list -> gx_vertical_list_child_height);
131
    }
132
    else
133
    {
134
14
        vertical_list -> gx_vertical_list_visible_rows = 1;
135
    }
136
137
223
    return(GX_SUCCESS);
138
}
139