GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_view_scroll_info_get.c Lines: 31 31 100.0 %
Date: 2024-12-05 08:52:37 Branches: 16 16 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_system.h"
28
#include "gx_window.h"
29
#include "gx_widget.h"
30
#include "gx_utility.h"
31
#include "gx_multi_line_text_view.h"
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_multi_line_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 multi-line text view scroll information.     */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    text_view                            Multi line text view widget    */
50
/*                                           control block                */
51
/*    style                                 Style                         */
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
/*  RELEASE HISTORY                                                       */
72
/*                                                                        */
73
/*    DATE              NAME                      DESCRIPTION             */
74
/*                                                                        */
75
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
76
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
77
/*                                            resulting in version 6.1    */
78
/*                                                                        */
79
/**************************************************************************/
80
4512
UINT _gx_multi_line_text_view_scroll_info_get(GX_MULTI_LINE_TEXT_VIEW *text_view, ULONG style, GX_SCROLL_INFO *info)
81
{
82
GX_RECTANGLE client;
83
GX_VALUE     line_height;
84
INT          text_height;
85
INT          value;
86
INT          shift;
87
GX_FONT     *font;
88
89
    GX_PARAMETER_NOT_USED(style);
90
91
    /* Get font. */
92
4512
    _gx_widget_font_get((GX_WIDGET *)text_view, text_view -> gx_multi_line_text_view_font_id, &font);
93
94
4512
    if (!font)
95
    {
96
15
        return GX_FAILURE;
97
    }
98
99
4497
    if (text_view -> gx_multi_line_text_view_line_index_old)
100
    {
101
        /* Calculate text total rows. */
102
42
        _gx_multi_line_text_view_string_total_rows_compute(text_view);
103
    }
104
105
    /* Pickup text height. */
106
4497
    line_height = (GX_VALUE)(font -> gx_font_line_height + text_view -> gx_multi_line_text_view_line_space);
107
4497
    text_height = (INT)(line_height * (INT)text_view -> gx_multi_line_text_view_text_total_rows);
108
109
4497
    client = text_view -> gx_window_client;
110
111
4497
    if (text_view -> gx_multi_line_text_view_whitespace)
112
    {
113
        /* Offset client bounding box.  */
114
3527
        _gx_utility_rectangle_resize(&client, (GX_VALUE)(-text_view -> gx_multi_line_text_view_whitespace));
115
    }
116
117
4497
    info -> gx_scroll_minimum = client.gx_rectangle_top;
118
4497
    info -> gx_scroll_maximum = info -> gx_scroll_minimum + text_height - 1;
119
4497
    info -> gx_scroll_visible = (GX_VALUE)(client.gx_rectangle_bottom - client.gx_rectangle_top + 1);
120
121
4497
    if (text_height < info -> gx_scroll_visible)
122
    {
123
202
        info -> gx_scroll_maximum = info -> gx_scroll_minimum + info -> gx_scroll_visible - 1;
124
    }
125
126
4497
    shift = text_view -> gx_multi_line_text_view_text_scroll_shift;
127
4497
    value = client.gx_rectangle_top - shift;
128
129
4497
    if (value < info -> gx_scroll_minimum)
130
    {
131
8
        value = info -> gx_scroll_minimum;
132
    }
133
4489
    else if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
134
    {
135
121
        value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
136
    }
137
138
4497
    shift = client.gx_rectangle_top - value;
139
140
4497
    if (shift != text_view -> gx_multi_line_text_view_text_scroll_shift)
141
    {
142
        /* Update shift value.  */
143
129
        text_view -> gx_multi_line_text_view_text_scroll_shift = shift;
144
    }
145
146
4497
    info -> gx_scroll_value = value;
147
4497
    info -> gx_scroll_increment = line_height;
148
149
4497
    if (text_view -> gx_multi_line_text_view_text_total_rows >
150
4497
        text_view -> gx_multi_line_text_view_cache_size)
151
    {
152
3997
        _gx_multi_line_text_view_line_cache_update((GX_MULTI_LINE_TEXT_VIEW *)text_view);
153
    }
154
155
4497
    return GX_SUCCESS;
156
}
157