GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_single_line_text_input_text_select.c Lines: 22 22 100.0 %
Date: 2024-12-05 08:52:37 Branches: 8 8 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 (Single 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_single_line_text_input.h"
29
#include "gx_text_input_cursor.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_single_line_text_input_text_select              PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function highlighs text with specified start mark and end mark */
44
/*    index.                                                              */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    text_input                            Single-line text input widget */
49
/*                                            control block               */
50
/*    start_mark                            The index of the first        */
51
/*                                            highlight character.        */
52
/*    end_mark                              The index of the last         */
53
/*                                            highlight character         */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    None                                                                */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _gx_system_dirty_mark                Mark widget as drity           */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    Application Code                                                    */
66
/*    GUIX Internal Code                                                  */
67
/*                                                                        */
68
/*  RELEASE HISTORY                                                       */
69
/*                                                                        */
70
/*    DATE              NAME                      DESCRIPTION             */
71
/*                                                                        */
72
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
73
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
74
/*                                            resulting in version 6.1    */
75
/*                                                                        */
76
/**************************************************************************/
77
397
UINT _gx_single_line_text_input_text_select(GX_SINGLE_LINE_TEXT_INPUT *input, UINT start_index, UINT end_index)
78
{
79
GX_RECTANGLE dirty_rect;
80
397
UINT         start_mark = input -> gx_single_line_text_input_start_mark;
81
397
UINT         end_mark = input -> gx_single_line_text_input_end_mark;
82
83
397
    if (start_index <= end_index)
84
    {
85
252
        input -> gx_single_line_text_input_start_mark = start_index;
86
252
        input -> gx_single_line_text_input_end_mark = end_index + 1;
87
    }
88
    else
89
    {
90
145
        input -> gx_single_line_text_input_start_mark = start_index + 1;
91
145
        input -> gx_single_line_text_input_end_mark = end_index;
92
    }
93
94
397
    if (input -> gx_widget_status & GX_STATUS_VISIBLE)
95
    {
96
396
        if (start_mark != end_mark)
97
        {
98
1
            _gx_single_line_text_input_text_rectangle_get(input, (INT)(start_mark - end_mark), &dirty_rect);
99
100
            /* Mark old highlight area as dirty. */
101
1
            _gx_system_dirty_partial_add((GX_WIDGET *)input, &dirty_rect);
102
        }
103
        else
104
        {
105
395
            _gx_text_input_cursor_dirty_rectangle_get(&input->gx_single_line_text_input_cursor_instance, &dirty_rect);
106
107
            /* Mark cursor area as dirty. */
108
395
            _gx_system_dirty_partial_add((GX_WIDGET *)input, &dirty_rect);
109
        }
110
111
396
        start_mark = input -> gx_single_line_text_input_start_mark;
112
396
        end_mark = input -> gx_single_line_text_input_end_mark;
113
114
396
        if (input -> gx_single_line_text_input_insert_pos != end_mark)
115
        {
116
293
            input -> gx_single_line_text_input_insert_pos = end_mark;
117
293
            _gx_single_line_text_input_position_update(input);
118
        }
119
120
396
        _gx_single_line_text_input_text_rectangle_get(input, (INT)(start_mark - end_mark), &dirty_rect);
121
122
        /* Mark highlight text area as dirty. */
123
396
        _gx_system_dirty_partial_add((GX_WIDGET *)input, &dirty_rect);
124
    }
125
126
397
    return GX_SUCCESS;
127
}
128