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