grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / asl / modereqhooks.c
blob6c0cf61677305a61be7ee726fc90167d7dfc0858
1 /*
2 Copyright © 1995-2010, 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 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 retval = GHRET_OK;
263 break;
265 case LDCMD_LAYOUT:
266 retval = (ULONG)SMGadLayout(ld, ASLB(AslBase));
267 break;
269 case LDCMD_HANDLEEVENTS:
270 retval = (ULONG)SMHandleEvents(ld, ASLB(AslBase));
271 break;
273 case LDCMD_CLEANUP:
274 SMGadCleanup(ld, ASLB(AslBase));
275 retval = GHRET_OK;
276 break;
278 default:
279 retval = GHRET_FAIL;
280 break;
283 return (retval);
285 AROS_USERFUNC_EXIT
288 /*****************************************************************************************/
290 struct ButtonInfo
292 WORD gadid;
293 STRPTR text;
294 LONG deftextid;
295 #if USE_SHARED_COOLIMAGES
296 ULONG coolid;
297 Object **objvar;
298 const struct CoolImage *coolimage;
299 #else
300 const struct CoolImage *coolimage;
301 Object **objvar;
302 #endif
305 /*****************************************************************************************/
307 STATIC BOOL SMGadInit(struct LayoutData *ld, struct AslBase_intern *AslBase)
309 struct SMUserData *udata = ld->ld_UserData;
310 struct IntSMReq *ismreq = (struct IntSMReq *)ld->ld_IntReq;
311 STRPTR str[6];
312 #if USE_SHARED_COOLIMAGES
313 struct ButtonInfo bi[NUMBUTS] =
315 { ID_BUTOK , GetIR(ismreq)->ir_PositiveText , MSG_MODEREQ_POSITIVE_GAD, COOL_MONITORIMAGE_ID, &udata->OKBut },
316 { ID_BUTCANCEL , GetIR(ismreq)->ir_NegativeText , MSG_MODEREQ_NEGATIVE_GAD, COOL_CANCELIMAGE_ID , &udata->CancelBut }
318 #else
319 struct ButtonInfo bi[NUMBUTS] =
321 { ID_BUTOK , GetIR(ismreq)->ir_PositiveText , MSG_MODEREQ_POSITIVE_GAD, &cool_monitorimage, &udata->OKBut },
322 { ID_BUTCANCEL , GetIR(ismreq)->ir_NegativeText , MSG_MODEREQ_NEGATIVE_GAD, &cool_cancelimage , &udata->CancelBut }
324 #endif
325 Object *gad;
326 LONG error;
327 WORD gadrows, x, y, w, h, i, y2;
328 WORD labelwidth = 0, maxcyclewidth = 0;
331 NEWLIST(&udata->ListviewList);
333 error = SMGetModes(ld, AslBase);
334 if (error) goto failure;
336 error = ERROR_NO_FREE_STORE;
338 /* calc. min. size */
340 w = 0;
341 for(i = 0; i < NUMBUTS; i++)
343 if(!bi[i].text) bi[i].text = GetString(bi[i].deftextid, GetIR(ismreq)->ir_Catalog, AslBase);
345 x = TextLength(&ld->ld_DummyRP, bi[i].text, strlen(bi[i].text));
347 #if SREQ_COOL_BUTTONS
348 #if USE_SHARED_COOLIMAGES
349 if (CoolImagesBase)
351 bi[i].coolimage = (const struct CoolImage *)COOL_ObtainImageA(bi[i].coolid, NULL);
354 if (CoolImagesBase)
355 #endif
356 if (ld->ld_TrueColor)
358 x += IMAGEBUTTONEXTRAWIDTH + bi[i].coolimage->width;
360 #endif
362 if (x > w) w = x;
365 udata->ButWidth = w + BUTTONEXTRAWIDTH;
367 ld->ld_ButWidth = udata->ButWidth;
368 ld->ld_NumButtons = 4;
370 #if SREQ_COOL_BUTTONS
372 #if USE_SHARED_COOLIMAGES
373 if (CoolImagesBase)
375 #endif
376 y = BUTTONEXTRAHEIGHT + ld->ld_Font->tf_YSize;
377 if (ld->ld_TrueColor)
379 y2 = IMAGEBUTTONEXTRAHEIGHT + DEF_COOLIMAGEHEIGHT;
380 } else {
381 y2 = 0;
383 udata->ButHeight = (y > y2) ? y : y2;
384 #if USE_SHARED_COOLIMAGES
386 else
388 udata->ButHeight = BUTTONEXTRAHEIGHT + ld->ld_Font->tf_YSize;
390 #endif
392 #else
393 udata->ButHeight = BUTTONEXTRAHEIGHT + ld->ld_Font->tf_YSize;
394 #endif
396 gadrows = 1; /* button row */
397 if (ismreq->ism_Flags & ISMF_DOOVERSCAN) gadrows++;
398 if (ismreq->ism_Flags & ISMF_DOWIDTH) gadrows++;
399 if (ismreq->ism_Flags & ISMF_DOHEIGHT) gadrows++;
400 if (ismreq->ism_Flags & ISMF_DODEPTH) gadrows++;
401 if (ismreq->ism_Flags & ISMF_DOAUTOSCROLL) gadrows++;
403 ld->ld_MinWidth = OUTERSPACINGX * 2 +
404 GADGETSPACINGX * 1 +
405 udata->ButWidth * NUMBUTS;
407 ld->ld_MinHeight = OUTERSPACINGY * 2 +
408 (GADGETSPACINGY + udata->ButHeight) * gadrows +
409 BORDERLVSPACINGY * 2 +
410 (ld->ld_Font->tf_YSize + BORDERLVITEMSPACINGY * 2) * SREQ_MIN_VISIBLELINES;
412 /* make listview gadget */
414 x = ld->ld_WBorLeft + OUTERSPACINGX;
415 y = ld->ld_WBorTop + OUTERSPACINGY;
416 w = -ld->ld_WBorRight - ld->ld_WBorLeft - OUTERSPACINGX * 2 - PROPSIZE;
417 h = -ld->ld_WBorBottom - ld->ld_WBorTop - OUTERSPACINGY * 2 -
418 udata->ButHeight * gadrows -
419 GADGETSPACINGY * gadrows;
422 struct TagItem lv_tags[] =
424 {GA_Left , x },
425 {GA_Top , y },
426 {GA_RelWidth , w },
427 {GA_RelHeight , h },
428 {GA_UserData , (IPTR)ld },
429 {GA_ID , ID_LISTVIEW },
430 {GA_RelVerify , TRUE },
431 {ASLLV_Labels , (IPTR)&udata->ListviewList },
432 {ASLLV_Font , (IPTR)ld->ld_Font },
433 {TAG_DONE }
436 udata->Listview = gad = NewObjectA(AslBase->asllistviewclass, NULL, lv_tags);
437 if (!udata->Listview) goto failure;
441 /* make scroller gadget for listview */
443 x = -ld->ld_WBorRight - OUTERSPACINGX - PROPSIZE + 1;
444 y = ld->ld_WBorTop + OUTERSPACINGY;
445 w = PROPSIZE;
446 h = -ld->ld_WBorBottom - ld->ld_WBorTop - OUTERSPACINGY * 2 -
447 udata->ButHeight * gadrows -
448 GADGETSPACINGY * gadrows;
450 struct TagItem scroller_tags[] =
452 {GA_RelRight , x },
453 {GA_Top , y },
454 {GA_Width , w },
455 {GA_RelHeight , h },
456 {GA_ID , ID_LISTVIEW },
457 {PGA_NewLook , TRUE },
458 {PGA_Borderless , TRUE },
459 {PGA_Freedom , FREEVERT },
460 {PGA_Top , 0 },
461 {PGA_Total , 20 },
462 {PGA_Visible , 1 },
463 {GA_Previous , (IPTR)gad },
464 {TAG_DONE }
467 if (!makescrollergadget(&udata->ScrollGad, ld, scroller_tags, AslBase)) goto failure;
468 gad = udata->ScrollGad.arrow2;
471 connectscrollerandlistview(&udata->ScrollGad, udata->Listview, AslBase);
473 /* make button row */
475 y = -ld->ld_WBorBottom - OUTERSPACINGY - udata->ButHeight + 1;
478 struct TagItem button_tags[] =
480 {GA_Text , 0 },
481 {GA_Previous , 0 },
482 {GA_ID , 0 },
483 #if SREQ_COOL_BUTTONS
484 {ASLBT_CoolImage , 0 },
485 #else
486 {TAG_IGNORE , 0 },
487 #endif
488 {GA_UserData , (IPTR)ld },
489 {GA_Left , 0 },
490 {GA_RelBottom , y },
491 {GA_Width , udata->ButWidth },
492 {GA_Height , udata->ButHeight },
493 {GA_RelVerify , TRUE },
494 {GA_Image , 0 }, /* means we want a frame */
495 {TAG_DONE }
498 for(i = 0; i < NUMBUTS; i++)
500 button_tags[0].ti_Data = (IPTR)bi[i].text;
501 button_tags[1].ti_Data = (IPTR)gad;
502 button_tags[2].ti_Data = bi[i].gadid;
504 #if USE_SHARED_COOLIMAGES
505 if (CoolImagesBase == NULL) button_tags[3].ti_Tag = TAG_IGNORE;
506 #endif
507 button_tags[3].ti_Data = (IPTR)bi[i].coolimage;
509 *(bi[i].objvar) = gad = NewObjectA(AslBase->aslbuttonclass, NULL, button_tags);
510 if (!gad) goto failure;
515 /* make labels */
517 if (ismreq->ism_Flags & (ISMF_DOOVERSCAN | ISMF_DOWIDTH | ISMF_DOHEIGHT | ISMF_DODEPTH | ISMF_DOAUTOSCROLL))
519 #define FSET(x) ((ismreq->ism_Flags & x) ? TRUE : FALSE)
521 struct LabelInfo
523 BOOL doit;
524 STRPTR text;
525 Object **objvar;
526 } li [] =
528 {FSET(ISMF_DOOVERSCAN) , (STRPTR)MSG_MODEREQ_OVERSCAN_LABEL , &udata->OverscanLabel },
529 {FSET(ISMF_DOWIDTH) , (STRPTR)MSG_MODEREQ_WIDTH_LABEL , &udata->WidthLabel },
530 {FSET(ISMF_DOHEIGHT) , (STRPTR)MSG_MODEREQ_HEIGHT_LABEL , &udata->HeightLabel },
531 {FSET(ISMF_DODEPTH) , (STRPTR)MSG_MODEREQ_COLORS_LABEL , &udata->DepthLabel },
532 {FSET(ISMF_DOAUTOSCROLL), (STRPTR)MSG_MODEREQ_AUTOSCROLL_LABEL, &udata->AutoScrollLabel}
535 #undef FSET
537 struct TagItem label_tags[] =
539 {GA_Left , 0 },
540 {GA_RelBottom , 0 },
541 {GA_Width , 0 },
542 {GA_Height , udata->ButHeight },
543 {GA_Text , 0 },
544 {GA_Previous , (IPTR)gad },
545 {GA_UserData , (IPTR)ld },
546 {GA_Disabled , TRUE },
547 {TAG_DONE }
549 WORD i2;
551 for(i = 0, i2 = 0; i < 5; i++)
553 if (li[i].doit)
555 li[i].text = GetString((IPTR)li[i].text, GetIR(ismreq)->ir_Catalog, AslBase);
556 str[i2++] = li[i].text;
560 x = ld->ld_WBorLeft + OUTERSPACINGX;
561 y = -ld->ld_WBorBottom - OUTERSPACINGY - udata->ButHeight -
562 (udata->ButHeight + GADGETSPACINGY) * (gadrows - 1) + 1;
565 w = labelwidth = BiggestTextLength(str, i2, &(ld->ld_DummyRP), AslBase);
567 label_tags[1].ti_Data = y;
569 for(i = 0; i < 5;i++)
571 if (!li[i].doit) continue;
573 label_tags[2].ti_Data = TextLength(&ld->ld_DummyRP, li[i].text, strlen(li[i].text));
574 label_tags[0].ti_Data = x + w - label_tags[2].ti_Data;
575 label_tags[4].ti_Data = (IPTR)li[i].text;
576 label_tags[5].ti_Data = (IPTR)gad;
578 *(li[i].objvar) = gad = NewObjectA(AslBase->aslbuttonclass, NULL, label_tags);
579 if (!gad) goto failure;
581 y += udata->ButHeight + GADGETSPACINGY;
582 label_tags[1].ti_Data = y;
585 y = -ld->ld_WBorBottom - OUTERSPACINGY - udata->ButHeight -
586 (udata->ButHeight + GADGETSPACINGY) * (gadrows - 1) + 1;
587 x = ld->ld_WBorLeft + OUTERSPACINGX + w + LABELSPACINGX;
589 w = -ld->ld_WBorLeft - ld->ld_WBorRight - OUTERSPACINGX * 2 -
590 w - LABELSPACINGX;
592 /* Make Overscan gadget */
594 if (ismreq->ism_Flags & ISMF_DOOVERSCAN)
596 struct TagItem cycle_tags[] =
598 {GA_Previous , (IPTR)gad },
599 {GA_Left , x },
600 {GA_RelBottom , y },
601 {GA_RelWidth , w },
602 {GA_Height , udata->ButHeight },
603 {GA_RelVerify , TRUE },
604 {GA_UserData , (IPTR)ld },
605 {GA_ID , ID_OVERSCAN },
606 {ASLCY_Labels , (IPTR)&ismreq->ism_Overscan1Text},
607 {ASLCY_Active , ismreq->ism_OverscanType - 1 },
608 {ASLCY_Font , (IPTR)ld->ld_Font },
609 {TAG_DONE }
612 static LONG labelids[] =
614 MSG_MODEREQ_OVERSCAN_TEXT,
615 MSG_MODEREQ_OVERSCAN_GRAPHICS,
616 MSG_MODEREQ_OVERSCAN_EXTREME,
617 MSG_MODEREQ_OVERSCAN_MAXIMUM,
620 STRPTR *labels = (STRPTR *)&ismreq->ism_Overscan1Text;
622 for(i = 0; i < 4; i++)
624 labels[i] = GetString(labelids[i], GetIR(ismreq)->ir_Catalog, AslBase);
627 i = CYCLEEXTRAWIDTH + BiggestTextLength(&ismreq->ism_Overscan1Text,
629 &(ld->ld_DummyRP),
630 AslBase);
631 if (i > maxcyclewidth) maxcyclewidth = i;
633 udata->OverscanGadget = gad = NewObjectA(AslBase->aslcycleclass, NULL, cycle_tags);
634 if (!gad) goto failure;
636 y += udata->ButHeight + GADGETSPACINGY;
638 } /* if (ismreq->ism_Flags & ISMF_DOOVERSCAN) */
641 struct TagItem string_tags[] =
643 {GA_Previous , (IPTR)gad },
644 {GA_ID , ID_WIDTH },
645 {STRINGA_LongVal , ismreq->ism_DisplayWidth },
646 {GA_RelBottom , y },
647 {GA_Left , x },
648 {GA_RelWidth , w },
649 {GA_Height , udata->ButHeight },
650 {GA_RelVerify , TRUE },
651 {GA_UserData , (IPTR)ld },
652 {GA_TabCycle , TRUE },
653 {STRINGA_MaxChars , 8 },
654 {STRINGA_Font , (IPTR)ld->ld_Font },
655 {TAG_DONE }
658 /* Make width gadget */
660 if (ismreq->ism_Flags & ISMF_DOWIDTH)
662 udata->WidthGadget = gad = NewObjectA(AslBase->aslstringclass, NULL, string_tags);
663 if (!gad) goto failure;
665 y += udata->ButHeight + GADGETSPACINGY;
668 /* Make height gadget */
670 if (ismreq->ism_Flags & ISMF_DOHEIGHT)
672 string_tags[0].ti_Data = (IPTR)gad;
673 string_tags[1].ti_Data = ID_HEIGHT;
674 string_tags[2].ti_Data = ismreq->ism_DisplayHeight;
675 string_tags[3].ti_Data = y;
677 udata->HeightGadget = gad = NewObjectA(AslBase->aslstringclass, NULL, string_tags);
678 if (!gad) goto failure;
680 y += udata->ButHeight + GADGETSPACINGY;
685 struct TagItem cycle_tags[] =
687 {GA_Previous , (IPTR)gad },
688 {GA_ID , ID_COLORS },
689 {ASLCY_Labels , 0 },
690 {ASLCY_Active , 0 },
691 {GA_RelBottom , y },
692 {GA_Left , x },
693 {GA_RelWidth , w },
694 {GA_Height , udata->ButHeight },
695 {GA_RelVerify , TRUE },
696 {GA_UserData , (IPTR)ld },
697 {ASLCY_Font , (IPTR)ld->ld_Font },
698 {TAG_DONE }
702 /* Make Colors gadget */
704 if (ismreq->ism_Flags & ISMF_DODEPTH)
706 i = CYCLEEXTRAWIDTH + TextLength(&ld->ld_DummyRP, "16777216", 8);
707 if (i > maxcyclewidth) maxcyclewidth = i;
709 udata->DepthGadget = gad = NewObjectA(AslBase->aslcycleclass, NULL, cycle_tags);
710 if (!gad) goto failure;
712 y += udata->ButHeight + GADGETSPACINGY;
715 /* Make AutoScroll gadget */
717 if (ismreq->ism_Flags & ISMF_DOAUTOSCROLL)
719 cycle_tags[0].ti_Data = (IPTR)gad;
720 cycle_tags[1].ti_Data = ID_AUTOSCROLL;
721 cycle_tags[2].ti_Data = (IPTR)&ismreq->ism_AutoScrollOFFText;
722 cycle_tags[3].ti_Data = ismreq->ism_AutoScroll;
723 cycle_tags[4].ti_Data = y;
725 ismreq->ism_AutoScrollOFFText = GetString(MSG_MODEREQ_AUTOSCROLL_OFF, GetIR(ismreq)->ir_Catalog, AslBase);
726 ismreq->ism_AutoScrollONText = GetString(MSG_MODEREQ_AUTOSCROLL_ON , GetIR(ismreq)->ir_Catalog, AslBase);
728 i = CYCLEEXTRAWIDTH + BiggestTextLength(&ismreq->ism_AutoScrollOFFText,
730 &(ld->ld_DummyRP),
731 AslBase);
732 if (i > maxcyclewidth) maxcyclewidth = i;
734 udata->AutoScrollGadget = gad = NewObjectA(AslBase->aslcycleclass, NULL, cycle_tags);
735 if (!gad) goto failure;
737 y += udata->ButHeight + GADGETSPACINGY;
742 } /* if (ismreq->ism_Flags & (ISMF_DOOVERSCAN | ISMF_DOWIDTH | ISMF_DOHEIGHT | ISMF_DODEPTH | ISMF_DOAUTOSCROLL)) */
744 #if AVOID_FLICKER
746 struct TagItem eraser_tags[] =
748 {GA_Previous, (IPTR)gad},
749 {TAG_DONE}
752 udata->EraserGadget = gad = NewObjectA(AslBase->asleraserclass, NULL, eraser_tags);
753 /* Doesn't matter if this failed */
755 #endif
757 w = OUTERSPACINGX + labelwidth + LABELSPACINGX + maxcyclewidth + OUTERSPACINGX;
758 if (w > ld->ld_MinWidth) ld->ld_MinWidth = w;
760 ld->ld_GList = (struct Gadget *)udata->Listview;
762 /* Menus */
764 struct NewMenu nm[] =
766 {NM_TITLE, (STRPTR)MSG_MODEREQ_MEN_CONTROL },
767 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_LASTMODE , 0, 0, 0, (APTR)SMMEN_LASTMODE },
768 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_NEXTMODE , 0, 0, 0, (APTR)SMMEN_NEXTMODE },
769 {NM_ITEM, NM_BARLABEL },
770 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_PROPERTIES , 0, 0, 0, (APTR)SMMEN_PROPERTYLIST },
771 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_RESTORE , 0, 0, 0, (APTR)SMMEN_RESTORE },
772 {NM_ITEM, NM_BARLABEL },
773 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_OK , 0, 0, 0, (APTR)SMMEN_OK },
774 {NM_ITEM, (STRPTR)MSG_MODEREQ_MEN_CONTROL_CANCEL , 0, 0, 0, (APTR)SMMEN_CANCEL },
775 {NM_END }
778 struct TagItem menu_tags[] =
780 {GTMN_NewLookMenus , TRUE },
781 {GTMN_TextAttr , (IPTR)GetIR(ismreq)->ir_TextAttr },
782 {TAG_DONE }
785 if (menu_tags[1].ti_Data == 0) menu_tags[1].ti_Tag = TAG_IGNORE;
787 LocalizeMenus(nm, GetIR(ismreq)->ir_Catalog, AslBase);
789 /* Don't fail, if menus cannot be created/layouted, because a requester
790 without menus is still better than no requester at all */
792 if ((ld->ld_Menu = CreateMenusA(nm, NULL)))
794 if (!LayoutMenusA(ld->ld_Menu, ld->ld_VisualInfo, menu_tags))
796 FreeMenus(ld->ld_Menu);ld->ld_Menu = NULL;
801 SMRestore(ld, AslBase);
803 SetIoErr(0);
804 ReturnBool ("SMGadInit", TRUE);
806 failure:
807 SetIoErr(error);
809 D(bug("failure\n"));
811 SMGadCleanup(ld, ASLB(AslBase));
813 ReturnBool ("SMGadInit", FALSE);
817 /*****************************************************************************************/
819 STATIC VOID SMWindowOpened(struct LayoutData *ld, struct AslBase_intern *AslBase)
821 struct IntSMReq *ismreq = (struct IntSMReq *)ld->ld_IntReq;
823 if (ismreq->ism_InfoOpened)
825 SMOpenPropertyWindow(ld, AslBase);
829 /*****************************************************************************************/
831 STATIC BOOL SMGadLayout(struct LayoutData *ld, struct AslBase_intern *AslBase)
833 ReturnBool ("SMGadLayout", TRUE );
836 /*****************************************************************************************/
838 STATIC ULONG SMHandleEvents(struct LayoutData *ld, struct AslBase_intern *AslBase)
840 struct IntuiMessage *imsg = ld->ld_Event;
841 struct SMUserData *udata = (struct SMUserData *)ld->ld_UserData;
842 WORD gadid;
843 ULONG retval = GHRET_OK;
845 EnterFunc(bug("SMHandleEvents: Class: %d\n", imsg->Class));
847 if (imsg->IDCMPWindow == ld->ld_Window2)
849 return SMHandlePropertyEvents(ld, imsg, AslBase);
852 switch (imsg->Class)
854 case IDCMP_CLOSEWINDOW:
855 retval = FALSE;
856 break;
858 case IDCMP_RAWKEY:
859 switch (imsg->Code)
861 case CURSORUP:
862 SMChangeActiveLVItem(ld, -1, imsg->Qualifier, AslBase);
863 break;
865 case RAWKEY_PAGEUP:
866 SMChangeActiveLVItem(ld, -1, IEQUALIFIER_LSHIFT, AslBase);
867 break;
869 case RAWKEY_HOME:
870 SMChangeActiveLVItem(ld, -1, IEQUALIFIER_LALT, AslBase);
871 break;
873 case RAWKEY_NM_WHEEL_UP:
874 SMChangeActiveLVItem(ld, -3, imsg->Qualifier, AslBase);
875 break;
877 case CURSORDOWN:
878 SMChangeActiveLVItem(ld, 1, imsg->Qualifier, AslBase);
879 break;
881 case RAWKEY_PAGEDOWN:
882 SMChangeActiveLVItem(ld, 1, IEQUALIFIER_LSHIFT, AslBase);
883 break;
885 case RAWKEY_END:
886 SMChangeActiveLVItem(ld, 1, IEQUALIFIER_LALT, AslBase);
887 break;
889 case RAWKEY_NM_WHEEL_DOWN:
890 SMChangeActiveLVItem(ld, 3, imsg->Qualifier, AslBase);
891 break;
893 break;
895 case IDCMP_VANILLAKEY:
896 switch(imsg->Code)
898 case 27:
899 retval = FALSE;
900 break;
902 break;
904 case IDCMP_GADGETUP:
905 gadid = ((struct Gadget *)imsg->IAddress)->GadgetID;
907 D(bug("GADGETUP! gadgetid=%d\n", gadid));
909 switch (gadid)
911 case ID_BUTCANCEL:
912 retval = FALSE;
913 break;
915 case ID_BUTOK:
916 retval = SMGetSelectedMode(ld, AslBase);
917 break;
919 case ID_LISTVIEW:
921 struct DisplayMode *dispmode;
922 IPTR active;
924 GetAttr(ASLLV_Active, udata->Listview, &active);
926 if ((dispmode = (struct DisplayMode *)FindListNode(&udata->ListviewList, (WORD)active)))
928 SMActivateMode(ld, active, 0, AslBase);
930 if (imsg->Code) /* TRUE if double clicked */
932 retval = SMGetSelectedMode(ld, AslBase);
936 break;
938 case ID_OVERSCAN:
939 SMChangeActiveLVItem(ld, 0, 0, AslBase);
940 break;
942 case ID_WIDTH:
944 struct DisplayMode *dispmode;
945 LONG width;
947 dispmode = SMGetActiveMode(ld, AslBase);
948 ASSERT_VALID_PTR(dispmode);
950 width = SMGetWidth (ld, AslBase);
952 SMFixValues(ld, dispmode, &width, 0, 0, AslBase);
954 break;
956 case ID_HEIGHT:
958 struct DisplayMode *dispmode;
959 LONG height;
961 dispmode = SMGetActiveMode(ld, AslBase);
962 ASSERT_VALID_PTR(dispmode);
964 height = SMGetWidth (ld, AslBase);
966 SMFixValues(ld, dispmode, 0, &height, 0, AslBase);
968 break;
970 } /* switch (gadget ID) */
972 break; /* case IDCMP_GADGETUP: */
974 case IDCMP_MENUPICK:
975 if (ld->ld_Menu)
977 UWORD men = imsg->Code;
979 while(men != MENUNULL)
981 struct MenuItem *item;
983 if ((item = ItemAddress(ld->ld_Menu, men)))
985 switch((IPTR)GTMENUITEM_USERDATA(item))
987 /* Control menu */
989 case SMMEN_LASTMODE:
990 SMChangeActiveLVItem(ld, -1, 0, AslBase);
991 break;
993 case SMMEN_NEXTMODE:
994 SMChangeActiveLVItem(ld, 1, 0, AslBase);
995 break;
997 case SMMEN_PROPERTYLIST:
998 if (ld->ld_Window2)
1000 SMClosePropertyWindow(ld, AslBase);
1001 } else {
1002 SMOpenPropertyWindow(ld, AslBase);
1004 break;
1006 case SMMEN_RESTORE:
1007 SMRestore(ld, AslBase);
1008 break;
1010 case SMMEN_OK:
1011 retval = SMGetSelectedMode(ld, AslBase);
1012 break;
1014 case SMMEN_CANCEL:
1015 retval = FALSE;
1016 break;
1018 } /* switch id */
1020 men = item->NextSelect;
1021 } /* if ((item = ItemAddress(ld->ld_Menu, men))) */
1022 else
1024 men = MENUNULL;
1027 } /* while(men != MENUNULL) */
1029 } /* if (ld->ld_Menu) */
1031 break; /* case IDCMP_MENUPICK: */
1033 } /* switch (imsg->Class) */
1035 ReturnInt ("SMHandleEvents", ULONG, retval);
1038 /*****************************************************************************************/
1040 STATIC VOID SMGadCleanup(struct LayoutData *ld, struct AslBase_intern *AslBase)
1042 struct SMUserData *udata = (struct SMUserData *)ld->ld_UserData;
1043 struct ScreenModeRequester *req = (struct ScreenModeRequester *)ld->ld_Req;
1044 struct IntReq *intreq = ld->ld_IntReq;
1045 struct IntSMReq *ismreq = (struct IntSMReq *)intreq;
1047 EnterFunc(bug("SMGadCleanup(ld=%p)\n", ld));
1049 if (ld->ld_Window && ld->ld_GList)
1051 RemoveGList(ld->ld_Window, ld->ld_GList, -1);
1054 killscrollergadget(&udata->ScrollGad, AslBase);
1056 FreeObjects(&SREQ_FIRST_OBJECT(udata), &SREQ_LAST_OBJECT(udata), AslBase);
1058 req->sm_InfoOpened = ismreq->ism_InfoOpened = ld->ld_Window2 ? TRUE : FALSE;
1060 if (ld->ld_Window)
1062 req->sm_LeftEdge = intreq->ir_LeftEdge = ld->ld_Window->LeftEdge;
1063 req->sm_TopEdge = intreq->ir_TopEdge = ld->ld_Window->TopEdge;
1064 req->sm_Width = intreq->ir_Width = ld->ld_Window->Width;
1065 req->sm_Height = intreq->ir_Height = ld->ld_Window->Height;
1067 req->sm_InfoLeftEdge = ismreq->ism_InfoLeftEdge;
1068 req->sm_InfoTopEdge = ismreq->ism_InfoTopEdge;
1070 if (ld->ld_Window2) /* can only be open if ld->ld_Window is open, too */
1072 req->sm_InfoWidth = ld->ld_Window2->Width;
1073 req->sm_InfoHeight = ld->ld_Window2->Height;
1075 SMClosePropertyWindow(ld, AslBase);
1079 ReturnVoid("SMGadCleanup");
1082 /*****************************************************************************************/
1084 STATIC ULONG SMGetSelectedMode(struct LayoutData *ld, struct AslBase_intern *AslBase)
1086 /*struct SMUserData *udata = (struct SMUserData *)ld->ld_UserData; */
1087 struct IntReq *intreq = ld->ld_IntReq;
1088 struct IntSMReq *ismreq = (struct IntSMReq *)intreq;
1089 struct ScreenModeRequester *req = (struct ScreenModeRequester *)ld->ld_Req;
1090 struct DisplayMode *dispmode;
1091 struct Rectangle *rect;
1092 LONG width, height;
1094 dispmode = SMGetActiveMode(ld, AslBase);
1095 ASSERT_VALID_PTR(dispmode);
1097 ismreq->ism_DisplayID =
1098 req->sm_DisplayID = dispmode->dm_DimensionInfo.Header.DisplayID;
1100 /* OverscanType: This must be before width/height because of rect variable!
1101 ** SMGetOverscan() can handle the case when ASLSM_DoOverscanType
1102 ** is not set to TRUE
1105 ismreq->ism_OverscanType =
1106 req->sm_OverscanType = SMGetOverscan(ld, dispmode, &rect, AslBase);
1108 /* Width */
1110 if (ismreq->ism_Flags & ISMF_DOWIDTH)
1112 width = SMGetWidth(ld, AslBase);
1113 } else {
1114 width = rect->MaxX - rect->MinX + 1;
1117 SMFixValues(ld, dispmode, &width, 0, 0, AslBase);
1119 ismreq->ism_DisplayWidth =
1120 req->sm_DisplayWidth = width;
1122 /* Height */
1124 if (ismreq->ism_Flags & ISMF_DOHEIGHT)
1126 height = SMGetHeight(ld, AslBase);
1127 } else {
1128 height = rect->MaxY - rect->MinY + 1;
1131 SMFixValues(ld, dispmode, 0, &height, 0, AslBase);
1133 ismreq->ism_DisplayHeight =
1134 req->sm_DisplayHeight = height;
1136 /* Depth */
1138 if (ismreq->ism_Flags & ISMF_DODEPTH)
1140 ismreq->ism_DisplayDepth = SMGetDepth(ld, 0, AslBase);
1142 else
1144 ismreq->ism_DisplayDepth = dispmode->dm_DimensionInfo.MaxDepth;
1147 req->sm_DisplayDepth = ismreq->ism_DisplayDepth;
1149 /* AutoScroll */
1150 if (ismreq->ism_Flags & ISMF_DOAUTOSCROLL)
1152 ismreq->ism_AutoScroll = SMGetAutoScroll(ld, AslBase);
1154 req->sm_AutoScroll = ismreq->ism_AutoScroll;
1156 return GHRET_FINISHED_OK;
1159 /*****************************************************************************************/