GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_scroll_thumb_shift_limit.c Lines: 25 25 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
/**   Scrollbar Management (Scrollbar)                                    */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_display.h"
29
#include "gx_context.h"
30
#include "gx_widget.h"
31
#include "gx_utility.h"
32
#include "gx_scrollbar.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_scrollbar_thumb_shift_limit                     PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    Limit the travel of a scrollbar thumb button so that it cannot      */
47
/*    shift outside parent's limits.                                      */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    thumb                                 Thumb button control block    */
52
/*    shift                                 Requested shift amount        */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    Shift                                 Allowed shift amount          */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    None                                                                */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Application Code                                                    */
65
/*    GUIX Internal Code                                                  */
66
/*                                                                        */
67
/**************************************************************************/
68
1254
INT _gx_scroll_thumb_shift_limit(GX_SCROLL_THUMB *thumb, INT shift)
69
{
70
INT           minlimit;
71
INT           maxlimit;
72
INT           shiftpos;
73
GX_WIDGET    *parent;
74
GX_SCROLLBAR *bar;
75
GX_RECTANGLE  parentsize;
76
ULONG         style;
77
78
    /* pick up thumb style */
79
1254
    style = thumb -> gx_widget_style;
80
81
    /* pick up parent scrollbar */
82
1254
    parent = thumb -> gx_widget_parent;
83
1254
    parentsize = parent -> gx_widget_size;
84
85
1254
    bar = (GX_SCROLLBAR *)parent;
86
87
1254
    if (style & GX_SCROLLBAR_VERTICAL)
88
    {
89
510
        minlimit = parentsize.gx_rectangle_top + bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min;
90
510
        maxlimit = parentsize.gx_rectangle_bottom - bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_max;
91
92
510
        if (shift > 0)
93
        {
94
            /* shifting down, don't allow down too far */
95
369
            shiftpos = thumb -> gx_widget_size.gx_rectangle_bottom + shift;
96
369
            if (shiftpos > maxlimit)
97
            {
98
19
                shift = maxlimit - thumb -> gx_widget_size.gx_rectangle_bottom;
99
            }
100
        }
101
        else
102
        {
103
            /* shifting up, don't allow shift up too far */
104
141
            shiftpos = thumb -> gx_widget_size.gx_rectangle_top + shift;
105
141
            if (shiftpos < minlimit)
106
            {
107
22
                shift = minlimit - thumb -> gx_widget_size.gx_rectangle_top;
108
            }
109
        }
110
    }
111
    else
112
    {
113
744
        minlimit = parentsize.gx_rectangle_left + bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min;
114
744
        maxlimit = parentsize.gx_rectangle_right - bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_max;
115
116
744
        if (shift > 0)
117
        {
118
            /* shifting right, don't allow down too over */
119
374
            shiftpos = thumb -> gx_widget_size.gx_rectangle_right + shift;
120
374
            if (shiftpos > maxlimit)
121
            {
122
1
                shift = maxlimit - thumb -> gx_widget_size.gx_rectangle_right;
123
            }
124
        }
125
        else
126
        {
127
            /* shifting left, don't allow shift up too far */
128
370
            shiftpos = thumb -> gx_widget_size.gx_rectangle_left + shift;
129
370
            if (shiftpos < minlimit)
130
            {
131
2
                shift = minlimit - thumb -> gx_widget_size.gx_rectangle_left;
132
            }
133
        }
134
    }
135
1254
    return shift;
136
}
137