Re: Is this program totally daft, or can you help me getting it to work? - Motif

This is a discussion on Re: Is this program totally daft, or can you help me getting it to work? - Motif ; The callback is incorrect. Currently it tries to create a new label widget as a child of "Form", which is invalid because it is not initialized. What (I think) you want to do is change the text string of the ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Re: Is this program totally daft, or can you help me getting it to work?

  1. Re: Is this program totally daft, or can you help me getting it to work?

    The callback is incorrect. Currently it tries to create a new label widget as
    a child of "Form", which is invalid because it is not initialized. What (I
    think) you want to do is change the text string of the existing pushbutton
    widget.

    You probably want something like:

    XmString s = XmStringCreateLocalized("something");
    XtVaSetValues(w, XmNlabelString, s, NULL);
    XmStringFree(s);

  2. Re: Is this program totally daft, or can you help me getting it to work?

    Eirik wrote:
    >
    > On Mon, 04 Aug 2003 14:55:05 +0000, Scott J. Tringali wrote:
    >
    > > The callback is incorrect. Currently it tries to create a new label widget as
    > > a child of "Form", which is invalid because it is not initialized. What (I
    > > think) you want to do is change the text string of the existing pushbutton
    > > widget.
    > >
    > > You probably want something like:
    > >
    > > XmString s = XmStringCreateLocalized("something");
    > > XtVaSetValues(w, XmNlabelString, s, NULL);
    > > XmStringFree(s);

    >
    > How can I change another widget than the one from which the function is
    > called(w)?


    There are several ways to do this, including:

    - Global variables

    - If you want the parent widget, you can use XtParent(w); if you want the
    widget's children, you can get the XmNchildren and XmNnumChildren resources,
    and so on.

    - Use the client_data field in XtAddCallback() -- either cast it to a Widget,
    or create a struct with whatever contents and make it a pointer to that struct

    - Use the XmNuserData resource in the widget

    - Use XtNameToWidget() to get a widget by name

    Btw, you also called XtVaAppInitialize() with too few arguments. You need a
    final NULL argument to terminate the (empty) vararg list. And it's kinda bad
    form (ouch) to call your top level widget "Form" -- as it's not a Form widget,
    but an ApplicationShell widget.

    --
    Per Espen Hagen, Principal Scientist
    Norwegian Defence Research Establishment

  3. Re: Is this program totally daft, or can you help me getting it to work?

    Eirik wrote:
    >> - Global variables
    >>
    >> - If you want the parent widget, you can use XtParent(w); if you
    >> want the widget's children, you can get the XmNchildren and
    >> XmNnumChildren resources, and so on.
    >>
    >> - Use the client_data field in XtAddCallback() -- either cast it to
    >> a Widget, or create a struct with whatever contents and make it a
    >> pointer to that struct
    >>
    >> - Use the XmNuserData resource in the widget
    >>
    >> - Use XtNameToWidget() to get a widget by name

    >
    > Could you give me some examples?


    There are plenty of Motif code examples available on the Net; from tiny toys
    to big applications like Netscape and DDD. You can find links to many of
    them on e.g. lesstif.org. Read a good book or two (Antony Fountain et al.'s
    "Motif Programming Manual" and "Motif Reference Manual" can be downloaded as
    PDFs), learn to use the man pages. Read the entire Motif FAQ. Judging from
    the newbie C bugs in the code you posted, you may have quite a bit to learn.

    Btw, if you are the same Eirik who wrote to me by mail after my last
    posting: Use a valid email From/Reply-To address if you want a reply :-)

    --
    Per Espen Hagen
    To answer by mail, remove one "c" from the address



  4. Re: Is this program totally daft, or can you help me getting it to work?

    On Sat, 16 Aug 2003 12:12:25 +0200, Per Espen Hagen wrote:

    > Eirik wrote:
    >>> - Global variables

    #include
    #include

    const Widget x;

    void endra();
    int main(int argc, char *argv[])
    {
    Widget Topp = XtInitialize(argv[0], "", NULL, 0, &argc, argv);
    x = XtCreateManagedWidget("", xmPushButtonWidgetClass, Topp, NULL, 0);
    XtVaSetValues(x, XmNlabelString, XmStringCreateLocalized("Text2"), NULL);
    XtAddCallback(x, XmNactivateCallback, endra, NULL);
    /* Yes! Endeleg! Eg er eit perfekt menneske! */
    XtRealizeWidget(Topp);
    XtMainLoop();
    return 0;
    }

    void endra()
    {
    XmString TExt = XmStringCreateLocalized("Text");
    XtVaSetValues(x, XmNlabelString, TExt, NULL);
    XmStringFree(TExt);
    }

    The only problem with this code is that gcc says:
    test2.c:11 :warning: assignment of read-only variable 'x'
    Maybe this is an issue more suitable for comp.lang.c.

    Thank you for all helpful(and not so helpful) replies.

  5. Re: Is this program totally daft, or can you help me getting it to work?

    Eirik wrote in message news:...
    > On Sat, 16 Aug 2003 12:12:25 +0200, Per Espen Hagen wrote:
    >
    > > Eirik wrote:
    > >>> - Global variables

    > #include
    > #include
    >
    > const Widget x;
    >
    > void endra();
    > int main(int argc, char *argv[])
    > {
    > Widget Topp = XtInitialize(argv[0], "", NULL, 0, &argc, argv);
    > x = XtCreateManagedWidget("", xmPushButtonWidgetClass, Topp, NULL, 0);
    > XtVaSetValues(x, XmNlabelString, XmStringCreateLocalized("Text2"), NULL);
    > XtAddCallback(x, XmNactivateCallback, endra, NULL);
    > /* Yes! Endeleg! Eg er eit perfekt menneske! */
    > XtRealizeWidget(Topp);
    > XtMainLoop();
    > return 0;
    > }
    >
    > void endra()
    > {
    > XmString TExt = XmStringCreateLocalized("Text");
    > XtVaSetValues(x, XmNlabelString, TExt, NULL);
    > XmStringFree(TExt);
    > }
    >
    > The only problem with this code is that gcc says:
    > test2.c:11 :warning: assignment of read-only variable 'x'


    Replace

    const Widget x;

    by

    static Widget x;

    you can not assign values to a const.

    > Maybe this is an issue more suitable for comp.lang.c.


    No, get this book:

    http://cm.bell-labs.com/cm/cs/cbook

    --- Casantos

+ Reply to Thread