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 /**************************************************************************/
_gx_window_client_scroll(GX_WINDOW * window,GX_VALUE x_scroll,GX_VALUE y_scroll)78 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     scroll = GX_NULL;
88 
89     if (x_scroll)
90     {
91         _gx_window_scrollbar_find(window, (USHORT)GX_TYPE_HORIZONTAL_SCROLL, &scroll);
92 
93         if (scroll)
94         {
95             scroll_value = scroll -> gx_scrollbar_info.gx_scroll_value;
96             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             _gx_scrollbar_value_set(scroll, scroll_value);
102             x_scroll = 0;
103         }
104     }
105 
106     if (y_scroll)
107     {
108         _gx_window_scrollbar_find(window, GX_TYPE_VERTICAL_SCROLL, &scroll);
109 
110         if (scroll)
111         {
112             scroll_value = scroll -> gx_scrollbar_info.gx_scroll_value;
113             scroll_value = scroll_value - y_scroll;
114             _gx_scrollbar_value_set(scroll, scroll_value);
115             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     if (x_scroll)
126     {
127         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             _gx_window_scroll(window, x_scroll, 0);
133             _gx_window_scroll(window, 0, y_scroll);
134         }
135         else
136         {
137             /* just scrolling in x */
138             _gx_window_scroll(window, x_scroll, 0);
139         }
140     }
141     else
142     {
143         /* just scrolling in y */
144         _gx_window_scroll(window, 0, y_scroll);
145     }
146 
147     return GX_SUCCESS;
148 }
149 
150