# HG changeset patch # User Frank Benoit # Date 1204479853 -3600 # Node ID bfdfcd1c8f28d92259c5c8dd7985506504e4d24a # Parent 0f63eae37f354fc1efe281f6e9998846b8d56b17 Fix: utf8 awareness diff -r 0f63eae37f35 -r bfdfcd1c8f28 dwtexamples/texteditor/TextEditor.d --- a/dwtexamples/texteditor/TextEditor.d Sat Mar 01 15:03:35 2008 -0800 +++ b/dwtexamples/texteditor/TextEditor.d Sun Mar 02 18:44:13 2008 +0100 @@ -42,48 +42,52 @@ import dwtexamples.texteditor.Images; +version( JIVE ){ + import jive.stacktrace; +} + /** */ -public class TextEditor { +public class TextEditor { Shell shell; ToolBar toolBar; StyledText text; - Images images; + Images images; alias ArraySeq!(StyleRange) StyleCache; StyleCache cachedStyles; - Color RED = null; - Color BLUE = null; - Color GREEN = null; + Color RED = null; + Color BLUE = null; + Color GREEN = null; Font font = null; ToolItem boldButton, italicButton, underlineButton, strikeoutButton; - + //string resources static ResourceBundle resources; private static const char[] resourceData = import( "examples_texteditor.properties" ); - - /* + + /* * static ctor */ static this() { resources = ResourceBundle.getBundleFromData( resourceData ); } - - /* + + /* * ctor */ this() { images = new Images(); } - - /* - * creates edit menu + + /* + * creates edit menu */ Menu createEditMenu() { Menu bar = shell.getMenuBar (); Menu menu = new Menu (bar); - + MenuItem item = new MenuItem (menu, DWT.PUSH); item.setText (resources.getString("Cut_menuitem")); item.setAccelerator(DWT.MOD1 + 'X'); @@ -110,7 +114,7 @@ text.paste(); } }); - new MenuItem (menu, DWT.SEPARATOR); + new MenuItem (menu, DWT.SEPARATOR); item = new MenuItem (menu, DWT.PUSH); item.setText (resources.getString("Font_menuitem")); item.addSelectionListener(new class() SelectionAdapter { @@ -120,14 +124,14 @@ }); return menu; } - - /* - * creates file menu + + /* + * creates file menu */ Menu createFileMenu() { Menu bar = shell.getMenuBar (); Menu menu = new Menu (bar); - + MenuItem item = new MenuItem (menu, DWT.PUSH); item.setText (resources.getString("Exit_menuitem")); item.addSelectionListener(new class() SelectionAdapter { @@ -158,7 +162,7 @@ if (widget is boldButton) { style.fontStyle ^= DWT.BOLD; } else if (widget is italicButton) { - style.fontStyle ^= DWT.ITALIC; + style.fontStyle ^= DWT.ITALIC; } else if (widget is underlineButton) { style.underline = !style.underline; } else if (widget is strikeoutButton) { @@ -166,7 +170,7 @@ } text.setStyleRange(style); } - text.setSelectionRange(sel.x + sel.y, 0); + text.setSelectionRange(sel.x + sel.y, 0); } /* @@ -181,7 +185,7 @@ } text.setSelectionRange(sel.x + sel.y, 0); } - + /* * Set the foreground color for the selected text. */ @@ -203,8 +207,8 @@ } text.setSelectionRange(sel.x + sel.y, 0); } - - /* + + /* * creates menu bar */ void createMenuBar () { @@ -219,13 +223,13 @@ editItem.setText (resources.getString("Edit_menuitem")); editItem.setMenu (createEditMenu ()); } - - /* + + /* * creates shell */ void createShell (Display display) { shell = new Shell (display); - shell.setText (resources.getString("Window_title")); + shell.setText (resources.getString("Window_title")); images.loadAll (display); GridLayout layout = new GridLayout(); layout.numColumns = 1; @@ -240,8 +244,8 @@ } }); } - - /* + + /* * creates styled text widget */ void createStyledText() { @@ -259,8 +263,8 @@ } }); } - - /* + + /* * creates tool bar */ void createToolBar() { @@ -286,7 +290,7 @@ strikeoutButton.setImage(images.Strikeout); strikeoutButton.setToolTipText(resources.getString("Strikeout")); strikeoutButton.addSelectionListener(listener); - + ToolItem item = new ToolItem(toolBar, DWT.SEPARATOR); item = new ToolItem(toolBar, DWT.PUSH); item.setImage(images.Red); @@ -308,7 +312,7 @@ public void widgetSelected(SelectionEvent event) { fgColor(BLUE); } - }); + }); item = new ToolItem(toolBar, DWT.SEPARATOR); item = new ToolItem(toolBar, DWT.PUSH); item.setImage(images.Erase); @@ -318,15 +322,15 @@ } }); } - + /* * Cache the style information for text that has been cut or copied. */ void handleCutCopy() { // Save the cut/copied style info so that during paste we will maintain // the style information. Cut/copied text is put in the clipboard in - // RTF format, but is not pasted in RTF format. The other way to - // handle the pasting of styles would be to access the Clipboard directly and + // RTF format, but is not pasted in RTF format. The other way to + // handle the pasting of styles would be to access the Clipboard directly and // parse the RTF text. cachedStyles = new StyleCache(); Point sel = text.getSelectionRange(); @@ -348,14 +352,16 @@ } } } - - /* + + /* * handle modify */ void handleExtendedModify(ExtendedModifyEvent event) { if (event.length is 0) return; StyleRange style; - if (event.length is 1 || text.getTextRange(event.start, event.length) == text.getLineDelimiter()) { + //PORTING event.length is char count, but it needs to decide on codepoint count + auto cont = text.getTextRange(event.start, event.length); + if ( codepointCount(cont) is 1 || cont == text.getLineDelimiter()) { // Have the new text take on the style of the text to its right (during // typing) if no style information is active. int caretOffset = text.getCaretOffset(); @@ -367,7 +373,7 @@ style.length = event.length; } else { style = new StyleRange(event.start, event.length, null, null, DWT.NORMAL); - } + } if (boldButton.getSelection()) style.fontStyle |= DWT.BOLD; if (italicButton.getSelection()) style.fontStyle |= DWT.ITALIC; style.underline = underlineButton.getSelection(); @@ -383,9 +389,9 @@ } } } - - /* - * opens the shell + + /* + * opens the shell */ public Shell open (Display display) { createShell (display); @@ -396,8 +402,8 @@ shell.open (); return shell; } - - /* + + /* * set the font for styled text widget */ void setFont() { @@ -405,14 +411,14 @@ fontDialog.setFontList((text.getFont()).getFontData()); FontData fontData = fontDialog.open(); if (fontData !is null) { - Font newFont = new Font(shell.getDisplay(), fontData); + Font newFont = new Font(shell.getDisplay(), fontData); text.setFont(newFont); if (font !is null) font.dispose(); font = newFont; } } - - /* + + /* * initialize the colors */ void initializeColors() { @@ -423,7 +429,7 @@ } } -/* +/* * main function */ public void main (char[][] args) {