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 /**   Slider Management (Slider)                                          */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 /* Include necessary system files.  */
24 
25 #include "gx_api.h"
26 #include "gx_system.h"
27 #include "gx_display.h"
28 #include "gx_context.h"
29 #include "gx_widget.h"
30 #include "gx_utility.h"
31 #include "gx_slider.h"
32 
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _gx_slider_value_set                                PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Kenneth Maxwell, Microsoft Corporation                              */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This service sets the slider value.                                 */
48 /*                                                                        */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    slider                                Slider widget control block   */
53 /*    info                                  Pointer to slider info        */
54 /*    new_value                             New slider value              */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    status                                Completion status             */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _gx_slider_needle_position_get        Get the slider needle         */
63 /*                                            position                    */
64 /*    _gx_utility_rectangle_combine         Combine the first and second  */
65 /*                                            rectangle into the first    */
66 /*                                            rectangle                   */
67 /*    _gx_system_dirty_partial_add          Mark the partial area of this */
68 /*                                            widget as dirty             */
69 /*    _gx_widget_event_generate             Generate an event and send it */
70 /*                                            to the parent widget        */
71 /*                                                                        */
72 /*  CALLED BY                                                             */
73 /*                                                                        */
74 /*    Application Code                                                    */
75 /*    GUIX Internal Code                                                  */
76 /*                                                                        */
77 /*  RELEASE HISTORY                                                       */
78 /*                                                                        */
79 /*    DATE              NAME                      DESCRIPTION             */
80 /*                                                                        */
81 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
82 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
83 /*                                            resulting in version 6.1    */
84 /*                                                                        */
85 /**************************************************************************/
_gx_slider_value_set(GX_SLIDER * slider,GX_SLIDER_INFO * info,INT new_value)86 UINT _gx_slider_value_set(GX_SLIDER *slider, GX_SLIDER_INFO *info, INT new_value)
87 {
88 GX_RECTANGLE oldpos;
89 GX_RECTANGLE newpos;
90 
91     if (new_value != info -> gx_slider_info_current_val)
92     {
93         /* get the old need position */
94         _gx_slider_needle_position_get(slider, info, &oldpos);
95 
96         /* assign slider value */
97         info -> gx_slider_info_current_val = new_value;
98 
99         /* get the new needle position */
100 
101         _gx_slider_needle_position_get(slider, info, &newpos);
102 
103         /* combine old and new needle positions */
104         _gx_utility_rectangle_combine(&newpos, &oldpos);
105 
106         if (slider -> gx_widget_type == GX_TYPE_PIXELMAP_SLIDER)
107         {
108             newpos.gx_rectangle_left = slider -> gx_widget_size.gx_rectangle_left;
109             newpos.gx_rectangle_right = slider -> gx_widget_size.gx_rectangle_right;
110         }
111 
112         /* mark as dirty so that I get redrawn */
113         _gx_system_dirty_partial_add((GX_WIDGET *)slider, &newpos);
114 
115         /* notify my parent of my new value */
116         _gx_widget_event_generate((GX_WIDGET *)slider, GX_EVENT_SLIDER_VALUE, new_value);
117     }
118     return(GX_SUCCESS);
119 }
120 
121