////////////////////////////////////////////////////////
// pushme.C, Using callback functions in Objective-C
////////////////////////////////////////////////////////
#include <stdlib.h>  // Needed for exit prototype

#define Object MotifObject
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#include <Xm/FileSB.h>
#undef Object

#include <objc/Object.h>

static void quitCallback ( Widget, XtPointer, XtPointer );


@interface PushMe: Object
{
  Widget button, toplevel;
  XtAppContext app;
  XmString     xmstr;
}

- init:(const char*)name;
- compString:(const char*)string;
- createPushButtonWidget:(const char*)string;
- realizeWidget;
- (XtAppContext)getApp;

@end

@implementation PushMe

- init:(const char*)string;
{
  // Initialize the Intrinsics
  int n=0;
  toplevel = XtAppInitialize ( &app, string, NULL, 0, 
			      &n, NULL, NULL, NULL, 0 );
  return self;
}

- compString:(const char*)string;
{
  // Create a compound string 
  
  xmstr = XmStringCreateSimple((char*)string);
  return self;
}

- createPushButtonWidget:(const char*)string;
{
  // Create an XmPushButton widget to display the string
  
  button = XtVaCreateManagedWidget ((char*)string,
				    xmPushButtonWidgetClass,
				    toplevel,
				    XmNlabelString, xmstr, 
				    NULL );
  
  // Free the compound string after the XmPushButton has copied it.
  
  XmStringFree ( xmstr );
  
  // Register the quitCallback callback function
  // to be called when the button is pushed
  
  XtAddCallback (button, 
		 XmNactivateCallback, 
		 quitCallback, 
		 NULL ); // No client data needed
  return self;
}
  
- realizeWidget;
{
  // Realize all widgets and enter the main event loop
  
  XtRealizeWidget ( toplevel );
  return self;
}

- (XtAppContext)getApp;
{
  return app;
}

@end

void main ( unsigned int argc, char **argv )
{
  
  id abutton=[[PushMe alloc] init:"Pushme"];
  [[[abutton compString:"Push me"] createPushButtonWidget:"button"] 
   realizeWidget];
  XtAppMainLoop ([abutton getApp]);
}

// Callback invoked when button is activated

void quitCallback ( Widget w, XtPointer x, XtPointer y)
{
  Widget filebrowser;
  filebrowser=XmCreateFileSelectionDialog(w, "filebrowser", NULL, 0);
  XtManageChild(filebrowser);  
// exit ( 0 );
} 






