Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet222.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | 9f4c18c268b2 |
children |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) | |
12 *******************************************************************************/ | |
13 | |
14 module org.eclipse.swt.snippets.Snippet222; | |
15 /* | |
16 * example snippet: StyledText bulleted list example | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.2 | |
22 */ | |
23 | |
24 import org.eclipse.swt.SWT; | |
25 import org.eclipse.swt.custom.StyledText; | |
26 import org.eclipse.swt.custom.StyleRange; | |
27 import org.eclipse.swt.custom.PaintObjectEvent; | |
28 import org.eclipse.swt.custom.PaintObjectListener; | |
29 import org.eclipse.swt.custom.Bullet; | |
30 import org.eclipse.swt.custom.ST; | |
31 import org.eclipse.swt.layout.GridData; | |
32 import org.eclipse.swt.layout.FillLayout; | |
33 import org.eclipse.swt.widgets.Display; | |
34 import org.eclipse.swt.widgets.Shell; | |
35 import org.eclipse.swt.widgets.Button; | |
36 import org.eclipse.swt.widgets.Event; | |
37 import org.eclipse.swt.widgets.Listener; | |
38 import org.eclipse.swt.graphics.FontData; | |
39 import org.eclipse.swt.graphics.Font; | |
40 import org.eclipse.swt.graphics.TextLayout; | |
41 import org.eclipse.swt.graphics.GlyphMetrics; | |
112 | 42 version(Tango){ |
43 import tango.util.Convert; | |
44 } else { // Phobos | |
45 import std.conv; | |
46 } | |
28 | 47 |
48 import java.lang.all; | |
49 version(JIVE){ | |
50 import jive.stacktrace; | |
51 } | |
52 | |
53 void main() { | |
54 Display display = new Display(); | |
55 Shell shell = new Shell(display); | |
56 shell.setText("StyledText Bullet Example"); | |
57 shell.setLayout(new FillLayout()); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
58 StyledText styledText = new StyledText (shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); |
28 | 59 StringBuffer text = new StringBuffer(); |
60 text.append("Here is StyledText with some bulleted lists:\n\n"); | |
112 | 61 for (int i = 0; i < 4; i++) text.append("Red Bullet List Item " ~ to!(String)(i) ~ "\n"); |
28 | 62 text.append("\n"); |
112 | 63 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(String)(i) ~ "\n"); |
64 for (int i = 0; i < 4; i++) text.append("Sub List Item " ~ to!(String)(i) ~ "\n"); | |
65 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(String)(2+i) ~ "\n"); | |
28 | 66 text.append("\n"); |
112 | 67 for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " ~ to!(String)(i) ~ "\n"); |
28 | 68 styledText.setText(text.toString()); |
69 | |
70 StyleRange style0 = new StyleRange(); | |
71 style0.metrics = new GlyphMetrics(0, 0, 40); | |
72 style0.foreground = display.getSystemColor(SWT.COLOR_RED); | |
73 Bullet bullet0 = new Bullet (style0); | |
74 StyleRange style1 = new StyleRange(); | |
75 style1.metrics = new GlyphMetrics(0, 0, 50); | |
76 style1.foreground = display.getSystemColor(SWT.COLOR_BLUE); | |
77 Bullet bullet1 = new Bullet (ST.BULLET_NUMBER | ST.BULLET_TEXT, style1); | |
78 bullet1.text = "."; | |
79 StyleRange style2 = new StyleRange(); | |
80 style2.metrics = new GlyphMetrics(0, 0, 80); | |
81 style2.foreground = display.getSystemColor(SWT.COLOR_GREEN); | |
82 Bullet bullet2 = new Bullet (ST.BULLET_TEXT, style2); | |
83 bullet2.text = "\u2713"; | |
84 StyleRange style3 = new StyleRange(); | |
85 style3.metrics = new GlyphMetrics(0, 0, 50); | |
86 Bullet bullet3 = new Bullet (ST.BULLET_CUSTOM, style2); | |
87 | |
88 styledText.setLineBullet(2, 4, bullet0); | |
89 styledText.setLineBullet(7, 2, bullet1); | |
90 styledText.setLineBullet(9, 4, bullet2); | |
91 styledText.setLineBullet(13, 2, bullet1); | |
92 styledText.setLineBullet(16, 4, bullet3); | |
93 | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
112
diff
changeset
|
94 styledText.addPaintObjectListener(new class PaintObjectListener { |
28 | 95 public void paintObject(PaintObjectEvent event) { |
96 Display display = event.display; | |
97 StyleRange style = event.style; | |
98 Font font = style.font; | |
99 if (font is null) font = styledText.getFont(); | |
100 TextLayout layout = new TextLayout(display); | |
101 layout.setAscent(event.ascent); | |
102 layout.setDescent(event.descent); | |
103 layout.setFont(font); | |
112 | 104 layout.setText("\u2023 1." ~ to!(String)( event.bulletIndex) ~ ")"); |
28 | 105 layout.draw(event.gc, event.x + 10, event.y); |
106 layout.dispose(); | |
107 } | |
108 }); | |
109 shell.open(); | |
110 while (!shell.isDisposed()) { | |
111 if (!display.readAndDispatch()) display.sleep(); | |
112 } | |
113 display.dispose (); | |
114 } | |
115 |