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 /** Multi Line Text View Management (Multi Line 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_multi_line_text_view.h" 33 34 /**************************************************************************/ 35 /* */ 36 /* FUNCTION RELEASE */ 37 /* */ 38 /* _gx_multi_line_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 multi-line text view scroll information. */ 47 /* */ 48 /* INPUT */ 49 /* */ 50 /* text_view Multi line text view widget */ 51 /* control block */ 52 /* style Style */ 53 /* info Pointer to destination for */ 54 /* scroll info */ 55 /* */ 56 /* OUTPUT */ 57 /* */ 58 /* status Completion status */ 59 /* */ 60 /* CALLS */ 61 /* */ 62 /* _gx_widget_font_get Obtain the font */ 63 /* _gx_multi_line_text_view_string_total_rows_computer */ 64 /* Compute the number of rows */ 65 /* for the text view text */ 66 /* _gx_utility_rectangle_resize Offset rectangle */ 67 /* */ 68 /* CALLED BY */ 69 /* */ 70 /* GUIX Internal Code */ 71 /* */ 72 /* RELEASE HISTORY */ 73 /* */ 74 /* DATE NAME DESCRIPTION */ 75 /* */ 76 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ 77 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ 78 /* resulting in version 6.1 */ 79 /* */ 80 /**************************************************************************/ _gx_multi_line_text_view_scroll_info_get(GX_MULTI_LINE_TEXT_VIEW * text_view,ULONG style,GX_SCROLL_INFO * info)81UINT _gx_multi_line_text_view_scroll_info_get(GX_MULTI_LINE_TEXT_VIEW *text_view, ULONG style, GX_SCROLL_INFO *info) 82 { 83 GX_RECTANGLE client; 84 GX_VALUE line_height; 85 INT text_height; 86 INT value; 87 INT shift; 88 GX_FONT *font; 89 90 GX_PARAMETER_NOT_USED(style); 91 92 /* Get font. */ 93 _gx_widget_font_get((GX_WIDGET *)text_view, text_view -> gx_multi_line_text_view_font_id, &font); 94 95 if (!font) 96 { 97 return GX_FAILURE; 98 } 99 100 if (text_view -> gx_multi_line_text_view_line_index_old) 101 { 102 /* Calculate text total rows. */ 103 _gx_multi_line_text_view_string_total_rows_compute(text_view); 104 } 105 106 /* Pickup text height. */ 107 line_height = (GX_VALUE)(font -> gx_font_line_height + text_view -> gx_multi_line_text_view_line_space); 108 text_height = (INT)(line_height * (INT)text_view -> gx_multi_line_text_view_text_total_rows); 109 110 client = text_view -> gx_window_client; 111 112 if (text_view -> gx_multi_line_text_view_whitespace) 113 { 114 /* Offset client bounding box. */ 115 _gx_utility_rectangle_resize(&client, (GX_VALUE)(-text_view -> gx_multi_line_text_view_whitespace)); 116 } 117 118 info -> gx_scroll_minimum = client.gx_rectangle_top; 119 info -> gx_scroll_maximum = info -> gx_scroll_minimum + text_height - 1; 120 info -> gx_scroll_visible = (GX_VALUE)(client.gx_rectangle_bottom - client.gx_rectangle_top + 1); 121 122 if (text_height < info -> gx_scroll_visible) 123 { 124 info -> gx_scroll_maximum = info -> gx_scroll_minimum + info -> gx_scroll_visible - 1; 125 } 126 127 shift = text_view -> gx_multi_line_text_view_text_scroll_shift; 128 value = client.gx_rectangle_top - shift; 129 130 if (value < info -> gx_scroll_minimum) 131 { 132 value = info -> gx_scroll_minimum; 133 } 134 else if (value > info -> gx_scroll_maximum - info -> gx_scroll_visible + 1) 135 { 136 value = info -> gx_scroll_maximum - info -> gx_scroll_visible + 1; 137 } 138 139 shift = client.gx_rectangle_top - value; 140 141 if (shift != text_view -> gx_multi_line_text_view_text_scroll_shift) 142 { 143 /* Update shift value. */ 144 text_view -> gx_multi_line_text_view_text_scroll_shift = shift; 145 } 146 147 info -> gx_scroll_value = value; 148 info -> gx_scroll_increment = line_height; 149 150 if (text_view -> gx_multi_line_text_view_text_total_rows > 151 text_view -> gx_multi_line_text_view_cache_size) 152 { 153 _gx_multi_line_text_view_line_cache_update((GX_MULTI_LINE_TEXT_VIEW *)text_view); 154 } 155 156 return GX_SUCCESS; 157 } 158 159