GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_input_mark_previous.c Lines: 29 29 100.0 %
Date: 2026-03-06 19:21:09 Branches: 10 10 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
/**   Multi Line Text Input Management (Multi 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_window.h"
30
#include "gx_scrollbar.h"
31
#include "gx_multi_line_text_input.h"
32
#include "gx_multi_line_text_view.h"
33
#include "gx_text_input_cursor.h"
34
#include "gx_utility.h"
35
#include "gx_widget.h"
36
37
/**************************************************************************/
38
/*                                                                        */
39
/*  FUNCTION                                               RELEASE        */
40
/*                                                                        */
41
/*    _gx_multi_line_text_input_mark_previous             PORTABLE C      */
42
/*                                                           6.1.7        */
43
/*  AUTHOR                                                                */
44
/*                                                                        */
45
/*    Kenneth Maxwell, Microsoft Corporation                              */
46
/*                                                                        */
47
/*  DESCRIPTION                                                           */
48
/*                                                                        */
49
/*    This function moves highlight text end mark one character left.     */
50
/*                                                                        */
51
/*  INPUT                                                                 */
52
/*                                                                        */
53
/*    text_input                        Multi line text input             */
54
/*                                        control block                   */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    None                                                                */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _gx_text_input_cursor_dirty_rectangle_get                           */
63
/*                                          Get cursor rectangle          */
64
/*    _gx_multi_line_text_input_cursor_pos_update                         */
65
/*                                          Calculate cursor position     */
66
/*                                            according to insert index   */
67
/*    _gx_system_dirty_partial_add          Add one dirty area to         */
68
/*                                            dirty list                  */
69
/*    _gx_system_dirty_mark                 Mark widget area dirty        */
70
/*    _gx_utility_utf8_string_character_get Parses utf8 string to         */
71
/*                                            multi-byte glyph            */
72
/*    _gx_utility_string_length_check       Test string length            */
73
/*                                                                        */
74
/*  CALLED BY                                                             */
75
/*                                                                        */
76
/*    _gx_multi_line_text_input_keydown_process                           */
77
/*                                                                        */
78
/**************************************************************************/
79
661
UINT _gx_multi_line_text_input_mark_previous(GX_MULTI_LINE_TEXT_INPUT *text_input)
80
{
81
661
GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance;
82
GX_CONST GX_CHAR     *string;
83
INT                   old_shift;
84
GX_RECTANGLE          cur_rect;
85
661
UINT                  glyph_len = 1;
86
UINT                  cursor_line;
87
GX_POINT              start_pos;
88
GX_POINT              end_pos;
89
661
UINT                  start_mark = text_input -> gx_multi_line_text_input_start_mark;
90
661
UINT                  end_mark = text_input -> gx_multi_line_text_input_end_mark;
91
92
661
    if (start_mark == end_mark)
93
    {
94
87
        start_mark = text_input -> gx_multi_line_text_input_text_insert_position;
95
87
        end_mark = text_input -> gx_multi_line_text_input_text_insert_position;
96
97
87
        text_input -> gx_multi_line_text_input_start_mark = start_mark;
98
87
        text_input -> gx_multi_line_text_input_end_mark = end_mark;
99
    }
100
101
661
    if (end_mark > 0)
102
    {
103
660
        cursor_line = (UINT)(text_input -> gx_multi_line_text_input_text_cursor_line - 1);
104
660
        cursor_line = (UINT)(cursor_line - text_input -> gx_multi_line_text_view_first_cache_line);
105
106
#ifdef GX_UTF8_SUPPORT
107
660
        _gx_utility_utf8_string_backward_character_length_get(&text_input -> gx_multi_line_text_view_text,
108
660
                                                              (INT)(end_mark - 1), &glyph_len);
109
#endif
110
660
        string = &text_input -> gx_multi_line_text_view_text.gx_string_ptr[end_mark - glyph_len];
111
112

660
        if (string[0] == GX_KEY_CARRIAGE_RETURN || string[0] == GX_KEY_LINE_FEED)
113
        {
114
169
            glyph_len = text_input -> gx_multi_line_text_input_new_line_character_size;
115
        }
116
117
660
        text_input -> gx_multi_line_text_input_end_mark -= glyph_len;
118
119
        /* Record scroll shift before recalculate cursor position. */
120
660
        old_shift = text_input -> gx_multi_line_text_view_text_scroll_shift;
121
122
660
        start_pos = cursor_ptr -> gx_text_input_cursor_pos;
123
124
660
        text_input -> gx_multi_line_text_input_text_insert_position = text_input -> gx_multi_line_text_input_end_mark;
125
126
660
        _gx_multi_line_text_input_cursor_pos_update(text_input, GX_TRUE);
127
128
        /* Dirty mark. */
129
660
        if (old_shift == text_input -> gx_multi_line_text_view_text_scroll_shift)
130
        {
131
564
            end_pos = cursor_ptr -> gx_text_input_cursor_pos;
132
133
564
            _gx_multi_line_text_input_text_rectangle_get(text_input, start_pos, end_pos, &cur_rect);
134
135
            /* Mark highlight area as dirty. */
136
564
            _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
137
        }
138
        else
139
        {
140
96
            _gx_system_dirty_mark((GX_WIDGET *)text_input);
141
        }
142
    }
143
661
    return GX_SUCCESS;
144
}
145