added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / intuition / scrdecorclass.c
bloba7c0dfb47359dc736336be33e04ddc73e889b43b
1 /*
2 Copyright 1995-2005, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
8 #include <dos/dos.h>
9 #include <dos/dosextens.h>
11 #include <intuition/intuition.h>
12 #include <intuition/intuitionbase.h>
13 #include <intuition/classes.h>
14 #include <intuition/classusr.h>
15 #include <intuition/scrdecorclass.h>
16 #include <intuition/cghooks.h>
17 #include <intuition/icclass.h>
18 #include <intuition/extensions.h>
20 #include <graphics/gfxbase.h>
21 #include <graphics/gfxmacros.h>
23 #include <utility/tagitem.h>
24 #include <utility/hooks.h>
26 #include <clib/macros.h>
28 #include <string.h>
30 #include <proto/exec.h>
31 #include <proto/intuition.h>
32 #include <proto/graphics.h>
33 #include <proto/utility.h>
35 #include <proto/alib.h>
37 #include "intuition_intern.h"
38 #include "gadgets.h"
40 /**************************************************************************************************/
42 #ifdef __AROS__
43 #define USE_AROS_DEFSIZE 1
44 #else
45 #define USE_AROS_DEFSIZE 0
46 #endif
48 #define DEFSIZE_WIDTH 14
49 #define DEFSIZE_HEIGHT 14
51 #define HSPACING 3
52 #define VSPACING 3
53 /* Ralph Schmidt
54 * heuristics for smaller arrows used in apps
55 * like filer
57 #define HSPACING_MIDDLE 2
58 #define VSPACING_MIDDLE 2
59 #define HSPACING_SMALL 1
60 #define VSPACING_SMALL 1
62 #define DRI(dri) ((struct DrawInfo *)(dri))
64 /**************************************************************************************************/
66 static void renderimageframe(struct RastPort *rp, ULONG which, ULONG state, UWORD *pens,
67 WORD left, WORD top, WORD width, WORD height,
68 struct IntuitionBase *IntuitionBase)
70 WORD right = left + width - 1;
71 WORD bottom = top + height - 1;
72 BOOL leftedgegodown = FALSE;
73 BOOL topedgegoright = FALSE;
75 if (left == 0) leftedgegodown = TRUE;
76 if (top == 0) topedgegoright = TRUE;
78 SetAPen(rp, pens[((state == IDS_SELECTED) || (state == IDS_INACTIVESELECTED)) ? SHADOWPEN : SHINEPEN]);
80 /* left edge */
81 RectFill(rp, left,
82 top,
83 left,
84 bottom - (leftedgegodown ? 0 : 1));
86 /* top edge */
87 RectFill(rp, left + 1,
88 top,
89 right - (topedgegoright ? 0 : 1),
90 top);
92 SetAPen(rp, pens[((state == IDS_SELECTED) || (state == IDS_INACTIVESELECTED)) ? SHINEPEN : SHADOWPEN]);
94 /* right edge */
95 RectFill(rp, right,
96 top + (topedgegoright ? 1 : 0),
97 right,
98 bottom);
100 /* bottom edge */
101 RectFill(rp, left + (leftedgegodown ? 1 : 0),
102 bottom,
103 right - 1,
104 bottom);
107 /**************************************************************************************************/
109 static UWORD getbgpen(ULONG state, UWORD *pens)
111 UWORD bg;
113 switch (state)
115 case IDS_NORMAL:
116 case IDS_SELECTED:
117 bg = pens[FILLPEN];
118 break;
120 default:
121 bg = pens[BACKGROUNDPEN];
122 break;
125 return bg;
129 /**************************************************************************************************/
131 #undef IntuitionBase
132 #define IntuitionBase ((struct IntuitionBase *)(cl->cl_UserData))
134 /**************************************************************************************************/
136 IPTR ScrDecorClass__OM_NEW(Class *cl, Object *obj, struct opSet *msg)
138 struct scrdecor_data *data;
140 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
141 if (obj)
143 data = INST_DATA(cl, obj);
145 data->userbuffersize = (ULONG) GetTagData(SDA_UserBuffer, 0, msg->ops_AttrList);
149 return (IPTR)obj;
152 /**************************************************************************************************/
154 IPTR ScrDecorClass__OM_GET(Class *cl, Object *obj, struct opGet *msg)
156 struct scrdecor_data *data = INST_DATA(cl, obj);
158 switch(msg->opg_AttrID)
160 case SDA_UserBuffer:
161 *msg->opg_Storage = (IPTR) data->userbuffersize;
162 break;
164 case SDA_TrueColorOnly:
165 *msg->opg_Storage = FALSE;
166 break;
168 default:
169 return DoSuperMethodA(cl, obj, (Msg)msg);
172 return 1;
176 /**************************************************************************************************/
178 IPTR ScrDecorClass__SDM_GETDEFSIZE_SYSIMAGE(Class *cl, Object *obj, struct sdpGetDefSizeSysImage *msg)
180 ULONG def_low_width = DEFSIZE_WIDTH, def_low_height = DEFSIZE_HEIGHT;
181 ULONG def_med_width = DEFSIZE_WIDTH, def_med_height = DEFSIZE_HEIGHT;
182 ULONG def_high_width = DEFSIZE_WIDTH, def_high_height = DEFSIZE_HEIGHT;
184 switch(msg->sdp_Which)
186 case SDEPTHIMAGE:
187 #if USE_AROS_DEFSIZE
188 def_low_width = def_med_width = def_high_width = DEFSIZE_WIDTH;
189 def_low_height = def_med_height = def_high_height = DEFSIZE_HEIGHT;
190 #else
191 def_low_width = 17;
192 def_med_width = 23;
193 def_high_width = 23;
194 #endif
195 break;
197 default:
198 return FALSE;
201 switch(msg->sdp_SysiSize)
203 case SYSISIZE_LOWRES:
204 *msg->sdp_Width = def_low_width;
205 *msg->sdp_Height = def_low_height;
206 break;
208 case SYSISIZE_MEDRES:
209 *msg->sdp_Width = def_med_width;
210 *msg->sdp_Height = def_med_height;
211 break;
213 case SYSISIZE_HIRES:
214 default:
215 *msg->sdp_Width = def_high_width;
216 *msg->sdp_Height = def_high_height;
217 break;
220 return TRUE;
223 /**************************************************************************************************/
225 IPTR ScrDecorClass__SDM_DRAW_SYSIMAGE(Class *cl, Object *obj, struct sdpDrawSysImage *msg)
227 struct scrdecor_data *data = INST_DATA(cl, obj);
228 struct RastPort *rp = msg->sdp_RPort;
229 UWORD *pens = DRI(msg->sdp_Dri)->dri_Pens;
230 LONG state = msg->sdp_State;
231 LONG left = msg->sdp_X;
232 LONG top = msg->sdp_Y;
233 LONG width = msg->sdp_Width;
234 LONG height = msg->sdp_Height;
235 LONG right = left + width - 1;
236 LONG bottom = top + height - 1;
238 SetDrMd(rp, JAM1);
240 switch(msg->sdp_Which)
242 case SDEPTHIMAGE:
244 UWORD bg;
245 WORD h_spacing;
246 WORD v_spacing;
248 renderimageframe(rp, DEPTHIMAGE, state, pens,
249 left, top, width, height, IntuitionBase);
250 left++;
251 top++;
252 right--;
253 bottom--;
254 width -= 2;
255 height -= 2;
257 h_spacing = width / 6;
258 v_spacing = height / 6;
260 bg = pens[BACKGROUNDPEN];
262 /* Clear background into correct color */
263 SetAPen(rp, bg);
264 RectFill(rp, left, top, right, bottom);
266 /* Draw a image of two partly overlapped tiny windows,
269 left += h_spacing;
270 top += v_spacing;
272 width -= h_spacing * 2;
273 height -= v_spacing * 2;
275 right = left + width - 1;
276 bottom = top + height - 1;
278 /* Render top left window */
280 SetAPen(rp, pens[SHADOWPEN]);
281 drawrect(rp, left, top, right - (width / 3 ), bottom - (height / 3), IntuitionBase);
283 /* Render bottom right window */
284 SetAPen(rp, pens[SHADOWPEN]);
285 drawrect(rp, left + (width / 3), top + (height / 3), right, bottom, IntuitionBase);
287 /* Fill bottom right window (inside of the frame above) */
288 SetAPen(rp, pens[SHINEPEN]);
289 RectFill(rp, left + (width / 3) + 1, top + (height / 3) + 1,
290 right - 1, bottom - 1);
293 if (state == IDS_SELECTED)
295 /* Re-Render top left window */
297 SetAPen(rp, pens[SHADOWPEN]);
298 drawrect(rp, left, top, right - (width / 3 ), bottom - (height / 3), IntuitionBase);
300 break;
303 default:
304 return FALSE;
307 return TRUE;
310 /**************************************************************************************************/
312 static void findtitlearea(struct Screen *scr, LONG *left, LONG *right)
314 struct Gadget *g;
316 *left = 0;
317 *right = scr->Width - 1;
319 for (g = scr->FirstGadget; g; g = g->NextGadget)
321 if (!(g->Flags & GFLG_RELRIGHT))
323 if (g->LeftEdge + g->Width > *left)
324 *left = g->LeftEdge + g->Width;
326 else
328 if (g->LeftEdge + scr->Width - 1 - 1 < *right)
329 *right = g->LeftEdge + scr->Width - 1 - 1;
335 /**************************************************************************************************/
337 IPTR ScrDecorClass__SDM_DRAW_SCREENBAR(Class *cl, Object *obj, struct sdpDrawScreenBar *msg)
339 struct scrdecor_data *data = INST_DATA(cl, obj);
340 struct RastPort *rp = msg->sdp_RPort;
341 UWORD *pens = DRI(msg->sdp_Dri)->dri_Pens;
342 LONG left, right;
343 BOOL beeping = FALSE;
345 #if 0
346 #if USE_NEWDISPLAYBEEP
347 beeping = (msg->sdp_Screen->Flags & BEEPING) && GetBitMapAttr(rp->BitMap, BMA_DEPTH) > 8;
348 #endif
349 #endif
351 SetDrMd(rp, JAM1);
353 SetAPen(rp, pens[beeping ? BARDETAILPEN : BARBLOCKPEN]);
354 RectFill(rp, 0, 0, msg->sdp_Screen->Width - 1, msg->sdp_Screen->BarHeight - 1);
356 SetAPen(rp, pens[beeping ? BARDETAILPEN : BARTRIMPEN]);
357 RectFill(rp, 0, msg->sdp_Screen->BarHeight, msg->sdp_Screen->Width - 1, msg->sdp_Screen->BarHeight);
359 findtitlearea(msg->sdp_Screen, &left, &right);
361 SetAPen(rp, pens[SHADOWPEN]);
362 RectFill(rp, right, 1, right, msg->sdp_Screen->BarHeight - 1);
364 return TRUE;
368 /**************************************************************************************************/
370 IPTR ScrDecorClass__SDM_DRAW_SCREENBAR(Class *cl, Object *obj, struct sdpDrawScreenBar *msg)
372 struct scrdecor_data *data = INST_DATA(cl, obj);
373 struct RastPort *rp = msg->sdp_RPort;
374 UWORD *pens = DRI(msg->sdp_Dri)->dri_Pens;
375 LONG right, left;
376 BOOL beeping = FALSE;
378 #if 0
379 #if USE_NEWDISPLAYBEEP
380 beeping = (msg->sdp_Screen->Flags & BEEPING) && GetBitMapAttr(rp->BitMap, BMA_DEPTH) > 8;
381 #endif
382 #endif
384 findtitlearea(msg->sdp_Screen, &left, &right);
386 SetDrMd(rp, JAM1);
388 SetAPen(rp, pens[beeping ? BARDETAILPEN : BARBLOCKPEN]);
389 RectFill(rp, left + 1, 0, right - 1, msg->sdp_Screen->BarHeight - 1);
391 SetAPen(rp, pens[beeping ? BARDETAILPEN : BARTRIMPEN]);
392 RectFill(rp, 0, msg->sdp_Screen->BarHeight, msg->sdp_Screen->Width - 1, msg->sdp_Screen->BarHeight);
394 SetAPen(rp, pens[beeping ? BARBLOCKPEN: BARDETAILPEN]);
395 SetBPen(rp, pens[beeping ? BARDETAILPEN : BARBLOCKPEN]);
397 Move(rp, msg->sdp_Screen->BarHBorder, msg->sdp_Screen->BarVBorder + rp->TxBaseline);
399 Text(rp, msg->sdp_Screen->Title, strlen(msg->sdp_Screen->Title));
401 return TRUE;
404 /**************************************************************************************************/
406 IPTR ScrDecorClass__SDM_LAYOUT_SCREENGADGETS(Class *cl, Object *obj, struct sdpLayoutScreenGadgets *msg)
408 struct Gadget *gadget = msg->sdp_Gadgets;
410 while(gadget)
412 switch(gadget->GadgetType & GTYP_SYSTYPEMASK)
414 case GTYP_SDEPTH:
415 gadget->LeftEdge = -gadget->Height + 1;
416 gadget->Width = gadget->Height;
417 gadget->Flags &= ~GFLG_RELWIDTH;
418 gadget->Flags |= GFLG_RELRIGHT;
419 break;
423 if (msg->sdp_Flags & SDF_LSG_MULTIPLE)
425 gadget = gadget->NextGadget;
427 else
429 gadget = NULL;
433 return TRUE;
436 IPTR ScrDecorClass__SDM_INITSCREEN(Class *cl, Object *obj, struct sdpInitScreen *msg)
438 return TRUE;
441 IPTR ScrDecorClass__SDM_EXITSCREEN(Class *cl, Object *obj, struct sdpExitScreen *msg)
443 return TRUE;
446 /**************************************************************************************************/