GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_input_mark_next.c Lines: 27 27 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
/**   Multi Line 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_window.h"
29
#include "gx_scrollbar.h"
30
#include "gx_multi_line_text_input.h"
31
#include "gx_multi_line_text_view.h"
32
#include "gx_text_input_cursor.h"
33
#include "gx_utility.h"
34
35
/**************************************************************************/
36
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _gx_multi_line_text_input_mark_next                 PORTABLE C      */
40
/*                                                           6.1          */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    Kenneth Maxwell, Microsoft Corporation                              */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This function moves highlight text end mark one character right.    */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    text_input                        Multi line text input             */
52
/*                                        control block                   */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_text_input_cursor_dirty_rectangle_get                           */
61
/*                                          Get cursor rectangle          */
62
/*    _gx_multi_line_text_input_cursor_pos_update                         */
63
/*                                          Calculate cursor position     */
64
/*                                            according to insert index   */
65
/*    _gx_system_dirty_partial_add          Add one dirty area to         */
66
/*                                            dirty list                  */
67
/*    _gx_system_dirty_mark                 Mark widget area dirty        */
68
/*    _gx_utility_utf8_string_character_get Parses utf8 string to         */
69
/*                                            multi-byte glyph            */
70
/*    _gx_utility_string_length_check       Test string length            */
71
/*                                                                        */
72
/*  CALLED BY                                                             */
73
/*                                                                        */
74
/*    _gx_multi_line_text_input_keydown_process                           */
75
/*                                                                        */
76
/*  RELEASE HISTORY                                                       */
77
/*                                                                        */
78
/*    DATE              NAME                      DESCRIPTION             */
79
/*                                                                        */
80
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
81
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
82
/*                                            resulting in version 6.1    */
83
/*                                                                        */
84
/**************************************************************************/
85
683
UINT _gx_multi_line_text_input_mark_next(GX_MULTI_LINE_TEXT_INPUT *text_input)
86
{
87
GX_RECTANGLE cur_rect;
88
INT          old_shift;
89
683
UINT         glyph_len = 1;
90
GX_STRING    string;
91
GX_POINT     start_pos;
92
GX_POINT     end_pos;
93
683
UINT         start_mark = text_input -> gx_multi_line_text_input_start_mark;
94
683
UINT         end_mark = text_input -> gx_multi_line_text_input_end_mark;
95
96
683
    if (start_mark == end_mark)
97
    {
98
85
        start_mark = text_input -> gx_multi_line_text_input_text_insert_position;
99
85
        end_mark = text_input -> gx_multi_line_text_input_text_insert_position;
100
101
85
        text_input -> gx_multi_line_text_input_start_mark = start_mark;
102
85
        text_input -> gx_multi_line_text_input_end_mark = end_mark;
103
    }
104
105
683
    if (end_mark < text_input -> gx_multi_line_text_view_text.gx_string_length)
106
    {
107
#ifdef GX_UTF8_SUPPORT
108
682
        string.gx_string_ptr = text_input -> gx_multi_line_text_view_text.gx_string_ptr + end_mark;
109
682
        string.gx_string_length = text_input -> gx_multi_line_text_view_text.gx_string_length - end_mark;
110
682
        _gx_utility_utf8_string_character_get(&string, GX_NULL, &glyph_len);
111
#endif
112
682
        string.gx_string_ptr = text_input -> gx_multi_line_text_view_text.gx_string_ptr + end_mark;
113
114

682
        if (string.gx_string_ptr[0] == GX_KEY_CARRIAGE_RETURN || string.gx_string_ptr[0] == GX_KEY_LINE_FEED)
115
        {
116
100
            glyph_len = text_input -> gx_multi_line_text_input_new_line_character_size;
117
        }
118
119
682
        text_input -> gx_multi_line_text_input_end_mark += glyph_len;
120
121
682
        old_shift = text_input -> gx_multi_line_text_view_text_scroll_shift;
122
123
682
        start_pos = text_input -> gx_multi_line_text_input_cursor_instance.gx_text_input_cursor_pos;
124
125
682
        text_input -> gx_multi_line_text_input_text_insert_position = text_input -> gx_multi_line_text_input_end_mark;
126
127
        /* Recalculate cursor position according to cursor insert position. */
128
682
        _gx_multi_line_text_input_cursor_pos_update(text_input, GX_TRUE);
129
130
682
        end_pos = text_input -> gx_multi_line_text_input_cursor_instance.gx_text_input_cursor_pos;
131
132
        /* Dirty mark. */
133
682
        if (old_shift == text_input -> gx_multi_line_text_view_text_scroll_shift)
134
        {
135
631
            _gx_multi_line_text_input_text_rectangle_get(text_input, start_pos, end_pos, &cur_rect);
136
137
            /* Mark highlight area as dirty. */
138
631
            _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
139
        }
140
        else
141
        {
142
51
            _gx_system_dirty_mark((GX_WIDGET *)text_input);
143
        }
144
    }
145
683
    return GX_SUCCESS;
146
}
147