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 /**   Widget Management (Widget)                                          */
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 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _gx_widget_hide                                     PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Kenneth Maxwell, Microsoft Corporation                              */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function hides the widget.                                     */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    widget                                Pointer to widget             */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    None                                                                */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    [gx_widget_event_process_function]    Call widget event processing  */
56 /*    _gx_system_dirty_partial_add          Mark the parent dirty         */
57 /*    _gx_window_view_update_detect         Update viewports if needed    */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    Application 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_hide(GX_WIDGET * widget)72 UINT _gx_widget_hide(GX_WIDGET *widget)
73 {
74 GX_EVENT   hide_event;
75 GX_WINDOW *win;
76 GX_WIDGET *next;
77 
78     widget -> gx_widget_status |= GX_STATUS_HIDDEN;
79 
80     if (widget -> gx_widget_status & GX_STATUS_VISIBLE)
81     {
82         /* Send a GX_EVENT_HIDE event to widget and all children of the widget.  */
83         hide_event.gx_event_type = GX_EVENT_HIDE;
84         hide_event.gx_event_target = GX_NULL;
85         hide_event.gx_event_sender = 0;
86 
87         /* Call widget's event processing.  */
88         widget -> gx_widget_event_process_function(widget, &hide_event);
89 
90         if (widget -> gx_widget_status & GX_STATUS_HAS_FOCUS)
91         {
92             if(widget -> gx_widget_nav_next == widget)
93             {
94                 /* Current widget is the last widget in navigation order, move focus to its parent. */
95                 next = widget -> gx_widget_parent;
96             }
97             else
98             {
99                 /* Move focus to the next widget in navigation order. */
100                 next  = widget -> gx_widget_nav_next;
101             }
102 
103             if (next)
104             {
105                 _gx_system_focus_claim(next);
106             }
107         }
108 
109         if (widget -> gx_widget_parent)
110         {
111             _gx_system_dirty_partial_add(widget -> gx_widget_parent, &widget -> gx_widget_size);
112 
113             /* if this widget was part of navigation order, re-create nav order list */
114             if (widget -> gx_widget_status & GX_STATUS_ACCEPTS_FOCUS)
115             {
116                 _gx_widget_nav_order_initialize(widget -> gx_widget_parent);
117             }
118         }
119 
120         if (widget -> gx_widget_type >= GX_TYPE_WINDOW)
121         {
122             win = (GX_WINDOW *)widget;
123             if (win -> gx_window_views)
124             {
125                 _gx_system_views_free(win -> gx_window_views);
126                 win -> gx_window_views = GX_NULL;
127             }
128             _gx_window_view_update_detect((GX_WINDOW *)widget);
129         }
130 
131     }
132 
133 
134     return(GX_SUCCESS);
135 }
136 
137