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 Management                                            */
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_scrollbar.h"
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_vertical_list_scroll_info_get                   PORTABLE C      */
37 /*                                                           6.4.0        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function gets the scrollbar information.                       */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    win                                   Pointer to window             */
49 /*    style                                 Style                         */
50 /*    info                                  Information of scrollbar      */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _gx_first_client_child_get            Get the first client child    */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    Application Code                                                    */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
69 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*  12-31-2023     Ting Zhu                 Modified comments(s),         */
72 /*                                            improved the calculation of */
73 /*                                            the maximum scrolling value.*/
74 /*                                            resulting in version 6.4.0  */
75 /*                                                                        */
76 /**************************************************************************/
_gx_vertical_list_scroll_info_get(GX_VERTICAL_LIST * list,ULONG style,GX_SCROLL_INFO * info)77 VOID _gx_vertical_list_scroll_info_get(GX_VERTICAL_LIST *list, ULONG style, GX_SCROLL_INFO *info)
78 {
79 INT        value;
80 GX_VALUE   height;
81 GX_WIDGET *child;
82 
83     GX_PARAMETER_NOT_USED(style);
84 
85     if (list -> gx_vertical_list_callback)
86     {
87         /* If list callback is set, children winthin the list should share the same height. */
88         info -> gx_scroll_maximum = (list->gx_vertical_list_total_rows * list -> gx_vertical_list_child_height - 1);
89     }
90     else
91     {
92         info -> gx_scroll_maximum = 0;
93 
94         child = _gx_widget_first_client_child_get((GX_WIDGET *)list);
95 
96         while (child)
97         {
98             _gx_widget_height_get(child, &height);
99 
100             info -> gx_scroll_maximum += height;
101 
102             child = _gx_widget_next_client_child_get(child);
103         }
104     }
105     info -> gx_scroll_minimum = 0;
106     info -> gx_scroll_visible = (GX_VALUE)(list -> gx_window_client.gx_rectangle_bottom - list -> gx_window_client.gx_rectangle_top + 1);
107 
108     if (info -> gx_scroll_maximum <= info -> gx_scroll_visible)
109     {
110         info -> gx_scroll_value = 0;
111         info -> gx_scroll_increment = 0;
112         info -> gx_scroll_maximum = info->gx_scroll_visible;
113         return;
114     }
115 
116     value = list -> gx_vertical_list_top_index * list -> gx_vertical_list_child_height;
117 
118     if (list -> gx_vertical_list_top_index >= 0)
119     {
120         child = _gx_widget_first_client_child_get((GX_WIDGET *)list);
121 
122         if (child)
123         {
124             value += list -> gx_window_client.gx_rectangle_top - child -> gx_widget_size.gx_rectangle_top;
125         }
126     }
127 
128     if (value < info -> gx_scroll_minimum)
129     {
130         value = info -> gx_scroll_minimum;
131     }
132     else
133     {
134         if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
135         {
136             value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
137         }
138     }
139 
140     info -> gx_scroll_value = value;
141     info -> gx_scroll_increment = list -> gx_vertical_list_child_height / 2;
142 }
143 
144