GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_input_mark_end.c Lines: 21 21 100.0 %
Date: 2024-12-05 08:52:37 Branches: 4 4 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_multi_line_text_input.h"
29
#include "gx_multi_line_text_view.h"
30
#include "gx_text_input_cursor.h"
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_multi_line_text_input_mark_end                  PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function moves the end mark of highligh text to the end        */
45
/*    of the line.                                                        */
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_text_input_cursor_dirty_rectangle_get                           */
59
/*                                          Retrieve cursor rectangle     */
60
/*    _gx_multi_line_text_input_cursor_pos_calculate                      */
61
/*                                          Calculate cursor position     */
62
/*                                            according to click point    */
63
/*    _gx_multi_line_text_input_text_rectangle_get                        */
64
/*                                          Retrieve text rectangle       */
65
/*                                            between specified positions */
66
/*    _gx_system_dirty_partial_add          Mark specified area dirty     */
67
/*    _gx_system_dirty_mark                 Mark specified widget dirty   */
68
/*                                                                        */
69
/*  CALLED BY                                                             */
70
/*                                                                        */
71
/*    _gx_multi_line_text_input_keydown_process                           */
72
/*                                                                        */
73
/*  RELEASE HISTORY                                                       */
74
/*                                                                        */
75
/*    DATE              NAME                      DESCRIPTION             */
76
/*                                                                        */
77
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
78
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
79
/*                                            resulting in version 6.1    */
80
/*                                                                        */
81
/**************************************************************************/
82
63
UINT _gx_multi_line_text_input_mark_end(GX_MULTI_LINE_TEXT_INPUT *text_input)
83
{
84
63
GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance;
85
GX_POINT              old_cursor_pos;
86
GX_POINT              cursor_pos;
87
GX_RECTANGLE          cursor_rect;
88
INT                   shift;
89
63
UINT                  start_mark = text_input -> gx_multi_line_text_input_start_mark;
90
63
UINT                  end_mark = text_input -> gx_multi_line_text_input_end_mark;
91
92
63
    old_cursor_pos = cursor_ptr -> gx_text_input_cursor_pos;
93
63
    if (start_mark == end_mark)
94
    {
95
27
        start_mark = text_input -> gx_multi_line_text_input_text_insert_position;
96
27
        end_mark = text_input -> gx_multi_line_text_input_text_insert_position;
97
98
27
        text_input -> gx_multi_line_text_input_start_mark = start_mark;
99
27
        text_input -> gx_multi_line_text_input_end_mark = end_mark;
100
    }
101
102
63
    cursor_pos = old_cursor_pos;
103
63
    cursor_pos.gx_point_x = (GX_VALUE)(text_input -> gx_window_client.gx_rectangle_right -
104
63
                                       text_input -> gx_multi_line_text_view_whitespace);
105
106
63
    shift = text_input -> gx_multi_line_text_view_text_scroll_shift;
107
108
    /* Calculate new cursor position. */
109
63
    _gx_multi_line_text_input_cursor_pos_calculate(text_input, cursor_pos);
110
111
63
    text_input -> gx_multi_line_text_input_end_mark = text_input -> gx_multi_line_text_input_text_insert_position;
112
63
    if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift)
113
    {
114
39
        _gx_multi_line_text_input_text_rectangle_get(text_input, old_cursor_pos, cursor_ptr -> gx_text_input_cursor_pos, &cursor_rect);
115
116
        /* Mark highlight area as dirty. */
117
39
        _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cursor_rect);
118
    }
119
    else
120
    {
121
24
        _gx_system_dirty_mark((GX_WIDGET *)text_input);
122
    }
123
124
63
    return GX_SUCCESS;
125
}
126