Mercurial > dwindows
comparison mac/dw.m @ 679:d2d7d1802af4
Implemented a rather hacky fix for the spinbutton issues. The stepper control is really poorly
designed. The better fix would be to use a shared property but I can't figure out how to do
that programmatically. So for the time being using this hacky method that actually works.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 02 Mar 2011 02:29:33 +0000 |
parents | 0ec8edbb82cf |
children | db315779a283 |
comparison
equal
deleted
inserted
replaced
678:0ec8edbb82cf | 679:d2d7d1802af4 |
---|---|
796 -(void *)userdata { return userdata; } | 796 -(void *)userdata { return userdata; } |
797 -(void)setUserdata:(void *)input { userdata = input; } | 797 -(void)setUserdata:(void *)input { userdata = input; } |
798 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 798 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
799 @end | 799 @end |
800 | 800 |
801 /* Subclass for a stepper component of the spinbutton type */ | |
802 /* This is a bad way of doing this... but I can't get the other methods to work */ | |
803 @interface DWStepper : NSStepper | |
804 { | |
805 id textfield; | |
806 } | |
807 -(void)setTextfield:(id)input; | |
808 -(id)textfield; | |
809 -(void)mouseDown:(NSEvent *)event; | |
810 -(void)mouseUp:(NSEvent *)event; | |
811 @end | |
812 | |
813 @implementation DWStepper | |
814 -(void)setTextfield:(id)input { textfield = input; } | |
815 -(id)textfield { return textfield; } | |
816 -(void)mouseDown:(NSEvent *)event | |
817 { | |
818 [super mouseDown:event]; | |
819 if([[NSApp currentEvent] type] == NSLeftMouseUp) | |
820 { | |
821 [textfield takeIntValueFrom:self]; | |
822 } | |
823 } | |
824 -(void)mouseUp:(NSEvent *)event | |
825 { | |
826 [textfield takeIntValueFrom:self]; | |
827 } | |
828 @end | |
829 | |
801 /* Subclass for a Spinbutton type */ | 830 /* Subclass for a Spinbutton type */ |
802 @interface DWSpinButton : NSView{ | 831 @interface DWSpinButton : NSView <NSTextFieldDelegate> |
832 { | |
803 void *userdata; | 833 void *userdata; |
804 NSTextField *textfield; | 834 NSTextField *textfield; |
805 NSStepper *stepper; | 835 DWStepper *stepper; |
806 } | 836 } |
807 -(id)init; | 837 -(id)init; |
808 -(void *)userdata; | 838 -(void *)userdata; |
809 -(void)setUserdata:(void *)input; | 839 -(void)setUserdata:(void *)input; |
810 -(NSTextField *)textfield; | 840 -(NSTextField *)textfield; |
811 -(NSStepper *)stepper; | 841 -(NSStepper *)stepper; |
842 -(void)controlTextDidChange:(NSNotification *)aNotification; | |
812 @end | 843 @end |
813 | 844 |
814 @implementation DWSpinButton | 845 @implementation DWSpinButton |
815 -(id)init | 846 -(id)init |
816 { | 847 { |
817 self = [super init]; | 848 self = [super init]; |
818 | 849 |
819 if (self) | 850 if(self) |
820 { | 851 { |
821 textfield = [[NSTextField alloc] init]; | 852 textfield = [[NSTextField alloc] init]; |
822 [self addSubview:textfield]; | 853 [self addSubview:textfield]; |
823 stepper = [[NSStepper alloc] init]; | 854 stepper = [[DWStepper alloc] init]; |
824 [self addSubview:stepper]; | 855 [self addSubview:stepper]; |
856 [stepper setTextfield:textfield]; | |
825 [textfield takeIntValueFrom:stepper]; | 857 [textfield takeIntValueFrom:stepper]; |
826 [stepper takeIntValueFrom:textfield]; | 858 [textfield setDelegate:self]; |
827 } | 859 } |
828 return self; | 860 return self; |
829 } | 861 } |
830 -(void *)userdata { return userdata; } | 862 -(void *)userdata { return userdata; } |
831 -(void)setUserdata:(void *)input { userdata = input; } | 863 -(void)setUserdata:(void *)input { userdata = input; } |
832 -(NSTextField *)textfield { return textfield; } | 864 -(NSTextField *)textfield { return textfield; } |
833 -(NSStepper *)stepper { return stepper; } | 865 -(NSStepper *)stepper { return stepper; } |
866 -(void)controlTextDidChange:(NSNotification *)aNotification | |
867 { | |
868 [stepper takeIntValueFrom:textfield]; | |
869 } | |
834 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 870 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
835 @end | 871 @end |
836 | 872 |
837 /* Subclass for a test object type */ | 873 /* Subclass for a test object type */ |
838 @interface DWObject : NSObject {} | 874 @interface DWObject : NSObject {} |
2060 */ | 2096 */ |
2061 void API dw_spinbutton_set_pos(HWND handle, long position) | 2097 void API dw_spinbutton_set_pos(HWND handle, long position) |
2062 { | 2098 { |
2063 DWSpinButton *spinbutton = handle; | 2099 DWSpinButton *spinbutton = handle; |
2064 NSStepper *stepper = [spinbutton stepper]; | 2100 NSStepper *stepper = [spinbutton stepper]; |
2101 NSTextField *textfield = [spinbutton textfield]; | |
2065 [stepper setIntValue:(int)position]; | 2102 [stepper setIntValue:(int)position]; |
2103 [textfield takeIntValueFrom:stepper]; | |
2066 } | 2104 } |
2067 | 2105 |
2068 /* | 2106 /* |
2069 * Sets the spinbutton limits. | 2107 * Sets the spinbutton limits. |
2070 * Parameters: | 2108 * Parameters: |