1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Tree View Management (Menu)                                         */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_tree_view.h"
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_tree_view_scroll_info_get                       PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function gets the tree view scroll information.                */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    tree                                 Pointer to tree view control   */
47 /*                                           block                        */
48 /*    type                                 GX_SCROLLBAR_HORIZONTAL        */
49 /*                                           or GX_SCROLLBAR_VERTICAL     */
50 /*    info                                 Pointer to destination for     */
51 /*                                           scroll info                  */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    status                               Completion status              */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_tree_view_scroll                 Scroll tree view client area   */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    GUIX Internal Code                                                  */
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 /**************************************************************************/
_gx_tree_view_scroll_info_get(GX_TREE_VIEW * tree,ULONG type,GX_SCROLL_INFO * info)74 UINT _gx_tree_view_scroll_info_get(GX_TREE_VIEW *tree, ULONG type, GX_SCROLL_INFO *info)
75 {
76 GX_RECTANGLE *client;
77 INT           shift;
78 INT           value;
79 
80     client = &tree -> gx_window_client;
81 
82     if (type & GX_SCROLLBAR_VERTICAL)
83     {
84         info -> gx_scroll_minimum = client -> gx_rectangle_top;
85         info -> gx_scroll_maximum = info -> gx_scroll_minimum + tree -> gx_tree_view_tree_height - 1;
86         info -> gx_scroll_visible = (GX_VALUE)(client -> gx_rectangle_bottom - client -> gx_rectangle_top + 1);
87 
88         if (tree -> gx_tree_view_tree_height < info -> gx_scroll_visible)
89         {
90             info -> gx_scroll_maximum = info -> gx_scroll_minimum + info -> gx_scroll_visible - 1;
91         }
92 
93         shift = tree -> gx_tree_view_y_shift;
94         value = client -> gx_rectangle_top - shift;
95 
96         if (value < info -> gx_scroll_minimum)
97         {
98             value = info -> gx_scroll_minimum;
99         }
100         else if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
101         {
102             value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
103         }
104 
105         shift = client -> gx_rectangle_top - value;
106 
107         if (shift != tree -> gx_tree_view_y_shift)
108         {
109             _gx_tree_view_scroll(tree, 0, (GX_VALUE)(shift - tree->gx_tree_view_y_shift));
110         }
111 
112         info -> gx_scroll_value = value;
113     }
114     else
115     {
116         info -> gx_scroll_minimum = client -> gx_rectangle_left;
117         info -> gx_scroll_maximum = info -> gx_scroll_minimum + tree -> gx_tree_view_tree_width - 1;
118         info -> gx_scroll_visible = (GX_VALUE)(client -> gx_rectangle_right - client -> gx_rectangle_left + 1);
119 
120         if (tree -> gx_tree_view_tree_width < info -> gx_scroll_visible)
121         {
122             info -> gx_scroll_maximum = info -> gx_scroll_minimum + info -> gx_scroll_visible - 1;
123         }
124 
125         shift = tree -> gx_tree_view_x_shift;
126         value = client -> gx_rectangle_left - shift;
127 
128         if (value < info -> gx_scroll_minimum)
129         {
130             value = info -> gx_scroll_minimum;
131         }
132         else if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1)
133         {
134             value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1;
135         }
136 
137         shift = client -> gx_rectangle_left - value;
138         if (shift != tree -> gx_tree_view_x_shift)
139         {
140             _gx_tree_view_scroll(tree, (GX_VALUE)(shift - tree->gx_tree_view_x_shift), 0);
141         }
142         info -> gx_scroll_value = value;
143     }
144 
145     info -> gx_scroll_increment = (GX_VALUE)(info -> gx_scroll_maximum - info -> gx_scroll_minimum) / 10;
146 
147     return(GX_SUCCESS);
148 }
149 
150