1 /*	Public domain	*/
2 
3 typedef struct ap_flag_names {
4 	const char *name;
5 	Uint bitmask;
6 } AP_FlagNames;
7 
8 /* Translate a hashref of options to a set of bit flags. */
9 static __inline__ void
AP_MapHashToFlags(void * pHV,const AP_FlagNames * map,Uint * pFlags)10 AP_MapHashToFlags(void *pHV, const AP_FlagNames *map, Uint *pFlags)
11 {
12 	SV **val;
13 	int i;
14 
15 	for (i = 0; map[i].name != NULL; i++) {
16 		val = hv_fetch((HV *)pHV, map[i].name, strlen(map[i].name), 0);
17 		if (val)
18 			*pFlags |= map[i].bitmask;
19 	}
20 }
21 
22 /* Functions to allow Widget subclasses to access flags in their superclass. */
23 static __inline__ int
AP_SetNamedFlag(const char * str,const AP_FlagNames * map,Uint * flags)24 AP_SetNamedFlag(const char *str, const AP_FlagNames *map, Uint *flags)
25 {
26 	int i;
27 	for (i = 0; map[i].name != NULL; i++) {
28 		if (strEQ(str, map[i].name)) {
29 			*flags |= map[i].bitmask;
30 			return 0;
31 		}
32 	}
33 	return -1;
34 }
35 static __inline__ int
AP_UnsetNamedFlag(const char * str,const AP_FlagNames * map,Uint * flags)36 AP_UnsetNamedFlag(const char *str, const AP_FlagNames *map, Uint *flags)
37 {
38 	int i;
39 	for (i = 0; map[i].name != NULL; i++) {
40 		if (strEQ(str, map[i].name)) {
41 			*flags &= ~(map[i].bitmask);
42 			return 0;
43 		}
44 	}
45 	return -1;
46 }
47 static __inline__ int
AP_GetNamedFlag(const char * str,const AP_FlagNames * map,Uint flags,Uint * flag)48 AP_GetNamedFlag(const char *str, const AP_FlagNames *map, Uint flags, Uint *flag)
49 {
50 	int i;
51 	for (i = 0; map[i].name != NULL; i++) {
52 		if (strEQ(str, map[i].name)) {
53 			*flag = flags & map[i].bitmask;
54 			return 0;
55 		}
56 	}
57 	return -1;
58 }
59 static __inline__ int
AP_SetNamedFlagSigned(const char * str,const AP_FlagNames * map,int * flags)60 AP_SetNamedFlagSigned(const char *str, const AP_FlagNames *map, int *flags)
61 {
62 	int i;
63 	for (i = 0; map[i].name != NULL; i++) {
64 		if (strEQ(str, map[i].name)) {
65 			*flags |= map[i].bitmask;
66 			return 0;
67 		}
68 	}
69 	return -1;
70 }
71 static __inline__ int
AP_UnsetNamedFlagSigned(const char * str,const AP_FlagNames * map,int * flags)72 AP_UnsetNamedFlagSigned(const char *str, const AP_FlagNames *map, int *flags)
73 {
74 	int i;
75 	for (i = 0; map[i].name != NULL; i++) {
76 		if (strEQ(str, map[i].name)) {
77 			*flags &= ~(map[i].bitmask);
78 			return 0;
79 		}
80 	}
81 	return -1;
82 }
83 
84 /* defined in Event.xs */
85 extern void AP_StoreEventPV(AG_Event *event, SV *pv);
86 extern void AP_EventHandler(AG_Event *event);
87 extern void AP_EventHandlerDecRef(AG_Event *event);
88 extern SV * AP_RetrieveEventPV(AG_Event *event);
89 extern void AP_DecRefEventPV(AG_Event *event);
90 
91 /* Flags used by all widget types. */
92 static const AP_FlagNames AP_WidgetFlagNames[] = {
93 	{ "hFill",		AG_WIDGET_HFILL },
94 	{ "vFill",		AG_WIDGET_VFILL },
95 	{ "hide",		AG_WIDGET_HIDE },
96 	{ "disabled",		AG_WIDGET_DISABLED },
97 	{ "focusable",		AG_WIDGET_FOCUSABLE },
98 	{ "unfocusedMotion",	AG_WIDGET_UNFOCUSED_MOTION },
99 	{ "unfocusedButtonUp",	AG_WIDGET_UNFOCUSED_BUTTONUP },
100 	{ "unfocusedButtonDown",AG_WIDGET_UNFOCUSED_BUTTONDOWN },
101 	{ "catchTab",		AG_WIDGET_CATCH_TAB },
102 	{ "noSpacing",		AG_WIDGET_NOSPACING }
103 };
104 
105 typedef AG_Object * Agar__Object;
106 typedef AG_Widget * Agar__Widget;
107 typedef AG_Event * Agar__Event;
108 typedef AG_PixelFormat * Agar__PixelFormat;
109 typedef AG_Surface * Agar__Surface;
110 typedef AG_Window * Agar__Window;
111 typedef AG_Config * Agar__Config;
112 typedef AG_Font * Agar__Font;
113 typedef AG_Box * Agar__Box;
114 typedef AG_Button * Agar__Button;
115 typedef AG_Checkbox * Agar__Checkbox;
116 typedef AG_Combo * Agar__Combo;
117 typedef AG_Console * Agar__Console;
118 typedef AG_Editable * Agar__Editable;
119 typedef AG_FileDlg * Agar__FileDlg;
120 typedef AG_Fixed * Agar__Fixed;
121 typedef AG_GLView * Agar__GLView;
122 typedef AG_Graph * Agar__Graph;
123 typedef AG_FixedPlotter * Agar__FixedPlotter;
124 typedef AG_HSVPal * Agar__HSVPal;
125 typedef AG_Icon * Agar__Icon;
126 typedef AG_Label * Agar__Label;
127 typedef AG_MPane * Agar__MPane;
128 typedef AG_Menu * Agar__Menu;
129 typedef AG_MenuItem * Agar__MenuItem;
130 typedef AG_Notebook * Agar__Notebook;
131 typedef AG_NotebookTab * Agar__NotebookTab;
132 typedef AG_Numerical * Agar__Numerical;
133 typedef AG_Pane * Agar__Pane;
134 typedef AG_Pixmap * Agar__Pixmap;
135 typedef AG_PopupMenu * Agar__PopupMenu;
136 typedef AG_ProgressBar * Agar__ProgressBar;
137 typedef AG_Radio * Agar__Radio;
138 typedef AG_Scrollbar * Agar__Scrollbar;
139 typedef AG_Scrollview * Agar__Scrollview;
140 typedef AG_Separator * Agar__Separator;
141 typedef AG_Slider * Agar__Slider;
142 typedef AG_Socket * Agar__Socket;
143 typedef AG_Statusbar * Agar__Statusbar;
144 typedef AG_Table * Agar__Table;
145 typedef AG_Textbox * Agar__Textbox;
146 typedef AG_Tlist * Agar__Tlist;
147 typedef AG_TlistItem * Agar__TlistItem;
148 typedef AG_Toolbar * Agar__Toolbar;
149 typedef AG_UCombo * Agar__UCombo;
150