diff options
2 files changed, 43 insertions, 7 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java index c65cfd471a..551c1b3b95 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java @@ -9,6 +9,7 @@ import org.eclipse.swt.dnd.*; import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.printing.*;
import java.util.*;
/**
@@ -3385,18 +3386,35 @@ public void paste(){ /**
* Prints the widget's text to the default printer.
* <p>
+ * This method may be called from a non-UI thread.
+ * </p>
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void print() {
- checkWidget();
+public void print() {
+ if (isDisposed()) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
new StyledTextPrinter(this).print();
}
/**
+ * Prints the widget's text to the specified printer.
+ * <p>
+ * This method may be called from a non-UI thread.
+ * </p>
+ *
+ * @param printer the printer to print to
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * </ul>
+ */
+public void print(Printer printer) {
+ if (isDisposed()) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
+ new StyledTextPrinter(this).print(printer);
+}
+
+/**
* Scrolls the widget horizontally.
*/
void handleHorizontalScroll(Event event) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrinter.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrinter.java index 27e67857e7..c040974146 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrinter.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrinter.java @@ -29,6 +29,7 @@ class StyledTextPrinter { String rtf;
int index, end;
+ int tabSize;
StringBuffer wordBuffer;
/* We can optimize for fonts because we know styledText only has one font.
@@ -61,6 +62,12 @@ class StyledTextPrinter { public void print() {
printer = new Printer();
+ print(printer);
+ printer.dispose();
+ }
+
+ public void print(Printer printer) {
+ this.printer = printer;
if (printer.startJob("StyledText")) {
Rectangle clientArea = printer.getClientArea();
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
@@ -71,7 +78,11 @@ class StyledTextPrinter { bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one inch from bottom edge of paper
/* Create a buffer for computing tab width. */
- int tabSize = styledText.getTabs();
+ styledText.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ tabSize = styledText.getTabs();
+ }
+ });
StringBuffer tabBuffer = new StringBuffer(tabSize);
for (int i = 0; i < tabSize; i++) tabBuffer.append(' ');
tabs = tabBuffer.toString();
@@ -80,7 +91,11 @@ class StyledTextPrinter { gc = new GC(printer);
x = leftMargin;
y = topMargin;
+ printer.startPage();
printStyledTextRTF();
+ if (y + lineHeight <= bottomMargin) {
+ printer.endPage();
+ }
printer.endJob();
/* Cleanup */
@@ -92,11 +107,14 @@ class StyledTextPrinter { ((Color)colorTable.elementAt(i)).dispose();
}
}
- printer.dispose();
}
-
+
void printStyledTextRTF() {
- rtf = styledText.getRtf();
+ styledText.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ rtf = styledText.getRtf();
+ }
+ });
end = rtf.length();
index = 0;
wordBuffer = new StringBuffer();
|