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 View Management (Multi Line Text View)              */
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_multi_line_text_view.h"
29 #include "gx_scrollbar.h"
30 #include "gx_window.h"
31 #include "gx_widget.h"
32 #include "gx_utility.h"
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _gx_multi_line_text_view_text_set                   PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Kenneth Maxwell, Microsoft Corporation                              */
43 /*                                                                        */
44 /*  DESCRIPTION (Deprecated)                                              */
45 /*                                                                        */
46 /*    This function assigns a text string to the multi line text view     */
47 /*    widget.                                                             */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    text_view                             Multi-line text view widget   */
52 /*                                            control block               */
53 /*    text                                  Null-terminated text string   */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _gx_multi_line_text_view_text_set_ext                               */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
76 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
_gx_multi_line_text_view_text_set(GX_MULTI_LINE_TEXT_VIEW * text_view,GX_CONST GX_CHAR * text)77 UINT _gx_multi_line_text_view_text_set(GX_MULTI_LINE_TEXT_VIEW *text_view,
78                                        GX_CONST GX_CHAR *text)
79 {
80 UINT      status = GX_SUCCESS;
81 UINT      length = 0;
82 GX_STRING string;
83 
84     if (text)
85     {
86         status = _gx_utility_string_length_check(text, &length, GX_MAX_STRING_LENGTH);
87     }
88 
89     if (status == GX_SUCCESS)
90     {
91         string.gx_string_ptr = text;
92         string.gx_string_length = length;
93         status = _gx_multi_line_text_view_text_set_ext(text_view, &string);
94     }
95     return status;
96 }
97 #endif
98 
99 
100 
101 /**************************************************************************/
102 /*                                                                        */
103 /*  FUNCTION                                               RELEASE        */
104 /*                                                                        */
105 /*    _gx_multi_line_text_view_text_set_ext               PORTABLE C      */
106 /*                                                           6.1          */
107 /*  AUTHOR                                                                */
108 /*                                                                        */
109 /*    Kenneth Maxwell, Microsoft Corporation                              */
110 /*                                                                        */
111 /*  DESCRIPTION                                                           */
112 /*                                                                        */
113 /*    This function assigns a text string to the multi line text view     */
114 /*    widget.                                                             */
115 /*                                                                        */
116 /*  INPUT                                                                 */
117 /*                                                                        */
118 /*    text_view                             Multi-line text view widget   */
119 /*                                            control block               */
120 /*    text                                  GX_STRING type text string    */
121 /*                                                                        */
122 /*  OUTPUT                                                                */
123 /*                                                                        */
124 /*    status                                Completion status             */
125 /*                                                                        */
126 /*  CALLS                                                                 */
127 /*                                                                        */
128 /*    _gx_utility_string_length_check       Test string length            */
129 /*    _gx_system_private_string_copy        Make a private copy for       */
130 /*                                            assigned text               */
131 /*    _gx_system_dirty_mark                 Mark a widget as dirty        */
132 /*                                                                        */
133 /*  CALLED BY                                                             */
134 /*                                                                        */
135 /*    Application Code                                                    */
136 /*                                                                        */
137 /*  RELEASE HISTORY                                                       */
138 /*                                                                        */
139 /*    DATE              NAME                      DESCRIPTION             */
140 /*                                                                        */
141 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
142 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
143 /*                                            added logic to delete       */
144 /*                                            dynamic bidi text,          */
145 /*                                            resulting in version 6.1    */
146 /*                                                                        */
147 /**************************************************************************/
_gx_multi_line_text_view_text_set_ext(GX_MULTI_LINE_TEXT_VIEW * text_view,GX_CONST GX_STRING * text)148 UINT _gx_multi_line_text_view_text_set_ext(GX_MULTI_LINE_TEXT_VIEW *text_view, GX_CONST GX_STRING *text)
149 {
150 UINT status = GX_SUCCESS;
151 
152     if (text_view -> gx_widget_style & GX_STYLE_TEXT_COPY)
153     {
154         status = _gx_system_private_string_copy(&text_view -> gx_multi_line_text_view_text, text);
155     }
156     else
157     {
158         if (text)
159         {
160             text_view -> gx_multi_line_text_view_text = *text;
161         }
162         else
163         {
164             text_view -> gx_multi_line_text_view_text.gx_string_ptr = GX_NULL;
165             text_view -> gx_multi_line_text_view_text.gx_string_length = 0;
166         }
167     }
168 
169     text_view -> gx_multi_line_text_view_text_id = 0;
170     text_view -> gx_multi_line_text_view_line_index_old = GX_TRUE;
171 
172 #if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT)
173     if (text_view -> gx_multi_line_text_view_bidi_resolved_text_info)
174     {
175         _gx_utility_bidi_resolved_text_info_delete(&text_view -> gx_multi_line_text_view_bidi_resolved_text_info);
176     }
177 #endif
178 
179     if (text_view -> gx_widget_status & GX_STATUS_VISIBLE)
180     {
181         _gx_system_dirty_mark((GX_WIDGET *)text_view);
182     }
183 
184     return(status);
185 }
186 
187