diff options
author | Po Lu <luangruo@yahoo.com> | 2022-02-21 03:27:48 +0000 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2022-02-21 03:28:46 +0000 |
commit | 816cf19a3a4a2697392d58516c73374d7aaa1533 (patch) | |
tree | e63dd1e9bbd7eee7171d7072616ffba29fa71cbc | |
parent | f0ac4b7797fb16833a7a0c49593f36d88c69d2d5 (diff) | |
download | emacs-816cf19a3a4a2697392d58516c73374d7aaa1533.tar.gz |
Implement left-right separators for dialog boxes on Haiku
* src/haiku_support.cc (BAlert_set_offset_spacing): New
function.
* src/haiku_support.h: Update prototypes.
* src/haikumenu.c (struct submenu_stack_cell): Remove unused
struct.
(haiku_dialog_show): Use offset spacing if a left-right boundary
was seen and make sure the user can always quit a dialog if no
enabled items exist.
-rw-r--r-- | src/haiku_support.cc | 10 | ||||
-rw-r--r-- | src/haiku_support.h | 3 | ||||
-rw-r--r-- | src/haikumenu.c | 54 |
3 files changed, 51 insertions, 16 deletions
diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 0f4ed169fbf..4f6a96568cb 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -2686,6 +2686,16 @@ BAlert_add_button (void *alert, const char *text) return al->ButtonAt (al->CountButtons () - 1); } +/* Make sure the leftmost button is grouped to the left hand side of + the alert. */ +void +BAlert_set_offset_spacing (void *alert) +{ + BAlert *al = (BAlert *) alert; + + al->SetButtonSpacing (B_OFFSET_SPACING); +} + static int32 be_alert_thread_entry (void *thread_data) { diff --git a/src/haiku_support.h b/src/haiku_support.h index 9fc81c28750..ef433514fe7 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -754,6 +754,9 @@ extern "C" extern void * BAlert_add_button (void *alert, const char *text); + extern void + BAlert_set_offset_spacing (void *alert); + extern int32 BAlert_go (void *alert, void (*block_input_function) (void), diff --git a/src/haikumenu.c b/src/haikumenu.c index 11a76217a9d..41db0d414dd 100644 --- a/src/haikumenu.c +++ b/src/haikumenu.c @@ -32,12 +32,6 @@ static Lisp_Object *volatile menu_item_selection; int popup_activated_p = 0; -struct submenu_stack_cell -{ - void *parent_menu; - void *pane; -}; - static void digest_menu_items (void *first_menu, int start, int menu_items_used, int mbar_p) @@ -190,6 +184,11 @@ haiku_dialog_show (struct frame *f, Lisp_Object title, Lisp_Object header, const char **error_name) { int i, nb_buttons = 0; + bool boundary_seen = false; + Lisp_Object pane_name, vals[10]; + void *alert, *button; + bool enabled_item_seen_p = false; + int32 val; *error_name = NULL; @@ -199,17 +198,15 @@ haiku_dialog_show (struct frame *f, Lisp_Object title, return Qnil; } - Lisp_Object pane_name = AREF (menu_items, MENU_ITEMS_PANE_NAME); + pane_name = AREF (menu_items, MENU_ITEMS_PANE_NAME); i = MENU_ITEMS_PANE_LENGTH; if (STRING_MULTIBYTE (pane_name)) pane_name = ENCODE_UTF_8 (pane_name); block_input (); - void *alert = BAlert_new (SSDATA (pane_name), NILP (header) ? HAIKU_INFO_ALERT : - HAIKU_IDEA_ALERT); - - Lisp_Object vals[10]; + alert = BAlert_new (SSDATA (pane_name), NILP (header) ? HAIKU_INFO_ALERT : + HAIKU_IDEA_ALERT); while (i < menu_items_used) { @@ -229,7 +226,11 @@ haiku_dialog_show (struct frame *f, Lisp_Object title, if (EQ (item_name, Qquote)) { + if (nb_buttons) + boundary_seen = true; + i++; + continue; } if (nb_buttons >= 9) @@ -245,9 +246,11 @@ haiku_dialog_show (struct frame *f, Lisp_Object title, if (!NILP (descrip) && STRING_MULTIBYTE (descrip)) descrip = ENCODE_UTF_8 (descrip); - void *button = BAlert_add_button (alert, SSDATA (item_name)); + button = BAlert_add_button (alert, SSDATA (item_name)); BButton_set_enabled (button, !NILP (enable)); + enabled_item_seen_p |= !NILP (enable); + if (!NILP (descrip)) BView_set_tooltip (button, SSDATA (descrip)); @@ -255,21 +258,40 @@ haiku_dialog_show (struct frame *f, Lisp_Object title, ++nb_buttons; i += MENU_ITEMS_ITEM_LENGTH; } + + /* Haiku only lets us specify a single button to place on the + left. */ + if (boundary_seen) + BAlert_set_offset_spacing (alert); + + /* If there isn't a single enabled item, add an "Ok" button so the + popup can be dismissed. */ + if (!enabled_item_seen_p) + BAlert_add_button (alert, "Ok"); unblock_input (); unrequest_sigio (); ++popup_activated_p; - int32_t val = BAlert_go (alert, block_input, unblock_input, - process_pending_signals); + val = BAlert_go (alert, block_input, unblock_input, + process_pending_signals); --popup_activated_p; request_sigio (); if (val < 0) quit (); - else + else if (val < nb_buttons) return vals[val]; - return Qnil; + /* The dialog was dismissed via the button appended to dismiss popup + dialogs without a single enabled item. */ + if (nb_buttons) + quit (); + /* Otherwise, the Ok button was added because no buttons were seen + at all. */ + else + return Qt; + + emacs_abort (); } Lisp_Object |