GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_slider_create.c Lines: 23 23 100.0 %
Date: 2024-12-05 08:52:37 Branches: 10 10 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
/**   Slider Management (Slider)                                          */
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_slider.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_slider_create                                   PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This service creates a slider.                                      */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    slider                                Slider control block          */
48
/*    name                                  Name of prompt                */
49
/*    parent                                Parent widget control block   */
50
/*    tick_count                            Number of slider ticks        */
51
/*    slider_info                           Pointer to slider info        */
52
/*    style                                 Style of slider               */
53
/*    slider_id                             Application-defined ID of     */
54
/*                                            slider                      */
55
/*    size                                  Dimensions of slider          */
56
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    status                                Completion status             */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*                                                                        */
63
/*    memset                                Set control block to zero     */
64
/*    _gx_widget_create                     Create the underlying widget  */
65
/*    _gx_widget_width_get                  Retrieve the width of the     */
66
/*                                            widget                      */
67
/*    _gx_widget_height_get                 Retrieve the height of the    */
68
/*                                            widget                      */
69
/*    _gx_widget_link                       Link the widget to its parent */
70
/*                                                                        */
71
/*  CALLED BY                                                             */
72
/*                                                                        */
73
/*    Application 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
/**************************************************************************/
84
3696
UINT  _gx_slider_create(GX_SLIDER *slider, GX_CONST GX_CHAR *name,
85
                        GX_WIDGET *parent, INT tick_count,
86
                        GX_SLIDER_INFO *slider_info, ULONG style,
87
                        USHORT slider_id, GX_CONST GX_RECTANGLE *size)
88
{
89
90
    /* Call the widget create function.  */
91
3696
    _gx_widget_create((GX_WIDGET *)slider, name, GX_NULL, style, slider_id, size);
92
93
    /* Populate the rest of slider control block - overriding as necessary.  */
94
3696
    slider -> gx_widget_type = GX_TYPE_SLIDER;
95
96
3696
    slider -> gx_slider_info = *slider_info;
97
3696
    if (slider -> gx_slider_info.gx_slider_info_needle_width <= 0)
98
    {
99
8
        if (style & GX_STYLE_SLIDER_VERTICAL)
100
        {
101
1
            _gx_widget_width_get((GX_WIDGET *)slider, &slider -> gx_slider_info.gx_slider_info_needle_width);
102
1
            slider -> gx_slider_info.gx_slider_info_needle_width /= 2;
103
        }
104
        else
105
        {
106
7
            slider -> gx_slider_info.gx_slider_info_needle_width =  GX_SLIDER_NEEDLE_WIDTH;
107
        }
108
    }
109
3696
    if (slider -> gx_slider_info.gx_slider_info_needle_height <= 0)
110
    {
111
2
        if (style & GX_STYLE_SLIDER_VERTICAL)
112
        {
113
1
            slider -> gx_slider_info.gx_slider_info_needle_height =  GX_SLIDER_NEEDLE_WIDTH;
114
        }
115
        else
116
        {
117
1
            _gx_widget_height_get((GX_WIDGET *)slider, &slider -> gx_slider_info.gx_slider_info_needle_height);
118
1
            slider -> gx_slider_info.gx_slider_info_needle_height /= 2;
119
        }
120
    }
121
3696
    slider -> gx_widget_normal_fill_color =      GX_COLOR_ID_BUTTON_UPPER;
122
3696
    slider -> gx_widget_selected_fill_color =    GX_COLOR_ID_BUTTON_UPPER;
123
3696
    slider -> gx_slider_tick_color =             GX_COLOR_ID_SLIDER_TICK;
124
3696
    slider -> gx_slider_tick_count =             tick_count;
125
3696
    slider -> gx_widget_draw_function = (VOID (*)(GX_WIDGET *))_gx_slider_draw;
126
3696
    slider -> gx_widget_event_process_function = (UINT (*)(GX_WIDGET *, GX_EVENT *))_gx_slider_event_process;
127
128
    /* Determine if a parent widget was provided.  */
129
3696
    if (parent)
130
    {
131
3694
        _gx_widget_link(parent, (GX_WIDGET *)slider);
132
    }
133
134
    /* Return the status from widget create.  */
135
3696
    return(GX_SUCCESS);
136
}
137