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_home                      PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function move the cursor to the position                       */
45 /*    before the first character.                                         */
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_multi_line_text_input_cursor_pos_calculate                      */
59 /*                                          Calculate cursor position     */
60 /*                                            according to click point    */
61 /*    _gx_multi_line_text_input_cursor_rectangle_define                   */
62 /*                                          Define a rectangle for the    */
63 /*                                            cursor                      */
64 /*    _gx_system_dirty_partial_add          Add one dirty area to         */
65 /*                                            dirty list                  */
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_home(GX_MULTI_LINE_TEXT_INPUT * text_input)80 UINT _gx_multi_line_text_input_home(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_POINT              cur_pos;
84 GX_RECTANGLE          cur_rect;
85 
86     if (text_input -> gx_multi_line_text_input_start_mark != text_input -> gx_multi_line_text_input_end_mark)
87     {
88         _gx_multi_line_text_input_left_arrow(text_input);
89     }
90 
91     cur_pos = cursor_ptr -> gx_text_input_cursor_pos;
92 
93     _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cur_rect);
94 
95     cur_pos.gx_point_x = (GX_VALUE)(text_input -> gx_window_client.gx_rectangle_left +
96                                     text_input -> gx_multi_line_text_view_whitespace);
97 
98     /* Calculate new cursor position. */
99     _gx_multi_line_text_input_cursor_pos_calculate(text_input, cur_pos);
100 
101     if (cur_rect.gx_rectangle_left != cursor_ptr -> gx_text_input_cursor_pos.gx_point_x)
102     {
103         /* Mark old cursor rectangle dirty. */
104         _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
105 
106         /* Mark new cursor rectangle dirty. */
107         _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cur_rect);
108         _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect);
109     }
110 
111     return GX_SUCCESS;
112 }
113 
114