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 /**   Scroll Management (Scroll Thumb)                                    */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_system.h"
29 #include "gx_widget.h"
30 #include "gx_scrollbar.h"
31 #include "gx_button.h"
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_scroll_thumb_event_process                      PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function processes events for a scrollbar thumb button         */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    scroll_thumb                          Scroll thumb widget control   */
50 /*                                            block                       */
51 /*    event                                 Pointer to event to process   */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    status                                Completion status             */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_button_event_process              Default button event process  */
60 /*    _gx_system_input_capture              Default widget event process  */
61 /*    _gx_system_input_release              Direct all input events       */
62 /*    _gx_widget_shift                      Shift the widget              */
63 /*    _gx_widget_height_get                 Get the height of widget      */
64 /*    _gx_scroll_thumb_shift_limit          Limit the travel of the       */
65 /*                                            scrollbar thumb button      */
66 /*    _gx_widget_width_get                  Get the width of widget       */
67 /*    [_gx_widget_event_process_function]   Widget event process routine  */
68 /*    _gx_widget_event_process              Default widget event process  */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    Application Code                                                    */
73 /*    GUIX Internal Code                                                  */
74 /*                                                                        */
75 /*  RELEASE HISTORY                                                       */
76 /*                                                                        */
77 /*    DATE              NAME                      DESCRIPTION             */
78 /*                                                                        */
79 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
80 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
81 /*                                            resulting in version 6.1    */
82 /*                                                                        */
83 /**************************************************************************/
_gx_scroll_thumb_event_process(GX_SCROLL_THUMB * thumb,GX_EVENT * event_ptr)84 UINT  _gx_scroll_thumb_event_process(GX_SCROLL_THUMB *thumb, GX_EVENT *event_ptr)
85 {
86 GX_EVENT   newevent;
87 GX_WIDGET *widget = (GX_WIDGET *)thumb;
88 UINT       status;
89 INT        shift;
90 GX_VALUE   widget_height;
91 GX_VALUE   widget_width;
92 
93     /* Default status to success.  */
94     status =  GX_SUCCESS;
95 
96     /* Process relative to the type of event.  */
97     switch (event_ptr -> gx_event_type)
98     {
99     case GX_EVENT_SHOW:
100         status = _gx_widget_event_process(widget, event_ptr);
101         if (thumb -> gx_scroll_thumb_pixelmap)
102         {
103             if (_gx_widget_transparent_pixelmap_detect(widget, thumb -> gx_scroll_thumb_pixelmap))
104             {
105                 _gx_widget_status_add(widget, GX_STATUS_TRANSPARENT);
106             }
107         }
108         break;
109 
110     case GX_EVENT_PEN_DOWN:
111         _gx_system_input_capture(widget);
112 
113         thumb -> gx_scroll_thumb_drag_mode = GX_TRUE;
114 
115         if (widget -> gx_widget_style & GX_SCROLLBAR_VERTICAL)
116         {
117             thumb -> gx_scroll_thumb_start_drag = event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_y;
118         }
119         else
120         {
121             thumb -> gx_scroll_thumb_start_drag = event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_x;
122         }
123         break;
124 
125     case GX_EVENT_PEN_UP:
126         if (widget ->gx_widget_status & GX_STATUS_OWNS_INPUT)
127         {
128             _gx_system_input_release(widget);
129         }
130         break;
131 
132     case GX_EVENT_PEN_DRAG:
133         if (thumb -> gx_widget_style & GX_SCROLLBAR_VERTICAL)
134         {
135             if (event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_y != thumb -> gx_scroll_thumb_start_drag)
136             {
137                 shift = event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_y - thumb -> gx_scroll_thumb_start_drag;
138                 shift = _gx_scroll_thumb_shift_limit(thumb, shift);
139 
140                 if (shift)
141                 {
142                     _gx_widget_shift(widget, 0, (GX_VALUE)shift, GX_TRUE);
143                     thumb -> gx_scroll_thumb_start_drag = event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_y;
144                     newevent.gx_event_type = GX_EVENT_VERTICAL_SCROLL;
145                     newevent.gx_event_payload.gx_event_intdata[0] = widget -> gx_widget_size.gx_rectangle_top;
146 
147                     _gx_widget_height_get(widget, &widget_height);
148                     newevent.gx_event_payload.gx_event_intdata[1] = (INT)widget_height;
149 
150                     newevent.gx_event_sender = GX_ID_SCROLL_THUMB;
151 
152                     /* send the scroll event to my parent scrollbar */
153                     thumb -> gx_widget_parent -> gx_widget_event_process_function(thumb -> gx_widget_parent, &newevent);
154                 }
155             }
156         }
157         else
158         {
159             if (event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_x != thumb -> gx_scroll_thumb_start_drag)
160             {
161                 shift = event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_x - thumb -> gx_scroll_thumb_start_drag;
162                 shift = _gx_scroll_thumb_shift_limit(thumb, shift);
163 
164                 if (shift)
165                 {
166                     _gx_widget_shift(widget, (GX_VALUE)shift, 0, GX_TRUE);
167                     thumb -> gx_scroll_thumb_start_drag = event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_x;
168                     newevent.gx_event_type = GX_EVENT_HORIZONTAL_SCROLL;
169                     newevent.gx_event_payload.gx_event_intdata[0] = widget -> gx_widget_size.gx_rectangle_left;
170 
171                     _gx_widget_width_get(widget, &widget_width);
172                     newevent.gx_event_payload.gx_event_intdata[1] = (INT)widget_width;
173                     newevent.gx_event_sender = GX_ID_SCROLL_THUMB;
174 
175                     /* send the scroll event to my parent scrollbar */
176                     widget -> gx_widget_parent -> gx_widget_event_process_function(thumb -> gx_widget_parent, &newevent);
177                 }
178             }
179         }
180         break;
181 
182     default:
183 
184         /* Call the widget default processing.  */
185         status =  _gx_widget_event_process(widget, event_ptr);
186     }
187 
188     /* Return completion status.  */
189     return(status);
190 }
191 
192