Tk Source Code

Check-in [f8f6fdfe]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Refinement of custom scrollbars on Tk-Cocoa; now more centered, virtually identical to scrollbars in Safari, etc.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core-8-5-branch
Files: files | file ages | folders
SHA1: f8f6fdfe2055d83fd0f387ae5785a87fb685aca8
User & Date: kevin_walzer 2014-12-24 07:13:40
Context
2014-12-28
05:24
Refinement of redraw during window resizing in Cocoa; refinement of button display check-in: 9746e1ca user: kevin_walzer tags: core-8-5-branch
2014-12-24
09:17
merge-mark check-in: 66f4565d user: jan.nijtmans tags: trunk
07:13
Refinement of custom scrollbars on Tk-Cocoa; now more centered, virtually identical to scrollbars in Safari, etc. check-in: f8f6fdfe user: kevin_walzer tags: core-8-5-branch
04:48
Add method to tkMacOSXButton.c check-in: afb02fa2 user: kevin_walzer tags: core-8-5-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to macosx/tkMacOSXScrlbr.c.

49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
- (void)drawArrow:(NSScrollerArrow)arrow highlightPart:(int)flag;
- (void)drawKnobSlotInRect:(NSRect)rect highlight:(BOOL)highlight;
#endif
@end

@implementation TkNSScroller


    - (void)drawRect:(NSRect)dirtyRect
    {
	NSInteger tag = [self tag];
	if ( tag != -1) {
	    TkScrollbar *scrollPtr = (TkScrollbar *)tag;
	    MacDrawable* macWin = (MacDrawable *)scrollPtr;
	    Tk_Window tkwin = scrollPtr->tkwin;
	    NSRect Tkframe = TkMacOSXGetScrollFrame(scrollPtr);
	    /* Do not draw if the widget is misplaced or unmapped. */
	    if ( NSIsEmptyRect(Tkframe) || 
		 ! macWin->winPtr->flags & TK_MAPPED ||
		 ! NSEqualRects(Tkframe, [self frame]) 
		 ) {
		return;
	    }

	    /*
	     * Do not draw if the widget is completely outside of its parent.
	     */
	    if (tkwin) {
		int parent_height = Tk_Height(Tk_Parent(tkwin));
		int widget_height = Tk_Height(tkwin);
		int y = Tk_Y(tkwin);
		if ( y > parent_height || y + widget_height < 0 ) {
		    return;
		}

		int parent_width = Tk_Width(Tk_Parent(tkwin));
		int widget_width = Tk_Width(tkwin);
		int x = Tk_X(tkwin);
		if (x > parent_width || x + widget_width < 0) {
		    return;
		}
	    }
	}
	[super drawRect:dirtyRect];
    }
    
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- (BOOL)isHorizontal {
    NSRect bounds = [self bounds];
    return NSWidth(bounds) < NSHeight (bounds);
}


- (void)drawKnob
{
    NSRect knobRect = [self rectForPart:NSScrollerKnob];
    
    if ([self isHorizontal]) {
	NSRect newRect = NSMakeRect(knobRect.origin.x, knobRect.origin.y, knobRect.size.width - 5, knobRect.size.height);
	NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:newRect xRadius:7 yRadius:7];
 
        [[NSColor lightGrayColor] set];
	[path fill];
    } else {
	NSRect newRect = NSMakeRect(knobRect.origin.x, knobRect.origin.y, knobRect.size.width, knobRect.size.height - 5);
	NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:newRect xRadius:7 yRadius:7];
 
    [[NSColor lightGrayColor] set];
	[path fill];
    }
       
}

- (void)drawArrow:(NSScrollerArrow)arrow highlightPart:(int)flag
{
    // We don't want arrows
}

- (void)drawKnobSlotInRect:(NSRect)rect highlight:(BOOL)highlight
{

}

#endif   

@end



/*
 * Declaration of Mac specific scrollbar structure.







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|









|
|
|

|
|

|
|

|
|











|

>
|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
- (void)drawArrow:(NSScrollerArrow)arrow highlightPart:(int)flag;
- (void)drawKnobSlotInRect:(NSRect)rect highlight:(BOOL)highlight;
#endif
@end

@implementation TkNSScroller


- (void)drawRect:(NSRect)dirtyRect
{
    NSInteger tag = [self tag];
    if ( tag != -1) {
	TkScrollbar *scrollPtr = (TkScrollbar *)tag;
	MacDrawable* macWin = (MacDrawable *)scrollPtr;
	Tk_Window tkwin = scrollPtr->tkwin;
	NSRect Tkframe = TkMacOSXGetScrollFrame(scrollPtr);
	/* Do not draw if the widget is misplaced or unmapped. */
	if ( NSIsEmptyRect(Tkframe) ||
	     ! macWin->winPtr->flags & TK_MAPPED ||
	     ! NSEqualRects(Tkframe, [self frame])
	     ) {
	    return;
	}

	/*
	 * Do not draw if the widget is completely outside of its parent.
	 */
	if (tkwin) {
	    int parent_height = Tk_Height(Tk_Parent(tkwin));
	    int widget_height = Tk_Height(tkwin);
	    int y = Tk_Y(tkwin);
	    if ( y > parent_height || y + widget_height < 0 ) {
		return;
	    }

	    int parent_width = Tk_Width(Tk_Parent(tkwin));
	    int widget_width = Tk_Width(tkwin);
	    int x = Tk_X(tkwin);
	    if (x > parent_width || x + widget_width < 0) {
		return;
	    }
	}
    }
    [super drawRect:dirtyRect];
}

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- (BOOL)isVertical {
    NSRect bounds = [self bounds];
    return NSWidth(bounds) < NSHeight (bounds);
}


- (void)drawKnob
{
    NSRect knobRect = [self rectForPart:NSScrollerKnob];
    
    if ([self isVertical]) {
	NSRect newRect = NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y, knobRect.size.width - 6, knobRect.size.height);
    NSBezierPath  *scrollerPath = [NSBezierPath bezierPathWithRoundedRect:newRect xRadius:4 yRadius:4];
 
    [[NSColor lightGrayColor] set];
	[scrollerPath fill];
    } else {
	NSRect newRect = NSMakeRect(knobRect.origin.x, knobRect.origin.y + 3, knobRect.size.width, knobRect.size.height - 6);
	NSBezierPath  *scrollerPath = [NSBezierPath bezierPathWithRoundedRect:newRect xRadius:4 yRadius:4];
 
        [[NSColor lightGrayColor] set];
	[scrollerPath fill];
    }
       
}

- (void)drawArrow:(NSScrollerArrow)arrow highlightPart:(int)flag
{
    // We don't want arrows
}

- (void)drawKnobSlotInRect:(NSRect)rect highlight:(BOOL)highlight
{
  
}

#endif

@end



/*
 * Declaration of Mac specific scrollbar structure.