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 /**   Horizontal 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 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_horizontal_list_right_wrap                      PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function scrolls down the horizontal list.                     */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    list                                  horizontal list widget control*/
49 /*                                            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_back_attach                Attach a widget to the back   */
60 /*    _gx_widget_shift                      Relocate a widget             */
61 /*    [gx_horizontal_list_callback]         Horizontal list callback      */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    _gx_horizontal_list_scroll                                          */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_gx_horizontal_list_right_wrap(GX_HORIZONTAL_LIST * list)76 VOID _gx_horizontal_list_right_wrap(GX_HORIZONTAL_LIST *list)
77 {
78 GX_WIDGET   *test;
79 GX_WIDGET   *check;
80 GX_BOOL      moving = GX_TRUE;
81 GX_RECTANGLE newpos;
82 
83     while (moving)
84     {
85         moving = GX_FALSE;
86 
87         if ((list -> gx_horizontal_list_top_index > 0) ||
88             (list -> gx_widget_style & GX_STYLE_WRAP))
89         {
90             /* scrolling down, see if my bottom widget can be moved to the top: */
91             test = _gx_widget_last_client_child_get((GX_WIDGET *)list);
92 
93             if (test)
94             {
95                 if (test -> gx_widget_size.gx_rectangle_left > list -> gx_widget_size.gx_rectangle_right)
96                 {
97                     /* right widget is to the right of my client area, move it to the top: */
98                     moving = GX_TRUE;
99                     list -> gx_horizontal_list_top_index--;
100 
101                     /* Wrap index. */
102                     if (list -> gx_horizontal_list_top_index < 0)
103                     {
104                         list -> gx_horizontal_list_top_index = list -> gx_horizontal_list_total_columns - 1;
105                     }
106 
107                     check = _gx_widget_first_client_child_get((GX_WIDGET *)list);
108 
109                     if (check)
110                     {
111                         _gx_widget_detach(test);
112                         newpos = test -> gx_widget_size;
113                         _gx_utility_rectangle_shift(&newpos,
114                                                    (GX_VALUE)(-(newpos.gx_rectangle_right -
115                                                    check -> gx_widget_size.gx_rectangle_left + 1)), 0);
116                         _gx_widget_resize(test, &newpos);
117 
118                         list -> gx_horizontal_list_callback(list, test, list -> gx_horizontal_list_top_index);
119                         if (list -> gx_horizontal_list_selected == list -> gx_horizontal_list_top_index)
120                         {
121                             test -> gx_widget_style |=  GX_STYLE_DRAW_SELECTED;
122                         }
123                         else
124                         {
125                             test -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
126                         }
127                         _gx_widget_back_attach((GX_WIDGET *)list, test);
128                     }
129                     else
130                     {
131                         break;
132                     }
133                 }
134             }
135         }
136     }
137 }
138 
139