GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_horizontal_list_page_index_set.c Lines: 13 13 100.0 %
Date: 2024-12-05 08:52:37 Branches: 9 10 90.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
/**   Horizontal List (List)                                              */
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_window.h"
29
#include "gx_system.h"
30
#include "gx_scrollbar.h"
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_horizontal_list_page_index_set                  PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This service sets the index of first list item                      */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    horizontal_list                       Horizontal list widget        */
49
/*                                            control block               */
50
/*    list_entry                            Pointer to new list entry     */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    status                                Completion status             */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_widget_event_generate             Creates a new GX_EVENT        */
59
/*    _gx_system_dirty_mark                 Mark the widget dirty         */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    _gx_horizontal_list_event_process                                   */
64
/*                                                                        */
65
/*  RELEASE HISTORY                                                       */
66
/*                                                                        */
67
/*    DATE              NAME                      DESCRIPTION             */
68
/*                                                                        */
69
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
70
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
71
/*                                            resulting in version 6.1    */
72
/*                                                                        */
73
/**************************************************************************/
74
102
UINT _gx_horizontal_list_page_index_set(GX_HORIZONTAL_LIST *list, INT index)
75
{
76
GX_WIDGET    *child;
77
GX_SCROLLBAR *pScroll;
78
INT           scroll_value;
79
80
102
    if ((list -> gx_horizontal_list_total_columns > 0) &&
81

91
        ((index <= list -> gx_horizontal_list_total_columns - list -> gx_horizontal_list_visible_columns) || (list -> gx_widget_style & GX_STYLE_WRAP)))
82
    {
83
78
        child = _gx_widget_first_client_child_get((GX_WIDGET *)list);
84
85
78
        if (child)
86
        {
87
            /* Calculate scroll value. */
88
78
            scroll_value = child -> gx_widget_size.gx_rectangle_left;
89
78
            scroll_value += (index - list -> gx_horizontal_list_top_index) * list -> gx_horizontal_list_child_width;
90
78
            scroll_value = list -> gx_window_client.gx_rectangle_left - scroll_value;
91
92
            /* Scroll to make index as the first visible entry. */
93
78
            _gx_horizontal_list_scroll(list, scroll_value);
94
95
78
            _gx_window_scrollbar_find((GX_WINDOW *)list, GX_TYPE_HORIZONTAL_SCROLL, &pScroll);
96
97
78
            if (pScroll)
98
            {
99
33
                _gx_scrollbar_reset(pScroll, GX_NULL);
100
            }
101
        }
102
    }
103
104
102
    return GX_SUCCESS;
105
}
106