GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_input_highlight_rectangle_get.c Lines: 30 30 100.0 %
Date: 2024-12-05 08:52:37 Branches: 10 10 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 (Multi 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_multi_line_text_input.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_multi_line_text_input_text_rectangle_get        PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function retrieves the bounding box of specified text.         */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    input                                 Multi-line text input widget  */
48
/*                                            control block               */
49
/*    start_index                           The start index of the        */
50
/*                                            specified text              */
51
/*    end_index                             The end index of the          */
52
/*                                            specified text              */
53
/*    rect                                  Retrieved bounding rectangle  */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    None                                                                */
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
/**************************************************************************/
72
975
UINT _gx_multi_line_text_input_highlight_rectangle_get(GX_MULTI_LINE_TEXT_INPUT *input, GX_RECTANGLE *rect)
73
{
74
975
GX_TEXT_INPUT_CURSOR *cursor_ptr = &input -> gx_multi_line_text_input_cursor_instance;
75
INT                   line_height;
76
INT                   first_visible_line;
77
INT                   last_visible_line;
78
INT                   line_cache_start;
79
975
UINT                 *line_index = input -> gx_multi_line_text_view_line_index;
80
GX_FONT              *font;
81
GX_POINT              start_pos;
82
GX_POINT              end_pos;
83
UINT                  cursor_line;
84
85
975
    _gx_widget_font_get((GX_WIDGET *)input, input -> gx_multi_line_text_view_font_id, &font);
86
87
975
    if (!font)
88
    {
89
2
        return GX_FAILURE;
90
    }
91
92
    /* Pickup text height. */
93
973
    line_height = font -> gx_font_line_height + input -> gx_multi_line_text_view_line_space;
94
95
973
    if (!line_height)
96
    {
97
2
        return GX_FAILURE;
98
    }
99
100
971
    first_visible_line = -input -> gx_multi_line_text_view_text_scroll_shift / line_height;
101
971
    last_visible_line = first_visible_line + (INT)input -> gx_multi_line_text_view_text_visible_rows;
102
971
    if (last_visible_line > (INT)(input -> gx_multi_line_text_view_text_total_rows - 1))
103
    {
104
320
        last_visible_line = (INT)input -> gx_multi_line_text_view_text_total_rows - 1;
105
    }
106
107
971
    line_cache_start = (INT)input -> gx_multi_line_text_view_first_cache_line;
108
109
971
    if (input -> gx_multi_line_text_input_start_mark <= line_index[first_visible_line - line_cache_start])
110
    {
111
462
        start_pos.gx_point_x = input -> gx_widget_size.gx_rectangle_left;
112
462
        start_pos.gx_point_y = input -> gx_widget_size.gx_rectangle_top;
113
    }
114
509
    else if (input -> gx_multi_line_text_input_start_mark >= line_index[last_visible_line - line_cache_start])
115
    {
116
206
        start_pos.gx_point_x = input -> gx_widget_size.gx_rectangle_left;
117
206
        start_pos.gx_point_y = input -> gx_widget_size.gx_rectangle_bottom;
118
    }
119
    else
120
    {
121
303
        end_pos = cursor_ptr -> gx_text_input_cursor_pos;
122
303
        input -> gx_multi_line_text_input_text_insert_position = input -> gx_multi_line_text_input_start_mark;
123
303
        cursor_line = input -> gx_multi_line_text_input_text_cursor_line;
124
125
303
        _gx_multi_line_text_input_cursor_pos_update(input, GX_FALSE);
126
303
        start_pos = cursor_ptr -> gx_text_input_cursor_pos;
127
128
303
        input -> gx_multi_line_text_input_text_insert_position = input -> gx_multi_line_text_input_end_mark;
129
303
        input -> gx_multi_line_text_input_text_cursor_line = cursor_line;
130
303
        cursor_ptr -> gx_text_input_cursor_pos = end_pos;
131
    }
132
133
971
    _gx_multi_line_text_input_text_rectangle_get(input, start_pos, cursor_ptr -> gx_text_input_cursor_pos, rect);
134
135
971
    return GX_SUCCESS;
136
}
137