GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_rich_text_view_scroll_info_get.c Lines: 28 28 100.0 %
Date: 2026-03-06 19:21:09 Branches: 14 14 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
/**   Rich Text View Management (Rich 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_rich_text_view.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_rich_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 rich text view scroll information.           */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    text_view                            Rich text view control block   */
51
/*    style                                Reserved                       */
52
/*    info                                 Pointer to destination for     */
53
/*                                           scroll info                  */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    status                                Completion status             */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _gx_widget_font_get                   Obtain the font               */
62
/*    _gx_multi_line_text_view_string_total_rows_computer                 */
63
/*                                          Compute the number of rows    */
64
/*                                            for the text view text      */
65
/*    _gx_utility_rectangle_resize          Offset rectangle              */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    GUIX Internal Code                                                  */
70
/*                                                                        */
71
/**************************************************************************/
72
50
UINT _gx_rich_text_view_scroll_info_get(GX_RICH_TEXT_VIEW *text_view, ULONG style, GX_SCROLL_INFO *info)
73
{
74
GX_RECTANGLE client;
75
GX_VALUE     line_height;
76
INT          text_height;
77
INT          value;
78
INT          shift;
79
GX_FONT     *font;
80
81
    GX_PARAMETER_NOT_USED(style);
82
83
    /* Get font. */
84
50
    _gx_widget_font_get((GX_WIDGET *)text_view, text_view -> gx_rich_text_view_fonts.gx_rich_text_fonts_normal_id, &font);
85
86
50
    if (!font)
87
    {
88
3
        return GX_FAILURE;
89
    }
90
91
47
    if (text_view -> gx_multi_line_text_view_line_index_old)
92
    {
93
        /* Calculate text total height. */
94
6
        _gx_rich_text_view_text_total_height_calculate(text_view);
95
    }
96
97
    /* Pickup text height. */
98
47
    line_height = (GX_VALUE)(font -> gx_font_line_height + text_view -> gx_multi_line_text_view_line_space);
99
47
    text_height = (INT)text_view -> gx_rich_text_view_text_total_height;
100
101
47
    client = text_view -> gx_window_client;
102
103
47
    if (text_view -> gx_multi_line_text_view_whitespace)
104
    {
105
        /* Offset client bounding box.  */
106
44
        _gx_utility_rectangle_resize(&client, (GX_VALUE)(-text_view -> gx_multi_line_text_view_whitespace));
107
    }
108
109
47
    info -> gx_scroll_minimum = client.gx_rectangle_top;
110
47
    info -> gx_scroll_maximum = info -> gx_scroll_minimum + text_height - 1;
111
47
    info -> gx_scroll_visible = (GX_VALUE)(client.gx_rectangle_bottom - client.gx_rectangle_top + 1);
112
113
47
    if (text_height < info -> gx_scroll_visible)
114
    {
115
36
        info -> gx_scroll_maximum = info -> gx_scroll_minimum + info -> gx_scroll_visible - 1;
116
    }
117
118
47
    shift = text_view -> gx_multi_line_text_view_text_scroll_shift;
119
47
    value = client.gx_rectangle_top - shift;
120
121
47
    if (value < info -> gx_scroll_minimum)
122
    {
123
1
        value = info -> gx_scroll_minimum;
124
    }
125
46
    else if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
126
    {
127
2
        value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
128
    }
129
130
47
    shift = client.gx_rectangle_top - value;
131
132
47
    if (shift != text_view -> gx_multi_line_text_view_text_scroll_shift)
133
    {
134
        /* Update shift value.  */
135
3
        text_view -> gx_multi_line_text_view_text_scroll_shift = shift;
136
    }
137
138
47
    info -> gx_scroll_value = value;
139
47
    info -> gx_scroll_increment = line_height;
140
141
47
    return GX_SUCCESS;
142
}
143