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 /**   Numeric Scroll Wheel Management (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_scroll_wheel.h"
28 #include "gx_utility.h"
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_numeric_scroll_wheel_text_get                   PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function returns pointer to numeric text.                      */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    wheel                                 Scroll wheel control block    */
47 /*    row                                   Desired text row              */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    status                                Completion status             */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _gx_utility_ltoa                      Convert integer to string     */
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    _gx_text_scroll_wheel_draw                                          */
60 /*                                                                        */
61 /*  RELEASE HISTORY                                                       */
62 /*                                                                        */
63 /*    DATE              NAME                      DESCRIPTION             */
64 /*                                                                        */
65 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
66 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
67 /*                                            resulting in version 6.1    */
68 /*                                                                        */
69 /**************************************************************************/
_gx_numeric_scroll_wheel_text_get(GX_NUMERIC_SCROLL_WHEEL * wheel,INT row,GX_STRING * string)70 UINT _gx_numeric_scroll_wheel_text_get(GX_NUMERIC_SCROLL_WHEEL *wheel, INT row, GX_STRING *string)
71 {
72 INT  step;
73 INT  val;
74 
75     if (row < wheel -> gx_scroll_wheel_total_rows)
76     {
77         step = wheel -> gx_numeric_scroll_wheel_end_val - wheel -> gx_numeric_scroll_wheel_start_val;
78 
79         if (step == (wheel -> gx_scroll_wheel_total_rows - 1))
80         {
81             step = 1;
82         }
83         else if (step == (1 - wheel -> gx_scroll_wheel_total_rows))
84         {
85             step = -1;
86         }
87         else if (wheel -> gx_scroll_wheel_total_rows > 1)
88         {
89             step /= (wheel -> gx_scroll_wheel_total_rows - 1);
90         }
91 
92         val = wheel -> gx_numeric_scroll_wheel_start_val + (step * row);
93         _gx_utility_ltoa(val, wheel -> gx_numeric_scroll_wheel_string_buffer, GX_NUMERIC_SCROLL_WHEEL_STRING_BUFFER_SIZE);
94 
95         string -> gx_string_ptr = wheel -> gx_numeric_scroll_wheel_string_buffer;
96         _gx_utility_string_length_check(string -> gx_string_ptr, &string -> gx_string_length, GX_NUMERIC_SCROLL_WHEEL_STRING_BUFFER_SIZE - 1);
97     }
98     else
99     {
100         string -> gx_string_ptr = GX_NULL;
101         string -> gx_string_length = 0;
102     }
103 
104     return(GX_SUCCESS);
105 }
106 
107