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_widget.h"
30 #include "gx_single_line_text_input.h"
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_single_line_text_input_text_rectangle_get       PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function retrieves the bounding box from the current cursor    */
45 /*    position to the specified offset position.                          */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    text_input                            Single-line text input widget */
50 /*                                            control block               */
51 /*    offset_index                          Index offset to the current   */
52 /*                                            cursor position             */
53 /*    rect                                  Retrieved bounding rectangle  */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    Completion status                                                   */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _gx_system_dirty_mark                Mark widget as drity           */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
68 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_gx_single_line_text_input_text_rectangle_get(GX_SINGLE_LINE_TEXT_INPUT * input,INT offset_index,GX_RECTANGLE * rect)72 UINT _gx_single_line_text_input_text_rectangle_get(GX_SINGLE_LINE_TEXT_INPUT *input, INT offset_index, GX_RECTANGLE *rect)
73 {
74 GX_TEXT_INPUT_CURSOR *cursor = &input -> gx_single_line_text_input_cursor_instance;
75 GX_FONT              *font;
76 GX_VALUE              text_width;
77 GX_VALUE              border_width;
78 INT                   start_index;
79 INT                   end_index;
80 GX_STRING             string;
81 
82     if (offset_index == 0)
83     {
84         return GX_FAILURE;
85     }
86 
87     if (offset_index > 0)
88     {
89         start_index = (INT)input -> gx_single_line_text_input_insert_pos;
90         end_index = start_index + offset_index;
91     }
92     else
93     {
94         start_index = (INT)input -> gx_single_line_text_input_insert_pos + (INT)offset_index;
95         end_index = (INT)(input -> gx_single_line_text_input_insert_pos);
96     }
97 
98     /* Pick up font. */
99     _gx_widget_font_get((GX_WIDGET *)input, input -> gx_prompt_font_id, &font);
100 
101     /* Get the width of specified text. */
102     string.gx_string_ptr = input -> gx_single_line_text_input_buffer + start_index;
103     string.gx_string_length = (UINT)(end_index - start_index);
104     _gx_system_string_width_get_ext(font, &string, &text_width);
105 
106     /* Pickup widget border width. */
107     _gx_widget_border_width_get((GX_WIDGET *)input, &border_width);
108 
109     /* Get client rectangle. */
110     _gx_widget_client_get((GX_WIDGET *)input, border_width, rect);
111 
112     if (offset_index > 0)
113     {
114         rect -> gx_rectangle_left = cursor -> gx_text_input_cursor_pos.gx_point_x;
115         rect -> gx_rectangle_right = (GX_VALUE)(rect -> gx_rectangle_left + text_width - 1);
116     }
117     else
118     {
119         rect -> gx_rectangle_right = (GX_VALUE)(cursor -> gx_text_input_cursor_pos.gx_point_x - 1);
120         rect -> gx_rectangle_left = (GX_VALUE)(rect -> gx_rectangle_right - text_width);
121     }
122 
123     return GX_SUCCESS;
124 }
125 
126