GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_scrollbar_size_update.c Lines: 34 34 100.0 %
Date: 2024-12-05 08:52:37 Branches: 8 8 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
/**   Scrollbar Management (Scrollbar)                                    */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
/* Include necessary system files.  */
24
25
#include "gx_api.h"
26
#include "gx_system.h"
27
#include "gx_display.h"
28
#include "gx_context.h"
29
#include "gx_widget.h"
30
#include "gx_utility.h"
31
#include "gx_scrollbar.h"
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_scrollbar_size_update                           PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    Calculate and return the position of a GX_SCROLLBAR thumb button    */
46
/*    based scrollbar dimensions, current value, and visible range.       */
47
/*                                                                        */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    scroll                                Scroll control block          */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _gx_widget_border_width_get           Obtain widget border width    */
60
/*    _gx_widget_resize                     Resize a widget               */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    GUIX Internal Code                                                  */
65
/*                                                                        */
66
/*  RELEASE HISTORY                                                       */
67
/*                                                                        */
68
/*    DATE              NAME                      DESCRIPTION             */
69
/*                                                                        */
70
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
71
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
72
/*                                            resulting in version 6.1    */
73
/*                                                                        */
74
/**************************************************************************/
75
6891
VOID _gx_scrollbar_size_update(GX_SCROLLBAR *scroll)
76
{
77
GX_WINDOW   *parent;
78
GX_RECTANGLE size;
79
GX_VALUE     border_width;
80
6891
UINT         style = scroll -> gx_widget_style;
81
82
6891
    parent = (GX_WINDOW *)scroll -> gx_widget_parent;
83
84
6891
    if (parent)
85
    {
86
6889
        _gx_widget_border_width_get((GX_WIDGET *) parent, &border_width);
87
88
6889
        if (style & GX_SCROLLBAR_VERTICAL)
89
        {
90
5868
            size.gx_rectangle_top = parent -> gx_window_client.gx_rectangle_top;
91
5868
            size.gx_rectangle_bottom = parent -> gx_window_client.gx_rectangle_bottom;
92
5868
            size.gx_rectangle_right = (GX_VALUE)(parent -> gx_widget_size.gx_rectangle_right - border_width);
93
5868
            size.gx_rectangle_left = (GX_VALUE)(size.gx_rectangle_right - scroll -> gx_scrollbar_appearance.gx_scroll_width + 1);
94
        }
95
        else
96
        {
97
1021
            size.gx_rectangle_left = parent -> gx_window_client.gx_rectangle_left;
98
1021
            size.gx_rectangle_right = parent -> gx_window_client.gx_rectangle_right;
99
1021
            size.gx_rectangle_bottom = (GX_VALUE)(parent -> gx_widget_size.gx_rectangle_bottom - border_width);
100
1021
            size.gx_rectangle_top = (GX_VALUE)(size.gx_rectangle_bottom - scroll -> gx_scrollbar_appearance.gx_scroll_width + 1);
101
        }
102
6889
        _gx_widget_resize((GX_WIDGET *)scroll, &size);
103
104
6889
        if (style & GX_SCROLLBAR_END_BUTTONS)
105
        {
106
6690
            if (style & GX_SCROLLBAR_VERTICAL)
107
            {
108
                /* calculate size for up button */
109
5799
                size.gx_rectangle_top = (GX_VALUE)(scroll -> gx_widget_size.gx_rectangle_top + 1);
110
5799
                size.gx_rectangle_right = (GX_VALUE)(scroll -> gx_widget_size.gx_rectangle_right - 1);
111
5799
                size.gx_rectangle_left = (GX_VALUE)(scroll->gx_widget_size.gx_rectangle_left + 1);
112
5799
                size.gx_rectangle_bottom = (GX_VALUE)(size.gx_rectangle_top + scroll -> gx_scrollbar_appearance.gx_scroll_width - 1);
113
5799
                _gx_widget_resize((GX_WIDGET *)&scroll -> gx_scrollbar_upleft, &size);
114
115
                /* calculate size for down button */
116
5799
                size.gx_rectangle_bottom = (GX_VALUE)(scroll -> gx_widget_size.gx_rectangle_bottom - 1);
117
5799
                size.gx_rectangle_top = (GX_VALUE)(size.gx_rectangle_bottom - scroll -> gx_scrollbar_appearance.gx_scroll_width + 1);
118
5799
                _gx_widget_resize((GX_WIDGET *)&scroll -> gx_scrollbar_downright, &size);
119
            }
120
            else
121
            {
122
                /* calculate size for left button */
123
891
                size.gx_rectangle_left = (GX_VALUE)(scroll -> gx_widget_size.gx_rectangle_left + 1);
124
891
                size.gx_rectangle_bottom = (GX_VALUE)(scroll -> gx_widget_size.gx_rectangle_bottom - 1);
125
891
                size.gx_rectangle_top = (GX_VALUE)(scroll->gx_widget_size.gx_rectangle_top + 1);
126
891
                size.gx_rectangle_right = (GX_VALUE)(size.gx_rectangle_left + scroll -> gx_scrollbar_appearance.gx_scroll_width - 1);
127
891
                _gx_widget_resize((GX_WIDGET *)&scroll -> gx_scrollbar_upleft, &size);
128
129
                /* calculate size for right button */
130
891
                size.gx_rectangle_right = (GX_VALUE)(scroll -> gx_widget_size.gx_rectangle_right - 1);
131
891
                size.gx_rectangle_left = (GX_VALUE)(size.gx_rectangle_right - scroll -> gx_scrollbar_appearance.gx_scroll_width);
132
891
                _gx_widget_resize((GX_WIDGET *)&scroll -> gx_scrollbar_downright, &size);
133
            }
134
        }
135
    }
136
6891
}
137