add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / asl / modereqhooks.c
blob8273d43480bbcaf6d255f4c7b9858f2239ce7adc
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 File requester specific code.
6 */
9 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <proto/utility.h>
12 #include <proto/intuition.h>
13 #include <proto/graphics.h>
14 #include <proto/gadtools.h>
15 #include <exec/memory.h>
16 #include <dos/dos.h>
17 #include <intuition/screens.h>
18 #include <intuition/icclass.h>
19 #include <intuition/gadgetclass.h>
20 #include <graphics/displayinfo.h>
21 #include <graphics/modeid.h>
22 #include <graphics/monitor.h>
23 #include <graphics/gfx.h>
24 #include <devices/rawkeycodes.h>
25 #include <libraries/gadtools.h>
26 #include <workbench/startup.h>
27 #include <string.h>
28 #include <stdio.h>
30 #include "asl_intern.h"
31 #include "modereqhooks.h"
32 #include "modereqsupport.h"
33 #include "layout.h"
35 #if USE_SHARED_COOLIMAGES
36 #include <libraries/coolimages.h>
37 #include <proto/coolimages.h>
38 #else
39 #include "coolimages.h"
40 #endif
42 #define CATCOMP_NUMBERS
43 #include "strings.h"
45 #define SDEBUG 0
46 #define DEBUG 0
48 #include <aros/debug.h>
50 /*****************************************************************************************/
52 STATIC BOOL SMGadInit(struct LayoutData *, struct AslBase_intern *);
53 STATIC VOID SMWindowOpened(struct LayoutData *, struct AslBase_intern *);
54 STATIC BOOL SMGadLayout(struct LayoutData *, struct AslBase_intern *);
55 STATIC VOID SMGadCleanup(struct LayoutData *, struct AslBase_intern *);
56 STATIC ULONG SMHandleEvents(struct LayoutData *, struct AslBase_intern *);
57 STATIC ULONG SMGetSelectedMode(struct LayoutData *, struct AslBase_intern *AslBase);
59 /*****************************************************************************************/
61 #define ID_BUTOK ID_MAINBUTTON_OK
62 #define ID_BUTCANCEL ID_MAINBUTTON_CANCEL
64 #define ID_LISTVIEW 1
65 #define ID_OVERSCAN 2
66 #define ID_WIDTH 3
67 #define ID_HEIGHT 4
68 #define ID_COLORS 5
69 #define ID_AUTOSCROLL 6
71 #undef NUMBUTS
72 #define NUMBUTS 2L
74 #define CLASS_ASLBASE ((struct AslBase_intern *)cl->cl_UserData)
75 #define HOOK_ASLBASE ((struct AslBase_intern *)hook->h_Data)
78 /*****************************************************************************************/
80 AROS_UFH3(VOID, SMTagHook,
81 AROS_UFHA(struct Hook *, hook, A0),
82 AROS_UFHA(struct ParseTagArgs *, pta, A2),
83 AROS_UFHA(struct AslBase_intern *, AslBase, A1)
86 AROS_USERFUNC_INIT
88 struct TagItem *tag;
89 const struct TagItem *tstate;
90 struct IntSMReq *ismreq;
92 EnterFunc(bug("SMTagHook(hook=%p, pta=%p)\n", hook, pta));
94 ismreq = (struct IntSMReq *)pta->pta_IntReq;
96 tstate = pta->pta_Tags;
97 while ((tag = NextTagItem(&tstate)) != NULL)
99 IPTR tidata = tag->ti_Data;
101 switch (tag->ti_Tag)
103 case ASLSM_CustomSMList:
104 ismreq->ism_CustomSMList = (struct List *)tidata;
105 break;
107 case ASLSM_FilterFunc:
108 ismreq->ism_FilterFunc = (struct Hook *)tidata;
109 break;
111 case ASLSM_DoAutoScroll:
112 if (tidata)
113 ismreq->ism_Flags |= ISMF_DOAUTOSCROLL;
114 else
115 ismreq->ism_Flags &= ~ISMF_DOAUTOSCROLL;
116 break;
118 case ASLSM_DoDepth:
119 if (tidata)
120 ismreq->ism_Flags |= ISMF_DODEPTH;
121 else
122 ismreq->ism_Flags &= ~ISMF_DODEPTH;
123 break;
125 case ASLSM_DoWidth:
126 if (tidata)
127 ismreq->ism_Flags |= ISMF_DOWIDTH;
128 else
129 ismreq->ism_Flags &= ~ISMF_DOWIDTH;
130 break;
132 case ASLSM_DoHeight:
133 if (tidata)
134 ismreq->ism_Flags |= ISMF_DOHEIGHT;
135 else
136 ismreq->ism_Flags &= ~ISMF_DOHEIGHT;
137 break;
139 case ASLSM_DoOverscanType:
140 if (tidata)
141 ismreq->ism_Flags |= ISMF_DOOVERSCAN;
142 else
143 ismreq->ism_Flags &= ~ISMF_DOOVERSCAN;
144 break;
146 case ASLSM_UserData:
147 ((struct ScreenModeRequester *)pta->pta_Req)->sm_UserData = (APTR)tidata;
148 break;
150 case ASLSM_InitialAutoScroll:
151 ismreq->ism_AutoScroll = tidata ? TRUE : FALSE;
152 break;
154 case ASLSM_InitialDisplayDepth:
155 ismreq->ism_DisplayDepth = tidata;
156 break;
158 case ASLSM_InitialDisplayWidth:
159 ismreq->ism_DisplayWidth = tidata;
160 break;
162 case ASLSM_InitialDisplayHeight:
163 ismreq->ism_DisplayHeight = tidata;
164 break;
166 case ASLSM_InitialDisplayID:
167 ismreq->ism_DisplayID = tidata;
168 break;
170 case ASLSM_InitialInfoLeftEdge:
171 ismreq->ism_InfoLeftEdge = tidata;
172 break;
174 case ASLSM_InitialInfoTopEdge:
175 ismreq->ism_InfoTopEdge = tidata;
176 break;
178 case ASLSM_InitialInfoOpened:
179 ismreq->ism_InfoOpened = tidata ? TRUE : FALSE;
180 break;
182 case ASLSM_InitialOverscanType:
183 ismreq->ism_OverscanType = (((LONG)tidata >= OSCAN_TEXT) &&
184 ((LONG)tidata <= OSCAN_VIDEO)) ? tidata: OSCAN_TEXT;
185 break;
187 case ASLSM_MinWidth:
188 ismreq->ism_MinWidth = tidata;
189 break;
191 case ASLSM_MaxWidth:
192 ismreq->ism_MaxWidth = tidata;
193 break;
195 case ASLSM_MinHeight:
196 ismreq->ism_MinHeight = tidata;
197 break;
199 case ASLSM_MaxHeight:
200 ismreq->ism_MaxHeight = tidata;
201 break;
203 case ASLSM_MinDepth:
204 ismreq->ism_MinDepth = tidata;
205 break;
207 case ASLSM_MaxDepth:
208 ismreq->ism_MaxDepth = tidata;
209 break;
211 case ASLSM_PropertyFlags:
212 ismreq->ism_PropertyFlags = tidata;
213 break;
215 case ASLSM_PropertyMask:
216 ismreq->ism_PropertyMask = tidata;
217 break;
219 default:
220 break;
222 } /* switch (tag->ti_Tag) */
224 } /* while ((tag = NextTagItem(&tstate)) != 0) */
226 if (ismreq->ism_MinDepth < 1) ismreq->ism_MinDepth = 1;
228 if (ismreq->ism_MaxDepth < ismreq->ism_MinDepth)
229 ismreq->ism_MaxDepth = ismreq->ism_MinDepth;
231 if (ismreq->ism_DisplayDepth < ismreq->ism_MinDepth)
232 ismreq->ism_DisplayDepth = ismreq->ism_MinDepth;
234 if (ismreq->ism_DisplayDepth > ismreq->ism_MaxDepth)
235 ismreq->ism_DisplayDepth = ismreq->ism_MaxDepth;
237 ReturnVoid("SMTagHook");
239 AROS_USERFUNC_EXIT
242 /*****************************************************************************************/
244 AROS_UFH3(ULONG, SMGadgetryHook,
245 AROS_UFHA(struct Hook *, hook, A0),
246 AROS_UFHA(struct LayoutData *, ld, A2),
247 AROS_UFHA(struct AslBase_intern *, AslBase, A1)
250 AROS_USERFUNC_INIT
252 ULONG retval;
254 switch (ld->ld_Command)
256 case LDCMD_INIT:
257 retval = (ULONG)SMGadInit(ld, ASLB(AslBase));
258 break;
260 case LDCMD_WINDOWOPENED:
261 SMWindowOpened(ld, ASLB(AslBase));
262 break;
264 case LDCMD_LAYOUT:
265 retval = (ULONG)SMGadLayout(ld, ASLB(AslBase));
266 break;
268 case LDCMD_HANDLEEVENTS:
269 retval = (ULONG)SMHandleEvents(ld, ASLB(AslBase));
270 break;
272 case LDCMD_CLEANUP:
273 SMGadCleanup(ld, ASLB(AslBase));
274 retval = GHRET_OK;
275 break;
277 default:
278 retval = GHRET_FAIL;
279 break;
282 return (retval);
284 AROS_USERFUNC_EXIT
287 /*****************************************************************************************/
289 struct ButtonInfo
291 WORD gadid;
292 STRPTR text;
293 LONG deftextid;
294 #if USE_SHARED_COOLIMAGES
295 ULONG coolid;
296 Object **objvar;
297 const struct CoolImage *coolimage;
298 #else
299 const struct CoolImage *coolimage;
300 Object **objvar;
301 #endif
304 /*****************************************************************************************/
306 STATIC BOOL SMGadInit(struct LayoutData *ld, struct AslBase_intern *AslBase)
308 struct SMUserData *udata = ld->ld_UserData;
309 struct IntSMReq *ismreq = (struct IntSMReq *)ld->ld_IntReq;
310 STRPTR str[6];
311 #if USE_SHARED_COOLIMAGES
312 struct ButtonInfo bi[NUMBUTS] =
314 { ID_BUTOK , GetIR(ismreq)->ir_PositiveText , MSG_MODEREQ_POSITIVE_GAD, COOL_MONITORIMAGE_ID, &udata->OKBut },
315 { ID_BUTCANCEL , GetIR(ismreq)->ir_NegativeText , MSG_MODEREQ_NEGATIVE_GAD, COOL_CANCELIMAGE_ID , &udata->CancelBut }
317 #else
318 struct ButtonInfo bi[NUMBUTS] =
320 { ID_BUTOK , GetIR(ismreq)->ir_PositiveText , MSG_MODEREQ_POSITIVE_GAD, &cool_monitorimage, &udata->OKBut },
321 { ID_BUTCANCEL , GetIR(ismreq)->ir_NegativeText , MSG_MODEREQ_NEGATIVE_GAD, &cool_cancelimage , &udata->CancelBut }
323 #endif
324 Object *gad;
325 LONG error;
326 WORD gadrows, x, y, w, h, i, y2;
327 WORD labelwidth = 0, maxcyclewidth = 0;
330 NEWLIST(&udata->ListviewList);
332 error = SMGetModes(ld, AslBase);
333 if (error) goto failure;
335 error = ERROR_NO_FREE_STORE;
337 /* calc. min. size */
339 w = 0;
340 for(i = 0; i < NUMBUTS; i++)
342 if(!bi[i].text) bi[i].text = GetString(bi[i].deftextid, GetIR(ismreq)->ir_Catalog, AslBase);
344 x = TextLength(&ld->ld_DummyRP, bi[i].text, strlen(bi[i].text));
346 #if SREQ_COOL_BUTTONS
347 #if USE_SHARED_COOLIMAGES
348 if (CoolImagesBase)
350 bi[i].coolimage = (const struct CoolImage *)COOL_ObtainImageA(bi[i].coolid, NULL);
353 if (CoolImagesBase)
354 #endif
355 if (ld->ld_TrueColor)
357 x += IMAGEBUTTONEXTRAWIDTH + bi[i].coolimage->width;
359 #endif
361 if (x > w) w = x;
364 udata->ButWidth = w + BUTTONEXTRAWIDTH;
366 ld->ld_ButWidth = udata->ButWidth;
367 ld->ld_NumButtons = 4;
369 #if SREQ_COOL_BUTTONS
371 #if USE_SHARED_COOLIMAGES
372 if (CoolImagesBase)
374 #endif
375 y = BUTTONEXTRAHEIGHT + ld->ld_Font->tf_YSize;
376 if (ld->ld_TrueColor)
378 y2 = IMAGEBUTTONEXTRAHEIGHT + DEF_COOLIMAGEHEIGHT;
379 } else {
380 y2 = 0;
382 udata->ButHeight = (y > y2) ? y : y2;
383 #if USE_SHARED_COOLIMAGES
385 else
387 udata->ButHeight = BUTTONEXTRAHEIGHT + ld->ld_Font->tf_YSize;
389 #endif
391 #else
392 udata->ButHeight = BUTTONEXTRAHEIGHT + ld->ld_Font->tf_YSize;
393 #endif
395 gadrows = 1; /* button row */
396 if (ismreq->ism_Flags & ISMF_DOOVERSCAN) gadrows++;
397 if (ismreq->ism_Flags & ISMF_DOWIDTH) gadrows++;
398 if (ismreq->ism_Flags & ISMF_DOHEIGHT) gadrows++;
399 if (ismreq->ism_Flags & ISMF_DODEPTH) gadrows++;
400 if (ismreq->ism_Flags & ISMF_DOAUTOSCROLL) gadrows++;
402 ld->ld_MinWidth = OUTERSPACINGX * 2 +
403 GADGETSPACINGX * 1 +
404 udata->ButWidth * NUMBUTS;
406 ld->ld_MinHeight = OUTERSPACINGY * 2 +
407 (GADGETSPACINGY + udata->ButHeight) * gadrows +
408 BORDERLVSPACINGY * 2 +
409 (ld->ld_Font->tf_YSize + BORDERLVITEMSPACINGY * 2) * SREQ_MIN_VISIBLELINES;
411 /* make listview gadget */
413 x = ld->ld_WBorLeft + OUTERSPACINGX;
414 y = ld->ld_WBorTop + OUTERSPACINGY;
415 w = -ld->ld_WBorRight - ld->ld_WBorLeft - OUTERSPACINGX * 2 - PROPSIZE;
416 h = -ld->ld_WBorBottom - ld->ld_WBorTop - OUTERSPACINGY * 2 -
417 udata->ButHeight * gadrows -
418 GADGETSPACINGY * gadrows;
421 struct TagItem lv_tags[] =
423 {GA_Left , x },
424 {GA_Top , y },
425 {GA_RelWidth , w },
426 {GA_RelHeight , h },
427 {GA_UserData , (IPTR)ld },
428 {GA_ID , ID_LISTVIEW },
429 {GA_RelVerify , TRUE },
430 {ASLLV_Labels , (IPTR)&udata->ListviewList },
431 {ASLLV_Font , (IPTR)ld->ld_Font },
432 {TAG_DONE }
435 udata->Listview = gad = NewObjectA(AslBase->asllistviewclass, NULL, lv_tags);
436 if (!udata->Listview) goto failure;
440 /* make scroller gadget for listview */
442 x = -ld->ld_WBorRight - OUTERSPACINGX - PROPSIZE + 1;
443 y = ld->ld_WBorTop + OUTERSPACINGY;
444 w = PROPSIZE;
445 h = -ld->ld_WBorBottom - ld->ld_WBorTop - OUTERSPACINGY * 2 -
446 udata->ButHeight * gadrows -
447 GADGETSPACINGY * gadrows;
449 struct TagItem scroller_tags[] =
451 {GA_RelRight , x },
452 {GA_Top , y },
453 {GA_Width , w },
454 {GA_RelHeight , h },
455 {GA_ID , ID_LISTVIEW },
456 {PGA_NewLook , TRUE },
457 {PGA_Borderless , TRUE },
458 {PGA_Freedom , FREEVERT },
459 {PGA_Top , 0 },
460 {PGA_Total , 20 },
461 {PGA_Visible , 1 },
462 {GA_Previous , (IPTR)gad },
463 {TAG_DONE }
466 if (!makescrollergadget(&udata->ScrollGad, ld, scroller_tags, AslBase)) goto failure;
467 gad = udata->ScrollGad.arrow2;
470 connectscrollerandlistview(&udata->ScrollGad, udata->Listview, AslBase);
472 /* make button row */
474 y = -ld->ld_WBorBottom - OUTERSPACINGY - udata->ButHeight + 1;
477 struct TagItem button_tags[] =
479 {GA_Text , 0 },
480 {GA_Previous , 0 },
481 {GA_ID , 0 },
482 #if SREQ_COOL_BUTTONS
483 {ASLBT_CoolImage , 0 },
484 #else
485 {TAG_IGNORE , 0 },
486 #endif
487 {GA_UserData , (IPTR)ld },
488 {GA_Left , 0 },
489 {GA_RelBottom , y },
490 {GA_Width , udata->ButWidth },
491 {GA_Height , udata->ButHeight },
492 {GA_RelVerify , TRUE },
493 {GA_Image , 0 }, /* means we want a frame */
494 {TAG_DONE }
497 for(i = 0; i < NUMBUTS; i++)
499 button_tags[0].ti_Data = (IPTR)bi[i].text;
500 button_tags[1].ti_Data = (IPTR)gad;
501 button_tags[2].ti_Data = bi[i].gadid;
503 #if USE_SHARED_COOLIMAGES
504 if (CoolImagesBase == NULL) button_tags[3].ti_Tag = TAG_IGNORE;
505 #endif
506 button_tags[3].ti_Data = (IPTR)bi[i].coolimage;
508 *(bi[i].objvar) = gad = NewObjectA(AslBase->aslbuttonclass, NULL, button_tags);
509 if (!gad) goto failure;
514 /* make labels */
516 if (ismreq->ism_Flags & (ISMF_DOOVERSCAN | ISMF_DOWIDTH | ISMF_DOHEIGHT | ISMF_DODEPTH | ISMF_DOAUTOSCROLL))
518 #define FSET(x) ((ismreq->ism_Flags & x) ? TRUE : FALSE)
520 struct LabelInfo
522 BOOL doit;
523 STRPTR text;
524 Object **objvar;
525 } li [] =
527 {FSET(ISMF_DOOVERSCAN) , (STRPTR)MSG_MODEREQ_OVERSCAN_LABEL , &udata->OverscanLabel },
528 {FSET(ISMF_DOWIDTH) , (STRPTR)MSG_MODEREQ_WIDTH_LABEL , &udata->WidthLabel },
529 {FSET(ISMF_DOHEIGHT) , (STRPTR)MSG_MODEREQ_HEIGHT_LABEL , &udata->HeightLabel },
530 {FSET(ISMF_DODEPTH) , (STRPTR)MSG_MODEREQ_COLORS_LABEL , &udata->DepthLabel },
531 {FSET(ISMF_DOAUTOSCROLL), (STRPTR)MSG_MODEREQ_AUTOSCROLL_LABEL, &udata->AutoScrollLabel}
534 #undef FSET
536 struct TagItem label_tags[] =
538 {GA_Left , 0 },
539 {GA_RelBottom , 0 },
540 {GA_Width , 0 },
541 {GA_Height , udata->ButHeight },
542 {GA_Text , 0 },
543 {GA_Previous , (IPTR)gad },
544 {GA_UserData , (IPTR)ld },
545 {GA_Disabled , TRUE },
546 {TAG_DONE }
548 WORD i2;
550 for(i = 0, i2 = 0; i < 5; i++)
552 if (li[i].doit)
554 li[i].text = GetString((LONG)li[i].text, GetIR(ismreq)->ir_Catalog, AslBase);
555 str[i2++] = li[i].text;
559 x = ld->ld_WBorLeft + OUTERSPACINGX;
560 y = -ld->ld_WBorBottom - OUTERSPACINGY - udata->ButHeight -
561 (udata->ButHeight + GADGETSPACINGY) * (gadrows - 1) + 1;
564 w = labelwidth = BiggestTextLength(str, i2, &(ld->ld_DummyRP), AslBase);
566 label_tags[1].ti_Data = y;
568 for(i = 0; i < 5;i++)
570 if (!li[i].doit) continue;
572 label_tags[2].ti_Data = TextLength(&ld->ld_DummyRP, li[i].text, strlen(li[i].text));
573 label_tags[0].ti_Data = x + w - label_tags[2].ti_Data;
574 label_tags[4].ti_Data = (IPTR)li[i].text;
575 label_tags[5].ti_Data = (IPTR)gad;
577 *(li[i].objvar) = gad = NewObjectA(AslBase->aslbuttonclass, NULL, label_tags);
578 if (!gad) goto failure;
580 y += udata->ButHeight + GADGETSPACINGY;
581 label_tags[1].ti_Data = y;
584 y = -ld->ld_WBorBottom - OUTERSPACINGY - udata->ButHeight -
585 (udata->ButHeight + GADGETSPACINGY) * (gadrows - 1) + 1;
586 x = ld->ld_WBorLeft + OUTERSPACINGX + w + LABELSPACINGX;
588 w = -ld->ld_WBorLeft - ld->ld_WBorRight - OUTERSPACINGX * 2 -
589 w - LABELSPACINGX;
591 /* Make Overscan gadget */
593 if (ismreq->ism_Flags & ISMF_DOOVERSCAN)
595 struct TagItem cycle_tags[] =
597 {GA_Previous , (IPTR)gad },
598 {GA_Left , x },
599 {GA_RelBottom , y },
600 {GA_RelWidth , w },
601 {GA_Height , udata->ButHeight },
602 {GA_RelVerify , TRUE },
603 {GA_UserData , (IPTR)ld },
604 {GA_ID , ID_OVERSCAN },
605 {ASLCY_Labels , (IPTR)&ismreq->ism_Overscan1Text},
606 {ASLCY_Active , ismreq->ism_OverscanType - 1 },
607 {ASLCY_Font , (IPTR)ld->ld_Font },
608 {TAG_DONE }
611 static LONG labelids[] =
613 MSG_MODEREQ_OVERSCAN_TEXT,
614 MSG_MODEREQ_OVERSCAN_GRAPHICS,
615 MSG_MODEREQ_OVERSCAN_EXTREME,
616 MSG_MODEREQ_OVERSCAN_MAXIMUM,
619 STRPTR *labels = (STRPTR *)&ismreq->ism_Overscan1Text;
621 for(i = 0; i < 4; i++)
623 labels[i] = GetString(labelids[i], GetIR(ismreq)->ir_Catalog, AslBase);
626 i = CYCLEEXTRAWIDTH + BiggestTextLength(&ismreq->ism_Overscan1Text,
628 &(ld->ld_DummyRP),
629 AslBase);
630 if (i > maxcyclewidth) maxcyclewidth = i;
632 udata->OverscanGadget = gad = NewObjectA(AslBase->aslcycleclass, NULL, cycle_tags);
633 if (!gad) goto failure;
635 y += udata->ButHeight + GADGETSPACINGY;
637 } /* if (ismreq->ism_Flags & ISMF_DOOVERSCAN) */
640 struct TagItem string_tags[] =
642 {GA_Previous , (IPTR)gad },
643 {GA_ID , ID_WIDTH },
644 {STRINGA_LongVal , ismreq->ism_DisplayWidth },
645 {GA_RelBottom , y },
646 {GA_Left , x },
647 {GA_RelWidth , w },
648 {GA_Height , udata->ButHeight },
649 {GA_RelVerify , TRUE },
650 {GA_UserData , (IPTR)ld },
651 {GA_TabCycle , TRUE },
652 {STRINGA_MaxChars , 8 },
653 {STRINGA_Font , (IPTR)ld->ld_Font },
654 {TAG_DONE }
657 /* Make width gadget */
659 if (ismreq->ism_Flags & ISMF_DOWIDTH)
661 udata->WidthGadget = gad = NewObjectA(AslBase->aslstringclass, NULL, string_tags);
662 if (!gad) goto failure;
664 y += udata->ButHeight + GADGETSPACINGY;
667 /* Make height gadget */
669 if (ismreq->ism_Flags & ISMF_DOHEIGHT)
671 string_tags[0].ti_Data = (IPTR)gad;
672 string_tags[1].ti_Data = ID_HEIGHT;
673 string_tags[2].ti_Data = ismreq->ism_DisplayHeight;
674 string_tags[3].ti_Data = y;
676 udata->HeightGadget = gad = NewObjectA(AslBase->aslstringclass, NULL, string_tags);
677 if (!gad) goto failure;
679 y += udata->ButHeight + GADGETSPACINGY;
684 struct TagItem cycle_tags[] =
686 {GA_Previous , (IPTR)gad },
687 {GA_ID , ID_COLORS },
688 {ASLCY_Labels , 0 },
689 {ASLCY_Active , 0 },
690 {GA_RelBottom , y },
691 {GA_Left , x },
692 {GA_RelWidth , w },
693 {GA_Height , udata->ButHeight },
694 {GA_RelVerify , TRUE },
695 {GA_UserData , (IPTR)ld },
696 {ASLCY_Font , (IPTR)ld->ld_Font },
697 {TAG_DONE }
701 /* Make Colors gadget */
703 if (ismreq->ism_Flags & ISMF_DODEPTH)
705 i = CYCLEEXTRAWIDTH + TextLength(&ld->ld_DummyRP, "16777216", 8);
706 if (i > maxcyclewidth) maxcyclewidth = i;
708 udata->DepthGadget = gad = NewObjectA(AslBase->aslcycleclass, NULL, cycle_tags);
709 if (!gad) goto failure;
711 y += udata->ButHeight + GADGETSPACINGY;
714 /* Make AutoScroll gadget */
716 if (ismreq->ism_Flags & ISMF_DOAUTOSCROLL)
718 cycle_tags[0].ti_Data = (IPTR)gad;
719 cycle_tags[1].ti_Data = ID_AUTOSCROLL;
720 cycle_tags[2].ti_Data = (IPTR)&ismreq->ism_AutoScrollOFFText;
721 cycle_tags[3].ti_Data = ismreq->ism_AutoScroll;
722 cycle_tags[4].ti_Data = y;
724 ismreq->ism_AutoScrollOFFText = GetString(MSG_MODEREQ_AUTOSCROLL_OFF, GetIR(ismreq)->ir_Catalog, AslBase);
725 ismreq->ism_AutoScrollONText = GetString(MSG_MODEREQ_AUTOSCROLL_ON , GetIR(ismreq)->ir_Catalog, AslBase);
727 i = CYCLEEXTRAWIDTH + BiggestTextLength(&ismreq->ism_AutoScrollOFFText,
729 &(ld->ld_DummyRP),
730 AslBase);
731 if (i > maxcyclewidth) maxcyclewidth = i;
733 udata->AutoScrollGadget = gad = NewObjectA(AslBase->aslcycleclass, NULL, cycle_tags);
734 if (!gad) goto failure;
736 y += udata->ButHeight + GADGETSPACINGY;
741 } /* if (ismreq->ism_Flags & (ISMF_DOOVERSCAN | ISMF_DOWIDTH | ISMF_DOHEIGHT | ISMF_DODEPTH | ISMF_DOAUTOSCROLL)) */
743 #if AVOID_FLICKER
745 struct TagItem eraser_tags[] =
747 {GA_Previous, (IPTR)gad},
748 {TAG_DONE}
751 udata->EraserGadget = gad = NewObjectA(AslBase->asleraserclass, NULL, eraser_tags);
752 /* Doesn't matter if this failed */
754 #endif
756 w = OUTERSPACINGX + labelwidth + LABELSPACINGX + maxcyclewidth + OUTERSPACINGX;
757 if (w > ld->ld_MinWidth) ld->ld_MinWidth = w;
759 ld->ld_GList = (struct Gadget *)udata->Listview;
761 /* Menus */
763 struct NewMenu nm[] =
765 {NM_TITLE, (STRPTR)MSG_MODEREQ_MEN_CONTROL },
766 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_LASTMODE , 0, 0, 0, (APTR)SMMEN_LASTMODE },
767 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_NEXTMODE , 0, 0, 0, (APTR)SMMEN_NEXTMODE },
768 {NM_ITEM, NM_BARLABEL },
769 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_PROPERTIES , 0, 0, 0, (APTR)SMMEN_PROPERTYLIST },
770 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_RESTORE , 0, 0, 0, (APTR)SMMEN_RESTORE },
771 {NM_ITEM, NM_BARLABEL },
772 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_OK , 0, 0, 0, (APTR)SMMEN_OK },
773 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_CANCEL , 0, 0, 0, (APTR)SMMEN_CANCEL },
774 {NM_END }
777 struct TagItem menu_tags[] =
779 {GTMN_NewLookMenus , TRUE },
780 {GTMN_TextAttr , (IPTR)GetIR(ismreq)->ir_TextAttr },
781 {TAG_DONE }
784 if (menu_tags[1].ti_Data == 0) menu_tags[1].ti_Tag = TAG_IGNORE;
786 LocalizeMenus(nm, GetIR(ismreq)->ir_Catalog, AslBase);
788 /* Don't fail, if menus cannot be created/layouted, because a requester
789 without menus is still better than no requester at all */
791 if ((ld->ld_Menu = CreateMenusA(nm, NULL)))
793 if (!LayoutMenusA(ld->ld_Menu, ld->ld_VisualInfo, menu_tags))
795 FreeMenus(ld->ld_Menu);ld->ld_Menu = NULL;
800 SMRestore(ld, AslBase);
802 SetIoErr(0);
803 ReturnBool ("SMGadInit", TRUE);
805 failure:
806 SetIoErr(error);
808 D(bug("failure\n"));
810 SMGadCleanup(ld, ASLB(AslBase));
812 ReturnBool ("SMGadInit", FALSE);
816 /*****************************************************************************************/
818 STATIC VOID SMWindowOpened(struct LayoutData *ld, struct AslBase_intern *AslBase)
820 struct IntSMReq *ismreq = (struct IntSMReq *)ld->ld_IntReq;
822 if (ismreq->ism_InfoOpened)
824 SMOpenPropertyWindow(ld, AslBase);
828 /*****************************************************************************************/
830 STATIC BOOL SMGadLayout(struct LayoutData *ld, struct AslBase_intern *AslBase)
832 ReturnBool ("SMGadLayout", TRUE );
835 /*****************************************************************************************/
837 STATIC ULONG SMHandleEvents(struct LayoutData *ld, struct AslBase_intern *AslBase)
839 struct IntuiMessage *imsg = ld->ld_Event;
840 struct SMUserData *udata = (struct SMUserData *)ld->ld_UserData;
841 WORD gadid;
842 ULONG retval = GHRET_OK;
844 EnterFunc(bug("SMHandleEvents: Class: %d\n", imsg->Class));
846 if (imsg->IDCMPWindow == ld->ld_Window2)
848 return SMHandlePropertyEvents(ld, imsg, AslBase);
851 switch (imsg->Class)
853 case IDCMP_CLOSEWINDOW:
854 retval = FALSE;
855 break;
857 case IDCMP_RAWKEY:
858 switch (imsg->Code)
860 case CURSORUP:
861 SMChangeActiveLVItem(ld, -1, imsg->Qualifier, AslBase);
862 break;
864 case RAWKEY_PAGEUP:
865 SMChangeActiveLVItem(ld, -1, IEQUALIFIER_LSHIFT, AslBase);
866 break;
868 case RAWKEY_HOME:
869 SMChangeActiveLVItem(ld, -1, IEQUALIFIER_LALT, AslBase);
870 break;
872 case RAWKEY_NM_WHEEL_UP:
873 SMChangeActiveLVItem(ld, -3, imsg->Qualifier, AslBase);
874 break;
876 case CURSORDOWN:
877 SMChangeActiveLVItem(ld, 1, imsg->Qualifier, AslBase);
878 break;
880 case RAWKEY_PAGEDOWN:
881 SMChangeActiveLVItem(ld, 1, IEQUALIFIER_LSHIFT, AslBase);
882 break;
884 case RAWKEY_END:
885 SMChangeActiveLVItem(ld, 1, IEQUALIFIER_LALT, AslBase);
886 break;
888 case RAWKEY_NM_WHEEL_DOWN:
889 SMChangeActiveLVItem(ld, 3, imsg->Qualifier, AslBase);
890 break;
892 break;
894 case IDCMP_VANILLAKEY:
895 switch(imsg->Code)
897 case 27:
898 retval = FALSE;
899 break;
901 break;
903 case IDCMP_GADGETUP:
904 gadid = ((struct Gadget *)imsg->IAddress)->GadgetID;
906 D(bug("GADGETUP! gadgetid=%d\n", gadid));
908 switch (gadid)
910 case ID_BUTCANCEL:
911 retval = FALSE;
912 break;
914 case ID_BUTOK:
915 retval = SMGetSelectedMode(ld, AslBase);
916 break;
918 case ID_LISTVIEW:
920 struct DisplayMode *dispmode;
921 IPTR active;
923 GetAttr(ASLLV_Active, udata->Listview, &active);
925 if ((dispmode = (struct DisplayMode *)FindListNode(&udata->ListviewList, (WORD)active)))
927 SMActivateMode(ld, active, 0, AslBase);
929 if (imsg->Code) /* TRUE if double clicked */
931 retval = SMGetSelectedMode(ld, AslBase);
935 break;
937 case ID_OVERSCAN:
938 SMChangeActiveLVItem(ld, 0, 0, AslBase);
939 break;
941 case ID_WIDTH:
943 struct DisplayMode *dispmode;
944 LONG width;
946 dispmode = SMGetActiveMode(ld, AslBase);
947 ASSERT_VALID_PTR(dispmode);
949 width = SMGetWidth (ld, AslBase);
951 SMFixValues(ld, dispmode, &width, 0, 0, AslBase);
953 break;
955 case ID_HEIGHT:
957 struct DisplayMode *dispmode;
958 LONG height;
960 dispmode = SMGetActiveMode(ld, AslBase);
961 ASSERT_VALID_PTR(dispmode);
963 height = SMGetWidth (ld, AslBase);
965 SMFixValues(ld, dispmode, 0, &height, 0, AslBase);
967 break;
969 } /* switch (gadget ID) */
971 break; /* case IDCMP_GADGETUP: */
973 case IDCMP_MENUPICK:
974 if (ld->ld_Menu)
976 UWORD men = imsg->Code;
978 while(men != MENUNULL)
980 struct MenuItem *item;
982 if ((item = ItemAddress(ld->ld_Menu, men)))
984 switch((IPTR)GTMENUITEM_USERDATA(item))
986 /* Control menu */
988 case SMMEN_LASTMODE:
989 SMChangeActiveLVItem(ld, -1, 0, AslBase);
990 break;
992 case SMMEN_NEXTMODE:
993 SMChangeActiveLVItem(ld, 1, 0, AslBase);
994 break;
996 case SMMEN_PROPERTYLIST:
997 if (ld->ld_Window2)
999 SMClosePropertyWindow(ld, AslBase);
1000 } else {
1001 SMOpenPropertyWindow(ld, AslBase);
1003 break;
1005 case SMMEN_RESTORE:
1006 SMRestore(ld, AslBase);
1007 break;
1009 case SMMEN_OK:
1010 retval = SMGetSelectedMode(ld, AslBase);
1011 break;
1013 case SMMEN_CANCEL:
1014 retval = FALSE;
1015 break;
1017 } /* switch id */
1019 men = item->NextSelect;
1020 } /* if ((item = ItemAddress(ld->ld_Menu, men))) */
1021 else
1023 men = MENUNULL;
1026 } /* while(men != MENUNULL) */
1028 } /* if (ld->ld_Menu) */
1030 break; /* case IDCMP_MENUPICK: */
1032 } /* switch (imsg->Class) */
1034 ReturnInt ("SMHandleEvents", ULONG, retval);
1037 /*****************************************************************************************/
1039 STATIC VOID SMGadCleanup(struct LayoutData *ld, struct AslBase_intern *AslBase)
1041 struct SMUserData *udata = (struct SMUserData *)ld->ld_UserData;
1042 struct ScreenModeRequester *req = (struct ScreenModeRequester *)ld->ld_Req;
1043 struct IntReq *intreq = ld->ld_IntReq;
1044 struct IntSMReq *ismreq = (struct IntSMReq *)intreq;
1046 EnterFunc(bug("SMGadCleanup(ld=%p)\n", ld));
1048 if (ld->ld_Window && ld->ld_GList)
1050 RemoveGList(ld->ld_Window, ld->ld_GList, -1);
1053 killscrollergadget(&udata->ScrollGad, AslBase);
1055 FreeObjects(&SREQ_FIRST_OBJECT(udata), &SREQ_LAST_OBJECT(udata), AslBase);
1057 req->sm_InfoOpened = ismreq->ism_InfoOpened = ld->ld_Window2 ? TRUE : FALSE;
1059 if (ld->ld_Window)
1061 req->sm_LeftEdge = intreq->ir_LeftEdge = ld->ld_Window->LeftEdge;
1062 req->sm_TopEdge = intreq->ir_TopEdge = ld->ld_Window->TopEdge;
1063 req->sm_Width = intreq->ir_Width = ld->ld_Window->Width;
1064 req->sm_Height = intreq->ir_Height = ld->ld_Window->Height;
1066 req->sm_InfoLeftEdge = ismreq->ism_InfoLeftEdge;
1067 req->sm_InfoTopEdge = ismreq->ism_InfoTopEdge;
1069 if (ld->ld_Window2) /* can only be open if ld->ld_Window is open, too */
1071 req->sm_InfoWidth = ld->ld_Window2->Width;
1072 req->sm_InfoHeight = ld->ld_Window2->Height;
1074 SMClosePropertyWindow(ld, AslBase);
1078 ReturnVoid("SMGadCleanup");
1081 /*****************************************************************************************/
1083 STATIC ULONG SMGetSelectedMode(struct LayoutData *ld, struct AslBase_intern *AslBase)
1085 /*struct SMUserData *udata = (struct SMUserData *)ld->ld_UserData; */
1086 struct IntReq *intreq = ld->ld_IntReq;
1087 struct IntSMReq *ismreq = (struct IntSMReq *)intreq;
1088 struct ScreenModeRequester *req = (struct ScreenModeRequester *)ld->ld_Req;
1089 struct DisplayMode *dispmode;
1090 struct Rectangle *rect;
1091 LONG width, height;
1093 dispmode = SMGetActiveMode(ld, AslBase);
1094 ASSERT_VALID_PTR(dispmode);
1096 ismreq->ism_DisplayID =
1097 req->sm_DisplayID = dispmode->dm_DimensionInfo.Header.DisplayID;
1099 /* OverscanType: This must be before width/height because of rect variable!
1100 ** SMGetOverscan() can handle the case when ASLSM_DoOverscanType
1101 ** is not set to TRUE
1104 ismreq->ism_OverscanType =
1105 req->sm_OverscanType = SMGetOverscan(ld, dispmode, &rect, AslBase);
1107 /* Width */
1109 if (ismreq->ism_Flags & ISMF_DOWIDTH)
1111 width = SMGetWidth(ld, AslBase);
1112 } else {
1113 width = rect->MaxX - rect->MinX + 1;
1116 SMFixValues(ld, dispmode, &width, 0, 0, AslBase);
1118 ismreq->ism_DisplayWidth =
1119 req->sm_DisplayWidth = width;
1121 /* Height */
1123 if (ismreq->ism_Flags & ISMF_DOHEIGHT)
1125 height = SMGetHeight(ld, AslBase);
1126 } else {
1127 height = rect->MaxY - rect->MinY + 1;
1130 SMFixValues(ld, dispmode, 0, &height, 0, AslBase);
1132 ismreq->ism_DisplayHeight =
1133 req->sm_DisplayHeight = height;
1135 /* Depth */
1137 if (ismreq->ism_Flags & ISMF_DODEPTH)
1139 ismreq->ism_DisplayDepth = SMGetDepth(ld, 0, AslBase);
1141 req->sm_DisplayDepth = ismreq->ism_DisplayDepth;
1143 /* AutoScroll */
1144 if (ismreq->ism_Flags & ISMF_DOAUTOSCROLL)
1146 ismreq->ism_AutoScroll = SMGetAutoScroll(ld, AslBase);
1148 req->sm_AutoScroll = ismreq->ism_AutoScroll;
1150 return GHRET_FINISHED_OK;
1153 /*****************************************************************************************/
1154 /*****************************************************************************************/
1155 /*****************************************************************************************/
1156 /*****************************************************************************************/