1 #ifndef _WINGSP_H_
2 #define _WINGSP_H_
3 
4 
5 #include <X11/Xlib.h>
6 #include <X11/Xutil.h>
7 
8 #ifdef USE_PANGO
9 #include <pango/pango.h>
10 #endif
11 
12 #include <WINGs/WINGs.h>
13 
14 #if WINGS_H_VERSION < 20041030
15 #error There_is_an_old_WINGs.h_file_somewhere_in_your_system._Please_remove_it.
16 #endif
17 
18 #include <assert.h>
19 
20 #ifdef _XLOCALE_H_	/* workaround for libX11<1.4 */
21 #undef _XLOCALE_H_
22 #include <stdlib.h>
23 #define _XLOCALE_H_
24 #else
25 #include <stdlib.h>
26 #endif
27 #include <string.h>
28 #include <strings.h>
29 #include <stdio.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
34 
35 /* ---[ global settigns ]------------------------------------------------- */
36 
37 #define DOUBLE_BUFFER   1
38 
39 #define SCROLLER_WIDTH	20
40 
41 typedef struct _WINGsConfiguration {
42     char *systemFont;
43     char *boldSystemFont;
44     int  defaultFontSize;
45     Bool antialiasedText;
46     char *floppyPath;
47     unsigned doubleClickDelay;
48     unsigned mouseWheelUp;
49     unsigned mouseWheelDown;
50 } _WINGsConfiguration;
51 
52 extern char *_WINGS_progname;
53 extern _WINGsConfiguration WINGsConfiguration;
54 extern struct W_Application WMApplication;
55 
56 
57 /* ---[ drag*.c ]--------------------------------------------------------- */
58 
59 /*
60  * We need to define these structure first because they are used in W_Screen
61  * below. The rest of drag-related stuff if after because it needs W_Screen
62  */
63 #define XDND_VERSION    3
64 
65 typedef struct W_DraggingInfo {
66     unsigned char protocolVersion; /* version supported on the other side */
67     Time timestamp;
68 
69     Atom sourceAction;
70     Atom destinationAction;
71 
72     struct W_DragSourceInfo* sourceInfo;    /* infos needed by source */
73     struct W_DragDestinationInfo* destInfo; /* infos needed by destination */
74 } W_DraggingInfo;
75 
76 /* ---[ Structures from WINGs.h ]----------------------------------------- */
77 
78 /* Pre-definition of internal structs */
79 typedef struct W_Color W_Color;
80 typedef struct W_Pixmap W_Pixmap;
81 typedef struct W_View W_View;
82 
83 typedef struct W_FocusInfo {
84     W_View *toplevel;
85     W_View *focused;    /* view that has the focus in this toplevel */
86     struct W_FocusInfo *next;
87 } W_FocusInfo;
88 
89 typedef struct W_Screen {
90     Display *display;
91     int screen;
92     int depth;
93 
94     Colormap colormap;
95 
96     Visual *visual;
97 
98     Time lastEventTime;
99 
100     Window rootWin;
101 
102     W_View *rootView;
103 
104     RContext *rcontext;
105 
106     struct W_IMContext *imctx;
107 
108     struct _XftDraw *xftdraw;          /* shared XftDraw */
109 
110     /* application related */
111 
112     W_FocusInfo *focusInfo;
113 
114     RImage *applicationIconImage;      /* image (can have alpha channel) */
115     W_Pixmap *applicationIconPixmap; /* pixmap - no alpha channel */
116     Window applicationIconWindow;
117 
118     struct W_Window *windowList;       /* list of windows in the app */
119 
120     Window groupLeader;                /* the leader of the application */
121                                        /* also used for other things */
122 
123     struct W_SelectionHandlers *selectionHandlerList;
124 
125     struct {
126         unsigned int hasAppIcon:1;
127         unsigned int simpleApplication:1;
128     } aflags;
129 
130     WMOpenPanel *sharedOpenPanel;
131     WMSavePanel *sharedSavePanel;
132 
133     struct W_FontPanel *sharedFontPanel;
134 
135     struct W_ColorPanel *sharedColorPanel;
136 
137     Pixmap stipple;
138 
139     W_View *dragSourceView;
140     W_DraggingInfo dragInfo;
141 
142     /* colors */
143     W_Color *white;
144     W_Color *black;
145     W_Color *gray;
146     W_Color *darkGray;
147 
148     GC stippleGC;
149 
150     GC copyGC;
151     GC clipGC;
152 
153     GC monoGC;                         /* GC for 1bpp visuals */
154 
155     GC xorGC;
156 
157     GC ixorGC;                         /* IncludeInferiors XOR */
158 
159     GC drawStringGC;                   /* for WMDrawString() */
160 
161     GC drawImStringGC;                 /* for WMDrawImageString() */
162 
163     struct W_Font *normalFont;
164 
165     struct W_Font *boldFont;
166 
167     WMHashTable *fontCache;
168 
169     Bool antialiasedText;
170 
171     unsigned int ignoredModifierMask; /* modifiers to ignore when typing txt */
172 
173     struct W_Balloon *balloon;
174 
175 
176     W_Pixmap *checkButtonImageOn;
177     W_Pixmap *checkButtonImageOff;
178 
179     W_Pixmap *radioButtonImageOn;
180     W_Pixmap *radioButtonImageOff;
181 
182     W_Pixmap *buttonArrow;
183     W_Pixmap *pushedButtonArrow;
184 
185     W_Pixmap *scrollerDimple;
186 
187     W_Pixmap *upArrow;
188     W_Pixmap *downArrow;
189     W_Pixmap *leftArrow;
190     W_Pixmap *rightArrow;
191 
192     W_Pixmap *hiUpArrow;
193     W_Pixmap *hiDownArrow;
194     W_Pixmap *hiLeftArrow;
195     W_Pixmap *hiRightArrow;
196 
197     W_Pixmap *pullDownIndicator;
198     W_Pixmap *popUpIndicator;
199 
200     W_Pixmap *checkMark;
201 
202     W_Pixmap *homeIcon;
203     W_Pixmap *altHomeIcon;
204 
205     W_Pixmap *trashcanIcon;
206     W_Pixmap *altTrashcanIcon;
207 
208     W_Pixmap *createDirIcon;
209     W_Pixmap *altCreateDirIcon;
210 
211     W_Pixmap *disketteIcon;
212     W_Pixmap *altDisketteIcon;
213     W_Pixmap *unmountIcon;
214     W_Pixmap *altUnmountIcon;
215 
216     W_Pixmap *magnifyIcon;
217     /*W_Pixmap *altMagnifyIcon;*/
218     W_Pixmap *wheelIcon;
219     W_Pixmap *grayIcon;
220     W_Pixmap *rgbIcon;
221     W_Pixmap *cmykIcon;
222     W_Pixmap *hsbIcon;
223     W_Pixmap *customPaletteIcon;
224     W_Pixmap *colorListIcon;
225 
226     W_Pixmap *defaultObjectIcon;
227 
228     Cursor defaultCursor;
229 
230     Cursor textCursor;
231 
232     Cursor invisibleCursor;
233 
234     Atom attribsAtom;              /* GNUstepWindowAttributes */
235 
236     Atom deleteWindowAtom;         /* WM_DELETE_WINDOW */
237 
238     Atom protocolsAtom;            /* _XA_WM_PROTOCOLS */
239 
240     Atom clipboardAtom;            /* CLIPBOARD */
241 
242     Atom xdndAwareAtom;            /* XdndAware */
243     Atom xdndSelectionAtom;
244     Atom xdndEnterAtom;
245     Atom xdndLeaveAtom;
246     Atom xdndPositionAtom;
247     Atom xdndDropAtom;
248     Atom xdndFinishedAtom;
249     Atom xdndTypeListAtom;
250     Atom xdndActionListAtom;
251     Atom xdndActionDescriptionAtom;
252     Atom xdndStatusAtom;
253 
254     Atom xdndActionCopy;
255     Atom xdndActionMove;
256     Atom xdndActionLink;
257     Atom xdndActionAsk;
258     Atom xdndActionPrivate;
259 
260     Atom wmIconDragOffsetAtom;
261 
262     Atom wmStateAtom;              /* WM_STATE */
263 
264     Atom utf8String;
265 
266     Atom netwmName;
267     Atom netwmIconName;
268     Atom netwmIcon;
269 
270     /* stuff for detecting double-clicks */
271     Time lastClickTime;            /* time of last mousedown event */
272     Window lastClickWindow;        /* window of the last mousedown */
273 
274     struct W_View *modalView;
275     unsigned modalLoop:1;
276     unsigned ignoreNextDoubleClick:1;
277 
278     /*
279      * New stuff in Window Maker 0.95.7
280      * Added at the end of the structure to avoid breaking binary compatibility
281      * with previous versions of the toolkit
282      */
283     W_Pixmap *tristateButtonImageOn;
284     W_Pixmap *tristateButtonImageOff;
285     W_Pixmap *tristateButtonImageTri;
286 
287 } W_Screen;
288 
289 #define W_DRAWABLE(scr)		(scr)->rcontext->drawable
290 
291 
292 /* ---[ configuration.c ]------------------------------------------------- */
293 
294 void W_ReadConfigurations(void);
295 
296 
297 /* ---[ drag*.c ]--------------------------------------------------------- */
298 
299 typedef struct W_DragOperationItem {
300     WMDragOperationType type;
301     char* text;
302 } W_DragOperationItem;
303 
304 typedef void* W_DndState(WMView *destView, XClientMessageEvent *event,
305                          WMDraggingInfo *info);
306 
307 typedef struct W_DragSourceInfo {
308     WMView *sourceView;
309     Window destinationWindow;
310     W_DndState *state;
311     WMSelectionProcs *selectionProcs;
312     Window icon;
313     WMPoint imageLocation;
314     WMPoint mouseOffset; /* mouse pos in icon */
315     Cursor dragCursor;
316     WMRect noPositionMessageZone;
317     Atom firstThreeTypes[3];
318 } W_DragSourceInfo;
319 
320 typedef struct W_DragDestinationInfo {
321     WMView *destView;
322     WMView *xdndAwareView;
323     Window sourceWindow;
324     W_DndState *state;
325     Bool sourceActionChanged;
326     WMArray *sourceTypes;
327     WMArray *requiredTypes;
328     Bool typeListAvailable;
329     WMArray *dropDatas;
330 } W_DragDestinationInfo;
331 
332 /* -- Functions -- */
333 
334 void W_HandleDNDClientMessage(WMView *toplevel, XClientMessageEvent *event);
335 
336 Atom W_OperationToAction(WMScreen *scr, WMDragOperationType operation);
337 
338 WMDragOperationType W_ActionToOperation(WMScreen *scr, Atom action);
339 
340 void W_FreeDragOperationItem(void* item);
341 
342 Bool W_SendDnDClientMessage(Display *dpy, Window win, Atom message,
343                             unsigned long data1, unsigned long data2,
344                             unsigned long data3, unsigned long data4,
345                             unsigned long data5);
346 
347 void W_DragSourceStartTimer(WMDraggingInfo *info);
348 
349 void W_DragSourceStopTimer(void);
350 
351 void W_DragSourceStateHandler(WMDraggingInfo *info, XClientMessageEvent *event);
352 
353 void W_DragDestinationStartTimer(WMDraggingInfo *info);
354 
355 void W_DragDestinationStopTimer(void);
356 
357 void W_DragDestinationStoreEnterMsgInfo(WMDraggingInfo *info, WMView *toplevel,
358                                         XClientMessageEvent *event);
359 
360 void W_DragDestinationStorePositionMsgInfo(WMDraggingInfo *info,
361                                            WMView *toplevel,
362                                            XClientMessageEvent *event);
363 
364 void W_DragDestinationCancelDropOnEnter(WMView *toplevel, WMDraggingInfo *info);
365 
366 void W_DragDestinationStateHandler(WMDraggingInfo *info,
367                                    XClientMessageEvent *event);
368 
369 void W_DragDestinationInfoClear(WMDraggingInfo *info);
370 
371 void W_FreeViewXdndPart(WMView *view);
372 
373 
374 /* ---[ handlers.c ]------------------------------------------------------ */
375 
376 Bool W_CheckIdleHandlers(void);
377 
378 void W_CheckTimerHandlers(void);
379 
380 Bool W_HandleInputEvents(Bool waitForInput, int inputfd);
381 
382 
383 /* ---[ notification.c ]-------------------------------------------------- */
384 
385 void W_InitNotificationCenter(void);
386 
387 void W_ReleaseNotificationCenter(void);
388 
389 void W_FlushASAPNotificationQueue(void);
390 
391 void W_FlushIdleNotificationQueue(void);
392 
393 
394 /* ---[ selection.c ]----------------------------------------------------- */
395 
396 void W_HandleSelectionEvent(XEvent *event);
397 
398 
399 /* ---[ wapplication.c ]-------------------------------------------------- */
400 
401 typedef struct W_Application {
402     char *applicationName;
403     int argc;
404     char **argv;
405     char *resourcePath;
406 } W_Application;
407 
408 /* -- Functions -- */
409 
410 void W_InitApplication(WMScreen *scr);
411 
412 Bool W_ApplicationInitialized(void);
413 
414 
415 /* ---[ wballoon.c ]------------------------------------------------------ */
416 
417 struct W_Balloon *W_CreateBalloon(WMScreen *scr);
418 
419 void W_BalloonHandleEnterView(WMView *view);
420 
421 void W_BalloonHandleLeaveView(WMView *view);
422 
423 
424 /* ---[ wcolor.c ]-------------------------------------------------------- */
425 
426 struct W_Color {
427     struct W_Screen *screen;
428 
429     XColor color;
430     unsigned short alpha;
431     short refCount;
432     GC gc;
433     struct {
434         unsigned int exact:1;
435     } flags;
436 };
437 
438 #define W_PIXEL(c)		(c)->color.pixel
439 
440 
441 /* ---[ wevent.c ]-------------------------------------------------------- */
442 
443 typedef struct W_EventHandler {
444     unsigned long eventMask;
445 
446     WMEventProc *proc;
447 
448     void *clientData;
449 } W_EventHandler;
450 
451 /* -- Functions -- */
452 
453 void W_CallDestroyHandlers(W_View *view);
454 
455 
456 /* ---[ wfont.c ]--------------------------------------------------------- */
457 
458 typedef struct W_Font {
459     struct W_Screen *screen;
460 
461     struct _XftFont *font;
462 
463     short height;
464     short y;
465     short refCount;
466     char *name;
467 
468 #ifdef USE_PANGO
469     PangoLayout *layout;
470 #endif
471 } W_Font;
472 
473 #define W_FONTID(f)		(f)->font->fid
474 
475 
476 /* ---[ widgets.c ]------------------------------------------------------- */
477 
478 #define WC_UserWidget	128
479 
480 #define CHECK_CLASS(widget, class) assert(W_CLASS(widget)==(class))
481 
482 #define W_CLASS(widget)  	(((W_WidgetType*)(widget))->widgetClass)
483 #define W_VIEW(widget)   	(((W_WidgetType*)(widget))->view)
484 
485 /* -- Functions -- */
486 
487 W_Class W_RegisterUserWidget(void);
488 
489 
490 /* ---[ winputmethod.c ]-------------------------------------------------- */
491 
492 void W_InitIM(WMScreen *scr);
493 
494 void W_CreateIC(WMView *view);
495 
496 void W_DestroyIC(WMView *view);
497 
498 void W_FocusIC(WMView *view);
499 
500 void W_UnFocusIC(WMView *view);
501 
502 void W_SetPreeditPositon(W_View *view, int x, int y);
503 
504 int W_LookupString(W_View *view, XKeyPressedEvent *event, char *buffer,
505                    int buflen, KeySym *keysym, Status *status);
506 
507 
508 /* ---[ wmisc.c ]--------------------------------------------------------- */
509 
510 void W_DrawRelief(W_Screen *scr, Drawable d, int x, int y, unsigned int width,
511                   unsigned int height, WMReliefType relief);
512 
513 void W_DrawReliefWithGC(W_Screen *scr, Drawable d, int x, int y,
514                         unsigned int width, unsigned int height,
515                         WMReliefType relief,
516                         GC black, GC dark, GC light, GC white);
517 
518 void W_PaintTextAndImage(W_View *view, int wrap, WMColor *textColor,
519                          W_Font *font, WMReliefType relief, const char *text,
520                          WMAlignment alignment, W_Pixmap *image,
521                          WMImagePosition position, WMColor *backColor, int ofs);
522 
523 void W_PaintText(W_View *view, Drawable d, WMFont *font,  int x, int y,
524                  int width, WMAlignment alignment, WMColor *color,
525                  int wrap, const char *text, int length);
526 
527 int W_GetTextHeight(WMFont *font, const char *text, int width, int wrap);
528 
529 
530 /* ---[ wpixmap.c ]------------------------------------------------------- */
531 
532 struct W_Pixmap {
533     struct W_Screen *screen;
534     Pixmap pixmap;
535     Pixmap mask;
536     unsigned short width;
537     unsigned short height;
538     short depth;
539     short refCount;
540 };
541 
542 
543 /* ---[ wview.c ]--------------------------------------------------------- */
544 
545 typedef struct W_ViewDelegate {
546     void *data;
547     void (*didMove)(struct W_ViewDelegate*, WMView*);
548     void (*didResize)(struct W_ViewDelegate*, WMView*);
549     void (*willMove)(struct W_ViewDelegate*, WMView*, int*, int*);
550     void (*willResize)(struct W_ViewDelegate*, WMView*,
551                        unsigned int*, unsigned int*);
552 } W_ViewDelegate;
553 
554 struct W_View {
555     struct W_Screen *screen;
556 
557     WMWidget *self;     /* must point to the widget the view belongs to */
558 
559     W_ViewDelegate *delegate;
560 
561     Window window;
562 
563     WMSize size;
564 
565     short topOffs;
566     short leftOffs;
567     short bottomOffs;
568     short rightOffs;
569 
570     WMPoint pos;
571 
572     struct W_View *nextFocusChain;     /* next/prev in focus chain */
573     struct W_View *prevFocusChain;
574 
575     struct W_View *nextResponder;      /* next to receive keyboard events */
576 
577     struct W_View *parent;             /* parent WMView */
578 
579     struct W_View *childrenList;       /* first in list of child windows */
580 
581     struct W_View *nextSister;         /* next on parent's children list */
582 
583     WMArray *eventHandlers;            /* event handlers for this window */
584 
585     unsigned long attribFlags;
586     XSetWindowAttributes attribs;
587 
588     void *hangedData;                  /* data holder for user program */
589 
590     WMColor *backColor;
591     WMPixmap *backImage;
592 
593 
594     Cursor cursor;
595 
596     Atom *droppableTypes;
597     struct W_DragSourceProcs      *dragSourceProcs;
598     struct W_DragDestinationProcs *dragDestinationProcs;
599     WMPixmap *dragImage;
600     int helpContext;
601 
602     XIC xic;
603 
604     struct {
605         unsigned int realized:1;
606         unsigned int mapped:1;
607         unsigned int parentDying:1;
608         unsigned int dying:1;           /* the view is being destroyed */
609         unsigned int topLevel:1;        /* is a top level window */
610         unsigned int root:1;            /* is the root window */
611         unsigned int mapWhenRealized:1; /* map the view when it's realized */
612         unsigned int alreadyDead:1;     /* view was freed */
613 
614         unsigned int dontCompressMotion:1; /* motion notify event compress */
615         unsigned int notifySizeChanged:1;
616         unsigned int dontCompressExpose:1; /* expose event compress */
617 
618         /* toplevel only */
619         unsigned int worksWhenModal:1;
620         unsigned int pendingRelease1:1;
621         unsigned int pendingRelease2:1;
622         unsigned int pendingRelease3:1;
623         unsigned int pendingRelease4:1;
624         unsigned int pendingRelease5:1;
625         unsigned int xdndHintSet:1;
626     } flags;
627 
628     int refCount;
629 };
630 
631 #define W_VIEW_REALIZED(view)	(view)->flags.realized
632 #define W_VIEW_MAPPED(view)	(view)->flags.mapped
633 
634 #define W_VIEW_DISPLAY(view)    (view)->screen->display
635 #define W_VIEW_SCREEN(view)	(view)->screen
636 #define W_VIEW_DRAWABLE(view)	(view)->window
637 
638 #define W_VIEW_WIDTH(view)	(view)->size.width
639 #define W_VIEW_HEIGHT(view)	(view)->size.height
640 
641 /* -- Functions -- */
642 
643 W_View *W_GetViewForXWindow(Display *display, Window window);
644 
645 W_View *W_CreateView(W_View *parent);
646 
647 W_View *W_CreateTopView(W_Screen *screen);
648 
649 W_View *W_CreateUnmanagedTopView(W_Screen *screen);
650 
651 W_View *W_CreateRootView(W_Screen *screen);
652 
653 void W_DestroyView(W_View *view);
654 
655 void W_RealizeView(W_View *view);
656 
657 void W_RedisplayView(WMView *view);
658 
659 void W_ReparentView(W_View *view, W_View *newParent, int x, int y);
660 
661 void W_RaiseView(W_View *view);
662 
663 void W_LowerView(W_View *view);
664 
665 void W_MapView(W_View *view);
666 
667 void W_MapSubviews(W_View *view);
668 
669 void W_UnmapSubviews(W_View *view);
670 
671 W_View *W_TopLevelOfView(W_View *view);
672 
673 void W_UnmapView(W_View *view);
674 
675 WMView *W_RetainView(WMView *view);
676 
677 void W_ReleaseView(WMView *view);
678 
679 void W_MoveView(W_View *view, int x, int y);
680 
681 void W_ResizeView(W_View *view, unsigned int width, unsigned int height);
682 
683 void W_SetViewBackgroundColor(W_View *view, WMColor *color);
684 
685 void W_SetViewBackgroundPixmap(W_View *view, WMPixmap *pix);
686 
687 void W_SetViewCursor(W_View *view, Cursor cursor);
688 
689 void W_SetFocusOfTopLevel(W_View *toplevel, W_View *view);
690 
691 W_View *W_FocusedViewOfToplevel(W_View *view);
692 
693 void W_BroadcastMessage(W_View *targetParent, XEvent *event);
694 
695 void W_DispatchMessage(W_View *target, XEvent *event);
696 
697 
698 #ifdef __cplusplus
699 }
700 #endif /* __cplusplus */
701 
702 #endif /* _WINGSP_H_ */
703