зеркало из https://github.com/mozilla/pjs.git
Trim down formatItem. Some of the function isn't used and hasn't been for a long time.
This commit is contained in:
Родитель
8d6bb44abc
Коммит
a43aa88aef
|
@ -1518,8 +1518,7 @@ XFE_RDFMenuToolbarBase::entryToXmString(HT_Resource entry,
|
|||
char * psz;
|
||||
|
||||
tmp = XFE_RDFMenuToolbarBase::formatItem(entry,
|
||||
True,
|
||||
INTL_DefaultWinCharSetID(NULL));
|
||||
INTL_DefaultWinCharSetID(NULL));
|
||||
|
||||
// Mid truncate the name
|
||||
if (XmStringGetLtoR(tmp,XmSTRING_DEFAULT_CHARSET,&psz))
|
||||
|
@ -1546,133 +1545,62 @@ XFE_RDFMenuToolbarBase::entryToXmString(HT_Resource entry,
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
XmString
|
||||
XFE_RDFMenuToolbarBase::formatItem(HT_Resource entry,
|
||||
Boolean no_indent,
|
||||
int16 charset)
|
||||
int16 charset)
|
||||
{
|
||||
XmString xmhead, xmtail, xmcombo;
|
||||
int depth = (no_indent ? 0 : HT_GetItemIndentation(entry));
|
||||
char head [255];
|
||||
XmString xmstring;
|
||||
char buf [1024];
|
||||
int j = 0;
|
||||
char *title = HT_GetNodeName(entry);
|
||||
char *name = HT_GetNodeName(entry);
|
||||
char *url = HT_GetNodeURL(entry);
|
||||
int indent = 2;
|
||||
int left_offset = 2;
|
||||
XmFontList font_list;
|
||||
|
||||
if (! no_indent)
|
||||
{
|
||||
head [j++] = (HT_IsContainer(entry)
|
||||
? (HT_IsContainerOpen(entry) ? '-' : '+') :
|
||||
HT_IsSeparator(entry) ? ' ' :
|
||||
/* ### item->last_visit == 0*/ 0 ? '?' : ' ');
|
||||
while (j < ((depth * indent) + left_offset))
|
||||
head [j++] = ' ';
|
||||
}
|
||||
head [j] = 0;
|
||||
|
||||
if (HT_IsSeparator(entry))
|
||||
{
|
||||
strcpy (buf, "-------------------------");
|
||||
}
|
||||
else if (title || url)
|
||||
else if (name || url)
|
||||
{
|
||||
fe_FormatDocTitle (title, url, buf, 1024);
|
||||
fe_FormatDocTitle (name, url, buf, 1024);
|
||||
}
|
||||
#if 0
|
||||
#if CAN_HAVE_EMPTY_URL_ENTRIES
|
||||
else if (HT_IsUrl(entry))
|
||||
{
|
||||
// It is a url entry with no url or title. Very strange.
|
||||
// The rdf backend currently disallows this.
|
||||
strcpy (buf, XP_GetString( XFE_GG_EMPTY_LL ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!*head)
|
||||
xmhead = 0;
|
||||
else
|
||||
xmhead = XmStringSegmentCreate (head, "ICON", XmSTRING_DIRECTION_L_TO_R,
|
||||
False);
|
||||
|
||||
if (!*buf)
|
||||
xmtail = 0;
|
||||
else if (title || url)
|
||||
xmtail = fe_ConvertToXmString ((unsigned char *) buf, charset,
|
||||
NULL, XmFONT_IS_FONT, &font_list);
|
||||
{
|
||||
xmstring = 0;
|
||||
}
|
||||
else if (name || url)
|
||||
{
|
||||
xmstring = fe_ConvertToXmString ((unsigned char *) buf, charset,
|
||||
NULL, XmFONT_IS_FONT, &font_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
char *loc;
|
||||
|
||||
loc = (char *) fe_ConvertToLocaleEncoding (charset,
|
||||
(unsigned char *) buf);
|
||||
xmtail = XmStringSegmentCreate (loc, "HEADING",
|
||||
XmSTRING_DIRECTION_L_TO_R, False);
|
||||
xmstring = XmStringSegmentCreate (loc, "HEADING",
|
||||
XmSTRING_DIRECTION_L_TO_R, False);
|
||||
if (loc != buf)
|
||||
{
|
||||
XP_FREE(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (xmhead && xmtail)
|
||||
{
|
||||
int size = XmStringLength (xmtail);
|
||||
|
||||
/*
|
||||
There is a bug down under XmStringNConcat() where, in the process of
|
||||
appending the two strings, it will read up to four bytes past the end
|
||||
of the second string. It doesn't do anything with the data it reads
|
||||
from there, but people have been regularly crashing as a result of it,
|
||||
because sometimes these strings end up at the end of the page!!
|
||||
|
||||
I tried making the second string a bit longer (by adding some spaces
|
||||
to the end of `buf') and passing in a correspondingly smaller length
|
||||
to XmStringNConcat(), but that causes it not to append *any* of the
|
||||
characters in the second string. So XmStringNConcat() would seem to
|
||||
simply not work at all when the length isn't exactly the same as the
|
||||
length of the second string.
|
||||
|
||||
Plan B is to simply realloc() the XmString to make it a bit larger,
|
||||
so that we know that it's safe to go off the end.
|
||||
|
||||
The NULLs at the beginning of the data we append probably aren't
|
||||
necessary, but they are read and parsed as a length, even though the
|
||||
data is not used (with the current structure of the XmStringNConcat()
|
||||
code.) (The initialization of this memory is only necessary at all
|
||||
to keep Purify from (rightly) squawking about it.)
|
||||
|
||||
And oh, by the way, the strncpy() down there, which I have verified
|
||||
is doing strncpy( <the-right-place> , <the-string-below>, 15 )
|
||||
actually writes 15 \000 bytes instead of four \000 bytes plus the
|
||||
random text below. So I seem to have stumbled across a bug in
|
||||
strncpy() as well, even though it doesn't hose me. THIS TIME. -- jwz
|
||||
*/
|
||||
#define MOTIF_BUG_BUFFER "\000\000\000\000 MOTIF BUG"
|
||||
#ifdef MOTIF_BUG_BUFFER
|
||||
xmtail = (XmString) realloc ((void *) xmtail,
|
||||
size + sizeof (MOTIF_BUG_BUFFER));
|
||||
strncpy (((char *) xmtail) + size, MOTIF_BUG_BUFFER,
|
||||
sizeof (MOTIF_BUG_BUFFER));
|
||||
# undef MOTIF_BUG_BUFFER
|
||||
#endif /* MOTIF_BUG_BUFFER */
|
||||
|
||||
xmcombo = XmStringNConcat (xmhead, xmtail, size);
|
||||
}
|
||||
else if (xmhead)
|
||||
{
|
||||
xmcombo = xmhead;
|
||||
xmhead = 0;
|
||||
}
|
||||
else if (xmtail)
|
||||
{
|
||||
xmcombo = xmtail;
|
||||
xmtail = 0;
|
||||
}
|
||||
if (xmstring)
|
||||
{
|
||||
return (xmstring);
|
||||
}
|
||||
else
|
||||
{
|
||||
xmcombo = XmStringCreateLtoR ("", XmFONTLIST_DEFAULT_TAG);
|
||||
}
|
||||
|
||||
if (xmhead) XmStringFree (xmhead);
|
||||
if (xmtail) XmStringFree (xmtail);
|
||||
return (xmcombo);
|
||||
{
|
||||
return XmStringCreateLtoR ("", XmFONTLIST_DEFAULT_TAG);
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
|
|
|
@ -240,7 +240,6 @@ private:
|
|||
|
||||
// Format item blah blah blah
|
||||
static XmString formatItem (HT_Resource entry,
|
||||
Boolean no_indent,
|
||||
int16 charset);
|
||||
|
||||
// Obtain an internationallized XmString from an entry
|
||||
|
|
Загрузка…
Ссылка в новой задаче