1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
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 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_gx_scroll_thumb_shift_limit(GX_SCROLL_THUMB * thumb,INT shift)76 INT _gx_scroll_thumb_shift_limit(GX_SCROLL_THUMB *thumb, INT shift)
77 {
78 INT           minlimit;
79 INT           maxlimit;
80 INT           shiftpos;
81 GX_WIDGET    *parent;
82 GX_SCROLLBAR *bar;
83 GX_RECTANGLE  parentsize;
84 ULONG         style;
85 
86     /* pick up thumb style */
87     style = thumb -> gx_widget_style;
88 
89     /* pick up parent scrollbar */
90     parent = thumb -> gx_widget_parent;
91     parentsize = parent -> gx_widget_size;
92 
93     bar = (GX_SCROLLBAR *)parent;
94 
95     if (style & GX_SCROLLBAR_VERTICAL)
96     {
97         minlimit = parentsize.gx_rectangle_top + bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min;
98         maxlimit = parentsize.gx_rectangle_bottom - bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_max;
99 
100         if (shift > 0)
101         {
102             /* shifting down, don't allow down too far */
103             shiftpos = thumb -> gx_widget_size.gx_rectangle_bottom + shift;
104             if (shiftpos > maxlimit)
105             {
106                 shift = maxlimit - thumb -> gx_widget_size.gx_rectangle_bottom;
107             }
108         }
109         else
110         {
111             /* shifting up, don't allow shift up too far */
112             shiftpos = thumb -> gx_widget_size.gx_rectangle_top + shift;
113             if (shiftpos < minlimit)
114             {
115                 shift = minlimit - thumb -> gx_widget_size.gx_rectangle_top;
116             }
117         }
118     }
119     else
120     {
121         minlimit = parentsize.gx_rectangle_left + bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min;
122         maxlimit = parentsize.gx_rectangle_right - bar -> gx_scrollbar_appearance.gx_scroll_thumb_travel_max;
123 
124         if (shift > 0)
125         {
126             /* shifting right, don't allow down too over */
127             shiftpos = thumb -> gx_widget_size.gx_rectangle_right + shift;
128             if (shiftpos > maxlimit)
129             {
130                 shift = maxlimit - thumb -> gx_widget_size.gx_rectangle_right;
131             }
132         }
133         else
134         {
135             /* shifting left, don't allow shift up too far */
136             shiftpos = thumb -> gx_widget_size.gx_rectangle_left + shift;
137             if (shiftpos < minlimit)
138             {
139                 shift = minlimit - thumb -> gx_widget_size.gx_rectangle_left;
140             }
141         }
142     }
143     return shift;
144 }
145 
146