# HG changeset patch # User Jacob Carlborg # Date 1243982191 -7200 # Node ID 3d9eb62cd2e340be1a493e31fe7c5c251ce3ef7e # Parent 52d360200ae4d93dfc8658a26d7e9f8b8b705281 Fixes #8 diff -r 52d360200ae4 -r 3d9eb62cd2e3 dwt/internal/cocoa/NSString.d --- a/dwt/internal/cocoa/NSString.d Sat May 30 23:40:34 2009 +0200 +++ b/dwt/internal/cocoa/NSString.d Wed Jun 03 00:36:31 2009 +0200 @@ -21,6 +21,8 @@ import dwt.internal.objc.cocoa.Cocoa; import objc = dwt.internal.objc.runtime; +import tango.stdc.stdlib; + public class NSString : NSObject { public this() { @@ -36,7 +38,7 @@ } public String getString() { - wchar[] buffer = new wchar[length()]; + wchar[] buffer = new wchar[lengthOfCharacters]; getCharacters(buffer.ptr); return dwt.dwthelper.utils.toString(buffer); } @@ -74,6 +76,14 @@ return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_length); } +public NSUInteger lengthOfCharacters() { + return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_length); +} + +public NSUInteger lengthOfBytesUsingEncoding(NSStringEncoding enc) { + return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_lengthOfBytesUsingEncoding_, enc); +} + public NSString lowercaseString() { objc.id result = OS.objc_msgSend(this.id, OS.sel_lowercaseString); return result is this.id ? this : (result !is null ? new NSString(result) : null); @@ -119,4 +129,4 @@ return result !is null ? new NSString(result) : null; } -} +} \ No newline at end of file diff -r 52d360200ae4 -r 3d9eb62cd2e3 dwt/internal/cocoa/OS.d --- a/dwt/internal/cocoa/OS.d Sat May 30 23:40:34 2009 +0200 +++ b/dwt/internal/cocoa/OS.d Wed Jun 03 00:36:31 2009 +0200 @@ -561,6 +561,7 @@ sel_getBytes_length_ = sel_registerName("getBytes:length:"); sel_getCharacters_ = sel_registerName("getCharacters:"); sel_getCharacters_range_ = sel_registerName("getCharacters:range:"); + sel_getCString_maxLength_encoding_ = sel_registerName("getCString:maxLength:encoding:"); sel_getComponents_ = sel_registerName("getComponents:"); sel_getGlyphs_range_ = sel_registerName("getGlyphs:range:"); sel_getIndexes_maxCount_inIndexRange_ = sel_registerName("getIndexes:maxCount:inIndexRange:"); @@ -667,6 +668,7 @@ sel_lastPathComponent = sel_registerName("lastPathComponent"); sel_leading = sel_registerName("leading"); sel_length = sel_registerName("length"); + sel_lengthOfBytesUsingEncoding_ = sel_registerName("lengthOfBytesUsingEncoding:"); sel_levelForItem_ = sel_registerName("levelForItem:"); sel_lineFragmentUsedRectForGlyphAtIndex_effectiveRange_ = sel_registerName("lineFragmentUsedRectForGlyphAtIndex:effectiveRange:"); sel_lineFragmentUsedRectForGlyphAtIndex_effectiveRange_withoutAdditionalLayout_ = sel_registerName("lineFragmentUsedRectForGlyphAtIndex:effectiveRange:withoutAdditionalLayout:"); @@ -1099,6 +1101,7 @@ sel_strokeRect_ = sel_registerName("strokeRect:"); sel_styleMask = sel_registerName("styleMask"); sel_submenu = sel_registerName("submenu"); + sel_substringWithRange_ = sel_registerName("substringWithRange:"); sel_subviews = sel_registerName("subviews"); sel_superclass = sel_registerName("superclass"); sel_superview = sel_registerName("superview"); @@ -2033,6 +2036,7 @@ public static const objc.SEL sel_getBytes_length_; public static const objc.SEL sel_getCharacters_; public static const objc.SEL sel_getCharacters_range_; +public static const objc.SEL sel_getCString_maxLength_encoding_; public static const objc.SEL sel_getComponents_; public static const objc.SEL sel_getGlyphs_range_; public static const objc.SEL sel_getIndexes_maxCount_inIndexRange_; @@ -2139,6 +2143,7 @@ public static const objc.SEL sel_lastPathComponent; public static const objc.SEL sel_leading; public static const objc.SEL sel_length; +public static const objc.SEL sel_lengthOfBytesUsingEncoding_; public static const objc.SEL sel_levelForItem_; public static const objc.SEL sel_lineFragmentUsedRectForGlyphAtIndex_effectiveRange_; public static const objc.SEL sel_lineFragmentUsedRectForGlyphAtIndex_effectiveRange_withoutAdditionalLayout_; @@ -2571,6 +2576,7 @@ public static const objc.SEL sel_strokeRect_; public static const objc.SEL sel_styleMask; public static const objc.SEL sel_submenu; +public static const objc.SEL sel_substringWithRange_; public static const objc.SEL sel_subviews; public static const objc.SEL sel_superclass; public static const objc.SEL sel_superview; @@ -3980,8 +3986,8 @@ public static const int NSStreamStatusOpening = 1; public static const int NSStreamStatusReading = 3; public static const int NSStreamStatusWriting = 4; -public static const int NSStringEncodingConversionAllowLossy = 1; -public static const int NSStringEncodingConversionExternalRepresentation = 2; +alias Cocoa.NSStringEncodingConversionOptions.NSStringEncodingConversionAllowLossy NSStringEncodingConversionAllowLossy; +alias Cocoa.NSStringEncodingConversionOptions.NSStringEncodingConversionExternalRepresentation NSStringEncodingConversionExternalRepresentation; public static const int NSSubqueryExpressionType = 13; public static const int NSSunOSOperatingSystem = 6; public static const int NSSymbolStringEncoding = 6; diff -r 52d360200ae4 -r 3d9eb62cd2e3 dwt/internal/objc/cocoa/Cocoa.d --- a/dwt/internal/objc/cocoa/Cocoa.d Sat May 30 23:40:34 2009 +0200 +++ b/dwt/internal/objc/cocoa/Cocoa.d Wed Jun 03 00:36:31 2009 +0200 @@ -671,6 +671,11 @@ NSProprietaryStringEncoding = 65536 } +enum NSStringEncodingConversionOptions : NSUInteger +{ + NSStringEncodingConversionAllowLossy = 1, + NSStringEncodingConversionExternalRepresentation = 2 +} // NSTableView.h diff -r 52d360200ae4 -r 3d9eb62cd2e3 dwt/widgets/Text.d --- a/dwt/widgets/Text.d Sat May 30 23:40:34 2009 +0200 +++ b/dwt/widgets/Text.d Wed Jun 03 00:36:31 2009 +0200 @@ -1,4 +1,4 @@ -/******************************************************************************* +/******************************************************************************* * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -58,6 +58,8 @@ import dwt.widgets.Scrollable; import dwt.widgets.TypedListener; +import mambo.io; + /** * Instances of this class are selectable user interface * objects that allow the user to enter and modify text. @@ -98,37 +100,37 @@ int textLimit, tabs = 8; char echoCharacter; bool doubleClick, receivingFocus; - String hiddenText, message; + wchar[] hiddenText, message; NSRange* selectionRange; NSRange selectionRangeStruct; -/** - * The maximum number of characters that can be entered - * into a text widget. - *

