Bringing vpdf from vendor/MorphOS-OSS/current into main branch.
[AROS-Contrib.git] / vpdf / util.h
blobff0644ec9698bb5d4f9d5b5255bdc601ef31b494
1 #ifndef UTIL_H
2 #define UTIL_H
4 #include <libraries/mui.h>
5 #include <proto/dos.h>
6 #include <proto/intuition.h>
7 #include <dos/dosextens.h>
9 static inline LONG xget(void *object, ULONG attr)
11 LONG a = 0;
12 get(object,attr,&a);
13 return a;
16 static inline int sxget(void *object, LONG attr)
18 int a[ 0 ];
19 get(object, attr, a);
20 return a[ 0 ];
23 #define nfset(obj, attr, val) \
24 SetAttrs(obj, MUIA_Group_Forward, FALSE, \
25 attr, val, \
26 TAG_DONE)
28 #define getstr(obj) ((char *)xget(obj, MUIA_String_Contents))
31 #define isDir(fib) ((fib)->fib_DirEntryType > 0)
33 static inline LONG isDirPath(char *path)
35 BPTR lock = Lock(path, ACCESS_READ);
36 if (lock != NULL)
38 struct FileInfoBlock fib;
39 if (Examine(lock, &fib))
41 UnLock(lock);
42 return isDir(&fib);
45 return FALSE;
48 /// Morphos specific hook stuff
51 * Hook, called with the following:
52 * n - name of the hook (_hook appened at the end)
53 * y - a2
54 * z - a1
56 * return type is LONG
59 #ifdef __MORPHOS__
61 #define M_RHOOK(n, y, z) \
62 static int n##_GATE(void); \
63 static int n##_GATE2(struct Hook *h, y, z); \
64 static struct EmulLibEntry n = { \
65 TRAP_LIB, 0, (void (*)(void))n##_GATE }; \
66 static int n##_GATE(void) { \
67 return (n##_GATE2((void *)REG_A0, (void *)REG_A2, (void *)REG_A1)); } \
68 static struct Hook n##Hook = { {0, 0}, (void *)&n , NULL , NULL }; \
69 static int n##_GATE2(struct Hook *h, y, z)
71 #define M_HOOK(n, y, z) \
72 static void n##_GATE(void); \
73 static void n##_GATE2(struct Hook *h, y, z); \
74 static struct EmulLibEntry n = { \
75 TRAP_LIB, 0, (void (*)(void))n##_GATE }; \
76 static void n##_GATE(void) { \
77 return (n##_GATE2((void *)REG_A0, (void *)REG_A2, (void *)REG_A1)); } \
78 static struct Hook n##Hook = { {0, 0}, (void *)&n , NULL , NULL }; \
79 static void n##_GATE2(struct Hook *h, y, z)
81 /* simple version */
83 #define S_HOOK(n) \
84 static struct EmulLibEntry n ## Func = { \
85 TRAP_LIB, 0, (void (*)(void))n }; \
86 static const struct Hook n ## Hook = { { NULL,NULL }, (void*)&n ## Func,NULL,NULL };\
87 void n(void)
89 #else
90 #define M_HOOK(n, y, z) \
91 static void ASM SAVEDS n##_func(__reg(a0, struct Hook *h), \
92 __reg(a2, y), __reg(a1, z));
93 static struct Hook n ## Hook =
95 0, 0, ( HOOKFUNC ) n##_func
99 static void ASM SAVEDS n##_func( __reg( a0, struct Hook *h ), \
100 __reg( a2, y ), __reg( a1, z ) )
101 #endif /* !__MORPHOS__ */
103 ////
105 #define FORTAG(_tagp) \
107 struct TagItem *tag, *_tags = _tagp; \
108 while ((tag = NextTagItem(&_tags))) switch ((int)tag->ti_Tag)
109 #define NEXTTAG }
111 #define FORCHILD(_o, _a) \
113 APTR child, _cstate = (APTR)((struct MinList *)xget(_o, _a))->mlh_Head; \
114 while ((child = NextObject(&_cstate)))
116 #define NEXTCHILD }
118 #define SUCCCHILD ({ APTR _succcstate = _cstate; \
119 NextObject(&_succcstate);})
121 #define INITTAGS (((struct opSet *)msg)->ops_AttrList)
123 #undef NextObject
124 #define NextObject(cstate) \
126 struct Node **nptr = (struct Node **)cstate;\
127 struct Node *this = *nptr;\
128 APTR next = this->ln_Succ;\
129 if (next)\
131 *nptr = next;\
132 next = BASEOBJECT(this);\
134 next;\
137 #ifndef MADF_VISIBLE
138 #define MADF_VISIBLE (1<<14)
139 #endif
141 #ifndef MADF_DISABLED
142 #define MADF_DISABLED (1<<15)
143 #endif
145 #ifndef _isvibible
146 #define _isvisible(obj) (_flags(obj) & MADF_VISIBLE)
147 #endif
149 #define METHOD static ULONG
150 #define PUBLIC_METHOD ULONG
152 struct MUI_RGBcolor
154 ULONG red;
155 ULONG green;
156 ULONG blue;
159 #ifndef MUIA_Pendisplay_RGBcolor
160 #define MUIA_Pendisplay_RGBcolor 0x8042a1a9 /* V11 isg struct MUI_RGBcolor * */
161 #endif
163 #ifndef MUIM_Text
164 #define MUIM_Text 0x8042ee70 /* private */ /* V20 */
165 #define MUIM_TextDim 0x80422ad7 /* private */ /* V20 */
167 struct MUIP_Text { ULONG MethodID; LONG left;LONG top;LONG width;LONG height;STRPTR text;LONG len;STRPTR preparse;ULONG flags; }; /* private */
168 struct MUIP_TextDim { ULONG MethodID; STRPTR text;LONG len;STRPTR preparse;ULONG flags; }; /* private */
169 #endif
171 #ifndef MUIA_List_AutoLineHeight
172 #define MUIA_List_AutoLineHeight 0x8042bc08 /* V20 i.. BOOL */ /* private */
173 #endif
175 #ifndef MUIM_Group_GetChild
176 #define MUIM_Group_GetChild 0x8042c556 /* private */ /* V20 */
178 #define MUIV_Group_GetChild_First MUIV_Family_GetChild_First
179 #define MUIV_Group_GetChild_Last MUIV_Family_GetChild_Last
180 #define MUIV_Group_GetChild_Next MUIV_Family_GetChild_Next
181 #define MUIV_Group_GetChild_Previous MUIV_Family_GetChild_Previous
182 #define MUIV_Group_GetChild_Iterate MUIV_Family_GetChild_Iterate
183 #endif
185 #ifndef MUIM_Group_ExitChange2
186 #define MUIM_Group_ExitChange2 0x8042e541 /* private */ /* V12 */
187 #endif
189 #ifndef MUIA_CustomBackfill
190 #define MUIA_CustomBackfill 0x80420a63 /* V11 isg BOOL */ /* private */
191 #endif
193 #ifndef MUIA_Window_OverrideStoredDimension
194 #define MUIA_Window_OverrideStoredDimension 0x8042c0f5 /* V20 is. BOOL */ /* private */
195 #endif
197 #ifndef MUIM_Backfill
198 #define MUIM_Backfill 0x80428d73 /* private */ /* V11 */
199 struct MUIP_Backfill { ULONG MethodID; LONG left; LONG top; LONG right; LONG bottom; LONG xoffset; LONG yoffset; LONG brightness; }; /* private */
200 #endif
202 #ifndef MUIA_Image_FontMatchString
203 #define MUIA_Image_FontMatchString 0x804263c1 /* V20 is. char * */ /* private */
204 #endif
206 // this one is really internal
207 #ifndef MUIM_Group_Balance
208 #define MUIM_Group_Balance 0x80425906 /* private */ /* V11 */
209 struct MUIP_Group_Balance { ULONG MethodID; Object *bal; LONG clickx; LONG clicky; LONG mode; LONG mousex; LONG mousey; }; /* private */
210 #endif
212 #ifndef MUIM_Window_HandleRMB
213 #define MUIM_Window_HandleRMB 0x80421786 /* private */ /* V20 */
214 #endif
216 #ifndef MUIM_Application_KillPushMethod
217 #define MUIM_Application_KillPushMethod 0x80429954 /* private */ /* V15 */
218 #endif
220 #ifndef MUIM_Virtgroup_MakeVisible
221 #define MUIM_Virtgroup_MakeVisible 0x8042d2d2 /* private */ /* V4 */
222 struct MUIP_Virtgroup_MakeVisible { ULONG MethodID; Object *obj; ULONG flags; }; /* private */
223 #endif
225 #ifndef _parent
226 #define _parent(obj) ((Object*)xget(obj, MUIA_Parent))
227 #endif
229 #ifndef MUIA_Title_Sortable
230 #define MUIA_Title_Sortable 0x804211f1 /* V20 isg BOOL */ /* private */
231 #endif
233 #ifndef MUIA_Window_OverrideStoredPosition
234 #define MUIA_Window_OverrideStoredPosition 0x8042fc00 /* V20 is. BOOL */ /* private */
235 #endif
237 #ifndef MUIA_Group_ChildCount
238 #define MUIA_Group_ChildCount 0x80420322 /* V20 ..g LONG */ /* private */
239 #endif
241 #ifndef MUIA_Alpha
242 #define MUIA_Alpha 0x8042c819 /* V20 isg LONG */ /* private */
243 #endif
245 #ifndef MUIF_PUSHMETHOD_VERIFY
246 #define MUIF_PUSHMETHOD_VERIFY (1<<30UL)
247 #endif
249 #endif