[Libreoffice-commits] core.git: vcl/aqua vcl/inc
Boris Dušek
me at dusek.me
Mon Aug 12 00:57:30 PDT 2013
vcl/aqua/source/a11y/aqua11ytextattributeswrapper.mm | 112 +++++++++++++------
vcl/aqua/source/a11y/aqua11ywrapper.mm | 33 -----
vcl/inc/aqua/aqua11ywrapper.h | 9 -
3 files changed, 82 insertions(+), 72 deletions(-)
New commits:
commit fb6edeb20de56359be3d45316a2d665ad8d424a2
Author: Boris Dušek <me at dusek.me>
Date: Sun Aug 11 15:02:04 2013 +0200
Refactoring: remove 3 unneeded ivars
The default font size, font name and font traits were stored as ivars
of AquaA11yWrapper, but they are in fact only needed as temporary state
for the createAttributedStringForElement:inOrigRange: method of
AquaA11yTextAttributesWrapper. So remove these 3 ivars and instead
introduce a class that holds these 3 properties and make
createAttributedStringForElement:inOrigRange: use instance of this
class to hold the needed state instead.
I checked that the default font size, font name and font traits ivars
are really only used in AquaA11yTextAttributesWrapper at that one place.
Change-Id: Id2e45977c394db116f3fb0636136300c23e71f25
Reviewed-on: https://gerrit.libreoffice.org/5346
Reviewed-by: Tor Lillqvist <tml at iki.fi>
Tested-by: Tor Lillqvist <tml at iki.fi>
diff --git a/vcl/aqua/source/a11y/aqua11ytextattributeswrapper.mm b/vcl/aqua/source/a11y/aqua11ytextattributeswrapper.mm
index e8a676e..d95f999 100644
--- a/vcl/aqua/source/a11y/aqua11ytextattributeswrapper.mm
+++ b/vcl/aqua/source/a11y/aqua11ytextattributeswrapper.mm
@@ -36,6 +36,72 @@ using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
using namespace ::rtl;
+// cannot use NSFontDescriptor as it has no notion of explicit NSUn{bold,italic}FontMask
+ at interface AquaA11yFontDescriptor : NSObject
+{
+ NSString *_name;
+ NSFontTraitMask _traits;
+ CGFloat _size;
+}
+-(void)setName:(NSString*)name;
+-(void)setBold:(NSFontTraitMask)bold;
+-(void)setItalic:(NSFontTraitMask)italic;
+-(void)setSize:(CGFloat)size;
+-(NSFont*)font;
+ at end
+
+ at implementation AquaA11yFontDescriptor
+- (id)init
+{
+ if((self = [super init]))
+ {
+ _name = nil;
+ _traits = 0;
+ _size = 0.0;
+ }
+ return self;
+}
+
+- (id)initWithDescriptor:(AquaA11yFontDescriptor*)descriptor {
+ if((self = [super init]))
+ {
+ _name = [descriptor->_name retain];
+ _traits = descriptor->_traits;
+ _size = descriptor->_size;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [_name release];
+ [super dealloc];
+}
+
+-(void)setName:(NSString*)name {
+ if (_name != name) {
+ [name retain];
+ [_name release];
+ _name = name;
+ }
+}
+
+-(void)setBold:(NSFontTraitMask)bold {
+ _traits &= ~(NSBoldFontMask | NSUnboldFontMask);
+ _traits |= bold & (NSBoldFontMask | NSUnboldFontMask);
+};
+
+-(void)setItalic:(NSFontTraitMask)italic {
+ _traits &= ~(NSItalicFontMask | NSUnitalicFontMask);
+ _traits |= italic & (NSItalicFontMask | NSUnitalicFontMask);
+};
+
+-(void)setSize:(CGFloat)size { _size = size; }
+
+-(NSFont*)font {
+ return [[NSFontManager sharedFontManager] fontWithFamily:_name traits:_traits weight:0 size:_size];
+}
+ at end
+
@implementation AquaA11yTextAttributesWrapper : NSObject
+(int)convertUnderlineStyle:(PropertyValue)property {
@@ -123,7 +189,7 @@ using namespace ::rtl;
}
}
-+(void)applyAttributesFrom:(Sequence < PropertyValue >)attributes toString:(NSMutableAttributedString *)string forRange:(NSRange)range storeDefaultsTo:(AquaA11yWrapper *)wrapperStore getDefaultsFrom:(AquaA11yWrapper *)wrapper {
++(void)applyAttributesFrom:(Sequence < PropertyValue >)attributes toString:(NSMutableAttributedString *)string forRange:(NSRange)range fontDescriptor:(AquaA11yFontDescriptor*)fontDescriptor {
NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
// constants
static const OUString attrUnderline("CharUnderline");
@@ -139,9 +205,6 @@ using namespace ::rtl;
static const OUString attrBackgroundColor("CharBackColor");
static const OUString attrSuperscript("CharEscapement");
// vars
- OUString fontname;
- int fonttraits = 0;
- float fontsize = 0.0;
sal_Int32 underlineColor = 0;
BOOL underlineHasColor = NO;
// add attributes to string
@@ -156,13 +219,17 @@ using namespace ::rtl;
[ string addAttribute: NSAccessibilityUnderlineTextAttribute value: [ NSNumber numberWithInt: style ] range: range ];
}
} else if ( property.Name.equals ( attrFontname ) ) {
+ OUString fontname;
property.Value >>= fontname;
+ [fontDescriptor setName:CreateNSString(fontname)];
} else if ( property.Name.equals ( attrBold ) ) {
- fonttraits |= [ AquaA11yTextAttributesWrapper convertBoldStyle: property ];
+ [fontDescriptor setBold:[AquaA11yTextAttributesWrapper convertBoldStyle:property]];
} else if ( property.Name.equals ( attrItalic ) ) {
- fonttraits |= [ AquaA11yTextAttributesWrapper convertItalicStyle: property ];
+ [fontDescriptor setItalic:[AquaA11yTextAttributesWrapper convertItalicStyle:property]];
} else if ( property.Name.equals ( attrHeight ) ) {
- property.Value >>= fontsize;
+ float size;
+ property.Value >>= size;
+ [fontDescriptor setSize:size];
} else if ( property.Name.equals ( attrStrikethrough ) ) {
if ( [ AquaA11yTextAttributesWrapper isStrikethrough: property ] ) {
[ string addAttribute: NSAccessibilityStrikethroughTextAttribute value: [ NSNumber numberWithBool: YES ] range: range ];
@@ -195,27 +262,8 @@ using namespace ::rtl;
[ AquaA11yTextAttributesWrapper addColor: underlineColor forAttribute: NSAccessibilityUnderlineColorTextAttribute andRange: range toString: string ];
}
// add font information
- if ( wrapperStore != nil ) { // default
- [ wrapperStore setDefaultFontname: CreateNSString ( fontname ) ];
- [ wrapperStore setDefaultFontsize: fontsize ];
- [ wrapperStore setDefaultFonttraits: fonttraits ];
- NSFont * font = [ [ NSFontManager sharedFontManager ] fontWithFamily: CreateNSString ( fontname ) traits: fonttraits weight: 0 size: fontsize ];
- [ AquaA11yTextAttributesWrapper addFont: font toString: string forRange: range ];
- } else if ( wrapper != nil) { // attribute run and bold and/or italic was found
- NSString *fontName = nil;
- if (fontname.isEmpty())
- fontName = [wrapper defaultFontname];
- else
- fontName = CreateNSString(fontname);
- if (!(fonttraits & (NSBoldFontMask | NSUnboldFontMask)))
- fonttraits |= [wrapper defaultFonttraits] & (NSBoldFontMask | NSUnboldFontMask);
- if (!(fonttraits & (NSItalicFontMask | NSUnitalicFontMask)))
- fonttraits |= [wrapper defaultFonttraits] & (NSItalicFontMask | NSUnitalicFontMask);
- if (fontsize == 0.0)
- fontsize = [wrapper defaultFontsize];
- NSFont * font = [ [ NSFontManager sharedFontManager ] fontWithFamily: fontName traits: fonttraits weight: 0 size: fontsize ];
- [ AquaA11yTextAttributesWrapper addFont: font toString: string forRange: range ];
- }
+ NSFont * font = [fontDescriptor font];
+ [AquaA11yTextAttributesWrapper addFont:font toString:string forRange:range];
[ pool release ];
}
@@ -234,7 +282,8 @@ using namespace ::rtl;
[ string beginEditing ];
// add default attributes for whole string
Sequence < PropertyValue > defaultAttributes = [ wrapper accessibleTextAttributes ] -> getDefaultAttributes ( emptySequence );
- [ AquaA11yTextAttributesWrapper applyAttributesFrom: defaultAttributes toString: string forRange: NSMakeRange ( 0, len ) storeDefaultsTo: wrapper getDefaultsFrom: nil ];
+ AquaA11yFontDescriptor *defaultFontDescriptor = [[AquaA11yFontDescriptor alloc] init];
+ [ AquaA11yTextAttributesWrapper applyAttributesFrom: defaultAttributes toString: string forRange: NSMakeRange ( 0, len ) fontDescriptor: defaultFontDescriptor ];
// add attributes for attribute run(s)
while ( currentIndex < endIndex ) {
TextSegment textSegment = [ wrapper accessibleText ] -> getTextAtIndex ( currentIndex, AccessibleTextType::ATTRIBUTE_RUN );
@@ -242,9 +291,12 @@ using namespace ::rtl;
NSRange rangeForAttributeRun = NSMakeRange ( currentIndex - loc , endOfRange - currentIndex );
// add run attributes
Sequence < PropertyValue > attributes = [ wrapper accessibleTextAttributes ] -> getRunAttributes ( currentIndex, emptySequence );
- [ AquaA11yTextAttributesWrapper applyAttributesFrom: attributes toString: string forRange: rangeForAttributeRun storeDefaultsTo: nil getDefaultsFrom: wrapper ];
+ AquaA11yFontDescriptor *fontDescriptor = [[AquaA11yFontDescriptor alloc] initWithDescriptor:defaultFontDescriptor];
+ [ AquaA11yTextAttributesWrapper applyAttributesFrom: attributes toString: string forRange: rangeForAttributeRun fontDescriptor: fontDescriptor ];
+ [fontDescriptor release];
currentIndex = textSegment.SegmentEnd;
}
+ [defaultFontDescriptor release];
[ string endEditing ];
}
} catch ( IllegalArgumentException & e ) {
diff --git a/vcl/aqua/source/a11y/aqua11ywrapper.mm b/vcl/aqua/source/a11y/aqua11ywrapper.mm
index 375997f..aee6360 100644
--- a/vcl/aqua/source/a11y/aqua11ywrapper.mm
+++ b/vcl/aqua/source/a11y/aqua11ywrapper.mm
@@ -81,9 +81,6 @@ static std::ostream &operator<<(std::ostream &s, NSPoint point) {
}
-(void) setDefaults: (Reference < XAccessibleContext >) rxAccessibleContext {
- mDefaultFontsize = 0.0;
- mDefaultFonttraits = 0;
- mpDefaultFontname = nil;
mpReferenceWrapper = new ReferenceWrapper;
mActsAsRadioGroup = NO;
mpReferenceWrapper -> rAccessibleContext = rxAccessibleContext;
@@ -144,9 +141,6 @@ static std::ostream &operator<<(std::ostream &s, NSPoint point) {
if ( mpReferenceWrapper != nil ) {
delete mpReferenceWrapper;
}
- if ( mpDefaultFontname != nil ) {
- [ mpDefaultFontname release ];
- }
[ super dealloc ];
}
@@ -1127,33 +1121,6 @@ Reference < XAccessibleContext > hitTestRunner ( com::sun::star::awt::Point poin
// attributes have to be bound to a font on the Mac. Our UNO-API instead handles
// and reports them independently. When they occur we bundle them to a font with
// this information here to create a according NSFont.
--(void)setDefaultFontname:(NSString *)fontname {
- if ( mpDefaultFontname != nil ) {
- [ mpDefaultFontname release ];
- }
- mpDefaultFontname = fontname;
-}
-
--(NSString *)defaultFontname {
- return mpDefaultFontname;
-}
-
--(void)setDefaultFontsize:(float)fontsize {
- mDefaultFontsize = fontsize;
-}
-
--(float)defaultFontsize {
- return mDefaultFontsize;
-}
-
--(void)setDefaultFonttraits:(int)fonttraits {
- mDefaultFonttraits = fonttraits;
-}
-
--(int)defaultFonttraits {
- return mDefaultFonttraits;
-}
-
-(void)setActsAsRadioGroup:(BOOL)actsAsRadioGroup {
mActsAsRadioGroup = actsAsRadioGroup;
}
diff --git a/vcl/inc/aqua/aqua11ywrapper.h b/vcl/inc/aqua/aqua11ywrapper.h
index 185536a..83b5a77 100644
--- a/vcl/inc/aqua/aqua11ywrapper.h
+++ b/vcl/inc/aqua/aqua11ywrapper.h
@@ -52,9 +52,6 @@ struct ReferenceWrapper
@interface AquaA11yWrapper : NSView
{
ReferenceWrapper * mpReferenceWrapper;
- NSString * mpDefaultFontname;
- float mDefaultFontsize;
- int mDefaultFonttraits;
BOOL mActsAsRadioGroup;
BOOL mIsTableCell;
}
@@ -91,12 +88,6 @@ struct ReferenceWrapper
-(id)initWithAccessibleContext: (::com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessibleContext >) anAccessibleContext;
-(void) setDefaults: (::com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessibleContext >) rxAccessibleContext;
-(void) dealloc;
--(void)setDefaultFontname:(NSString *)fontname;
--(NSString *)defaultFontname;
--(void)setDefaultFontsize:(float)fontsize;
--(float)defaultFontsize;
--(void)setDefaultFonttraits:(int)fonttraits;
--(int)defaultFonttraits;
+(void)setPopupMenuOpen:(BOOL)popupMenuOpen;
-(::com::sun::star::accessibility::XAccessibleAction *)accessibleAction;
-(::com::sun::star::accessibility::XAccessibleContext *)accessibleContext;
More information about the Libreoffice-commits
mailing list