文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>X Toolkit Intrinsics 点滴

X Toolkit Intrinsics 点滴

时间:2009-04-06  来源:winzipftp

These widget classes are provided by the X Toolkit intrinsics.

Widget Class      Superclass     Header File
RectObj-----------N/A------------X11/RectObj.h
Core--------------RectObj--------X11/Core.h
Composite---------Core-----------X11/Composite.h
Constraint--------Composite------X11/Constraint.h
Shell-------------Composite------X11/Shell.h
OverrideShell-----Shell----------X11/Shell.h
WMShell-----------Shell----------X11/Shell.h
VendorShell-------WMShell--------X11/Shell.h
Transient---------VendorShell----X11/Vendor.h
TopLevelShell-----VendorShell----X11/Shell.h
ApplicationShell--TopLevelShell--X11/Shell.h

typedef void                   *XtPointer;

struct _XDisplay
{
        XExtData *ext_data;     /* hook for extension to hang data */
        struct _XFreeFuncs *free_funcs; /* internal free functions */
        int fd;                 /* Network socket. */
        int conn_checker;       /* ugly thing used by _XEventsQueued */
        ......
};

typedef struct _XDisplay Display;

typedef struct {
        XExtData *ext_data;     /* hook for extension to hang data */
        struct _XDisplay *display;/* back pointer to display structure */
        Window root;            /* Root window id. */
        int width, height;      /* width and height of screen */
        int mwidth, mheight;    /* width and height of  in millimeters */
        int ndepths;            /* number of depths possible */
        Depth *depths;          /* list of allowable depths on the screen */
        int root_depth;         /* bits per pixel */
        Visual *root_visual;    /* root visual */
        GC default_gc;          /* GC for the root root visual */
        Colormap cmap;          /* default color map */
        unsigned long white_pixel;
        unsigned long black_pixel;      /* White and Black pixel values */
        int max_maps, min_maps; /* max and min color maps */
        int backing_store;      /* Never, WhenMapped, Always */
        Bool save_unders;
        long root_input_mask;   /* initial root input mask */
} Screen;

/* <Xmd.h> */
typedef unsigned int CARD32;
typedef CARD32 XID;
/* <X.h> */
typedef XID Window;

typedef struct _WidgetRec      *Widget;
typedef struct _WidgetClassRec *WidgetClass;

/* <Intrinsic.h> */
#define _XtString char*
typedef char *String;
/* <Xfuncproto.h> */
#define _Xconst const

/* <Intrinsic.h> */
typedef unsigned int        Cardinal;
typedef struct _XtResource {
    String      resource_name;  /* Resource name                            */
    String      resource_class; /* Resource class                           */
    String      resource_type;  /* Representation type desired              */
    Cardinal    resource_size;  /* Size in bytes of representation          */
    Cardinal    resource_offset;/* Offset from base to put resource value   */
    String      default_type;   /* representation type of specified default */
    XtPointer   default_addr;   /* Address of default resource              */
} XtResource, *XtResourceList;
void XtGetValues(
    Widget              /* widget */,
    ArgList             /* args */,
    Cardinal            /* num_args */
);
void XtSetValues(
    Widget              /* widget */,
    ArgList             /* args */,
    Cardinal            /* num_args */
);

/* <Intrinsic.h> */
typedef void (*XtEventHandler)(
    Widget              /* widget */,
    XtPointer           /* closure */,
    XEvent*             /* event */,
    Boolean*            /* continue_to_dispatch */
);

void XtAddEventHandler(
    Widget              /* widget */,
    EventMask           /* event_mask */,
    _XtBoolean          /* nonmaskable */,
    XtEventHandler      /* proc */,
    XtPointer           /* closure */
);

typedef void (*XtCallbackProc)(
    Widget              /* widget */,
    XtPointer           /* closure */,  /* data the application registered */
    XtPointer           /* call_data */ /* callback specific data */
);

