Mercurial > hg > xemacs-beta
annotate src/scrollbar.c @ 5925:08cfc8f77fb6 cygwin
make space for long ptr, and store as such, for frame in WINDOW data,
add a bit more debugging to debug-mswindow,
Vin Shelton patch to fix M-x shell
| author | Henry Thompson <ht@markup.co.uk> |
|---|---|
| date | Fri, 27 Feb 2015 17:41:20 +0000 |
| parents | 56144c8593a8 |
| children |
| rev | line source |
|---|---|
| 428 | 1 /* Generic scrollbar implementation. |
| 2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois. | |
| 3 Copyright (C) 1995 Free Software Foundation, Inc. | |
| 4 Copyright (C) 1995 Sun Microsystems, Inc. | |
| 5 Copyright (C) 1995 Darrell Kindred <dkindred+@cmu.edu>. | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5124
diff
changeset
|
6 Copyright (C) 2003, 2010 Ben Wing. |
| 428 | 7 |
| 8 This file is part of XEmacs. | |
| 9 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5170
diff
changeset
|
10 XEmacs is free software: you can redistribute it and/or modify it |
| 428 | 11 under the terms of the GNU General Public License as published by the |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5170
diff
changeset
|
12 Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5170
diff
changeset
|
13 option) any later version. |
| 428 | 14 |
| 15 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 18 for more details. | |
| 19 | |
| 20 You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5170
diff
changeset
|
21 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 428 | 22 |
| 23 /* Synched up with: Not in FSF. */ | |
| 24 | |
| 25 /* This file has been Mule-ized. */ | |
| 26 | |
| 27 #include <config.h> | |
| 28 #include "lisp.h" | |
| 29 | |
| 30 #include "buffer.h" | |
| 31 #include "commands.h" | |
| 32 #include "scrollbar.h" | |
| 872 | 33 #include "device-impl.h" |
| 34 #include "frame-impl.h" | |
| 428 | 35 #include "glyphs.h" |
| 36 #include "gutter.h" | |
| 37 #include "window.h" | |
| 38 | |
| 39 Lisp_Object Qinit_scrollbar_from_resources; | |
| 40 | |
| 41 Lisp_Object Qscrollbar_line_up; | |
| 42 Lisp_Object Qscrollbar_line_down; | |
| 43 Lisp_Object Qscrollbar_page_up; | |
| 44 Lisp_Object Qscrollbar_page_down; | |
| 45 Lisp_Object Qscrollbar_to_top; | |
| 46 Lisp_Object Qscrollbar_to_bottom; | |
| 47 Lisp_Object Qscrollbar_vertical_drag; | |
| 48 | |
| 49 Lisp_Object Qscrollbar_char_left; | |
| 50 Lisp_Object Qscrollbar_char_right; | |
| 51 Lisp_Object Qscrollbar_page_left; | |
| 52 Lisp_Object Qscrollbar_page_right; | |
| 53 Lisp_Object Qscrollbar_to_left; | |
| 54 Lisp_Object Qscrollbar_to_right; | |
| 55 Lisp_Object Qscrollbar_horizontal_drag; | |
| 56 | |
| 57 #define DEFAULT_SCROLLBAR_WIDTH 15 | |
| 58 #define DEFAULT_SCROLLBAR_HEIGHT 15 | |
| 59 | |
| 60 /* Width and height of the scrollbar. */ | |
| 61 Lisp_Object Vscrollbar_width; | |
| 62 Lisp_Object Vscrollbar_height; | |
| 63 | |
| 64 /* Scrollbar visibility specifiers */ | |
| 65 Lisp_Object Vhorizontal_scrollbar_visible_p; | |
| 66 Lisp_Object Vvertical_scrollbar_visible_p; | |
| 67 | |
| 68 /* Scrollbar location specifiers */ | |
| 69 Lisp_Object Vscrollbar_on_left_p; | |
| 70 Lisp_Object Vscrollbar_on_top_p; | |
| 71 | |
| 72 Lisp_Object Vscrollbar_pointer_glyph; | |
| 73 | |
| 74 EXFUN (Fcenter_to_window_line, 2); | |
| 75 | |
| 76 static void update_scrollbar_instance (struct window *w, int vertical, | |
| 77 struct scrollbar_instance *instance); | |
| 78 | |
| 1204 | 79 static const struct memory_description scrollbar_instance_description [] = { |
| 934 | 80 { XD_LISP_OBJECT, offsetof (struct scrollbar_instance, mirror) }, |
| 81 { XD_LISP_OBJECT, offsetof (struct scrollbar_instance, next) }, | |
| 82 { XD_END } | |
| 83 }; | |
| 84 | |
| 428 | 85 |
| 617 | 86 static Lisp_Object |
| 87 mark_scrollbar_instance (Lisp_Object obj) | |
| 88 { | |
| 89 struct scrollbar_instance *data = XSCROLLBAR_INSTANCE (obj); | |
| 90 mark_object (wrap_window_mirror (data->mirror)); | |
| 91 if (data->next) | |
| 92 return wrap_scrollbar_instance (data->next); | |
| 93 else | |
| 94 return Qnil; | |
| 95 } | |
| 96 | |
|
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
97 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("scrollbar-instance", scrollbar_instance, |
|
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
98 mark_scrollbar_instance, |
|
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
99 scrollbar_instance_description, |
|
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
100 struct scrollbar_instance); |
| 617 | 101 |
| 428 | 102 static void |
| 103 free_scrollbar_instance (struct scrollbar_instance *instance, | |
| 104 struct frame *frame) | |
| 105 { | |
| 106 if (!instance) | |
| 107 return; | |
| 108 else | |
| 109 { | |
| 110 struct device *d = XDEVICE (frame->device); | |
| 111 | |
| 112 MAYBE_DEVMETH (d, free_scrollbar_instance, (instance)); | |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
113 /* not worth calling free_normal_lisp_object() -- scrollbar instances |
| 617 | 114 are not created that frequently and it's dangerous. */ |
| 428 | 115 } |
| 116 } | |
| 117 | |
| 118 static void | |
| 119 free_window_mirror_scrollbars (struct window_mirror *mir) | |
| 120 { | |
| 121 free_scrollbar_instance (mir->scrollbar_vertical_instance, mir->frame); | |
| 122 mir->scrollbar_vertical_instance = 0; | |
| 123 | |
| 124 free_scrollbar_instance (mir->scrollbar_horizontal_instance, mir->frame); | |
| 125 mir->scrollbar_horizontal_instance = 0; | |
| 126 } | |
| 127 | |
| 128 static struct window_mirror * | |
| 129 free_scrollbars_loop (Lisp_Object window, struct window_mirror *mir) | |
| 130 { | |
| 131 struct window_mirror *retval = NULL; | |
| 132 | |
| 133 while (mir) | |
| 134 { | |
| 135 assert (!NILP (window)); | |
| 136 | |
| 137 if (mir->vchild) | |
| 138 { | |
| 139 retval = free_scrollbars_loop (XWINDOW (window)->vchild, | |
| 140 mir->vchild); | |
| 141 } | |
| 142 else if (mir->hchild) | |
| 143 { | |
| 144 retval = free_scrollbars_loop (XWINDOW (window)->hchild, | |
| 145 mir->hchild); | |
| 146 } | |
| 147 | |
| 148 if (retval != NULL) | |
| 149 return retval; | |
| 150 | |
| 151 if (mir->scrollbar_vertical_instance || | |
| 152 mir->scrollbar_horizontal_instance) | |
| 153 free_window_mirror_scrollbars (mir); | |
| 154 | |
| 155 mir = mir->next; | |
| 156 window = XWINDOW (window)->next; | |
| 157 } | |
| 158 | |
| 159 return NULL; | |
| 160 } | |
| 161 | |
| 162 /* Destroy all scrollbars associated with FRAME. Only called from | |
| 163 delete_frame_internal. */ | |
| 164 void | |
| 165 free_frame_scrollbars (struct frame *f) | |
| 166 { | |
| 167 if (!HAS_FRAMEMETH_P (f, create_scrollbar_instance)) | |
| 168 return; | |
| 169 | |
| 170 if (f->mirror_dirty) | |
| 171 update_frame_window_mirror (f); | |
| 172 | |
| 617 | 173 free_scrollbars_loop (f->root_window, XWINDOW_MIRROR (f->root_mirror)); |
| 428 | 174 |
| 175 while (FRAME_SB_VCACHE (f)) | |
| 176 { | |
| 177 struct scrollbar_instance *tofree = FRAME_SB_VCACHE (f); | |
| 178 FRAME_SB_VCACHE (f) = FRAME_SB_VCACHE (f)->next; | |
| 179 tofree->next = NULL; | |
| 180 free_scrollbar_instance (tofree, f); | |
| 181 } | |
| 182 | |
| 183 while (FRAME_SB_HCACHE (f)) | |
| 184 { | |
| 185 struct scrollbar_instance *tofree = FRAME_SB_HCACHE (f); | |
| 186 FRAME_SB_HCACHE (f) = FRAME_SB_HCACHE (f)->next; | |
| 187 tofree->next = NULL; | |
| 188 free_scrollbar_instance (tofree, f); | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 | |
| 193 static struct scrollbar_instance * | |
| 194 create_scrollbar_instance (struct frame *f, int vertical) | |
| 195 { | |
| 196 struct device *d = XDEVICE (f->device); | |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5124
diff
changeset
|
197 Lisp_Object obj = ALLOC_NORMAL_LISP_OBJECT (scrollbar_instance); |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
198 struct scrollbar_instance *instance = XSCROLLBAR_INSTANCE (obj); |
| 428 | 199 |
| 200 MAYBE_DEVMETH (d, create_scrollbar_instance, (f, vertical, instance)); | |
| 201 | |
| 202 return instance; | |
| 203 } | |
| 204 | |
| 205 | |
| 206 #define GET_SCROLLBAR_INSTANCE_INTERNAL(cache) \ | |
| 207 do { \ | |
| 208 if (FRAME_SB_##cache (f)) \ | |
| 209 { \ | |
| 210 struct scrollbar_instance *retval = FRAME_SB_##cache (f); \ | |
| 211 FRAME_SB_##cache (f) = FRAME_SB_##cache (f)->next; \ | |
| 212 retval->next = NULL; \ | |
| 213 return retval; \ | |
| 214 } \ | |
| 215 } while (0) | |
| 216 | |
| 217 static struct scrollbar_instance * | |
| 218 get_scrollbar_instance (struct frame *f, int vertical) | |
| 219 { | |
| 220 /* Check if there are any available scrollbars already in existence. */ | |
| 221 if (vertical) | |
| 222 GET_SCROLLBAR_INSTANCE_INTERNAL (VCACHE); | |
| 223 else | |
| 224 GET_SCROLLBAR_INSTANCE_INTERNAL (HCACHE); | |
| 225 | |
| 226 return create_scrollbar_instance (f, vertical); | |
| 227 } | |
| 228 #undef GET_SCROLLBAR_INSTANCE_INTERNAL | |
| 229 | |
| 230 #define RELEASE_SCROLLBAR_INSTANCE_INTERNAL(cache) \ | |
| 231 do { \ | |
| 232 if (!FRAME_SB_##cache (f)) \ | |
| 233 { \ | |
| 234 instance->next = NULL; \ | |
| 235 FRAME_SB_##cache (f) = instance; \ | |
| 236 } \ | |
| 237 else \ | |
| 238 { \ | |
| 239 instance->next = FRAME_SB_##cache (f); \ | |
| 240 FRAME_SB_##cache (f) = instance; \ | |
| 241 } \ | |
| 242 } while (0) | |
| 243 | |
| 244 static void | |
| 245 release_scrollbar_instance (struct frame *f, int vertical, | |
| 246 struct scrollbar_instance *instance) | |
| 247 { | |
| 248 /* #### should we do "instance->mir = 0;" for safety? */ | |
| 249 if (vertical) | |
| 250 RELEASE_SCROLLBAR_INSTANCE_INTERNAL (VCACHE); | |
| 251 else | |
| 252 RELEASE_SCROLLBAR_INSTANCE_INTERNAL (HCACHE); | |
| 253 } | |
| 254 #undef RELEASE_SCROLLBAR_INSTANCE_INTERNAL | |
| 255 | |
| 256 #ifdef MEMORY_USAGE_STATS | |
| 257 | |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
258 struct scrollbar_instance_stats |
| 428 | 259 { |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
260 struct usage_stats u; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
261 Bytecount device_data; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
262 }; |
| 428 | 263 |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
264 Bytecount |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
265 compute_all_scrollbar_instance_usage (struct scrollbar_instance *inst) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
266 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
267 Bytecount total = 0; |
| 428 | 268 |
| 269 while (inst) | |
| 270 { | |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
271 total += lisp_object_memory_usage (wrap_scrollbar_instance (inst)); |
| 428 | 272 inst = inst->next; |
| 273 } | |
| 274 | |
| 275 return total; | |
| 276 } | |
| 277 | |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
278 static void |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
279 scrollbar_instance_memory_usage (Lisp_Object scrollbar_instance, |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
280 struct generic_usage_stats *gustats) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
281 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
282 struct scrollbar_instance_stats *stats = |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
283 (struct scrollbar_instance_stats *) gustats; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
284 struct scrollbar_instance *inst = XSCROLLBAR_INSTANCE (scrollbar_instance); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
285 struct device *d = FRAME_XDEVICE (inst->mirror->frame); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
286 Bytecount total = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
287 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
288 if (HAS_DEVMETH_P (d, compute_scrollbar_instance_usage)) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
289 total += DEVMETH (d, compute_scrollbar_instance_usage, (d, inst, |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
290 &gustats->u)); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
291 |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
292 stats->device_data = total; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
293 } |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
294 |
| 428 | 295 #endif /* MEMORY_USAGE_STATS */ |
| 296 | |
| 297 void | |
| 298 update_window_scrollbars (struct window *w, struct window_mirror *mirror, | |
| 299 int active, int horiz_only) | |
| 300 { | |
| 301 struct frame *f = XFRAME (w->frame); | |
| 302 struct device *d = XDEVICE (f->device); | |
| 1318 | 303 int depth; |
| 428 | 304 |
| 305 if (!HAS_DEVMETH_P (d, create_scrollbar_instance)) | |
| 306 return; | |
| 307 | |
| 1318 | 308 depth = enter_redisplay_critical_section_maybe (); |
| 428 | 309 |
| 310 /* It is possible for this to get called from the mirror update | |
| 311 routines. In that case the structure is in an indeterminate | |
| 312 state but we know exactly what struct we are working with. So we | |
| 313 pass it in in that case. We also take advantage of it at some | |
| 314 other points where we know what the mirror struct is. */ | |
| 315 if (!mirror) | |
| 316 mirror = find_window_mirror (w); | |
| 317 | |
| 318 if (!mirror->scrollbar_vertical_instance && active) | |
| 319 mirror->scrollbar_vertical_instance = get_scrollbar_instance (f, 1); | |
| 320 | |
| 321 if (!mirror->scrollbar_horizontal_instance && active) | |
| 322 mirror->scrollbar_horizontal_instance = get_scrollbar_instance (f, 0); | |
| 323 | |
| 324 if (!horiz_only && mirror->scrollbar_vertical_instance) | |
| 325 { | |
| 326 int size = (active ? window_scrollbar_width (w) : 0); | |
| 327 struct scrollbar_instance *instance; | |
| 328 | |
| 329 instance = mirror->scrollbar_vertical_instance; | |
| 330 instance->scrollbar_is_active = active; | |
| 331 instance->mirror = mirror; | |
| 332 | |
| 333 if (active && size) | |
| 334 update_scrollbar_instance (w, 1, instance); | |
| 335 MAYBE_DEVMETH (d, update_scrollbar_instance_status, | |
| 336 (w, active, size, instance)); | |
| 337 | |
| 338 if (!active) | |
| 339 { | |
| 340 release_scrollbar_instance (f, 1, instance); | |
| 341 mirror->scrollbar_vertical_instance = NULL; | |
| 342 } | |
| 343 } | |
| 344 | |
| 345 if (mirror->scrollbar_horizontal_instance) | |
| 346 { | |
| 347 int size = (active ? window_scrollbar_height (w) : 0); | |
| 348 struct scrollbar_instance *instance; | |
| 349 | |
| 350 instance = mirror->scrollbar_horizontal_instance; | |
| 351 instance->scrollbar_is_active = active; | |
| 352 instance->mirror = mirror; | |
| 353 | |
| 354 if (active && size) | |
| 355 update_scrollbar_instance (w, 0, instance); | |
| 356 MAYBE_DEVMETH (d, update_scrollbar_instance_status, | |
| 357 (w, active, size, instance)); | |
| 358 | |
| 359 if (!active) | |
| 360 { | |
| 361 release_scrollbar_instance (f, 0, instance); | |
| 362 mirror->scrollbar_horizontal_instance = NULL; | |
| 363 } | |
| 364 } | |
| 365 | |
| 1318 | 366 exit_redisplay_critical_section_maybe (depth); |
| 428 | 367 } |
| 368 | |
| 369 void | |
| 370 release_window_mirror_scrollbars (struct window_mirror *mir) | |
| 371 { | |
| 372 struct device *d = XDEVICE (mir->frame->device); | |
| 373 | |
| 374 if (!HAS_DEVMETH_P (d, create_scrollbar_instance)) | |
| 375 return; | |
| 376 | |
| 377 if (mir->scrollbar_vertical_instance) | |
| 378 { | |
| 379 release_scrollbar_instance (mir->frame, 1, | |
| 380 mir->scrollbar_vertical_instance); | |
| 381 MAYBE_DEVMETH (d, release_scrollbar_instance, | |
| 382 (mir->scrollbar_vertical_instance)); | |
| 383 } | |
| 384 mir->scrollbar_vertical_instance = 0; | |
| 385 | |
| 386 if (mir->scrollbar_horizontal_instance) | |
| 387 { | |
| 388 release_scrollbar_instance (mir->frame, 0, | |
| 389 mir->scrollbar_horizontal_instance); | |
| 390 MAYBE_DEVMETH (d, release_scrollbar_instance, | |
| 391 (mir->scrollbar_horizontal_instance)); | |
| 392 } | |
| 393 mir->scrollbar_horizontal_instance = 0; | |
| 394 } | |
| 395 | |
| 396 /* | |
| 397 * If w->sb_point is on the top line then return w->sb_point else | |
| 398 * return w->start. If flag, then return beginning point of line | |
| 399 * which w->sb_point lies on. | |
| 400 */ | |
| 665 | 401 static Charbpos |
| 428 | 402 scrollbar_point (struct window *w, int flag) |
| 403 { | |
| 665 | 404 Charbpos start_pos, end_pos, sb_pos; |
| 428 | 405 Lisp_Object buf; |
| 406 struct buffer *b; | |
| 407 | |
| 408 if (NILP (w->buffer)) /* non-leaf window */ | |
| 409 return 0; | |
| 410 | |
| 411 start_pos = marker_position (w->start[CURRENT_DISP]); | |
| 412 sb_pos = marker_position (w->sb_point); | |
| 413 | |
| 414 if (!flag && sb_pos < start_pos) | |
| 415 return start_pos; | |
| 416 | |
| 417 buf = get_buffer (w->buffer, 0); | |
| 418 if (!NILP (buf)) | |
| 419 b = XBUFFER (buf); | |
| 420 else | |
| 421 return start_pos; | |
| 422 | |
| 423 if (flag) | |
| 424 end_pos = find_next_newline_no_quit (b, sb_pos, -1); | |
| 425 else | |
| 426 end_pos = find_next_newline_no_quit (b, start_pos, 1); | |
| 427 | |
| 428 if (flag) | |
| 429 return end_pos; | |
| 430 else if (sb_pos > end_pos) | |
| 431 return start_pos; | |
| 432 else | |
| 433 return sb_pos; | |
| 434 } | |
| 435 | |
| 436 /* | |
| 437 * Update a window's horizontal or vertical scrollbar. | |
| 438 */ | |
| 439 static void | |
| 440 update_scrollbar_instance (struct window *w, int vertical, | |
| 441 struct scrollbar_instance *instance) | |
| 442 { | |
| 443 struct frame *f = XFRAME (w->frame); | |
| 444 struct device *d = XDEVICE (f->device); | |
| 445 struct buffer *b = XBUFFER (w->buffer); | |
| 665 | 446 Charbpos start_pos, end_pos, sb_pos; |
| 428 | 447 int scrollbar_width = window_scrollbar_width (w); |
| 448 int scrollbar_height = window_scrollbar_height (w); | |
| 449 | |
| 450 int new_line_increment = -1, new_page_increment = -1; | |
| 451 int new_minimum = -1, new_maximum = -1; | |
| 452 int new_slider_size = -1, new_slider_position = -1; | |
| 453 int new_width = -1, new_height = -1, new_x = -1, new_y = -1; | |
| 2286 | 454 #if 0 |
| 444 | 455 struct window *new_window = 0; /* #### currently unused */ |
| 2286 | 456 #endif |
| 428 | 457 |
| 458 end_pos = BUF_Z (b) - w->window_end_pos[CURRENT_DISP]; | |
| 459 sb_pos = scrollbar_point (w, 0); | |
| 460 start_pos = sb_pos; | |
| 461 | |
| 462 /* The end position must be strictly greater than the start | |
| 463 position, at least for the Motify scrollbar. It shouldn't hurt | |
| 464 anything for other scrollbar implementations. */ | |
| 465 if (end_pos <= start_pos) | |
| 466 end_pos = start_pos + 1; | |
| 467 | |
| 468 if (vertical) | |
| 469 { | |
| 470 new_height = WINDOW_TEXT_HEIGHT (w); | |
| 471 new_width = scrollbar_width; | |
| 472 } | |
| 473 else | |
| 474 { | |
| 475 new_height = scrollbar_height; | |
| 476 new_width = WINDOW_TEXT_WIDTH (w); | |
| 477 } | |
| 478 | |
| 479 /* If the height and width are not greater than 0, then later on the | |
| 480 Motif widgets will bitch and moan. */ | |
| 481 if (new_height <= 0) | |
| 482 new_height = 1; | |
| 483 if (new_width <= 0) | |
| 484 new_width = 1; | |
| 485 | |
| 486 assert (instance->mirror && XWINDOW (real_window(instance->mirror, 0)) == w); | |
| 487 | |
| 488 /* Only character-based scrollbars are implemented at the moment. | |
| 489 Line-based will be implemented in the future. */ | |
| 490 | |
| 491 instance->scrollbar_is_active = 1; | |
| 492 new_line_increment = 1; | |
| 493 new_page_increment = 1; | |
| 494 | |
| 495 /* We used to check for inhibit_scrollbar_slider_size_change here, | |
| 496 but that seems bogus. */ | |
| 497 { | |
| 498 int x_offset, y_offset; | |
| 499 | |
| 500 /* Scrollbars are always the farthest from the text area, barring | |
| 501 gutters. */ | |
| 502 if (vertical) | |
| 503 { | |
| 504 if (!NILP (w->scrollbar_on_left_p)) | |
| 505 { | |
| 506 x_offset = WINDOW_LEFT (w); | |
| 507 } | |
| 442 | 508 else |
| 428 | 509 { |
| 510 x_offset = WINDOW_RIGHT (w) - scrollbar_width; | |
| 511 if (window_needs_vertical_divider (w)) | |
| 512 x_offset -= window_divider_width (w); | |
| 513 } | |
| 514 y_offset = WINDOW_TEXT_TOP (w) + f->scrollbar_y_offset; | |
| 515 } | |
| 516 else | |
| 517 { | |
| 518 x_offset = WINDOW_TEXT_LEFT (w); | |
| 519 y_offset = f->scrollbar_y_offset; | |
| 520 | |
| 521 if (!NILP (w->scrollbar_on_top_p)) | |
| 522 { | |
| 523 y_offset += WINDOW_TOP (w); | |
| 524 } | |
| 525 else | |
| 526 { | |
| 527 y_offset += WINDOW_TEXT_BOTTOM (w); | |
| 528 } | |
| 529 } | |
| 530 | |
| 531 new_x = x_offset; | |
| 532 new_y = y_offset; | |
| 533 } | |
| 534 | |
| 535 /* A disabled scrollbar has its slider sized to the entire height of | |
| 536 the scrollbar. Currently the minibuffer scrollbar is | |
| 537 disabled. */ | |
| 538 if (!MINI_WINDOW_P (w) && vertical) | |
| 539 { | |
| 540 if (!DEVMETH_OR_GIVEN (d, inhibit_scrollbar_slider_size_change, (), 0)) | |
| 541 { | |
| 542 new_minimum = BUF_BEGV (b); | |
| 543 new_maximum = max (BUF_ZV (b), new_minimum + 1); | |
| 544 new_slider_size = min ((end_pos - start_pos), | |
| 545 (new_maximum - new_minimum)); | |
| 546 new_slider_position = sb_pos; | |
| 2286 | 547 #if 0 |
| 428 | 548 new_window = w; |
| 2286 | 549 #endif |
| 428 | 550 } |
| 551 } | |
| 552 else if (!MINI_WINDOW_P (w)) | |
| 553 { | |
| 554 /* The minus one is to account for the truncation glyph. */ | |
| 555 int wcw = window_char_width (w, 0) - 1; | |
| 556 int max_width, max_slide; | |
| 557 | |
| 558 if (w->max_line_len < wcw) | |
| 559 { | |
| 560 max_width = 1; | |
| 561 max_slide = 1; | |
| 562 wcw = 1; | |
| 563 } | |
| 564 else | |
| 565 { | |
| 566 max_width = w->max_line_len + 2; | |
| 567 max_slide = max_width - wcw; | |
| 568 } | |
| 569 | |
| 570 new_minimum = 0; | |
| 571 new_maximum = max_width; | |
| 572 new_slider_size = wcw; | |
| 573 new_slider_position = min (w->hscroll, max_slide); | |
| 574 } | |
| 575 else /* MINI_WINDOW_P (w) */ | |
| 576 { | |
| 577 new_minimum = 1; | |
| 578 new_maximum = 2; | |
| 579 new_slider_size = 1; | |
| 580 new_slider_position = 1; | |
| 581 instance->scrollbar_is_active = 0; | |
| 582 } | |
| 583 | |
| 584 DEVMETH (d, update_scrollbar_instance_values, (w, instance, | |
| 585 new_line_increment, | |
| 586 new_page_increment, | |
| 587 new_minimum, | |
| 588 new_maximum, | |
| 589 new_slider_size, | |
| 590 new_slider_position, | |
| 591 new_width, new_height, | |
| 592 new_x, new_y)); | |
| 593 } | |
| 594 | |
| 595 void | |
| 596 init_frame_scrollbars (struct frame *f) | |
| 597 { | |
| 598 struct device *d = XDEVICE (f->device); | |
| 599 | |
| 600 if (HAS_DEVMETH_P (d, create_scrollbar_instance)) | |
| 601 { | |
| 602 int depth = unlock_ghost_specifiers_protected (); | |
| 793 | 603 Lisp_Object frame = wrap_frame (f); |
| 604 | |
| 428 | 605 call_critical_lisp_code (XDEVICE (FRAME_DEVICE (f)), |
| 606 Qinit_scrollbar_from_resources, | |
| 607 frame); | |
| 771 | 608 unbind_to (depth); |
| 428 | 609 } |
| 610 } | |
| 611 | |
| 612 void | |
| 613 init_device_scrollbars (struct device *d) | |
| 614 { | |
| 615 if (HAS_DEVMETH_P (d, create_scrollbar_instance)) | |
| 616 { | |
| 617 int depth = unlock_ghost_specifiers_protected (); | |
| 793 | 618 Lisp_Object device = wrap_device (d); |
| 619 | |
| 428 | 620 call_critical_lisp_code (d, |
| 621 Qinit_scrollbar_from_resources, | |
| 622 device); | |
| 771 | 623 unbind_to (depth); |
| 428 | 624 } |
| 625 } | |
| 626 | |
| 627 void | |
| 628 init_global_scrollbars (struct device *d) | |
| 629 { | |
| 630 if (HAS_DEVMETH_P (d, create_scrollbar_instance)) | |
| 631 { | |
| 632 int depth = unlock_ghost_specifiers_protected (); | |
| 633 call_critical_lisp_code (d, | |
| 634 Qinit_scrollbar_from_resources, | |
| 635 Qglobal); | |
| 771 | 636 unbind_to (depth); |
| 428 | 637 } |
| 638 } | |
| 639 | |
| 640 static void | |
| 2286 | 641 vertical_scrollbar_changed_in_window (Lisp_Object UNUSED (specifier), |
| 428 | 642 struct window *w, |
| 2286 | 643 Lisp_Object UNUSED (oldval)) |
| 428 | 644 { |
| 645 /* Hold on your cerebella guys. If we always show the dividers, | |
| 646 changing scrollbar affects only how the text and scrollbar are | |
| 647 laid out in the window. If we do not want the dividers to show up | |
| 648 always, then we mark more drastic change, because changing | |
| 649 divider appearance changes lotta things. Although we actually need | |
| 650 to do this only if the scrollbar has appeared or disappeared | |
| 651 completely at either window edge, we do this always, as users | |
| 652 usually do not reposition scrollbars 200 times a second or so. Do | |
| 653 you? */ | |
| 654 if (NILP (w->vertical_divider_always_visible_p)) | |
| 655 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (XFRAME (WINDOW_FRAME (w))); | |
| 656 else | |
| 657 MARK_WINDOWS_CHANGED (w); | |
| 658 } | |
| 659 | |
| 660 /* This function is called as a result of a change to the | |
| 661 `scrollbar-pointer' glyph. */ | |
| 662 static void | |
| 2286 | 663 scrollbar_pointer_changed_in_window (Lisp_Object UNUSED (specifier), |
| 664 struct window *w, | |
| 665 Lisp_Object UNUSED (oldval)) | |
| 428 | 666 { |
| 667 struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
| 668 | |
| 669 if (f->init_finished) | |
| 670 MAYBE_FRAMEMETH (f, scrollbar_pointer_changed_in_window, (w)); | |
| 671 } | |
| 672 | |
| 673 /* #### | |
| 674 | |
| 675 All of the following stuff is functions that handle scrollbar | |
| 676 actions. All of it should be moved into Lisp. This may require | |
| 677 adding some badly-needed primitives. */ | |
| 678 | |
| 679 /********** vertical scrollbar stuff **********/ | |
| 680 | |
| 681 /* | |
| 682 * If the original point is still visible, put the cursor back there. | |
| 683 * Otherwise, when scrolling down stick it at the beginning of the | |
| 684 * first visible line and when scrolling up stick it at the beginning | |
| 685 * of the last visible line. | |
| 686 */ | |
| 687 | |
| 688 /* #### This function should be moved into Lisp */ | |
| 689 static void | |
| 690 scrollbar_reset_cursor (Lisp_Object win, Lisp_Object orig_pt) | |
| 691 { | |
| 692 /* When this function is called we know that start is already | |
| 693 accurate. We know this because either set-window-start or | |
| 694 recenter was called immediately prior to it being called. */ | |
| 695 Lisp_Object buf; | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
696 Charbpos start_pos = XFIXNUM (Fwindow_start (win)); |
|
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
697 Charbpos ptint = XFIXNUM (orig_pt); |
| 428 | 698 struct window *w = XWINDOW (win); |
| 699 int selected = ((w == XWINDOW (Fselected_window (XFRAME (w->frame)->device))) | |
| 700 ? 1 | |
| 701 : 0); | |
| 702 | |
| 703 buf = Fwindow_buffer (win); | |
| 704 if (NILP (buf)) | |
| 705 return; /* the window was deleted out from under us */ | |
| 706 | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
707 if (ptint < XFIXNUM (Fwindow_start (win))) |
| 428 | 708 { |
| 709 if (selected) | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
710 Fgoto_char (make_fixnum (start_pos), buf); |
| 428 | 711 else |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
712 Fset_window_point (win, make_fixnum (start_pos)); |
| 428 | 713 } |
| 1708 | 714 else if (!point_would_be_visible (XWINDOW (win), start_pos, ptint, 0)) |
| 428 | 715 { |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
716 Fmove_to_window_line (make_fixnum (-1), win); |
| 428 | 717 |
| 718 if (selected) | |
| 719 Fbeginning_of_line (Qnil, buf); | |
| 720 else | |
| 721 { | |
| 722 /* #### Taken from forward-line. */ | |
| 665 | 723 Charbpos pos; |
| 428 | 724 |
| 725 pos = find_next_newline (XBUFFER (buf), | |
| 726 marker_position (w->pointm[CURRENT_DISP]), | |
| 727 -1); | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
728 Fset_window_point (win, make_fixnum (pos)); |
| 428 | 729 } |
| 730 } | |
| 731 else | |
| 732 { | |
| 733 if (selected) | |
| 734 Fgoto_char (orig_pt, buf); | |
| 735 else | |
| 736 Fset_window_point (win, orig_pt); | |
| 737 } | |
| 738 } | |
| 739 | |
| 740 DEFUN ("scrollbar-line-up", Fscrollbar_line_up, 1, 1, 0, /* | |
| 741 Function called when the line-up arrow on the scrollbar is clicked. | |
| 742 This is the little arrow at the top of the scrollbar. One argument, the | |
| 743 scrollbar's window. You can advise this function to change the scrollbar | |
| 744 behavior. | |
| 745 */ | |
| 746 (window)) | |
| 747 { | |
| 748 CHECK_LIVE_WINDOW (window); | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
749 window_scroll (window, make_fixnum (1), -1, ERROR_ME_NOT); |
| 428 | 750 zmacs_region_stays = 1; |
| 751 return Qnil; | |
| 752 } | |
| 753 | |
| 754 DEFUN ("scrollbar-line-down", Fscrollbar_line_down, 1, 1, 0, /* | |
| 755 Function called when the line-down arrow on the scrollbar is clicked. | |
| 756 This is the little arrow at the bottom of the scrollbar. One argument, the | |
| 757 scrollbar's window. You can advise this function to change the scrollbar | |
| 758 behavior. | |
| 759 */ | |
| 760 (window)) | |
| 761 { | |
| 762 CHECK_LIVE_WINDOW (window); | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
763 window_scroll (window, make_fixnum (1), 1, ERROR_ME_NOT); |
| 428 | 764 zmacs_region_stays = 1; |
| 765 return Qnil; | |
| 766 } | |
| 767 | |
| 768 DEFUN ("scrollbar-page-up", Fscrollbar_page_up, 1, 1, 0, /* | |
| 769 Function called when the user gives the "page-up" scrollbar action. | |
| 770 \(The way this is done can vary from scrollbar to scrollbar.) One argument, | |
| 771 a cons containing the scrollbar's window and a value (#### document me! | |
| 772 This value is nil for Motif/Lucid scrollbars and a number for Athena | |
| 773 scrollbars). You can advise this function to change the scrollbar | |
| 774 behavior. | |
| 775 */ | |
| 776 (object)) | |
| 777 { | |
| 778 Lisp_Object window = Fcar (object); | |
| 779 | |
| 780 CHECK_LIVE_WINDOW (window); | |
| 781 /* Motif and Athena scrollbars behave differently, but in accordance | |
| 782 with their standard behaviors. It is not possible to hide the | |
| 783 differences down in lwlib because knowledge of XEmacs buffer and | |
| 784 cursor motion routines is necessary. */ | |
| 442 | 785 |
| 786 if (NILP (XCDR (object))) | |
| 787 window_scroll (window, Qnil, -1, ERROR_ME_NOT); | |
| 788 else | |
| 789 { | |
| 665 | 790 Charbpos charbpos; |
| 442 | 791 Lisp_Object value = Fcdr (object); |
| 428 | 792 |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
793 CHECK_FIXNUM (value); |
| 442 | 794 Fmove_to_window_line (Qzero, window); |
| 795 /* can't use Fvertical_motion() because it moves the buffer point | |
| 796 rather than the window's point. | |
| 428 | 797 |
| 442 | 798 #### It does? Why does it take a window argument then? */ |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
799 charbpos = vmotion (XWINDOW (window), XFIXNUM (Fwindow_point (window)), |
|
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
800 XFIXNUM (value), 0); |
|
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
801 Fset_window_point (window, make_fixnum (charbpos)); |
| 442 | 802 Fcenter_to_window_line (Qzero, window); |
| 803 } | |
| 804 | |
| 428 | 805 zmacs_region_stays = 1; |
| 806 return Qnil; | |
| 807 } | |
| 808 | |
| 809 DEFUN ("scrollbar-page-down", Fscrollbar_page_down, 1, 1, 0, /* | |
| 810 Function called when the user gives the "page-down" scrollbar action. | |
| 811 \(The way this is done can vary from scrollbar to scrollbar.) One argument, | |
| 812 a cons containing the scrollbar's window and a value (#### document me! | |
| 813 This value is nil for Motif/Lucid scrollbars and a number for Athena | |
| 814 scrollbars). You can advise this function to change the scrollbar | |
| 815 behavior. | |
| 816 */ | |
| 817 (object)) | |
| 818 { | |
| 819 Lisp_Object window = Fcar (object); | |
| 820 | |
| 821 CHECK_LIVE_WINDOW (window); | |
| 822 /* Motif and Athena scrollbars behave differently, but in accordance | |
| 823 with their standard behaviors. It is not possible to hide the | |
| 824 differences down in lwlib because knowledge of XEmacs buffer and | |
| 825 cursor motion routines is necessary. */ | |
| 442 | 826 |
| 827 if (NILP (XCDR (object))) | |
| 828 window_scroll (window, Qnil, 1, ERROR_ME_NOT); | |
| 829 else | |
| 830 { | |
| 831 Lisp_Object value = Fcdr (object); | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
832 CHECK_FIXNUM (value); |
| 442 | 833 Fmove_to_window_line (value, window); |
| 834 Fcenter_to_window_line (Qzero, window); | |
| 835 } | |
| 836 | |
| 428 | 837 zmacs_region_stays = 1; |
| 838 return Qnil; | |
| 839 } | |
| 840 | |
| 841 DEFUN ("scrollbar-to-top", Fscrollbar_to_top, 1, 1, 0, /* | |
| 842 Function called when the user invokes the "to-top" scrollbar action. | |
| 843 The way this is done can vary from scrollbar to scrollbar, but | |
| 844 C-button1 on the up-arrow is very common. One argument, the | |
| 845 scrollbar's window. You can advise this function to change the | |
| 846 scrollbar behavior. | |
| 847 */ | |
| 848 (window)) | |
| 849 { | |
| 850 Lisp_Object orig_pt = Fwindow_point (window); | |
| 851 Fset_window_point (window, Fpoint_min (Fwindow_buffer (window))); | |
| 852 Fcenter_to_window_line (Qzero, window); | |
| 853 scrollbar_reset_cursor (window, orig_pt); | |
| 854 zmacs_region_stays = 1; | |
| 855 return Qnil; | |
| 856 } | |
| 857 | |
| 858 DEFUN ("scrollbar-to-bottom", Fscrollbar_to_bottom, 1, 1, 0, /* | |
| 859 Function called when the user invokes the "to-bottom" scrollbar action. | |
| 860 The way this is done can vary from scrollbar to scrollbar, but | |
| 861 C-button1 on the down-arrow is very common. One argument, the | |
| 862 scrollbar's window. You can advise this function to change the | |
| 863 scrollbar behavior. | |
| 864 */ | |
| 865 (window)) | |
| 866 { | |
| 867 Lisp_Object orig_pt = Fwindow_point (window); | |
| 868 Fset_window_point (window, Fpoint_max (Fwindow_buffer (window))); | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
869 Fcenter_to_window_line (make_fixnum (-3), window); |
| 428 | 870 scrollbar_reset_cursor (window, orig_pt); |
| 871 zmacs_region_stays = 1; | |
| 872 return Qnil; | |
| 873 } | |
| 874 | |
| 875 DEFUN ("scrollbar-vertical-drag", Fscrollbar_vertical_drag, 1, 1, 0, /* | |
| 876 Function called when the user drags the vertical scrollbar slider. | |
| 877 One argument, a cons containing the scrollbar's window and a value | |
| 878 between point-min and point-max. You can advise this function to | |
| 879 change the scrollbar behavior. | |
| 880 */ | |
| 881 (object)) | |
| 882 { | |
| 665 | 883 Charbpos start_pos; |
| 428 | 884 Lisp_Object orig_pt; |
| 885 Lisp_Object window = Fcar (object); | |
| 886 Lisp_Object value = Fcdr (object); | |
| 887 | |
| 888 orig_pt = Fwindow_point (window); | |
| 889 Fset_marker (XWINDOW (window)->sb_point, value, Fwindow_buffer (window)); | |
| 890 start_pos = scrollbar_point (XWINDOW (window), 1); | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
891 Fset_window_start (window, make_fixnum (start_pos), Qnil); |
| 428 | 892 scrollbar_reset_cursor (window, orig_pt); |
| 893 Fsit_for(Qzero, Qnil); | |
| 894 zmacs_region_stays = 1; | |
| 895 return Qnil; | |
| 896 } | |
| 897 | |
| 898 DEFUN ("scrollbar-set-hscroll", Fscrollbar_set_hscroll, 2, 2, 0, /* | |
| 899 Set WINDOW's hscroll position to VALUE. | |
| 900 This ensures that VALUE is in the proper range for the horizontal scrollbar. | |
| 901 */ | |
| 902 (window, value)) | |
| 903 { | |
| 904 struct window *w; | |
| 905 int hscroll, wcw, max_len; | |
| 906 | |
| 907 CHECK_LIVE_WINDOW (window); | |
| 908 if (!EQ (value, Qmax)) | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
909 CHECK_FIXNUM (value); |
| 428 | 910 |
| 911 w = XWINDOW (window); | |
| 912 wcw = window_char_width (w, 0) - 1; | |
| 440 | 913 /* #### We should be able to scroll further right as long as there is |
| 428 | 914 a visible truncation glyph. This calculation for max is bogus. */ |
| 915 max_len = w->max_line_len + 2; | |
| 916 | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
917 if (EQ (value, Qmax) || (XFIXNUM (value) > (max_len - wcw))) |
| 428 | 918 hscroll = max_len - wcw; |
| 919 else | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
920 hscroll = XFIXNUM (value); |
| 428 | 921 |
| 922 /* Can't allow this out of set-window-hscroll's acceptable range. */ | |
| 923 /* #### What hell on the earth this code limits scroll size to the | |
| 924 machine-dependent SHORT size? -- kkm */ | |
| 925 if (hscroll < 0) | |
| 926 hscroll = 0; | |
| 927 else if (hscroll >= (1 << (SHORTBITS - 1)) - 1) | |
| 928 hscroll = (1 << (SHORTBITS - 1)) - 1; | |
| 929 | |
| 930 if (hscroll != w->hscroll) | |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
931 Fset_window_hscroll (window, make_fixnum (hscroll)); |
| 428 | 932 |
| 933 return Qnil; | |
| 934 } | |
| 935 | |
| 936 | |
| 937 /************************************************************************/ | |
| 938 /* initialization */ | |
| 939 /************************************************************************/ | |
| 940 | |
| 941 void | |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
942 scrollbar_objects_create (void) |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
943 { |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
944 #ifdef MEMORY_USAGE_STATS |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
945 OBJECT_HAS_METHOD (scrollbar_instance, memory_usage); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
946 #endif |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
947 } |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
948 void |
| 428 | 949 syms_of_scrollbar (void) |
| 950 { | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3024
diff
changeset
|
951 INIT_LISP_OBJECT (scrollbar_instance); |
| 617 | 952 |
| 563 | 953 DEFSYMBOL (Qscrollbar_line_up); |
| 954 DEFSYMBOL (Qscrollbar_line_down); | |
| 955 DEFSYMBOL (Qscrollbar_page_up); | |
| 956 DEFSYMBOL (Qscrollbar_page_down); | |
| 957 DEFSYMBOL (Qscrollbar_to_top); | |
| 958 DEFSYMBOL (Qscrollbar_to_bottom); | |
| 959 DEFSYMBOL (Qscrollbar_vertical_drag); | |
| 428 | 960 |
| 563 | 961 DEFSYMBOL (Qscrollbar_char_left); |
| 962 DEFSYMBOL (Qscrollbar_char_right); | |
| 963 DEFSYMBOL (Qscrollbar_page_left); | |
| 964 DEFSYMBOL (Qscrollbar_page_right); | |
| 965 DEFSYMBOL (Qscrollbar_to_left); | |
| 966 DEFSYMBOL (Qscrollbar_to_right); | |
| 967 DEFSYMBOL (Qscrollbar_horizontal_drag); | |
| 428 | 968 |
| 563 | 969 DEFSYMBOL (Qinit_scrollbar_from_resources); |
| 428 | 970 |
| 971 /* #### All these functions should be moved into Lisp. | |
| 972 See comment above. */ | |
| 973 DEFSUBR (Fscrollbar_line_up); | |
| 974 DEFSUBR (Fscrollbar_line_down); | |
| 975 DEFSUBR (Fscrollbar_page_up); | |
| 976 DEFSUBR (Fscrollbar_page_down); | |
| 977 DEFSUBR (Fscrollbar_to_top); | |
| 978 DEFSUBR (Fscrollbar_to_bottom); | |
| 979 DEFSUBR (Fscrollbar_vertical_drag); | |
| 980 | |
| 981 DEFSUBR (Fscrollbar_set_hscroll); | |
| 982 } | |
| 983 | |
| 984 void | |
| 985 vars_of_scrollbar (void) | |
| 986 { | |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
987 #ifdef MEMORY_USAGE_STATS |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
988 OBJECT_HAS_PROPERTY |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
989 (scrollbar_instance, memusage_stats_list, |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
990 list1 (intern ("device-data"))); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
991 #endif /* MEMORY_USAGE_STATS */ |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
992 |
| 428 | 993 DEFVAR_LISP ("scrollbar-pointer-glyph", &Vscrollbar_pointer_glyph /* |
| 994 *The shape of the mouse-pointer when over a scrollbar. | |
| 995 This is a glyph; use `set-glyph-image' to change it. | |
| 996 If unspecified in a particular domain, the window-system-provided | |
| 997 default pointer is used. | |
| 998 */ ); | |
| 999 | |
| 1000 Fprovide (intern ("scrollbar")); | |
| 1001 } | |
| 1002 | |
| 1003 void | |
| 1004 specifier_vars_of_scrollbar (void) | |
| 1005 { | |
| 1006 DEFVAR_SPECIFIER ("scrollbar-width", &Vscrollbar_width /* | |
| 1007 *Width of vertical scrollbars. | |
| 1008 This is a specifier; use `set-specifier' to change it. | |
| 1009 */ ); | |
| 1010 Vscrollbar_width = make_magic_specifier (Qnatnum); | |
| 1011 set_specifier_fallback | |
| 1012 (Vscrollbar_width, | |
| 1295 | 1013 #ifdef HAVE_TTY |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
1014 list2 (Fcons (list1 (Qtty), make_fixnum (0)), |
|
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
1015 Fcons (Qnil, make_fixnum (DEFAULT_SCROLLBAR_WIDTH))) |
| 1295 | 1016 #else |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
1017 list1 (Fcons (Qnil, make_fixnum (DEFAULT_SCROLLBAR_WIDTH))) |
| 1295 | 1018 #endif |
| 1019 ); | |
| 428 | 1020 set_specifier_caching (Vscrollbar_width, |
| 438 | 1021 offsetof (struct window, scrollbar_width), |
| 428 | 1022 vertical_scrollbar_changed_in_window, |
| 438 | 1023 offsetof (struct frame, scrollbar_width), |
| 444 | 1024 frame_size_slipped, 0); |
| 428 | 1025 |
| 1026 DEFVAR_SPECIFIER ("scrollbar-height", &Vscrollbar_height /* | |
| 1027 *Height of horizontal scrollbars. | |
| 1028 This is a specifier; use `set-specifier' to change it. | |
| 1029 */ ); | |
| 1030 Vscrollbar_height = make_magic_specifier (Qnatnum); | |
| 1031 set_specifier_fallback | |
| 1032 (Vscrollbar_height, | |
| 1295 | 1033 #ifdef HAVE_TTY |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
1034 list2 (Fcons (list1 (Qtty), make_fixnum (0)), |
|
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
1035 Fcons (Qnil, make_fixnum (DEFAULT_SCROLLBAR_HEIGHT))) |
| 1295 | 1036 #else |
|
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
1037 list1 (Fcons (Qnil, make_fixnum (DEFAULT_SCROLLBAR_HEIGHT))) |
| 1295 | 1038 #endif |
| 1039 ); | |
| 428 | 1040 set_specifier_caching (Vscrollbar_height, |
| 438 | 1041 offsetof (struct window, scrollbar_height), |
| 428 | 1042 some_window_value_changed, |
| 438 | 1043 offsetof (struct frame, scrollbar_height), |
| 444 | 1044 frame_size_slipped, 0); |
| 428 | 1045 |
| 1046 DEFVAR_SPECIFIER ("horizontal-scrollbar-visible-p", &Vhorizontal_scrollbar_visible_p /* | |
| 1047 *Whether the horizontal scrollbar is visible. | |
| 1048 This is a specifier; use `set-specifier' to change it. | |
| 1049 */ ); | |
| 1050 Vhorizontal_scrollbar_visible_p = Fmake_specifier (Qboolean); | |
| 1051 set_specifier_fallback (Vhorizontal_scrollbar_visible_p, | |
| 1052 list1 (Fcons (Qnil, Qt))); | |
| 1053 set_specifier_caching (Vhorizontal_scrollbar_visible_p, | |
| 438 | 1054 offsetof (struct window, |
| 1055 horizontal_scrollbar_visible_p), | |
| 428 | 1056 some_window_value_changed, |
| 438 | 1057 offsetof (struct frame, |
| 1058 horizontal_scrollbar_visible_p), | |
| 444 | 1059 frame_size_slipped, 0); |
| 428 | 1060 |
| 1061 DEFVAR_SPECIFIER ("vertical-scrollbar-visible-p", &Vvertical_scrollbar_visible_p /* | |
| 1062 *Whether the vertical scrollbar is visible. | |
| 1063 This is a specifier; use `set-specifier' to change it. | |
| 1064 */ ); | |
| 1065 Vvertical_scrollbar_visible_p = Fmake_specifier (Qboolean); | |
| 1066 set_specifier_fallback (Vvertical_scrollbar_visible_p, | |
| 1067 list1 (Fcons (Qnil, Qt))); | |
| 1068 set_specifier_caching (Vvertical_scrollbar_visible_p, | |
| 438 | 1069 offsetof (struct window, |
| 1070 vertical_scrollbar_visible_p), | |
| 428 | 1071 vertical_scrollbar_changed_in_window, |
| 438 | 1072 offsetof (struct frame, |
| 1073 vertical_scrollbar_visible_p), | |
| 444 | 1074 frame_size_slipped, 0); |
| 428 | 1075 |
| 1076 DEFVAR_SPECIFIER ("scrollbar-on-left-p", &Vscrollbar_on_left_p /* | |
| 1077 *Whether the vertical scrollbar is on the left side of window or frame. | |
| 1078 This is a specifier; use `set-specifier' to change it. | |
| 1079 */ ); | |
| 1080 Vscrollbar_on_left_p = Fmake_specifier (Qboolean); | |
| 442 | 1081 |
| 428 | 1082 { |
| 1083 /* Kludge. Under X, we want athena scrollbars on the left, | |
| 1084 while all other scrollbars go on the right by default. */ | |
| 1085 Lisp_Object fallback = list1 (Fcons (Qnil, Qnil)); | |
| 1086 #if defined (HAVE_X_WINDOWS) \ | |
| 1087 && !defined (LWLIB_SCROLLBARS_MOTIF) \ | |
| 1088 && !defined (LWLIB_SCROLLBARS_LUCID) \ | |
| 1089 && !defined (LWLIB_SCROLLBARS_ATHENA3D) | |
| 1090 | |
| 1091 fallback = Fcons (Fcons (list1 (Qx), Qt), fallback); | |
| 1092 #endif | |
| 1093 set_specifier_fallback (Vscrollbar_on_left_p, fallback); | |
| 1094 } | |
| 1095 | |
| 1096 set_specifier_caching (Vscrollbar_on_left_p, | |
| 438 | 1097 offsetof (struct window, scrollbar_on_left_p), |
| 428 | 1098 vertical_scrollbar_changed_in_window, |
| 438 | 1099 offsetof (struct frame, scrollbar_on_left_p), |
| 444 | 1100 frame_size_slipped, 0); |
| 428 | 1101 |
| 1102 DEFVAR_SPECIFIER ("scrollbar-on-top-p", &Vscrollbar_on_top_p /* | |
| 1103 *Whether the horizontal scrollbar is on the top side of window or frame. | |
| 1104 This is a specifier; use `set-specifier' to change it. | |
| 1105 */ ); | |
| 1106 Vscrollbar_on_top_p = Fmake_specifier (Qboolean); | |
| 1107 set_specifier_fallback (Vscrollbar_on_top_p, | |
| 1108 list1 (Fcons (Qnil, Qnil))); | |
| 1109 set_specifier_caching (Vscrollbar_on_top_p, | |
| 438 | 1110 offsetof (struct window, scrollbar_on_top_p), |
| 428 | 1111 some_window_value_changed, |
| 438 | 1112 offsetof (struct frame, scrollbar_on_top_p), |
| 444 | 1113 frame_size_slipped, 0); |
| 428 | 1114 } |
| 1115 | |
| 1116 void | |
| 1117 complex_vars_of_scrollbar (void) | |
| 1118 { | |
| 1119 Vscrollbar_pointer_glyph = Fmake_glyph_internal (Qpointer); | |
| 1120 | |
| 1121 set_specifier_caching (XGLYPH (Vscrollbar_pointer_glyph)->image, | |
| 438 | 1122 offsetof (struct window, scrollbar_pointer), |
| 428 | 1123 scrollbar_pointer_changed_in_window, |
| 444 | 1124 0, 0, 0); |
| 428 | 1125 } |
