GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_view_scroll_info_get.c Lines: 31 31 100.0 %
Date: 2026-03-06 19:21:09 Branches: 16 16 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   Multi Line Text View Management (Multi Line Text View)              */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
#include "gx_window.h"
30
#include "gx_widget.h"
31
#include "gx_utility.h"
32
#include "gx_multi_line_text_view.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_multi_line_text_view_scroll_info_get            PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function gets the multi-line text view scroll information.     */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    text_view                            Multi line text view widget    */
51
/*                                           control block                */
52
/*    style                                 Style                         */
53
/*    info                                 Pointer to destination for     */
54
/*                                           scroll info                  */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    status                                Completion status             */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _gx_widget_font_get                   Obtain the font               */
63
/*    _gx_multi_line_text_view_string_total_rows_computer                 */
64
/*                                          Compute the number of rows    */
65
/*                                            for the text view text      */
66
/*    _gx_utility_rectangle_resize          Offset rectangle              */
67
/*                                                                        */
68
/*  CALLED BY                                                             */
69
/*                                                                        */
70
/*    GUIX Internal Code                                                  */
71
/*                                                                        */
72
/**************************************************************************/
73
4512
UINT _gx_multi_line_text_view_scroll_info_get(GX_MULTI_LINE_TEXT_VIEW *text_view, ULONG style, GX_SCROLL_INFO *info)
74
{
75
GX_RECTANGLE client;
76
GX_VALUE     line_height;
77
INT          text_height;
78
INT          value;
79
INT          shift;
80
GX_FONT     *font;
81
82
    GX_PARAMETER_NOT_USED(style);
83
84
    /* Get font. */
85
4512
    _gx_widget_font_get((GX_WIDGET *)text_view, text_view -> gx_multi_line_text_view_font_id, &font);
86
87
4512
    if (!font)
88
    {
89
15
        return GX_FAILURE;
90
    }
91
92
4497
    if (text_view -> gx_multi_line_text_view_line_index_old)
93
    {
94
        /* Calculate text total rows. */
95
42
        _gx_multi_line_text_view_string_total_rows_compute(text_view);
96
    }
97
98
    /* Pickup text height. */
99
4497
    line_height = (GX_VALUE)(font -> gx_font_line_height + text_view -> gx_multi_line_text_view_line_space);
100
4497
    text_height = (INT)(line_height * (INT)text_view -> gx_multi_line_text_view_text_total_rows);
101
102
4497
    client = text_view -> gx_window_client;
103
104
4497
    if (text_view -> gx_multi_line_text_view_whitespace)
105
    {
106
        /* Offset client bounding box.  */
107
3527
        _gx_utility_rectangle_resize(&client, (GX_VALUE)(-text_view -> gx_multi_line_text_view_whitespace));
108
    }
109
110
4497
    info -> gx_scroll_minimum = client.gx_rectangle_top;
111
4497
    info -> gx_scroll_maximum = info -> gx_scroll_minimum + text_height - 1;
112
4497
    info -> gx_scroll_visible = (GX_VALUE)(client.gx_rectangle_bottom - client.gx_rectangle_top + 1);
113
114
4497
    if (text_height < info -> gx_scroll_visible)
115
    {
116
202
        info -> gx_scroll_maximum = info -> gx_scroll_minimum + info -> gx_scroll_visible - 1;
117
    }
118
119
4497
    shift = text_view -> gx_multi_line_text_view_text_scroll_shift;
120
4497
    value = client.gx_rectangle_top - shift;
121
122
4497
    if (value < info -> gx_scroll_minimum)
123
    {
124
8
        value = info -> gx_scroll_minimum;
125
    }
126
4489
    else if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
127
    {
128
121
        value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
129
    }
130
131
4497
    shift = client.gx_rectangle_top - value;
132
133
4497
    if (shift != text_view -> gx_multi_line_text_view_text_scroll_shift)
134
    {
135
        /* Update shift value.  */
136
129
        text_view -> gx_multi_line_text_view_text_scroll_shift = shift;
137
    }
138
139
4497
    info -> gx_scroll_value = value;
140
4497
    info -> gx_scroll_increment = line_height;
141
142
4497
    if (text_view -> gx_multi_line_text_view_text_total_rows >
143
4497
        text_view -> gx_multi_line_text_view_cache_size)
144
    {
145
3997
        _gx_multi_line_text_view_line_cache_update((GX_MULTI_LINE_TEXT_VIEW *)text_view);
146
    }
147
148
4497
    return GX_SUCCESS;
149
}
150