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 Input Management (Multi Line Text Input) */ 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_scrollbar.h" 32 #include "gx_multi_line_text_view.h" 33 #include "gx_multi_line_text_input.h" 34 #include "gx_utility.h" 35 36 /**************************************************************************/ 37 /* */ 38 /* FUNCTION RELEASE */ 39 /* */ 40 /* _gx_multi_line_text_input_cursor_visible PORTABLE C */ 41 /* 6.1 */ 42 /* AUTHOR */ 43 /* */ 44 /* Kenneth Maxwell, Microsoft Corporation */ 45 /* */ 46 /* DESCRIPTION */ 47 /* */ 48 /* This function scrolls multi line text input text to make the cursor */ 49 /* visible. */ 50 /* */ 51 /* INPUT */ 52 /* */ 53 /* text_input Multi line text input */ 54 /* control block */ 55 /* */ 56 /* OUTPUT */ 57 /* */ 58 /* None */ 59 /* */ 60 /* CALLS */ 61 /* */ 62 /* _gx_window_scrollbar_find Find scrollbar for a window */ 63 /* _gx_scrollbar_reset Reset scrollbar information */ 64 /* _gx_multi_line_text_view_line_cache_update */ 65 /* Update line index cache */ 66 /* _gx_system_dirty_mark Mark widget as dirty */ 67 /* _gx_utility_rectangle_resize Increase the size of rectangle*/ 68 /* as specified */ 69 /* */ 70 /* CALLED BY */ 71 /* */ 72 /* GUIX Intercal Code */ 73 /* */ 74 /* RELEASE HISTORY */ 75 /* */ 76 /* DATE NAME DESCRIPTION */ 77 /* */ 78 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ 79 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ 80 /* resulting in version 6.1 */ 81 /* */ 82 /**************************************************************************/ 83 _gx_multi_line_text_input_cursor_visible(GX_MULTI_LINE_TEXT_INPUT * text_input)84UINT _gx_multi_line_text_input_cursor_visible(GX_MULTI_LINE_TEXT_INPUT *text_input) 85 { 86 GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance; 87 GX_RECTANGLE client; 88 INT shift; 89 GX_SCROLLBAR *scroll; 90 GX_FONT *font; 91 GX_VALUE line_height; 92 GX_VALUE ypos; 93 94 _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_multi_line_text_view_font_id, &font); 95 96 if (!font) 97 { 98 return GX_FAILURE; 99 } 100 101 client = text_input -> gx_window_client; 102 103 if (text_input -> gx_multi_line_text_view_whitespace) 104 { 105 /* Offset client bounding box. */ 106 _gx_utility_rectangle_resize(&client, (GX_VALUE)(-text_input -> gx_multi_line_text_view_whitespace)); 107 } 108 109 line_height = (GX_VALUE)(font -> gx_font_line_height + text_input -> gx_multi_line_text_view_line_space); 110 111 ypos = (GX_VALUE)(cursor_ptr -> gx_text_input_cursor_pos.gx_point_y - (line_height >> 1)); 112 113 if (ypos < client.gx_rectangle_top) 114 { 115 shift = client.gx_rectangle_top - ypos; 116 } 117 else if (ypos + line_height - 1 > client.gx_rectangle_bottom) 118 { 119 shift = client.gx_rectangle_bottom - (ypos + line_height - 1); 120 } 121 else 122 { 123 shift = 0; 124 } 125 126 if (shift) 127 { 128 text_input -> gx_multi_line_text_view_text_scroll_shift += shift; 129 cursor_ptr -> gx_text_input_cursor_pos.gx_point_y = (GX_VALUE)(cursor_ptr -> gx_text_input_cursor_pos.gx_point_y + shift); 130 131 _gx_window_scrollbar_find((GX_WINDOW *)text_input, GX_TYPE_VERTICAL_SCROLL, &scroll); 132 if (scroll) 133 { 134 /* Reset scrollbar. */ 135 _gx_scrollbar_reset(scroll, GX_NULL); 136 } 137 else 138 { 139 140 if (text_input -> gx_multi_line_text_view_text_total_rows > 141 text_input -> gx_multi_line_text_view_cache_size) 142 { 143 _gx_multi_line_text_view_line_cache_update((GX_MULTI_LINE_TEXT_VIEW *)text_input); 144 } 145 } 146 147 _gx_system_dirty_mark((GX_WIDGET *)text_input); 148 } 149 150 return GX_SUCCESS; 151 } 152 153