[comp.windows.x.motif] Multi-line labels

ems@socrates.JPL.NASA.gov (Eric Slimko) (08/21/90)

   Is it possible to create multi-line labels
through the resource file?  XmStringCreateLtoR
does the job correctly in the program, but I'd rather
have the label set in the resourse file.

If you could do me the favor of a personal reply,
I would appreciate it.

Thanks,

Eric Slimko		  |  Jet Propulsion Laboratories
ems@socrates.jpl.nasa.gov |  NASA/CalTech

david@jpl-devvax.JPL.NASA.GOV (David E. Smyth) (09/21/90)

ems@socrates.jpl.nasa.gov writes:
>
>   Is it possible to create multi-line labels
>through the resource file?  XmStringCreateLtoR
>does the job correctly in the program, but I'd rather
>have the label set in the resourse file.

Write a string to XmString converter which looks for \n.
Simple, really.  
Use the same name that Motif uses, and make sure the
linker sees your converter before it sees the Motif
converter, and you are golden.  Do a name search on
your motf library to figure out the name you should
export.

-------------------------------------------------------------------------
David Smyth				david@jpl-devvax.jpl.nasa.gov
Senior Software Engineer,		seismo!cit-vax!jpl-devvax!david
X and Object Guru.			(818)393-0983
Jet Propulsion Lab, M/S 230-103, 4800 Oak Grove Drive, Pasadena, CA 91109
------------------------------------------------------------------------- 
Life is tough: vacation in the South Pacific, work in Southern California!
-------------------------------------------------------------------------

ks@bat.gsfc.nasa.gov (SSUID Ken Sall) (09/22/90)

To: motif@alphalpha.com uunet!ucsd.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!
david
Subject: Re: Multi-line labels

ems@socrates.jpl.nasa.gov writes:
>
>   Is it possible to create multi-line labels
>through the resource file?  XmStringCreateLtoR
>does the job correctly in the program, but I'd rather
>have the label set in the resourse file.

david@jpl-devvax.jpl.nasa.gov writes:
>>Write a string to XmString converter which looks for \n.

===================================================================
Have you tried:

        *Label*labelString:             Here\nis\nthe\nLabel

This works fine for me (results in 4-line label).


Ken Sall ( ks@cen.com   ks@elk.gsfc.nasa.gov )
Century Computing, Inc.
Laurel, MD 20707
(301) 953-3330

TAE Plus project
under contract to:
NASA Goddard Space Flight Center
OSF Member

brennan@rtp.dg.com (Dave Brennan) (10/11/90)

david@jpl-devvax.JPL.NASA.GOV (David E. Smyth) writes:

   ems@socrates.jpl.nasa.gov writes:

   >   Is it possible to create multi-line labels
   >through the resource file?

   Write a string to XmString converter which looks for \n.
   Use the same name that Motif uses, and make sure the
   linker sees your converter before it sees the Motif
   converter, and you are golden.  Do a name search on
   your motf library to figure out the name you should
   export.

Actually, you don't have to go to all that trouble.  The following code
replaces the String to XmString converter so you can use \n in resources.
Just call MuInstallStringToXmStringConverter (yea, it's a long name, so sue
me! :-) before you create your first Motif widget.  (After you create the
toplevel shell would be a good time.)

/*
 *  by David Brennan (brennan@dg-rtp.dg.com)
 *
 *  This code is provided without warranty.
 */

#include <Xm/Xm.h>

static void
mu_cvt_string_to_xmstring ( XrmValuePtr args, Cardinal *num_args,
			      XrmValue *from, XrmValue *to )
{
  static char *new_string;

  if ( from->addr == NULL ) return;

  new_string = XmStringCreateLtoR ( from->addr, XmSTRING_DEFAULT_CHARSET );

  if ( new_string == NULL ) 
    {
      to->addr = NULL;
      to->size = 0;
      XtStringConversionWarning ( from->addr, XmRXmString );
    }
  else
    {
      to->addr = (caddr_t) &new_string;
      to->size = sizeof (caddr_t);
    }
}

void
MuInstallStringToXmStringConverter (void)
{
  /* first register Motif converters so that this ours don't get overridden */

  XmRegisterConverters ();

  /* now registers ours and override Motif's */

  XtAddConverter ( XmRString, XmRXmString, mu_cvt_string_to_xmstring, 
		   NULL, 0 );
}
                                          |\
Dave Brennan                              | \____oo_     brennan@rtp.dg.com
=========================================((__|  /___>    ...rti!dg-rtp!brennan
User Interfaces, Data General                | //        daveb@rpitsmts.bitnet
Research Triangle Park, NC                   |//         Phone: (919) 248-6330