GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_child_focus_assign.c Lines: 26 26 100.0 %
Date: 2026-03-06 19:21:09 Branches: 24 24 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_child_focus_assign                       PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function processes events for the specified widget.            */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    widget                                Widget control block          */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    status                                Completion status             */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*    gx_system_focus_claim()                                             */
57
/*                                                                        */
58
/*  CALLED BY                                                             */
59
/*                                                                        */
60
/*    Application Code                                                    */
61
/*    GUIX Internal Code                                                  */
62
/*                                                                        */
63
/**************************************************************************/
64
4181
VOID _gx_widget_child_focus_assign(GX_WIDGET *parent)
65
{
66
4181
GX_WIDGET *winner = GX_NULL;
67
4181
GX_WIDGET *test = parent -> gx_widget_first_child;
68
69
    /* does any child have default focus status? */
70
22116
    while (test)
71
    {
72
18728
        if (test -> gx_widget_status & GX_STATUS_DEFAULT_FOCUS)
73
        {
74
3910
            winner = test;
75
76
3910
            if (winner -> gx_widget_status & GX_STATUS_NAV_PARENT)
77
            {
78
793
                break;
79
            }
80
            else
81
            {
82
                /* keep drilling down to children of children */
83
3117
                test = winner -> gx_widget_first_child;
84
            }
85
        }
86
        else
87
        {
88
14818
            test = test -> gx_widget_next;
89
        }
90
    }
91
92
4181
    if (winner)
93
    {
94
3607
        if (!(winner -> gx_widget_status & GX_STATUS_HAS_FOCUS) ||
95
3
            winner != _gx_system_focus_owner)
96
        {
97
3605
            _gx_system_focus_claim(winner);
98
        }
99
3607
        return;
100
    }
101
102
    /* nothing has default focus flag, so just try to give focus to first child that accepts focus */
103
574
    test = parent -> gx_widget_first_child;
104
105
1636
    while (test)
106
    {
107
1063
        if ((test -> gx_widget_status & GX_STATUS_ACCEPTS_FOCUS) &&
108
25
            !(test -> gx_widget_status & GX_STATUS_NONCLIENT))
109
        {
110
24
            winner = test;
111
112
24
            if (winner -> gx_widget_status & GX_STATUS_NAV_PARENT)
113
            {
114
1
                break;
115
            }
116
            else
117
            {
118
23
                test = winner -> gx_widget_first_child;
119
            }
120
        }
121
        else
122
        {
123
1039
            test = test -> gx_widget_next;
124
        }
125
    }
126
127

574
    if (winner && !(winner -> gx_widget_status & GX_STATUS_HAS_FOCUS))
128
    {
129
12
        _gx_system_focus_claim(winner);
130
    }
131
}
132