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_down_arrow                PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function move the cursor to down by one line.                  */
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_down_arrow(GX_MULTI_LINE_TEXT_INPUT * text_input)80 UINT _gx_multi_line_text_input_down_arrow(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_POINT              cursor_pos;
85 INT                   shift;
86 GX_RECTANGLE          cursor_rect;
87 GX_FONT              *font;
88 
89     _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_multi_line_text_view_font_id, &font);
90 
91     if (!font)
92     {
93         return GX_FAILURE;
94     }
95 
96     if (text_input -> gx_multi_line_text_input_start_mark != text_input -> gx_multi_line_text_input_end_mark)
97     {
98         _gx_multi_line_text_input_right_arrow(text_input);
99     }
100 
101     /* Record cursor rectangle and scroll shift value before recalculate cursor position. */
102     _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cursor_rect);
103 
104     shift = text_input -> gx_multi_line_text_view_text_scroll_shift;
105 
106     line_height = (GX_VALUE)(font -> gx_font_line_height +
107                              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     if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift)
119     {
120         /* Mark old cursor area dirty. */
121         _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cursor_rect);
122 
123         /* Mark new cursor area dirty. */
124         _gx_text_input_cursor_dirty_rectangle_get(&text_input -> gx_multi_line_text_input_cursor_instance, &cursor_rect);
125         _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cursor_rect);
126     }
127     else
128     {
129         /* Mark widget area dirty. */
130         _gx_system_dirty_mark((GX_WIDGET *)text_input);
131     }
132 
133     return GX_SUCCESS;
134 }
135 
136