Re: passing Widget variables as arguments



Qzectb wrote:
I'm new to Motif programming and am trying to clean up and extend an
existing Motif-based program written in C.


If a variable is declared in a calling program as

Widget w ;

and I want to pass the variable to a function that includes lines like

void Test(Widget w)
{
...
w = XmCreatePulldownMenu(foo, name, NULL, 0);
...
}


so that the initialized value of w is successfully returned to the
calling program, how is this properly done? I've been assuming that w
is treated as a pointer to some kind of structure, so that the above
syntax would work as intended. Instead, I find that the contents of w
aren't surviving the trip back to the calling program.

If I embed the XmCreatePulldownMenu call "in line" in the calling
program, it works as intended, so it appears to be only an argument-
passing issue that is causing me problems.

Thanks for any advice.


That should work, provided foo is a global menubar widget and name is a
global character string. You can't see the widget on the menubar
because you haven't populated it with anything. But it's there. Try
compiling this and then look at the widget tree with editres; you'll
see it:

#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <X11/Xmu/Editres.h>

Widget foo;
char name[] = "name";

void test(Widget);

int main(int argc, char * argv[])
{
Widget toplevel, form, w;
int ac;
Arg av[5];

XtAppContext app;

toplevel = XtAppInitialize(&app, "Test", NULL, 0,
&argc, argv, NULL, NULL, 0);
form = XtVaCreateManagedWidget("form",
xmFormWidgetClass, toplevel,
XmNheight, 100,
XmNwidth, 100,
NULL);

ac = 0;
XtSetArg(av[ac], XmNrightAttachment, XmATTACH_WIDGET); ac++;
XtSetArg(av[ac], XmNrightWidget, form); ac++;
XtSetArg(av[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
XtSetArg(av[ac], XmNleftWidget, form); ac++;
foo = XmCreateMenuBar (form, "menu_bar", av, ac);
XtManageChild(foo);

test(w);

XtAddEventHandler ( toplevel, (EventMask) 0, True,
(XtEventHandler) _XEditResCheckMessages, NULL );
XtSetLanguageProc(NULL, NULL, NULL);
XtRealizeWidget(toplevel);
XtAppMainLoop(app);

return 0;
}

void test(Widget w)
{
w = XmCreatePulldownMenu(foo, name, NULL, 0);
}
.



Relevant Pages

  • Re: passing Widget variables as arguments
    ... If a variable is declared in a calling program as ... Passing w as a variable like it is done above is not of any value. ... the widget is no ... Widget Test(Widget foo, String name) ...
    (comp.windows.x.motif)
  • Re: Using a window style in a Toplevel window
    ... from tkinter import ttk ... From the main module FMain.py call the window function that is ... located in FSecondWindow module and create a toplevel window. ... a Frame widget in the new widget set, you can simply insert such a frame ...
    (comp.lang.python)
  • How to Design Delegate Architecture ?
    ... void Method2(NumericUpDown widget) ... I thought of adding the methods to a static class: ... I also thought of using delegates and retrieving a particular delegate based ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Multi-column Optionmenu
    ... }> TopLevel that's filled with Radiobuttons. ... minimal" Dialog widget. ... closing the window. ...
    (comp.lang.perl.tk)
  • Re: Using -menu on a toplevel with a non-menu widget
    ... I'm writing a menu widget using a toplevel with a canvas in; ... the toplevel doesn't show it as a menubar. ... create a fake menu by using a frame with a class of Menu, but I seriously doubt that will work. ...
    (comp.lang.tcl)