changeset 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
files mac/dw.m
diffstat 1 files changed, 43 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Tue Mar 01 14:56:48 2011 +0000
+++ b/mac/dw.m	Wed Mar 02 02:29:33 2011 +0000
@@ -798,17 +798,48 @@
 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
 @end
 
+/* Subclass for a stepper component of the spinbutton type */
+/* This is a bad way of doing this... but I can't get the other methods to work */
+@interface DWStepper : NSStepper 
+{ 
+    id textfield;
+}
+-(void)setTextfield:(id)input;
+-(id)textfield;
+-(void)mouseDown:(NSEvent *)event;
+-(void)mouseUp:(NSEvent *)event;
+@end
+
+@implementation DWStepper
+-(void)setTextfield:(id)input { textfield = input; }
+-(id)textfield { return textfield; }
+-(void)mouseDown:(NSEvent *)event
+{
+    [super mouseDown:event];
+    if([[NSApp currentEvent] type] == NSLeftMouseUp) 
+    {
+        [textfield takeIntValueFrom:self]; 
+    }
+}
+-(void)mouseUp:(NSEvent *)event
+{
+    [textfield takeIntValueFrom:self]; 
+}
+@end
+
 /* Subclass for a Spinbutton type */
-@interface DWSpinButton : NSView{
+@interface DWSpinButton : NSView <NSTextFieldDelegate>
+{
 	void *userdata;
     NSTextField *textfield;
-    NSStepper *stepper;
+    DWStepper *stepper;
 }
 -(id)init;
 -(void *)userdata;
 -(void)setUserdata:(void *)input;
 -(NSTextField *)textfield;
 -(NSStepper *)stepper;
+-(void)controlTextDidChange:(NSNotification *)aNotification;
 @end
 
 @implementation DWSpinButton
@@ -816,14 +847,15 @@
 {
     self = [super init];
     
-    if (self) 
+    if(self) 
     {
         textfield = [[NSTextField alloc] init];
         [self addSubview:textfield];
-        stepper = [[NSStepper alloc] init];
+        stepper = [[DWStepper alloc] init];
         [self addSubview:stepper];
+        [stepper setTextfield:textfield];
         [textfield takeIntValueFrom:stepper];
-        [stepper takeIntValueFrom:textfield];
+        [textfield setDelegate:self];
     }
     return self;
 }
@@ -831,6 +863,10 @@
 -(void)setUserdata:(void *)input { userdata = input; }
 -(NSTextField *)textfield { return textfield; }
 -(NSStepper *)stepper { return stepper; }
+-(void)controlTextDidChange:(NSNotification *)aNotification
+{
+    [stepper takeIntValueFrom:textfield];
+}
 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
 @end
 
@@ -2062,7 +2098,9 @@
 {
     DWSpinButton *spinbutton = handle;
 	NSStepper *stepper = [spinbutton stepper];
+    NSTextField *textfield = [spinbutton textfield];
     [stepper setIntValue:(int)position];
+    [textfield takeIntValueFrom:stepper];
 }
 
 /*