GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_window_execute.c Lines: 59 59 100.0 %
Date: 2024-12-05 08:52:37 Branches: 30 30 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
/**   Window Management (Window)                                          */
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_window.h"
30
#include "gx_utility.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_window_execute                                  PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function modally executes a window.                            */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    window                                Window's widget control block */
50
/*    return_ptr                            return value                  */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    status                                Completion status             */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    Application Code                                                    */
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
/*                                                                        */
72
/**************************************************************************/
73
9
UINT  _gx_window_execute(GX_WINDOW *window, ULONG *return_ptr)
74
{
75
9
UINT status = GX_SUCCESS;
76
9
UINT return_code = 0;
77
78
#ifdef GX_THREADX_BINDING
79
ULONG    event_memory[GX_EVENT_ULONGS];
80
#else
81
GX_EVENT event_memory;
82
#endif
83
84
GX_EVENT  *event_ptr;
85
GX_WIDGET *widget;
86
87
9
    if (window -> gx_widget_status & GX_STATUS_MODAL)
88
    {
89
1
        return GX_NO_CHANGE;
90
    }
91
92
8
    _gx_widget_status_add((GX_WIDGET *)window, GX_STATUS_MODAL);
93
94
    /* Loop to process GUIX events.  */
95
37
    while (!return_code)
96
    {
97
#ifdef GX_THREADX_BINDING
98
        /* Pickup event from event queue.  */
99
31
        status =  tx_queue_receive(&_gx_system_event_queue, &event_memory[0], TX_NO_WAIT);
100
101
        /* Was there an event?  */
102
31
        if (status == TX_QUEUE_EMPTY)
103
        {
104
            /* No event to process, so re-draw dirty widgets */
105
30
            _gx_system_canvas_refresh();
106
107
            /* Now block this thread until an event is received.  */
108
30
            status = tx_queue_receive(&_gx_system_event_queue, &event_memory[0], TX_WAIT_FOREVER);
109
30
            if (status == TX_SUCCESS)
110
            {
111
28
                status = GX_SUCCESS;
112
            }
113
        }
114
#else
115
        /* here for generic RTOS binding */
116
        status = GX_EVENT_POP(&event_memory, GX_FALSE);
117
        if (status == GX_FAILURE)
118
        {
119
            _gx_system_canvas_refresh();
120
            status = GX_EVENT_POP(&event_memory, GX_TRUE);
121
        }
122
#endif
123
124
        /* Check for a successful status.  */
125
31
        if (status == GX_SUCCESS)
126
        {
127
            /* Setup a pointer to the event.  */
128
29
            event_ptr =  (GX_EVENT *)(&event_memory);
129
130


29
            switch (event_ptr -> gx_event_type)
131
            {
132
            /* Determine if a redraw event is present.  */
133
13
            case GX_EVENT_REDRAW:
134
                /* Yes, a redraw event is present, detect and process the dirty area(s).  */
135
13
                widget = (GX_WIDGET *)_gx_system_root_window_created_list;
136
39
                while (widget)
137
                {
138
26
                    _gx_system_dirty_mark(widget);
139
26
                    widget = widget -> gx_widget_next;
140
                }
141
13
                break;
142
143
2
            case GX_EVENT_TIMER:
144
2
                if (event_ptr -> gx_event_target == GX_NULL)
145
                {
146
                    /* the event is from gx_system_timer_expiration */
147
1
                    _gx_system_timer_update(event_ptr -> gx_event_payload.gx_event_ulongdata);
148
                }
149
                else
150
                {
151
1
                    return_code = _gx_system_event_dispatch(event_ptr);
152
                }
153
2
                break;
154
155
6
            case GX_EVENT_PEN_DOWN:
156
            case GX_EVENT_PEN_UP:
157
            case GX_EVENT_PEN_DRAG:
158

10
                if (_gx_system_capture_count > 0 ||
159
4
                    _gx_utility_rectangle_point_detect(&window -> gx_widget_size, event_ptr -> gx_event_payload.gx_event_pointdata))
160
                {
161
3
                    return_code = _gx_system_event_dispatch(event_ptr);
162
                }
163
6
                break;
164
165
1
            case GX_EVENT_TERMINATE:
166
1
                _gx_system_event_send(event_ptr);
167
1
                return_code = GX_EVENT_TERMINATE;
168
1
                break;
169
170
1
            case GX_EVENT_HIDE:
171
1
                _gx_system_event_dispatch(event_ptr);
172
1
                return_code = GX_EVENT_HIDE;
173
1
                break;
174
175
1
            case GX_EVENT_CLOSE:
176
1
                _gx_system_event_dispatch(event_ptr);
177
1
                return_code = GX_EVENT_CLOSE;
178
1
                break;
179
180
1
            case 0:
181
                /* event has been purged */
182
1
                break;
183
184
4
            default:
185
                /* Dispatch the event to GUIX proper window/widget.  */
186
4
                return_code = _gx_system_event_dispatch(event_ptr);
187
4
                break;
188
            }
189
        }
190
        else
191
        {
192
            /* Error receiving event - call system error handler.  */
193
2
            _gx_system_error_process(GX_SYSTEM_EVENT_RECEIVE_ERROR);
194
195
            /* Return to exit the system thread.  */
196
197
2
            _gx_widget_status_remove((GX_WIDGET *)window, GX_STATUS_MODAL);
198
199
2
            if (return_ptr)
200
            {
201
1
                *return_ptr = 0;
202
            }
203
2
            return GX_SYSTEM_EVENT_RECEIVE_ERROR;
204
        }
205
    }
206
207
6
    _gx_widget_status_remove((GX_WIDGET *)window, GX_STATUS_MODAL);
208
209
6
    if (return_ptr)
210
    {
211
3
        *return_ptr = return_code;
212
    }
213
214
6
    _gx_widget_detach((GX_WIDGET *)window);
215
6
    return GX_SUCCESS;
216
}
217