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_capture                            PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Kenneth Maxwell, Microsoft Corporation                              */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    Temporarily direct all input events to specified widget             */
44 /*                                                                        */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    ownert                                Widget that wants to own      */
49 /*                                            input events                */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    widget added to capture stack                                       */
54 /*    widget receives GX_STATUS_OWNS_INPUT                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _GX_ENTER_CRITICAL                    Enter critical section        */
59 /*    _gx_widget_status_add                 Add status flag to the widget */
60 /*    _GX_EXIT_CRITICAL                     Exit critical section         */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    GUIX Internal Code                                                  */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
71 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
75 
_gx_system_input_capture(GX_WIDGET * owner)76 UINT _gx_system_input_capture(GX_WIDGET *owner)
77 {
78 GX_WIDGET **stackptr;
79 UINT        status = GX_SUCCESS;
80 
81     GX_ENTER_CRITICAL
82     if (_gx_system_capture_count < GX_MAX_INPUT_CAPTURE_NESTING)
83     {
84         if (!(owner -> gx_widget_status & GX_STATUS_OWNS_INPUT))
85         {
86             stackptr = _gx_system_input_capture_stack + _gx_system_capture_count;
87             *stackptr = owner;
88             _gx_widget_status_add(owner, GX_STATUS_OWNS_INPUT);
89             _gx_system_capture_count++;
90             _gx_system_input_owner = owner;
91         }
92         else
93         {
94             status = GX_NO_CHANGE;
95         }
96     }
97     else
98     {
99         status = GX_INPUT_CAPTURE_NESTING_EXCEEDED;
100     }
101 
102     GX_EXIT_CRITICAL
103     return status;
104 }
105 
106