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 |
|
|
/** Rich Text View Management (Rich Text View) */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
|
21 |
|
|
#define GX_SOURCE_CODE |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#include "gx_api.h" |
27 |
|
|
#include "gx_widget.h" |
28 |
|
|
#include "gx_system.h" |
29 |
|
|
#include "gx_window.h" |
30 |
|
|
#include "gx_rich_text_view.h" |
31 |
|
|
#include "gx_utility.h" |
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _gx_rich_text_view_text_total_height_calculate PORTABLE C */ |
38 |
|
|
/* 6.1 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function calculates rich text view text total height. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* text_view Multi line text view */ |
50 |
|
|
/* control block */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* None */ |
54 |
|
|
/* */ |
55 |
|
|
/* CALLS */ |
56 |
|
|
/* */ |
57 |
|
|
/* _gx_utility_rectangle_resize Resize rectangle */ |
58 |
|
|
/* _gx_widget_string_get_ext Detect and process rich text */ |
59 |
|
|
/* tag */ |
60 |
|
|
/* _gx_widget_font_get Retrieve font by id */ |
61 |
|
|
/* _gx_utility_utf8_string_character_get Retrieve glyph length */ |
62 |
|
|
/* _gx_system_string_width_get Get string width */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLED BY */ |
65 |
|
|
/* */ |
66 |
|
|
/* GUIX Internal Code */ |
67 |
|
|
/* */ |
68 |
|
|
/* RELEASE HISTORY */ |
69 |
|
|
/* */ |
70 |
|
|
/* DATE NAME DESCRIPTION */ |
71 |
|
|
/* */ |
72 |
|
|
/* 09-30-2020 Kenneth Maxwell Initial Version 6.1 */ |
73 |
|
|
/* */ |
74 |
|
|
/**************************************************************************/ |
75 |
|
48 |
UINT _gx_rich_text_view_text_total_height_calculate(GX_RICH_TEXT_VIEW *text_view) |
76 |
|
|
{ |
77 |
|
|
GX_STRING text; |
78 |
|
|
GX_FONT *font; |
79 |
|
|
GX_RICH_TEXT_LINE_INFO line_info; |
80 |
|
|
GX_RICH_TEXT_FORMAT format; |
81 |
|
|
GX_VALUE client_width; |
82 |
|
|
GX_RECTANGLE client; |
83 |
|
48 |
INT total_height = 0; |
84 |
|
|
|
85 |
✓✓ |
48 |
if (!text_view -> gx_multi_line_text_view_text.gx_string_length) |
86 |
|
|
{ |
87 |
|
5 |
text_view -> gx_rich_text_view_text_total_height = 0; |
88 |
|
5 |
text_view -> gx_multi_line_text_view_line_index_old = GX_FALSE; |
89 |
|
5 |
return GX_SUCCESS; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
/* Pick up client retangle. */ |
93 |
|
43 |
client = text_view -> gx_window_client; |
94 |
|
|
|
95 |
|
|
/* Offset client area by the size of whitespace. */ |
96 |
|
43 |
_gx_utility_rectangle_resize(&client, (GX_VALUE)(-text_view -> gx_multi_line_text_view_whitespace)); |
97 |
|
|
|
98 |
|
|
/* Calculate text display width. */ |
99 |
|
43 |
client_width = (GX_VALUE)(client.gx_rectangle_right - client.gx_rectangle_left - 1); |
100 |
|
|
|
101 |
|
|
/* Set default draw style. */ |
102 |
|
43 |
format.gx_rich_text_font_id = text_view -> gx_rich_text_view_fonts.gx_rich_text_fonts_normal_id; |
103 |
|
43 |
format.gx_rich_text_flags = 0; |
104 |
|
|
|
105 |
|
|
/* Pick up text for drawing. */ |
106 |
✓✓ |
43 |
if (text_view -> gx_multi_line_text_view_text_id) |
107 |
|
|
{ |
108 |
|
40 |
_gx_widget_string_get_ext((GX_WIDGET *)text_view, text_view -> gx_multi_line_text_view_text_id, &text); |
109 |
|
|
} |
110 |
|
|
else |
111 |
|
|
{ |
112 |
|
3 |
_gx_system_private_string_get(&text_view -> gx_multi_line_text_view_text, &text, text_view -> gx_widget_style); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
/* Calculate the total rows of text view string. */ |
116 |
✓✓ |
244 |
while (text.gx_string_length > 0) |
117 |
|
|
{ |
118 |
|
|
/* Pickup draw font. */ |
119 |
|
203 |
_gx_widget_font_get((GX_WIDGET *)text_view, format.gx_rich_text_font_id, &font); |
120 |
|
|
|
121 |
✓✓ |
203 |
if (!font) |
122 |
|
|
{ |
123 |
|
2 |
return GX_INVALID_FONT; |
124 |
|
|
} |
125 |
|
|
|
126 |
|
201 |
line_info.gx_rich_text_line_info_text.gx_string_ptr = text.gx_string_ptr; |
127 |
|
201 |
line_info.gx_rich_text_line_info_text.gx_string_length = 0; |
128 |
|
201 |
line_info.gx_rich_text_line_info_start_format = format; |
129 |
|
201 |
line_info.gx_rich_text_line_info_end_format = format; |
130 |
|
201 |
line_info.gx_rich_text_line_info_line_height = font -> gx_font_line_height; |
131 |
|
201 |
line_info.gx_rich_text_line_info_text_width = 0; |
132 |
|
|
|
133 |
|
201 |
_gx_rich_text_view_line_info_get(text_view, text, &line_info, client_width); |
134 |
|
|
|
135 |
|
201 |
total_height += line_info.gx_rich_text_line_info_line_height; |
136 |
|
201 |
total_height += text_view -> gx_multi_line_text_view_line_space; |
137 |
|
|
|
138 |
|
201 |
format = line_info.gx_rich_text_line_info_end_format; |
139 |
|
|
|
140 |
|
|
|
141 |
|
201 |
text.gx_string_ptr += line_info.gx_rich_text_line_info_text.gx_string_length; |
142 |
|
201 |
text.gx_string_length -= line_info.gx_rich_text_line_info_text.gx_string_length; |
143 |
|
|
} |
144 |
|
|
|
145 |
|
41 |
_gx_rich_text_view_context_reset(); |
146 |
|
|
|
147 |
|
41 |
text_view -> gx_rich_text_view_text_total_height = (UINT)total_height; |
148 |
|
41 |
text_view -> gx_multi_line_text_view_line_index_old = GX_FALSE; |
149 |
|
41 |
return GX_SUCCESS; |
150 |
|
|
} |
151 |
|
|
|