Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * USER text functions |
| 3 | * |
| 4 | * Copyright 1993, 1994 Alexandre Julliard |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 5 | * Copyright 2002 Bill Medland |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 6 | * |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 7 | * Contains |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 8 | * 1. DrawText functions |
| 9 | * 2. GrayString functions |
| 10 | * 3. TabbedText functions |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 11 | * |
| 12 | * This library is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU Lesser General Public |
| 14 | * License as published by the Free Software Foundation; either |
| 15 | * version 2.1 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This library is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * Lesser General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 25 | */ |
| 26 | |
Alexandre Julliard | 5769d1d | 2002-04-26 19:05:15 +0000 | [diff] [blame] | 27 | #include "config.h" |
| 28 | #include "wine/port.h" |
| 29 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 30 | #include <stdarg.h> |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 31 | #include <stdlib.h> |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 32 | #include <string.h> |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 33 | #include <assert.h> |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 34 | |
| 35 | #include "windef.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 36 | #include "winbase.h" |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 37 | #include "wingdi.h" |
| 38 | #include "wine/winuser16.h" |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 39 | #include "wine/unicode.h" |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 40 | #include "winerror.h" |
| 41 | #include "winnls.h" |
Alexandre Julliard | f56c6fb | 2004-09-01 18:26:40 +0000 | [diff] [blame] | 42 | #include "controls.h" |
Alexandre Julliard | eea4153 | 2005-04-13 16:13:45 +0000 | [diff] [blame] | 43 | #include "user_private.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 44 | #include "wine/debug.h" |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 45 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 46 | WINE_DEFAULT_DEBUG_CHANNEL(text); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 47 | |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 48 | /********************************************************************* |
| 49 | * |
| 50 | * DrawText functions |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 51 | * |
| 52 | * Design issues |
| 53 | * How many buffers to use |
| 54 | * While processing in DrawText there are potentially three different forms |
| 55 | * of the text that need to be held. How are they best held? |
| 56 | * 1. The original text is needed, of course, to see what to display. |
| 57 | * 2. The text that will be returned to the user if the DT_MODIFYSTRING is |
| 58 | * in effect. |
| 59 | * 3. The buffered text that is about to be displayed e.g. the current line. |
| 60 | * Typically this will exclude the ampersands used for prefixing etc. |
| 61 | * |
| 62 | * Complications. |
| 63 | * a. If the buffered text to be displayed includes the ampersands then |
| 64 | * we will need special measurement and draw functions that will ignore |
| 65 | * the ampersands (e.g. by copying to a buffer without the prefix and |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 66 | * then using the normal forms). This may involve less space but may |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 67 | * require more processing. e.g. since a line containing tabs may |
| 68 | * contain several underlined characters either we need to carry around |
| 69 | * a list of prefix locations or we may need to locate them several |
| 70 | * times. |
| 71 | * b. If we actually directly modify the "original text" as we go then we |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 72 | * will need some special "caching" to handle the fact that when we |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 73 | * ellipsify the text the ellipsis may modify the next line of text, |
| 74 | * which we have not yet processed. (e.g. ellipsification of a W at the |
| 75 | * end of a line will overwrite the W, the \n and the first character of |
| 76 | * the next line, and a \0 will overwrite the second. Try it!!) |
| 77 | * |
| 78 | * Option 1. Three separate storages. (To be implemented) |
| 79 | * If DT_MODIFYSTRING is in effect then allocate an extra buffer to hold |
| 80 | * the edited string in some form, either as the string itself or as some |
| 81 | * sort of "edit list" to be applied just before returning. |
| 82 | * Use a buffer that holds the ellipsified current line sans ampersands |
| 83 | * and accept the need occasionally to recalculate the prefixes (if |
| 84 | * DT_EXPANDTABS and not DT_NOPREFIX and not DT_HIDEPREFIX) |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 85 | */ |
| 86 | |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 87 | #define TAB 9 |
| 88 | #define LF 10 |
| 89 | #define CR 13 |
| 90 | #define SPACE 32 |
| 91 | #define PREFIX 38 |
| 92 | |
Susan Farley | 196daf8 | 2000-09-22 22:09:11 +0000 | [diff] [blame] | 93 | #define FORWARD_SLASH '/' |
| 94 | #define BACK_SLASH '\\' |
| 95 | |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 96 | static const WCHAR ELLIPSISW[] = {'.','.','.', 0}; |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 97 | |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 98 | typedef struct tag_ellipsis_data |
| 99 | { |
| 100 | int before; |
| 101 | int len; |
| 102 | int under; |
| 103 | int after; |
| 104 | } ellipsis_data; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 105 | |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 106 | /********************************************************************* |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 107 | * TEXT_Ellipsify (static) |
| 108 | * |
| 109 | * Add an ellipsis to the end of the given string whilst ensuring it fits. |
| 110 | * |
| 111 | * If the ellipsis alone doesn't fit then it will be returned anyway. |
| 112 | * |
| 113 | * See Also TEXT_PathEllipsify |
| 114 | * |
| 115 | * Arguments |
| 116 | * hdc [in] The handle to the DC that defines the font. |
| 117 | * str [in/out] The string that needs to be modified. |
| 118 | * max_str [in] The dimension of str (number of WCHAR). |
| 119 | * len_str [in/out] The number of characters in str |
| 120 | * width [in] The maximum width permitted (in logical coordinates) |
| 121 | * size [out] The dimensions of the text |
| 122 | * modstr [out] The modified form of the string, to be returned to the |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 123 | * calling program. It is assumed that the caller has |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 124 | * made sufficient space available so we don't need to |
| 125 | * know the size of the space. This pointer may be NULL if |
| 126 | * the modified string is not required. |
| 127 | * len_before [out] The number of characters before the ellipsis. |
| 128 | * len_ellip [out] The number of characters in the ellipsis. |
| 129 | * |
| 130 | * See for example Microsoft article Q249678. |
| 131 | * |
| 132 | * For now we will simply use three dots rather than worrying about whether |
| 133 | * the font contains an explicit ellipsis character. |
| 134 | */ |
| 135 | static void TEXT_Ellipsify (HDC hdc, WCHAR *str, unsigned int max_len, |
| 136 | unsigned int *len_str, int width, SIZE *size, |
| 137 | WCHAR *modstr, |
| 138 | int *len_before, int *len_ellip) |
| 139 | { |
| 140 | unsigned int len_ellipsis; |
Paul Rupe | 2e2988d | 2002-06-10 22:47:58 +0000 | [diff] [blame] | 141 | unsigned int lo, mid, hi; |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 142 | |
| 143 | len_ellipsis = strlenW (ELLIPSISW); |
| 144 | if (len_ellipsis > max_len) len_ellipsis = max_len; |
| 145 | if (*len_str > max_len - len_ellipsis) |
| 146 | *len_str = max_len - len_ellipsis; |
| 147 | |
Paul Rupe | 2e2988d | 2002-06-10 22:47:58 +0000 | [diff] [blame] | 148 | /* First do a quick binary search to get an upper bound for *len_str. */ |
| 149 | if (*len_str > 0 && |
| 150 | GetTextExtentExPointW(hdc, str, *len_str, width, NULL, NULL, size) && |
| 151 | size->cx > width) |
| 152 | { |
| 153 | for (lo = 0, hi = *len_str; lo < hi; ) |
| 154 | { |
| 155 | mid = (lo + hi) / 2; |
| 156 | if (!GetTextExtentExPointW(hdc, str, mid, width, NULL, NULL, size)) |
| 157 | break; |
| 158 | if (size->cx > width) |
| 159 | hi = mid; |
| 160 | else |
| 161 | lo = mid + 1; |
| 162 | } |
| 163 | *len_str = hi; |
| 164 | } |
| 165 | /* Now this should take only a couple iterations at most. */ |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 166 | for ( ; ; ) |
| 167 | { |
Peter Berg Larsen | a667d53 | 2005-03-29 19:49:21 +0000 | [diff] [blame] | 168 | memcpy(str + *len_str, ELLIPSISW, len_ellipsis*sizeof(WCHAR)); |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 169 | |
| 170 | if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width, |
| 171 | NULL, NULL, size)) break; |
| 172 | |
| 173 | if (!*len_str || size->cx <= width) break; |
| 174 | |
| 175 | (*len_str)--; |
| 176 | } |
| 177 | *len_ellip = len_ellipsis; |
| 178 | *len_before = *len_str; |
| 179 | *len_str += len_ellipsis; |
| 180 | |
| 181 | if (modstr) |
| 182 | { |
Peter Berg Larsen | a667d53 | 2005-03-29 19:49:21 +0000 | [diff] [blame] | 183 | memcpy (modstr, str, *len_str * sizeof(WCHAR)); |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 184 | *(str+*len_str) = '\0'; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | /********************************************************************* |
Bill Medland | 92d77c9 | 2002-02-14 19:21:59 +0000 | [diff] [blame] | 189 | * TEXT_PathEllipsify (static) |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 190 | * |
| 191 | * Add an ellipsis to the provided string in order to make it fit within |
| 192 | * the width. The ellipsis is added as specified for the DT_PATH_ELLIPSIS |
| 193 | * flag. |
| 194 | * |
| 195 | * See Also TEXT_Ellipsify |
| 196 | * |
| 197 | * Arguments |
| 198 | * hdc [in] The handle to the DC that defines the font. |
| 199 | * str [in/out] The string that needs to be modified |
| 200 | * max_str [in] The dimension of str (number of WCHAR). |
| 201 | * len_str [in/out] The number of characters in str |
| 202 | * width [in] The maximum width permitted (in logical coordinates) |
| 203 | * size [out] The dimensions of the text |
| 204 | * modstr [out] The modified form of the string, to be returned to the |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 205 | * calling program. It is assumed that the caller has |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 206 | * made sufficient space available so we don't need to |
| 207 | * know the size of the space. This pointer may be NULL if |
| 208 | * the modified string is not required. |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 209 | * pellip [out] The ellipsification results |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 210 | * |
| 211 | * For now we will simply use three dots rather than worrying about whether |
| 212 | * the font contains an explicit ellipsis character. |
| 213 | * |
| 214 | * The following applies, I think to Win95. We will need to extend it for |
| 215 | * Win98 which can have both path and end ellipsis at the same time (e.g. |
| 216 | * C:\MyLongFileName.Txt becomes ...\MyLongFileN...) |
| 217 | * |
| 218 | * The resulting string consists of as much as possible of the following: |
| 219 | * 1. The ellipsis itself |
| 220 | * 2. The last \ or / of the string (if any) |
| 221 | * 3. Everything after the last \ or / of the string (if any) or the whole |
| 222 | * string if there is no / or \. I believe that under Win95 this would |
| 223 | * include everything even though some might be clipped off the end whereas |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 224 | * under Win98 that might be ellipsified too. |
| 225 | * Yet to be investigated is whether this would include wordbreaking if the |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 226 | * filename is more than 1 word and splitting if DT_EDITCONTROL was in |
| 227 | * effect. (If DT_EDITCONTROL is in effect then on occasions text will be |
| 228 | * broken within words). |
| 229 | * 4. All the stuff before the / or \, which is placed before the ellipsis. |
| 230 | */ |
| 231 | static void TEXT_PathEllipsify (HDC hdc, WCHAR *str, unsigned int max_len, |
| 232 | unsigned int *len_str, int width, SIZE *size, |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 233 | WCHAR *modstr, ellipsis_data *pellip) |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 234 | { |
| 235 | int len_ellipsis; |
| 236 | int len_trailing; |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 237 | int len_under; |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 238 | WCHAR *lastBkSlash, *lastFwdSlash, *lastSlash; |
| 239 | |
| 240 | len_ellipsis = strlenW (ELLIPSISW); |
| 241 | if (!max_len) return; |
| 242 | if (len_ellipsis >= max_len) len_ellipsis = max_len - 1; |
| 243 | if (*len_str + len_ellipsis >= max_len) |
| 244 | *len_str = max_len - len_ellipsis-1; |
| 245 | /* Hopefully this will never happen, otherwise it would probably lose |
| 246 | * the wrong character |
| 247 | */ |
| 248 | str[*len_str] = '\0'; /* to simplify things */ |
| 249 | |
| 250 | lastBkSlash = strrchrW (str, BACK_SLASH); |
| 251 | lastFwdSlash = strrchrW (str, FORWARD_SLASH); |
| 252 | lastSlash = lastBkSlash > lastFwdSlash ? lastBkSlash : lastFwdSlash; |
| 253 | if (!lastSlash) lastSlash = str; |
| 254 | len_trailing = *len_str - (lastSlash - str); |
| 255 | |
| 256 | /* overlap-safe movement to the right */ |
| 257 | memmove (lastSlash+len_ellipsis, lastSlash, len_trailing * sizeof(WCHAR)); |
Peter Berg Larsen | a667d53 | 2005-03-29 19:49:21 +0000 | [diff] [blame] | 258 | memcpy (lastSlash, ELLIPSISW, len_ellipsis*sizeof(WCHAR)); |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 259 | len_trailing += len_ellipsis; |
| 260 | /* From this point on lastSlash actually points to the ellipsis in front |
| 261 | * of the last slash and len_trailing includes the ellipsis |
| 262 | */ |
| 263 | |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 264 | len_under = 0; |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 265 | for ( ; ; ) |
| 266 | { |
| 267 | if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width, |
| 268 | NULL, NULL, size)) break; |
| 269 | |
| 270 | if (lastSlash == str || size->cx <= width) break; |
| 271 | |
| 272 | /* overlap-safe movement to the left */ |
| 273 | memmove (lastSlash-1, lastSlash, len_trailing * sizeof(WCHAR)); |
| 274 | lastSlash--; |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 275 | len_under++; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 276 | |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 277 | assert (*len_str); |
| 278 | (*len_str)--; |
| 279 | } |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 280 | pellip->before = lastSlash-str; |
| 281 | pellip->len = len_ellipsis; |
| 282 | pellip->under = len_under; |
| 283 | pellip->after = len_trailing - len_ellipsis; |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 284 | *len_str += len_ellipsis; |
| 285 | |
| 286 | if (modstr) |
| 287 | { |
Peter Berg Larsen | 1021219 | 2005-04-18 15:37:15 +0000 | [diff] [blame] | 288 | memcpy(modstr, str, *len_str * sizeof(WCHAR)); |
| 289 | modstr[*len_str] = '\0'; |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
Bill Medland | afe92e8 | 2002-02-05 18:07:04 +0000 | [diff] [blame] | 293 | /********************************************************************* |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 294 | * TEXT_WordBreak (static) |
| 295 | * |
| 296 | * Perform wordbreak processing on the given string |
| 297 | * |
| 298 | * Assumes that DT_WORDBREAK has been specified and not all the characters |
Bill Medland | bc39eee | 2002-02-26 00:39:30 +0000 | [diff] [blame] | 299 | * fit. Note that this function should even be called when the first character |
| 300 | * that doesn't fit is known to be a space or tab, so that it can swallow them. |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 301 | * |
Bill Medland | bc39eee | 2002-02-26 00:39:30 +0000 | [diff] [blame] | 302 | * Note that the Windows processing has some strange properties. |
| 303 | * 1. If the text is left-justified and there is room for some of the spaces |
| 304 | * that follow the last word on the line then those that fit are included on |
| 305 | * the line. |
| 306 | * 2. If the text is centred or right-justified and there is room for some of |
| 307 | * the spaces that follow the last word on the line then all but one of those |
| 308 | * that fit are included on the line. |
| 309 | * 3. (Reasonable behaviour) If the word breaking causes a space to be the first |
| 310 | * character of a new line it will be skipped. |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 311 | * |
| 312 | * Arguments |
| 313 | * hdc [in] The handle to the DC that defines the font. |
| 314 | * str [in/out] The string that needs to be broken. |
| 315 | * max_str [in] The dimension of str (number of WCHAR). |
| 316 | * len_str [in/out] The number of characters in str |
| 317 | * width [in] The maximum width permitted |
| 318 | * format [in] The format flags in effect |
| 319 | * chars_fit [in] The maximum number of characters of str that are already |
| 320 | * known to fit; chars_fit+1 is known not to fit. |
| 321 | * chars_used [out] The number of characters of str that have been "used" and |
| 322 | * do not need to be included in later text. For example this will |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 323 | * include any spaces that have been discarded from the start of |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 324 | * the next line. |
| 325 | * size [out] The size of the returned text in logical coordinates |
| 326 | * |
| 327 | * Pedantic assumption - Assumes that the text length is monotonically |
| 328 | * increasing with number of characters (i.e. no weird kernings) |
| 329 | * |
| 330 | * Algorithm |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 331 | * |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 332 | * Work back from the last character that did fit to either a space or the last |
| 333 | * character of a word, whichever is met first. |
| 334 | * If there was one or the first character didn't fit then |
Bill Medland | bc39eee | 2002-02-26 00:39:30 +0000 | [diff] [blame] | 335 | * If the text is centred or right justified and that one character was a |
| 336 | * space then break the line before that character |
| 337 | * Otherwise break the line after that character |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 338 | * and if the next character is a space then discard it. |
| 339 | * Suppose there was none (and the first character did fit). |
| 340 | * If Break Within Word is permitted |
| 341 | * break the word after the last character that fits (there must be |
| 342 | * at least one; none is caught earlier). |
| 343 | * Otherwise |
| 344 | * discard any trailing space. |
| 345 | * include the whole word; it may be ellipsified later |
| 346 | * |
| 347 | * Break Within Word is permitted under a set of circumstances that are not |
| 348 | * totally clear yet. Currently our best guess is: |
| 349 | * If DT_EDITCONTROL is in effect and neither DT_WORD_ELLIPSIS nor |
| 350 | * DT_PATH_ELLIPSIS is |
| 351 | */ |
| 352 | |
| 353 | static void TEXT_WordBreak (HDC hdc, WCHAR *str, unsigned int max_str, |
| 354 | unsigned int *len_str, |
| 355 | int width, int format, unsigned int chars_fit, |
| 356 | unsigned int *chars_used, SIZE *size) |
| 357 | { |
| 358 | WCHAR *p; |
| 359 | int word_fits; |
| 360 | assert (format & DT_WORDBREAK); |
| 361 | assert (chars_fit < *len_str); |
| 362 | |
| 363 | /* Work back from the last character that did fit to either a space or the |
| 364 | * last character of a word, whichever is met first. |
| 365 | */ |
| 366 | p = str + chars_fit; /* The character that doesn't fit */ |
| 367 | word_fits = TRUE; |
| 368 | if (!chars_fit) |
| 369 | ; /* we pretend that it fits anyway */ |
| 370 | else if (*p == SPACE) /* chars_fit < *len_str so this is valid */ |
| 371 | p--; /* the word just fitted */ |
| 372 | else |
| 373 | { |
| 374 | while (p > str && *(--p) != SPACE) |
| 375 | ; |
| 376 | word_fits = (p != str || *p == SPACE); |
| 377 | } |
| 378 | /* If there was one or the first character didn't fit then */ |
| 379 | if (word_fits) |
| 380 | { |
Robert O'Callahan | 71a8a74 | 2002-04-27 00:14:16 +0000 | [diff] [blame] | 381 | int next_is_space; |
Bill Medland | bc39eee | 2002-02-26 00:39:30 +0000 | [diff] [blame] | 382 | /* break the line before/after that character */ |
| 383 | if (!(format & (DT_RIGHT | DT_CENTER)) || *p != SPACE) |
| 384 | p++; |
Robert O'Callahan | 71a8a74 | 2002-04-27 00:14:16 +0000 | [diff] [blame] | 385 | next_is_space = (p - str) < *len_str && *p == SPACE; |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 386 | *len_str = p - str; |
| 387 | /* and if the next character is a space then discard it. */ |
| 388 | *chars_used = *len_str; |
Robert O'Callahan | 71a8a74 | 2002-04-27 00:14:16 +0000 | [diff] [blame] | 389 | if (next_is_space) |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 390 | (*chars_used)++; |
| 391 | } |
| 392 | /* Suppose there was none. */ |
| 393 | else |
| 394 | { |
| 395 | if ((format & (DT_EDITCONTROL | DT_WORD_ELLIPSIS | DT_PATH_ELLIPSIS)) == |
| 396 | DT_EDITCONTROL) |
| 397 | { |
| 398 | /* break the word after the last character that fits (there must be |
| 399 | * at least one; none is caught earlier). |
| 400 | */ |
| 401 | *len_str = chars_fit; |
| 402 | *chars_used = chars_fit; |
| 403 | |
| 404 | /* FIXME - possible error. Since the next character is now removed |
| 405 | * this could make the text longer so that it no longer fits, and |
| 406 | * so we need a loop to test and shrink. |
| 407 | */ |
| 408 | } |
| 409 | /* Otherwise */ |
| 410 | else |
| 411 | { |
| 412 | /* discard any trailing space. */ |
| 413 | const WCHAR *e = str + *len_str; |
| 414 | p = str + chars_fit; |
| 415 | while (p < e && *p != SPACE) |
| 416 | p++; |
| 417 | *chars_used = p - str; |
| 418 | if (p < e) /* i.e. loop failed because *p == SPACE */ |
| 419 | (*chars_used)++; |
| 420 | |
| 421 | /* include the whole word; it may be ellipsified later */ |
| 422 | *len_str = p - str; |
| 423 | /* Possible optimisation; if DT_WORD_ELLIPSIS only use chars_fit+1 |
| 424 | * so that it will be too long |
| 425 | */ |
| 426 | } |
| 427 | } |
| 428 | /* Remeasure the string */ |
| 429 | GetTextExtentExPointW (hdc, str, *len_str, 0, NULL, NULL, size); |
| 430 | } |
| 431 | |
| 432 | /********************************************************************* |
| 433 | * TEXT_SkipChars |
| 434 | * |
| 435 | * Skip over the given number of characters, bearing in mind prefix |
| 436 | * substitution and the fact that a character may take more than one |
| 437 | * WCHAR (Unicode surrogates are two words long) (and there may have been |
| 438 | * a trailing &) |
| 439 | * |
| 440 | * Parameters |
| 441 | * new_count [out] The updated count |
| 442 | * new_str [out] The updated pointer |
| 443 | * start_count [in] The count of remaining characters corresponding to the |
| 444 | * start of the string |
| 445 | * start_str [in] The starting point of the string |
| 446 | * max [in] The number of characters actually in this segment of the |
| 447 | * string (the & counts) |
| 448 | * n [in] The number of characters to skip (if prefix then |
| 449 | * &c counts as one) |
| 450 | * prefix [in] Apply prefix substitution |
| 451 | * |
| 452 | * Return Values |
| 453 | * none |
| 454 | * |
| 455 | * Remarks |
| 456 | * There must be at least n characters in the string |
| 457 | * We need max because the "line" may have ended with a & followed by a tab |
| 458 | * or newline etc. which we don't want to swallow |
| 459 | */ |
| 460 | |
| 461 | static void TEXT_SkipChars (int *new_count, const WCHAR **new_str, |
| 462 | int start_count, const WCHAR *start_str, |
| 463 | int max, int n, int prefix) |
| 464 | { |
| 465 | /* This is specific to wide characters, MSDN doesn't say anything much |
| 466 | * about Unicode surrogates yet and it isn't clear if _wcsinc will |
| 467 | * correctly handle them so we'll just do this the easy way for now |
| 468 | */ |
| 469 | |
| 470 | if (prefix) |
| 471 | { |
| 472 | const WCHAR *str_on_entry = start_str; |
| 473 | assert (max >= n); |
| 474 | max -= n; |
| 475 | while (n--) |
Mike McCormack | c818a4e | 2005-09-21 09:46:28 +0000 | [diff] [blame] | 476 | { |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 477 | if (*start_str++ == PREFIX && max--) |
| 478 | start_str++; |
Mike McCormack | c818a4e | 2005-09-21 09:46:28 +0000 | [diff] [blame] | 479 | } |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 480 | start_count -= (start_str - str_on_entry); |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | start_str += n; |
| 485 | start_count -= n; |
| 486 | } |
| 487 | *new_str = start_str; |
| 488 | *new_count = start_count; |
| 489 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 490 | |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 491 | /********************************************************************* |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 492 | * TEXT_Reprefix |
| 493 | * |
| 494 | * Reanalyse the text to find the prefixed character. This is called when |
| 495 | * wordbreaking or ellipsification has shortened the string such that the |
| 496 | * previously noted prefixed character is no longer visible. |
| 497 | * |
| 498 | * Parameters |
| 499 | * str [in] The original string segment (including all characters) |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 500 | * ns [in] The number of characters in str (including prefixes) |
| 501 | * pe [in] The ellipsification data |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 502 | * |
| 503 | * Return Values |
| 504 | * The prefix offset within the new string segment (the one that contains the |
| 505 | * ellipses and does not contain the prefix characters) (-1 if none) |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 506 | */ |
| 507 | |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 508 | static int TEXT_Reprefix (const WCHAR *str, unsigned int ns, |
| 509 | const ellipsis_data *pe) |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 510 | { |
| 511 | int result = -1; |
| 512 | unsigned int i = 0; |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 513 | unsigned int n = pe->before + pe->under + pe->after; |
| 514 | assert (n <= ns); |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 515 | while (i < n) |
| 516 | { |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 517 | if (i == pe->before) |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 518 | { |
| 519 | /* Reached the path ellipsis; jump over it */ |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 520 | if (ns < pe->under) break; |
| 521 | str += pe->under; |
| 522 | ns -= pe->under; |
| 523 | i += pe->under; |
| 524 | if (!pe->after) break; /* Nothing after the path ellipsis */ |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 525 | } |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 526 | if (!ns) break; |
| 527 | ns--; |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 528 | if (*str++ == PREFIX) |
| 529 | { |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 530 | if (!ns) break; |
| 531 | if (*str != PREFIX) |
| 532 | result = (i < pe->before || pe->under == 0) ? i : i - pe->under + pe->len; |
| 533 | /* pe->len may be non-zero while pe_under is zero */ |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 534 | str++; |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 535 | ns--; |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 536 | } |
Bill Medland | 001e732 | 2002-01-31 20:44:39 +0000 | [diff] [blame] | 537 | i++; |
| 538 | } |
| 539 | return result; |
| 540 | } |
Alexandre Julliard | 7e49205 | 2001-12-17 21:37:53 +0000 | [diff] [blame] | 541 | |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 542 | /********************************************************************* |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 543 | * Returns true if and only if the remainder of the line is a single |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 544 | * newline representation or nothing |
| 545 | */ |
| 546 | |
| 547 | static int remainder_is_none_or_newline (int num_chars, const WCHAR *str) |
| 548 | { |
| 549 | if (!num_chars) return TRUE; |
| 550 | if (*str != LF && *str != CR) return FALSE; |
| 551 | if (!--num_chars) return TRUE; |
| 552 | if (*str == *(str+1)) return FALSE; |
| 553 | str++; |
| 554 | if (*str != CR && *str != LF) return FALSE; |
| 555 | if (--num_chars) return FALSE; |
| 556 | return TRUE; |
| 557 | } |
| 558 | |
| 559 | /********************************************************************* |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 560 | * Return next line of text from a string. |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 561 | * |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 562 | * hdc - handle to DC. |
| 563 | * str - string to parse into lines. |
| 564 | * count - length of str. |
| 565 | * dest - destination in which to return line. |
Ulrich Czekalla | ebc5fe9 | 2001-01-20 02:16:52 +0000 | [diff] [blame] | 566 | * len - dest buffer size in chars on input, copied length into dest on output. |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 567 | * width - maximum width of line in pixels. |
| 568 | * format - format type passed to DrawText. |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 569 | * retsize - returned size of the line in pixels. |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 570 | * last_line - TRUE if is the last line that will be processed |
| 571 | * p_retstr - If DT_MODIFYSTRING this points to a cursor in the buffer in which |
| 572 | * the return string is built. |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 573 | * tabwidth - The width of a tab in logical coordinates |
| 574 | * pprefix_offset - Here is where we return the offset within dest of the first |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 575 | * prefixed (underlined) character. -1 is returned if there |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 576 | * are none. Note that there may be more; the calling code |
| 577 | * will need to use TEXT_Reprefix to find any later ones. |
| 578 | * pellip - Here is where we return the information about any ellipsification |
| 579 | * that was carried out. Note that if tabs are being expanded then |
| 580 | * this data will correspond to the last text segment actually |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 581 | * returned in dest; by definition there would not have been any |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 582 | * ellipsification in earlier text segments of the line. |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 583 | * |
| 584 | * Returns pointer to next char in str after end of the line |
| 585 | * or NULL if end of str reached. |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 586 | */ |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 587 | static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count, |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 588 | WCHAR *dest, int *len, int width, DWORD format, |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 589 | SIZE *retsize, int last_line, WCHAR **p_retstr, |
| 590 | int tabwidth, int *pprefix_offset, |
| 591 | ellipsis_data *pellip) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 592 | { |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 593 | int i = 0, j = 0; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 594 | int plen = 0; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 595 | SIZE size; |
Ulrich Czekalla | ebc5fe9 | 2001-01-20 02:16:52 +0000 | [diff] [blame] | 596 | int maxl = *len; |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 597 | int seg_i, seg_count, seg_j; |
| 598 | int max_seg_width; |
| 599 | int num_fit; |
| 600 | int word_broken; |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 601 | int line_fits; |
Mike McCormack | c787b14 | 2005-07-06 10:36:28 +0000 | [diff] [blame] | 602 | unsigned int j_in_seg; |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 603 | int ellipsified; |
Bill Medland | 2162eb8 | 2002-03-22 00:12:15 +0000 | [diff] [blame] | 604 | *pprefix_offset = -1; |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 605 | |
| 606 | /* For each text segment in the line */ |
| 607 | |
| 608 | retsize->cy = 0; |
| 609 | while (*count) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 610 | { |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 611 | |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 612 | /* Skip any leading tabs */ |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 613 | |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 614 | if (str[i] == TAB && (format & DT_EXPANDTABS)) |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 615 | { |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 616 | plen = ((plen/tabwidth)+1)*tabwidth; |
| 617 | (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++; |
| 618 | while (*count && str[i] == TAB) |
| 619 | { |
| 620 | plen += tabwidth; |
| 621 | (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++; |
| 622 | } |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 623 | } |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 624 | |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 625 | |
| 626 | /* Now copy as far as the next tab or cr/lf or eos */ |
| 627 | |
| 628 | seg_i = i; |
| 629 | seg_count = *count; |
| 630 | seg_j = j; |
| 631 | |
| 632 | while (*count && |
| 633 | (str[i] != TAB || !(format & DT_EXPANDTABS)) && |
| 634 | ((str[i] != CR && str[i] != LF) || (format & DT_SINGLELINE))) |
| 635 | { |
| 636 | if (str[i] == PREFIX && !(format & DT_NOPREFIX) && *count > 1) |
| 637 | { |
| 638 | (*count)--, i++; /* Throw away the prefix itself */ |
| 639 | if (str[i] == PREFIX) |
| 640 | { |
| 641 | /* Swallow it before we see it again */ |
| 642 | (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++; |
| 643 | } |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 644 | else if (*pprefix_offset == -1 || *pprefix_offset >= seg_j) |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 645 | { |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 646 | *pprefix_offset = j; |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 647 | } |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 648 | /* else the previous prefix was in an earlier segment of the |
| 649 | * line; we will leave it to the drawing code to catch this |
| 650 | * one. |
| 651 | */ |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 652 | } |
| 653 | else |
| 654 | { |
| 655 | (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 660 | /* Measure the whole text segment and possibly WordBreak and |
| 661 | * ellipsify it |
| 662 | */ |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 663 | |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 664 | j_in_seg = j - seg_j; |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 665 | max_seg_width = width - plen; |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 666 | GetTextExtentExPointW (hdc, dest + seg_j, j_in_seg, max_seg_width, &num_fit, NULL, &size); |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 667 | |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 668 | /* The Microsoft handling of various combinations of formats is weird. |
| 669 | * The following may very easily be incorrect if several formats are |
| 670 | * combined, and may differ between versions (to say nothing of the |
| 671 | * several bugs in the Microsoft versions). |
| 672 | */ |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 673 | word_broken = 0; |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 674 | line_fits = (num_fit >= j_in_seg); |
| 675 | if (!line_fits && (format & DT_WORDBREAK)) |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 676 | { |
| 677 | const WCHAR *s; |
Mike McCormack | c787b14 | 2005-07-06 10:36:28 +0000 | [diff] [blame] | 678 | unsigned int chars_used; |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 679 | TEXT_WordBreak (hdc, dest+seg_j, maxl-seg_j, &j_in_seg, |
| 680 | max_seg_width, format, num_fit, &chars_used, &size); |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 681 | line_fits = (size.cx <= max_seg_width); |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 682 | /* and correct the counts */ |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 683 | TEXT_SkipChars (count, &s, seg_count, str+seg_i, i-seg_i, |
| 684 | chars_used, !(format & DT_NOPREFIX)); |
| 685 | i = s - str; |
| 686 | word_broken = 1; |
| 687 | } |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 688 | pellip->before = j_in_seg; |
| 689 | pellip->under = 0; |
| 690 | pellip->after = 0; |
| 691 | pellip->len = 0; |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 692 | ellipsified = 0; |
| 693 | if (!line_fits && (format & DT_PATH_ELLIPSIS)) |
| 694 | { |
| 695 | TEXT_PathEllipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg, |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 696 | max_seg_width, &size, *p_retstr, pellip); |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 697 | line_fits = (size.cx <= max_seg_width); |
| 698 | ellipsified = 1; |
| 699 | } |
| 700 | /* NB we may end up ellipsifying a word-broken or path_ellipsified |
| 701 | * string */ |
| 702 | if ((!line_fits && (format & DT_WORD_ELLIPSIS)) || |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 703 | ((format & DT_END_ELLIPSIS) && |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 704 | ((last_line && *count) || |
| 705 | (remainder_is_none_or_newline (*count, &str[i]) && !line_fits)))) |
| 706 | { |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 707 | int before, len_ellipsis; |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 708 | TEXT_Ellipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg, |
| 709 | max_seg_width, &size, *p_retstr, &before, &len_ellipsis); |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 710 | if (before > pellip->before) |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 711 | { |
| 712 | /* We must have done a path ellipsis too */ |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 713 | pellip->after = before - pellip->before - pellip->len; |
| 714 | /* Leave the len as the length of the first ellipsis */ |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 715 | } |
| 716 | else |
| 717 | { |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 718 | /* If we are here after a path ellipsification it must be |
| 719 | * because even the ellipsis itself didn't fit. |
| 720 | */ |
| 721 | assert (pellip->under == 0 && pellip->after == 0); |
| 722 | pellip->before = before; |
| 723 | pellip->len = len_ellipsis; |
| 724 | /* pellip->after remains as zero as does |
| 725 | * pellip->under |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 726 | */ |
| 727 | } |
| 728 | line_fits = (size.cx <= max_seg_width); |
| 729 | ellipsified = 1; |
| 730 | } |
| 731 | /* As an optimisation if we have ellipsified and we are expanding |
| 732 | * tabs and we haven't reached the end of the line we can skip to it |
| 733 | * now rather than going around the loop again. |
| 734 | */ |
| 735 | if ((format & DT_EXPANDTABS) && ellipsified) |
| 736 | { |
| 737 | if (format & DT_SINGLELINE) |
| 738 | *count = 0; |
| 739 | else |
| 740 | { |
| 741 | while ((*count) && str[i] != CR && str[i] != LF) |
| 742 | { |
| 743 | (*count)--, i++; |
| 744 | } |
| 745 | } |
| 746 | } |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 747 | |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 748 | j = seg_j + j_in_seg; |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 749 | if (*pprefix_offset >= seg_j + pellip->before) |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 750 | { |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 751 | *pprefix_offset = TEXT_Reprefix (str + seg_i, i - seg_i, pellip); |
| 752 | if (*pprefix_offset != -1) |
| 753 | *pprefix_offset += seg_j; |
Bill Medland | 7423dc0 | 2002-02-21 20:07:26 +0000 | [diff] [blame] | 754 | } |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 755 | |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 756 | plen += size.cx; |
| 757 | if (size.cy > retsize->cy) |
| 758 | retsize->cy = size.cy; |
| 759 | |
| 760 | if (word_broken) |
| 761 | break; |
| 762 | else if (!*count) |
| 763 | break; |
| 764 | else if (str[i] == CR || str[i] == LF) |
| 765 | { |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 766 | (*count)--, i++; |
| 767 | if (*count && (str[i] == CR || str[i] == LF) && str[i] != str[i-1]) |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 768 | { |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 769 | (*count)--, i++; |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 770 | } |
| 771 | break; |
| 772 | } |
| 773 | /* else it was a Tab and we go around again */ |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 774 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 775 | |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 776 | retsize->cx = plen; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 777 | *len = j; |
Bill Medland | 7af9098 | 2002-02-19 18:25:53 +0000 | [diff] [blame] | 778 | if (*count) |
| 779 | return (&str[i]); |
| 780 | else |
| 781 | return NULL; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | |
| 785 | /*********************************************************************** |
Bill Medland | a4605ac | 2002-01-29 02:46:09 +0000 | [diff] [blame] | 786 | * TEXT_DrawUnderscore |
| 787 | * |
| 788 | * Draw the underline under the prefixed character |
| 789 | * |
| 790 | * Parameters |
| 791 | * hdc [in] The handle of the DC for drawing |
| 792 | * x [in] The x location of the line segment (logical coordinates) |
| 793 | * y [in] The y location of where the underscore should appear |
| 794 | * (logical coordinates) |
| 795 | * str [in] The text of the line segment |
| 796 | * offset [in] The offset of the underscored character within str |
Vitaliy Margolen | 3fc2544 | 2003-06-04 20:21:21 +0000 | [diff] [blame] | 797 | * rect [in] Clipping rectangle (if not NULL) |
Bill Medland | a4605ac | 2002-01-29 02:46:09 +0000 | [diff] [blame] | 798 | */ |
| 799 | |
Vitaliy Margolen | 3fc2544 | 2003-06-04 20:21:21 +0000 | [diff] [blame] | 800 | static void TEXT_DrawUnderscore (HDC hdc, int x, int y, const WCHAR *str, int offset, const RECT *rect) |
Bill Medland | a4605ac | 2002-01-29 02:46:09 +0000 | [diff] [blame] | 801 | { |
| 802 | int prefix_x; |
| 803 | int prefix_end; |
| 804 | SIZE size; |
| 805 | HPEN hpen; |
| 806 | HPEN oldPen; |
| 807 | |
| 808 | GetTextExtentPointW (hdc, str, offset, &size); |
| 809 | prefix_x = x + size.cx; |
| 810 | GetTextExtentPointW (hdc, str, offset+1, &size); |
| 811 | prefix_end = x + size.cx - 1; |
| 812 | /* The above method may eventually be slightly wrong due to kerning etc. */ |
| 813 | |
Vitaliy Margolen | 3fc2544 | 2003-06-04 20:21:21 +0000 | [diff] [blame] | 814 | /* Check for clipping */ |
| 815 | if (rect){ |
| 816 | if (prefix_x > rect->right || prefix_end < rect->left || y < rect->top || y > rect->bottom) |
| 817 | return; /* Completely outside */ |
| 818 | /* Partially outside */ |
| 819 | if (prefix_x < rect->left ) prefix_x = rect->left; |
| 820 | if (prefix_end > rect->right) prefix_end = rect->right; |
| 821 | } |
| 822 | |
Bill Medland | a4605ac | 2002-01-29 02:46:09 +0000 | [diff] [blame] | 823 | hpen = CreatePen (PS_SOLID, 1, GetTextColor (hdc)); |
| 824 | oldPen = SelectObject (hdc, hpen); |
| 825 | MoveToEx (hdc, prefix_x, y, NULL); |
| 826 | LineTo (hdc, prefix_end, y); |
| 827 | SelectObject (hdc, oldPen); |
| 828 | DeleteObject (hpen); |
| 829 | } |
| 830 | |
| 831 | /*********************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 832 | * DrawTextExW (USER32.@) |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 833 | * |
| 834 | * The documentation on the extra space required for DT_MODIFYSTRING at MSDN |
| 835 | * is not quite complete, especially with regard to \0. We will assume that |
| 836 | * the returned string could have a length of up to i_count+3 and also have |
| 837 | * a trailing \0 (which would be 4 more than a not-null-terminated string but |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 838 | * 3 more than a null-terminated string). If this is not so then increase |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 839 | * the allowance in DrawTextExA. |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 840 | */ |
Bill Medland | 22da469 | 2004-12-01 15:29:04 +0000 | [diff] [blame] | 841 | #define MAX_BUFFER 1024 |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 842 | INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count, |
| 843 | LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 844 | { |
| 845 | SIZE size; |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 846 | const WCHAR *strPtr; |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 847 | WCHAR *retstr, *p_retstr; |
| 848 | size_t size_retstr; |
Bill Medland | 22da469 | 2004-12-01 15:29:04 +0000 | [diff] [blame] | 849 | WCHAR line[MAX_BUFFER]; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 850 | int len, lh, count=i_count; |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 851 | TEXTMETRICW tm; |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 852 | int lmargin = 0, rmargin = 0; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 853 | int x = rect->left, y = rect->top; |
| 854 | int width = rect->right - rect->left; |
| 855 | int max_width = 0; |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 856 | int last_line; |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 857 | int tabwidth /* to keep gcc happy */ = 0; |
| 858 | int prefix_offset; |
| 859 | ellipsis_data ellip; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 860 | |
Dmitry Timoshkov | ba0ee34 | 2004-11-30 17:21:16 +0000 | [diff] [blame] | 861 | TRACE("%s, %d, [%s] %08x\n", debugstr_wn (str, count), count, |
| 862 | wine_dbgstr_rect(rect), flags); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 863 | |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 864 | if (dtp) TRACE("Params: iTabLength=%d, iLeftMargin=%d, iRightMargin=%d\n", |
| 865 | dtp->iTabLength, dtp->iLeftMargin, dtp->iRightMargin); |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 866 | |
Rein Klazes | ec23fb3 | 2006-01-27 15:47:15 +0100 | [diff] [blame] | 867 | if (!str || count == 0) return 0; |
| 868 | if (count == -1) |
| 869 | { |
| 870 | count = strlenW(str); |
| 871 | if (count == 0) |
| 872 | { |
| 873 | if( flags & DT_CALCRECT) |
| 874 | { |
| 875 | rect->right = rect->left; |
| 876 | rect->bottom = rect->top; |
| 877 | } |
| 878 | return 0; |
| 879 | } |
| 880 | } |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 881 | strPtr = str; |
| 882 | |
Bill Medland | 0f9013f | 2002-02-15 18:21:59 +0000 | [diff] [blame] | 883 | if (flags & DT_SINGLELINE) |
| 884 | flags &= ~DT_WORDBREAK; |
| 885 | |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 886 | GetTextMetricsW(hdc, &tm); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 887 | if (flags & DT_EXTERNALLEADING) |
| 888 | lh = tm.tmHeight + tm.tmExternalLeading; |
| 889 | else |
| 890 | lh = tm.tmHeight; |
| 891 | |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 892 | if (dtp) |
| 893 | { |
| 894 | lmargin = dtp->iLeftMargin * tm.tmAveCharWidth; |
| 895 | rmargin = dtp->iRightMargin * tm.tmAveCharWidth; |
| 896 | if (!(flags & (DT_CENTER | DT_RIGHT))) |
| 897 | x += lmargin; |
| 898 | dtp->uiLengthDrawn = 0; /* This param RECEIVES number of chars processed */ |
| 899 | } |
| 900 | |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 901 | if (flags & DT_EXPANDTABS) |
| 902 | { |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 903 | int tabstop = ((flags & DT_TABSTOP) && dtp) ? dtp->iTabLength : 8; |
| 904 | tabwidth = tm.tmAveCharWidth * tabstop; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | if (flags & DT_CALCRECT) flags |= DT_NOCLIP; |
| 908 | |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 909 | if (flags & DT_MODIFYSTRING) |
| 910 | { |
| 911 | size_retstr = (count + 4) * sizeof (WCHAR); |
| 912 | retstr = HeapAlloc(GetProcessHeap(), 0, size_retstr); |
| 913 | if (!retstr) return 0; |
| 914 | memcpy (retstr, str, size_retstr); |
| 915 | } |
| 916 | else |
| 917 | { |
| 918 | size_retstr = 0; |
| 919 | retstr = NULL; |
| 920 | } |
| 921 | p_retstr = retstr; |
| 922 | |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 923 | do |
| 924 | { |
Bill Medland | 22da469 | 2004-12-01 15:29:04 +0000 | [diff] [blame] | 925 | len = sizeof(line)/sizeof(line[0]); |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 926 | last_line = !(flags & DT_NOCLIP) && y + ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) > rect->bottom; |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 927 | strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags, &size, last_line, &p_retstr, tabwidth, &prefix_offset, &ellip); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 928 | |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 929 | if (flags & DT_CENTER) x = (rect->left + rect->right - |
| 930 | size.cx) / 2; |
| 931 | else if (flags & DT_RIGHT) x = rect->right - size.cx; |
| 932 | |
| 933 | if (flags & DT_SINGLELINE) |
| 934 | { |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 935 | if (flags & DT_VCENTER) y = rect->top + |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 936 | (rect->bottom - rect->top) / 2 - size.cy / 2; |
| 937 | else if (flags & DT_BOTTOM) y = rect->bottom - size.cy; |
Bill Medland | fcb8e0d | 2002-01-18 18:09:09 +0000 | [diff] [blame] | 938 | } |
Susan Farley | 196daf8 | 2000-09-22 22:09:11 +0000 | [diff] [blame] | 939 | |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 940 | if (!(flags & DT_CALCRECT)) |
| 941 | { |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 942 | const WCHAR *str = line; |
| 943 | int xseg = x; |
| 944 | while (len) |
| 945 | { |
| 946 | int len_seg; |
| 947 | SIZE size; |
| 948 | if ((flags & DT_EXPANDTABS)) |
| 949 | { |
| 950 | const WCHAR *p; |
| 951 | p = str; while (p < str+len && *p != TAB) p++; |
| 952 | len_seg = p - str; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 953 | if (len_seg != len && !GetTextExtentPointW(hdc, str, len_seg, &size)) |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 954 | return 0; |
| 955 | } |
| 956 | else |
| 957 | len_seg = len; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 958 | |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 959 | if (!ExtTextOutW( hdc, xseg, y, |
| 960 | ((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) | |
| 961 | ((flags & DT_RTLREADING) ? ETO_RTLREADING : 0), |
| 962 | rect, str, len_seg, NULL )) return 0; |
| 963 | if (prefix_offset != -1 && prefix_offset < len_seg) |
| 964 | { |
Vitaliy Margolen | 3fc2544 | 2003-06-04 20:21:21 +0000 | [diff] [blame] | 965 | TEXT_DrawUnderscore (hdc, xseg, y + tm.tmAscent + 1, str, prefix_offset, (flags & DT_NOCLIP) ? NULL : rect); |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 966 | } |
| 967 | len -= len_seg; |
| 968 | str += len_seg; |
| 969 | if (len) |
| 970 | { |
| 971 | assert ((flags & DT_EXPANDTABS) && *str == TAB); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 972 | len--; str++; |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 973 | xseg += ((size.cx/tabwidth)+1)*tabwidth; |
| 974 | if (prefix_offset != -1) |
| 975 | { |
| 976 | if (prefix_offset < len_seg) |
| 977 | { |
| 978 | /* We have just drawn an underscore; we ought to |
| 979 | * figure out where the next one is. I am going |
| 980 | * to leave it for now until I have a better model |
Bill Medland | 7d983d2 | 2002-03-11 01:15:31 +0000 | [diff] [blame] | 981 | * for the line, which will make reprefixing easier. |
| 982 | * This is where ellip would be used. |
Bill Medland | cabe8ca | 2002-02-12 18:40:36 +0000 | [diff] [blame] | 983 | */ |
| 984 | prefix_offset = -1; |
| 985 | } |
| 986 | else |
| 987 | prefix_offset -= len_seg; |
| 988 | } |
| 989 | } |
| 990 | } |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 991 | } |
| 992 | else if (size.cx > max_width) |
| 993 | max_width = size.cx; |
| 994 | |
| 995 | y += lh; |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 996 | if (dtp) |
| 997 | dtp->uiLengthDrawn += len; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 998 | } |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 999 | while (strPtr && !last_line); |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 1000 | |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1001 | if (flags & DT_CALCRECT) |
| 1002 | { |
| 1003 | rect->right = rect->left + max_width; |
| 1004 | rect->bottom = y; |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 1005 | if (dtp) |
| 1006 | rect->right += lmargin + rmargin; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1007 | } |
Bill Medland | 8513907 | 2002-02-20 18:56:18 +0000 | [diff] [blame] | 1008 | if (retstr) |
| 1009 | { |
| 1010 | memcpy (str, retstr, size_retstr); |
| 1011 | HeapFree (GetProcessHeap(), 0, retstr); |
| 1012 | } |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1013 | return y - rect->top; |
| 1014 | } |
| 1015 | |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1016 | /*********************************************************************** |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 1017 | * DrawTextExA (USER32.@) |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 1018 | * |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1019 | * If DT_MODIFYSTRING is specified then there must be room for up to |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 1020 | * 4 extra characters. We take great care about just how much modified |
| 1021 | * string we return. |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1022 | */ |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 1023 | INT WINAPI DrawTextExA( HDC hdc, LPSTR str, INT count, |
| 1024 | LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp ) |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1025 | { |
| 1026 | WCHAR *wstr; |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 1027 | WCHAR *p; |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1028 | INT ret = 0; |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 1029 | int i; |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1030 | DWORD wcount; |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 1031 | DWORD wmax; |
| 1032 | DWORD amax; |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1033 | |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1034 | if (!count) return 0; |
Rein Klazes | ec23fb3 | 2006-01-27 15:47:15 +0100 | [diff] [blame] | 1035 | if( !str || ((count == -1) && !(count = strlen(str)))) |
| 1036 | { |
| 1037 | if( flags & DT_CALCRECT) |
| 1038 | { |
| 1039 | rect->right = rect->left; |
| 1040 | rect->bottom = rect->top; |
| 1041 | } |
| 1042 | return 0; |
| 1043 | } |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1044 | wcount = MultiByteToWideChar( CP_ACP, 0, str, count, NULL, 0 ); |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 1045 | wmax = wcount; |
| 1046 | amax = count; |
| 1047 | if (flags & DT_MODIFYSTRING) |
| 1048 | { |
| 1049 | wmax += 4; |
| 1050 | amax += 4; |
| 1051 | } |
| 1052 | wstr = HeapAlloc(GetProcessHeap(), 0, wmax * sizeof(WCHAR)); |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1053 | if (wstr) |
| 1054 | { |
| 1055 | MultiByteToWideChar( CP_ACP, 0, str, count, wstr, wcount ); |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 1056 | if (flags & DT_MODIFYSTRING) |
| 1057 | for (i=4, p=wstr+wcount; i--; p++) *p=0xFFFE; |
| 1058 | /* Initialise the extra characters so that we can see which ones |
| 1059 | * change. U+FFFE is guaranteed to be not a unicode character and |
| 1060 | * so will not be generated by DrawTextEx itself. |
| 1061 | */ |
Ge van Geldorp | d1632bf | 2003-12-13 03:25:57 +0000 | [diff] [blame] | 1062 | ret = DrawTextExW( hdc, wstr, wcount, rect, flags, dtp ); |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 1063 | if (flags & DT_MODIFYSTRING) |
Bill Medland | fdb799a | 2002-02-02 18:14:35 +0000 | [diff] [blame] | 1064 | { |
| 1065 | /* Unfortunately the returned string may contain multiple \0s |
| 1066 | * and so we need to measure it ourselves. |
| 1067 | */ |
| 1068 | for (i=4, p=wstr+wcount; i-- && *p != 0xFFFE; p++) wcount++; |
| 1069 | WideCharToMultiByte( CP_ACP, 0, wstr, wcount, str, amax, NULL, NULL ); |
| 1070 | } |
Gerard Patel | 158e2cb | 2000-12-11 03:39:08 +0000 | [diff] [blame] | 1071 | HeapFree(GetProcessHeap(), 0, wstr); |
| 1072 | } |
| 1073 | return ret; |
| 1074 | } |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1075 | |
| 1076 | /*********************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 1077 | * DrawTextW (USER32.@) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1078 | */ |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 1079 | INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1080 | { |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 1081 | DRAWTEXTPARAMS dtp; |
| 1082 | |
| 1083 | memset (&dtp, 0, sizeof(dtp)); |
| 1084 | if (flags & DT_TABSTOP) |
| 1085 | { |
| 1086 | dtp.iTabLength = (flags >> 8) && 0xff; |
| 1087 | flags &= 0xffff00ff; |
| 1088 | } |
| 1089 | return DrawTextExW(hdc, (LPWSTR)str, count, rect, flags, &dtp); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | /*********************************************************************** |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 1093 | * DrawTextA (USER32.@) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1094 | */ |
Travis Michielsen | 188b32b | 2001-07-26 20:10:40 +0000 | [diff] [blame] | 1095 | INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count, LPRECT rect, UINT flags ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1096 | { |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 1097 | DRAWTEXTPARAMS dtp; |
| 1098 | |
| 1099 | memset (&dtp, 0, sizeof(dtp)); |
| 1100 | if (flags & DT_TABSTOP) |
| 1101 | { |
| 1102 | dtp.iTabLength = (flags >> 8) && 0xff; |
| 1103 | flags &= 0xffff00ff; |
| 1104 | } |
| 1105 | return DrawTextExA( hdc, (LPSTR)str, count, rect, flags, &dtp ); |
| 1106 | } |
| 1107 | |
| 1108 | /*********************************************************************** |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 1109 | * |
| 1110 | * GrayString functions |
| 1111 | */ |
| 1112 | |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1113 | /* callback for ASCII gray string proc */ |
| 1114 | static BOOL CALLBACK gray_string_callbackA( HDC hdc, LPARAM param, INT len ) |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 1115 | { |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1116 | return TextOutA( hdc, 0, 0, (LPCSTR)param, len ); |
| 1117 | } |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 1118 | |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1119 | /* callback for Unicode gray string proc */ |
| 1120 | static BOOL CALLBACK gray_string_callbackW( HDC hdc, LPARAM param, INT len ) |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 1121 | { |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1122 | return TextOutW( hdc, 0, 0, (LPCWSTR)param, len ); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | /*********************************************************************** |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1126 | * TEXT_GrayString |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1127 | */ |
| 1128 | static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, GRAYSTRINGPROC fn, LPARAM lp, INT len, |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1129 | INT x, INT y, INT cx, INT cy ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1130 | { |
| 1131 | HBITMAP hbm, hbmsave; |
| 1132 | HBRUSH hbsave; |
| 1133 | HFONT hfsave; |
Sander van Leeuwen | 500c201 | 2002-01-04 21:26:56 +0000 | [diff] [blame] | 1134 | HDC memdc; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1135 | int slen = len; |
| 1136 | BOOL retval = TRUE; |
| 1137 | COLORREF fg, bg; |
| 1138 | |
| 1139 | if(!hdc) return FALSE; |
Sander van Leeuwen | 500c201 | 2002-01-04 21:26:56 +0000 | [diff] [blame] | 1140 | if (!(memdc = CreateCompatibleDC(hdc))) return FALSE; |
| 1141 | |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1142 | hbm = CreateBitmap(cx, cy, 1, 1, NULL); |
| 1143 | hbmsave = (HBITMAP)SelectObject(memdc, hbm); |
| 1144 | hbsave = SelectObject( memdc, GetStockObject(BLACK_BRUSH) ); |
| 1145 | PatBlt( memdc, 0, 0, cx, cy, PATCOPY ); |
| 1146 | SelectObject( memdc, hbsave ); |
| 1147 | SetTextColor(memdc, RGB(255, 255, 255)); |
| 1148 | SetBkColor(memdc, RGB(0, 0, 0)); |
| 1149 | hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT)); |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 1150 | |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1151 | retval = fn(memdc, lp, slen); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1152 | SelectObject(memdc, hfsave); |
| 1153 | |
| 1154 | /* |
| 1155 | * Windows doc says that the bitmap isn't grayed when len == -1 and |
| 1156 | * the callback function returns FALSE. However, testing this on |
| 1157 | * win95 showed otherwise... |
| 1158 | */ |
| 1159 | #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR |
| 1160 | if(retval || len != -1) |
| 1161 | #endif |
| 1162 | { |
Alexandre Julliard | eea4153 | 2005-04-13 16:13:45 +0000 | [diff] [blame] | 1163 | hbsave = (HBRUSH)SelectObject(memdc, SYSCOLOR_55AABrush); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1164 | PatBlt(memdc, 0, 0, cx, cy, 0x000A0329); |
| 1165 | SelectObject(memdc, hbsave); |
| 1166 | } |
| 1167 | |
| 1168 | if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb); |
| 1169 | fg = SetTextColor(hdc, RGB(0, 0, 0)); |
| 1170 | bg = SetBkColor(hdc, RGB(255, 255, 255)); |
| 1171 | BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746); |
| 1172 | SetTextColor(hdc, fg); |
| 1173 | SetBkColor(hdc, bg); |
| 1174 | if(hb) SelectObject(hdc, hbsave); |
| 1175 | |
| 1176 | SelectObject(memdc, hbmsave); |
| 1177 | DeleteObject(hbm); |
| 1178 | DeleteDC(memdc); |
| 1179 | return retval; |
| 1180 | } |
| 1181 | |
| 1182 | |
| 1183 | /*********************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 1184 | * GrayStringA (USER32.@) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1185 | */ |
| 1186 | BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc, |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 1187 | LPARAM lParam, INT cch, INT x, INT y, |
| 1188 | INT cx, INT cy ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1189 | { |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1190 | if (!cch) cch = strlen( (LPCSTR)lParam ); |
| 1191 | if ((cx == 0 || cy == 0) && cch != -1) |
| 1192 | { |
| 1193 | SIZE s; |
| 1194 | GetTextExtentPoint32A( hdc, (LPCSTR)lParam, cch, &s ); |
| 1195 | if (cx == 0) cx = s.cx; |
| 1196 | if (cy == 0) cy = s.cy; |
| 1197 | } |
| 1198 | if (!gsprc) gsprc = gray_string_callbackA; |
| 1199 | return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy ); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | |
| 1203 | /*********************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 1204 | * GrayStringW (USER32.@) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1205 | */ |
| 1206 | BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc, |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 1207 | LPARAM lParam, INT cch, INT x, INT y, |
| 1208 | INT cx, INT cy ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1209 | { |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1210 | if (!cch) cch = strlenW( (LPCWSTR)lParam ); |
| 1211 | if ((cx == 0 || cy == 0) && cch != -1) |
| 1212 | { |
| 1213 | SIZE s; |
| 1214 | GetTextExtentPoint32W( hdc, (LPCWSTR)lParam, cch, &s ); |
| 1215 | if (cx == 0) cx = s.cx; |
| 1216 | if (cy == 0) cy = s.cy; |
| 1217 | } |
| 1218 | if (!gsprc) gsprc = gray_string_callbackW; |
| 1219 | return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy ); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
Bill Medland | fd59f34 | 2002-01-15 20:29:35 +0000 | [diff] [blame] | 1222 | |
| 1223 | /*********************************************************************** |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1224 | * TEXT_TabbedTextOut |
| 1225 | * |
| 1226 | * Helper function for TabbedTextOut() and GetTabbedTextExtent(). |
| 1227 | * Note: this doesn't work too well for text-alignment modes other |
| 1228 | * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-) |
| 1229 | */ |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1230 | static LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCWSTR lpstr, |
| 1231 | INT count, INT cTabStops, const INT *lpTabPos, INT nTabOrg, |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1232 | BOOL fDisplayText ) |
| 1233 | { |
| 1234 | INT defWidth; |
| 1235 | SIZE extent; |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1236 | int i, j; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1237 | int start = x; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1238 | |
Bill Medland | 62a80b7 | 2003-01-31 03:23:18 +0000 | [diff] [blame] | 1239 | if (!lpTabPos) |
| 1240 | cTabStops=0; |
| 1241 | |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1242 | if (cTabStops == 1) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1243 | { |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1244 | defWidth = *lpTabPos; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1245 | cTabStops = 0; |
| 1246 | } |
| 1247 | else |
| 1248 | { |
| 1249 | TEXTMETRICA tm; |
| 1250 | GetTextMetricsA( hdc, &tm ); |
| 1251 | defWidth = 8 * tm.tmAveCharWidth; |
| 1252 | } |
| 1253 | |
| 1254 | while (count > 0) |
| 1255 | { |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1256 | RECT r; |
| 1257 | INT x0; |
| 1258 | x0 = x; |
| 1259 | r.left = x0; |
| 1260 | /* chop the string into substrings of 0 or more <tabs> |
| 1261 | * possibly followed by 1 or more normal characters */ |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1262 | for (i = 0; i < count; i++) |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1263 | if (lpstr[i] != '\t') break; |
| 1264 | for (j = i; j < count; j++) |
| 1265 | if (lpstr[j] == '\t') break; |
| 1266 | /* get the extent of the normal character part */ |
| 1267 | GetTextExtentPointW( hdc, lpstr + i, j - i , &extent ); |
| 1268 | /* and if there is a <tab>, calculate its position */ |
| 1269 | if( i) { |
Robert Shearman | ff93df6 | 2005-07-12 18:11:26 +0000 | [diff] [blame] | 1270 | /* get x coordinate for the drawing of this string */ |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1271 | for (; cTabStops > i; lpTabPos++, cTabStops--) |
Robert Shearman | ff93df6 | 2005-07-12 18:11:26 +0000 | [diff] [blame] | 1272 | { |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1273 | if( nTabOrg + abs( *lpTabPos) > x) { |
| 1274 | if( lpTabPos[ i - 1] >= 0) { |
| 1275 | /* a left aligned tab */ |
| 1276 | x = nTabOrg + lpTabPos[ i-1] + extent.cx; |
Robert Shearman | ff93df6 | 2005-07-12 18:11:26 +0000 | [diff] [blame] | 1277 | break; |
| 1278 | } |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1279 | else |
Robert Shearman | ff93df6 | 2005-07-12 18:11:26 +0000 | [diff] [blame] | 1280 | { |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1281 | /* if tab pos is negative then text is right-aligned |
| 1282 | * to tab stop meaning that the string extends to the |
| 1283 | * left, so we must subtract the width of the string */ |
| 1284 | if (nTabOrg - lpTabPos[ i - 1] - extent.cx > x) |
| 1285 | { |
| 1286 | x = nTabOrg - lpTabPos[ i - 1]; |
| 1287 | x0 = x - extent.cx; |
| 1288 | break; |
| 1289 | } |
Robert Shearman | ff93df6 | 2005-07-12 18:11:26 +0000 | [diff] [blame] | 1290 | } |
| 1291 | } |
| 1292 | } |
| 1293 | /* if we have run out of tab stops and we have a valid default tab |
| 1294 | * stop width then round x up to that width */ |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1295 | if ((cTabStops <= i) && (defWidth > 0)) { |
| 1296 | x0 = nTabOrg + ((x - nTabOrg) / defWidth + i) * defWidth; |
| 1297 | x = x0 + extent.cx; |
| 1298 | } else if ((cTabStops <= i) && (defWidth < 0)) { |
| 1299 | x = nTabOrg + ((x - nTabOrg + extent.cx) / -defWidth + i) |
| 1300 | * -defWidth; |
| 1301 | x0 = x - extent.cx; |
| 1302 | } |
| 1303 | } else |
| 1304 | x += extent.cx; |
| 1305 | |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1306 | if (fDisplayText) |
| 1307 | { |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1308 | r.top = y; |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1309 | r.right = x; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1310 | r.bottom = y + extent.cy; |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1311 | ExtTextOutW( hdc, x0, y, GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0, |
| 1312 | &r, lpstr + i, j - i, NULL ); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1313 | } |
Rein Klazes | 16a5c4f | 2005-10-26 10:04:21 +0000 | [diff] [blame] | 1314 | count -= j; |
| 1315 | lpstr += j; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1316 | } |
Robert Shearman | ff93df6 | 2005-07-12 18:11:26 +0000 | [diff] [blame] | 1317 | return MAKELONG(x - start, extent.cy); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | /*********************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 1322 | * TabbedTextOutA (USER32.@) |
Robert Shearman | ff93df6 | 2005-07-12 18:11:26 +0000 | [diff] [blame] | 1323 | * |
| 1324 | * See TabbedTextOutW. |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1325 | */ |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 1326 | LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr, INT count, |
| 1327 | INT cTabStops, const INT *lpTabPos, INT nTabOrg ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1328 | { |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1329 | LONG ret; |
| 1330 | DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 ); |
| 1331 | LPWSTR strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); |
| 1332 | if (!strW) return 0; |
| 1333 | MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len ); |
| 1334 | ret = TabbedTextOutW( hdc, x, y, strW, len, cTabStops, lpTabPos, nTabOrg ); |
| 1335 | HeapFree( GetProcessHeap(), 0, strW ); |
| 1336 | return ret; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | /*********************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 1341 | * TabbedTextOutW (USER32.@) |
Robert Shearman | ff93df6 | 2005-07-12 18:11:26 +0000 | [diff] [blame] | 1342 | * |
| 1343 | * Draws tabbed text aligned using the specified tab stops. |
| 1344 | * |
| 1345 | * PARAMS |
| 1346 | * hdc [I] Handle to device context to draw to. |
| 1347 | * x [I] X co-ordinate to start drawing the text at in logical units. |
| 1348 | * y [I] Y co-ordinate to start drawing the text at in logical units. |
| 1349 | * str [I] Pointer to the characters to draw. |
| 1350 | * count [I] Number of WCHARs pointed to by str. |
| 1351 | * cTabStops [I] Number of tab stops pointed to by lpTabPos. |
| 1352 | * lpTabPos [I] Tab stops in logical units. Should be sorted in ascending order. |
| 1353 | * nTabOrg [I] Starting position to expand tabs from in logical units. |
| 1354 | * |
| 1355 | * RETURNS |
| 1356 | * The dimensions of the string drawn. The height is in the high-order word |
| 1357 | * and the width is in the low-order word. |
| 1358 | * |
| 1359 | * NOTES |
| 1360 | * The tabs stops can be negative, in which case the text is right aligned to |
| 1361 | * that tab stop and, despite what MSDN says, this is supported on |
| 1362 | * Windows XP SP2. |
| 1363 | * |
| 1364 | * BUGS |
| 1365 | * MSDN says that the TA_UPDATECP from GetTextAlign causes this function to |
| 1366 | * ignore the x and y co-ordinates, but this is unimplemented at the moment. |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1367 | */ |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 1368 | LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str, INT count, |
| 1369 | INT cTabStops, const INT *lpTabPos, INT nTabOrg ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1370 | { |
Alexandre Julliard | aff7dda | 2002-11-22 21:22:14 +0000 | [diff] [blame] | 1371 | TRACE("%p %d,%d %s %d\n", hdc, x, y, debugstr_wn(str,count), count ); |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1372 | return TEXT_TabbedTextOut( hdc, x, y, str, count, cTabStops, lpTabPos, nTabOrg, TRUE ); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | |
| 1376 | /*********************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 1377 | * GetTabbedTextExtentA (USER32.@) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1378 | */ |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 1379 | DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count, |
| 1380 | INT cTabStops, const INT *lpTabPos ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1381 | { |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1382 | LONG ret; |
| 1383 | DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 ); |
| 1384 | LPWSTR strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); |
| 1385 | if (!strW) return 0; |
| 1386 | MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len ); |
| 1387 | ret = GetTabbedTextExtentW( hdc, strW, len, cTabStops, lpTabPos ); |
| 1388 | HeapFree( GetProcessHeap(), 0, strW ); |
| 1389 | return ret; |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | |
| 1393 | /*********************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 1394 | * GetTabbedTextExtentW (USER32.@) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1395 | */ |
Dimitrie O. Paun | 981a9a4 | 2000-12-12 00:35:54 +0000 | [diff] [blame] | 1396 | DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count, |
| 1397 | INT cTabStops, const INT *lpTabPos ) |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1398 | { |
Alexandre Julliard | aff7dda | 2002-11-22 21:22:14 +0000 | [diff] [blame] | 1399 | TRACE("%p %s %d\n", hdc, debugstr_wn(lpstr,count), count ); |
Alexandre Julliard | 45078fb | 2002-11-22 20:41:17 +0000 | [diff] [blame] | 1400 | return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops, lpTabPos, 0, FALSE ); |
Alexandre Julliard | 93652e1 | 2000-08-04 04:21:02 +0000 | [diff] [blame] | 1401 | } |