Mercurial > dwindows
comparison mac/dw.m @ 705:7087f3a294e5
Spinbuttons now respond to value changed. Fix for typing in spinbutton a value out of the range.
Other related event fixes.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 11 Mar 2011 20:30:59 +0000 |
parents | 336800e9e648 |
children | 79b38b1f3346 |
comparison
equal
deleted
inserted
replaced
704:336800e9e648 | 705:7087f3a294e5 |
---|---|
132 }; | 132 }; |
133 | 133 |
134 int _event_handler(id object, NSEvent *event, int message) | 134 int _event_handler(id object, NSEvent *event, int message) |
135 { | 135 { |
136 SignalHandler *handler = _get_handler(object, message); | 136 SignalHandler *handler = _get_handler(object, message); |
137 /*NSLog(@"Event handler - type %d\n", message);*/ | 137 NSLog(@"Event handler - type %d\n", message); |
138 | 138 |
139 if(handler) | 139 if(handler) |
140 { | 140 { |
141 switch(message) | 141 switch(message) |
142 { | 142 { |
668 @end | 668 @end |
669 | 669 |
670 @implementation DWSlider | 670 @implementation DWSlider |
671 -(void *)userdata { return userdata; } | 671 -(void *)userdata { return userdata; } |
672 -(void)setUserdata:(void *)input { userdata = input; } | 672 -(void)setUserdata:(void *)input { userdata = input; } |
673 -(void)sliderChanged:(id)sender { NSLog(@"Slider changed"); _event_handler(self, (void *)[self integerValue], 14); } | 673 -(void)sliderChanged:(id)sender { _event_handler(self, (void *)[self integerValue], 14); } |
674 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 674 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
675 @end | 675 @end |
676 | 676 |
677 /* Subclass for a slider type */ | 677 /* Subclass for a slider type */ |
678 @interface DWScrollbar : NSScroller | 678 @interface DWScrollbar : NSScroller |
684 -(void *)userdata; | 684 -(void *)userdata; |
685 -(void)setUserdata:(void *)input; | 685 -(void)setUserdata:(void *)input; |
686 -(float)range; | 686 -(float)range; |
687 -(float)visible; | 687 -(float)visible; |
688 -(void)setRange:(float)input1 andVisible:(float)input2; | 688 -(void)setRange:(float)input1 andVisible:(float)input2; |
689 -(void)changed:(id)sender; | 689 -(void)scrollerChanged:(id)sender; |
690 @end | 690 @end |
691 | 691 |
692 @implementation DWScrollbar | 692 @implementation DWScrollbar |
693 -(void *)userdata { return userdata; } | 693 -(void *)userdata { return userdata; } |
694 -(void)setUserdata:(void *)input { userdata = input; } | 694 -(void)setUserdata:(void *)input { userdata = input; } |
695 -(float)range { return range; } | 695 -(float)range { return range; } |
696 -(float)visible { return visible; } | 696 -(float)visible { return visible; } |
697 -(void)setRange:(float)input1 andVisible:(float)input2 { range = input1; visible = input2; } | 697 -(void)setRange:(float)input1 andVisible:(float)input2 { range = input1; visible = input2; } |
698 -(void)changed:(id)sender { NSNumber *num = [NSNumber numberWithDouble:[self floatValue]]; _event_handler(self, (void *)[num integerValue], 14); } | 698 -(void)scrollerChanged:(id)sender { NSNumber *num = [NSNumber numberWithDouble:[self floatValue]]; _event_handler(self, (void *)[num integerValue], 14); } |
699 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 699 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
700 @end | 700 @end |
701 | 701 |
702 /* Subclass for a render area type */ | 702 /* Subclass for a render area type */ |
703 @interface DWRender : NSView | 703 @interface DWRender : NSView |
1163 /* Subclass for a stepper component of the spinbutton type */ | 1163 /* Subclass for a stepper component of the spinbutton type */ |
1164 /* This is a bad way of doing this... but I can't get the other methods to work */ | 1164 /* This is a bad way of doing this... but I can't get the other methods to work */ |
1165 @interface DWStepper : NSStepper | 1165 @interface DWStepper : NSStepper |
1166 { | 1166 { |
1167 id textfield; | 1167 id textfield; |
1168 id parent; | |
1168 } | 1169 } |
1169 -(void)setTextfield:(id)input; | 1170 -(void)setTextfield:(id)input; |
1170 -(id)textfield; | 1171 -(id)textfield; |
1172 -(void)setParent:(id)input; | |
1173 -(id)parent; | |
1171 -(void)mouseDown:(NSEvent *)event; | 1174 -(void)mouseDown:(NSEvent *)event; |
1172 -(void)mouseUp:(NSEvent *)event; | 1175 -(void)mouseUp:(NSEvent *)event; |
1173 @end | 1176 @end |
1174 | 1177 |
1175 @implementation DWStepper | 1178 @implementation DWStepper |
1176 -(void)setTextfield:(id)input { textfield = input; } | 1179 -(void)setTextfield:(id)input { textfield = input; } |
1177 -(id)textfield { return textfield; } | 1180 -(id)textfield { return textfield; } |
1181 -(void)setParent:(id)input { parent = input; } | |
1182 -(id)parent { return parent; } | |
1178 -(void)mouseDown:(NSEvent *)event | 1183 -(void)mouseDown:(NSEvent *)event |
1179 { | 1184 { |
1180 [super mouseDown:event]; | 1185 [super mouseDown:event]; |
1181 if([[NSApp currentEvent] type] == NSLeftMouseUp) | 1186 if([[NSApp currentEvent] type] == NSLeftMouseUp) |
1182 { | 1187 { |
1183 [textfield takeIntValueFrom:self]; | 1188 [textfield takeIntValueFrom:self]; |
1189 _event_handler(parent, (void *)[self integerValue], 14); | |
1184 } | 1190 } |
1185 } | 1191 } |
1186 -(void)mouseUp:(NSEvent *)event | 1192 -(void)mouseUp:(NSEvent *)event |
1187 { | 1193 { |
1188 [textfield takeIntValueFrom:self]; | 1194 [textfield takeIntValueFrom:self]; |
1195 _event_handler(parent, (void *)[self integerValue], 14); | |
1189 } | 1196 } |
1190 @end | 1197 @end |
1191 | 1198 |
1192 /* Subclass for a Spinbutton type */ | 1199 /* Subclass for a Spinbutton type */ |
1193 @interface DWSpinButton : NSView <NSTextFieldDelegate> | 1200 @interface DWSpinButton : NSView <NSTextFieldDelegate> |
1213 { | 1220 { |
1214 textfield = [[NSTextField alloc] init]; | 1221 textfield = [[NSTextField alloc] init]; |
1215 [self addSubview:textfield]; | 1222 [self addSubview:textfield]; |
1216 stepper = [[DWStepper alloc] init]; | 1223 stepper = [[DWStepper alloc] init]; |
1217 [self addSubview:stepper]; | 1224 [self addSubview:stepper]; |
1225 [stepper setParent:self]; | |
1218 [stepper setTextfield:textfield]; | 1226 [stepper setTextfield:textfield]; |
1219 [textfield takeIntValueFrom:stepper]; | 1227 [textfield takeIntValueFrom:stepper]; |
1220 [textfield setDelegate:self]; | 1228 [textfield setDelegate:self]; |
1221 } | 1229 } |
1222 return self; | 1230 return self; |
1226 -(NSTextField *)textfield { return textfield; } | 1234 -(NSTextField *)textfield { return textfield; } |
1227 -(NSStepper *)stepper { return stepper; } | 1235 -(NSStepper *)stepper { return stepper; } |
1228 -(void)controlTextDidChange:(NSNotification *)aNotification | 1236 -(void)controlTextDidChange:(NSNotification *)aNotification |
1229 { | 1237 { |
1230 [stepper takeIntValueFrom:textfield]; | 1238 [stepper takeIntValueFrom:textfield]; |
1239 [textfield takeIntValueFrom:stepper]; | |
1240 _event_handler(self, (void *)[stepper integerValue], 14); | |
1231 } | 1241 } |
1232 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 1242 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
1233 @end | 1243 @end |
1234 | 1244 |
1235 /* Subclass for a MDI type | 1245 /* Subclass for a MDI type |
2571 [scrollbar setArrowsPosition:NSScrollerArrowsDefaultSetting]; | 2581 [scrollbar setArrowsPosition:NSScrollerArrowsDefaultSetting]; |
2572 [scrollbar setTarget:scrollbar]; | 2582 [scrollbar setTarget:scrollbar]; |
2573 [scrollbar setAction:@selector(changed:)]; | 2583 [scrollbar setAction:@selector(changed:)]; |
2574 [scrollbar setRange:0.0 andVisible:0.0]; | 2584 [scrollbar setRange:0.0 andVisible:0.0]; |
2575 [scrollbar setKnobProportion:1.0]; | 2585 [scrollbar setKnobProportion:1.0]; |
2586 [scrollbar setTarget:scrollbar]; | |
2587 [scrollbar setAction:@selector(scrollerChanged:)]; | |
2576 [scrollbar setTag:cid]; | 2588 [scrollbar setTag:cid]; |
2577 [scrollbar setEnabled:YES]; | 2589 [scrollbar setEnabled:YES]; |
2578 return scrollbar; | 2590 return scrollbar; |
2579 } | 2591 } |
2580 | 2592 |