comparison mac/dw.m @ 659:756015085da7

Fixes for container signal handling.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 24 Feb 2011 18:59:01 +0000
parents 0502e5b6743b
children 2784e7ee8bcb
comparison
equal deleted inserted replaced
658:0502e5b6743b 659:756015085da7
82 } 82 }
83 83
84 int _event_handler(id object, NSEvent *event, int message) 84 int _event_handler(id object, NSEvent *event, int message)
85 { 85 {
86 SignalHandler *handler = _get_handler(object, message); 86 SignalHandler *handler = _get_handler(object, message);
87 NSLog(@"Event handler\n"); 87 NSLog(@"Event handler - type %d\n", message);
88 88
89 if(handler) 89 if(handler)
90 { 90 {
91 switch(message) 91 switch(message)
92 { 92 {
151 int (* API clickfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; 151 int (* API clickfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction;
152 152
153 NSLog(@"Clicked\n"); 153 NSLog(@"Clicked\n");
154 return clickfunc(object, handler->data); 154 return clickfunc(object, handler->data);
155 } 155 }
156 case 10:
157 {
158 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction;
159 char *text = (char *)event;
160 void *user = NULL;
161 LONG x,y;
162
163 dw_pointer_query_pos(&x, &y);
164
165 return containercontextfunc(handler->window, text, x, y, handler->data, user);
166 }
167 case 12:
168 {
169 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction;
170 char *text = (char *)event;
171 void *user = NULL;
172
173 return treeselectfunc(handler->window, NULL, text, handler->data, user);
174 }
156 } 175 }
157 } 176 }
158 return -1; 177 return -1;
159 } 178 }
160 179
453 -(void *)userdata; 472 -(void *)userdata;
454 -(void)setUserdata:(void *)input; 473 -(void)setUserdata:(void *)input;
455 -(float)range; 474 -(float)range;
456 -(float)visible; 475 -(float)visible;
457 -(void)setRange:(float)input1 andVisible:(float)input2; 476 -(void)setRange:(float)input1 andVisible:(float)input2;
477 -(void)changed:(id)sender;
458 @end 478 @end
459 479
460 @implementation DWScrollbar 480 @implementation DWScrollbar
461 -(void *)userdata { return userdata; } 481 -(void *)userdata { return userdata; }
462 -(void)setUserdata:(void *)input { userdata = input; } 482 -(void)setUserdata:(void *)input { userdata = input; }
463 -(float)range { return range; } 483 -(float)range { return range; }
464 -(float)visible { return visible; } 484 -(float)visible { return visible; }
465 -(void)setRange:(float)input1 andVisible:(float)input2 { range = input1; visible = input2; } 485 -(void)setRange:(float)input1 andVisible:(float)input2 { range = input1; visible = input2; }
486 -(void)changed:(id)sender { /*NSNumber *num = [NSNumber numberWithDouble:[scroller floatValue]]; NSLog([num stringValue]);*/ }
466 @end 487 @end
467 488
468 /* Subclass for a render area type */ 489 /* Subclass for a render area type */
469 @interface DWRender : NSView 490 @interface DWRender : NSView
470 { 491 {
502 { 523 {
503 void *userdata; 524 void *userdata;
504 NSMutableArray *tvcols; 525 NSMutableArray *tvcols;
505 NSMutableArray *data; 526 NSMutableArray *data;
506 NSMutableArray *types; 527 NSMutableArray *types;
507 NSMutableArray *titles; 528 NSPointerArray *titles;
508 int lastAddPoint; 529 int lastAddPoint;
509 } 530 }
510 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable; 531 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable;
511 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow; 532 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow;
512 -(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; 533 -(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex;
515 -(void)addColumn:(NSTableColumn *)input andType:(int)type; 536 -(void)addColumn:(NSTableColumn *)input andType:(int)type;
516 -(int)addRow:(NSArray *)input; 537 -(int)addRow:(NSArray *)input;
517 -(int)addRows:(int)number; 538 -(int)addRows:(int)number;
518 -(void)editCell:(id)input at:(int)row and:(int)col; 539 -(void)editCell:(id)input at:(int)row and:(int)col;
519 -(int)cellType:(int)col; 540 -(int)cellType:(int)col;
541 -(void)setRow:(int)row title:(void *)input;
542 -(void *)getRowTitle:(int)row;
520 -(int)lastAddPoint; 543 -(int)lastAddPoint;
521 -(void)clear; 544 -(void)clear;
522 -(void)setup; 545 -(void)setup;
546 -(void)selectionChanged:(id)sender;
547 -(NSMenu *)menuForEvent:(NSEvent *)event;
523 @end 548 @end
524 549
525 @implementation DWContainer 550 @implementation DWContainer
526 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable 551 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable
527 { 552 {
551 } 576 }
552 } 577 }
553 if(col != -1) 578 if(col != -1)
554 { 579 {
555 int index = (aRow * count) + col; 580 int index = (aRow * count) + col;
556 return [data objectAtIndex:index]; 581 id this = [data objectAtIndex:index];
582 return ([this isKindOfClass:[NSNull class]]) ? nil : this;
557 } 583 }
558 } 584 }
559 return nil; 585 return nil;
560 } 586 }
561 -(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex 587 -(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
581 } 607 }
582 } 608 }
583 -(void *)userdata { return userdata; } 609 -(void *)userdata { return userdata; }
584 -(void)setUserdata:(void *)input { userdata = input; } 610 -(void)setUserdata:(void *)input { userdata = input; }
585 -(void)addColumn:(NSTableColumn *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } } 611 -(void)addColumn:(NSTableColumn *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } }
586 -(int)addRow:(NSArray *)input { if(data) { [data addObjectsFromArray:input]; [titles addObject:[NSNull null]]; return [titles count]; } return 0; } 612 -(int)addRow:(NSArray *)input { if(data) { [data addObjectsFromArray:input]; [titles addPointer:NULL]; return [titles count]; } return 0; }
587 -(int)addRows:(int)number 613 -(int)addRows:(int)number
588 { 614 {
589 if(tvcols) 615 if(tvcols)
590 { 616 {
591 int count = number * [tvcols count]; 617 int count = number * [tvcols count];
597 { 623 {
598 [data addObject:[NSNull null]]; 624 [data addObject:[NSNull null]];
599 } 625 }
600 for(z=0;z<number;z++) 626 for(z=0;z<number;z++)
601 { 627 {
602 [titles addObject:[NSNull null]]; 628 [titles addPointer:NULL];
603 } 629 }
604 return [titles count]; 630 return [titles count];
605 } 631 }
606 return 0; 632 return 0;
607 } 633 }
612 int index = (row * [tvcols count]) + col; 638 int index = (row * [tvcols count]) + col;
613 [data replaceObjectAtIndex:index withObject:input]; 639 [data replaceObjectAtIndex:index withObject:input];
614 } 640 }
615 } 641 }
616 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } 642 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; }
643 -(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } }
644 -(void *)getRowTitle:(int)row { if(titles) { return [titles pointerAtIndex:row]; } return NULL; }
617 -(int)lastAddPoint { return lastAddPoint; } 645 -(int)lastAddPoint { return lastAddPoint; }
618 -(void)clear { if(data) { [data removeAllObjects]; } } 646 -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; }
619 -(void)setup { tvcols = [[NSMutableArray alloc] init]; data = [[NSMutableArray alloc] init]; types = [[NSMutableArray alloc] init]; titles = [[NSMutableArray alloc] init];} 647 -(void)setup
648 {
649 tvcols = [[NSMutableArray alloc] init];
650 data = [[NSMutableArray alloc] init];
651 types = [[NSMutableArray alloc] init];
652 titles = [NSPointerArray pointerArrayWithWeakObjects];
653 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:[self window]];
654 }
655 -(void)selectionChanged:(id)sender
656 {
657 _event_handler(self, (NSEvent *)[self getRowTitle:[self selectedRow]], 12);
658 }
659 -(NSMenu *)menuForEvent:(NSEvent *)event
660 {
661 int row;
662 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil];
663 row = [self rowAtPoint:where];
664 _event_handler(self, (NSEvent *)[self getRowTitle:row], 10);
665 return nil;
666 }
620 @end 667 @end
621 668
622 /* Subclass for a Calendar type */ 669 /* Subclass for a Calendar type */
623 @interface DWCalendar : NSDatePicker 670 @interface DWCalendar : NSDatePicker
624 { 671 {
1974 * id: An ID to be used with dw_window_from_id() or 0L. 2021 * id: An ID to be used with dw_window_from_id() or 0L.
1975 */ 2022 */
1976 HWND API dw_scrollbar_new(int vertical, ULONG id) 2023 HWND API dw_scrollbar_new(int vertical, ULONG id)
1977 { 2024 {
1978 DWScrollbar *scrollbar = [[DWScrollbar alloc] init]; 2025 DWScrollbar *scrollbar = [[DWScrollbar alloc] init];
2026 [scrollbar setTarget:scrollbar];
2027 [scrollbar setAction:@selector(changed:)];
2028 [scrollbar setRange:0.0 andVisible:0.0];
2029 [scrollbar setKnobProportion:1.0];
1979 return scrollbar; 2030 return scrollbar;
1980 } 2031 }
1981 2032
1982 /* 2033 /*
1983 * Returns the position of the scrollbar. 2034 * Returns the position of the scrollbar.
3182 * row: Zero based row of data being set. 3233 * row: Zero based row of data being set.
3183 * title: String title of the item. 3234 * title: String title of the item.
3184 */ 3235 */
3185 void API dw_container_set_row_title(void *pointer, int row, char *title) 3236 void API dw_container_set_row_title(void *pointer, int row, char *title)
3186 { 3237 {
3187 NSLog(@"dw_container_set_row_title() unimplemented\n"); 3238 DWContainer *cont = pointer;
3239 return [cont setRow:row title:title];
3188 } 3240 }
3189 3241
3190 /* 3242 /*
3191 * Sets the title of a row in the container. 3243 * Sets the title of a row in the container.
3192 * Parameters: 3244 * Parameters: