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 /**   Vertical List (List)                                                */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_widget.h"
28 #include "gx_window.h"
29 #include "gx_system.h"
30 #include "gx_utility.h"
31 /* #include "gx_scrollbar.h"  */
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_vertical_list_down_wrap                         PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function scrolls down the vertical list.                       */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    list                                  Vertical list control block   */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    None                                                                */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _gx_last_client_child_get             Get the last client child     */
58 /*    _gx_first_client_child_get            Get the first client child    */
59 /*    _gx_widget_style_remove               Remove a style flag           */
60 /*    _gx_widget_back_attach                Attach a widget to the back   */
61 /*    _gx_widget_shift                      Relocate a widget             */
62 /*    [gx_vertical_list_callback]           Vertical list callback        */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    GUIX Internal Code                                                  */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
73 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_gx_vertical_list_down_wrap(GX_VERTICAL_LIST * list)77 VOID _gx_vertical_list_down_wrap(GX_VERTICAL_LIST *list)
78 {
79 GX_WIDGET   *test;
80 GX_WIDGET   *check;
81 GX_BOOL      moving = GX_TRUE;
82 GX_RECTANGLE newpos;
83 
84     while (moving)
85     {
86         moving = GX_FALSE;
87 
88         if ((list -> gx_vertical_list_top_index > 0) ||
89             (list -> gx_widget_style & GX_STYLE_WRAP))
90         {
91             /* scrolling down, see if my bottom widget can be moved to the top: */
92             test = _gx_widget_last_client_child_get((GX_WIDGET *)list);
93 
94             if (test)
95             {
96                 if ((test -> gx_widget_size.gx_rectangle_top > list -> gx_widget_size.gx_rectangle_bottom))
97                 {
98                     /* bottom widget is below my client area, move it to the top: */
99                     moving = GX_TRUE;
100                     list -> gx_vertical_list_top_index--;
101 
102                     /* Wrap index. */
103                     if (list -> gx_vertical_list_top_index < 0)
104                     {
105                         list -> gx_vertical_list_top_index  = list -> gx_vertical_list_total_rows - 1;
106                     }
107 
108                     check = _gx_widget_first_client_child_get((GX_WIDGET *)list);
109 
110                     if (check)
111                     {
112                         _gx_widget_detach(test);
113                         newpos = test -> gx_widget_size;
114                         _gx_utility_rectangle_shift(&newpos, 0, (GX_VALUE)(-(newpos.gx_rectangle_bottom - check -> gx_widget_size.gx_rectangle_top + 1)));
115                         _gx_widget_resize(test, &newpos);
116 
117                         list -> gx_vertical_list_callback(list, test, list -> gx_vertical_list_top_index);
118                         if (list -> gx_vertical_list_selected == list -> gx_vertical_list_top_index)
119                         {
120                             test -> gx_widget_style |=  GX_STYLE_DRAW_SELECTED;
121                         }
122                         else
123                         {
124                             test -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
125                         }
126                         _gx_widget_back_attach((GX_WIDGET *)list, test);
127                     }
128                     else
129                     {
130                         break;
131                     }
132                 }
133             }
134         }
135     }
136 }
137 
138