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 (Menu)                                         */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_tree_view.h"
28 
29 /**************************************************************************/
30 /*                                                                        */
31 /*  FUNCTION                                               RELEASE        */
32 /*                                                                        */
33 /*    _gx_tree_view_scroll_info_get                       PORTABLE C      */
34 /*                                                           6.1          */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    Kenneth Maxwell, Microsoft Corporation                              */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    This function gets the tree view scroll information.                */
42 /*                                                                        */
43 /*  INPUT                                                                 */
44 /*                                                                        */
45 /*    tree                                 Pointer to tree view control   */
46 /*                                           block                        */
47 /*    type                                 GX_SCROLLBAR_HORIZONTAL        */
48 /*                                           or GX_SCROLLBAR_VERTICAL     */
49 /*    info                                 Pointer to destination for     */
50 /*                                           scroll info                  */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    status                               Completion status              */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _gx_tree_view_scroll                 Scroll tree view client area   */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    GUIX Internal Code                                                  */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
69 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_gx_tree_view_scroll_info_get(GX_TREE_VIEW * tree,ULONG type,GX_SCROLL_INFO * info)73 UINT _gx_tree_view_scroll_info_get(GX_TREE_VIEW *tree, ULONG type, GX_SCROLL_INFO *info)
74 {
75 GX_RECTANGLE *client;
76 INT           shift;
77 INT           value;
78 
79     client = &tree -> gx_window_client;
80 
81     if (type & GX_SCROLLBAR_VERTICAL)
82     {
83         info -> gx_scroll_minimum = client -> gx_rectangle_top;
84         info -> gx_scroll_maximum = info -> gx_scroll_minimum + tree -> gx_tree_view_tree_height - 1;
85         info -> gx_scroll_visible = (GX_VALUE)(client -> gx_rectangle_bottom - client -> gx_rectangle_top + 1);
86 
87         if (tree -> gx_tree_view_tree_height < info -> gx_scroll_visible)
88         {
89             info -> gx_scroll_maximum = info -> gx_scroll_minimum + info -> gx_scroll_visible - 1;
90         }
91 
92         shift = tree -> gx_tree_view_y_shift;
93         value = client -> gx_rectangle_top - shift;
94 
95         if (value < info -> gx_scroll_minimum)
96         {
97             value = info -> gx_scroll_minimum;
98         }
99         else if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
100         {
101             value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
102         }
103 
104         shift = client -> gx_rectangle_top - value;
105 
106         if (shift != tree -> gx_tree_view_y_shift)
107         {
108             _gx_tree_view_scroll(tree, 0, (GX_VALUE)(shift - tree->gx_tree_view_y_shift));
109         }
110 
111         info -> gx_scroll_value = value;
112     }
113     else
114     {
115         info -> gx_scroll_minimum = client -> gx_rectangle_left;
116         info -> gx_scroll_maximum = info -> gx_scroll_minimum + tree -> gx_tree_view_tree_width - 1;
117         info -> gx_scroll_visible = (GX_VALUE)(client -> gx_rectangle_right - client -> gx_rectangle_left + 1);
118 
119         if (tree -> gx_tree_view_tree_width < info -> gx_scroll_visible)
120         {
121             info -> gx_scroll_maximum = info -> gx_scroll_minimum + info -> gx_scroll_visible - 1;
122         }
123 
124         shift = tree -> gx_tree_view_x_shift;
125         value = client -> gx_rectangle_left - shift;
126 
127         if (value < info -> gx_scroll_minimum)
128         {
129             value = info -> gx_scroll_minimum;
130         }
131         else if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
132         {
133             value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
134         }
135 
136         shift = client -> gx_rectangle_left - value;
137         if (shift != tree -> gx_tree_view_x_shift)
138         {
139             _gx_tree_view_scroll(tree, (GX_VALUE)(shift - tree->gx_tree_view_x_shift), 0);
140         }
141         info -> gx_scroll_value = value;
142     }
143 
144     info -> gx_scroll_increment = (GX_VALUE)(info -> gx_scroll_maximum - info -> gx_scroll_minimum) / 10;
145 
146     return(GX_SUCCESS);
147 }
148 
149