GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_single_line_text_input_position_update.c Lines: 23 23 100.0 %
Date: 2024-12-05 08:52:37 Branches: 3 3 100.0 %

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