changeset 768:7a236fdcf4ba

Fixed a typo in VK_RETURN and initial implementation of dw_window_click_default(). Currently having trouble setting focus on comboboxes but most of the rest work.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 18 Mar 2011 04:48:22 +0000
parents 9b0c22b58447
children 3afbdb036817
files dw.h mac/dw.m
diffstat 2 files changed, 82 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Fri Mar 18 03:38:24 2011 +0000
+++ b/dw.h	Fri Mar 18 04:48:22 2011 +0000
@@ -401,7 +401,7 @@
 #define VK_BACK                  0x7F
 #define VK_TAB                   0x09
 #define VK_CLEAR                 71
-#define VK_RETURN                3
+#define VK_RETURN                13
 #define VK_MENU                  0xF735 /* NSMenuFunctionKey */
 #define VK_PAUSE                 0xF730 /* NSPauseFunctionKey */
 #define VK_CAPITAL               57
--- a/mac/dw.m	Fri Mar 18 03:38:24 2011 +0000
+++ b/mac/dw.m	Fri Mar 18 04:48:22 2011 +0000
@@ -615,14 +615,28 @@
 @interface DWEntryField : NSTextField
 {
     void *userdata;
+    id clickDefault;
 }
 -(void *)userdata;
 -(void)setUserdata:(void *)input;
+-(void)setClickDefault:(id)input;
 @end
 
 @implementation DWEntryField
 -(void *)userdata { return userdata; }
 -(void)setUserdata:(void *)input { userdata = input; }
+-(void)setClickDefault:(id)input { clickDefault = input; }
+-(void)keyUp:(NSEvent *)theEvent 
+{ 
+    unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
+    if(clickDefault && vk == VK_RETURN)
+    { 
+        [[self window] makeFirstResponder:clickDefault]; 
+    } else 
+    { 
+        [super keyUp:theEvent]; 
+    } 
+}
 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
 @end
 
@@ -630,14 +644,27 @@
 @interface DWEntryFieldPassword : NSSecureTextField
 {
     void *userdata;
+    id clickDefault;
 }
 -(void *)userdata;
 -(void)setUserdata:(void *)input;
+-(void)setClickDefault:(id)input;
 @end
 
 @implementation DWEntryFieldPassword
 -(void *)userdata { return userdata; }
 -(void)setUserdata:(void *)input { userdata = input; }
+-(void)setClickDefault:(id)input { clickDefault = input; }
+-(void)keyUp:(NSEvent *)theEvent 
+{ 
+    if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
+    { 
+        [[self window] makeFirstResponder:clickDefault]; 
+    } else 
+    { 
+        [super keyUp:theEvent]; 
+    } 
+}
 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
 @end
 
@@ -1333,16 +1360,29 @@
 #endif
 {
     void *userdata;
+    id clickDefault;
 }
 -(void *)userdata;
 -(void)setUserdata:(void *)input;
 -(void)comboBoxSelectionDidChange:(NSNotification *)not;
+-(void)setClickDefault:(id)input;
 @end
 
 @implementation DWComboBox
 -(void *)userdata { return userdata; }
 -(void)setUserdata:(void *)input { userdata = input; }
 -(void)comboBoxSelectionDidChange:(NSNotification *)not { _event_handler(self, (void *)[self indexOfSelectedItem], 11); }
+-(void)setClickDefault:(id)input { clickDefault = input; }
+-(void)keyUp:(NSEvent *)theEvent 
+{ 
+    if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
+    { 
+        [[self window] makeFirstResponder:clickDefault]; 
+    } else 
+    { 
+        [super keyUp:theEvent]; 
+    } 
+}
 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
 @end
 
@@ -1391,6 +1431,7 @@
     void *userdata;
     NSTextField *textfield;
     DWStepper *stepper;
+    id clickDefault;
 }
 -(id)init;
 -(void *)userdata;
@@ -1398,6 +1439,7 @@
 -(NSTextField *)textfield;
 -(NSStepper *)stepper;
 -(void)controlTextDidChange:(NSNotification *)aNotification;
+-(void)setClickDefault:(id)input;
 @end
 
 @implementation DWSpinButton
@@ -1428,6 +1470,19 @@
     [textfield takeIntValueFrom:stepper];
     _event_handler(self, (void *)[stepper integerValue], 14);
 }
+-(void)setClickDefault:(id)input { clickDefault = input; }
+-(void)keyUp:(NSEvent *)theEvent 
+{ 
+    if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
+    { 
+        [[self window] makeFirstResponder:clickDefault]; 
+    } 
+    else 
+    { 
+        [super keyUp:theEvent]; 
+    } 
+}
+-(void)performClick:(id)sender { [textfield performClick:sender]; }
 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
 @end
 
@@ -5965,9 +6020,32 @@
  *         window: Window (widget) to look for the ENTER press.
  *         next: Window (widget) to move to next (or click)
  */
-void API dw_window_click_default(HWND window, HWND next)
-{
-    NSLog(@"dw_window_click_default() unimplemented\n");
+void API dw_window_click_default(HWND handle, HWND next)
+{
+    id object = handle;
+    id control = next;
+    
+    if([object isMemberOfClass:[NSWindow class]] && [control isMemberOfClass:[DWButton class]])
+    {
+        NSWindow *window = object;
+        
+        [window setDefaultButtonCell:control];
+    }
+    else
+    {
+        if([control isMemberOfClass:[DWSpinButton class]])
+        {
+            control = [control textfield];
+        }
+        else if([control isMemberOfClass:[DWComboBox class]])
+        {
+            /* TODO: Figure out why the combobox can't be
+             * focused using makeFirstResponder method.
+             */
+            control = [control textfield];
+        }
+        [object setClickDefault:control];
+    }
 }
 
 static id _DWCapture;