Using X resources

For better colours and fonts, try inserting these X defaults into your .Xdefaults file. [Note that in wxWidgets 2 for Motif, colours are governed by wxSystemSettings rather than by X resources. Eventually these hard-wired values will be customizable.]

Here's an older message about X defaults:

Hermann Himmelbauer wrote:
> 
> Hello,
> I would like to change the appearance of my wxWidgets-application
> under Motif (wxText Background Colour, wxText Fonts etc.)
> I would like to handle this with a XResource-file -
> I'd either write it in the .Xdefaults File or put a File in the
> app-defaults directory. The problem is that I do not know how this
> file should be called and what I should insert in it...

The best place to put the resource file is in /usr/lib/X11/app-defaults.
The name of the file is the same as the class name of the application
(as returned by wxApp::GetClassName()). By default the classname is
the same as the application name, but you can override wxApp::GetClassName()
to return your own class name. The normal X convention is for the class
name to be the same as the application name but with the first letter in
upper case e.g. myapp would have a class name of Myapp. The class name can be
used to group together the resources for a family of applications in a single
file e.g. myapp and anotherapp might share the class name MyAppSuite and the
resources would be stored in the file:

/usr/lib/X11/app-defaults/MyAppSuite.

> Can anyone please send me an example of such a Resource file or just
> tell me a location where I could find such a sample?

There are two approaches you could take for setting resources:

1) Identify the resource names of each element of each Motif Widget that
   you wish to change and define the appropriate resource value.
   This is very tedious and generally involves much trial and error.

2) Specify your own resource values and query them using wxGetResource
   and then set the appropriate wx attributes.
   e.g. to set the button colour of a dialog by resource
app-defaults file entry:
*MyDialog.ButtonColour: BLUE

Code:
    char* value;
    if (wxGetResource("MyDialog", "ButtonColour", &value))
    {
        wxColour colour(value);
        dialog->SetButtonColour(colour);
    }

> Where could I by the way find more information about XResource Files?

The O'Reilly manuals give a huge amount of information:
Vol 1: Xlib Programming Manual
Vol 2: Xlib Reference Manual
...
Vol 6: Motif Programming Manual
etc.
Publisher: O'Reilly & Associates, Inc.

Regards,
Chris
-- 
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
/ Chris Breeze, Software Engineer                                    /
/ chris@hel.co.uk        Hitachi Europe Limited, Maidenhead, England /
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/

Here's a more recent mailing on this topic:

To: wxwin-users@wx.dent.med.uni-muenchen.DE
Subject: Re: Widget Style 
Date: Thu, 18 Jun 1998 08:34:34 -0400
From: Curtis Jamison 

Hi All -

This thread is developing a distinct SGI flavor. Windows95 folks might
want to bail out now ;-)

I've already gone through the exercise of setting up my .Xdefaults file
to get rid of that hideous blue that shows up on the SGI, so I thought
I'd run a check on my system (an O2 with Irix 6.3 using wxWidgets 1.68)
and see what Tom's two commands do for me. What I found was what a
geneticist would call incomplete penetrance: Some of the widgets were
well-behaved, and some ignored the global color commands.

First, I commented out all changes I'd made for my application, then I
systematically added items to the .Xdefaults file to see what the
reaction was. Of the two commands, '*useschemes: all' has the most effect
on wxWidgets. The main window and dialogs all used my chosen scheme for
the most part. The big exception was wxMenubar, which didn't use the
SGI menu font, while wxMenu does, thus giving a rather odd look with 12pt
courier in the menubar and 10pt helvetica bold italic in the menus below.

The schemes seemed to have no effect upon subwindows, which showed up in
the blue Motif-default color scheme (including the menu).

'*SGImode: True' seemed to have absolutely no effect on any behaviors.

With some help from Julian, I've generated a set of .Xdefault commands
which pretty much controls everything about wxWidgets which I'm using
in my application thus far:

	! Tasteful colors for wxWidgets
	*foreground:    black
	*background:    gray
	*MenuBar*background:    gray
	*popup*background:      gray
	*pulldown*background:   gray
	*panel*background:      gray
	*file_selector*background:      gray
	*panelBorder*background:        gray
	*textWindow*background: white
	*client*background:     gray
	*MenuBar*fontList:      -*-helvetica-*-r-*--12-*-*-*-*-*-*-*
	
	! Undo the color change in exmh background so I can see mail
	*exmh*background: gray90

An item of note is the *background filter, which is necessary to catch
the backgrounds in dialog boxes. If you have other app backgrounds which
use .Xdefaults (like my exmh mail reader) you'll need to specifically 
over-ride the background for them if the generic background color isn't
suitable (eg., I couldn't see my mailbox listings since the exmh mailbox
font is also gray). BTW, chucking '*useschemes: all' in with this mix gives
the same psychodelic 60's set of mismatched displays, except now the
subwindows use the new colors and fonts.

