comparison mac/dw.m @ 1312:c5db6c70905c

Added code to remove signal handlers when objects are destroyed on Mac. There seems to be issues with all of the objects not deallocing.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 04 Nov 2011 10:57:51 +0000
parents dbd507f42947
children 9f12bc79924b
comparison
equal deleted inserted replaced
1311:5f3ce2b1e82d 1312:c5db6c70905c
630 -(void)dealloc 630 -(void)dealloc
631 { 631 {
632 UserData *root = userdata; 632 UserData *root = userdata;
633 free(box); 633 free(box);
634 _remove_userdata(&root, NULL, TRUE); 634 _remove_userdata(&root, NULL, TRUE);
635 dw_signal_disconnect_by_window(self);
635 [super dealloc]; 636 [super dealloc];
636 } 637 }
637 -(Box *)box { return box; } 638 -(Box *)box { return box; }
638 -(id)contentView { return self; } 639 -(id)contentView { return self; }
639 -(void *)userdata { return userdata; } 640 -(void *)userdata { return userdata; }
775 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } 776 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); }
776 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } 777 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); }
777 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } 778 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); }
778 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } 779 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); }
779 -(BOOL)isFlipped { return YES; } 780 -(BOOL)isFlipped { return YES; }
780 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; [super dealloc]; } 781 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; dw_signal_disconnect_by_window(self); [super dealloc]; }
781 -(BOOL)acceptsFirstResponder { return YES; } 782 -(BOOL)acceptsFirstResponder { return YES; }
782 @end 783 @end
783 784
784 /* Subclass for a top-level window */ 785 /* Subclass for a top-level window */
785 @interface DWView : DWBox 786 @interface DWView : DWBox
814 if(windowmenu) 815 if(windowmenu)
815 { 816 {
816 [windowmenu release]; 817 [windowmenu release];
817 } 818 }
818 [[NSNotificationCenter defaultCenter] removeObserver:self]; 819 [[NSNotificationCenter defaultCenter] removeObserver:self];
820 dw_signal_disconnect_by_window(self);
819 [super dealloc]; 821 [super dealloc];
820 } 822 }
821 - (void)windowResized:(NSNotification *)notification; 823 - (void)windowResized:(NSNotification *)notification;
822 { 824 {
823 NSSize size = [self frame].size; 825 NSSize size = [self frame].size;
917 } 919 }
918 -(void)setButtonType:(NSButtonType)input { buttonType = input; [super setButtonType:input]; } 920 -(void)setButtonType:(NSButtonType)input { buttonType = input; [super setButtonType:input]; }
919 -(NSButtonType)buttonType { return buttonType; } 921 -(NSButtonType)buttonType { return buttonType; }
920 -(void)setParent:(DWBox *)input { parent = input; } 922 -(void)setParent:(DWBox *)input { parent = input; }
921 -(DWBox *)parent { return parent; } 923 -(DWBox *)parent { return parent; }
922 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 924 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
923 @end 925 @end
924 926
925 /* Subclass for a progress type */ 927 /* Subclass for a progress type */
926 @interface DWPercent : NSProgressIndicator 928 @interface DWPercent : NSProgressIndicator
927 { 929 {
932 @end 934 @end
933 935
934 @implementation DWPercent 936 @implementation DWPercent
935 -(void *)userdata { return userdata; } 937 -(void *)userdata { return userdata; }
936 -(void)setUserdata:(void *)input { userdata = input; } 938 -(void)setUserdata:(void *)input { userdata = input; }
937 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 939 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
940 @end
941
942 /* Subclass for a menu item type */
943 @interface DWMenuItem : NSMenuItem { }
944 -(void)dealloc;
945 @end
946
947 @implementation DWMenuItem
948 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; }
938 @end 949 @end
939 950
940 /* Subclass for a scrollbox type */ 951 /* Subclass for a scrollbox type */
941 @interface DWScrollBox : NSScrollView 952 @interface DWScrollBox : NSScrollView
942 { 953 {
952 @implementation DWScrollBox 963 @implementation DWScrollBox
953 -(void *)userdata { return userdata; } 964 -(void *)userdata { return userdata; }
954 -(void)setUserdata:(void *)input { userdata = input; } 965 -(void)setUserdata:(void *)input { userdata = input; }
955 -(void)setBox:(void *)input { box = input; } 966 -(void)setBox:(void *)input { box = input; }
956 -(id)box { return box; } 967 -(id)box { return box; }
957 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 968 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
958 @end 969 @end
959 970
960 /* Subclass for a textfield that supports vertical centering */ 971 /* Subclass for a textfield that supports vertical centering */
961 @interface DWTextFieldCell : NSTextFieldCell 972 @interface DWTextFieldCell : NSTextFieldCell
962 { 973 {
1071 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"]) 1082 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"])
1072 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self]; 1083 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self];
1073 } 1084 }
1074 return [super performKeyEquivalent:theEvent]; 1085 return [super performKeyEquivalent:theEvent];
1075 } 1086 }
1076 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1087 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1077 @end 1088 @end
1078 1089
1079 /* Subclass for a entryfield password type */ 1090 /* Subclass for a entryfield password type */
1080 @interface DWEntryFieldPassword : NSSecureTextField 1091 @interface DWEntryFieldPassword : NSSecureTextField
1081 { 1092 {
1118 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"]) 1129 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"])
1119 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self]; 1130 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self];
1120 } 1131 }
1121 return [super performKeyEquivalent:theEvent]; 1132 return [super performKeyEquivalent:theEvent];
1122 } 1133 }
1123 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1134 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1124 @end 1135 @end
1125 1136
1126 /* Subclass for a Notebook control type */ 1137 /* Subclass for a Notebook control type */
1127 @interface DWNotebook : NSTabView 1138 @interface DWNotebook : NSTabView
1128 #ifdef BUILDING_FOR_SNOW_LEOPARD 1139 #ifdef BUILDING_FOR_SNOW_LEOPARD
1169 _do_resize(box, size.width, size.height); 1180 _do_resize(box, size.width, size.height);
1170 _handle_resize_events(box); 1181 _handle_resize_events(box);
1171 } 1182 }
1172 _event_handler(self, DW_INT_TO_POINTER([page pageid]), 15); 1183 _event_handler(self, DW_INT_TO_POINTER([page pageid]), 15);
1173 } 1184 }
1174 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1185 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1175 @end 1186 @end
1176 1187
1177 @implementation DWNotebookPage 1188 @implementation DWNotebookPage
1178 -(void *)userdata { return userdata; } 1189 -(void *)userdata { return userdata; }
1179 -(void)setUserdata:(void *)input { userdata = input; } 1190 -(void)setUserdata:(void *)input { userdata = input; }
1180 -(int)pageid { return pageid; } 1191 -(int)pageid { return pageid; }
1181 -(void)setPageid:(int)input { pageid = input; } 1192 -(void)setPageid:(int)input { pageid = input; }
1182 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1193 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1183 @end 1194 @end
1184 1195
1185 /* Subclass for a color chooser type */ 1196 /* Subclass for a color chooser type */
1186 @interface DWColorChoose : NSColorPanel 1197 @interface DWColorChoose : NSColorPanel
1187 { 1198 {
1261 } 1272 }
1262 -(void *)userdata { return userdata; } 1273 -(void *)userdata { return userdata; }
1263 -(void)setUserdata:(void *)input { userdata = input; } 1274 -(void)setUserdata:(void *)input { userdata = input; }
1264 -(float)percent { return percent; } 1275 -(float)percent { return percent; }
1265 -(void)setPercent:(float)input { percent = input; } 1276 -(void)setPercent:(float)input { percent = input; }
1266 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1277 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1267 @end 1278 @end
1268 1279
1269 /* Subclass for a slider type */ 1280 /* Subclass for a slider type */
1270 @interface DWSlider : NSSlider 1281 @interface DWSlider : NSSlider
1271 { 1282 {
1278 1289
1279 @implementation DWSlider 1290 @implementation DWSlider
1280 -(void *)userdata { return userdata; } 1291 -(void *)userdata { return userdata; }
1281 -(void)setUserdata:(void *)input { userdata = input; } 1292 -(void)setUserdata:(void *)input { userdata = input; }
1282 -(void)sliderChanged:(id)sender { _event_handler(self, (void *)[self integerValue], 14); } 1293 -(void)sliderChanged:(id)sender { _event_handler(self, (void *)[self integerValue], 14); }
1283 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1294 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1284 @end 1295 @end
1285 1296
1286 /* Subclass for a slider type */ 1297 /* Subclass for a slider type */
1287 @interface DWScrollbar : NSScroller 1298 @interface DWScrollbar : NSScroller
1288 { 1299 {
1352 { 1363 {
1353 [self setDoubleValue:(newpos/max)]; 1364 [self setDoubleValue:(newpos/max)];
1354 } 1365 }
1355 _event_handler(self, DW_INT_TO_POINTER((int)newpos), 14); 1366 _event_handler(self, DW_INT_TO_POINTER((int)newpos), 14);
1356 } 1367 }
1357 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1368 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1358 @end 1369 @end
1359 1370
1360 /* Subclass for a MLE type */ 1371 /* Subclass for a MLE type */
1361 @interface DWMLE : NSTextView 1372 @interface DWMLE : NSTextView
1362 { 1373 {
1367 @end 1378 @end
1368 1379
1369 @implementation DWMLE 1380 @implementation DWMLE
1370 -(void *)userdata { return userdata; } 1381 -(void *)userdata { return userdata; }
1371 -(void)setUserdata:(void *)input { userdata = input; } 1382 -(void)setUserdata:(void *)input { userdata = input; }
1372 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1383 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1373 @end 1384 @end
1374 1385
1375 /* Subclass NSTextFieldCell for displaying image and text */ 1386 /* Subclass NSTextFieldCell for displaying image and text */
1376 @interface DWImageAndTextCell : NSTextFieldCell 1387 @interface DWImageAndTextCell : NSTextFieldCell
1377 { 1388 {
1831 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; 1842 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil];
1832 row = (int)[self rowAtPoint:where]; 1843 row = (int)[self rowAtPoint:where];
1833 _event_handler(self, (NSEvent *)[self getRowTitle:row], 10); 1844 _event_handler(self, (NSEvent *)[self getRowTitle:row], 10);
1834 return nil; 1845 return nil;
1835 } 1846 }
1836 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1847 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1837 @end 1848 @end
1838 1849
1839 /* Dive into the tree freeing all desired child nodes */ 1850 /* Dive into the tree freeing all desired child nodes */
1840 void _free_tree_recurse(NSMutableArray *node, NSMutableArray *item) 1851 void _free_tree_recurse(NSMutableArray *node, NSMutableArray *item)
1841 { 1852 {
2072 { 2083 {
2073 UserData *root = userdata; 2084 UserData *root = userdata;
2074 _remove_userdata(&root, NULL, TRUE); 2085 _remove_userdata(&root, NULL, TRUE);
2075 _free_tree_recurse(data, NULL); 2086 _free_tree_recurse(data, NULL);
2076 [treecol release]; 2087 [treecol release];
2088 dw_signal_disconnect_by_window(self);
2077 [super dealloc]; 2089 [super dealloc];
2078 } 2090 }
2079 @end 2091 @end
2080 2092
2081 /* Subclass for a Calendar type */ 2093 /* Subclass for a Calendar type */
2088 @end 2100 @end
2089 2101
2090 @implementation DWCalendar 2102 @implementation DWCalendar
2091 -(void *)userdata { return userdata; } 2103 -(void *)userdata { return userdata; }
2092 -(void)setUserdata:(void *)input { userdata = input; } 2104 -(void)setUserdata:(void *)input { userdata = input; }
2093 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 2105 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2094 @end 2106 @end
2095 2107
2096 /* Subclass for a Combobox type */ 2108 /* Subclass for a Combobox type */
2097 @interface DWComboBox : NSComboBox 2109 @interface DWComboBox : NSComboBox
2098 #ifdef BUILDING_FOR_SNOW_LEOPARD 2110 #ifdef BUILDING_FOR_SNOW_LEOPARD
2121 } else 2133 } else
2122 { 2134 {
2123 [super keyUp:theEvent]; 2135 [super keyUp:theEvent];
2124 } 2136 }
2125 } 2137 }
2126 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 2138 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2127 @end 2139 @end
2128 2140
2129 /* Subclass for a stepper component of the spinbutton type */ 2141 /* Subclass for a stepper component of the spinbutton type */
2130 /* This is a bad way of doing this... but I can't get the other methods to work */ 2142 /* This is a bad way of doing this... but I can't get the other methods to work */
2131 @interface DWStepper : NSStepper 2143 @interface DWStepper : NSStepper
2218 { 2230 {
2219 [super keyUp:theEvent]; 2231 [super keyUp:theEvent];
2220 } 2232 }
2221 } 2233 }
2222 -(void)performClick:(id)sender { [textfield performClick:sender]; } 2234 -(void)performClick:(id)sender { [textfield performClick:sender]; }
2223 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 2235 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2224 @end 2236 @end
2225 2237
2226 /* Subclass for a MDI type 2238 /* Subclass for a MDI type
2227 * This is just a box for display purposes... but it is a 2239 * This is just a box for display purposes... but it is a
2228 * unique class so it can be identified when creating windows. 2240 * unique class so it can be identified when creating windows.
7132 */ 7144 */
7133 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux) 7145 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux)
7134 { 7146 {
7135 NSMenu *menu = menux; 7147 NSMenu *menu = menux;
7136 NSMenu *submenu = submenux; 7148 NSMenu *submenu = submenux;
7137 NSMenuItem *item = NULL; 7149 DWMenuItem *item = NULL;
7138 if(strlen(title) == 0) 7150 if(strlen(title) == 0)
7139 { 7151 {
7140 [menu addItem:[NSMenuItem separatorItem]]; 7152 [menu addItem:[DWMenuItem separatorItem]];
7141 } 7153 }
7142 else 7154 else
7143 { 7155 {
7144 char accel[2]; 7156 char accel[2];
7145 char *newtitle = malloc(strlen(title)+1); 7157 char *newtitle = malloc(strlen(title)+1);
7149 accel[1] = 0; 7161 accel[1] = 0;
7150 7162
7151 nstr = [ NSString stringWithUTF8String:newtitle ]; 7163 nstr = [ NSString stringWithUTF8String:newtitle ];
7152 free(newtitle); 7164 free(newtitle);
7153 7165
7154 item = [menu addItemWithTitle: nstr 7166 item = [[DWMenuItem alloc] initWithTitle:nstr
7155 action:@selector(menuHandler:) 7167 action:@selector(menuHandler:)
7156 keyEquivalent:[ NSString stringWithUTF8String:accel ]]; 7168 keyEquivalent:[ NSString stringWithUTF8String:accel ]];
7169 [menu addItem:item];
7170
7157 [item setTag:itemid]; 7171 [item setTag:itemid];
7158 if(flags & DW_MIS_CHECKED) 7172 if(flags & DW_MIS_CHECKED)
7159 { 7173 {
7160 [item setState:NSOnState]; 7174 [item setState:NSOnState];
7161 } 7175 }