summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXScrlbr.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2015-04-09 02:00:49 (GMT)
committerKevin Walzer <kw@codebykevin.com>2015-04-09 02:00:49 (GMT)
commit69e749839382af95c02bdb100c49402eb6b926ae (patch)
treee0d98826c7a37d1a2c4e79ce3376a5f0054ec088 /macosx/tkMacOSXScrlbr.c
parent9f2f06f947fdb1bc1d9c47da80db1ec6728b32a2 (diff)
downloadtk-69e749839382af95c02bdb100c49402eb6b926ae.zip
tk-69e749839382af95c02bdb100c49402eb6b926ae.tar.gz
tk-69e749839382af95c02bdb100c49402eb6b926ae.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.c84
1 files changed, 47 insertions, 37 deletions
diff --git a/macosx/tkMacOSXScrlbr.c b/macosx/tkMacOSXScrlbr.c
index bdb76af..37178ed 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;
+ TkWindow *winPtr = (TkWindow *) tkwin;
+ TkMacOSXDrawingContext dc;
+ scrollPtr->flags &= ~REDRAW_PENDING;
- if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
+ 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.*/
+ /*
+ * 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;
+ 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;
+ }
+ if (y < fieldlength + arrowSize) {
+ return TOP_ARROW;
}
- return BOTTOM_GAP;
+ 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.
@@ -432,7 +437,6 @@ static void
UpdateControlValues(
TkScrollbar *scrollPtr) /* Scrollbar data struct. */
{
-
Tk_Window tkwin = scrollPtr->tkwin;
MacDrawable *macWin = (MacDrawable *) Tk_WindowId(scrollPtr->tkwin);
double dViewSize;
@@ -462,8 +466,10 @@ UpdateControlValues(
*/
info.bounds = contrlRect;
- if (!scrollPtr->vertical) {
- info.attributes |= kThemeTrackHorizontal;
+ if (scrollPtr->vertical) {
+ info.attributes &= ~kThemeTrackHorizontal;
+ } else {
+ info.attributes |= kThemeTrackHorizontal;
}
/*
@@ -484,7 +490,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;
}