#ifndef CODE_TYPES_H
#define CODE_TYPES_H

/*-----------------------------------------------------------------------
 * Xclasses header file
 * ($Id: types.h,v 1.3 2003/03/06 10:02:44 schmitzj Exp $)
 * 
 * Copyright (C) 1998 Jürgen Schmitz
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 *-----------------------------------------------------------------------
 */

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/Xresource.h>
#include <X11/xpm.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <Xclasses/types.h>
#include <Xclasses/dlist.h>
#include "../include/allconfig.h"

// -------------------------------------------------------------------
#define OwnJSEvent	(1L<<31)

// #define XSPEC	XSync(display(),0); usleep(10000);
#define XSPEC
#define USE_XSYNC

#ifndef XK_Page_Up
#define XK_Page_Up		XK_Prior
#endif
#ifndef XK_Page_Down
#define XK_Page_Down	XK_Next
#endif

#ifndef XK_KP_Page_Up
#define XK_KP_Page_Up		XK_KP_Prior
#endif
#ifndef XK_KP_Page_Down
#define XK_KP_Page_Down	XK_KP_Next
#endif

#ifndef MIN
#define MIN(x,y)	((x)<(y)?(x):(y))
#endif

#ifndef MAX
#define MAX(x,y)	((x)>(y)?(x):(y))
#endif

// -------------------------------------------------------------------
// win_list.cxx, für Gadgets
#define GT_ANY		0xFFFF
#define GT_GADGET	1
#define GT_GROUP	2

struct ggs
{
    struct ggs      *next;
    struct ggs      *prev;
    int				hashwert;
    struct ggs		*nohash_next;
    struct ggs		*nohash_prev;
    Window          win;
    int				typ;
    union
    {
	    class gadget    *ggclasse;
	    class group		*gpclasse;
	    class gadget	*classe;
	};
};

void Add(struct ggs *);
void Rem(struct ggs *);
struct ggs *FindGG(Window win,int typ);
struct ggs *NextGG(struct ggs *old,int typ);
struct ggs *nohash_NextGG(struct ggs *old);
struct ggs *nohash_PrevGG(struct ggs *old);

void fontAdd(char *,XFontStruct *);
XFontStruct *FindFont(char *);
void FreeFonts(Display *);

// -------------------------------------------------------------------
// Abstand Text bei Before_x (input, output, lefttext, ...)
#define TEXTDISTANCE 	4

// -------------------------------------------------------------------
// Fehler-Ausgaben, von eprintf.cxx
void eprintf(char *);
void error_printf(char *,class Xclasses*);
void warn_printf(char *,class Xclasses*);
void fatal_printf(char *,class Xclasses*);
void outOfMemory(char *classname);

// -------------------------------------------------------------------
// Xclasses.cxx
void resetObjectCheck(void);
int objectsChanged(void);
int objectExists(Xclasses *obj);
void writeObjectTree(void);

// -------------------------------------------------------------------
// XCprogram.cxx
extern class pXCprogram *thisProgram;
extern class Xclasses serviceobjs;

// -------------------------------------------------------------------
// keyclass.cxx
int KeyHandler(class Xclasses *,XEvent *event,KeySym key,char *taste);
class keyclass *GetKeyclass(Display *d,Window w);
class keyclass *GetKeyclass(class Xclasses *obj);

// -------------------------------------------------------------------
// intern.cxx
void argvparser(int &argc, char *argv[]);
void about_Xclasses(class Xwindows *aw,class Xclasses *parent);
void go_sleep(int milli);
int glob_string(char *name,char *pattern,int hidden); // hidden = 1 -> "." besonders behandeln
void remarg(int argc,char *argv[],int r);
char *xc_gethostname(void);

// -------------------------------------------------------------------
// appwindow.cxx
extern dlist allapps;
void aw_alarmhandler(int);
void aw_unalarm(void);

// -------------------------------------------------------------------
// Xwindows.cxx
extern dlist allXwins;

// -------------------------------------------------------------------
// Xdisplay.cxx
Display *g_display(void);

// -------------------------------------------------------------------
// Xcolors.cxx
extern Colormap cmap;
extern class Xcolors *baseXcolors;

// -------------------------------------------------------------------
// gadget.cxx
extern int helpmode;

// -------------------------------------------------------------------
// group.cxx
extern int group_free_clear;

#define NO_LIMIT	0xffffff

// -------------------------------------------------------------------
// xclasses_config.cxx
#define GLOBAL_CONFIGS	CONFIGSDIR"/"
extern char *prgname;
void read_global_config(class Xdisplay *d);

// -------------------------------------------------------------------
// init.cxx
void start_x_session(class Xdisplay *);
void init_x_session(class Xcolors *);
void free_x_session(class Xcolors *);
void end_x_session(class Xdisplay *);

// -------------------------------------------------------------------
// resource.cxx
void initResource(class Xdisplay *);
void parseArgv(int &argc, char *argv[]);
char *getResource(char *,char *);
void setResource(char *,char *);
void writeObjectDatabase(char *filename);
void writeObjectDatabase(void);

// -------------------------------------------------------------------
// tools.cxx
void WMPosition(Display *d,Window win,int &wx,int &wy);
Window FindWindowOnServer(Display *d,char *wname);

#endif
