From 332cb289af703fd2a5c4f0b33518873b2247ca88 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Sun, 5 Nov 2017 23:22:29 -0500
Subject: [PATCH] hook in the functionality to suppress scrolling.

However, we still need to figure out if we want to supress gui_canvas_getscroll
when suppressing the scrollbars. Currently it still gets called, which will
adjust the viewport to make objects at negative indices visible. I think
instead we want to anchor the viewport to 0,0 at top left and supress those
calls to get a nice speedup in the GUI.
---
 pd/nw/pd_canvas.js |  6 ++++--
 pd/nw/pdgui.js     | 14 +++++++++++++-
 pd/src/g_canvas.c  |  2 +-
 pd/src/g_editor.c  |  3 ++-
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js
index 7753dfbd7..1aa6ddbc0 100644
--- a/pd/nw/pd_canvas.js
+++ b/pd/nw/pd_canvas.js
@@ -1030,9 +1030,11 @@ function register_window_id(cid, attr_array) {
     // For now, there is no way for the cord inspector to be turned on by
     // default. But if this changes we need to set its menu item checkbox
     // accordingly here
-    //set_cord_inspector_checkbox();
+    // set_cord_inspector_checkbox();
 
-    // One final kludge-- because window creation is asyncronous, we may
+    // Set scroll bars
+    pdgui.canvas_set_scrollbars(cid, !attr_array.hide_scroll);
+    // One final kludge-- because window creation is asynchronous, we may
     // have gotten a dirty flag before the window was created. In that case
     // we check the title_queue to see if our title now contains an asterisk
     // (which is the visual cue for "dirty")
diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index d4ed12919..1a4001d0e 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -976,6 +976,17 @@ function gui_canvas_set_cordinspector(cid, state) {
     patchwin[cid].window.set_cord_inspector_checkbox(state !== 0 ? true : false);
 }
 
+function canvas_set_scrollbars(cid, scroll) {
+    patchwin[cid].window.document.body.style.
+        overflow = scroll ? "visible" : "hidden";
+}
+
+exports.canvas_set_scrollbars = canvas_set_scrollbars;
+
+function gui_canvas_set_scrollbars(cid, no_scrollbars) {
+    canvas_set_scrollbars(cid, no_scrollbars === 0);
+}
+
 exports.menu_send = menu_send;
 
 function gui_set_toplevel_window_list(dummy, attr_array) {
@@ -1417,7 +1428,8 @@ function gui_canvas_new(cid, width, height, geometry, zoom, editmode, name, dir,
             dirty: dirty_flag,
             args: cargs,
             zoom: zoom,
-            editmode: editmode
+            editmode: editmode,
+            hide_scroll: hide_scroll
     });
 }
 
diff --git a/pd/src/g_canvas.c b/pd/src/g_canvas.c
index 14ad4af98..736a9dbd9 100644
--- a/pd/src/g_canvas.c
+++ b/pd/src/g_canvas.c
@@ -744,8 +744,8 @@ void canvas_scalar_event(t_canvas *x, t_symbol *s, int argc, t_atom *argv)
 
 void canvas_show_scrollbars(t_canvas *x, t_floatarg f)
 {
-post("setting noscroll to %d", f);
     x->gl_noscroll = (int)f;
+    gui_vmess("gui_canvas_set_scrollbars", "xi", x, (int)f);
 }
 
 void canvas_show_menu(t_canvas *x, t_floatarg f)
diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c
index 61e9c6330..abea62817 100644
--- a/pd/src/g_editor.c
+++ b/pd/src/g_editor.c
@@ -2767,7 +2767,8 @@ static void canvas_donecanvasdialog(t_glist *x,
     xmargin = atom_getfloatarg(9, argc, argv);
     ymargin = atom_getfloatarg(10, argc, argv);
 
-    x->gl_noscroll = atom_getintarg(11, argc, argv);
+    pd_vmess(&x->gl_pd, gensym("scroll"), "f",
+        atom_getfloatarg(11, argc, argv));
     x->gl_nomenu = atom_getintarg(12, argc, argv);
 
     /* parent windows are treated differently than applies to
-- 
GitLab