comparison dwtx/jface/text/WhitespaceCharacterPainter.d @ 162:1a5b8f8129df

...
author Frank Benoit <benoit@tionex.de>
date Mon, 08 Sep 2008 00:51:37 +0200
parents 000f9136b8f7
children
comparison
equal deleted inserted replaced
161:f8d52b926852 162:1a5b8f8129df
168 import dwt.graphics.GC; 168 import dwt.graphics.GC;
169 import dwt.graphics.Point; 169 import dwt.graphics.Point;
170 170
171 171
172 /** 172 /**
173 * A painter for drawing visible characters for (invisible) whitespace 173 * A painter for drawing visible characters for (invisible) whitespace
174 * characters. 174 * characters.
175 * 175 *
176 * @since 3.3 176 * @since 3.3
177 */ 177 */
178 public class WhitespaceCharacterPainter : IPainter, PaintListener { 178 public class WhitespaceCharacterPainter : IPainter, PaintListener {
179 179
180 private static const char SPACE_SIGN= '\u00b7'; 180 private static const char SPACE_SIGN= '\u00b7';
181 private static const char IDEOGRAPHIC_SPACE_SIGN= '\u00b0'; 181 private static const char IDEOGRAPHIC_SPACE_SIGN= '\u00b0';
182 private static const char TAB_SIGN= '\u00bb'; 182 private static const char TAB_SIGN= '\u00bb';
183 private static const char CARRIAGE_RETURN_SIGN= '\u00a4'; 183 private static const char CARRIAGE_RETURN_SIGN= '\u00a4';
184 private static const char LINE_FEED_SIGN= '\u00b6'; 184 private static const char LINE_FEED_SIGN= '\u00b6';
185 185
186 /** Indicates whether this painter is active. */ 186 /** Indicates whether this painter is active. */
187 private bool fIsActive= false; 187 private bool fIsActive= false;
188 /** The source viewer this painter is attached to. */ 188 /** The source viewer this painter is attached to. */
189 private ITextViewer fTextViewer; 189 private ITextViewer fTextViewer;
190 /** The viewer's widget. */ 190 /** The viewer's widget. */
192 /** Tells whether the advanced graphics sub system is available. */ 192 /** Tells whether the advanced graphics sub system is available. */
193 private bool fIsAdvancedGraphicsPresent; 193 private bool fIsAdvancedGraphicsPresent;
194 194
195 /** 195 /**
196 * Creates a new painter for the given text viewer. 196 * Creates a new painter for the given text viewer.
197 * 197 *
198 * @param textViewer the text viewer the painter should be attached to 198 * @param textViewer the text viewer the painter should be attached to
199 */ 199 */
200 public this(ITextViewer textViewer) { 200 public this(ITextViewer textViewer) {
201 super(); 201 // super();
202 fTextViewer= textViewer; 202 fTextViewer= textViewer;
203 fTextWidget= textViewer.getTextWidget(); 203 fTextWidget= textViewer.getTextWidget();
204 GC gc= new GC(fTextWidget); 204 GC gc= new GC(fTextWidget);
205 gc.setAdvanced(true); 205 gc.setAdvanced(true);
206 fIsAdvancedGraphicsPresent= gc.getAdvanced(); 206 fIsAdvancedGraphicsPresent= gc.getAdvanced();
276 } 276 }
277 } 277 }
278 278
279 /** 279 /**
280 * Draw characters in view range. 280 * Draw characters in view range.
281 * 281 *
282 * @param gc 282 * @param gc
283 * @param x 283 * @param x
284 * @param y 284 * @param y
285 * @param w 285 * @param w
286 * @param h 286 * @param h
299 } 299 }
300 } 300 }
301 301
302 /** 302 /**
303 * Draw the given line range. 303 * Draw the given line range.
304 * 304 *
305 * @param gc 305 * @param gc
306 * @param startLine first line number 306 * @param startLine first line number
307 * @param endLine last line number (inclusive) 307 * @param endLine last line number (inclusive)
308 * @param x the X-coordinate of the drawing range 308 * @param x the X-coordinate of the drawing range
309 * @param w the width of the drawing range 309 * @param w the width of the drawing range
368 } 368 }
369 } 369 }
370 370
371 /** 371 /**
372 * Draw characters of content range. 372 * Draw characters of content range.
373 * 373 *
374 * @param gc the GC 374 * @param gc the GC
375 * @param startOffset inclusive start index 375 * @param startOffset inclusive start index
376 * @param endOffset exclusive end index 376 * @param endOffset exclusive end index
377 */ 377 */
378 private void drawCharRange(GC gc, int startOffset, int endOffset) { 378 private void drawCharRange(GC gc, int startOffset, int endOffset) {
432 fg= styleRange.foreground; 432 fg= styleRange.foreground;
433 } 433 }
434 } 434 }
435 draw(gc, widgetOffset, visibleChar.toString(), fg); 435 draw(gc, widgetOffset, visibleChar.toString(), fg);
436 } 436 }
437 visibleChar.delete_(0, visibleChar.length()); 437 visibleChar.truncate(0);
438 } 438 }
439 } 439 }
440 } 440 }
441 441
442 /** 442 /**
443 * Check if the given widget line is a folded line. 443 * Check if the given widget line is a folded line.
444 * 444 *
445 * @param widgetLine the widget line number 445 * @param widgetLine the widget line number
446 * @return <code>true</code> if the line is folded 446 * @return <code>true</code> if the line is folded
447 */ 447 */
448 private bool isFoldedLine(int widgetLine) { 448 private bool isFoldedLine(int widgetLine) {
449 if ( cast(ITextViewerExtension5)fTextViewer ) { 449 if ( cast(ITextViewerExtension5)fTextViewer ) {
462 fTextWidget.redraw(); 462 fTextWidget.redraw();
463 } 463 }
464 464
465 /** 465 /**
466 * Draw string at widget offset. 466 * Draw string at widget offset.
467 * 467 *
468 * @param gc 468 * @param gc
469 * @param offset the widget offset 469 * @param offset the widget offset
470 * @param s the string to be drawn 470 * @param s the string to be drawn
471 * @param fg the foreground color 471 * @param fg the foreground color
472 */ 472 */
474 // Compute baseline delta (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=165640) 474 // Compute baseline delta (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=165640)
475 int baseline= fTextWidget.getBaseline(offset); 475 int baseline= fTextWidget.getBaseline(offset);
476 FontMetrics fontMetrics= gc.getFontMetrics(); 476 FontMetrics fontMetrics= gc.getFontMetrics();
477 int fontBaseline= fontMetrics.getAscent() + fontMetrics.getLeading(); 477 int fontBaseline= fontMetrics.getAscent() + fontMetrics.getLeading();
478 int baslineDelta= baseline - fontBaseline; 478 int baslineDelta= baseline - fontBaseline;
479 479
480 Point pos= fTextWidget.getLocationAtOffset(offset); 480 Point pos= fTextWidget.getLocationAtOffset(offset);
481 gc.setForeground(fg); 481 gc.setForeground(fg);
482 gc.drawString(s, pos.x, pos.y + baslineDelta, true); 482 gc.drawString(s, pos.x, pos.y + baslineDelta, true);
483 } 483 }
484 484
485 /** 485 /**
486 * Convert a document offset to the corresponding widget offset. 486 * Convert a document offset to the corresponding widget offset.
487 * 487 *
488 * @param documentOffset 488 * @param documentOffset
489 * @return widget offset 489 * @return widget offset
490 */ 490 */
491 private int getWidgetOffset(int documentOffset) { 491 private int getWidgetOffset(int documentOffset) {
492 if ( cast(ITextViewerExtension5)fTextViewer ) { 492 if ( cast(ITextViewerExtension5)fTextViewer ) {
501 return widgetOffset; 501 return widgetOffset;
502 } 502 }
503 503
504 /** 504 /**
505 * Convert a widget offset to the corresponding document offset. 505 * Convert a widget offset to the corresponding document offset.
506 * 506 *
507 * @param widgetOffset 507 * @param widgetOffset
508 * @return document offset 508 * @return document offset
509 */ 509 */
510 private int getDocumentOffset(int widgetOffset) { 510 private int getDocumentOffset(int widgetOffset) {
511 if ( cast(ITextViewerExtension5)fTextViewer ) { 511 if ( cast(ITextViewerExtension5)fTextViewer ) {