Mercurial > dwindows
comparison mac/dw.m @ 837:89d4bad9c96e
Initial attempt at implementing the scrollbox on the Mac.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 29 Mar 2011 01:25:45 +0000 |
parents | 168b9db65825 |
children | 8e0405435d0a |
comparison
equal
deleted
inserted
replaced
836:28f9810dfebc | 837:89d4bad9c96e |
---|---|
688 -(void *)userdata; | 688 -(void *)userdata; |
689 -(void)setUserdata:(void *)input; | 689 -(void)setUserdata:(void *)input; |
690 @end | 690 @end |
691 | 691 |
692 @implementation DWPercent | 692 @implementation DWPercent |
693 -(void *)userdata { return userdata; } | |
694 -(void)setUserdata:(void *)input { userdata = input; } | |
695 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | |
696 @end | |
697 | |
698 /* Subclass for a scrollbox type */ | |
699 @interface DWScrollBox : NSScrollView | |
700 { | |
701 void *userdata; | |
702 } | |
703 -(void *)userdata; | |
704 -(void)setUserdata:(void *)input; | |
705 @end | |
706 | |
707 @implementation DWScrollBox | |
693 -(void *)userdata { return userdata; } | 708 -(void *)userdata { return userdata; } |
694 -(void)setUserdata:(void *)input { userdata = input; } | 709 -(void)setUserdata:(void *)input { userdata = input; } |
695 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 710 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
696 @end | 711 @end |
697 | 712 |
2035 Box *box = [view box]; | 2050 Box *box = [view box]; |
2036 NSSize size = [view frame].size; | 2051 NSSize size = [view frame].size; |
2037 _do_resize(box, size.width, size.height); | 2052 _do_resize(box, size.width, size.height); |
2038 } | 2053 } |
2039 } | 2054 } |
2055 /* Handle laying out scrollviews... if required space is less | |
2056 * than available space, then expand. Otherwise use required space. | |
2057 */ | |
2058 else if([handle isMemberOfClass:[DWScrollBox class]]) | |
2059 { | |
2060 int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0; | |
2061 DWScrollBox *scrollbox = (DWScrollBox *)handle; | |
2062 DWBox *contentbox = [scrollbox documentView]; | |
2063 Box *thisbox = [contentbox box]; | |
2064 NSSize contentsize = [scrollbox contentSize]; | |
2065 | |
2066 /* Get the required space for the box */ | |
2067 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady); | |
2068 | |
2069 if(contentsize.width < usedx) | |
2070 { | |
2071 contentsize.width = usedx; | |
2072 } | |
2073 if(contentsize.height < usedy) | |
2074 { | |
2075 contentsize.height = usedy; | |
2076 } | |
2077 [contentbox setFrameSize:contentsize]; | |
2078 | |
2079 /* Layout the content of the scrollbox */ | |
2080 _do_resize(thisbox, contentsize.width, contentsize.height); | |
2081 } | |
2040 /* Special handling for spinbutton controls */ | 2082 /* Special handling for spinbutton controls */ |
2041 else if([handle isMemberOfClass:[DWSpinButton class]]) | 2083 else if([handle isMemberOfClass:[DWSpinButton class]]) |
2042 { | 2084 { |
2043 DWSpinButton *spinbutton = (DWSpinButton *)handle; | 2085 DWSpinButton *spinbutton = (DWSpinButton *)handle; |
2044 NSTextField *textfield = [spinbutton textfield]; | 2086 NSTextField *textfield = [spinbutton textfield]; |
2574 * pad: Number of pixels to pad around the box. | 2616 * pad: Number of pixels to pad around the box. |
2575 * This works fine under GTK+, but is incomplete on other platforms | 2617 * This works fine under GTK+, but is incomplete on other platforms |
2576 */ | 2618 */ |
2577 HWND API dw_scrollbox_new( int type, int pad ) | 2619 HWND API dw_scrollbox_new( int type, int pad ) |
2578 { | 2620 { |
2579 DWBox *box = dw_box_new(type, pad); | 2621 DWScrollBox *scrollbox = [[DWScrollBox alloc] init]; |
2580 [box setFocusRingType:NSFocusRingTypeExterior]; | 2622 DWBox *box = dw_box_new(type, pad); |
2581 NSLog(@"dw_scrollbox_new() unimplemented\n"); | 2623 [scrollbox setHasVerticalScroller:YES]; |
2582 return box; | 2624 [scrollbox setHasHorizontalScroller:YES]; |
2625 [scrollbox setBorderType:NSNoBorder]; | |
2626 [scrollbox setDocumentView:box]; | |
2627 return scrollbox; | |
2583 } | 2628 } |
2584 | 2629 |
2585 /* | 2630 /* |
2586 * Returns the position of the scrollbar in the scrollbox | 2631 * Returns the position of the scrollbar in the scrollbox |
2587 * Parameters: | 2632 * Parameters: |
2635 if([ object isKindOfClass:[ NSWindow class ] ]) | 2680 if([ object isKindOfClass:[ NSWindow class ] ]) |
2636 { | 2681 { |
2637 NSWindow *window = box; | 2682 NSWindow *window = box; |
2638 view = [window contentView]; | 2683 view = [window contentView]; |
2639 } | 2684 } |
2685 else if([ object isMemberOfClass:[ DWScrollBox class ] ]) | |
2686 { | |
2687 DWScrollBox *scrollbox = box; | |
2688 view = [scrollbox documentView]; | |
2689 } | |
2640 | 2690 |
2641 thisbox = [view box]; | 2691 thisbox = [view box]; |
2642 thisitem = thisbox->items; | 2692 thisitem = thisbox->items; |
2643 object = item; | 2693 object = item; |
2644 | 2694 |
2737 /* Query the objects */ | 2787 /* Query the objects */ |
2738 if([ object isKindOfClass:[ NSWindow class ] ]) | 2788 if([ object isKindOfClass:[ NSWindow class ] ]) |
2739 { | 2789 { |
2740 NSWindow *window = box; | 2790 NSWindow *window = box; |
2741 view = [window contentView]; | 2791 view = [window contentView]; |
2792 } | |
2793 else if([ object isMemberOfClass:[ DWScrollBox class ] ]) | |
2794 { | |
2795 DWScrollBox *scrollbox = box; | |
2796 view = [scrollbox documentView]; | |
2742 } | 2797 } |
2743 | 2798 |
2744 thisbox = [view box]; | 2799 thisbox = [view box]; |
2745 thisitem = thisbox->items; | 2800 thisitem = thisbox->items; |
2746 object = item; | 2801 object = item; |
4979 * DW_SCROLL_BOTTOM. (rows is ignored for last two) | 5034 * DW_SCROLL_BOTTOM. (rows is ignored for last two) |
4980 * rows: The number of rows to be scrolled. | 5035 * rows: The number of rows to be scrolled. |
4981 */ | 5036 */ |
4982 void API dw_container_scroll(HWND handle, int direction, long rows) | 5037 void API dw_container_scroll(HWND handle, int direction, long rows) |
4983 { | 5038 { |
5039 #if 0 | |
5040 DWContainer *cont = handle; | |
5041 NSScrollView *sv = [cont scrollview]; | |
5042 #endif | |
4984 NSLog(@"dw_container_scroll() unimplemented\n"); | 5043 NSLog(@"dw_container_scroll() unimplemented\n"); |
4985 } | 5044 } |
4986 | 5045 |
4987 /* | 5046 /* |
4988 * Starts a new query of a container. | 5047 * Starts a new query of a container. |