GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_button_select.c Lines: 20 20 100.0 %
Date: 2024-12-05 08:52:37 Branches: 16 16 100.0 %

Line Branch Exec Source
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
/**   Button Management (Button)                                          */
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_button.h"
29
#include "gx_system.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_button_select                                   PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function selects one button, invalidating and eventing as      */
45
/*    necessary.                                                          */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    button                                Button control block          */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    status                                Completion status             */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    _gx_widget_front_move                 Move widget to the front      */
58
/*    _gx_button_siblings_deselect          Deselect all the siblings     */
59
/*    _gx_widget_event_generate             Generate events for widget    */
60
/*    _gx_system_timer_start                Allocate a free timer and     */
61
/*                                          activates it                  */
62
/*    _gx_system_dirty_mark                 Mark the widget dirty         */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Application Code                                                    */
67
/*                                                                        */
68
/*  RELEASE HISTORY                                                       */
69
/*                                                                        */
70
/*    DATE              NAME                      DESCRIPTION             */
71
/*                                                                        */
72
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
73
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
74
/*                                            resulting in version 6.1    */
75
/*                                                                        */
76
/**************************************************************************/
77
332
UINT  _gx_button_select(GX_BUTTON *button)
78
{
79
332
GX_WIDGET *widget = (GX_WIDGET *)button;
80
81
332
    if (button -> gx_widget_style & GX_STYLE_ENABLED)
82
    {
83
331
        if (!(button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED))
84
        {
85
            /* Set style for pen down.  */
86
291
            button -> gx_widget_style |= GX_STYLE_BUTTON_PUSHED;
87
88
291
            if (widget -> gx_widget_status & GX_STATUS_ACCEPTS_FOCUS)
89
            {
90
256
                _gx_widget_front_move(widget, NULL);
91
            }
92
93
291
            if (button -> gx_widget_style & GX_STYLE_BUTTON_RADIO)
94
            {
95
72
                _gx_button_siblings_deselect(button);
96
72
                _gx_widget_event_generate(widget, GX_EVENT_RADIO_SELECT, 0);
97
            }
98
291
            if (button -> gx_widget_style & GX_STYLE_BUTTON_EVENT_ON_PUSH)
99
            {
100
2
                _gx_widget_event_generate(widget, GX_EVENT_CLICKED, 0);
101
            }
102
            else
103
            {
104
289
                if (button -> gx_widget_style & GX_STYLE_BUTTON_TOGGLE)
105
                {
106
2
                    _gx_widget_event_generate(widget, GX_EVENT_TOGGLE_ON, 0);
107
                }
108
            }
109
110
291
            if (button -> gx_widget_style & GX_STYLE_BUTTON_REPEAT)
111
            {
112
22
                _gx_system_timer_start(widget, GX_BUTTON_TIMER, GX_REPEAT_BUTTON_INITIAL_TICS, GX_REPEAT_BUTTON_REPEAT_TICS);
113
            }
114
115
            /* Mark as dirty.  */
116
291
            _gx_system_dirty_mark(widget);
117
        }
118
        else
119
        {
120
40
            if (button -> gx_widget_style & GX_STYLE_BUTTON_TOGGLE)
121
            {
122
2
                button -> gx_widget_status |= GX_STATUS_TOGGLE_UNLOCK;
123
            }
124
        }
125
    }
126
332
        return(GX_SUCCESS);
127
128
}
129