GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_view_string_total_rows_compute.c Lines: 38 38 100.0 %
Date: 2024-12-05 08:52:37 Branches: 18 18 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 View Management (Multi Line Text View)              */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_widget.h"
28
#include "gx_system.h"
29
#include "gx_window.h"
30
#include "gx_multi_line_text_view.h"
31
#include "gx_utility.h"
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_multi_line_text_view_string_total_rows_compute  PORTABLE C      */
38
/*                                                           6.1.10       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function gets the total rows of the text view text.            */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    text_view                             Multi line text view          */
50
/*                                            control block               */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    None                                                                */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    _gx_widget_font_get                   Retrieve font                 */
58
/*    _gx_window_client_width_get           Get the client width          */
59
/*    _gx_multi_line_text_view_display_info_get                           */
60
/*                                          Obtain the information on     */
61
/*                                            a string                    */
62
/*    _gx_system_string_get                 Get string by resource id     */
63
/*    _gx_system_private_string_get         Get string pointer in         */
64
/*                                            dynamically copied string   */
65
/*                                            buffer                      */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    _gx_multi_line_text_input_cursor_pos_calculate                      */
70
/*    _gx_multi_line_text_input_cursor_pos_update                         */
71
/*    _gx_multi_line_text_view_text_id_set                                */
72
/*    _gx_multi_line_text_view_text_set                                   */
73
/*                                                                        */
74
/*  RELEASE HISTORY                                                       */
75
/*                                                                        */
76
/*    DATE              NAME                      DESCRIPTION             */
77
/*                                                                        */
78
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
79
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
80
/*                                            added logic to calculate    */
81
/*                                            total lines for dynamic     */
82
/*                                            bidi text,                  */
83
/*                                            resulting in version 6.1    */
84
/*  01-31-2022     Ting Zhu                 Modified comment(s),          */
85
/*                                            updated with new bidi text  */
86
/*                                            reorder function call,      */
87
/*                                            resulting in version 6.1.10 */
88
/*                                                                        */
89
/**************************************************************************/
90
4238
UINT _gx_multi_line_text_view_string_total_rows_compute(GX_MULTI_LINE_TEXT_VIEW *text_view)
91
{
92
4238
UINT                    total_rows = 0;
93
GX_VALUE                client_width;
94
GX_MULTI_LINE_TEXT_INFO text_info;
95
4238
UINT                    index = 0;
96
4238
INT                     cache_index = -1;
97
GX_STRING               string;
98
4238
UINT                    first_cache_line = text_view -> gx_multi_line_text_view_first_cache_line;
99
GX_FONT                *font;
100
101
#if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT)
102
GX_BIDI_TEXT_INFO           bidi_text_info;
103
GX_BIDI_RESOLVED_TEXT_INFO *next;
104
GX_CANVAS                  *canvas;
105
GX_DISPLAY                 *display;
106
#endif
107
108
4238
    _gx_widget_font_get((GX_WIDGET *)text_view, text_view -> gx_multi_line_text_view_font_id, &font);
109
110
4238
    if (!font)
111
    {
112
25
        return GX_FAILURE;
113
    }
114
115
4213
    if (!text_view -> gx_multi_line_text_view_text.gx_string_length)
116
    {
117
171
        text_view -> gx_multi_line_text_view_first_cache_line = 0;
118
171
        text_view -> gx_multi_line_text_view_cache_size = 0;
119
171
        text_view -> gx_multi_line_text_view_text_total_rows = 0;
120
171
        text_view -> gx_multi_line_text_view_line_index[0] = '\0';
121
171
        text_view -> gx_multi_line_text_view_line_index_old = GX_FALSE;
122
171
        return GX_SUCCESS;
123
    }
124
125
4042
    _gx_window_client_width_get((GX_WINDOW *)text_view, &client_width);
126
127
4042
    client_width = (GX_VALUE)(client_width - (text_view -> gx_multi_line_text_view_whitespace << 1));
128
129
4042
    if (text_view -> gx_multi_line_text_view_text_id)
130
    {
131
248
        _gx_widget_string_get_ext((GX_WIDGET *)text_view, text_view -> gx_multi_line_text_view_text_id, &string);
132
    }
133
    else
134
    {
135
3794
        _gx_system_private_string_get(&text_view -> gx_multi_line_text_view_text, &string, text_view -> gx_widget_style);
136
    }
137
138
#if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT)
139
    if (_gx_system_bidi_text_enabled && (text_view -> gx_widget_type == GX_TYPE_MULTI_LINE_TEXT_VIEW))
140
    {
141
        if (!text_view -> gx_multi_line_text_view_bidi_resolved_text_info)
142
        {
143
            bidi_text_info.gx_bidi_text_info_display_width = (GX_VALUE)(client_width - 3);
144
            bidi_text_info.gx_bidi_text_info_font = font;
145
            bidi_text_info.gx_bidi_text_info_text = string;
146
            GX_UTILITY_TEXT_DIRECTION_GET(bidi_text_info.gx_bidi_text_info_direction, text_view, canvas, display);
147
148
            _gx_utility_bidi_paragraph_reorder_ext(&bidi_text_info, &text_view -> gx_multi_line_text_view_bidi_resolved_text_info);
149
        }
150
151
        next = text_view -> gx_multi_line_text_view_bidi_resolved_text_info;
152
153
        while (next)
154
        {
155
            total_rows += next -> gx_bidi_resolved_text_info_total_lines;
156
            next = next -> gx_bidi_resolved_text_info_next;
157
        }
158
    }
159
    else
160
    {
161
#endif
162
        /* Calculate the total rows of text view string. */
163
101320
        while (index < text_view -> gx_multi_line_text_view_text.gx_string_length)
164
        {
165
            /* Save line index. */
166
97278
            if ((total_rows >= first_cache_line) &&
167
74203
                (total_rows < first_cache_line + GX_MULTI_LINE_INDEX_CACHE_SIZE))
168
            {
169
69954
                cache_index = (GX_UBYTE)(total_rows - first_cache_line);
170
69954
                text_view -> gx_multi_line_text_view_line_index[cache_index] = index;
171
            }
172
173
            /* Calculate some information used to draw the text. */
174
97278
            _gx_multi_line_text_view_display_info_get(text_view, index, text_view -> gx_multi_line_text_view_text.gx_string_length, &text_info, (GX_VALUE)(client_width - 2));
175
176
97278
            total_rows++;
177
97278
            index += text_info.gx_text_display_number;
178
        }
179
180
4042
        if ((string.gx_string_ptr[index - 1] == GX_KEY_CARRIAGE_RETURN) ||
181
3610
            (string.gx_string_ptr[index - 1] == GX_KEY_LINE_FEED))
182
        {
183
            /* Save line index. */
184
589
            if (total_rows < first_cache_line + GX_MULTI_LINE_INDEX_CACHE_SIZE)
185
            {
186
412
                cache_index = (GX_UBYTE)(total_rows - first_cache_line);
187
412
                text_view -> gx_multi_line_text_view_line_index[cache_index] = index;
188
            }
189
190
589
            total_rows++;
191
        }
192
193
4042
        text_view -> gx_multi_line_text_view_cache_size = (GX_UBYTE)(cache_index + 1);
194
#if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT)
195
    }
196
#endif
197
198
4042
    text_view -> gx_multi_line_text_view_text_total_rows = total_rows;
199
4042
    text_view -> gx_multi_line_text_view_line_index_old = GX_FALSE;
200
201
4042
    return GX_SUCCESS;
202
}
203