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_left_wrap                       PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function scrolls up 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_first_client_child_get            Get the first client child    */
58 /*    _gx_last_client_child_get             Get the last client child     */
59 /*    _gx_widget_front_move                 Move widget to the front      */
60 /*    _gx_widget_shift                      Shift 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_left_wrap(GX_HORIZONTAL_LIST * list)76 VOID _gx_horizontal_list_left_wrap(GX_HORIZONTAL_LIST *list)
77 {
78 GX_WIDGET   *test;
79 GX_WIDGET   *check;
80 GX_RECTANGLE newpos;
81 GX_BOOL      moving = GX_TRUE;
82 INT          index;
83 
84     while (moving)
85     {
86         moving = GX_FALSE;
87 
88         if ((list -> gx_horizontal_list_top_index + list -> gx_horizontal_list_child_count < list -> gx_horizontal_list_total_columns) ||
89             (list -> gx_widget_style & GX_STYLE_WRAP))
90         {
91             /* scrolling up. See if my top widget is already above my
92                client area: */
93 
94             test = _gx_widget_first_client_child_get((GX_WIDGET *)list);
95             if (test)
96             {
97                 if (test -> gx_widget_size.gx_rectangle_right < list -> gx_widget_size.gx_rectangle_left)
98                 {
99                     /* left widget is left of my client area, move it to the right: */
100 
101                     moving = GX_TRUE;
102                     check = _gx_widget_last_client_child_get((GX_WIDGET *)list);
103 
104                     _gx_widget_detach(test);
105 
106                     newpos = test -> gx_widget_size;
107                     _gx_utility_rectangle_shift(&newpos,
108                                                 (GX_VALUE)(check -> gx_widget_size.gx_rectangle_right -
109                                                            test -> gx_widget_size.gx_rectangle_left + 1),
110                                                 0);
111                     _gx_widget_resize(test, &newpos);
112 
113                     index = list -> gx_horizontal_list_top_index + list -> gx_horizontal_list_child_count;
114 
115                     /* Wrap index. */
116                     if (index >= list -> gx_horizontal_list_total_columns)
117                     {
118                         index -= list -> gx_horizontal_list_total_columns;
119                     }
120 
121                     list -> gx_horizontal_list_callback(list, test, index);
122                     if (index == list -> gx_horizontal_list_selected)
123                     {
124                         test -> gx_widget_style |=  GX_STYLE_DRAW_SELECTED;
125                     }
126                     else
127                     {
128                         test -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
129                     }
130                     _gx_widget_attach((GX_WIDGET *)list, test);
131                     list -> gx_horizontal_list_top_index++;
132 
133                     /* Wrap page index.  */
134                     if (list -> gx_horizontal_list_top_index >= list -> gx_horizontal_list_total_columns)
135                     {
136                         list -> gx_horizontal_list_top_index -= list -> gx_horizontal_list_total_columns;
137                     }
138                 }
139             }
140         }
141     }
142 }
143 
144