It seems to me the failure point is here the inheritance of display
parameters. wxWidgets seems to assume that it can read the .Xdefaults file
for every subwindow, while the SGI Xserver assumes that it only needs to
pass scheme information to an application once. I tried SGI's rapidapp
code generator for an early prototype of my application, and there was a
good deal of code which passed display parameters from parent to child.
This is a good deal more like MS Windows than traditional X.

It is unclear to me how much of this issue is SGI specific as opposed to
Motif specific. I'll be interested to see how 2.0 handles this. In the
long run however, I think the loss of SGI schemes and the inconvenience
of .Xdefault settings is far outweighed by the cross-platform compilation.
I'm already planning on including a script which will allow the user to
set up a color scheme.

Curt
-- 
Curtis Jamison			

Genome Technology Branch
National Human Genome Research Institute
National Institutes of Health

Voice: (301) 402 0202
email: cjamison@nhgri.nih.gov
--

runge@egd.igd.fhg.de said:
> borbor@cs.cityu.edu.hk wrote:
> > 
> > Hi Tom,
> > 
> > I have tried your suggestion, but it still doesn't work. I don't know
> > why. I just think when I write the program using the Motif function
> > calls directly, the program will appears in SGI-style.
> 
> No, they won't. You need these app-defaults. Wx is just a
> wrapper for all used "native" widgetsets. So, there is no
> difference in handling the motif-widgets, whether you use
> motif directly or via wx.
> You should verify, if your app really got your changes in
> the app-defs. I found the mechanism a little bit confusing.
> Please try "xrdb -query". If you get no output at all, the
> apps will use ~/.Xdefaults and you can change the values
> just by editing this file. If you get some, you have to edit
> it and do an "xrdb ~/.Xdefaults".
> To be very sure that your app gets your changes, you should
> try this:
> - add *SGImode: True
>   and *useSchemes: all
>   to your ~/.Xdefaults
> - "xrdb ~/.Xdefaults"
> - start your app (or try any other motif-app).
> That really should work, at least it does on my machine.
> 
> Good luck ;-)
> 
> -- 
> Tom
> 

To: wxwin-users@wx.dent.med.uni-muenchen.DE
Subject: Re: Widget Style (SGI schemes)
Date: Thu, 18 Jun 1998 13:55:39 -0400
From: Curtis Jamison 


Once more for this thread...

After a lot of fiddling, I've managed a work-around for the SGI widget
style/schemes problem.

First of all, I partly wrong about the *SGImode flag not doing anything.
It turns out that statement is case-sensitive. So while '*SGImode: True'
really doesn't do anything, '*sgiMode: TRUE' actually does make the widgets
appear as IRIS IM widgets.

Second, it appears that new wxFrames are treated as partially anonymous
entities, and thus don't pick the scheme colors, since only named top-level
classes get the scheme propagated to them. Plus, you can't control them
directly via the ~/.Xdefaults file, since the name doesn't show. Setting
global names is dangerous, since all your X programs will inherit them, as
I pointed out previoiusly.

As a workaround, SGI has a xrdb default file registry. If you place a
xrdb file into /usr/lib/X11/app-defaults/, your program will
use that instead of the local .Xdefaults. Better yet, globals named in
this file do not affect other X apps. In this file, if you turn schemes on,
then you can reference the default values for the colors, and assign them as 
globals to be used throughout the execution of your program.

For example, here is the program I'm working on:

	>more /usr/lib/X11/app-defaults/STSclient_motif 

	*sgiMode: TRUE
	*useSchemes: all

	*fontList:              SGI_DYNAMIC PlainLabelFont
	*MenuBar*fontList:      SGI_DYNAMIC ObliqueLabelFont
	*background:            SGI_DYNAMIC BasicBackground
	*textWindow*background: SGI_DYNAMIC TextBackground

	>

This picks up my Vancouver color scheme, and then propogates the background
colors to subsequent wxFrames. All the variables can be defined in this
manner. Mappings for scheme color variables can be found in the "Indigo Magic
Desktop Integration Guide" which should be in your on-line books or somewhere
on the http:

The downside of this method is the fact that you have to have root access to
install files into the /usr/lib/X11/app-defaults directory. As I said before,
I intend to make an install script which will try to put this file there.

Another possible method is to use the SgiUseSchemes() method found in the
X11/SGIScheme.h library. This is also detailed in the Integration Guide. I
suppose one could use use a conditional compilation to include this in non-
platform specific code, but I didn't want to work that hard at this :>

Hope this helps (and didn't bore too many people).

Curt
-- 
Curtis Jamison			

Genome Technology Branch
National Human Genome Research Institute
National Institutes of Health

Voice: (301) 402 0202
email: cjamison@nhgri.nih.gov