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 /**   List Management (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 #include "gx_utility.h"
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_vertical_list_up_wrap                           PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function scrolls up the vertical list.                         */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    vertical_list                         Vertical list control block   */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    None                                                                */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _gx_first_client_child_get            Get the first client child    */
58 /*    _gx_last_client_child_get             Get the last client child     */
59 /*    _gx_utility_rectangle_shift           Move a rectangle              */
60 /*    [gx_vertical_list_callback]           Invoke the list callback      */
61 /*                                            routine                     */
62 /*    _gx_widget_resize                     Resize a widget               */
63 /*    _gx_widget_attach                     Attach a widget to its parent */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    _gx_vertical_list_scroll              Vertical list scroll function */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
74 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_gx_vertical_list_up_wrap(GX_VERTICAL_LIST * list)78 VOID _gx_vertical_list_up_wrap(GX_VERTICAL_LIST *list)
79 {
80 GX_WIDGET   *test;
81 GX_WIDGET   *check;
82 GX_BOOL      moving = GX_TRUE;
83 GX_RECTANGLE newpos;
84 INT          index;
85 
86     while (moving)
87     {
88         moving = GX_FALSE;
89 
90         if ((list -> gx_vertical_list_top_index + list -> gx_vertical_list_child_count < list -> gx_vertical_list_total_rows) ||
91             (list -> gx_widget_style & GX_STYLE_WRAP))
92         {
93             /* scrolling up. See if my top widget is already above my
94                client area: */
95 
96             test = _gx_widget_first_client_child_get((GX_WIDGET *)list);
97             if (test)
98             {
99                 if (test -> gx_widget_size.gx_rectangle_bottom < list -> gx_widget_size.gx_rectangle_top)
100                 {
101                     /* top widget is above my client area, move it to the bottom: */
102                     moving = GX_TRUE;
103                     check = _gx_widget_last_client_child_get((GX_WIDGET *)list);
104 
105                     _gx_widget_detach(test);
106 
107                     newpos = test -> gx_widget_size;
108                     _gx_utility_rectangle_shift(&newpos, 0, (GX_VALUE)(check -> gx_widget_size.gx_rectangle_bottom - newpos.gx_rectangle_top + 1));
109                     _gx_widget_resize(test, &newpos);
110 
111                     index = list -> gx_vertical_list_top_index + list -> gx_vertical_list_child_count;
112 
113                     /* Wrap index. */
114                     if (index >= list -> gx_vertical_list_total_rows)
115                     {
116                         index -= list -> gx_vertical_list_total_rows;
117                     }
118 
119                     list -> gx_vertical_list_callback(list, test, index);
120                     if (index == list -> gx_vertical_list_selected)
121                     {
122                         test -> gx_widget_style |=  GX_STYLE_DRAW_SELECTED;
123                     }
124                     else
125                     {
126                         test -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
127                     }
128                     _gx_widget_attach((GX_WIDGET *)list, test);
129                     list -> gx_vertical_list_top_index++;
130 
131                     /* Wrao page index.  */
132                     if (list -> gx_vertical_list_top_index >= list -> gx_vertical_list_total_rows)
133                     {
134                         list -> gx_vertical_list_top_index -= list -> gx_vertical_list_total_rows;
135                     }
136                 }
137             }
138         }
139     }
140 }
141 
142