- * Note that this value is platform dependent, based upon - * the native widget implementation. - *

- */ -public static const int LIMIT; + /** + * The maximum number of characters that can be entered + * into a text widget. + *

+ * Note that this value is platform dependent, based upon + * the native widget implementation. + *

+ */ + public static const int LIMIT; -/** - * The delimiter used by multi-line text widgets. When text - * is queried and from the widget, it will be delimited using - * this delimiter. - */ -public static const String DELIMITER; -static const wchar PASSWORD = '\u2022'; + /** + * The delimiter used by multi-line text widgets. When text + * is queried and from the widget, it will be delimited using + * this delimiter. + */ + public static const String DELIMITER; + static const wchar PASSWORD = '\u2022'; -/* - * These values can be different on different platforms. - * Therefore they are not initialized in the declaration - * to stop the compiler from inlining. - */ -static this () { - LIMIT = 0x7FFFFFFF; - DELIMITER = "\r"; -} + /* + * These values can be different on different platforms. + * Therefore they are not initialized in the declaration + * to stop the compiler from inlining. + */ + static this () { + LIMIT = 0x7FFFFFFF; + DELIMITER = "\r"; + } /** * Constructs a new instance of this class given its parent @@ -436,8 +438,8 @@ if ((style & DWT.CENTER) !is 0) align_ = OS.NSCenterTextAlignment; if ((style & DWT.RIGHT) !is 0) align_ = OS.NSRightTextAlignment; widget.setAlignment (align_); - // widget.setTarget(widget); - // widget.setAction(OS.sel_sendSelection); +// widget.setTarget(widget); +// widget.setAction(OS.sel_sendSelection); view = widget; } else { NSScrollView scrollWidget = cast(NSScrollView) (new SWTScrollView ()).alloc (); @@ -455,7 +457,7 @@ size.width = size.height = Float.MAX_VALUE; widget.setMaxSize (size); widget.setAutoresizingMask (OS.NSViewWidthSizable | OS.NSViewHeightSizable); - + if ((style & DWT.WRAP) is 0) { NSTextContainer textContainer = widget.textContainer (); widget.setHorizontallyResizable (true); @@ -464,14 +466,14 @@ csize.width = csize.height = Float.MAX_VALUE; textContainer.setContainerSize (csize); } - + NSTextAlignment align_ = OS.NSLeftTextAlignment; if ((style & DWT.CENTER) !is 0) align_ = OS.NSCenterTextAlignment; if ((style & DWT.RIGHT) !is 0) align_ = OS.NSRightTextAlignment; widget.setAlignment (align_); - - // widget.setTarget(widget); - // widget.setAction(OS.sel_sendSelection); + +// widget.setTarget(widget); +// widget.setAction(OS.sel_sendSelection); widget.setRichText (false); widget.setDelegate(widget); @@ -606,8 +608,8 @@ //TODO - caret location for unicode text return new Point (0, 0); } - // NSText - // NSRange range = (cast(NSTextView)view).selectedRange(); +// NSText +// NSRange range = (cast(NSTextView)view).selectedRange(); return null; } @@ -718,17 +720,17 @@ } else { str = (cast(NSTextView)view).textStorage().string(); } - + NSUInteger length_ = str.length (); - char [] buffer = new char [length_]; + wchar [] buffer = new wchar [length_]; if (hiddenText !is null) { hiddenText.getChars (0, length_, buffer, 0); } else { NSRange range = NSRange (); range.length = length_; - str.getCharacters (buffer.toString16().ptr, range); + str.getCharacters (buffer.ptr, range); } - return buffer; + return dwt.dwthelper.utils.toString(buffer); } char [] getEditText (int start, int end) { @@ -738,7 +740,7 @@ } else { str = (cast(NSTextView)view).textStorage().string(); } - + int length = cast(int)/*64*/str.length (); end = Math.min (end, length - 1); if (start > end) return new char [0]; @@ -746,13 +748,13 @@ NSRange range = NSRange (); range.location = start; range.length = Math.max (0, end - start + 1); - char [] buffer = new char [range.length]; + wchar [] buffer = new wchar [range.length]; if (hiddenText !is null) { hiddenText.getChars (cast(int)/*64*/range.location, cast(int)/*64*/(range.location + range.length), buffer, 0); } else { - str.getCharacters (buffer.toString16().ptr, range); + str.getCharacters (buffer.ptr, range); } - return buffer; + return dwt.dwthelper.utils.toString(buffer); } /** @@ -843,11 +845,11 @@ */ public String getMessage () { checkWidget (); - return message; + return dwt.dwthelper.utils.toString(message); } int getPosition (int x, int y) { - // checkWidget (); +// checkWidget (); //TODO return 0; } @@ -932,9 +934,9 @@ NSTextView widget = cast(NSTextView) view; NSRange range = widget.selectedRange (); NSString str = widget.textStorage ().string (); - char[] buffer = new char [range.length]; - str.getCharacters (buffer.toString16().ptr, range); - return new_String (buffer); + wchar[] buffer = new wchar [range.length]; + str.getCharacters (buffer.ptr, range); + return dwt.dwthelper.utils.toString(buffer); } } @@ -1446,17 +1448,17 @@ public void setEchoChar (char echo) { checkWidget (); if ((style & DWT.MULTI) !is 0) return; - // if (txnObject is 0) { - // if ((style & DWT.PASSWORD) is 0) { - // Point selection = getSelection (); - // String text = getText (); - // echoCharacter = echo; - // setEditText (text); - // setSelection (selection); - // } - // } else { - // OS.TXNEchoMode (txnObject, echo, OS.kTextEncodingMacUnicode, echo !is '\0'); - // } +// if (txnObject is 0) { +// if ((style & DWT.PASSWORD) is 0) { +// Point selection = getSelection (); +// String text = getText (); +// echoCharacter = echo; +// setEditText (text); +// setSelection (selection); +// } +// } else { +// OS.TXNEchoMode (txnObject, echo, OS.kTextEncodingMacUnicode, echo !is '\0'); +// } echoCharacter = echo; } @@ -1487,7 +1489,7 @@ void setEditText (String string) { char [] buffer; if ((style & DWT.PASSWORD) is 0 && echoCharacter !is '\0') { - hiddenText = string; + hiddenText = string.toString16(); buffer = new char [Math.min(hiddenText.length (), textLimit)]; for (int i = 0; i < buffer.length; i++) buffer [i] = echoCharacter; } else { @@ -1568,15 +1570,15 @@ public void setMessage (String message) { checkWidget (); //if (message is null) error (DWT.ERROR_NULL_ARGUMENT); - this.message = message; - // if ((style & DWT.SEARCH) !is 0) { - // char [] buffer = new char [message.length ()]; - // message.getChars (0, buffer.length, buffer, 0); - // int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length); - // if (ptr is 0) error (DWT.ERROR_CANNOT_SET_TEXT); - // OS.HISearchFieldSetDescriptiveText (handle, ptr); - // OS.CFRelease (ptr); - // } + this.message = message.toString16(); +// if ((style & DWT.SEARCH) !is 0) { +// char [] buffer = new char [message.length ()]; +// message.getChars (0, buffer.length, buffer, 0); +// int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length); +// if (ptr is 0) error (DWT.ERROR_CANNOT_SET_TEXT); +// OS.HISearchFieldSetDescriptiveText (handle, ptr); +// OS.CFRelease (ptr); +// } } /** @@ -1712,14 +1714,14 @@ public void setTabs (int tabs) { checkWidget (); if (this.tabs is tabs) return; - // if (txnObject is 0) return; - // this.tabs = tabs; - // TXNTab tab = new TXNTab (); - // tab.value = cast(short) (textExtent (new char[]{' '}, 0).x * tabs); - // int [] tags = new int [] {OS.kTXNTabSettingsTag}; - // int [] datas = new int [1]; - // OS.memmove (datas, tab, TXNTab.sizeof); - // OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas); +// if (txnObject is 0) return; +// this.tabs = tabs; +// TXNTab tab = new TXNTab (); +// tab.value = cast(short) (textExtent (new char[]{' '}, 0).x * tabs); +// int [] tags = new int [] {OS.kTXNTabSettingsTag}; +// int [] datas = new int [1]; +// OS.memmove (datas, tab, TXNTab.sizeof); +// OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas); } /** @@ -1799,10 +1801,10 @@ checkWidget (); if ((style & DWT.SINGLE) !is 0) return; //TODO no working - // NSTextView widget = cast(NSTextView) view; - // NSRange range = NSRange (); - // NSRect rect = widget.firstRectForCharacterRange (range); - // view.scrollRectToVisible (rect); +// NSTextView widget = cast(NSTextView) view; +// NSRange range = NSRange (); +// NSRect rect = widget.firstRectForCharacterRange (range); +// view.scrollRectToVisible (rect); } /** @@ -1841,12 +1843,12 @@ NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange (objc.id id, objc.SEL sel, objc.id aTextView, objc.id oldSelectedCharRange, objc.id newSelectedCharRange) { /* - * If the selection is changing as a result of the receiver getting focus - * then return the receiver's last selection range, otherwise the full - * text will be automatically selected. - */ + * If the selection is changing as a result of the receiver getting focus + * then return the receiver's last selection range, otherwise the full + * text will be automatically selected. + */ if (receivingFocus && selectionRange !is null) return selectionRangeStruct; - + /* allow the selection change to proceed */ NSRange result = NSRange (); OS.memmove(&result, newSelectedCharRange, NSRange.sizeof);