2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
9 /*****************************************************************************************/
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <proto/intuition.h>
14 #include <proto/graphics.h>
15 #include <proto/utility.h>
16 #include <proto/diskfont.h>
17 #include <exec/memory.h>
18 #include <exec/initializers.h>
19 #include <intuition/imageclass.h>
25 #include <clib/macros.h>
27 #include "asl_intern.h"
28 #include "fontreqsupport.h"
29 #include "fontreqhooks.h"
36 #include <aros/debug.h>
38 /*****************************************************************************************/
40 static WORD
FOCompareFontNodes(struct IntFontReq
*iforeq
, struct Node
*node1
,
41 struct Node
*node2
, struct AslBase_intern
*AslBase
)
43 return Stricmp(node1
->ln_Name
, node2
->ln_Name
);
46 /*****************************************************************************************/
48 static WORD
FOCompareSizeNodes(struct IntFontReq
*iforeq
, struct Node
*node1
,
49 struct Node
*node2
, struct AslBase_intern
*AslBase
)
51 return ((IPTR
)node1
->ln_Name
) - ((IPTR
)node2
->ln_Name
);
54 /*****************************************************************************************/
56 static int AVFCompare(struct AvailFonts
*one
, struct AvailFonts
*two
)
58 int retval
= strcmp(one
->af_Attr
.ta_Name
, two
->af_Attr
.ta_Name
);
60 if (!retval
) retval
= ((int)one
->af_Attr
.ta_YSize
) -
61 ((int)two
->af_Attr
.ta_YSize
);
66 /*****************************************************************************************/
68 static void SortAvailFonts(struct AvailFontsHeader
*afh
, struct AslBase_intern
*AslBase
)
70 struct AvailFonts
*avf
;
73 avf
= (struct AvailFonts
*)&afh
[1];
74 numentries
= afh
->afh_NumEntries
;
75 if (numentries
< 2) return;
80 (int (*)(const void *, const void *))AVFCompare
);
83 /*****************************************************************************************/
85 LONG
FOGetFonts(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
87 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
88 struct IntFontReq
*iforeq
= (struct IntFontReq
*)ld
->ld_IntReq
;
89 struct AvailFonts
*avf
;
90 ULONG afshortage
= 0, afsize
= 100;
93 FOFreeFonts(ld
, AslBase
);
97 udata
->AFH
= (struct AvailFontsHeader
*)AllocVec(afsize
, MEMF_ANY
);
100 afshortage
= AvailFonts((STRPTR
)udata
->AFH
, afsize
, AFF_MEMORY
| AFF_DISK
);
105 afsize
+= afshortage
;
109 } while (udata
->AFH
&& afshortage
);
111 if (!udata
->AFH
) return ERROR_NO_FREE_STORE
;
113 SortAvailFonts(udata
->AFH
, AslBase
);
115 avf
= (struct AvailFonts
*)&udata
->AFH
[1];
117 for(i
= 0; i
< udata
->AFH
->afh_NumEntries
;)
119 struct AvailFonts
*avf_start
= avf
;
120 struct ASLLVFontReqNode
*fontnode
;
124 while (i2
< udata
->AFH
->afh_NumEntries
- 1)
127 if (strcmp(avf_start
->af_Attr
.ta_Name
, avf
->af_Attr
.ta_Name
)) break;
131 i
+= num_sizes
; avf
= avf_start
+ num_sizes
;
133 if (iforeq
->ifo_Flags
& FOF_FIXEDWIDTHONLY
)
135 if (avf_start
->af_Attr
.ta_Flags
& FPF_PROPORTIONAL
) continue;
138 if (strlen(avf_start
->af_Attr
.ta_Name
) >= sizeof fontnode
->Name
)
140 D(bug("[ASL] Font %s ignored because name too long\n", avf_start
->af_Attr
.ta_Name
));
144 if (iforeq
->ifo_FilterFunc
)
150 REG_A4
= (ULONG
)iforeq
->ifo_IntReq
.ir_BasePtr
; /* Compatability */
151 REG_A0
= (ULONG
)iforeq
->ifo_FilterFunc
;
152 REG_A2
= (ULONG
)ld
->ld_Req
;
153 REG_A1
= (ULONG
)&avf_start
->af_Attr
;
154 ret
= (*MyEmulHandle
->EmulCallDirect68k
)(iforeq
->ifo_FilterFunc
->h_Entry
);
159 if (!(CallHookPkt(iforeq
->ifo_FilterFunc
, ld
->ld_Req
, &avf_start
->af_Attr
))) continue;
163 if (iforeq
->ifo_HookFunc
&& (iforeq
->ifo_Flags
& FOF_FILTERFUNC
))
168 UWORD
*funcptr
= iforeq
->ifo_HookFunc
;
169 ULONG
*p
= (ULONG
*)REG_A7
- 3;
171 p
[0] = (ULONG
)FOF_FILTERFUNC
;
172 p
[1] = (ULONG
)&avf_start
->af_Attr
;
173 p
[2] = (ULONG
)ld
->ld_Req
;
176 if (*funcptr
>= (UWORD
)0xFF00)
179 REG_A4
= (ULONG
)iforeq
->ifo_IntReq
.ir_BasePtr
; /* Compatability */
181 ret
= (ULONG
)(*MyEmulHandle
->EmulCallDirect68k
)(funcptr
);
183 if (*funcptr
>= (UWORD
)0xFF00)
191 if (!(iforeq
->ifo_HookFunc(FOF_FILTERFUNC
,
193 (struct FontRequester
*)ld
->ld_Req
))) continue;
197 fontnode
= MyAllocVecPooled(ld
->ld_IntReq
->ir_MemPool
,
198 sizeof(*fontnode
) + sizeof(struct Node
) * num_sizes
,
207 sp
= strchr(avf_start
->af_Attr
.ta_Name
, '.');
210 len
= (IPTR
)sp
- (IPTR
)avf_start
->af_Attr
.ta_Name
- 1;;
214 /* Paranoia: Should never happen */
215 len
= strlen(avf_start
->af_Attr
.ta_Name
);
218 strncpy(fontnode
->Name
, avf_start
->af_Attr
.ta_Name
, len
+ 1);
219 fontnode
->node
.ln_Name
= fontnode
->Name
;
220 fontnode
->TAttr
= avf_start
->af_Attr
;
221 fontnode
->TAttr
.ta_Name
= fontnode
->Name
;
223 fontnode
->NumSizes
= num_sizes
;
225 NEWLIST(&fontnode
->SizeList
);
227 for(i2
= 0; i2
< num_sizes
; i2
++, avf_start
++)
229 UWORD size
= avf_start
->af_Attr
.ta_YSize
;
231 if (size
== prevsize
) continue;
233 if ((size
< iforeq
->ifo_MinHeight
) ||
234 (size
> iforeq
->ifo_MaxHeight
)) continue;
236 fontnode
->SizeNode
[i2
].ln_Name
= (char *)(IPTR
)size
;
237 SortInNode(iforeq
, &fontnode
->SizeList
, &fontnode
->SizeNode
[i2
], (APTR
)FOCompareSizeNodes
, AslBase
);
242 SortInNode(iforeq
, &udata
->NameListviewList
, &fontnode
->node
, (APTR
)FOCompareFontNodes
, AslBase
);
246 } /* for(i = 0; i < udata->AFH->afh_NumEntries; ) */
248 if (udata
->NameListview
)
250 struct TagItem set_tags
[] =
252 {ASLLV_Labels
, (IPTR
)&udata
->NameListviewList
},
258 SetGadgetAttrsA((struct Gadget
*)udata
->NameListview
, ld
->ld_Window
, NULL
, set_tags
);
260 GetAttr(STRINGA_TextVal
, udata
->NameString
, (IPTR
*)&fontname
);
261 GetAttr(STRINGA_LongVal
, udata
->SizeString
, (IPTR
*)&fontsize
);
263 FORestore(ld
, fontname
, fontsize
, AslBase
);
267 return IsListEmpty(&udata
->NameListviewList
) ? ERROR_NO_MORE_ENTRIES
: 0;
271 /*****************************************************************************************/
273 void FOFreeFonts(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
275 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
276 struct ASLVFontReqNode
*node
, *succ
;
277 struct TagItem set_tags
[] =
283 udata
->ActiveFont
= NULL
;
285 if (udata
->NameListview
) SetGadgetAttrsA((struct Gadget
*)udata
->NameListview
, ld
->ld_Window
, NULL
, set_tags
);
286 if (udata
->SizeListview
) SetGadgetAttrsA((struct Gadget
*)udata
->SizeListview
, ld
->ld_Window
, NULL
, set_tags
);
288 ForeachNodeSafe(&udata
->NameListviewList
, node
, succ
)
290 MyFreeVecPooled(node
, AslBase
);
293 NEWLIST(&udata
->NameListviewList
);
302 /*****************************************************************************************/
304 VOID
FOUpdatePreview(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
306 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
307 struct IntReq
*intreq
= ld
->ld_IntReq
;
308 struct IntFontReq
*iforeq
= (struct IntFontReq
*)ld
->ld_IntReq
;
310 struct TextFont
*font
;
314 GetAttr(STRINGA_LongVal
, udata
->SizeString
, &val
);
315 ta
.ta_YSize
= (WORD
)val
;
319 GetAttr(STRINGA_TextVal
, udata
->NameString
, (IPTR
*)&name
);
320 if ((name
= VecPooledCloneString(name
, ".font", intreq
->ir_MemPool
, AslBase
)))
322 UBYTE style
= FS_NORMAL
;
323 UBYTE apen
= iforeq
->ifo_FrontPen
;
324 UBYTE bpen
= iforeq
->ifo_BackPen
;
328 if (iforeq
->ifo_Flags
& FOF_DOSTYLE
)
330 style
= FOGetStyle(ld
, AslBase
);
333 if (iforeq
->ifo_Flags
& FOF_DOFRONTPEN
)
335 apen
= FOGetFGColor(ld
, AslBase
);
338 if (iforeq
->ifo_Flags
& FOF_DOBACKPEN
)
340 bpen
= FOGetBGColor(ld
, AslBase
);
343 font
= OpenDiskFont(&ta
);
345 struct TagItem settags
[] =
347 {ASLFP_Font
, (IPTR
)font
},
348 {ASLFP_Style
, style
},
349 {ASLFP_APen
, apen
},
350 {ASLFP_BPen
, bpen
},
354 SetGadgetAttrsA((struct Gadget
*)udata
->Preview
, ld
->ld_Window
, NULL
, settags
);
357 if (udata
->PreviewFont
) CloseFont(udata
->PreviewFont
);
358 udata
->PreviewFont
= font
;
360 MyFreeVecPooled(name
, AslBase
);
364 /*****************************************************************************************/
366 struct ASLLVFontReqNode
*FOGetActiveFont(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
368 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
371 GetAttr(ASLLV_Active
, udata
->NameListview
, &active
);
373 return (struct ASLLVFontReqNode
*)FindListNode(&udata
->NameListviewList
, active
);
376 /*****************************************************************************************/
378 void FOChangeActiveFont(struct LayoutData
*ld
, WORD delta
, UWORD quali
, BOOL jump
, struct AslBase_intern
*AslBase
)
380 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
381 IPTR active
, total
, visible
, size
;
383 GetAttr(ASLLV_Active
, udata
->NameListview
, &active
);
384 GetAttr(ASLLV_Total
, udata
->NameListview
, &total
);
385 GetAttr(ASLLV_Visible
, udata
->NameListview
, &visible
);
386 GetAttr(STRINGA_LongVal
, udata
->SizeString
, &size
);
390 if (quali
& (IEQUALIFIER_LSHIFT
| IEQUALIFIER_RSHIFT
))
392 delta
*= (visible
- 1);
394 else if (quali
& (IEQUALIFIER_LALT
| IEQUALIFIER_RALT
| IEQUALIFIER_CONTROL
))
400 /* try to jump to first item which matches text in name string gadget,
401 but only if text in string gadget mismatches actual active
402 item's text (in this case move normally = one step)) */
404 struct ASLLVFontReqNode
*node
;
405 UBYTE buffer
[MAXASLFONTNAME
+ 6];
410 GetAttr(STRINGA_TextVal
, udata
->NameString
, (IPTR
*)&val
);
411 strlcpy(buffer
, val
, sizeof buffer
);
413 len
= strlen(buffer
);
417 if (((LONG
)active
) >= 0)
419 if ((node
= (struct ASLLVFontReqNode
*)FindListNode(&udata
->NameListviewList
, (WORD
)active
)))
421 if (stricmp(node
->node
.ln_Name
, buffer
) == 0) dojump
= FALSE
;
428 ForeachNode(&udata
->NameListviewList
, node
)
430 if (Strnicmp((CONST_STRPTR
)node
->node
.ln_Name
, (CONST_STRPTR
)buffer
, len
) == 0)
446 if (((LONG
)active
) < 0) active
= 0;
447 if (active
>= total
) active
= total
- 1;
449 FOActivateFont(ld
, active
, (LONG
)size
, AslBase
);
453 /*****************************************************************************************/
455 void FOChangeActiveSize(struct LayoutData
*ld
, WORD delta
, UWORD quali
, struct AslBase_intern
*AslBase
)
457 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
458 IPTR active
, total
, visible
;
460 GetAttr(ASLLV_Active
, udata
->SizeListview
, &active
);
461 GetAttr(ASLLV_Total
, udata
->SizeListview
, &total
);
462 GetAttr(ASLLV_Visible
, udata
->SizeListview
, &visible
);
466 if (quali
& (IEQUALIFIER_LSHIFT
| IEQUALIFIER_RSHIFT
))
468 delta
*= (visible
- 1);
470 else if (quali
& (IEQUALIFIER_LALT
| IEQUALIFIER_RALT
| IEQUALIFIER_CONTROL
))
477 if (((LONG
)active
) < 0) active
= 0;
478 if (active
>= total
) active
= total
- 1;
480 FOActivateSize(ld
, active
, AslBase
);
484 /*****************************************************************************************/
486 void FOActivateFont(struct LayoutData
*ld
, WORD which
, LONG size
, struct AslBase_intern
*AslBase
)
488 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
489 // struct IntFontReq *iforeq = (struct IntFontReq *)ld->ld_IntReq;
490 struct ASLLVFontReqNode
*fontnode
;
492 struct TagItem name_tags
[] =
495 {ASLLV_MakeVisible
, 0 },
498 struct TagItem size_tags
[] =
501 {ASLLV_Active
, (IPTR
)-1 },
502 {ASLLV_MakeVisible
, 0 },
505 WORD sizelvindex
= 0;
507 fontnode
= (struct ASLLVFontReqNode
*)FindListNode(&udata
->NameListviewList
, which
);
508 udata
->ActiveFont
= fontnode
;
512 SetGadgetAttrsA((struct Gadget
*)udata
->SizeListview
, ld
->ld_Window
, NULL
, size_tags
);
514 name_tags
[0].ti_Data
= (IPTR
)-1;
515 name_tags
[1].ti_Tag
= TAG_IGNORE
;
516 SetGadgetAttrsA((struct Gadget
*)udata
->NameListview
, ld
->ld_Window
, NULL
, name_tags
);
520 name_tags
[0].ti_Data
= name_tags
[1].ti_Data
= which
;
521 SetGadgetAttrsA((struct Gadget
*)udata
->NameListview
, ld
->ld_Window
, NULL
, name_tags
);
523 size_tags
[0].ti_Data
= (IPTR
)&fontnode
->SizeList
;
524 ForeachNode(&fontnode
->SizeList
, node
)
526 MARK_UNSELECTED(node
);
527 if ((IPTR
)node
->ln_Name
== size
)
529 size_tags
[1].ti_Data
= size_tags
[2].ti_Data
= sizelvindex
;
533 SetGadgetAttrsA((struct Gadget
*)udata
->SizeListview
, ld
->ld_Window
, NULL
, size_tags
);
535 FOSetFontString(fontnode
->node
.ln_Name
, ld
, AslBase
);
538 FOUpdatePreview(ld
, AslBase
);
541 /*****************************************************************************************/
543 void FOActivateSize(struct LayoutData
*ld
, WORD which
, struct AslBase_intern
*AslBase
)
545 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
546 // struct IntFontReq *iforeq = (struct IntFontReq *)ld->ld_IntReq;
548 struct TagItem size_tags
[] =
551 {ASLLV_MakeVisible
, 0 },
555 if (!udata
->ActiveFont
) return;
559 node
= FindListNode(&udata
->ActiveFont
->SizeList
, which
);
567 ForeachNode(&udata
->ActiveFont
->SizeList
, node
)
569 if ((IPTR
)node
->ln_Name
== size
)
577 if (!found
) node
= NULL
;
580 size_tags
[0].ti_Data
= node
? which
: -1;
581 size_tags
[1].ti_Data
= node
? which
: 0;
583 SetGadgetAttrsA((struct Gadget
*)udata
->SizeListview
, ld
->ld_Window
, NULL
, size_tags
);
585 if (node
) FOSetSizeString((IPTR
)node
->ln_Name
, ld
, AslBase
);
587 FOUpdatePreview(ld
, AslBase
);
590 /*****************************************************************************************/
592 void FORestore(struct LayoutData
*ld
, STRPTR fontname
, LONG fontsize
, struct AslBase_intern
*AslBase
)
594 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
595 struct IntFontReq
*iforeq
= (struct IntFontReq
*)ld
->ld_IntReq
;
596 struct ASLLVFontReqNode
*fontnode
;
597 struct TagItem set_tags
[] =
602 UBYTE initialfontname
[MAXASLFONTNAME
+ 6];
606 strlcpy(initialfontname
, fontname
, sizeof initialfontname
);
607 if ((sp
= strchr(initialfontname
, '.'))) *sp
= '\0';
609 FOSetSizeString(fontsize
, ld
, AslBase
);
611 SetGadgetAttrsA((struct Gadget
*)udata
->SizeListview
, ld
->ld_Window
, NULL
, set_tags
);
613 ForeachNode(&udata
->NameListviewList
, fontnode
)
615 if (stricmp(fontnode
->node
.ln_Name
, initialfontname
) == 0) break;
619 if (iforeq
->ifo_Flags
& FOF_DODRAWMODE
)
621 FOSetDrawMode(ld
, iforeq
->ifo_DrawMode
, AslBase
);
624 if (iforeq
->ifo_Flags
& FOF_DOSTYLE
)
626 FOSetStyle(ld
, iforeq
->ifo_TextAttr
.ta_Style
, AslBase
);
629 if (iforeq
->ifo_Flags
& FOF_DOFRONTPEN
)
631 FOSetFGColor(ld
, iforeq
->ifo_FrontPen
, AslBase
);
634 if (iforeq
->ifo_Flags
& FOF_DOBACKPEN
)
636 FOSetBGColor(ld
, iforeq
->ifo_BackPen
, AslBase
);
639 FOActivateFont(ld
, i
, fontsize
, AslBase
);
642 /*****************************************************************************************/
644 void FOSetFontString(STRPTR name
, struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
646 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
647 struct TagItem set_tags
[] =
649 {STRINGA_TextVal
, (IPTR
)name
},
653 SetGadgetAttrsA((struct Gadget
*)udata
->NameString
, ld
->ld_Window
, NULL
, set_tags
);
656 /*****************************************************************************************/
658 void FOSetSizeString(LONG size
, struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
660 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
661 struct TagItem set_tags
[] =
663 {STRINGA_LongVal
, (IPTR
)size
},
667 SetGadgetAttrsA((struct Gadget
*)udata
->SizeString
, ld
->ld_Window
, NULL
, set_tags
);
670 /*****************************************************************************************/
672 LONG
FOGetDrawMode(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
674 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
677 ASSERT(udata
->DrawModeGadget
);
679 GetAttr(ASLCY_Active
, udata
->DrawModeGadget
, &active
);
684 /*****************************************************************************************/
686 void FOSetDrawMode(struct LayoutData
*ld
, UWORD id
, struct AslBase_intern
*AslBase
)
688 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
689 struct TagItem set_tags
[] =
691 {ASLCY_Active
, id
},
695 ASSERT(udata
->DrawModeGadget
);
697 SetGadgetAttrsA((struct Gadget
*)udata
->DrawModeGadget
, ld
->ld_Window
, NULL
, set_tags
);
701 /*****************************************************************************************/
703 UBYTE
FOGetStyle(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
705 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
708 ASSERT(udata
->StyleGadget
);
710 GetAttr(ASLFS_Style
, udata
->StyleGadget
, &style
);
715 /*****************************************************************************************/
717 void FOSetStyle(struct LayoutData
*ld
, UBYTE style
, struct AslBase_intern
*AslBase
)
719 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
720 struct TagItem set_tags
[] =
722 {ASLFS_Style
, style
},
726 ASSERT(udata
->StyleGadget
);
728 SetGadgetAttrsA((struct Gadget
*)udata
->StyleGadget
, ld
->ld_Window
, NULL
, set_tags
);
732 /*****************************************************************************************/
734 UBYTE
FOGetFGColor(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
736 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
739 ASSERT(udata
->FGColorGadget
);
741 GetAttr(ASLCP_Color
, udata
->FGColorGadget
, &color
);
746 /*****************************************************************************************/
748 void FOSetFGColor(struct LayoutData
*ld
, UBYTE color
, struct AslBase_intern
*AslBase
)
750 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
751 struct TagItem set_tags
[] =
753 {ASLCP_Color
, color
},
757 ASSERT(udata
->FGColorGadget
);
759 SetGadgetAttrsA((struct Gadget
*)udata
->FGColorGadget
, ld
->ld_Window
, NULL
, set_tags
);
763 /*****************************************************************************************/
765 UBYTE
FOGetBGColor(struct LayoutData
*ld
, struct AslBase_intern
*AslBase
)
767 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
770 ASSERT(udata
->BGColorGadget
);
772 GetAttr(ASLCP_Color
, udata
->BGColorGadget
, &color
);
777 /*****************************************************************************************/
779 void FOSetBGColor(struct LayoutData
*ld
, UBYTE color
, struct AslBase_intern
*AslBase
)
781 struct FOUserData
*udata
= (struct FOUserData
*)ld
->ld_UserData
;
782 struct TagItem set_tags
[] =
784 {ASLCP_Color
, color
},
788 ASSERT(udata
->BGColorGadget
);
790 SetGadgetAttrsA((struct Gadget
*)udata
->BGColorGadget
, ld
->ld_Window
, NULL
, set_tags
);
794 /*****************************************************************************************/