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 /**   Scroll Wheel Management (Generic Scroll Wheel)                      */
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 #include "gx_scroll_wheel.h"
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _gx_generic_scroll_wheel_total_rows_set             PORTABLE C      */
39 /*                                                           6.1.7        */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Ting Zhu, Microsoft Corporation                                     */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function assigns total number of the generic scroll wheel.     */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    wheel                                 Scroll Wheel control block    */
51 /*    count                                 Number of rows                */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    status                                Completion status             */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_widget_hide                       Hide a widget                 */
60 /*    _gx_widget_first_visible_client_child_get                           */
61 /*                                          Get the first visible client  */
62 /*    _gx_widget_next_visible_client_child_get                            */
63 /*                                          Get the next visible client   */
64 /*    _gx_generic_scroll_wheel_children_position                          */
65 /*                                          Position the children of the  */
66 /*                                            generic scroll wheel        */
67 /*    _gx_system_dirty_mark                 Mark the widget dirty         */
68 /*                                                                        */
69 /*  CALLED BY                                                             */
70 /*                                                                        */
71 /*    GUIX Internal Code                                                  */
72 /*                                                                        */
73 /*  RELEASE HISTORY                                                       */
74 /*                                                                        */
75 /*    DATE              NAME                      DESCRIPTION             */
76 /*                                                                        */
77 /*  06-02-2021     Ting Zhu                 Initial Version 6.1.7         */
78 /*                                                                        */
79 /**************************************************************************/
_gx_generic_scroll_wheel_total_rows_set(GX_GENERIC_SCROLL_WHEEL * wheel,INT count)80 UINT _gx_generic_scroll_wheel_total_rows_set(GX_GENERIC_SCROLL_WHEEL *wheel, INT count)
81 {
82 INT        row;
83 GX_WIDGET *test;
84 
85     /* Update total count of rows. */
86     wheel -> gx_scroll_wheel_total_rows = count;
87 
88     /* Update selected row. */
89     if (count == 0)
90     {
91         wheel -> gx_scroll_wheel_selected_row = 0;
92     }
93     else if (wheel -> gx_scroll_wheel_selected_row >= count)
94     {
95         wheel -> gx_scroll_wheel_selected_row = count - 1;
96     }
97 
98     /* Rreset child count and make all children visible. */
99     wheel -> gx_generic_scroll_wheel_child_count = 0;
100 
101     test = _gx_widget_first_client_child_get((GX_WIDGET *)wheel);
102 
103     while (test)
104     {
105         if (!(test->gx_widget_status & GX_STATUS_VISIBLE))
106         {
107             _gx_widget_show(test);
108         }
109 
110         wheel->gx_generic_scroll_wheel_child_count++;
111 
112         test = _gx_widget_next_client_child_get(test);
113     }
114 
115     test = wheel -> gx_widget_last_child;
116 
117     /* Check whether list child count is larger than count. */
118     while (test && (wheel -> gx_generic_scroll_wheel_child_count > count))
119     {
120         if (!(test -> gx_widget_status & GX_STATUS_NONCLIENT))
121         {
122             _gx_widget_hide(test);
123             wheel -> gx_generic_scroll_wheel_child_count--;
124         }
125 
126         test = test -> gx_widget_previous;
127     }
128 
129     wheel -> gx_generic_scroll_wheel_top_index = 0;
130 
131     if (wheel -> gx_generic_scroll_wheel_callback)
132     {
133 
134         /* Re-populate list child. */
135         row = 0;
136 
137         test = _gx_widget_first_visible_client_child_get((GX_WIDGET *)wheel);
138 
139         while (test)
140         {
141             /* Reset child id. */
142             test -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
143             wheel -> gx_generic_scroll_wheel_callback(wheel, test, row++);
144 
145             test = _gx_widget_next_visible_client_child_get(test);
146         }
147     }
148 
149     _gx_generic_scroll_wheel_children_position(wheel);
150 
151     /* Refresh screen. */
152     if (wheel -> gx_widget_status & GX_STATUS_VISIBLE)
153     {
154         _gx_system_dirty_mark((GX_WIDGET *)wheel);
155     }
156     return GX_SUCCESS;
157 }
158 
159