Mercurial > dwindows
comparison mac/dw.m @ 792:fc6a626a96cc
Initial groupbox support. Sizing of the content frame is not quite right yet.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 22 Mar 2011 21:03:35 +0000 |
parents | 7a236fdcf4ba |
children | e328c7746cda |
comparison
equal
deleted
inserted
replaced
791:4eb337e18caf | 792:fc6a626a96cc |
---|---|
454 NSColor *bgcolor; | 454 NSColor *bgcolor; |
455 } | 455 } |
456 -(id)init; | 456 -(id)init; |
457 -(void)dealloc; | 457 -(void)dealloc; |
458 -(Box *)box; | 458 -(Box *)box; |
459 -(id)contentView; | |
459 -(void *)userdata; | 460 -(void *)userdata; |
460 -(void)setUserdata:(void *)input; | 461 -(void)setUserdata:(void *)input; |
461 -(void)drawRect:(NSRect)rect; | 462 -(void)drawRect:(NSRect)rect; |
462 -(BOOL)isFlipped; | 463 -(BOOL)isFlipped; |
463 -(void)mouseDown:(NSEvent *)theEvent; | 464 -(void)mouseDown:(NSEvent *)theEvent; |
487 free(box); | 488 free(box); |
488 _remove_userdata(&root, NULL, TRUE); | 489 _remove_userdata(&root, NULL, TRUE); |
489 [super dealloc]; | 490 [super dealloc]; |
490 } | 491 } |
491 -(Box *)box { return box; } | 492 -(Box *)box { return box; } |
493 -(id)contentView { return self; } | |
492 -(void *)userdata { return userdata; } | 494 -(void *)userdata { return userdata; } |
493 -(void)setUserdata:(void *)input { userdata = input; } | 495 -(void)setUserdata:(void *)input { userdata = input; } |
494 -(void)drawRect:(NSRect)rect | 496 -(void)drawRect:(NSRect)rect |
495 { | 497 { |
496 if(bgcolor) | 498 if(bgcolor) |
519 { | 521 { |
520 bgcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(input)/255.0 green: DW_GREEN_VALUE(input)/255.0 blue: DW_BLUE_VALUE(input)/255.0 alpha: 1] retain]; | 522 bgcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(input)/255.0 green: DW_GREEN_VALUE(input)/255.0 blue: DW_BLUE_VALUE(input)/255.0 alpha: 1] retain]; |
521 } | 523 } |
522 [orig release]; | 524 [orig release]; |
523 } | 525 } |
526 @end | |
527 | |
528 /* Subclass for a group box type */ | |
529 @interface DWGroupBox : NSBox | |
530 { | |
531 void *userdata; | |
532 NSColor *bgcolor; | |
533 } | |
534 -(Box *)box; | |
535 -(void *)userdata; | |
536 -(void)setUserdata:(void *)input; | |
537 @end | |
538 | |
539 @implementation DWGroupBox | |
540 -(Box *)box { return [[self contentView] box]; } | |
541 -(void *)userdata { return userdata; } | |
542 -(void)setUserdata:(void *)input { userdata = input; } | |
524 @end | 543 @end |
525 | 544 |
526 /* Subclass for a top-level window */ | 545 /* Subclass for a top-level window */ |
527 @interface DWView : DWBox | 546 @interface DWView : DWBox |
528 { | 547 { |
1569 for(z=0;z<thisbox->count;z++) | 1588 for(z=0;z<thisbox->count;z++) |
1570 { | 1589 { |
1571 if(thisbox->items[z].type == TYPEBOX) | 1590 if(thisbox->items[z].type == TYPEBOX) |
1572 { | 1591 { |
1573 int initialx, initialy; | 1592 int initialx, initialy; |
1574 DWBox *box = thisbox->items[z].hwnd; | 1593 id box = thisbox->items[z].hwnd; |
1575 Box *tmp = [box box]; | 1594 Box *tmp = [box box]; |
1576 | 1595 |
1577 initialx = x - (*usedx); | 1596 initialx = x - (*usedx); |
1578 initialy = y - (*usedy); | 1597 initialy = y - (*usedy); |
1579 | 1598 |
1681 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); | 1700 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); |
1682 } | 1701 } |
1683 | 1702 |
1684 if(thisbox->items[z].type == TYPEBOX) | 1703 if(thisbox->items[z].type == TYPEBOX) |
1685 { | 1704 { |
1686 DWBox *box = thisbox->items[z].hwnd; | 1705 id box = thisbox->items[z].hwnd; |
1687 Box *tmp = [box box]; | 1706 Box *tmp = [box box]; |
1688 | 1707 |
1689 if(tmp) | 1708 if(tmp) |
1690 { | 1709 { |
1691 tmp->parentxratio = thisbox->items[z].xratio; | 1710 tmp->parentxratio = thisbox->items[z].xratio; |
1782 if(thisbox->items[z].vsize == SIZEEXPAND && thisbox->type == DW_HORZ) | 1801 if(thisbox->items[z].vsize == SIZEEXPAND && thisbox->type == DW_HORZ) |
1783 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); | 1802 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); |
1784 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ | 1803 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ |
1785 if(thisbox->items[z].type == TYPEBOX) | 1804 if(thisbox->items[z].type == TYPEBOX) |
1786 { | 1805 { |
1787 DWBox *box = thisbox->items[z].hwnd; | 1806 id box = thisbox->items[z].hwnd; |
1788 Box *tmp = [box box]; | 1807 Box *tmp = [box box]; |
1789 | 1808 |
1790 if(tmp) | 1809 if(tmp) |
1791 { | 1810 { |
1792 if(*depth > 0) | 1811 if(*depth > 0) |
1862 /* Special handling for notebook controls */ | 1881 /* Special handling for notebook controls */ |
1863 if([handle isMemberOfClass:[DWNotebook class]]) | 1882 if([handle isMemberOfClass:[DWNotebook class]]) |
1864 { | 1883 { |
1865 DWNotebook *notebook = (DWNotebook *)handle; | 1884 DWNotebook *notebook = (DWNotebook *)handle; |
1866 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; | 1885 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; |
1867 DWBox *view = [notepage view]; | 1886 id view = [notepage view]; |
1868 | 1887 |
1869 if(view != nil) | 1888 if(view != nil) |
1870 { | 1889 { |
1871 Box *box = [view box]; | 1890 Box *box = [view box]; |
1872 NSSize size = [view frame].size; | 1891 NSSize size = [view frame].size; |
1882 [textfield setFrameOrigin:NSMakePoint(0,0)]; | 1901 [textfield setFrameOrigin:NSMakePoint(0,0)]; |
1883 [textfield setFrameSize:NSMakeSize(size.width-20,size.height)]; | 1902 [textfield setFrameSize:NSMakeSize(size.width-20,size.height)]; |
1884 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)]; | 1903 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)]; |
1885 [stepper setFrameSize:NSMakeSize(20,size.height)]; | 1904 [stepper setFrameSize:NSMakeSize(20,size.height)]; |
1886 } | 1905 } |
1906 else if([handle isMemberOfClass:[DWGroupBox class]]) | |
1907 { | |
1908 DWGroupBox *groupbox = thisbox->items[z].hwnd; | |
1909 [groupbox sizeToFit]; | |
1910 } | |
1887 else if([handle isMemberOfClass:[DWRender class]]) | 1911 else if([handle isMemberOfClass:[DWRender class]]) |
1888 { | 1912 { |
1889 _event_handler(handle, nil, 1); | 1913 _event_handler(handle, nil, 1); |
1890 } | 1914 } |
1891 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) | 1915 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) |
2381 * pad: Number of pixels to pad around the box. | 2405 * pad: Number of pixels to pad around the box. |
2382 * title: Text to be displayined in the group outline. | 2406 * title: Text to be displayined in the group outline. |
2383 */ | 2407 */ |
2384 HWND API dw_groupbox_new(int type, int pad, char *title) | 2408 HWND API dw_groupbox_new(int type, int pad, char *title) |
2385 { | 2409 { |
2410 NSBox *groupbox = [[DWGroupBox alloc] init]; | |
2386 DWBox *box = dw_box_new(type, pad); | 2411 DWBox *box = dw_box_new(type, pad); |
2387 [box setFocusRingType:NSFocusRingTypeExterior]; | 2412 [groupbox setBorderType:NSBezelBorder]; |
2388 return box; | 2413 [groupbox setTitle:[NSString stringWithUTF8String:title]]; |
2414 [groupbox setContentView:box]; | |
2415 return groupbox; | |
2389 } | 2416 } |
2390 | 2417 |
2391 #ifndef INCOMPLETE | 2418 #ifndef INCOMPLETE |
2392 /* | 2419 /* |
2393 * Create a new scrollable Box to be packed. | 2420 * Create a new scrollable Box to be packed. |
2489 height = 1; | 2516 height = 1; |
2490 if(hsize && !width) | 2517 if(hsize && !width) |
2491 width = 1; | 2518 width = 1; |
2492 | 2519 |
2493 /* Fill in the item data appropriately */ | 2520 /* Fill in the item data appropriately */ |
2494 if([ object isKindOfClass:[ DWBox class ] ]) | 2521 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]]) |
2495 tmpitem[0].type = TYPEBOX; | 2522 tmpitem[0].type = TYPEBOX; |
2496 else | 2523 else |
2497 tmpitem[0].type = TYPEITEM; | 2524 tmpitem[0].type = TYPEITEM; |
2498 | 2525 |
2499 tmpitem[0].hwnd = item; | 2526 tmpitem[0].hwnd = item; |
2582 height = 1; | 2609 height = 1; |
2583 if(hsize && !width) | 2610 if(hsize && !width) |
2584 width = 1; | 2611 width = 1; |
2585 | 2612 |
2586 /* Fill in the item data appropriately */ | 2613 /* Fill in the item data appropriately */ |
2587 if([ object isKindOfClass:[ DWBox class ] ]) | 2614 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]]) |
2588 tmpitem[thisbox->count].type = TYPEBOX; | 2615 tmpitem[thisbox->count].type = TYPEBOX; |
2589 else | 2616 else |
2590 tmpitem[thisbox->count].type = TYPEITEM; | 2617 tmpitem[thisbox->count].type = TYPEITEM; |
2591 | 2618 |
2592 tmpitem[thisbox->count].hwnd = item; | 2619 tmpitem[thisbox->count].hwnd = item; |
6023 void API dw_window_click_default(HWND handle, HWND next) | 6050 void API dw_window_click_default(HWND handle, HWND next) |
6024 { | 6051 { |
6025 id object = handle; | 6052 id object = handle; |
6026 id control = next; | 6053 id control = next; |
6027 | 6054 |
6028 if([object isMemberOfClass:[NSWindow class]] && [control isMemberOfClass:[DWButton class]]) | 6055 if([object isMemberOfClass:[NSWindow class]]) |
6029 { | 6056 { |
6030 NSWindow *window = object; | 6057 if([control isMemberOfClass:[DWButton class]]) |
6058 { | |
6059 NSWindow *window = object; | |
6031 | 6060 |
6032 [window setDefaultButtonCell:control]; | 6061 [window setDefaultButtonCell:control]; |
6062 } | |
6033 } | 6063 } |
6034 else | 6064 else |
6035 { | 6065 { |
6036 if([control isMemberOfClass:[DWSpinButton class]]) | 6066 if([control isMemberOfClass:[DWSpinButton class]]) |
6037 { | 6067 { |