diff --git a/About.rbbas b/About.rbbas index 6597d848..4924b99b 100644 --- a/About.rbbas +++ b/About.rbbas @@ -13,6 +13,14 @@ Protected Module About These release notes were added as of version 100. Check the git history for previous release notes. Add new notes above existing ones, and remember to increment the Version constant. + 106: 2012-08-23 + - Fixed memory leak with MacSpeechSynthesizer. (thank to Charles for finding the problem) + - Extended MDItem (CreateFromFile, AllAttributes) + - Added MacOSFolderItemExtension SpotlightMetadata which returns all the metadata for a file as a Dictionary + - Extended NSDictionary.Value and NSMutableDictionary.Value to accept a key as variant + - Added optional class checking in the NSObject Constructor + - Many improvements in NSAttributedString and its mutable counterpart, though there is still much work to be done + 105: - Moved M_PList module into "Convenience extensions and objects folder" within macoslib. @@ -41,7 +49,7 @@ Protected Module About #tag EndNote - #tag Constant, Name = Version, Type = Double, Dynamic = False, Default = \"105", Scope = Protected + #tag Constant, Name = Version, Type = Double, Dynamic = False, Default = \"106", Scope = Protected #tag EndConstant diff --git a/Application/App.rbbas b/Application/App.rbbas index 4db7ca0b..4e8c041a 100644 --- a/Application/App.rbbas +++ b/Application/App.rbbas @@ -24,6 +24,8 @@ Inherits Application Cocoa.Initialize + DebugLogWND.Show + End Sub #tag EndEvent diff --git a/Examples/LabelExtensionExampleWindow.rbfrm b/Examples/LabelExtensionExampleWindow.rbfrm index 3c43ca2d..5a17f695 100644 --- a/Examples/LabelExtensionExampleWindow.rbfrm +++ b/Examples/LabelExtensionExampleWindow.rbfrm @@ -51,7 +51,7 @@ Begin Window LabelExtensionExampleWindow TextUnit = 0 Top = 7 Underline = "" - Value = 0 + Value = 1 Visible = True Width = 726 Begin Label Label1 @@ -245,36 +245,8 @@ End dim RTFdata as NSData = new NSData( RTFStringIntroStyled ) dim nsas as NSAttributedString = NSAttributedString.CreateFromRTF( RTFdata ) - 'dim nsas as new NSMutableAttributedString - 'nsas.AppendAttributedString NSAttributedString.CreateFromString_WithAttributes( "Hello", nsas.kNSFontAttributeName : "Lucida Grande", _ - 'nsas.kAttributeBold : true - me.SetAttributedString new AttributedString( nsas ) - - - - 'declare function delegate_ lib CocoaLib selector "delegate" (id as Ptr) as Ptr - 'declare function view_ lib CocoaLib selector "view" (id as Ptr) as Ptr - ' - ''dim myView as Ptr = view_( Ptr( me.Handle )) - ''AssertPtr myView, "myview is nil" - '' - ''ReportObjCDetailsForNSObjectPtr myView - ' - ' - 'dim nstv as NSTextField = new NSTextField( Ptr( me.Handle )) - ' - 'dim del as Ptr = delegate_( nstv ) - ' - 'if del=nil then - 'DReport "del is nil" - 'return - 'end if - ' - ''DebugReportModule.ReportObjCDetailsForClassPtr Cocoa.NSClassFromString( Cocoa.ClassNameForObjectPointer( Ptr( me.Handle ))) - ' - ''ReportObjCDetailsForNSObjectPtr Ptr( me.handle ) End Sub #tag EndEvent #tag EndEvents diff --git a/Examples/MacSpeechSynthesizerExample.rbfrm b/Examples/MacSpeechSynthesizerExample.rbfrm index 34a37b9a..e2dcf5c2 100644 --- a/Examples/MacSpeechSynthesizerExample.rbfrm +++ b/Examples/MacSpeechSynthesizerExample.rbfrm @@ -216,7 +216,6 @@ Begin Window MacSpeechSynthesizerExample Selectable = False TabIndex = 6 TabPanelIndex = 0 - TabStop = True Text = "Voice attributes: (a Dictionary available for each voice)" TextAlign = 0 TextColor = &h000000 @@ -341,7 +340,6 @@ Begin Window MacSpeechSynthesizerExample Selectable = False TabIndex = 10 TabPanelIndex = 0 - TabStop = True Text = "Volume:" TextAlign = 0 TextColor = &h000000 @@ -355,18 +353,15 @@ Begin Window MacSpeechSynthesizerExample Width = 67 End Begin MacSpeechSynthesizer Speech - Enabled = True Height = 32 Index = -2147483648 - Left = 952 + InitialParent = "" + Left = 948 LockedInPosition= False Rate = "" Scope = 0 - TabIndex = 9 TabPanelIndex = 0 - TabStop = True - Top = -16 - Visible = True + Top = -4 Volume = "" Width = 32 End @@ -392,7 +387,6 @@ Begin Window MacSpeechSynthesizerExample Selectable = False TabIndex = 12 TabPanelIndex = 0 - TabStop = True Text = "Current voice:" TextAlign = 0 TextColor = &h000000 @@ -427,7 +421,6 @@ Begin Window MacSpeechSynthesizerExample Selectable = False TabIndex = 13 TabPanelIndex = 0 - TabStop = True Text = "-" TextAlign = 0 TextColor = &h000000 @@ -521,7 +514,6 @@ Begin Window MacSpeechSynthesizerExample Selectable = False TabIndex = 16 TabPanelIndex = 0 - TabStop = True Text = "Rate:" TextAlign = 0 TextColor = &h000000 @@ -553,7 +545,6 @@ Begin Window MacSpeechSynthesizerExample Scope = 0 TabIndex = 17 TabPanelIndex = 0 - TabStop = True TextFont = "SmallSystem" TextSize = 0 TextUnit = 0 @@ -651,16 +642,17 @@ Begin Window MacSpeechSynthesizerExample End Begin Line Line1 BorderWidth = 1 - Enabled = True + Height = 50 Index = -2147483648 InitialParent = "" + Left = "" LineColor = "" LockedInPosition= False Scope = 0 - TabIndex = 16 TabPanelIndex = 0 - TabStop = True + Top = "" Visible = True + Width = 100 X1 = 519 X2 = 519 Y1 = 144 @@ -668,16 +660,17 @@ Begin Window MacSpeechSynthesizerExample End Begin Line Line2 BorderWidth = 1 - Enabled = True + Height = 50 Index = -2147483648 InitialParent = "" + Left = "" LineColor = "" LockedInPosition= False Scope = 0 - TabIndex = 17 TabPanelIndex = 0 - TabStop = True + Top = "" Visible = True + Width = 100 X1 = 519 X2 = 540 Y1 = 194 diff --git a/macoslib.rbvcp b/macoslib.rbvcp index babd061c..65152b32 100644 --- a/macoslib.rbvcp +++ b/macoslib.rbvcp @@ -469,7 +469,7 @@ Class=MacFSEventStream;macoslib/Convenience extensions and objects/MacFSEvents/M Class=MacFSEvent;macoslib/Convenience extensions and objects/MacFSEvents/MacFSEvent.rbbas;&h2FB591;&h7F7254BF;false Class=BadSystemException;macoslib/Exception Classes/BadSystemException.rbbas;&h73914445;&h1CC2A86E;false Class=PropertyList;macoslib/DebugReport Cross-Platform/DebugReportModule/PropertyList.rbbas;&h4423F494;&h533B78C4;false -Class=PLArray;macoslib/DebugReport Cross-Platform/DebugReportModule/PLArray.rbbas;&h148E8525;&h533B78C4;false<<<<<<< HEAD +Class=PLArray;macoslib/DebugReport Cross-Platform/DebugReportModule/PLArray.rbbas;&h148E8525;&h533B78C4;false Folder=KT's PList Stuff;Additional Modules/KT's PList Stuff;&h3D338A86;&h171E2973;false Module=M_PList;Additional Modules/KT's PList Stuff/M_PList.rbbas;&h3144AB7A;&h3D338A86;false Class=MacPListBrowser;Additional Modules/KT's PList Stuff/MacPListBrowser.rbbas;&h9DC53AC;&h3D338A86;false diff --git a/macoslib/Cocoa/Cocoa.rbbas b/macoslib/Cocoa/Cocoa.rbbas index 5597ecff..cbdbcafe 100644 --- a/macoslib/Cocoa/Cocoa.rbbas +++ b/macoslib/Cocoa/Cocoa.rbbas @@ -639,6 +639,8 @@ Protected Module Cocoa case Variant.TypeNil return new NSNull + case Variant.TypeColor + return new NSColor( v.ColorValue ) else raise new TypeMismatchException end select diff --git a/macoslib/Cocoa/NSAttributedString.rbbas b/macoslib/Cocoa/NSAttributedString.rbbas index 6f4105b2..762273a3 100644 --- a/macoslib/Cocoa/NSAttributedString.rbbas +++ b/macoslib/Cocoa/NSAttributedString.rbbas @@ -38,7 +38,7 @@ Inherits NSObject #tag Method, Flags = &h0 Function AttributesAtIndex_LongestEffectiveRange(atIndex as integer, byref effectiveRange as NSRange, maxRange as NSRange) As NSDictionary - #if TargetMacOS + #if TargetMacOS declare function attributesAtIndex lib CocoaLib selector "attributesAtIndex:longestEffectiveRange:inRange:" (id as Ptr, idx as integer, byref range as NSRange, maxRange as NSRange) as Ptr dim p as Ptr = attributesAtIndex( me.id, atIndex, effectiveRange, maxRange ) @@ -47,14 +47,32 @@ Inherits NSObject End Function #tag EndMethod + #tag Method, Flags = &h1000 + Sub Constructor(id as Ptr, hasOwnership as boolean = false) + // Calling the overridden superclass constructor. + // Note that this may need modifications if there are multiple constructor choices. + // Possible constructor calls: + // Constructor() -- From NSObject + // Constructor(obj_id as Ptr, hasOwnership as Boolean = false) -- From NSObject + + Super.Constructor( id, hasOwnership, "NSAttributedString" ) + + End Sub + #tag EndMethod + #tag Method, Flags = &h0 Shared Function CreateFromHTML(HTMLdata as NSData, baseURL as NSURL = nil) As NSAttributedString #if TargetMacOS declare function initWithHTML lib CocoaLib selector "initWithHTML:documentAttributes:" ( id as Ptr, data as Ptr, docAttr as Ptr) as Ptr + declare function initWithHTMLandBase lib CocoaLib selector "initWithHTML:baseURL:documentAttributes:" ( id as Ptr, data as Ptr, baseURL as Ptr, docAttr as Ptr) as Ptr dim p as Ptr = Allocate( "NSAttributedString" ) - p = initWithHTML( p, HTMLData.id, nil ) + if baseURL=nil then + p = initWithHTML( p, HTMLData.id, nil ) + else + p = initWithHTMLandBase( p, HTMLData.id, baseURL.id, nil ) + end if if p<>nil then return new NSAttributedString( p, false ) end if @@ -93,14 +111,13 @@ Inherits NSObject #tag EndMethod #tag Method, Flags = &h0 - Shared Function CreateFromString_WithAttributes(value as String, attr as Dictionary) As NSAttributedString + Shared Function CreateFromString_WithAttributes(value as String, attr as NSDictionary) As NSAttributedString #if TargetMacOS declare function initWithString lib CocoaLib selector "initWithString:attributes:" (id as Ptr, theString as CFStringRef, attr as Ptr) as Ptr dim p as Ptr - dim NSDict as NSDictionary = NSDictionary.CreateFromDictionary( attr ) p = NSAttributedString.Allocate( "NSAttributedString" ) - p = initWithString( p, value, NSDict ) + p = initWithString( p, value, attr ) return new NSAttributedString( p ) #endif @@ -108,15 +125,15 @@ Inherits NSObject #tag EndMethod #tag Method, Flags = &h0 - Shared Function CreateFromString_WithAttributes(value as String, paramarray attrs() as pair) As NSAttributedString - //Same as CreateFromString_WithAttributes but Dictionary values are given a Pair() - - #if TargetMacOS - dim attr as new Dictionary - attr.AppendPairs attrs - - return NSAttributedString.CreateFromString_WithAttributes( value, attr ) - #endif + Shared Function CreateFromString_WithAttributes__(value as String, paramarray attrs() as pair) As NSAttributedString + '//Same as CreateFromString_WithAttributes but Dictionary values are given a Pair() + ' + '#if TargetMacOS + 'dim attr as new Dictionary + 'attr.AppendPairs attrs + ' + 'return NSAttributedString.CreateFromString_WithAttributes( value, attr ) + '#endif End Function #tag EndMethod @@ -137,19 +154,166 @@ Inherits NSObject #if TargetMacOS dim base as NSMutableAttributedString - if me isa NSMutableAttributedString then - base = new NSMutableAttributedString( me.Copy_ ) - else - base = new NSMutableAttributedString( me.MutableCopy, false ) - end if + base = new NSMutableAttributedString( me.MutableCopy, true ) + base.BeginEditing base.AppendAttributedString aString + base.FixAttributes + base.EndEditing return base //Return a NSMutableAttributedString #endif End Function #tag EndMethod + #tag Method, Flags = &h0 + Shared Function QuickCreate(text as string, baseStyles as NSDictionary, paramarray styles as Tuple) As NSAttributedString + + dim nsdict as NSMutableDictionary + dim result as NSAttributedString + + nsdict = StyleDictionaryFromTuples( styles, baseStyles ) + + 'if baseStyles<>nil then + 'nsdict = new NSMutableDictionary( baseStyles.MutableCopy, true ) + 'else + 'nsdict = new NSMutableDictionary + 'end if + ' + 'for i as integer=0 to styles.Ubound + 't = styles( i ) + ' + 'select case t(0) + 'case "font" + 'dim fontfamily as string + 'dim isBold as Boolean + 'dim isItalic as Boolean + 'dim textColor as color = &c000000 + 'dim size as double = 12.0 + 'dim nsf as NSFont + 'dim IsSuperScript as Boolean + 'dim IsSubscript as Boolean + ' + 'for j = 1 to t.Count - 1 + 'select case Vartype( t(j)) + 'case Variant.TypeString + 'select case t(j) + 'case "bold" + 'isBold = true + 'case "italic" + 'isItalic = true + 'case "sup", "super", "superscript" + 'IsSuperScript = true + 'case "sub", "subscript" + 'IsSubscript = true + 'else + 'fontfamily = t(j) + 'end select + 'case Variant.TypeInteger, Variant.TypeDouble + 'size = t(j) + 'case Variant.TypeColor + 'textColor = t(j) + 'else + ' + 'end select + 'next + ' + 'nsf = NSFontManager.SharedManager.GetFont( fontfamily, size, isBold, isItalic ) + 'nsdict.Value( Cocoa.StringConstant( "NSFontAttributeName" )) = nsf + 'nsdict.Value( Cocoa.StringConstant( "NSForegroundColorAttributeName" )) = new NSColor( textColor ) + ' + 'case "underline", "strikethrough" + 'dim underlineStyle as integer + 'dim underlineColor as Color + 'dim hasUnderlineColor as Boolean + 'dim underlinePattern as integer + 'dim underlineByWord as Boolean //Mask = 32768, i.e. &h8000 + 'dim StyleValue as integer + ' + 'for j = 1 to t.Count - 1 + 'select case Vartype( t(j)) + 'case Variant.TypeString + 'select case t(j) + 'case "single" + 'underlineStyle = 1 + 'case "thick" + 'underlineStyle = 2 + 'case "double" + 'underlineStyle = 9 + 'case "solid" + 'underlinePattern = 0 + 'case "dash" + 'underlinePattern = &h200 + 'case "dashdot" + 'underlinePattern = &h300 + 'case "dashdotdot" + 'underlinePattern = &h400 + 'case "dot" + 'underlinePattern = &h100 + 'case "byword" + 'underlineByWord = true + 'end select + ' + 'case Variant.TypeColor + 'underlineColor = t(j) + 'hasUnderlineColor = true + 'else + ' + 'end select + 'next + ' + 'StyleValue = underlineStyle OR underlinePattern + 'if underlineByWord then + 'StyleValue = StyleValue OR &h8000 + 'end if + 'if t(0)="underline" then + 'nsdict.Value( Cocoa.StringConstant( "NSUnderlineStyleAttributeName" )) = new NSNumber( StyleValue ) + 'else + 'nsdict.Value( Cocoa.StringConstant( "NSStrikethroughStyleAttributeName" )) = new NSNumber( StyleValue ) + 'end if + ' + 'if hasUnderlineColor then + 'if t(0)="underline" then + 'nsdict.Value( Cocoa.StringConstant( "NSUnderlineColorAttributeName" )) = new NSColor( underlineColor ) + 'else + 'nsdict.Value( Cocoa.StringConstant( "NSStrikethroughColorAttributeName" )) = new NSColor( underlineColor ) + 'end if + 'end if + ' + 'case "link" + 'nsdict.Value( Cocoa.StringConstant( "NSLinkAttributeName" )) = NSString( t(1)) + ' + 'case "tooltip" + 'nsdict.Value( Cocoa.StringConstant( "NSToolTipAttributeName" )) = NSString( t(1)) + ' + 'case "spacing" + ' + 'else + ' + 'end select + ' + 'next + ' + 'nsdict.Value( Cocoa.StringConstant( "NSParagraphStyleAttributeName" )) = NSParagraphStyle.Default + ' + result = NSAttributedString.CreateFromString_WithAttributes( text, nsdict ) + if nsdict.HasKey( NSString( "macoslibSuperScript" )) OR nsdict.HasKey( NSString( "macoslibSubScript" )) then + dim nsmas as NSMutableAttributedString = new NSMutableAttributedString( result.MutableCopy, true ) + if nsdict.HasKey( NSString( "macoslibSuperScript" )) then + nsmas.Superscript() + else //Cannot be both true + nsmas.Subscript() + end if + + result = nsmas + end if + + DReport result + + return result + End Function + #tag EndMethod + #tag Method, Flags = &h0 Function StringValue() As string #if TargetMacOS @@ -160,6 +324,154 @@ Inherits NSObject End Function #tag EndMethod + #tag Method, Flags = &h0 + Shared Function StyleDictionaryFromTuples(baseStyles as NSDictionary = nil, paramarray styles() as Tuple) As NSMutableDictionary + + Return StyleDictionaryFromTuples( styles, baseStyles ) + End Function + #tag EndMethod + + #tag Method, Flags = &h0 + Shared Function StyleDictionaryFromTuples(styles() as Tuple, baseStyles as NSDictionary = nil) As NSMutableDictionary + dim t as Tuple + dim j as integer + dim nsps as NSParagraphStyle + dim nsdict as NSMutableDictionary + + if baseStyles<>nil then + nsdict = new NSMutableDictionary( baseStyles.MutableCopy, true ) + else + nsdict = new NSMutableDictionary + end if + + for i as integer=0 to styles.Ubound + t = styles( i ) + + select case t(0) + case "font" + dim fontfamily as string + dim isBold as Boolean + dim isItalic as Boolean + dim textColor as color = &c000000 + dim size as double = 12.0 + dim nsf as NSFont + dim IsSuperScript as Boolean + dim IsSubscript as Boolean + + for j = 1 to t.Count - 1 + select case Vartype( t(j)) + case Variant.TypeString + select case t(j) + case "bold" + isBold = true + case "italic" + isItalic = true + case "sup", "super", "superscript" + IsSuperScript = true + case "sub", "subscript" + IsSubscript = true + else + fontfamily = t(j) + end select + case Variant.TypeInteger, Variant.TypeDouble + size = t(j) + case Variant.TypeColor + textColor = t(j) + else + + end select + next + + nsf = NSFontManager.SharedManager.GetFont( fontfamily, size, isBold, isItalic ) + nsdict.Value( Cocoa.StringConstant( "NSFontAttributeName" )) = nsf + nsdict.Value( Cocoa.StringConstant( "NSForegroundColorAttributeName" )) = new NSColor( textColor ) + + if IsSuperscript then + nsdict.Value( "macoslibSuperScript" ) = new NSNumber( true ) + else //Cannot be both true + nsdict.Value( "macoslibSubScript" ) = new NSNumber( true ) + end if + + case "underline", "strikethrough" + dim underlineStyle as integer + dim underlineColor as Color + dim hasUnderlineColor as Boolean + dim underlinePattern as integer + dim underlineByWord as Boolean //Mask = 32768, i.e. &h8000 + dim StyleValue as integer + + for j = 1 to t.Count - 1 + select case Vartype( t(j)) + case Variant.TypeString + select case t(j) + case "single" + underlineStyle = 1 + case "thick" + underlineStyle = 2 + case "double" + underlineStyle = 9 + case "solid" + underlinePattern = 0 + case "dash" + underlinePattern = &h200 + case "dashdot" + underlinePattern = &h300 + case "dashdotdot" + underlinePattern = &h400 + case "dot" + underlinePattern = &h100 + case "byword" + underlineByWord = true + end select + + case Variant.TypeColor + underlineColor = t(j) + hasUnderlineColor = true + else + + end select + next + + StyleValue = underlineStyle OR underlinePattern + if underlineByWord then + StyleValue = StyleValue OR &h8000 + end if + if t(0)="underline" then + nsdict.Value( Cocoa.StringConstant( "NSUnderlineStyleAttributeName" )) = new NSNumber( StyleValue ) + else + nsdict.Value( Cocoa.StringConstant( "NSStrikethroughStyleAttributeName" )) = new NSNumber( StyleValue ) + end if + + if hasUnderlineColor then + if t(0)="underline" then + nsdict.Value( Cocoa.StringConstant( "NSUnderlineColorAttributeName" )) = new NSColor( underlineColor ) + else + nsdict.Value( Cocoa.StringConstant( "NSStrikethroughColorAttributeName" )) = new NSColor( underlineColor ) + end if + end if + + case "link" + nsdict.Value( Cocoa.StringConstant( "NSLinkAttributeName" )) = NSString( t(1)) + + case "tooltip" + nsdict.Value( Cocoa.StringConstant( "NSToolTipAttributeName" )) = NSString( t(1)) + + case "spacing" + + else + + end select + + next + + nsdict.Value( Cocoa.StringConstant( "NSParagraphStyleAttributeName" )) = NSParagraphStyle.Default + + DReport nsdict + + return nsdict + End Function + #tag EndMethod + #tag Constant, Name = kAttributeBold, Type = String, Dynamic = False, Default = \"macoslib_Bold", Scope = Public #tag EndConstant diff --git a/macoslib/Cocoa/NSDictionary.rbbas b/macoslib/Cocoa/NSDictionary.rbbas index 9bdcf6a0..cf887d7b 100644 --- a/macoslib/Cocoa/NSDictionary.rbbas +++ b/macoslib/Cocoa/NSDictionary.rbbas @@ -40,6 +40,19 @@ Inherits NSObject End Sub #tag EndMethod + #tag Method, Flags = &h1000 + Sub Constructor(id as Ptr, hasOwnership as boolean = false) + // Calling the overridden superclass constructor. + // Note that this may need modifications if there are multiple constructor choices. + // Possible constructor calls: + // Constructor() -- From NSObject + // Constructor(obj_id as Ptr, hasOwnership as Boolean = false) -- From NSObject + + Super.Constructor( id, hasOwnership, "NSDictionary" ) + + End Sub + #tag EndMethod + #tag Method, Flags = &h0 Function Copy() As NSDictionary #if TargetMacOS @@ -112,13 +125,21 @@ Inherits NSObject #tag EndMethod #tag Method, Flags = &h0 - Function Value(key as NSObject) As Variant + Function Value(key as variant) As Variant //# Get a value corresponding to a key #if TargetMacOS Declare function objectForKey lib CocoaLib selector "objectForKey:" ( id as Ptr, key as Ptr ) as Ptr - dim p as Ptr = objectForKey( me.id, key.id ) + dim trueKey as NSObject + + if key isa NSObject then + trueKey = Key + else + trueKey = Cocoa.NSObjectFromVariant( key ) + end if + + dim p as Ptr = objectForKey( me.id, truekey.id ) if p=nil then return nil diff --git a/macoslib/Cocoa/NSMutableAttributedString.rbbas b/macoslib/Cocoa/NSMutableAttributedString.rbbas index faf174e8..f4f6603c 100644 --- a/macoslib/Cocoa/NSMutableAttributedString.rbbas +++ b/macoslib/Cocoa/NSMutableAttributedString.rbbas @@ -2,26 +2,41 @@ Class NSMutableAttributedString Inherits NSAttributedString #tag Method, Flags = &h0 - Function AddAttribute(attributeName as string, value as variant, forRange as NSRange) As boolean + Function AddAttribute(attributeName as string, value as variant, optional forRange as NSRange) As boolean + + //@ Simple values like string, numbers, colors can be set in 'value', otherwise, only NSObjects can be used. #if TargetMacOS declare sub addAttribute lib CocoaLib selector "addAttribute:value:range:" (id as Ptr, name as CFStringRef, value as Ptr, aRange as NSRange) 'dim mgr as NSFontManager = NSFontManager.SharedManager dim nsf as NSFont - dim range as NSRange + dim range, realrange as NSRange + dim realvalue as NSObject + + 'if NOT value isa NSObject then + 'raise new MacOSError( -50, "Invalid value. Must be a subclass of NSObject." ) + 'end if + + if forRange.length=0 then + realrange = Cocoa.NSMakeRange( 0, me.Length ) + else + realrange = forRange + end if - if NOT value isa NSObject then - raise new MacOSError( -50, "Invalid value. Must be a subclass of NSObject." ) + if NOT value IsA NSObject then + realvalue = Cocoa.NSObjectFromVariant( value ) + else + realvalue = value end if if attributeName.Left( 2 )="NS" AND attributeName.Right( 13 )="AttributeName" then //Cocoa constant - addAttribute( me.id, Cocoa.StringConstant( attributeName ), NSObject( value ).id, forRange ) + addAttribute( me.id, Cocoa.StringConstant( attributeName ), realvalue.id, realrange ) else select case attributeName //Add some convenience methods case me.kAttributeBold //Bold - nsf = me.AttributeAtIndex( "NSFontAttributeName", forRange.location, range ) + nsf = me.AttributeAtIndex( "NSFontAttributeName", realrange.location, range ) if nsf=nil then return false end if @@ -29,10 +44,10 @@ Inherits NSAttributedString if nsf=nil then return false end if - addAttribute( me.id, Cocoa.StringConstant( "NSFontAttributeName" ), nsf.id, forRange ) + addAttribute( me.id, Cocoa.StringConstant( "NSFontAttributeName" ), nsf.id, realrange ) case me.kAttributeItalic //Italic - nsf = me.AttributeAtIndex( "NSFontAttributeName", forRange.location, range ) + nsf = me.AttributeAtIndex( "NSFontAttributeName", realrange.location, range ) if nsf=nil then return false end if @@ -40,10 +55,10 @@ Inherits NSAttributedString if nsf=nil then return false end if - addAttribute( me.id, Cocoa.StringConstant( "NSFontAttributeName" ), nsf.id, forRange ) + addAttribute( me.id, Cocoa.StringConstant( "NSFontAttributeName" ), nsf.id, realrange ) else //Other attribute - addAttribute( me.id, attributeName, NSObject( value ).id, forRange ) + addAttribute( me.id, attributeName, realvalue.id, realrange ) end select end if @@ -89,6 +104,81 @@ Inherits NSAttributedString End Sub #tag EndMethod + #tag Method, Flags = &h0 + Sub BeginEditing() + #if TargetMacOS + declare sub beginEditing lib CocoaLib selector "beginEditing" (id as Ptr) + + if IsEditing then RETURN + + beginEditing me.id + IsEditing_ = true + #endif + End Sub + #tag EndMethod + + #tag Method, Flags = &h1000 + Sub Constructor() + // Calling the overridden superclass constructor. + // Note that this may need modifications if there are multiple constructor choices. + // Possible constructor calls: + // Constructor() -- From NSObject + // Constructor(obj_id as Ptr, hasOwnership as Boolean = false) -- From NSObject + + Super.Constructor( Initialize( Allocate( "NSMutableAttributedString" )), true ) + + End Sub + #tag EndMethod + + #tag Method, Flags = &h1000 + Sub Constructor(id as Ptr, hasOwnership as boolean = false) + // Calling the overridden superclass constructor. + // Note that this may need modifications if there are multiple constructor choices. + // Possible constructor calls: + // Constructor() -- From NSObject + // Constructor(obj_id as Ptr, hasOwnership as Boolean = false) -- From NSObject + + Super.Constructor( id, hasOwnership, "NSMutableAttributedString" ) + + End Sub + #tag EndMethod + + #tag Method, Flags = &h0 + Sub EndEditing() + #if TargetMacOS + declare sub endEditing lib CocoaLib selector "endEditing" (id as Ptr) + + endEditing me.id + IsEditing_ = false + #endif + End Sub + #tag EndMethod + + #tag Method, Flags = &h0 + Sub FixAttributes(optional inRange as NSRange) + + #if TargetMacOS + declare sub fixAttributesInRange lib CocoaLib selector "fixAttributesInRange:" (id as Ptr, aRange as NSRange) + + dim realRange as NSRange + if inRange.length=0 then //Use full string + realRange = Cocoa.NSMakeRange( 0, me.Length ) + else + realRange = inRange + end if + + if IsEditing then + fixAttributesInRange( me.id, realRange ) + else + BeginEditing + fixAttributesInRange( me.id, realRange ) + EndEditing + end if + + #endif + End Sub + #tag EndMethod + #tag Method, Flags = &h0 Function MutableString() As NSMutableString @@ -182,6 +272,101 @@ Inherits NSAttributedString End Function #tag EndMethod + #tag Method, Flags = &h0 + Sub Subscript(optional inRange as NSRange) + + #if TargetMacOS + declare sub subscriptRange lib CocoaLib selector "subscriptRange:" (id as Ptr, aRange as NSRange) + + dim realRange as NSRange + if inRange.length=0 then //Use full string + realRange = Cocoa.NSMakeRange( 0, me.Length ) + else + realRange = inRange + end if + + if IsEditing then + subscriptRange( me.id, realRange ) + FixAttributes realRange + else + BeginEditing + subscriptRange( me.id, realRange ) + FixAttributes realRange + EndEditing + end if + + #endif + End Sub + #tag EndMethod + + #tag Method, Flags = &h0 + Sub Superscript(optional inRange as NSRange) + + #if TargetMacOS + declare sub superscriptRange lib CocoaLib selector "superscriptRange:" (id as Ptr, aRange as NSRange) + + dim realRange as NSRange + if inRange.length=0 then //Use full string + realRange = Cocoa.NSMakeRange( 0, me.Length ) + else + realRange = inRange + end if + + if IsEditing then + superscriptRange( me.id, realRange ) + FixAttributes realRange + else + BeginEditing + superscriptRange( me.id, realRange ) + FixAttributes realRange + EndEditing + end if + + #endif + End Sub + #tag EndMethod + + #tag Method, Flags = &h0 + Sub Unscript(optional inRange as NSRange) + + #if TargetMacOS + declare sub unscriptRange lib CocoaLib selector "unscriptRange:" (id as Ptr, aRange as NSRange) + + dim realRange as NSRange + if inRange.length=0 then //Use full string + realRange = Cocoa.NSMakeRange( 0, me.Length ) + else + realRange = inRange + end if + + if IsEditing then + unscriptRange( me.id, realRange ) + FixAttributes realRange + else + BeginEditing + unscriptRange( me.id, realRange ) + FixAttributes realRange + EndEditing + end if + + #endif + End Sub + #tag EndMethod + + + #tag ComputedProperty, Flags = &h0 + #tag Getter + Get + return IsEditing_ + End Get + #tag EndGetter + IsEditing As Boolean + #tag EndComputedProperty + + #tag Property, Flags = &h21 + Private IsEditing_ As Boolean + #tag EndProperty + #tag ViewBehavior #tag ViewProperty @@ -198,6 +383,11 @@ Inherits NSAttributedString InitialValue="-2147483648" InheritedFrom="Object" #tag EndViewProperty + #tag ViewProperty + Name="IsEditing" + Group="Behavior" + Type="Boolean" + #tag EndViewProperty #tag ViewProperty Name="Left" Visible=true diff --git a/macoslib/Cocoa/NSMutableDictionary.rbbas b/macoslib/Cocoa/NSMutableDictionary.rbbas index 03d47620..d555a945 100644 --- a/macoslib/Cocoa/NSMutableDictionary.rbbas +++ b/macoslib/Cocoa/NSMutableDictionary.rbbas @@ -47,12 +47,20 @@ Inherits NSDictionary #tag EndMethod #tag Method, Flags = &h0 - Sub Value(key as NSObject, assigns newValue as NSObject) + Sub Value(key as variant, assigns newValue as NSObject) #if TargetMacOS declare sub setObject lib Cocoalib selector "setObject:forKey:" ( id as Ptr, key as Ptr, value as Ptr ) - setObject( me.id, newValue.id, key.id ) + dim truekey as NSObject + + if key IsA NSObject then + truekey = key + else + truekey = Cocoa.NSObjectFromVariant( key ) + end if + + setObject( me.id, newValue.id, truekey.id ) #endif End Sub #tag EndMethod diff --git a/macoslib/Cocoa/NSObject.rbbas b/macoslib/Cocoa/NSObject.rbbas index 5d4ee387..765c59dd 100644 --- a/macoslib/Cocoa/NSObject.rbbas +++ b/macoslib/Cocoa/NSObject.rbbas @@ -49,7 +49,14 @@ Implements objHasVariantValue #tag EndMethod #tag Method, Flags = &h0 - Sub Constructor(obj_id as Ptr, hasOwnership as Boolean = false) + Sub Constructor(obj_id as Ptr, hasOwnership as Boolean = false, checkForClass as string = "") + + if checkForClass<>"" then + if NOT Cocoa.InheritsFromClass( obj_id, checkForClass ) then + raise new macoslibException( "The passed pointer does not match the wanted class """ + checkForClass + """" ) + end if + end if + self._id = obj_id if not hasOwnership then @@ -60,6 +67,8 @@ Implements objHasVariantValue #tag Method, Flags = &h0 Function Copy_() As Ptr + //# Returns an immutable copy of the object + #if TargetMacOS declare function Copy lib Cocoalib selector "copy" (id as Ptr) as Ptr diff --git a/macoslib/Cocoa/NSParagraphStyle.rbbas b/macoslib/Cocoa/NSParagraphStyle.rbbas index b5f2b9de..cddb0652 100644 --- a/macoslib/Cocoa/NSParagraphStyle.rbbas +++ b/macoslib/Cocoa/NSParagraphStyle.rbbas @@ -1,6 +1,35 @@ #tag Class Class NSParagraphStyle Inherits NSObject + #tag Method, Flags = &h1000 + Sub Constructor(id as Ptr, hasOwnership as boolean = false) + // Calling the overridden superclass constructor. + // Note that this may need modifications if there are multiple constructor choices. + // Possible constructor calls: + // Constructor() -- From NSObject + // Constructor(obj_id as Ptr, hasOwnership as Boolean = false, checkForClass as string = "") -- From NSObject + + Super.Constructor( id, hasOwnership, "NSParagraphStyle" ) + + End Sub + #tag EndMethod + + #tag Method, Flags = &h0 + Shared Function Default() As NSParagraphStyle + //# Returns the default paragraph style + + #if TargetMacOS + declare function defaultParagraphStyle lib CocoaLib selector "defaultParagraphStyle" (Cls as Ptr) as Ptr + + dim p as Ptr + p = defaultParagraphStyle( Cocoa.NSClassFromString( "NSParagraphStyle" )) + if p<>nil then + return new NSParagraphStyle( p, false ) + end if + #endif + End Function + #tag EndMethod + #tag Method, Flags = &h0 Function LineBreakMode() As integer diff --git a/macoslib/Cocoa/NSSpeechSynthesizer.rbbas b/macoslib/Cocoa/NSSpeechSynthesizer.rbbas index 62520dc0..f2622ac2 100644 --- a/macoslib/Cocoa/NSSpeechSynthesizer.rbbas +++ b/macoslib/Cocoa/NSSpeechSynthesizer.rbbas @@ -45,7 +45,7 @@ Inherits NSObject #if TargetMacOS declare function initWithVoice lib CocoaLib selector "initWithVoice:" (id as Ptr, p as Ptr) as Ptr - Super.Constructor( initWithVoice( Allocate( "NSSpeechSynthesizer" ), nil ), false ) + Super.Constructor( initWithVoice( Allocate( "NSSpeechSynthesizer" ), nil ), true ) me.SetDelegate #endif End Sub @@ -190,6 +190,18 @@ Inherits NSObject End Sub #tag EndMethod + #tag Method, Flags = &h0 + Sub Destructor() + + DReportTitled "NSSpeechSynthesizer:", "Destructor called" + + declare sub setDelegate lib CocoaLib selector "setDelegate:" (obj_id as Ptr, del_id as Ptr) + declare sub release lib CocoaLib + setDelegate me.id, nil + self.Release + End Sub + #tag EndMethod + #tag Method, Flags = &h21 Private Shared Function FindObjectByID(id as Ptr) As NSSearchField dim w as WeakRef = CocoaDelegateMap.Lookup(id, new WeakRef(nil)) @@ -306,7 +318,6 @@ Inherits NSObject dim newClassId as Ptr = objc_allocateClassPair(Cocoa.NSClassFromString(superclassName), className, 0) if newClassId = nil then raise new macoslibException( "Unable to create ObjC subclass " + className + " from " + superclassName ) //perhaps the class already exists. We could check for this, and raise an exception for other errors. - raise new ObjCException return nil end if diff --git a/macoslib/Cocoa/NSTextField.rbbas b/macoslib/Cocoa/NSTextField.rbbas index f68773b2..7e87bfc3 100644 --- a/macoslib/Cocoa/NSTextField.rbbas +++ b/macoslib/Cocoa/NSTextField.rbbas @@ -10,6 +10,19 @@ Inherits NSObject End Sub #tag EndMethod + #tag Method, Flags = &h1000 + Sub Constructor(id as Ptr, hasOwnership as boolean = false) + // Calling the overridden superclass constructor. + // Note that this may need modifications if there are multiple constructor choices. + // Possible constructor calls: + // Constructor() -- From NSObject + // Constructor(obj_id as Ptr, hasOwnership as Boolean = false, checkForClass as string = "") -- From NSObject + + Super.Constructor( id, hasOwnership, "NSTextField" ) + + End Sub + #tag EndMethod + #tag Method, Flags = &h1000 Sub Constructor(fromObject as TextField) @@ -148,6 +161,11 @@ Inherits NSObject Group="Behavior" Type="Boolean" #tag EndViewProperty + #tag ViewProperty + Name="EditableAttributes" + Group="Behavior" + Type="Boolean" + #tag EndViewProperty #tag ViewProperty Name="Index" Visible=true @@ -173,11 +191,6 @@ Inherits NSObject Group="Behavior" Type="Boolean" #tag EndViewProperty - #tag ViewProperty - Name="Styled" - Group="Behavior" - Type="Boolean" - #tag EndViewProperty #tag ViewProperty Name="Super" Visible=true diff --git a/macoslib/Cocoa/NSTextView.rbbas b/macoslib/Cocoa/NSTextView.rbbas index e0ef0802..01e2d988 100644 --- a/macoslib/Cocoa/NSTextView.rbbas +++ b/macoslib/Cocoa/NSTextView.rbbas @@ -1,6 +1,20 @@ #tag Class Class NSTextView Inherits NSText + #tag Method, Flags = &h1000 + Sub Constructor(id as Ptr, hasOwnership as boolean = false) + // Calling the overridden superclass constructor. + // Note that this may need modifications if there are multiple constructor choices. + // Possible constructor calls: + // Constructor() -- From NSObject + // Constructor(obj_id as Ptr, hasOwnership as Boolean = false, checkForClass as string = "") -- From NSObject + + Super.Constructor( id, hasOwnership, "NSTextView" ) + + End Sub + #tag EndMethod + + #tag ComputedProperty, Flags = &h0 #tag Getter Get diff --git a/macoslib/Convenience extensions and objects/AttributedStringExtensions/AttributedString.rbbas b/macoslib/Convenience extensions and objects/AttributedStringExtensions/AttributedString.rbbas index 9a2eda84..6520e3bb 100644 --- a/macoslib/Convenience extensions and objects/AttributedStringExtensions/AttributedString.rbbas +++ b/macoslib/Convenience extensions and objects/AttributedStringExtensions/AttributedString.rbbas @@ -7,7 +7,7 @@ Inherits NSAttributedString #if TargetMacOS if Cocoa.InheritsFromClass( fromNSAttributedString, "NSMutableAttributedString" ) then - Mutable = true + _Mutable = true end if me._id = fromNSAttributedString.id @@ -54,7 +54,7 @@ Inherits NSAttributedString #tag EndMethod #tag Method, Flags = &h0 - Function Mid(startPosition as integer, length as integer = -1) As AttributedString + Function Mid(startPosition as integer, length as integer = - 1) As AttributedString //# Return the attributed substring in the given range //@ The startPosition must be in the range 1 to Length() @@ -122,9 +122,14 @@ Inherits NSAttributedString Handle As integer #tag EndComputedProperty - #tag Property, Flags = &h21 - Private Mutable As Boolean - #tag EndProperty + #tag ComputedProperty, Flags = &h0 + #tag Getter + Get + return _Mutable + End Get + #tag EndGetter + Mutable As Boolean + #tag EndComputedProperty #tag Property, Flags = &h0 NSbacking As NSAttributedString @@ -178,6 +183,10 @@ Inherits NSAttributedString Private SelStart As Integer #tag EndComputedProperty + #tag Property, Flags = &h21 + Private _Mutable As Boolean + #tag EndProperty + #tag ViewBehavior #tag ViewProperty diff --git a/macoslib/Convenience extensions and objects/MacOSFolderItemExtension.rbbas b/macoslib/Convenience extensions and objects/MacOSFolderItemExtension.rbbas index 80a3aed0..37bc11bf 100644 --- a/macoslib/Convenience extensions and objects/MacOSFolderItemExtension.rbbas +++ b/macoslib/Convenience extensions and objects/MacOSFolderItemExtension.rbbas @@ -928,6 +928,17 @@ Protected Module MacOSFolderItemExtension End Function #tag EndMethod + #tag Method, Flags = &h0 + Function SpotlightMetadata(extends f as FolderItem) As Dictionary + //# Returns a Dictionary containing all the Spotlight metadata + + #if TargetMacOS + dim mdi as MDItem = MDItem.CreateFromFile( f ) + return mdi.AllAttributes + #endif + End Function + #tag EndMethod + #tag Method, Flags = &h0 Function UniformTypeIdentifier(extends f as FolderItem) As String //# Get the Uniform Type Identifier of the given FolderItem diff --git a/macoslib/Convenience extensions and objects/MacSpeechSynthesizer.rbbas b/macoslib/Convenience extensions and objects/MacSpeechSynthesizer.rbbas index 1f2a7878..d7de2a3e 100644 --- a/macoslib/Convenience extensions and objects/MacSpeechSynthesizer.rbbas +++ b/macoslib/Convenience extensions and objects/MacSpeechSynthesizer.rbbas @@ -31,11 +31,11 @@ Protected Class MacSpeechSynthesizer _synth = new NSSpeechSynthesizer //Redirect events - AddHandler synth.FinishedSpeaking, AddressOf HandleDidFinishSpeaking - AddHandler synth.SpeechError, AddressOf HandleSpeechError - AddHandler synth.SyncMessage, AddressOf HandleSyncMessage - AddHandler synth.WillSpeakPhoneme, AddressOf HandleWillSpeakPhoneme - AddHandler synth.WillSpeakWord, AddressOf HandleWillSpeakWord + AddHandler synth.FinishedSpeaking, WeakAddressOf HandleDidFinishSpeaking + AddHandler synth.SpeechError, WeakAddressOf HandleSpeechError + AddHandler synth.SyncMessage, WeakAddressOf HandleSyncMessage + AddHandler synth.WillSpeakPhoneme, WeakAddressOf HandleWillSpeakPhoneme + AddHandler synth.WillSpeakWord, WeakAddressOf HandleWillSpeakWord End Sub #tag EndMethod @@ -57,6 +57,22 @@ Protected Class MacSpeechSynthesizer End Function #tag EndMethod + #tag Method, Flags = &h0 + Sub Destructor() + DReportTitled "MacSpeechSynthesizer:", "Destructor called" + + if synth<>nil then + RemoveHandler synth.FinishedSpeaking, AddressOf HandleDidFinishSpeaking + RemoveHandler synth.SpeechError, AddressOf HandleSpeechError + RemoveHandler synth.SyncMessage, AddressOf HandleSyncMessage + RemoveHandler synth.WillSpeakPhoneme, AddressOf HandleWillSpeakPhoneme + RemoveHandler synth.WillSpeakWord, AddressOf HandleWillSpeakWord + + _synth = nil + end if + End Sub + #tag EndMethod + #tag Method, Flags = &h21 Private Sub HandleDidFinishSpeaking(sender as NSSpeechSynthesizer, success as Boolean) #pragma unused success diff --git a/macoslib/DebugReport Cross-Platform/DebugLogWND.rbfrm b/macoslib/DebugReport Cross-Platform/DebugLogWND.rbfrm index 9d79c93b..5949e347 100644 --- a/macoslib/DebugReport Cross-Platform/DebugLogWND.rbfrm +++ b/macoslib/DebugReport Cross-Platform/DebugLogWND.rbfrm @@ -385,7 +385,7 @@ Begin Window DebugLogWND Width = 26 End Begin PopupArrow PopupArrow1 - AutoDeactivate = True + AutoDeactivate = False Enabled = True Facing = 3 Height = 10 @@ -468,6 +468,7 @@ End Sub Open() #if DebugReportOptions.AllowDebugReport AND NOT (DebugReportOptions.AutomaticallyDisableInFinalBuilds AND NOT DebugBuild) + //Position window. Check for prefs file if DebugReportModule.Prefs<>nil then @@ -563,11 +564,14 @@ End dim base as new MenuItem( "MENU" ) dim mi as MenuItem + dim obj as Object base.Append new Menuitem( "Copy", "_COPY_" ) base.Append new Menuitem( "Clear", "_CLEAR_" ) base.Append new Menuitem( "-" ) base.Append new Menuitem( "Save log to Desktop", "_SAVE_" ) + base.Append new Menuitem( "-" ) + base.Append new MenuItem( "List objects in memory", "_OBJECTS_" ) mi = base.PopUp if mi is nil then return false // Added by Kem Tekinay. Prevents crash if the user doesn't select anything @@ -586,6 +590,27 @@ End beep 'dim f as FolderItem 'f = SpecialFolder.Desktop.Child( "Debug Log " + Date( new date).AbbreviatedDate + + case "_OBJECTS_" + 'dim iterator as Runtime.ObjectIterator = Runtime.IterateObjects + dim imax as integer = Runtime.ObjectCount - 1 + + DReportTitled "Objects in memory" + + for i as integer=0 to imax + dim s as string = Runtime.ObjectClass( i ) + + if s.Instr( "MenuItem" )=0 then + QReport s + end if + next + 'while iterator.MoveNext + 'obj = iterator.Current + 'if NOT obj isa MenuItem then + 'QReport Introspection.GetType( obj ).Name + 'end if + 'wend + end select End Function #tag EndEvent diff --git a/macoslib/Spotlight/MDItem.rbbas b/macoslib/Spotlight/MDItem.rbbas index 23abee42..ef505e4a 100644 --- a/macoslib/Spotlight/MDItem.rbbas +++ b/macoslib/Spotlight/MDItem.rbbas @@ -8,6 +8,23 @@ Inherits CFType #tag EndEvent + #tag Method, Flags = &h0 + Function AllAttributes() As Dictionary + #if TargetMacOS + declare function MDItemCopyAttributeNames lib CarbonLib (item as Ptr) as Ptr + declare function MDItemCopyAttributes lib CarbonLib (item as Ptr, names as Ptr) as Ptr + + dim cfa as CFArray + dim cfdict as CFDictionary + cfa = new CFArray( MDItemCopyAttributeNames( me.Reference ), true ) + cfdict = new CFDictionary( MDItemCopyAttributes ( me.Reference, cfa.Reference ), true ) + + return cfDict.AsDictionary + #endif + + End Function + #tag EndMethod + #tag Method, Flags = &h0 Function Attribute(key as String) As CFType #if targetMacOS @@ -55,6 +72,20 @@ Inherits CFType End Function #tag EndMethod + #tag Method, Flags = &h0 + Shared Function CreateFromFile(file as FolderItem) As MDItem + //# Creates a MDItem for a given file + + #if TargetMacOS + declare function MDItemCreateWithURL lib CarbonLib (alloc as Ptr, url as Ptr) as Ptr + + dim url as CFURL = new CFURL( file ) + + return new MDItem( MDItemCreateWithURL( nil, url ), false ) + #endif + End Function + #tag EndMethod + #tag ViewBehavior #tag ViewProperty