GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_scroll_thumb_shift_limit.c Lines: 25 25 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
/**   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_thumb_shift_limit                     PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    Limit the travel of a scrollbar thumb button so that it cannot      */
46
/*    shift outside parent's limits.                                      */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    thumb                                 Thumb button control block    */
51
/*    shift                                 Requested shift amount        */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Shift                                 Allowed shift amount          */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    None                                                                */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    Application Code                                                    */
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
1254
INT _gx_scroll_thumb_shift_limit(GX_SCROLL_THUMB *thumb, INT shift)
76
{
77
INT           minlimit;
78
INT           maxlimit;
79
INT           shiftpos;
80
GX_WIDGET    *parent;
81
GX_SCROLLBAR *bar;
82
GX_RECTANGLE  parentsize;
83
ULONG         style;
84
85
    /* pick up thumb style */
86
1254
    style = thumb -> gx_widget_style;
87
88
    /* pick up parent scrollbar */
89
1254
    parent = thumb -> gx_widget_parent;
90
1254
    parentsize = parent -> gx_widget_size;
91
92
1254
    bar = (GX_SCROLLBAR *)parent;
93
94
1254
    if (style & GX_SCROLLBAR_VERTICAL)
95
    {
96
510
        minlimit = parentsize.gx_rectangle_top + bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min;
97
510
        maxlimit = parentsize.gx_rectangle_bottom - bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_max;
98
99
510
        if (shift > 0)
100
        {
101
            /* shifting down, don't allow down too far */
102
369
            shiftpos = thumb -> gx_widget_size.gx_rectangle_bottom + shift;
103
369
            if (shiftpos > maxlimit)
104
            {
105
19
                shift = maxlimit - thumb -> gx_widget_size.gx_rectangle_bottom;
106
            }
107
        }
108
        else
109
        {
110
            /* shifting up, don't allow shift up too far */
111
141
            shiftpos = thumb -> gx_widget_size.gx_rectangle_top + shift;
112
141
            if (shiftpos < minlimit)
113
            {
114
22
                shift = minlimit - thumb -> gx_widget_size.gx_rectangle_top;
115
            }
116
        }
117
    }
118
    else
119
    {
120
744
        minlimit = parentsize.gx_rectangle_left + bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min;
121
744
        maxlimit = parentsize.gx_rectangle_right - bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_max;
122
123
744
        if (shift > 0)
124
        {
125
            /* shifting right, don't allow down too over */
126
374
            shiftpos = thumb -> gx_widget_size.gx_rectangle_right + shift;
127
374
            if (shiftpos > maxlimit)
128
            {
129
1
                shift = maxlimit - thumb -> gx_widget_size.gx_rectangle_right;
130
            }
131
        }
132
        else
133
        {
134
            /* shifting left, don't allow shift up too far */
135
370
            shiftpos = thumb -> gx_widget_size.gx_rectangle_left + shift;
136
370
            if (shiftpos < minlimit)
137
            {
138
2
                shift = minlimit - thumb -> gx_widget_size.gx_rectangle_left;
139
            }
140
        }
141
    }
142
1254
    return shift;
143
}
144