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 /**   Vertical List (List)                                                */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_widget.h"
29 #include "gx_window.h"
30 #include "gx_system.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_vertical_list_children_position                 PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function positions the children for the vertical list          */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    vertical_list                         Vertical list control block   */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    status                                Completion status             */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _gx_widget_height_get                 retrieves the height of the   */
58 /*                                            widget                      */
59 /*    _gx_widget_resize                     resizes the widget            */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application Code                                                    */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
70 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_gx_vertical_list_children_position(GX_VERTICAL_LIST * vertical_list)74 UINT _gx_vertical_list_children_position(GX_VERTICAL_LIST *vertical_list)
75 {
76 GX_RECTANGLE childsize = vertical_list -> gx_window_client;
77 GX_WIDGET   *child = vertical_list -> gx_widget_first_child;
78 INT          index    = vertical_list -> gx_vertical_list_top_index;
79 GX_VALUE     height;
80 GX_VALUE     client_height;
81 
82     vertical_list -> gx_vertical_list_child_height = 0;
83     vertical_list -> gx_vertical_list_child_count = 0;
84 
85     while (child)
86     {
87         if (!(child -> gx_widget_status & GX_STATUS_NONCLIENT))
88         {
89             /* increment child count */
90             vertical_list -> gx_vertical_list_child_count++;
91 
92             /* assign this child's id */
93 
94             if (!(child -> gx_widget_id))
95             {
96                 child -> gx_widget_id = (USHORT)(LIST_CHILD_ID_START + vertical_list -> gx_vertical_list_child_count);
97             }
98 
99             if (index == vertical_list -> gx_vertical_list_selected)
100             {
101                 child -> gx_widget_style |= GX_STYLE_DRAW_SELECTED;
102             }
103             else
104             {
105                 child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
106             }
107             index++;
108 
109             child -> gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS;
110 
111             /* pick up child item height, needed for scrolling */
112             _gx_widget_height_get(child, &height);
113             if (height > vertical_list -> gx_vertical_list_child_height)
114             {
115                 vertical_list -> gx_vertical_list_child_height = height;
116             }
117 
118             /* move this child into position */
119             childsize.gx_rectangle_bottom = (GX_VALUE)(childsize.gx_rectangle_top + height - 1);
120             _gx_widget_resize(child, &childsize);
121             childsize.gx_rectangle_top = (GX_VALUE)(childsize.gx_rectangle_bottom + 1);
122         }
123         child = child -> gx_widget_next;
124     }
125 
126     /* calculate number of visible rows, needed for scrolling info */
127     if (vertical_list -> gx_vertical_list_child_height > 0)
128     {
129         _gx_window_client_height_get((GX_WINDOW *)vertical_list, &client_height);
130         vertical_list -> gx_vertical_list_visible_rows = (GX_VALUE)((client_height + vertical_list -> gx_vertical_list_child_height - 1) /
131                                                                     vertical_list -> gx_vertical_list_child_height);
132     }
133     else
134     {
135         vertical_list -> gx_vertical_list_visible_rows = 1;
136     }
137 
138     return(GX_SUCCESS);
139 }
140 
141