2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 Font requester specific code.
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>
17 #include <intuition/screens.h>
18 #include <intuition/icclass.h>
19 #include <intuition/imageclass.h>
20 #include <graphics/gfx.h>
21 #include <devices/rawkeycodes.h>
22 #include <libraries/gadtools.h>
23 #include <workbench/startup.h>
27 #include "asl_intern.h"
28 #include "fontreqhooks.h"
29 #include "fontreqsupport.h"
32 #if USE_SHARED_COOLIMAGES
33 #include <libraries/coolimages.h>
34 #include <proto/coolimages.h>
36 #include "coolimages.h"
39 #define CATCOMP_NUMBERS
45 #include <aros/debug.h>
47 /*****************************************************************************************/
49 STATIC BOOL
FOGadInit(struct LayoutData
*, struct AslBase_intern
*);
50 STATIC VOID
FOWindowOpened(struct LayoutData
*, struct AslBase_intern
*);
51 STATIC BOOL
FOGadLayout(struct LayoutData
*, struct AslBase_intern
*);
52 STATIC VOID
FOGadCleanup(struct LayoutData
*, struct AslBase_intern
*);
53 STATIC ULONG
FOHandleEvents(struct LayoutData
*, struct AslBase_intern
*);
54 STATIC ULONG
FOGetSelectedFont(struct LayoutData
*, struct AslBase_intern
*AslBase
);
56 /*****************************************************************************************/
58 #define ID_BUTOK ID_MAINBUTTON_OK
59 #define ID_BUTCANCEL ID_MAINBUTTON_CANCEL
61 #define ID_NAMELISTVIEW 1
62 #define ID_SIZELISTVIEW 2
63 #define ID_NAMESTRING 3
64 #define ID_SIZESTRING 4
74 #define FONTPREVIEWHEIGHT 40
76 #define CLASS_ASLBASE ((struct AslBase_intern *)cl->cl_UserData)
77 #define HOOK_ASLBASE ((struct AslBase_intern *)hook->h_Data)
79 #define AslBase HOOK_ASLBASE
81 /*****************************************************************************************/
83 AROS_UFH3(IPTR
, SizeListviewRenderFunc
,
84 AROS_UFHA(struct Hook
*, hook
, A0
),
85 AROS_UFHA(struct Node
*, node
, A2
),
86 AROS_UFHA(struct ASLLVDrawMsg
*, msg
, A1
)
93 if (msg
->lvdm_MethodID
== LV_DRAW
)
95 struct DrawInfo
*dri
= msg
->lvdm_DrawInfo
;
96 struct RastPort
*rp
= msg
->lvdm_RastPort
;
98 WORD min_x
= msg
->lvdm_Bounds
.MinX
;
99 WORD min_y
= msg
->lvdm_Bounds
.MinY
;
100 WORD max_x
= msg
->lvdm_Bounds
.MaxX
;
101 WORD max_y
= msg
->lvdm_Bounds
.MaxY
;
103 UWORD erasepen
= BACKGROUNDPEN
;
104 UWORD textpen
= TEXTPEN
;
109 switch (msg
->lvdm_State
)
111 case ASLLVR_SELECTED
:
113 textpen
= FILLTEXTPEN
;
119 struct TextExtent te
;
123 SetAPen(rp
, dri
->dri_Pens
[erasepen
]);
124 RectFill(rp
, min_x
, min_y
, max_x
, max_y
);
128 sprintf(s
, "%ld", (long)node
->ln_Name
);
136 max_x
- min_x
+ 1 - BORDERLVITEMSPACINGX
* 2,
139 SetAPen(rp
, dri
->dri_Pens
[textpen
]);
142 Move(rp
, min_x
+ BORDERLVITEMSPACINGX
,
143 min_y
+ BORDERLVITEMSPACINGY
+ rp
->Font
->tf_Baseline
);
154 retval
= ASLLVCB_UNKNOWN
;
162 /*****************************************************************************************/
166 /*****************************************************************************************/
168 AROS_UFH3(VOID
, FOTagHook
,
169 AROS_UFHA(struct Hook
*, hook
, A0
),
170 AROS_UFHA(struct ParseTagArgs
*, pta
, A2
),
171 AROS_UFHA(struct AslBase_intern
*, AslBase
, A1
)
177 struct TagItem
*tstate
;
178 struct IntFontReq
*iforeq
;
180 EnterFunc(bug("FOTagHook(hook=%p, pta=%p)\n", hook
, pta
));
182 iforeq
= (struct IntFontReq
*)pta
->pta_IntReq
;
184 tstate
= pta
->pta_Tags
;
185 while ((tag
= NextTagItem(&tstate
)) != NULL
)
187 IPTR tidata
= tag
->ti_Data
;
191 case ASLFO_InitialName
:
193 iforeq
->ifo_TextAttr
.ta_Name
= (STRPTR
)tidata
;
196 case ASLFO_InitialSize
:
197 iforeq
->ifo_TextAttr
.ta_YSize
= (UWORD
)tidata
;
200 case ASLFO_InitialStyle
:
201 iforeq
->ifo_TextAttr
.ta_Style
= (UBYTE
)tidata
;
204 case ASLFO_InitialFlags
:
205 iforeq
->ifo_TextAttr
.ta_Flags
= (UBYTE
)tidata
;
208 case ASLFO_InitialFrontPen
:
209 iforeq
->ifo_FrontPen
= (UBYTE
)tidata
;
212 case ASLFO_InitialBackPen
:
213 iforeq
->ifo_BackPen
= (UBYTE
)tidata
;
216 case ASLFO_InitialDrawMode
:
217 iforeq
->ifo_DrawMode
= (UBYTE
)tidata
;
221 iforeq
->ifo_Flags
= (UBYTE
)tidata
;
224 case ASLFO_DoFrontPen
:
226 iforeq
->ifo_Flags
|= FOF_DOFRONTPEN
;
228 iforeq
->ifo_Flags
&= ~FOF_DOFRONTPEN
;
231 case ASLFO_DoBackPen
:
233 iforeq
->ifo_Flags
|= FOF_DOBACKPEN
;
235 iforeq
->ifo_Flags
&= ~FOF_DOBACKPEN
;
240 iforeq
->ifo_Flags
|= FOF_DOSTYLE
;
242 iforeq
->ifo_Flags
&= ~FOF_DOSTYLE
;
245 case ASLFO_DoDrawMode
:
247 iforeq
->ifo_Flags
|= FOF_DODRAWMODE
;
249 iforeq
->ifo_Flags
&= ~FOF_DODRAWMODE
;
252 case ASLFO_FixedWidthOnly
:
254 iforeq
->ifo_Flags
|= FOF_FIXEDWIDTHONLY
;
256 iforeq
->ifo_Flags
&= ~FOF_FIXEDWIDTHONLY
;
259 case ASLFO_MinHeight
:
260 iforeq
->ifo_MinHeight
= (UWORD
)tidata
;
263 case ASLFO_MaxHeight
:
264 iforeq
->ifo_MaxHeight
= (UWORD
)tidata
;
267 case ASLFO_FilterFunc
:
268 iforeq
->ifo_FilterFunc
= (struct Hook
*)tidata
;
272 iforeq
->ifo_HookFunc
= (APTR
)tidata
;
275 case ASLFO_MaxFrontPen
:
276 iforeq
->ifo_MaxFrontPen
= (UWORD
)tidata
;
279 case ASLFO_MaxBackPen
:
280 iforeq
->ifo_MaxBackPen
= (UWORD
)tidata
;
284 iforeq
->ifo_ModeList
= (STRPTR
*)tidata
;
287 case ASLFO_FrontPens
:
288 iforeq
->ifo_FrontPens
= (UBYTE
*)tidata
;
292 iforeq
->ifo_BackPens
= (UBYTE
*)tidata
;
295 case ASLFO_SampleText
:
296 iforeq
->ifo_SampleText
= (STRPTR
)tidata
;
302 } /* switch (tag->ti_Tag) */
304 } /* while ((tag = NextTagItem(&tstate)) != 0) */
306 ReturnVoid("FOTagHook");
311 /*****************************************************************************************/
313 AROS_UFH3(ULONG
, FOGadgetryHook
,
314 AROS_UFHA(struct Hook
*, hook
, A0
),
315 AROS_UFHA(struct LayoutData
*, ld
, A2
),
316 AROS_UFHA(struct AslBase_intern
*, AslBase
, A1
)
323 switch (ld
->ld_Command
)
326 retval
= (ULONG
)FOGadInit(ld
, ASLB(AslBase
));
329 case LDCMD_WINDOWOPENED
:
330 FOWindowOpened(ld
, ASLB(AslBase
));
335 retval
= (ULONG
)FOGadLayout(ld
, ASLB(AslBase
));
338 case LDCMD_HANDLEEVENTS
:
339 retval
= (ULONG
)FOHandleEvents(ld
, ASLB(AslBase
));
343 FOGadCleanup(ld
, ASLB(AslBase
));
357 /*****************************************************************************************/
364 #if USE_SHARED_COOLIMAGES
367 const struct CoolImage
*coolimage
;
369 const struct CoolImage
*coolimage
;
374 /*****************************************************************************************/
376 STATIC BOOL
FOGadInit(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
378 struct FOUserData
*udata
= ld
->ld_UserData
;
379 struct IntFontReq
*iforeq
= (struct IntFontReq
*)ld
->ld_IntReq
;
381 #if USE_SHARED_COOLIMAGES
382 struct ButtonInfo bi
[NUMBUTS
] =
384 { ID_BUTOK
, GetIR(iforeq
)->ir_PositiveText
, MSG_FONTREQ_POSITIVE_GAD
, COOL_USEIMAGE_ID
, &udata
->OKBut
},
385 { ID_BUTCANCEL
, GetIR(iforeq
)->ir_NegativeText
, MSG_FONTREQ_NEGATIVE_GAD
, COOL_CANCELIMAGE_ID
, &udata
->CancelBut
}
388 struct ButtonInfo bi
[NUMBUTS
] =
390 { ID_BUTOK
, GetIR(iforeq
)->ir_PositiveText
, MSG_FONTREQ_POSITIVE_GAD
, &cool_useimage
, &udata
->OKBut
},
391 { ID_BUTCANCEL
, GetIR(iforeq
)->ir_NegativeText
, MSG_FONTREQ_NEGATIVE_GAD
, &cool_cancelimage
, &udata
->CancelBut
}
396 WORD gadrows
, x
, y
, w
, h
, i
, y2
;
397 WORD sizelvwidth
, labelwidth
= 0, maxgadcolwidth
= 0;
399 NEWLIST(&udata
->NameListviewList
);
401 udata
->SizeListviewRenderHook
.h_Entry
= (APTR
)AROS_ASMSYMNAME(SizeListviewRenderFunc
);
402 udata
->SizeListviewRenderHook
.h_SubEntry
= NULL
;
403 udata
->SizeListviewRenderHook
.h_Data
= AslBase
;
405 udata
->StringEditHook
.h_Entry
= (APTR
)AROS_ASMSYMNAME(StringEditFunc
);
406 udata
->StringEditHook
.h_SubEntry
= NULL
;
407 udata
->StringEditHook
.h_Data
= AslBase
;
409 FOGetFonts(ld
, AslBase
);
411 error
= ERROR_NO_FREE_STORE
;
413 /* calc. min. size */
416 for(i
= 0; i
< NUMBUTS
; i
++)
418 if(!bi
[i
].text
) bi
[i
].text
= GetString(bi
[i
].deftextid
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
420 x
= TextLength(&ld
->ld_DummyRP
, bi
[i
].text
, strlen(bi
[i
].text
));
422 #if FOREQ_COOL_BUTTONS
423 #if USE_SHARED_COOLIMAGES
426 bi
[i
].coolimage
= (const struct CoolImage
*)COOL_ObtainImageA(bi
[i
].coolid
, NULL
);
431 if (ld
->ld_TrueColor
)
433 x
+= IMAGEBUTTONEXTRAWIDTH
+ bi
[i
].coolimage
->width
;
440 udata
->ButWidth
= w
+ BUTTONEXTRAWIDTH
;
442 ld
->ld_ButWidth
= udata
->ButWidth
;
443 ld
->ld_NumButtons
= 4;
445 #if FOREQ_COOL_BUTTONS
447 #if USE_SHARED_COOLIMAGES
451 y
= BUTTONEXTRAHEIGHT
+ ld
->ld_Font
->tf_YSize
;
452 if (ld
->ld_TrueColor
)
454 y2
= IMAGEBUTTONEXTRAHEIGHT
+ DEF_COOLIMAGEHEIGHT
;
458 udata
->ButHeight
= (y
> y2
) ? y
: y2
;
459 #if USE_SHARED_COOLIMAGES
463 udata
->ButHeight
= BUTTONEXTRAHEIGHT
+ ld
->ld_Font
->tf_YSize
;
468 udata
->ButHeight
= BUTTONEXTRAHEIGHT
+ ld
->ld_Font
->tf_YSize
;
471 gadrows
= 2; /* button row + string gadgets under listviews */
472 if (iforeq
->ifo_Flags
& FOF_DODRAWMODE
) gadrows
++;
473 if (iforeq
->ifo_Flags
& FOF_DOSTYLE
) gadrows
++;
474 if (iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
)) gadrows
++;
476 ld
->ld_MinWidth
= OUTERSPACINGX
* 2 +
478 udata
->ButWidth
* NUMBUTS
;
480 ld
->ld_MinHeight
= OUTERSPACINGY
* 2 +
481 (GADGETSPACINGY
+ udata
->ButHeight
) * gadrows
+
482 BORDERLVSPACINGY
* 2 +
483 (ld
->ld_Font
->tf_YSize
+ BORDERLVITEMSPACINGY
* 2) * FOREQ_MIN_VISIBLELINES
+
484 FONTPREVIEWHEIGHT
+ GADGETSPACINGY
-
485 GADGETSPACINGY
; /* because the string gadgets are attached to listview gadgets */
487 /* make listview gadgets */
489 sizelvwidth
= PROPSIZE
+
490 FOREQ_VISIBILE_SIZE_CHARS
* ld
->ld_Font
->tf_XSize
+
491 BORDERLVSPACINGX
* 2 +
492 BORDERLVITEMSPACINGX
* 2;
494 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
;
495 y
= ld
->ld_WBorTop
+ OUTERSPACINGY
;
496 w
= -ld
->ld_WBorRight
- ld
->ld_WBorLeft
- OUTERSPACINGX
* 2 - PROPSIZE
- GADGETSPACINGX
- sizelvwidth
;
497 h
= -ld
->ld_WBorBottom
- ld
->ld_WBorTop
- OUTERSPACINGY
* 2 -
498 udata
->ButHeight
* gadrows
-
499 GADGETSPACINGY
* gadrows
-
500 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) +
501 GADGETSPACINGY
; /* because the string gadgets are attached to listview gadgets */
504 struct TagItem lv_tags
[] =
510 {GA_UserData
, (IPTR
)ld
},
511 {GA_ID
, ID_NAMELISTVIEW
},
512 {GA_RelVerify
, TRUE
},
513 {ASLLV_Labels
, (IPTR
)&udata
->NameListviewList
},
515 {TAG_IGNORE
, (IPTR
)&udata
->SizeListviewRenderHook
},
516 {ASLLV_Font
, (IPTR
)ld
->ld_Font
},
520 udata
->NameListview
= gad
= NewObjectA(AslBase
->asllistviewclass
, NULL
, lv_tags
);
521 if (!gad
) goto failure
;
523 lv_tags
[0].ti_Tag
= GA_RelRight
;
524 lv_tags
[0].ti_Data
= -ld
->ld_WBorRight
- OUTERSPACINGX
- sizelvwidth
+ 1;
525 lv_tags
[2].ti_Tag
= GA_Width
;
526 lv_tags
[2].ti_Data
= sizelvwidth
- PROPSIZE
;
527 lv_tags
[5].ti_Data
= ID_SIZELISTVIEW
;
528 lv_tags
[7].ti_Data
= 0;
529 lv_tags
[8].ti_Tag
= GA_Previous
;
530 lv_tags
[8].ti_Data
= (IPTR
)gad
;
531 lv_tags
[9].ti_Tag
= ASLLV_CallBack
;
533 udata
->SizeListview
= gad
= NewObjectA(AslBase
->asllistviewclass
, NULL
, lv_tags
);
534 if (!gad
) goto failure
;
538 /* make scroller gadgets for listviews */
540 x
= -ld
->ld_WBorRight
- OUTERSPACINGX
- PROPSIZE
- sizelvwidth
- GADGETSPACINGX
+ 1;
541 y
= ld
->ld_WBorTop
+ OUTERSPACINGY
;
543 h
= -ld
->ld_WBorBottom
- ld
->ld_WBorTop
- OUTERSPACINGY
* 2 -
544 udata
->ButHeight
* gadrows
-
545 GADGETSPACINGY
* gadrows
-
546 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) +
549 struct TagItem scroller_tags
[] =
555 {GA_ID
, ID_NAMELISTVIEW
},
556 {PGA_NewLook
, TRUE
},
557 {PGA_Borderless
, TRUE
},
558 {PGA_Freedom
, FREEVERT
},
562 {GA_Previous
, (IPTR
)gad
},
566 if (!makescrollergadget(&udata
->NameScrollGad
, ld
, scroller_tags
, AslBase
)) goto failure
;
567 gad
= udata
->NameScrollGad
.arrow2
;
569 scroller_tags
[0].ti_Data
= x
+ sizelvwidth
+ GADGETSPACINGX
;
570 scroller_tags
[1].ti_Data
= y
;
571 scroller_tags
[2].ti_Data
= w
;
572 scroller_tags
[3].ti_Data
= h
;
573 scroller_tags
[4].ti_Data
= ID_SIZELISTVIEW
;
574 scroller_tags
[11].ti_Data
= (IPTR
)gad
;
576 if (!makescrollergadget(&udata
->SizeScrollGad
, ld
, scroller_tags
, AslBase
)) goto failure
;
577 gad
= udata
->SizeScrollGad
.arrow2
;
581 connectscrollerandlistview(&udata
->NameScrollGad
, udata
->NameListview
, AslBase
);
582 connectscrollerandlistview(&udata
->SizeScrollGad
, udata
->SizeListview
, AslBase
);
584 /* make preview gadget */
586 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
;
587 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
-
588 GADGETSPACINGY
- FONTPREVIEWHEIGHT
;
589 w
= -ld
->ld_WBorRight
- ld
->ld_WBorLeft
- OUTERSPACINGX
* 2;
592 struct TagItem preview_tags
[] =
597 {GA_Height
, FONTPREVIEWHEIGHT
},
598 {GA_Previous
, (IPTR
)gad
},
599 {GA_ID
, ID_PREVIEW
},
600 {ASLFP_SampleText
, (IPTR
)iforeq
->ifo_SampleText
},
601 {ASLFP_APen
, iforeq
->ifo_FrontPen
},
602 {ASLFP_BPen
, iforeq
->ifo_BackPen
},
606 udata
->Preview
= gad
= NewObjectA(AslBase
->aslfontpreviewclass
, NULL
, preview_tags
);
607 if (!gad
) goto failure
;
610 /* make string gadgets */
612 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
;
613 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
-
614 (udata
->ButHeight
+ GADGETSPACINGY
) * (gadrows
- 1) -
615 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) + 1;
617 w
= -ld
->ld_WBorRight
- ld
->ld_WBorLeft
- OUTERSPACINGX
* 2 - GADGETSPACINGX
- sizelvwidth
;
620 struct TagItem string_tags
[] =
625 {GA_Height
, udata
->ButHeight
},
626 {GA_Previous
, (IPTR
)gad
},
627 {STRINGA_TextVal
, (IPTR
)"" },
628 {STRINGA_MaxChars
, MAXASLFONTNAME
},
629 {STRINGA_EditHook
, (IPTR
)&udata
->StringEditHook
},
630 {GA_ID
, ID_NAMESTRING
},
631 {GA_RelVerify
, TRUE
},
632 {GA_UserData
, (IPTR
)ld
},
633 {GA_TabCycle
, TRUE
},
634 {STRINGA_Font
, (IPTR
)ld
->ld_Font
},
638 udata
->NameString
= gad
= NewObjectA(AslBase
->aslstringclass
, NULL
, string_tags
);
639 if (!gad
) goto failure
;
641 string_tags
[0].ti_Tag
= GA_RelRight
;
642 string_tags
[0].ti_Data
= -ld
->ld_WBorRight
- OUTERSPACINGX
- sizelvwidth
+ 1;
643 string_tags
[2].ti_Tag
= GA_Width
;
644 string_tags
[2].ti_Data
= sizelvwidth
;
645 string_tags
[4].ti_Data
= (IPTR
)gad
;
646 string_tags
[5].ti_Tag
= STRINGA_LongVal
;
647 string_tags
[5].ti_Data
= iforeq
->ifo_TextAttr
.ta_YSize
;
648 string_tags
[6].ti_Data
= 6;
649 string_tags
[8].ti_Data
= ID_SIZESTRING
;
651 udata
->SizeString
= gad
= NewObjectA(AslBase
->aslstringclass
, NULL
, string_tags
);
652 if (!gad
) goto failure
;
656 /* make button row */
658 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
+ 1;
661 struct TagItem button_tags
[] =
666 #if FOREQ_COOL_BUTTONS
667 {ASLBT_CoolImage
, 0 },
671 {GA_UserData
, (IPTR
)ld
},
674 {GA_Width
, udata
->ButWidth
},
675 {GA_Height
, udata
->ButHeight
},
676 {GA_RelVerify
, TRUE
},
677 {GA_Image
, 0 }, /* means we want a frame */
681 for(i
= 0; i
< NUMBUTS
; i
++)
683 button_tags
[0].ti_Data
= (IPTR
)bi
[i
].text
;
684 button_tags
[1].ti_Data
= (IPTR
)gad
;
685 button_tags
[2].ti_Data
= bi
[i
].gadid
;
686 #if USE_SHARED_COOLIMAGES
687 if (CoolImagesBase
== NULL
) button_tags
[3].ti_Tag
= TAG_IGNORE
;
689 button_tags
[3].ti_Data
= (IPTR
)bi
[i
].coolimage
;
691 *(bi
[i
].objvar
) = gad
= NewObjectA(AslBase
->aslbuttonclass
, NULL
, button_tags
);
692 if (!gad
) goto failure
;
701 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
;
702 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
-
703 (udata
->ButHeight
+ GADGETSPACINGY
) * (gadrows
- 2) -
704 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) + 1;
706 if (iforeq
->ifo_Flags
& (FOF_DODRAWMODE
| FOF_DOSTYLE
| FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
708 #define FSET(x) ((iforeq->ifo_Flags & x) ? TRUE : FALSE)
717 {FSET(FOF_DOSTYLE
) , (STRPTR
)MSG_FONTREQ_STYLE_LABEL
, &udata
->StyleLabel
},
718 {FALSE
, (STRPTR
)MSG_FONTREQ_COLOR_LABEL_FG
, &udata
->ColorLabel
},
719 {FSET(FOF_DODRAWMODE
) , (STRPTR
)MSG_FONTREQ_MODE_LABEL
, &udata
->DrawModeLabel
}
724 struct TagItem label_tags
[] =
729 {GA_Height
, udata
->ButHeight
},
731 {GA_Previous
, (IPTR
)gad
},
732 {GA_UserData
, (IPTR
)ld
},
733 {GA_Disabled
, TRUE
},
738 if (iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
742 switch(iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
748 li
[1].text
= (STRPTR
)MSG_FONTREQ_COLOR_LABEL_BG
;
751 case FOF_DOFRONTPEN
| FOF_DOBACKPEN
:
752 li
[1].text
= (STRPTR
)MSG_FONTREQ_COLOR_LABEL_FGBG
;
756 } /* if (iforeq->ifo_Flags & (FOF_DOFRONTPEN | FOF_DOBACKPEN)) */
757 for(i
= 0, i2
= 0; i
< 3; i
++)
761 if ((i
== 2) && (iforeq
->ifo_ModeList
))
763 li
[i
].text
= iforeq
->ifo_ModeList
[0];
767 li
[i
].text
= GetString((IPTR
)li
[i
].text
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
769 str
[i2
++] = li
[i
].text
;
773 w
= labelwidth
= BiggestTextLength(str
, i2
, &(ld
->ld_DummyRP
), AslBase
);
775 for(i
= 0; i
< 3;i
++)
777 if (!li
[i
].doit
) continue;
779 label_tags
[2].ti_Data
= TextLength(&ld
->ld_DummyRP
, li
[i
].text
, strlen(li
[i
].text
));
780 label_tags
[0].ti_Data
= x
+ w
- label_tags
[2].ti_Data
;
781 label_tags
[4].ti_Data
= (IPTR
)li
[i
].text
;
782 label_tags
[5].ti_Data
= (IPTR
)gad
;
784 *(li
[i
].objvar
) = gad
= NewObjectA(AslBase
->aslbuttonclass
, NULL
, label_tags
);
785 if (!gad
) goto failure
;
787 y
+= udata
->ButHeight
+ GADGETSPACINGY
;
788 label_tags
[1].ti_Data
= y
;
791 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
-
792 (udata
->ButHeight
+ GADGETSPACINGY
) * (gadrows
- 2) -
793 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) + 1;
795 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
+ w
+ LABELSPACINGX
;
797 /* Make Style gadget */
799 if (iforeq
->ifo_Flags
& FOF_DOSTYLE
)
801 STRPTR stylestrings
[3];
803 struct TagItem style_tags
[] =
805 {GA_Previous
, (IPTR
)gad
},
809 {GA_Height
, udata
->ButHeight
},
810 {GA_RelVerify
, TRUE
},
811 {GA_UserData
, (IPTR
)ld
},
813 {ASLFS_LabelArray
, (IPTR
)stylestrings
},
814 {ASLFS_Style
, iforeq
->ifo_TextAttr
.ta_Style
},
818 stylestrings
[0] = GetString(MSG_FONTREQ_STYLE_BOLD
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
819 stylestrings
[1] = GetString(MSG_FONTREQ_STYLE_ITALIC
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
820 stylestrings
[2] = GetString(MSG_FONTREQ_STYLE_UNDERLINED
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
822 w
= BiggestTextLength(stylestrings
, 3, &(ld
->ld_DummyRP
), AslBase
);
826 style_tags
[3].ti_Data
= w
;
828 if (w
> maxgadcolwidth
) maxgadcolwidth
= w
;
830 udata
->StyleGadget
= gad
= NewObjectA(AslBase
->aslfontstyleclass
, NULL
, style_tags
);
831 if (!gad
) goto failure
;
833 y
+= udata
->ButHeight
+ GADGETSPACINGY
;
837 w
= udata
->ButHeight
* 12 / 10 + 19; /* CYCLEIMAGEWIDTH = 19 */
839 /* Make FrontPen gadget */
841 if (iforeq
->ifo_Flags
& FOF_DOFRONTPEN
)
843 struct TagItem cp_tags
[] =
845 {GA_Previous
, (IPTR
)gad
},
849 {GA_Height
, udata
->ButHeight
},
850 {GA_RelVerify
, TRUE
},
851 {GA_UserData
, (IPTR
)ld
},
852 {GA_ID
, ID_FRONTPEN
},
853 {ASLCP_Color
, iforeq
->ifo_FrontPen
},
854 {ASLCP_ColorTable
, (IPTR
)iforeq
->ifo_FrontPens
},
855 {ASLCP_NumColors
, iforeq
->ifo_MaxFrontPen
},
860 udata
->FGColorGadget
= gad
= NewObjectA(AslBase
->aslcolorpickerclass
, NULL
, cp_tags
);
861 if (!gad
) goto failure
;
863 x
+= w
+ GADGETSPACINGX
;
866 /* Make BackPen gadget */
868 if (iforeq
->ifo_Flags
& FOF_DOBACKPEN
)
870 struct TagItem cp_tags
[] =
872 {GA_Previous
, (IPTR
)gad
},
876 {GA_Height
, udata
->ButHeight
},
877 {GA_RelVerify
, TRUE
},
878 {GA_UserData
, (IPTR
)ld
},
879 {GA_ID
, ID_BACKPEN
},
880 {ASLCP_Color
, iforeq
->ifo_BackPen
},
881 {ASLCP_ColorTable
, (IPTR
)iforeq
->ifo_BackPens
},
882 {ASLCP_NumColors
, iforeq
->ifo_MaxBackPen
},
887 udata
->BGColorGadget
= gad
= NewObjectA(AslBase
->aslcolorpickerclass
, NULL
, cp_tags
);
888 if (!gad
) goto failure
;
892 if (iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
894 if ((iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
)) == (FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
896 w
+= GADGETSPACINGX
+ w
;
899 if (w
> maxgadcolwidth
) maxgadcolwidth
= w
;
901 y
+= udata
->ButHeight
+ GADGETSPACINGY
;
905 /* Make DrawMode gadget */
907 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
+ labelwidth
+ LABELSPACINGX
;
909 w
= -ld
->ld_WBorLeft
- ld
->ld_WBorRight
- OUTERSPACINGX
* 2 -
910 labelwidth
- LABELSPACINGX
;
913 if (iforeq
->ifo_Flags
& FOF_DODRAWMODE
)
915 struct TagItem cycle_tags
[] =
917 {GA_Previous
, (IPTR
)gad
},
921 {GA_Height
, udata
->ButHeight
},
922 {GA_RelVerify
, TRUE
},
923 {GA_UserData
, (IPTR
)ld
},
924 {GA_ID
, ID_DRAWMODE
},
926 {ASLCY_Active
, iforeq
->ifo_DrawMode
},
927 {ASLCY_Font
, (IPTR
)ld
->ld_Font
},
931 static LONG labelids
[] =
933 MSG_FONTREQ_MODE_TEXT
,
934 MSG_FONTREQ_MODE_TEXTANDFIELD
,
935 MSG_FONTREQ_MODE_COMPLEMENT
,
940 if (iforeq
->ifo_ModeList
)
942 labels
= &iforeq
->ifo_ModeList
[1];
946 labels
= (STRPTR
*)&iforeq
->ifo_DrawModeJAM1Text
;
948 for(i
= 0; i
< 3; i
++)
950 labels
[i
] = GetString(labelids
[i
], GetIR(iforeq
)->ir_Catalog
, AslBase
);
954 cycle_tags
[8].ti_Data
= (IPTR
)labels
;
956 i
= CYCLEEXTRAWIDTH
+ BiggestTextLength(labels
,
960 if (i
> maxgadcolwidth
) maxgadcolwidth
= i
;
962 udata
->DrawModeGadget
= gad
= NewObjectA(AslBase
->aslcycleclass
, NULL
, cycle_tags
);
963 if (!gad
) goto failure
;
965 y
+= udata
->ButHeight
+ GADGETSPACINGY
;
967 } /* if (iforeq->ifo_Flags & FOF_DODRAWMODE) */
969 } /* if (iforeq->ifo_Flags & (FOF_DODRAWMODE | FOF_DOSTYLE | FOF_DOFRONTPEN | FOF_DOBACKPEN)) */
973 struct TagItem eraser_tags
[] =
975 {GA_Previous
, (IPTR
)gad
},
979 udata
->EraserGadget
= gad
= NewObjectA(AslBase
->asleraserclass
, NULL
, eraser_tags
);
980 /* Doesn't matter if this failed */
984 w
= OUTERSPACINGX
+ labelwidth
+ LABELSPACINGX
+ maxgadcolwidth
+ OUTERSPACINGX
;
985 if (w
> ld
->ld_MinWidth
) ld
->ld_MinWidth
= w
;
987 ld
->ld_GList
= (struct Gadget
*)udata
->NameListview
;
991 struct NewMenu nm
[] =
993 {NM_TITLE
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL
},
994 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_LASTFONT
, 0, 0, 0, (APTR
)FOMEN_LASTFONT
},
995 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_NEXTFONT
, 0, 0, 0, (APTR
)FOMEN_NEXTFONT
},
996 {NM_ITEM
, NM_BARLABEL
},
997 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_RESTORE
, 0, 0, 0, (APTR
)FOMEN_RESTORE
},
998 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_RESCAN
, 0, 0, 0, (APTR
)FOMEN_RESCAN
},
999 {NM_ITEM
, NM_BARLABEL
},
1000 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_OK
, 0, 0, 0, (APTR
)FOMEN_OK
},
1001 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_CANCEL
, 0, 0, 0, (APTR
)FOMEN_CANCEL
},
1005 struct TagItem menu_tags
[] =
1007 {GTMN_NewLookMenus
, TRUE
},
1008 {GTMN_TextAttr
, (IPTR
)GetIR(iforeq
)->ir_TextAttr
},
1012 if (menu_tags
[1].ti_Data
== 0) menu_tags
[1].ti_Tag
= TAG_IGNORE
;
1014 LocalizeMenus(nm
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
1016 /* Don't fail, if menus cannot be created/layouted, because a requester
1017 without menus is still better than no requester at all */
1019 if ((ld
->ld_Menu
= CreateMenusA(nm
, NULL
)))
1021 if (!LayoutMenusA(ld
->ld_Menu
, ld
->ld_VisualInfo
, menu_tags
))
1023 FreeMenus(ld
->ld_Menu
);ld
->ld_Menu
= NULL
;
1028 FORestore(ld
, iforeq
->ifo_TextAttr
.ta_Name
, iforeq
->ifo_TextAttr
.ta_YSize
, AslBase
);
1031 ReturnBool ("FOGadInit", TRUE
);
1036 D(bug("failure\n"));
1038 FOGadCleanup(ld
, ASLB(AslBase
));
1040 ReturnBool ("FOGadInit", FALSE
);
1044 /*****************************************************************************************/
1046 STATIC VOID
FOWindowOpened(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1048 // struct IntFontReq *iforeq = (struct IntFontReq *)ld->ld_IntReq;
1051 /*****************************************************************************************/
1053 STATIC BOOL
FOGadLayout(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1055 ReturnBool ("FOGadLayout", TRUE
);
1058 /*****************************************************************************************/
1060 STATIC ULONG
FOHandleEvents(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1062 struct IntuiMessage
*imsg
= ld
->ld_Event
;
1063 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
1064 struct IntFontReq
*iforeq
= (struct IntFontReq
*)ld
->ld_IntReq
;
1066 ULONG retval
= GHRET_OK
;
1068 EnterFunc(bug("FOHandleEvents: Class: %d\n", imsg
->Class
));
1070 switch (imsg
->Class
)
1072 case IDCMP_CLOSEWINDOW
:
1080 FOChangeActiveFont(ld
, -1, imsg
->Qualifier
, FALSE
, AslBase
);
1084 FOChangeActiveFont(ld
, -1, IEQUALIFIER_LSHIFT
, FALSE
, AslBase
);
1088 FOChangeActiveFont(ld
, -1, IEQUALIFIER_LALT
, FALSE
, AslBase
);
1091 case RAWKEY_NM_WHEEL_UP
:
1092 FOChangeActiveFont(ld
, -3, imsg
->Qualifier
, FALSE
, AslBase
);
1096 FOChangeActiveFont(ld
, 1, imsg
->Qualifier
, FALSE
, AslBase
);
1099 case RAWKEY_PAGEDOWN
:
1100 FOChangeActiveFont(ld
, 1, IEQUALIFIER_LSHIFT
, FALSE
, AslBase
);
1104 FOChangeActiveFont(ld
, 1, IEQUALIFIER_LALT
, FALSE
, AslBase
);
1107 case RAWKEY_NM_WHEEL_DOWN
:
1108 FOChangeActiveFont(ld
, 3, imsg
->Qualifier
, FALSE
, AslBase
);
1113 case IDCMP_VANILLAKEY
:
1122 case IDCMP_GADGETUP
:
1123 gadid
= ((struct Gadget
*)imsg
->IAddress
)->GadgetID
;
1125 D(bug("GADGETUP! gadgetid=%d code=%d\n", gadid
, imsg
->Code
));
1134 retval
= FOGetSelectedFont(ld
, AslBase
);
1137 case ID_NAMELISTVIEW
:
1139 struct ASLLVFontReqNode
*fontnode
;
1143 GetAttr(ASLLV_Active
, udata
->NameListview
, &active
);
1144 GetAttr(STRINGA_LongVal
, udata
->SizeString
, &size
);
1146 if ((fontnode
= (struct ASLLVFontReqNode
*)FindListNode(&udata
->NameListviewList
, (WORD
)active
)))
1148 FOActivateFont(ld
, active
, (LONG
)size
, AslBase
);
1150 if (imsg
->Code
) /* TRUE if double clicked */
1152 retval
= FOGetSelectedFont(ld
, AslBase
);
1155 ActivateGadget((struct Gadget
*)udata
->NameString
, ld
->ld_Window
, NULL
);
1159 case ID_SIZELISTVIEW
:
1160 if (udata
->ActiveFont
)
1165 GetAttr(ASLLV_Active
, udata
->SizeListview
, &active
);
1167 if ((node
= FindListNode(&udata
->ActiveFont
->SizeList
, (WORD
)active
)))
1169 FOSetSizeString((IPTR
)node
->ln_Name
, ld
, AslBase
);
1170 FOUpdatePreview(ld
, AslBase
);
1172 if (imsg
->Code
) /* TRUE if double clicked */
1174 retval
= FOGetSelectedFont(ld
, AslBase
);
1177 ActivateGadget((struct Gadget
*)udata
->SizeString
, ld
->ld_Window
, NULL
);
1182 if (imsg
->Code
== STRINGCODE_CURSORUP
)
1184 FOChangeActiveFont(ld
, -1, imsg
->Qualifier
, TRUE
, AslBase
);
1185 ActivateGadget((struct Gadget
*)udata
->NameString
, ld
->ld_Window
, NULL
);
1188 else if (imsg
->Code
== STRINGCODE_CURSORDOWN
)
1190 FOChangeActiveFont(ld
, 1, imsg
->Qualifier
, TRUE
, AslBase
);
1191 ActivateGadget((struct Gadget
*)udata
->NameString
, ld
->ld_Window
, NULL
);
1194 else if ((imsg
->Code
== 0) || (imsg
->Code
== 9))
1196 FOUpdatePreview(ld
, AslBase
);
1202 if (imsg
->Code
== STRINGCODE_CURSORUP
)
1204 FOChangeActiveSize(ld
, -1, imsg
->Qualifier
, AslBase
);
1205 ActivateGadget((struct Gadget
*)udata
->SizeString
, ld
->ld_Window
, NULL
);
1208 else if (imsg
->Code
== STRINGCODE_CURSORDOWN
)
1210 FOChangeActiveSize(ld
, 1, imsg
->Qualifier
, AslBase
);
1211 ActivateGadget((struct Gadget
*)udata
->SizeString
, ld
->ld_Window
, NULL
);
1214 else if ((imsg
->Code
== 0) || (imsg
->Code
== 9))
1219 GetAttr(STRINGA_LongVal
, udata
->SizeString
, (IPTR
*)&val
);
1222 if ((size
< iforeq
->ifo_MinHeight
) || (size
> iforeq
->ifo_MaxHeight
))
1224 if (size
< iforeq
->ifo_MinHeight
) size
= iforeq
->ifo_MinHeight
;
1225 if (size
> iforeq
->ifo_MaxHeight
) size
= iforeq
->ifo_MaxHeight
;
1226 FOSetSizeString(size
, ld
, AslBase
);
1229 FOActivateSize(ld
, -size
, AslBase
);
1238 FOUpdatePreview(ld
, AslBase
);
1241 } /* switch (gadget ID) */
1243 break; /* case IDCMP_GADGETUP: */
1245 case IDCMP_MENUPICK
:
1248 UWORD men
= imsg
->Code
;
1250 while(men
!= MENUNULL
)
1252 struct MenuItem
*item
;
1254 if ((item
= ItemAddress(ld
->ld_Menu
, men
)))
1256 switch((IPTR
)GTMENUITEM_USERDATA(item
))
1260 case FOMEN_LASTFONT
:
1261 FOChangeActiveFont(ld
, -1, 0, FALSE
, AslBase
);
1264 case FOMEN_NEXTFONT
:
1265 FOChangeActiveFont(ld
, 1, 0, FALSE
, AslBase
);
1269 FORestore(ld
, iforeq
->ifo_TextAttr
.ta_Name
, iforeq
->ifo_TextAttr
.ta_YSize
, AslBase
);
1273 FOGetFonts(ld
, AslBase
);
1277 retval
= FOGetSelectedFont(ld
, AslBase
);
1286 men
= item
->NextSelect
;
1287 } /* if ((item = ItemAddress(ld->ld_Menu, men))) */
1293 } /* while(men != MENUNULL) */
1295 } /* if (ld->ld_Menu) */
1297 break; /* case IDCMP_MENUPICK: */
1299 } /* switch (imsg->Class) */
1301 ReturnInt ("FOHandleEvents", ULONG
, retval
);
1304 /*****************************************************************************************/
1306 STATIC VOID
FOGadCleanup(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1308 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
1309 struct FontRequester
*req
= (struct FontRequester
*)ld
->ld_Req
;
1310 struct IntReq
*intreq
= ld
->ld_IntReq
;
1311 // struct IntFontReq *iforeq = (struct IntFontReq *)intreq;
1313 EnterFunc(bug("FOGadCleanup(ld=%p)\n", ld
));
1315 if (ld
->ld_Window
&& ld
->ld_GList
)
1317 RemoveGList(ld
->ld_Window
, ld
->ld_GList
, -1);
1320 killscrollergadget(&udata
->NameScrollGad
, AslBase
);
1321 killscrollergadget(&udata
->SizeScrollGad
, AslBase
);
1323 FreeObjects(&FOREQ_FIRST_OBJECT(udata
), &FOREQ_LAST_OBJECT(udata
), AslBase
);
1325 FOFreeFonts(ld
, AslBase
);
1327 if (udata
->PreviewFont
) CloseFont(udata
->PreviewFont
);
1331 req
->fo_LeftEdge
= intreq
->ir_LeftEdge
= ld
->ld_Window
->LeftEdge
;
1332 req
->fo_TopEdge
= intreq
->ir_TopEdge
= ld
->ld_Window
->TopEdge
;
1333 req
->fo_Width
= intreq
->ir_Width
= ld
->ld_Window
->Width
;
1334 req
->fo_Height
= intreq
->ir_Height
= ld
->ld_Window
->Height
;
1337 ReturnVoid("FOGadCleanup");
1340 /*****************************************************************************************/
1342 STATIC ULONG
FOGetSelectedFont(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1344 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
1345 struct IntReq
*intreq
= ld
->ld_IntReq
;
1346 struct IntFontReq
*iforeq
= (struct IntFontReq
*)intreq
;
1347 struct FontRequester
*req
= (struct FontRequester
*)ld
->ld_Req
;
1350 ULONG retval
= GHRET_OK
;
1352 GetAttr(STRINGA_TextVal
, udata
->NameString
, (IPTR
*)&name
);
1353 if (!(req
->fo_TAttr
.tta_Name
= VecPooledCloneString(name
, ".font", intreq
->ir_MemPool
, AslBase
))) goto bye
;
1354 iforeq
->ifo_TextAttr
.ta_Name
= req
->fo_TAttr
.tta_Name
;
1356 GetAttr(STRINGA_LongVal
, udata
->SizeString
, &val
);
1357 req
->fo_TAttr
.tta_YSize
= iforeq
->ifo_TextAttr
.ta_YSize
= (UWORD
)val
;
1361 if (iforeq
->ifo_Flags
& FOF_DODRAWMODE
)
1363 iforeq
->ifo_DrawMode
= FOGetDrawMode(ld
, AslBase
);
1365 req
->fo_DrawMode
= iforeq
->ifo_DrawMode
;
1370 if (iforeq
->ifo_Flags
& FOF_DOSTYLE
)
1372 iforeq
->ifo_TextAttr
.ta_Style
= FOGetStyle(ld
, AslBase
);
1374 req
->fo_TAttr
.tta_Style
= iforeq
->ifo_TextAttr
.ta_Style
;
1376 if (iforeq
->ifo_Flags
& FOF_DOFRONTPEN
)
1378 iforeq
->ifo_FrontPen
= FOGetFGColor(ld
, AslBase
);
1380 req
->fo_FrontPen
= iforeq
->ifo_FrontPen
;
1382 if (iforeq
->ifo_Flags
& FOF_DOBACKPEN
)
1384 iforeq
->ifo_BackPen
= FOGetBGColor(ld
, AslBase
);
1386 req
->fo_BackPen
= iforeq
->ifo_BackPen
;
1388 /* Hmm ... there is also a struct TextAttr fo_Attr in
1389 FontRequester structure. Just put the same values in!? */
1391 req
->fo_Attr
.ta_Name
= req
->fo_TAttr
.tta_Name
;
1392 req
->fo_Attr
.ta_YSize
= req
->fo_TAttr
.tta_YSize
;
1393 req
->fo_Attr
.ta_Style
= req
->fo_TAttr
.tta_Style
;
1394 req
->fo_Attr
.ta_Flags
= req
->fo_TAttr
.tta_Flags
;
1396 retval
= GHRET_FINISHED_OK
;
1402 /*****************************************************************************************/