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