GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_single_line_text_input_text_rectangle_get.c Lines: 21 21 100.0 %
Date: 2026-03-06 19:21:09 Branches: 6 6 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
/**************************************************************************/
64
533
UINT _gx_single_line_text_input_text_rectangle_get(GX_SINGLE_LINE_TEXT_INPUT *input, INT offset_index, GX_RECTANGLE *rect)
65
{
66
533
GX_TEXT_INPUT_CURSOR *cursor = &input -> gx_single_line_text_input_cursor_instance;
67
GX_FONT              *font;
68
GX_VALUE              text_width;
69
GX_VALUE              border_width;
70
INT                   start_index;
71
INT                   end_index;
72
GX_STRING             string;
73
74
533
    if (offset_index == 0)
75
    {
76
95
        return GX_FAILURE;
77
    }
78
79
438
    if (offset_index > 0)
80
    {
81
213
        start_index = (INT)input -> gx_single_line_text_input_insert_pos;
82
213
        end_index = start_index + offset_index;
83
    }
84
    else
85
    {
86
225
        start_index = (INT)input -> gx_single_line_text_input_insert_pos + (INT)offset_index;
87
225
        end_index = (INT)(input -> gx_single_line_text_input_insert_pos);
88
    }
89
90
    /* Pick up font. */
91
438
    _gx_widget_font_get((GX_WIDGET *)input, input -> gx_prompt_font_id, &font);
92
93
    /* Get the width of specified text. */
94
438
    string.gx_string_ptr = input -> gx_single_line_text_input_buffer + start_index;
95
438
    string.gx_string_length = (UINT)(end_index - start_index);
96
438
    _gx_system_string_width_get_ext(font, &string, &text_width);
97
98
    /* Pickup widget border width. */
99
438
    _gx_widget_border_width_get((GX_WIDGET *)input, &border_width);
100
101
    /* Get client rectangle. */
102
438
    _gx_widget_client_get((GX_WIDGET *)input, border_width, rect);
103
104
438
    if (offset_index > 0)
105
    {
106
213
        rect -> gx_rectangle_left = cursor -> gx_text_input_cursor_pos.gx_point_x;
107
213
        rect -> gx_rectangle_right = (GX_VALUE)(rect -> gx_rectangle_left + text_width - 1);
108
    }
109
    else
110
    {
111
225
        rect -> gx_rectangle_right = (GX_VALUE)(cursor -> gx_text_input_cursor_pos.gx_point_x - 1);
112
225
        rect -> gx_rectangle_left = (GX_VALUE)(rect -> gx_rectangle_right - text_width);
113
    }
114
115
438
    return GX_SUCCESS;
116
}
117