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 /**   Multi Line Text Input Management(Multi 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_system.h"
28 #include "gx_utility.h"
29 #include "gx_window.h"
30 #include "gx_scrollbar.h"
31 #include "gx_multi_line_text_input.h"
32 #include "gx_multi_line_text_view.h"
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _gx_multi_line_text_input_char_remove               PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Kenneth Maxwell, Microsoft Corporation                              */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function removes a substring from a specified position         */
47 /*      of input buffer.                                                  */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    text_input                            Multi line text input control */
52 /*                                            block                       */
53 /*    start_pos                             Specified position in input   */
54 /*                                            buffer                      */
55 /*    del_bytes                             The number of bytes that to   */
56 /*                                            be removed                  */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    None                                                                */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    memmove                               Move the rest of the string   */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    _gx_multi_line_text_input_backspace                                 */
69 /*    _gx_multi_line_text_input_delete                                    */
70 /*                                                                        */
71 /*  RELEASE HISTORY                                                       */
72 /*                                                                        */
73 /*    DATE              NAME                      DESCRIPTION             */
74 /*                                                                        */
75 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
76 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
77 /*                                            resulting in version 6.1    */
78 /*                                                                        */
79 /**************************************************************************/
_gx_multi_line_text_input_char_remove(GX_MULTI_LINE_TEXT_INPUT * text_input,UINT start_pos,UINT del_bytes)80 UINT _gx_multi_line_text_input_char_remove(GX_MULTI_LINE_TEXT_INPUT *text_input, UINT start_pos, UINT del_bytes)
81 {
82 UINT       string_size;
83 GX_CHAR   *input_buffer;
84 
85     input_buffer = (GX_CHAR *) text_input -> gx_multi_line_text_view_text.gx_string_ptr;
86     string_size = text_input -> gx_multi_line_text_view_text.gx_string_length;
87     memmove(input_buffer + start_pos, input_buffer + start_pos + del_bytes, string_size - start_pos - del_bytes);
88     input_buffer[string_size - del_bytes] = '\0';
89 
90     /* Update the input string size and cursor position. */
91     text_input -> gx_multi_line_text_view_text.gx_string_length -= del_bytes;
92 
93     /* Set the text modified flag to GX_TRUE. */
94     text_input -> gx_multi_line_text_input_text_was_modified = GX_TRUE;
95 
96     return GX_SUCCESS;
97 }
98 
99