GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_tree_view_position.c Lines: 51 51 100.0 %
Date: 2024-12-05 08:52:37 Branches: 28 28 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
/**   Tree View Management (View)                                         */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_menu.h"
28
#include "gx_widget.h"
29
#include "gx_system.h"
30
#include "gx_tree_view.h"
31
#include "gx_window.h"
32
#include "gx_scrollbar.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_tree_view_position                              PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function positions a tree menu.                                */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    tree                                  Tree view control block       */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    status                                Completion status             */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_widget_first_client_child_get     Get the first client child    */
59
/*    _gx_widget_next_client_child_get      Get the next client child     */
60
/*    _gx_widget_height_get                 Get widget height             */
61
/*    _gx_widget_width_get                  Get widget width              */
62
/*    _gx_widget_resize                     Resize a widget               */
63
/*    _gx_menu_position                     Position a menu widget        */
64
/*    _gx_window_scrollbar_find             Find scrollbar for a window   */
65
/*    _gx_scrollbar_reset                   Reset scrollbar information   */
66
/*    _gx_widget_hide                       Hide a widget                 */
67
/*    _gx_widget_show                       Show a widget                 */
68
/*                                                                        */
69
/*  CALLED BY                                                             */
70
/*                                                                        */
71
/*    Application Code                                                    */
72
/*    GUIX Internal Code                                                  */
73
/*                                                                        */
74
/*  RELEASE HISTORY                                                       */
75
/*                                                                        */
76
/*    DATE              NAME                      DESCRIPTION             */
77
/*                                                                        */
78
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
79
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
80
/*                                            resulting in version 6.1    */
81
/*                                                                        */
82
/**************************************************************************/
83
68
UINT  _gx_tree_view_position(GX_TREE_VIEW *tree)
84
{
85
GX_WIDGET    *child;
86
GX_RECTANGLE  size;
87
GX_RECTANGLE *client;
88
GX_VALUE      height;
89
GX_VALUE      width;
90
GX_VALUE      bottom;
91
68
GX_VALUE      max_right = 0;
92
GX_MENU_LIST *list;
93
GX_SCROLLBAR *scroll;
94
95
68
    client = &tree -> gx_window_client;
96
97
68
    size.gx_rectangle_left = (GX_VALUE)(client -> gx_rectangle_left + tree -> gx_tree_view_indentation + tree -> gx_tree_view_x_shift);
98
68
    bottom = (GX_VALUE)(client -> gx_rectangle_top - 1 + tree -> gx_tree_view_y_shift);
99
100
68
    child = _gx_widget_first_client_child_get((GX_WIDGET *)tree);
101
102
    /* Reposition tree view items. */
103
447
    while (child)
104
    {
105
379
        if (child -> gx_widget_type == GX_TYPE_MENU_LIST)
106
        {
107
35
            child = _gx_widget_next_client_child_get(child);
108
35
            continue;
109
        }
110
111
344
        _gx_widget_height_get(child, &height);
112
344
        _gx_widget_width_get(child, &width);
113
344
        size.gx_rectangle_top = (GX_VALUE)(bottom + 1);
114
344
        size.gx_rectangle_bottom = (GX_VALUE)(size.gx_rectangle_top + height - 1);
115
344
        size.gx_rectangle_right = (GX_VALUE)(size.gx_rectangle_left + width - 1);
116
117
344
        _gx_widget_resize((GX_WIDGET *)child, &size);
118
119
344
        if (child -> gx_widget_type == GX_TYPE_MENU)
120
        {
121
271
            _gx_menu_position((GX_MENU *)child, tree -> gx_tree_view_indentation);
122
123
271
            list = &((GX_MENU *)child) -> gx_menu_list;
124
125

271
            if (list -> gx_widget_parent && list -> gx_widget_first_child)
126
            {
127
28
                bottom = list -> gx_widget_size.gx_rectangle_bottom;
128
129
28
                if (list -> gx_widget_size.gx_rectangle_right > max_right)
130
                {
131
27
                    max_right = list -> gx_widget_size.gx_rectangle_right;
132
                }
133
            }
134
            else
135
            {
136
243
                if (list -> gx_widget_parent)
137
                {
138
1
                    _gx_widget_detach((GX_WIDGET *)list);
139
                }
140
141
243
                bottom = size.gx_rectangle_bottom;
142
143
243
                if (size.gx_rectangle_right > max_right)
144
                {
145
57
                    max_right = size.gx_rectangle_right;
146
                }
147
            }
148
        }
149
        else
150
        {
151
73
            bottom = size.gx_rectangle_bottom;
152
        }
153
154
344
        child -> gx_widget_status &= (ULONG)(~GX_STATUS_ACCEPTS_FOCUS);
155
344
        child = _gx_widget_next_client_child_get(child);
156
    }
157
158
68
    tree -> gx_tree_view_tree_width = (GX_VALUE)(max_right - (client -> gx_rectangle_left + tree -> gx_tree_view_x_shift) + 1);
159
68
    tree -> gx_tree_view_tree_height = (GX_VALUE)(bottom - (client -> gx_rectangle_top + tree -> gx_tree_view_y_shift) + 1);
160
161
68
    _gx_window_scrollbar_find((GX_WINDOW *)tree, (USHORT)GX_TYPE_HORIZONTAL_SCROLL, &scroll);
162
163
68
    width = (GX_VALUE)(client -> gx_rectangle_right - client -> gx_rectangle_left + 1);
164
68
    height = (GX_VALUE)(client -> gx_rectangle_bottom - client -> gx_rectangle_top + 1);
165
166
68
    if (scroll)
167
    {
168
66
        _gx_scrollbar_reset(scroll, GX_NULL);
169
170
66
        if (tree -> gx_tree_view_tree_width <= width)
171
        {
172
56
            _gx_widget_hide((GX_WIDGET *)scroll);
173
        }
174
        else
175
        {
176
10
            _gx_widget_show((GX_WIDGET *)scroll);
177
        }
178
    }
179
180
68
    _gx_window_scrollbar_find((GX_WINDOW *)tree, GX_TYPE_VERTICAL_SCROLL, &scroll);
181
182
68
    if (scroll)
183
    {
184
66
        _gx_scrollbar_reset(scroll, GX_NULL);
185
186
66
        if (tree -> gx_tree_view_tree_height <= height)
187
        {
188
59
            _gx_widget_hide((GX_WIDGET *)scroll);
189
        }
190
        else
191
        {
192
7
            _gx_widget_show((GX_WIDGET *)scroll);
193
        }
194
    }
195
196
68
    if ((tree -> gx_widget_style & GX_STYLE_TREE_VIEW_SHOW_ROOT_LINES) &&
197
63
        (tree -> gx_widget_status & GX_STATUS_VISIBLE))
198
    {
199
62
        _gx_system_dirty_mark((GX_WIDGET *)tree);
200
    }
201
202
    /* Return completion status code. */
203
68
    return(GX_SUCCESS);
204
}
205