GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_block_move.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
/**   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_canvas.h"
30
#include "gx_utility.h"
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_widget_block_move                               PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This service move a rectangular block of pixels.                    */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    widget                                Pointer to widget             */
49
/*    block                                 Rectangle to move             */
50
/*    x_shift                               Number of pixels to shift on  */
51
/*                                            the x-axis                  */
52
/*    y_shift                               Number of pixels to shift on  */
53
/*                                            the y-axis                  */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    status                                Completion status             */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _gx_system_dirty_partial_add          Add area to the dirty list    */
62
/*    _gx_widget_canvas_get                 Find canvas associated with   */
63
/*                                            the specified widget        */
64
/*    _gx_canvas_drawing_initiate           Start canvas draw             */
65
/*    _gx_canvas_block_move                 Canvas-level block move call  */
66
/*    _gx_canvas_drawing_complete           Finish canvas draw            */
67
/*                                                                        */
68
/*  CALLED BY                                                             */
69
/*                                                                        */
70
/*    Application Code                                                    */
71
/*    GUIX Internal 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
/**************************************************************************/
82
3813
UINT _gx_widget_block_move(GX_WIDGET *widget, GX_RECTANGLE *block, INT x_shift, INT y_shift)
83
{
84
GX_CANVAS   *canvas;
85
UINT         status;
86
GX_RECTANGLE dirty;
87
GX_VALUE     width;
88
GX_VALUE     height;
89
90
3813
    if (widget -> gx_widget_status & GX_STATUS_TRANSPARENT)
91
    {
92
        /* cannot do block move if transparent widget */
93
323
        _gx_system_dirty_partial_add(widget, block);
94
323
        return GX_SUCCESS;
95
    }
96
97
3490
    _gx_widget_canvas_get(widget, &canvas);
98
99
3490
    if (!canvas)
100
    {
101
1
        return GX_INVALID_CANVAS;
102
    }
103
104
3489
    GX_ENTER_CRITICAL
105
106
3489
    _gx_widget_width_get(widget, &width);
107
3489
    _gx_widget_height_get(widget, &height);
108
109

3489
    if ((GX_ABS(x_shift) >= width) || (GX_ABS(y_shift) >= height))
110
    {
111
        /* Shift is too large, just invalidate the widget. */
112
752
        _gx_system_dirty_partial_add(widget, block);
113
    }
114
    else
115
    {
116
2737
        _gx_canvas_drawing_initiate(canvas, widget, block);
117
2737
        status = _gx_canvas_block_move(block, (GX_VALUE)x_shift, (GX_VALUE)y_shift, &dirty);
118
119
2737
        if (status == GX_SUCCESS)
120
        {
121
            /* re-draw the portion that could not be moved */
122
2669
            _gx_canvas_drawing_initiate(canvas, widget, &dirty);
123
2669
            widget->gx_widget_draw_function(widget);
124
2669
            _gx_canvas_drawing_complete(canvas, GX_FALSE);
125
2669
            _gx_canvas_drawing_complete(canvas, GX_TRUE);
126
        }
127
        else
128
        {
129
            /* block move was not successful, just invalidate the widget client */
130
68
            _gx_system_dirty_partial_add(widget, block);
131
68
            _gx_canvas_drawing_complete(canvas, GX_FALSE);
132
        }
133
    }
134
135
3489
    GX_EXIT_CRITICAL
136
3489
    return(GX_SUCCESS);
137
}
138