#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>

#include <Xm/Xm.h>
#include <Xm/DialogS.h>
#include <Xm/DrawingA.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/TextF.h>

#include "textf_base.h"
#include "textf.h"

void textf_c::popup_menu( Widget w, XtPointer client_data, XEvent *event,
				    Boolean *continue_to_dispatch )
{
	XButtonPressedEvent *buttonEvent = (XButtonPressedEvent *) event ;

	if ( buttonEvent->button == Button3 ) {

		textf_p object = (textf_p) client_data ;

		object->popup_menu( buttonEvent ) ;
	}

}


void textf_c::popup_menu( XButtonPressedEvent *event )
{
	XmMenuPosition( thePopup->xd_rootwidget(), event ) ;

	XtManageChild( thePopup->xd_rootwidget() ) ;
}

void textf_c::create( Widget parent, char *widget_name )
{
	((textf_base_p) this)->textf_base_c::create( parent, widget_name ) ;

	thePopup = new textf_popup_c ;
	thePopup->create( xd_rootwidget(), "popup" ) ;

	XtAddEventHandler( xd_rootwidget(), ButtonPressMask, False, popup_menu, 
			   (XtPointer) this ) ;
}
