1 /***************************************************************************
3 TextEditor.mcc - Textediting MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005-2009 by TextEditor.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 TextEditor class Support Site: http://www.sf.net/projects/texteditor-mcc
21 ***************************************************************************/
23 #include <proto/intuition.h>
27 void UpdateStyles (struct InstData
*data
)
35 struct marking newblock
;
37 NiceBlock(&data
->blockinfo
, &newblock
);
38 style
= GetStyle(data
->blockinfo
.stopx
- ((newblock
.startx
== data
->blockinfo
.startx
&& newblock
.startline
== data
->blockinfo
.startline
) ? 1 : 0), data
->blockinfo
.stopline
);
42 style
= GetStyle(data
->CPos_X
, data
->actualline
);
45 if(style
!= data
->style
)
47 UWORD oldstyle
= data
->style
;
53 if(!(oldstyle
& BOLD
))
54 set(data
->object
, MUIA_TextEditor_StyleBold
, TRUE
);
59 set(data
->object
, MUIA_TextEditor_StyleBold
, FALSE
);
63 if(!(oldstyle
& ITALIC
))
64 set(data
->object
, MUIA_TextEditor_StyleItalic
, TRUE
);
69 set(data
->object
, MUIA_TextEditor_StyleItalic
, FALSE
);
73 if(!(oldstyle
& UNDERLINE
))
74 set(data
->object
, MUIA_TextEditor_StyleUnderline
, TRUE
);
78 if(oldstyle
& UNDERLINE
)
79 set(data
->object
, MUIA_TextEditor_StyleUnderline
, FALSE
);
86 LONG
GetStyle (LONG x
, struct line_node
*line
)
94 unsigned short *styles
= line
->line
.Styles
;
100 else style
|= *styles
++;
108 void AddStyleToLine (LONG x
, struct line_node
*line
, LONG length
, unsigned short style
, struct InstData
*data
)
110 unsigned short *styles
= line
->line
.Styles
;
111 unsigned short *oldstyles
= styles
;
112 unsigned short *newstyles
;
113 unsigned short cur_style
= 0;
114 unsigned short end_style
= GetStyle(x
+length
, line
);
121 newstyles
= MyAllocPooled(data
->mypool
, (*((long *)styles
-1))+8);
122 else newstyles
= MyAllocPooled(data
->mypool
, 32);
126 line
->line
.Styles
= newstyles
;
129 while(*styles
!= EOS
&& *styles
< x
)
131 *newstyles
++ = *styles
++;
133 cur_style
&= *styles
;
134 else cur_style
|= *styles
;
135 *newstyles
++ = *styles
++;
140 if(cur_style
& ~style
)
143 *newstyles
++ = style
;
148 if(!(cur_style
& style
))
151 *newstyles
++ = style
;
156 while(*styles
!= EOS
&& *styles
<= x
+length
)
158 if((*(styles
+1) != style
) && (*(styles
+1) != (unsigned short)~style
))
160 *newstyles
++ = *styles
++;
161 *newstyles
++ = *styles
++;
166 if(!(((style
> 0xff) && (!(end_style
& ~style
))) ||
167 ((style
< 0xff) && ((end_style
& style
)))))
169 *newstyles
++ = x
+length
;
170 *newstyles
++ = ~style
;
175 while(*styles
!= EOS
)
177 *newstyles
++ = *styles
++;
178 *newstyles
++ = *styles
++;
184 MyFreePooled(data
->mypool
, oldstyles
);
191 void AddStyle (struct marking
*realblock
, unsigned short style
, long Set
, struct InstData
*data
)
193 struct marking newblock
;
195 struct line_node
*startline
, *stopline
;
201 if(!(data
->style
& style
))
211 if(data
->style
& style
)
217 data
->HasChanged
= TRUE
;
219 if(realblock
->enabled
&& (realblock
->startx
!= realblock
->stopx
|| realblock
->startline
!= realblock
->stopline
))
221 NiceBlock(realblock
, &newblock
);
222 startx
= newblock
.startx
;
223 stopx
= newblock
.stopx
;
224 startline
= newblock
.startline
;
225 stopline
= newblock
.stopline
;
229 startx
= data
->CPos_X
;
231 startline
= data
->actualline
;
232 stopline
= startline
;
235 if(startline
== stopline
)
237 AddStyleToLine(startx
, startline
, stopx
-startx
, style
, data
);
241 struct line_node
*line
= startline
->next
;
243 AddStyleToLine(startx
, startline
, startline
->line
.Length
-startx
-1, style
, data
);
244 while(line
!= stopline
)
246 AddStyleToLine(0, line
, line
->line
.Length
-1, style
, data
);
249 AddStyleToLine(0, line
, stopx
, style
, data
);
251 RedrawArea(startx
, startline
, stopx
, stopline
, data
);
254 data
->style
&= style
;
255 else data
->style
|= style
;