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 /**   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_widget.h"
30 #include "gx_multi_line_text_input.h"
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_multi_line_text_input_text_rectangle_get        PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function retrieves the bounding box of specified text.         */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    input                                 Multi-line text input widget  */
49 /*                                            control block               */
50 /*    start_index                           The start index of the        */
51 /*                                            specified text              */
52 /*    end_index                             The end index of the          */
53 /*                                            specified text              */
54 /*    rect                                  Retrieved bounding rectangle  */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    None                                                                */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _gx_system_dirty_mark                Mark widget as drity           */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
69 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_gx_multi_line_text_input_text_rectangle_get(GX_MULTI_LINE_TEXT_INPUT * input,GX_POINT start_cursor_pos,GX_POINT end_cursor_pos,GX_RECTANGLE * rect)73 UINT _gx_multi_line_text_input_text_rectangle_get(GX_MULTI_LINE_TEXT_INPUT *input, GX_POINT start_cursor_pos, GX_POINT end_cursor_pos, GX_RECTANGLE *rect)
74 {
75 GX_FONT *font;
76 GX_VALUE border_width;
77 GX_VALUE half_line_height;
78 GX_VALUE cursor_width;
79 
80 
81     /* Pick up font. */
82     _gx_widget_font_get((GX_WIDGET *)input, input -> gx_multi_line_text_view_font_id, &font);
83 
84     if (!font)
85     {
86         return GX_FAILURE;
87     }
88 
89     /* Pickup widget border width. */
90     _gx_widget_border_width_get((GX_WIDGET *)input, &border_width);
91 
92     /* Get client rectangle. */
93     _gx_widget_client_get((GX_WIDGET *)input, border_width, rect);
94 
95     half_line_height = (GX_VALUE)(font -> gx_font_line_height + input -> gx_multi_line_text_view_line_space);
96     half_line_height = (GX_VALUE)(half_line_height >> 1);
97 
98     if (start_cursor_pos.gx_point_y == end_cursor_pos.gx_point_y)
99     {
100         if (start_cursor_pos.gx_point_x > end_cursor_pos.gx_point_x)
101         {
102             GX_SWAP_VALS(start_cursor_pos.gx_point_x, end_cursor_pos.gx_point_x);
103         }
104 
105         cursor_width = input -> gx_multi_line_text_input_cursor_instance.gx_text_input_cursor_width;
106         rect -> gx_rectangle_top = (GX_VALUE)(start_cursor_pos.gx_point_y - half_line_height);
107         rect -> gx_rectangle_bottom = (GX_VALUE)(start_cursor_pos.gx_point_y + half_line_height);
108         rect -> gx_rectangle_left = (GX_VALUE)(start_cursor_pos.gx_point_x - (cursor_width >> 1));
109         rect -> gx_rectangle_right = (GX_VALUE)(end_cursor_pos.gx_point_x + ((cursor_width + 1) >> 1) - 1);
110     }
111     else
112     {
113         if (start_cursor_pos.gx_point_y > end_cursor_pos.gx_point_y)
114         {
115             GX_SWAP_VALS(start_cursor_pos.gx_point_y, end_cursor_pos.gx_point_y);
116         }
117         rect -> gx_rectangle_top = (GX_VALUE)(start_cursor_pos.gx_point_y - half_line_height);
118         rect -> gx_rectangle_bottom = (GX_VALUE)(end_cursor_pos.gx_point_y + half_line_height);
119     }
120 
121     return GX_SUCCESS;
122 }
123 
124