typedef struct _XtCallbackRec {
    XtCallbackProc  callback;
    XtPointer       closure;
} XtCallbackRec, *XtCallbackList;

void XtAddCallback(Widget w, _Xconst _XtString callback_name, XtCallbackProc call-
              back, XtPointer closure);
void XtAddCallbacks(Widget w, _Xconst _XtString callback_name,
              XtCallbackList callbacks);
void XtCallCallbacks(Widget w, String callback_name, XtPointer call_data);
void XtCallCallbackList(Widget w, XtCallbackList callbacks, XtPointer call_data);

示例程序:
/*
 * testSimple.c
 */

#include <stdio.h>

#include <X11/IntrinsicP.h>
#include <X11/Vendor.h>
#include <X11/StringDefs.h>

#include <X11/Xmu/Drawing.h>
#include <X11/Xmu/SysUtil.h>

//#include <X11/Xaw/SimpleP.h>
/* $XFree86: xc/lib/Xaw/SimpleP.h,v 1.12 2001/12/14 19:54:43 dawes Exp $ */

#ifndef _SimpleP_h
#define _SimpleP_h

#include <X11/Xfuncproto.h>

//#include <X11/Xaw/Simple.h>
/* $XFree86: xc/lib/Xaw/Simple.h,v 1.8 2001/01/17 19:42:30 dawes Exp $ */

#ifndef _Simple_h
#define _Simple_h

#include <X11/Xmu/Converters.h>

/* Resources:

 Name       Class  RepType  Default Value
 ----       -----  -------  -------------
 background      Background  Pixel  XtDefaultBackground
 border       BorderColor Pixel  XtDefaultForeground
 borderWidth      BorderWidth Dimension 1
 cursor       Cursor  Cursor  None
 cursorName      Cursor  String  NULL
 destroyCallback     Callback  Pointer  NULL
 displayList      DisplayList XawDisplayList* NULL
 height       Height  Dimension 0
 insensitiveBorder   Insensitive Pixmap  Gray
 mappedWhenManaged   MappedWhenManaged Boolean  True
 pointerColor        Foreground         Pixel           XtDefaultForeground
 pointerColorBackground Background      Pixel           XtDefaultBackground
 sensitive      Sensitive  Boolean  True
 tip       Tip  String  NULL
 width       Width  Dimension 0
 x       Position  Position 0
 y       Position  Position 0

*/

#define XtNcursor "cursor"
#define XtNcursorName "cursorName"
#define XtNinsensitiveBorder "insensitiveBorder"

#define XtCInsensitive "Insensitive"

#ifndef XtCInternational
#define XtCInternational "International"
#endif

#ifndef XtNinternational
#define XtNinternational "international"
#endif

typedef struct _SimpleClassRec *SimpleWidgetClass;
typedef struct _SimpleRec *SimpleWidget;

//extern WidgetClass simpleWidgetClass;

#endif /* _Simple_h */

_XFUNCPROTOBEGIN

//#include <X11/Xaw/XawInit.h>
/* $XdotOrg: xc/lib/Xaw/XawInit.h,v 1.2 2004/04/23 18:43:38 eich Exp $ */
#ifndef _XawInit_h
#define _XawInit_h

#define XawVendor XVENDORNAMESHORT

#define XawVersion 6700002L

#include <X11/Xfuncproto.h>

_XFUNCPROTOBEGIN

void XawInitializeWidgetSet(void);

extern Widget XawOpenApplication(
        XtAppContext *app_context_return,
        Display      *dpy,
        Screen       *screen,
        String        application_name,
        String        application_class,
        WidgetClass   widget_class,
        int          *argc,
        String       *argv
    );

_XFUNCPROTOEND

#endif /* _XawInit_h */

typedef struct
{
    Bool (*change_sensitive)(Widget);
} SimpleClassPart;

#define XtInheritChangeSensitive ((Bool (*)(Widget))_XtInherit)

typedef struct _SimpleClassRec
{
    CoreClassPart core_class;
    SimpleClassPart simple_class;
} SimpleClassRec;

