GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_button_event_process.c Lines: 40 40 100.0 %
Date: 2024-12-05 08:52:37 Branches: 29 29 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
/**   Button Management (Button)                                          */
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
#include "gx_button.h"
30
#include "gx_utility.h"
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_button_event_process                            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 button.            */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    button                                Pointer to button control     */
49
/*                                            block                       */
50
/*    event_ptr                             Incoming event to process     */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    status                                Completion status             */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    [_gx_button_select_handler]           Button select callback        */
59
/*    _gx_system_input_capture              Assign system input widget    */
60
/*    _gx_system_input_release              Release system input widget   */
61
/*    [_gx_button_deselect_handler]         Widget-provided deselect      */
62
/*                                            handler routine             */
63
/*    _gx_widget_event_generate             Generate event to notify      */
64
/*                                             parent widget              */
65
/*    _gx_system_timer_stop                 Stop an active GUIX timer     */
66
/*    _gx_widget_event_process              Default widget event process  */
67
/*                                                                        */
68
/*  CALLED BY                                                             */
69
/*                                                                        */
70
/*    Application Code                                                    */
71
/*    GUIX Internal Code                                                  */
72
/*                                                                        */
73
/*  RELEASE HISTORY                                                       */
74
/*                                                                        */
75
/*    DATE              NAME                      DESCRIPTION             */
76
/*                                                                        */
77
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
78
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
79
/*                                            resulting in version 6.1    */
80
/*                                                                        */
81
/**************************************************************************/
82
19362
UINT  _gx_button_event_process(GX_BUTTON *button, GX_EVENT *event_ptr)
83
{
84
UINT       status;
85
19362
GX_WIDGET *widget = (GX_WIDGET *)button;
86
19362
GX_BOOL    generate_event = GX_FALSE;
87
88
    /* Default status to success.  */
89
19362
    status =  GX_SUCCESS;
90
91
    /* Process relative to the type of event.  */
92

19362
    switch (event_ptr -> gx_event_type)
93
    {
94
333
    case GX_EVENT_PEN_DOWN:
95
    case GX_EVENT_SELECT:
96
333
        if (widget -> gx_widget_style & GX_STYLE_ENABLED)
97
        {
98
332
            button -> gx_button_select_handler(widget);
99
332
            _gx_system_input_capture(widget);
100
        }
101
102
333
        if (event_ptr -> gx_event_type == GX_EVENT_PEN_DOWN)
103
        {
104
            /* Delivery event to parent here, _gx_widget_event_process handle GX_EVENT_PEN_DOWN to
105
               produce a GX_EVENT_CLICK event, if call _gx_widget_event_process here, 2 GX_EVENT_CLICK events will
106
               be sent.*/
107
256
            status = _gx_widget_event_to_parent(widget, event_ptr);
108
        }
109
333
        break;
110
111
132
    case GX_EVENT_PEN_UP:
112
132
        if (widget -> gx_widget_status & GX_STATUS_OWNS_INPUT)
113
        {
114
127
            _gx_system_input_release(widget);
115
116
127
            if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
117
            {
118
126
                if (_gx_utility_rectangle_point_detect(&widget -> gx_widget_size, event_ptr -> gx_event_payload.gx_event_pointdata))
119
                {
120
118
                    generate_event = GX_TRUE;
121
                }
122
126
                if (!(widget -> gx_widget_style & GX_STYLE_BUTTON_RADIO))
123
                {
124
121
                    button -> gx_button_deselect_handler(widget, generate_event);
125
                }
126
            }
127
        }
128
132
        status = _gx_widget_event_to_parent(widget, event_ptr);
129
132
        break;
130
131
131
    case GX_EVENT_DESELECT:
132
    case GX_EVENT_INPUT_RELEASE:
133
131
        if (widget -> gx_widget_status & GX_STATUS_OWNS_INPUT)
134
        {
135
100
            _gx_system_input_release(widget);
136
137
100
            if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
138
            {
139
99
                if (event_ptr -> gx_event_type == GX_EVENT_DESELECT)
140
                {
141
2
                    generate_event = GX_TRUE;
142
                }
143
99
                if (!(widget -> gx_widget_style & GX_STYLE_BUTTON_RADIO))
144
                {
145
98
                    button -> gx_button_deselect_handler(widget, generate_event);
146
                }
147
            }
148
        }
149
131
        break;
150
151
114
    case GX_EVENT_TIMER:
152
114
        if (event_ptr -> gx_event_payload.gx_event_timer_id == GX_BUTTON_TIMER)
153
        {
154
113
            if (widget -> gx_widget_style & GX_STYLE_BUTTON_REPEAT)
155
            {
156
112
                _gx_widget_event_generate(widget, GX_EVENT_CLICKED, widget -> gx_widget_id);
157
            }
158
            else
159
            {
160
1
                _gx_system_timer_stop(widget, GX_BUTTON_TIMER);
161
            }
162
        }
163
114
        break;
164
165
18652
    default:
166
167
        /* Call the widget default processing.  */
168
18652
        status =  _gx_widget_event_process(widget, event_ptr);
169
    }
170
171
    /* Return completion status.  */
172
19362
    return(status);
173
}
174