glenn@bitstream.com (Glenn P. Parker) (06/11/91)
In article <JEFF.91Jun11074934@dude.meaddata.com> jeff@meaddata.com (Jeff French) writes: > What I can't figure out is how to specify 'helpFile' in my .Xdefaults. > The only thing that has worked so far is: > > *helpFile: file1.hlp This will also work: resource*helpFile: file1.hlp > Unfortunately, different classes will have different help files. I > have tried all of the following, but received nil back from > GetAttribute(): > > resource*base*derived*helpFile: file2.hlp > *base*derived*helpFile: file3.hlp > *derived*helpFile: file4.hlp 1. The GetAttribute function only recognizes the Interactor hierarchy, NOT the class hierarchy, so "base*derived" will not do what you expected (it implies a derived inside a base). 2. The GetAttribute ONLY recognizes the Interactor hierarchy during the Reconfig pass, so you can't use it willy-nilly whenever you want. 3. Outside of the Reconfig pass, GetAttribute still recognizes resources at the "top" level, like the one that worked and the one I suggested. To adapt to these restrictions, you would have to fetch the resource within your Reconfig function and save it for later (make a copy). Then your .Xdefaults file should look like: resource*derived.helpFile: file1.hlp If you can't adapt to these restrictions, you could try this: class derived : public base { public: derived(char *m) : base(m) {SetClassName("derived");} const char *get(); }; const char* derived::get() { const char* classname = GetClassName(); static const char suffix[] = "_helpfile"; char* attrname = new char[strlen(classname) + sizeof(suffix)]; strcpy(attrname, classname); strcat(attrname, suffix); const char* attrvalue = GetAttribute(attrname); delete attrname; return attrvalue; } Then put this in your .Xdefaults: resource*derived_helpfile: file1.hlp Not too pretty, I know. -- Glenn P. Parker glenn@bitstream.com Bitstream, Inc. uunet!huxley!glenn 215 First Street BIX: parker Cambridge, MA 02142-1270
J.K.Wight@newcastle.ac.uk (Jim Wight) (06/11/91)
jeff@meaddata.com (Jeff French) writes > Hi folks. I am using IV2.6 and have what I hope is an easy question > about specifying resources in .Xdefaults and accessing them by > GetAttribute(). [code deleted] > What I can't figure out is how to specify 'helpFile' in my .Xdefaults. > The only thing that has worked so far is: > > *helpFile: file1.hlp The manual page for Interactor states that unless GetAttribute is called from Reconfig the context is only the top-level class and instance. Thus prog -xrm "resource.helpFile:file1.hlp" and prog -xrm "prog.helpFile:file1.hlp" both work. It also explains why only *helpFile:file1.hlp of your examples worked. If you redefine Reconfig for your base class and call GetAttribute from within that routine then you will be able to specify helpFile differently for different classes. I rewrote your "base" class thus class base : public Message { public: base(char *m) : Message(m) {SetClassName("base");} void Reconfig() {Message::Reconfig(); printf("%s\n", GetAttribute("helpFile"));} }; and the correct value was printed out from this command prog -xrm "*derived.helpFile:file1.hlp" The resources for other derived classes would be specified similarly. Jim