/* X-Designer
** (c) 1992, 1993, 1994, 1995
** Imperial Software Technology (IST),
** 95 London Street,
** Reading,
** Berkshire,
** United Kingdom RG1 4QA.
**
** Telephone: +44 1734 587055
** Fax:       +44 1734 589005
** Email:     support@ist.co.uk
*/


/*
** sccsid = "@(#)dist/src/xd/hdrs/xwidget.h	1.5" -- 95/05/04
*/

#include <X11/IntrinsicP.h>
#include <X11/Intrinsic.h>

#ifndef FILE
#include <stdio.h>
#endif
#include "icon.h"

/*
** An attribute: This is used for storing "local" resources
*/
typedef struct Attr_s {
	struct Attr_s *next;
	int id, value;
} Attr_t, *Attr_p;

/*
** One of these structures exists for every resource which we are handling
** in a resource dialog. It contains pointers to the widgets which display
** the resource value as well as the toggle indicating that the resource
** is to be generated to the resource file
*/

typedef enum{ xdc_free_default, xdc_free, xdc_dont_free } xdc_free_type;

typedef struct ResWidget_s {
    Widget widget;
    Widget resfile_toggle;
    caddr_t value;
    unsigned changed : 1;
    xdc_free_type free_on_get;
    xdc_free_type free_on_set;
    char *counter_name;
    struct Dialog_s *dialog;
} ResWidget_t, *ResWidget_p;

#define DISPLAY_PAGE    0
#define MARGINS_PAGE    1
#define SETTINGS_PAGE   2
#define CALLBACKS_PAGE  3
#define MISC_PAGE       4
#define NPAGES          5

typedef struct Dialog_s {
    Widget shell;
    Widget form;
    Widget apply_button;
    Widget undo_button;
    Widget inherit_button;
    Widget *pages;
    Widget *buttons;
    Widget *last_on_page;
    int *page_index;
    int page_count;
    ResWidget_t *widgets;
    Boolean editable;
    Boolean modified;
} Dialog_t, *Dialog_p;

/*
** A widget class:
*/
typedef struct Popup_s {
    void (*dialog_create)();
    void (*dialog_init)();
    void (*dialog_update)();
    Boolean created;
} Popup_t, *Popup_p;

typedef struct Resource_s {
    char *name;
    XrmQuark q_name;
    Popup_p popup;
    int page_index;
    Boolean visible;
    xdc_free_type free_on_get;
    xdc_free_type free_on_set;
    char *counter_name;
} Resource_t,*Resource_p;

typedef struct XWidgetClass_s {
	WidgetClass *class;             /* The widget class */
	char *class_name;               /* The name of the variable containing the Widget Class */
	char *include_filename;         /* name of include file for generated code */
	int page_num;                   /* Which page should it go on */
	char *(*defined_name)();        /* to turn a resource name back to a XtN name */
	int (*create)();                /* Routine called when creating widget */
	int (*destroy)();               /* Routine called when destroying a widget */
	Widget (*realise)();            /* Routine called to realise a widget */
	int (*resource_panel)();        /* Routine called to pop up the resource dialogue */
	int (*constraint_panel)();      /* Routine called to pop up the constraints dialogue */
	int (*resource_update)();       /* Routine called when resource dialogue needs updating */
	int (*constraint_update)();     /* Routine called when constraints dialogue needs updating */
	Boolean (*can_add_child)();     /* Routine called to find out if a child can be added to this widget */
	Boolean (*appropriate_parent)();/* Routine called to find out this widget can be added to the parent */
	int (*generate)();              /* Routine called to generate code */
	int (*write)();                 /* Routine called to write save file */
	int (*update)();                /* Routine called to update dialogues */
	Dialog_p resource_dialog;       /* The resource dialogue */
	Dialog_p constraint_dialog;     /* The constraint dialogue */
	Boolean can_swap_fg;            /* The class has a foreground resource */
	Boolean can_create;             /* The class has a foreground resource */
	Boolean generate_initialise;    /* Generate XtInitializeClassWidget in main program */
	Boolean initialised;            /* The can   swap fg flag is valid */
	Boolean layoutable;             /* The widget may use the layout editor */
	int extension;                  /* For the programmers own use */
	Icon_t icon;
	Widget button;                  /* The widget in the icon palette */
	Resource_p popups;              /* Resource specific popup editors */
	int user_page_count;            /* How many user defined pages */
	char *widget_help_doc;          /* Help doc for widget help */
	char *widget_help_tag;          /* Help tag for widget help */
	char *dialogue_help_doc;        /* Help doc for dialogue */
	char *dialogue_help_tag;        /* Help tag for dialogue */
	Boolean used;                   /* Is the class used in the design */
} XWidgetClass_t, *XWidgetClass_p;

extern XWidgetClass_p xwidgets[];

/*
** A widget instance:
*/
typedef struct XWidget_s {
	XWidgetClass_p class;           /* Pointer to the XWidget class record */
	Widget widget;                  /* The actual widget */
	struct Thing *thing;
	int extension;                  /* For the programmers own use */
} XWidget_t, *XWidget_p;

/*
** A family of widgets:
*/
typedef struct XFamily_s {
	char *name;                     /* The name of this family */
	XWidgetClass_p *widget_classes; /* The widgets in this family */
} XFamily_t, *XFamily_p;

typedef struct Enum_s {
    char *name;
    int value;
    char *code_symbol;
    char *res_file_symbol;
} Enum_t, *Enum_p;

typedef struct Enum_def_s {
    char *name;
    XrmQuark type;
    Enum_p enumeration;
} Enum_def_t, *Enum_def_p;

typedef struct Type_alias_s {
    char *from_name;
    XrmQuark from_type;
    char *to_name;
    XrmQuark to_type;
} Type_alias_t, *Type_alias_p;

typedef struct Converter_s {
    char *name;
    XrmQuark q_name;
    char *defined_name;
    Boolean (*converter_proc)();
    char *converter_name;
    Boolean converter_required;
    Popup_p popup;
} Converter_t, *Converter_p;

typedef struct ResClass_s {
    char *name;
    XrmQuark type;
    int page;
    int parse_type;
    Widget (*create_widgets)();
    int (*set_value)();
    caddr_t (*get_value)();
    int (*write)();
    int (*generate)();
}ResClass_t, *ResClass_p;

typedef struct ResGen_s {
    FILE *file;
    int language;
    int phase;
    char *name;
    caddr_t value;
    XWidget_p xwidget;
} ResGen_t, *ResGen_p;

#define BOOL_DEFAULT    0
#define BOOL_YES        1
#define BOOL_NO         2

typedef struct {
    Widget text;
    char *resource_name;
    Popup_p popup;
}ConvCB_t, *ConvCB_p;
