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 moves highlight text end mark one line up.            */
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_mark_up(GX_MULTI_LINE_TEXT_INPUT * text_input)83 UINT _gx_multi_line_text_input_mark_up(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_VALUE              half_line_height;
88 GX_POINT              cursor_pos;
89 INT                   shift;
90 GX_RECTANGLE          cursor_rect;
91 GX_FONT              *font;
92 UINT                  start_mark = text_input -> gx_multi_line_text_input_start_mark;
93 UINT                  end_mark = text_input -> gx_multi_line_text_input_end_mark;
94 GX_VALUE              width;
95 
96     if (start_mark == end_mark)
97     {
98         start_mark = text_input -> gx_multi_line_text_input_text_insert_position;
99         end_mark = text_input -> gx_multi_line_text_input_text_insert_position;
100 
101         text_input -> gx_multi_line_text_input_start_mark = start_mark;
102         text_input -> gx_multi_line_text_input_end_mark = end_mark;
103     }
104 
105     shift = text_input -> gx_multi_line_text_view_text_scroll_shift;
106 
107     _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_multi_line_text_view_font_id, &font);
108 
109     if (!font)
110     {
111         return GX_FAILURE;
112     }
113 
114     line_height = (GX_VALUE)(font -> gx_font_line_height + text_input -> gx_multi_line_text_view_line_space);
115 
116     if (!line_height)
117     {
118         return GX_FAILURE;
119     }
120 
121     cursor_pos = cursor_ptr -> gx_text_input_cursor_pos;
122     cursor_pos.gx_point_y = (GX_VALUE)(cursor_pos.gx_point_y - line_height);
123     _gx_multi_line_text_input_cursor_pos_calculate(text_input, cursor_pos);
124     text_input -> gx_multi_line_text_input_end_mark = text_input -> gx_multi_line_text_input_text_insert_position;
125 
126     if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift)
127     {
128         _gx_widget_border_width_get((GX_WIDGET *)text_input, &width);
129         _gx_widget_client_get((GX_WIDGET *)text_input, width, &cursor_rect);
130 
131         half_line_height = (GX_VALUE)((line_height + 1) >> 1);
132         cursor_rect.gx_rectangle_top = (GX_VALUE)(cursor_pos.gx_point_y - half_line_height);
133         cursor_rect.gx_rectangle_bottom = (GX_VALUE)(cursor_pos.gx_point_y + line_height + half_line_height);
134 
135         /* Mark highlight area as dirty. */
136         _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cursor_rect);
137     }
138     else
139     {
140         /* Mark widget area dirty. */
141         _gx_system_dirty_mark((GX_WIDGET *)text_input);
142     }
143 
144     return GX_SUCCESS;
145 }
146 
147