GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_button_line_pointers_set.c Lines: 25 25 100.0 %
Date: 2024-12-05 08:52:37 Branches: 20 20 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 Button Management (Button)                                     */
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_button.h"
29
#include "gx_system.h"
30
#include "gx_utility.h"
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_multi_line_text_button_line_pointers_set        PORTABLE C      */
37
/*                                                           6.1.10       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function creates a multi-line text button, which is a special  */
45
/*    type of button (widget).                                            */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    button                                Button control block          */
50
/*    name                                  Name of button                */
51
/*    parent                                Parent widget control block   */
52
/*    text_id                               text resource id              */
53
/*    style                                 Style of button               */
54
/*    size                                  Button size                   */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    status                                Completion status             */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _gx_system_string_get                                               */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Application 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
/*                                            added line pointers set     */
75
/*                                            loigc for dynamic bidi text,*/
76
/*                                            resulting in version 6.1    */
77
/*  01-31-2022     Ting Zhu                 Modified comment(s),          */
78
/*                                            updated with new bidi text  */
79
/*                                            reorder function call,      */
80
/*                                            resulting in version 6.1.10 */
81
/*                                                                        */
82
/**************************************************************************/
83
278
VOID _gx_multi_line_text_button_line_pointers_set(GX_MULTI_LINE_TEXT_BUTTON *button)
84
{
85
INT               line_index;
86
GX_STRING         string;
87
GX_CONST GX_CHAR *text;
88
89
#if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT)
90
GX_BIDI_TEXT_INFO           text_info;
91
GX_BIDI_RESOLVED_TEXT_INFO *next;
92
GX_CANVAS                  *canvas;
93
GX_DISPLAY                 *display;
94
#endif
95
96
97
278
    button -> gx_multi_line_text_button_line_count = 1;
98
99
1390
    for (line_index = 0; line_index < GX_MULTI_LINE_TEXT_BUTTON_MAX_LINES; line_index++)
100
    {
101
1112
        button -> gx_multi_line_text_button_lines[line_index].gx_string_ptr = GX_NULL;
102
1112
        button -> gx_multi_line_text_button_lines[line_index].gx_string_length = 0;
103
    }
104
278
    line_index = 0;
105
106
278
    if (button -> gx_text_button_text_id)
107
    {
108
273
        _gx_widget_string_get_ext((GX_WIDGET *)button, button -> gx_text_button_text_id, &string);
109
    }
110
    else
111
    {
112
5
        _gx_system_private_string_get(&button -> gx_text_button_string, &string, button -> gx_widget_style);
113
    }
114
115
278
    text = string.gx_string_ptr;
116
117
278
    if (!text)
118
    {
119
5
        return;
120
    }
121
122
#if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT)
123
    if (_gx_system_bidi_text_enabled)
124
    {
125
        if (!button -> gx_text_button_bidi_resolved_text_info)
126
        {
127
            text_info.gx_bidi_text_info_display_width = -1;
128
            text_info.gx_bidi_text_info_font = GX_NULL;
129
            text_info.gx_bidi_text_info_text = string;
130
            GX_UTILITY_TEXT_DIRECTION_GET(text_info.gx_bidi_text_info_direction, button, canvas, display);
131
            _gx_utility_bidi_paragraph_reorder_ext(&text_info, &button -> gx_text_button_bidi_resolved_text_info);
132
        }
133
134
        next = button -> gx_text_button_bidi_resolved_text_info;
135
136
        while (next)
137
        {
138
            button -> gx_multi_line_text_button_lines[line_index++] = *next -> gx_bidi_resolved_text_info_text;
139
            next = next -> gx_bidi_resolved_text_info_next;
140
141
            if (line_index >= GX_MULTI_LINE_TEXT_BUTTON_MAX_LINES)
142
            {
143
                break;
144
            }
145
        }
146
147
        if (line_index)
148
        {
149
            button -> gx_multi_line_text_button_line_count = line_index;
150
        }
151
    }
152
    else
153
    {
154
#endif
155
4959
        while (*text)
156
        {
157

4688
            if ((*text == GX_KEY_CARRIAGE_RETURN) || (*text == GX_KEY_LINE_FEED))
158
            {
159

546
                if ((*text == GX_KEY_CARRIAGE_RETURN) && (*(text + 1) == GX_KEY_LINE_FEED))
160
                {
161
2
                    text += 2;
162
                }
163
                else
164
                {
165
544
                    text++;
166
                }
167
546
                line_index++;
168
169
546
                if (line_index >= GX_MULTI_LINE_TEXT_BUTTON_MAX_LINES)
170
                {
171
2
                    break;
172
                }
173
                else
174
                {
175
544
                    button -> gx_multi_line_text_button_line_count++;
176
                }
177
            }
178
            else
179
            {
180
4142
                if (button -> gx_multi_line_text_button_lines[line_index].gx_string_ptr == GX_NULL)
181
                {
182
816
                    button -> gx_multi_line_text_button_lines[line_index].gx_string_ptr = text;
183
                }
184
4142
                button -> gx_multi_line_text_button_lines[line_index].gx_string_length++;
185
4142
                text++;
186
            }
187
        }
188
#if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT)
189
    }
190
#endif
191
}
192