1 /* |
|
2 * Copyright (c) 2000 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nw_fbox_formboxutils.h" |
|
20 #include "nwx_defs.h" |
|
21 #include "nwx_string.h" |
|
22 #include "nw_fbox_formbox.h" |
|
23 #include "GDIDevicecontext.h" |
|
24 #include "BrsrStatusCodes.h" |
|
25 |
|
26 |
|
27 /* ------------------------------------------------------------------------- * |
|
28 private data typed |
|
29 * ------------------------------------------------------------------------- */ |
|
30 |
|
31 const NW_Ucs2 EscapeChar = '\\'; |
|
32 const NW_Ucs2 NW_FBox_FormBoxUtils_Truncate[] = {'.','.','.','\0'}; |
|
33 const NW_Ucs2 NW_FBox_FormBoxUtils_TrueStr[] = { 't', 'r', 'u', 'e', '\0' }; |
|
34 const NW_Ucs2 NW_FBox_FormBoxUtils_FalseStr[] = { 'f', 'a', 'l', 's', 'e', '\0' }; |
|
35 |
|
36 /* ------------------------------------------------------------------------- */ |
|
37 TBrowserStatusCode |
|
38 NW_FBox_FormBoxUtils_GetDisplayLength(CGDIDeviceContext* deviceContext, |
|
39 NW_Text_t* text, |
|
40 CGDIFont* font, |
|
41 NW_Text_Length_t totalLength, |
|
42 NW_Uint16 width, |
|
43 NW_Text_Length_t* displayLength, |
|
44 NW_Bool isNumber) |
|
45 { |
|
46 NW_GDI_Dimension2D_t extent; |
|
47 NW_GDI_Dimension2D_t truncate_extent; |
|
48 NW_Text_UCS2_t* truncate_text; |
|
49 TBrowserStatusCode status = KBrsrSuccess; |
|
50 NW_Bool OverFlow = NW_FALSE; |
|
51 NW_Text_Length_t i; |
|
52 NW_Text_Length_t start = 0; |
|
53 truncate_text = NW_Text_UCS2_New ((NW_Ucs2*) NW_FBox_FormBoxUtils_Truncate, |
|
54 NW_FBox_FormBoxUtils_Truncate_len, |
|
55 0); |
|
56 if (truncate_text == NULL) |
|
57 { |
|
58 return KBrsrOutOfMemory; |
|
59 } |
|
60 status = deviceContext->GetTextExtent ( NW_TextOf(truncate_text), |
|
61 font, |
|
62 0, |
|
63 NW_GDI_FlowDirection_LeftRight, |
|
64 &truncate_extent); |
|
65 if (status != KBrsrSuccess) |
|
66 { |
|
67 NW_Object_Delete(truncate_text); |
|
68 return status; |
|
69 } |
|
70 |
|
71 NW_Object_Delete(truncate_text); |
|
72 extent.width = 0; |
|
73 extent.height = 0; |
|
74 for (i=1; i<=totalLength; i++) |
|
75 { |
|
76 if(isNumber) |
|
77 { |
|
78 start = (NW_Text_Length_t) (totalLength - i); |
|
79 } |
|
80 status = deviceContext->GetSubstringExtent( text, |
|
81 font, |
|
82 start, |
|
83 i, |
|
84 0, |
|
85 NW_GDI_FlowDirection_LeftRight, |
|
86 &extent ); |
|
87 if (status != KBrsrSuccess) |
|
88 { |
|
89 return status; |
|
90 } |
|
91 if(!OverFlow) |
|
92 { |
|
93 if(extent.width > width) |
|
94 { |
|
95 if(i > 3) |
|
96 { |
|
97 i = (NW_Text_Length_t) (i - 3); |
|
98 } |
|
99 else |
|
100 { |
|
101 i = 0; |
|
102 } |
|
103 OverFlow = NW_TRUE; |
|
104 } |
|
105 continue; |
|
106 } |
|
107 else if ((extent.width + truncate_extent.width) > width) |
|
108 { |
|
109 break; |
|
110 } |
|
111 } |
|
112 *displayLength = --i; |
|
113 return status; |
|
114 } |
|
115 |
|
116 /* ------------------------------------------------------------------------- */ |
|
117 NW_HED_DocumentRoot_t * |
|
118 NW_FBox_FormBoxUtils_GetDocRoot(NW_LMgr_Box_t* box) |
|
119 { |
|
120 NW_HED_DocumentRoot_t* docRoot = NULL; |
|
121 NW_FBox_FormLiaison_t *fboxFormLiaison = NULL; |
|
122 NW_ASSERT(box != NULL); |
|
123 NW_ASSERT(NW_Object_IsInstanceOf(box, &NW_FBox_FormBox_Class)); |
|
124 fboxFormLiaison = NW_FBox_FormBox_GetFormLiaison (box); |
|
125 (void) NW_FBox_FormLiaison_GetDocRoot(fboxFormLiaison, &docRoot ); |
|
126 return docRoot; |
|
127 } |
|
128 |
|
129 /* ------------------------------------------------------------------------- */ |
|
130 NW_Uint16 |
|
131 NW_FBox_FormBoxUtils_GetNumEscapeChars(const NW_Ucs2* format) |
|
132 { |
|
133 NW_Uint16 numEscapeChars = 0; |
|
134 if((!format) || (!*format)) |
|
135 { |
|
136 return numEscapeChars; |
|
137 } |
|
138 while(*format) |
|
139 { |
|
140 if((*format == EscapeChar) && *(format + 1)) |
|
141 { |
|
142 numEscapeChars++; |
|
143 format++; |
|
144 } |
|
145 format++; |
|
146 } |
|
147 return numEscapeChars; |
|
148 } |
|
149 |
|
150 /* ------------------------------------------------------------------------- */ |
|
151 void |
|
152 NW_FBox_FormBoxUtils_FillEscapeChars(const NW_Ucs2* format, NW_Ucs2 *input, |
|
153 NW_Ucs2 *retValue, NW_Uint16 retValueLen) |
|
154 { |
|
155 if( (!format) || (!*format) || (!input)) |
|
156 { |
|
157 return; |
|
158 } |
|
159 while(*format && retValueLen) |
|
160 { |
|
161 if((*format == EscapeChar) && *(format + 1)) |
|
162 { |
|
163 format++; |
|
164 *retValue = *format; |
|
165 retValue++; |
|
166 } |
|
167 else if (*input) |
|
168 { |
|
169 *retValue = *input; |
|
170 retValue++; |
|
171 input++; |
|
172 } |
|
173 else |
|
174 { |
|
175 break; |
|
176 } |
|
177 format++; |
|
178 retValueLen --; |
|
179 } |
|
180 while(*input && retValueLen) |
|
181 { |
|
182 /*lint --e{794} Conceivable use of null pointer*/ |
|
183 |
|
184 *retValue = *input; |
|
185 retValue++; |
|
186 input++; |
|
187 retValueLen --; |
|
188 } |
|
189 } |
|
190 |
|
191 /* ------------------------------------------------------------------------- */ |
|
192 void |
|
193 NW_FBox_FormBoxUtils_StripEscapeChars(const NW_Ucs2* format, NW_Ucs2 *input, |
|
194 NW_Ucs2 *retValue, NW_Uint16 retValueLen) |
|
195 { |
|
196 if( (!format) || (!*format) || (!input)) |
|
197 { |
|
198 return; |
|
199 } |
|
200 while(*format && *input && retValueLen) |
|
201 { |
|
202 if((*format == EscapeChar) && *(format + 1)) |
|
203 { |
|
204 format += 2; |
|
205 } |
|
206 else |
|
207 { |
|
208 *retValue = *input; |
|
209 retValue++; |
|
210 format++; |
|
211 retValueLen --; |
|
212 } |
|
213 input++; |
|
214 } |
|
215 while(*input && retValueLen) |
|
216 { |
|
217 *retValue = *input; |
|
218 retValue++; |
|
219 input++; |
|
220 retValueLen --; |
|
221 } |
|
222 } |
|