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