define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / rom / intuition / boolgadgets.c
bloba19cecc4b5827308adf146b53c288930436ecacb
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
6 Routines for BOOL Gadgets
7 */
9 /****************************************************************************************/
11 #include <proto/graphics.h>
12 #include <proto/intuition.h>
13 #include <intuition/cghooks.h>
14 #include <intuition/imageclass.h>
15 #include <graphics/gfxmacros.h>
17 #include <string.h>
19 #include "intuition_intern.h"
20 #include "gadgets.h"
22 #define DEBUG_REFRESHBOOLGADGET(x) ;
24 /****************************************************************************************/
26 #define RENDERGADGET(win,gad,rend) \
27 if (rend) \
28 { \
29 if (gad->Flags & GFLG_GADGIMAGE) \
30 { \
31 DrawImageState (rp \
32 , (struct Image *)rend \
33 , bbox.Left \
34 , bbox.Top \
35 , state \
36 , dri \
37 ); \
38 } \
39 else \
40 { \
41 DrawBorder (rp \
42 , (struct Border *)rend \
43 , bbox.Left \
44 , bbox.Top \
45 ); \
46 } \
49 #define GETRENDER(gad) (gad->SelectRender && (gad->Flags & GFLG_SELECTED)) ? \
50 gad->SelectRender : gad->GadgetRender;
52 #define BOXSIZEX 4
53 #define BOXSIZEY 4
55 /****************************************************************************************/
57 static void RenderBoolLabel(struct RastPort *rp, struct Gadget *gadget, struct BBox *bbox,
58 struct DrawInfo *dri, struct IntuitionBase *IntuitionBase)
60 #warning Amiga handmade (non-boopsi) bool gadgets do not seem to know anything about
61 #warning GFLG_LABELSTRING/GFLG_LABELIMAGE. Instead they always assume GadgetText to
62 #warning point to a struct IntuiText!!!
64 if (gadget->GadgetText)
66 SetFont(rp, dri->dri_Font);
68 switch (gadget->Flags & GFLG_LABELMASK)
70 case GFLG_LABELITEXT:
71 PrintIText (rp, gadget->GadgetText, bbox->Left, bbox->Top);
72 break;
74 case GFLG_LABELSTRING:
76 STRPTR text = (STRPTR) gadget->GadgetText;
77 int len, labelwidth, labelheight;
79 len = strlen (text);
81 labelwidth = LabelWidth (rp, text, len, IntuitionBase);
82 labelheight = rp->Font->tf_YSize;
84 SetAPen (rp, 1);
85 SetDrMd (rp, JAM1);
87 Move (rp, bbox->Left + bbox->Width / 2 - labelwidth / 2,
88 bbox->Top + bbox->Height / 2 - labelheight / 2 + rp->Font->tf_Baseline);
90 RenderLabel (rp, text, len, IntuitionBase);
91 break;
94 case GFLG_LABELIMAGE:
95 DrawImageState (rp, (struct Image *)gadget->GadgetText,
96 bbox->Left,
97 bbox->Top,
98 IDS_NORMAL,
99 dri);
100 break;
102 } /* switch (gadget->Flags & GFLG_LABELMASK) */
104 } /* GadgetText */
108 /****************************************************************************************/
110 void RefreshBoolGadget (struct Gadget * gadget, struct Window * window,
111 struct Requester * requester, struct IntuitionBase * IntuitionBase)
113 struct RastPort *rp;
114 struct GadgetInfo gi;
115 struct DrawInfo *dri;
116 struct BBox bbox;
117 ULONG state;
118 APTR render;
120 DEBUG_REFRESHBOOLGADGET(dprintf("RefreshBoolGadget: gadget %p window %p req %p\n",
121 gadget, window, requester));
123 CalcBBox (window, requester, gadget, &bbox);
125 state = GetGadgetState(window, gadget);
127 SetupGInfo(&gi, window, requester, gadget, IntuitionBase);
129 rp = ObtainGIRPort(&gi);
130 if (!rp) return;
132 dri = GetScreenDrawInfo(window->WScreen);
134 SetDrMd (rp, JAM1);
136 switch (gadget->Flags & GFLG_GADGHIGHBITS)
138 case GFLG_GADGHIMAGE:
139 render = GETRENDER(gadget);
140 RENDERGADGET(window,gadget,render);
141 break;
143 case GFLG_GADGHCOMP:
144 case GFLG_GADGHNONE:
145 case GFLG_GADGHBOX:
146 render = gadget->GadgetRender;
147 RENDERGADGET(window,gadget,render);
148 break;
150 } /* switch GadgetHighlightMethod */
152 RenderBoolLabel(rp, gadget, &bbox, dri, IntuitionBase);
154 if ((bbox.Width >= 1) && (bbox.Height >= 1))
156 switch (gadget->Flags & GFLG_GADGHIGHBITS)
158 case GFLG_GADGHCOMP:
159 if (gadget->Flags & GFLG_SELECTED)
161 SetDrMd (rp, COMPLEMENT);
163 RectFill (rp, bbox.Left,
164 bbox.Top,
165 bbox.Left + bbox.Width - 1,
166 bbox.Top + bbox.Height - 1);
168 break;
170 case GFLG_GADGHBOX:
171 if (gadget->Flags & GFLG_SELECTED)
173 SetDrMd (rp, COMPLEMENT);
175 RectFill (rp, bbox.Left - BOXSIZEX,
176 bbox.Top - BOXSIZEY,
177 bbox.Left + bbox.Width - 1 + BOXSIZEX,
178 bbox.Top + bbox.Height - 1 + BOXSIZEY);
180 RectFill (rp, bbox.Left,
181 bbox.Top,
182 bbox.Left + bbox.Width - 1,
183 bbox.Top + bbox.Height - 1);
186 break;
188 } /* Highlight after contents have been drawn */
190 if ( gadget->Flags & GFLG_DISABLED )
192 RenderDisabledPattern(rp, dri, bbox.Left,
193 bbox.Top,
194 bbox.Left + bbox.Width - 1,
195 bbox.Top + bbox.Height - 1,
196 IntuitionBase );
199 } /* if ((bbox.Width >= 1) && (bbox.Height >= 1)) */
201 FreeScreenDrawInfo(window->WScreen, dri);
203 ReleaseGIRPort(rp);
205 } /* RefreshBoolGadget */
207 /*****************************************************************************************
209 This function is called by Intuition's InputHandler when the GFLG_SELECTED state changed
211 *****************************************************************************************/
213 void RefreshBoolGadgetState(struct Gadget * gadget, struct Window * window,
214 struct Requester * requester, struct IntuitionBase *IntuitionBase)
216 struct GadgetInfo gi;
217 struct RastPort *rp;
218 struct DrawInfo *dri;
219 struct BBox bbox;
220 ULONG state;
221 APTR render;
223 DEBUG_REFRESHBOOLGADGET(dprintf("RefreshBoolGadgetState: gadget %p window %p req %p\n",
224 gadget, window, requester));
226 if ((gadget->Flags & GFLG_GADGHIGHBITS) == GFLG_GADGHNONE) return;
228 CalcBBox (window, requester, gadget, &bbox);
230 state = GetGadgetState(window, gadget);
232 SetupGInfo(&gi, window, requester, gadget, IntuitionBase);
234 rp = ObtainGIRPort(&gi);
235 if (!rp) return;
237 dri = GetScreenDrawInfo(window->WScreen);
239 SetDrMd (rp, JAM1);
241 switch (gadget->Flags & GFLG_GADGHIGHBITS)
243 case GFLG_GADGHIMAGE:
244 render = GETRENDER(gadget);
245 RENDERGADGET(window,gadget,render);
246 RenderBoolLabel(rp, gadget, &bbox, dri, IntuitionBase);
247 break;
249 } /* switch GadgetHighlightMethod */
251 if ((bbox.Width >= 1) && (bbox.Height >= 1))
253 switch (gadget->Flags & GFLG_GADGHIGHBITS)
255 case GFLG_GADGHCOMP:
256 SetDrMd (rp, COMPLEMENT);
258 RectFill (rp, bbox.Left,
259 bbox.Top,
260 bbox.Left + bbox.Width - 1,
261 bbox.Top + bbox.Height - 1);
262 break;
264 case GFLG_GADGHBOX:
265 SetDrMd (rp, COMPLEMENT);
267 RectFill (rp, bbox.Left - BOXSIZEX,
268 bbox.Top - BOXSIZEY,
269 bbox.Left + bbox.Width - 1 + BOXSIZEX,
270 bbox.Top + bbox.Height - 1 + BOXSIZEY);
272 RectFill (rp, bbox.Left,
273 bbox.Top,
274 bbox.Left + bbox.Width - 1,
275 bbox.Top + bbox.Height - 1);
276 break;
278 } /* switch (gadget->Flags & GFLG_GADGHIGHBITS) */
280 } /* if ((bbox.Width >= 1) && (bbox.Height >= 1)) */
282 FreeScreenDrawInfo(window->WScreen, dri);
284 ReleaseGIRPort(rp);
287 /****************************************************************************************/