GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_nav_order_initialize.c Lines: 44 44 100.0 %
Date: 2026-08-28 02:37:13 Branches: 38 38 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026 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
/**   Widget Management (Widget)                                          */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
#include "gx_widget.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_widget_nav_order_initialize                     PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function configures next/previous navigation order.            */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    widget                                Widget control block          */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    status                                Completion status             */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*                                                                        */
57
/*  CALLED BY                                                             */
58
/*                                                                        */
59
/*    GUIX Internal Code                                                  */
60
/*                                                                        */
61
/**************************************************************************/
62
7530
VOID _gx_widget_nav_order_initialize(GX_WIDGET *widget)
63
{
64
GX_WIDGET *winner;
65
GX_WIDGET *child;
66
7530
GX_WIDGET *first_stop = NULL;
67
7530
GX_WIDGET *last_stop = NULL;
68
7530
GX_BOOL    assign_default_focus = GX_TRUE;
69
70
7530
    child = widget -> gx_widget_first_child;
71
72
    /* test to see if any child already has default focus status flag */
73
✓✓
46348
    while (child)
74
    {
75
✓✓
38818
        if (assign_default_focus)
76
        {
77
✓✓
30528
            if (child -> gx_widget_status & GX_STATUS_DEFAULT_FOCUS)
78
            {
79
2657
                assign_default_focus = GX_FALSE;
80
            }
81
        }
82
        else
83
        {
84
            /* make sure only one child has default focus flag */
85
8290
            child -> gx_widget_status &= ~GX_STATUS_DEFAULT_FOCUS;
86
        }
87
88
38818
        child -> gx_widget_nav_next = GX_NULL;
89
38818
        child -> gx_widget_nav_previous = GX_NULL;
90
38818
        child = child -> gx_widget_next;
91
    }
92
93
    /* loop through child widgets looking for
94
       the top-left child and assigning the navigation order
95
       in left-to-right top-to-bottom order.
96
     */
97
98
    do
99
    {
100
33058
        child = widget -> gx_widget_first_child;
101
33058
        winner = GX_NULL;
102
103
✓✓
423220
        while (child)
104
        {
105
✓✓✓✓
390162
            if (child == last_stop || (child -> gx_widget_status & GX_STATUS_VISIBLE) == 0)
106
            {
107
35528
                child = child -> gx_widget_next;
108
35528
                continue;
109
            }
110
111
✓✓
354634
            if (!child -> gx_widget_nav_next)
112
            {
113
✓✓
229577
                if ((child -> gx_widget_status & GX_STATUS_ACCEPTS_FOCUS) &&
114
✓✓
150596
                    !(child -> gx_widget_status & GX_STATUS_NONCLIENT))
115
                {
116
✓✓
150585
                    if (winner)
117
                    {
118
✓✓
125057
                        if (child -> gx_widget_size.gx_rectangle_top < winner -> gx_widget_size.gx_rectangle_top)
119
                        {
120
14427
                            winner = child;
121
                        }
122
                        else
123
                        {
124
✓✓
110630
                            if (child -> gx_widget_size.gx_rectangle_top == winner -> gx_widget_size.gx_rectangle_top &&
125
✓✓
9552
                                child -> gx_widget_size.gx_rectangle_left < winner -> gx_widget_size.gx_rectangle_left)
126
                            {
127
543
                                winner = child;
128
                            }
129
                        }
130
                    }
131
                    else
132
                    {
133
25528
                        winner = child;
134
                    }
135
                }
136
            }
137
138
354634
            child = child -> gx_widget_next;
139
        }
140
141
✓✓
33058
        if (winner)
142
        {
143
✓✓
25528
            if (!first_stop)
144
            {
145
5757
                first_stop = winner;
146
147
✓✓
5757
                if (assign_default_focus)
148
                {
149
3229
                    first_stop -> gx_widget_status |= GX_STATUS_DEFAULT_FOCUS;
150
                }
151
            }
152
153
✓✓
25528
            if (last_stop)
154
            {
155
19771
                winner -> gx_widget_nav_previous = last_stop;
156
19771
                last_stop -> gx_widget_nav_next = winner;
157
            }
158
25528
            last_stop = winner;
159
        }
160
✓✓
33058
    } while (winner);
161
162
    /* loop the last in the order back to the first */
163
✓✓
7530
    if (last_stop)
164
    {
165
5757
        last_stop -> gx_widget_nav_next = first_stop;
166
5757
        first_stop -> gx_widget_nav_previous = last_stop;
167
    }
168
7530
}
169