comparison mac/dw.m @ 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 fc6a626a96cc
comparison
equal deleted inserted replaced
767:9b0c22b58447 768:7a236fdcf4ba
613 613
614 /* Subclass for a entryfield type */ 614 /* Subclass for a entryfield type */
615 @interface DWEntryField : NSTextField 615 @interface DWEntryField : NSTextField
616 { 616 {
617 void *userdata; 617 void *userdata;
618 id clickDefault;
618 } 619 }
619 -(void *)userdata; 620 -(void *)userdata;
620 -(void)setUserdata:(void *)input; 621 -(void)setUserdata:(void *)input;
622 -(void)setClickDefault:(id)input;
621 @end 623 @end
622 624
623 @implementation DWEntryField 625 @implementation DWEntryField
624 -(void *)userdata { return userdata; } 626 -(void *)userdata { return userdata; }
625 -(void)setUserdata:(void *)input { userdata = input; } 627 -(void)setUserdata:(void *)input { userdata = input; }
628 -(void)setClickDefault:(id)input { clickDefault = input; }
629 -(void)keyUp:(NSEvent *)theEvent
630 {
631 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
632 if(clickDefault && vk == VK_RETURN)
633 {
634 [[self window] makeFirstResponder:clickDefault];
635 } else
636 {
637 [super keyUp:theEvent];
638 }
639 }
626 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 640 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
627 @end 641 @end
628 642
629 /* Subclass for a entryfield password type */ 643 /* Subclass for a entryfield password type */
630 @interface DWEntryFieldPassword : NSSecureTextField 644 @interface DWEntryFieldPassword : NSSecureTextField
631 { 645 {
632 void *userdata; 646 void *userdata;
647 id clickDefault;
633 } 648 }
634 -(void *)userdata; 649 -(void *)userdata;
635 -(void)setUserdata:(void *)input; 650 -(void)setUserdata:(void *)input;
651 -(void)setClickDefault:(id)input;
636 @end 652 @end
637 653
638 @implementation DWEntryFieldPassword 654 @implementation DWEntryFieldPassword
639 -(void *)userdata { return userdata; } 655 -(void *)userdata { return userdata; }
640 -(void)setUserdata:(void *)input { userdata = input; } 656 -(void)setUserdata:(void *)input { userdata = input; }
657 -(void)setClickDefault:(id)input { clickDefault = input; }
658 -(void)keyUp:(NSEvent *)theEvent
659 {
660 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
661 {
662 [[self window] makeFirstResponder:clickDefault];
663 } else
664 {
665 [super keyUp:theEvent];
666 }
667 }
641 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 668 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
642 @end 669 @end
643 670
644 /* Subclass for a Notebook control type */ 671 /* Subclass for a Notebook control type */
645 @interface DWNotebook : NSTabView 672 @interface DWNotebook : NSTabView
1331 #ifdef BUILDING_FOR_SNOW_LEOPARD 1358 #ifdef BUILDING_FOR_SNOW_LEOPARD
1332 <NSComboBoxDelegate> 1359 <NSComboBoxDelegate>
1333 #endif 1360 #endif
1334 { 1361 {
1335 void *userdata; 1362 void *userdata;
1363 id clickDefault;
1336 } 1364 }
1337 -(void *)userdata; 1365 -(void *)userdata;
1338 -(void)setUserdata:(void *)input; 1366 -(void)setUserdata:(void *)input;
1339 -(void)comboBoxSelectionDidChange:(NSNotification *)not; 1367 -(void)comboBoxSelectionDidChange:(NSNotification *)not;
1368 -(void)setClickDefault:(id)input;
1340 @end 1369 @end
1341 1370
1342 @implementation DWComboBox 1371 @implementation DWComboBox
1343 -(void *)userdata { return userdata; } 1372 -(void *)userdata { return userdata; }
1344 -(void)setUserdata:(void *)input { userdata = input; } 1373 -(void)setUserdata:(void *)input { userdata = input; }
1345 -(void)comboBoxSelectionDidChange:(NSNotification *)not { _event_handler(self, (void *)[self indexOfSelectedItem], 11); } 1374 -(void)comboBoxSelectionDidChange:(NSNotification *)not { _event_handler(self, (void *)[self indexOfSelectedItem], 11); }
1375 -(void)setClickDefault:(id)input { clickDefault = input; }
1376 -(void)keyUp:(NSEvent *)theEvent
1377 {
1378 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
1379 {
1380 [[self window] makeFirstResponder:clickDefault];
1381 } else
1382 {
1383 [super keyUp:theEvent];
1384 }
1385 }
1346 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1386 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
1347 @end 1387 @end
1348 1388
1349 /* Subclass for a stepper component of the spinbutton type */ 1389 /* Subclass for a stepper component of the spinbutton type */
1350 /* This is a bad way of doing this... but I can't get the other methods to work */ 1390 /* This is a bad way of doing this... but I can't get the other methods to work */
1389 #endif 1429 #endif
1390 { 1430 {
1391 void *userdata; 1431 void *userdata;
1392 NSTextField *textfield; 1432 NSTextField *textfield;
1393 DWStepper *stepper; 1433 DWStepper *stepper;
1434 id clickDefault;
1394 } 1435 }
1395 -(id)init; 1436 -(id)init;
1396 -(void *)userdata; 1437 -(void *)userdata;
1397 -(void)setUserdata:(void *)input; 1438 -(void)setUserdata:(void *)input;
1398 -(NSTextField *)textfield; 1439 -(NSTextField *)textfield;
1399 -(NSStepper *)stepper; 1440 -(NSStepper *)stepper;
1400 -(void)controlTextDidChange:(NSNotification *)aNotification; 1441 -(void)controlTextDidChange:(NSNotification *)aNotification;
1442 -(void)setClickDefault:(id)input;
1401 @end 1443 @end
1402 1444
1403 @implementation DWSpinButton 1445 @implementation DWSpinButton
1404 -(id)init 1446 -(id)init
1405 { 1447 {
1426 { 1468 {
1427 [stepper takeIntValueFrom:textfield]; 1469 [stepper takeIntValueFrom:textfield];
1428 [textfield takeIntValueFrom:stepper]; 1470 [textfield takeIntValueFrom:stepper];
1429 _event_handler(self, (void *)[stepper integerValue], 14); 1471 _event_handler(self, (void *)[stepper integerValue], 14);
1430 } 1472 }
1473 -(void)setClickDefault:(id)input { clickDefault = input; }
1474 -(void)keyUp:(NSEvent *)theEvent
1475 {
1476 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
1477 {
1478 [[self window] makeFirstResponder:clickDefault];
1479 }
1480 else
1481 {
1482 [super keyUp:theEvent];
1483 }
1484 }
1485 -(void)performClick:(id)sender { [textfield performClick:sender]; }
1431 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1486 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
1432 @end 1487 @end
1433 1488
1434 /* Subclass for a MDI type 1489 /* Subclass for a MDI type
1435 * This is just a box for display purposes... but it is a 1490 * This is just a box for display purposes... but it is a
5963 * Sets window to click the default dialog item when an ENTER is pressed. 6018 * Sets window to click the default dialog item when an ENTER is pressed.
5964 * Parameters: 6019 * Parameters:
5965 * window: Window (widget) to look for the ENTER press. 6020 * window: Window (widget) to look for the ENTER press.
5966 * next: Window (widget) to move to next (or click) 6021 * next: Window (widget) to move to next (or click)
5967 */ 6022 */
5968 void API dw_window_click_default(HWND window, HWND next) 6023 void API dw_window_click_default(HWND handle, HWND next)
5969 { 6024 {
5970 NSLog(@"dw_window_click_default() unimplemented\n"); 6025 id object = handle;
6026 id control = next;
6027
6028 if([object isMemberOfClass:[NSWindow class]] && [control isMemberOfClass:[DWButton class]])
6029 {
6030 NSWindow *window = object;
6031
6032 [window setDefaultButtonCell:control];
6033 }
6034 else
6035 {
6036 if([control isMemberOfClass:[DWSpinButton class]])
6037 {
6038 control = [control textfield];
6039 }
6040 else if([control isMemberOfClass:[DWComboBox class]])
6041 {
6042 /* TODO: Figure out why the combobox can't be
6043 * focused using makeFirstResponder method.
6044 */
6045 control = [control textfield];
6046 }
6047 [object setClickDefault:control];
6048 }
5971 } 6049 }
5972 6050
5973 static id _DWCapture; 6051 static id _DWCapture;
5974 6052
5975 /* 6053 /*