GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_window_client_scroll.c Lines: 23 23 100.0 %
Date: 2024-12-05 08:52:37 Branches: 12 12 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
/**   Window Management (Window)                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_widget.h"
28
#include "gx_window.h"
29
#include "gx_system.h"
30
#include "gx_display.h"
31
#include "gx_canvas.h"
32
#include "gx_utility.h"
33
#include "gx_scrollbar.h"
34
35
/**************************************************************************/
36
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _gx_window_client_scroll                            PORTABLE C      */
40
/*                                                           6.1          */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    Kenneth Maxwell, Microsoft Corporation                              */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This service scrolls the window client area by the specified amount */
48
/*                                                                        */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    window                                Pointer to window             */
53
/*    x_scroll                              Amount to scroll on x-axis    */
54
/*    y_scroll                              Amount to scroll on y-axis    */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    status                                Completion status             */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _gx_widget_scroll                     main scroll function          */
63
/*    _gx_scrollbar_value_set               reset scrollbar thumb pos     */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Application Code                                                    */
68
/*                                                                        */
69
/*  RELEASE HISTORY                                                       */
70
/*                                                                        */
71
/*    DATE              NAME                      DESCRIPTION             */
72
/*                                                                        */
73
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
74
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
75
/*                                            resulting in version 6.1    */
76
/*                                                                        */
77
/**************************************************************************/
78
76
UINT _gx_window_client_scroll(GX_WINDOW *window, GX_VALUE x_scroll, GX_VALUE y_scroll)
79
{
80
GX_SCROLLBAR *scroll;
81
INT           scroll_value;
82
83
    /* This function is designed to be called by the application, i.e. not driven
84
       by the user operating a scrollbar. However if the window does have scrollbars,
85
       we will satisfy the scrolling request by assigning the scroll bar value.
86
     */
87
76
    scroll = GX_NULL;
88
89
76
    if (x_scroll)
90
    {
91
63
        _gx_window_scrollbar_find(window, (USHORT)GX_TYPE_HORIZONTAL_SCROLL, &scroll);
92
93
63
        if (scroll)
94
        {
95
59
            scroll_value = scroll -> gx_scrollbar_info.gx_scroll_value;
96
59
            scroll_value = scroll_value - x_scroll;
97
98
            /* this function will generate a scroll event, which will cause
99
               the parent window to scroll
100
            */
101
59
            _gx_scrollbar_value_set(scroll, scroll_value);
102
59
            x_scroll = 0;
103
        }
104
    }
105
106
76
    if (y_scroll)
107
    {
108
75
        _gx_window_scrollbar_find(window, GX_TYPE_VERTICAL_SCROLL, &scroll);
109
110
75
        if (scroll)
111
        {
112
71
            scroll_value = scroll -> gx_scrollbar_info.gx_scroll_value;
113
71
            scroll_value = scroll_value - y_scroll;
114
71
            _gx_scrollbar_value_set(scroll, scroll_value);
115
71
            y_scroll = 0;
116
        }
117
    }
118
119
    /* If we get to here with non-zero scroll values, the window is being
120
       scrolled with no scrollbars.
121
       Manually invoke the _gx_window_scroll functions to accomplish
122
       the requested scrolling
123
    */
124
125
76
    if (x_scroll)
126
    {
127
4
        if (y_scroll)
128
        {
129
            /* If we are scrolling both x and y, we need to do two
130
               operations for the block-move to work correctly
131
             */
132
1
            _gx_window_scroll(window, x_scroll, 0);
133
1
            _gx_window_scroll(window, 0, y_scroll);
134
        }
135
        else
136
        {
137
            /* just scrolling in x */
138
3
            _gx_window_scroll(window, x_scroll, 0);
139
        }
140
    }
141
    else
142
    {
143
        /* just scrolling in y */
144
72
        _gx_window_scroll(window, 0, y_scroll);
145
    }
146
147
76
    return GX_SUCCESS;
148
}
149