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 /**   Tree View Management (Tree View)                                    */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_tree_view.h"
28 #include "gx_system.h"
29 #include "gx_widget.h"
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _gx_tree_view_selected_visible                      PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Kenneth Maxwell, Microsoft Corporation                              */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    Internal helper function to make selected item visible.             */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    tree                                  Pointer to the tree view      */
48 /*                                            control block               */
49 /*    selected                              New selected item             */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    status                                Completion status             */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _gx_tree_view_position                Reposition tree view childdren*/
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    _gx_tree_view_selected_set                                          */
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_tree_view_selected_visible(GX_TREE_VIEW * tree)72 static UINT _gx_tree_view_selected_visible(GX_TREE_VIEW *tree)
73 {
74 GX_WIDGET    *parent;
75 GX_WIDGET    *selected = tree -> gx_tree_view_selected;
76 GX_MENU_LIST *list;
77 
78     parent = selected -> gx_widget_parent;
79     while (parent != (GX_WIDGET *)tree)
80     {
81         if (parent -> gx_widget_type == GX_TYPE_MENU_LIST)
82         {
83             list = (GX_MENU_LIST *)parent;
84             list -> gx_menu_list_owner -> gx_widget_style |= GX_STYLE_MENU_EXPANDED;
85             parent = list -> gx_menu_list_owner;
86         }
87         else
88         {
89             parent = parent -> gx_widget_parent;
90         }
91     }
92 
93     _gx_tree_view_position(tree);
94 
95     return GX_SUCCESS;
96 }
97 
98 /**************************************************************************/
99 /*                                                                        */
100 /*  FUNCTION                                               RELEASE        */
101 /*                                                                        */
102 /*    _gx_tree_view_selected_set                          PORTABLE C      */
103 /*                                                           6.1          */
104 /*  AUTHOR                                                                */
105 /*                                                                        */
106 /*    Kenneth Maxwell, Microsoft Corporation                              */
107 /*                                                                        */
108 /*  DESCRIPTION                                                           */
109 /*                                                                        */
110 /*    This function set selected item for the specified tree view.        */
111 /*                                                                        */
112 /*  INPUT                                                                 */
113 /*                                                                        */
114 /*    tree                                  Pointer to the tree view      */
115 /*                                            control block               */
116 /*    selected                              New selected item             */
117 /*                                                                        */
118 /*  OUTPUT                                                                */
119 /*                                                                        */
120 /*    status                                Completion status             */
121 /*                                                                        */
122 /*  CALLS                                                                 */
123 /*                                                                        */
124 /*    _gx_system_dirty_mark                 Mark the widget area as dirty */
125 /*    _gx_widget_event_generate             Create an event and send it to*/
126 /*                                            the widget parent           */
127 /*    _gx_tree_view_selected_visible        Make selected item visible.   */
128 /*                                                                        */
129 /*  CALLED BY                                                             */
130 /*                                                                        */
131 /*    Application Code                                                    */
132 /*    GUIX Internal Code                                                  */
133 /*                                                                        */
134 /*  RELEASE HISTORY                                                       */
135 /*                                                                        */
136 /*    DATE              NAME                      DESCRIPTION             */
137 /*                                                                        */
138 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
139 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
140 /*                                            resulting in version 6.1    */
141 /*                                                                        */
142 /**************************************************************************/
_gx_tree_view_selected_set(GX_TREE_VIEW * tree,GX_WIDGET * selected)143 UINT  _gx_tree_view_selected_set(GX_TREE_VIEW *tree, GX_WIDGET *selected)
144 {
145     if (tree -> gx_tree_view_selected == selected)
146     {
147         return GX_SUCCESS;
148     }
149 
150     if (tree -> gx_tree_view_selected)
151     {
152         tree -> gx_tree_view_selected -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
153         _gx_system_dirty_mark(tree -> gx_tree_view_selected);
154     }
155 
156     selected -> gx_widget_style |= GX_STYLE_DRAW_SELECTED;
157 
158     tree -> gx_tree_view_selected = selected;
159 
160     if (tree -> gx_widget_id)
161     {
162         /* Generate tree select event. */
163         _gx_widget_event_generate((GX_WIDGET *)tree, GX_EVENT_TREE_SELECT, selected -> gx_widget_id);
164     }
165 
166     if (!(selected -> gx_widget_status & GX_STATUS_VISIBLE))
167     {
168         _gx_tree_view_selected_visible(tree);
169     }
170 
171     _gx_system_dirty_mark(selected);
172 
173     /* Return completion status code. */
174     return(GX_SUCCESS);
175 }
176