add cast to XtCalloc() call
[nedit-bw.git] / leftrightmousewheel.patch
blob85267573a3533991537cbadbf3e79b828b56b4ea
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 @@ -426,10 +426,16 @@ static char defaultTranslations[] =
21 "Ctrl~Meta~Alt Button3<MotionNotify>: mouse_pan()\n"
22 "<Btn3Up>: end_drag()\n"
23 "<FocusIn>: focusIn()\n"
24 "<FocusOut>: focusOut()\n"
25 /* Support for mouse wheel in XFree86 */
26 + "Shift Alt<Btn4Down>,<Btn4Up>: scroll_left(1)\n"
27 + "Shift Alt<Btn5Down>,<Btn5Up>: scroll_right(1)\n"
28 + "Ctrl Alt<Btn4Down>,<Btn4Up>: scroll_left(1, tab)\n"
29 + "Ctrl Alt<Btn5Down>,<Btn5Up>: scroll_right(1, tab)\n"
30 + "Alt<Btn4Down>,<Btn4Up>: scroll_left(1, char)\n"
31 + "Alt<Btn5Down>,<Btn5Up>: scroll_right(1, char)\n"
32 "Shift<Btn4Down>,<Btn4Up>: scroll_up(1)\n"
33 "Shift<Btn5Down>,<Btn5Up>: scroll_down(1)\n"
34 "Ctrl<Btn4Down>,<Btn4Up>: scroll_up(1, pages)\n"
35 "Ctrl<Btn5Down>,<Btn5Up>: scroll_down(1, pages)\n"
36 "<Btn4Down>,<Btn4Up>: scroll_up(5)\n"
37 @@ -3399,12 +3405,31 @@ static void scrollLeftAP(Widget w, XEven
38 int horizOffset, nPixels;
39 int sliderMax, sliderSize;
41 if (*nArgs == 0 || sscanf(args[0], "%d", &nPixels) != 1)
42 return;
44 + if (*nArgs == 2) {
45 + if (strncmp(args[1], "char", 4) == 0) {
46 + nPixels *= TextDMinFontWidth(textD, True);
47 + }
48 + else if (strncmp(args[1], "tab", 3) == 0) {
49 + nPixels *= TextDMinFontWidth(textD, True) * textD->buffer->tabDist;
50 + }
51 + else if (strncmp(args[1], "emtab", 5) == 0) {
52 + int tabDist = ((TextWidget)w)->text.emulateTabs;
53 + if (tabDist <= 0)
54 + tabDist = textD->buffer->tabDist;
55 + nPixels *= TextDMinFontWidth(textD, True) * tabDist;
56 + }
57 + else if (strncmp(args[1], "pixel", 5) != 0) {
58 + return;
59 + }
60 + }
62 XtVaGetValues(textD->hScrollBar, XmNmaximum, &sliderMax,
63 - XmNsliderSize, &sliderSize, NULL);
64 + XmNsliderSize, &sliderSize, NULL);
65 horizOffset = min(max(0, textD->horizOffset - nPixels), sliderMax - sliderSize);
66 if (textD->horizOffset != horizOffset) {
67 TextDSetScroll(textD, textD->topLineNum, horizOffset);
70 @@ -3416,10 +3441,29 @@ static void scrollRightAP(Widget w, XEve
71 int horizOffset, nPixels;
72 int sliderMax, sliderSize;
74 if (*nArgs == 0 || sscanf(args[0], "%d", &nPixels) != 1)
75 return;
77 + if (*nArgs == 2) {
78 + if (strncmp(args[1], "char", 4) == 0) {
79 + nPixels *= TextDMinFontWidth(textD, True);
80 + }
81 + else if (strncmp(args[1], "tab", 3) == 0) {
82 + nPixels *= TextDMinFontWidth(textD, True) * textD->buffer->tabDist;
83 + }
84 + else if (strncmp(args[1], "emtab", 5) == 0) {
85 + int tabDist = ((TextWidget)w)->text.emulateTabs;
86 + if (tabDist <= 0)
87 + tabDist = textD->buffer->tabDist;
88 + nPixels *= TextDMinFontWidth(textD, True) * tabDist;
89 + }
90 + else if (strncmp(args[1], "pixel", 5) != 0) {
91 + return;
92 + }
93 + }
95 XtVaGetValues(textD->hScrollBar, XmNmaximum, &sliderMax,
96 XmNsliderSize, &sliderSize, NULL);
97 horizOffset = min(max(0, textD->horizOffset + nPixels), sliderMax - sliderSize);
98 if (textD->horizOffset != horizOffset) {
99 TextDSetScroll(textD, textD->topLineNum, horizOffset);
100 diff --quilt old/util/misc.c new/util/misc.c
101 --- old/util/misc.c
102 +++ new/util/misc.c
103 @@ -154,10 +154,14 @@ static void scrollUpAP(Widget w, XEvent
104 Cardinal *nArgs);
105 static void pageDownAP(Widget w, XEvent *event, String *args,
106 Cardinal *nArgs);
107 static void pageUpAP(Widget w, XEvent *event, String *args,
108 Cardinal *nArgs);
109 +static void scrollLeftAP(Widget w, XEvent *event, String *args,
110 + Cardinal *nArgs);
111 +static void scrollRightAP(Widget w, XEvent *event, String *args,
112 + Cardinal *nArgs);
113 static long queryDesktop(Display *display, Window window, Atom deskTopAtom);
114 static void warning(const char* mesg);
115 static void microsleep(long usecs);
118 @@ -1927,11 +1931,13 @@ void InstallMouseWheelActions(XtAppConte
120 static XtActionsRec Actions[] = {
121 {"scrolled-window-scroll-up", scrollUpAP},
122 {"scrolled-window-page-up", pageUpAP},
123 {"scrolled-window-scroll-down", scrollDownAP},
124 - {"scrolled-window-page-down", pageDownAP}
125 + {"scrolled-window-page-down", pageDownAP},
126 + {"scrolled-window-scroll-left", scrollLeftAP},
127 + {"scrolled-window-scroll-right", scrollRightAP}
130 XtAppAddActions(context, Actions, XtNumber(Actions));
133 @@ -1942,10 +1948,16 @@ void InstallMouseWheelActions(XtAppConte
134 void AddMouseWheelSupport(Widget w)
136 if (XmIsScrolledWindow(XtParent(w)))
138 static const char scrollTranslations[] =
139 + "Shift Alt<Btn4Down>,<Btn4Up>: scrolled-window-scroll-left(1)\n"
140 + "Shift Alt<Btn5Down>,<Btn5Up>: scrolled-window-scroll-right(1)\n"
141 + "Ctrl Alt<Btn4Down>,<Btn4Up>: scrolled-window-scroll-left(8)\n"
142 + "Ctrl Alt<Btn5Down>,<Btn5Up>: scrolled-window-scroll-right(8)\n"
143 + "Alt<Btn4Down>,<Btn4Up>: scrolled-window-scroll-left(4)\n"
144 + "Alt<Btn5Down>,<Btn5Up>: scrolled-window-scroll-right(4)\n"
145 "Shift<Btn4Down>,<Btn4Up>: scrolled-window-scroll-up(1)\n"
146 "Shift<Btn5Down>,<Btn5Up>: scrolled-window-scroll-down(1)\n"
147 "Ctrl<Btn4Down>,<Btn4Up>: scrolled-window-page-up()\n"
148 "Ctrl<Btn5Down>,<Btn5Up>: scrolled-window-page-down()\n"
149 "<Btn4Down>,<Btn4Up>: scrolled-window-scroll-up(3)\n"
150 @@ -2018,10 +2030,43 @@ static void scrollDownAP(Widget w, XEven
151 for (i=0; i<nLines; i++)
152 XtCallActionProc(scrollBar, "IncrementDownOrRight", event, al, 1) ;
153 return;
156 +static void scrollLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
158 + Widget scrolledWindow, scrollBar;
159 + String al[1];
160 + int i, nLines;
162 + if (*nArgs == 0 || sscanf(args[0], "%d", &nLines) != 1)
163 + return;
164 + al[0] = "Left";
165 + scrolledWindow = XtParent(w);
166 + scrollBar = XtNameToWidget (scrolledWindow, "HorScrollBar");
167 + if (scrollBar)
168 + for (i=0; i<nLines; i++)
169 + XtCallActionProc(scrollBar, "IncrementUpOrLeft", event, al, 1) ;
170 + return;
173 +static void scrollRightAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
175 + Widget scrolledWindow, scrollBar;
176 + String al[1];
177 + int i, nLines;
179 + if (*nArgs == 0 || sscanf(args[0], "%d", &nLines) != 1)
180 + return;
181 + al[0] = "Right";
182 + scrolledWindow = XtParent(w);
183 + scrollBar = XtNameToWidget (scrolledWindow, "HorScrollBar");
184 + if (scrollBar)
185 + for (i=0; i<nLines; i++)
186 + XtCallActionProc(scrollBar, "IncrementDownOrRight", event, al, 1) ;
187 + return;
191 ** This is a disguisting hack to work around a bug in OpenMotif.
192 ** OpenMotif's toggle button Select() action routine remembers the last radio
193 ** button that was toggled (stored as global state) and refuses to take any
194 diff --quilt old/doc/help.etx new/doc/help.etx
195 --- old/doc/help.etx
196 +++ new/doc/help.etx
197 @@ -2502,11 +2502,11 @@ Macro Subroutines
199 **$display_width**
200 Width of the current pane in pixels.
202 **$em_tab_dist**
203 - If tab emulation is turned on in the Tabs...
204 + If tab emulation is turned on in the Tab Stops...
205 dialog of the Preferences menu, the value is the
206 distance between emulated tab stops. If tab
207 emulation is turned off, the value is 0.
209 **$empty_array**
210 @@ -2621,23 +2621,23 @@ Macro Subroutines
211 Contains the value of the array sub-script separation string.
213 **$tab_dist**
214 The distance between tab stops for a
215 hardware tab character, as set in the
216 - Tabs... dialog of the Preferences menu.
217 + Tab Stops... dialog of the Preferences menu.
219 **$text_length**
220 The length of the text in the current document.
222 **$top_line**
223 The line number of the top line of the currently active pane.
225 **$use_tabs**
226 Whether the user is allowing the NEdit to insert tab characters to maintain
227 spacing in tab emulation and rectangular dragging operations. (The setting of
228 - the "Use tab characters in padding and emulated tabs" button in the Tabs...
229 - dialog of the Preferences menu.)
230 + the "Use tab characters in padding and emulated tabs" button in the
231 + Tab Stops... dialog of the Preferences menu.)
233 **$wrap_margin**
234 The right margin in the current window for text wrapping and filling.
236 **$wrap_text**
237 @@ -3782,15 +3782,19 @@ Action Routines
239 **scroll_down( nUnits, ["lines" | "pages"] )**
240 Scroll the display down (towards the end of the file) by a given
241 number of units, units being lines or pages. Default units are lines.
243 -**scroll_left( nPixels )**
244 - Scroll the display left by nPixels.
246 -**scroll_right( nPixels )**
247 - Scroll the display right by nPixels.
248 +**scroll_left( nUnits, ["chars" | "tabs" | "emtabs" | "pixels"] )**
249 + Scroll the display left by a given number of units, units being characters,
250 + hardware tab stop spacing, emulated tab stop spacing, or pixels. If emulated
251 + tabs are disabled in the Tab Stops... dialog, "emtabs" is the same as "tabs".
253 +**scroll_right( nUnits, ["chars" | "tabs" | "emtabs" | "pixels"] )**
254 + Scroll the display right by a given number of units, units being characters,
255 + hardware tab stop spacing, emulated tab stop spacing, or pixels. If emulated
256 + tabs are disabled in the Tab Stops... dialog, "emtabs" is the same as "tabs".
258 **scroll_up( nUnits, ["lines" | "pages"] )**
259 Scroll the display up (towards the beginning of the file) by a given
260 number of units, units being lines or pages. Default units are lines.