//	Zinc Application Framework - M_FMTSTR.HPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#if !defined(M_FMTSTR_HPP)
#define M_FMTSTR_HPP
#include <z_fmtstr.hpp>
#include "m_utils.hpp"

extern "C"
{
#include _PrimitiveP_
#include _Text_
#include _TextFP_
}

// ----- MtfFormattedString widget definition -------------------------------

#define MtfFormattedString OSFormattedString
#define MtfFormattedStringIndex (XmTextFieldIndex + 1)

struct MtfFormattedStringClassPart
{
	XtPointer reserved;
};

struct MtfFormattedStringClassRec
{
	CoreClassPart coreClassPart;
	XmPrimitiveClassPart primitiveClassPart;
	XmTextFieldClassPart textClassPart;
	MtfFormattedStringClassPart mtfFormattedStringClassPart;  	
};

struct MtfFormattedStringPart
{
#if defined(__linux__)
	// The liniux tile_stipple pixmap is created with the depth of one so
	// it we need to create on of the correct depth.
	Pixmap linuxTileStipple;
#endif
};

struct MtfFormattedString
{
	CorePart core;
	XmPrimitivePart primitive;
	XmTextFieldPart text;
	MtfFormattedStringPart mtfFormattedStringPart;

	static MtfFormattedStringClassRec classRecord;
	static XmOffsetPtr offsets;
	static XtActionsRec action[];
	static char translations[];

	// Actions that map to Zinc functionality.
	static void activate(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->Event(L_SELECT); }
	static void backward_char(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->MoveCursor(L_LEFT); }
	static void backward_word(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->MoveCursor(L_WORD_LEFT); }
	static void beginning_of_line(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->MoveCursor(L_BOL); }
	static void changed(MtfFormattedString *, ZafFormattedString *object, XmTextVerifyCallbackStruct *);
	static void beep(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);
	static void call_default(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);
	static void classInitialize();
	static void delete_bol(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->DeleteText(L_BOL); }
	static void delete_eol(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->DeleteText(L_EOL); }
	static void delete_next_char(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->DeleteText(L_RIGHT); }
	static void delete_next_word(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->DeleteText(L_WORD_RIGHT); }
	static void delete_previous_char(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->DeleteText(L_LEFT); }
	static void delete_selection(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->DeleteText(L_DELETE); }
	static void delete_previous_word(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->DeleteText(L_WORD_LEFT); }
	static void drag_drop(MtfFormattedString *mtfObject, XEvent *xEvent, String *params, Cardinal *nparams);
	static void end_of_line(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->MoveCursor(L_EOL); }
	static void enter(MtfFormattedString *mtfObject, XEvent *xEvent, String *, Cardinal *);
	static void extend_adjust(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);
	static void extend_end(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);
	static void extend_start(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);
	static void expose(MtfFormattedString *mtfObject, XEvent *, Region xRegion);
	static void focus_in(MtfFormattedString *mtfObject, XEvent *xEvent, String *params, Cardinal *nparams);
	static void forward_char(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->MoveCursor(L_RIGHT); }
	static void forward_word(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->MoveCursor(L_WORD_RIGHT); }
	static void grab_focus(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);
	static void help(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *)
		{ GetZincObject(mtfObject)->Event(L_HELP); }
	static void highlight(MtfFormattedString *mtfObject);
	static void unhighlight(MtfFormattedString *mtfObject);
	static void insert_char(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);
	static void leave(MtfFormattedString *mtfObject, XEvent *xEvent, String *, Cardinal *);
	static bool motion_filter(ZafFormattedString *zncObject, int &column, int &line);
	static void move_destination(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);
	static void noop(MtfFormattedString *, XEvent *, String *, Cardinal *)
		{ } // no operation is performed by this function.
	static void reverse_char(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);
	static void select_all(MtfFormattedString *mtfObject, XEvent *, String *, Cardinal *);

	// General purpose functions.
	static ZafFormattedString *GetZincObject(MtfFormattedString *mtfObject)
		{ return ((ZafFormattedString *)mtfObject->primitive.user_data); }
	static MtfFormattedString *GetMotifWidget(OSWindowID screenID)
		{ return ((MtfFormattedString *)screenID); }
};

#if defined(__linux__)
#	define LinuxTileStipple(mtfFormattedStr) XmField(mtfFormattedStr,\
	MtfFormattedString::offsets, MtfFormattedString, linuxTileStipple, Pixmap)
#endif

#endif
