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 /** Multi Line Text Input Management (Multi Line Text Input) */ 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_multi_line_text_input.h" 29 #include "gx_text_input_cursor.h" 30 #include "gx_widget.h" 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _gx_multi_line_text_input_mark_down PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Kenneth Maxwell, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function moves highlight text end mark one line down. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* text_input Multi line text input */ 49 /* control block */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* None */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _gx_widget_font_get Retrieve font */ 58 /* _gx_text_input_cursor_dirty_rectangle_get */ 59 /* Get cursor rectangle */ 60 /* _gx_multi_line_text_input_cursor_pos_calculate */ 61 /* Update cursor position */ 62 /* according to click position */ 63 /* _gx_system_dirty_partial_add Add one dirty area to */ 64 /* dirty list */ 65 /* _gx_system_dirty_mark Mark widget area dirty */ 66 /* */ 67 /* CALLED BY */ 68 /* */ 69 /* _gx_multi_line_text_input_keydown_process */ 70 /* */ 71 /* RELEASE HISTORY */ 72 /* */ 73 /* DATE NAME DESCRIPTION */ 74 /* */ 75 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ 76 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ 77 /* resulting in version 6.1 */ 78 /* */ 79 /**************************************************************************/ _gx_multi_line_text_input_mark_down(GX_MULTI_LINE_TEXT_INPUT * text_input)80UINT _gx_multi_line_text_input_mark_down(GX_MULTI_LINE_TEXT_INPUT *text_input) 81 { 82 GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance; 83 GX_VALUE line_height; 84 GX_VALUE half_line_height; 85 GX_POINT cursor_pos; 86 INT shift; 87 GX_RECTANGLE dirty; 88 GX_FONT *font; 89 GX_VALUE width; 90 91 _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_multi_line_text_view_font_id, &font); 92 93 if (!font) 94 { 95 return GX_FAILURE; 96 } 97 98 if (text_input -> gx_multi_line_text_input_start_mark == text_input -> gx_multi_line_text_input_end_mark) 99 { 100 text_input -> gx_multi_line_text_input_start_mark = text_input -> gx_multi_line_text_input_text_insert_position; 101 text_input -> gx_multi_line_text_input_end_mark = text_input -> gx_multi_line_text_input_text_insert_position; 102 103 } 104 105 shift = text_input -> gx_multi_line_text_view_text_scroll_shift; 106 107 line_height = (GX_VALUE)(font -> gx_font_line_height + text_input -> gx_multi_line_text_view_line_space); 108 109 if (!line_height) 110 { 111 return GX_FAILURE; 112 } 113 114 cursor_pos = cursor_ptr -> gx_text_input_cursor_pos; 115 cursor_pos.gx_point_y = (GX_VALUE)(cursor_pos.gx_point_y + line_height); 116 _gx_multi_line_text_input_cursor_pos_calculate(text_input, cursor_pos); 117 118 text_input -> gx_multi_line_text_input_end_mark = text_input -> gx_multi_line_text_input_text_insert_position; 119 120 if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift) 121 { 122 _gx_widget_border_width_get((GX_WIDGET *)text_input, &width); 123 _gx_widget_client_get((GX_WIDGET *)text_input, width, &dirty); 124 125 half_line_height = (GX_VALUE)((line_height + 1) >> 1); 126 dirty.gx_rectangle_top = (GX_VALUE)(cursor_pos.gx_point_y - line_height - half_line_height); 127 dirty.gx_rectangle_bottom = (GX_VALUE)(cursor_pos.gx_point_y + half_line_height); 128 129 /* Mark highlight area as dirty. */ 130 _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &dirty); 131 } 132 else 133 { 134 /* Mark all widget as dirty. */ 135 _gx_system_dirty_mark((GX_WIDGET *)text_input); 136 } 137 138 return GX_SUCCESS; 139 } 140 141