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 /**   Rich Text View Management (Rich Text View)                          */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_system.h"
29 #include "gx_window.h"
30 #include "gx_widget.h"
31 #include "gx_utility.h"
32 #include "gx_rich_text_view.h"
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _gx_rich_text_view_scroll_info_get                  PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Kenneth Maxwell, Microsoft Corporation                              */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function gets the rich text view scroll information.           */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    text_view                            Rich text view control block   */
51 /*    style                                Reserved                       */
52 /*    info                                 Pointer to destination for     */
53 /*                                           scroll info                  */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _gx_widget_font_get                   Obtain the font               */
62 /*    _gx_multi_line_text_view_string_total_rows_computer                 */
63 /*                                          Compute the number of rows    */
64 /*                                            for the text view text      */
65 /*    _gx_utility_rectangle_resize          Offset rectangle              */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    GUIX Internal Code                                                  */
70 /*                                                                        */
71 /*  RELEASE HISTORY                                                       */
72 /*                                                                        */
73 /*    DATE              NAME                      DESCRIPTION             */
74 /*                                                                        */
75 /*  09-30-2020     Kenneth Maxwell          Initial Version 6.1           */
76 /*                                                                        */
77 /**************************************************************************/
_gx_rich_text_view_scroll_info_get(GX_RICH_TEXT_VIEW * text_view,ULONG style,GX_SCROLL_INFO * info)78 UINT _gx_rich_text_view_scroll_info_get(GX_RICH_TEXT_VIEW *text_view, ULONG style, GX_SCROLL_INFO *info)
79 {
80 GX_RECTANGLE client;
81 GX_VALUE     line_height;
82 INT          text_height;
83 INT          value;
84 INT          shift;
85 GX_FONT     *font;
86 
87     GX_PARAMETER_NOT_USED(style);
88 
89     /* Get font. */
90     _gx_widget_font_get((GX_WIDGET *)text_view, text_view -> gx_rich_text_view_fonts.gx_rich_text_fonts_normal_id, &font);
91 
92     if (!font)
93     {
94         return GX_FAILURE;
95     }
96 
97     if (text_view -> gx_multi_line_text_view_line_index_old)
98     {
99         /* Calculate text total height. */
100         _gx_rich_text_view_text_total_height_calculate(text_view);
101     }
102 
103     /* Pickup text height. */
104     line_height = (GX_VALUE)(font -> gx_font_line_height + text_view -> gx_multi_line_text_view_line_space);
105     text_height = (INT)text_view -> gx_rich_text_view_text_total_height;
106 
107     client = text_view -> gx_window_client;
108 
109     if (text_view -> gx_multi_line_text_view_whitespace)
110     {
111         /* Offset client bounding box.  */
112         _gx_utility_rectangle_resize(&client, (GX_VALUE)(-text_view -> gx_multi_line_text_view_whitespace));
113     }
114 
115     info -> gx_scroll_minimum = client.gx_rectangle_top;
116     info -> gx_scroll_maximum = info -> gx_scroll_minimum + text_height - 1;
117     info -> gx_scroll_visible = (GX_VALUE)(client.gx_rectangle_bottom - client.gx_rectangle_top + 1);
118 
119     if (text_height < info -> gx_scroll_visible)
120     {
121         info -> gx_scroll_maximum = info -> gx_scroll_minimum + info -> gx_scroll_visible - 1;
122     }
123 
124     shift = text_view -> gx_multi_line_text_view_text_scroll_shift;
125     value = client.gx_rectangle_top - 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_top - value;
137 
138     if (shift != text_view -> gx_multi_line_text_view_text_scroll_shift)
139     {
140         /* Update shift value.  */
141         text_view -> gx_multi_line_text_view_text_scroll_shift = shift;
142     }
143 
144     info -> gx_scroll_value = value;
145     info -> gx_scroll_increment = line_height;
146 
147     return GX_SUCCESS;
148 }
149 
150