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 */ 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_multi_line_text_view.h" 30 #include "gx_text_input_cursor.h" 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _gx_multi_line_text_input_mark_home PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Kenneth Maxwell, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function moves the end mark of highligh text to the start */ 45 /* of the line. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* text_input Multi line text input */ 50 /* control block */ 51 /* */ 52 /* OUTPUT */ 53 /* */ 54 /* None */ 55 /* */ 56 /* CALLS */ 57 /* */ 58 /* _gx_text_input_cursor_dirty_rectangle_get */ 59 /* Retrieve cursor rectangle */ 60 /* _gx_multi_line_text_input_cursor_pos_calculate */ 61 /* Calculate cursor position */ 62 /* according to click point */ 63 /* _gx_multi_line_text_input_text_rectangle_get */ 64 /* Retrieve text rectangle */ 65 /* between specified positions */ 66 /* _gx_system_dirty_partial_add Mark specified area dirty */ 67 /* _gx_system_dirty_mark Mark specified widget dirty */ 68 /* */ 69 /* CALLED BY */ 70 /* */ 71 /* _gx_multi_line_text_input_keydown_process */ 72 /* */ 73 /* RELEASE HISTORY */ 74 /* */ 75 /* DATE NAME DESCRIPTION */ 76 /* */ 77 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ 78 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ 79 /* resulting in version 6.1 */ 80 /* */ 81 /**************************************************************************/ _gx_multi_line_text_input_mark_home(GX_MULTI_LINE_TEXT_INPUT * text_input)82UINT _gx_multi_line_text_input_mark_home(GX_MULTI_LINE_TEXT_INPUT *text_input) 83 { 84 GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance; 85 GX_POINT old_cursor_pos; 86 GX_POINT cursor_pos; 87 GX_RECTANGLE cursor_rect; 88 INT shift; 89 UINT start_mark = text_input -> gx_multi_line_text_input_start_mark; 90 UINT end_mark = text_input -> gx_multi_line_text_input_end_mark; 91 92 old_cursor_pos = cursor_ptr -> gx_text_input_cursor_pos; 93 if (start_mark == end_mark) 94 { 95 start_mark = text_input -> gx_multi_line_text_input_text_insert_position; 96 end_mark = text_input -> gx_multi_line_text_input_text_insert_position; 97 98 text_input -> gx_multi_line_text_input_start_mark = start_mark; 99 text_input -> gx_multi_line_text_input_end_mark = end_mark; 100 } 101 102 cursor_pos = old_cursor_pos; 103 cursor_pos.gx_point_x = (GX_VALUE)(text_input -> gx_window_client.gx_rectangle_left + 104 text_input -> gx_multi_line_text_view_whitespace); 105 106 shift = text_input -> gx_multi_line_text_view_text_scroll_shift; 107 108 /* Calculate new cursor position. */ 109 _gx_multi_line_text_input_cursor_pos_calculate(text_input, cursor_pos); 110 111 text_input -> gx_multi_line_text_input_end_mark = text_input -> gx_multi_line_text_input_text_insert_position; 112 113 if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift) 114 { 115 _gx_multi_line_text_input_text_rectangle_get(text_input, old_cursor_pos, cursor_ptr -> gx_text_input_cursor_pos, &cursor_rect); 116 117 /* Mark highlight area as dirty. */ 118 _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cursor_rect); 119 } 120 else 121 { 122 _gx_system_dirty_mark((GX_WIDGET *)text_input); 123 } 124 125 return GX_SUCCESS; 126 } 127 128