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 /**   String 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_system.h"
29 #include "gx_utility.h"
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _gx_string_scroll_wheel_string_list_set             PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Kenneth Maxwell, Microsoft Corporation                              */
40 /*                                                                        */
41 /*  DESCRIPTION (Deprecated)                                              */
42 /*                                                                        */
43 /*    This function assigns a string list for the string scroll wheel.    */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    wheel                                 Scroll wheel control block    */
48 /*    string_list                           String list to be set         */
49 /*    string_count                          The number of assigned strings*/
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    status                                Completion status             */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _gx_system_memory_allocator           Application defined memory    */
58 /*                                            allocator function          */
59 /*    _gx_system_memory_free                Application defined memory    */
60 /*                                            free function               */
61 /*    _gx_string_scroll_wheel_string_list_set_ext                         */
62 /*                                          New stirng list set function  */
63 /*    _gx_utility_string_length_check       Calculate string length       */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application Code                                                    */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
74 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
78 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
_gx_string_scroll_wheel_string_list_set(GX_STRING_SCROLL_WHEEL * wheel,GX_CONST GX_CHAR ** string_list,INT string_count)79 UINT _gx_string_scroll_wheel_string_list_set(GX_STRING_SCROLL_WHEEL *wheel,
80                                              GX_CONST GX_CHAR **string_list,
81                                              INT string_count)
82 {
83 UINT status = GX_SUCCESS;
84 
85     if (wheel -> gx_widget_style & GX_STYLE_TEXT_COPY)
86     {
87         if (wheel -> gx_string_scroll_wheel_string_list)
88         {
89             if (_gx_system_memory_free == GX_NULL)
90             {
91                 return GX_SYSTEM_MEMORY_ERROR;
92             }
93 
94             _gx_system_memory_free((void *)wheel -> gx_string_scroll_wheel_string_list);
95         }
96     }
97 
98     wheel -> gx_string_scroll_wheel_string_list = GX_NULL;
99     wheel -> gx_string_scroll_wheel_string_list_buffer_size = 0;
100 
101     if (wheel -> gx_widget_style & GX_STYLE_TEXT_COPY)
102     {
103         status = _gx_system_private_string_list_copy(&wheel -> gx_string_scroll_wheel_string_list_deprecated, string_list, string_count);
104     }
105     else
106     {
107         wheel -> gx_string_scroll_wheel_string_list_deprecated = string_list;
108     }
109 
110     if (status == GX_SUCCESS)
111     {
112         wheel -> gx_string_scroll_wheel_string_id_list = GX_NULL;
113         status = _gx_scroll_wheel_total_rows_set((GX_SCROLL_WHEEL *)wheel, string_count);
114     }
115 
116     return status;
117 }
118 #endif
119 
120 /**************************************************************************/
121 /*                                                                        */
122 /*  FUNCTION                                               RELEASE        */
123 /*                                                                        */
124 /*    _gx_string_scroll_wheel_string_list_set_ext         PORTABLE C      */
125 /*                                                           6.1          */
126 /*  AUTHOR                                                                */
127 /*                                                                        */
128 /*    Kenneth Maxwell, Microsoft Corporation                              */
129 /*                                                                        */
130 /*  DESCRIPTION                                                           */
131 /*                                                                        */
132 /*    This function assigns a string list for the string scroll wheel.    */
133 /*                                                                        */
134 /*  INPUT                                                                 */
135 /*                                                                        */
136 /*    wheel                                 Scroll wheel control block    */
137 /*    string_list                           String list to be set         */
138 /*    string_count                          The number of assigned strings*/
139 /*                                                                        */
140 /*  OUTPUT                                                                */
141 /*                                                                        */
142 /*    status                                Completion status             */
143 /*                                                                        */
144 /*  CALLS                                                                 */
145 /*                                                                        */
146 /*    _gx_system_private_string_list_copy   Makde a private copy of string*/
147 /*                                            list                        */
148 /*    _gx_scroll_wheel_total_rows_set       Set scroll wheel total rows   */
149 /*                                                                        */
150 /*  CALLED BY                                                             */
151 /*                                                                        */
152 /*    Application Code                                                    */
153 /*                                                                        */
154 /*  RELEASE HISTORY                                                       */
155 /*                                                                        */
156 /*    DATE              NAME                      DESCRIPTION             */
157 /*                                                                        */
158 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
159 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
160 /*                                            added logic to delete       */
161 /*                                            dynamic bidi text,          */
162 /*                                            resulting in version 6.1    */
163 /*                                                                        */
164 /**************************************************************************/
_gx_string_scroll_wheel_string_list_set_ext(GX_STRING_SCROLL_WHEEL * wheel,GX_CONST GX_STRING * string_list,INT string_count)165 UINT _gx_string_scroll_wheel_string_list_set_ext(GX_STRING_SCROLL_WHEEL *wheel,
166                                                  GX_CONST GX_STRING *string_list,
167                                                  INT string_count)
168 {
169 UINT status = GX_SUCCESS;
170 
171 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
172     if (wheel -> gx_widget_style & GX_STYLE_TEXT_COPY)
173     {
174         if (wheel -> gx_string_scroll_wheel_string_list_deprecated)
175         {
176             if (_gx_system_memory_free == GX_NULL)
177             {
178                 return GX_SYSTEM_MEMORY_ERROR;
179             }
180 
181             _gx_system_memory_free((void *)wheel -> gx_string_scroll_wheel_string_list_deprecated);
182         }
183     }
184     wheel -> gx_string_scroll_wheel_string_list_deprecated = GX_NULL;
185 #endif
186 
187     if (wheel -> gx_widget_style & GX_STYLE_TEXT_COPY)
188     {
189         status = _gx_system_private_string_list_copy_ext((GX_STRING **)&wheel -> gx_string_scroll_wheel_string_list,
190                                                          &wheel -> gx_string_scroll_wheel_string_list_buffer_size, string_list, string_count);
191     }
192     else
193     {
194         wheel -> gx_string_scroll_wheel_string_list = string_list;
195     }
196 
197 #ifdef GX_DYNAMIC_BIDI_TEXT_SUPPORT
198      _gx_text_scroll_wheel_dynamic_bidi_text_delete((GX_TEXT_SCROLL_WHEEL *)wheel);
199 #endif  // GX_DYNAMIC_BIDI_TEXT_SUPPORT
200 
201     if (status == GX_SUCCESS)
202     {
203         wheel -> gx_string_scroll_wheel_string_id_list = GX_NULL;
204         status = _gx_scroll_wheel_total_rows_set((GX_SCROLL_WHEEL *)wheel, string_count);
205     }
206 
207     return status;
208 }
209 
210