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 /**   Text Input Management (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_multi_line_text_input.h"
28 #include "gx_system.h"
29 #include "gx_text_input_cursor.h"
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _gx_multi_line_text_input_text_select               PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Kenneth Maxwell, Microsoft Corporation                              */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function highlighs text with specified start mark and end mark */
44 /*    index.                                                              */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    input                                 Multi-line text input widget  */
49 /*                                            control block               */
50 /*    start_mark                            The index of the first        */
51 /*                                            highlight character.        */
52 /*    end_mark                              The index of the last         */
53 /*                                            highlight character         */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _gx_system_dirty_mark                Mark widget as drity           */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*    GUIX Internal Code                                                  */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
73 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_gx_multi_line_text_input_text_select(GX_MULTI_LINE_TEXT_INPUT * input,UINT start_index,UINT end_index)77 UINT _gx_multi_line_text_input_text_select(GX_MULTI_LINE_TEXT_INPUT *input, UINT start_index, UINT end_index)
78 {
79 GX_RECTANGLE dirty_rect;
80 UINT         start_mark = input -> gx_multi_line_text_input_start_mark;
81 UINT         end_mark = input -> gx_multi_line_text_input_end_mark;
82 
83     if (start_index <= end_index)
84     {
85         input -> gx_multi_line_text_input_start_mark = start_index;
86         input -> gx_multi_line_text_input_end_mark = end_index + 1;
87     }
88     else
89     {
90         input -> gx_multi_line_text_input_start_mark = start_index + 1;
91         input -> gx_multi_line_text_input_end_mark = end_index;
92     }
93 
94     if (input -> gx_widget_status & GX_STATUS_VISIBLE)
95     {
96         if (start_mark != end_mark)
97         {
98             _gx_multi_line_text_input_highlight_rectangle_get(input, &dirty_rect);
99 
100             /* Mark highlight area as dirty. */
101             _gx_system_dirty_partial_add((GX_WIDGET *)input, &dirty_rect);
102         }
103         else
104         {
105             _gx_text_input_cursor_dirty_rectangle_get(&input -> gx_multi_line_text_input_cursor_instance, &dirty_rect);
106 
107             /* Mark cursor area as dirty. */
108             _gx_system_dirty_partial_add((GX_WIDGET *)input, &dirty_rect);
109         }
110 
111         start_mark = input -> gx_multi_line_text_input_start_mark;
112         end_mark = input -> gx_multi_line_text_input_end_mark;
113 
114         if (input -> gx_multi_line_text_input_text_insert_position != end_mark)
115         {
116             input -> gx_multi_line_text_input_text_insert_position = end_mark;
117             _gx_multi_line_text_input_cursor_pos_update(input, GX_FALSE);
118         }
119 
120         _gx_multi_line_text_input_highlight_rectangle_get(input, &dirty_rect);
121 
122         /* Mark highlight area as dirty. */
123         _gx_system_dirty_partial_add((GX_WIDGET *)input, &dirty_rect);
124     }
125 
126     return GX_SUCCESS;
127 }
128 
129