//extern SimpleClassRec simpleClassRec;

typedef struct
{
    /* resources */
    Cursor cursor;
    Pixmap insensitive_border;
    String cursor_name;   /* cursor specified by name */
    Pixel pointer_fg, pointer_bg; /* Pointer colors */
    Boolean international;
    XtCallbackList callbacks;

    /* private */
} SimplePart;

typedef struct _SimpleRec
{
    CorePart core;
    SimplePart simple;
} SimpleRec;

_XFUNCPROTOEND

#endif /* _SimpleP_h */

//#include <X11/Xaw/XawInit.h>

//#include "Private.h"
/* $XFree86: xc/lib/Xaw/Private.h,v 3.9 1999/05/16 10:12:48 dawes Exp $ */

#ifndef _XawPrivate_h
#define _XawPrivate_h

#define XawMax(a, b) ((a) > (b) ? (a) : (b))
#define XawMin(a, b) ((a) < (b) ? (a) : (b))
#define XawAbs(a)    ((a) < 0 ? -(a) : (a))

#define XawStackAlloc(size, stk_buffer)  \
((size) <= sizeof(stk_buffer)   \
 ? (XtPointer)(stk_buffer)   \
 : XtMalloc((unsigned)(size)))

#define XawStackFree(pointer, stk_buffer) \
do {      \
  if ((pointer) != (XtPointer)(stk_buffer)) \
    XtFree((char *)pointer);   \
} while (0)

#ifndef XtX
#define XtX(w)            (((RectObj)w)->rectangle.x)
#endif
#ifndef XtY
#define XtY(w)            (((RectObj)w)->rectangle.y)
#endif
#ifndef XtWidth
#define XtWidth(w)        (((RectObj)w)->rectangle.width)
#endif
#ifndef XtHeight
#define XtHeight(w)       (((RectObj)w)->rectangle.height)
#endif
#ifndef XtBorderWidth
#define XtBorderWidth(w)  (((RectObj)w)->rectangle.border_width)
#endif

/* misc */
void XawTypeToStringWarning(Display*, String);

/* OS.c */
int _XawGetPageSize(void);

#endif /* _XawPrivate_h */

/*
 * Class Methods
 */
static Bool ChangeSensitive(Widget);
static void XawSimpleClassInitialize(void);
static void XawSimpleClassPartInitialize(WidgetClass);
static void XawSimpleRealize(Widget, Mask*, XSetWindowAttributes*);
static Boolean XawSimpleSetValues(Widget, Widget, Widget, ArgList, Cardinal*);

/*
 * Prototypes
 */
static void ConvertCursor(Widget);

/*
 * Initialization
 */

#define offset(field) XtOffsetOf(SimpleRec, simple.field)
static XtResource resources[] =
{
    {
        XtNcursor,
        XtCCursor,
        XtRCursor,
        sizeof(Cursor),
        offset(cursor),
        XtRImmediate,
        (XtPointer)None
    },
    {
        XtNinsensitiveBorder,
        XtCInsensitive,
        XtRPixmap,
        sizeof(Pixmap),
        offset(insensitive_border),
        XtRImmediate,
        NULL
    },
    {
        XtNpointerColor,
        XtCForeground,
        XtRPixel,
        sizeof(Pixel),
        offset(pointer_fg),
        XtRString,
        XtDefaultForeground
    },
    {
        XtNpointerColorBackground,
        XtCBackground,
        XtRPixel,
        sizeof(Pixel),
        offset(pointer_bg),
        XtRString,
        XtDefaultBackground
    },
    {
        XtNcursorName,
        XtCCursor,
        XtRString,
        sizeof(String),
        offset(cursor_name),
        XtRString,
        NULL
    },
    {
        XtNinternational,
        XtCInternational,
        XtRBoolean,
        sizeof(Boolean),
        offset(international),
        XtRImmediate,
        (XtPointer)False
    },
    {
        XtNcallback,
        XtCCallback,
        XtRCallback,
        sizeof(XtPointer),
        offset(callbacks),
        XtRCallback,
        NULL
    },
#undef offset
};

