GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_input_end.c Lines: 20 20 100.0 %
Date: 2024-12-05 08:52:37 Branches: 6 6 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
/**   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_window.h"
29
#include "gx_multi_line_text_input.h"
30
#include "gx_multi_line_text_view.h"
31
#include "gx_text_input_cursor.h"
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_multi_line_text_input_end                       PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function deletes a character after the cursor.                 */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    text_input                           Multi line text input          */
50
/*                                           control block                */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    None                                                                */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_multi_line_text_input_cursor_pos_calculate                      */
59
/*                                          Calculate cursor position     */
60
/*                                            according to click point    */
61
/*    _gx_multi_line_text_input_cursor_rectangle_define                   */
62
/*                                          Define a rectangle for the    */
63
/*                                            cursor                      */
64
/*    _gx_system_dirty_partial_add          Add one dirty area to         */
65
/*                                            dirty list                  */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    _gx_multi_line_text_input_keydown_process                           */
70
/*                                                                        */
71
/*  RELEASE HISTORY                                                       */
72
/*                                                                        */
73
/*    DATE              NAME                      DESCRIPTION             */
74
/*                                                                        */
75
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
76
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
77
/*                                            resulting in version 6.1    */
78
/*                                                                        */
79
/**************************************************************************/
80
269
UINT _gx_multi_line_text_input_end(GX_MULTI_LINE_TEXT_INPUT *text_input)
81
{
82
269
GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance;
83
GX_POINT              cur_pos;
84
GX_RECTANGLE          cur_rect;
85
UINT                  line_end_index;
86
UINT                  line_cache_start;
87
UINT                  index;
88
89
269
    if (text_input -> gx_multi_line_text_input_start_mark != text_input -> gx_multi_line_text_input_end_mark)
90
    {
91
70
        _gx_multi_line_text_input_right_arrow(text_input);
92
    }
93
94
269
    cur_pos = cursor_ptr -> gx_text_input_cursor_pos;
95
96
269
    _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cur_rect);
97
98
269
    cur_pos.gx_point_x = (GX_VALUE)(text_input -> gx_window_client.gx_rectangle_right -
99
269
                                    text_input -> gx_multi_line_text_view_whitespace);
100
101
    /* Calculate new cursor position. */
102
269
    _gx_multi_line_text_input_cursor_pos_calculate(text_input, cur_pos);
103
104
    /* Calcualte insert position, consider the situation that there are some whitespaces in the end of
105
       cursor line. */
106
269
    line_cache_start = text_input -> gx_multi_line_text_view_first_cache_line;
107
108
269
    index = text_input -> gx_multi_line_text_input_text_cursor_line - 1;
109
110
269
    if ((INT)(index - line_cache_start) >= (INT)(text_input -> gx_multi_line_text_view_cache_size - 1))
111
    {
112
66
        line_end_index = text_input -> gx_multi_line_text_view_text.gx_string_length;
113
    }
114
    else
115
    {
116
203
        line_end_index = text_input -> gx_multi_line_text_view_line_index[index - line_cache_start + 1];
117
    }
118
269
    text_input -> gx_multi_line_text_input_text_insert_position = line_end_index;
119
120
269
    if (cur_rect.gx_rectangle_left != cursor_ptr -> gx_text_input_cursor_pos.gx_point_x)
121
    {
122
        /* Mark old cursor rectangle dirty. */
123
140
        _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
124
125
        /* Mark new cursor rectangle dirty. */
126
140
        _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cur_rect);
127
140
        _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
128
    }
129
130
269
    return GX_SUCCESS;
131
}
132