GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_nav_order_initialize.c Lines: 44 44 100.0 %
Date: 2026-03-06 19:21:09 Branches: 38 38 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
/**   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
7516
VOID _gx_widget_nav_order_initialize(GX_WIDGET *widget)
63
{
64
GX_WIDGET *winner;
65
GX_WIDGET *child;
66
7516
GX_WIDGET *first_stop = NULL;
67
7516
GX_WIDGET *last_stop = NULL;
68
7516
GX_BOOL    assign_default_focus = GX_TRUE;
69
70
7516
    child = widget -> gx_widget_first_child;
71
72
    /* test to see if any child already has default focus status flag */
73
46240
    while (child)
74
    {
75
38724
        if (assign_default_focus)
76
        {
77
30436
            if (child -> gx_widget_status & GX_STATUS_DEFAULT_FOCUS)
78
            {
79
2655
                assign_default_focus = GX_FALSE;
80
            }
81
        }
82
        else
83
        {
84
            /* make sure only one child has default focus flag */
85
8288
            child -> gx_widget_status &= ~GX_STATUS_DEFAULT_FOCUS;
86
        }
87
88
38724
        child -> gx_widget_nav_next = GX_NULL;
89
38724
        child -> gx_widget_nav_previous = GX_NULL;
90
38724
        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
32993
        child = widget -> gx_widget_first_child;
101
32993
        winner = GX_NULL;
102
103
422251
        while (child)
104
        {
105

389258
            if (child == last_stop || (child -> gx_widget_status & GX_STATUS_VISIBLE) == 0)
106
            {
107
35475
                child = child -> gx_widget_next;
108
35475
                continue;
109
            }
110
111
353783
            if (!child -> gx_widget_nav_next)
112
            {
113
228913
                if ((child -> gx_widget_status & GX_STATUS_ACCEPTS_FOCUS) &&
114
150358
                    !(child -> gx_widget_status & GX_STATUS_NONCLIENT))
115
                {
116
150347
                    if (winner)
117
                    {
118
124870
                        if (child -> gx_widget_size.gx_rectangle_top < winner -> gx_widget_size.gx_rectangle_top)
119
                        {
120
14407
                            winner = child;
121
                        }
122
                        else
123
                        {
124
110463
                            if (child -> gx_widget_size.gx_rectangle_top == winner -> gx_widget_size.gx_rectangle_top &&
125
9551
                                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
25477
                        winner = child;
134
                    }
135
                }
136
            }
137
138
353783
            child = child -> gx_widget_next;
139
        }
140
141
32993
        if (winner)
142
        {
143
25477
            if (!first_stop)
144
            {
145
5746
                first_stop = winner;
146
147
5746
                if (assign_default_focus)
148
                {
149
3220
                    first_stop -> gx_widget_status |= GX_STATUS_DEFAULT_FOCUS;
150
                }
151
            }
152
153
25477
            if (last_stop)
154
            {
155
19731
                winner -> gx_widget_nav_previous = last_stop;
156
19731
                last_stop -> gx_widget_nav_next = winner;
157
            }
158
25477
            last_stop = winner;
159
        }
160
32993
    } while (winner);
161
162
    /* loop the last in the order back to the first */
163
7516
    if (last_stop)
164
    {
165
5746
        last_stop -> gx_widget_nav_next = first_stop;
166
5746
        first_stop -> gx_widget_nav_previous = last_stop;
167
    }
168
7516
}
169