SimpleClassRec simpleClassRec =
{
    /* core */
    {
        (WidgetClass)&widgetClassRec, /* superclass */
        "Simple",    /* class_name */
        sizeof(SimpleRec),   /* widget_size */
        XawSimpleClassInitialize,  /* class_initialize */
        XawSimpleClassPartInitialize, /* class_part_initialize */
        False,    /* class_inited */
        NULL,    /* initialize */
        NULL,    /* initialize_hook */
        XawSimpleRealize,   /* realize */
        NULL,    /* actions */
        0,     /* num_actions */
        resources,    /* resources */
        XtNumber(resources),  /* num_resources */
        NULLQUARK,    /* xrm_class */
        True,    /* compress_motion */
        True,    /* compress_exposure */
        True,    /* compress_enterleave */
        False,    /* visible_interest */
        NULL,    /* destroy */
        NULL,    /* resize */
        NULL,    /* expose */
        XawSimpleSetValues, /* set_values */
        NULL,               /* set_values_hook */
        XtInheritSetValuesAlmost,  /* set_values_almost */
        NULL,    /* get_values_hook */
        NULL,    /* accept_focus */
        XtVersion,    /* version */
        NULL,    /* callback_private */
        NULL,    /* tm_table */
        XtInheritQueryGeometry,  /* query_geometry */
        XtInheritDisplayAccelerator, /* display_accelerator */
        NULL,    /* extension */
    },
    /* simple */
    {
        ChangeSensitive,   /* change_sensitive */
    },
};

WidgetClass simpleWidgetClass = (WidgetClass)&simpleClassRec;

