grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / classes / zune / texteditor / mcc / StyleOperators.c
blob3731be0f94c311bafbe71e849a884d4a3fdacc67
1 /***************************************************************************
3 TextEditor.mcc - Textediting MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005-2014 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
19 $Id$
21 ***************************************************************************/
23 #include <proto/exec.h>
24 #include <proto/intuition.h>
26 #include "private.h"
27 #include "Debug.h"
29 /// UpdateStyles()
30 void UpdateStyles(struct InstData *data)
32 UWORD newStyle;
34 ENTER();
36 if(Enabled(data))
38 struct marking newblock;
40 NiceBlock(&data->blockinfo, &newblock);
41 if(newblock.startx == data->blockinfo.startx && newblock.startline == data->blockinfo.startline)
42 newStyle = GetStyle(data->blockinfo.stopx-1, data->blockinfo.stopline);
43 else
44 newStyle = GetStyle(data->blockinfo.stopx, data->blockinfo.stopline);
46 else
48 newStyle = GetStyle(data->CPos_X, data->actualline);
51 if(newStyle != data->style)
53 UWORD oldStyle = data->style;
55 data->style = newStyle;
57 if(isFlagSet(newStyle, BOLD) && isFlagClear(oldStyle, BOLD))
58 set(data->object, MUIA_TextEditor_StyleBold, TRUE);
59 else if(isFlagClear(newStyle, BOLD) && isFlagSet(oldStyle, BOLD))
60 set(data->object, MUIA_TextEditor_StyleBold, FALSE);
62 if(isFlagSet(newStyle, ITALIC) && isFlagClear(oldStyle, ITALIC))
63 set(data->object, MUIA_TextEditor_StyleItalic, TRUE);
64 else if(isFlagClear(newStyle, ITALIC) && isFlagSet(oldStyle, ITALIC))
65 set(data->object, MUIA_TextEditor_StyleItalic, FALSE);
67 if(isFlagSet(newStyle, UNDERLINE) && isFlagClear(oldStyle, UNDERLINE))
68 set(data->object, MUIA_TextEditor_StyleUnderline, TRUE);
69 else if(isFlagClear(newStyle, UNDERLINE) && isFlagSet(oldStyle, UNDERLINE))
70 set(data->object, MUIA_TextEditor_StyleUnderline, FALSE);
73 LEAVE();
76 ///
77 /// GetStyle()
78 UWORD GetStyle(LONG x, struct line_node *line)
80 UWORD style = 0;
82 ENTER();
84 if(line->line.Styles != NULL && x >= 0)
86 struct LineStyle *styles = line->line.Styles;
88 while(styles->column != EOS && styles->column <= x+1)
90 if(styles->style > 0xff)
91 style &= styles->style;
92 else
93 style |= styles->style;
95 styles++;
99 RETURN(style);
100 return(style);
104 /// AddStyleToLine()
105 void AddStyleToLine(struct InstData *data, LONG x, struct line_node *line, LONG length, UWORD style)
107 struct Grow styleGrow;
108 struct LineStyle *styles;
109 UWORD cur_style = 0;
110 UWORD end_style = GetStyle(x+length, line);
112 ENTER();
114 x++;
116 InitGrow(&styleGrow, data->mypool, sizeof(struct LineStyle));
118 if((styles = line->line.Styles) != NULL)
120 while(styles->column != EOS && styles->column < x)
122 AddToGrow(&styleGrow, styles);
124 if(styles->style > 0xff)
125 cur_style &= styles->style;
126 else
127 cur_style |= styles->style;
129 styles++;
132 if(style > 0xff)
134 if(cur_style & ~style)
136 struct LineStyle newStyle;
138 newStyle.column = x;
139 newStyle.style = style;
140 AddToGrow(&styleGrow, &newStyle);
143 else
145 if(!(cur_style & style))
147 struct LineStyle newStyle;
149 newStyle.column = x;
150 newStyle.style = style;
151 AddToGrow(&styleGrow, &newStyle);
155 if(styles != NULL)
157 while(styles->column != EOS && styles->column <= x+length)
159 UWORD invstyle = ~style;
161 if(styles->style != style && styles->style != invstyle)
163 AddToGrow(&styleGrow, styles);
166 styles++;
169 if(!(((style > 0xff) && (!(end_style & ~style))) ||
170 ((style < 0xff) && ((end_style & style)))))
172 struct LineStyle newStyle;
174 newStyle.column = x+length;
175 newStyle.style = ~style;
176 AddToGrow(&styleGrow, &newStyle);
179 if(styles != NULL)
181 while(styles->column != EOS)
183 AddToGrow(&styleGrow, styles);
185 styles++;
189 // the old styles are not needed anymore
190 if(line->line.Styles != NULL)
191 FreeVecPooled(data->mypool, line->line.Styles);
193 if(styleGrow.itemCount > 0)
195 struct LineStyle newStyle;
197 newStyle.column = EOS;
198 newStyle.style = 0;
199 AddToGrow(&styleGrow, &newStyle);
202 line->line.Styles = (struct LineStyle *)styleGrow.array;
204 LEAVE();
208 /// AddStyle()
209 void AddStyle(struct InstData *data, struct marking *realblock, UWORD style, BOOL set)
211 struct marking newblock;
212 LONG startx;
213 LONG stopx;
214 struct line_node *startline;
215 struct line_node *stopline;
217 ENTER();
219 if(set == FALSE)
221 if((data->style & style) == 0)
223 LEAVE();
224 return;
227 style = ~style;
229 else
231 if((data->style & style) != 0)
233 LEAVE();
234 return;
237 data->HasChanged = TRUE;
239 if(realblock->enabled == TRUE && (realblock->startx != realblock->stopx || realblock->startline != realblock->stopline))
241 NiceBlock(realblock, &newblock);
242 startx = newblock.startx;
243 stopx = newblock.stopx;
244 startline = newblock.startline;
245 stopline = newblock.stopline;
247 else
249 startx = data->CPos_X;
250 stopx = startx+1;
251 startline = data->actualline;
252 stopline = startline;
255 if(startline == stopline)
257 AddStyleToLine(data, startx, startline, stopx-startx, style);
259 else
261 struct line_node *line = GetNextLine(startline);
263 AddStyleToLine(data, startx, startline, startline->line.Length-startx-1, style);
264 while(line != stopline)
266 AddStyleToLine(data, 0, line, line->line.Length-1, style);
267 line = GetNextLine(line);
269 AddStyleToLine(data, 0, line, stopx, style);
271 RedrawArea(data, startx, startline, stopx, stopline);
273 if(style > 0xff)
274 data->style &= style;
275 else
276 data->style |= style;
278 LEAVE();