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_scrollbar.h" |
30 |
|
|
#include "gx_multi_line_text_input.h" |
31 |
|
|
#include "gx_multi_line_text_view.h" |
32 |
|
|
#include "gx_text_input_cursor.h" |
33 |
|
|
#include "gx_utility.h" |
34 |
|
|
#include "gx_widget.h" |
35 |
|
|
|
36 |
|
|
/**************************************************************************/ |
37 |
|
|
/* */ |
38 |
|
|
/* FUNCTION RELEASE */ |
39 |
|
|
/* */ |
40 |
|
|
/* _gx_multi_line_text_input_mark_previous PORTABLE C */ |
41 |
|
|
/* 6.1.7 */ |
42 |
|
|
/* AUTHOR */ |
43 |
|
|
/* */ |
44 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
45 |
|
|
/* */ |
46 |
|
|
/* DESCRIPTION */ |
47 |
|
|
/* */ |
48 |
|
|
/* This function moves highlight text end mark one character left. */ |
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_text_input_cursor_dirty_rectangle_get */ |
62 |
|
|
/* Get cursor rectangle */ |
63 |
|
|
/* _gx_multi_line_text_input_cursor_pos_update */ |
64 |
|
|
/* Calculate cursor position */ |
65 |
|
|
/* according to insert 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 |
|
|
/* _gx_utility_utf8_string_character_get Parses utf8 string to */ |
70 |
|
|
/* multi-byte glyph */ |
71 |
|
|
/* _gx_utility_string_length_check Test string length */ |
72 |
|
|
/* */ |
73 |
|
|
/* CALLED BY */ |
74 |
|
|
/* */ |
75 |
|
|
/* _gx_multi_line_text_input_keydown_process */ |
76 |
|
|
/* */ |
77 |
|
|
/* RELEASE HISTORY */ |
78 |
|
|
/* */ |
79 |
|
|
/* DATE NAME DESCRIPTION */ |
80 |
|
|
/* */ |
81 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
82 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
83 |
|
|
/* resulting in version 6.1 */ |
84 |
|
|
/* 06-02-2021 Kenneth Maxwell Modified comment(s), */ |
85 |
|
|
/* removed unused variable */ |
86 |
|
|
/* assignment, */ |
87 |
|
|
/* resulting in version 6.1.7 */ |
88 |
|
|
/* */ |
89 |
|
|
/**************************************************************************/ |
90 |
|
661 |
UINT _gx_multi_line_text_input_mark_previous(GX_MULTI_LINE_TEXT_INPUT *text_input) |
91 |
|
|
{ |
92 |
|
661 |
GX_TEXT_INPUT_CURSOR *cursor_ptr = &text_input -> gx_multi_line_text_input_cursor_instance; |
93 |
|
|
GX_CONST GX_CHAR *string; |
94 |
|
|
INT old_shift; |
95 |
|
|
GX_RECTANGLE cur_rect; |
96 |
|
661 |
UINT glyph_len = 1; |
97 |
|
|
UINT cursor_line; |
98 |
|
|
GX_POINT start_pos; |
99 |
|
|
GX_POINT end_pos; |
100 |
|
661 |
UINT start_mark = text_input -> gx_multi_line_text_input_start_mark; |
101 |
|
661 |
UINT end_mark = text_input -> gx_multi_line_text_input_end_mark; |
102 |
|
|
|
103 |
✓✓ |
661 |
if (start_mark == end_mark) |
104 |
|
|
{ |
105 |
|
87 |
start_mark = text_input -> gx_multi_line_text_input_text_insert_position; |
106 |
|
87 |
end_mark = text_input -> gx_multi_line_text_input_text_insert_position; |
107 |
|
|
|
108 |
|
87 |
text_input -> gx_multi_line_text_input_start_mark = start_mark; |
109 |
|
87 |
text_input -> gx_multi_line_text_input_end_mark = end_mark; |
110 |
|
|
} |
111 |
|
|
|
112 |
✓✓ |
661 |
if (end_mark > 0) |
113 |
|
|
{ |
114 |
|
660 |
cursor_line = (UINT)(text_input -> gx_multi_line_text_input_text_cursor_line - 1); |
115 |
|
660 |
cursor_line = (UINT)(cursor_line - text_input -> gx_multi_line_text_view_first_cache_line); |
116 |
|
|
|
117 |
|
|
#ifdef GX_UTF8_SUPPORT |
118 |
|
660 |
_gx_utility_utf8_string_backward_character_length_get(&text_input -> gx_multi_line_text_view_text, |
119 |
|
660 |
(INT)(end_mark - 1), &glyph_len); |
120 |
|
|
#endif |
121 |
|
660 |
string = &text_input -> gx_multi_line_text_view_text.gx_string_ptr[end_mark - glyph_len]; |
122 |
|
|
|
123 |
✓✓✓✓
|
660 |
if (string[0] == GX_KEY_CARRIAGE_RETURN || string[0] == GX_KEY_LINE_FEED) |
124 |
|
|
{ |
125 |
|
169 |
glyph_len = text_input -> gx_multi_line_text_input_new_line_character_size; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
660 |
text_input -> gx_multi_line_text_input_end_mark -= glyph_len; |
129 |
|
|
|
130 |
|
|
/* Record scroll shift before recalculate cursor position. */ |
131 |
|
660 |
old_shift = text_input -> gx_multi_line_text_view_text_scroll_shift; |
132 |
|
|
|
133 |
|
660 |
start_pos = cursor_ptr -> gx_text_input_cursor_pos; |
134 |
|
|
|
135 |
|
660 |
text_input -> gx_multi_line_text_input_text_insert_position = text_input -> gx_multi_line_text_input_end_mark; |
136 |
|
|
|
137 |
|
660 |
_gx_multi_line_text_input_cursor_pos_update(text_input, GX_TRUE); |
138 |
|
|
|
139 |
|
|
/* Dirty mark. */ |
140 |
✓✓ |
660 |
if (old_shift == text_input -> gx_multi_line_text_view_text_scroll_shift) |
141 |
|
|
{ |
142 |
|
564 |
end_pos = cursor_ptr -> gx_text_input_cursor_pos; |
143 |
|
|
|
144 |
|
564 |
_gx_multi_line_text_input_text_rectangle_get(text_input, start_pos, end_pos, &cur_rect); |
145 |
|
|
|
146 |
|
|
/* Mark highlight area as dirty. */ |
147 |
|
564 |
_gx_system_dirty_partial_add((GX_WIDGET *)text_input, &cur_rect); |
148 |
|
|
} |
149 |
|
|
else |
150 |
|
|
{ |
151 |
|
96 |
_gx_system_dirty_mark((GX_WIDGET *)text_input); |
152 |
|
|
} |
153 |
|
|
} |
154 |
|
661 |
return GX_SUCCESS; |
155 |
|
|
} |
156 |
|
|
|