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 const 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
));
334 retval
= (ULONG
)FOGadLayout(ld
, ASLB(AslBase
));
337 case LDCMD_HANDLEEVENTS
:
338 retval
= (ULONG
)FOHandleEvents(ld
, ASLB(AslBase
));
342 FOGadCleanup(ld
, ASLB(AslBase
));
356 /*****************************************************************************************/
363 #if USE_SHARED_COOLIMAGES
366 const struct CoolImage
*coolimage
;
368 const struct CoolImage
*coolimage
;
373 /*****************************************************************************************/
375 STATIC BOOL
FOGadInit(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
377 struct FOUserData
*udata
= ld
->ld_UserData
;
378 struct IntFontReq
*iforeq
= (struct IntFontReq
*)ld
->ld_IntReq
;
380 #if USE_SHARED_COOLIMAGES
381 struct ButtonInfo bi
[NUMBUTS
] =
383 { ID_BUTOK
, GetIR(iforeq
)->ir_PositiveText
, MSG_FONTREQ_POSITIVE_GAD
, COOL_USEIMAGE_ID
, &udata
->OKBut
},
384 { ID_BUTCANCEL
, GetIR(iforeq
)->ir_NegativeText
, MSG_FONTREQ_NEGATIVE_GAD
, COOL_CANCELIMAGE_ID
, &udata
->CancelBut
}
387 struct ButtonInfo bi
[NUMBUTS
] =
389 { ID_BUTOK
, GetIR(iforeq
)->ir_PositiveText
, MSG_FONTREQ_POSITIVE_GAD
, &cool_useimage
, &udata
->OKBut
},
390 { ID_BUTCANCEL
, GetIR(iforeq
)->ir_NegativeText
, MSG_FONTREQ_NEGATIVE_GAD
, &cool_cancelimage
, &udata
->CancelBut
}
395 WORD gadrows
, x
, y
, w
, h
, i
, y2
;
396 WORD sizelvwidth
, labelwidth
= 0, maxgadcolwidth
= 0;
398 NEWLIST(&udata
->NameListviewList
);
400 udata
->SizeListviewRenderHook
.h_Entry
= (APTR
)AROS_ASMSYMNAME(SizeListviewRenderFunc
);
401 udata
->SizeListviewRenderHook
.h_SubEntry
= NULL
;
402 udata
->SizeListviewRenderHook
.h_Data
= AslBase
;
404 udata
->StringEditHook
.h_Entry
= (APTR
)AROS_ASMSYMNAME(StringEditFunc
);
405 udata
->StringEditHook
.h_SubEntry
= NULL
;
406 udata
->StringEditHook
.h_Data
= AslBase
;
408 FOGetFonts(ld
, AslBase
);
410 error
= ERROR_NO_FREE_STORE
;
412 /* calc. min. size */
415 for(i
= 0; i
< NUMBUTS
; i
++)
417 if(!bi
[i
].text
) bi
[i
].text
= GetString(bi
[i
].deftextid
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
419 x
= TextLength(&ld
->ld_DummyRP
, bi
[i
].text
, strlen(bi
[i
].text
));
421 #if FOREQ_COOL_BUTTONS
422 #if USE_SHARED_COOLIMAGES
425 bi
[i
].coolimage
= (const struct CoolImage
*)COOL_ObtainImageA(bi
[i
].coolid
, NULL
);
430 if (ld
->ld_TrueColor
)
432 x
+= IMAGEBUTTONEXTRAWIDTH
+ bi
[i
].coolimage
->width
;
439 udata
->ButWidth
= w
+ BUTTONEXTRAWIDTH
;
441 ld
->ld_ButWidth
= udata
->ButWidth
;
442 ld
->ld_NumButtons
= 4;
444 #if FOREQ_COOL_BUTTONS
446 #if USE_SHARED_COOLIMAGES
450 y
= BUTTONEXTRAHEIGHT
+ ld
->ld_Font
->tf_YSize
;
451 if (ld
->ld_TrueColor
)
453 y2
= IMAGEBUTTONEXTRAHEIGHT
+ DEF_COOLIMAGEHEIGHT
;
457 udata
->ButHeight
= (y
> y2
) ? y
: y2
;
458 #if USE_SHARED_COOLIMAGES
462 udata
->ButHeight
= BUTTONEXTRAHEIGHT
+ ld
->ld_Font
->tf_YSize
;
467 udata
->ButHeight
= BUTTONEXTRAHEIGHT
+ ld
->ld_Font
->tf_YSize
;
470 gadrows
= 2; /* button row + string gadgets under listviews */
471 if (iforeq
->ifo_Flags
& FOF_DODRAWMODE
) gadrows
++;
472 if (iforeq
->ifo_Flags
& FOF_DOSTYLE
) gadrows
++;
473 if (iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
)) gadrows
++;
475 ld
->ld_MinWidth
= OUTERSPACINGX
* 2 +
477 udata
->ButWidth
* NUMBUTS
;
479 ld
->ld_MinHeight
= OUTERSPACINGY
* 2 +
480 (GADGETSPACINGY
+ udata
->ButHeight
) * gadrows
+
481 BORDERLVSPACINGY
* 2 +
482 (ld
->ld_Font
->tf_YSize
+ BORDERLVITEMSPACINGY
* 2) * FOREQ_MIN_VISIBLELINES
+
483 FONTPREVIEWHEIGHT
+ GADGETSPACINGY
-
484 GADGETSPACINGY
; /* because the string gadgets are attached to listview gadgets */
486 /* make listview gadgets */
488 sizelvwidth
= PROPSIZE
+
489 FOREQ_VISIBILE_SIZE_CHARS
* ld
->ld_Font
->tf_XSize
+
490 BORDERLVSPACINGX
* 2 +
491 BORDERLVITEMSPACINGX
* 2;
493 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
;
494 y
= ld
->ld_WBorTop
+ OUTERSPACINGY
;
495 w
= -ld
->ld_WBorRight
- ld
->ld_WBorLeft
- OUTERSPACINGX
* 2 - PROPSIZE
- GADGETSPACINGX
- sizelvwidth
;
496 h
= -ld
->ld_WBorBottom
- ld
->ld_WBorTop
- OUTERSPACINGY
* 2 -
497 udata
->ButHeight
* gadrows
-
498 GADGETSPACINGY
* gadrows
-
499 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) +
500 GADGETSPACINGY
; /* because the string gadgets are attached to listview gadgets */
503 struct TagItem lv_tags
[] =
509 {GA_UserData
, (IPTR
)ld
},
510 {GA_ID
, ID_NAMELISTVIEW
},
511 {GA_RelVerify
, TRUE
},
512 {ASLLV_Labels
, (IPTR
)&udata
->NameListviewList
},
514 {TAG_IGNORE
, (IPTR
)&udata
->SizeListviewRenderHook
},
515 {ASLLV_Font
, (IPTR
)ld
->ld_Font
},
519 udata
->NameListview
= gad
= NewObjectA(AslBase
->asllistviewclass
, NULL
, lv_tags
);
520 if (!gad
) goto failure
;
522 lv_tags
[0].ti_Tag
= GA_RelRight
;
523 lv_tags
[0].ti_Data
= -ld
->ld_WBorRight
- OUTERSPACINGX
- sizelvwidth
+ 1;
524 lv_tags
[2].ti_Tag
= GA_Width
;
525 lv_tags
[2].ti_Data
= sizelvwidth
- PROPSIZE
;
526 lv_tags
[5].ti_Data
= ID_SIZELISTVIEW
;
527 lv_tags
[7].ti_Data
= 0;
528 lv_tags
[8].ti_Tag
= GA_Previous
;
529 lv_tags
[8].ti_Data
= (IPTR
)gad
;
530 lv_tags
[9].ti_Tag
= ASLLV_CallBack
;
532 udata
->SizeListview
= gad
= NewObjectA(AslBase
->asllistviewclass
, NULL
, lv_tags
);
533 if (!gad
) goto failure
;
537 /* make scroller gadgets for listviews */
539 x
= -ld
->ld_WBorRight
- OUTERSPACINGX
- PROPSIZE
- sizelvwidth
- GADGETSPACINGX
+ 1;
540 y
= ld
->ld_WBorTop
+ OUTERSPACINGY
;
542 h
= -ld
->ld_WBorBottom
- ld
->ld_WBorTop
- OUTERSPACINGY
* 2 -
543 udata
->ButHeight
* gadrows
-
544 GADGETSPACINGY
* gadrows
-
545 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) +
548 struct TagItem scroller_tags
[] =
554 {GA_ID
, ID_NAMELISTVIEW
},
555 {PGA_NewLook
, TRUE
},
556 {PGA_Borderless
, TRUE
},
557 {PGA_Freedom
, FREEVERT
},
561 {GA_Previous
, (IPTR
)gad
},
565 if (!makescrollergadget(&udata
->NameScrollGad
, ld
, scroller_tags
, AslBase
)) goto failure
;
566 gad
= udata
->NameScrollGad
.arrow2
;
568 scroller_tags
[0].ti_Data
= x
+ sizelvwidth
+ GADGETSPACINGX
;
569 scroller_tags
[1].ti_Data
= y
;
570 scroller_tags
[2].ti_Data
= w
;
571 scroller_tags
[3].ti_Data
= h
;
572 scroller_tags
[4].ti_Data
= ID_SIZELISTVIEW
;
573 scroller_tags
[11].ti_Data
= (IPTR
)gad
;
575 if (!makescrollergadget(&udata
->SizeScrollGad
, ld
, scroller_tags
, AslBase
)) goto failure
;
576 gad
= udata
->SizeScrollGad
.arrow2
;
580 connectscrollerandlistview(&udata
->NameScrollGad
, udata
->NameListview
, AslBase
);
581 connectscrollerandlistview(&udata
->SizeScrollGad
, udata
->SizeListview
, AslBase
);
583 /* make preview gadget */
585 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
;
586 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
-
587 GADGETSPACINGY
- FONTPREVIEWHEIGHT
;
588 w
= -ld
->ld_WBorRight
- ld
->ld_WBorLeft
- OUTERSPACINGX
* 2;
591 struct TagItem preview_tags
[] =
596 {GA_Height
, FONTPREVIEWHEIGHT
},
597 {GA_Previous
, (IPTR
)gad
},
598 {GA_ID
, ID_PREVIEW
},
599 {ASLFP_SampleText
, (IPTR
)iforeq
->ifo_SampleText
},
600 {ASLFP_APen
, iforeq
->ifo_FrontPen
},
601 {ASLFP_BPen
, iforeq
->ifo_BackPen
},
605 udata
->Preview
= gad
= NewObjectA(AslBase
->aslfontpreviewclass
, NULL
, preview_tags
);
606 if (!gad
) goto failure
;
609 /* make string gadgets */
611 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
;
612 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
-
613 (udata
->ButHeight
+ GADGETSPACINGY
) * (gadrows
- 1) -
614 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) + 1;
616 w
= -ld
->ld_WBorRight
- ld
->ld_WBorLeft
- OUTERSPACINGX
* 2 - GADGETSPACINGX
- sizelvwidth
;
619 struct TagItem string_tags
[] =
624 {GA_Height
, udata
->ButHeight
},
625 {GA_Previous
, (IPTR
)gad
},
626 {STRINGA_TextVal
, (IPTR
)"" },
627 {STRINGA_MaxChars
, MAXFONTNAME
},
628 {STRINGA_EditHook
, (IPTR
)&udata
->StringEditHook
},
629 {GA_ID
, ID_NAMESTRING
},
630 {GA_RelVerify
, TRUE
},
631 {GA_UserData
, (IPTR
)ld
},
632 {GA_TabCycle
, TRUE
},
633 {STRINGA_Font
, (IPTR
)ld
->ld_Font
},
637 udata
->NameString
= gad
= NewObjectA(AslBase
->aslstringclass
, NULL
, string_tags
);
638 if (!gad
) goto failure
;
640 string_tags
[0].ti_Tag
= GA_RelRight
;
641 string_tags
[0].ti_Data
= -ld
->ld_WBorRight
- OUTERSPACINGX
- sizelvwidth
+ 1;
642 string_tags
[2].ti_Tag
= GA_Width
;
643 string_tags
[2].ti_Data
= sizelvwidth
;
644 string_tags
[4].ti_Data
= (IPTR
)gad
;
645 string_tags
[5].ti_Tag
= STRINGA_LongVal
;
646 string_tags
[5].ti_Data
= iforeq
->ifo_TextAttr
.ta_YSize
;
647 string_tags
[6].ti_Data
= 6;
648 string_tags
[8].ti_Data
= ID_SIZESTRING
;
650 udata
->SizeString
= gad
= NewObjectA(AslBase
->aslstringclass
, NULL
, string_tags
);
651 if (!gad
) goto failure
;
655 /* make button row */
657 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
+ 1;
660 struct TagItem button_tags
[] =
665 #if FOREQ_COOL_BUTTONS
666 {ASLBT_CoolImage
, 0 },
670 {GA_UserData
, (IPTR
)ld
},
673 {GA_Width
, udata
->ButWidth
},
674 {GA_Height
, udata
->ButHeight
},
675 {GA_RelVerify
, TRUE
},
676 {GA_Image
, 0 }, /* means we want a frame */
680 for(i
= 0; i
< NUMBUTS
; i
++)
682 button_tags
[0].ti_Data
= (IPTR
)bi
[i
].text
;
683 button_tags
[1].ti_Data
= (IPTR
)gad
;
684 button_tags
[2].ti_Data
= bi
[i
].gadid
;
685 #if USE_SHARED_COOLIMAGES
686 if (CoolImagesBase
== NULL
) button_tags
[3].ti_Tag
= TAG_IGNORE
;
688 button_tags
[3].ti_Data
= (IPTR
)bi
[i
].coolimage
;
690 *(bi
[i
].objvar
) = gad
= NewObjectA(AslBase
->aslbuttonclass
, NULL
, button_tags
);
691 if (!gad
) goto failure
;
700 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
;
701 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
-
702 (udata
->ButHeight
+ GADGETSPACINGY
) * (gadrows
- 2) -
703 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) + 1;
705 if (iforeq
->ifo_Flags
& (FOF_DODRAWMODE
| FOF_DOSTYLE
| FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
707 #define FSET(x) ((iforeq->ifo_Flags & x) ? TRUE : FALSE)
716 {FSET(FOF_DOSTYLE
) , (STRPTR
)MSG_FONTREQ_STYLE_LABEL
, &udata
->StyleLabel
},
717 {FALSE
, (STRPTR
)MSG_FONTREQ_COLOR_LABEL_FG
, &udata
->ColorLabel
},
718 {FSET(FOF_DODRAWMODE
) , (STRPTR
)MSG_FONTREQ_MODE_LABEL
, &udata
->DrawModeLabel
}
723 struct TagItem label_tags
[] =
728 {GA_Height
, udata
->ButHeight
},
730 {GA_Previous
, (IPTR
)gad
},
731 {GA_UserData
, (IPTR
)ld
},
732 {GA_Disabled
, TRUE
},
737 if (iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
741 switch(iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
747 li
[1].text
= (STRPTR
)MSG_FONTREQ_COLOR_LABEL_BG
;
750 case FOF_DOFRONTPEN
| FOF_DOBACKPEN
:
751 li
[1].text
= (STRPTR
)MSG_FONTREQ_COLOR_LABEL_FGBG
;
755 } /* if (iforeq->ifo_Flags & (FOF_DOFRONTPEN | FOF_DOBACKPEN)) */
756 for(i
= 0, i2
= 0; i
< 3; i
++)
760 if ((i
== 2) && (iforeq
->ifo_ModeList
))
762 li
[i
].text
= iforeq
->ifo_ModeList
[0];
766 li
[i
].text
= GetString((LONG
)li
[i
].text
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
768 str
[i2
++] = li
[i
].text
;
772 w
= labelwidth
= BiggestTextLength(str
, i2
, &(ld
->ld_DummyRP
), AslBase
);
774 for(i
= 0; i
< 3;i
++)
776 if (!li
[i
].doit
) continue;
778 label_tags
[2].ti_Data
= TextLength(&ld
->ld_DummyRP
, li
[i
].text
, strlen(li
[i
].text
));
779 label_tags
[0].ti_Data
= x
+ w
- label_tags
[2].ti_Data
;
780 label_tags
[4].ti_Data
= (IPTR
)li
[i
].text
;
781 label_tags
[5].ti_Data
= (IPTR
)gad
;
783 *(li
[i
].objvar
) = gad
= NewObjectA(AslBase
->aslbuttonclass
, NULL
, label_tags
);
784 if (!gad
) goto failure
;
786 y
+= udata
->ButHeight
+ GADGETSPACINGY
;
787 label_tags
[1].ti_Data
= y
;
790 y
= -ld
->ld_WBorBottom
- OUTERSPACINGY
- udata
->ButHeight
-
791 (udata
->ButHeight
+ GADGETSPACINGY
) * (gadrows
- 2) -
792 (FONTPREVIEWHEIGHT
+ GADGETSPACINGY
) + 1;
794 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
+ w
+ LABELSPACINGX
;
796 /* Make Style gadget */
798 if (iforeq
->ifo_Flags
& FOF_DOSTYLE
)
800 STRPTR stylestrings
[3];
802 struct TagItem style_tags
[] =
804 {GA_Previous
, (IPTR
)gad
},
808 {GA_Height
, udata
->ButHeight
},
809 {GA_RelVerify
, TRUE
},
810 {GA_UserData
, (IPTR
)ld
},
812 {ASLFS_LabelArray
, (IPTR
)stylestrings
},
813 {ASLFS_Style
, iforeq
->ifo_TextAttr
.ta_Style
},
817 stylestrings
[0] = GetString(MSG_FONTREQ_STYLE_BOLD
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
818 stylestrings
[1] = GetString(MSG_FONTREQ_STYLE_ITALIC
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
819 stylestrings
[2] = GetString(MSG_FONTREQ_STYLE_UNDERLINED
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
821 w
= BiggestTextLength(stylestrings
, 3, &(ld
->ld_DummyRP
), AslBase
);
825 style_tags
[3].ti_Data
= w
;
827 if (w
> maxgadcolwidth
) maxgadcolwidth
= w
;
829 udata
->StyleGadget
= gad
= NewObjectA(AslBase
->aslfontstyleclass
, NULL
, style_tags
);
830 if (!gad
) goto failure
;
832 y
+= udata
->ButHeight
+ GADGETSPACINGY
;
836 w
= udata
->ButHeight
* 12 / 10 + 19; /* CYCLEIMAGEWIDTH = 19 */
838 /* Make FrontPen gadget */
840 if (iforeq
->ifo_Flags
& FOF_DOFRONTPEN
)
842 struct TagItem cp_tags
[] =
844 {GA_Previous
, (IPTR
)gad
},
848 {GA_Height
, udata
->ButHeight
},
849 {GA_RelVerify
, TRUE
},
850 {GA_UserData
, (IPTR
)ld
},
851 {GA_ID
, ID_FRONTPEN
},
852 {ASLCP_Color
, iforeq
->ifo_FrontPen
},
853 {ASLCP_ColorTable
, (IPTR
)iforeq
->ifo_FrontPens
},
854 {ASLCP_NumColors
, iforeq
->ifo_MaxFrontPen
},
859 udata
->FGColorGadget
= gad
= NewObjectA(AslBase
->aslcolorpickerclass
, NULL
, cp_tags
);
860 if (!gad
) goto failure
;
862 x
+= w
+ GADGETSPACINGX
;
865 /* Make BackPen gadget */
867 if (iforeq
->ifo_Flags
& FOF_DOBACKPEN
)
869 struct TagItem cp_tags
[] =
871 {GA_Previous
, (IPTR
)gad
},
875 {GA_Height
, udata
->ButHeight
},
876 {GA_RelVerify
, TRUE
},
877 {GA_UserData
, (IPTR
)ld
},
878 {GA_ID
, ID_BACKPEN
},
879 {ASLCP_Color
, iforeq
->ifo_BackPen
},
880 {ASLCP_ColorTable
, (IPTR
)iforeq
->ifo_BackPens
},
881 {ASLCP_NumColors
, iforeq
->ifo_MaxBackPen
},
886 udata
->BGColorGadget
= gad
= NewObjectA(AslBase
->aslcolorpickerclass
, NULL
, cp_tags
);
887 if (!gad
) goto failure
;
891 if (iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
893 if ((iforeq
->ifo_Flags
& (FOF_DOFRONTPEN
| FOF_DOBACKPEN
)) == (FOF_DOFRONTPEN
| FOF_DOBACKPEN
))
895 w
+= GADGETSPACINGX
+ w
;
898 if (w
> maxgadcolwidth
) maxgadcolwidth
= w
;
900 y
+= udata
->ButHeight
+ GADGETSPACINGY
;
904 /* Make DrawMode gadget */
906 x
= ld
->ld_WBorLeft
+ OUTERSPACINGX
+ labelwidth
+ LABELSPACINGX
;
908 w
= -ld
->ld_WBorLeft
- ld
->ld_WBorRight
- OUTERSPACINGX
* 2 -
909 labelwidth
- LABELSPACINGX
;
912 if (iforeq
->ifo_Flags
& FOF_DODRAWMODE
)
914 struct TagItem cycle_tags
[] =
916 {GA_Previous
, (IPTR
)gad
},
920 {GA_Height
, udata
->ButHeight
},
921 {GA_RelVerify
, TRUE
},
922 {GA_UserData
, (IPTR
)ld
},
923 {GA_ID
, ID_DRAWMODE
},
925 {ASLCY_Active
, iforeq
->ifo_DrawMode
},
926 {ASLCY_Font
, (IPTR
)ld
->ld_Font
},
930 static LONG labelids
[] =
932 MSG_FONTREQ_MODE_TEXT
,
933 MSG_FONTREQ_MODE_TEXTANDFIELD
,
934 MSG_FONTREQ_MODE_COMPLEMENT
,
939 if (iforeq
->ifo_ModeList
)
941 labels
= &iforeq
->ifo_ModeList
[1];
945 labels
= (STRPTR
*)&iforeq
->ifo_DrawModeJAM1Text
;
947 for(i
= 0; i
< 3; i
++)
949 labels
[i
] = GetString(labelids
[i
], GetIR(iforeq
)->ir_Catalog
, AslBase
);
953 cycle_tags
[8].ti_Data
= (IPTR
)labels
;
955 i
= CYCLEEXTRAWIDTH
+ BiggestTextLength(labels
,
959 if (i
> maxgadcolwidth
) maxgadcolwidth
= i
;
961 udata
->DrawModeGadget
= gad
= NewObjectA(AslBase
->aslcycleclass
, NULL
, cycle_tags
);
962 if (!gad
) goto failure
;
964 y
+= udata
->ButHeight
+ GADGETSPACINGY
;
966 } /* if (iforeq->ifo_Flags & FOF_DODRAWMODE) */
968 } /* if (iforeq->ifo_Flags & (FOF_DODRAWMODE | FOF_DOSTYLE | FOF_DOFRONTPEN | FOF_DOBACKPEN)) */
972 struct TagItem eraser_tags
[] =
974 {GA_Previous
, (IPTR
)gad
},
978 udata
->EraserGadget
= gad
= NewObjectA(AslBase
->asleraserclass
, NULL
, eraser_tags
);
979 /* Doesn't matter if this failed */
983 w
= OUTERSPACINGX
+ labelwidth
+ LABELSPACINGX
+ maxgadcolwidth
+ OUTERSPACINGX
;
984 if (w
> ld
->ld_MinWidth
) ld
->ld_MinWidth
= w
;
986 ld
->ld_GList
= (struct Gadget
*)udata
->NameListview
;
990 struct NewMenu nm
[] =
992 {NM_TITLE
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL
},
993 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_LASTFONT
, 0, 0, 0, (APTR
)FOMEN_LASTFONT
},
994 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_NEXTFONT
, 0, 0, 0, (APTR
)FOMEN_NEXTFONT
},
995 {NM_ITEM
, NM_BARLABEL
},
996 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_RESTORE
, 0, 0, 0, (APTR
)FOMEN_RESTORE
},
997 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_RESCAN
, 0, 0, 0, (APTR
)FOMEN_RESCAN
},
998 {NM_ITEM
, NM_BARLABEL
},
999 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_OK
, 0, 0, 0, (APTR
)FOMEN_OK
},
1000 {NM_ITEM
, (STRPTR
)MSG_FONTREQ_MEN_CONTROL_CANCEL
, 0, 0, 0, (APTR
)FOMEN_CANCEL
},
1004 struct TagItem menu_tags
[] =
1006 {GTMN_NewLookMenus
, TRUE
},
1007 {GTMN_TextAttr
, (IPTR
)GetIR(iforeq
)->ir_TextAttr
},
1011 if (menu_tags
[1].ti_Data
== 0) menu_tags
[1].ti_Tag
= TAG_IGNORE
;
1013 LocalizeMenus(nm
, GetIR(iforeq
)->ir_Catalog
, AslBase
);
1015 /* Don't fail, if menus cannot be created/layouted, because a requester
1016 without menus is still better than no requester at all */
1018 if ((ld
->ld_Menu
= CreateMenusA(nm
, NULL
)))
1020 if (!LayoutMenusA(ld
->ld_Menu
, ld
->ld_VisualInfo
, menu_tags
))
1022 FreeMenus(ld
->ld_Menu
);ld
->ld_Menu
= NULL
;
1027 FORestore(ld
, iforeq
->ifo_TextAttr
.ta_Name
, iforeq
->ifo_TextAttr
.ta_YSize
, AslBase
);
1030 ReturnBool ("FOGadInit", TRUE
);
1035 D(bug("failure\n"));
1037 FOGadCleanup(ld
, ASLB(AslBase
));
1039 ReturnBool ("FOGadInit", FALSE
);
1043 /*****************************************************************************************/
1045 STATIC VOID
FOWindowOpened(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1047 // struct IntFontReq *iforeq = (struct IntFontReq *)ld->ld_IntReq;
1050 /*****************************************************************************************/
1052 STATIC BOOL
FOGadLayout(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1054 ReturnBool ("FOGadLayout", TRUE
);
1057 /*****************************************************************************************/
1059 STATIC ULONG
FOHandleEvents(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1061 struct IntuiMessage
*imsg
= ld
->ld_Event
;
1062 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
1063 struct IntFontReq
*iforeq
= (struct IntFontReq
*)ld
->ld_IntReq
;
1065 ULONG retval
= GHRET_OK
;
1067 EnterFunc(bug("FOHandleEvents: Class: %d\n", imsg
->Class
));
1069 switch (imsg
->Class
)
1071 case IDCMP_CLOSEWINDOW
:
1079 FOChangeActiveFont(ld
, -1, imsg
->Qualifier
, FALSE
, AslBase
);
1083 FOChangeActiveFont(ld
, -1, IEQUALIFIER_LSHIFT
, FALSE
, AslBase
);
1087 FOChangeActiveFont(ld
, -1, IEQUALIFIER_LALT
, FALSE
, AslBase
);
1090 case RAWKEY_NM_WHEEL_UP
:
1091 FOChangeActiveFont(ld
, -3, imsg
->Qualifier
, FALSE
, AslBase
);
1095 FOChangeActiveFont(ld
, 1, imsg
->Qualifier
, FALSE
, AslBase
);
1098 case RAWKEY_PAGEDOWN
:
1099 FOChangeActiveFont(ld
, 1, IEQUALIFIER_LSHIFT
, FALSE
, AslBase
);
1103 FOChangeActiveFont(ld
, 1, IEQUALIFIER_LALT
, FALSE
, AslBase
);
1106 case RAWKEY_NM_WHEEL_DOWN
:
1107 FOChangeActiveFont(ld
, 3, imsg
->Qualifier
, FALSE
, AslBase
);
1112 case IDCMP_VANILLAKEY
:
1121 case IDCMP_GADGETUP
:
1122 gadid
= ((struct Gadget
*)imsg
->IAddress
)->GadgetID
;
1124 D(bug("GADGETUP! gadgetid=%d code=%d\n", gadid
, imsg
->Code
));
1133 retval
= FOGetSelectedFont(ld
, AslBase
);
1136 case ID_NAMELISTVIEW
:
1138 struct ASLLVFontReqNode
*fontnode
;
1142 GetAttr(ASLLV_Active
, udata
->NameListview
, &active
);
1143 GetAttr(STRINGA_LongVal
, udata
->SizeString
, &size
);
1145 if ((fontnode
= (struct ASLLVFontReqNode
*)FindListNode(&udata
->NameListviewList
, (WORD
)active
)))
1147 FOActivateFont(ld
, active
, (LONG
)size
, AslBase
);
1149 if (imsg
->Code
) /* TRUE if double clicked */
1151 retval
= FOGetSelectedFont(ld
, AslBase
);
1154 ActivateGadget((struct Gadget
*)udata
->NameString
, ld
->ld_Window
, NULL
);
1158 case ID_SIZELISTVIEW
:
1159 if (udata
->ActiveFont
)
1164 GetAttr(ASLLV_Active
, udata
->SizeListview
, &active
);
1166 if ((node
= FindListNode(&udata
->ActiveFont
->SizeList
, (WORD
)active
)))
1168 FOSetSizeString((LONG
)node
->ln_Name
, ld
, AslBase
);
1169 FOUpdatePreview(ld
, AslBase
);
1171 if (imsg
->Code
) /* TRUE if double clicked */
1173 retval
= FOGetSelectedFont(ld
, AslBase
);
1176 ActivateGadget((struct Gadget
*)udata
->SizeString
, ld
->ld_Window
, NULL
);
1181 if (imsg
->Code
== STRINGCODE_CURSORUP
)
1183 FOChangeActiveFont(ld
, -1, imsg
->Qualifier
, TRUE
, AslBase
);
1184 ActivateGadget((struct Gadget
*)udata
->NameString
, ld
->ld_Window
, NULL
);
1187 else if (imsg
->Code
== STRINGCODE_CURSORDOWN
)
1189 FOChangeActiveFont(ld
, 1, imsg
->Qualifier
, TRUE
, AslBase
);
1190 ActivateGadget((struct Gadget
*)udata
->NameString
, ld
->ld_Window
, NULL
);
1193 else if ((imsg
->Code
== 0) || (imsg
->Code
== 9))
1195 FOUpdatePreview(ld
, AslBase
);
1201 if (imsg
->Code
== STRINGCODE_CURSORUP
)
1203 FOChangeActiveSize(ld
, -1, imsg
->Qualifier
, AslBase
);
1204 ActivateGadget((struct Gadget
*)udata
->SizeString
, ld
->ld_Window
, NULL
);
1207 else if (imsg
->Code
== STRINGCODE_CURSORDOWN
)
1209 FOChangeActiveSize(ld
, 1, imsg
->Qualifier
, AslBase
);
1210 ActivateGadget((struct Gadget
*)udata
->SizeString
, ld
->ld_Window
, NULL
);
1213 else if ((imsg
->Code
== 0) || (imsg
->Code
== 9))
1218 GetAttr(STRINGA_LongVal
, udata
->SizeString
, (IPTR
*)&val
);
1221 if ((size
< iforeq
->ifo_MinHeight
) || (size
> iforeq
->ifo_MaxHeight
))
1223 if (size
< iforeq
->ifo_MinHeight
) size
= iforeq
->ifo_MinHeight
;
1224 if (size
> iforeq
->ifo_MaxHeight
) size
= iforeq
->ifo_MaxHeight
;
1225 FOSetSizeString(size
, ld
, AslBase
);
1228 FOActivateSize(ld
, -size
, AslBase
);
1237 FOUpdatePreview(ld
, AslBase
);
1240 } /* switch (gadget ID) */
1242 break; /* case IDCMP_GADGETUP: */
1244 case IDCMP_MENUPICK
:
1247 UWORD men
= imsg
->Code
;
1249 while(men
!= MENUNULL
)
1251 struct MenuItem
*item
;
1253 if ((item
= ItemAddress(ld
->ld_Menu
, men
)))
1255 switch((IPTR
)GTMENUITEM_USERDATA(item
))
1259 case FOMEN_LASTFONT
:
1260 FOChangeActiveFont(ld
, -1, 0, FALSE
, AslBase
);
1263 case FOMEN_NEXTFONT
:
1264 FOChangeActiveFont(ld
, 1, 0, FALSE
, AslBase
);
1268 FORestore(ld
, iforeq
->ifo_TextAttr
.ta_Name
, iforeq
->ifo_TextAttr
.ta_YSize
, AslBase
);
1272 FOGetFonts(ld
, AslBase
);
1276 retval
= FOGetSelectedFont(ld
, AslBase
);
1285 men
= item
->NextSelect
;
1286 } /* if ((item = ItemAddress(ld->ld_Menu, men))) */
1292 } /* while(men != MENUNULL) */
1294 } /* if (ld->ld_Menu) */
1296 break; /* case IDCMP_MENUPICK: */
1298 } /* switch (imsg->Class) */
1300 ReturnInt ("FOHandleEvents", ULONG
, retval
);
1303 /*****************************************************************************************/
1305 STATIC VOID
FOGadCleanup(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1307 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
1308 struct FontRequester
*req
= (struct FontRequester
*)ld
->ld_Req
;
1309 struct IntReq
*intreq
= ld
->ld_IntReq
;
1310 // struct IntFontReq *iforeq = (struct IntFontReq *)intreq;
1312 EnterFunc(bug("FOGadCleanup(ld=%p)\n", ld
));
1314 if (ld
->ld_Window
&& ld
->ld_GList
)
1316 RemoveGList(ld
->ld_Window
, ld
->ld_GList
, -1);
1319 killscrollergadget(&udata
->NameScrollGad
, AslBase
);
1320 killscrollergadget(&udata
->SizeScrollGad
, AslBase
);
1322 FreeObjects(&FOREQ_FIRST_OBJECT(udata
), &FOREQ_LAST_OBJECT(udata
), AslBase
);
1324 FOFreeFonts(ld
, AslBase
);
1326 if (udata
->PreviewFont
) CloseFont(udata
->PreviewFont
);
1330 req
->fo_LeftEdge
= intreq
->ir_LeftEdge
= ld
->ld_Window
->LeftEdge
;
1331 req
->fo_TopEdge
= intreq
->ir_TopEdge
= ld
->ld_Window
->TopEdge
;
1332 req
->fo_Width
= intreq
->ir_Width
= ld
->ld_Window
->Width
;
1333 req
->fo_Height
= intreq
->ir_Height
= ld
->ld_Window
->Height
;
1336 ReturnVoid("FOGadCleanup");
1339 /*****************************************************************************************/
1341 STATIC ULONG
FOGetSelectedFont(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
1343 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
1344 struct IntReq
*intreq
= ld
->ld_IntReq
;
1345 struct IntFontReq
*iforeq
= (struct IntFontReq
*)intreq
;
1346 struct FontRequester
*req
= (struct FontRequester
*)ld
->ld_Req
;
1349 ULONG retval
= GHRET_OK
;
1351 GetAttr(STRINGA_TextVal
, udata
->NameString
, (IPTR
*)&name
);
1352 if (!(req
->fo_TAttr
.tta_Name
= VecPooledCloneString(name
, ".font", intreq
->ir_MemPool
, AslBase
))) goto bye
;
1353 iforeq
->ifo_TextAttr
.ta_Name
= req
->fo_TAttr
.tta_Name
;
1355 GetAttr(STRINGA_LongVal
, udata
->SizeString
, &val
);
1356 req
->fo_TAttr
.tta_YSize
= iforeq
->ifo_TextAttr
.ta_YSize
= (UWORD
)val
;
1360 if (iforeq
->ifo_Flags
& FOF_DODRAWMODE
)
1362 iforeq
->ifo_DrawMode
= FOGetDrawMode(ld
, AslBase
);
1364 req
->fo_DrawMode
= iforeq
->ifo_DrawMode
;
1369 if (iforeq
->ifo_Flags
& FOF_DOSTYLE
)
1371 iforeq
->ifo_TextAttr
.ta_Style
= FOGetStyle(ld
, AslBase
);
1373 req
->fo_TAttr
.tta_Style
= iforeq
->ifo_TextAttr
.ta_Style
;
1375 if (iforeq
->ifo_Flags
& FOF_DOFRONTPEN
)
1377 iforeq
->ifo_FrontPen
= FOGetFGColor(ld
, AslBase
);
1379 req
->fo_FrontPen
= iforeq
->ifo_FrontPen
;
1381 if (iforeq
->ifo_Flags
& FOF_DOBACKPEN
)
1383 iforeq
->ifo_BackPen
= FOGetBGColor(ld
, AslBase
);
1385 req
->fo_BackPen
= iforeq
->ifo_BackPen
;
1387 /* Hmm ... there is also a struct TextAttr fo_Attr in
1388 FontRequester structure. Just put the same values in!? */
1390 req
->fo_Attr
.ta_Name
= req
->fo_TAttr
.tta_Name
;
1391 req
->fo_Attr
.ta_YSize
= req
->fo_TAttr
.tta_YSize
;
1392 req
->fo_Attr
.ta_Style
= req
->fo_TAttr
.tta_Style
;
1393 req
->fo_Attr
.ta_Flags
= req
->fo_TAttr
.tta_Flags
;
1395 retval
= GHRET_FINISHED_OK
;
1401 /*****************************************************************************************/