2000-08-04 06:21:02 +02:00
|
|
|
/*
|
|
|
|
* USER text functions
|
|
|
|
*
|
|
|
|
* Copyright 1993, 1994 Alexandre Julliard
|
2002-02-21 21:07:26 +01:00
|
|
|
* Copyright 2002 Bill Medland
|
2000-08-04 06:21:02 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Contains
|
2002-01-15 21:29:35 +01:00
|
|
|
* 1. DrawText functions
|
|
|
|
* 2. GrayString functions
|
|
|
|
* 3. TabbedText functions
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2005-10-26 12:04:21 +02:00
|
|
|
#include <stdlib.h>
|
2000-08-04 06:21:02 +02:00
|
|
|
#include <string.h>
|
2002-02-05 19:07:04 +01:00
|
|
|
#include <assert.h>
|
2000-08-04 06:21:02 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
2000-08-04 06:21:02 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winnls.h"
|
2004-09-01 20:26:40 +02:00
|
|
|
#include "controls.h"
|
2013-09-12 17:45:51 +02:00
|
|
|
#include "usp10.h"
|
2005-04-13 18:13:45 +02:00
|
|
|
#include "user_private.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2018-05-04 05:11:43 +02:00
|
|
|
#include "wine/heap.h"
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(text);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2002-01-15 21:29:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* DrawText functions
|
2002-01-31 21:44:39 +01:00
|
|
|
*
|
|
|
|
* Design issues
|
|
|
|
* How many buffers to use
|
|
|
|
* While processing in DrawText there are potentially three different forms
|
|
|
|
* of the text that need to be held. How are they best held?
|
|
|
|
* 1. The original text is needed, of course, to see what to display.
|
|
|
|
* 2. The text that will be returned to the user if the DT_MODIFYSTRING is
|
|
|
|
* in effect.
|
|
|
|
* 3. The buffered text that is about to be displayed e.g. the current line.
|
|
|
|
* Typically this will exclude the ampersands used for prefixing etc.
|
|
|
|
*
|
|
|
|
* Complications.
|
|
|
|
* a. If the buffered text to be displayed includes the ampersands then
|
|
|
|
* we will need special measurement and draw functions that will ignore
|
|
|
|
* the ampersands (e.g. by copying to a buffer without the prefix and
|
2002-06-01 01:06:46 +02:00
|
|
|
* then using the normal forms). This may involve less space but may
|
2002-01-31 21:44:39 +01:00
|
|
|
* require more processing. e.g. since a line containing tabs may
|
|
|
|
* contain several underlined characters either we need to carry around
|
|
|
|
* a list of prefix locations or we may need to locate them several
|
|
|
|
* times.
|
|
|
|
* b. If we actually directly modify the "original text" as we go then we
|
2002-06-01 01:06:46 +02:00
|
|
|
* will need some special "caching" to handle the fact that when we
|
2002-01-31 21:44:39 +01:00
|
|
|
* ellipsify the text the ellipsis may modify the next line of text,
|
|
|
|
* which we have not yet processed. (e.g. ellipsification of a W at the
|
|
|
|
* end of a line will overwrite the W, the \n and the first character of
|
|
|
|
* the next line, and a \0 will overwrite the second. Try it!!)
|
|
|
|
*
|
|
|
|
* Option 1. Three separate storages. (To be implemented)
|
|
|
|
* If DT_MODIFYSTRING is in effect then allocate an extra buffer to hold
|
|
|
|
* the edited string in some form, either as the string itself or as some
|
|
|
|
* sort of "edit list" to be applied just before returning.
|
|
|
|
* Use a buffer that holds the ellipsified current line sans ampersands
|
|
|
|
* and accept the need occasionally to recalculate the prefixes (if
|
|
|
|
* DT_EXPANDTABS and not DT_NOPREFIX and not DT_HIDEPREFIX)
|
2002-01-15 21:29:35 +01:00
|
|
|
*/
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
#define TAB 9
|
|
|
|
#define LF 10
|
|
|
|
#define CR 13
|
|
|
|
#define SPACE 32
|
|
|
|
#define PREFIX 38
|
2012-09-05 13:31:17 +02:00
|
|
|
#define ALPHA_PREFIX 30 /* Win16: Alphabet prefix */
|
|
|
|
#define KANA_PREFIX 31 /* Win16: Katakana prefix */
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2000-09-23 00:09:11 +02:00
|
|
|
#define FORWARD_SLASH '/'
|
|
|
|
#define BACK_SLASH '\\'
|
|
|
|
|
2020-09-21 16:31:11 +02:00
|
|
|
static const WCHAR ELLIPSISW[] = L"...";
|
2000-12-11 04:39:08 +01:00
|
|
|
|
2002-03-11 02:15:31 +01:00
|
|
|
typedef struct tag_ellipsis_data
|
|
|
|
{
|
|
|
|
int before;
|
|
|
|
int len;
|
|
|
|
int under;
|
|
|
|
int after;
|
|
|
|
} ellipsis_data;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2002-02-05 19:07:04 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* TEXT_Ellipsify (static)
|
|
|
|
*
|
|
|
|
* Add an ellipsis to the end of the given string whilst ensuring it fits.
|
|
|
|
*
|
|
|
|
* If the ellipsis alone doesn't fit then it will be returned anyway.
|
|
|
|
*
|
|
|
|
* See Also TEXT_PathEllipsify
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
* hdc [in] The handle to the DC that defines the font.
|
|
|
|
* str [in/out] The string that needs to be modified.
|
|
|
|
* max_str [in] The dimension of str (number of WCHAR).
|
|
|
|
* len_str [in/out] The number of characters in str
|
|
|
|
* width [in] The maximum width permitted (in logical coordinates)
|
|
|
|
* size [out] The dimensions of the text
|
|
|
|
* modstr [out] The modified form of the string, to be returned to the
|
2002-06-01 01:06:46 +02:00
|
|
|
* calling program. It is assumed that the caller has
|
2002-02-05 19:07:04 +01:00
|
|
|
* made sufficient space available so we don't need to
|
|
|
|
* know the size of the space. This pointer may be NULL if
|
|
|
|
* the modified string is not required.
|
|
|
|
* len_before [out] The number of characters before the ellipsis.
|
|
|
|
* len_ellip [out] The number of characters in the ellipsis.
|
|
|
|
*
|
|
|
|
* See for example Microsoft article Q249678.
|
|
|
|
*
|
|
|
|
* For now we will simply use three dots rather than worrying about whether
|
|
|
|
* the font contains an explicit ellipsis character.
|
|
|
|
*/
|
|
|
|
static void TEXT_Ellipsify (HDC hdc, WCHAR *str, unsigned int max_len,
|
|
|
|
unsigned int *len_str, int width, SIZE *size,
|
|
|
|
WCHAR *modstr,
|
|
|
|
int *len_before, int *len_ellip)
|
|
|
|
{
|
|
|
|
unsigned int len_ellipsis;
|
2002-06-11 00:47:58 +02:00
|
|
|
unsigned int lo, mid, hi;
|
2002-02-05 19:07:04 +01:00
|
|
|
|
2020-09-21 13:53:21 +02:00
|
|
|
len_ellipsis = lstrlenW (ELLIPSISW);
|
2002-02-05 19:07:04 +01:00
|
|
|
if (len_ellipsis > max_len) len_ellipsis = max_len;
|
|
|
|
if (*len_str > max_len - len_ellipsis)
|
|
|
|
*len_str = max_len - len_ellipsis;
|
|
|
|
|
2002-06-11 00:47:58 +02:00
|
|
|
/* First do a quick binary search to get an upper bound for *len_str. */
|
|
|
|
if (*len_str > 0 &&
|
|
|
|
GetTextExtentExPointW(hdc, str, *len_str, width, NULL, NULL, size) &&
|
|
|
|
size->cx > width)
|
|
|
|
{
|
|
|
|
for (lo = 0, hi = *len_str; lo < hi; )
|
|
|
|
{
|
|
|
|
mid = (lo + hi) / 2;
|
|
|
|
if (!GetTextExtentExPointW(hdc, str, mid, width, NULL, NULL, size))
|
|
|
|
break;
|
|
|
|
if (size->cx > width)
|
|
|
|
hi = mid;
|
|
|
|
else
|
|
|
|
lo = mid + 1;
|
|
|
|
}
|
|
|
|
*len_str = hi;
|
|
|
|
}
|
|
|
|
/* Now this should take only a couple iterations at most. */
|
2002-02-05 19:07:04 +01:00
|
|
|
for ( ; ; )
|
|
|
|
{
|
2005-03-29 21:49:21 +02:00
|
|
|
memcpy(str + *len_str, ELLIPSISW, len_ellipsis*sizeof(WCHAR));
|
2002-02-05 19:07:04 +01:00
|
|
|
|
|
|
|
if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width,
|
|
|
|
NULL, NULL, size)) break;
|
|
|
|
|
|
|
|
if (!*len_str || size->cx <= width) break;
|
|
|
|
|
|
|
|
(*len_str)--;
|
|
|
|
}
|
|
|
|
*len_ellip = len_ellipsis;
|
|
|
|
*len_before = *len_str;
|
|
|
|
*len_str += len_ellipsis;
|
|
|
|
|
|
|
|
if (modstr)
|
|
|
|
{
|
2005-03-29 21:49:21 +02:00
|
|
|
memcpy (modstr, str, *len_str * sizeof(WCHAR));
|
2008-05-21 18:49:07 +02:00
|
|
|
modstr[*len_str] = '\0';
|
2002-02-05 19:07:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2002-02-14 20:21:59 +01:00
|
|
|
* TEXT_PathEllipsify (static)
|
2002-02-05 19:07:04 +01:00
|
|
|
*
|
|
|
|
* Add an ellipsis to the provided string in order to make it fit within
|
|
|
|
* the width. The ellipsis is added as specified for the DT_PATH_ELLIPSIS
|
|
|
|
* flag.
|
|
|
|
*
|
|
|
|
* See Also TEXT_Ellipsify
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
* hdc [in] The handle to the DC that defines the font.
|
|
|
|
* str [in/out] The string that needs to be modified
|
|
|
|
* max_str [in] The dimension of str (number of WCHAR).
|
|
|
|
* len_str [in/out] The number of characters in str
|
|
|
|
* width [in] The maximum width permitted (in logical coordinates)
|
|
|
|
* size [out] The dimensions of the text
|
|
|
|
* modstr [out] The modified form of the string, to be returned to the
|
2002-06-01 01:06:46 +02:00
|
|
|
* calling program. It is assumed that the caller has
|
2002-02-05 19:07:04 +01:00
|
|
|
* made sufficient space available so we don't need to
|
|
|
|
* know the size of the space. This pointer may be NULL if
|
|
|
|
* the modified string is not required.
|
2002-03-11 02:15:31 +01:00
|
|
|
* pellip [out] The ellipsification results
|
2002-02-05 19:07:04 +01:00
|
|
|
*
|
|
|
|
* For now we will simply use three dots rather than worrying about whether
|
|
|
|
* the font contains an explicit ellipsis character.
|
|
|
|
*
|
|
|
|
* The following applies, I think to Win95. We will need to extend it for
|
|
|
|
* Win98 which can have both path and end ellipsis at the same time (e.g.
|
|
|
|
* C:\MyLongFileName.Txt becomes ...\MyLongFileN...)
|
|
|
|
*
|
|
|
|
* The resulting string consists of as much as possible of the following:
|
|
|
|
* 1. The ellipsis itself
|
|
|
|
* 2. The last \ or / of the string (if any)
|
|
|
|
* 3. Everything after the last \ or / of the string (if any) or the whole
|
|
|
|
* string if there is no / or \. I believe that under Win95 this would
|
|
|
|
* include everything even though some might be clipped off the end whereas
|
2002-03-11 02:15:31 +01:00
|
|
|
* under Win98 that might be ellipsified too.
|
|
|
|
* Yet to be investigated is whether this would include wordbreaking if the
|
2002-02-05 19:07:04 +01:00
|
|
|
* filename is more than 1 word and splitting if DT_EDITCONTROL was in
|
|
|
|
* effect. (If DT_EDITCONTROL is in effect then on occasions text will be
|
|
|
|
* broken within words).
|
|
|
|
* 4. All the stuff before the / or \, which is placed before the ellipsis.
|
|
|
|
*/
|
|
|
|
static void TEXT_PathEllipsify (HDC hdc, WCHAR *str, unsigned int max_len,
|
|
|
|
unsigned int *len_str, int width, SIZE *size,
|
2002-03-11 02:15:31 +01:00
|
|
|
WCHAR *modstr, ellipsis_data *pellip)
|
2002-02-05 19:07:04 +01:00
|
|
|
{
|
|
|
|
int len_ellipsis;
|
|
|
|
int len_trailing;
|
2002-03-11 02:15:31 +01:00
|
|
|
int len_under;
|
2002-02-05 19:07:04 +01:00
|
|
|
WCHAR *lastBkSlash, *lastFwdSlash, *lastSlash;
|
|
|
|
|
2020-09-21 13:53:21 +02:00
|
|
|
len_ellipsis = lstrlenW (ELLIPSISW);
|
2002-02-05 19:07:04 +01:00
|
|
|
if (!max_len) return;
|
|
|
|
if (len_ellipsis >= max_len) len_ellipsis = max_len - 1;
|
|
|
|
if (*len_str + len_ellipsis >= max_len)
|
|
|
|
*len_str = max_len - len_ellipsis-1;
|
|
|
|
/* Hopefully this will never happen, otherwise it would probably lose
|
|
|
|
* the wrong character
|
|
|
|
*/
|
|
|
|
str[*len_str] = '\0'; /* to simplify things */
|
|
|
|
|
2020-09-21 13:53:21 +02:00
|
|
|
lastBkSlash = wcsrchr (str, BACK_SLASH);
|
|
|
|
lastFwdSlash = wcsrchr (str, FORWARD_SLASH);
|
2002-02-05 19:07:04 +01:00
|
|
|
lastSlash = lastBkSlash > lastFwdSlash ? lastBkSlash : lastFwdSlash;
|
|
|
|
if (!lastSlash) lastSlash = str;
|
|
|
|
len_trailing = *len_str - (lastSlash - str);
|
|
|
|
|
|
|
|
/* overlap-safe movement to the right */
|
|
|
|
memmove (lastSlash+len_ellipsis, lastSlash, len_trailing * sizeof(WCHAR));
|
2005-03-29 21:49:21 +02:00
|
|
|
memcpy (lastSlash, ELLIPSISW, len_ellipsis*sizeof(WCHAR));
|
2002-02-05 19:07:04 +01:00
|
|
|
len_trailing += len_ellipsis;
|
|
|
|
/* From this point on lastSlash actually points to the ellipsis in front
|
|
|
|
* of the last slash and len_trailing includes the ellipsis
|
|
|
|
*/
|
|
|
|
|
2002-03-11 02:15:31 +01:00
|
|
|
len_under = 0;
|
2002-02-05 19:07:04 +01:00
|
|
|
for ( ; ; )
|
|
|
|
{
|
|
|
|
if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width,
|
|
|
|
NULL, NULL, size)) break;
|
|
|
|
|
|
|
|
if (lastSlash == str || size->cx <= width) break;
|
|
|
|
|
|
|
|
/* overlap-safe movement to the left */
|
|
|
|
memmove (lastSlash-1, lastSlash, len_trailing * sizeof(WCHAR));
|
|
|
|
lastSlash--;
|
2002-03-11 02:15:31 +01:00
|
|
|
len_under++;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-02-05 19:07:04 +01:00
|
|
|
assert (*len_str);
|
|
|
|
(*len_str)--;
|
|
|
|
}
|
2002-03-11 02:15:31 +01:00
|
|
|
pellip->before = lastSlash-str;
|
|
|
|
pellip->len = len_ellipsis;
|
|
|
|
pellip->under = len_under;
|
|
|
|
pellip->after = len_trailing - len_ellipsis;
|
2002-02-05 19:07:04 +01:00
|
|
|
*len_str += len_ellipsis;
|
|
|
|
|
|
|
|
if (modstr)
|
|
|
|
{
|
2005-04-18 17:37:15 +02:00
|
|
|
memcpy(modstr, str, *len_str * sizeof(WCHAR));
|
|
|
|
modstr[*len_str] = '\0';
|
2002-02-05 19:07:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-19 19:25:53 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* TEXT_WordBreak (static)
|
|
|
|
*
|
|
|
|
* Perform wordbreak processing on the given string
|
|
|
|
*
|
|
|
|
* Assumes that DT_WORDBREAK has been specified and not all the characters
|
2002-02-26 01:39:30 +01:00
|
|
|
* fit. Note that this function should even be called when the first character
|
|
|
|
* that doesn't fit is known to be a space or tab, so that it can swallow them.
|
2002-02-19 19:25:53 +01:00
|
|
|
*
|
2002-02-26 01:39:30 +01:00
|
|
|
* Note that the Windows processing has some strange properties.
|
|
|
|
* 1. If the text is left-justified and there is room for some of the spaces
|
|
|
|
* that follow the last word on the line then those that fit are included on
|
|
|
|
* the line.
|
2011-08-02 22:20:32 +02:00
|
|
|
* 2. If the text is centered or right-justified and there is room for some of
|
2002-02-26 01:39:30 +01:00
|
|
|
* the spaces that follow the last word on the line then all but one of those
|
|
|
|
* that fit are included on the line.
|
|
|
|
* 3. (Reasonable behaviour) If the word breaking causes a space to be the first
|
|
|
|
* character of a new line it will be skipped.
|
2002-02-19 19:25:53 +01:00
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
* hdc [in] The handle to the DC that defines the font.
|
|
|
|
* str [in/out] The string that needs to be broken.
|
|
|
|
* max_str [in] The dimension of str (number of WCHAR).
|
|
|
|
* len_str [in/out] The number of characters in str
|
|
|
|
* width [in] The maximum width permitted
|
|
|
|
* format [in] The format flags in effect
|
|
|
|
* chars_fit [in] The maximum number of characters of str that are already
|
|
|
|
* known to fit; chars_fit+1 is known not to fit.
|
|
|
|
* chars_used [out] The number of characters of str that have been "used" and
|
|
|
|
* do not need to be included in later text. For example this will
|
2002-06-01 01:06:46 +02:00
|
|
|
* include any spaces that have been discarded from the start of
|
2002-02-19 19:25:53 +01:00
|
|
|
* the next line.
|
|
|
|
* size [out] The size of the returned text in logical coordinates
|
|
|
|
*
|
|
|
|
* Pedantic assumption - Assumes that the text length is monotonically
|
|
|
|
* increasing with number of characters (i.e. no weird kernings)
|
|
|
|
*
|
|
|
|
* Algorithm
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2002-02-19 19:25:53 +01:00
|
|
|
* Work back from the last character that did fit to either a space or the last
|
|
|
|
* character of a word, whichever is met first.
|
|
|
|
* If there was one or the first character didn't fit then
|
2011-08-02 22:20:32 +02:00
|
|
|
* If the text is centered or right justified and that one character was a
|
2002-02-26 01:39:30 +01:00
|
|
|
* space then break the line before that character
|
|
|
|
* Otherwise break the line after that character
|
2002-02-19 19:25:53 +01:00
|
|
|
* and if the next character is a space then discard it.
|
|
|
|
* Suppose there was none (and the first character did fit).
|
|
|
|
* If Break Within Word is permitted
|
|
|
|
* break the word after the last character that fits (there must be
|
|
|
|
* at least one; none is caught earlier).
|
|
|
|
* Otherwise
|
|
|
|
* discard any trailing space.
|
|
|
|
* include the whole word; it may be ellipsified later
|
|
|
|
*
|
|
|
|
* Break Within Word is permitted under a set of circumstances that are not
|
|
|
|
* totally clear yet. Currently our best guess is:
|
|
|
|
* If DT_EDITCONTROL is in effect and neither DT_WORD_ELLIPSIS nor
|
|
|
|
* DT_PATH_ELLIPSIS is
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void TEXT_WordBreak (HDC hdc, WCHAR *str, unsigned int max_str,
|
|
|
|
unsigned int *len_str,
|
|
|
|
int width, int format, unsigned int chars_fit,
|
|
|
|
unsigned int *chars_used, SIZE *size)
|
|
|
|
{
|
|
|
|
WCHAR *p;
|
2013-09-27 08:43:21 +02:00
|
|
|
BOOL word_fits;
|
2013-09-12 17:45:51 +02:00
|
|
|
SCRIPT_LOGATTR *sla;
|
|
|
|
SCRIPT_ANALYSIS sa;
|
|
|
|
int i;
|
|
|
|
|
2002-02-19 19:25:53 +01:00
|
|
|
assert (format & DT_WORDBREAK);
|
|
|
|
assert (chars_fit < *len_str);
|
|
|
|
|
2018-05-04 05:11:43 +02:00
|
|
|
sla = heap_alloc(sizeof(SCRIPT_LOGATTR) * *len_str);
|
2013-09-12 17:45:51 +02:00
|
|
|
|
|
|
|
memset(&sa, 0, sizeof(SCRIPT_ANALYSIS));
|
|
|
|
sa.eScript = SCRIPT_UNDEFINED;
|
|
|
|
|
|
|
|
ScriptBreak(str, *len_str, &sa, sla);
|
|
|
|
|
2002-02-19 19:25:53 +01:00
|
|
|
/* Work back from the last character that did fit to either a space or the
|
|
|
|
* last character of a word, whichever is met first.
|
|
|
|
*/
|
|
|
|
p = str + chars_fit; /* The character that doesn't fit */
|
2013-09-12 17:45:51 +02:00
|
|
|
i = chars_fit;
|
2002-02-19 19:25:53 +01:00
|
|
|
word_fits = TRUE;
|
|
|
|
if (!chars_fit)
|
2014-03-11 18:41:43 +01:00
|
|
|
word_fits = FALSE;
|
2013-09-12 17:45:51 +02:00
|
|
|
else if (sla[i].fSoftBreak) /* chars_fit < *len_str so this is valid */
|
|
|
|
{
|
|
|
|
/* the word just fitted */
|
|
|
|
p--;
|
|
|
|
}
|
2002-02-19 19:25:53 +01:00
|
|
|
else
|
|
|
|
{
|
2013-09-12 17:45:51 +02:00
|
|
|
while (i > 0 && !sla[(--i)+1].fSoftBreak) p--;
|
|
|
|
p--;
|
|
|
|
word_fits = (i != 0 || sla[i+1].fSoftBreak );
|
2002-02-19 19:25:53 +01:00
|
|
|
}
|
2013-09-12 17:45:51 +02:00
|
|
|
|
2014-03-11 18:41:43 +01:00
|
|
|
/* If there was one. */
|
2002-02-19 19:25:53 +01:00
|
|
|
if (word_fits)
|
|
|
|
{
|
2013-09-27 08:43:21 +02:00
|
|
|
BOOL next_is_space;
|
2002-02-26 01:39:30 +01:00
|
|
|
/* break the line before/after that character */
|
|
|
|
if (!(format & (DT_RIGHT | DT_CENTER)) || *p != SPACE)
|
|
|
|
p++;
|
2002-04-27 02:14:16 +02:00
|
|
|
next_is_space = (p - str) < *len_str && *p == SPACE;
|
2002-02-19 19:25:53 +01:00
|
|
|
*len_str = p - str;
|
|
|
|
/* and if the next character is a space then discard it. */
|
|
|
|
*chars_used = *len_str;
|
2002-04-27 02:14:16 +02:00
|
|
|
if (next_is_space)
|
2002-02-19 19:25:53 +01:00
|
|
|
(*chars_used)++;
|
|
|
|
}
|
|
|
|
/* Suppose there was none. */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((format & (DT_EDITCONTROL | DT_WORD_ELLIPSIS | DT_PATH_ELLIPSIS)) ==
|
|
|
|
DT_EDITCONTROL)
|
|
|
|
{
|
|
|
|
/* break the word after the last character that fits (there must be
|
2014-06-13 10:01:22 +02:00
|
|
|
* at least one). */
|
|
|
|
if (!chars_fit)
|
|
|
|
++chars_fit;
|
2002-02-19 19:25:53 +01:00
|
|
|
*len_str = chars_fit;
|
|
|
|
*chars_used = chars_fit;
|
|
|
|
|
|
|
|
/* FIXME - possible error. Since the next character is now removed
|
|
|
|
* this could make the text longer so that it no longer fits, and
|
|
|
|
* so we need a loop to test and shrink.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
/* Otherwise */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* discard any trailing space. */
|
|
|
|
const WCHAR *e = str + *len_str;
|
|
|
|
p = str + chars_fit;
|
|
|
|
while (p < e && *p != SPACE)
|
|
|
|
p++;
|
|
|
|
*chars_used = p - str;
|
|
|
|
if (p < e) /* i.e. loop failed because *p == SPACE */
|
|
|
|
(*chars_used)++;
|
|
|
|
|
|
|
|
/* include the whole word; it may be ellipsified later */
|
|
|
|
*len_str = p - str;
|
|
|
|
/* Possible optimisation; if DT_WORD_ELLIPSIS only use chars_fit+1
|
|
|
|
* so that it will be too long
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Remeasure the string */
|
|
|
|
GetTextExtentExPointW (hdc, str, *len_str, 0, NULL, NULL, size);
|
2018-05-04 05:11:43 +02:00
|
|
|
heap_free(sla);
|
2002-02-19 19:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* TEXT_SkipChars
|
|
|
|
*
|
|
|
|
* Skip over the given number of characters, bearing in mind prefix
|
|
|
|
* substitution and the fact that a character may take more than one
|
|
|
|
* WCHAR (Unicode surrogates are two words long) (and there may have been
|
|
|
|
* a trailing &)
|
|
|
|
*
|
|
|
|
* Parameters
|
|
|
|
* new_count [out] The updated count
|
|
|
|
* new_str [out] The updated pointer
|
|
|
|
* start_count [in] The count of remaining characters corresponding to the
|
|
|
|
* start of the string
|
|
|
|
* start_str [in] The starting point of the string
|
|
|
|
* max [in] The number of characters actually in this segment of the
|
|
|
|
* string (the & counts)
|
|
|
|
* n [in] The number of characters to skip (if prefix then
|
|
|
|
* &c counts as one)
|
|
|
|
* prefix [in] Apply prefix substitution
|
|
|
|
*
|
|
|
|
* Return Values
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
* Remarks
|
|
|
|
* There must be at least n characters in the string
|
|
|
|
* We need max because the "line" may have ended with a & followed by a tab
|
|
|
|
* or newline etc. which we don't want to swallow
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void TEXT_SkipChars (int *new_count, const WCHAR **new_str,
|
|
|
|
int start_count, const WCHAR *start_str,
|
|
|
|
int max, int n, int prefix)
|
|
|
|
{
|
|
|
|
/* This is specific to wide characters, MSDN doesn't say anything much
|
|
|
|
* about Unicode surrogates yet and it isn't clear if _wcsinc will
|
|
|
|
* correctly handle them so we'll just do this the easy way for now
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (prefix)
|
|
|
|
{
|
|
|
|
const WCHAR *str_on_entry = start_str;
|
|
|
|
assert (max >= n);
|
|
|
|
max -= n;
|
|
|
|
while (n--)
|
2005-09-21 11:46:28 +02:00
|
|
|
{
|
2012-09-05 13:31:17 +02:00
|
|
|
if ((*start_str == PREFIX || *start_str == ALPHA_PREFIX) && max--)
|
2002-02-19 19:25:53 +01:00
|
|
|
start_str++;
|
2012-09-05 13:31:17 +02:00
|
|
|
start_str++;
|
2005-09-21 11:46:28 +02:00
|
|
|
}
|
2002-02-19 19:25:53 +01:00
|
|
|
start_count -= (start_str - str_on_entry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start_str += n;
|
|
|
|
start_count -= n;
|
|
|
|
}
|
|
|
|
*new_str = start_str;
|
|
|
|
*new_count = start_count;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 21:44:39 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* TEXT_Reprefix
|
|
|
|
*
|
|
|
|
* Reanalyse the text to find the prefixed character. This is called when
|
|
|
|
* wordbreaking or ellipsification has shortened the string such that the
|
|
|
|
* previously noted prefixed character is no longer visible.
|
|
|
|
*
|
|
|
|
* Parameters
|
|
|
|
* str [in] The original string segment (including all characters)
|
2002-03-11 02:15:31 +01:00
|
|
|
* ns [in] The number of characters in str (including prefixes)
|
|
|
|
* pe [in] The ellipsification data
|
2002-01-31 21:44:39 +01:00
|
|
|
*
|
|
|
|
* Return Values
|
|
|
|
* The prefix offset within the new string segment (the one that contains the
|
|
|
|
* ellipses and does not contain the prefix characters) (-1 if none)
|
|
|
|
*/
|
|
|
|
|
2002-03-11 02:15:31 +01:00
|
|
|
static int TEXT_Reprefix (const WCHAR *str, unsigned int ns,
|
|
|
|
const ellipsis_data *pe)
|
2002-01-31 21:44:39 +01:00
|
|
|
{
|
|
|
|
int result = -1;
|
2012-09-05 13:31:17 +02:00
|
|
|
unsigned int i;
|
2002-03-11 02:15:31 +01:00
|
|
|
unsigned int n = pe->before + pe->under + pe->after;
|
|
|
|
assert (n <= ns);
|
2012-09-05 13:31:17 +02:00
|
|
|
for (i = 0; i < n; i++, str++)
|
2002-01-31 21:44:39 +01:00
|
|
|
{
|
2002-03-11 02:15:31 +01:00
|
|
|
if (i == pe->before)
|
2002-01-31 21:44:39 +01:00
|
|
|
{
|
|
|
|
/* Reached the path ellipsis; jump over it */
|
2002-03-11 02:15:31 +01:00
|
|
|
if (ns < pe->under) break;
|
|
|
|
str += pe->under;
|
|
|
|
ns -= pe->under;
|
|
|
|
i += pe->under;
|
|
|
|
if (!pe->after) break; /* Nothing after the path ellipsis */
|
2002-01-31 21:44:39 +01:00
|
|
|
}
|
2002-03-11 02:15:31 +01:00
|
|
|
if (!ns) break;
|
|
|
|
ns--;
|
2012-09-05 13:31:17 +02:00
|
|
|
if (*str == PREFIX || *str == ALPHA_PREFIX)
|
2002-01-31 21:44:39 +01:00
|
|
|
{
|
2012-09-05 13:31:17 +02:00
|
|
|
str++;
|
2002-03-11 02:15:31 +01:00
|
|
|
if (!ns) break;
|
|
|
|
if (*str != PREFIX)
|
|
|
|
result = (i < pe->before || pe->under == 0) ? i : i - pe->under + pe->len;
|
|
|
|
/* pe->len may be non-zero while pe_under is zero */
|
|
|
|
ns--;
|
2002-01-31 21:44:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2001-12-17 22:37:53 +01:00
|
|
|
|
2002-02-21 21:07:26 +01:00
|
|
|
/*********************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* Returns true if and only if the remainder of the line is a single
|
2002-02-21 21:07:26 +01:00
|
|
|
* newline representation or nothing
|
|
|
|
*/
|
|
|
|
|
2013-09-27 08:43:21 +02:00
|
|
|
static BOOL remainder_is_none_or_newline (int num_chars, const WCHAR *str)
|
2002-02-21 21:07:26 +01:00
|
|
|
{
|
|
|
|
if (!num_chars) return TRUE;
|
|
|
|
if (*str != LF && *str != CR) return FALSE;
|
|
|
|
if (!--num_chars) return TRUE;
|
|
|
|
if (*str == *(str+1)) return FALSE;
|
|
|
|
str++;
|
|
|
|
if (*str != CR && *str != LF) return FALSE;
|
|
|
|
if (--num_chars) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-12-12 01:35:54 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* Return next line of text from a string.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-12-12 01:35:54 +01:00
|
|
|
* hdc - handle to DC.
|
|
|
|
* str - string to parse into lines.
|
|
|
|
* count - length of str.
|
|
|
|
* dest - destination in which to return line.
|
2001-01-20 03:16:52 +01:00
|
|
|
* len - dest buffer size in chars on input, copied length into dest on output.
|
2000-12-12 01:35:54 +01:00
|
|
|
* width - maximum width of line in pixels.
|
|
|
|
* format - format type passed to DrawText.
|
2002-02-19 19:25:53 +01:00
|
|
|
* retsize - returned size of the line in pixels.
|
2002-02-21 21:07:26 +01:00
|
|
|
* last_line - TRUE if is the last line that will be processed
|
|
|
|
* p_retstr - If DT_MODIFYSTRING this points to a cursor in the buffer in which
|
|
|
|
* the return string is built.
|
2002-03-11 02:15:31 +01:00
|
|
|
* tabwidth - The width of a tab in logical coordinates
|
|
|
|
* pprefix_offset - Here is where we return the offset within dest of the first
|
2002-06-01 01:06:46 +02:00
|
|
|
* prefixed (underlined) character. -1 is returned if there
|
2002-03-11 02:15:31 +01:00
|
|
|
* are none. Note that there may be more; the calling code
|
|
|
|
* will need to use TEXT_Reprefix to find any later ones.
|
|
|
|
* pellip - Here is where we return the information about any ellipsification
|
|
|
|
* that was carried out. Note that if tabs are being expanded then
|
|
|
|
* this data will correspond to the last text segment actually
|
2002-06-01 01:06:46 +02:00
|
|
|
* returned in dest; by definition there would not have been any
|
2002-03-11 02:15:31 +01:00
|
|
|
* ellipsification in earlier text segments of the line.
|
2000-12-12 01:35:54 +01:00
|
|
|
*
|
|
|
|
* Returns pointer to next char in str after end of the line
|
|
|
|
* or NULL if end of str reached.
|
|
|
|
*/
|
2000-12-11 04:39:08 +01:00
|
|
|
static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
|
2002-02-21 21:07:26 +01:00
|
|
|
WCHAR *dest, int *len, int width, DWORD format,
|
2018-05-09 10:23:26 +02:00
|
|
|
SIZE *retsize, int last_line, WCHAR *modstr,
|
2002-03-11 02:15:31 +01:00
|
|
|
int tabwidth, int *pprefix_offset,
|
|
|
|
ellipsis_data *pellip)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-02-12 19:40:36 +01:00
|
|
|
int i = 0, j = 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
int plen = 0;
|
|
|
|
SIZE size;
|
2001-01-20 03:16:52 +01:00
|
|
|
int maxl = *len;
|
2002-02-19 19:25:53 +01:00
|
|
|
int seg_i, seg_count, seg_j;
|
|
|
|
int max_seg_width;
|
|
|
|
int num_fit;
|
2013-09-27 08:43:21 +02:00
|
|
|
BOOL word_broken, line_fits, ellipsified;
|
2005-07-06 12:36:28 +02:00
|
|
|
unsigned int j_in_seg;
|
2002-03-22 01:12:15 +01:00
|
|
|
*pprefix_offset = -1;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2002-02-19 19:25:53 +01:00
|
|
|
/* For each text segment in the line */
|
|
|
|
|
|
|
|
retsize->cy = 0;
|
|
|
|
while (*count)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-02-19 19:25:53 +01:00
|
|
|
|
|
|
|
/* Skip any leading tabs */
|
|
|
|
|
|
|
|
if (str[i] == TAB && (format & DT_EXPANDTABS))
|
|
|
|
{
|
|
|
|
plen = ((plen/tabwidth)+1)*tabwidth;
|
|
|
|
(*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
|
|
|
|
while (*count && str[i] == TAB)
|
|
|
|
{
|
|
|
|
plen += tabwidth;
|
|
|
|
(*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Now copy as far as the next tab or cr/lf or eos */
|
|
|
|
|
|
|
|
seg_i = i;
|
|
|
|
seg_count = *count;
|
|
|
|
seg_j = j;
|
|
|
|
|
|
|
|
while (*count &&
|
|
|
|
(str[i] != TAB || !(format & DT_EXPANDTABS)) &&
|
|
|
|
((str[i] != CR && str[i] != LF) || (format & DT_SINGLELINE)))
|
|
|
|
{
|
2012-09-05 13:31:17 +02:00
|
|
|
if ((format & DT_NOPREFIX) || *count <= 1)
|
2002-02-19 19:25:53 +01:00
|
|
|
{
|
2012-09-05 13:31:17 +02:00
|
|
|
(*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str[i] == PREFIX || str[i] == ALPHA_PREFIX) {
|
2002-02-19 19:25:53 +01:00
|
|
|
(*count)--, i++; /* Throw away the prefix itself */
|
|
|
|
if (str[i] == PREFIX)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-02-19 19:25:53 +01:00
|
|
|
/* Swallow it before we see it again */
|
|
|
|
(*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2002-03-11 02:15:31 +01:00
|
|
|
else if (*pprefix_offset == -1 || *pprefix_offset >= seg_j)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-03-11 02:15:31 +01:00
|
|
|
*pprefix_offset = j;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2002-02-20 19:56:18 +01:00
|
|
|
/* else the previous prefix was in an earlier segment of the
|
|
|
|
* line; we will leave it to the drawing code to catch this
|
|
|
|
* one.
|
|
|
|
*/
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2012-09-05 13:31:17 +02:00
|
|
|
else if (str[i] == KANA_PREFIX)
|
|
|
|
{
|
|
|
|
/* Throw away katakana access keys */
|
|
|
|
(*count)--, i++; /* skip the prefix */
|
2019-04-05 21:03:57 +02:00
|
|
|
(*count)--; i++; /* skip the letter */
|
2012-09-05 13:31:17 +02:00
|
|
|
}
|
2002-02-19 19:25:53 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
(*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
|
2002-02-12 19:40:36 +01:00
|
|
|
}
|
2002-02-19 19:25:53 +01:00
|
|
|
}
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2002-02-21 21:07:26 +01:00
|
|
|
/* Measure the whole text segment and possibly WordBreak and
|
|
|
|
* ellipsify it
|
|
|
|
*/
|
2002-02-12 19:40:36 +01:00
|
|
|
|
2002-02-20 19:56:18 +01:00
|
|
|
j_in_seg = j - seg_j;
|
2002-02-19 19:25:53 +01:00
|
|
|
max_seg_width = width - plen;
|
2002-02-20 19:56:18 +01:00
|
|
|
GetTextExtentExPointW (hdc, dest + seg_j, j_in_seg, max_seg_width, &num_fit, NULL, &size);
|
2002-02-19 19:25:53 +01:00
|
|
|
|
2002-02-21 21:07:26 +01:00
|
|
|
/* The Microsoft handling of various combinations of formats is weird.
|
|
|
|
* The following may very easily be incorrect if several formats are
|
|
|
|
* combined, and may differ between versions (to say nothing of the
|
|
|
|
* several bugs in the Microsoft versions).
|
|
|
|
*/
|
2013-09-27 08:43:21 +02:00
|
|
|
word_broken = FALSE;
|
2002-02-20 19:56:18 +01:00
|
|
|
line_fits = (num_fit >= j_in_seg);
|
|
|
|
if (!line_fits && (format & DT_WORDBREAK))
|
2002-02-12 19:40:36 +01:00
|
|
|
{
|
2002-02-19 19:25:53 +01:00
|
|
|
const WCHAR *s;
|
2005-07-06 12:36:28 +02:00
|
|
|
unsigned int chars_used;
|
2002-02-19 19:25:53 +01:00
|
|
|
TEXT_WordBreak (hdc, dest+seg_j, maxl-seg_j, &j_in_seg,
|
|
|
|
max_seg_width, format, num_fit, &chars_used, &size);
|
2002-02-20 19:56:18 +01:00
|
|
|
line_fits = (size.cx <= max_seg_width);
|
2002-02-19 19:25:53 +01:00
|
|
|
/* and correct the counts */
|
|
|
|
TEXT_SkipChars (count, &s, seg_count, str+seg_i, i-seg_i,
|
|
|
|
chars_used, !(format & DT_NOPREFIX));
|
|
|
|
i = s - str;
|
2013-09-27 08:43:21 +02:00
|
|
|
word_broken = TRUE;
|
2002-02-12 19:40:36 +01:00
|
|
|
}
|
2002-03-11 02:15:31 +01:00
|
|
|
pellip->before = j_in_seg;
|
|
|
|
pellip->under = 0;
|
|
|
|
pellip->after = 0;
|
|
|
|
pellip->len = 0;
|
2013-09-27 08:43:21 +02:00
|
|
|
ellipsified = FALSE;
|
2002-02-21 21:07:26 +01:00
|
|
|
if (!line_fits && (format & DT_PATH_ELLIPSIS))
|
|
|
|
{
|
|
|
|
TEXT_PathEllipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg,
|
2018-05-09 10:23:26 +02:00
|
|
|
max_seg_width, &size, modstr, pellip);
|
2002-02-21 21:07:26 +01:00
|
|
|
line_fits = (size.cx <= max_seg_width);
|
2013-09-27 08:43:21 +02:00
|
|
|
ellipsified = TRUE;
|
2002-02-21 21:07:26 +01:00
|
|
|
}
|
|
|
|
/* NB we may end up ellipsifying a word-broken or path_ellipsified
|
|
|
|
* string */
|
|
|
|
if ((!line_fits && (format & DT_WORD_ELLIPSIS)) ||
|
2002-06-01 01:06:46 +02:00
|
|
|
((format & DT_END_ELLIPSIS) &&
|
2002-02-21 21:07:26 +01:00
|
|
|
((last_line && *count) ||
|
|
|
|
(remainder_is_none_or_newline (*count, &str[i]) && !line_fits))))
|
|
|
|
{
|
2002-03-11 02:15:31 +01:00
|
|
|
int before, len_ellipsis;
|
2002-02-21 21:07:26 +01:00
|
|
|
TEXT_Ellipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg,
|
2018-05-09 10:23:26 +02:00
|
|
|
max_seg_width, &size, modstr, &before, &len_ellipsis);
|
2002-03-11 02:15:31 +01:00
|
|
|
if (before > pellip->before)
|
2002-02-21 21:07:26 +01:00
|
|
|
{
|
|
|
|
/* We must have done a path ellipsis too */
|
2002-03-11 02:15:31 +01:00
|
|
|
pellip->after = before - pellip->before - pellip->len;
|
|
|
|
/* Leave the len as the length of the first ellipsis */
|
2002-02-21 21:07:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-03-11 02:15:31 +01:00
|
|
|
/* If we are here after a path ellipsification it must be
|
|
|
|
* because even the ellipsis itself didn't fit.
|
|
|
|
*/
|
|
|
|
assert (pellip->under == 0 && pellip->after == 0);
|
|
|
|
pellip->before = before;
|
|
|
|
pellip->len = len_ellipsis;
|
|
|
|
/* pellip->after remains as zero as does
|
|
|
|
* pellip->under
|
2002-02-21 21:07:26 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
ellipsified = 1;
|
|
|
|
}
|
|
|
|
/* As an optimisation if we have ellipsified and we are expanding
|
|
|
|
* tabs and we haven't reached the end of the line we can skip to it
|
|
|
|
* now rather than going around the loop again.
|
|
|
|
*/
|
|
|
|
if ((format & DT_EXPANDTABS) && ellipsified)
|
|
|
|
{
|
|
|
|
if (format & DT_SINGLELINE)
|
|
|
|
*count = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((*count) && str[i] != CR && str[i] != LF)
|
|
|
|
{
|
|
|
|
(*count)--, i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2002-02-20 19:56:18 +01:00
|
|
|
j = seg_j + j_in_seg;
|
2002-03-11 02:15:31 +01:00
|
|
|
if (*pprefix_offset >= seg_j + pellip->before)
|
2002-02-21 21:07:26 +01:00
|
|
|
{
|
2002-03-11 02:15:31 +01:00
|
|
|
*pprefix_offset = TEXT_Reprefix (str + seg_i, i - seg_i, pellip);
|
|
|
|
if (*pprefix_offset != -1)
|
|
|
|
*pprefix_offset += seg_j;
|
2002-02-21 21:07:26 +01:00
|
|
|
}
|
2002-02-20 19:56:18 +01:00
|
|
|
|
2002-02-19 19:25:53 +01:00
|
|
|
plen += size.cx;
|
|
|
|
if (size.cy > retsize->cy)
|
|
|
|
retsize->cy = size.cy;
|
|
|
|
|
|
|
|
if (word_broken)
|
|
|
|
break;
|
|
|
|
else if (!*count)
|
|
|
|
break;
|
|
|
|
else if (str[i] == CR || str[i] == LF)
|
|
|
|
{
|
2002-02-20 19:56:18 +01:00
|
|
|
(*count)--, i++;
|
|
|
|
if (*count && (str[i] == CR || str[i] == LF) && str[i] != str[i-1])
|
2002-02-19 19:25:53 +01:00
|
|
|
{
|
2002-02-20 19:56:18 +01:00
|
|
|
(*count)--, i++;
|
2002-02-19 19:25:53 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* else it was a Tab and we go around again */
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-02-19 19:25:53 +01:00
|
|
|
retsize->cx = plen;
|
2000-08-04 06:21:02 +02:00
|
|
|
*len = j;
|
2002-02-19 19:25:53 +01:00
|
|
|
if (*count)
|
|
|
|
return (&str[i]);
|
|
|
|
else
|
|
|
|
return NULL;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-29 03:46:09 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* TEXT_DrawUnderscore
|
|
|
|
*
|
|
|
|
* Draw the underline under the prefixed character
|
|
|
|
*
|
|
|
|
* Parameters
|
|
|
|
* hdc [in] The handle of the DC for drawing
|
|
|
|
* x [in] The x location of the line segment (logical coordinates)
|
|
|
|
* y [in] The y location of where the underscore should appear
|
|
|
|
* (logical coordinates)
|
|
|
|
* str [in] The text of the line segment
|
|
|
|
* offset [in] The offset of the underscored character within str
|
2003-06-04 22:21:21 +02:00
|
|
|
* rect [in] Clipping rectangle (if not NULL)
|
2002-01-29 03:46:09 +01:00
|
|
|
*/
|
|
|
|
|
2003-06-04 22:21:21 +02:00
|
|
|
static void TEXT_DrawUnderscore (HDC hdc, int x, int y, const WCHAR *str, int offset, const RECT *rect)
|
2002-01-29 03:46:09 +01:00
|
|
|
{
|
|
|
|
int prefix_x;
|
|
|
|
int prefix_end;
|
|
|
|
SIZE size;
|
|
|
|
HPEN hpen;
|
|
|
|
HPEN oldPen;
|
|
|
|
|
|
|
|
GetTextExtentPointW (hdc, str, offset, &size);
|
|
|
|
prefix_x = x + size.cx;
|
|
|
|
GetTextExtentPointW (hdc, str, offset+1, &size);
|
|
|
|
prefix_end = x + size.cx - 1;
|
|
|
|
/* The above method may eventually be slightly wrong due to kerning etc. */
|
|
|
|
|
2003-06-04 22:21:21 +02:00
|
|
|
/* Check for clipping */
|
|
|
|
if (rect){
|
|
|
|
if (prefix_x > rect->right || prefix_end < rect->left || y < rect->top || y > rect->bottom)
|
|
|
|
return; /* Completely outside */
|
|
|
|
/* Partially outside */
|
|
|
|
if (prefix_x < rect->left ) prefix_x = rect->left;
|
|
|
|
if (prefix_end > rect->right) prefix_end = rect->right;
|
|
|
|
}
|
|
|
|
|
2002-01-29 03:46:09 +01:00
|
|
|
hpen = CreatePen (PS_SOLID, 1, GetTextColor (hdc));
|
|
|
|
oldPen = SelectObject (hdc, hpen);
|
|
|
|
MoveToEx (hdc, prefix_x, y, NULL);
|
|
|
|
LineTo (hdc, prefix_end, y);
|
|
|
|
SelectObject (hdc, oldPen);
|
|
|
|
DeleteObject (hpen);
|
|
|
|
}
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* DrawTextExW (USER32.@)
|
2002-02-02 19:14:35 +01:00
|
|
|
*
|
|
|
|
* The documentation on the extra space required for DT_MODIFYSTRING at MSDN
|
|
|
|
* is not quite complete, especially with regard to \0. We will assume that
|
|
|
|
* the returned string could have a length of up to i_count+3 and also have
|
|
|
|
* a trailing \0 (which would be 4 more than a not-null-terminated string but
|
2002-06-01 01:06:46 +02:00
|
|
|
* 3 more than a null-terminated string). If this is not so then increase
|
2002-02-02 19:14:35 +01:00
|
|
|
* the allowance in DrawTextExA.
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2004-12-01 16:29:04 +01:00
|
|
|
#define MAX_BUFFER 1024
|
2001-07-26 22:10:40 +02:00
|
|
|
INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
|
|
|
|
LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
|
|
|
SIZE size;
|
2000-12-11 04:39:08 +01:00
|
|
|
const WCHAR *strPtr;
|
2018-05-09 10:23:26 +02:00
|
|
|
WCHAR *retstr;
|
2002-02-20 19:56:18 +01:00
|
|
|
size_t size_retstr;
|
2004-12-01 16:29:04 +01:00
|
|
|
WCHAR line[MAX_BUFFER];
|
2000-08-04 06:21:02 +02:00
|
|
|
int len, lh, count=i_count;
|
2000-12-11 04:39:08 +01:00
|
|
|
TEXTMETRICW tm;
|
2001-07-26 22:10:40 +02:00
|
|
|
int lmargin = 0, rmargin = 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
int x = rect->left, y = rect->top;
|
|
|
|
int width = rect->right - rect->left;
|
|
|
|
int max_width = 0;
|
2002-02-20 19:56:18 +01:00
|
|
|
int last_line;
|
2002-03-11 02:15:31 +01:00
|
|
|
int tabwidth /* to keep gcc happy */ = 0;
|
|
|
|
int prefix_offset;
|
|
|
|
ellipsis_data ellip;
|
2013-09-27 08:43:21 +02:00
|
|
|
BOOL invert_y=FALSE;
|
2018-05-04 05:12:06 +02:00
|
|
|
int ret = 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2004-11-30 18:21:16 +01:00
|
|
|
TRACE("%s, %d, [%s] %08x\n", debugstr_wn (str, count), count,
|
|
|
|
wine_dbgstr_rect(rect), flags);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2012-12-21 20:18:48 +01:00
|
|
|
if (dtp) TRACE("Params: iTabLength=%d, iLeftMargin=%d, iRightMargin=%d\n",
|
2001-07-26 22:10:40 +02:00
|
|
|
dtp->iTabLength, dtp->iLeftMargin, dtp->iRightMargin);
|
2000-12-11 04:39:08 +01:00
|
|
|
|
2008-10-13 17:51:52 +02:00
|
|
|
if (!str) return 0;
|
|
|
|
|
|
|
|
strPtr = str;
|
|
|
|
|
|
|
|
if (flags & DT_SINGLELINE)
|
|
|
|
flags &= ~DT_WORDBREAK;
|
|
|
|
|
|
|
|
GetTextMetricsW(hdc, &tm);
|
|
|
|
if (flags & DT_EXTERNALLEADING)
|
|
|
|
lh = tm.tmHeight + tm.tmExternalLeading;
|
|
|
|
else
|
|
|
|
lh = tm.tmHeight;
|
|
|
|
|
|
|
|
if (str[0] && count == 0)
|
|
|
|
return lh;
|
|
|
|
|
|
|
|
if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS))
|
|
|
|
return 0;
|
|
|
|
|
2006-01-27 15:47:15 +01:00
|
|
|
if (count == -1)
|
|
|
|
{
|
2020-09-21 13:53:21 +02:00
|
|
|
count = lstrlenW(str);
|
2006-01-27 15:47:15 +01:00
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
if( flags & DT_CALCRECT)
|
|
|
|
{
|
|
|
|
rect->right = rect->left;
|
2008-10-13 17:51:52 +02:00
|
|
|
if( flags & DT_SINGLELINE)
|
|
|
|
rect->bottom = rect->top + lh;
|
|
|
|
else
|
|
|
|
rect->bottom = rect->top;
|
2006-01-27 15:47:15 +01:00
|
|
|
}
|
2008-10-13 17:51:52 +02:00
|
|
|
return lh;
|
2006-01-27 15:47:15 +01:00
|
|
|
}
|
|
|
|
}
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2009-09-25 23:55:45 +02:00
|
|
|
if (GetGraphicsMode(hdc) == GM_COMPATIBLE)
|
|
|
|
{
|
|
|
|
SIZE window_ext, viewport_ext;
|
|
|
|
GetWindowExtEx(hdc, &window_ext);
|
|
|
|
GetViewportExtEx(hdc, &viewport_ext);
|
|
|
|
if ((window_ext.cy > 0) != (viewport_ext.cy > 0))
|
2013-09-27 08:43:21 +02:00
|
|
|
invert_y = TRUE;
|
2009-09-25 23:55:45 +02:00
|
|
|
}
|
|
|
|
|
2001-07-26 22:10:40 +02:00
|
|
|
if (dtp)
|
|
|
|
{
|
2009-02-02 19:47:00 +01:00
|
|
|
lmargin = dtp->iLeftMargin;
|
|
|
|
rmargin = dtp->iRightMargin;
|
2018-06-04 13:58:07 +02:00
|
|
|
width -= lmargin + rmargin;
|
2001-07-26 22:10:40 +02:00
|
|
|
if (!(flags & (DT_CENTER | DT_RIGHT)))
|
|
|
|
x += lmargin;
|
|
|
|
dtp->uiLengthDrawn = 0; /* This param RECEIVES number of chars processed */
|
|
|
|
}
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
if (flags & DT_EXPANDTABS)
|
|
|
|
{
|
2016-03-02 05:22:10 +01:00
|
|
|
int tabstop = ((flags & DT_TABSTOP) && dtp && dtp->iTabLength) ? dtp->iTabLength : 8;
|
2002-02-12 19:40:36 +01:00
|
|
|
tabwidth = tm.tmAveCharWidth * tabstop;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
|
|
|
|
|
2002-02-20 19:56:18 +01:00
|
|
|
if (flags & DT_MODIFYSTRING)
|
|
|
|
{
|
|
|
|
size_retstr = (count + 4) * sizeof (WCHAR);
|
2018-05-04 05:11:43 +02:00
|
|
|
retstr = heap_alloc(size_retstr);
|
2002-02-20 19:56:18 +01:00
|
|
|
if (!retstr) return 0;
|
|
|
|
memcpy (retstr, str, size_retstr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_retstr = 0;
|
|
|
|
retstr = NULL;
|
|
|
|
}
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
do
|
|
|
|
{
|
2018-04-01 22:20:49 +02:00
|
|
|
len = ARRAY_SIZE(line);
|
2009-09-25 23:55:45 +02:00
|
|
|
if (invert_y)
|
|
|
|
last_line = !(flags & DT_NOCLIP) && y - ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) < rect->bottom;
|
|
|
|
else
|
|
|
|
last_line = !(flags & DT_NOCLIP) && y + ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) > rect->bottom;
|
2018-05-09 10:23:26 +02:00
|
|
|
strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags, &size, last_line, retstr, tabwidth, &prefix_offset, &ellip);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2018-06-04 13:58:07 +02:00
|
|
|
if (flags & DT_CENTER)
|
|
|
|
x = (rect->left + lmargin + rect->right - rmargin - size.cx) / 2;
|
|
|
|
else if (flags & DT_RIGHT)
|
|
|
|
x = rect->right - size.cx - rmargin;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
|
|
|
if (flags & DT_SINGLELINE)
|
|
|
|
{
|
2001-07-26 22:10:40 +02:00
|
|
|
if (flags & DT_VCENTER) y = rect->top +
|
2000-08-04 06:21:02 +02:00
|
|
|
(rect->bottom - rect->top) / 2 - size.cy / 2;
|
|
|
|
else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
|
2002-01-18 19:09:09 +01:00
|
|
|
}
|
2000-09-23 00:09:11 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
if (!(flags & DT_CALCRECT))
|
|
|
|
{
|
2002-02-12 19:40:36 +01:00
|
|
|
const WCHAR *str = line;
|
|
|
|
int xseg = x;
|
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
int len_seg;
|
|
|
|
SIZE size;
|
|
|
|
if ((flags & DT_EXPANDTABS))
|
|
|
|
{
|
|
|
|
const WCHAR *p;
|
|
|
|
p = str; while (p < str+len && *p != TAB) p++;
|
|
|
|
len_seg = p - str;
|
2018-05-04 05:12:06 +02:00
|
|
|
if (len_seg != len && !GetTextExtentPointW(hdc, str, len_seg, &size)) goto done;
|
2002-02-12 19:40:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
len_seg = len;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-02-12 19:40:36 +01:00
|
|
|
if (!ExtTextOutW( hdc, xseg, y,
|
|
|
|
((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) |
|
|
|
|
((flags & DT_RTLREADING) ? ETO_RTLREADING : 0),
|
2012-10-30 15:03:05 +01:00
|
|
|
rect, str, len_seg, NULL ))
|
2018-05-04 05:12:06 +02:00
|
|
|
goto done;
|
2002-02-12 19:40:36 +01:00
|
|
|
if (prefix_offset != -1 && prefix_offset < len_seg)
|
|
|
|
{
|
2003-06-04 22:21:21 +02:00
|
|
|
TEXT_DrawUnderscore (hdc, xseg, y + tm.tmAscent + 1, str, prefix_offset, (flags & DT_NOCLIP) ? NULL : rect);
|
2002-02-12 19:40:36 +01:00
|
|
|
}
|
|
|
|
len -= len_seg;
|
|
|
|
str += len_seg;
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
assert ((flags & DT_EXPANDTABS) && *str == TAB);
|
2002-06-01 01:06:46 +02:00
|
|
|
len--; str++;
|
2002-02-12 19:40:36 +01:00
|
|
|
xseg += ((size.cx/tabwidth)+1)*tabwidth;
|
|
|
|
if (prefix_offset != -1)
|
|
|
|
{
|
|
|
|
if (prefix_offset < len_seg)
|
|
|
|
{
|
|
|
|
/* We have just drawn an underscore; we ought to
|
|
|
|
* figure out where the next one is. I am going
|
|
|
|
* to leave it for now until I have a better model
|
2002-03-11 02:15:31 +01:00
|
|
|
* for the line, which will make reprefixing easier.
|
|
|
|
* This is where ellip would be used.
|
2002-02-12 19:40:36 +01:00
|
|
|
*/
|
|
|
|
prefix_offset = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prefix_offset -= len_seg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
else if (size.cx > max_width)
|
|
|
|
max_width = size.cx;
|
|
|
|
|
2009-09-25 23:55:45 +02:00
|
|
|
if (invert_y)
|
|
|
|
y -= lh;
|
|
|
|
else
|
|
|
|
y += lh;
|
2001-07-26 22:10:40 +02:00
|
|
|
if (dtp)
|
|
|
|
dtp->uiLengthDrawn += len;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2002-02-20 19:56:18 +01:00
|
|
|
while (strPtr && !last_line);
|
2001-07-26 22:10:40 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
if (flags & DT_CALCRECT)
|
|
|
|
{
|
|
|
|
rect->right = rect->left + max_width;
|
|
|
|
rect->bottom = y;
|
2001-07-26 22:10:40 +02:00
|
|
|
if (dtp)
|
|
|
|
rect->right += lmargin + rmargin;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2018-05-04 05:12:06 +02:00
|
|
|
|
|
|
|
if (retstr) memcpy(str, retstr, size_retstr);
|
|
|
|
|
|
|
|
ret = y - rect->top;
|
2018-06-04 13:54:16 +02:00
|
|
|
if (ret == 0) ret = 1;
|
2018-05-04 05:12:06 +02:00
|
|
|
done:
|
|
|
|
heap_free(retstr);
|
|
|
|
return ret;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
2000-12-11 04:39:08 +01:00
|
|
|
/***********************************************************************
|
2001-07-26 22:10:40 +02:00
|
|
|
* DrawTextExA (USER32.@)
|
2002-02-02 19:14:35 +01:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* If DT_MODIFYSTRING is specified then there must be room for up to
|
2002-02-02 19:14:35 +01:00
|
|
|
* 4 extra characters. We take great care about just how much modified
|
|
|
|
* string we return.
|
2000-12-11 04:39:08 +01:00
|
|
|
*/
|
2001-07-26 22:10:40 +02:00
|
|
|
INT WINAPI DrawTextExA( HDC hdc, LPSTR str, INT count,
|
|
|
|
LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
|
2000-12-11 04:39:08 +01:00
|
|
|
{
|
|
|
|
WCHAR *wstr;
|
2002-02-02 19:14:35 +01:00
|
|
|
WCHAR *p;
|
2000-12-11 04:39:08 +01:00
|
|
|
INT ret = 0;
|
2002-02-02 19:14:35 +01:00
|
|
|
int i;
|
2000-12-11 04:39:08 +01:00
|
|
|
DWORD wcount;
|
2002-02-02 19:14:35 +01:00
|
|
|
DWORD wmax;
|
|
|
|
DWORD amax;
|
2007-03-26 22:58:20 +02:00
|
|
|
UINT cp;
|
2000-12-11 04:39:08 +01:00
|
|
|
|
|
|
|
if (!count) return 0;
|
2008-10-13 17:51:52 +02:00
|
|
|
if (!str && count > 0) return 0;
|
2006-01-27 15:47:15 +01:00
|
|
|
if( !str || ((count == -1) && !(count = strlen(str))))
|
|
|
|
{
|
2008-10-13 17:51:52 +02:00
|
|
|
int lh;
|
|
|
|
TEXTMETRICA tm;
|
|
|
|
|
|
|
|
if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
GetTextMetricsA(hdc, &tm);
|
|
|
|
if (flags & DT_EXTERNALLEADING)
|
|
|
|
lh = tm.tmHeight + tm.tmExternalLeading;
|
|
|
|
else
|
|
|
|
lh = tm.tmHeight;
|
|
|
|
|
2006-01-27 15:47:15 +01:00
|
|
|
if( flags & DT_CALCRECT)
|
|
|
|
{
|
|
|
|
rect->right = rect->left;
|
2008-10-13 17:51:52 +02:00
|
|
|
if( flags & DT_SINGLELINE)
|
|
|
|
rect->bottom = rect->top + lh;
|
|
|
|
else
|
|
|
|
rect->bottom = rect->top;
|
2006-01-27 15:47:15 +01:00
|
|
|
}
|
2008-10-13 17:51:52 +02:00
|
|
|
return lh;
|
2006-01-27 15:47:15 +01:00
|
|
|
}
|
2007-03-26 22:58:20 +02:00
|
|
|
cp = GdiGetCodePage( hdc );
|
|
|
|
wcount = MultiByteToWideChar( cp, 0, str, count, NULL, 0 );
|
2002-02-02 19:14:35 +01:00
|
|
|
wmax = wcount;
|
|
|
|
amax = count;
|
|
|
|
if (flags & DT_MODIFYSTRING)
|
|
|
|
{
|
|
|
|
wmax += 4;
|
|
|
|
amax += 4;
|
|
|
|
}
|
2018-05-04 05:11:43 +02:00
|
|
|
wstr = heap_alloc(wmax * sizeof(WCHAR));
|
2000-12-11 04:39:08 +01:00
|
|
|
if (wstr)
|
|
|
|
{
|
2007-03-26 22:58:20 +02:00
|
|
|
MultiByteToWideChar( cp, 0, str, count, wstr, wcount );
|
2002-02-02 19:14:35 +01:00
|
|
|
if (flags & DT_MODIFYSTRING)
|
|
|
|
for (i=4, p=wstr+wcount; i--; p++) *p=0xFFFE;
|
|
|
|
/* Initialise the extra characters so that we can see which ones
|
|
|
|
* change. U+FFFE is guaranteed to be not a unicode character and
|
|
|
|
* so will not be generated by DrawTextEx itself.
|
|
|
|
*/
|
2003-12-13 04:25:57 +01:00
|
|
|
ret = DrawTextExW( hdc, wstr, wcount, rect, flags, dtp );
|
2001-07-26 22:10:40 +02:00
|
|
|
if (flags & DT_MODIFYSTRING)
|
2002-02-02 19:14:35 +01:00
|
|
|
{
|
|
|
|
/* Unfortunately the returned string may contain multiple \0s
|
|
|
|
* and so we need to measure it ourselves.
|
|
|
|
*/
|
|
|
|
for (i=4, p=wstr+wcount; i-- && *p != 0xFFFE; p++) wcount++;
|
2007-03-26 22:58:20 +02:00
|
|
|
WideCharToMultiByte( cp, 0, wstr, wcount, str, amax, NULL, NULL );
|
2002-02-02 19:14:35 +01:00
|
|
|
}
|
2018-05-04 05:11:43 +02:00
|
|
|
heap_free(wstr);
|
2000-12-11 04:39:08 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2000-08-04 06:21:02 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* DrawTextW (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2001-07-26 22:10:40 +02:00
|
|
|
INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-01-15 21:29:35 +01:00
|
|
|
DRAWTEXTPARAMS dtp;
|
|
|
|
|
|
|
|
memset (&dtp, 0, sizeof(dtp));
|
2008-10-13 15:30:55 +02:00
|
|
|
dtp.cbSize = sizeof(dtp);
|
2002-01-15 21:29:35 +01:00
|
|
|
if (flags & DT_TABSTOP)
|
|
|
|
{
|
2006-11-09 15:39:58 +01:00
|
|
|
dtp.iTabLength = (flags >> 8) & 0xff;
|
2002-01-15 21:29:35 +01:00
|
|
|
flags &= 0xffff00ff;
|
|
|
|
}
|
|
|
|
return DrawTextExW(hdc, (LPWSTR)str, count, rect, flags, &dtp);
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-26 22:10:40 +02:00
|
|
|
* DrawTextA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2001-07-26 22:10:40 +02:00
|
|
|
INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count, LPRECT rect, UINT flags )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-01-15 21:29:35 +01:00
|
|
|
DRAWTEXTPARAMS dtp;
|
|
|
|
|
|
|
|
memset (&dtp, 0, sizeof(dtp));
|
2008-10-13 15:30:55 +02:00
|
|
|
dtp.cbSize = sizeof(dtp);
|
2002-01-15 21:29:35 +01:00
|
|
|
if (flags & DT_TABSTOP)
|
|
|
|
{
|
2006-11-09 15:39:58 +01:00
|
|
|
dtp.iTabLength = (flags >> 8) & 0xff;
|
2002-01-15 21:29:35 +01:00
|
|
|
flags &= 0xffff00ff;
|
|
|
|
}
|
|
|
|
return DrawTextExA( hdc, (LPSTR)str, count, rect, flags, &dtp );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* GrayString functions
|
|
|
|
*/
|
|
|
|
|
2002-11-22 21:41:17 +01:00
|
|
|
/* callback for ASCII gray string proc */
|
|
|
|
static BOOL CALLBACK gray_string_callbackA( HDC hdc, LPARAM param, INT len )
|
2002-01-15 21:29:35 +01:00
|
|
|
{
|
2002-11-22 21:41:17 +01:00
|
|
|
return TextOutA( hdc, 0, 0, (LPCSTR)param, len );
|
|
|
|
}
|
2002-01-15 21:29:35 +01:00
|
|
|
|
2002-11-22 21:41:17 +01:00
|
|
|
/* callback for Unicode gray string proc */
|
|
|
|
static BOOL CALLBACK gray_string_callbackW( HDC hdc, LPARAM param, INT len )
|
2002-01-15 21:29:35 +01:00
|
|
|
{
|
2002-11-22 21:41:17 +01:00
|
|
|
return TextOutW( hdc, 0, 0, (LPCWSTR)param, len );
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* TEXT_GrayString
|
|
|
|
*/
|
|
|
|
static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, GRAYSTRINGPROC fn, LPARAM lp, INT len,
|
2002-11-22 21:41:17 +01:00
|
|
|
INT x, INT y, INT cx, INT cy )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
|
|
|
HBITMAP hbm, hbmsave;
|
|
|
|
HBRUSH hbsave;
|
|
|
|
HFONT hfsave;
|
2002-01-04 22:26:56 +01:00
|
|
|
HDC memdc;
|
2000-08-04 06:21:02 +02:00
|
|
|
int slen = len;
|
2015-11-06 05:00:42 +01:00
|
|
|
BOOL retval;
|
2000-08-04 06:21:02 +02:00
|
|
|
COLORREF fg, bg;
|
|
|
|
|
|
|
|
if(!hdc) return FALSE;
|
2002-01-04 22:26:56 +01:00
|
|
|
if (!(memdc = CreateCompatibleDC(hdc))) return FALSE;
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
hbm = CreateBitmap(cx, cy, 1, 1, NULL);
|
2008-10-25 23:39:12 +02:00
|
|
|
hbmsave = SelectObject(memdc, hbm);
|
2000-08-04 06:21:02 +02:00
|
|
|
hbsave = SelectObject( memdc, GetStockObject(BLACK_BRUSH) );
|
|
|
|
PatBlt( memdc, 0, 0, cx, cy, PATCOPY );
|
|
|
|
SelectObject( memdc, hbsave );
|
|
|
|
SetTextColor(memdc, RGB(255, 255, 255));
|
|
|
|
SetBkColor(memdc, RGB(0, 0, 0));
|
2008-10-25 23:39:12 +02:00
|
|
|
hfsave = SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
|
2000-12-12 01:35:54 +01:00
|
|
|
|
2002-11-22 21:41:17 +01:00
|
|
|
retval = fn(memdc, lp, slen);
|
2000-08-04 06:21:02 +02:00
|
|
|
SelectObject(memdc, hfsave);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Windows doc says that the bitmap isn't grayed when len == -1 and
|
|
|
|
* the callback function returns FALSE. However, testing this on
|
|
|
|
* win95 showed otherwise...
|
|
|
|
*/
|
|
|
|
#ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
|
|
|
|
if(retval || len != -1)
|
|
|
|
#endif
|
|
|
|
{
|
2013-10-16 16:07:53 +02:00
|
|
|
hbsave = SelectObject(memdc, SYSCOLOR_Get55AABrush());
|
2000-08-04 06:21:02 +02:00
|
|
|
PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
|
|
|
|
SelectObject(memdc, hbsave);
|
|
|
|
}
|
|
|
|
|
2008-10-25 23:39:12 +02:00
|
|
|
if(hb) hbsave = SelectObject(hdc, hb);
|
2000-08-04 06:21:02 +02:00
|
|
|
fg = SetTextColor(hdc, RGB(0, 0, 0));
|
|
|
|
bg = SetBkColor(hdc, RGB(255, 255, 255));
|
|
|
|
BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
|
|
|
|
SetTextColor(hdc, fg);
|
|
|
|
SetBkColor(hdc, bg);
|
|
|
|
if(hb) SelectObject(hdc, hbsave);
|
|
|
|
|
|
|
|
SelectObject(memdc, hbmsave);
|
|
|
|
DeleteObject(hbm);
|
|
|
|
DeleteDC(memdc);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* GrayStringA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
|
2000-12-12 01:35:54 +01:00
|
|
|
LPARAM lParam, INT cch, INT x, INT y,
|
|
|
|
INT cx, INT cy )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-11-22 21:41:17 +01:00
|
|
|
if (!cch) cch = strlen( (LPCSTR)lParam );
|
|
|
|
if ((cx == 0 || cy == 0) && cch != -1)
|
|
|
|
{
|
|
|
|
SIZE s;
|
|
|
|
GetTextExtentPoint32A( hdc, (LPCSTR)lParam, cch, &s );
|
|
|
|
if (cx == 0) cx = s.cx;
|
|
|
|
if (cy == 0) cy = s.cy;
|
|
|
|
}
|
|
|
|
if (!gsprc) gsprc = gray_string_callbackA;
|
|
|
|
return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy );
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* GrayStringW (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
|
2000-12-12 01:35:54 +01:00
|
|
|
LPARAM lParam, INT cch, INT x, INT y,
|
|
|
|
INT cx, INT cy )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2020-09-21 13:53:21 +02:00
|
|
|
if (!cch) cch = lstrlenW( (LPCWSTR)lParam );
|
2002-11-22 21:41:17 +01:00
|
|
|
if ((cx == 0 || cy == 0) && cch != -1)
|
|
|
|
{
|
|
|
|
SIZE s;
|
|
|
|
GetTextExtentPoint32W( hdc, (LPCWSTR)lParam, cch, &s );
|
|
|
|
if (cx == 0) cx = s.cx;
|
|
|
|
if (cy == 0) cy = s.cy;
|
|
|
|
}
|
|
|
|
if (!gsprc) gsprc = gray_string_callbackW;
|
|
|
|
return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy );
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
2002-01-15 21:29:35 +01:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* TEXT_TabbedTextOut
|
|
|
|
*
|
|
|
|
* Helper function for TabbedTextOut() and GetTabbedTextExtent().
|
|
|
|
* Note: this doesn't work too well for text-alignment modes other
|
|
|
|
* than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
|
|
|
|
*/
|
2002-11-22 21:41:17 +01:00
|
|
|
static LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCWSTR lpstr,
|
|
|
|
INT count, INT cTabStops, const INT *lpTabPos, INT nTabOrg,
|
2000-08-04 06:21:02 +02:00
|
|
|
BOOL fDisplayText )
|
|
|
|
{
|
|
|
|
INT defWidth;
|
|
|
|
SIZE extent;
|
2005-10-26 12:04:21 +02:00
|
|
|
int i, j;
|
2000-08-04 06:21:02 +02:00
|
|
|
int start = x;
|
2015-11-13 21:52:10 +01:00
|
|
|
TEXTMETRICW tm;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2011-04-23 13:36:12 +02:00
|
|
|
if (!lpstr || count == 0) return 0;
|
|
|
|
|
2003-01-31 04:23:18 +01:00
|
|
|
if (!lpTabPos)
|
|
|
|
cTabStops=0;
|
|
|
|
|
2015-11-13 21:52:10 +01:00
|
|
|
GetTextMetricsW( hdc, &tm );
|
|
|
|
|
2005-10-26 12:04:21 +02:00
|
|
|
if (cTabStops == 1)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-11-22 21:41:17 +01:00
|
|
|
defWidth = *lpTabPos;
|
2000-08-04 06:21:02 +02:00
|
|
|
cTabStops = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defWidth = 8 * tm.tmAveCharWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (count > 0)
|
|
|
|
{
|
2005-10-26 12:04:21 +02:00
|
|
|
RECT r;
|
|
|
|
INT x0;
|
|
|
|
x0 = x;
|
|
|
|
r.left = x0;
|
|
|
|
/* chop the string into substrings of 0 or more <tabs>
|
|
|
|
* possibly followed by 1 or more normal characters */
|
2000-08-04 06:21:02 +02:00
|
|
|
for (i = 0; i < count; i++)
|
2005-10-26 12:04:21 +02:00
|
|
|
if (lpstr[i] != '\t') break;
|
|
|
|
for (j = i; j < count; j++)
|
|
|
|
if (lpstr[j] == '\t') break;
|
|
|
|
/* get the extent of the normal character part */
|
|
|
|
GetTextExtentPointW( hdc, lpstr + i, j - i , &extent );
|
|
|
|
/* and if there is a <tab>, calculate its position */
|
|
|
|
if( i) {
|
2005-07-12 20:11:26 +02:00
|
|
|
/* get x coordinate for the drawing of this string */
|
2007-05-02 20:30:43 +02:00
|
|
|
for (; cTabStops >= i; lpTabPos++, cTabStops--)
|
2005-07-12 20:11:26 +02:00
|
|
|
{
|
2005-10-26 12:04:21 +02:00
|
|
|
if( nTabOrg + abs( *lpTabPos) > x) {
|
|
|
|
if( lpTabPos[ i - 1] >= 0) {
|
|
|
|
/* a left aligned tab */
|
2007-05-02 20:30:43 +02:00
|
|
|
x0 = nTabOrg + lpTabPos[i-1];
|
|
|
|
x = x0 + extent.cx;
|
2005-07-12 20:11:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-10-26 12:04:21 +02:00
|
|
|
else
|
2005-07-12 20:11:26 +02:00
|
|
|
{
|
2005-10-26 12:04:21 +02:00
|
|
|
/* if tab pos is negative then text is right-aligned
|
|
|
|
* to tab stop meaning that the string extends to the
|
|
|
|
* left, so we must subtract the width of the string */
|
|
|
|
if (nTabOrg - lpTabPos[ i - 1] - extent.cx > x)
|
|
|
|
{
|
|
|
|
x = nTabOrg - lpTabPos[ i - 1];
|
|
|
|
x0 = x - extent.cx;
|
|
|
|
break;
|
|
|
|
}
|
2005-07-12 20:11:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if we have run out of tab stops and we have a valid default tab
|
|
|
|
* stop width then round x up to that width */
|
2007-05-02 20:30:43 +02:00
|
|
|
if ((cTabStops < i) && (defWidth > 0)) {
|
2005-10-26 12:04:21 +02:00
|
|
|
x0 = nTabOrg + ((x - nTabOrg) / defWidth + i) * defWidth;
|
|
|
|
x = x0 + extent.cx;
|
2007-05-02 20:30:43 +02:00
|
|
|
} else if ((cTabStops < i) && (defWidth < 0)) {
|
2005-10-26 12:04:21 +02:00
|
|
|
x = nTabOrg + ((x - nTabOrg + extent.cx) / -defWidth + i)
|
|
|
|
* -defWidth;
|
|
|
|
x0 = x - extent.cx;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
x += extent.cx;
|
2018-10-08 13:20:36 +02:00
|
|
|
|
|
|
|
if (!extent.cy) extent.cy = tm.tmHeight;
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
if (fDisplayText)
|
|
|
|
{
|
|
|
|
r.top = y;
|
2005-10-26 12:04:21 +02:00
|
|
|
r.right = x;
|
2000-08-04 06:21:02 +02:00
|
|
|
r.bottom = y + extent.cy;
|
2005-10-26 12:04:21 +02:00
|
|
|
ExtTextOutW( hdc, x0, y, GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
|
|
|
|
&r, lpstr + i, j - i, NULL );
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2005-10-26 12:04:21 +02:00
|
|
|
count -= j;
|
|
|
|
lpstr += j;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2015-11-13 21:52:10 +01:00
|
|
|
|
2005-07-12 20:11:26 +02:00
|
|
|
return MAKELONG(x - start, extent.cy);
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* TabbedTextOutA (USER32.@)
|
2005-07-12 20:11:26 +02:00
|
|
|
*
|
|
|
|
* See TabbedTextOutW.
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2000-12-12 01:35:54 +01:00
|
|
|
LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr, INT count,
|
|
|
|
INT cTabStops, const INT *lpTabPos, INT nTabOrg )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-11-22 21:41:17 +01:00
|
|
|
LONG ret;
|
|
|
|
DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 );
|
2018-05-04 05:11:43 +02:00
|
|
|
LPWSTR strW = heap_alloc( len * sizeof(WCHAR) );
|
2002-11-22 21:41:17 +01:00
|
|
|
if (!strW) return 0;
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len );
|
|
|
|
ret = TabbedTextOutW( hdc, x, y, strW, len, cTabStops, lpTabPos, nTabOrg );
|
2018-05-04 05:11:43 +02:00
|
|
|
heap_free( strW );
|
2002-11-22 21:41:17 +01:00
|
|
|
return ret;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* TabbedTextOutW (USER32.@)
|
2005-07-12 20:11:26 +02:00
|
|
|
*
|
|
|
|
* Draws tabbed text aligned using the specified tab stops.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hdc [I] Handle to device context to draw to.
|
|
|
|
* x [I] X co-ordinate to start drawing the text at in logical units.
|
|
|
|
* y [I] Y co-ordinate to start drawing the text at in logical units.
|
|
|
|
* str [I] Pointer to the characters to draw.
|
|
|
|
* count [I] Number of WCHARs pointed to by str.
|
|
|
|
* cTabStops [I] Number of tab stops pointed to by lpTabPos.
|
|
|
|
* lpTabPos [I] Tab stops in logical units. Should be sorted in ascending order.
|
|
|
|
* nTabOrg [I] Starting position to expand tabs from in logical units.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The dimensions of the string drawn. The height is in the high-order word
|
|
|
|
* and the width is in the low-order word.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The tabs stops can be negative, in which case the text is right aligned to
|
|
|
|
* that tab stop and, despite what MSDN says, this is supported on
|
|
|
|
* Windows XP SP2.
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* MSDN says that the TA_UPDATECP from GetTextAlign causes this function to
|
|
|
|
* ignore the x and y co-ordinates, but this is unimplemented at the moment.
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2000-12-12 01:35:54 +01:00
|
|
|
LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str, INT count,
|
|
|
|
INT cTabStops, const INT *lpTabPos, INT nTabOrg )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-11-22 22:22:14 +01:00
|
|
|
TRACE("%p %d,%d %s %d\n", hdc, x, y, debugstr_wn(str,count), count );
|
2002-11-22 21:41:17 +01:00
|
|
|
return TEXT_TabbedTextOut( hdc, x, y, str, count, cTabStops, lpTabPos, nTabOrg, TRUE );
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* GetTabbedTextExtentA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2000-12-12 01:35:54 +01:00
|
|
|
DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
|
|
|
|
INT cTabStops, const INT *lpTabPos )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-11-22 21:41:17 +01:00
|
|
|
LONG ret;
|
|
|
|
DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 );
|
2018-05-04 05:11:43 +02:00
|
|
|
LPWSTR strW = heap_alloc( len * sizeof(WCHAR) );
|
2002-11-22 21:41:17 +01:00
|
|
|
if (!strW) return 0;
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len );
|
|
|
|
ret = GetTabbedTextExtentW( hdc, strW, len, cTabStops, lpTabPos );
|
2018-05-04 05:11:43 +02:00
|
|
|
heap_free( strW );
|
2002-11-22 21:41:17 +01:00
|
|
|
return ret;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* GetTabbedTextExtentW (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2000-12-12 01:35:54 +01:00
|
|
|
DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
|
|
|
|
INT cTabStops, const INT *lpTabPos )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2002-11-22 22:22:14 +01:00
|
|
|
TRACE("%p %s %d\n", hdc, debugstr_wn(lpstr,count), count );
|
2002-11-22 21:41:17 +01:00
|
|
|
return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops, lpTabPos, 0, FALSE );
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|