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_window.h" 29 #include "gx_widget.h" 30 #include "gx_scrollbar.h" 31 #include "gx_multi_line_text_input.h" 32 #include "gx_multi_line_text_view.h" 33 #include "gx_text_input_cursor.h" 34 35 /**************************************************************************/ 36 /* */ 37 /* FUNCTION RELEASE */ 38 /* */ 39 /* _gx_multi_line_text_input_up_arrow PORTABLE C */ 40 /* 6.1 */ 41 /* AUTHOR */ 42 /* */ 43 /* Kenneth Maxwell, Microsoft Corporation */ 44 /* */ 45 /* DESCRIPTION */ 46 /* */ 47 /* This function move the cursor up by one line. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* text_input Multi line text input */ 52 /* control block */ 53 /* */ 54 /* OUTPUT */ 55 /* */ 56 /* None */ 57 /* */ 58 /* CALLS */ 59 /* */ 60 /* _gx_widget_font_get Retrieve font */ 61 /* _gx_text_input_cursor_dirty_rectangle_get */ 62 /* Get cursor rectangle */ 63 /* _gx_multi_line_text_input_cursor_pos_calculate */ 64 /* Calculate cursor position */ 65 /* according to click index */ 66 /* _gx_system_dirty_partial_add Add one dirty area to */ 67 /* dirty list */ 68 /* _gx_system_dirty_mark Mark widget area dirty */ 69 /* */ 70 /* CALLED BY */ 71 /* */ 72 /* _gx_multi_line_text_input_keydown_process */ 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 /**************************************************************************/ _gx_multi_line_text_input_up_arrow(GX_MULTI_LINE_TEXT_INPUT * text_input)83UINT _gx_multi_line_text_input_up_arrow(GX_MULTI_LINE_TEXT_INPUT *text_input) 84 { 85 GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance; 86 GX_VALUE line_height; 87 GX_POINT cursor_pos; 88 INT shift; 89 GX_RECTANGLE cursor_rect; 90 GX_FONT *font; 91 92 _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_multi_line_text_view_font_id, &font); 93 94 if (!font) 95 { 96 return GX_FAILURE; 97 } 98 99 if (text_input -> gx_multi_line_text_input_start_mark != text_input -> gx_multi_line_text_input_end_mark) 100 { 101 _gx_multi_line_text_input_left_arrow(text_input); 102 } 103 104 /* Record cursor rectangle and scroll shift value before recalculate cursor position. */ 105 _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cursor_rect); 106 shift = text_input -> gx_multi_line_text_view_text_scroll_shift; 107 108 line_height = (GX_VALUE)(font -> gx_font_line_height + 109 text_input -> gx_multi_line_text_view_line_space); 110 111 if (!line_height) 112 { 113 return GX_FAILURE; 114 } 115 116 cursor_pos = cursor_ptr -> gx_text_input_cursor_pos; 117 cursor_pos.gx_point_y = (GX_VALUE)(cursor_pos.gx_point_y - line_height); 118 _gx_multi_line_text_input_cursor_pos_calculate(text_input, cursor_pos); 119 120 121 if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift) 122 { 123 /* Mark old cursor area dirty. */ 124 _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cursor_rect); 125 126 _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cursor_rect); 127 128 /* Mark new cursor area dirty. */ 129 _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cursor_rect); 130 } 131 else 132 { 133 /* Mark widget area dirty. */ 134 _gx_system_dirty_mark((GX_WIDGET *)text_input); 135 } 136 137 return GX_SUCCESS; 138 } 139 140