summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXScrlbr.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2015-04-09 02:00:59 (GMT)
committerKevin Walzer <kw@codebykevin.com>2015-04-09 02:00:59 (GMT)
commitd10216afc1dcddd76f93bcdbb6e87bdca8dc7453 (patch)
tree3d2c1b4ec2054fbe9fd8a6a5cd948ad5cc6d8c71 /macosx/tkMacOSXScrlbr.c
parentf801eafc556ad7c6648d5da223a6563c99b998ca (diff)
downloadtk-d10216afc1dcddd76f93bcdbb6e87bdca8dc7453.zip
tk-d10216afc1dcddd76f93bcdbb6e87bdca8dc7453.tar.gz
tk-d10216afc1dcddd76f93bcdbb6e87bdca8dc7453.tar.bz2
Re-working of internal Cocoa widget drawing routines, especially when resizing; fix rendering of scrollbar when resized or clipped; cleanup of button metrics; thanks to Marc Culler for extensive patches
Diffstat (limited to 'macosx/tkMacOSXScrlbr.c')
-rw-r--r--macosx/tkMacOSXScrlbr.c89
1 files changed, 50 insertions, 39 deletions
diff --git a/macosx/tkMacOSXScrlbr.c b/macosx/tkMacOSXScrlbr.c
index bc93b79..7dde501 100644
--- a/macosx/tkMacOSXScrlbr.c
+++ b/macosx/tkMacOSXScrlbr.c
@@ -26,6 +26,7 @@
#define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum))
#endif /* __LP64__ */
+#define MOUNTAIN_LION_STYLE (NSAppKitVersionNumber < 1138)
/*
* Declaration of Mac specific scrollbar structure.
@@ -80,7 +81,6 @@ static void ScrollbarEventProc(ClientData clientData, XEvent *eventPtr);
static int ScrollbarPress(TkScrollbar *scrollPtr, XEvent *eventPtr);
static void UpdateControlValues(TkScrollbar *scrollPtr);
-
/*
*----------------------------------------------------------------------
*
@@ -136,27 +136,26 @@ TkpDisplayScrollbar(
{
register TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
register Tk_Window tkwin = scrollPtr->tkwin;
-
-
- if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
+ TkWindow *winPtr = (TkWindow *) tkwin;
+ TkMacOSXDrawingContext dc;
+
+ scrollPtr->flags &= ~REDRAW_PENDING;
+
+ if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
return;
}
- TkWindow *winPtr = (TkWindow *) tkwin;
MacDrawable *macWin = (MacDrawable *) winPtr->window;
- TkMacOSXDrawingContext dc;
NSView *view = TkMacOSXDrawableView(macWin);
+ if (!view ||
+ macWin->flags & TK_DO_NOT_DRAW ||
+ !TkMacOSXSetupDrawingContext((Drawable) macWin, NULL, 1, &dc)) {
+ return;
+ }
+
CGFloat viewHeight = [view bounds].size.height;
CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0,
.ty = viewHeight};
-
-
- scrollPtr->flags &= ~REDRAW_PENDING;
- if (!scrollPtr->tkwin || !Tk_IsMapped(tkwin) || !view ||
- !TkMacOSXSetupDrawingContext((Drawable) macWin, NULL, 1, &dc)) {
- return;
- }
-
CGContextConcatCTM(dc.context, t);
/*Draw Unix-style scroll trough to provide rect for native scrollbar.*/
@@ -173,7 +172,6 @@ TkpDisplayScrollbar(
(Pixmap) macWin);
}
-
Tk_Draw3DRectangle(tkwin, (Pixmap) macWin, scrollPtr->bgBorder,
scrollPtr->highlightWidth, scrollPtr->highlightWidth,
Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
@@ -186,15 +184,11 @@ TkpDisplayScrollbar(
/*Update values and draw in native rect.*/
UpdateControlValues(scrollPtr);
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
- if (scrollPtr->vertical) {
- HIThemeDrawTrack (&info, 0, dc.context, kHIThemeOrientationNormal);
- } else {
+ if (MOUNTAIN_LION_STYLE) {
HIThemeDrawTrack (&info, 0, dc.context, kHIThemeOrientationInverted);
+ } else {
+ HIThemeDrawTrack (&info, 0, dc.context, kHIThemeOrientationNormal);
}
-#else
- HIThemeDrawTrack (&info, 0, dc.context, kHIThemeOrientationNormal);
-#endif
TkMacOSXRestoreDrawingContext(&dc);
scrollPtr->flags &= ~REDRAW_PENDING;
@@ -265,11 +259,12 @@ TkpComputeScrollbarGeometry(
if (scrollPtr->sliderLast > fieldLength) {
scrollPtr->sliderLast = fieldLength;
}
- scrollPtr->sliderFirst += scrollPtr->inset +
+ if (!(MOUNTAIN_LION_STYLE)) {
+ scrollPtr->sliderFirst += scrollPtr->inset +
metrics[variant].topArrowHeight;
- scrollPtr->sliderLast += scrollPtr->inset +
+ scrollPtr->sliderLast += scrollPtr->inset +
metrics[variant].bottomArrowHeight;
-
+ }
/*
* Register the desired geometry for the window (leave enough space
* for the two arrows plus a minimum-size slider, plus border around
@@ -370,21 +365,29 @@ TkpScrollbarPosition(
int x, int y) /* Coordinates within scrollPtr's window. */
{
- /*Using code from tkUnixScrlbr.c because Unix scroll bindings are driving the display at the script level. All the Mac scrollbar has to do is re-draw itself.*/
-
- int length, width, tmp;
+ /*
+ * Using code from tkUnixScrlbr.c because Unix scroll bindings are
+ * driving the display at the script level. All the Mac scrollbar
+ * has to do is re-draw itself.
+ */
+
+ int length, fieldlength, width, tmp;
register const int inset = scrollPtr->inset;
+ register const int arrowSize = scrollPtr->arrowLength + inset;
if (scrollPtr->vertical) {
length = Tk_Height(scrollPtr->tkwin);
+ fieldlength = length - 2 * arrowSize;
width = Tk_Width(scrollPtr->tkwin);
} else {
tmp = x;
x = y;
y = tmp;
length = Tk_Width(scrollPtr->tkwin);
+ fieldlength = length - 2 * arrowSize;
width = Tk_Height(scrollPtr->tkwin);
}
+ fieldlength = fieldlength < 0 ? 0 : fieldlength;
if (x<inset || x>=width-inset || y<inset || y>=length-inset) {
return OUTSIDE;
@@ -395,19 +398,19 @@ TkpScrollbarPosition(
* TkpDisplayScrollbar. Be sure to keep the two consistent.
*/
- if (y < inset + scrollPtr->arrowLength) {
- return TOP_ARROW;
- }
if (y < scrollPtr->sliderFirst) {
return TOP_GAP;
}
if (y < scrollPtr->sliderLast) {
return SLIDER;
}
- if (y >= length - (scrollPtr->arrowLength + inset)) {
- return BOTTOM_ARROW;
+ if (y < fieldlength){
+ return BOTTOM_GAP;
}
- return BOTTOM_GAP;
+ if (y < fieldlength + arrowSize) {
+ return TOP_ARROW;
+ }
+ return BOTTOM_ARROW;
}
/*
@@ -415,9 +418,11 @@ TkpScrollbarPosition(
*
* UpdateControlValues --
*
- * This procedure updates the Macintosh scrollbar control to display the
- * values defined by the Tk scrollbar. This is the key interface to the Mac-native * scrollbar; the Unix bindings drive scrolling in the Tk window and all the Mac
- * scrollbar has to do is redraw itself.
+ * This procedure updates the Macintosh scrollbar control to
+ * display the values defined by the Tk scrollbar. This is the
+ * key interface to the Mac-native * scrollbar; the Unix bindings
+ * drive scrolling in the Tk window and all the Mac scrollbar has
+ * to do is redraw itself.
*
* Results:
* None.
@@ -462,8 +467,10 @@ UpdateControlValues(
*/
info.bounds = contrlRect;
- if (!scrollPtr->vertical) {
- info.attributes |= kThemeTrackHorizontal;
+ if (scrollPtr->vertical) {
+ info.attributes &= ~kThemeTrackHorizontal;
+ } else {
+ info.attributes |= kThemeTrackHorizontal;
}
/*
@@ -484,7 +491,11 @@ UpdateControlValues(
factor - dViewSize;
info.trackInfo.scrollbar.viewsize = dViewSize;
if (scrollPtr->vertical) {
+ if (MOUNTAIN_LION_STYLE) {
+ info.value = factor * scrollPtr->firstFraction;
+ } else {
info.value = info.max - factor * scrollPtr->firstFraction;
+ }
} else {
info.value = MIN_SCROLLBAR_VALUE + factor * scrollPtr->firstFraction;
}