1 /***************************************************************************
3 BetterString.mcc - A better String gadget MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005 by BetterString.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 BetterString class Support Site: http://www.sf.net/projects/bstring-mcc/
21 ***************************************************************************/
26 #include <clib/alib_protos.h>
27 #include <graphics/gfxmacros.h>
28 #include <libraries/mui.h>
29 #include <proto/graphics.h>
30 #include <proto/intuition.h>
31 #include <proto/muimaster.h>
35 VOID
PrintString (struct IClass
*cl
, Object
*obj
)
37 struct InstData
*data
= (struct InstData
*)INST_DATA(cl
, obj
);
38 struct RastPort
*oldrport
= muiRenderInfo(obj
)->mri_RastPort
;
39 struct RastPort
*rport
= &data
->rport
;
40 struct MUI_AreaData
*ad
= muiAreaData(obj
);
41 struct TextFont
*font
= data
->Font
? data
->Font
: ad
->mad_Font
;
42 STRPTR contents
= data
->Contents
;
43 WORD x
=10, y
=0, width
, height
,
44 crsr_x
, crsr_width
=0, crsr_color
,
45 dst_x
, dst_y
, length
, offset
= 0, StrLength
;
47 BOOL BlockEnabled
= (data
->Flags
& FLG_BlockEnabled
&& data
->BlockStart
!= data
->BlockStop
);
48 UWORD Blk_Start
, Blk_Width
;
50 dst_x
= ad
->mad_Box
.Left
+ ad
->mad_addleft
;
51 dst_y
= ad
->mad_Box
.Top
+ ad
->mad_addtop
;
52 width
= ad
->mad_Box
.Width
- ad
->mad_subwidth
;
53 height
= font
->tf_YSize
;
55 StrLength
= strlen(contents
);
57 STRPTR fake_contents
= NULL
;
58 if(data
->Flags
& FLG_Secret
&& (fake_contents
= (STRPTR
)MyAllocPooled(data
->Pool
, StrLength
+1)))
60 contents
= fake_contents
;
61 WORD strlength
= StrLength
;
62 contents
[strlength
] = '\0';
64 contents
[strlength
] = '*';
67 crsr_width
= (data
->Flags
& FLG_Active
) && !BlockEnabled
? TextLength(rport
, (*(contents
+data
->BufferPos
) == '\0') ? "n" : contents
+data
->BufferPos
, 1) : 0;
69 if(data
->DisplayPos
> data
->BufferPos
)
70 data
->DisplayPos
= data
->BufferPos
;
74 UWORD backdistance
= MyTextFit(font
, contents
+StrLength
-1, StrLength
, width
/*-crsr_width*/, -1);
76 if(backdistance
> StrLength
-data
->DisplayPos
)
77 data
->DisplayPos
= StrLength
-backdistance
;
82 UWORD distance
= MyTextFit(font
, contents
+data
->BufferPos
-1, data
->BufferPos
, width
-crsr_width
, -1);
84 if(distance
< data
->BufferPos
-data
->DisplayPos
)
85 data
->DisplayPos
= data
->BufferPos
- distance
;
88 text
= contents
+data
->DisplayPos
;
89 StrLength
-= data
->DisplayPos
;
93 Blk_Start
= (data
->BlockStart
< data
->BlockStop
) ? data
->BlockStart
: data
->BlockStop
;
94 Blk_Width
= abs(data
->BlockStop
-data
->BlockStart
);
96 if(Blk_Start
< data
->DisplayPos
)
98 Blk_Width
-= data
->DisplayPos
-Blk_Start
;
99 Blk_Start
= data
->DisplayPos
;
101 crsr_x
= TextLength(rport
, text
, Blk_Start
-data
->DisplayPos
);
102 crsr_width
= TextLength(rport
, contents
+Blk_Start
, Blk_Width
);
103 crsr_color
= data
->MarkedColor
;
107 if(data
->Flags
& FLG_Active
)
109 crsr_x
= TextLength(rport
, text
, data
->BufferPos
-data
->DisplayPos
);
110 crsr_color
= data
->CursorColor
;
114 muiRenderInfo(obj
)->mri_RastPort
= rport
;
115 DoMethod(obj
, MUIM_DrawBackground
, x
, y
, width
, height
, dst_x
, dst_y
, 0L);
116 muiRenderInfo(obj
)->mri_RastPort
= oldrport
;
118 length
= MyTextFit(font
, text
, StrLength
, width
, 1);
119 if(data
->Alignment
!= MUIV_String_Format_Left
)
121 UWORD textlength
= MyTextLength(font
, text
, length
);
123 if(crsr_width
&& !BlockEnabled
&& data
->BufferPos
== data
->DisplayPos
+StrLength
)
125 length
= MyTextFit(font
, text
, StrLength
, width
-crsr_width
, 1);
126 textlength
+= crsr_width
;
129 switch(data
->Alignment
)
131 case MUIV_String_Format_Center
:
132 offset
= (width
- textlength
)/2;
134 case MUIV_String_Format_Right
:
135 offset
= (width
- textlength
);
140 if(crsr_width
&& crsr_x
< width
)
142 SetAPen(rport
, crsr_color
);
143 if(crsr_x
+crsr_width
> width
)
145 crsr_width
= width
-crsr_x
;
147 RectFill(rport
, x
+offset
+crsr_x
, y
, x
+offset
+crsr_x
+crsr_width
-1, y
+font
->tf_YSize
-1);
153 LONG textcolor
= (data
->Flags
& FLG_Active
) ? data
->ActiveText
: data
->InactiveText
;
155 Move(rport
, x
+offset
, y
+font
->tf_Baseline
);
157 if(BlockEnabled
&& textcolor
!= data
->MarkedTextColor
)
159 newlength
= Blk_Start
-data
->DisplayPos
;
160 SetAPen(rport
, textcolor
);
161 Text(rport
, text
, newlength
);
164 newlength
= (((Blk_Start
-data
->DisplayPos
) + Blk_Width
) > length
) ? length
- (Blk_Start
-data
->DisplayPos
) : Blk_Width
;
165 SetAPen(rport
, data
->MarkedTextColor
);
166 Text(rport
, text
, newlength
);
169 length
-= newlength
+ (Blk_Start
-data
->DisplayPos
);
172 SetAPen(rport
, textcolor
);
173 Text(rport
, text
, length
);
177 MyFreePooled(data
->Pool
, fake_contents
);
179 BltBitMapRastPort(data
->rport
.BitMap
, x
, y
, muiRenderInfo(obj
)->mri_RastPort
, dst_x
, dst_y
, width
, height
, 0xc0);
181 if(data
->Flags
& FLG_Ghosted
)
183 UWORD GhostPattern
[] = {0x4444, 0x1111};
184 struct RastPort
*rport
= muiRenderInfo(obj
)->mri_RastPort
;
186 SetAfPt(rport
, GhostPattern
, 1);
187 SetAPen(rport
, _pens(obj
)[MPEN_SHADOW
]);
188 RectFill(rport
, ad
->mad_Box
.Left
, ad
->mad_Box
.Top
, ad
->mad_Box
.Left
+ad
->mad_Box
.Width
-1, ad
->mad_Box
.Top
+ad
->mad_Box
.Height
-1);
189 SetAfPt(rport
, 0, 0);