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_position_update          PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function update the cursor position according to character     */
45 /*      insert index.                                                     */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    text_input                            Single-line text input widget */
50 /*                                            control block               */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Complete status                                                     */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _gx_widget_font_get                   Get font by specified ID      */
59 /*    _gx_widget_border_width_get           Get widget border width       */
60 /*    _gx_widget_client_get                 Get widget client rectangle   */
61 /*    _gx_system_string_width_get           Get the width of a string     */
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_single_line_text_input_position_update(GX_SINGLE_LINE_TEXT_INPUT * text_input)77 UINT _gx_single_line_text_input_position_update(GX_SINGLE_LINE_TEXT_INPUT *text_input)
78 {
79 GX_TEXT_INPUT_CURSOR *cursor_ptr;
80 UINT                  insert_pos;
81 GX_FONT              *gx_font;
82 GX_RECTANGLE          client;
83 GX_VALUE              width;
84 GX_VALUE              x_pos;
85 GX_STRING             string;
86 
87     cursor_ptr = &text_input -> gx_single_line_text_input_cursor_instance;
88     insert_pos = text_input -> gx_single_line_text_input_insert_pos;
89 
90     _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_prompt_font_id, &gx_font);
91     _gx_widget_border_width_get((GX_WIDGET *)text_input, &width);
92     _gx_widget_client_get((GX_WIDGET *)text_input, width, &client);
93 
94     /* Calculate distance from first character to character insert position.  */
95     string.gx_string_ptr = text_input -> gx_single_line_text_input_buffer;
96     string.gx_string_length = insert_pos;
97     _gx_system_string_width_get_ext(gx_font, &string, &width);
98 
99     switch (text_input -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
100     {
101     case GX_STYLE_TEXT_RIGHT:
102         x_pos = (GX_VALUE)(client.gx_rectangle_right - 1);
103         break;
104 
105     case GX_STYLE_TEXT_CENTER:
106         x_pos = client.gx_rectangle_left;
107         x_pos = (GX_VALUE)(x_pos + 1 + ((client.gx_rectangle_right - client.gx_rectangle_left + 1) >> 1));
108         break;
109 
110     case GX_STYLE_TEXT_LEFT:
111     default:
112         x_pos = (GX_VALUE)(client.gx_rectangle_left + 1);
113         break;
114     }
115 
116     /* Pick up draw start position.  */
117     x_pos = (GX_VALUE)(x_pos - text_input -> gx_single_line_text_input_xoffset);
118 
119     /* Update cursor position.  */
120     cursor_ptr -> gx_text_input_cursor_pos.gx_point_x = (GX_VALUE)(x_pos + width);
121 
122     return GX_SUCCESS;
123 }
124 
125