Skip to content

Commit 05acf40

Browse files
author
Matt Bennett
committed
remove ARC and auto synthesize assumptions in cocoa_window.mm
1 parent 2c30f35 commit 05acf40

File tree

1 file changed

+70
-92
lines changed

1 file changed

+70
-92
lines changed

modules/highgui/src/window_cocoa.mm

Lines changed: 70 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -82,46 +82,42 @@ CV_IMPL void cvSetTrackbarMin(const char* trackbar_name, const char* window_name
8282
static NSMutableDictionary *windows = nil;
8383
static bool wasInitialized = false;
8484

85-
@interface CVView : NSView
86-
{
87-
NSImage *_image;
85+
@interface CVView : NSView {
86+
NSImage *image;
8887
}
89-
@property(strong) NSImage *image;
88+
@property(retain) NSImage *image;
9089
- (void)setImageData:(CvArr *)arr;
9190
@end
9291

93-
@interface CVSlider : NSView
94-
{
95-
NSSlider *_slider;
96-
NSTextField *_name;
97-
int *_value;
98-
void *_userData;
99-
CvTrackbarCallback _callback;
100-
CvTrackbarCallback2 _callback2;
92+
@interface CVSlider : NSView {
93+
NSSlider *slider;
94+
NSTextField *name;
95+
int *value;
96+
void *userData;
97+
CvTrackbarCallback callback;
98+
CvTrackbarCallback2 callback2;
10199
}
102-
103-
@property(strong) NSSlider *slider;
104-
@property(strong) NSTextField *name;
100+
@property(retain) NSSlider *slider;
101+
@property(retain) NSTextField *name;
105102
@property(assign) int *value;
106103
@property(assign) void *userData;
107104
@property(assign) CvTrackbarCallback callback;
108105
@property(assign) CvTrackbarCallback2 callback2;
109106
@end
110107

111-
@interface CVWindow : NSWindow
112-
{
113-
CvMouseCallback _mouseCallback;
114-
void *_mouseParam;
115-
BOOL _autosize;
116-
BOOL _firstContent;
117-
NSMutableDictionary *_sliders;
118-
int _status;
108+
@interface CVWindow : NSWindow {
109+
NSMutableDictionary *sliders;
110+
CvMouseCallback mouseCallback;
111+
void *mouseParam;
112+
BOOL autosize;
113+
BOOL firstContent;
114+
int status;
119115
}
120116
@property(assign) CvMouseCallback mouseCallback;
121117
@property(assign) void *mouseParam;
122118
@property(assign) BOOL autosize;
123119
@property(assign) BOOL firstContent;
124-
@property(strong) NSMutableDictionary *sliders;
120+
@property(retain) NSMutableDictionary *sliders;
125121
@property(readwrite) int status;
126122
- (CVView *)contentView;
127123
- (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags;
@@ -701,21 +697,14 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value )
701697
}
702698

703699
@implementation CVWindow
704-
#if defined(__LP64__)
700+
705701
@synthesize mouseCallback;
706702
@synthesize mouseParam;
707703
@synthesize autosize;
708704
@synthesize firstContent;
709705
@synthesize sliders;
710706
@synthesize status;
711-
#else // 32-bit Obj-C does not have automatic synthesize
712-
@synthesize mouseCallback = _mouseCallback;
713-
@synthesize mouseParam = _mouseParam;
714-
@synthesize autosize = _autosize;
715-
@synthesize firstContent = _firstContent;
716-
@synthesize sliders = _sliders;
717-
@synthesize status = _status;
718-
#endif
707+
719708
- (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags {
720709
(void)event;
721710
//cout << "cvSendMouseEvent" << endl;
@@ -740,13 +729,12 @@ - (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags {
740729
mp.y = mp.y * imageSize.height / std::max(viewHeight, 1.);
741730

742731
if( mp.x >= 0 && mp.y >= 0 && mp.x < imageSize.width && mp.y < imageSize.height )
743-
_mouseCallback(type, mp.x, mp.y, flags, _mouseParam);
732+
mouseCallback(type, mp.x, mp.y, flags, mouseParam);
744733
}
745734

746735
- (void)cvMouseEvent:(NSEvent *)event {
747736
//cout << "cvMouseEvent" << endl;
748-
749-
if([self mouseCallback] == nil)
737+
if(!mouseCallback)
750738
return;
751739

752740
int flags = 0;
@@ -806,13 +794,13 @@ - (void)mouseDown:(NSEvent *)theEvent {
806794

807795
- (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)value callback:(CvTrackbarCallback)callback {
808796
//cout << "createSliderWithName" << endl;
809-
if(_sliders == nil)
810-
_sliders = [[NSMutableDictionary alloc] init];
797+
if(sliders == nil)
798+
sliders = [[NSMutableDictionary alloc] init];
811799

812800
NSString *cvname = [NSString stringWithFormat:@"%s", name];
813801

814802
// Avoid overwriting slider
815-
if([_sliders valueForKey:cvname]!=nil)
803+
if([sliders valueForKey:cvname]!=nil)
816804
return;
817805

818806
// Create slider
@@ -831,11 +819,11 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v
831819
[slider setCallback:callback];
832820

833821
// Save slider
834-
[_sliders setValue:slider forKey:cvname];
822+
[sliders setValue:slider forKey:cvname];
835823
[[self contentView] addSubview:slider];
836824

837825

838-
//update contentView size to contain _sliders
826+
//update contentView size to contain sliders
839827
NSSize viewSize=[[self contentView] frame].size,
840828
sliderSize=[slider frame].size;
841829
viewSize.height += sliderSize.height;
@@ -845,7 +833,7 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v
845833
[[self contentView] setFrameSize:viewSize];
846834
[[self contentView] setNeedsDisplay:YES];
847835

848-
//update window size to contain _sliders
836+
//update window size to contain sliders
849837
NSRect rect = [self frame];
850838
rect.size.height += [slider frame].size.height;
851839
rect.size.width = std::max<int>(rect.size.width, MIN_SLIDER_WIDTH);
@@ -862,16 +850,13 @@ - (CVView *)contentView {
862850
@end
863851

864852
@implementation CVView
865-
#if defined(__LP64__)
853+
866854
@synthesize image;
867-
#else // 32-bit Obj-C does not have automatic synthesize
868-
@synthesize image = _image;
869-
#endif
870855

871856
- (id)init {
872857
//cout << "CVView init" << endl;
873858
[super init];
874-
_image = [[NSImage alloc] init];
859+
image = [[NSImage alloc] init];
875860
return self;
876861
}
877862

@@ -926,11 +911,11 @@ - (void)setImageData:(CvArr *)arr {
926911
dst[i * 4 + 2] = src[i * 3 + 2];
927912
}
928913

929-
if( _image )
930-
[_image release];
914+
if( image )
915+
[image release];
931916

932-
_image = [[NSImage alloc] init];
933-
[_image addRepresentation:bitmap];
917+
image = [[NSImage alloc] init];
918+
[image addRepresentation:bitmap];
934919
[bitmap release];
935920

936921
/*CGColorSpaceRelease(colorspace);
@@ -951,7 +936,7 @@ - (void)setFrameSize:(NSSize)size {
951936
int height = size.height;
952937

953938
CVWindow *cvwindow = (CVWindow *)[self window];
954-
if ([cvwindow respondsToSelector:@selector(_sliders)]) {
939+
if ([cvwindow respondsToSelector:@selector(sliders)]) {
955940
for(NSString *key in [cvwindow sliders]) {
956941
NSSlider *slider = [[cvwindow sliders] valueForKey:key];
957942
NSRect r = [slider frame];
@@ -971,17 +956,17 @@ - (void)drawRect:(NSRect)rect {
971956
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
972957
CVWindow *cvwindow = (CVWindow *)[self window];
973958
int height = 0;
974-
if ([cvwindow respondsToSelector:@selector(_sliders)]) {
959+
if ([cvwindow respondsToSelector:@selector(sliders)]) {
975960
for(NSString *key in [cvwindow sliders]) {
976961
height += [[[cvwindow sliders] valueForKey:key] frame].size.height;
977962
}
978963
}
979964

980965

981-
NSRect imageRect = {{0,0}, {[_image size].width, [_image size].height}};
966+
NSRect imageRect = {{0,0}, {[image size].width, [image size].height}};
982967

983-
if(_image != nil) {
984-
[_image drawInRect: imageRect
968+
if(image != nil) {
969+
[image drawInRect: imageRect
985970
fromRect: NSZeroRect
986971
operation: NSCompositeSourceOver
987972
fraction: 1.0];
@@ -993,47 +978,40 @@ - (void)drawRect:(NSRect)rect {
993978
@end
994979

995980
@implementation CVSlider
996-
#if defined(__LP64__)
981+
997982
@synthesize slider;
998983
@synthesize name;
999984
@synthesize value;
1000985
@synthesize userData;
1001986
@synthesize callback;
1002987
@synthesize callback2;
1003-
#else // 32-bit Obj-C does not have automatic synthesize
1004-
@synthesize slider = _slider;
1005-
@synthesize name = _name;
1006-
@synthesize value = _value;
1007-
@synthesize userData = _userData;
1008-
@synthesize callback = _callback;
1009-
@synthesize callback2 = _callback2;
1010-
#endif
988+
1011989
- (id)init {
1012990
[super init];
1013991

1014-
_callback = NULL;
1015-
_value = NULL;
1016-
_userData = NULL;
992+
callback = NULL;
993+
value = NULL;
994+
userData = NULL;
1017995

1018996
[self setFrame:NSMakeRect(0,0,200,30)];
1019997

1020-
_name = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 0,110, 25)];
1021-
[_name setEditable:NO];
1022-
[_name setSelectable:NO];
1023-
[_name setBezeled:NO];
1024-
[_name setBordered:NO];
1025-
[_name setDrawsBackground:NO];
1026-
[[_name cell] setLineBreakMode:NSLineBreakByTruncatingTail];
1027-
[self addSubview:_name];
1028-
1029-
_slider = [[NSSlider alloc] initWithFrame:NSMakeRect(120, 0, 70, 25)];
1030-
[_slider setAutoresizingMask:NSViewWidthSizable];
1031-
[_slider setMinValue:0];
1032-
[_slider setMaxValue:100];
1033-
[_slider setContinuous:YES];
1034-
[_slider setTarget:self];
1035-
[_slider setAction:@selector(sliderChanged:)];
1036-
[self addSubview:_slider];
998+
name = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 0,110, 25)];
999+
[name setEditable:NO];
1000+
[name setSelectable:NO];
1001+
[name setBezeled:NO];
1002+
[name setBordered:NO];
1003+
[name setDrawsBackground:NO];
1004+
[[name cell] setLineBreakMode:NSLineBreakByTruncatingTail];
1005+
[self addSubview:name];
1006+
1007+
slider = [[NSSlider alloc] initWithFrame:NSMakeRect(120, 0, 70, 25)];
1008+
[slider setAutoresizingMask:NSViewWidthSizable];
1009+
[slider setMinValue:0];
1010+
[slider setMaxValue:100];
1011+
[slider setContinuous:YES];
1012+
[slider setTarget:self];
1013+
[slider setAction:@selector(sliderChanged:)];
1014+
[self addSubview:slider];
10371015

10381016
[self setAutoresizingMask:NSViewWidthSizable];
10391017

@@ -1044,13 +1022,13 @@ - (id)init {
10441022

10451023
- (void)sliderChanged:(NSNotification *)notification {
10461024
(void)notification;
1047-
int pos = [_slider intValue];
1048-
if(_value)
1049-
*_value = pos;
1050-
if(_callback)
1051-
_callback(pos);
1052-
if(_callback2)
1053-
_callback2(pos, _userData);
1025+
int pos = [slider intValue];
1026+
if(value)
1027+
*value = pos;
1028+
if(callback)
1029+
callback(pos);
1030+
if(callback2)
1031+
callback2(pos, userData);
10541032
}
10551033

10561034
@end

0 commit comments

Comments
 (0)