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 (Single 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_single_line_text_input.h" |
30 |
|
|
|
31 |
|
|
/**************************************************************************/ |
32 |
|
|
/* */ |
33 |
|
|
/* FUNCTION RELEASE */ |
34 |
|
|
/* */ |
35 |
|
|
/* _gx_single_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 from the current cursor */ |
44 |
|
|
/* position to the specified offset position. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* text_input Single-line text input widget */ |
49 |
|
|
/* control block */ |
50 |
|
|
/* offset_index Index offset to the current */ |
51 |
|
|
/* cursor position */ |
52 |
|
|
/* rect Retrieved bounding rectangle */ |
53 |
|
|
/* */ |
54 |
|
|
/* OUTPUT */ |
55 |
|
|
/* */ |
56 |
|
|
/* Completion status */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* _gx_system_dirty_mark Mark widget as drity */ |
61 |
|
|
/* */ |
62 |
|
|
/* RELEASE HISTORY */ |
63 |
|
|
/* */ |
64 |
|
|
/* DATE NAME DESCRIPTION */ |
65 |
|
|
/* */ |
66 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
67 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
68 |
|
|
/* resulting in version 6.1 */ |
69 |
|
|
/* */ |
70 |
|
|
/**************************************************************************/ |
71 |
|
533 |
UINT _gx_single_line_text_input_text_rectangle_get(GX_SINGLE_LINE_TEXT_INPUT *input, INT offset_index, GX_RECTANGLE *rect) |
72 |
|
|
{ |
73 |
|
533 |
GX_TEXT_INPUT_CURSOR *cursor = &input -> gx_single_line_text_input_cursor_instance; |
74 |
|
|
GX_FONT *font; |
75 |
|
|
GX_VALUE text_width; |
76 |
|
|
GX_VALUE border_width; |
77 |
|
|
INT start_index; |
78 |
|
|
INT end_index; |
79 |
|
|
GX_STRING string; |
80 |
|
|
|
81 |
✓✓ |
533 |
if (offset_index == 0) |
82 |
|
|
{ |
83 |
|
95 |
return GX_FAILURE; |
84 |
|
|
} |
85 |
|
|
|
86 |
✓✓ |
438 |
if (offset_index > 0) |
87 |
|
|
{ |
88 |
|
213 |
start_index = (INT)input -> gx_single_line_text_input_insert_pos; |
89 |
|
213 |
end_index = start_index + offset_index; |
90 |
|
|
} |
91 |
|
|
else |
92 |
|
|
{ |
93 |
|
225 |
start_index = (INT)input -> gx_single_line_text_input_insert_pos + (INT)offset_index; |
94 |
|
225 |
end_index = (INT)(input -> gx_single_line_text_input_insert_pos); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
/* Pick up font. */ |
98 |
|
438 |
_gx_widget_font_get((GX_WIDGET *)input, input -> gx_prompt_font_id, &font); |
99 |
|
|
|
100 |
|
|
/* Get the width of specified text. */ |
101 |
|
438 |
string.gx_string_ptr = input -> gx_single_line_text_input_buffer + start_index; |
102 |
|
438 |
string.gx_string_length = (UINT)(end_index - start_index); |
103 |
|
438 |
_gx_system_string_width_get_ext(font, &string, &text_width); |
104 |
|
|
|
105 |
|
|
/* Pickup widget border width. */ |
106 |
|
438 |
_gx_widget_border_width_get((GX_WIDGET *)input, &border_width); |
107 |
|
|
|
108 |
|
|
/* Get client rectangle. */ |
109 |
|
438 |
_gx_widget_client_get((GX_WIDGET *)input, border_width, rect); |
110 |
|
|
|
111 |
✓✓ |
438 |
if (offset_index > 0) |
112 |
|
|
{ |
113 |
|
213 |
rect -> gx_rectangle_left = cursor -> gx_text_input_cursor_pos.gx_point_x; |
114 |
|
213 |
rect -> gx_rectangle_right = (GX_VALUE)(rect -> gx_rectangle_left + text_width - 1); |
115 |
|
|
} |
116 |
|
|
else |
117 |
|
|
{ |
118 |
|
225 |
rect -> gx_rectangle_right = (GX_VALUE)(cursor -> gx_text_input_cursor_pos.gx_point_x - 1); |
119 |
|
225 |
rect -> gx_rectangle_left = (GX_VALUE)(rect -> gx_rectangle_right - text_width); |
120 |
|
|
} |
121 |
|
|
|
122 |
|
438 |
return GX_SUCCESS; |
123 |
|
|
} |
124 |
|
|
|