diff options
| author | Po Lu | 2022-03-11 01:33:24 +0000 |
|---|---|---|
| committer | Po Lu | 2022-03-11 01:33:24 +0000 |
| commit | 170cae0e9080697e1efa1678bc1504890bcf4a6e (patch) | |
| tree | 5e36e9a9d025714288dfd8764c4e7cc420d81ab3 /src | |
| parent | 22dde4e621fb49b9f05d560aee22332ad60bf485 (diff) | |
| download | emacs-170cae0e9080697e1efa1678bc1504890bcf4a6e.tar.gz emacs-170cae0e9080697e1efa1678bc1504890bcf4a6e.zip | |
Fix scroll bar portion on Haiku scroll bars
* src/haiku_support.cc (EmacsScrollBar): Set steps to
appropriate value.
(ValueChanged): Test new value against old value before sending
value event.
(MessageReceived): Handle portion and range.
(BView_scroll_bar_update): New argument for portion.
* src/haiku_support.h: Update prototypes.
* src/haikuterm.c (haiku_set_scroll_bar_thumb):
(haiku_set_horizontal_scroll_bar_thumb): New functions.
(haiku_set_horizontal_scroll_bar):
(haiku_set_vertical_scroll_bar): Use those functions to set
scroll bar values.
(haiku_read_socket): Handle new meanings of scroll bar values.
* src/haikuterm.h (struct scroll_bar):
Diffstat (limited to 'src')
| -rw-r--r-- | src/haiku_support.cc | 31 | ||||
| -rw-r--r-- | src/haiku_support.h | 3 | ||||
| -rw-r--r-- | src/haikuterm.c | 118 | ||||
| -rw-r--r-- | src/haikuterm.h | 2 |
4 files changed, 127 insertions, 27 deletions
diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 2f2adfd8f8a..6f5196dc1ce 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc | |||
| @@ -1571,16 +1571,26 @@ public: | |||
| 1571 | vw->SetResizingMode (B_FOLLOW_NONE); | 1571 | vw->SetResizingMode (B_FOLLOW_NONE); |
| 1572 | horizontal = horizontal_p; | 1572 | horizontal = horizontal_p; |
| 1573 | get_scroll_bar_info (&info); | 1573 | get_scroll_bar_info (&info); |
| 1574 | SetSteps (5000, 10000); | ||
| 1574 | } | 1575 | } |
| 1575 | 1576 | ||
| 1576 | void | 1577 | void |
| 1577 | MessageReceived (BMessage *msg) | 1578 | MessageReceived (BMessage *msg) |
| 1578 | { | 1579 | { |
| 1580 | int32 portion, range; | ||
| 1581 | |||
| 1579 | if (msg->what == SCROLL_BAR_UPDATE) | 1582 | if (msg->what == SCROLL_BAR_UPDATE) |
| 1580 | { | 1583 | { |
| 1581 | old_value = msg->GetInt32 ("emacs:units", 0); | 1584 | old_value = msg->GetInt32 ("emacs:units", 0); |
| 1582 | this->SetRange (0, msg->GetInt32 ("emacs:range", 0)); | 1585 | portion = msg->GetInt32 ("emacs:portion", 0); |
| 1583 | this->SetValue (msg->GetInt32 ("emacs:units", 0)); | 1586 | range = msg->GetInt32 ("emacs:range", 0); |
| 1587 | |||
| 1588 | if (!msg->GetBool ("emacs:dragging", false)) | ||
| 1589 | { | ||
| 1590 | this->SetRange (0, range); | ||
| 1591 | this->SetValue (old_value); | ||
| 1592 | this->SetProportion ((float) portion / range); | ||
| 1593 | } | ||
| 1584 | } | 1594 | } |
| 1585 | 1595 | ||
| 1586 | BScrollBar::MessageReceived (msg); | 1596 | BScrollBar::MessageReceived (msg); |
| @@ -1612,11 +1622,15 @@ public: | |||
| 1612 | return; | 1622 | return; |
| 1613 | } | 1623 | } |
| 1614 | 1624 | ||
| 1615 | rq.scroll_bar = this; | 1625 | if (new_value != old_value) |
| 1616 | rq.window = Window (); | 1626 | { |
| 1617 | rq.position = new_value; | 1627 | rq.scroll_bar = this; |
| 1628 | rq.window = Window (); | ||
| 1629 | rq.position = new_value; | ||
| 1630 | old_value = new_value; | ||
| 1618 | 1631 | ||
| 1619 | haiku_write (SCROLL_BAR_VALUE_EVENT, &rq); | 1632 | haiku_write (SCROLL_BAR_VALUE_EVENT, &rq); |
| 1633 | } | ||
| 1620 | } | 1634 | } |
| 1621 | 1635 | ||
| 1622 | BRegion | 1636 | BRegion |
| @@ -2269,13 +2283,16 @@ BView_move_frame (void *view, int x, int y, int x1, int y1) | |||
| 2269 | } | 2283 | } |
| 2270 | 2284 | ||
| 2271 | void | 2285 | void |
| 2272 | BView_scroll_bar_update (void *sb, int portion, int whole, int position) | 2286 | BView_scroll_bar_update (void *sb, int portion, int whole, int position, |
| 2287 | bool dragging) | ||
| 2273 | { | 2288 | { |
| 2274 | BScrollBar *bar = (BScrollBar *) sb; | 2289 | BScrollBar *bar = (BScrollBar *) sb; |
| 2275 | BMessage msg = BMessage (SCROLL_BAR_UPDATE); | 2290 | BMessage msg = BMessage (SCROLL_BAR_UPDATE); |
| 2276 | BMessenger mr = BMessenger (bar); | 2291 | BMessenger mr = BMessenger (bar); |
| 2277 | msg.AddInt32 ("emacs:range", whole); | 2292 | msg.AddInt32 ("emacs:range", whole); |
| 2278 | msg.AddInt32 ("emacs:units", position); | 2293 | msg.AddInt32 ("emacs:units", position); |
| 2294 | msg.AddInt32 ("emacs:portion", portion); | ||
| 2295 | msg.AddBool ("emacs:dragging", dragging); | ||
| 2279 | 2296 | ||
| 2280 | mr.SendMessage (&msg); | 2297 | mr.SendMessage (&msg); |
| 2281 | } | 2298 | } |
diff --git a/src/haiku_support.h b/src/haiku_support.h index fb86372c4ff..e7c55d4d758 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h | |||
| @@ -628,7 +628,8 @@ extern "C" | |||
| 628 | BView_move_frame (void *view, int x, int y, int x1, int y1); | 628 | BView_move_frame (void *view, int x, int y, int x1, int y1); |
| 629 | 629 | ||
| 630 | extern void | 630 | extern void |
| 631 | BView_scroll_bar_update (void *sb, int portion, int whole, int position); | 631 | BView_scroll_bar_update (void *sb, int portion, int whole, int position, |
| 632 | bool dragging); | ||
| 632 | 633 | ||
| 633 | extern int | 634 | extern int |
| 634 | BScrollBar_default_size (int horizontal_p); | 635 | BScrollBar_default_size (int horizontal_p); |
diff --git a/src/haikuterm.c b/src/haikuterm.c index d3168129ce4..b100952f111 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c | |||
| @@ -40,6 +40,9 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 40 | #include <cairo.h> | 40 | #include <cairo.h> |
| 41 | #endif | 41 | #endif |
| 42 | 42 | ||
| 43 | /* Minimum and maximum values used for Haiku scroll bars. */ | ||
| 44 | #define BE_SB_MAX 10000000 | ||
| 45 | |||
| 43 | struct haiku_display_info *x_display_list = NULL; | 46 | struct haiku_display_info *x_display_list = NULL; |
| 44 | extern frame_parm_handler haiku_frame_parm_handlers[]; | 47 | extern frame_parm_handler haiku_frame_parm_handlers[]; |
| 45 | 48 | ||
| @@ -428,6 +431,78 @@ haiku_mouse_or_wdesc_frame (void *window) | |||
| 428 | } | 431 | } |
| 429 | } | 432 | } |
| 430 | 433 | ||
| 434 | /* Set the thumb size and position of scroll bar BAR. We are | ||
| 435 | currently displaying PORTION out of a whole WHOLE, and our position | ||
| 436 | POSITION. */ | ||
| 437 | |||
| 438 | static void | ||
| 439 | haiku_set_scroll_bar_thumb (struct scroll_bar *bar, int portion, | ||
| 440 | int position, int whole) | ||
| 441 | { | ||
| 442 | void *scroll_bar = bar->scroll_bar; | ||
| 443 | float top, shown; | ||
| 444 | int size, value; | ||
| 445 | |||
| 446 | if (scroll_bar_adjust_thumb_portion_p) | ||
| 447 | { | ||
| 448 | /* We use an estimate of 30 chars per line rather than the real | ||
| 449 | `portion' value. This has the disadvantage that the thumb | ||
| 450 | size is not very representative, but it makes our life a lot | ||
| 451 | easier. Otherwise, we have to constantly adjust the thumb | ||
| 452 | size, which we can't always do quickly enough: while | ||
| 453 | dragging, the size of the thumb might prevent the user from | ||
| 454 | dragging the thumb all the way to the end. */ | ||
| 455 | portion = WINDOW_TOTAL_LINES (XWINDOW (bar->window)) * 30; | ||
| 456 | /* When the thumb is at the bottom, position == whole. So we | ||
| 457 | need to increase `whole' to make space for the thumb. */ | ||
| 458 | whole += portion; | ||
| 459 | } | ||
| 460 | |||
| 461 | if (whole <= 0) | ||
| 462 | top = 0, shown = 1; | ||
| 463 | else | ||
| 464 | { | ||
| 465 | top = (float) position / whole; | ||
| 466 | shown = (float) portion / whole; | ||
| 467 | } | ||
| 468 | |||
| 469 | /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX | ||
| 470 | is the scroll bar's maximum and MIN is the scroll bar's minimum | ||
| 471 | value. */ | ||
| 472 | size = clip_to_bounds (1, shown * BE_SB_MAX, BE_SB_MAX); | ||
| 473 | |||
| 474 | /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */ | ||
| 475 | value = top * BE_SB_MAX; | ||
| 476 | value = min (value, BE_SB_MAX - size); | ||
| 477 | |||
| 478 | if (!bar->dragging) | ||
| 479 | bar->page_size = size; | ||
| 480 | |||
| 481 | BView_scroll_bar_update (scroll_bar, size, BE_SB_MAX, value, | ||
| 482 | bar->dragging); | ||
| 483 | } | ||
| 484 | |||
| 485 | static void | ||
| 486 | haiku_set_horizontal_scroll_bar_thumb (struct scroll_bar *bar, int portion, | ||
| 487 | int position, int whole) | ||
| 488 | { | ||
| 489 | void *scroll_bar = bar->scroll_bar; | ||
| 490 | float shown, top; | ||
| 491 | int size, value; | ||
| 492 | |||
| 493 | shown = (float) portion / whole; | ||
| 494 | top = (float) position / (whole - portion); | ||
| 495 | |||
| 496 | size = clip_to_bounds (1, shown * BE_SB_MAX, BE_SB_MAX); | ||
| 497 | value = clip_to_bounds (0, top * (BE_SB_MAX - size), BE_SB_MAX - size); | ||
| 498 | |||
| 499 | if (!bar->dragging) | ||
| 500 | bar->page_size = size; | ||
| 501 | |||
| 502 | BView_scroll_bar_update (scroll_bar, shown, BE_SB_MAX, value, | ||
| 503 | bar->dragging); | ||
| 504 | } | ||
| 505 | |||
| 431 | static struct scroll_bar * | 506 | static struct scroll_bar * |
| 432 | haiku_scroll_bar_from_widget (void *scroll_bar, void *window) | 507 | haiku_scroll_bar_from_widget (void *scroll_bar, void *window) |
| 433 | { | 508 | { |
| @@ -2211,7 +2286,6 @@ haiku_set_horizontal_scroll_bar (struct window *w, int portion, int whole, int p | |||
| 2211 | if (NILP (w->horizontal_scroll_bar)) | 2286 | if (NILP (w->horizontal_scroll_bar)) |
| 2212 | { | 2287 | { |
| 2213 | bar = haiku_scroll_bar_create (w, left, top, width, height, true); | 2288 | bar = haiku_scroll_bar_create (w, left, top, width, height, true); |
| 2214 | BView_scroll_bar_update (bar->scroll_bar, portion, whole, position); | ||
| 2215 | bar->update = position; | 2289 | bar->update = position; |
| 2216 | bar->position = position; | 2290 | bar->position = position; |
| 2217 | bar->total = whole; | 2291 | bar->total = whole; |
| @@ -2234,13 +2308,9 @@ haiku_set_horizontal_scroll_bar (struct window *w, int portion, int whole, int p | |||
| 2234 | bar->width = width; | 2308 | bar->width = width; |
| 2235 | bar->height = height; | 2309 | bar->height = height; |
| 2236 | } | 2310 | } |
| 2237 | |||
| 2238 | if (!bar->dragging) | ||
| 2239 | { | ||
| 2240 | BView_scroll_bar_update (bar->scroll_bar, portion, whole, position); | ||
| 2241 | BView_invalidate (bar->scroll_bar); | ||
| 2242 | } | ||
| 2243 | } | 2311 | } |
| 2312 | |||
| 2313 | haiku_set_horizontal_scroll_bar_thumb (bar, portion, position, whole); | ||
| 2244 | bar->position = position; | 2314 | bar->position = position; |
| 2245 | bar->total = whole; | 2315 | bar->total = whole; |
| 2246 | XSETVECTOR (barobj, bar); | 2316 | XSETVECTOR (barobj, bar); |
| @@ -2271,7 +2341,6 @@ haiku_set_vertical_scroll_bar (struct window *w, | |||
| 2271 | if (NILP (w->vertical_scroll_bar)) | 2341 | if (NILP (w->vertical_scroll_bar)) |
| 2272 | { | 2342 | { |
| 2273 | bar = haiku_scroll_bar_create (w, left, top, width, height, false); | 2343 | bar = haiku_scroll_bar_create (w, left, top, width, height, false); |
| 2274 | BView_scroll_bar_update (bar->scroll_bar, portion, whole, position); | ||
| 2275 | bar->position = position; | 2344 | bar->position = position; |
| 2276 | bar->total = whole; | 2345 | bar->total = whole; |
| 2277 | } | 2346 | } |
| @@ -2293,15 +2362,9 @@ haiku_set_vertical_scroll_bar (struct window *w, | |||
| 2293 | bar->width = width; | 2362 | bar->width = width; |
| 2294 | bar->height = height; | 2363 | bar->height = height; |
| 2295 | } | 2364 | } |
| 2296 | |||
| 2297 | if (!bar->dragging) | ||
| 2298 | { | ||
| 2299 | BView_scroll_bar_update (bar->scroll_bar, portion, whole, position); | ||
| 2300 | bar->update = position; | ||
| 2301 | BView_invalidate (bar->scroll_bar); | ||
| 2302 | } | ||
| 2303 | } | 2365 | } |
| 2304 | 2366 | ||
| 2367 | haiku_set_scroll_bar_thumb (bar, portion, position, whole); | ||
| 2305 | bar->position = position; | 2368 | bar->position = position; |
| 2306 | bar->total = whole; | 2369 | bar->total = whole; |
| 2307 | 2370 | ||
| @@ -3191,6 +3254,7 @@ haiku_read_socket (struct terminal *terminal, struct input_event *hold_quit) | |||
| 3191 | struct haiku_scroll_bar_value_event *b = buf; | 3254 | struct haiku_scroll_bar_value_event *b = buf; |
| 3192 | struct scroll_bar *bar | 3255 | struct scroll_bar *bar |
| 3193 | = haiku_scroll_bar_from_widget (b->scroll_bar, b->window); | 3256 | = haiku_scroll_bar_from_widget (b->scroll_bar, b->window); |
| 3257 | int portion, whole; | ||
| 3194 | 3258 | ||
| 3195 | if (!bar) | 3259 | if (!bar) |
| 3196 | continue; | 3260 | continue; |
| @@ -3205,13 +3269,29 @@ haiku_read_socket (struct terminal *terminal, struct input_event *hold_quit) | |||
| 3205 | 3269 | ||
| 3206 | if (bar->position != b->position) | 3270 | if (bar->position != b->position) |
| 3207 | { | 3271 | { |
| 3208 | inev.kind = bar->horizontal ? HORIZONTAL_SCROLL_BAR_CLICK_EVENT : | 3272 | inev.kind = (bar->horizontal |
| 3209 | SCROLL_BAR_CLICK_EVENT; | 3273 | ? HORIZONTAL_SCROLL_BAR_CLICK_EVENT : |
| 3274 | SCROLL_BAR_CLICK_EVENT); | ||
| 3210 | inev.part = bar->horizontal ? | 3275 | inev.part = bar->horizontal ? |
| 3211 | scroll_bar_horizontal_handle : scroll_bar_handle; | 3276 | scroll_bar_horizontal_handle : scroll_bar_handle; |
| 3212 | 3277 | ||
| 3213 | XSETINT (inev.x, b->position); | 3278 | if (bar->horizontal) |
| 3214 | XSETINT (inev.y, bar->total); | 3279 | { |
| 3280 | portion = bar->total * ((float) b->position | ||
| 3281 | / BE_SB_MAX); | ||
| 3282 | whole = (bar->total | ||
| 3283 | * ((float) (BE_SB_MAX - bar->page_size) | ||
| 3284 | / BE_SB_MAX)); | ||
| 3285 | portion = min (portion, whole); | ||
| 3286 | } | ||
| 3287 | else | ||
| 3288 | { | ||
| 3289 | whole = BE_SB_MAX - bar->page_size; | ||
| 3290 | portion = min (b->position, whole); | ||
| 3291 | } | ||
| 3292 | |||
| 3293 | XSETINT (inev.x, portion); | ||
| 3294 | XSETINT (inev.y, whole); | ||
| 3215 | XSETWINDOW (inev.frame_or_window, w); | 3295 | XSETWINDOW (inev.frame_or_window, w); |
| 3216 | } | 3296 | } |
| 3217 | break; | 3297 | break; |
diff --git a/src/haikuterm.h b/src/haikuterm.h index a2520858f54..64fd0ec2b71 100644 --- a/src/haikuterm.h +++ b/src/haikuterm.h | |||
| @@ -213,6 +213,8 @@ struct scroll_bar | |||
| 213 | 213 | ||
| 214 | /* True if the scroll bar is horizontal. */ | 214 | /* True if the scroll bar is horizontal. */ |
| 215 | bool horizontal; | 215 | bool horizontal; |
| 216 | |||
| 217 | int page_size; | ||
| 216 | }; | 218 | }; |
| 217 | 219 | ||
| 218 | #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec)) | 220 | #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec)) |