simple ttyname patch
[nedit-bw.git] / leftrightmousewheel.patch
blobc22648d3c20cdb1ead5e23c3086528938dbd5b41
1 Subject: scroll left/right with mouse wheel
3 Adds a units option for the scroll_left()/scroll_right() action routines:
5 * "chars"
6 * "tabs"
7 * "emtabs"
8 * "pixels"
10 ---
12 doc/help.etx | 22 +++++++++++++---------
13 source/text.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
14 util/misc.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
15 3 files changed, 104 insertions(+), 11 deletions(-)
17 diff --quilt old/source/text.c new/source/text.c
18 --- old/source/text.c
19 +++ new/source/text.c
20 @@ -428,6 +428,12 @@ static char defaultTranslations[] =
21 "<FocusIn>: focusIn()\n"
22 "<FocusOut>: focusOut()\n"
23 /* Support for mouse wheel in XFree86 */
24 + "Shift Alt<Btn4Down>,<Btn4Up>: scroll_left(1)\n"
25 + "Shift Alt<Btn5Down>,<Btn5Up>: scroll_right(1)\n"
26 + "Ctrl Alt<Btn4Down>,<Btn4Up>: scroll_left(1, tab)\n"
27 + "Ctrl Alt<Btn5Down>,<Btn5Up>: scroll_right(1, tab)\n"
28 + "Alt<Btn4Down>,<Btn4Up>: scroll_left(1, char)\n"
29 + "Alt<Btn5Down>,<Btn5Up>: scroll_right(1, char)\n"
30 "Shift<Btn4Down>,<Btn4Up>: scroll_up(1)\n"
31 "Shift<Btn5Down>,<Btn5Up>: scroll_down(1)\n"
32 "Ctrl<Btn4Down>,<Btn4Up>: scroll_up(1, pages)\n"
33 @@ -3401,8 +3407,27 @@ static void scrollLeftAP(Widget w, XEven
35 if (*nArgs == 0 || sscanf(args[0], "%d", &nPixels) != 1)
36 return;
38 + if (*nArgs == 2) {
39 + if (strncmp(args[1], "char", 4) == 0) {
40 + nPixels *= TextDMinFontWidth(textD, True);
41 + }
42 + else if (strncmp(args[1], "tab", 3) == 0) {
43 + nPixels *= TextDMinFontWidth(textD, True) * textD->buffer->tabDist;
44 + }
45 + else if (strncmp(args[1], "emtab", 5) == 0) {
46 + int tabDist = ((TextWidget)w)->text.emulateTabs;
47 + if (tabDist <= 0)
48 + tabDist = textD->buffer->tabDist;
49 + nPixels *= TextDMinFontWidth(textD, True) * tabDist;
50 + }
51 + else if (strncmp(args[1], "pixel", 5) != 0) {
52 + return;
53 + }
54 + }
56 XtVaGetValues(textD->hScrollBar, XmNmaximum, &sliderMax,
57 - XmNsliderSize, &sliderSize, NULL);
58 + XmNsliderSize, &sliderSize, NULL);
59 horizOffset = min(max(0, textD->horizOffset - nPixels), sliderMax - sliderSize);
60 if (textD->horizOffset != horizOffset) {
61 TextDSetScroll(textD, textD->topLineNum, horizOffset);
62 @@ -3418,6 +3443,25 @@ static void scrollRightAP(Widget w, XEve
64 if (*nArgs == 0 || sscanf(args[0], "%d", &nPixels) != 1)
65 return;
67 + if (*nArgs == 2) {
68 + if (strncmp(args[1], "char", 4) == 0) {
69 + nPixels *= TextDMinFontWidth(textD, True);
70 + }
71 + else if (strncmp(args[1], "tab", 3) == 0) {
72 + nPixels *= TextDMinFontWidth(textD, True) * textD->buffer->tabDist;
73 + }
74 + else if (strncmp(args[1], "emtab", 5) == 0) {
75 + int tabDist = ((TextWidget)w)->text.emulateTabs;
76 + if (tabDist <= 0)
77 + tabDist = textD->buffer->tabDist;
78 + nPixels *= TextDMinFontWidth(textD, True) * tabDist;
79 + }
80 + else if (strncmp(args[1], "pixel", 5) != 0) {
81 + return;
82 + }
83 + }
85 XtVaGetValues(textD->hScrollBar, XmNmaximum, &sliderMax,
86 XmNsliderSize, &sliderSize, NULL);
87 horizOffset = min(max(0, textD->horizOffset + nPixels), sliderMax - sliderSize);
88 diff --quilt old/util/misc.c new/util/misc.c
89 --- old/util/misc.c
90 +++ new/util/misc.c
91 @@ -156,6 +156,10 @@ static void pageDownAP(Widget w, XEvent
92 Cardinal *nArgs);
93 static void pageUpAP(Widget w, XEvent *event, String *args,
94 Cardinal *nArgs);
95 +static void scrollLeftAP(Widget w, XEvent *event, String *args,
96 + Cardinal *nArgs);
97 +static void scrollRightAP(Widget w, XEvent *event, String *args,
98 + Cardinal *nArgs);
99 static long queryDesktop(Display *display, Window window, Atom deskTopAtom);
100 static void warning(const char* mesg);
101 static void microsleep(long usecs);
102 @@ -1929,7 +1933,9 @@ void InstallMouseWheelActions(XtAppConte
103 {"scrolled-window-scroll-up", scrollUpAP},
104 {"scrolled-window-page-up", pageUpAP},
105 {"scrolled-window-scroll-down", scrollDownAP},
106 - {"scrolled-window-page-down", pageDownAP}
107 + {"scrolled-window-page-down", pageDownAP},
108 + {"scrolled-window-scroll-left", scrollLeftAP},
109 + {"scrolled-window-scroll-right", scrollRightAP}
112 XtAppAddActions(context, Actions, XtNumber(Actions));
113 @@ -1944,6 +1950,12 @@ void AddMouseWheelSupport(Widget w)
114 if (XmIsScrolledWindow(XtParent(w)))
116 static const char scrollTranslations[] =
117 + "Shift Alt<Btn4Down>,<Btn4Up>: scrolled-window-scroll-left(1)\n"
118 + "Shift Alt<Btn5Down>,<Btn5Up>: scrolled-window-scroll-right(1)\n"
119 + "Ctrl Alt<Btn4Down>,<Btn4Up>: scrolled-window-scroll-left(8)\n"
120 + "Ctrl Alt<Btn5Down>,<Btn5Up>: scrolled-window-scroll-right(8)\n"
121 + "Alt<Btn4Down>,<Btn4Up>: scrolled-window-scroll-left(4)\n"
122 + "Alt<Btn5Down>,<Btn5Up>: scrolled-window-scroll-right(4)\n"
123 "Shift<Btn4Down>,<Btn4Up>: scrolled-window-scroll-up(1)\n"
124 "Shift<Btn5Down>,<Btn5Up>: scrolled-window-scroll-down(1)\n"
125 "Ctrl<Btn4Down>,<Btn4Up>: scrolled-window-page-up()\n"
126 @@ -2020,6 +2032,39 @@ static void scrollDownAP(Widget w, XEven
127 return;
130 +static void scrollLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
132 + Widget scrolledWindow, scrollBar;
133 + String al[1];
134 + int i, nLines;
136 + if (*nArgs == 0 || sscanf(args[0], "%d", &nLines) != 1)
137 + return;
138 + al[0] = "Left";
139 + scrolledWindow = XtParent(w);
140 + scrollBar = XtNameToWidget (scrolledWindow, "HorScrollBar");
141 + if (scrollBar)
142 + for (i=0; i<nLines; i++)
143 + XtCallActionProc(scrollBar, "IncrementUpOrLeft", event, al, 1) ;
144 + return;
147 +static void scrollRightAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
149 + Widget scrolledWindow, scrollBar;
150 + String al[1];
151 + int i, nLines;
153 + if (*nArgs == 0 || sscanf(args[0], "%d", &nLines) != 1)
154 + return;
155 + al[0] = "Right";
156 + scrolledWindow = XtParent(w);
157 + scrollBar = XtNameToWidget (scrolledWindow, "HorScrollBar");
158 + if (scrollBar)
159 + for (i=0; i<nLines; i++)
160 + XtCallActionProc(scrollBar, "IncrementDownOrRight", event, al, 1) ;
161 + return;
165 ** This is a disguisting hack to work around a bug in OpenMotif.
166 diff --quilt old/doc/help.etx new/doc/help.etx
167 --- old/doc/help.etx
168 +++ new/doc/help.etx
169 @@ -2503,7 +2503,7 @@ Macro Subroutines
170 Width of the current pane in pixels.
172 **$em_tab_dist**
173 - If tab emulation is turned on in the Tabs...
174 + If tab emulation is turned on in the Tab Stops...
175 dialog of the Preferences menu, the value is the
176 distance between emulated tab stops. If tab
177 emulation is turned off, the value is 0.
178 @@ -2622,7 +2622,7 @@ Macro Subroutines
179 **$tab_dist**
180 The distance between tab stops for a
181 hardware tab character, as set in the
182 - Tabs... dialog of the Preferences menu.
183 + Tab Stops... dialog of the Preferences menu.
185 **$text_length**
186 The length of the text in the current document.
187 @@ -2633,8 +2633,8 @@ Macro Subroutines
188 **$use_tabs**
189 Whether the user is allowing the NEdit to insert tab characters to maintain
190 spacing in tab emulation and rectangular dragging operations. (The setting of
191 - the "Use tab characters in padding and emulated tabs" button in the Tabs...
192 - dialog of the Preferences menu.)
193 + the "Use tab characters in padding and emulated tabs" button in the
194 + Tab Stops... dialog of the Preferences menu.)
196 **$wrap_margin**
197 The right margin in the current window for text wrapping and filling.
198 @@ -3783,11 +3783,15 @@ Action Routines
199 Scroll the display down (towards the end of the file) by a given
200 number of units, units being lines or pages. Default units are lines.
202 -**scroll_left( nPixels )**
203 - Scroll the display left by nPixels.
205 -**scroll_right( nPixels )**
206 - Scroll the display right by nPixels.
207 +**scroll_left( nUnits, ["chars" | "tabs" | "emtabs" | "pixels"] )**
208 + Scroll the display left by a given number of units, units being characters,
209 + hardware tab stop spacing, emulated tab stop spacing, or pixels. If emulated
210 + tabs are disabled in the Tab Stops... dialog, "emtabs" is the same as "tabs".
212 +**scroll_right( nUnits, ["chars" | "tabs" | "emtabs" | "pixels"] )**
213 + Scroll the display right by a given number of units, units being characters,
214 + hardware tab stop spacing, emulated tab stop spacing, or pixels. If emulated
215 + tabs are disabled in the Tab Stops... dialog, "emtabs" is the same as "tabs".
217 **scroll_up( nUnits, ["lines" | "pages"] )**
218 Scroll the display up (towards the beginning of the file) by a given