/*
 * Miscellaneous definitions and prototypes, including those from misc.c.
 */

/* $Id: misc.h,v 1.26 2000/10/02 20:56:30 torsten Exp $ */

#if defined(HAVE_PARAM_H)
#include <sys/param.h>
#endif

/*
**  By default everything uses drand48(),
**    I was making more exceptions than inclusions.
 */
#if !defined(__EMX__) && !defined(__CYGWIN__)
#define USE_DRAND
#endif

#if defined(SVR4) || defined(__osf__)
#define SHORT_RANGE
#else
#if !defined(__GLIBC__) & !defined(random) & !defined(__CYGWIN__)
long random(void);
#endif

#if !defined(linux) & !defined(__EMX__) & !defined(__FreeBSD__) & !defined(__CYGWIN__)
#if defined(BSD4_4) || defined(HPArchitecture) || defined(SGIArchitecture) || defined(_AIX) || defined(_SCO_DS)
void srandom(unsigned int);
#else
int srandom(unsigned int);
#endif	/* BSD4_4 */
#endif	/* linux */
#endif

#ifdef USE_DRAND
#ifdef DECLARE_DRAND48
extern double drand48();
extern long lrand48();
#endif
#define RANDOMI()	lrand48()
#define RANDOMI2(s, f)	(drand48() * ((f) - (s)) + (s))
#define SRANDOM(seed)	srand48((long) (seed))
#else
#ifdef SHORT_RANGE
#define RANGE		0x00000fff
#else
#define RANGE		0x0fffffff
#endif
#define RANDOMI()	random()
#define RANDOMI2(s, f)	(((double)(random() % RANGE) / \
			  (double)RANGE) * ((f) - (s)) + (s))
#define SRANDOM(seed)	srandom((unsigned) (seed))
#endif

#ifdef __EMX__
#define strcasecmp stricmp
#endif

#define ICONWIDTH 48
#define ICONHEIGHT 44

/* dialog.c */
void AlertBox(Widget parent, char *msg, XtCallbackProc okProc,
	      XtCallbackProc nokProc, void *data);
void Notice(Widget w,...);

/* fatBitsEdit.c */
void FatCursorSet(Widget w, Pixmap cursor);
void FatCursorAddZoom(int zoom, Widget winwid);
void FatCursorRemoveZoom(Widget winwid);
void FatCursorDestroyCallback(Widget w, XtPointer arg, XtPointer junk);
void FatCursorOff(Widget w);
void FatbitsUpdate(Widget w, int zoom);
void FatbitsEdit(Widget paint);

/* fileName.c */
void *GetFileNameGetLastId(void);
void StdSaveRegionFile(Widget w, XtPointer paintArg, XtPointer junk);
void StdSaveAsFile(Widget w, XtPointer paintArg, XtPointer junk);
void StdSaveFile(Widget w, XtPointer paintArg, XtPointer junk);
void *ReadMagic(char *file);
void *getArgType(Widget w);
void GetFileName(Widget w, int type, char *def,
		 XtCallbackProc okFunc, XtPointer data);

/* fontSelect.c */
void FontSelect(Widget w, Widget paint);

/* iprocess.c */
Boolean isFilterDefined();
void ScriptEditor(Widget w, Widget paint);

/* grab.c */
#ifdef __IMAGE_H__
Image *DoGrabImage(Widget w, int width, int height);
#endif
void DoGrabPixel(Widget w, Pixel * p, Colormap * cmap);
XColor *DoGrabColor(Widget w);

/* help.c */
char *matchGet(char *line, char *pat);
void HelpDialog(Widget parent, String name);
#ifdef _STDIO_H
void HelpTextOutput(FILE * fd, String name);
#endif
void HelpInit(Widget top);

/* main.c */
void SetDefaultWHZ(int w, int h, int zoom);
void GetDefaultWH(int *w, int *h);
void GetPaintWH(int *w, int *h);
void GetInitZoom(int *z);
char *GetDefaultRC(void);
void SetIconImage(Widget w);
void SetMenuBarHidden(Boolean flag);
void SetFullMenuPopup(Boolean flag);
Boolean ThereIsNoMenuBar();
Boolean IsFullPopup();
Boolean ToolsAreHorizontal();

/* misc.c */
Widget GetToplevel(Widget w);
Widget GetShell(Widget w);
void SetIBeamCursor(Widget w);
void SetCrossHairCursor(Widget w);
void SetPencilCursor(Widget w);
void SetCapAndJoin(Widget w, GC gc, int join);
void EnlargePixmap(Display * dpy, Pixmap cursor, int zoom,
		   Pixmap * data, Pixmap * mask);
XRectangle *RectUnion(XRectangle * a, XRectangle * b);
XRectangle *RectIntersect(XRectangle * a, XRectangle * b);
void GetPixmapWHD(Display * dpy, Drawable d, int *wth, int *hth, int *dth);
Pixmap dupPixmap(Display * dpy, Pixmap pix);
Pixmap GetBackgroundPixmap(Widget w);
GC GetGCX(Widget w);
void StrToArgv(char *str, int *argc, char **argv);
XImage *NewXImage(Display * dpy, Visual * visual,
		  int depth, int width, int height);
double gauss(void);
int gaussclamp(int range);
void *xmalloc(size_t n);
void AutoCrop(Widget paint);
Widget XtVisCreatePopupShell(String name,  WidgetClass widget_class,  Widget parent, ArgList args, Cardinal num_args);

/* graphic.c */
void loadClipboard(Widget w, XtPointer junk, XtPointer junk2);
void lineWidth(Widget w, int width);
void changeDashStyleAction(Widget w, XEvent * event);
void setToolIconPixmap(Widget paint, void *ptr);
void setBrushIconPixmap(Widget paint, void *ptr);
void setFontIcon(Widget paint);
void setCanvasColorsIcon(Widget paint);
void changeBackground(Widget w, XtPointer paintArg, XtPointer junk2);
void AddItemToCanvasPalette(Widget paint, Pixel p, Pixmap pix);
Boolean inCanvasPixmaps(Widget paint, Pixmap pix);

/* pattern.c */
void PatternEdit(Widget w, Pixel *pixels, Pixmap *patterns, void *brushes,
                 int npixels, int npatterns, int nbrushes);
void checkPatternLink(Widget w, int mode);
void setPatternLineWidth(void * ptr, int width);

/* print.c */
void PrintPopup(Widget w, XtPointer paintArg);
void ExternPopup(Widget w, XtPointer paintArg);
void checkExternalLink(Widget pw);

/* size.c */
void SizeSelect(Widget w, Widget paint, void (*func) (Widget, int, int, int));

/* typeConvert.c */
void InitTypeConverters(void);

/* operation.c */
void takeSnapshot(Widget w, XtPointer junk, XtPointer junk2);
void exitPaint(Widget w, XtPointer junk, XtPointer junk2);
void setToolIconOnWidget(Widget w);

/* snapshot.c */
void SnapshotImage(Widget w, XtPointer paintArg, int flag);


/* brushOp.c */
void BrushSelect(Widget w);
void setBrushIconOnWidget(Widget w);

/* rw/readWritePNM.c */
#ifdef __IMAGE_H__
extern int WritePNM(char *file, Image * image);
#endif