static void
XawSimpleClassInitialize(void)
{
    static XtConvertArgRec convertArg[] =
    {
        {
            XtWidgetBaseOffset,
            (XtPointer)XtOffsetOf(WidgetRec, core.screen),
            sizeof(Screen *)
        },
        {
            XtResourceString,
            (XtPointer)XtNpointerColor,
            sizeof(Pixel)
        },
        {
            XtResourceString,
            (XtPointer)XtNpointerColorBackground,
            sizeof(Pixel)
        },
        {
            XtWidgetBaseOffset,
            (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
            sizeof(Colormap)
        },
    };

    XawInitializeWidgetSet();
    XtSetTypeConverter(XtRString, XtRColorCursor, XmuCvtStringToColorCursor,
                       convertArg, XtNumber(convertArg), XtCacheByDisplay, NULL);
}

static void
XawSimpleClassPartInitialize(WidgetClass cclass)
{
    SimpleWidgetClass c = (SimpleWidgetClass)cclass;
    SimpleWidgetClass super = (SimpleWidgetClass)c->core_class.superclass;

    if (c->simple_class.change_sensitive == NULL)
    {
        char buf[BUFSIZ];

        (void)XmuSnprintf(buf, sizeof(buf),
                          "%s Widget: The Simple Widget class method "
                          "'change_sensitive' is undefined.\nA function "
                          "must be defined or inherited.",
                          c->core_class.class_name);
        XtWarning(buf);
        c->simple_class.change_sensitive = ChangeSensitive;
    }

    if (c->simple_class.change_sensitive == XtInheritChangeSensitive)
        c->simple_class.change_sensitive = super->simple_class.change_sensitive;
}

static void
XawSimpleRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
{
    Pixmap border_pixmap = CopyFromParent;

    if (!XtIsSensitive(w))
    {
        /* change border to gray; have to remember the old one,
         * so XtDestroyWidget deletes the proper one */
        if (((SimpleWidget)w)->simple.insensitive_border == None)
            ((SimpleWidget)w)->simple.insensitive_border =
                XmuCreateStippledPixmap(XtScreen(w),
                                        w->core.border_pixel,
                                        w->core.background_pixel,
                                        w->core.depth);
        border_pixmap = w->core.border_pixmap;
        attributes->border_pixmap =
            w->core.border_pixmap = ((SimpleWidget)w)->simple.insensitive_border;

        *valueMask |= CWBorderPixmap;
        *valueMask &= ~CWBorderPixel;
    }

    ConvertCursor(w);

    if ((attributes->cursor = ((SimpleWidget)w)->simple.cursor) != None)
        *valueMask |= CWCursor;

    XtCreateWindow(w, InputOutput, (Visual *)CopyFromParent,
                   *valueMask, attributes);

    if (!XtIsSensitive(w))
        w->core.border_pixmap = border_pixmap;

}

/*
 * Function:
 * ConvertCursor
 *
 * Parameters:
 * w - simple widget
 *
 * Description:
 * Converts a name to a new cursor.
 */
static void
ConvertCursor(Widget w)
{
    SimpleWidget simple = (SimpleWidget) w;
    XrmValue from, to;
    Cursor cursor = None;

    if (simple->simple.cursor_name == NULL)
        return;

    from.addr = (XPointer)simple->simple.cursor_name;
    from.size = strlen((char *)from.addr) + 1;

    to.size = sizeof(Cursor);
    to.addr = (XPointer)&cursor;

    if (XtConvertAndStore(w, XtRString, &from, XtRColorCursor, &to))
        simple->simple.cursor = cursor;
    else
        XtAppErrorMsg(XtWidgetToApplicationContext(w),
                      "convertFailed","ConvertCursor","XawError",
                      "Simple: ConvertCursor failed.",
                      NULL, NULL);
}

/*ARGSUSED*/
static Boolean
XawSimpleSetValues(Widget current, Widget request, Widget cnew,
                   ArgList args, Cardinal *num_args)
{
    SimpleWidget s_old = (SimpleWidget)current;
    SimpleWidget s_new = (SimpleWidget)cnew;
    Bool new_cursor = False;

    /* this disables user changes after creation */
    s_new->simple.international = s_old->simple.international;

    if (XtIsSensitive(current) != XtIsSensitive(cnew))
        (*((SimpleWidgetClass)XtClass(cnew))->simple_class.change_sensitive)
        (cnew);

    if (s_old->simple.cursor != s_new->simple.cursor)
        new_cursor = True;

    /*
     * We are not handling the string cursor_name correctly here
     */

    if (s_old->simple.pointer_fg != s_new->simple.pointer_fg ||
            s_old->simple.pointer_bg != s_new->simple.pointer_bg ||
            s_old->simple.cursor_name != s_new->simple.cursor_name)
    {
        ConvertCursor(cnew);
        new_cursor = True;
    }

    if (new_cursor && XtIsRealized(cnew))
    {
        if (s_new->simple.cursor != None)
            XDefineCursor(XtDisplay(cnew), XtWindow(cnew), s_new->simple.cursor);
        else
            XUndefineCursor(XtDisplay(cnew), XtWindow(cnew));
    }

    return (False);
}

static Bool
ChangeSensitive(Widget w)
{
    if (XtIsRealized(w))
    {
        if (XtIsSensitive(w))
            if (w->core.border_pixmap != XtUnspecifiedPixmap)
                XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w),
                                       w->core.border_pixmap);
            else
                XSetWindowBorder(XtDisplay(w), XtWindow(w),
                                 w->core.border_pixel);
        else
        {
            if (((SimpleWidget)w)->simple.insensitive_border == None)
                ((SimpleWidget)w)->simple.insensitive_border =
                    XmuCreateStippledPixmap(XtScreen(w),
                                            w->core.border_pixel,
                                            w->core.background_pixel,
                                            w->core.depth);
            XSetWindowBorderPixmap(XtDisplay(w), XtWindow(w),
                                   ((SimpleWidget)w)->simple.insensitive_border);
        }
    }

    return (False);
}

