/***************************** LICENSE START ***********************************

 Copyright 2012 ECMWF and INPE. This software is distributed under the terms
 of the Apache License version 2.0. In applying this license, ECMWF does not
 waive the privileges and immunities granted to it by virtue of its status as
 an Intergovernmental Organization or submit itself to any jurisdiction.

 ***************************** LICENSE END *************************************/

/*
** Generated by X-Designer
*/
/*
**LIBS: -lXm -lXt -lX11
*/

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

#include <Xm/Xm.h>
#include <Xm/DialogS.h>
#include <Xm/Form.h>
#include <Xm/ScrollBar.h>
#include <Xm/Text.h>

#include "xdclass.h"

class UITextEditor_c: public xd_XmForm_c {
public:
	virtual void create (Widget parent, char *widget_name = NULL);
protected:
	Widget UITextEditor;
	Widget text_;
public:
	static void modifiedCB( Widget, XtPointer, XtPointer );
	virtual void modifiedCB( Widget, XtPointer ) = 0;
};

typedef UITextEditor_c *UITextEditor_p;

UITextEditor_p UITextEditor = (UITextEditor_p) NULL;



void UITextEditor_c::create (Widget parent, char *widget_name)
{
	Widget children[3];      /* Children to manage */
	Display *display = XtDisplay ( parent );
	Arg al[64];                    /* Arg List */
	register int ac = 0;           /* Arg Count */
	XrmValue from_value, to_value; /* For resource conversion */
	XPointer to_address; /* For Thread-safe resource conversion */ 
	Pixel to_pixel; /* For Thread-safe resource conversion */ 
	XtPointer tmp_value;             /* ditto */
	Widget widget2 = (Widget)NULL;
	Widget widget4 = (Widget)NULL;
	Widget widget5 = (Widget)NULL;

	if ( !widget_name )
		widget_name = (char *) "UITextEditor";

	XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
	UITextEditor = XmCreateForm ( parent, widget_name, al, ac );
	ac = 0;
	_xd_rootwidget = UITextEditor;
	if (DefaultDepthOfScreen(DefaultScreenOfDisplay(display)) != 1) {

		from_value.addr = "#f4def4deffff" ;
		from_value.size = strlen( from_value.addr ) + 1;
		to_value.size = sizeof(Pixel);
		to_value.addr = (XPointer) &to_pixel;
		XtConvertAndStore (UITextEditor, XmRString, &from_value, XmRPixel, &to_value);

		if ( to_value.addr ) {
			XtSetArg(al[ac], XmNbackground, (*((Pixel*) to_value.addr))); ac++;
		}
	}
	XtSetArg(al[ac], XmNeditMode, XmMULTI_LINE_EDIT); ac++;
	text_ = XmCreateScrolledText ( UITextEditor, (char *) "text_", al, ac );
	ac = 0;
	widget2 = XtParent ( text_ );

	XtSetArg(al[ac], XmNhorizontalScrollBar, &widget4); ac++;
	XtSetArg(al[ac], XmNverticalScrollBar, &widget5); ac++;
	XtGetValues(widget2, al, ac );
	ac = 0;

	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNtopOffset, 0); ac++;
	XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNbottomOffset, 0); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNleftOffset, 0); ac++;
	XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNrightOffset, 0); ac++;
	XtSetValues ( widget2, al, ac );
	ac = 0;
	XtAddCallback (text_, XmNvalueChangedCallback, &UITextEditor_c::modifiedCB, (XtPointer) this);
	if (text_ != (Widget) 0) { XtManageChild(text_); }
}

void UITextEditor_c::modifiedCB( Widget widget, XtPointer client_data, XtPointer call_data )
{
	UITextEditor_p instance = (UITextEditor_p) client_data;
	instance->modifiedCB ( widget, call_data );
}

