Tk Source Code

Artifact [1755aa20]
Login

Artifact 1755aa20ae4f8423ca2d9dfeb8140d8ffb3a327b3de4746fafab2d3531bf20e2:

Attachment "scrollerPagingBehaviorCmd.diff" to ticket [76588c85] added by chrstphrchvz 2020-05-17 15:30:49.
diff --git library/ttk/scrollbar.tcl library/ttk/scrollbar.tcl
index efcf3a1c6..26d008ce8 100644
--- library/ttk/scrollbar.tcl
+++ library/ttk/scrollbar.tcl
@@ -9,7 +9,24 @@ namespace eval ttk::scrollbar {
     # State(first)	-- value of -first at start of drag.
 }
 
-bind TScrollbar <ButtonPress-1> 	{ ttk::scrollbar::Press %W %x %y }
+if {[tk windowingsystem] ne "aqua"} {
+    bind TScrollbar <ButtonPress-1>	{ ttk::scrollbar::Press %W %x %y }
+} else {
+    bind TScrollbar <ButtonPress-1> {
+	if {[::tk::mac::scrollerPagingBehavior]} {
+	    ttk::scrollbar::Jump %W %x %y
+	} else {
+	    ttk::scrollbar::Press %W %x %y
+	}
+    }
+    bind TScrollbar <Option-ButtonPress-1> {
+	if {[::tk::mac::scrollerPagingBehavior]} {
+	    ttk::scrollbar::Press %W %x %y
+	} else {
+	    ttk::scrollbar::Jump %W %x %y
+	}
+    }
+}
 bind TScrollbar <B1-Motion>		{ ttk::scrollbar::Drag %W %x %y }
 bind TScrollbar <ButtonRelease-1>	{ ttk::scrollbar::Release %W %x %y }
 
diff --git macosx/tkMacOSXInit.c macosx/tkMacOSXInit.c
index b13b8553b..b36be0bc8 100644
--- macosx/tkMacOSXInit.c
+++ macosx/tkMacOSXInit.c
@@ -418,6 +418,43 @@ TkpInit(
     Tcl_CreateObjCommand(interp, "::tk::mac::iconBitmap",
 	    TkMacOSXIconBitmapObjCmd, NULL, NULL);
     Tcl_CreateObjCommand(interp, "::tk::mac::GetAppPath", TkMacOSXGetAppPath, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "::tk::mac::scrollerPagingBehavior",
+	    TkMacOSXScrollerPagingBehaviorObjCmd, NULL, NULL);
+    return TCL_OK;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TkMacOSXScrollerPagingBehaviorObjCmd --
+ *
+ *	Retrieve whether left-clicking a scrollbar (without holding the
+ *	Option key) should jump by page (0) or jump to the spot clicked (1),
+ *	based on what is set in	System Preferences > General.
+ *
+ * Results:
+ *	A standard Tcl result.
+ *
+ * Side effects:
+ *	None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TkMacOSXScrollerPagingBehaviorObjCmd(
+    ClientData clientData,
+    Tcl_Interp *interp,
+    int objc,
+    Tcl_Obj *const objv[])
+{
+    if (objc > 1) {
+	Tcl_WrongNumArgs(interp, 1, objv, NULL);
+	return TCL_ERROR;
+    }
+    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
+	    [[NSUserDefaults standardUserDefaults]
+	     boolForKey:@"AppleScrollerPagingBehavior"]));
     return TCL_OK;
 }