GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_create.c Lines: 32 32 100.0 %
Date: 2024-12-05 08:52:37 Branches: 8 8 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
/**   Widget Management (Widget)                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_widget.h"
29
#include "gx_utility.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_widget_create                                   PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function creates a widget.                                     */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    widget                                Widget control block          */
49
/*    name                                  Name of widget                */
50
/*    parent                                Parent widget control block   */
51
/*    style                                 Style of widget               */
52
/*    Id                                    Application-defined ID of the */
53
/*                                            the widget                  */
54
/*    size                                  Widget size                   */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    status                                Completion status             */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _gx_system_lock                       Lock access to GUIX           */
63
/*    _gx_widget_link                       Link a widget to parent       */
64
/*    _gx_system_unlock                     Release the protection        */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application Code                                                    */
69
/*    GUIX Internal Code                                                  */
70
/*                                                                        */
71
/*  RELEASE HISTORY                                                       */
72
/*                                                                        */
73
/*    DATE              NAME                      DESCRIPTION             */
74
/*                                                                        */
75
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
76
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
77
/*                                            resulting in version 6.1    */
78
/*                                                                        */
79
/**************************************************************************/
80
156278
UINT  _gx_widget_create(GX_WIDGET *widget, GX_CONST GX_CHAR *name, GX_WIDGET *parent,
81
                        ULONG style, USHORT Id, GX_CONST GX_RECTANGLE *size)
82
{
83
84
    /* lock access to GUIX */
85
156278
    GX_ENTER_CRITICAL
86
87
    /* Setup the widget.  */
88
156278
    widget -> gx_widget_type =                         GX_TYPE_WIDGET;
89
90
156278
    widget -> gx_widget_style =                        style;
91
156278
    widget -> gx_widget_size =                         *size;
92
156278
    widget -> gx_widget_clip  =                        widget -> gx_widget_size;
93
156278
    widget -> gx_widget_event_process_function =       _gx_widget_event_process;
94
156278
    widget -> gx_widget_draw_function =                (VOID (*)(GX_WIDGET *))_gx_widget_draw;
95
156278
    widget -> gx_widget_normal_fill_color =            GX_COLOR_ID_WIDGET_FILL;
96
156278
    widget -> gx_widget_selected_fill_color =          GX_COLOR_ID_SELECTED_FILL;
97
156278
    widget -> gx_widget_disabled_fill_color = GX_COLOR_ID_DISABLED_FILL;
98
156278
    widget -> gx_widget_id =                           Id;
99
100
#if defined(GX_BRUSH_ALPHA_SUPPORT)
101
156278
    widget -> gx_widget_alpha =                        0xff;
102
#endif
103
104
156278
    if (style & GX_STYLE_DYNAMICALLY_ALLOCATED)
105
    {
106
700
        widget -> gx_widget_status = GX_STATUS_DYNAMICALLY_ALLOCATED;
107
    }
108
    else
109
    {
110
155578
        widget -> gx_widget_status = 0;
111
    }
112
113
156278
    if (widget -> gx_widget_style & GX_STYLE_ENABLED)
114
    {
115
110354
        widget -> gx_widget_status |= (GX_STATUS_ACCEPTS_FOCUS | GX_STATUS_SELECTABLE);
116
    }
117
118
156278
    if (style & GX_STYLE_TRANSPARENT)
119
    {
120
81086
        widget -> gx_widget_status |= GX_STATUS_TRANSPARENT;
121
    }
122
123
    /* setup linked list */
124
156278
    widget -> gx_widget_parent = GX_NULL;
125
156278
    widget -> gx_widget_first_child = GX_NULL;
126
156278
    widget -> gx_widget_last_child = GX_NULL;
127
156278
    widget -> gx_widget_next = GX_NULL;
128
156278
    widget -> gx_widget_previous = GX_NULL;
129
156278
    widget -> gx_widget_nav_next = GX_NULL;
130
156278
    widget -> gx_widget_nav_previous = GX_NULL;
131
132
    /* Save the widget name.  */
133
156278
    widget -> gx_widget_name =  name;
134
135
    /* Determine if a parent widget was provided.  */
136
156278
    if (parent)
137
    {
138
1
        _gx_widget_link(parent, widget);
139
    }
140
141
    /* Release the protection.  */
142
156278
    GX_EXIT_CRITICAL
143
144
    /* Return successful status.  */
145
156278
    return(GX_SUCCESS);
146
}
147