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 /**   Window Management (Window)                                          */
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 #include "gx_utility.h"
32 #include "gx_scrollbar.h"
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _gx_horizontal_list_total_columns_set               PORTABLE C      */
39 /*                                                           6.1.10       */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Kenneth Maxwell, Microsoft Corporation                              */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function assigns the number of list columns                    */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    vertical_list                         Vertical list widget control  */
51 /*                                          block                         */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    None                                                                */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_system_lock                       Obtain GUIX system lock       */
60 /*    _gx_system_unlock                     Release GUIX system lock      */
61 /*    _gx_first_client_child_get            Get the first client child    */
62 /*    _gx_window_scrollbar_find             Find the scrollbar            */
63 /*    _gx_scrollbar_reset                   Reset the schollbar           */
64 /*    _gx_system_dirty_mark                 Mark the widget dirty         */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    GUIX Internal Code                                                  */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
75 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*  01-31-2022     Ting Zhu                 Modified comment(s),          */
78 /*                                            improved logic,             */
79 /*                                            resulting in version 6.1.10 */
80 /*                                                                        */
81 /**************************************************************************/
_gx_horizontal_list_total_columns_set(GX_HORIZONTAL_LIST * list,INT count)82 UINT _gx_horizontal_list_total_columns_set(GX_HORIZONTAL_LIST *list, INT count)
83 {
84 INT           page_index;
85 INT           index;
86 GX_WIDGET    *test;
87 GX_SCROLLBAR *pScroll;
88 
89     _gx_system_lock();
90 
91     /* Update total count of rows. */
92     list -> gx_horizontal_list_total_columns = count;
93 
94     /* Update selected index. */
95     if (list -> gx_horizontal_list_selected < 0)
96     {
97         list -> gx_horizontal_list_selected = 0;
98     }
99 
100     if (list -> gx_horizontal_list_selected > count - 1)
101     {
102         list -> gx_horizontal_list_selected = count - 1;
103     }
104 
105     /* Calculate current page index. */
106     page_index = list -> gx_horizontal_list_top_index;
107 
108     test = _gx_widget_first_client_child_get((GX_WIDGET *)list);
109 
110     while (test && (test -> gx_widget_size.gx_rectangle_right <= list -> gx_widget_size.gx_rectangle_left))
111     {
112         page_index++;
113         test = _gx_widget_next_client_child_get(test);
114     }
115 
116     /* Calculate new page index */
117     if (page_index + list -> gx_horizontal_list_visible_columns > count)
118     {
119         if (count > list -> gx_horizontal_list_visible_columns)
120         {
121             page_index = count - list -> gx_horizontal_list_visible_columns;
122         }
123         else
124         {
125             page_index = 0;
126         }
127     }
128 
129     /* Add idle children back to horizontal list.  */
130     if (list -> gx_horizontal_list_idle_child_list)
131     {
132         while (list -> gx_horizontal_list_idle_child_list)
133         {
134             test = list -> gx_horizontal_list_idle_child_list;
135             list -> gx_horizontal_list_idle_child_list = list -> gx_horizontal_list_idle_child_list -> gx_widget_next;
136 
137             _gx_widget_attach((GX_WIDGET *)list, test);
138             list -> gx_horizontal_list_child_count++;
139         }
140     }
141 
142     /* Check whether list child count is larger than count. */
143     while (list -> gx_horizontal_list_child_count > count)
144     {
145         test = _gx_widget_last_client_child_get((GX_WIDGET *)list);
146 
147         if (test)
148         {
149             _gx_widget_detach(test);
150 
151             /* Put detached widget to idle list.  */
152             test -> gx_widget_next = list -> gx_horizontal_list_idle_child_list;
153             list -> gx_horizontal_list_idle_child_list = test;
154             list -> gx_horizontal_list_child_count--;
155         }
156         else
157         {
158             return GX_FAILURE;
159         }
160     }
161 
162     list -> gx_horizontal_list_top_index = 0;
163     index = 0;
164     test = _gx_widget_first_client_child_get((GX_WIDGET *)list);
165 
166     while (test)
167     {
168         list -> gx_horizontal_list_callback(list, test, index++);
169 
170         test = _gx_widget_next_client_child_get(test);
171     }
172 
173     /* Reposition child widgets.  */
174     _gx_horizontal_list_children_position(list);
175 
176 
177     /* Make new page index visible */
178     _gx_horizontal_list_page_index_set(list, page_index);
179 
180     _gx_window_scrollbar_find((GX_WINDOW *)list, GX_TYPE_HORIZONTAL_SCROLL, &pScroll);
181 
182     if (pScroll)
183     {
184         _gx_scrollbar_reset(pScroll, GX_NULL);
185     }
186 
187     _gx_system_unlock();
188 
189     /* Refresh screen. */
190     if (list -> gx_widget_status & GX_STATUS_VISIBLE)
191     {
192         _gx_system_dirty_mark((GX_WIDGET *)list);
193     }
194     return GX_SUCCESS;
195 }
196 
197