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 /**   Single Line Text Input Managment (Single Line Text Input)           */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_single_line_text_input.h"
28 #include "gx_utility.h"
29 
30 GX_CALLER_CHECKING_EXTERNS
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _gxe_single_line_text_input_text_set                PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Kenneth Maxwell, Microsoft Corporation                              */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function checks for errors in the single line text input text  */
44 /*    set function call.                                                  */
45 /*                                                                        */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    input                                 Pointer to single line text   */
50 /*                                            input control block         */
51 /*    text                                  Null-terminated text string   */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    status                                Completion status             */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_single_line_text_input_text_set   Actual multi line text input  */
60 /*                                            text set fucntion           */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
71 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
75 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
_gxe_single_line_text_input_text_set(GX_SINGLE_LINE_TEXT_INPUT * input,GX_CONST GX_CHAR * text)76 UINT _gxe_single_line_text_input_text_set(GX_SINGLE_LINE_TEXT_INPUT *input, GX_CONST GX_CHAR *text)
77 {
78 UINT status;
79 
80     /* Check for invalid caller.  */
81     GX_INIT_AND_THREADS_CALLER_CHECKING
82 
83     if (!input)
84     {
85         return(GX_PTR_ERROR);
86     }
87 
88     /* Check for invalid widget. */
89     if (input -> gx_widget_type == 0)
90     {
91         return(GX_INVALID_WIDGET);
92     }
93 
94     status = _gx_single_line_text_input_text_set(input, text);
95 
96     return(status);
97 }
98 #endif
99 
100 /**************************************************************************/
101 /*                                                                        */
102 /*  FUNCTION                                               RELEASE        */
103 /*                                                                        */
104 /*    _gxe_single_line_text_input_text_set_ext            PORTABLE C      */
105 /*                                                           6.1          */
106 /*  AUTHOR                                                                */
107 /*                                                                        */
108 /*    Kenneth Maxwell, Microsoft Corporation                              */
109 /*                                                                        */
110 /*  DESCRIPTION                                                           */
111 /*                                                                        */
112 /*    This function checks for errors in the single line text input text  */
113 /*    set ext function call.                                              */
114 /*                                                                        */
115 /*                                                                        */
116 /*  INPUT                                                                 */
117 /*                                                                        */
118 /*    input                                 Pointer to single line text   */
119 /*                                            input control block         */
120 /*    text                                  GX_STRING type text string    */
121 /*                                                                        */
122 /*  OUTPUT                                                                */
123 /*                                                                        */
124 /*    status                                Completion status             */
125 /*                                                                        */
126 /*  CALLS                                                                 */
127 /*                                                                        */
128 /*    _gx_single_line_text_input_text_set_ext                             */
129 /*                                          Actual multi line text input  */
130 /*                                            text set ext fucntion       */
131 /*                                                                        */
132 /*  CALLED BY                                                             */
133 /*                                                                        */
134 /*    Application Code                                                    */
135 /*                                                                        */
136 /*  RELEASE HISTORY                                                       */
137 /*                                                                        */
138 /*    DATE              NAME                      DESCRIPTION             */
139 /*                                                                        */
140 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
141 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
142 /*                                            resulting in version 6.1    */
143 /*                                                                        */
144 /**************************************************************************/
_gxe_single_line_text_input_text_set_ext(GX_SINGLE_LINE_TEXT_INPUT * input,GX_CONST GX_STRING * text)145 UINT _gxe_single_line_text_input_text_set_ext(GX_SINGLE_LINE_TEXT_INPUT *input, GX_CONST GX_STRING *text)
146 {
147 UINT status = GX_SUCCESS;
148 UINT text_length = 0;
149 
150     /* Check for invalid caller.  */
151     GX_INIT_AND_THREADS_CALLER_CHECKING
152 
153     if (!input)
154     {
155         return(GX_PTR_ERROR);
156     }
157 
158     /* Check for invalid widget. */
159     if (input -> gx_widget_type == 0)
160     {
161         return(GX_INVALID_WIDGET);
162     }
163 
164     if (text)
165     {
166         if (text -> gx_string_ptr)
167         {
168             status = _gx_utility_string_length_check(text -> gx_string_ptr, &text_length, text -> gx_string_length);
169 
170             if (status != GX_SUCCESS)
171             {
172                 return status;
173             }
174         }
175 
176         if (text_length != text -> gx_string_length)
177         {
178             return GX_INVALID_STRING_LENGTH;
179         }
180     }
181 
182     status = _gx_single_line_text_input_text_set_ext(input, text);
183 
184     return(status);
185 }
186 
187