summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-08 04:35:50 -0400
committerPietro Gagliardi <[email protected]>2015-04-08 04:35:50 -0400
commit941825e1902d7ccdea93ad21f518a8c60ce271b2 (patch)
tree81f39bf8afab350e6a002a1e655774e387f20bb5
parent4ab6251449b4c88869b12514f67c8731ab14c93c (diff)
Cleaned out some of that gunk. I can't avoid subclassing the standard controls, but making it so that the uiControl returned by uiDarwinNewControl() can be freed by the caller will help.
-rw-r--r--new/button_darwin.m19
-rw-r--r--new/init_darwin.m2
-rw-r--r--new/newcontrol_darwin.m15
-rw-r--r--new/ui_darwin.h6
-rw-r--r--new/uipriv_darwin.h11
-rw-r--r--new/util_darwin.m10
6 files changed, 17 insertions, 46 deletions
diff --git a/new/button_darwin.m b/new/button_darwin.m
index d422718..30cf179 100644
--- a/new/button_darwin.m
+++ b/new/button_darwin.m
@@ -1,7 +1,7 @@
// 7 april 2015
#import "uipriv_darwin.h"
-@interface uiNSButton : NSButton <uiFreeOnDealloc>
+@interface uiNSButton : NSButton
@property uiControl *uiC;
@property void (*uiOnClicked)(uiControl *, void *);
@property void *uiOnClickedData;
@@ -10,12 +10,15 @@
@implementation uiNSButton
-uiLogObjCClassAllocations(uiDoFreeOnDealloc(self.uiFreeList);)
-uiFreeOnDeallocImpl
+- (void)dealloc
+{
+ uiDarwinControlFree(self.uiC);
+ [super dealloc];
+}
- (IBAction)uiButtonClicked:(id)sender
{
- (*(self.onClicked))(self.c, self.onClickedData);
+ (*(self.uiOnClicked))(self.uiC, self.uiOnClickedData);
}
@end
@@ -33,7 +36,7 @@ uiControl *uiNewButton(const char *text)
c = uiDarwinNewControl([uiNSButton class], NO, NO, NULL);
b = (uiNSButton *) uiControlHandle(c);
- b.c = c;
+ b.uiC = c;
[b setTitle:toNSString(text)];
[b setButtonType:NSMomentaryPushInButton];
@@ -44,7 +47,7 @@ uiControl *uiNewButton(const char *text)
[b setTarget:b];
[b setAction:@selector(uiButtonClicked:)];
- b.onClicked = defaultOnClicked;
+ b.uiOnClicked = defaultOnClicked;
return b.c;
}
@@ -56,6 +59,6 @@ void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
button *b;
b = (uiNSButton *) uiControlHandle(c);
- b.onClicked = f;
- b.onClickedData = data;
+ b.uiOnClicked = f;
+ b.uiOnClickedData = data;
}
diff --git a/new/init_darwin.m b/new/init_darwin.m
index bd27dee..b251b47 100644
--- a/new/init_darwin.m
+++ b/new/init_darwin.m
@@ -6,8 +6,6 @@
@implementation uiApplication
-uiLogObjCClassAllocations()
-
// hey look! we're overriding terminate:!
// we're going to make sure we can go back to main() whether Cocoa likes it or not!
// and just how are we going to do that, hm?
diff --git a/new/newcontrol_darwin.m b/new/newcontrol_darwin.m
index 5a346f1..2274190 100644
--- a/new/newcontrol_darwin.m
+++ b/new/newcontrol_darwin.m
@@ -8,7 +8,6 @@ struct uiSingleViewControl {
NSView *view;
NSScrollView *scrollView;
NSView *immediate; // the control that is added to the parent container; either view or scrollView
- void *data;
};
#define S(c) ((uiSingleViewControl *) (c))
@@ -59,12 +58,9 @@ static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, i
[S(c)->immediate setFrame:frame];
}
-// TODO connect free function
-
-uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void *data)
+uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder)
{
uiSingleViewControl *c;
- uiFreeOnDealloc *freer;
c = uiNew(uiSingleViewControl);
// thanks to autoxr and arwyn in irc.freenode.net/#macdev
@@ -91,15 +87,10 @@ uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHas
c->control.preferredSize = singlePreferredSize;
c->control.resize = singleResize;
- c->data = data;
-
- freer = (uiFreeOnDealloc *) (c->view);
- [freer uiFreeOnDealloc:c];
-
return (uiControl *) c;
}
-void *uiDarwinControlData(uiControl *c)
+void uiDarwinControlFree(uiControl *c)
{
- return S(c)->data;
+ uiFree(c);
}
diff --git a/new/ui_darwin.h b/new/ui_darwin.h
index 02d0faa..e898c10 100644
--- a/new/ui_darwin.h
+++ b/new/ui_darwin.h
@@ -10,8 +10,8 @@ This file assumes that you have imported <Cocoa/Cocoa.h> and "ui.h" beforehand.
// uiDarwinNewControl() creates a new uiControl with the given Cocoa control inside.
// The first parameter should come from [RealControlType class].
// The two scrollView parameters allow placing scrollbars on the new control.
-// The data parameter can be accessed with uiDarwinControlData().
-extern uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void *data);
-extern void *uiDarwinControlData(uiControl *c);
+// Your control must call uiDarwinControlFree() on the returned uiControl in its -[dealloc] method.
+extern uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder);
+extern void uiDarwinControlFree(uiControl *);
#endif
diff --git a/new/uipriv_darwin.h b/new/uipriv_darwin.h
index 5e8c82e..effffb3 100644
--- a/new/uipriv_darwin.h
+++ b/new/uipriv_darwin.h
@@ -39,17 +39,6 @@ struct uiSizing {
// util_darwin.m
extern void setStandardControlFont(NSControl *);
-@protocol uiFreeOnDealloc
-- (void)uiFreeOnDealloc:(void *)p;
-@end
-#define uiFreeOnDeallocImpl \
-- (void)uiFreeOnDealloc:(void *)p \
-{ \
- if (self.uiFreeList == nil) \
- self.uiFreeList = [NSMutableArray new]; \
- [self.uiFreeList addObject:[NSValue valueWIthPointer:p]]; \
-}
-extern void uiDoFreeOnDealloc(NSMutableArray *);
// container_darwin.m
@interface uiContainer : NSView
diff --git a/new/util_darwin.m b/new/util_darwin.m
index 4ed562a..d8166e9 100644
--- a/new/util_darwin.m
+++ b/new/util_darwin.m
@@ -6,13 +6,3 @@ void setStandardControlFont(NSControl *control)
{
[control setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
}
-
-void uiDoFreeOnDealloc(NSMutableArray *m)
-{
- [m enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
- NSValue *v = (NSValue *) obj;
-
- uiFree([v pointerValue]);
- }];
- [m release];
-}