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 /**   Button Management (Button)                                          */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_widget.h"
29 #include "gx_button.h"
30 #include "gx_system.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_button_deselect                                 PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This service deselects the specified button.                        */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    button                                Pointer to button control     */
50 /*                                            block                       */
51 /*    generate_event                        If GX_TRUE, the button will   */
52 /*                                            generate an event depending */
53 /*                                            on the button style.        */
54 /*                                          If GX_FALSE, the button will  */
55 /*                                            not generate any higher     */
56 /*                                            level event.                */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                                Completion status             */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _gx_system_timer_stop                 Stop an active GUIX timer     */
65 /*    _gx_widget_event_generate             Generate event to notify      */
66 /*                                             parent widget              */
67 /*    _gx_system_dirty_mark                 Sets the dirty flag           */
68 /*                                                                        */
69 /*  CALLED BY                                                             */
70 /*                                                                        */
71 /*    Application Code                                                    */
72 /*                                                                        */
73 /*  RELEASE HISTORY                                                       */
74 /*                                                                        */
75 /*    DATE              NAME                      DESCRIPTION             */
76 /*                                                                        */
77 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
78 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
79 /*                                            resulting in version 6.1    */
80 /*                                                                        */
81 /**************************************************************************/
_gx_button_deselect(GX_BUTTON * button,GX_BOOL generate_event)82 UINT  _gx_button_deselect(GX_BUTTON *button, GX_BOOL generate_event)
83 {
84 GX_WIDGET *widget = (GX_WIDGET *)button;
85 
86     if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
87     {
88         if (button -> gx_widget_style & GX_STYLE_BUTTON_TOGGLE)
89         {
90             if (!(button -> gx_widget_status & GX_STATUS_TOGGLE_UNLOCK))
91             {
92                 return GX_SUCCESS;
93             }
94             button -> gx_widget_status &= ~GX_STATUS_TOGGLE_UNLOCK;
95         }
96 
97         if (button -> gx_widget_style & GX_STYLE_BUTTON_REPEAT)
98         {
99             _gx_system_timer_stop(widget, GX_BUTTON_TIMER);
100         }
101 
102         /* Remove style for pen down.  */
103         button -> gx_widget_style &= ~GX_STYLE_BUTTON_PUSHED;
104 
105         if (generate_event)
106         {
107             if (button -> gx_widget_style & GX_STYLE_BUTTON_RADIO)
108             {
109                 _gx_widget_event_generate(widget, GX_EVENT_RADIO_DESELECT, 0);
110             }
111             else
112             {
113                 if (button -> gx_widget_style & GX_STYLE_BUTTON_TOGGLE)
114                 {
115                     _gx_widget_event_generate(widget, GX_EVENT_TOGGLE_OFF, 0);
116                 }
117                 else
118                 {
119                     if (!(button -> gx_widget_style & GX_STYLE_BUTTON_EVENT_ON_PUSH))
120                     {
121                         _gx_widget_event_generate(widget, GX_EVENT_CLICKED, 0);
122                     }
123                 }
124             }
125         }
126     }
127 
128     if (button -> gx_widget_status & GX_STATUS_VISIBLE)
129     {
130         /* Mark as dirty.  */
131         _gx_system_dirty_mark(widget);
132     }
133 
134     return(GX_SUCCESS);
135 }
136 
137