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_scrollbar.h"
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_vertical_list_page_index_set                    PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This service sets the starting page index for vertical list.        */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    vertical_list                         Vertical list widget control  */
49 /*                                          block                         */
50 /*    index                                 The new top index             */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    status                                Completion status             */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    _gx_vertical_list_selected_set        Process drop list event       */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
67 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*                                                                        */
70 /**************************************************************************/
_gx_vertical_list_page_index_set(GX_VERTICAL_LIST * list,INT index)71 UINT _gx_vertical_list_page_index_set(GX_VERTICAL_LIST *list, INT index)
72 {
73 GX_WIDGET    *child;
74 GX_SCROLLBAR *pScroll;
75 INT           scroll_value;
76 
77     if ((list -> gx_vertical_list_total_rows > 0) &&
78         ((index <= list -> gx_vertical_list_total_rows - list -> gx_vertical_list_visible_rows) || (list -> gx_widget_style & GX_STYLE_WRAP)))
79     {
80         child = _gx_widget_first_client_child_get((GX_WIDGET *)list);
81 
82         if (child)
83         {
84             scroll_value = child -> gx_widget_size.gx_rectangle_top;
85             scroll_value += (index - list -> gx_vertical_list_top_index) * list -> gx_vertical_list_child_height;
86             scroll_value = list -> gx_window_client.gx_rectangle_top - scroll_value;
87 
88             /* Scroll to make index as the first visible entry. */
89             _gx_vertical_list_scroll(list, scroll_value);
90 
91             _gx_window_scrollbar_find((GX_WINDOW *)list, GX_TYPE_VERTICAL_SCROLL, &pScroll);
92 
93             if (pScroll)
94             {
95                 _gx_scrollbar_reset(pScroll, GX_NULL);
96             }
97         }
98     }
99 
100     return GX_SUCCESS;
101 }
102 
103