[comp.windows.x] Querying the resource database for a child's "requested" resources?

gnb@bby.oz.au (Gregory N. Bond) (04/11/91)

Consider a subclass of a constraint widget that has three children
that are created in the parent widget initialize routine.  The three
children are all the same class, but for one of them I want a
different default value for a constraint resource.  (i.e. I want
children 1 and 2 to have "dislpayed: true" and child three to have
"displayed: false" as the default, where displayed is a constraint
resource).

I also want the resource database to be able to override the default,
as you would expect.

The default value for the displayed resource is true, so I don't need
anr args to the create call and children 1 and 2 work as expected -
they are normally displayed but the user can turn them off.  How can I
specify the different default constraint resource for the third child?
If I specify it as an arg to the XtCreateManagedWidget() call, it
overrides the resource database and the user cannot change the
setting.

What I think I need is a way of asking the resource database what the
user wants for the displayed resource of the as-yet non-existant child
before calling XtCreateManagedWidget(), and set the resource to false
with an arglist if either the user hasn't specified or false is what
they want.

Is that clear?

Greg.
--
Gregory Bond, Burdett Buckeridge & Young Ltd, Melbourne, Australia
Internet: gnb@melba.bby.oz.au    non-MX: gnb%melba.bby.oz@uunet.uu.net
Uucp: {uunet,pyramid,ubc-cs,ukc,mcvax,prlb2,nttlab...}!munnari!melba.bby.oz!gnb

aw@jello.bae.bellcore.com (Andrew Wason) (04/13/91)

In article <GNB.91Apr11174058@leo.bby.oz.au>, gnb@bby.oz.au (Gregory N. Bond) writes:
> Consider a subclass of a constraint widget that has three children
> that are created in the parent widget initialize routine.  The three
> children are all the same class, but for one of them I want a
> different default value for a constraint resource.  (i.e. I want
> children 1 and 2 to have "dislpayed: true" and child three to have
> "displayed: false" as the default, where displayed is a constraint
> resource).
> 
> I also want the resource database to be able to override the default,
> as you would expect.
> 
> The default value for the displayed resource is true, so I don't need
> anr args to the create call and children 1 and 2 work as expected -
> they are normally displayed but the user can turn them off.  How can I
> specify the different default constraint resource for the third child?
> If I specify it as an arg to the XtCreateManagedWidget() call, it
> overrides the resource database and the user cannot change the
> setting.

I think you can do this by using XtGetSubresources for
the display resource on widget three.

Create a struct to hold the value of the XtNdisplay resource.
Create a new XtResourceList with one entry for your XtNdisplay resource,
but with default_addr set to False (instead of the normal default of True).
(assume widgets 1,2,3 are of class "Display", class pointer
displayWidgetClass).

  typedef struct {
      Boolean display;
  } ThreeDisplayStruct;
  ThreeDisplayStruct threeDisplay;
  XtResource displayResource[] = {
      { XtNdisplay, XtCDisplay, XtRBoolean, sizeof(Boolean),
        XtOffsetOf(ThreeDisplayStruct, display),
        XtRImmediate, (XtPointer)False }
  };

Now call XtGetSubresources to fetch this resource for your widget
(parent is the constraint parent).

  XtGetSubresources(parent, (caddr_t)&threeDisplay,
                    "three", "Display",
                    displayResource, XtNumber(displayResource),
                    NULL, 0);

Now create your widget using the XtNdisplay resource you just fetched.

  three = XtVaCreateManagedWidget("three",
                                  displayWidgetClass, parent,
                                  XtNdisplay, threeDisplay.display,
                                  NULL);


This would be even simpler if XtNdisplay wasn't a constraint
resource (call it XtNnewDisplay), you could create the widget
first and then refetch the XtNnewDisplay resource directly into the
widget instance record.

  three = XtCreateManagedWidget("three",
                                displayWidgetClass, parent,
                                NULL, 0);
  XtGetSubresources(three, (caddr_t)&three,
                    NULL, NULL,
                    &resources[5], 1,
                    NULL, 0);

Where resources[5] is the entry for XtNnewDisplay in widget threes
resource list (don't try this for callback resources though).


I haven't actually tried any of this, but I think it will work.
Let me know if you try it.


Andrew

_______________________________________________________________________________

Andrew Wason                                       Bell Communications Research
aw@bae.bellcore.com                                Piscataway, NJ
bellcore!bae!aw