1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Multi Line Text Input Management (Multi Line Text Input)            */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_system.h"
29 #include "gx_window.h"
30 #include "gx_widget.h"
31 #include "gx_scrollbar.h"
32 #include "gx_multi_line_text_input.h"
33 #include "gx_multi_line_text_view.h"
34 #include "gx_text_input_cursor.h"
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _gx_multi_line_text_input_up_arrow                  PORTABLE C      */
41 /*                                                           6.1          */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Kenneth Maxwell, Microsoft Corporation                              */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This function moves highlight text end mark one line up.            */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    text_input                            Multi line text input         */
53 /*                                            control block               */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _gx_widget_font_get                   Retrieve font                 */
62 /*    _gx_text_input_cursor_dirty_rectangle_get                           */
63 /*                                          Get cursor rectangle          */
64 /*    _gx_multi_line_text_input_cursor_pos_calculate                      */
65 /*                                          Calculate cursor position     */
66 /*                                            according to click index    */
67 /*    _gx_system_dirty_partial_add          Add one dirty area to         */
68 /*                                            dirty list                  */
69 /*    _gx_system_dirty_mark                 Mark widget area dirty        */
70 /*                                                                        */
71 /*  CALLED BY                                                             */
72 /*                                                                        */
73 /*    _gx_multi_line_text_input_keydown_process                           */
74 /*                                                                        */
75 /*  RELEASE HISTORY                                                       */
76 /*                                                                        */
77 /*    DATE              NAME                      DESCRIPTION             */
78 /*                                                                        */
79 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
80 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
81 /*                                            resulting in version 6.1    */
82 /*                                                                        */
83 /**************************************************************************/
_gx_multi_line_text_input_mark_up(GX_MULTI_LINE_TEXT_INPUT * text_input)84 UINT _gx_multi_line_text_input_mark_up(GX_MULTI_LINE_TEXT_INPUT *text_input)
85 {
86 GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance;
87 GX_VALUE              line_height;
88 GX_VALUE              half_line_height;
89 GX_POINT              cursor_pos;
90 INT                   shift;
91 GX_RECTANGLE          cursor_rect;
92 GX_FONT              *font;
93 UINT                  start_mark = text_input -> gx_multi_line_text_input_start_mark;
94 UINT                  end_mark = text_input -> gx_multi_line_text_input_end_mark;
95 GX_VALUE              width;
96 
97     if (start_mark == end_mark)
98     {
99         start_mark = text_input -> gx_multi_line_text_input_text_insert_position;
100         end_mark = text_input -> gx_multi_line_text_input_text_insert_position;
101 
102         text_input -> gx_multi_line_text_input_start_mark = start_mark;
103         text_input -> gx_multi_line_text_input_end_mark = end_mark;
104     }
105 
106     shift = text_input -> gx_multi_line_text_view_text_scroll_shift;
107 
108     _gx_widget_font_get((GX_WIDGET *)text_input, text_input -> gx_multi_line_text_view_font_id, &font);
109 
110     if (!font)
111     {
112         return GX_FAILURE;
113     }
114 
115     line_height = (GX_VALUE)(font -> gx_font_line_height + text_input -> gx_multi_line_text_view_line_space);
116 
117     if (!line_height)
118     {
119         return GX_FAILURE;
120     }
121 
122     cursor_pos = cursor_ptr -> gx_text_input_cursor_pos;
123     cursor_pos.gx_point_y = (GX_VALUE)(cursor_pos.gx_point_y - line_height);
124     _gx_multi_line_text_input_cursor_pos_calculate(text_input, cursor_pos);
125     text_input -> gx_multi_line_text_input_end_mark = text_input -> gx_multi_line_text_input_text_insert_position;
126 
127     if (shift == text_input -> gx_multi_line_text_view_text_scroll_shift)
128     {
129         _gx_widget_border_width_get((GX_WIDGET *)text_input, &width);
130         _gx_widget_client_get((GX_WIDGET *)text_input, width, &cursor_rect);
131 
132         half_line_height = (GX_VALUE)((line_height + 1) >> 1);
133         cursor_rect.gx_rectangle_top = (GX_VALUE)(cursor_pos.gx_point_y - half_line_height);
134         cursor_rect.gx_rectangle_bottom = (GX_VALUE)(cursor_pos.gx_point_y + line_height + half_line_height);
135 
136         /* Mark highlight area as dirty. */
137         _gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cursor_rect);
138     }
139     else
140     {
141         /* Mark widget area dirty. */
142         _gx_system_dirty_mark((GX_WIDGET *)text_input);
143     }
144 
145     return GX_SUCCESS;
146 }
147 
148