1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
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 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
68 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_gx_widget_child_focus_assign(GX_WIDGET * parent)72 VOID _gx_widget_child_focus_assign(GX_WIDGET *parent)
73 {
74 GX_WIDGET *winner = GX_NULL;
75 GX_WIDGET *test = parent -> gx_widget_first_child;
76 
77     /* does any child have default focus status? */
78     while (test)
79     {
80         if (test -> gx_widget_status & GX_STATUS_DEFAULT_FOCUS)
81         {
82             winner = test;
83 
84             if (winner -> gx_widget_status & GX_STATUS_NAV_PARENT)
85             {
86                 break;
87             }
88             else
89             {
90                 /* keep drilling down to children of children */
91                 test = winner -> gx_widget_first_child;
92             }
93         }
94         else
95         {
96             test = test -> gx_widget_next;
97         }
98     }
99 
100     if (winner)
101     {
102         if (!(winner -> gx_widget_status & GX_STATUS_HAS_FOCUS) ||
103             winner != _gx_system_focus_owner)
104         {
105             _gx_system_focus_claim(winner);
106         }
107         return;
108     }
109 
110     /* nothing has default focus flag, so just try to give focus to first child that accepts focus */
111     test = parent -> gx_widget_first_child;
112 
113     while (test)
114     {
115         if ((test -> gx_widget_status & GX_STATUS_ACCEPTS_FOCUS) &&
116             !(test -> gx_widget_status & GX_STATUS_NONCLIENT))
117         {
118             winner = test;
119 
120             if (winner -> gx_widget_status & GX_STATUS_NAV_PARENT)
121             {
122                 break;
123             }
124             else
125             {
126                 test = winner -> gx_widget_first_child;
127             }
128         }
129         else
130         {
131             test = test -> gx_widget_next;
132         }
133     }
134 
135     if (winner && !(winner -> gx_widget_status & GX_STATUS_HAS_FOCUS))
136     {
137         _gx_system_focus_claim(winner);
138     }
139 }
140 
141