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 /**   Tree View Management (View)                                         */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_menu.h"
29 #include "gx_widget.h"
30 #include "gx_system.h"
31 #include "gx_tree_view.h"
32 #include "gx_window.h"
33 #include "gx_scrollbar.h"
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _gx_tree_view_position                              PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Kenneth Maxwell, Microsoft Corporation                              */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function positions a tree menu.                                */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    tree                                  Tree view control block       */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    status                                Completion status             */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_widget_first_client_child_get     Get the first client child    */
60 /*    _gx_widget_next_client_child_get      Get the next client child     */
61 /*    _gx_widget_height_get                 Get widget height             */
62 /*    _gx_widget_width_get                  Get widget width              */
63 /*    _gx_widget_resize                     Resize a widget               */
64 /*    _gx_menu_position                     Position a menu widget        */
65 /*    _gx_window_scrollbar_find             Find scrollbar for a window   */
66 /*    _gx_scrollbar_reset                   Reset scrollbar information   */
67 /*    _gx_widget_hide                       Hide a widget                 */
68 /*    _gx_widget_show                       Show a widget                 */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    Application Code                                                    */
73 /*    GUIX Internal Code                                                  */
74 /*                                                                        */
75 /*  RELEASE HISTORY                                                       */
76 /*                                                                        */
77 /*    DATE              NAME                      DESCRIPTION             */
78 /*                                                                        */
79 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
80 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
81 /*                                            resulting in version 6.1    */
82 /*                                                                        */
83 /**************************************************************************/
_gx_tree_view_position(GX_TREE_VIEW * tree)84 UINT  _gx_tree_view_position(GX_TREE_VIEW *tree)
85 {
86 GX_WIDGET    *child;
87 GX_RECTANGLE  size;
88 GX_RECTANGLE *client;
89 GX_VALUE      height;
90 GX_VALUE      width;
91 GX_VALUE      bottom;
92 GX_VALUE      max_right = 0;
93 GX_MENU_LIST *list;
94 GX_SCROLLBAR *scroll;
95 
96     client = &tree -> gx_window_client;
97 
98     size.gx_rectangle_left = (GX_VALUE)(client -> gx_rectangle_left + tree -> gx_tree_view_indentation + tree -> gx_tree_view_x_shift);
99     bottom = (GX_VALUE)(client -> gx_rectangle_top - 1 + tree -> gx_tree_view_y_shift);
100 
101     child = _gx_widget_first_client_child_get((GX_WIDGET *)tree);
102 
103     /* Reposition tree view items. */
104     while (child)
105     {
106         if (child -> gx_widget_type == GX_TYPE_MENU_LIST)
107         {
108             child = _gx_widget_next_client_child_get(child);
109             continue;
110         }
111 
112         _gx_widget_height_get(child, &height);
113         _gx_widget_width_get(child, &width);
114         size.gx_rectangle_top = (GX_VALUE)(bottom + 1);
115         size.gx_rectangle_bottom = (GX_VALUE)(size.gx_rectangle_top + height - 1);
116         size.gx_rectangle_right = (GX_VALUE)(size.gx_rectangle_left + width - 1);
117 
118         _gx_widget_resize((GX_WIDGET *)child, &size);
119 
120         if (child -> gx_widget_type == GX_TYPE_MENU)
121         {
122             _gx_menu_position((GX_MENU *)child, tree -> gx_tree_view_indentation);
123 
124             list = &((GX_MENU *)child) -> gx_menu_list;
125 
126             if (list -> gx_widget_parent && list -> gx_widget_first_child)
127             {
128                 bottom = list -> gx_widget_size.gx_rectangle_bottom;
129 
130                 if (list -> gx_widget_size.gx_rectangle_right > max_right)
131                 {
132                     max_right = list -> gx_widget_size.gx_rectangle_right;
133                 }
134             }
135             else
136             {
137                 if (list -> gx_widget_parent)
138                 {
139                     _gx_widget_detach((GX_WIDGET *)list);
140                 }
141 
142                 bottom = size.gx_rectangle_bottom;
143 
144                 if (size.gx_rectangle_right > max_right)
145                 {
146                     max_right = size.gx_rectangle_right;
147                 }
148             }
149         }
150         else
151         {
152             bottom = size.gx_rectangle_bottom;
153         }
154 
155         child -> gx_widget_status &= (ULONG)(~GX_STATUS_ACCEPTS_FOCUS);
156         child = _gx_widget_next_client_child_get(child);
157     }
158 
159     tree -> gx_tree_view_tree_width = (GX_VALUE)(max_right - (client -> gx_rectangle_left + tree -> gx_tree_view_x_shift) + 1);
160     tree -> gx_tree_view_tree_height = (GX_VALUE)(bottom - (client -> gx_rectangle_top + tree -> gx_tree_view_y_shift) + 1);
161 
162     _gx_window_scrollbar_find((GX_WINDOW *)tree, (USHORT)GX_TYPE_HORIZONTAL_SCROLL, &scroll);
163 
164     width = (GX_VALUE)(client -> gx_rectangle_right - client -> gx_rectangle_left + 1);
165     height = (GX_VALUE)(client -> gx_rectangle_bottom - client -> gx_rectangle_top + 1);
166 
167     if (scroll)
168     {
169         _gx_scrollbar_reset(scroll, GX_NULL);
170 
171         if (tree -> gx_tree_view_tree_width <= width)
172         {
173             _gx_widget_hide((GX_WIDGET *)scroll);
174         }
175         else
176         {
177             _gx_widget_show((GX_WIDGET *)scroll);
178         }
179     }
180 
181     _gx_window_scrollbar_find((GX_WINDOW *)tree, GX_TYPE_VERTICAL_SCROLL, &scroll);
182 
183     if (scroll)
184     {
185         _gx_scrollbar_reset(scroll, GX_NULL);
186 
187         if (tree -> gx_tree_view_tree_height <= height)
188         {
189             _gx_widget_hide((GX_WIDGET *)scroll);
190         }
191         else
192         {
193             _gx_widget_show((GX_WIDGET *)scroll);
194         }
195     }
196 
197     if ((tree -> gx_widget_style & GX_STYLE_TREE_VIEW_SHOW_ROOT_LINES) &&
198         (tree -> gx_widget_status & GX_STATUS_VISIBLE))
199     {
200         _gx_system_dirty_mark((GX_WIDGET *)tree);
201     }
202 
203     /* Return completion status code. */
204     return(GX_SUCCESS);
205 }
206 
207