From 1c0ecec225130bcb318474bf01dddc3c4e5c0004 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Dec 2016 20:47:42 +0100 Subject: [PATCH 1/3] Better fix for 32 bit wxOSX build Instead of disabling vertical alignment support in wxDataViewCtrl, move the private variables to the header file: this is supported by all versions of the Objective-C runtime, including the old one used for 32 bit applications, unlike the new way based on declaring the variable in an anonymous extension. This replaces the changes of 22216b70e7281432c0846ae48b0462c470ee514b. --- include/wx/osx/cocoa/dataview.h | 6 ++++++ src/osx/cocoa/dataview.mm | 17 ----------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 5f6583b886..7b9a8611a9 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -376,6 +376,12 @@ private: #define wxTextFieldCell NSTextFieldCell #else @interface wxTextFieldCell : NSTextFieldCell +{ +@private + int _wxAlignment; + BOOL _adjustRect; +} + -(void) setWXAlignment:(int)alignment; @end #endif diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index deb772f508..3d2af4c3ad 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -1252,20 +1252,6 @@ outlineView:(NSOutlineView*)outlineView // wxTextFieldCell // ============================================================================ -#ifndef _LP64 - // The code below doesn't compile in 32 bits failing with - // - // error: instance variables may not be placed in class extension - // - // Until this can be fixed, disable it to at least fix compilation. -#else -@interface wxTextFieldCell () -{ - int _wxAlignment; - BOOL _adjustRect; -} -@end - @implementation wxTextFieldCell - (void)setWXAlignment:(int)alignment @@ -1331,7 +1317,6 @@ outlineView:(NSOutlineView*)outlineView } @end -#endif // 32/64 bits // ============================================================================ @@ -2763,10 +2748,8 @@ void wxDataViewRenderer::OSXUpdateAlignment() int align = GetEffectiveAlignment(); NSCell *cell = GetNativeData()->GetColumnCell(); [cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; -#ifdef _LP64 if ([cell respondsToSelector:@selector(setWXAlignment:)]) [(wxTextFieldCell*)cell setWXAlignment:align]; -#endif // _LP64 } void wxDataViewRenderer::SetMode(wxDataViewCellMode mode) From a326da369be98d944f93d2ff7d10a43937c75a6c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Dec 2016 20:50:44 +0100 Subject: [PATCH 2/3] No real changes, just remove leading underscore from variables Now that these variables are in a public header, don't use leading underscores for them, if only for consistency with all the others. --- include/wx/osx/cocoa/dataview.h | 4 ++-- src/osx/cocoa/dataview.mm | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 7b9a8611a9..afbc45444e 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -378,8 +378,8 @@ private: @interface wxTextFieldCell : NSTextFieldCell { @private - int _wxAlignment; - BOOL _adjustRect; + int wxAlignment; + BOOL adjustRect; } -(void) setWXAlignment:(int)alignment; diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 3d2af4c3ad..211bb5ae70 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -1256,8 +1256,8 @@ outlineView:(NSOutlineView*)outlineView - (void)setWXAlignment:(int)alignment { - _wxAlignment = alignment; - _adjustRect = (alignment & (wxALIGN_CENTRE_VERTICAL | wxALIGN_BOTTOM)) != 0; + wxAlignment = alignment; + adjustRect = (alignment & (wxALIGN_CENTRE_VERTICAL | wxALIGN_BOTTOM)) != 0; } // These three overrides implement vertical alignment of text cells. @@ -1269,7 +1269,7 @@ outlineView:(NSOutlineView*)outlineView // Get the parent's idea of where we should draw NSRect r = [super drawingRectForBounds:theRect]; - if (!_adjustRect) + if (!adjustRect) return r; if (theRect.size.height <= MINIMUM_NATIVE_ROW_HEIGHT) return r; // don't mess with default-sized rows as they are centered @@ -1277,12 +1277,12 @@ outlineView:(NSOutlineView*)outlineView NSSize bestSize = [self cellSizeForBounds:theRect]; if (bestSize.height < r.size.height) { - if (_wxAlignment & wxALIGN_CENTER_VERTICAL) + if (wxAlignment & wxALIGN_CENTER_VERTICAL) { r.origin.y += int(r.size.height - bestSize.height) / 2; r.size.height = bestSize.height; } - else if (_wxAlignment & wxALIGN_BOTTOM) + else if (wxAlignment & wxALIGN_BOTTOM) { r.origin.y += r.size.height - bestSize.height; r.size.height = bestSize.height; @@ -1294,26 +1294,26 @@ outlineView:(NSOutlineView*)outlineView - (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength { - BOOL oldAdjustRect = _adjustRect; + BOOL oldAdjustRect = adjustRect; if (oldAdjustRect) { aRect = [self drawingRectForBounds:aRect]; - _adjustRect = NO; + adjustRect = NO; } [super selectWithFrame:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength]; - _adjustRect = oldAdjustRect; + adjustRect = oldAdjustRect; } - (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent { - BOOL oldAdjustRect = _adjustRect; + BOOL oldAdjustRect = adjustRect; if (oldAdjustRect) { aRect = [self drawingRectForBounds:aRect]; - _adjustRect = NO; + adjustRect = NO; } [super editWithFrame:aRect inView:controlView editor:textObj delegate:anObject event:theEvent]; - _adjustRect = oldAdjustRect; + adjustRect = oldAdjustRect; } @end From 467c48841f12f6f966240e643a3c93cd47506cc0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 11 Jul 2017 22:35:22 +0200 Subject: [PATCH 3/3] Rename wxTextFieldCell members once again Use underscores on them to show that they are different from properties or local variables (in pure Objective C they would actually start with underscores, but this is not a good idea in C++ code) and avoid conflict between a member name and "wxAlignment" type name, which was confusing. --- include/wx/osx/cocoa/dataview.h | 4 ++-- src/osx/cocoa/dataview.mm | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index afbc45444e..7d82302a44 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -378,8 +378,8 @@ private: @interface wxTextFieldCell : NSTextFieldCell { @private - int wxAlignment; - BOOL adjustRect; + int alignment_; + BOOL adjustRect_; } -(void) setWXAlignment:(int)alignment; diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 211bb5ae70..457bb3b140 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -1256,8 +1256,8 @@ outlineView:(NSOutlineView*)outlineView - (void)setWXAlignment:(int)alignment { - wxAlignment = alignment; - adjustRect = (alignment & (wxALIGN_CENTRE_VERTICAL | wxALIGN_BOTTOM)) != 0; + alignment_ = alignment; + adjustRect_ = (alignment & (wxALIGN_CENTRE_VERTICAL | wxALIGN_BOTTOM)) != 0; } // These three overrides implement vertical alignment of text cells. @@ -1269,7 +1269,7 @@ outlineView:(NSOutlineView*)outlineView // Get the parent's idea of where we should draw NSRect r = [super drawingRectForBounds:theRect]; - if (!adjustRect) + if (!adjustRect_) return r; if (theRect.size.height <= MINIMUM_NATIVE_ROW_HEIGHT) return r; // don't mess with default-sized rows as they are centered @@ -1277,12 +1277,12 @@ outlineView:(NSOutlineView*)outlineView NSSize bestSize = [self cellSizeForBounds:theRect]; if (bestSize.height < r.size.height) { - if (wxAlignment & wxALIGN_CENTER_VERTICAL) + if (alignment_ & wxALIGN_CENTER_VERTICAL) { r.origin.y += int(r.size.height - bestSize.height) / 2; r.size.height = bestSize.height; } - else if (wxAlignment & wxALIGN_BOTTOM) + else if (alignment_ & wxALIGN_BOTTOM) { r.origin.y += r.size.height - bestSize.height; r.size.height = bestSize.height; @@ -1294,26 +1294,26 @@ outlineView:(NSOutlineView*)outlineView - (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength { - BOOL oldAdjustRect = adjustRect; + BOOL oldAdjustRect = adjustRect_; if (oldAdjustRect) { aRect = [self drawingRectForBounds:aRect]; - adjustRect = NO; + adjustRect_ = NO; } [super selectWithFrame:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength]; - adjustRect = oldAdjustRect; + adjustRect_ = oldAdjustRect; } - (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent { - BOOL oldAdjustRect = adjustRect; + BOOL oldAdjustRect = adjustRect_; if (oldAdjustRect) { aRect = [self drawingRectForBounds:aRect]; - adjustRect = NO; + adjustRect_ = NO; } [super editWithFrame:aRect inView:controlView editor:textObj delegate:anObject event:theEvent]; - adjustRect = oldAdjustRect; + adjustRect_ = oldAdjustRect; } @end