/*****************************************/
void XawInitializeWidgetSet(void)
{
    static Boolean firsttime = True;

    if (firsttime)
    {
        firsttime = False;

        XtInitializeWidgetClass(vendorShellWidgetClass);
    }
}

/*****************************************/
static void
usr_callback(Widget w, XtPointer client_data, XtPointer call_data)
{
    static int num = 0;
    int pos;

    Display *dpy;
    Screen  *screen;
    Window   win;
    GC gc;

    XTextItem xtext;

    static int x, y;
    int blackColor, whiteColor;
    char strBuf[64];

    dpy = XtDisplay(w);
    screen = XtScreen(w);
    win = XtWindow(w);

    blackColor = BlackPixel(dpy, DefaultScreen(dpy));
    whiteColor = WhitePixel(dpy, DefaultScreen(dpy));

    gc = XCreateGC(dpy, win, 0, NULL);
    XSetForeground(dpy, gc, blackColor);

    //XClearWindow(dpy, win);
    /*
    for(pos = 0; pos < 400; pos += 8)
    {
        XDrawLine(dpy, win, gc, pos, 0, pos, 400);
        XDrawLine(dpy, win, gc, 0, pos, 400, pos);
    }
    */

    *strBuf = '\0';
    sprintf(strBuf, "count: %d", num);
    xtext.chars = strBuf;
    xtext.nchars = strlen(strBuf);
    xtext.delta = 0;
    xtext.font = None;

    XClearArea(dpy, win, x, y-12, 32*8, 16, False); /* y-8 <-> 8 */
    x = XtWidth(w) / 2;
    y = XtHeight(w) / 2;
    XDrawText(dpy, win, gc, x, y, &xtext, 1);
    //printf("painted %d: x = %d, y = %d\n", num, x, y);
    ++num;
    return;
}

/*****************************************/
static void
usr_hndlr(Widget w, XtPointer client_data, XEvent *event, Boolean *bContinue)
{
    XtCallCallbacks(w, XtNcallback, NULL);
    return;
}

/*****************************************/
int main(int argc, char *argv[])
{
    XtAppContext app_context;
    Display *dpy;
    Widget topLevel, hello;
    int blackColor;

    Arg args[20];
    int ac;

    topLevel = XtVaAppInitialize(
                   &app_context,       /* Application context */
                   "XHello",         /* Application class */
                   NULL, 0,            /* command line option list */
                   &argc, argv,        /* command line args */
                   NULL,               /* for missing app-defaults file */
                   NULL);              /* terminate varargs list */

    ac = 0;
    XtSetArg(args[ac], XtNheight, 50);
    ac++;
    XtSetArg(args[ac], XtNwidth, 100);
    ac++;
    XtSetValues(topLevel, args, ac);

    hello = XtVaCreateManagedWidget(
                "hello",   /* arbitrary widget name */
                simpleWidgetClass, /* widget class from Label.h */
                topLevel,   /* parent widget */
                NULL);              /* terminate varargs list */

    //ac = 0;
    //XtSetArg(args[ac], XtNheight, 25);
    //ac++;
    //XtSetArg(args[ac], XtNwidth, 25);
    //ac++;
    //dpy = XtDisplay(hello);
    //blackColor = BlackPixel(dpy, DefaultScreen(dpy));
    //XtSetArg(args[ac], XtNbackground, blackColor);
    //ac++;
    //XtSetValues(hello, args, ac);

    XtAddCallback(hello, XtNcallback, usr_callback, "Hello");

    XtAddEventHandler(hello, ButtonPressMask, FALSE, usr_hndlr, NULL);

    /*
     *  Create windows for widgets and map them.
     */
    XtRealizeWidget(topLevel);

    /*
     *  Loop for events.
     */
    XtAppMainLoop(app_context);

    return 0;
}
相关阅读 更多 +
排行榜 更多 +
暗黑封魔录手游

暗黑封魔录手游

角色扮演 下载
战国美人游戏

战国美人游戏

角色扮演 下载
仙境苍穹手游

仙境苍穹手游

角色扮演 下载