GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_system_input_release.c Lines: 27 27 100.0 %
Date: 2024-12-05 08:52:37 Branches: 14 14 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
/**   System Management (System)                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_widget.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_system_input_release                            PORTABLE C      */
36
/*                                                           6.2.1        */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    Release previously captured input events                            */
44
/*                                                                        */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    owner                                 Widget that releases input    */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    status                                Return status                 */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*    _GX_ENTER_CRITICAL                    Enter critical section        */
57
/*    _gx_widget_status_remove              Remove a flag from the widget */
58
/*    _GX_EXIT_CRITICAL                     Exit critical section         */
59
/*                                                                        */
60
/*  CALLED BY                                                             */
61
/*                                                                        */
62
/*    GUIX Internal 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
/*  07-29-2022     Kenneth Maxwell          Modified comment(s),          */
72
/*                                            optimized logic and ensured */
73
/*                                            released stack entries are  */
74
/*                                            reset to NULL,              */
75
/*                                            resulting in version 6.1.12 */
76
/*  03-08-2023     Ting Zhu                 Modified comment(s),          */
77
/*                                            improved logic,             */
78
/*                                            resulting in version 6.2.1  */
79
/*                                                                        */
80
/**************************************************************************/
81
82
3762
UINT _gx_system_input_release(GX_WIDGET *owner)
83
{
84
3762
UINT        status = GX_PTR_ERROR;
85
GX_WIDGET **stack;
86
INT         current;
87
INT         top;
88
89
3762
    GX_ENTER_CRITICAL
90
3762
    if (_gx_system_capture_count > 0)
91
    {
92
3755
        if (owner -> gx_widget_status & GX_STATUS_OWNS_INPUT)
93
        {
94
3754
            stack = _gx_system_input_capture_stack;
95
3754
            top = _gx_system_capture_count - 1;
96
3754
            current = 0;
97
98
3755
            while (current <= top)
99
            {
100
3754
                if (stack[current] == owner)
101
                {
102
3753
                    _gx_widget_status_remove(owner, GX_STATUS_OWNS_INPUT);
103
3753
                    _gx_system_capture_count--;
104
3753
                    status = GX_SUCCESS;
105
3753
                    break;
106
                }
107
1
                current++;
108
            }
109
110
3754
            if (status == GX_SUCCESS)
111
            {
112
                /* collapse the stack if this entry was in the middle */
113
3871
                while (current < top)
114
                {
115
118
                    stack[current] = stack[current + 1];
116
118
                    current++;
117
                }
118
3753
                stack[current] = GX_NULL;
119
120
3753
                if (top > 0)
121
                {
122
118
                    _gx_system_input_owner = stack[top - 1];
123
                }
124
                else
125
                {
126
3635
                    _gx_system_input_owner = GX_NULL;
127
                }
128
            }
129
        }
130
        else
131
        {
132
1
            status = GX_NO_CHANGE;
133
        }
134
    }
135
    else
136
    {
137
7
        status = GX_NO_CHANGE;
138
    }
139
140
3762
    GX_EXIT_CRITICAL
141
3762
    return status;
142
}
143