1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Text Input Management (Single Line Text Input)                      */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_system.h"
29 #include "gx_single_line_text_input.h"
30 #include "gx_text_input_cursor.h"
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_single_line_text_input_text_select              PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function highlighs text with specified start mark and end mark */
45 /*    index.                                                              */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    text_input                            Single-line text input widget */
50 /*                                            control block               */
51 /*    start_mark                            The index of the first        */
52 /*                                            highlight character.        */
53 /*    end_mark                              The index of the last         */
54 /*                                            highlight character         */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    None                                                                */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _gx_system_dirty_mark                Mark widget as drity           */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application Code                                                    */
67 /*    GUIX Internal 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 /**************************************************************************/
_gx_single_line_text_input_text_select(GX_SINGLE_LINE_TEXT_INPUT * input,UINT start_index,UINT end_index)78 UINT _gx_single_line_text_input_text_select(GX_SINGLE_LINE_TEXT_INPUT *input, UINT start_index, UINT end_index)
79 {
80 GX_RECTANGLE dirty_rect;
81 UINT         start_mark = input -> gx_single_line_text_input_start_mark;
82 UINT         end_mark = input -> gx_single_line_text_input_end_mark;
83 
84     if (start_index <= end_index)
85     {
86         input -> gx_single_line_text_input_start_mark = start_index;
87         input -> gx_single_line_text_input_end_mark = end_index + 1;
88     }
89     else
90     {
91         input -> gx_single_line_text_input_start_mark = start_index + 1;
92         input -> gx_single_line_text_input_end_mark = end_index;
93     }
94 
95     if (input -> gx_widget_status & GX_STATUS_VISIBLE)
96     {
97         if (start_mark != end_mark)
98         {
99             _gx_single_line_text_input_text_rectangle_get(input, (INT)(start_mark - end_mark), &dirty_rect);
100 
101             /* Mark old highlight area as dirty. */
102             _gx_system_dirty_partial_add((GX_WIDGET *)input, &dirty_rect);
103         }
104         else
105         {
106             _gx_text_input_cursor_dirty_rectangle_get(&input->gx_single_line_text_input_cursor_instance, &dirty_rect);
107 
108             /* Mark cursor area as dirty. */
109             _gx_system_dirty_partial_add((GX_WIDGET *)input, &dirty_rect);
110         }
111 
112         start_mark = input -> gx_single_line_text_input_start_mark;
113         end_mark = input -> gx_single_line_text_input_end_mark;
114 
115         if (input -> gx_single_line_text_input_insert_pos != end_mark)
116         {
117             input -> gx_single_line_text_input_insert_pos = end_mark;
118             _gx_single_line_text_input_position_update(input);
119         }
120 
121         _gx_single_line_text_input_text_rectangle_get(input, (INT)(start_mark - end_mark), &dirty_rect);
122 
123         /* Mark highlight text area as dirty. */
124         _gx_system_dirty_partial_add((GX_WIDGET *)input, &dirty_rect);
125     }
126 
127     return GX_SUCCESS;
128 }
129 
130